// JavaScript Document

<!-- 
function calcRound(num) {

   result=Math.floor(num)+"." ;

   n = result.length;

   var cents=100*(num-Math.floor(num))+0.5;

   result += Math.floor(cents/10);

   result += Math.floor(cents%10);

   return(result)

}

function alertMsg(field,msg) 
{
   alert(msg);
   field.focus();
   field.select();
} 

function validDigit(ch) {
    if ((ch != ".") && (ch != "0") && (ch != "1") && (ch != "2") && (ch != "3") && (ch != "4") &&
        (ch != "5") && (ch != "6") && (ch != "7") && (ch != "8") && (ch != "9"))
 {
        return false;
    }
    else {
        return true;
    }
} 

function digit(string) {
    var i;
    var chr;
    for (i = 0; i < string.length; i++) {
        chr = string.substring(i, i+1);
        if (!validDigit(chr)) {
            return false;
        }
    }
    return true;
} 

function empty(string) 
{
    if(string.length==0)
      {
       return true;
      }
    else
      {
       for(i=0;i< string.length;i++)
         { ch=string.substring(i,i+1);
           if (ch != " ") 
            {
              return false;
            }
         }
      return true;   
      }
} 
 

function check_empty(field,alert_msg) 
{
    if(empty(field.value)) 
      {
       alertMsg(field, alert_msg);
       return false; 
      }
    return true;
}

function validate() 
{
   with (document.pcmiquote)
   {      
		if(!check_empty(VSI, "Vehicle Sum Insured cannot be blank!"))
	      return false;

    	if(!digit(VSI.value))  
	      {
	       alertMsg(VSI, "Please enter only valid digit!");
	       return false;
		  }
  }
caltotal()
}

function capacity(ab)
{
//a for basic
//b for third party
	if (document.pcmiquote.CC.selectedIndex == 1)
		{
		 tariff1a = 225.20;
		 tariff1b = 72.00;
		 if (ab == "a")
			 return tariff1a;
		 else
			 return tariff1b;
		}
	if (document.pcmiquote.CC.selectedIndex == 2)
		{
 		 tariff2a = 251.50;
		 tariff2b = 81.00;
		 if (ab == "a")
			 return tariff2a;
		 else
			 return tariff2b;

		}
	if (document.pcmiquote.CC.selectedIndex == 3)

		{
		tariff3a = 277.90;
		tariff3b = 90.00;
		 if (ab == "a")
			 return tariff3a;
		 else
			 return tariff3b;

		}
	if (document.pcmiquote.CC.selectedIndex == 4)
		{
		tariff4a = 304.20;
		tariff4b = 99.00;
		 if (ab == "a")
			 return tariff4a;
		 else
			 return tariff4b;

		}
	if (document.pcmiquote.CC.selectedIndex == 5)
		{
		 tariff5a = 330.50;
		 tariff5b = 108.00;
		 if (ab == "a")
			 return tariff5a;
		 else
			 return tariff5b;

		}
	if (document.pcmiquote.CC.selectedIndex == 0)
		{
		alert("Please select a CC range")
		return false;
		}
}

function calbasic()
{
	checkcount()
 if ((document.pcmiquote.VSI.value != "0") && (document.pcmiquote.VSI.value != "") && 

(document.pcmiquote.CC.selectedIndex != "0"))
	{
	 BSI = capacity("a")
	 pBASIC = (((document.pcmiquote.VSI.value - 1000)/1000) * 26) + BSI
	 document.pcmiquote.BASIC.value = calcRound(pBASIC)
	 //return pBASIC
	
    var myindex=document.pcmiquote.cNCD.selectedIndex
    //alert(document.pcmiquote.cNCD.options[myindex].value)
	 pNCD = document.pcmiquote.cNCD.options[myindex].value * pBASIC
 	 document.pcmiquote.NCD.value = calcRound(pNCD)
	 //return pNCD
	 return true;
	}
 else 
	{
	 document.pcmiquote.BASIC.value = "0"
	 document.pcmiquote.NCD.value = "0"
	 return "0"
	}
}

function wsrcand(type)
{
  if (type == "ws")
	 {
	  if (document.pcmiquote.cWS.value != "0") 
		{
		  pWS = document.pcmiquote.cWS.value
		  pWS = pWS * 0.15
		  document.pcmiquote.WS.value = calcRound(pWS)
		}  
  else document.pcmiquote.WS.value = "0"
	 }
  if (type == "rc")
	 {
	  if (document.pcmiquote.cRC.value != "0") 
		{
		  pRC = document.pcmiquote.cRC.value
		  pRC = pRC * 0.15
		  document.pcmiquote.RC.value = calcRound(pRC)
		}  
  else document.pcmiquote.RC.value = "0"
	 }
  if (type == "and")
	 {
	  if (document.pcmiquote.cAND.value != "0") 
		{
		  pAND = document.pcmiquote.cAND.selectedIndex * 10
		  document.pcmiquote.AND.value = calcRound(pAND)
		}  
	  else document.pcmiquote.AND.value = "0"
	 }
//(document.pcmiquote.cRC.value != "0") (document.pcmiquote.cAND.value != "0")
}

function checkcount()
{
 with (document.pcmiquote)
 { 
	if (!cLLP.checked)
		{
		 LLP.value = "0";
		}

	if (cLLP.checked)
		{
		 var PSGindex=document.pcmiquote.PSG.selectedIndex
        //alert(document.pcmiquote.PSG.options[PSGindex].value)
		 var pPSG = document.pcmiquote.PSG.options[PSGindex].value

		 thirdpp = capacity('b');
		 if (thirdpp != 0)
			 { 
	 		  if (pPSG > 5)
			  	  pLLP = ((25 / 100) * thirdpp) + ((pPSG - 5) * 10)
		 	  else
			 	  pLLP = ((25 / 100) * thirdpp)
    	 LLP.value = calcRound(pLLP)
			 }
		 else 
			 LLP.value = "0"
		}

	if (!cLLAN.checked)
		{
		 LLAN.value = "0"
		}

	if (cLLAN.checked)
		{
		 LLAN.value = "7.50"
		}

	if (!cSRCC.checked)
		{
		 SRCC.value = "0"
		}

	if (cSRCC.checked)
		{
		 pSRCC = (0.3 / 100) * VSI.value 
		 SRCC.value = calcRound(pSRCC)
		}

	if (!cFLOOD.checked)
		{
		 FLOOD.value = "0"
		}

	if (cFLOOD.checked)
		{
		 pFLOOD = (0.5 / 100) * VSI.value
		 FLOOD.value = calcRound(pFLOOD)
		}


 }
 return true;
}

function caltotal()
{
 with (document.pcmiquote)
	{
	 var pBASIC = BASIC.value;
	 var pNCD = NCD.value;
	 var pLLP = LLP.value;
	 var pLLAN = LLAN.value;
	 var pSRCC = SRCC.value;
	 var pFLOOD = FLOOD.value;
	 var pWS = WS.value;
	 var pRC = RC.value;
	 var pAND = AND.value;
	 //alert(pAND)

	 var pGP = eval("pBASIC - pNCD");
		  pGP = eval(pGP) + eval(pLLP) + eval(pLLAN) + eval(pSRCC) + eval(pFLOOD) + eval

(pWS) + eval(pRC) + eval(pAND);
	 //pGP = eval("pGP + pLLP + pLLP + pLLAN + pSRCC + pFLOOD + pWS + pRC + pAND");
	 GP.value = calcRound(pGP);

	 var pTPP = eval("pGP + 10");
	 //TPP.value = Math.round(pTPP);
	 TPP.value = calcRound(pTPP);
	}
 return true;
}
//-->