// JavaScript Document

function lfnval()
	{
		Amt = parseFloat(document.f1.loanAmt.value);
		
			if(document.f1.Roi.value>100){
							alert("Rate of interest cannot be greater than 100%");
							document.f1.Roi.focus();
							document.f1.Roi.select();		
							return;
			}
			
			if(document.f1.Roi.value == '')
			{
				alert("Enter Rate of interest");
				document.f1.Roi.focus();
				document.f1.Roi.select();		
				return ;
			}
			
			if(document.f1.Roi.value <= 0){
				alert("Rate of interest cannot be Zero");
				document.f1.Roi.focus();
				document.f1.Roi.select();		
				return ;
			}
			rateValue = document.f1.Roi.value
			rateValue1 =  (rateValue.substr(rateValue.lastIndexOf(".")+1,rateValue.length))
			if( rateValue1.length > 2 ){
				alert("Rate of interest with more than 2 number after decimal are not allowed");
				document.f1.Roi.focus();
				document.f1.Roi.select();		
				return ;
			}
			
			if(document.f1.loanTerm.selectedIndex == 0)
			{
				
				alert("please enter Loan Term")
				document.f1.loanTerm.focus();
				return
			}
			
			if (document.f1.loanAmt.value != "" ) 
			{
				if (isNaN(document.f1.loanAmt.value)) {
					document.f1.loanAmt.value = "";
					document.f1.loanAmt.focus();
					alert("Please enter number")
					return 
				}	
			}
			else {
				alert("please enter Loan Amount required")
				document.f1.loanAmt.focus();
				return
			}
			
	AROI()

}

 
var pflag = true;
function resultHid(){
	modeVal='Cal';
	if(modeVal=="Cal"){
	document.f1.result.value="";
	}
}

function allowOnlyPrice(val)
{
	if (val == "")
	{
		pflag = true
	}
	if((event.keyCode < 48 || event.keyCode > 57) && ((event.keyCode != 46)||!(pflag))){
		event.returnValue = false;
	}
	if ((event.keyCode == 46))
	{
		pflag = false
	}
	
}


function AROI() 
{
	var Lmonth=document.f1.loanTerm.value
	var Lrate=document.f1.Roi.value
	var LAmt=document.f1.loanAmt.value
	
	if("MO"=="AN")
	{
		Term = ((Lmonth)*12);

		var n=(Lmonth);
		var frm=document.f1;
		var finalk=((Lrate)/100);

		var finaln
		var x;
		var finaln=(Lmonth)

		var x;
		var FK=eval(finalk)+eval(1);
		var x1=Math.pow(FK,finaln);

		x=(x1-1)/(finalk*x1);
		x=x*10000;
		x=x/10000;

		var loanamt=(LAmt);
		Emi=loanamt/(12*x);
		Emi=Emi*10000;
		Emi=Emi/10000;
	}
	else {
		//k  = parseFloat(((Lrate)/12)/100);
		k  = (((Lrate)/12)/100);
		Term = ((Lmonth)*12)
		Amt=(LAmt)
		Emi=(Amt*k*Math.pow((1+k),Term))/(Math.pow((1+k),Term)-1)
		
		var EmiCal= Number(Emi)
			
		Number.prototype.toDec = function(n) 
			{
				return (Math.round(Math.pow(10,n) * this) / Math.pow(10,n));
	    	}	
		Emi=EmiCal.toDec(2)			
		var Emitxt=Emi+""
		var EmiLen=Emitxt.length
		var EmiIdx=Emitxt.indexOf(".")
		
		if((EmiLen-EmiIdx)=="2")
		{
			Emi=Emi.toDec(2)+"0"	
		}
		
	}
		if(!isNaN(Emi))
		{  
			document.f1.result.value=Emi
		}
	
}

function res() 
{
	AROI();
}

function clearFlds() 
{
	modeVal='Cal';
	if(modeVal=="Cal")
	{
		document.f1.result.value="";
	}
	document.f1.loanAmt.value= "";
	document.f1.Roi.value = "" ;
	document.f1.loanTerm.selectedIndex = 0
	document.f1.RestCode[0].checked = false;
	document.f1.RestCode[1].checked = true;
}


function State() {
	document.f1.loanAmt.value= "";
	document.f1.loanTerm.value = "" ;
	document.f1.action="emical.asp"
	document.f1.method="POST";
	document.f1.submit();
}




