// This script is to calculate the basic motor insurance premium quote only for individual private
// car owners on full comprehensive cover as per according to the PIAM Motor Tariff Table. 
// Some conditions apply.

	function motorQuotation (fm)
	{
	
	var ccValue, noclaimValue, thirdptyPremium, motorPremium, driveValue;
	var sum_insAmount = fm.sum_ins.value;
	var cc = fm.ccapacity.value;
	var windValue = fm.windscreen.value * 0.15;
	var audioValue = fm.audio.value * 0.15;
	
	if (fm.drivers.value <= 10)
	driveValue = fm.drivers.value * 10;
	else
	driveValue = 0;
	
	if (sum_insAmount == "")  {
		alert ("Please Enter Vehicle Sum Insured Amount");
		fm.sum_ins.focus();
		return false;
	}

	if (isNaN(sum_insAmount))	{
		alert("Please Enter A Numeric Value, e.g. 75000");
		fm.sum_ins.focus();
		return false;
	}

	if (cc == "") {
		alert ("Please Enter Vehicle Engine Capacity");
		fm.ccapacity.focus();
		return false;
	}

	if (fm.noclaim.value == ""){
		alert ("Please Enter No Claim Discount Value (if entitled)");
		fm.noclaim.focus();
		return false;
	}
			motorPremium = (sum_insAmount - 1000) * 0.026;
			
			ccValue = parseFloat(fm.ccapacity.options[fm.ccapacity.selectedIndex].value);
			thirdptyPremium = parseFloat(fm.ccapacity.options[fm.ccapacity.selectedIndex].name);

			motorPremium += ccValue;

			noclaimValue = motorPremium * fm.noclaim.options[fm.noclaim.selectedIndex].value;

			motorPremium -= noclaimValue;


		if (fm.llpassenger.checked)
				motorPremium += (thirdptyPremium * 0.25);
		if (fm.llpan.checked)
				motorPremium += 7.5;
		if (fm.srcc.checked)
				motorPremium += (sum_insAmount * 0.003);
		if (fm.flood.checked)
				motorPremium += (sum_insAmount * 0.005);
		if (fm.windscreen.value != "")
				motorPremium += windValue;
		if (fm.audio.value != "")
				motorPremium += audioValue;
		if (fm.drivers.value != "")
				motorPremium += driveValue;
		else motorPremium = motorPremium;

		motorPremium = motorPremium + 10;
		motorPremiumGross = motorPremium - 10;

		fm.showMotorPremium.value = numeric(Math.round(eval(motorPremium)* Math.pow(10,2))/100);
		fm.showGrossPremium.value = numeric(Math.round(eval(motorPremiumGross)* Math.pow(10,2))/100);
	}

	function numeric(anynum) {
   	//-- Returns passed number as string in $xxx,xxx.xx format.
   anynum=eval(anynum)
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}
	
	// Add comma to thousands.
   	if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   	}

   	// Add comma to millions.
   	if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   	}
   	retval = dStr + pStr 
   	//-- Put numbers in parentheses if negative.
   	if (anynum<0) {retval="("+retval+")"}
   	return ""+retval
   //return "$"+retval
	}
	
	function clearValue()
	{
		form_motor.totalPremium.value = 0;
	}

