
function clearText(thefield) {
	thefield.style.backgroundColor = 'white';
		
		if (thefield.defaultValue==thefield.value) {
			thefield.value = "";
		}
	}
function isNumber(value) {
	for (var i=0; i < value.length; i++) {
		a = parseInt(value.charAt(i));
		if (isNaN(a)) {
			return false;
			break;
		}
	}
	return true;
}
function isDecimal(value) {
	for (var i=0; i < value.length; i++) {
		a = parseInt(value.charAt(i));
		if (isNaN(a))
		{
			if (value.charAt(i) != '$' && value.charAt(i) != '.')
			{
			return false;
			break;
			}
		}
	}
	return true;
}

	function $(id){
		return document.getElementById(id);
	}
	function contact_validate(){
		var err = true;
		if($('firstname').value == '' || $('firstname').value == 'First Name'){
			$('firstname').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('lastname').value == '' || $('lastname').value == 'Last Name'){
			$('lastname').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('phonearea').value == '' || $('phonearea').value == 'XXX')
		{
			$('phonearea').style.backgroundColor = '#F28A00';
			err = false;
		}
		else
			if ($('phonearea').value.length != 3 || !isNumber($('phonearea').value))
			{
				$('phonearea').style.backgroundColor = '#F28A00';
				err = false;
			}

		if($('phone3').value == '' || $('phone3').value == 'XXX')
		{
			$('phone3').style.backgroundColor = '#F28A00';
			err = false;
		}
		else
			if ($('phone3').value.length != 3 || !isNumber($('phone3').value))
			{
				$('phone3').style.backgroundColor = '#F28A00';
				err = false;
			}

		if($('phone4').value == '' || $('phone4').value == 'XXXX')
		{
			$('phone4').style.backgroundColor = '#F28A00';
			err = false;
		}
		else
			if ($('phone4').value.length != 4 || !isNumber($('phone4').value))
			{
				$('phone4').style.backgroundColor = '#F28A00';
				err = false;
			}

		if ($('BestNumber').value == 2)
			{
				if($('workphonearea').value == '' || $('workphonearea').value == 'XXX')
					{
						$('workphonearea').style.backgroundColor = '#F28A00';
						err = false;
					}
				else
					if ($('workphonearea').value.length != 3 || !isNumber($('workphonearea').value))
					{
						$('workphonearea').style.backgroundColor = '#F28A00';
						err = false;
					}
			if($('workphone3').value == '' || $('workphone3').value == 'XXX')
				 {
					$('workphone3').style.backgroundColor = '#F28A00';
					err = false;
				 }
				 else
					if ($('workphone3').value.length != 3 || !isNumber($('workphone3').value))
					 {
					 $('workphone3').style.backgroundColor = '#F28A00';
					 err = false;
					}
				if($('workphone4').value == '' || $('workphone4').value == 'XXX')
					{
					$('workphone4').style.backgroundColor = '#F28A00';
					err = false;
					}
				 else
					if ($('workphone4').value.length != 4 || !isNumber($('workphone4').value))
					{
					$('workphone4').style.backgroundColor = '#F28A00';
					err = false;
					}
			}
			if ($('BestNumber').value == 3)
			{

			  if($('cellphonearea').value == '' || $('cellphonearea').value == 'XXX')
			   {
				$('cellphonearea').style.backgroundColor = '#F28A00';
				err = false;
				}
			else
				if ($('cellphonearea').value.length != 3 || !isNumber($('cellphonearea').value))
				{
					$('cellphonearea').style.backgroundColor = '#F28A00';
					err = false;
				}
			 if($('cellphone3').value == '' || $('cellphone3').value == 'XXX')
			   {
				$('cellphone3').style.backgroundColor = '#F28A00';
				err = false;
				}
			  else
				if ($('cellphone3').value.length != 3 || !isNumber($('cellphone3').value))
				{
					$('cellphone3').style.backgroundColor = '#F28A00';
					err = false;
				}
				if($('cellphone4').value == '' || $('cellphone4').value == 'XXX')
			   {
				$('cellphone4').style.backgroundColor = '#F28A00';
				err = false;
				}
			  else
				if ($('cellphone4').value.length !=4 || !isNumber($('cellphone4').value))
				{
					$('cellphone4').style.backgroundColor = '#F28A00';
					err = false;
				}
			}

			if ($('BestNumber').selectedIndex == 0|| $('BestNumber').value == '')
				{
				$('BestNumber').style.backgroundColor = '#F28A00';
				err = false;
				}else
					{
						$('BestNumber').style.backgroundColor = '#FFFFFF';
					}
		/*var emailRegExp = '/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
		if (!emailRegExp.test($('email').value))
			{
			$('email').style.backgroundColor = '#F28A00';
			return false;
			}*/
		if($('email').value == '' || $('email').value == 'Email Address'){
			$('email').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('lender').value == '' || $('lender').value == 'Lender'){
			$('lender').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('months_behind').value == '' || $('months_behind').value == 'Months Behind'){
			$('months_behind').style.backgroundColor = '#F28A00';
			err = false;
		}
		if(!isDecimal($('MonthlyPayment').value)){
			$('MonthlyPayment').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('MonthlyPayment').value == '' || $('MonthlyPayment').value == 'Monthly Payment'){
			$('MonthlyPayment').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('address').value == '' || $('address').value == 'Address'){
			$('address').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('city').value == '' || $('city').value == 'City'){
			$('city').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('state').value == '' || $('state').value == 'State'){
			$('state').style.backgroundColor = '#F28A00';
			err = false;
		}
		else
			{
		     $('state').style.backgroundColor = '#FFFFFF';
			}
		if($('zip').value == '' || $('zip').value == 'Zip'){
			$('zip').style.backgroundColor = '#F28A00';
			err = false;
		}
		if(!isNumber($('zip').value) || $('zip').value.length != 5){
			$('zip').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('Foreclosure_Date_YN').selectedIndex==0)
		{
			$('Foreclosure_Date_YN').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('AffordMortgage').selectedIndex==0)
		{
			$('AffordMortgage').style.backgroundColor = '#F28A00';
			err = false;
		}
		if($('Foreclosure_Date_YN').selectedIndex==1)
		{
			if($('ForeMonth').value == '' || $('ForeMonth').value == 'mm')
					{
					$('ForeMonth').style.backgroundColor = '#F28A00';
					err = false;
					}
				 else
					if ($('ForeMonth').value.length != 2 || !isNumber($('ForeMonth').value))
					{
					$('ForeMonth').style.backgroundColor = '#F28A00';
					err = false;
					}
					if($('ForeDay').value == '' || $('ForeDay').value == 'dd')
					{
					$('ForeDay').style.backgroundColor = '#F28A00';
					err = false;
					}
				 else
					if ($('ForeDay').value.length != 2 || !isNumber($('ForeDay').value))
					{
					$('ForeDay').style.backgroundColor = '#F28A00';
					err = false;
					}

					if($('ForeYear').value == '' || $('ForeYear').value == 'yyyy')
					{
					$('ForeYear').style.backgroundColor = '#F28A00';
					err = false;
					}
				 else
					if ($('ForeYear').value.length != 4 || !isNumber($('ForeYear').value))
					{
					$('ForeYear').style.backgroundColor = '#F28A00';
					err = false;
					}

		}
		else
		{
				$('ForeMonth').style.backgroundColor = '#FFFFFF';
				$('ForeDay').style.backgroundColor   = '#FFFFFF';
				$('ForeYear').style.backgroundColor  = '#FFFFFF';
		}
		if ($('Foreclosure_Date_YN').selectedIndex==1 && $('state').value=='CA')
		{
			alert('Due to California State law, we may be unable to assist homeowners in California that have received a "Notice of Default"');
		}
		if(!err){
			$('err_text').innerHTML = 'Please fill out all of the fields';
			$('err_text').style.color = '#F28A00';
			$('err_text').style.fontWeight = 'bold';
			alert('Please fill out all of the fields');
			return false;
		}
		//return true;
		document.contactMe.submit();
	}

