// JavaScript Document
 var xmlHttp=null;
	 
	function check_num(n){
		ele = document.getElementById(n);
		n = ele.value;
		if (!isNaN(parseFloat(n)) && isFinite(n)){
			return n;
			
		}
		else{
			alert("Please Use Numeric Values for: " + ele.name);
			ele.value = 0;
			ele.focus();
			return 0;
		}
		
	} 
	function calPayments(){
	
		pPrice = check_num('pPrice');	
		pTerm = check_num('pTerm');	
		pDown = check_num('pDown');
		//pInterest = check_num('pInterest');	
		cStamps = check_num('cStamps');	
		cClose = check_num('cClose');		
		
		
		
		url="?action=calculate&pPrice="+ pPrice +"&pTerm=" + pTerm +"&pDown=" + pDown +"&pInterest=0&cStamps=" + cStamps +"&cClose=" + cClose ;
		
		//alert(url);
		ajaxCall(url, state_calPayments, "GET", "");
	}
	
	function state_calPayments(){
	 	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			response  = xmlHttp.responseXML;  
			
			i_downpay = (response.getElementsByTagName('i_downpay')[0].firstChild.data);	
			i_payment= (response.getElementsByTagName('i_payment')[0].firstChild.data);	
			i_loanamt= (response.getElementsByTagName('i_loanamt')[0].firstChild.data);	
			i_other= (response.getElementsByTagName('i_other')[0].firstChild.data);	
			i_other_total = (response.getElementsByTagName('i_other_total')[0].firstChild.data);	
			i_int = (response.getElementsByTagName('i_int')[0].firstChild.data);	
			i_balloon = (response.getElementsByTagName('i_balloon')[0].firstChild.data);	
			i_atype = (response.getElementsByTagName('i_atype')[0].firstChild.data);
			i_tax = (response.getElementsByTagName('i_tax')[0].firstChild.data);
			
			
			
			document.getElementById('sDown').innerHTML = i_downpay;
			document.getElementById('sLoanAmt').innerHTML = i_loanamt;
			document.getElementById('sPayment').innerHTML = i_payment;
			document.getElementById('sCosts').innerHTML = i_other;
			document.getElementById('sCostsTotal').innerHTML = i_other_total;	
			document.getElementById('sLoanInt').innerHTML = i_int;
			document.getElementById('i_aType').innerHTML = i_atype;
			document.getElementById('sBalloon').innerHTML = i_balloon;
			document.getElementById('sTax').innerHTML = i_tax;
	  }
	}
	
	function ajaxCall(actiondata, readyfunc, formAction, params){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return
		}        
		var url="calculate.php";
		url=url+actiondata;
		url=url+"&sid="+Math.random();
		
		xmlHttp.onreadystatechange=readyfunc; 
		xmlHttp.open(formAction,url,true);
		//xmlHttp.setRequestHeader("MessageType", "CALL")
		//xmlHttp.setRequestHeader("Content-type", "text/xml");
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
		
		
		xmlHttp.send(params);
	
	}
	
	
	
	function GetXmlHttpObject()
	{
	  var xmlHttp=null;
	  try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	  catch (e)
		{
		// Internet Explorer
		try
		  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		catch (e)
		  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		}
	  return xmlHttp;
	}
