function checknum(as){
	var dd = as.value;	
	if(isNaN(dd)){
		dd = dd.substring(0,(dd.length-1));
		as.value = dd;
	}		
}
function loan()
{
	try{
		var a = document.getElementById("loanAmount").value;
		var b = document.getElementById("interestRate").value;
		var c = document.getElementById("loanDuration").value;
		var n = c * 12;
		var r = b/(12*100);
		var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
		var prin = Math.round(p*100)/100;
		document.getElementById("emiPerMonth").value = prin;
	}
	catch(err){
		document.emiPerMonth.value = "Please provide correct values."
	}
}

function getLoanEligibility()
{
	if(CheckValues('frmLoanEligible')){
	var interest=document.getElementById("ROI").value;
	var tenure=document.getElementById("Term").value;
	var income=0;
	var Aincome = 0;	
	var otheremi = 0;
	
	if(window.document.frmLoanEligible.ANEmployment[0].checked)
	{
		Aincome = document.getElementById("AIncome").value;
		
		AObligation = document.getElementById("AObligation").value;
		if(AObligation=='' || AObligation=='undefined'){
			AObligation=0;
		}
		//income=parseInt(Aincome);
		otheremi = parseInt(AObligation);
		//income=parseInt(Aincome) - parseInt(AObligation);
		
	
		var AAllowance = document.getElementById("AAllowance").value;
		if(AAllowance=='' || AAllowance=='undefined'){
		AAllowance=0;
		}
		if(AAllowance!='' && AAllowance!='undefined' && AAllowance!='0' ){
			AAllowance=parseInt(AAllowance);
		}			
		
		var AOverTime = document.getElementById("AOverTime").value;
		if(AOverTime=='' || AOverTime=='undefined'){
		AOverTime=0;
		}
		if(AOverTime!='' && AOverTime!='undefined' && AOverTime!='0'){
			AOverTime=parseInt(AOverTime);
		}
		
		var AIncentives = document.getElementById("AIncentives").value;
		if(AIncentives=='' || AIncentives=='undefined'){
		AIncentives=0;
		}		
		if(AIncentives!='' && AIncentives!='undefined' && AIncentives!='0'){
			AIncentives=parseInt(AIncentives);
		}

		income=parseInt(Aincome)+parseInt(AAllowance)+parseInt(AOverTime)+parseInt(AIncentives);
	
		
	}else{
		Aincome = document.getElementById("ANetProfit").value;
		
		var AObligation = document.getElementById("AObligation").value;
		if(AObligation=='' || AObligation=='undefined'){
			AObligation=0;
		}
		//income=parseInt(Aincome);
			otheremi = parseInt(AObligation);
		//income=parseInt(Aincome) - parseInt(AObligation);
		
	}
	
	if(window.document.frmLoanEligible.CNEmployment[0].checked)
	{
		Cincome = document.getElementById("CIncome").value;
		
		var CObligation = document.getElementById("CObligation").value;
		if(CObligation=='' || CObligation=='undefined'){
			CObligation=0;
		}
		income+=parseInt(Cincome);
			otheremi+=parseInt(CObligation);
		//income+=parseInt(Cincome) - parseInt(CObligation);
		
		var CAllowance = document.getElementById("CAllowance").value;
		if(CAllowance=='' || CAllowance=='undefined'){
		CAllowance=0;
		}
		if(CAllowance!='' && CAllowance!='undefined' && CAllowance!='0' ){
			CAllowance=parseInt(CAllowance);
		}			
		var COverTime = document.getElementById("COverTime").value;
		if(COverTime=='' || COverTime=='undefined'){
		COverTime=0;
		}
		if(COverTime!='' && COverTime!='undefined' && COverTime!='0'){
			COverTime=parseInt(COverTime);
		}
		var CIncentives = document.getElementById("CIncentives").value;
		if(CIncentives=='' || CIncentives=='undefined'){
		CIncentives=0;
		}
		if(CIncentives!='' && CIncentives!='undefined' && CIncentives!='0'){
			CIncentives=parseInt(CIncentives);
		}
		income+=parseInt(Cincome)+parseInt(CAllowance)+parseInt(COverTime)+parseInt(CIncentives);
		
		
	}else if(window.document.frmLoanEligible.CNEmployment[1].checked){
		Cincome = document.getElementById("CNetProfit").value;
		
		var CObligation = document.getElementById("CObligation").value;
		if(CObligation=='' || CObligation=='undefined'){
			CObligation=0;
		}
		income+=parseInt(Cincome);
			otheremi+=parseInt(CObligation);
		//income+=parseInt(Cincome) - parseInt(CObligation);
	}
	otheremi=otheremi;
	income = parseInt(income) - parseInt(otheremi);
	var incl=0;
	if(income <= 9999)
		{
			incl = parseInt(income)*(parseInt(35)/parseInt(100));	
		}
	if(income <= 14999 && income >= 10000)
		{
			incl = parseInt(income)*(parseInt(40)/parseInt(100));				
		}	
	if(income <= 19999 && income >= 15000)
		{
			incl = parseInt(income)*(parseInt(50)/parseInt(100));	
			//alert(incl);			
		}	
		if(income >= 20000)
		{
			incl = parseInt(income)*(parseInt(50)/parseInt(100));				
		}

	
	var lprin =0;	
	try{
		var la = parseInt(100000);
		var lb = interest;
		var lc = tenure;
		var ln = lc * 12;
		var lr = lb/(12*100);
		var lp = (la * lr *Math.pow((1+lr),ln))/(Math.pow((1+lr),ln)-1);
		lprin = Math.round(lp*100)/100;
		//alert("lprin  "+lprin);
	}
	catch(err){
		document.emiPerMonth.value = "Please provide correct values."
	}


	// var interc=parseInt(interest)*parseInt(100);
	// alert(interc);
	// var loanEligL=Math.round((parseInt(incl)/parseInt(interc))*100)/100;
	// var loanElig=parseInt((parseInt(incl)/parseInt(interc))*parseInt(100000));
	var loanEligL=Math.round((parseInt(incl)/parseInt(lprin))*100)/100;
	//alert("loanEligL  "+loanEligL);
	var loanElig=parseInt((parseInt(incl)/parseInt(lprin))*100000);
	//alert("loanElig  "+loanElig);
	

	

	var prin =0;
	try{
		var a = parseInt(loanElig);
		var b = interest;
		var c = tenure;
		var n = c * 12;
		var r = b/(12*100);
		var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
		prin = Math.round(p*100)/100;
		document.getElementById("EMI").value = "Rs." + prin;
	}
	catch(err){
		document.emiPerMonth.value = "Please provide correct values."
	}
	

	

	
	/*
	var calcloan =0;
	var calcloan1 =0;
	var calcloan2 =0;
	var eligibleLoan =0;
	
	calcloan=income;
	calcloan1=parseInt(prin)*parseInt(tenure);
	calcloan2=(parseFloat(calcloan)/parseFloat(calcloan1));
	eligibleLoan=Math.round(calcloan2*100)/100;
	*/
	
	document.getElementById("LoanAmount").value=loanEligL;
	document.getElementById("FinalROI").value=interest;
	}
}

var emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
var alphaExp = /^[a-zA-Z]+$/;

function fnValidateForm()
{

 if(fnCheckvalidate("name")||
	 document.getElementById("name").value=="Name" ||
	 !alphaExp.test(document.getElementById("name").value))
 	{
		alert("please enter valid name"); 
		document.getElementById("name").focus();
		return;
     }
 else if(fnCheckvalidate("email") || !emailpat.test(document.getElementById("email").value))
	{
	 alert("please enter valid E-mail"); 
	 document.getElementById("email").focus();
	 return;
	 }
 else if(fnCheckvalidate("country"))
 	{
		alert("please Select Country"); 
		document.getElementById("country").focus();
		return;
     }
 else if(fnCheckvalidate("project"))
 	{
		alert("please Select Project"); 
		document.getElementById("project").focus();
		return;
     }
 else if(fnCheckvalidate("comments"))
 	{
		alert("please enter comments "); 
		document.getElementById("project").focus();
		return;
     }
 else if(fnCheckvalidate("phone") || !phoneRe.test(document.getElementById("phone").value))
 	{
	 alert("please enter valid phone number");
	 document.getElementById("no").focus();
	 return;
	 } 
 else document.forms[0].submit();
} 

function fnCheckvalidate(srcid)
{
 if(document.getElementById(srcid).value.replace(/[\s]+$/g,"")==null ||
	 document.getElementById(srcid).value.replace(/[\s]+$/g,"").length==0) 
 return true;
 else return false;
}
