function js_trim(inputString) {
   // Removes leading and trailing spaces from the passed string. 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);
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "js_trim" function

function validateEmailString(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	//var ldot=str.indexOf(dot);
	// List of illegal chars from http://www.remote.org/jochen/mail/info/chars.html
	var REPattern = new RegExp("[!\"#\$%\(\):\<\>\[\\\]`\|]", "g");
	
	// Can't be blank
	if (str == ""){
		alert("E-mail required");
	    return false;
	}

	// Can't have any spaces
	if (str.indexOf(" ")!=-1){
	    alert("E-mail can't have spaces");
	    return false;
	}
	
	// Check for other illegal characters
	var foo = REPattern.exec(str);
	if (foo != null){
		alert(str.charAt(foo.index) + " is an invalid character");
		return false;
	}

	// Must have an @ sign
	if (str.indexOf(at)==-1){
	   alert("E-mail must have an @ sign");
	   return false;
	}

	// Can't have more than 1 @ sign
	if (str.indexOf(at,(lat+1))!=-1){
	    alert("E-mail can only have one @ sign");
	    return false;
	}

	// @ sign can't be first or last character
	if (str.indexOf(at)==0 || str.indexOf(at)==lstr-1){
	   alert("@ sign can't be first or last character");
	   return false;
	}

	// Must have a dot
	if (str.indexOf(dot)==-1){
	    alert("E-mail must have a dot");
	    return false;
	}

	// Dot can't be first or last character
	if (str.indexOf(dot)==0 || str.charAt(lstr-1)=="."){
	    alert("Dot can't be first or last character");
	    return false;
	}

	// Can't have a dot next to the @ sign
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Dot can't be next to @ sign");
	    return false;
	}

	// Must have a dot after the @ sign
	if (str.indexOf(dot,(lat+2))==-1){
	    alert("E-mail must have at least one dot after the @ sign");
	    return false;
	}
	
	return true;			
}
