 function numbersOnly(el)
   {
   el.value = el.value.replace(/[^0-9]/g, "");
   }

function chkvalid()
{
	if(document.contactForm.firstname.value == "")
	{
		alert("Please Enter First Name");
		document.contactForm.firstname.focus();
		return false;
	}
	if(document.contactForm.firstname.value.length < 2)
	{
		alert("Please Enter Your Full First Name");
		document.contactForm.firstname.focus();
		return false;
	}
	if(document.contactForm.lastname.value == "")
	{
		alert("Please Enter Last Name");
		document.contactForm.lastname.focus();
		return false;
	}
	if(document.contactForm.lastname.value.length < 2)
	{
		alert("Please Enter Your Full Last Name");
		document.contactForm.lastname.focus();
		return false;
	}
	//phone
	if(document.contactForm.phone1.value == "")
	{
		alert("Please enter first three numbers of your phone number.");
		document.contactForm.phone1.focus();
		return false;
	}
	if(document.contactForm.phone1.value.length != 3)
	{
		alert("Please enter first three numbers of your phone number.");
		document.contactForm.phone1.focus();
		return false;
	}
	if(document.contactForm.phone2.value == "")
	{
		alert("Please enter second set of three numbers of your phone number.");
		document.contactForm.phone2.focus();
		return false;
	}
	if(document.contactForm.phone2.value.length != 3)
	{
		alert("Please enter second set of three numbers of your phone number.");
		document.contactForm.phone2.focus();
		return false;
	}
	if(document.contactForm.phone3.value == "")
	{
		alert("Please enter third set of your phone number.");
		document.contactForm.phone3.focus();
		return false;
	}
	if(document.contactForm.phone3.value.length != 4)
	{
		alert("Please enter third set of your phone number.");
		document.contactForm.phone3.focus();
		return false;
	}
	//end phone

	if(document.contactForm.email.value == "")
	{
		alert("Please Enter Your Contact Email");
		document.contactForm.email.focus();
		return false;
	}
		// Start Email Validation
	if(document.contactForm.email.value != "")
	{
		var i;
		var input = document.contactForm.email.value ;
		var lenth = input.length ;
		var ctr=0 ;
	
		if ( ( document.contactForm.email.value.charAt(i) == '!' ) || ( 	document.contactForm.email.value.charAt(i) == '#' ) )
	    {
		  alert("Please enter a proper email address") ;
		  document.contactForm.email.focus();
	      return false;
	    }
		if (input =="")
		{
			alert("Please enter email address") ;
		    document.contactForm.email.focus();
			return false ;
		}
		if(input.length == 40)
		{
			alert("Please enter a proper email address") ;
		    document.contactForm.email.focus();
			return false ;
		}
	
		for ( i=0; i < lenth; i++ )
		{
			var oneChar = input.charAt(i) ;
			if(oneChar == "@")
			{
				ctr = ctr+1 ;
			}
			if ( (i == 0 && oneChar == "@") || (i == 0 && oneChar == ".") || 
				( oneChar == " " ) )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if ( (oneChar == "@" && input.charAt(i+1) == ".") || 
				(oneChar == "." && input.charAt(i+1) == "@") ||
				(oneChar == "." && input.charAt(i+1) == ".") )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if( input.indexOf("@") < 2 )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if(input.indexOf(".")<1)
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if (ctr > 1)
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
		}
	}	
	// End Email Validation Script
	if(document.contactForm.contacttime.value == "")
	{
		alert("Please select best contact time.");
		document.contactForm.contacttime.focus();
		return false;
	}
	if(document.contactForm.creditrating.value == "")
	{
		alert("Please select your credit rating.");
		document.contactForm.creditrating.focus();
		return false;
	}
	if(document.contactForm.income.value == "")
	{
			alert("Please select your annual income.");
			document.contactForm.income.focus();
			return false;
	}
	if(document.contactForm.address.value == "")
	{
		alert("Please enter your address.");
		document.contactForm.address.focus();
		return false;
	}
	if(document.contactForm.city.value == "")
	{
		alert("Please enter your city.");
		document.contactForm.city.focus();
		return false;
	}
	if(document.contactForm.state.value == "")
	{
		alert("Please select your state.");
		document.contactForm.state.focus();
		return false;
	}
	if(document.contactForm.zip.value == "")
	{
		alert("Please enter your zip code.");
		document.contactForm.zip.focus();
		return false;
	}
	if(document.contactForm.property_type.value == "")
	{
		alert("Please select a property type.");
		document.contactForm.property_type.focus();
		return false;
	}
	if(document.contactForm.homevalue.value == "")
	{
		alert("Please select estimated home value.");
		document.contactForm.homevalue.focus();
		return false;
	}
	if(document.contactForm.behind.value == "")
		{
			alert("Please select how behind on payments you are.");
			document.contactForm.behind.focus();
			return false;
		}
	if(document.contactForm.foreclosure[0].checked == true)
	{
		if(document.contactForm.foreclosuremonth.value == "")
		{
			alert("Please select month of your foreclosure");
			document.contactForm.foreclosuremonth.focus();
			return false;
		}
		if(document.contactForm.foreclosureday.value == "")
		{
			alert("Please select day of your foreclosure");
			document.contactForm.foreclosureday.focus();
			return false;
		}
		if(document.contactForm.foreclosureyear.value == "")
		{
			alert("Please select year of your foreclosure");
			document.contactForm.foreclosureyear.focus();
			return false;
		}
	}
	if(document.contactForm.owed.value == "")
	{
		alert("Please select how much you owe on your first mortgage.");
		document.contactForm.owed.focus();
		return false;
	}
	if(document.contactForm.fmlender.value == "")
		{
				alert("Please enter your first mortgage lender");
				document.contactForm.fmlender.focus();
				return false;
		}
	if(document.contactForm.fmpayment.value == "")
		{
				alert("Please select your first mortgage payment");
				document.contactForm.fmpayment.focus();
				return false;
		}
	if((document.contactForm.sowed.value != "")&&(document.contactForm.sowed.value != 0)&&(document.contactForm.behind.value > 0)||(document.contactForm.sowed.value != "")&&(document.contactForm.sowed.value != 0)&&(document.contactForm.behind.value > 0))
	{
		if(document.contactForm.smlender.value == "")
		{
			alert("Please enter your second mortgage lender");
			document.contactForm.smlender.focus();
			return false;
		}
		if(document.contactForm.smpayment.value == "")
		{
			alert("Please select your second mortgage payment");
			document.contactForm.smpayment.focus();
			return false;
		}	
	}
	if(document.contactForm.va_status.value == "")
		{
				alert("Please select if you or your spouse have been in the military");
				document.contactForm.va_status.focus();
				return false;
		}
	document.getElementById("form_complete").style.display = 'none';
	document.getElementById("processing").style.display = '';
}

//Drop Down
function FillFirstMortBal39()
{
	if (document.contactForm.homevalue.selectedIndex == -1)
		{return;}
	var tempval;
	if (document.contactForm.owed.selectedIndex != undefined)
		{tempval = document.contactForm.owed.selectedIndex;}
	else
		{tempval = 0;}
	while (document.contactForm.owed.options.length > 0) 
	{
		document.contactForm.owed.options[0] = null;
	}
	var i = 0;
	while (+document.contactForm.owed2.options[i].value <= (+document.contactForm.homevalue.options[document.contactForm.homevalue.selectedIndex].value * .90))
	{
		document.contactForm.owed.options[document.contactForm.owed.length] = new Option(document.contactForm.owed2.options[i].text, document.contactForm.owed2.options[i].value);
		i++;
	}
	document.contactForm.owed.options[tempval].selected = true;
	
	FillSecond39();	


}


//Second
function FillSecond39()
{
	if (document.contactForm.owed.selectedIndex == -1)
		{return;}
	var tempval;
	if (document.contactForm.sowed.selectedIndex != -1)
		{tempval = document.contactForm.sowed.selectedIndex;}
	else
		{tempval = 0;}
	while (document.contactForm.sowed.options.length > 0) 
	{
		document.contactForm.sowed.options[0] = null;
	}
	var i = 0;
	while ((+document.contactForm.sowed2.options[i].value + +document.contactForm.owed.options[document.contactForm.owed.selectedIndex].value) <= (+document.contactForm.homevalue.options[document.contactForm.homevalue.selectedIndex].value * .90))
	{
		document.contactForm.sowed.options[document.contactForm.sowed.length] = new Option(document.contactForm.sowed2.options[i].text, document.contactForm.sowed2.options[i].value);
		i++;
	}
	var strMoney = document.contactForm.sowed2.options[i].text;
	var x = strMoney.split("$");
	var str = x[1];
	str = str.replace(/ -/, "");
	//document.contactForm.SECOND_MORT_BALANCE.options[document.contactForm.SECOND_MORT_BALANCE.length] = new Option("More than $" + str, document.contactForm.SECOND_MORT_BALANCE2.options[i].value);
	if (document.contactForm.sowed.options.length == 0)
	{
		document.contactForm.sowed.options[document.contactForm.sowed.length] = new Option("No equity available", 0);
		document.contactForm.sowed.options[0].selected = true;		
	}
	if (tempval > 0)
		{document.contactForm.sowed.options[tempval].selected = true;
}
	


}
	
function ResetDropDowns()
{
	FillFirstMortBal39();
	FillSecond39();

}
