
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


//
//   email.js
//    Bugzy
//    November 2005
//

function validateEmail(emailAddress)
{
    // function to validate email
    var email   = emailAddress;	//trim(document.forms[0].email.value);
    var len     = email.length;
    var atsign  = email.indexOf("@");
    var latsign = email.lastIndexOf("@");
    var dot     = email.indexOf(".");
    var ldot    = email.lastIndexOf(".");
    var first   = email.charCodeAt(0);
    var last    = email.charCodeAt(len - 1);
    var space   = email.indexOf(" ");

	if (atsign == -1 || atsign != latsign) {
        return 0;
    }
	
    if (dot == -1 || dot + 1 == ldot) {
        return 0;
    }
	
    if (dot + 1 == atsign || dot - 1 == atsign || ldot - 1 == atsign || ldot < atsign) {
        return 0;
    }
	
    if ((first < 48) || (first > 57 && first < 65) || (first > 90 && first < 97) || (first > 122)) {
        return 0;
    }
	
    if ((last < 65) || (last > 90 && last < 97) || (last > 122)) {
        return 0;
    }
	
    if (space != -1) {
        return 0;
    }
	
	return 1;
}// validateEmail

