
/*

        Author:		Robbe D. Morris
		Date:		September 22, 2002
		URL:			http://www.robbemorris.com

*/

function SliderSetOtherSliders()
	{
          
            var oSliderRow;
            var lArrayLength=0;
            var lLoop=0;
			var lRowWeight=0;
			var lTotal=0;
			var lSubTotal=0;
			var lDelta=0;
			var lAdjustableItems=0;
			var lSumTotal=100;
			var fZerosAdjusted=false;
			var lZeroDelta=0;
			var lHotItemAdjuster=0;
 
      try
	 {

             if (SliderMathOption != SliderMathTypePercent) { return false; }
	        
			 lArrayLength = SliderArrays.length-1;  //minus 1 to skip deadspace in perfusion calculation
		     if (lArrayLength < 1) { return false; }
 
             //  Start Load lTotal = Total of all weights, lSubTotal = Weights not included SliderCurrentIdx or Locked Items, lDelta = Diff between lTotal and lSubTotal
 
 
            for (lLoop=0; lLoop<lArrayLength; lLoop++)
            {

                oSliderRow = SliderArrays[lLoop];
             
               if (oSliderRow[idxSliderDisplay] == true)
			   {
                    
					 lRowWeight = parseFloat(oSliderRow[idxSliderDisplayWeight]); 
					 
					 lTotal += lRowWeight;

					if((SliderIsLocked(lLoop) == false) && (lLoop != SliderCurrentIdx)) {  lSubTotal += lRowWeight; lAdjustableItems += 1;  }

				}

			}
	   
            lDelta = lSumTotal - lTotal;
		//	alert('delta: ' + lDelta);

             // End Load Total

           
		   // Start Lock Down check.  If all items are locked down, warn the user.
		   
           if (lSubTotal == 0)
		   {
			   if (lAdjustableItems ==0) {  return false;  }
			   else  { fZerosAdjusted=true;  }
		   }

           //  End Lock Down Check
 
           // Start Distribution:
 
            for (lLoop=0; lLoop<lArrayLength; lLoop++)
            {
                oSliderRow = SliderArrays[lLoop];
             
               if (oSliderRow[idxSliderDisplay] == true)
			   {
				   	if((SliderIsLocked(lLoop) == false) && (lLoop != SliderCurrentIdx)) 
				   {
						
						lRowWeight = parseFloat(oSliderRow[idxSliderDisplayWeight]); 
                       

                       if (fZerosAdjusted == true)
					   {
                          
						   lRowWeight = lDelta / lAdjustableItems;
        
		                   if (lRowWeight < 0.0001) { lHotItemAdjuster += lRowWeight; lRowWeight = 0; }
       
					   }
					   else
					   {
						   lRowWeight = lRowWeight + ((lRowWeight / lSubTotal) * lDelta);
						  if (lRowWeight < 0.0001) { lHotItemAdjuster += lRowWeight; lRowWeight = 0; }
					   }
						  
						  oSliderRow[idxSliderDisplayWeight] = lRowWeight;
						  
						  SliderArrays[lLoop] = oSliderRow;

				   }

				}

			}

 
                    //  Adjust the Current Index Weight for instances of other element rounding errors.

                         oSliderRow = SliderArrays[SliderCurrentIdx]; 
                         oSliderRow[idxSliderDisplayWeight] = parseFloat(oSliderRow[idxSliderDisplayWeight]) + lHotItemAdjuster;
                         SliderArrays[SliderCurrentIdx] = oSliderRow;

                    // End Current Index Adjust




			// End Distribution
                 
	      }
		   catch (exception) 
		  { 
		     if (exception.description == null) { alert("Slider Set Other Sliders: " + exception.message); }  
		     else {  alert("Slider Set Other Sliders: " + exception.description); }
		  }

		 return true; 
	}













	function SliderConvertWidthToWeight(nWidth)
	{
         var nRet=0;
		 var nMax=0;
		 var nWeight=0;

		 nMax = parseFloat(SliderMaxWidth);
         nWidth = parseFloat(nWidth);
 
         switch (SliderMathOption)
		{

              case 1:
 
                           nWeight = (nWidth / nMax) * 100;	   
                           nRet =  nWeight;
				           break;

			  case 2:
 
				           nWeight = (nWidth / nMax) * 9;	
						   if (nWeight <1) { nWeight=1; }
                           nRet =  nWeight;
				           break;

		}

		 return nRet;
		  
	}

	function SliderConvertWeightToWidth(nWeight)
	{
         var nRet=0;
		 var nMax=0;
		 var nWidthPercent=0;
		  
		 nMax = parseFloat(SliderMaxWidth);
         nWeight = parseFloat(nWeight);
 
         switch (SliderMathOption)
		{

              case 1:

                            nWeight = nWeight * (SliderMaxWidth / 100);								   
                           nRet = SliderRoundNumber(nWeight,"1");
				           break;

			  case 2:
				           if ((nWeight<1) || (nWeight >9)) { nWeight=1;}
						   nWidthPercent = nWeight / 9;
                           nRet = SliderRoundNumber(nMax * nWidthPercent,"1");
				           break;

		}

		 return nRet;
		  
	}

	  function SliderRoundNumber(number,X)
  {
	  
		var number2;
		var TmpNum;

		 X=(!X ? 1:X);
	
		number2 = Math.round(number*Math.pow(10,X))/Math.pow(10,X);
		TmpNum = "" + number2;
		var TmpArray = TmpNum.split(".");
		if (TmpArray.length <2) { number2 = number2 + ".0"; }
	 
	    return number2;
  }