// JavaScript Document
function validate()
{
	var vami,vcmi,votl,votd,vintr,vmtor;
	var vtotin,vemi,vmaxloan;
	if(!document.forms[1].ami.value)
	{
		alert("Please enter Applicants gross monthy income");
		document.forms[1].ami.focus();
		return false;           
	}

	if(!document.forms[1].cmi.value)
		document.forms[1].cmi.value=0;
	
	if(!document.forms[1].otl.value)
		document.forms[1].otl.value=0;
	
	if(!document.forms[1].otd.value)
		document.forms[1].otd.value=0;
	
	if(!document.forms[1].intr.value) {
		alert("Please enter Interest Rate(in %)");
		document.forms[1].intr.focus();
		return false;           
	}
	if(document.forms[1].intr.length>3)
	{
		alert("maximum charcaters allowed is 3 for intrest");
	}

	if(!document.forms[1].mtor.value) {
		alert("Please enter Months to Retire");
		document.forms[1].mtor.focus();
		return false;           
	}

	if(!slashchk(document.forms[1].ami.value)) {
		alert("Applicants Gross Salary contains invalid charactes. Please re-enter");
		document.forms[1].ami.focus();
		return false;           
	}
	
	if(!slashchk(document.forms[1].cmi.value)) {
		alert("Co-applicants Gross Salary contains invalid charactes. Please re-enter");
		document.forms[1].cmi.focus();
		return false;           
	}
	
	if(!slashchk(document.forms[1].otl.value)) {
		alert("Other Loan amount contains invalid charactes. Please re-enter");
		document.forms[1].otl.focus();
		return false;           
	}
	
	if(!slashchk(document.forms[1].otd.value)) {
		alert("Other Deductions Amount contains invalid charactes. Please re-enter");
		document.forms[1].otd.focus();
		return false;           
	}
	
	if(!slashchk(document.forms[1].intr.value)) {
		alert("Interest Rate contains invalid charactes. Please re-enter");
		document.forms[1].intr.focus();
		return false;           
	}

	if(!slashchk(document.forms[1].mtor.value)) {
		alert("Months to retire contains invalid charactes. Please re-enter");
		document.forms[1].mtor.focus();
		return false;           
	}

	vami=document.forms[1].ami.value;
	vcmi=document.forms[1].cmi.value;
	votl=document.forms[1].otl.value;
	votd=document.forms[1].otd.value;
	vintr=document.forms[1].intr.value;
	vmtor=document.forms[1].mtor.value;
	
	vtotin=(parseInt(vami)+parseInt(vcmi))-(parseInt(votl)+parseInt(votd));
	vemi=calcEmi(100000,document.forms[1].intr.value,document.forms[1].mtor.value);
	vmaxloan=(vtotin*(0.4)/(vemi));
	document.forms[1].emi.value=Math.ceil(vemi)+" Rs per Lakh";
	vmaxloan=vmaxloan*100;
	vmaxloan=Math.round(vmaxloan);
	vmaxloan=vmaxloan/100;
	document.forms[1].emitot.value=vmaxloan+" Lakhs";
	
	var totEmi	=	(((vmaxloan*100000))/100000)*((vemi));
	//var totEmi	=	totEmi*100000;
	document.forms[1].totemi.value=Math.round(totEmi)+" Rs";
	
}

function calcEmi(vAmt,vintr,vmtor) {
	var terms;
	var numAmt,denAmt;
	var emiv;
	terms=12;

	numAmt=vAmt*Math.pow((1+vintr/(terms*100)),vmtor);

	denAmt=100*terms*(Math.pow((1+vintr/(terms*100)),vmtor)-1)/vintr;

	emiv=12*(numAmt/(denAmt*12));
	
	emiv=Math.round(emiv);

	return emiv;
}


function slashchk(st) {
	var i;
	for(i=0;i<st.length;++i) {
		if(st.charAt(i)=="/") {
			return false;
		}
	}
	return true;
}
function clearAll() {
	document.forms[1].ami.value='';
	document.forms[1].cmi.value='';
	document.forms[1].otl.value='';
	document.forms[1].otd.value='';
	document.forms[1].intr.value='';
	document.forms[1].mtor.value='';
	document.forms[1].emi.value='';
	document.forms[1].emitot.value='';
	document.forms[1].totemi.value='';
	
}
function checkNumber(form)
{
	if(isNaN(form.ami.value))
	{
			alert("Please Enter numbers only");
			form.ami.value='';
	}
	if(isNaN(form.intr.value))
	{
			alert("Please Enter numbers only");
			form.intr.value='';
	}
	if(isNaN(form.mtor.value))
	{
			alert("Please Enter numbers only");
			form.mtor.value='';
	}
}


<!--EMI CALCULATOR------------->


function get_round(X) { return Math.round(X*100)/100 }
function showpay() {
 if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) ||
     (document.calc.months.value == null || document.calc.months.value.length == 0)
||
     (document.calc.rate.value == null || document.calc.rate.value.length == 0))
 { document.calc.pay.value = "Incomplete data";
document.calc.tot_amount.value = "Incomplete data";
document.calc.tot_interest.value = "Incomplete data";
document.calc.yearly_interest.value = "Incomplete data";
document.calc.interest_pa.value = "Incomplete data";
document.calc.interest_pm.value = "Incomplete data";
 }
 else
 {
 var princ = document.calc.loan.value;
 var term  = document.calc.months.value;
 var intr   = document.calc.rate.value / 1200;
 var yrs   = document.calc.months.value / 12;
 
 document.calc.pay.value = get_round(princ * intr / (1 - (Math.pow(1/(1 + intr), term))));
 if(term<=12){
	document.calc.annual_pay.value =get_round(document.calc.pay.value * term);
 }
 else
 	document.calc.annual_pay.value =get_round(document.calc.pay.value * 12);
 
 document.calc.tot_amount.value = get_round(document.calc.pay.value * term);
 document.calc.tot_interest.value = get_round(document.calc.tot_amount.value - princ);
 document.calc.yearly_interest.value = get_round(document.calc.tot_interest.value / yrs);
 document.calc.interest_pa.value = get_round(document.calc.yearly_interest.value / princ * 100);
 document.calc.interest_pm.value = get_round((document.calc.yearly_interest.value / princ * 100)/12);
 }
}

function clearForm()
{
	//alert("dsdsd");
	//clearing the form data
	
	document.calc.loan.value='';
	document.calc.rate.value='';
	document.calc.months.value='';
	document.calc.byear.value='';
	document.calc.bmonth.value='';
	document.calc.annual_pay.value='';
	document.calc.pay.value='';
	document.calc.yearly_interest.value='';
	document.calc.tot_interest.value='';
	document.calc.tot_amount.value='';

	
}




