
	
	var frm = document.postback
	
	function checkCurrency(o, s){
		var c = o.value;
		if(c.length){
			if(!validCurrency(c)){
				alert("Please enter a valid currency for " + s + ".");
				o.focus();
				return false;
			}else{
				if (parseFloat(stripNonNumeric(c)) < 0) {
					alert("Please enter a valid positive currency for " + s + ".");
					o.focus();
					return false;
				} else {
					o.value = formatCurrency(c);
				}
			}
		}
	}
	function checkZip(o){
		var z = o.value;
		if(z.length){
			if(!validZip(z)){
				alert("Please enter a valid Zip Code.");
				o.focus();
				return false;
			}else{
				o.value = formatZip(z);
			}
		}
	}
	
	function checkEmail(ctl)
	{
	if(ctl.value == "" || emailCheck(ctl.value))
	{
		return true;
	}
	else
	{
			ctl.focus();
	}
	}
	
	function SendForm(action)
	{
		if(action=="submit" && ValidateForm()){
			document.postback.PurchasePrice.value = stripNonNumeric(document.postback.PurchasePrice.value);
			document.postback.LoanAmount.value = stripNonNumeric(document.postback.LoanAmount.value);
			document.postback.target = "_self";
			
			document.postback.eventId.value = "8";
			document.postback.submit();
		}else if(action=="print" && ValidateForm()){
			document.postback.PurchasePrice.value = stripNonNumeric(document.postback.PurchasePrice.value);
			document.postback.LoanAmount.value = stripNonNumeric(document.postback.LoanAmount.value);
			document.postback.eventId.value = "74";
			document.postback.target = "_new";
			document.postback.submit();			
		}else if(action=="back"){
			history.back();
		}else if(action=="update"){
			document.postback.eventId.value = "8";
			document.postback.submit();
		}
		
	}
	
	function ValidateForm()
	{
		var phone1, phone2, phone3, phoneExt, fullPhone;
		
		phone1 = document.postback.MbrPhoneAreaCode.value;
		phone2 = document.postback.MbrPhoneExchange.value;
		phone3 = document.postback.MbrPhoneNumber.value;
		phoneExt = document.postback.MbrPhoneExt.value;
		fullPhone = phone1 + phone2 + phone3 + "";
		
		if ((fullPhone.length > 0) && (isNaN(fullPhone))) {
			alert("Please enter a valid Contact Phone Number.");
			document.postback.MbrPhoneAreaCode.focus();
			return false;
		}
		if ((fullPhone.length > 0) && (fullPhone.length < 10)) {
			alert("Please enter a valid Contact Phone Number.");
			document.postback.MbrPhoneAreaCode.focus();
			return false;
		}
		if ((phoneExt.length > 0) && (isNaN(phoneExt))) {
			alert("Please enter a valid Contact Phone Number extension.");
			document.postback.MbrPhoneExt.focus();
			return false;
		}
		
		phone1 = document.postback.HPrefAgentPhoneAreaCode.value;
		phone2 = document.postback.HPrefAgentPhoneExchange.value;
		phone3 = document.postback.HPrefAgentPhoneNumber.value;
		fullPhone = phone1 + phone2 + phone3 + "";
		
		if ((fullPhone.length > 0) && (isNaN(fullPhone))) {
			alert("Please enter a valid Agent Phone Number.");
			document.postback.HPrefAgentPhoneAreaCode.focus();
			return false;
		}
		if ((fullPhone.length > 0) && (fullPhone.length < 10)) {
			alert("Please enter a valid Agent Phone Number.");
			document.postback.HPrefAgentPhoneAreaCode.focus();
			return false;
		}
		
		if(document.postback.MbrEmail.value == ""){
			alert("Email Address is a required field");
			document.postback.MbrEmail.focus();
			return false;
		}
		return true;
	}//ValidateForm()
	
	function checkLoanAmounts()
	{
		var value = parseFloat(stripNonNumeric(document.LoanApp.PurchasePrice_PropertyValue.value));
		var loanAmount = parseFloat(stripNonNumeric(document.LoanApp.DownPayment_LoanAmount.value));
		var balance = parseFloat(stripNonNumeric(document.LoanApp.MortgageBalance.value));
		var ltv = (loanAmount / value) * 100;
		
		if((value <= 0) || (value > 9999999.99))
		{
			alert("Please enter an estimated home value between 1 and 9,999,999.99.");
			document.LoanApp.PurchasePrice_PropertyValue.focus();
			return false;
		}
		
		if((loanAmount <= 0) || (loanAmount > 9999999.99))
		{
			alert("Please enter a loan amount between 1 and 9,999,999.99.");
			document.LoanApp.DownPayment_LoanAmount.focus();
			return false;
		}
		
		if((balance < 0) || (balance > 9999999.99))
		{
			alert("Please enter a mortgage balance between 0 and 9,999,999.99.");
			document.LoanApp.MortgageBalance.focus();
			return false;
		}
		
		if(ltv > 300)
		{
			alert("Your Loan to Value ratio is too high.\nPlease decrease your loan amount or increase your property value.");
			document.LoanApp.PurchasePrice_PropertyValue.focus();
			return false;
		}
		
		return true;
	}
	
	function isRequired(sElement)
	{
		if(sElement=="LoanPurpose")                 return true;
		if(sElement=="PurchasePrice_PropertyValue") return true;
		if(sElement=="DownPayment_LoanAmount")      return true;
		if(sElement=="pp_address")                  return true;
		if(sElement=="pp_city")                     return true;
		if(sElement=="pp_st_abbrev")                return true;
		if(sElement=="pp_zip")                      return true;
		if(sElement=="pp_property_type")            return true;
		if(sElement=="breo_prop_type" && document.LoanApp.LoanPurpose.value == 2)	return true;
		if(sElement=="MortgageBalance" && document.LoanApp.LoanPurpose.value == 2)  return true;
		if(sElement=="pp_occupancy")                return true;
		return false;
	}//isRequired()
	
	function getDisplay(sElement)
	{
		if(sElement=="LoanPurpose")                 return "Loan Purpose";
		if(sElement=="PurchasePrice_PropertyValue")
		{
			if(document.LoanApp.LoanPurpose.value == 1)
				return "Purchase Price";
			else
				return "Home Value";
		}
		 
		if(sElement=="DownPayment_LoanAmount")
		{
			if(document.LoanApp.LoanPurpose.value == 1)
				return "Down Payment";
			else
				return "Amount Refinanced";
		}
		if(sElement=="pp_address")                  return "Address";
		if(sElement=="pp_city")                     return "City";
		if(sElement=="pp_st_abbrev")                return "State";
		if(sElement=="pp_zip")                      return "Zip";
		if(sElement=="pp_property_type")            return "Property Type";
		if(sElement=="breo_prop_type")				return "Property Use";
		if(sElement=="MortgageBalance")				return "Mortgage Balance";
		if(sElement=="pp_occupancy")                return "Occupancy";
		return "";
	}//getDisplay()

function checkNewLoanAmount()
{
	var curLoanAmt = document.LoanApp.currentLoanAmount.value;
	var newLoanAmt = document.LoanApp.DownPayment_LoanAmount.value;
	var dCurAmt;
	var dNewAmt;
	var dDifferenc;
	
	if(newLoanAmt != "")
	{
		if(curLoanAmt == "")
		{
			document.LoanApp.updateLoanAmount.value = "Y";
		}
		else
		{
			dCurAmt     = Math.round(parseFloat(stripNonNumeric(curLoanAmt)));
			dNewAmt     = Math.round(parseFloat(stripNonNumeric(newLoanAmt)))
			dDifference = Math.abs(dNewAmt - dCurAmt);
			if(dDifference <= 100)
			{
				document.LoanApp.updateLoanAmount.value = "N";
			}
			else
			{
				document.LoanApp.updateLoanAmount.value = "Y";
			}
		}
	}
}


function checkDate(ctrl)
{
	var val = stripSpaces(ctrl.value);
	if(val != "")
	{
		var date = new Date();

		if(val.length )
		{
			if(validDate(val))
			{
				ctrl.value = formatDate(val);
			}
			else
			{
				alert("Please enter a valid date in the format mm/dd/yyyy.");
				ctrl.focus();
				return false;
			}
			if(getYear(ctrl.value) < 1753)
			{
				alert("Please enter a year greater than 1753.");
				ctrl.focus();
				return false;
			}
			
		}
		else
			return true;
	}
	else
		return true;
}