// JavaScript Document

function enlargemap(){
	var mywindow	=	window.open("bigmapshow.php", "mywindow","status=0,scrollbars=no,toolbar=no,menubar=0,resizable=0,width=600,height=500");
	mywindow.moveTo(300,140);
}

function calculateint(){
	var frm	=	document.interestform;
	var loanamt	=	frm.mortamount.value;
	var noyears	=	frm.no_of_years.value;
	var interestrate =  frm.interest_rate.value;
	if(!validationcalculator(loanamt,noyears,interestrate)) { return false; }
	else{
		
		if(frm.payoption[0].checked==true){
			monthlyamt= loanamt * interestrate / 100 / 12 / (1 - Math.pow((1 + interestrate / 100 / 12), - noyears * 12));
		}
		else{
			monthlyamt= interestrate / 100 / 12 * loanamt;
		}
		frm.monthly_amount.value=formatNumber(monthlyamt,2,',','.','','','-','');
	}
}

function validationcalculator(lamt,noyears,intrate){
	document.getElementById('morttr').style.background="";
	document.getElementById('noofyearstr').style.background="";
	document.getElementById('intratetr').style.background="";

	if(lamt==""){
		alert("Please specify Loan Amount");
		document.getElementById('morttr').style.background="#FF3300";
		document.interestform.mortamount.focus();
		return false;
	}	
	if(noyears==""){
		alert("Please specify Number of years");
		document.getElementById('noofyearstr').style.background="#FF3300";
		document.interestform.no_of_years.focus();
		return false;
	}	
	if(intrate==""){
		alert("Please specify Interest Rate");
		document.getElementById('intratetr').style.background="#FF3300";
		document.interestform.interest_rate.focus();
		return false;
	}	
	return true;
}



function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) 
{
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec;
	if (z<0) z--; 
	for(var i = z; i < 0; i++) y.unshift('0');
	y.splice(z, 0, pnt); 
	while (z > 3) 
	{
		z-=3; 
		y.splice(z,0,thou);
	}
	var r = curr1+n1+y.join('')+n2+curr2;return r;
}
