var namereg=new RegExp();

function CheckSelfOrCo(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_selforco',valid)
	return valid
}

function CheckTitle(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_title',valid)
	return valid
}

function CheckFirstName(TheName) {
	var valid = 1
	namereg=/^[a-zA-Z\'\ \-]{2,}$/;
	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_firstname',valid)
	return valid
}

function CheckLastName(TheName) {
	var valid = 1
	namereg=/^[a-zA-Z\'\ \-]{2,}$/;
	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_lastname',valid)
	return valid
}

function CheckSSN(TheName) {
	var valid = 1
	namereg=/^\d{3}\-?\d{2}\-?\d{4}$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_ssn',valid)
	return valid
}

function CheckDOB(TheName) {
	var valid = 1
	namereg=/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_dob',valid)
	return valid
}

function CheckResident(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_resident',valid)
	return valid
}

function CheckStreetAddress(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_streetaddress',valid)
	return valid
}

function CheckCity(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_city',valid)
	return valid
}

function CheckState(TheName) {
	var valid = 1
	namereg=/^[A-Z]{2}$/;
	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_state',valid)
	return valid
}

function CheckZipCode(TheName) {
	var valid = 1
	namereg=/(^\d{5}$)|(^\d{5}-\d{4}$)/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_zipcode',valid)
	return valid
}

function CheckCurResidence(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_residence',valid)
	return valid
}

function CheckMonthlyPayment(TheName) {
	var valid = 1
	namereg=/^(\$)?\d+(\.\d{2})?$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_monthpay',valid)
	return valid
}

function CheckResLength(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_rentlength',valid)
	return valid
}

function CheckHomePhone(TheName) {
	var valid = 1
	namereg=/^\(?\d{3}\)?\-?\d{3}\-?\d{4}$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_homephone',valid)
	return valid
}

function CheckEmail(TheName) {
	var valid = 1
	namereg=/^[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]$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_email',valid)
	return valid
}

function CheckSelfEmployed(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_selfemployed',valid)
	return valid
}

function CheckCompanyName(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_emp_company',valid)
	return valid
}

function CheckEmpYears(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_emp_years',valid)
	return valid
}

function CheckIncome(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_emp_income',valid)
	return valid
}

function CheckSelfEmployed2(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_xselfemployed',valid)
	return valid
}

function CheckCompanyName2(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_xemp_company',valid)
	return valid
}

function CheckEmpYears2(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_xemp_years',valid)
	return valid
}

function CheckIncome2(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_xemp_income',valid)
	return valid
}

function CheckLoanType(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_loantype',valid)
	theForm = document.f_contact;
	CheckPriceRange(theForm.a_pricerange.options[theForm.a_pricerange.selectedIndex].value);
	CheckCurRate(theForm.a_mortgagerate.value);
	CheckCurBalance(theForm.a_mortbalance.options[theForm.a_mortbalance.selectedIndex].value);
	CheckHomeValue(theForm.a_homevalue.options[theForm.a_homevalue.selectedIndex].value)
	return valid
}

function CheckPriceRange(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	theForm = document.f_contact;
	if (theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value != "Home Purchase" && theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value != "") valid = 1
	setImageStatus('image_pricerange',valid)
	return valid
}

function CheckCurRate(TheName) {
	var valid = 1
	namereg=/^\d+(\.\d{1,9})?$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	theForm = document.f_contact;
	if (theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value == "Home Purchase") valid = 1
	setImageStatus('image_mortgagerate',valid)
	return valid
}

function CheckCurBalance(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	theForm = document.f_contact;
	if (theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value != "Home Equity Loan" && theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value != "Texas Cash Out" && theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value != "") valid = 1
	setImageStatus('image_mortbalance',valid)
	return valid
}

function CheckHomeValue(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	theForm = document.f_contact;
	if (theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value == "Home Purchase") valid = 1
	setImageStatus('image_homevalue',valid)
	return valid
}

function CheckLoanAmount(TheName) {
	var valid = 1
	namereg=/^(\$)?\d+(\.\d{2})?$/;

	if (!namereg.test(TheName)) valid=0
	if(TheName == '') valid=2
	setImageStatus('image_loanamt',valid)
	return valid
}

function CheckCredit(TheName) {
	var valid = 1
	if(TheName == '') valid=2
	setImageStatus('image_current_credit',valid)
	return valid
}







function checkForm() {
 theForm = document.f_contact;

 if (CheckSelfOrCo(theForm.action.options[theForm.action.selectedIndex].value) == 0 || CheckSelfOrCo(theForm.action.options[theForm.action.selectedIndex].value) == 2) {
   alert('Error: Please select whether there will be a co-borrower.');
   theForm.action.focus();
   theForm.action.blur();
   return false;
 }

 if (CheckTitle(theForm.a_title.options[theForm.a_title.selectedIndex].value) == 0 || CheckTitle(theForm.a_title.options[theForm.a_title.selectedIndex].value) == 2) {
   alert('Error: Please select a title.');
   theForm.a_title.focus();
   theForm.a_title.blur();
   return false;
 }

 if (CheckFirstName(theForm.a_firstname.value) == 0 || CheckFirstName(theForm.a_firstname.value) == 2) {
   alert('Error: Please enter your first name.');
   theForm.a_firstname.focus();
   theForm.a_firstname.blur();
   theForm.a_firstname.select();
   return false;
 }

 if (CheckLastName(theForm.a_lastname.value) == 0 || CheckLastName(theForm.a_lastname.value) == 2) {
   alert('Error: Please enter your last name.');
   theForm.a_lastname.focus();
   theForm.a_lastname.blur();
   theForm.a_lastname.select();
   return false;
 }

 if (CheckSSN(theForm.a_socialsn.value) == 0 || CheckSSN(theForm.a_socialsn.value) == 2) {
   alert('Error: Please enter your social security number in the proper format.'+"\n\nExample: 123-45-6789");
   theForm.a_socialsn.focus();
   theForm.a_socialsn.blur();
   theForm.a_socialsn.select();
   return false;
 }

 if (CheckDOB(theForm.a_dateofbirth.value) == 0 || CheckDOB(theForm.a_dateofbirth.value) == 2) {
   alert('Error: Please enter your date of birth in the proper format.'+"\n\nExample: 01/23/1979");
   theForm.a_dateofbirth.focus();
   theForm.a_dateofbirth.blur();
   theForm.a_dateofbirth.select();
   return false;
 }

 if (CheckResident(theForm.a_resident.options[theForm.a_resident.selectedIndex].value) == 0 || CheckResident(theForm.a_resident.options[theForm.a_resident.selectedIndex].value) == 2) {
   alert('Error: Please select your US residence status.');
   theForm.a_resident.focus();
   theForm.a_resident.blur();
   return false;
 }

 if (CheckStreetAddress(theForm.a_streetaddress.value) == 0 || CheckStreetAddress(theForm.a_streetaddress.value) == 2) {
   alert('Error: Please enter your street address.');
   theForm.a_streetaddress.focus();
   theForm.a_streetaddress.blur();
   theForm.a_streetaddress.select();
   return false;
 }

 if (CheckCity(theForm.a_city.value) == 0 || CheckCity(theForm.a_city.value) == 2) {
   alert('Error: Please enter your city.');
   theForm.a_city.focus();
   theForm.a_city.blur();
   theForm.a_city.select();
   return false;
 }

 if (CheckState(theForm.a_state.options[theForm.a_state.selectedIndex].value) == 0 || CheckState(theForm.a_state.options[theForm.a_state.selectedIndex].value) == 2) {
   alert('Error: Please select your state.');
   theForm.a_state.focus();
   theForm.a_state.blur();
   return false;
 }

 if (CheckZipCode(theForm.a_zipcode.value) == 0 || CheckZipCode(theForm.a_zipcode.value) == 2) {
   alert('Error: Please enter your 5 digit zip code.');
   theForm.a_zipcode.focus();
   theForm.a_zipcode.blur();
   theForm.a_zipcode.select();
   return false;
 }

 if (CheckCurResidence(theForm.a_current_residence.options[theForm.a_current_residence.selectedIndex].value) == 0 || CheckCurResidence(theForm.a_current_residence.options[theForm.a_current_residence.selectedIndex].value) == 2) {
   alert('Error: Please select your current residence status.');
   theForm.a_current_residence.focus();
   theForm.a_current_residence.blur();
   return false;
 }

 if (CheckMonthlyPayment(theForm.a_monthly_payment.value) == 0 || CheckMonthlyPayment(theForm.a_monthly_payment.value) == 2) {
   alert('Error: Please enter your current monthly payment (rent/mortgage).');
   theForm.a_monthly_payment.focus();
   theForm.a_monthly_payment.blur();
   theForm.a_monthly_payment.select();
   return false;
 }

 if (CheckResLength(theForm.a_rentlength.options[theForm.a_rentlength.selectedIndex].value) == 0 || CheckResLength(theForm.a_rentlength.options[theForm.a_rentlength.selectedIndex].value) == 2) {
   alert('Error: Please enter the length of time at your current residence.');
   theForm.a_rentlength.focus();
   theForm.a_rentlength.blur();
   return false;
 }

 if (CheckHomePhone(theForm.a_homephone.value) == 0 || CheckHomePhone(theForm.a_homephone.value) == 2) {
   alert('Error: Please enter your home phone number in the proper format.'+"\n\nExample: 123-456-7890");
   theForm.a_homephone.focus();
   theForm.a_homephone.blur();
   theForm.a_homephone.select();
   return false;
 }

 if (CheckEmail(theForm.a_emailaddress.value) == 0 || CheckEmail(theForm.a_emailaddress.value) == 2) {
   alert('Error: Please enter your email address in the proper format.'+"\n\nExample: user@domain.com");
   theForm.a_emailaddress.focus();
   theForm.a_emailaddress.blur();
   theForm.a_emailaddress.select();
   return false;
 }


 return true;
}

function checkFormCo() {
 theForm = document.f_contact;

 if (CheckTitle(theForm.a_co_title.options[theForm.a_co_title.selectedIndex].value) == 0 || CheckTitle(theForm.a_co_title.options[theForm.a_co_title.selectedIndex].value) == 2) {
   alert('Error: Please select a title.');
   theForm.a_co_title.focus();
   theForm.a_co_title.blur();
   return false;
 }

 if (CheckFirstName(theForm.a_co_firstname.value) == 0 || CheckFirstName(theForm.a_co_firstname.value) == 2) {
   alert('Error: Please enter your first name.');
   theForm.a_co_firstname.focus();
   theForm.a_co_firstname.blur();
   theForm.a_co_firstname.select();
   return false;
 }

 if (CheckLastName(theForm.a_co_lastname.value) == 0 || CheckLastName(theForm.a_co_lastname.value) == 2) {
   alert('Error: Please enter your last name.');
   theForm.a_co_lastname.focus();
   theForm.a_co_lastname.blur();
   theForm.a_co_lastname.select();
   return false;
 }

 if (CheckSSN(theForm.a_co_socialsn.value) == 0 || CheckSSN(theForm.a_co_socialsn.value) == 2) {
   alert('Error: Please enter your social security number in the proper format.'+"\n\nExample: 123-45-6789");
   theForm.a_co_socialsn.focus();
   theForm.a_co_socialsn.blur();
   theForm.a_co_socialsn.select();
   return false;
 }

 if (CheckDOB(theForm.a_co_dateofbirth.value) == 0 || CheckDOB(theForm.a_co_dateofbirth.value) == 2) {
   alert('Error: Please enter your date of birth in the proper format.'+"\n\nExample: 01/23/1979");
   theForm.a_co_dateofbirth.focus();
   theForm.a_co_dateofbirth.blur();
   theForm.a_co_dateofbirth.select();
   return false;
 }

 if (CheckResident(theForm.a_co_resident.options[theForm.a_co_resident.selectedIndex].value) == 0 || CheckResident(theForm.a_co_resident.options[theForm.a_co_resident.selectedIndex].value) == 2) {
   alert('Error: Please select your US residence status.');
   theForm.a_co_resident.focus();
   theForm.a_co_resident.blur();
   return false;
 }

 if (CheckStreetAddress(theForm.a_co_streetaddress.value) == 0 || CheckStreetAddress(theForm.a_co_streetaddress.value) == 2) {
   alert('Error: Please enter your street address.');
   theForm.a_co_streetaddress.focus();
   theForm.a_co_streetaddress.blur();
   theForm.a_co_streetaddress.select();
   return false;
 }

 if (CheckCity(theForm.a_co_city.value) == 0 || CheckCity(theForm.a_co_city.value) == 2) {
   alert('Error: Please enter your city.');
   theForm.a_co_city.focus();
   theForm.a_co_city.blur();
   theForm.a_co_city.select();
   return false;
 }

 if (CheckState(theForm.a_co_state.options[theForm.a_co_state.selectedIndex].value) == 0 || CheckState(theForm.a_co_state.options[theForm.a_co_state.selectedIndex].value) == 2) {
   alert('Error: Please select your state.');
   theForm.a_co_state.focus();
   theForm.a_co_state.blur();
   return false;
 }

 if (CheckZipCode(theForm.a_co_zipcode.value) == 0 || CheckZipCode(theForm.a_co_zipcode.value) == 2) {
   alert('Error: Please enter your 5 digit zip code.');
   theForm.a_co_zipcode.focus();
   theForm.a_co_zipcode.blur();
   theForm.a_co_zipcode.select();
   return false;
 }

 if (CheckCurResidence(theForm.a_co_current_residence.options[theForm.a_co_current_residence.selectedIndex].value) == 0 || CheckCurResidence(theForm.a_co_current_residence.options[theForm.a_co_current_residence.selectedIndex].value) == 2) {
   alert('Error: Please select your current residence status.');
   theForm.a_co_current_residence.focus();
   theForm.a_co_current_residence.blur();
   return false;
 }

 if (CheckMonthlyPayment(theForm.a_co_monthly_payment.value) == 0 || CheckMonthlyPayment(theForm.a_co_monthly_payment.value) == 2) {
   alert('Error: Please enter your current monthly payment (rent/mortgage).');
   theForm.a_co_monthly_payment.focus();
   theForm.a_co_monthly_payment.blur();
   theForm.a_co_monthly_payment.select();
   return false;
 }

 if (CheckResLength(theForm.a_co_rentlength.options[theForm.a_co_rentlength.selectedIndex].value) == 0 || CheckResLength(theForm.a_co_rentlength.options[theForm.a_co_rentlength.selectedIndex].value) == 2) {
   alert('Error: Please enter the length of time at your current residence.');
   theForm.a_co_rentlength.focus();
   theForm.a_co_rentlength.blur();
   return false;
 }

 if (CheckHomePhone(theForm.a_co_homephone.value) == 0 || CheckHomePhone(theForm.a_co_homephone.value) == 2) {
   alert('Error: Please enter your home phone number in the proper format.'+"\n\nExample: 123-456-7890");
   theForm.a_co_homephone.focus();
   theForm.a_co_homephone.blur();
   theForm.a_co_homephone.select();
   return false;
 }

 if (CheckEmail(theForm.a_co_emailaddress.value) == 0 || CheckEmail(theForm.a_co_emailaddress.value) == 2) {
   alert('Error: Please enter your email address in the proper format.'+"\n\nExample: user@domain.com");
   theForm.a_co_emailaddress.focus();
   theForm.a_co_emailaddress.blur();
   theForm.a_co_emailaddress.select();
   return false;
 }


 return true;
}


function checkFormFinal() {
 theForm = document.f_contact;

 if (CheckSelfEmployed(theForm.a_selfemployed.options[theForm.a_selfemployed.selectedIndex].value) == 0 || CheckSelfEmployed(theForm.a_selfemployed.options[theForm.a_selfemployed.selectedIndex].value) == 2) {
   alert('Error: Please select whether you are currently self employed.');
   theForm.a_selfemployed.focus();
   theForm.a_selfemployed.blur();
   return false;
 }

 if (CheckCompanyName(theForm.a_emp_company.value) == 0 || CheckCompanyName(theForm.a_emp_company.value) == 2) {
   alert('Error: Please enter your current Employee (Company Name).');
   theForm.a_emp_company.focus();
   theForm.a_emp_company.blur();
   theForm.a_emp_company.select();
   return false;
 }

 if (CheckEmpYears(theForm.a_emp_years.options[theForm.a_emp_years.selectedIndex].value) == 0 || CheckEmpYears(theForm.a_emp_years.options[theForm.a_emp_years.selectedIndex].value) == 2) {
   alert('Error: Please select the length of years at your current employer.');
   theForm.a_emp_years.focus();
   theForm.a_emp_years.blur();
   return false;
 }

 if (CheckIncome(theForm.a_emp_income.options[theForm.a_emp_income.selectedIndex].value) == 0 || CheckIncome(theForm.a_emp_income.options[theForm.a_emp_income.selectedIndex].value) == 2) {
   alert('Error: Please select your current gross income.');
   theForm.a_emp_income.focus();
   theForm.a_emp_income.blur();
   return false;
 }

 if (CheckSelfEmployed2(theForm.a_xselfemployed.options[theForm.a_xselfemployed.selectedIndex].value) == 0 || CheckSelfEmployed2(theForm.a_xselfemployed.options[theForm.a_xselfemployed.selectedIndex].value) == 2) {
   alert('Error: Please select whether you were previously self employed.');
   theForm.a_xselfemployed.focus();
   theForm.a_xselfemployed.blur();
   return false;
 }

 if (CheckCompanyName2(theForm.a_xemp_company.value) == 0 || CheckCompanyName2(theForm.a_xemp_company.value) == 2) {
   alert('Error: Please enter your previous Employee (Company Name).');
   theForm.a_xemp_company.focus();
   theForm.a_xemp_company.blur();
   theForm.a_xemp_company.select();
   return false;
 }

 if (CheckEmpYears2(theForm.a_xemp_years.options[theForm.a_xemp_years.selectedIndex].value) == 0 || CheckEmpYears2(theForm.a_xemp_years.options[theForm.a_xemp_years.selectedIndex].value) == 2) {
   alert('Error: Please select the length of years at your previous employer.');
   theForm.a_xemp_years.focus();
   theForm.a_xemp_years.blur();
   return false;
 }

 if (CheckIncome2(theForm.a_xemp_income.options[theForm.a_xemp_income.selectedIndex].value) == 0 || CheckIncome2(theForm.a_xemp_income.options[theForm.a_xemp_income.selectedIndex].value) == 2) {
   alert('Error: Please select your gross income at your previous employer.');
   theForm.a_xemp_income.focus();
   theForm.a_xemp_income.blur();
   return false;
 }

 if (CheckLoanType(theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value) == 0 || CheckLoanType(theForm.a_loantype.options[theForm.a_loantype.selectedIndex].value) == 2) {
   alert('Error: Please select the loan type.');
   theForm.a_loantype.focus();
   theForm.a_loantype.blur();
   return false;
 }

 if (CheckPriceRange(theForm.a_pricerange.options[theForm.a_pricerange.selectedIndex].value) == 0 || CheckPriceRange(theForm.a_pricerange.options[theForm.a_pricerange.selectedIndex].value) == 2) {
   alert('Error: Please select the price range you are interested in.');
   theForm.a_pricerange.focus();
   theForm.a_pricerange.blur();
   return false;
 }

 if (CheckCurRate(theForm.a_mortgagerate.value) == 0 || CheckCurRate(theForm.a_mortgagerate.value) == 2) {
   alert('Error: Please enter your current mortgages percentage rate.');
   theForm.a_mortgagerate.focus();
   theForm.a_mortgagerate.blur();
   theForm.a_mortgagerate.select();
   return false;
 }

 if (CheckCurBalance(theForm.a_mortbalance.options[theForm.a_mortbalance.selectedIndex].value) == 0 || CheckCurBalance(theForm.a_mortbalance.options[theForm.a_mortbalance.selectedIndex].value) == 2) {
   alert('Error: Please select the balance of your existing mortgage.');
   theForm.a_mortbalance.focus();
   theForm.a_mortbalance.blur();
   return false;
 }

 if (CheckHomeValue(theForm.a_homevalue.options[theForm.a_homevalue.selectedIndex].value) == 0 || CheckHomeValue(theForm.a_homevalue.options[theForm.a_homevalue.selectedIndex].value) == 2) {
   alert('Error: Please select the the value of your home.');
   theForm.a_homevalue.focus();
   theForm.a_homevalue.blur();
   return false;
 }

 if (CheckLoanAmount(theForm.a_loan_amt.value) == 0 || CheckLoanAmount(theForm.a_loan_amt.value) == 2) {
   alert('Error: Please enter the desired loan amount.');
   theForm.a_loan_amt.focus();
   theForm.a_loan_amt.blur();
   theForm.a_loan_amt.select();
   return false;
 }

 if (CheckCredit(theForm.a_current_credit.options[theForm.a_current_credit.selectedIndex].value) == 0 || CheckCredit(theForm.a_current_credit.options[theForm.a_current_credit.selectedIndex].value) == 2) {
   alert('Error: Please select your credit rating.');
   theForm.a_current_credit.focus();
   theForm.a_current_credit.blur();
   return false;
 }



 return true;
}



function setImageStatus() {
	document[setImageStatus.arguments[0]].src = status_images[setImageStatus.arguments[1]]
}


var status_images = new Array('images/fail.gif','images/valid.gif','images/attention.gif','images/spacer.gif')

