<!--
function StartUp()
{
   SetBaseCosts();
   if (document.forms[1].PassOptionListFlag.value=="PresentAppraisal") 
      SetPassedParameters();
   else
      document.forms[1].PassAddOptionSize.value=0;

   SubmitRecalculate();
}

function SetBaseCosts()                                                          
{
   var myCounter=0;
   var optionVSize=document.forms[0].OptionSize.value;
   var BaseCost=document.forms[0].TotalCost.value;
   var Base3Cost=document.forms[0].Base3.value;
   
   document.forms[0].Base1.value=doStrip(BaseCost.substring(1, BaseCost.indexOf(" ")));
   document.forms[0].Base2.value=doStrip(BaseCost.substring(BaseCost.indexOf("~")+2, BaseCost.length));
   document.forms[0].Base3.value=doStrip(Base3Cost.substring(Base3Cost.indexOf("$")+1, Base3Cost.length));
   
   while (myCounter<optionVSize)
      {
      var tempString=("document.forms[1].Option"+myCounter+".checked");
      var myOptionName=eval(tempString);
      if (myOptionName==true) 
         {
         var tempString2=("document.forms[1].OptionPrice"+myCounter+".value");
         var OptionValue=eval(tempString2);
         document.forms[0].Base1.value-=parseFloat(OptionValue);
         document.forms[0].Base2.value-=parseFloat(OptionValue);
         document.forms[0].Base3.value-=parseFloat(OptionValue);
         }
      myCounter++;
      }
}

function SetPassedParameters()
{
   document.forms[1].AddOptionList.value     = document.forms[1].PassAddOptionList.value;     
   document.forms[1].AddOptionPrices.value   = document.forms[1].PassAddOptionPrices.value;   
   document.forms[1].CheckedAddOptions.value = document.forms[1].PassCheckedAddOptions.value;
}

function round(num, d) 
{ 
    n = Math.pow(10, !d ? 2 : d);
    return Math.round(num*n) / n;
}

function doStrip(inputString)
{
   var outputString = "";
   var myChar = "";
   
   while (inputString.length > 0)
      {
      myChar = inputString.substring(0,1);
      if((myChar=="0")||(myChar=="1")||(myChar=="2")||(myChar=="3")||(myChar=="4")||(myChar=="5")||(myChar=="6")||(myChar=="7")||(myChar=="8")||(myChar=="9")||(myChar=="."))
         {
         outputString += myChar;
         inputString = inputString.substring(1);
         }
      else
         inputString = inputString.substring(1);
      }
   var outputInteger = parseFloat(outputString);  
   return outputInteger+0;
}

function commaStrip()
{
   var inputString = document.forms[1].OtherOptionText.value;
   var outputString = "";
   var myChar = "";
   
   while (inputString.length > 0)
      {
      myChar = inputString.substring(0,1);
      if ((myChar == "")||(myChar == null)||(myChar == ","))
         {
         outputString += "-";
         inputString = inputString.substring(1);
         }
      else 
         {
         outputString += myChar;
         inputString = inputString.substring(1);
         }
      }
   document.forms[1].OtherOptionText.value = outputString;
}

function doCurrencyFormat(inputValue)
// this function will take any DECIMALS and remove them along with their 'cent' values
{
   var outputValue="";
   var endString="";
   if (inputValue.indexOf(".")!=-1)
      {
      endString = inputValue.substring(inputValue.indexOf("."), inputValue.length);
      inputValue = inputValue.substring(0,inputValue.indexOf("."));
      var endStringLength = endString.length;
      if (endStringLength==2) endString+="0";
      }
   else
      { 
      endString = ".00";
      }
   while(inputValue.length > 3)
      {
      outputValue = "," + inputValue.substring(inputValue.length-3,inputValue.length) + outputValue;
      inputValue = inputValue.substring(0,inputValue.length-3);
      }
   outputValue = inputValue.substring(0,inputValue.length) + outputValue + endString;
   return outputValue;
}

function SubmitPrintRequest()
{
   SubmitRecalculate();
   document.body.background = "media/middlePrint.gif";
   window.print();
   document.body.background = "media/middle.gif";
}

function ClearOtherOptionText()
{
   if (document.forms[1].flag1.value=="false") 
      {
      document.forms[1].OtherOptionText.value="";
      document.forms[1].flag1.value=true;
      }
}

function ClearOtherOptionPrice() //            MOUSE IN
{
   if (document.forms[1].OtherOptionPrice == "---")
      {
      document.forms[1].OtherOptionPrice.value = ""; 
      }
   else
      {
      document.forms[1].hiddenTemp.value = document.forms[1].OtherOptionPrice.value;
      document.forms[1].OtherOptionPrice.value = "";
      }
}

function CheckOtherOptionPrice()  //           MOUSE OUT
{
   var temp = document.forms[1].OtherOptionPrice.value;
   if ((temp != "")&&(temp != "NaN"))
      {
      document.forms[1].OtherOptionPrice.value = doStrip(document.forms[1].OtherOptionPrice.value);
      document.forms[1].OtherOptionPrice.value = doCurrencyFormat(document.forms[1].OtherOptionPrice.value);
   
      temp = document.forms[1].OtherOptionPrice.value;
      document.forms[1].OtherOptionPrice.value = temp.substring(0,temp.length-3);
      document.forms[1].hiddenTemp.value = document.forms[1].OtherOptionPrice.value;
      }
   else
      {
      if ((document.forms[1].hiddenTemp.value == "")||(document.forms[1].hiddenTemp.value == "NaN"))
         document.forms[1].OtherOptionPrice.value = "---";
      else
         document.forms[1].OtherOptionPrice.value = document.forms[1].hiddenTemp.value;
      }
   if (document.forms[1].OtherOptionPrice.value=="NaN") 
      {
      document.forms[1].OtherOptionPrice.value="---";
      }
}

function CheckOtherOptionText()
{
   if (document.forms[1].OtherOptionText.value=="") 
      {
      document.forms[1].OtherOptionText.value="Enter New Option Here";
      document.forms[1].flag1.value="false";
      }
}

function AddtoAddOptionList()
{  
   // this sets the text and price for the option being added
   document.forms[1].AddOptionPrices.value   += doStrip(document.forms[1].OtherOptionPrice.value) + ",";
   document.forms[1].AddOptionList.value     += "(UserAdded) "+document.forms[1].OtherOptionText.value + ",";
   document.forms[1].CheckedAddOptions.value += "(UserAdded) "+document.forms[1].OtherOptionText.value + ",";
}

function noDups()
{  
   var dupCheck = "True";
   var OtherOptionText = document.forms[1].OtherOptionText.value;
   var counter = 0;
   var OptionListSize = document.forms[1].PassAddOptionSize.value;

   while (counter < OptionListSize)
      {
      var TokenName=("document.forms[1].OptionText"+counter+".value");
      TokenName=eval(TokenName);

      var TokenOptionName=("document.forms[1].AddOptionText"+counter+".value");
      TokenOptionName=eval(TokenOptionName);
      TokenOptionName=TokenOptionName.substring(12);
      
      if ((OtherOptionText==TokenName)||(OtherOptionText==TokenOptionName))
         {
         dupCheck = "False";
         counter = OptionListSize;
         }                                                            
      else counter++;
      }
   return dupCheck;
}

function BuildOtherOption()
{
   var check1 = document.forms[1].OtherOptionText.value+"";
   var check2 = document.forms[1].OtherOptionPrice.value+"";
   
   if (check2=="---") document.forms[1].OtherOptionPrice.value="0.0"

   if (check1!="Enter New Option Here") 
      {
      if (noDups()=="True") 
         {
         if (document.forms[1].OtherOptionText.value.indexOf(",")!=-1) commaStrip();
         AddtoAddOptionList();
         document.forms[1].submit();
         }
      else
         {
         alert("DUPLICATE ERROR: Please choose another option name, that name is already taken.");
         }
      
      }
}

function SubmitRecalculate()
{
   var NewOptionList = "";
   var NewAddOptionList = "";
   var grandTotal1 = 0.0;
   var grandTotal2 = 0.0;
   var grandTotal3 = 0.0;
   var grandTotal4 = 0.0;
   var tradeInValue = 0.0;
   var _optionValue = 0.0;
   var _trade_rough_value = document.forms[0].TradeRoughValue.value;
   var _hourAdj = document.forms[0].HourAdjust.value;
   var _conditionAdj1 = document.forms[0].ConditionAdjust.value;
   var _cashValue = document.forms[0].CashValue.value;
   var optionVSize = document.forms[0].OptionSize.value;
   var AddOptionSize = "";
   var aOption = new Array(optionVSize);
   
   var count = 0;
   while(count < optionVSize) 
      {
      var myOptionName=("document.forms[1].Option"+count+".checked");
      myOptionName=eval(myOptionName);
      if (myOptionName==true) 
         {
         var myOptionValue=("document.forms[1].OptionPrice"+count+".value");
         myOptionValue=eval(myOptionValue);
         
         grandTotal1 += parseFloat(myOptionValue);
         grandTotal2 += parseFloat(myOptionValue);
         grandTotal3 += parseFloat(myOptionValue);
         
         var myOptionText=("document.forms[1].OptionText"+count+".value");
         myOptionText=eval(myOptionText);
         NewOptionList += myOptionText+",";
         }
      count++;
      }

   count = 0;
   AddOptionSize = document.forms[1].PassAddOptionSize.value;
   
   while(count < AddOptionSize) 
      {
      var AddOptionName=("document.forms[1].AddOption"+count+".checked");
      AddOptionName=eval(AddOptionName);
      if (AddOptionName==true) 
         {
         var myAddOptionValue=("document.forms[1].AddOptionPrice"+count+".value");
         myAddOptionValue=eval(myAddOptionValue);
         
         grandTotal1 += parseFloat(myAddOptionValue);
         grandTotal2 += parseFloat(myAddOptionValue);
         grandTotal4 += parseFloat(myAddOptionValue);
         
         var myAddOptionText=("document.forms[1].AddOptionText"+count+".value");
         myAddOptionText=eval(myAddOptionText);

         if (myAddOptionText.indexOf("(UserAdded) ")==-1)
            NewAddOptionList += "(UserAdded) "+myAddOptionText+",";
         else
            NewAddOptionList += myAddOptionText+",";
         }
      count++;
      }

   document.forms[1].OptionList.value = NewOptionList;
   if (document.forms[1].flag2.value == "false") 
      { // first time in                                
      document.forms[1].flag2.value = "true";
      }
   else
      { // NOT first time in
      document.forms[1].CheckedAddOptions.value = NewAddOptionList;
      }

   if (document.forms[0].MyAction.value=="Buying") // this sets the proper price
      {
      document.forms[0].TotalCost1.value = parseFloat(document.forms[0].Base1.value) + parseFloat(grandTotal1);
      document.forms[0].TotalCost2.value = parseFloat(document.forms[0].Base2.value) + parseFloat(grandTotal2);
      document.forms[0].TotalCost1.value = doCurrencyFormat(document.forms[0].TotalCost1.value);
      document.forms[0].TotalCost2.value = doCurrencyFormat(document.forms[0].TotalCost2.value);
      document.forms[0].AppraisalValue1.value = "$"+document.forms[0].TotalCost1.value+"~"+"$"+document.forms[0].TotalCost2.value;
      document.forms[1].AppraisalValue2.value = "$"+document.forms[0].TotalCost1.value+"~"+"$"+document.forms[0].TotalCost2.value;
      }
   else // MyAction ="TradeIn"
      {
      document.forms[0].TotalCost3.value = 
          parseFloat(document.forms[0].Base3.value) 
        + parseFloat(grandTotal3);
      _optionValue = grandTotal3;
      _addOptionValue = grandTotal4;
      tradeInValue = 0
         + parseFloat(_trade_rough_value) 
         - parseFloat(_hourAdj)*0.8 
         + parseFloat(_optionValue) 
         + parseFloat(_conditionAdj1); 
        //FEB-06-2003 ZHL // - parseFloat(parseFloat(_cashValue) - parseFloat(_hourAdj) + parseFloat(_optionValue)) * 0.02;
      tradeInValue = round(parseFloat(tradeInValue) + parseFloat(_addOptionValue));
      tradeInValue = ""+tradeInValue;
      document.forms[0].TotalCost3.value = doCurrencyFormat(tradeInValue);

      document.forms[0].AppraisalValue1.value = "$"+document.forms[0].TotalCost3.value;
      document.forms[1].AppraisalValue2.value = "$"+document.forms[0].TotalCost3.value;
      }

} 

-->
