/*
 *  $Id: utils.js 10 2010-04-15 20:13:33Z stuart $
 *  
 *  stuconnolly.com   
 *
 *  Copyright (c) 2010 Stuart Connolly. All rights reserved.
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
/**
 * Trim function from http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C0C0062AC78
 */
function trim(value) 
{    
	var temp = value;

	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;

	if (obj.test(temp)) { 
		temp = temp.replace(obj, '$2'); 
	}

	var obj = /  /g;

	while (temp.match(obj)) { 
		temp = temp.replace(obj, " "); 
	}

	return temp;
}

/**
 * Checks if the supplied email address is valid.
 */
function validateEmailAddress(emailAddress) 
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	return reg.test(emailAddress);
}
