/*******************************************************************************
 * Copyright (c) 2003 Alister Lewis-Bowen
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Alister Lewis-Bowen <alister@different.com>
 ******************************************************************************/

//
//	Parse the QUERY_STRING and return an Object containing the key
//	value pairs.
//
function parseQueryString()
{
	var oArgs = new Object();
	var sQueryString = location.search.substring(1);
	var aPairs = sQueryString.split("&");
	for (var i = 0; i < aPairs.length; i++)
	{
		var iPos = aPairs[i].indexOf('=');
		if (iPos == -1) continue;
		var sKey = aPairs[i].substring(0,iPos);
		var sValue = aPairs[i].substring(iPos+1);
		oArgs[sKey] = unescape(sValue);
	}
	return oArgs;
}

//
//	Validate the given email address, sEmail, and return
//	true if valid, false if not.
//
function validateEMailAddress(sEmail)
{
	var AT = "@";
	var DOT = ".";
	var iAtPos = sEmail.indexOf(AT);
	var iLength = sEmail.length;
	if (sEmail.indexOf(AT) == -1) return false;
	if (sEmail.indexOf(AT) == -1 || sEmail.indexOf(AT) == 0 || sEmail.indexOf(AT) == iLength) return false;
	if (sEmail.indexOf(DOT) == -1 || sEmail.indexOf(DOT) == 0 || sEmail.indexOf(DOT) == iLength) return false;
	if (sEmail.indexOf(AT,(iAtPos+1)) != -1) return false;
	if (sEmail.substring(iAtPos-1,iAtPos) == DOT || sEmail.substring(iAtPos+1,iAtPos+2) == DOT) return false;
	if (sEmail.indexOf(DOT,(iAtPos+2)) == -1) return false;
	if (sEmail.indexOf(" ") != -1) return false;
	return true;
}


