
function validate_form(obj_form) {
	obj_form.message.value = trim ( obj_form.message.value );
	obj_form.first_name.value = trim ( obj_form.first_name.value );
	obj_form.last_name.value = trim ( obj_form.last_name.value );
	obj_form.phone.value = trim ( obj_form.phone.value );
	obj_form.email.value = trim ( obj_form.email.value );
	
	if ( obj_form.purpose [ 0 ].selected ) {	
		obj_form.purpose.focus ();
		alert("Purpose of Message is a required field.");
		return false;
	}
	if ( obj_form.message.value == "" ) {	
		obj_form.message.focus ();
		alert("Message is a required field.");
		return false;
	}	else if ( obj_form.message.value.length > 2000 ) {	
		obj_form.message.focus ();
		alert("Message can only be 2000 charcters long.");
		return false;
	}
	if ( obj_form.purpose [ 1 ].selected ) {
		obj_form.company_name.value = trim ( obj_form.company_name.value );
		if ( obj_form.company_name.value == "" ) {	
			obj_form.company_name.focus ();
			alert("Company Name is a required field.");
			return false;
		}
	}
	if ( obj_form.name_title [ 0 ].selected ) {	
		obj_form.name_title.focus ();
		alert("Name Title is a required field.");
		return false;
	}
	if ( obj_form.first_name.value == "" ) {	
		obj_form.first_name.focus ();
		alert("First Name is a required field.");
		return false;
	}
	if ( obj_form.last_name.value == "" ) {	
		obj_form.last_name.focus ();
		alert("Last Name is a required field.");
		return false;
	}
	if ( obj_form.zip.value == "" ) {	
		obj_form.zip.focus ();
		alert("Zip/Postal Code is a required field.");
		return false;
	}
	if ( obj_form.country [ 0 ].selected ) {	
		obj_form.country.focus ();
		alert("Country is a required field.");
		return false;
	}
	if ( obj_form.country [ 1 ].selected ) {	
		if ( obj_form.state [ 0 ].selected ) {	
			obj_form.state.focus ();
			alert("State is a required field.");
			return false;
		}
	}
	if ( obj_form.country [ 2 ].selected ) {	
		if ( obj_form.province [ 0 ].selected ) {	
			obj_form.province.focus ();
			alert("Province is a required field.");
			return false;
		}
	}
	if ( obj_form.purpose [ 1 ].selected ) {
		if ( obj_form.phone_type [ 0 ].selected ) {	
			obj_form.phone_type.focus ();
			alert("Phone Type is a required field.");
			return false;
		}	
		if ( obj_form.phone.value == "" ) {	
			obj_form.phone.focus ();
			alert("Phone Number is a required field.");
			return false;
		} else {
			if (!isPhoneNumber(obj_form.phone.value)) {
				alert("Please provide a valid Phone Number.");
				obj_form.phone.focus();
				return false;
			}
		}
	}
	if ( obj_form.email.value == "" ) {	
		obj_form.email.focus ();
		alert("E-mail is a required field.");
		return false;
	} else {
		if (!isEmail(obj_form.email.value)) {
			alert("Please provide a valid Email Address.");
			obj_form.email.focus();
			return false;
		}
	}
	
	if ( obj_form.email.value != obj_form.confirm_email.value  ) {	
		obj_form.confirm_email.focus ();
		alert("Email and Confirmation do not match.");
		return false;
	}
	
	return true;
}

function checkforMSDS(obj) {
	var company_name = document.getElementById('company_name');
	var company_name_star = document.getElementById('company_name_star');
	var company_name_field = document.getElementById('company_name_field');
	var phone_type_star = document.getElementById('phone_type_star');
	var phone_number_star = document.getElementById('phone_number_star');

	if ( obj.options[obj.selectedIndex].value == "MSDS Requests" ) {	
		company_name.style.visibility = "visible";
		company_name_field.style.visibility = "visible";
		company_name_star.style.visibility = "visible";
		phone_type_star.style.visibility = "visible";
		phone_type_star.style.position = "";
		phone_number_star.style.visibility = "visible";
		phone_number_star.style.position = "";

	} else { 
		company_name.style.visibility = "hidden";
		company_name_field.style.visibility = "hidden";
		company_name_star.style.visibility = "hidden";
		phone_type_star.style.visibility = "hidden";
		phone_type_star.style.position = "absolute";
		phone_number_star.style.visibility = "hidden";
		phone_number_star.style.position = "absolute";
	}
}

function checkCountry(obj) {
	var state_name = document.getElementById('state_name');
	var state_options = document.getElementById('state_options');
	var prov_name = document.getElementById('prov_name');
	var prov_options = document.getElementById('prov_options');
	
	
	var state_star = document.getElementById('state_star');
	//prov_options.style.visibility = 'visible';
	if ( obj.options[obj.selectedIndex].value == "USA" ) {	
		//alert('in1');
		prov_options.style.visibility = "hidden";
		prov_name.style.visibility = "hidden";
		prov_options.style.position = "absolute";
		prov_name.style.position = "absolute";
		
		state_star.style.visibility = "visible";
		
		state_name.style.visibility = "visible";
		state_name.style.position = "static";
		state_options.style.visibility = "visible";
		state_options.style.position = "static";
	} else { 
		if ( obj.options[obj.selectedIndex].value == "CAN" ) {	
			
			state_name.style.visibility = "hidden";
			state_options.style.visibility = "hidden";
			state_name.style.position = "absolute";
			state_options.style.position = "absolute";
			
			prov_name.style.visibility = "visible";
			prov_options.style.visibility = "visible";
			prov_name.style.position = "static";
			prov_options.style.position = "static";
			state_star.style.visibility = "visible";
		} else { 
			//alert('in3');
			prov_name.style.visibility = "hidden";
			prov_options.style.visibility = "hidden";
			prov_options.style.position = "absolute";
			prov_name.style.position = "absolute";
			
			state_name.style.visibility = "hidden";
			state_options.style.visibility = "hidden";
			state_options.style.position = "absolute";
			state_name.style.position = "absolute";
			state_star.style.visibility = "hidden";
		}
	}
}

function init() {
	checkCountry(document.consumer.country);
	checkforMSDS(document.consumer.purpose);
}

