/*function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consecutive spaces and replaces it with one space.
   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
}*/

// My trim is better!
function trim(inputString) {
	inString = inputString;
	var ltrimRe = /^\s+(.*)$/;
	var rtrimRe = /^(.*)\s+$/;
	if (ltrimRe.test(inString))
		inString = RegExp.$1;
	if (rtrimRe.test(inString))
		inString = RegExp.$1;

	return inString;
}

// slightly different from the one in mylib.php...
// this one returns the bad character if false, returns the boolean true if it's ok...
// therefore, you've got ot check the 'typeof' value returned from this function to see
// if the name is truly valid or not
function is_valid_name(name) {
	// // disallow most non-words except ' and -
	var re = /([!@#$%^&*()_+=\[\]\/\\;:\",<.>?~`|{}])/;
	if (re.test(name))
		return RegExp.$1;	// returns the bad character
	return true;
}

function getBadChar(name) {
	var re = /([!@#$%^&*()_+=\[\]\/\\;:\",<.>?~`|{}])/;
	if (re.test(name)) {
		return RegExp.$1;
	}
}

function isPostalZipCode (code) {
	//if (usePostal)	// assume Canada
		var reCA = /^\w{1}\d{1}\w{1}\s{0,1}\d{1}\w{1}\d{1}$/;
	//else 	// use zip
		var reUS = /^\d{5}$/;
	
	if (reCA.test(code) || reUS.test(code)) 
		return true;
	return false;
}
	

function isPhone(phone) {
	var phoneRe1 = /^\d{3}[.-]\d{3}[-.]\d{4}$/;
	var phoneRe2 = /^\d{10}$/;
	if (phoneRe1.test(phone) || phoneRe2.test(phone)) 
		return true;
	return false;
}

function is_valid_email(email) {
	var re = /^(\S+@).+((\.com)|(\.edu)|(\.gov)|(\.int)|(\.mil)|(\.net)|(\.org)|(\.info)|(\.biz)|(\.name)|(\.pro)|(\.museum)|(\.coop)|(\.aero)|(\.[a-z]{2,2}))$/;
	if (re.test(email))
		return true;
	return false;
}

