// List of fields and labels that require input. 

// Add all the required form element names to the array ReqField and

//	their corresponding labels to ReqLabel.  Note, order is important.

//  index 0 of ReqField must have it's label in index 0 of ReqLabel


var ReqField =  new Array( "Name","Telephone","Email" );

var ReqLabel = new Array("Contact Name", "Contact Telephone","Contact Email Address" );


function validator(theForm) {

    var msg = "";

    var i;


    //  Loop through all the fields checking their value for null.

    //  if a null is found, first check that no other error has been detected

    //  append an error for this field to the msg w/ a newline.


	for( i=0; i < ReqField.length; i++ ) {

		if( theForm.elements[ ReqField[i] ].value == "" ) {

			msg += ReqLabel[ i ] + " is required\n";

		}

	}


    // Customized validation starts.

    // Check that the email address has an @ sign in it.


	if (theForm.from.value.indexOf("@",1) < 2 ) {

		msg += "Value for Contact Email Address is in the format of userid@domain.\n";

	}


     // Check that the email address is not a mixed web address


	if (theForm.from.value.substring(0,4) == "www." ) {

		msg += "Value for Contact Email Address is in the format of userid@domain and not preceeded by www.\n";

	}


	if( msg != "" ) {    // Error(s) detected. Throw an alert and return false.

		alert( msg );

		return (false);

	} 

	return (true);

}