function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		}
		else {
			return true;
		}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

function check_phone_number(field,alerttxt) {

  /* Set whether the user should use a -, a space, or one long number without divisions.
     Use the following values to set:
	 1 = Use - (i.e 123-456-7890)
	 2 = Use a space (i.e. 123 456 7890)
	 3 = Use none (i.e. 1234567890)
  */	 
  var num_division = 1;
  
  with (field) {	
    
	var phone_num_OK = false; 
	var the_delim = "";
	var the_ph_test = "";
	var ph_err_msg ="";
    var the_phone_num = value;
	
	if (num_division == 1) {
		the_delim = "-";
		the_ph_test = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
	   	phone_num_OK = the_ph_test.test(the_phone_num);
	}
	else if (num_division == 2) {
		the_delim = " ";
		the_ph_test = /^[0-9]{3} [0-9]{3} [0-9]{4}$/;
	    phone_num_OK = the_ph_test.test(the_phone_num);
	}
	else if (num_division == 3) {
		the_delim = "";
		the_ph_test = /^[0-9]{10}$/;
	    phone_num_OK = the_ph_test.test(the_phone_num);
	}
	else {
		return false;	
	}
	
    if (phone_num_OK) {
	  return true;	
	}
	else {
		alert(alerttxt);
	    return false;
	}
	
  }
  
}

function validate_form(thisform) {
	with (thisform) {
		if (validate_required(Subject,"Please specify a Subject!")==false) {
			Subject.focus();
			return false;
		}
		if (validate_required(Name,"Please specify your name!")==false) {
			Name.focus();
			return false;
		}
		if (validate_required(Email,"Email must be filled out!")==false) {
			Email.focus();
			return false;
		}
		if (validate_email(Email,"Not a valid e-mail address!")==false) {
			Email.focus();
			return false;
		}
		if (check_phone_number(Phone,"Phone format: 123-456-7890")==false) {
			Phone.focus();
			return false;
		}
	

	}
}

