

function Validate_contact(contact_form) 
{
    var err = "";

    err += check_name(trim(contact_form.name.value), true);
    err += check_email(trim(contact_form.email.value), true);
   
	var found_it = "no";

	for (var i=0; i<contact_form.msg_type.length; i++)  {
		if (contact_form.msg_type[i].checked)  {
			found_it = "yes";
		}
		
	}   
	if ("no" == found_it)
	{
		err += "What type of comment are you sending: must be selected \n";
	}
	
   
 	err += check_looking_for(trim(contact_form.looking_for.value), true);
  //   err += check_comments(trim(contact_form.comments.value), true);
  //   err += check_phone(trim(contact_form.phone), false);
  //   err += check_fax(trim(contact_form.fax), false);
	 err += check_code(trim(contact_form.code.value), true);
	 
	
	 
    if (err != "") {
    	var error_msg = "The following fields had errors, please change them and submit the form again.\n\n";
        alert(error_msg + err);
        return false;
    }
	return true;
}


function Validate_media(media_contact) 
{
    var err = "";
	
    err += check_name(trim(media_contact.name.value), true);
    err += check_email(trim(media_contact.email.value), true);
    err += check_inquirey(trim(media_contact.inquirey.value), true);
	err += check_code(trim(media_contact.code.value), true);
	 
	
	 
    if (err != "") {
    	var error_msg = "The following fields had errors, please change them and submit the form again.\n\n";
        alert(error_msg + err);
        return false;
    }
	return true;
}

function Validate_experts(ask_experts) 
{
    var err = "";
	
    //err += check_name(trim(ask_experts.experts.value), true);
    err += check_fname(trim(ask_experts.first_name.value), true);
    err += check_lname(trim(ask_experts.last_name.value), true);
    err += check_email(trim(ask_experts.email.value), true);
    err += check_comments(trim(ask_experts.comments.value), true);
	err += check_code(trim(ask_experts.code.value), true);
	 
	
	 
    if (err != "") {
    	var error_msg = "The following fields had errors, please fix and submit the form again.\n\n";
        alert(error_msg + err);
        return false;
    }
	return true;
}

function check_msg_type()
{



}

function check_looking_for (str, bReq) {
	var error = "";
	if (str == "" && bReq) {
    	error = "I am looking for: can't be blank.\n";
    }
  
    return error;
}
function check_name (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Name: can't be blank. \n";
    }
    else if (!isAlpha(str))
    {
    	error = "Name: You can only enter letters for this field.\n";
    }
    return error;
}
function check_fname (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "First Name: can't be blank. \n";
    }
    else if (!isAlpha(str))
    {
    	error = "First Name: You can only enter letters for this field.\n";
    }
    return error;
}
function check_lname (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Last Name: can't be blank. \n";
    }
    else if (!isAlpha(str))
    {
    	error = "Last Name: You can only enter letters for this field.\n";
    }
    return error;
}
function check_email (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Email: can't be blank. \n";
    }
    else if (!isEmail(str) && str != "")
    {
    	error = "Email: You didn't enter a valid email address.\n";
    }
    return error;
}
function check_msg_type (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "What kind of comment are you sending: can't be blank. \n";
    }
 
    return error;
}
function check_comments (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Comments: can't be blank. \n";
    }
    
    return error;
}
function check_inquirey (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Inquirey: can't be blank. \n";
    }
    
    return error;
}
function check_phone (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Telephone: can't be blank. \n";
    }

    return error;
}
function check_fax (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Last name: can't be blank. \n";
    }

    return error;
}
function check_code (str, bReq) {
 	var error = "";
 	if (str == "" && bReq) {
    	error = "Verify Text: can't be blank. \n";
    }
    
    return error;
}
function autoTab(element, nextElement) 
{
    if (element.value.length == element.maxLength && nextElement != null) {
        element.form.elements[nextElement].focus();
    }
}

// check to see if input is alphanumeric
function isAlphaNumeric(str)
{
	if (str.match(/^[a-zA-Z0-9 \-.,]+$/))
	{
		return true;
	}
	else
	{
		return false;
	} 
}
// check to see if input is alpha
function isAlpha(str)
{
	if (str.match(/^[a-zA-Z \-.,]+$/))
	{
		return true;
	}
	else
	{
		return false;
	} 
}
// check to see if input is a zip code
function isZip(str)
{
	if (str.match(/^[0-9]+$/) && (str.length == 5 || str.length == 9))
	{
		return true;
	}
	else
	{
		return false;
	} 
}
function isEmail(str)
{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	
   	// search email text for regular exp matches
   	if (str.search(validRegExp) == -1) 
   	{	 
   		return false;
    }
	if (str.match(illegalChars)) {
		return false;
	}
	
	return true;
}
function trim(s)
{
	return rtrim(ltrim(s));
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function rtrim(s)
{
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{	r-=1;	}
	return s.substring(0, r+1);
}

//-->

