// Javascript
// Form validation script

function calcTotal(field) 
{
	var val = field.value;
	var name = field.name;
	var type = name.substring(0,4);
	val = parseInt(val);
		
	if ( isNaN(val) ) 
	{
		val = 0;
		setTimeout('document.proposal.'+name+'.value='+val+';',0);
		alert("You must enter a number only.");
		setTimeout('document.proposal.'+name+'.value=\'\';',0);
		setTimeout('document.proposal.'+name+'.focus();',0);
	}
	else 
	{
		setTimeout('document.proposal.'+name+'.value = '+val+';',0);
		setTotal(type);
	}
}

function setTotal(total_type)
{
	if (total_type = 'day1') 
	{
		document.proposal.day1_total.value = 0;
		document.proposal.day1_total.value = eval(parseInt(document.proposal.day1_single.value) + parseInt(document.proposal.day1_double.value) + parseInt(document.proposal.day1_suite.value) + parseInt(document.proposal.day1_other.value));
	}
	
	if (total_type = 'day2') 
	{
		document.proposal.day2_total.value = 0;
		document.proposal.day2_total.value = eval(parseInt(document.proposal.day2_single.value) + parseInt(document.proposal.day2_double.value) + parseInt(document.proposal.day2_suite.value) + parseInt(document.proposal.day2_other.value));
	}
	
	if (total_type = 'day3') 
	{
		document.proposal.day3_total.value = 0;
		document.proposal.day3_total.value = eval(parseInt(document.proposal.day3_single.value) + parseInt(document.proposal.day3_double.value) + parseInt(document.proposal.day3_suite.value) + parseInt(document.proposal.day3_other.value));
	}
	
	if (total_type = 'day4') 
	{
		document.proposal.day4_total.value = 0;
		document.proposal.day4_total.value = eval(parseInt(document.proposal.day4_single.value) + parseInt(document.proposal.day4_double.value) + parseInt(document.proposal.day4_suite.value) + parseInt(document.proposal.day4_other.value));
	}
	
	if (total_type = 'day5') 
	{
		document.proposal.day5_total.value = 0;
		document.proposal.day5_total.value = eval(parseInt(document.proposal.day5_single.value) + parseInt(document.proposal.day5_double.value) + parseInt(document.proposal.day5_suite.value) + parseInt(document.proposal.day5_other.value));
	}
}

function resetValue(field) 
{
	var newVal = field.value;
	var name = field.name;
	
	if ( newVal == '') 
	{
		newVal = 0;
		setTimeout('document.proposal.'+name+'.value='+newVal+';',0);
	}
}

var date = new Date();
curYear = date.getFullYear();
var endYear = curYear + 20;

function validateForm(frm) 
{
	var validData = true;

	if ( BlankField(frm.first_name.value) ) 
	{
		alert("You must enter your first name");
		frm.first_name.value = "";
		frm.first_name.focus();
		validData = false;
	}
	else if ( BlankField(frm.last_name.value) ) 
	{
		alert("You must enter your last name");
		frm.last_name.value = "";
		frm.last_name.focus();
		validData = false;
	}
	else if ( BlankField(frm.phone.value) || frm.phone.value.length < 10 ) 
	{
		alert("You must enter your phone number and area code");
		frm.phone.value = "";
		frm.phone.focus();
		validData = false;
	}
	else if ( BlankField(frm.email.value) ) 
	{
		alert("You must enter your email address");
		frm.email.value = "";
		frm.email.focus();
		validData = false;
	}
	else if ( !ValidEmail(frm.email.value) ) 
	{
		alert("Please enter a valid email address");
		frm.email.value = "";
		frm.email.focus();
		validData = false;
	}
	else if ( !BlankField(frm.arr_month.value) && ( ( frm.arr_month.value%1 != 0 ) || ( parseInt(frm.arr_month.value) < 1 ) || ( parseInt(frm.arr_month.value) > 12 ) ) ) 
	{
		alert("You must enter a valid month number for the arrival month");
		frm.arr_month.value = "";
		frm.arr_month.focus();
		validData = false;
	}
	else if ( !BlankField(frm.arr_day.value) && ( ( frm.arr_day.value%1 != 0 ) || ( parseInt(frm.arr_day.value) < 1 ) || ( parseInt(frm.arr_day.value) > 31 ) ) ) 
	{
		alert("You must enter a valid day number for the arrival day");
		frm.arr_day.value = "";
		frm.arr_day.focus();
		validData = false;
	}
	else if ( !BlankField(frm.arr_year.value) && ( ( frm.arr_year.value%1 != 0 ) || ( parseInt(frm.arr_year.value) < curYear ) || ( parseInt(frm.arr_year.value) > endYear ) ) ) 
	{
		alert("You must enter a valid year for the arrival year");
		frm.arr_year.value = "";
		frm.arr_year.focus();
		validData = false;
	}
	else if ( !BlankField(frm.dep_month.value) && ( ( frm.dep_month.value%1 != 0 ) || ( parseInt(frm.dep_month.value) < 1 ) || ( parseInt(frm.dep_month.value) > 12 ) ) ) 
	{
		alert("You must enter a valid month number for the departure month");
		frm.dep_month.value = "";
		frm.dep_month.focus();
		validData = false;
	}
	else if ( !BlankField(frm.dep_day.value) && ( ( frm.dep_day.value%1 != 0 ) || ( parseInt(frm.dep_day.value) < 1 ) || ( parseInt(frm.dep_day.value) > 31 ) ) ) 
	{
		alert("You must enter a valid day number for the departure day");
		frm.dep_day.value = "";
		frm.dep_day.focus();
		validData = false;
	}
	else if ( !BlankField(frm.dep_year.value) && ( ( frm.dep_year.value%1 != 0 ) || ( parseInt(frm.dep_year.value) < curYear ) || ( parseInt(frm.dep_year.value) > endYear ) ) ) 
	{
		alert("You must enter a valid year for the departure year");
		frm.dep_year.value = "";
		frm.dep_year.focus();
		validData = false;
	}
	else if ( !BlankField(frm.space1_people.value) && ( ( frm.space1_people.value%1 != 0 ) || ( parseInt(frm.space1_people.value) < 1 ) ) ) 
	{
		alert("You must enter a number only for the number of people expected for event 1");
		frm.space1_people.value = "";
		frm.space1_people.focus();
		validData = false;
	}
	else if ( !BlankField(frm.space2_people.value) && ( ( frm.space2_people.value%1 != 0 ) || ( parseInt(frm.space2_people.value) < 1 ) ) ) 
	{
		alert("You must enter a number only for the number of people expected for event 2");
		frm.space2_people.value = "";
		frm.space2_people.focus();
		validData = false;
	}
	else if ( !BlankField(frm.space3_people.value) && ( ( frm.space3_people.value%1 != 0 ) || ( parseInt(frm.space3_people.value) < 1 ) ) ) 
	{
		alert("You must enter a number only for the number of people expected for event 3");
		frm.space3_people.value = "";
		frm.space3_people.focus();
		validData = false;
	}
	else if ( !BlankField(frm.space4_people.value) && ( ( frm.space4_people.value%1 != 0 ) || ( parseInt(frm.space4_people.value) < 1 ) ) ) 
	{
		alert("You must enter a number only for the number of people expected for event 4");
		frm.space4_people.value = "";
		frm.space4_people.focus();
		validData = false;
	}
	else if ( !BlankField(frm.space5_people.value) && ( ( frm.space5_people.value%1 != 0 ) || ( parseInt(frm.space5_people.value) < 1 ) ) ) 
	{
		alert("You must enter a number only for the number of people expected for event 5");
		frm.space5_people.value = "";
		frm.space5_people.focus();
		validData = false;
	}
	else if ( frm.other_req.checked == true && BlankField(frm.require_other.value) ) 
	{
		alert("Please tell us your other response requirement");
		frm.require_other.focus();
		validData = false;
	}
	else if ( frm.contact_via[1].checked == true && BlankField(frm.fax.value) ) 
	{
		alert("Please tell us your fax number if you would like us to respond via fax");
		frm.fax.focus();
		validData = false;
	}
	else if ( frm.contact_via[1].checked == true && frm.fax.value.length < 10 ) 
	{
		alert("Please enter a valid fax number including area code");
		frm.fax.value = "";
		frm.fax.focus();
		validData = false;
	}
	else if ( (frm.contact_via[3].checked == true || frm.contact_via[4].checked) && BlankField(frm.address1.value) ) 
	{
		alert("Please tell us your address if you would like us to respond via mail");
		frm.address1.focus();
		validData = false;
	}
	else if ( (frm.contact_via[3].checked == true || frm.contact_via[4].checked) && BlankField(frm.city.value) ) 
	{
		alert("Please tell us your city if you would like us to respond via mail");
		frm.city.focus();
		validData = false;
	}
	else if ( (frm.contact_via[3].checked == true || frm.contact_via[4].checked) && BlankField(frm.state.value) ) 
	{
		alert("Please tell us your state if you would like us to respond via mail");
		frm.state.focus();
		validData = false;
	}
	else if ( (frm.contact_via[3].checked == true || frm.contact_via[4].checked) && BlankField(frm.zip.value) ) 
	{
		alert("Please tell us your zip code if you would like us to respond via mail");
		frm.zip.focus();
		validData = false;
	}
	else if ( frm.contact_via[5].checked == true && BlankField(frm.respond_other.value) ) 
	{
		alert("Please tell us your alternate response method");
		frm.respond_other.focus();
		validData = false;
	}

	return validData;
}
