function MM_validateForm1(f)
{
	zip = "" + f.zip.value;
	if (zip.length != 5 || zip.match(/[^0-9]/)) {
		alert('Valid zip code is required:\n');
		return false;
	}

	f.send.value = "Submitting Request";
	f.action = MT_URL + "HC03/store_click.asp";
	return true;
}


function MM_validateForm2(f) 
{
	errors = "";

	MM = (f.BirthMonth);
	DD = (f.BirthDay);
	YY = (f.BirthYear);
	zip = f.Zip.value;
	weight = f.Weight.value;

	HP = f.HomePhoneArea.value + f.HomePhoneFirst.value + f.HomePhoneLast.value;
	WP = f.WorkPhoneArea.value + f.WorkPhoneFirst.value + f.WorkPhoneLast.value

	errors += CheckField((f.FirstName.value), 'FirstName',0,2);
	errors += CheckField((f.LastName.value), 'LastName',0,2);	
	errors += CheckField((f.Address.value),'Address',0,5);

	if (!HP.match(/[0-9]{10}/))
		errors += " - Valid home phone is required\n";
	if (!WP.match(/[0-9]{10}/))
		errors += "- Valid work phone is required\n";
	if (!valid_email(f.Email.value))
		errors += "- Valid email is required\n";

	if (zip.length != 5 || zip.match(/[^0-9]/))
	            errors += "- Zip code is required\n";

	if (weight.length <= 2 || weight.match(/[^0-9]/))
	            errors += "- Valid weight is required\n";

	if (MM[MM.selectedIndex].value == "" || DD[DD.selectedIndex].value == "" || YY[YY.selectedIndex].value == "") errors += "- Date of birth is required\n";
	else if(!checkAge(DD[DD.selectedIndex].value, MM[MM.selectedIndex].value, YY[YY.selectedIndex].value))errors += "- Based on the information you provided, we are unable to provide you with an online quote at this time.\n";	
	if (errors) {
		alert('Please validate the following fields before continuing:\n\n'+errors);
		return false;
	} else {
		f.send.value = "Submitting Request";
		f.action = MT_URL + "HC03/STP1_1.asp";
		return true;
	}
}

function MM_validateForm3(f) 
{
	errors = "";

	insured_with = 	"" + f.INSURED_WITH.value;
	deductible = 	"" + f.AMOUNT_DEDUCTIBLE.value;
	copay = 	"" + f.AMOUNT_COPAY.value;
	conditions =  (f.precondition.value == 1) ? "" + f.CONDITIONS_EXPLANATION.value : "";
	covered = 	"" + f.CURRENTLY_COVERED.value;
	
	if (f.precondition.value == 1 && !conditions.match(/[A-Za-z]{3,}/))
		errors += "- Please detail your medical conditions\n";

	if (covered == 1 && !insured_with.match(/[A-Za-z]{2,}/))
		errors += "- Insured With is required\n";

	if (deductible == "")
		errors += "- Deductible amount is required\n";
	else if (deductible.match(/[^0-9]/))
		errors += "- Deductible amount requires only numeric characters.\n";
	else if (deductible.length > 5)
		errors += "- Deductible amount must be less than 6 characters.\n";
	

	if (copay == "")
		errors += "- Co-pay is required\n";
	else if (copay.match(/[^0-9]/))
		errors += "- Co-pay requires only numeric characters.\n";
	else if (copay.length > 3)
		errors += "- Co-pay must be less than 4 characters.\n";

	if (errors) {
		alert('Please validate the following fields before continuing:\n\n' + errors);
		return false;
	} else {
		f.action = MT_URL + "HC03/STP2.asp";
		return true;
	}
}

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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkAge(day, month, year){
	var min_age = 18;
	var theirDate = new Date(year, (month-1), day);
	var today = new Date;
	timeold = (today.getTime() - theirDate.getTime());
    msPerYear = 24 * 60 * 60 * 1000 * 365;         		
	yearold = Math.floor(timeold / msPerYear);  
	if (yearold < min_age) return false;
	else return true;
}

function CheckField(TheValue, Type, CheckType, Length)
{
	var tempcheck = 1;var ponerror="";

	if (TheValue.length < Length ) {
		ponerror += "- " + Type +" does not contain enough characters.\n";
	}

	return ponerror;
}

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 change_visibility()
{
	var row;
	
	row = document.getElementById('table1');
	row.style.display = (row.style.display == 'none') ? 'block':'none';
}

function select_item(s, item)
{
	for (i=0; i<s.options.length; i++)
		if (s.options[i].value == item ) {
			s.selectedIndex = i;
			break;
		}
}

