function freight_hauled(theForm, theNumber)
{	if ((theForm['commodities_type' + theNumber].value != '') && (theForm['commodities_' + theNumber].value != ''))
	{	if (theForm['commodities_type' + theNumber].value.toLowerCase() == 'general freight' && parseInt(theForm['commodities_' + theNumber].value) > 20)
		{	return true;
		}
	}
	return false;
}

function is_blank(str)
{
	var regex;

	// For our purposes, a null string is blank
	if(str == "")
		return true;
	regex = /[^ +]/;
	if(str.match(regex))
		return false;
	else
		return true;
}

function isValid_email(str)
{	
	apos = str.indexOf("@")
	dotpos = str.lastIndexOf(".")
	
	if (apos < 1 || dotpos-apos < 2)	 
		return true;
	else
		return false;
}

// JavaScript Document
function isdate_valid(str)
{
	var myRegExp = /^[0-1][0-9][\x2F][0-3][0-9][\x2F](19|20)[0-9]{2}$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isValid_zip(str)
{	
	var myRegExp = /^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)?$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isValid_phone(str)
{	
	var myRegExp = /^(\d{10})?$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}
function isValid_localphone(str)
{	
	var myRegExp = /^\d{10}$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isTwo_digits(str)
{	
	var myRegExp = /^\d{0,2}$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isFour_digits(str)
{	
	var myRegExp = /^(\d{4})?$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isValid_cash(str)
{	
	var myRegExp = /^(\d)*$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isValid_coverage(str)
{	
	var myRegExp = /^(\d)*$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function isValid_vin(str)
{	
	var myRegExp = /^([0-9a-zA-Z]{17})?$/;
	if(str.match(myRegExp))
		return false;
	else
		return true;
}

function validation_this(the_form)
{	
	 if(the_form["personal_name"] && is_blank(the_form["personal_name"].value))
	 {
		alert('Please enter Personal Name');
	 	the_form.personal_name.focus();
		the_form.personal_name.select();
		return false;
	 }
	 if(the_form["address_1"] && is_blank(the_form["address_1"].value))
	 {
		alert('Please enter Address 1');
	 	the_form.address_1.focus();
		the_form.address_1.select();
		return false;
	 }
	 if(the_form["postal_code"] && isValid_zip(the_form["postal_code"].value))
	 {
		alert('Please enter correct Postal Code (e.g. M3N 4Y7)');
	 	the_form.postal_code.focus();
		the_form.postal_code.select();
		return false;
	 }
	 if(the_form["phone1"] && isValid_localphone(the_form["phone1"].value + the_form["phone2"].value + the_form["phone3"].value))
	 {
		alert('Please enter correct Phone Number e.g. (416) 123-4567');
	 	the_form.phone1.focus();
		the_form.phone1.select();
		return false;
	 }
	 if(the_form["fax_number1"] && isValid_phone(the_form["fax_number1"].value + the_form["fax_number2"].value + the_form["fax_number3"].value))
	 {
		alert('Please enter correct Fax Number e.g. (416) 123-4567');
	 	the_form.fax_number1.focus();
		the_form.fax_number1.select();
		return false;
	 }
	 if(the_form["cell_phone1"] && isValid_phone(the_form["cell_phone1"].value + the_form["cell_phone2"].value + the_form["cell_phone3"].value))
	 {
		alert('Please enter correct Cell Phone Number e.g. (416) 123-4567');
	 	the_form.cell_phone1.focus();
		the_form.cell_phone1.select();
		return false;
	 }
	 if(the_form["email_address"] && isValid_email(the_form["email_address"].value))
	 {
		alert('Please enter valid E-mail Address');
	 	the_form.email_address.focus();
		the_form.email_address.select();
		return false;
	 }
	 if(the_form["current_previous_policy_number"] && is_blank(the_form["current_previous_policy_number"].value))
	 {
		alert('Please enter Current or previous insurance policy number');
	 	the_form.current_previous_policy_number.focus();
		the_form.current_previous_policy_number.select();
		return false;
	 }
	 if(the_form["driver_age"] && isTwo_digits(the_form["driver_age"].value))
	 {
		alert('one or two digit number allowed in Driver Age field.');
	 	the_form.driver_age.focus();
		the_form.driver_age.select();
		return false;
	 }
	 if(the_form["years_driver_experience"] && isTwo_digits(the_form["years_driver_experience"].value))
	 {
		alert('one or two digit number allowed in Years of Professional Driving Experience field');
	 	the_form.years_driver_experience.focus();
		the_form.years_driver_experience.select();
		return false;
	 }
	 if(the_form["number_claims"] && isTwo_digits(the_form["number_claims"].value))
	 {
		alert('one or two digit member allowed in Number of Claims field');
	 	the_form.number_claims.focus();
		the_form.number_claims.select();
		return false;
	 }
	 if(the_form["vehicle_year"] && isFour_digits(the_form["vehicle_year"].value))
	 {
		alert('Please enter correct four digit Year');
	 	the_form.vehicle_year.focus();
		the_form.vehicle_year.select();
		return false;
	 }
	 
	 if(the_form["cash_value"] && isValid_cash(the_form["cash_value"].value))
	 {
		alert('Please enter correct Actual Cash Value of Equipment (e.g. 23000)');
	 	the_form.cash_value.focus();
		the_form.cash_value.select();
		return false;
	 }
	 if(the_form["vin"] && isValid_vin(the_form["vin"].value))
	 {
		alert('Please enter correct 17 digit VIN');
	 	the_form.vin.focus();
		the_form.vin.select();
		return false;
	 }
	 
	if(the_form["commodities_type1"] && freight_hauled(the_form, 1))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_1.focus();
		the_form.commodities_1.select();
		return false;
	 }
	if(the_form["commodities_type2"] && freight_hauled(the_form, 2))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_2.focus();
		the_form.commodities_2.select();
		return false;
	 }
	if(the_form["commodities_type3"] && freight_hauled(the_form, 3))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_3.focus();
		the_form.commodities_3.select();
		return false;
	 }
	if(the_form["commodities_type4"] && freight_hauled(the_form, 4))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_4.focus();
		the_form.commodities_4.select();
		return false;
	 }
	if(the_form["commodities_type5"] && freight_hauled(the_form, 5))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_5.focus();
		the_form.commodities_5.select();
		return false;
	 }
	if(the_form["commodities_type6"] && freight_hauled(the_form, 6))
	 {
		alert('Please specify commodities in excess of 20% of General Freight');
	 	the_form.commodities_6.focus();
		the_form.commodities_6.select();
		return false;
	 }

 
	 if(the_form["cargo_coverage"] && isValid_coverage(the_form["cargo_coverage"].value))
	 {
		alert('Please enter correct Coverage Limit Required for Cargo (e.g. 1000000)');
	 	the_form.cargo_coverage.focus();
		the_form.cargo_coverage.select();
		return false;
	 }
	//step 2 
	 if(the_form["driver_name"] && is_blank(the_form["driver_name"].value))
	 {
		alert('Please enter Driver\'s Name');
	 	the_form.driver_name.focus();
		the_form.driver_name.select();
		return false;
	 }
	 
	 
	return true;
}