
function CalculateCost(){
	var strResponse = "";
	var xForm = document.forms[0];
	//Check to make sure each Dropdown has a vaild selection
	var Amount = xForm.cboAmount.options[xForm.cboAmount.selectedIndex].value
	var Days =  xForm.cboDays.options[xForm.cboDays.selectedIndex].value
	if(isValidSelection(xForm.cboDays) && isValidSelection(xForm.cboAmount)){
		strURL = "LoanCalculator.ashx?Days=" + Days + "&Amount=" + Amount;
		strResponse = MakeRemoteCall(strURL)
		xForm.txtTotalLoanCost.value = "$" + (parseInt(Amount) + parseFloat(strResponse*100)/100);
		xForm.txtTotalDue.value = "$" + parseFloat(strResponse*100)/100;
		
		}
	
}

function CalculatePayoutCost(){
var strResponse = "";
	var xForm = document.forms[0];
	//Check to make sure each Dropdown has a vaild selection
	var Amount = xForm.cboAmount.options[xForm.cboAmount.selectedIndex].value
	
	var NextPayDate = xForm.txtNextPayDate.value;
	var PayPeriod = xForm.cboPayPeriod.options[xForm.cboPayPeriod.selectedIndex].value;
	
	if(isValidDate(xForm.txtNextPayDate) && isValidSelection(xForm.cboAmount)){
		strURL = "LoanCalculatorPlus.ashx?txtNextPayDate=" + NextPayDate + "&txtLoanAmount=" + Amount+ "&cboPayPeriod=" +PayPeriod
		strResponse = MakeRemoteCall(strURL)
		
	//	xForm.txtTotalLoanCost.value = "$" + (parseInt(Amount) + parseFloat(strResponse*100)/100);
		//xForm.txtTotalLoanCost.value = strURL;
	//	xForm.txtTotalDue.value = "$" + parseFloat(strResponse*100)/100;
		
		getObject('AmortizationSchedule').innerHTML =strResponse;
		//alert(strResponse);
		//alert(getObject('AmortizationSchedule').innerHTML);
		}
}

function isValidDate(objForm){
	regex=/^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (regex.test(objForm.value))
		return true;
	else
		return false;
}

function getObject(objectId){
	if (document.all && !document.getElementById) {
		return document.all(objectId)
	} else {
		return document.getElementById(objectId)
	}
}
function isValidSelection(objForm){
	var blnReturn = false;
	//alert(objForm.options[objForm.selectedIndex].value);
	if(objForm.options[objForm.selectedIndex].value!="-1")
		blnReturn = true;
		
	return blnReturn;
}


function MakeRemoteCall(strURL){
	try {RemoteCall = new XMLHttpRequest();}
	catch (e){RemoteCall = new ActiveXObject("Microsoft.XMLHTTP");}
	RemoteCall.open("GET", strURL, false);
	RemoteCall.send("");
	if(RemoteCall.responseText!=""){
		return RemoteCall.responseText
	}else{
		return "";
	}
}