 // JavaScript Document	

//Validate All Quote Form Fields and Submit Quote Form if Validation Passes
/*******************************************************
FUNCTION: 	ValidateForm
ARGS: 		none
PURPOSE: 	tests if form input is valid
RETURNS: 	
*******************************************************/
function val_and_submit_contact_form() {
    var field_err_msg = "";
	var email_valid_code = "0";
	var tel_valid_code = "0";
	var input_msg = "";
	var you_are = "no";
	
	/* DEFINE THE FORM VARIABLES TO TEST */
	var the_name = document.contact_form.the_name.value;
	var co_name = document.contact_form.co_name.value;
	var the_email = document.contact_form.the_email.value;
	var tel = document.contact_form.tel.value;
	var notes = document.contact_form.notes.value;
	var contact_me_by = getCheckedValue(document.contact_form.rb_contact);
	
	//alert(contact_me_by);
	//return;
	
	/* TEST THE INDIVIDUAL FORM FIELDS FOR VALID INPUT */
    if (the_name.length == 0)
		field_err_msg = field_err_msg + "NAME (required).\n";
	    email_valid_code = test_email(the_email);

	tel_valid_code = test_tel(tel);
	if (tel_valid_code != "0")
		field_err_msg = field_err_msg + "TEL (required) must be a valid phone number.\n";
	if (email_valid_code != "0")
		field_err_msg = field_err_msg + "EMAIL (required) must be a valid email address.\n";
	if (notes.length == 0)
		field_err_msg = field_err_msg + "REMARK (required).\n";
		
	if (field_err_msg.length > 0)  {
		err_msg = "Please correct the following field(s).\n";
		err_msg = err_msg + "---------------\n";
		err_msg = err_msg + field_err_msg;
		alert(err_msg);
	}
	//VALIDATION PASSED - EMAIL THE FORM
	else {
		var the_page;
		the_page = "mailer.asp";
		var the_form;
		the_form = "contact";
		var the_args;
		the_args = "?the_form=" + the_form + "&the_name=" + the_name + "&co_name=" + co_name +  "&tel=" + tel + "&the_email=" + the_email + "&contact_me_by=" + contact_me_by + "&notes=" + notes;
		document.contact_form.action="mailer.asp" + the_args;
		document.contact_form.submit();
	}
}
