/*************************************************
 Copyright © 2004 IMSI, Inc.  All rights reserved.
**************************************************/


/*----------------------------------------------------------------------------------------
 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-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/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-9]\d{2}[\)\-]?\s?\d{3}[\-\s]?\d{4}$/;
	return objRegExp.test(strPhoneNumber);
}


function rollOver(strImageName, strSuffix)
{
	document.images[strImageName].src = "images/nav_" + strImageName + "_" + strSuffix + ".gif";
}


function rollOver_2(strImageName, strFileName)
{
	document.images[strImageName].src = "images/" + strFileName;
}