function linkAction ( strAction )
  {
   switch ( strAction.toLowerCase() )
     {
      case "print" :
        var docForm = document.frmEntry;
		var strParam = "vehMake=" + escape(docForm.txtVehMake.value) + "&vehModel=" + escape(docForm.txtVehModel.value) +
                       "&vehYear=" + escape(docForm.txtVehYear.value) + "&vehCC=" + escape(docForm.txtCC.value) +
					   "&vehPrice=" + escape(docForm.txtVehPrice.value) +
                       "&amtFin=" + escape(docForm.txtAmtFin.value) + "&yrTenor=" + escape(cboSingleValue(docForm.cboYrTenor)) +
                       "&intRate=" + escape(docForm.txtIntRate.value) + "&mthAmt=" + escape(docForm.txtMthAmt.value) +
                       "&settlement=" + escape(docForm.txtSettlement.value) + "&transFee=" + escape(cboSingleValue(docForm.cboTransFee)) +
                       "&roadtax=" + escape(docForm.txtRoadTax.value) + "&adminFee=" + escape(docForm.txtAdminFee.value) +
                       "&insuranceGross=" + escape(docForm.txtInsuranceGross.value) + "&insuranceNCD=" + escape(cboSingleValue(docForm.cboNCD)) +
                       "&insuranceNet=" + escape(docForm.txtInsuranceNet.value) + "&netSale=" + escape(docForm.txtNetSale.value);
        openWinCustom("./print.asp?"+strParam,680,600);
	    break;

      default : break;
     }
  }

function onChngAction ( docForm, strAction )
  {
   switch ( strAction.toLowerCase() )
     {
      case "linkvehprice" :
        if ( isDecimal(docForm.txtVehPrice.value) )
           {
            docForm.txtAmtFin.value   = docForm.hdnMaxLoan.value;
            docForm.txtVehPrice.value = numberFormat(docForm.txtVehPrice.value,2);
            getIntRateTenor ( docForm );
            docForm.cboYrTenor.selectedIndex = parseInt(docForm.hdnMaxTenor.value) - 2;
            docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2);
            docForm.txtMthAmt.value = calcInstallMth ( parseFloat(docForm.txtAmtFin.value), parseInt(cboSingleValue(docForm.cboYrTenor)), parseFloat(docForm.txtIntRate.value) );

            docForm.txtRoadTax.value  = numberFormat(docForm.hdnRoadTax.value,2);
            if ( parseInt(docForm.txtRoadTax.value) != 0 ) { docForm.hdnComplete.value = 1; }

            calcInsurance ( docForm );
            docForm.txtAdminFee.value = numberFormat ( getAdminFee ( parseFloat(docForm.txtAmtFin.value) ), 2 );
            if ( !isDecimal(docForm.txtSettlement.value) ) { docForm.txtSettlement.value = 0; }
            docForm.txtSettlement.value = numberFormat(docForm.txtSettlement.value,2);
            calcAll ( docForm );
           }
	    break;

      case "txtamtfin" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( !isOKFormIntegerNonZero(docForm.txtAmtFin,"Please enter valid finance amount") )
               { docForm.txtAmtFin.value = docForm.hdnMaxLoan.value; calcAll(docForm); docForm.txtAmtFin.focus(); return false; }
            else if ( parseInt(docForm.txtAmtFin.value) > parseInt(docForm.hdnMaxLoan.value) )
               {
                alert ( "Amount finance is more than maximum loan amount ("+docForm.hdnMaxLoan.value+")" );
                docForm.txtAmtFin.value = docForm.hdnMaxLoan.value; calcAll(docForm); docForm.txtAmtFin.focus(); return false;
               }
            else
               {
                if ( parseFloat(docForm.txtAdminFee.value) != 0 )
                   { docForm.txtAdminFee.value = numberFormat ( getAdminFee ( parseFloat(docForm.txtAmtFin.value) ), 2 ); }
                getIntRate ( docForm );  // recalculate min interest rate based on load maount and age of vehicle
                calcAll(docForm); return true;
               }
           }
        else
           { return true; }
	    break;

      case "cboyrtenor" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            // validate year tenor based on max tenor
            if ( parseInt(cboSingleValue(docForm.cboYrTenor)) > parseInt(docForm.hdnMaxTenor.value) )
               {
                alert ( "Tenor is more than maximum loan tenor ("+docForm.hdnMaxTenor.value+" years)" );
                docForm.cboYrTenor.selectedIndex = parseInt(docForm.hdnMaxTenor.value) - 2; calcAll(docForm); docForm.cboYrTenor.focus(); return false;
               }

            // added 2007 Mar 26, change of year tenor affect minimum interest rate
            var iVehAge = parseInt(iCurrYr) - parseInt(docForm.txtVehYear.value);
            docForm.hdnVehAge.value = iVehAge;

            // added 2007 Mar 27
			getLoanAmount ( docForm );

            if ( iVehAge <= 5 ) // year 2002 - 2007
               {
                if ( strVehCat == "V" )  // Private Window Vans
                   {
				    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 7 )
				       { docForm.hdnMinIntRate.value = 5.10; }
				    else
				       { docForm.hdnMinIntRate.value = 5.45; }
				   }
                else
                   {
				    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 7 )
				       {
				         docForm.hdnMinIntRate.value = 4.50;
				         //docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 80 / 100;
				         //docForm.txtAmtFin.value = docForm.hdnMaxLoan.value;
				       }
				    else
				       { docForm.hdnMinIntRate.value = 4.80; }
				   }
               }
            else if ( iVehAge <= 7 ) // year 2000 - 2001
               {
                if ( strVehCat == "V" )  // Private Window Vans
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 5 )
				       { docForm.hdnMinIntRate.value = 7.50; }
				   }
                else
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 7 )
				       { docForm.hdnMinIntRate.value = 5.25; }
				   }
               }
            else if ( iVehAge <= 9 ) // year 1998 - 1999
               {
                if ( strVehCat == "V" )  // Private Window Vans
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 5 )
				       { docForm.hdnMinIntRate.value = 7.50; }
				   }
                else
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 5 )
				       { docForm.hdnMinIntRate.value = 5.85; }
				   }
               }
            else //if ( iVehAge <= 12 ) // year 1995 - 1997
               {
                if ( strVehCat == "V" )  // Private Window Vans
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 5 )
				       { docForm.hdnMinIntRate.value = 7.50; }
				   }
                else
                   {
                    if ( parseInt(cboSingleValue(docForm.cboYrTenor)) <= 3 )
				       { docForm.hdnMinIntRate.value = 6.00; }
				   }
               }
            //alert( "Minimum Interest Rate:" + docForm.hdnMinIntRate.value);
            //alert( "Desired Interest Rate:" + docForm.txtIntRate.value);
            //if ( parseFloat(docForm.txtIntRate.value) < parseFloat(docForm.hdnMinIntRate.value) ) { docForm.txtIntRate.value = docForm.hdnMinIntRate.value; }
			docForm.txtIntRate.value = docForm.hdnMinIntRate.value;

            //9 years tenor and at 5.25% interest rate for vehicle 2000 to 2003 year make. 
            //If user change to 8 years, interest rate will remain at 5.25%.
            // It can later can be changed to 7 years at 5.0%.
            /*
            var iVehAge = parseInt(docForm.hdnVehAge.value);
            if ( iVehAge <= 4 )
               {
                if ( parseInt(cboSingleValue(docForm.cboYrTenor)) == 9 )
                   { docForm.hdnMinIntRate.value = 5.25; docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2); }
                else if ( parseInt(cboSingleValue(docForm.cboYrTenor)) == 8 )
                   { docForm.hdnMinIntRate.value = 5.25; docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2); }
                else if ( parseInt(cboSingleValue(docForm.cboYrTenor)) == 7 )
                   { docForm.hdnMinIntRate.value = 5; docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2); }
               }
            */
            calcAll(docForm); return true;
           }
        else
           { return true; }
	    break;

      case "txtintrate" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( !isOKFormDecimalNonZero(docForm.txtIntRate,2,"Please enter valid interest rate") )
               { docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2); calcAll(docForm); docForm.txtIntRate.focus(); return false; }
            else if ( parseFloat(docForm.txtIntRate.value) < parseFloat(docForm.hdnMinIntRate.value) )
               {
                //alert ( "Interest rate is less than minimum interest rate ("+numberFormat(docForm.hdnMinIntRate.value,2)+"%)" );
                alert ( "Rates below "+numberFormat(docForm.hdnMinIntRate.value,2)+"% are negotiable" );
                docForm.txtIntRate.value = numberFormat(docForm.hdnMinIntRate.value,2); calcAll(docForm); docForm.txtIntRate.focus(); return false;
               }
            else { calcAll(docForm); return true; }
           }
        else
           { return true; }
	    break;

      case "txtsettlement" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( !isOKFormDecimal(docForm.txtSettlement,2,"Please enter valid settlement") )
               { docForm.txtSettlement.value = "0.00"; calcAll(docForm); docForm.txtSettlement.focus(); return false; }
            else { calcAll(docForm); return true; }
           }
        else
           { return true; }
	    break;

      case "cbotransfee" :
        if ( isDecimal(docForm.txtVehPrice.value) ) { calcAll(docForm); }
        //if ( docForm.hdnComplete.value == "1" ) { calcAll(docForm); }
	    break;

      case "txtroadtax" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( parseFloat(docForm.hdnRoadTax.value) != 0 )
               {
                if ( !isOKFormDecimal(docForm.txtRoadTax,2,"Please enter valid Road Tax") )
                   { docForm.txtRoadTax.value = numberFormat(docForm.hdnRoadTax.value,2); calcAll(docForm); docForm.txtRoadTax.focus(); return false; }
                /* else if ( parseFloat(docForm.txtRoadTax.value) != parseFloat(docForm.hdnRoadTax.value) && parseFloat(docForm.txtRoadTax.value) != 0 )
                   {
                    alert ( "You can only enter 0.00 or " + numberFormat(docForm.hdnRoadTax.value,2) + " for Road Tax" );
                    docForm.txtRoadTax.value = numberFormat(docForm.hdnRoadTax.value,2); calcAll(docForm); docForm.txtRoadTax.focus(); return false;
                   } */
                else { calcAll(docForm); return true; }
               }
            else
               {
                if ( !isOKFormDecimal(docForm.txtRoadTax,2,"Please enter valid Road Tax") )
                   { docForm.txtRoadTax.value = numberFormat(docForm.hdnRoadTax.value,2); calcAll(docForm); docForm.txtRoadTax.focus(); return false; }
                else { calcAll(docForm); return true; }
               }
           }
        else
           { return true; }
	    break;

      case "txtinsurancegross" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( !isOKFormDecimal(docForm.txtInsuranceGross,2,"Please enter valid Gross Insurance amount !") )
               { docForm.txtInsuranceGross.value = docForm.hdnInsuranceGross.value; onChngAction(docForm,"cboNCD"); docForm.txtInsuranceGross.focus(); return false; }
            else if ( parseFloat(docForm.txtInsuranceGross.value) != parseFloat(docForm.hdnInsuranceGross.value) && parseFloat(docForm.txtInsuranceGross.value) != 0 )
               {
                alert ( "You can only enter 0.00 or " + numberFormat(docForm.hdnInsuranceGross.value,2) + " for Gross Insurance" );
                docForm.txtInsuranceGross.value = docForm.hdnInsuranceGross.value; onChngAction(docForm,"cboNCD"); docForm.txtInsuranceGross.focus(); return false;
               }
            else { onChngAction(docForm,"cboNCD"); return true; }
           }
        else
           { return true; }
	    break;

      case "cboncd" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            if ( parseFloat(docForm.txtInsuranceGross.value) == 0 ) { docForm.cboNCD.selectedIndex = 0; docForm.txtInsuranceNet.value = "0.00"; calcAll(docForm); return; }
            var iGross = parseFloat ( docForm.txtInsuranceGross.value );
            var iNCD   = parseInt ( cboSingleValue(docForm.cboNCD) );
            var iNet   = iGross - ( iGross * iNCD / 100 );
            docForm.txtInsuranceNet.value = numberFormat(iNet,2);
            calcAll ( docForm );
           }
	    break;

      case "txtadminfee" :
        if ( isDecimal(docForm.txtVehPrice.value) )  //docForm.hdnComplete.value == "1"
           {
            var iAdminFee = getAdminFee ( parseFloat(docForm.txtAmtFin.value) );
            if ( !isOKFormDecimal(docForm.txtAdminFee,2,"Please enter valid Handling Charges !") )
               {
                docForm.txtAdminFee.value = numberFormat ( iAdminFee, 2 );
			    calcAll(docForm); docForm.txtAdminFee.focus(); return false;
               }
            else if ( parseFloat(docForm.txtAdminFee.value) != iAdminFee && parseFloat(docForm.txtAdminFee.value) != 0 )
               {
                alert ( "You can only enter 0.00 or "+numberFormat(iAdminFee,2)+" for Handling Charges !" );
                docForm.txtAdminFee.value = numberFormat ( iAdminFee, 2 );
                calcAll(docForm); docForm.txtAdminFee.focus(); return false;
               }
            else { calcAll(docForm); return true; }
           }
        else
           { return true; }
	    break;

      default : break;
     }
  }


function formAction ( docForm, strAction )
  {
   switch ( strAction.toLowerCase() )
     {
      case "sbmdone" :
        if ( chkVehForm(docForm) )
           {
            if ( docForm.txtCC.value != docForm.hdnCCOld.value )
                { docForm.hdnDone.value = "1"; return true; }
            else
               { onChngAction(docForm,"linkVehPrice"); return false; }
		   }
		else
           { return false; }
        break;

      case "rstcalc" :
        docForm.hdnMaxLoan.value        = "";   docForm.hdnRoadTax.value  = "";
        docForm.hdnFuel.value           = "";   docForm.hdnCC.value       = "";
        docForm.hdnMinIntRate.value     = "";   docForm.hdnMaxTenor.value = "";
        docForm.hdnInsuranceGross.value = "";   docForm.hdnComplete.value = "";
        docForm.hdnVehAge.value         = "";
        break;

      case "sbmreset" :
        formAction ( docForm, "rstCalc" )
        docForm.txtVehMake.value  = "";   docForm.cboVehMake.selectedIndex  = 0;
        docForm.txtVehModel.value = "";   docForm.cboVehModel.selectedIndex = 0;
        docForm.txtVehYear.value  = "";   docForm.cboVehYear.selectedIndex  = 0;
        docForm.txtCC.value       = 0;    docForm.hdnCCOld.value            = 0;
        docForm.txtVehPrice.value = 0;
        docForm.submit();
        break;

      default : break;
     }
  }


function chkForm ( docForm )
  {
   trimAllFields ( docForm );
   if ( !isOKFormText(docForm.txtVehMake,"Please select vehicle manufacturer !") ) { return false; }
   if ( !isOKFormText(docForm.txtVehModel,"Please select vehicle model !") ) { return false; }
   if ( !isOKFormText(docForm.txtVehYear,"Please select vehicle year !") ) { return false; }
   if ( !isOKFormIntegerNonZero(docForm.txtAmtFin,"Please enter valid amount finance") ) { return false; }
   if ( !isOKFormCombo(docForm.cboYrTenor,"Please select tenor") ) { return false; }
   if ( !isOKFormDecimalNonZero(docForm.txtIntRate,2,"Please enter valid interest rate") ) { return false; }

   if ( docForm.txtSettlement.value     == "" ) { docForm.txtSettlement.value     = 0; }
   if ( docForm.txtRoadTax.value        == "" ) { docForm.txtRoadTax.value        = 0; }
   if ( docForm.txtInsuranceGross.value == "" ) { docForm.txtInsuranceGross.value = 0; }
	  
   if ( !isOKFormDecimal(docForm.txtSettlement,2,"Please enter valid settlement",true) ) { return false; }
   if ( !isOKFormCombo(docForm.cboTransFee,"Please select transfer fee") ) { return false; }
   docForm.txtRoadTax.value        = numberFormat ( docForm.txtRoadTax.value, 2 );
   docForm.txtInsuranceGross.value = numberFormat ( docForm.txtInsuranceGross.value, 2 );
   calcAll ( docForm );
   return true;
  }

function chkVehForm ( docForm )
  {
   trimAllFields ( docForm );
   if ( !isOKFormDecNonZero(docForm.txtVehPrice,"Please make sure you complete all information required !!") ) { return false; }
   if ( !chkCC(docForm) ) { return false; }
   return true;
  }

function chkCC ( docForm )
  {
   trimAllFields ( docForm );
   //if ( !isOKFormRadio(docForm.rdoFuel,"Please select fuel type") ) { return false; }
   if ( !isOKFormIntegerNonZero(docForm.txtCC,"Please enter valid CC !") ) { return false; }
   //docForm.txtRoadTax.value = calRoadTax ( docForm.txtCC.value );
   return true;
  }


// executed when Vehicle Manufacturer (Make ) / Model / Year has been selected
// auto display min interest rate and max tenor based on age of vehicle
function getIntRateTenor ( docForm )
  {
   var iVehAge = parseInt(iCurrYr) - parseInt(docForm.txtVehYear.value);
   docForm.hdnVehAge.value = iVehAge;

   if ( iVehAge <= 5 ) // year 2002 - 2007
      {
       if ( strVehCat == "V" )  // Private Window Vans
          { docForm.hdnMinIntRate.value = 5.45; docForm.hdnMaxTenor.value = 9; }
       else
          { docForm.hdnMinIntRate.value = 4.80; docForm.hdnMaxTenor.value = 9; }
      }
   else if ( iVehAge <= 7 ) // year 2000 - 2001
      {
       if ( strVehCat == "V" )  // Private Window Vans
          { docForm.hdnMinIntRate.value = 7.50; docForm.hdnMaxTenor.value = 5; }
       else
          { docForm.hdnMinIntRate.value = 5.25; docForm.hdnMaxTenor.value = 7; }
      }
   else if ( iVehAge <= 9 ) // year 1998 - 1999
      {
       if ( strVehCat == "V" )  // Private Window Vans
          { docForm.hdnMinIntRate.value = 7.50; docForm.hdnMaxTenor.value = 5; }
       else
          { docForm.hdnMinIntRate.value = 5.85; docForm.hdnMaxTenor.value = 5; }
      }
   else //if ( iVehAge <= 12 )  // year 1995 - 1997
      {
       if ( strVehCat == "V" )  // Private Window Vans
          { docForm.hdnMinIntRate.value = 7.50; docForm.hdnMaxTenor.value = 5; }
       else
          { docForm.hdnMinIntRate.value = 6.00; docForm.hdnMaxTenor.value = 3; }
      }
   getLoanAmount ( docForm );
   getIntRate ( docForm );  // recalculate min interest rate based on loan amout & age of vehicle
  }


function getLoanAmount ( docForm )
  {
     var iVehAge = parseInt(iCurrYr) - parseInt(docForm.txtVehYear.value);
   docForm.hdnVehAge.value = iVehAge;

  	// added 11 Sep 2006, to override maximum load value that's being retrieve from database
   if ( iVehAge <= 5 ) // year 2002 - 2007
      {
	  if ( strVehCat == "V" )  // Private Window Vans
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 80 / 100;
           docForm.hdnMaxTenor.value = 9;
         }
      else
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 90 / 100;
           docForm.hdnMaxTenor.value = 9;
         }
	}
	else if ( iVehAge <= 7 ) // year 2000 - 2001
	{
	  if ( strVehCat == "V" )  // Private Window Vans
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 60 / 100;
           docForm.hdnMaxTenor.value = 5;
         }
      else
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 85 / 100;
           docForm.hdnMaxTenor.value = 7;
         }
	}
   else if ( iVehAge <= 9 ) // year 1998 - 1999
	{
	  if ( strVehCat == "V" )  // Private Window Vans
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 60 / 100;
           docForm.hdnMaxTenor.value = 5;
         }
      else
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 75 / 100;
           docForm.hdnMaxTenor.value = 5;
         }
	}
   else //if ( iVehAge <= 12 )  // year 1995 - 1997
    {
	  if ( strVehCat == "V" )  // Private Window Vans
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 60 / 100;
           docForm.hdnMaxTenor.value = 5;
         }
      else
         {
           docForm.hdnMaxLoan.value = parseFloat(docForm.txtVehPrice.value) * 50 / 100;
           docForm.hdnMaxTenor.value = 3;
         }
    }
	docForm.txtAmtFin.value = docForm.hdnMaxLoan.value;
  }


// get minimum interest rate as it's based on loan amount and age of vehicle
function getIntRate ( docForm )
  {
   var iVehAge = parseInt(iCurrYr) - parseInt(docForm.txtVehYear.value);
   docForm.hdnVehAge.value = iVehAge;
   var iAmtFin = parseFloat(docForm.txtAmtFin.value);

   // 2006 Jan 5 only for Sport Cars, removed on Apr 2006
   /*
   if ( strVehCat == "SC" || strVehCat == "UP" )  // Sport Cars / Unpopular Model
      {
       if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 5.45; }
       else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 5.35; }
       else { docForm.hdnMinIntRate.value = 5.25; }
       }
	*/

   // to restore min int rate
   docForm.txtIntRate.value = docForm.hdnMinIntRate.value;
   //if ( parseFloat(docForm.txtIntRate.value) < parseFloat(docForm.hdnMinIntRate.value) ) { docForm.txtIntRate.value = docForm.hdnMinIntRate.value; }
   return;

  // not used at this moment, set interest rate based on amt fin
   if ( iVehAge <= 5 ) // year 2000 - 2004
      {
       if ( strVehCat == "V" )  // Private Window Vans
          {
           if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 4.75; }
           else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 4.65; }
           else { docForm.hdnMinIntRate.value = 4.55; }
          }
       else if ( strVehCat == "SC" || strVehCat == "UP" )  // Sport Cars / Unpopular Model
          {
           if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 5.45; }
           else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 5.35; }
           else { docForm.hdnMinIntRate.value = 5.25; }
          }
       else
          {
           if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 4.25; }
           else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 3.95; }
           else { docForm.hdnMinIntRate.value = 3.75; }
          }
      }
   else if ( iVehAge <= 9 ) // year 1996 - 1999
       {
        if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 4.75; }
        else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 4.65; }
        else { docForm.hdnMinIntRate.value = 4.55; }
       }
   else //if ( iVehAge <= 12 )  // year 1993 - 1995
       {
        if ( iAmtFin <= 50000 ) { docForm.hdnMinIntRate.value = 7.5; }
        else if ( iAmtFin <= 100000 ) { docForm.hdnMinIntRate.value = 7.35; }
        else { docForm.hdnMinIntRate.value = 7.2; }
       }
   // to restore min int rate
   docForm.txtIntRate.value = docForm.hdnMinIntRate.value;
   //if ( parseFloat(docForm.txtIntRate.value) < parseFloat(docForm.hdnMinIntRate.value) ) { docForm.txtIntRate.value = docForm.hdnMinIntRate.value; }
  }


// figure to be used for insurance calculation based on CC
function getInsurancePremTariff ( iCC )
  {
   if ( iCC <= 1400 ) { return 225.2; }
   else if ( iCC <= 1650 ) { return 251.5; }
   else if ( iCC <= 2200 ) { return 277.9; }
   else if ( iCC <= 3050 ) { return 304.2; }
   else if ( iCC <= 4100 ) { return 330.5; }
   else if ( iCC <= 4250 ) { return 356.8; }
   else if ( iCC <= 4400 ) { return 383.20; }
   else { return 409.5; }
  }


// auto calc insurance based on CC and vehicle sales price
function calcInsurance ( docForm )
  {
   var iPremTariff = getInsurancePremTariff ( parseInt(docForm.hdnCC.value) );
   var iSalePrice  = parseFloat ( docForm.txtVehPrice.value );
   var iGross      = ( ( (iSalePrice-1000)/1000 ) * 26 ) + iPremTariff;
   var iGross      = ( ( (iSalePrice/1000) - 1 ) * 26 ) + iPremTariff;
   var iNCD        = parseInt ( cboSingleValue(docForm.cboNCD) );
   var iNet        = iGross - ( iGross * iNCD / 100 );
   docForm.txtInsuranceGross.value = numberFormat(iGross,2);
   docForm.hdnInsuranceGross.value = numberFormat(iGross,2);
   docForm.txtInsuranceNet.value   = numberFormat(iNet,2);
  }


function getAdminFee ( iAmtFin )
  {
   if ( parseInt(iAmtFin) <= 50000 ) { return 800; }
   else if ( parseInt(iAmtFin) <= 100000 ) { return 900; }
   else { return parseInt(iAmtFin)*1/100; }
  }


function calcNetSale ( docForm )
  {
   var iNet = parseFloat(docForm.txtAmtFin.value) - parseFloat(docForm.txtSettlement.value) - 
              parseFloat(cboSingleValue(docForm.cboTransFee)) - parseFloat(docForm.txtRoadTax.value) - 
              parseFloat(docForm.txtAdminFee.value) - parseFloat(docForm.txtInsuranceNet.value);
   docForm.txtNetSale.value = numberFormat ( iNet, 2 );
  }


function calcInstallMth ( iLoanAmt, iYrTenor, iIntRate )
  {
   var iTtlInt  = iLoanAmt * iYrTenor * iIntRate / 100;
   var iMthAmt  = ( iTtlInt + iLoanAmt ) / ( iYrTenor * 12 );
   return numberFormat ( iMthAmt, 2 );
  }

function calcAll ( docForm )
  {
   calcNetSale ( docForm );
   docForm.txtMthAmt.value = calcInstallMth ( parseFloat(docForm.txtAmtFin.value), parseInt(cboSingleValue(docForm.cboYrTenor)), parseFloat(docForm.txtIntRate.value) );
  }