function trim(s) {
	var res = s.replace(/^\s*(.*)/, "$1");
	res = res.replace(/(.*?)\s*$/, "$1");
	return res;
}

function isNumber(n) {
	var validChars = "0123456789.";
	var c;
	var res = true;
 
	if (n == '') {
		res = false;
	} 
 
	for (i = 0; i < n.length && res; i++) { 
		c = n.charAt(i); 
		if (validChars.indexOf(c) == -1) {
			res = false;
		}
	}
	return res;
}

function validateEmailField(emailElem) {
	var email = emailElem.value;
	var atIndex = email.indexOf("@");
	var afterAt = email.substring((atIndex + 1), email.length);
	// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAt.indexOf(".");
	// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + atIndex + 1;
	// afterAt will be portion of string from ampersand to dot
	afterAt = email.substring((atIndex + 1), dotIndex);
	// afterDot will be portion of string from dot to end of string
	var afterDot = email.substring((dotIndex + 1), email.length);
	var beforeAmp = email.substring(0,(atIndex));
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
	// index of -1 means "not found"
	if ((email.indexOf("@") != "-1") && (email.length > 5) && (afterAt.length > 0) && (beforeAmp.length > 1) && (afterDot.length > 1) && (email_regex.test(email)) ) {
		return true;
	} else {
		return false;
	}
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}