function Validate5(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 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()
{

if (document.form_1031.comp_name.value=="")
{
alert("Please Enter The Closing Company");
document.form_1031.comp_name.select();
		document.form_1031.comp_name.focus();
		return false;
}
if (document.form_1031.comp_agent_name.value=="")
{
alert("Please Enter The Closing Agent Name");
document.form_1031.comp_agent_name.select();
		document.form_1031.comp_agent_name.focus();
		return false;
}

if (document.form_1031.file_num.value=="")
{
alert("Please Enter The File No");
document.form_1031.file_num.select();
		document.form_1031.file_num.focus();
		return false;
}


if( document.form_1031.comp_phone.value != '' &&  document.form_1031.comp_phone_1.value != '' && document.form_1031.comp_phone_2.value != '' )

{

if ( Validate1(document.form_1031.comp_phone.value) || Validate1(document.form_1031.comp_phone_1.value) || Validate1(document.form_1031.comp_phone_2.value) ||  (document.form_1031.comp_phone.value.length) < 3 || document.form_1031.comp_phone_1.value.length < 3 || document.form_1031.comp_phone_2.value.length < 4)
	{
		alert("Please Enter Phone Number");	
		document.form_1031.comp_phone.value="";
		document.form_1031.comp_phone_1.value="";
		document.form_1031.comp_phone_2.value="";
        document.form_1031.comp_phone.focus();
		return false;
	}
	
}

else
{

alert("Please Enter Phone number");
document.form_1031.comp_phone.value="";
document.form_1031.comp_phone_1.value="";
document.form_1031.comp_phone_2.value="";
document.form_1031.comp_phone.focus();

return false;

}
if (document.form_1031.comp_address.value=="")
{
alert("Please Enter Address");
document.form_1031.comp_address.select();
		document.form_1031.comp_address.focus();
		return false;
}

if (document.form_1031.comp_city.value=="")
{
alert("Please Enter Cty");
document.form_1031.comp_city.select();
		document.form_1031.comp_city.focus();
		return false;
}

if(document.form_1031.comp_state.value=="")
 {
	alert("Please Select State");
	document.form_1031.comp_state.focus();
	return false;
 }


if (document.form_1031.comp_zip.value=="")
{
alert("Please Enter The Zip Code");
document.form_1031.comp_zip.select();
		document.form_1031.comp_zip.focus();
		return false;
}
if(isNaN(document.form_1031.comp_zip.value) || (document.form_1031.comp_zip.value) < 4)
{
alert("Please Enter a Valid Zip Code");
document.form_1031.comp_zip.select();
document.form_1031.comp_zip.focus();
		return false;
}

if (document.form_1031.comp_email.value=="")
{
alert("Please Enter Email Address");
document.form_1031.comp_email.select();
		document.form_1031.comp_email.focus();
		return false;
}
else
	{
	  var evalue=document.form_1031.comp_email.value;
      var emailPat = /^(\".*\"|\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	  
	  var matchArray = evalue.match(emailPat);

		if(!emailPat.test(evalue))
		{
			alert("Your email address is invalid.  Please try again !!");
			//SetErrorImage("Email", true);
			document.form_1031.comp_email.select();
			document.form_1031.comp_email.focus();
  			return false;
		}
		
	}

if (document.form_1031.first_name.value=="")
{
alert("Please Enter The First Name");
document.form_1031.first_name.select();
		document.form_1031.first_name.focus();
		return false;
}

if (document.form_1031.last_name.value=="")
{
alert("Please Enter The Last Name");
document.form_1031.last_name.select();
		document.form_1031.last_name.focus();
		return false;
}

if (document.form_1031.address.value=="")
{
alert("Please Enter The Address");
document.form_1031.address.select();
		document.form_1031.address.focus();
		return false;
} 

if (document.form_1031.city.value=="")
{
alert("Please Enter The City");
document.form_1031.city.select();
		document.form_1031.city.focus();
		return false;
}
if(document.form_1031.state.value=="")
 {
	alert("Please Select State");
	document.form_1031.state.focus();
	return false;
 }



if (document.form_1031.zip.value=="")
{
alert("Please Enter The Zip Code");
document.form_1031.zip.select();
		document.form_1031.zip.focus();
		return false;
}
if(isNaN(document.form_1031.zip.value) || (document.form_1031.zip.value) < 4)
{
alert("Please Enter a Valid Zip Code");
document.form_1031.zip.select();
document.form_1031.zip.focus();
		return false;
}


if (document.form_1031.email.value=="")
{
alert("Please Enter Email Address");
document.form_1031.email.select();
		document.form_1031.email.focus();
		return false;
}
else
	{
	  var evalue=document.form_1031.email.value;
      var emailPat = /^(\".*\"|\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	  
	  var matchArray = evalue.match(emailPat);

		if(!emailPat.test(evalue))
		{
			alert("Your email address is invalid.  Please try again !!");
			//SetErrorImage("Email", true);
			document.form_1031.email.select();
			document.form_1031.email.focus();
  			return false;
		}
		
	}










if( document.form_1031.home_phone.value != '' &&  document.form_1031.home_phone_1.value != '' && document.form_1031.home_phone_2.value != '' )

{

if ( Validate1(document.form_1031.home_phone.value) || Validate1(document.form_1031.home_phone_1.value) || Validate1(document.form_1031.home_phone_2.value) ||  (document.form_1031.home_phone.value.length) < 3 || document.form_1031.home_phone_1.value.length < 3 || document.form_1031.home_phone_2.value.length < 4)
	{
		alert("Please Enter Home Phone Number");	
		document.form_1031.home_phone.value="";
		document.form_1031.home_phone_1.value="";
		document.form_1031.home_phone_2.value="";
        document.form_1031.home_phone.focus();
		return false;
	}
	
}

else
{

alert("Please Enter Home Phone number");
document.form_1031.home_phone.value="";
document.form_1031.home_phone_1.value="";
document.form_1031.home_phone_2.value="";
document.form_1031.home_phone.focus();

return false;

}








if( document.form_1031.w_phone.value != '' &&  document.form_1031.w_phone_1.value != '' && document.form_1031.w_phone_2.value != '' )

{

if ( Validate1(document.form_1031.w_phone.value) || Validate1(document.form_1031.w_phone_1.value) || Validate1(document.form_1031.w_phone_2.value) ||  (document.form_1031.w_phone.value.length) < 3 || document.form_1031.w_phone_1.value.length < 3 || document.form_1031.w_phone_2.value.length < 4)
	{
		alert("Please Enter Work Phone Number");	
		document.form_1031.w_phone.value="";
		document.form_1031.w_phone_1.value="";
		document.form_1031.w_phone_2.value="";
        document.form_1031.w_phone.focus();
		return false;
	}
	
}

else
{

alert("Please Enter Work Phone number");
document.form_1031.w_phone.value="";
document.form_1031.w_phone_1.value="";
document.form_1031.w_phone_2.value="";
document.form_1031.w_phone.focus();

return false;

}


if(document.form_1031.contact_time.value=="")
 {
	alert("Please Select Best Contact Time");
	document.form_1031.contact_time.focus();
	return false;
 }

if(document.form_1031.reltoexch.value=="")
 {
	alert("Please Enter Relation to Exchanger");
    document.form_1031.reltoexch.select();
    document.form_1031.reltoexch.focus();	
	return false;
 }

//document.form_1031.action="/cgi-bin/clearleadinc/get1031quote.cgi";
document.form_1031.action="http://www.clearleadinc.com/cgi-bin/clearleadinc/get1031quote.cgi";
document.form_1031.method="POST";
document.form_1031.submit();

}



function PhoneMove_comp(nLength, sMoveFrom, sMoveTo) {
	if (sMoveTo != '') {
		if (document.form_1031[sMoveFrom].value.length >= nLength) {
			document.form_1031[sMoveTo].focus();
		}

	}
}


function PhoneMove_home(nLength, sMoveFrom, sMoveTo) {
	if (sMoveTo != '') {
		if (document.form_1031[sMoveFrom].value.length >= nLength) {
			document.form_1031[sMoveTo].focus();
		}

	}
}

function PhoneMove_work(nLength, sMoveFrom, sMoveTo) {
	if (sMoveTo != '') {
		if (document.form_1031[sMoveFrom].value.length >= nLength) {
			document.form_1031[sMoveTo].focus();
		}

	}
}




function Validate2(x)
 {
 

 var retValue=false;
 var invalidChars="0123456789!#$%^&*(){}|\':;?/<>";
 var i;
  
for(i=0;i<invalidChars.length;i++)
 {
  if(x.indexOf(invalidChars.charAt(i))>-1)
  {
     retValue=true;
     break;
   }
 }
 
return retValue;
 }


function Validate3(x)
 {
 

 var retValue=false;
 var invalidChars=".@";
 var i;
  
for(i=0;i<invalidChars.length;i++)
 {
  if(x.indexOf(invalidChars.charAt(i))>-1)
  {
     retValue=true;
     break;
   }
 }
 
return retValue;
}

add_data="<table width=380 border=0 cellpadding=5 cellspacing=0><TR><TD height=50 vAlign=top borderColor=#e6e6fa class=body02 width=165><FONT face=\"Arial, Helvetica, sans-serif\" size=1>Current Mortgage Balance<FONT style=\"FONT-SIZE: 10pt\" color=#ff0000>*</FONT><BR><input name=\"Previous_loan\" type=text class=input></FONT></TD>"
add_data=add_data + "<TD class=body02 vAlign=top borderColor=#e6e6fa><FONT face=\"Arial, Helvetica, sans-serif\" size=1>Current Mortgage Intrest Rate<FONT style=\"FONT-SIZE: 10pt\" color=#ff0000>*</FONT><BR><input name=\"Current_rate\" type=text class=input></FONT></TD></TR></table>"

function additionalfields()
	{
		
	if (document.form1.loan.value == "Purchase" || document.form1.loan.value == "not"){
			addf.innerHTML="";
		}
		else{
			addf.innerHTML=add_data;
		}
		
}

function validate_refinance()
{

if (document.form1.loan.value=="not")
{
alert("Please Select Loan Type ");
document.form1.loan.focus();
return;
}
if (document.form1.loan_program.value=="not")
{
alert("Please Select Loan Program ");
document.form1.loan_program.focus();
return;
}
if (document.form1.property_type.value=="not")
{
alert("Please Select Property Type ");
document.form1.property_type.focus();
return;
}

if (document.form1.property_use.value=="not")
{
alert("Please Select Property Use ");
document.form1.property_use.focus();
return;
}


if (document.form1.loan_amount.value=="not")
{
alert("Please Select Loan Amount ");
document.form1.loan_amount.focus();
return;
}

if (document.form1.pro_value.value=="not")
{
alert("Please Select Property Value ");
document.form1.pro_value.focus();
return;
}




if (document.form1.credit_rate.value=="not")
{
alert("Please Select Credit Rating ");
document.form1.credit_rate.focus();
return;
}

if (document.form1.loan.value != "Purchase")

	{
if(document.form1.Previous_loan.value=="")
{
alert("Please Enter Current Mortgage Balance ");
document.form1.Previous_loan.focus();
return;
}
if (Validate5(document.form1.Previous_loan.value))
{
alert("Please Enter only Numbers");
document.form1.Previous_loan.value="";
document.form1.Previous_loan.focus();
return;
}


if(document.form1.Current_rate.value=="")
{
alert("Please Enter Current Mortgage Balance ");
document.form1.Current_rate.focus();
return;
}
if (Validate5(document.form1.Current_rate.value))
{
alert("Please Enter only Numbers");
document.form1.Current_rate.value="";
document.form1.Current_rate.focus();
return;
}
	
	}

if( document.form1.fname.value != '')
{


if( Validate2(document.form1.fname.value) )
		
	{
		alert("Please Enter Valid Name ");	
		document.form1.fname.value="";
		document.form1.fname.focus();
		return;
		
	}

}

else
{
alert("Please Enter First Name ");
document.form1.fname.focus();
return;

}

if( document.form1.lname.value != '')
{


if( Validate2(document.form1.lname.value) )
		
	{
		alert("Please Enter Valid Name ");	
		document.form1.lname.value="";
		document.form1.lname.focus();
		return;
		
	}

}

else
{
alert("Please Enter Last Name ");
document.form1.lname.focus();
return;

}

if( document.form1.w_phone.value != '' &&  document.form1.w_phone_1.value != '' && document.form1.w_phone_2.value != '' )

{

if ( Validate1(document.form1.w_phone.value) || Validate1(document.form1.w_phone_1.value) || Validate1(document.form1.w_phone_2.value) ||  (document.form1.w_phone.value.length) < 3 || document.form1.w_phone_1.value.length < 3 || document.form1.w_phone_2.value.length < 4)
	{
		alert("Please Enter Home Phone Number");	
		document.form1.w_phone.value="";
		document.form1.w_phone_1.value="";
		document.form1.w_phone_2.value="";
        document.form1.w_phone.focus();
		return;
	}
	
}

else
{

alert("Please Enter phone number");
document.form1.w_phone.value="";
document.form1.w_phone_1.value="";
document.form1.w_phone_2.value="";
document.form1.w_phone.focus();

return;

}

if( document.form1.phone.value != '')
{

if ( Validate1(document.form1.phone.value) || Validate1(document.form1.phone_1.value) || Validate1(document.form1.phone_2.value) ||  (document.form1.phone.value.length) < 3 || document.form1.phone_1.value.length < 3 || document.form1.phone_2.value.length < 4)
	{
		alert("Please Enter Valid Phone Number");	
		document.form1.phone.value="";
		document.form1.phone_1.value="";
		document.form1.phone_2.value="";
        document.form1.phone.focus();
		return;
	}
}



if (document.form1.address.value=="")
{
alert("Please Enter Address ");
document.form1.address.focus();
return;
}

if( document.form1.email.value != '')
{
var e_mail=  document.form1.email.value;

if(e_mail.indexOf('.')< 0 || e_mail.indexOf('@') < 0)
  {
	alert("Please Enter Valid Email");
	document.form1.email.value="";
	document.form1.email.focus();
	return;	
  }
 }

else
{
alert("Please Enter Email ");
document.form1.email.focus();
return;

}






if ( document.form1.zip_code.value != '')
	{

	if( Validate1(document.form1.zip_code.value) || document.form1.zip_code.value.length < 5 )
		{
		alert("Please Enter Valid Zip Code");	
		document.form1.zip_code.value="";
		document.form1.zip_code.focus();
		return;
		}
	}
	
	else
	{
	alert("Please Enter Zipcode");
	document.form1.zip_code.focus();
	return;
	}
	

if (document.form1.contact.value=="not")
{
alert("Please Select Contact Preference");
document.form1.contact.focus();
return;
}

document.form1.method="POST";
//document.form1.action="http://sys116:3000/cgi-bin/cli/refi-insert.cgi";
document.form1.action="http://www.clearleadinc.com/cgi-bin/clearleadinc/refi-insert.cgi";
document.form1.submit();

}


function phone_lostfocus_mort()
{

  if(document.form1.phone.value.length == 3)
   {
	document.form1.phone_1.focus();
	return;
    }
}

function phone_lostfocus1_mort()
{

   if(document.form1.phone_1.value.length == 3)
   {
	document.form1.phone_2.focus();
	return;
    }
}


function phone_lostfocus2_mort()
{

  if(document.form1.w_phone.value.length == 3)
   {
	document.form1.w_phone_1.focus();
	return;
    }
}

function phone_lostfocus3_mort()
{
	
   if(document.form1.w_phone_1.value.length == 3)
   {
	document.form1.w_phone_2.focus();
	return;
    }
}





function validate_antiques() {

	if( document.form_antiques.fname.value != '')
{


if( Validate2(document.form_antiques.fname.value) )
		
	{
		alert("Please Enter Valid Name ");	
		document.form_antiques.fname.value="";
		document.form_antiques.fname.focus();
		return;
		
	}

}

else
{
alert("Please Enter First Name ");
document.form_antiques.fname.focus();
return;

}

if( document.form_antiques.lname.value != '')
{


if( Validate2(document.form_antiques.lname.value) )
		
	{
		alert("Please Enter Valid Name ");	
		document.form_antiques.lname.value="";
		document.form_antiques.lname.focus();
		return;
		
	}

}

else
{
alert("Please Enter Last Name ");
document.form_antiques.lname.focus();
return;
}


if (document.form_antiques.address.value=="")
{
alert("Please Enter Address ");
document.form_antiques.address.focus();
return;
}

if (document.form_antiques.city.value=="")
{
alert("Please Enter The City");
document.form_antiques.city.select();
		document.form_antiques.city.focus();
		return false;
}

if(document.form_antiques.property_bng_soldState.value=="")
 {
	alert("Please Select State");
	document.form_antiques.property_bng_soldState.focus();
	return false;
 }

 if ( document.form_antiques.zip_code.value != '')
	{

	if( Validate1(document.form_antiques.zip_code.value) || document.form_antiques.zip_code.value.length < 5 )
		{
		alert("Please Enter Valid Zip Code");	
		document.form_antiques.zip_code.value="";
		document.form_antiques.zip_code.focus();
		return;
		}
	}
	
	else
	{
	alert("Please Enter Zipcode");
	document.form_antiques.zip_code.focus();
	return;
	}
	
if (!document.form_antiques.identification[0].checked && !document.form_antiques.identification[1].checked && !document.form_antiques.identification[2].checked )
{
	alert('Please select whether you are a Dealer or Collector or Other');
	return false;
}




if( document.form_antiques.home_phone_antiques.value != '' &&  document.form_antiques.home_phone_antiques_1.value != '' && document.form_antiques.home_phone_antiques_2.value != '' )
{
if ( Validate1(document.form_antiques.home_phone_antiques.value) || Validate1(document.form_antiques.home_phone_antiques_1.value) || Validate1(document.form_antiques.home_phone_antiques_2.value) ||  (document.form_antiques.home_phone_antiques.value.length) < 3 || document.form_antiques.home_phone_antiques_1.value.length < 3 || document.form_antiques.home_phone_antiques_2.value.length < 4)
	{
		alert("Please Enter Home Phone Number");	
		document.form_antiques.home_phone_antiques.value="";
		document.form_antiques.home_phone_antiques_1.value="";
		document.form_antiques.home_phone_antiques_2.value="";
        document.form_antiques.home_phone_antiques.focus();
		return false;
	}
}

else
{
alert("Please Enter Home Phone number");
document.form_antiques.home_phone_antiques.value="";
document.form_antiques.home_phone_antiques_1.value="";
document.form_antiques.home_phone_antiques_2.value="";
document.form_antiques.home_phone_antiques.focus();
return false;
}


if( document.form_antiques.w_phone_antiques.value != '' &&  document.form_antiques.w_phone_antiques_1.value != '' && document.form_antiques.w_phone_antiques_2.value != '' )
{
if ( Validate1(document.form_antiques.w_phone_antiques.value) || Validate1(document.form_antiques.w_phone_antiques_1.value) || Validate1(document.form_antiques.w_phone_antiques_2.value) ||  (document.form_antiques.w_phone_antiques.value.length) < 3 || document.form_antiques.w_phone_antiques_1.value.length < 3 || document.form_antiques.w_phone_antiques_2.value.length < 4)
	{
		alert("Please Enter Work Phone Number");	
		document.form_antiques.w_phone_antiques.value="";
		document.form_antiques.w_phone_antiques_1.value="";
		document.form_antiques.w_phone_antiques_2.value="";
        document.form_antiques.w_phone_antiques.focus();
		return false;
	}
}
else
{
alert("Please Enter Work Phone number");
document.form_antiques.w_phone_antiques.value="";
document.form_antiques.w_phone_antiques_1.value="";
document.form_antiques.w_phone_antiques_2.value="";
document.form_antiques.w_phone_antiques.focus();
return false;
}



if( document.form_antiques.email.value != '')
{
var e_mail=  document.form_antiques.email.value;

if(e_mail.indexOf('.')< 0 || e_mail.indexOf('@') < 0)
  {
	alert("Please Enter Valid Email");
	document.form_antiques.email.value="";
	document.form_antiques.email.focus();
	return;	
  }
 }

else
{
alert("Please Enter Email ");
document.form_antiques.email.focus();
return;
}

if (document.form_antiques.contact.value=="not")
{
alert("Please Select Best Contact Time");
document.form_antiques.contact.focus();
return;
}

document.form_antiques.method="POST";
//document.form_antiques.action="http://sys116:3000/cgi-bin/cli/antiques-insert.cgi";
document.form_antiques.action="http://www.clearleadinc.com/cgi-bin/clearleadinc/antiques-insert.cgi";
document.form_antiques.submit();

}



function phone_lostfocus_antiques()
	{
  if(document.form_antiques.home_phone_antiques.value.length == 3)   {
	document.form_antiques.home_phone_antiques_1.focus();
	return;
    }
}
function phone_lostfocus1_antiques()
{
	if(document.form_antiques.home_phone_antiques_1.value.length == 3)   {
	document.form_antiques.home_phone_antiques_2.focus();
	return;
    }
}


function phone_lostfocus2_antiques()
{
  if(document.form_antiques.w_phone_antiques.value.length == 3)   {
	document.form_antiques.w_phone_antiques_1.focus();
	return;
    }
}
function phone_lostfocus3_antiques()
{
	if(document.form_antiques.w_phone_antiques_1.value.length == 3)   {
	document.form_antiques.w_phone_antiques_2.focus();
	return;
    }
}
