function Validate1(x)
 {
 var retValue=false;
 var invalidChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%^&*(){}|\':;?/<>,.@-+=[]~`_ ";
 var i;
  
for(i=0;i<invalidChars.length;i++)
 {
  if(x.indexOf(invalidChars.charAt(i))>-1)
  {
     retValue=true;
     break;
   }
 }
 
return retValue;
 }
function validate_frm()
{
	
if(document.form1.fname.value=="")
	{
		alert("Please Enter Your First Name. ");
		document.form1.fname.focus();
		document.form1.fname.select();
		return false;
	}

	if(!(document.form1.fname.value ==""))
	{
	if(!(isNaN(document.form1.fname.value)))
		{
		alert("Please Enter a Valid First Name");
		document.form1.fname.focus();
		document.form1.fname.select();
		return false;
		}
	}
	if (document.form1.address.value=="")
{
alert("Please Enter Your Address ");
document.form1.address.focus();
return false;
}
if(!(document.form1.address.value ==""))
	{
	if(!(isNaN(document.form1.address.value)))
		{
		alert("Please Enter a Valid Address");
		document.form1.address.focus();
		document.form1.address.select();
		return false;
		}
	}
	if(document.form1.lname.value=="")
	{
		alert(" Please Include Your Last Name. ");
		document.form1.lname.focus();
		document.form1.lname.select();
		return false;
	}
	if(!(document.form1.lname.value ==""))
	{
	if(!(isNaN(document.form1.lname.value)))
		{
		alert("Please Enter a Valid Last Name");
		document.form1.lname.focus();
		document.form1.lname.select();
		return false;
		}
	}
	if (document.form1.state.value=="not")
{
alert("Please Enter State ");
document.form1.state.focus();
return false;
}
		if(document.form1.email.value=="")
	{
		alert("Please Include Your E-mail Address. ");
		document.form1.email.focus();
		document.form1.email.select();
		return false;
	}
if(!(document.form1.email.value==""))
	{
	var evalue = document.form1.email.value;
      //var emailPat = /^(\".*\"|\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	   //var emailPat = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9_]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	   var emailPat=/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	  var matchArray = evalue.match(emailPat);

		if(!emailPat.test(evalue))
		{
			alert("Please Enter a Valid E-mail Address.");
			//alert(fv);
			document.form1.email.focus();
			document.form1.email.select();
  			return false;
	}
	}
	
	if (document.form1.city.value=="")
{
alert("Please Enter City ");
document.form1.city.focus();
return false;
}
if(!(document.form1.city.value ==""))
	{
	if(!(isNaN(document.form1.city.value)))
		{
		alert("Please Enter a Valid City");
		document.form1.city.focus();
		document.form1.city.select();
		return false;
		}
	}
	if( document.form1.h_phone.value == '' &&  document.form1.h_phone_1.value == '' && document.form1.h_phone_2.value == '' )
{
alert("Please Enter Your Phone Number");
document.form1.h_phone.select();
return false;
}
if ( Validate1(document.form1.h_phone.value) || document.form1.h_phone.value.length < 3)
		{
	alert("Please Enter Valid Phone Number");
        document.form1.h_phone.select();
		return false;
		}
	
if ( Validate1(document.form1.h_phone_1.value) || document.form1.h_phone_1.value.length < 3)
		{
	alert("Please Enter Valid Phone Number");
        document.form1.h_phone_1.select();
		return false;
		}
		
if ( Validate1(document.form1.h_phone_2.value) || document.form1.h_phone_2.value.length < 4)
		{
	alert("Please Enter Valid Phone Number");
        document.form1.h_phone_2.select();
		return false;
		}
if(document.form1.zip_code.value == '' )
{
	alert(" Please Include Your Zip Code. ");
    document.form1.zip_code.select();
	document.form1.zip_code.focus();
	return false;
	}
	if(isNaN(document.form1.zip_code.value))
	{
		alert(" Please Enter a Valid Zip Code.");
		document.form1.zip_code.select();
		document.form1.zip_code.focus();
		return false;
	}
var pattern2 = /^\d{5}$/ ;
if(!pattern2.test(document.form1.zip_code.value))
{
if(!pattern2.test(document.form1.zip_code.value) ==true)
{
alert(' Please Enter a Valid Zip Code.');
document.form1.zip_code.select();
document.form1.zip_code.focus();
return false;
}
}
if(!(document.form1.zip_code.value== ""))
	{
	if(document.form1.zip_code.value == "00000")
	{	{
	alert("Please Enter Valid Zip");
	document.form1.zip_code.focus();
	document.form1.zip_code.select();
	return false;
	}
	}
}
if (document.form1.PREF_CALLTIME.value=="not")
{
alert("Please Select Contact Time ");
document.form1.PREF_CALLTIME.focus();
return false;
}
if (document.form1.OCC_STAT.value=="not")
{
alert("Please Select Occupational Status ");
document.form1.OCC_STAT.focus();
return false;
}
if (document.form1.BKCY.value=="not")
{
alert("Please Select  Have You Ever Declared Bankruptcy ");
document.form1.BKCY.focus();
return false;
}
if (document.form1.INCOME.value=="not")
{
alert("Please Select Annual Income ");
document.form1.INCOME.focus();
return false;
}
if (document.form1.MIN_PAY.value=="not")
{
alert("Please Select  Monthly Debt Payments ");
document.form1.MIN_PAY.focus();
return false;
}
if (document.form1.loan.value=="not")
{
alert("Please Select Loan Type ");
document.form1.loan.focus();
return false;
}
if (document.form1.loan_amount.value=="not")
{
alert("Please Select Estimated Loan Amount ");
document.form1.loan_amount.focus();
return false;
}
if (document.form1.property_type.value=="not")
{
alert("Please Select Property Type ");
document.form1.property_type.focus();
return false;
}
if (document.form1.pro_value.value=="not")
{
alert("Please Select Property Value ");
document.form1.pro_value.focus();
return false;
}
var s=parseInt(document.getElementsByName("loan_amount")[0].value);
	var s1=parseInt(document.getElementsByName("pro_value")[0].value);
	//window.alert(s/s1);
	var n=(s/s1)*100;
	//window.alert(n);
	if(n>90)
	{
		window.alert("Loan amount should not exceed 90% of Property value");
		document.getElementsByName("loan_amount")[0].focus();
		return false;
	}
	
if (document.form1.property_use.value=="not")
{
alert("Please Select Property Use ");
document.form1.property_use.focus();
return false;
}

if (document.form1.credit_rate.value=="not")
{
alert("Please Select Estimated Credit Rating ");
document.form1.credit_rate.focus();
return false;
}
if(document.form1.PROP_AREA.value == '' )
{
	alert(" Please Include Your Property Area Code. ");
    document.form1.PROP_AREA.select();
	document.form1.PROP_AREA.focus();
	return false;
	}
	if(isNaN(document.form1.PROP_AREA.value))
	{
		alert(" Please Enter a Valid Property Area Code.");
		document.form1.PROP_AREA.select();
		document.form1.PROP_AREA.focus();
		return false;
	}
	if((!(document.form1.PROP_AREA.value.length==3 || document.form1.PROP_AREA.value.length==4 || document.form1.PROP_AREA.value.length==5)))
	{
		alert("Please Enter Valid Property Area Code");
	document.form1.PROP_AREA.focus();
	document.form1.PROP_AREA.select();
	return false;
	}
if(!(document.form1.PROP_AREA.value== ""))
	{
	if(document.form1.PROP_AREA.value == "000")
	{	{
	alert("Please Enter Valid Property Area Code");
	document.form1.PROP_AREA.focus();
	document.form1.PROP_AREA.select();
	return false;
	}
	}
}
if (document.form1.PROP_ST.value=="not")
{
alert("Please Select Property Location ");
document.form1.PROP_ST.focus();
return false;
}
if(document.getElementsByName("loan")[0].value=="Purchase")
	{
		if(document.getElementsByName("desint_ratetype")[0].value=="not")
		{
		   window.alert("Select Desired Interest Rate Type ");
           document.getElementsByName("desint_ratetype")[0].focus();
		   return false;
		}
        // window.alert(document.getElementsByName("SPEC_HOME")[0].checked);
          //window.alert(document.getElementsByName("SPEC_HOME")[1].checked);

		if(document.getElementsByName("SPEC_HOME")[0].checked)
		{
		   if(!(document.getElementsByName("PURCHASE_CONTRACT")[0].checked || document.getElementsByName("PURCHASE_CONTRACT")[1].checked))
			{
				//window.alert(document.getElementsByName("PURCHASE_CONTRACT")[0].checked);
				window.alert("Do you have a signed contract to buy your home?");
                document.getElementsByName("PURCHASE_CONTRACT")[0].focus();
				return false;
			}
		}
	}
 
 
  
 
 if(document.getElementsByName("loan")[0].value=="Refinance" || document.getElementsByName("loan")[0].value=="Home Equity")
	{
       if(document.getElementsByName("desired_loantype")[0].value=="not")
		{
		   window.alert("Select Desired Loan Type ");
           document.getElementsByName("desired_loantype")[0].focus();
		   return false;
		}
  	if(document.getElementById("refinancerate").value=="not")
		{
		   window.alert("Select Current Interest Rate Type ");
		   document.getElementById("refinancerate").focus();
		   return false;
		}
       
	   if(document.getElementsByName("add_cash_refi")[0].value=="not")
		{
		   window.alert("Select Additional Cash Needed ");
           document.getElementsByName("add_cash_refi")[0].focus();
		   return false;
		}
if(document.getElementsByName("MTG_ONE_INT")[0].value=="not")
		{
		   window.alert("Select First Mortgage Interest Rate ");
           document.getElementsByName("MTG_ONE_INT")[0].focus();
		   return false;
		}
		if(document.getElementsByName("BAL_ONE")[0].value=="not")
		{
		   window.alert("Select First Mortgage Balance ");
           document.getElementsByName("BAL_ONE")[0].focus();
		   return false;
		}
        if(document.getElementsByName("creditcard_debt_refi")[0].value=="not")
		{
		   window.alert("Select Credit Card Debt Amount ");
           document.getElementsByName("creditcard_debt_refi")[0].focus();
		   return  false;
		}

	   // window.alert(document.getElementById("refinancerate").value);
	
		
		
	}

    if( document.getElementsByName("loan")[0].value=="Debt Consolidation")
	{
		
		
		/*if(document.getElementsByName("payment_amount")[0].value=="not")
		{
			window.alert("Select Payment Amount ");
			document.getElementsByName("payment_amount")[0].focus();
			return;
		}*/
		if(document.getElementsByName("creditcard_debt")[0].value=="not")
		{
			window.alert("Enter Credit Card Debt ");
			document.getElementsByName("creditcard_debt")[0].focus();
			return false;
		}
		if(document.getElementsByName("payment_status")[0].value=="not")
		{
			window.alert("Select Payment Status ");
			document.getElementsByName("payment_status")[0].focus();
			return false;
		}
		
		//window.alert(document.getElementsByName("BAL_ONE")[0].value);
        if(document.getElementsByName("BAL_ONE_debt")[0].value=="not")
		{
		   window.alert("Select First Mortgage Balance ");
           document.getElementsByName("BAL_ONE_debt")[0].focus();
		   return false;
		}
		if(document.getElementsByName("MTG_ONE_INT_debt")[0].value=="not")
		{
		   window.alert("Select First Mortgage Interest Rate ");
           document.getElementsByName("MTG_ONE_INT_debt")[0].focus();
		   return false;
		}
	}


document.form1.btnSubmit.disabled="true";
document.form1.btnSubmit.value="Processing....";
document.getElementById('processing_txt').innerHTML = "<img src=http://www.mortgages-expo.com/images/processing.gif></img>&nbsp;&nbsp;<strong><FONT color='#FFFFFF' face='Arial' size=2>Your Application is being Processed ... Please Wait ...</font></b>";


document.form1.method="POST";
//document.form2.action="http://sys120:8080//nymortgage-naveen/form.php";
//document.form1.action="http://optionrefi.com/refinance-form.php";
document.form1.submit();
}


function PhoneMoveform1(nLength, sMoveFrom, sMoveTo) {
	if (sMoveTo != '') {
		if (document.form1[sMoveFrom].value.length >= nLength) {
			document.form1[sMoveTo].focus();
		}

	}
}
