/******************************************************
 Copyright © 2004-2005 IMSI, Inc.  All rights reserved.
*******************************************************/


/*----------------------------------------------------------------------------------------
 Function:		rollOver
 Purpose:		Perform a DHTML rollover for the specified image
 
 Parameters:	imgName - Primary name of the image file
				sfx - Image state to display
------------------------------------------------------------------------------------------*/
function rollOver(imgName, sfx)
{
	document.images[imgName].src = "images/" + "nav_" + imgName + "_" + sfx + ".gif";
}


/*----------------------------------------------------------------------------------------
 Function:		WindowOpener
 Purpose:		Open a page in a Popup Window or bring it into Focus if it already exists.
 Notes:			To accomodate multiple popup windows from the same function, an array 
				(aobjPopupWindows) is used to store a handle to each window reference.
 
 Parameters:	strURL - URL to load in the Popup Window
				strName - Name of the Popup Window
				strArguments - Controls the positioning & appearance of the Popup Window
------------------------------------------------------------------------------------------*/
var aobjPopupWindows = new Array();

function WindowOpener(strURL, strName, strArguments)
{
	if ((typeof(aobjPopupWindows[strName]) != "object") || (aobjPopupWindows[strName].closed) || ((aobjPopupWindows[strName].location.pathname + aobjPopupWindows[strName].location.search).replace(/^(\/)?.*(\/)/, "") != strURL.replace(/^(\/)?.*(\/)/, "")))
	{
		aobjPopupWindows[strName] = window.open(strURL, strName, strArguments);
	}
	
	aobjPopupWindows[strName].focus();
}


/*----------------------------------------------------------------------------------------
 Prototype:		String.trim
 Purpose:		Remove leading and trailing whitespace from a string.
 
 Returns:		STRING ~ A copy of the string with leading and trailing whitespace removed
------------------------------------------------------------------------------------------*/
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/, "");
}


/*----------------------------------------------------------------------------------------
 Prototype:		Array.indexOf
 Purpose:		Finds the first matching index in an array.
 				Emulates the JavaScript String.indexOf method.
 
 Parameters:	vntValue - The value being searched for within the array
 Returns:		INTEGER ~ The first index of the array containing the value
						~ -1 if the value isn't found
------------------------------------------------------------------------------------------*/
Array.prototype.indexOf = function(vntValue)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == vntValue)
		{
			return i;
		}
	}
	
	return -1;
}


/*----------------------------------------------------------------------------------------
 Function:		blnValidateEmail
 Purpose:		Validate that a string contains a valid email address pattern.
 Notes:			Accounts for email with country appended, but does not validate that 
				email contains valid URL type (.com, .gov, etc.) or valid country suffix.
 
 Parameters:	strEmailAddress - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidateEmail(strEmailAddress)
{
	var objRegExp = /^([a-z0-9_\-\+\.]+)@([a-z0-9_\-\+\.]+)\.([a-z]{2,4}|store|museum)$/i;
	return objRegExp.test(strEmailAddress);
}


/*----------------------------------------------------------------------------------------
 Function:		blnValidatePhone
 Purpose:		Validate that a string contains a valid phone number pattern.
 Notes:			Only accounts for phone numbers from the USA.
 
 Parameters:	strPhoneNumber - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidatePhone(strPhoneNumber)
{
	var objRegExp = /^(1[\-\s\.]?)?(\([1-9]\d{2}\)\s?|[1-9]\d{2}[\-\s\.]?)\d{3}[\-\s\.]?\d{4}(\s?(x|ext\.?|extension)\s?\d{1,9})?$/i;
	return objRegExp.test(strPhoneNumber);
}


/*----------------------------------------------------------------------------------------
 Function:		blnValidateZipCode
 Purpose:		Determine if a string contains a valid United States Zip Code.
 
 Parameters:	strZipCode - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidateZipCode(strZipCode)
{
	var objRegExp  = /^\d{5}(-?\d{4})?$/;
	return objRegExp.test(strZipCode);
}


/*----------------------------------------------------------------------------------------
 Function:		blnValidatePostalCode
 Purpose:		Determine if a string contains a valid Canadian Postal Code.
 
 Parameters:	strPostalCode - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidatePostalCode(strPostalCode)
{
	var objRegExp  = /^[a-zA-Z]\d[a-zA-Z](\-|\s)?\d[a-zA-Z]\d$/;
	return objRegExp.test(strPostalCode);
}


/*----------------------------------------------------------------------------------------
 Function:		blnValidateURL
 Purpose:		Validate that a string contains a valid URL.
 
 Parameters:	strURL - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidateURL(strURL)
{
	var objRegExp = /^http(s)?:(\/){2}[a-z0-9\-&_+](([a-z0-9\-&_+]{0,61}[a-z0-9\-&_+])?\.)+([a-z]{2,4}|store|museum)(\:\d+)*(\/([a-z0-9\.\+\?\-&_~=#$%]+\/?)*)?$/i;
	return objRegExp.test(strURL);
}

/*----------------------------------------------------------------------------------------
 Function:		blnValidatePlanNum
 Purpose:		Validate that a string contains a valid Plan Number.
 
 Parameters:	strPlanNum - String to be tested for validity
 Returns:		BOOLEAN ~ True if valid
						~ False otherwise
------------------------------------------------------------------------------------------*/
function blnValidatePlanNum(strPlanNum)
{
	var objRegExp = /^\d+\-\d+$/i;
	return objRegExp.test(strPlanNum);
}