/*************************************************************************************
 *	getTabs
 *	Creates a string with the proper number of tabs for the element
 *	 Inputs
 *		Tag = tagname (or number)
 *	Output
 *		string with the proper number of tabs
 *************************************************************************************/
function getTabs(Tag)
{
	var i;
	var vTabs		= '';
	var vTags		= new Array	(	'<ol><table><ul>',
									'<form><li><tbody><thead><tr>',
									'<td><th>',
									'<a><button><checkbox><fieldset><font><iframe><img><input><script><select><span><textarea>'
								)

	var t 			= parseInt(Tag);
	if (isNaN(t))
	{
		var strTag	= Tag;
		strTag 		= jTrim(strTag.toLowerCase());
		strTag		= strTag.replace(/</g, '');				//> (shut up NoteTabPro)
		strTag		= strTag.replace(/\//g, '');
		strTag		= strTag.replace(/>/g, '');
		strTag		= '<' + strTag + '>';

		t			= 0;
		for (i=0; i < vTags.length; i++)
		{
			if (vTags[i].indexOf(strTag) > -1)
			{
				t 	= i+1;
				break;
			}
		}
	}
	for (i=0; i < t; i++)
		vTabs	+= '\t';
	return vTabs;
}

/*****************************************************************
 * buildURL		This function builds an URL by adding the new
 * 				keyword and value uniquely to the current URL
 *****************************************************************/
function buildURL(URL, qryKeyword, qryValue, bNoDuplicateCheck)
{
	var	strURL			= URL;
	var strKeyword		= getString(qryKeyword);
	var bMerge			= true;

	if (typeof(bNoDuplicateCheck) != 'undefined')
	{
		if (bNoDuplicateCheck)
			bMerge		= false;
	}

	if (strKeyword.length > 0)
	{
		strKeyword	   += '=';
		strKeyword	   += getString(qryValue);

		if (bMerge)
			strURL		= mergeURLs(strURL, strKeyword, '');
		else
		{
			if (strURL.indexOf('?') > -1)
				strURL	   += '&';
			else
				strURL	   += '?';
			strURL		   += strKeyword;
		}
	}
	return strURL;
}

/*****************************************************************
 * mergeURLs	This function merges two URLs with (or without)
 * 				query strings into one, composite URL.
 *				The second string is favored, so that its URL
 *				and query parameters take precedence over the
 *				the first.
 * Input
 *	string1				URL/query 1
 *	string2				URL/query 2
 *	ExcludedKeywords	comma separated list of keyword to exclude
 * Output
 * 	merged URL
 *****************************************************************/
function mergeURLs(String1, String2, ExcludedKeywords)
{
	var strKey, strItem;

	// load input strings into array for processing
	var dctName					= new Array(0);
	var dctValue				= new Array(0);

	var strTemp1				= getString(String1);
	var strTemp2				= getString(String2);
	var aStrings				= new Array(strTemp1, strTemp2);

	var strExcludedKeywords		= getString(ExcludedKeywords);
	var dctExclude				= strExcludedKeywords.split(',');
	var strURL					= '';

	for (var s=0; s < 2; s++)
	{
		var strQuery			= '';
		i						= aStrings[s].indexOf('?');		// find begin of query string
		if (i > -1)
		{
			strURL 				= aStrings[s].substr(0, i);
			strQuery			= aStrings[s].substr(i+1);
		}
		else
		{
			i					= aStrings[s].indexOf('=');		// find name/value separator
			if (i > -1)
				strQuery		= aStrings[s];
			else
			{
				if (aStrings[s].length > 0)
					strURL 		= aStrings[s];
				strQuery		= '';
			}
		}

		// split query string into name/value pairs
		var aValues								= strQuery.split('&');
		for (var v=0; v < aValues.length; v++)
		{
			var aNameValues						= aValues[v].split('=');
			strKey								= aNameValues[0];
			strItem								= '';
			if (aNameValues.length >= 1)
				strItem							= aNameValues[1];

			var bFound							= false;
			for (var i=0; i < dctName.length; i++)
			{
				if (dctName[i].toLowerCase() == strKey.toLowerCase())
				{
					bFound						= true;
					dctValue[i]					= strItem;
					break;
				}
			}
			if (!bFound)
			{
				i								= dctName.length;
				dctName[i]						= strKey;
				dctValue[i]						= strItem;
			}
		}
	}

	var bFirst					= true;
	for (var i=0; i < dctName.length; i++)
	{
		var bLoad				= true;
		for (var j=0; j < dctExclude.length; j++)
		{
			if (dctName[i].toLowerCase() == dctExclude[j].toLowerCase())
			{
				bLoad			= false;
				break;
			}
		}
		if (bLoad)
		{
			if (bFirst)
			{
				strURL		   += '?';
				bFirst			= false;
			}
			else
				strURL		   += '&';
			strURL		 	   += dctName[i] + '=' + dctValue[i];
		}
	}
	return strURL;
}

/*****************************************************************
 * getURLPath		Get the Path of the requested URL
 *****************************************************************/
 function getURLPath(URL, bIncludeDomain)
 {
	var bInclude;
	var vPath		= getString(URL);
	var i			= vPath.indexOf('?');
	if (i > -1)
		vPath		= vPath.substr(0, i);
	i				= vPath.lastIndexOf('/');
	if (i > -1)
		vPath		= vPath.substr(0, i+1);

	i				= vPath.indexOf('//')
	if (i > -1)
		vPath		= vPath.substr(i+2);

	if (typeof(bIncludeDomain) == 'undefined')
		bInclude		= false;
	else
		bInclude		= getBoolean(bIncludeDomain)

	if (!bInclude)
	{
		i		= vPath.indexOf('/')
		vPath	= vPath.substr(i);
	}
	return vPath;
 }

/*****************************************************************
 * jReplace
 *****************************************************************/
function jReplace(inputString, toFind, toReplace)
{
	var strTemp		= getString(inputString);
	var n			= toFind.length;
	var strOutput	= '';
	if (n == 0)
		return strTemp;

	for (var i=0; i < strTemp.length; i++)
	{
		if (strTemp.substr(i, n) == toFind)
		{
			strOutput		   += toReplace;
			i				   += n-1;
		}
		else
			strOutput		   += strTemp.substr(i, 1);
	}
	return strOutput;
}

/*****************************************************************
 * jReplace
 *****************************************************************/
function jTrim(inputString)
{
	var strTemp		= getString(inputString);
	while (strTemp.length > 0)
	{
		if (strTemp.charCodeAt(strTemp.length-1) < 33)
			strTemp	= strTemp.substr(0, strTemp.length-1);
		else
			break;
	}
	return strTemp;
}
function trimString(strInput) {	return jTrim(strInput); }

/*****************************************************************
 * getMySalespersonGUID		This function returns the current
 *							user's salesperson GUID.
 *****************************************************************/
function getMySalespersonGUID()
{
	var vUserID		= getCookie('SalespersonGUID');
	if (vUserID != '')
		return vUserID;
	else
		return getNullGUID();
}

/*****************************************************************
 * getMyLeadGeneratorGUID		This function returns the current
 *							user's Lead Generator GUID.
 *****************************************************************/
function getMyLeadGeneratorGUID()
{
	var vUserID		= getCookie('LeadGeneratorGUID');
	if (vUserID != '')
		return vUserID;
	else
		return getNullGUID();
}
/*****************************************************************
 * getMyGUID		This function returns the current users's GUID.
 *****************************************************************/
function getMyGUID()
{
	var vUserID		= getCookie('userID');
	if (vUserID != '')
		return vUserID;
	else
		return getNullGUID();
}

/*****************************************************************
 * getMyMEMGUID		This function returns the current
 *							user's MEMBERSHIP ENGAGEMENT MANAGER GUID.
 *****************************************************************/
function getMyMEMGUID()
{
	var vUserID		= getCookie('MEMGUID');
	if (vUserID != '')
		return vUserID;
	else
		return getNullGUID();
}
/*****************************************************************
 * amLoggedIn		This returns a boolean whether or not I am
 *					logged in.
 *****************************************************************/
function amLoggedIn()
{
	var vUserID		= getCookie('userID');
	return (vUserID != '');
}

/*****************************************************************
 * getUserGUID		This function returns the current users's GUID.
 *					If this is the super user, return the nullGUID.
 *****************************************************************/
function getUserGUID()
{
	var vUserID	= getMyGUID();
	var vSuperUser	= getCookie('sa');
	if (vSuperUser != '')
		return getNullGUID();
	else
		return vUserID;
}

/*****************************************************************
 * getMyLogin		This function returns the current user's
 *					login name
 *****************************************************************/
function getMyLogin()
{
	var vLoginName = getCookie("loginName")
	return vLoginName;
}

/*****************************************************************
 * getMyLoginTime	This function returns the current user's
 *					login time
 *****************************************************************/
function getMyLoginTime()
{
	var vLoginTime = getCookie("loginTime")
	vLoginTime		= jReplace(vLoginTime, '+', ' ');
	return getDateTime(vLoginTime, '');
}

/*****************************************************************
 * getMyDisplayName	This function returns the current user's
 *					display name
 *****************************************************************/
function getMyDisplayName()
{
	var vDisplayName = getCookie("userDisplay")
	return jReplace(vDisplayName, '+', ' ');
}

/*****************************************************************
 * isSuperUser
 *****************************************************************/
function isSuperUser(){	return (getCookie('sa') != '');}

/*****************************************************************
 * getCookie		This function returns the requested cookie
 *****************************************************************/
function getCookie(sName)
{
	// is this a client-side request?
	if (typeof(Request) == 'undefined')
	{
		var aCookie = document.cookie.split('; ');		// cookies are separated by semicolons
		for (var i=0; i < aCookie.length; i++)
		{
			var aCrumb = aCookie[i].split('=');			// a name/value pair (a crumb) is separated by an equal sign
			if (sName.toLowerCase() == aCrumb[0].toLowerCase())
				return unescape(aCrumb[1]);
		}
		return '';										// a cookie with the requested name does not exist
	}
	else
		return Request.Cookies(sName);					// return server-side cookie
}

/*****************************************************************
 * getDomain		This function returns the domain name
 *****************************************************************/
function getDomain()
{
	// is this a client-side request?
	if (typeof(Request) == 'undefined')
		return document.domain;
	else
		return Request.ServerVariables("SERVER_NAME");
 }

/*****************************************************************
 * getQuery			This function retrieves the value of the
 *					requested query string parameter.
 *
 *					modified 06/02/2004 DF Denes
 *					• allow parsing of requested query string
 *****************************************************************/
function getQuery(sName, sQuery)
{
	var strQuery;
	if (typeof(sQuery) == 'undefined')
	{
		if (typeof(Request) == 'undefined')					// client-side request?
			strQuery		= document.location.search + '';
		else
			strQuery		=  '?' + Request.QueryString + '';
	}
	else
	{
		if (substr(sQuery, 0, 1) != '?')
			strQuery		= '?' + sQuery + '';
		else
			strQuery		= sQuery + '';
	}

	var q					= strQuery.indexOf('?');
	if (q > -1)
		strQuery			= strQuery.substr(q+1);
	else
		strQuery			= '';

	var strValue			= '';
	var aQuery 				= strQuery.split('&');		// querystring items are separated by ampersands
	for (var i=0; i < aQuery.length; i++)
	{
		var aCrumb = aQuery[i].split('=');				// a name/value pair (a crumb) is separated by an equal sign
		if (sName.toLowerCase() == aCrumb[0].toLowerCase())
		{
			if (strValue.length > 0)
				strValue   += ', ';
			strValue	   += unescape(aCrumb[1]);
		}
	}
	return strValue;								// return the querystring value
}

function encodeString(String)
{
	if (String == null)
		return '';
	if (String.length > 0)
		return escape(String);
	else
		return '';
}
function decodeString(String)
{
	if (String == null)
		return '';
	if (String.length > 0)
		return unescape(String);
	else
		return '';
}

/*****************************************************************
 * getScreenID			Get the current page ID
 *****************************************************************/
function getScreenID()
{
	var strScreenID	= getQuery('ScreenName');
	if (strScreenID.length == 0)
		strScreenID	= getScreenName();
	return strScreenID;
}
/*****************************************************************
 * getScreenName		Get the current page name
 *						(without the extension)
 *****************************************************************/
function getScreenName()
{
	var strName, i;
	if (typeof(Request) == 'undefined')
		strName		= document.URL + '';
	else
		strName		= Request.ServerVariables('SCRIPT_NAME') + '';

	// remove path, if present
	i				= strName.lastIndexOf('/')
	if (i != -1)
		strName		= strName.substr(i+1);

	// remove extension, if present
	i				= strName.lastIndexOf('.')
	if (i != -1)
		strName		= strName.substr(0, i);

	return strName;
}

/*****************************************************************
 * getBoolean			Get the boolean value of a string
 *****************************************************************/
function getBoolean(Value)
{
 	var strValue	= getString(Value) + '';
	strValue		= strValue.toLowerCase();

	if (strValue == 'yes' || strValue == 'true' || strValue == 'on' || strValue == '1')
		return true;
	else
		return false;
}

function getMax(Value1, Value2) {return Math.max(Value1, Value2);}
function getMin(Value1, Value2) {return Math.min(Value1, Value2);}

/*****************************************************************
 * getDialogFeatures	Get the dialog feature string for the
 *						requested dialog box size and placement.
 *****************************************************************/
function getDialogFeatures(vWidth, vHeight, vCenter)
{
	if (typeof(Request) == 'undefined')
	{
		var strFeatures = '';

		strFeatures += 'dialogWidth:' 			+ vWidth	+ 'px;';
		strFeatures += 'dialogHeight:' 			+ vHeight	+ 'px;';

		if (window.event != null && !getBoolean(vCenter))
		{
			var vLeft		= window.event.screenX - window.event.offsetX + 6;
			var vTop		= window.event.screenY - window.event.offsetY + 6;

			if (((vLeft + vWidth) > window.screen.availWidth) || ((vTop + vHeight) > window.screen.availHeight))
				strFeatures	+= 'center:yes;';
			else
			{
				strFeatures	   += 'dialogLeft:' + vLeft		+ 'px;';
				strFeatures    += 'dialogTop:'	+ vTop		+ 'px;';
			}
		}
		else
			strFeatures	+= 'center:yes;';


		strFeatures	+= 'help:no;';
		strFeatures	+= 'resizable:no;';
		strFeatures	+= 'scrolling:no;';
		strFeatures	+= 'status:no;';

		return strFeatures;
	}
	return 'cannot use this function in server-side code';
 }

/*****************************************************************
 * getButtonTitle		Returns the button's title with
 *						accelerator key (IE only)
 *****************************************************************/
function getButtonTitle(Title, AcceleratorKey)
{
	var		conStdKeys	= 'ABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789';
	var		conQuote	= '&quot;';
	var		strKey		= '';

	if (AcceleratorKey != null)
		strKey	= AcceleratorKey.toUpperCase();
	else
		strKey	= '';

	if (is_ie && strKey.length == 1)
	{
		if (conStdKeys.indexOf(strKey) == -1)
			strKey	= conQuote + strKey + conQuote;
		return (Title + ' (Alt+' + strKey + ')');
	}
	else
		return Title;
}

/*****************************************************************
 *	getDateTime
 *	Formats the date time
 *	 Inputs
 *		date/time
 *		date/time (for year comparison)
 *	Output
 *		string
 *****************************************************************/
function getDateTime(dtmDate, dtmYear, bTimeOnly)
{
	var nDate		= Date.parse(dtmDate);
	if (isNaN(nDate))
		return '';
	var vDate		= new Date(nDate);

	var bTime		= bTimeOnly
	if (typeof(bTime) == 'undefined')
		bTime		= false;

	var strDate		= ''

	if (!bTime)
	{
		var nYear		= Date.parse(dtmYear);
		if (isNaN(nYear))
			nYear		= Date.parse('1/1/1970');
		var vYear		= new Date(nYear);

		strDate		   += vDate.getMonth() + 1;
		strDate		   += '/';
		strDate		   += vDate.getDate();

		if (vDate.getFullYear() != vYear.getFullYear())
		{
			strDate    += '/';
			strDate	   += vDate.getFullYear();
		}

		if (strDate.substr(strDate.length-4) == '1899')
			strDate		= '';
		if (strDate.substr(strDate.length-4) == '1900')
			strDate		= '';
	}

	var vHour		= vDate.getHours();
	var vMinute		= vDate.getMinutes();
	var strAmPm		= 'am';
	if (vHour > 11)
		strAmPm		= 'pm';

	if (vHour > 12)
		vHour	   -= 12;
	if (vHour == 0)
		vHour		= 12;

	var strTime		= '';
	strTime		   += vHour;
	strTime		   += ':';

	if (vMinute < 10)
		strTime	   += '0';
	strTime		   += vMinute;

	strTime		   += strAmPm;

//if (vMinute == 30)
//	Response.write(dtmDate)

	if (!bTime)
	{
		if (strTime != '12:00am')
		{
			if (strDate.length > 0)
				strDate += '&nbsp;';
			strDate	   += strTime;
		}
	}
	else
		strDate		= strTime;

	return strDate
}

/*****************************************************************
 *	getPreposition		Get the preposition for the requested noun
 *****************************************************************/
function getPreposition(Noun)
{
	var conVowels 		= 'aeiou';

	var vNoun			= jTrim(Noun);
	vNoun				= vNoun.toLowerCase();
	if (conVowels.indexOf(vNoun.substr(0, 1)) == -1)
		return 'a';
	else
		return 'an';
}

/*****************************************************************
 *	getPlural			Get the plural form of the requested noun
 *****************************************************************/
function getPlural(Noun)
{
	var vNoun	= jTrim(Noun + '');
	vNoun		= vNoun.toLowerCase();

	if (vNoun.substr(vNoun.length -2) != 'ey' && vNoun.substr(vNoun.length -1) == 'y')
		vNoun	= vNoun.substr(0, vNoun.length -1) + 'ies';

	if (vNoun.substr(vNoun.length -2) == 'ss')
		vNoun   += 'es';

	if (vNoun.substr(vNoun.length -1) != 's')
		vNoun   += 's';

	return vNoun;
}

/*****************************************************************
 *	getProperCase		Capitalize each word in the phrase
 *****************************************************************/
function getProperCase(strInput)
{
	var	strValue				= jTrim(strInput + " ");
	var	aValues					= strValue.split(' ');

	for (var i=0; i < aValues.length; i++)
	{
		strValue					= aValues[i].toLowerCase();
		var strOutput				= '';
		var bCapitalize				= true;

		if ((strValue != 'a' && strValue != 'an' && strValue != 'the') || i == 0)
		{
			for (var j=0; j < strValue.length; j++)
			{
				if (bCapitalize)
				{
					strOutput		   += strValue.substr(j, 1).toUpperCase();
					bCapitalize			= false;
				}
				else
				{
					strOutput		   += strValue.substr(j, 1);
					if (strOutput == 'Mc' || strOutput == "O'")
						bCapitalize		= true;
				}
			}
			aValues[i]					= strOutput;
		}
	}
	return aValues.join(' ');
}

/*****************************************************************
 *	getSentenceCase		Capitalize the beginning of each sentence
 *****************************************************************/
function getSentenceCase(strInput)
{
	var	strValue				= jTrim(strInput + " ");
	var	aValues					= strValue.split(' ');
	var bCapitalize				= true;

	for (var i=0; i < aValues.length; i++)
	{
		strValue				= aValues[i].toLowerCase();
		aValues[i]				= strValue;
		if (bCapitalize)
		{
			var strWord			= strValue.substr(0, 1).toUpperCase();
			strWord			   += strValue.substr(1).toLowerCase();
			aValues[i]			= strWord;
			bCapitalize			= false;
		}
		if (strValue.lastIndexOf(".") > -1)
			bCapitalize			= true;
	}
	return aValues.join(' ');
}

/*****************************************************************
 *	isGUID				Is the input value a GUID?
 *****************************************************************/
function isGUID(strValue)
{
	var strTemp	= fromKey(strValue);
	return ((strTemp.length == 38) && (strTemp.substr(0,1) == '{') && (strTemp.substr(strTemp.length-1, 1) == '}'));
}

/*****************************************************************
 *	toKey				Return a dictionary-usable key value
 *****************************************************************/
function toKey(strInput)
{
	return "'" + fromKey(getString(strInput)) + "'";
}
/*****************************************************************
 *	fromKey				Return a string from a dictionary key
 *****************************************************************/
function fromKey(strInput)
{
	var strOutput 			= getString(strInput);
	if (strOutput.length >= 2)
	{
		if (strOutput.substr(0,1) == "'")
			strOutput		= strOutput.substr(1);
		if (strOutput.substr(strOutput.length-1,1) == "'")
			strOutput		= strOutput.substr(0, strOutput.length-1);
	}
	return strOutput;
}

/*****************************************************************
 *	getString			Get the string value of the input
 *****************************************************************/
function getString(strInput)
{
	var strOutput	= '';
	if ((typeof(strInput) != 'undefined') && (strInput != null) && strInput != 'undefined')
		strOutput	= strInput + '';
	return strOutput;
}

/*****************************************************************
 *	getNonBreakingString
 *****************************************************************/
function getNonBreakingString(Value)
{
	var strValue		= getString(Value)
	return strValue.replace(/ /g, "&nbsp;");
}
/*****************************************************************
 *	getSQLValue			Get a valid string for a SQL query
 *****************************************************************/
function getSQLValue(inputString)
{
	var strValue		= getString(inputString)
	return strValue.replace(/\'/g, "''");
}
/*****************************************************************
 *	getJavaString			Get a valid string for a Java
 *							single-quoted string
 *****************************************************************/
function getJavaString(inputString)
{
	var strValue		= getString(inputString)
	return strValue.replace(/\'/g, "\\\'");
}


/*****************************************************************
 *	getOutputString			Get a valid string for HTML output
 *****************************************************************/
function getOutputString(inputString)
{
	var strValue		= getString(inputString);
	return strValue.replace(/\"/g, "&quot;");
}

/****************************************************************
 * Get the HTML string for a field value of type.
 ****************************************************************/
function getHTMLFieldValue(FieldValue, FieldType)
{
	var strFieldValue			= getString(FieldValue)
	var strFieldType			= getString(FieldType);

	if (strFieldType.toLowerCase() == 'bit')
	{
		if (getBoolean(strFieldValue))
			strFieldValue		= 'yes';
		else
			strFieldValue		= '';
	}
	else if ((strFieldType.toLowerCase() == 'datetime') || (strFieldType.toLowerCase() == 'smalldatetime'))
		strFieldValue			= getDateTime(strFieldValue, null);

	if (strFieldValue.length == 0)
		strFieldValue			= '&nbsp;';
	return strFieldValue.replace(/\'/g, "&#39;");
}

/**************************************************************************
 * writeDebugWindow 	Write the input message to a debug window
 **************************************************************************/
function writeDebugWindow(strMessage, strDescription)
{
	var strTitle		= getString(strDescription);
	var strOutput		= '';
		if (strTitle.length > 0)
			strOutput  += '<font style="color:darkblue; font-weight:bolder;">' + strTitle + '</font><br>';

	strOutput		   += '<pre style="margin:0px; margin-top:3px;">' + getString(strMessage) + '</pre>';
	strOutput		   += '<hr style="border: 1px solid lightgrey;">';

	writeDebugOutput(strOutput);
}

var objDebugWindow	= null;
/**************************************************************************
 * writeDebugOutput 	Write the message to a debug window
 **************************************************************************/
function writeDebugOutput(Value)
{
	var bOpenWindow			= false;
	if (objDebugWindow != null)
	{
		if (!objDebugWindow.closed)
			bOpenWindow		= true;
		else
			objDebugWindow	= null;
	}

	if (!bOpenWindow)
	{
		var nScreenWidth	= window.screen.availWidth;
		var nScreenHeight	= window.screen.availHeight;
		var nWidth			= parseInt(nScreenWidth / 2);
		var nHeight			= parseInt(nScreenHeight / 2);
		var nLeft			= nScreenWidth - nWidth - 20;
		var nTop			= nScreenHeight - nHeight - 60;
		var nBodyWidth		= nWidth - 25;
		var nBodyHeight		= nHeight - 25;

		var strFeatures	= '';
		strFeatures	   += 'toolbar=no';
		strFeatures	   += ',';
		strFeatures	   += 'location=no';
		strFeatures	   += ',';
		strFeatures	   += 'directories=no';
		strFeatures	   += ',';
		strFeatures	   += 'status=yes';
		strFeatures	   += ',';
		strFeatures	   += 'menubar=no';
		strFeatures	   += ',';
		strFeatures	   += 'resizable=yes';
		strFeatures	   += ',';
		strFeatures	   += 'width=' 	+ nWidth;
		strFeatures	   += ',';
		strFeatures	   += 'height=' + nHeight;
		strFeatures	   += ',';
		strFeatures	   += 'top=' 	+ nTop;
		strFeatures	   += ',';
		strFeatures	   += 'left=' 	+ nLeft;
		objDebugWindow = window.open('', 'generalFunctionsDebugging', strFeatures);

		objDebugWindow.document.write("<HTML>");
		objDebugWindow.document.write("<HEAD><TITLE>Debugging Information</TITLE></HEAD>");
		objDebugWindow.document.write("<BODY style='width:" + nBodyWidth + "px; height:" + nBodyHeight + "px; font-family:arial; font-size:9pt;' scroll=yes>");
		objDebugWindow.document.write(Value);
		objDebugWindow.document.write("</BODY>");
		objDebugWindow.document.write("</HTML>");
	}
	else
	{
		var vMsg				= objDebugWindow.document.body;
		vMsg.insertAdjacentHTML('BeforeEnd', Value);
	}
}

/**************************************************************************
 * getStyle				Get the requested style of the HTML element
 **************************************************************************/
function getStyle(objElement, strStyle)
{
 	var vReturn;

 	if (objElement != null)
	{
		if (objElement.style != null)
		{
			vReturn =	eval('objElement.style.' + strStyle)
			if (typeof(vReturn) != 'unknown')
				return vReturn;
		}
	}
	return '';
}
/**************************************************************************
 * setStyle				Put the requested style of the HTML element
 **************************************************************************/
function setStyle(objElement, strStyle, strValue)
{
 	if (objElement != null)
	{
		if (objElement.style != null)
			eval('objElement.style.' + strStyle + ' = "' + strValue + '"');
	}
}
/**************************************************************************
 * hasStyle				Does the requested HTML element have this style?
 **************************************************************************/
function hasStyle(objElement, strStyle, strValue)
{
	var strTest = getString(strValue);
 	if (objElement != null)
	{
		if (objElement.style != null)
		{
			vReturn =	eval('objElement.style.' + strStyle)
			if (typeof(vReturn) != 'unknown')
			{
				if (strTest.length == 0)
					return true;
				else
					return (vReturn == strTest);
			}
		}
	}
	return false;
}

/**************************************************************************
 * appendDelimitedList
 **************************************************************************/
function appendDelimitedList(List, NewValue, Delimiter)
{
	var strList			= getString(List);
	var strValue		= getString(NewValue);

	var strDelimiter	= ',';
	if (typeof(Delimiter) != 'undefined')
		strDelimiter	= getString(Delimiter);

	if (strValue.length > 0)
	{
		if (strList.length > 0)
			strList	   += strDelimiter;
		strList		   += strValue;
	}
	return strList;
}
/**************************************************************************
 * appendDelimitedListUnique
 **************************************************************************/
function appendDelimitedListUnique(List, NewValue, Delimiter)
{
	var strList			= getString(List);
	strList				= strList.toLowerCase();
	var strValue		= getString(NewValue);
	strValue			= strValue.toLowerCase();
	if (strList.indexOf(strValue) == -1)
		strList			= appendDelimitedList(List, NewValue, Delimiter);
	return strList;
}

function getNullGUID() {return '{00000000-0000-0000-0000-000000000000}';}


function getAbsoluteX(HTMLObject)
{
	var offsetParent	= getOffsetParent(HTMLObject);
	if (offsetParent && (offsetParent != HTMLObject))
		return HTMLObject.offsetLeft - offsetParent.scrollLeft + getAbsoluteX(offsetParent);
	else
		return HTMLObject.offsetLeft;
}
function getAbsoluteY(HTMLObject)
{
	var offsetParent	= getOffsetParent(HTMLObject);
	if (offsetParent && (offsetParent != HTMLObject))
		return HTMLObject.offsetTop - offsetParent.scrollTop + getAbsoluteY(offsetParent);
	else
		return HTMLObject.offsetTop;
}
function getAbsoluteRectangle(HTMLObject)
{
	var nLeft	= getAbsoluteX(HTMLObject);
	var nTop	= getAbsoluteY(HTMLObject);
	var nRight 	= nLeft + HTMLObject.clientWidth;
	var nBottom = nTop  + HTMLObject.clientHeight;
	return new Rectangle(nLeft, nTop, nRight, nBottom);
}

/*************************************************************
* Do these 2 rectagles intersect?
*************************************************************/
function intersects(Object1, Object2)
{
	/***********************************************************
	* Make sure Rectangle1 and Rectangle2 are Rectanlge objects
	*************************************************************/
	var Rectangle1				= Object1;
	var Rectangle2				= Object2;
	if (typeof(Object1) 		!= "object") 			return false;
	if (typeof(Object2) 		!= "object") 			return false;
	if (Object1.constructor 	!= Rectangle) 			Rectangle1 = getAbsoluteRectangle(Object1);
	if (Object2.constructor 	!= Rectangle) 			Rectangle2 = getAbsoluteRectangle(Object2);

	/***********************************************************
	* Check the 4 possible ways a rectangle can be disqualified.
	*************************************************************/
	if (Rectangle2.left 		> Rectangle1.right) 	return false;
	if (Rectangle2.top			> Rectangle1.bottom)	return false;
	if (Rectangle2.right		< Rectangle1.left)		return false;
	if (Rectangle2.bottom		< Rectangle1.top)		return false;

	/***********************************************************
	* If we could not disqualify it, it must intersect
	*************************************************************/
	return true;
}

/*************************************************************
* Rectangle object constructor
*************************************************************/
function Rectangle(nLeft, nTop, nRight, nBottom)
{
	/*******************************************************
	* Edit parameters
	********************************************************/
	nLeft		= Math.min(nLeft, nRight);
	nTop		= Math.min(nTop, nBottom);
	nRight		= Math.max(nLeft, nRight);
	nBottom		= Math.max(nTop, nBottom);

	/*******************************************************
	* Set the object properties
	********************************************************/
	this.left	= nLeft;
	this.top	= nTop;
	this.right	= nRight;
	this.bottom	= nBottom;
	this.height	= nBottom - nTop;
	this.width	= nRight  - nLeft;
}

/*********************************************************************
* Get the offset parent of the object
**********************************************************************/
function getOffsetParent(o)
{
	if (o.tagName.toUpperCase() == "BODY")
	{
		if (o.document.parentWindow.frameElement)
			return o.document.parentWindow.frameElement;
	}
	else
		return o.offsetParent;

	return null;
}

/**********************************************************************
 * return a reference the the body of the top most window
 **********************************************************************/
function getTopBody(o)
{
	var offsetParent	= getOffsetParent(o);
	if (offsetParent && (offsetParent != o))
	{
		return getTopBody(offsetParent);
	}
	else
		return o;
}

function getTopWindow() {return getTopBody(document.body).document.parentWindow;}

/*********************************************************************
* getGradientLine		Get the HTML output of a gradient line
**********************************************************************/
function getGradiantLine(strBaseColor, strGradiantColor, nLength, nHeight)
{
 	var i;
	var strOutput				= ''

	// split base color
	var aBaseColor			 	= new Array();
	aBaseColor[0]				= strBaseColor.substr(0, 2);
	aBaseColor[1]				= strBaseColor.substr(2, 2);
	aBaseColor[2]				= strBaseColor.substr(4, 2);

	// convert to decimal
	for (i=0; i < aBaseColor.length; i++)
	{
		if (isNaN(parseInt(aBaseColor[i], 16)))
			aBaseColor[i]		= 0;
		else
			aBaseColor[i]		= parseInt(aBaseColor[i], 16);
	}

	// split gradiant color
	var aGradiantColor			= new Array();
	aGradiantColor[0]			= strGradiantColor.substr(0, 2);
	aGradiantColor[1]			= strGradiantColor.substr(2, 2);
	aGradiantColor[2]			= strGradiantColor.substr(4, 2);

	// convert to decimal
	for (i=0; i < aGradiantColor.length; i++)
	{
		if (isNaN(parseInt(aGradiantColor[i], 16)))
			aGradiantColor[i]	= 0;
		else
			aGradiantColor[i]	= parseInt(aGradiantColor[i], 16);
	}

	// calculate color variances
	var aVariance				= new Array();
	for (i=0; i < aBaseColor.length; i++)
		aVariance[i]			= aGradiantColor[i] - aBaseColor[i];

	var nStart					= 0;
	var nWidth					= 4;
	var nEnd					= parseInt(nLength / (2 * nWidth));

	strOutput				   += "<table cellspacing='0' cellpadding='0' border='0'>\n<tr>\n";
	for (var nLine=0; nLine < 2; nLine++)
	{
		for (var nCell=0; nCell < nEnd; nCell++)
		{
			var nPct			= nCell / nEnd;
			if (nLine==1) nPct	= 1 - nPct;												// reverse direction

			if (nLine==1 && nCell == (nEnd -1))
				nWidth		   += nLength - (nEnd * 2 * nWidth);						// add "slop"

			var strColor		= '';
			var nColor			= 0;
			for (i=0; i < aVariance.length; i++)
			{
				nColor			= (aVariance[i] * nPct) + aBaseColor[i];
				strColor	   += dec2Hex(nColor);
			}
				strOutput	   += "<td";												//> (shut up NoteTab Pro)
				strOutput	   += " style='width:" + nWidth + "px; height:" + nHeight + "px;";
				strOutput	   += " background-color:#" + strColor + "; font-size:1px; color:#" + strColor + "'>";
				strOutput	   += "&nbsp;";
				strOutput	   += "</td>\n";
		}
	}
	strOutput				   += "</tr>\n</table>\n";
	return strOutput;
 }

 function dec2Hex(nDec)
 {
 	var strDec				= '0123456789ABCDEF';

	if (isNaN(parseInt(nDec)))
		return '00';

	var nInput				= parseInt(nDec);
	if (nInput > 255)
		return '00';

	var strOutput			= '';
	var nPart;
	for (var i=0; i < 2; i++)
	{
		if (i==0)
			nPart			= parseInt(nInput / 16);
		else
			nPart			= nInput % 16;
		strOutput		   += strDec.substr(nPart, 1);
	}
	return strOutput;
 }

/*******************************************************************************
 * This function returns a random string
 *******************************************************************************/
function getRandomString(Length)
{
	nLength				= parseInt(Length);
	if (isNaN(nLength))
		nLength			= 6;

	var strOutput	= '';
	for (var i=0; i < nLength; i++)
	{
		var c			= Math.floor((Math.random() * (122-97)) + 97); // 97='a', 122='z'
		strOutput	   += String.fromCharCode(c);
	}
	return strOutput.toUpperCase();
}

/*******************************************************************************
 * This function sends a support message -- server-side only
 *******************************************************************************/
 function sendSupportMessage(errorMessage, comments)
 {
	if (typeof(Request) == 'undefined')
		return;

	var vOpSys;

	if (is_winxp)
		vOpSys	= 'Windows XP';
	else if (is_win2k)
		vOpSys	= 'Windows 2k';
	else if (is_winnt)
		vOpSys	= 'Windows NT';
	else if (is_winme)
		vOpSys	= 'Windows ME';
	else if (is_win98)
		vOpSys	= 'Windows 98';
	else if (is_win95)
		vOpSys	= 'Windows 95';
	else if (is_win31)
		vOpSys	= 'Windows 3.1';
	else if (is_mac)
		vOpSys	= 'Macintosh';
	else if (is_linux)
		vOpSys	= 'Linux';
	else if (is_unix)
		vOpSys	= 'Unix';
	else
		vOpSys	= 'Other';

	if (is_ie6up)
		vBrowser	= 'Internet Explorer 6';
	else if (is_ie5_5up)
		vBrowser	= 'Internet Explorer 5.5';
	else if (is_ie5up)
		vBrowser	= 'Internet Explorer 5.0';
	else if (is_ie4up)
		vBrowser	= 'Internet Explorer 4.0';
	else if (is_ie3)
		vBrowser	= 'Internet Explorer 3.0';
	else if (is_nav6up)
		vBrowser	= 'Netscape 6';
	else if (is_nav4up)
		vBrowser	= 'Netscape 4';
	else if (is_nav)
		vBrowser	= 'Netscape 3';
	else if (is_aol6)
		vBrowser	= 'AOL 6.0';
	else if (is_aol5)
		vBrowser	= 'AOL 5.0';
	else if (is_aol4)
		vBrowser	= 'AOL 4.0';
	else if (is_aol)
		vBrowser	= 'AOL 3.0';
	else if (is_opera)
		vBrowser	= 'Opera';
	else
		vBrowser	= 'Other';

	// build message body
	var strMessage	= '';
	var vDate		= new Date();
	vDate			= getDateTime(vDate, '');

	strMessage	   += '<html>';
	strMessage	   += '<head>';
	strMessage	   += '<style>';
	strMessage	   += 'body {FONT-FAMILY: Tahoma; FONT-SIZE:8pt;}';
	strMessage	   += 'td {FONT-FAMILY: Tahoma; FONT-SIZE:8pt;}';
	strMessage	   += '</style>';
	strMessage	   += '</head>';
	strMessage	   += '<body>';
	strMessage	   += '<table>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Name</b></td>';
	strMessage	   += '<td>' + getMyDisplayName() + '<td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>EMail</b></td>';
	strMessage	   += '<td color=gray>(not available)<td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td valign="top"><b>HTTP Header Values</b></td>';
	strMessage	   += '<td>' + Request.ServerVariables('SERVER_SOFTWARE') + '<br>';
	strMessage	   += Request.ServerVariables('HTTP_USER_AGENT') + '</td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Operating System</b></td>';
	strMessage	   += '<td>' + vOpSys + '</td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Processor/Speed</b></td>';
	strMessage	   += '<td><font color=gray>(not available)</font></td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Memory</b></td>';
	strMessage	   += '<td><font color=gray>(not available)</font></td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Internet Connection</b></td>';
	strMessage	   += '<td><font color=gray>(not available)</font></td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Browser</b></td>';
	strMessage	   += '<td>' + vBrowser + '</td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr><td colspan="2"><hr></td></tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td><b>Time</b></td>';
	strMessage	   += '<td>' + vDate + '<td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td valign="top"><b>Type of Problem</b></td>';
	strMessage	   += '<td>Software Error Occurred</td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td valign="top"><b>Step-by-Step Account</b></td>';
	strMessage	   += '<td><font color=gray>(not available)</font></td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td valign="top"><b>Error Message</b></td>';
	strMessage	   += '<td>' + errorMessage + '</td>';
	strMessage	   += '</tr>';

	strMessage	   += '<tr>';
	strMessage	   += '<td valign="top"><b>Comments</b></td>';
	strMessage	   += '<td>' + getString(comments) + '</td>';
	strMessage	   += '</tr>';

	strMessage	   += '</table>';
	strMessage	   += '</body>';
	strMessage	   += '</html>';


	var cdoMail 		= new ActiveXObject('CDONTS.NewMail')
	cdoMail.BodyFormat	= 0;
	cdoMail.MailFormat	= 0;
	cdoMail.From		= 'automated.error.reporting@acmex.com';
	cdoMail.To			= 'support@acmex.com';
	cdoMail.Subject		= Request.ServerVariables('SERVER_NAME') + ' Troubleshooting Request';
	cdoMail.Body		= strMessage
	cdoMail.Send();
	cdoMail 			= null;
 }

/*******************************************************************************
 * Get the temporary folder path
 *******************************************************************************/
function getTempFolderPath()
{
	var objFSO		= new ActiveXObject('Scripting.FileSystemObject')
	return	objFSO.GetSpecialFolder(2)		// 2 = TemporaryFolder
}


/*******************************************************************************
 * get link
 *******************************************************************************/
function getLink(URL, Description)
{
	var strOutput, strTemp;
	strTemp			= URL + '';
	strTemp			= strTemp.toLowerCase();

	strOutput		= '<a target="_blank"';				//> (shut up NoteTab Pro)
	strOutput	   += ' href="';
	if (strTemp.substr(0,7) != 'http://')
		strOutput  += 'http://';
	strOutput	   += strTemp + '">';
	if (typeof(Description) == 'undefined')
		strOutput  += URL;
	else
		strOutput  += Description;
	strOutput	   += '</a>';

	return strOutput;
}

/*******************************************************************************
 * get Currency
 *******************************************************************************/
function getCurrency(InputAmount)
{
	var strOutput	= '';
	var nAmount		= parseFloat(InputAmount)
	if (isNaN(nAmount))
		return strOutput;

	nAmount			= nAmount.toString();
	var d			= nAmount.indexOf('.');
	if (d > -1)
	{
		strOutput	= nAmount.substr(d);
		strTemp		= strOutput + '00';
		strOutput	= strTemp.substr(0, 3);
		nAmount		= nAmount.substr(0,d);
	}
	else
		strOutput	= '.00';

	var j			= 0;
	for (var i=0; i < nAmount.length; i++)
	{
		if ((j%3)==0 && j>1)
			strOutput	= ',' + strOutput;
		j++;
		strOutput		= nAmount.substr((nAmount.length-i-1),1) + strOutput;
	}
	if (strOutput.substr(0,1) == '.')
		strOutput		= '0' + strOutput;
	strOutput			= '$' + strOutput;
	return strOutput;
}

/*******************************************************************************
 * get Credit Card Number
 *******************************************************************************/
function getCreditCard(InputCreditCard, bProtect)
{
	var bHide			= true;
	if (typeof(bProtect) != 'undefined')
		bHide			= getBoolean(bProtect);
	InputCreditCard		= InputCreditCard + '';

	var strOutput		= '';
	if (!bHide)
		strOutput		= InputCreditCard;
	else
	{
		for (var i=0; i < (InputCreditCard.length-4); i++)
			strOutput  += '*';
		strOutput	   += InputCreditCard.substr(InputCreditCard.length-4, 4);
	}
	return strOutput;
}

/*******************************************************************************
 * Bracket this value
 *******************************************************************************/
function bracketThis(InputValue, InputBracketType)
{
	var vValue			= InputValue;
	var vBracket		= '[';
	if (typeof(InputBracketType) != 'undefined')
		vBracket		= InputBracketType;

	if (vBracket == '[')
	{
		vValue			= vValue.replace(/\[/g, '');
		vValue			= vValue.replace(/\]/g, '');
		return '[' + vValue + ']';
	}
	else if (vBracket == '(')
	{
		vValue			= vValue.replace(/\(/g, '');
		vValue			= vValue.replace(/\)/g, '');
		return '(' + vValue + ')';
	}
	else if (vBracket == '{')
	{
		vValue			= vValue.replace(/\{/g, '');
		vValue			= vValue.replace(/\}/g, '');
		return '{' + vValue + '}';
	}
	else if (vBracket.length == 1)
	{
		vValue			= jReplace(vValue, vBracket, '');
		return vBracket + vValue + vBracket;
	}
	else
		return InputValue;
}

/*******************************************************************************
 * Count the requested string in the input string
 *******************************************************************************/
function getCount(InputString, RequestedStringToCount)
{
	var	strInput			= InputString + '';
	strInput				= strInput.toLowerCase();

	var strFind				= RequestedStringToCount + '';
	strFind					= strFind.toLowerCase();

	var nCount				= 0;
	var i					= 0;

	while (i > -1)
	{
		i					= strInput.indexOf(strFind, i);
		if (i > -1)
		{
			i++;
			nCount++;
		}
	}
	return nCount;
}

/*******************************************************************************
 * Get the document modified date
 *******************************************************************************/
function getDocumentTimestamp()
{
	if (typeof(Request) == 'undefined')
	{
		return document.lastModified;
	}
	else
	{
		var strPath		= Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))
		var objFSO 		= new ActiveXObject('Scripting.FileSystemObject')
		if (objFSO.FileExists(strPath))
		{
			var objFile	= objFSO.GetFile(strPath);
			return objFile.DateLastModified;
		}
		else
			return null;
	}
}

/*******************************************************************************
 * getGUIDstring		This function takes a string and turns it into a GUID.
 *******************************************************************************/
function getGUIDstring(InputString)
{
	var strIn		= getString(InputString)
	strIn			= strIn.replace(/{/g, '');
	strIn			= strIn.replace(/}/g, '');
	strIn			= strIn.replace(/-/g, '');

	var strGUID		= '';
	strGUID		   += '{';
	strGUID		   += strIn.substr(0, 8);
	strGUID		   += '-';
	strGUID		   += strIn.substr(8, 4);
	strGUID		   += '-';
	strGUID		   += strIn.substr(12, 4);
	strGUID		   += '-';
	strGUID		   += strIn.substr(16, 4);
	strGUID		   += '-';
	strGUID		   += strIn.substr(20, 12);
	strGUID		   += '}';

	return strGUID;
}

/*******************************************************************************
 * fileExists		This function takes a file string and return whether it
 *					exists or not (server-side only).
 *******************************************************************************/
function fileExists(FileName)
{
	if (typeof(Request) != 'undefined')
	{
		var strFile		= Server.MapPath(getString(FileName))
		var objFSO		= new ActiveXObject('Scripting.FileSystemObject')
		return objFSO.FileExists(strFile);
	}
	else
		return false;
}