		


function validate()
{
	var vami,vcmi,votl,votd,vintr,vmtor;
	var vtotin,vemi,vmaxloan;
	if(!document.forms[0].ami.value)
    {
   		alert("Please enter Applicants gross monthy income");
		document.forms[0].ami.focus();
        return false;           
	}
	if(!document.forms[0].cmi.value)
    	document.forms[0].cmi.value=0;
   	if(!document.forms[0].otl.value)
    	document.forms[0].otl.value=0;
	if(!document.forms[0].otd.value)
    	document.forms[0].otd.value=0;
	if(!document.forms[0].intr.value)
	{
     	alert("Please enter Interest Rate(in %)");
		document.forms[0].intr.focus();
        return false;           
	}
	if(!document.forms[0].mtor.value)
    {
   		alert("Please enter Months to Retire");
		document.forms[0].mtor.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].ami.value))
    {
   		alert("Applicants Gross Salary contains invalid charactes. Please re-enter");
		document.forms[0].ami.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].cmi.value))
    {
   		alert("Co-applicants Gross Salary contains invalid charactes. Please re-enter");
		document.forms[0].cmi.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].otl.value))
    {
   		alert("Other Loan amount contains invalid charactes. Please re-enter");
		document.forms[0].otl.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].otd.value))
    {
   		alert("Other Deductions Amount contains invalid charactes. Please re-enter");
		document.forms[0].otd.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].intr.value))
    {
   		alert("Interest Rate contains invalid charactes. Please re-enter");
		document.forms[0].intr.focus();
        return false;           
	}
	if(!slashchk(document.forms[0].mtor.value))
    {
   		alert("Months to retire contains invalid charactes. Please re-enter");
		document.forms[0].mtor.focus();
        return false;           
	}
	vami=document.forms[0].ami.value;
	vcmi=document.forms[0].cmi.value;
	votl=document.forms[0].otl.value;
	votd=document.forms[0].otd.value;
	vintr=document.forms[0].intr.value;
	vmtor=document.forms[0].mtor.value;
	
	vtotin=(parseInt(vami)+parseInt(vcmi))-(parseInt(votl)+parseInt(votd));
	vemi=calcEmi(100000,document.forms[0].intr.value,document.forms[0].mtor.value);
	vmaxloan=(vtotin*(0.4)/(vemi));
	document.forms[0].emi.value=Math.ceil(vemi)+" per Lakh";
	vmaxloan=vmaxloan*100;
	vmaxloan=Math.round(vmaxloan);
	vmaxloan=vmaxloan/100;
	document.forms[0].emitot.value=vmaxloan+" Lakhs";		
	
	
}

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;
}

