function trimString (str) {
	  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	
function stripCharsInBag(s, bag)
	{   var i;
	    var returnString = "";
	    // Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character isn't whitespace.
	        var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
	    }
	    return returnString;
	}
	
	function validEmail(email) {
		var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var checkend=/\.[a-zA-Z]{2,3}$/;
	
		// Are there any invalid characters in the address?
		if((email.search(exclude) != -1) || (email.search(checkend) == -1)) {
			return false;
		}
	
		atPos = email.indexOf("@",0);
		pPos1 = email.indexOf(".",0);
		periodPos = email.indexOf(".",atPos);
	
		// Are there consecutive periods?
		pos1 = pPos1;
		pos2 = 0;
		while (pos2 > -1) {
			pos2 = email.indexOf(".",pos1+1);
			if (pos2 == pos1+1) {
				return false;
			} else {
				pos1 = pos2;
			}
		}
	
		// Is there an @ symbol in the address?
		if (atPos == -1) {
			return false;
		}
	
		// Is the @ symbol in the first position?
		if (atPos == 0) {
			return false;
		}
	
		// Is there a period in the first position?
		if (pPos1 == 0) {
			return false;
		}
	
		// Is there more than one @ symbol in the address?
		if(email.indexOf("@",atPos+1) > -1) {
			return false;
		}
	
		// Is there a period after the @ symbol?
		if (periodPos == -1) {
			return false;
		}
	
		// Is the period imediately after the @ symbol?
		if (atPos+1 == periodPos) {
			return false;
		}
	
		// Are there at least 2 characters after the period?
		if (periodPos+3 > email.length) {
			return false;
		}
		return true;
	}