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.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.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.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.state.value=="not")
{
alert("Please Enter State ");
document.form1.state.focus();
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.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.getElementsByName("h_phone")[0].value=="")
	{
		 window.alert("Enter Home Phone");
		 document.getElementsByName("h_phone")[0].focus();
	     return false;
	}
	if(isNaN(document.getElementsByName("h_phone")[0].value))
	{
		   document.getElementsByName("h_phone")[0].value="";
		 window.alert("Phone Number must be Numeric");
		 document.getElementsByName("h_phone")[0].focus();		
		document.getElementsByName("h_phone")[0].select();

	     return false;
	}
 	if(document.getElementsByName("h_phone")[0].value.length != 3)
   {
		 document.getElementsByName("h_phone")[0].value="";
     window.alert("Please Enter Valid Phone Number");
	document.getElementsByName("h_phone")[0].focus();
	
		document.getElementsByName("h_phone")[0].select();
	return false;
    }
	
   if(document.getElementsByName("h_phone_1")[0].value=="")
	{
		 window.alert("Enter Home Phone");
		 document.getElementsByName("h_phone_1")[0].focus();
			     return false;
	}
	if(isNaN(document.getElementsByName("h_phone_1")[0].value))
	{
		document.getElementsByName("h_phone_1")[0].value="";
		 window.alert("Phone Number must be Numeric");
		  document.getElementsByName("h_phone_1")[0].focus();
		   
		 document.getElementsByName("h_phone_1")[0].select();

	     return false;
	}
	if(document.getElementsByName("h_phone_1")[0].value.length != 3)
   {
     window.alert("Please Enter Valid Phone Number");
	document.getElementsByName("h_phone_1")[0].focus();
	document.getElementsByName("h_phone_1")[0].value="";
		 document.getElementsByName("h_phone_1")[0].select();
	return false;
    }
	if(document.getElementsByName("h_phone_2")[0].value=="")
	{
		 window.alert("Enter Home Phone");
		 document.getElementsByName("h_phone_2")[0].focus();
	     return false;
	}
	if(isNaN(document.getElementsByName("h_phone_2")[0].value))
	{
		 window.alert("Phone Number must be Numeric");
		 document.getElementsByName("h_phone_2")[0].focus();
		 document.getElementsByName("h_phone_2")[0].value="";
		 document.getElementsByName("h_phone_2")[0].select();

	     return false;
	}   
   if(document.getElementsByName("h_phone_2")[0].value.length != 4)
   {
     window.alert("Please Enter Valid Phone Number");
	document.getElementsByName("h_phone_2")[0].focus();
	document.getElementsByName("h_phone_2")[0].value="";
		 document.getElementsByName("h_phone_2")[0].select();
	return false;
    }
	
	//alert(document.getElementsByName("w_phone")[0].value);
     if(document.getElementsByName("w_phone")[0].value !="")
	   {
	   
	   	if(isNaN(document.getElementsByName("w_phone")[0].value))
	{
		 window.alert("Phone Number must be Numeric");
		 document.getElementsByName("w_phone")[0].focus();
		  document.getElementsByName("w_phone")[0].value="";
		 document.getElementsByName("w_phone")[0].select();

	     return false;
	}
	 if(document.getElementsByName("w_phone")[0].value.length != 3)
         {
        window.alert("Please Enter Valid Phone Number");
	    document.getElementsByName("w_phone")[0].focus();
		 document.getElementsByName("w_phone")[0].value="";
		 document.getElementsByName("w_phone")[0].select();

	     return false;
       }
      
	   if(isNaN(document.getElementsByName("w_phone_1")[0].value))
	{
		 window.alert("Phone Number must be Numeric");
		 document.getElementsByName("w_phone_1")[0].focus();
		  document.getElementsByName("w_phone_1")[0].value="";
		 document.getElementsByName("w_phone_1")[0].select();

	     return false;
	}
	 if(document.getElementsByName("w_phone_1")[0].value.length != 3)
      {
       window.alert("Please Enter Valid Phone Number");
	   document.getElementsByName("w_phone_1")[0].focus();
	   document.getElementsByName("w_phone_1")[0].value="";
		 document.getElementsByName("w_phone_1")[0].select();
	   return false;
       }
	   if(isNaN(document.getElementsByName("w_phone_2")[0].value))
	{
		 window.alert("Phone Number must be Numeric");
		 document.getElementsByName("w_phone_2")[0].focus();
		  document.getElementsByName("w_phone_2")[0].value="";
		 document.getElementsByName("w_phone_2")[0].select();

	     return false;
	}
      if(document.getElementsByName("w_phone_2")[0].value.length != 4)
        {
       window.alert("Please Enter Valid Phone Number");
	   document.getElementsByName("w_phone_2")[0].focus();
	   document.getElementsByName("w_phone_2")[0].value="";
		 document.getElementsByName("w_phone_2")[0].select();
	   return false;
       }
	  
	
   }
	if(document.getElementsByName("PREF_CALLTIME")[0].value=="not")
	{
	  window.alert("Select Best Contact Time");
	  document.getElementsByName("PREF_CALLTIME")[0].focus();
	  return false;
	}
if (document.form1.loan.value=="not")
{
alert("Please Select Loan Type ");
document.form1.loan.focus();
return false;
}
if (document.form1.PROP_ST.value=="not")
{
alert("Please Select Property Location ");
document.form1.PROP_ST.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.property_type.value=="not")
{
alert("Please Select Property Type ");
document.form1.property_type.focus();
return false;
}
if (document.form1.property_use.value=="not")
{
alert("Please Select Property Use ");
document.form1.property_use.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 Purpose of loan  ");
           document.getElementsByName("desired_loantype")[0].focus();
		   return false;
		}

       // window.alert(document.getElementById("refinancerate").value);
		if(document.getElementById("refinancerate").value=="not")
		{
		   window.alert("Select Current Interest Rate Type ");
		   document.getElementById("refinancerate").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.getElementById("add_cash_refi").value=="not")
		{
		   window.alert("Select Additional Cash Needed");
		   document.getElementById("add_cash_refi").focus();
		   return false;
		}
		if(document.getElementById("creditcard_debt_refi").value=="not")
		{
		   window.alert("Select Credit Card Debt");
		   document.getElementById("creditcard_debt_refi").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("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;
		}
	}
 if (document.form1.pro_value.value=="not")
{
alert("Please Select Property Value ");
document.form1.pro_value.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.getElementsByName("loan")[0].value=="Purchase")
	{
		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("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.form1.credit_rate.value=="not")
{
alert("Please Select Estimated Credit Rating ");
document.form1.credit_rate.focus();
return false;
}
if (document.form1.INCOME.value=="not")
{
alert("Please Select Annual Income ");
document.form1.INCOME.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.MIN_PAY.value=="not")
{
alert("Please Select  Monthly Debt Payments ");
document.form1.MIN_PAY.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;
	}



//document.form1.action = "http://www.calmortgagedepo.com/cgi-bin/calmortgagedepo/cal_reallygreat.cgi";
document.getElementById('subimg').innerHTML="<img src='http://www.mortgages-expo.com/images/processing.gif'>&nbsp;&nbsp;<font size='2'><b>Your Application is being Processed ... Please Wait ...</b></font>";
document.form1.submit();
}
function phone_lostfocus_hphone1()
{

 
  if(document.getElementsByName("h_phone")[0].value.length == 3)
   {
	    if(isNaN(document.getElementsByName("h_phone_1")[0].value))
	{
		
		  document.getElementsByName("h_phone_1")[0].value="";
		 document.getElementsByName("h_phone_1")[0].select();

	     return false;
	}
	document.getElementsByName("h_phone_1")[0].focus();
	return false;
    }
}
function phone_lostfocus_hphone2()
{

  if(document.getElementsByName("h_phone_1")[0].value.length == 3)
   {
	     if(isNaN(document.getElementsByName("h_phone_2")[0].value))
	{
		
		  document.getElementsByName("h_phone_2")[0].value="";
		 document.getElementsByName("h_phone_2")[0].select();

	     return false;
	}
	document.getElementsByName("h_phone_2")[0].focus();
	return false;
    }
}
function phone_lostfocus_wphone1()
{

  if(document.getElementsByName("w_phone")[0].value.length == 3)
   {
	     if(isNaN(document.getElementsByName("w_phone_1")[0].value))
	{
		
		  document.getElementsByName("w_phone_1")[0].value="";
		 document.getElementsByName("w_phone_1")[0].select();

	     return false;
	}
	document.getElementsByName("w_phone_1")[0].focus();
	return false;
    }
}
function phone_lostfocus_wphone2()
{

  if(document.getElementsByName("w_phone_1")[0].value.length == 3)
   {
	      if(isNaN(document.getElementsByName("w_phone_2")[0].value))
	{
		
		  document.getElementsByName("w_phone_2")[0].value="";
		 document.getElementsByName("w_phone_2")[0].select();

	     return false;
	}
	document.getElementsByName("w_phone_2")[0].focus();
	return false;
    }
}
