function MM_validateForm1(f)
{
	zip = "" + f.zip.value;

	errors = "";
	
	if (zip.length < 5 || zip.match(/[^0-9]/)) {
		errors += 'Valid zip code is required\n';

	if (f.LoanType.value == "select")
		errors  += "Please select a loan type\n";

	if (errors != "")
		alert("Please validate the following fields before continuing:\n\n" + errors);
		document.MM_returnValue = (errors == '');		
		return false;
	} else {
		document.MM_returnValue = (errors == '');		
		
		if(f.LoanType.value != "Purchase")
			f.action = MT_URL + "MC04/STP1_HSU.asp?up=1"
		else
			f.action = "purchase.asp?zip=" + zip;		
			
		return true;
	}
}

function MM_validateForm2(f)
{
	var errors = "";


	income		= "" + f.Income.value;
	debt		= "" + f.MonthlyDebt.value;

	first_name 	= "" + f.FirstName.value;
	last_name  	= "" + f.LastName.value;
	address 	= "" + f.Address.value;
	city 		= "" + f.City.value;

	email		= "" + f.Email.value;
	
	home_phone	= "" + f.HomePhoneArea.value + f.HomePhoneFirst.value + f.HomePhoneLast.value;
	work_phone	= "" + f.WorkPhoneArea.value + f.WorkPhoneFirst.value + f.WorkPhoneLast.value;
	//ext_phone 	= "" + f.WorkPhoneExt.value;

	

	if (!first_name.match(/[A-Za-z]{1,}/))		
		errors += "First Name is required\n";

	if (!last_name.match(/[A-Za-z]{1,}/))		
		errors += "Last Name is required\n";

	if (!address.match(/[A-Za-z0-9]{3,}/))
		errors += "Address is required\n";

	if (!city.match(/[A-Za-z]{3}/))
		errors += "City is required\n";

	if (f.State.value == "")
		errors += "Please select a state\n";

	if (!home_phone.match(/[0-9]{10}/))	
		errors += "Valid Home Phone is required\n";

	if (work_phone != "" && !work_phone.match(/[0-9]{10}/))	
		errors += "Valid Work Phone is required\n";	
		
	if (!valid_email(email))
		errors += "Valid Email Address is required\n";

	if (f.Credit.value == "")
		errors += "Please select your Credit History\n";

	if (f.WorkStatus.value == "")
		errors += "Please indicate your work status\n";

	//if (income == "")
	//	errors += "Gross Monthly Income is required\n";

	//if (debt == "")
	//	errors += "Total Monthly Debt is required\n";

	if (f.EstimatedValue.value == "")
		errors += "Please select Estimate Value\n";

	if (f.PropertyType.value == "")
		errors += "Please select Property Type\n";

	if (f.PropertyUse.value == "")
		errors += "Please select Property Use\n";

	//if (f.PropertyState.value == "")
	//	errors += "Please select the State where the property is located\n";

	//if (f.PropertyZip.value == "")
	//	errors += "Please indicate the property zip code.\n";
		
	if (f.FirstBalance.value == "")
		errors += "Please indicate the first balance\n";

	if (f.FirstRate.value == "")
		errors += "Please indicate the first mortgage rate\n";

	if (f.FirstType.value == "")
		errors += "Please indicate the first mortgage type\n";
		
	//if (f.PurchaseYear.value == "")
	//	errors += "Please indicate the purchase year\n";		

	if (f.SecondBalance.value == "")
		errors += "Please indicate the second balance\n";

	if (f.SecondRate.value == "")
		errors += "Please indicate the second mortgage rate\n";

	if (f.LoanAmount.value == "")
		errors += "Please select Loan Amount\n";
/*		*/
	if (f.Purpose.value == "")
		errors += "Please select purpose for the refinance\n";


	if (errors) {
		alert('Please validate the following fields before continuing:\n\n' + errors);
		document.MM_returnValue = (errors == '');		
	} else {
		f.action = MT_URL + "MC04/STP2_HSU.asp?up=1";
		document.MM_returnValue = (errors == '');
	}
}

// 09.10.1007 updates
function MM_validateForm3(f)
{
	var errors = "";


	income		= "" + f.Income.value;
	debt		= "" + f.MonthlyDebt.value;

	first_name 	= "" + f.FirstName.value;
	last_name  	= "" + f.LastName.value;
	address 	= "" + f.Address.value;
	city 		= "" + f.City.value;

	email		= "" + f.Email.value;
	
	home_phone	= "" + f.HomePhoneArea.value + f.HomePhoneFirst.value + f.HomePhoneLast.value;
	work_phone	= "" + f.WorkPhoneArea.value + f.WorkPhoneFirst.value + f.WorkPhoneLast.value;
	//ext_phone 	= "" + f.WorkPhoneExt.value;

	

	if (!first_name.match(/[A-Za-z]{1,}/))		
		errors += "First Name is required\n";

	if (!last_name.match(/[A-Za-z]{1,}/))		
		errors += "Last Name is required\n";

	if (!address.match(/[A-Za-z0-9]{3,}/))
		errors += "Address is required\n";

	if (!city.match(/[A-Za-z]{3}/))
		errors += "City is required\n";

	if (f.State.value == "")
		errors += "Please select a state\n";

	if (!home_phone.match(/[0-9]{10}/))	
		errors += "Valid Home Phone is required\n";

	if (work_phone != "" && !work_phone.match(/[0-9]{10}/))	
		errors += "Valid Work Phone is required\n";	
		
	if (!valid_email(email))
		errors += "Valid Email Address is required\n";

	if (f.Credit.value == "")
		errors += "Please select your Credit History\n";

	if (f.WorkStatus.value == "")
		errors += "Please indicate your work status\n";

	//if (income == "")
	//	errors += "Gross Monthly Income is required\n";

	//if (debt == "")
	//	errors += "Total Monthly Debt is required\n";

	if (f.EstimatedValue.value == "")
		errors += "Please select Estimate Value\n";

	if (f.PropertyType.value == "")
		errors += "Please select Property Type\n";

	if (f.PropertyUse.value == "")
		errors += "Please select Property Use\n";

	//if (f.PropertyState.value == "")
	//	errors += "Please select the State where the property is located\n";

	//if (f.PropertyZip.value == "")
	//	errors += "Please indicate the property zip code.\n";
		
	if (f.FirstBalance.value == "")
		errors += "Please indicate the first balance\n";

	if (f.FirstRate.value == "")
		errors += "Please indicate the first mortgage rate\n";

	if (f.FirstType.value == "")
		errors += "Please indicate the first mortgage type\n";
		
	//if (f.PurchaseYear.value == "")
	//	errors += "Please indicate the purchase year\n";		

	if (f.SecondBalance.value == "")
		errors += "Please indicate the second balance\n";

	if (f.SecondRate.value == "")
		errors += "Please indicate the second mortgage rate\n";

	if (f.CashOut.value == "")
		errors += "Please select Additional Cash To Borrow\n";
/*		*/
	if (f.Purpose.value == "")
		errors += "Please select purpose for the refinance\n";


	if (errors) {
		alert('Please validate the following fields before continuing:\n\n' + errors);
		document.MM_returnValue = (errors == '');		
	} else {
		f.action = MT_URL + "MC04/STP2_HSU2.asp?up=1";
		document.MM_returnValue = (errors == '');
	}
}


function valid_email(val) 
{  
	if (val.search(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$/) > -1 )
		return true;
	else
		return false;
} 


function MM_openBrWindow(theURL,winName,features)
{  
	window.open(theURL, winName, features);
}


function show(nr)
{
	if (document.layers){
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all){
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById){
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}


function generate_values(select, default_value, first, last)
{
	for (i=0; i<=last-first; i++) {
		select.options[i+1] = new Option(i+first, i+first);
	
		if (i+first == default_value)		
			select.selectedIndex = i+1;
	}
}

function select_item(s, item) 
{
	for (i=0; i<s.options.length; i++)
		if (s.options[i].value == item ) {
			s.selectedIndex = i;
			break;
		}
}

