/**
 * Email form validator functions.
 *
 * By Duncan Eley 29.06.2003 
 */

/**
 * Called when email form is submitted to ensure all mandatory fields contain entries
 * and any other validation.
 */
function validateMail() {
	
	// Validation report string. Empty field strings and a message will be appended to this.
	var rep = "";
	
	// name field.
	if( isWhitespace(document.contactForm.name.value) ) {
		rep += "Name\n";		
	} // email address field.
	if( isWhitespace(document.contactForm.replyemail.value) ) {		
		rep += "Email address\n";		
	} // message field.
	if( isWhitespace(document.contactForm.message.value) ) {		
		rep += "Message\n";		
	}
	
	// A field must be empty.
	if(rep != "") {		
		alert("The following fields are empty and require values:\n\n" + rep);
		return false;
	} // All okely-dokely!
	else {
		return true;
	}
}

/**
 * Checks if a string contains only whitespace or is empty.
 *  Can be used for mandatory form fields.
 */
// whitespace characters
var whitespace = " \t\n\r";
function isWhitespace(s) {
   var i;

   // Is s empty?
   if(isEmpty(s)) return true;

   // Search through string's characters one by one
   // until we find a non-whitespace character.
   // When we do, return false; if we don't, return true.
   for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if(whitespace.indexOf(c) == -1) return false;
   }

   // All characters are whitespace.
   return true;
}

/**
 * Checks if a string passed is empty.
 * Can be used for mandatory form fields.
 */
function isEmpty(s) {

    if (s == null || s == "" || s == '') {
        return true;
    }
    else
        return false;
}




