<!--
function validateloan() {
	with (document.loan) {      
		if(!check_empty(price, "OopS!! You forget to enter Car Purchase Price")){
return false;}
		if(!digit(interest.value)) {
			alertMsg(interest, "You need to enter a numeric value");
			return false;
		}
	}
	totalloan();
}

function validatepremium() {
	with (document.insurance) {      
		if(!check_empty(insured, "Oops!!Amount Insured is blank")) {
			return false;
		}

		if(!digit(insured.value)) {
			alertMsg(insured, "You need to enter a numeric value");
			return false;
		}
	}
	totalpremium();
}

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 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 totalloan() {
	with (document.loan) {
		if (payperiod.value == 1) {
			cPeriod = 1;
		}
		if (payperiod.value == 2) {
			cPeriod = 2;
		}
		if (payperiod.value == 3) {
			cPeriod = 3;
		}
		if (payperiod.value == 4) {
			cPeriod = 4;
		}
		if (payperiod.value == 5) {
			cPeriod = 5;
		}
		if (payperiod.value == 6) {
			cPeriod = 6;
		}
		if (payperiod.value == 7) {
			cPeriod = 7;
		}
		if (payperiod.value == 8) {
			cPeriod = 8;
		}
		if (payperiod.value == 9) {
			cPeriod = 9;
		}
		cPayment = eval(price.value - downpayment.value);
		cIntPayment = eval((interest.value / 100) * cPeriod);
		cTopValue = eval((cPayment * cIntPayment) + cPayment);
		cBottomValue = eval(12 * cPeriod);
		cTotal = eval(cTopValue / cBottomValue);
		payment.value = calcRound(cTotal);
	Totinterest.value=calcRound(cTopValue-cPayment);	

}
	return true;
}

function totalpremium() {
	with (document.insurance) {
		if (cc.value == 1) {
			cCC = 225.20;
		}
		if (cc.value == 2) {
			cCC = 251.50;
		}
		if (cc.value == 3) {
			cCC = 277.90;
		}
		if (cc.value == 4) {
			cCC = 304.20;
		}
		if (cc.value == 5) {
			cCC = 330.50;
		}
		cPremium = eval((cCC + (insured.value - 1000) / 1000 * 26));
		if (ncd.value != 0) {
			cNCD = eval((cPremium * (ncd.value / 100)));
			cTotal = eval(cPremium - cNCD + 10);
		}
		else {
			cTotal = eval(cPremium + 10);
		}
		premium.value = calcRound(cTotal);
	}
	return true;
}
//-->