// form validation

function checkFormDetails(contactus) {
	var why = "";

	why += isEmpty(contactus.name.value, "NAME");
    if (why != "") {
       alert(why);
		contactus.name.focus();
       return false;
    }
	why += checkEmail(contactus.email.value, "EMAIL ADDRESS");
    if (why != "") {
       alert(why);
		contactus.email.focus();
       return false;
    }
	why += checkDropdown(contactus.state.selectedIndex, "STATE");
    if (why != "") {
       alert(why);
		contactus.state.focus();
       return false;
    }
	why += isEmpty(contactus.query.value, "COMMENT");
    if (why != "") {
       alert(why);
		contactus.query.focus();
       return false;
    }

return true;
}


// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// non-empty textbox

function isEmpty(strng, fldName) {
var error = "";
  if (strng.length == 0) {
     error = "The " + fldName + " field has not been filled in.\n"
  }
return error;	  
}


// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice, fldName) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the " + fldName + " drop-down list.\n";
    }    
return error;
}    


