



// 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( "City","email","Country" );



var ReqLabel = new Array("City", "Contact Email Address","Country" );







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.email.value.indexOf("@",1) < 2 ) {



        msg += "Value for Contact Email Address is in the format of userid@domain.\n";



    }







    if( msg != "" ) {    // Error(s) detected. Throw an alert and return false.



        alert( msg );



        return (false);



    } 



    return (true);



}