var g_sCurrentPage = window.location.toString().toLowerCase();
var nPos = g_sCurrentPage.lastIndexOf("/");
if (nPos != -1)
{
	g_sCurrentPage = g_sCurrentPage.substr(nPos+1);
	
	// strip off any trailing querystrings
	nPos = g_sCurrentPage.indexOf("?");
	if (nPos != -1)
	{
		g_sCurrentPage = g_sCurrentPage.substr(0,nPos);	
	}

}
//*****************************
// SetAnchorOnBlur
// Ensures that when an image is hyperlinked, it won't get that annoying dotted box around it.
//*****************************
function SetAnchorOnBlur()
{
	$("a").focus( function () { $(this).blur(); } );
}
//======================================== BEGIN SORT FUNCTIONS =============================================================================================
// sort function - ascending (case-insensitive)

function sortFuncAsc(record1, record2) 
{
	var value1 = record1.optText.toLowerCase();
	var value2 = record2.optText.toLowerCase();
	if (value1 > value2) return(1);
	if (value1 < value2) return(-1);
	return(0);
}

// sort function - descending (case-insensitive)
function sortFuncDesc(record1, record2) 
{
	var value1 = record1.optText.toLowerCase();
	var value2 = record2.optText.toLowerCase();
	if (value1 > value2) return(-1);
	if (value1 < value2) return(1);
	return(0);
}
function sortSelect(selectToSort, ascendingOrder) 
{
	if (arguments.length == 1) ascendingOrder = true;    // default to ascending sort

	// copy options into an array
	var myOptions = [];
	for (var loop=0; loop<selectToSort.options.length; loop++) 
	{
		myOptions[loop] = { optText:selectToSort.options[loop].text, optValue:selectToSort.options[loop].value };
	}

	// sort array
	if (ascendingOrder) 
	{
		myOptions.sort(sortFuncAsc);
	} else {
		myOptions.sort(sortFuncDesc);
	}

	// copy sorted options from array back to select box
	selectToSort.options.length = 0;
	for (var loop=0; loop<myOptions.length; loop++) 
	{
		var optObj = document.createElement('option');
		optObj.text = myOptions[loop].optText;
		optObj.value = myOptions[loop].optValue;
		selectToSort.options.add(optObj);
	}
}
//======================================== END SORT FUNCTIONS =============================================================================================

//****************************************************
// Move the selected item in the listbox up or down
//****************************************************
function listbox_move(listID, direction) {

	var listbox = document.getElementById(listID);
	var selIndex = listbox.selectedIndex;

	if(-1 == selIndex) {
		//alert("Please select an option to move.");
		return;
	}

	var increment = -1;
	if(direction == 'up')
		increment = -1;
	else
		increment = 1;

	if((selIndex + increment) < 0 ||
		(selIndex + increment) > (listbox.options.length-1)) {
		return;
	}

	var selValue = listbox.options[selIndex].value;
	var selText = listbox.options[selIndex].text;
	listbox.options[selIndex].value = listbox.options[selIndex + increment].value
	listbox.options[selIndex].text = listbox.options[selIndex + increment].text

	listbox.options[selIndex + increment].value = selValue;
	listbox.options[selIndex + increment].text = selText;

	listbox.selectedIndex = selIndex + increment;
}

//****************************************************
// ToNumeric
// converts a string to a number as long as the string is > "-999999"
//****************************************************
function ToNumeric(sString)
{
	if (sString.length<1) return 0;
	return Math.max(-99999,sString);
}
//*******************************
// IsEmailOK
//*******************************
function IsEmailOK(sEmail)
{
	return (sEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}
//**********************************************
// isNumberFloat
//**********************************************
function isNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}
//********************************
// IsHomePage
//********************************
function IsHomePage()
{
	if (g_sCurrentPage == "") return true;
	if (g_sCurrentPage == "index.asp") return true;
	
	return false;
}

//***********************************************
// FormatCurrency
//***********************************************
function FormatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if (isNaN(num))
	{
		num = "0";
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
//*******************************
// IsValueInStringList
//*******************************
function IsValueInStringList(sValue,sReturnList)
{
	var arrList = sReturnList.split(",");
	var nLen = arrList.length;
	for (var x = 0; x<nLen; x++)
	{
		sWrk = arrList[x];
		if (sWrk == sValue)
		{
			return true;
		}
	}
	
	return false;
}
//*******************************
// IsValidFloat
//*******************************
function IsValidFloat(sString)
{
	if (sString.length==0) return false;
	if (isNumberFloat(sString)==false) return false;
	if (isNumberInt(sString)==false) return false;
	if (parseFloat(sString)<0.01) return false;
	
	//var s = parseFloat(sString).toString();
	//if (s.length != sString.length) return false;
	
	return true;
}
//**********************************************
// isNumberInt
//**********************************************
function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}

//***************************************
// IsValidNumber
//DESCRIPTION: Validates that a string contains only valid numbers.
//
//PARAMETERS:
//   strValue - String to be tested for validity
//
//RETURNS:
//   True if valid, otherwise false.
//***************************************
function  IsValidNumber( strValue ) 
{
  //var objRegExp  =  /^((\d*)|(\d*\.\d{1})|(\d*\.\d{2}))$/;  // for full currency
  var objRegExp  =  /^(\d*)$/;
  //check for numeric characters
  return objRegExp.test(strValue);
}

//****************************************************
// IsNumberInt
//****************************************************
function IsNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}	

//****************************************************
// IsNumberFloat
//****************************************************
function IsNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}	
//*******************************
// IsValidEmail
//*******************************
function IsValidEmail(sEmail)
{
	return (sEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}
//**************************************************
// ValidateIntInput
//**************************************************
function ValidateIntInput(objEvent)
{
/*
	objEvent properties: See http://www.javascriptkit.com/domref/domevent.shtml
	See also: http://msdn.microsoft.com/en-us/library/ms535863(VS.85).aspx
	
	altKey, ctrlKey, shiftKey:   Boolean properties that indicate whether the Alt, Ctrl, and Shift keys were pressed at time of the event.
	button:   An integer indicating which mouse button was pressed or released, 
	          1 = left, 2 = right, 4 = middle. If multiple buttons are pressed, 
			  the value is the sum of both buttons, such as 3 (1+2) for left and right.  
    cancelBubble:  Set to true to prevent the event from bubbling. 
	clientX, clientY: Returns the mouse coordinates at the time of the event relative to upper-left corner of the window. 
	fromElement, toElement:  For mouseover and mouseout events, these properties indicate the elements the mouse 
	                         is leaving from and moving onto, respectively. relatedTarget 
	keyCode: Property indicating the Unicode for the key pressed. Use String.fromCharCode(keyCode) to convert code to string. 
	         (see also charCode in Netscape)
	offsetX, offsetY:  Returns the mouse coordinates relative to the originating element. 
	returnValue:  Set to false to cancel any default action for the event. 
					see also preventDefault() 
	srcElement:  The element in which the event occurred on. 
					see also target
	type: A string indicating the type of event, such as "mouseover", "click", etc. 
*/
	// disallow any accelerator keys
	if (objEvent.altKey || objEvent.ctrlKey ||  objEvent.shiftKey)
	{
		return false;	
	}
	
	var nKeyCode = objEvent.keyCode;

	// dis-allow shift key
	if (nKeyCode == 16) return false;

	//alert(event.data);
	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	
	return false;
}
//**********************************************
// ValidateNumericInput
// usage: from html input form: onkeydown="return ValidateNumericInput(event.keyCode)"
//**********************************************
function ValidateNumericInput(objEvent)
{
/*
	objEvent properties: See http://www.javascriptkit.com/domref/domevent.shtml
	See also: http://msdn.microsoft.com/en-us/library/ms535863(VS.85).aspx
	
	altKey, ctrlKey, shiftKey:   Boolean properties that indicate whether the Alt, Ctrl, and Shift keys were pressed at time of the event.
	button:   An integer indicating which mouse button was pressed or released, 
	          1 = left, 2 = right, 4 = middle. If multiple buttons are pressed, 
			  the value is the sum of both buttons, such as 3 (1+2) for left and right.  
    cancelBubble:  Set to true to prevent the event from bubbling. 
	clientX, clientY: Returns the mouse coordinates at the time of the event relative to upper-left corner of the window. 
	fromElement, toElement:  For mouseover and mouseout events, these properties indicate the elements the mouse 
	                         is leaving from and moving onto, respectively. relatedTarget 
	keyCode: Property indicating the Unicode for the key pressed. Use String.fromCharCode(keyCode) to convert code to string. 
	         (see also charCode in Netscape)
	offsetX, offsetY:  Returns the mouse coordinates relative to the originating element. 
	returnValue:  Set to false to cancel any default action for the event. 
					see also preventDefault() 
	srcElement:  The element in which the event occurred on. 
					see also target
	type: A string indicating the type of event, such as "mouseover", "click", etc. 
*/
	// disallow any accelerator keys
	if (objEvent.altKey || objEvent.ctrlKey ||  objEvent.shiftKey)
	{
		return false;	
	}
	
	var nKeyCode = objEvent.keyCode;

	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	if (nKeyCode == 16) return true;
	
	return false;
}
//**********************************************
// ValidateDecimalInput
// usage: from html input form: onkeydown="return ValidateDecimalInput(event.keyCode)" -allows numeric and . (decimal point) and comma
//**********************************************
function ValidateDecimalInput(objEvent)
{
/*
	objEvent properties: See http://www.javascriptkit.com/domref/domevent.shtml
	See also: http://msdn.microsoft.com/en-us/library/ms535863(VS.85).aspx
	
	altKey, ctrlKey, shiftKey:   Boolean properties that indicate whether the Alt, Ctrl, and Shift keys were pressed at time of the event.
	button:   An integer indicating which mouse button was pressed or released, 
	          1 = left, 2 = right, 4 = middle. If multiple buttons are pressed, 
			  the value is the sum of both buttons, such as 3 (1+2) for left and right.  
    cancelBubble:  Set to true to prevent the event from bubbling. 
	clientX, clientY: Returns the mouse coordinates at the time of the event relative to upper-left corner of the window. 
	fromElement, toElement:  For mouseover and mouseout events, these properties indicate the elements the mouse 
	                         is leaving from and moving onto, respectively. relatedTarget 
	keyCode: Property indicating the Unicode for the key pressed. Use String.fromCharCode(keyCode) to convert code to string. 
	         (see also charCode in Netscape)
	offsetX, offsetY:  Returns the mouse coordinates relative to the originating element. 
	returnValue:  Set to false to cancel any default action for the event. 
					see also preventDefault() 
	srcElement:  The element in which the event occurred on. 
					see also target
	type: A string indicating the type of event, such as "mouseover", "click", etc. 
*/
	// disallow any accelerator keys
	if (objEvent.altKey || objEvent.ctrlKey ||  objEvent.shiftKey)
	{
		return false;	
	}
	
	var nKeyCode = objEvent.keyCode;

	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	if (nKeyCode == 16) return true;
	
	// allow decimal point key
	if (nKeyCode == 190) return true;
	if (nKeyCode == 110) return true;
	// allow , comma key
	if (nKeyCode == 188) return true;
	return false;
}
//**********************************************
// ValidateDecimalInputNoCommas
// usage: from html input form: onkeydown="return ValidateDecimalInputNoCommas(event.keyCode)" -allows numeric and . (decimal point)
//**********************************************
function ValidateDecimalInputNoCommas(objEvent)
{
/*
	objEvent properties: See http://www.javascriptkit.com/domref/domevent.shtml
	See also: http://msdn.microsoft.com/en-us/library/ms535863(VS.85).aspx
	
	altKey, ctrlKey, shiftKey:   Boolean properties that indicate whether the Alt, Ctrl, and Shift keys were pressed at time of the event.
	button:   An integer indicating which mouse button was pressed or released, 
	          1 = left, 2 = right, 4 = middle. If multiple buttons are pressed, 
			  the value is the sum of both buttons, such as 3 (1+2) for left and right.  
    cancelBubble:  Set to true to prevent the event from bubbling. 
	clientX, clientY: Returns the mouse coordinates at the time of the event relative to upper-left corner of the window. 
	fromElement, toElement:  For mouseover and mouseout events, these properties indicate the elements the mouse 
	                         is leaving from and moving onto, respectively. relatedTarget 
	keyCode: Property indicating the Unicode for the key pressed. Use String.fromCharCode(keyCode) to convert code to string. 
	         (see also charCode in Netscape)
	offsetX, offsetY:  Returns the mouse coordinates relative to the originating element. 
	returnValue:  Set to false to cancel any default action for the event. 
					see also preventDefault() 
	srcElement:  The element in which the event occurred on. 
					see also target
	type: A string indicating the type of event, such as "mouseover", "click", etc. 
*/
	// disallow any accelerator keys
	if (objEvent.altKey || objEvent.ctrlKey ||  objEvent.shiftKey)
	{
		return false;	
	}
	
	var nKeyCode = objEvent.keyCode;

	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	if (nKeyCode == 16) return true;
	
	// allow decimal point key
	if (nKeyCode == 190) return true;
	if (nKeyCode == 110) return true;
	return false;
}
//**********************************************
// ValidateDecimalInputMinusOKNoCommas
// usage: from html input form: onkeydown="return ValidateDecimalInputNoCommas(event.keyCode)" -allows numeric and . (decimal point)
//**********************************************
function ValidateDecimalInputMinusOKNoCommas(objEvent)
{
/*
	objEvent properties: See http://www.javascriptkit.com/domref/domevent.shtml
	altKey, ctrlKey, shiftKey:   Boolean properties that indicate whether the Alt, Ctrl, and Shift keys were pressed at time of the event.
	button:   An integer indicating which mouse button was pressed or released, 
	          1 = left, 2 = right, 4 = middle. If multiple buttons are pressed, 
			  the value is the sum of both buttons, such as 3 (1+2) for left and right.  
    cancelBubble:  Set to true to prevent the event from bubbling. 
	clientX, clientY: Returns the mouse coordinates at the time of the event relative to upper-left corner of the window. 
	fromElement, toElement:  For mouseover and mouseout events, these properties indicate the elements the mouse 
	                         is leaving from and moving onto, respectively. relatedTarget 
	keyCode: Property indicating the Unicode for the key pressed. Use String.fromCharCode(keyCode) to convert code to string. 
	         (see also charCode in Netscape)
	offsetX, offsetY:  Returns the mouse coordinates relative to the originating element. 
	returnValue:  Set to false to cancel any default action for the event. 
					see also preventDefault() 
	srcElement:  The element in which the event occurred on. 
					see also target
	type: A string indicating the type of event, such as "mouseover", "click", etc. 
*/
	// disallow any accelerator keys
	if (objEvent.altKey || objEvent.ctrlKey ||  objEvent.shiftKey)
	{
		return false;	
	}
	
	var nKeyCode = objEvent.keyCode;

	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	if (nKeyCode == 16) return true;
	
	// allow decimal point key
	if (nKeyCode == 190) return true;
	if (nKeyCode == 110) return true;
	
	// allow minus sign or dash  key
	if (nKeyCode == 109) return true;
	if (nKeyCode == 189) return true;
	return false;
}
//****************************************************
// StripStringOfCommas
// Removes commas and minus sign from a string
//****************************************************
function StripStringOfCommas(sString)
{
	
	var s = sString.replace(/,/g,"");  	// remove commas from string
	s = s.replace(/-/g,"");  //remove the minus sign
	return s;
}
//****************************************************
// IsMac
//****************************************************
function IsMac()
{
  if(navigator.appVersion.indexOf("Win") != -1)
  {
    return false;
  }
  else if(navigator.appVersion.indexOf("Mac") != -1)
  {
    return true;
  }
  else return false;
}
//****************************************************
// ConvertHTML
// Converts the opening and closing HTML tags to parens
//****************************************************
function ConvertHTML(sInput)
{
	var sOutput = sInput;
    sOutput=sOutput.replace(/</g,"(");
    sOutput=sOutput.replace(/>/g,")");
	return sOutput;
}
//****************************************************
// CleanWordChars
//****************************************************
function CleanWordChars(inputString)
{
	//alert("entry to CleanWords");
	return inputString;  // mfindlay: not needed in a UTF-8 site.
	
	var returnString = inputString;
	
	var nLen = returnString.length;
	
	//alert("before: " + returnString);
	
	// clean special MSWord chars
	/*
	returnString = returnString.replace(//g,"...");  			// replace elipses with ascii ...
	returnString = returnString.replace(//g,"'");  			// replace apos with ascii apos
	returnString = returnString.replace(//g,"\"");  			// replace ending quotes with ascii ending quotes
	returnString = returnString.replace(//g,"\"");  			// replace beginning quotes with ascii ending quotes
	returnString = returnString.replace(//g,"1/2");  			// replace  with 1/2
	*/
	
	//alert("after: " + returnString);

	for (var x=0; x<nLen; x++)
	{
		var c = returnString.charAt(x);
		
		// standard alpha chars
		if ((c >='a') && (c <='z')) continue;
		if ((c >='A') && (c <='Z')) continue;
		if ((c >='0') && (c <='9')) continue;
		
		// standard keyboard special chars
		switch(c)
		{
			// Allow the < and the > since the calling code takes care of editing it.
			case '>' : continue;	
			case '<' : continue;	
			
			case ' ' : continue;	
			case '.' : continue;	
			case ',' : continue;	
			case '?' : continue;	
			case '!' : continue;	
			case '"' : continue;	
			case '-' : continue;	
			case '@' : continue;	
			case '#' : continue;	
			case '$' : continue;	
			case '%' : continue;	
			case '^' : continue;	
			case '*' : continue;	
			case '&' : continue;	
			case '(' : continue;	
			case ')' : continue;	
			case '_' : continue;	
			case '+' : continue;	
			case '=' : continue;	
			case '[' : continue;	
			case ']' : continue;	
			case '{' : continue;	
			case '}' : continue;	
			case '&' : continue;	
			case '\'' : continue;	
			case ';' : continue;	
			case ':' : continue;	
			case '`' : continue;	
			case '~' : continue;	
			case '/' : continue;	
			case '|' : continue;	
			case '\\' : continue;	
			case '\t' : continue;	
			case '\r' : continue;	
			case '\n' : continue;	
			case '\r\n' : continue;	
		}
		
		//alert("Replacing char: [" + c + "] with space");
		
		// drop this unknown char
		//returnString[x]=' '; 
		returnString = returnString.replace(c," ");  
	}
	
	return returnString;
}
//****************************************************
// StripStringOfVulnerableChars 
// Removes vulnerable chars from a string
//****************************************************
function StripStringOfVulnerableChars(sString,bStripSpaces)
{
	
	var s = sString.replace(/'/g,"");  	// remove tics from string
	s = s.replace(/;/g,"");  			// remove semicolons from string
	s = s.replace(/\(/g,"");  			// remove lefts paren from string
	s = s.replace(/\)/g,"");  			// remove right parens from string
	s = s.replace(/\*/g,"");  			// remove asterisk from string
	s = s.replace(/"/g,"");  			// remove double quotes from string
	s = s.replace(/--/g,"");  			// remove double dash from string
	s = s.replace(/=/g,"");  			// remove equal signs from string

	//s = s.replace(/#/g,"");  			// remove pound signs from string
	if (bStripSpaces)
	{
		s = s.replace(/ /g,"");  		// remove spaces from string
	}
	return s;
}

//****************************************************
// JSTrim
// Removes LEADING and TRAILING spaces ONLY from a string
// optional 3rd and 4th parms: BOOL BOOL
// 3rd parm: BOOL  - strip vulnerable chars
// 4th parm: BOOL  - strip internal spaces as part of strip
//****************************************************
function JSTrim (inputString, removeChar) 
{
	// Clean MSWord chars et al.
	var returnString = CleanWordChars(inputString);
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	var s = ConvertHTML(returnString);
	
	// check to see if additional parms were passed to tell us to 
	// strip out dangerous security risk chars
	var bCheckForVulnerabilities = (JSTrim.arguments.length > 2) ? JSTrim.arguments[2] : false;
	var bStripSpacesFromString = (JSTrim.arguments.length > 3) ? JSTrim.arguments[3] : false;
	
	// if requested, strip also for vulnerabilities
	if (bCheckForVulnerabilities) 
	{
		s = StripStringOfVulnerableChars(s,bStripSpacesFromString);
	}
	else
	{
		// just clean of all spaces?
		if (bStripSpacesFromString)
		{
			s = s.replace(/ /g,"");  		// remove spaces from string
		}
	}
	
	return s;
}
//****************************************************
// JSTrimSpace
// Removes leading and trailing spaces from a string
// optional 2nd and 3rd parms: BOOL BOOL
// 2nd parm: BOOL  - strip vulnerable chars
// 3rd parm: BOOL  - strip internal spaces as part of strip
//****************************************************
function JSTrimSpace(inputString)
{
	// strip vulnerable chars?
	var bCheckForVulnerabilities = (JSTrimSpace.arguments.length > 1) ? JSTrimSpace.arguments[1] : false;
	var bStripSpacesFromString = (JSTrimSpace.arguments.length > 2) ? JSTrimSpace.arguments[2] : false;

	return JSTrim(inputString,' ',bCheckForVulnerabilities,bStripSpacesFromString);
}

//****************************************************
// CCTrim (credit card trim)
// Removes dashes from a string
// Removes spaces from anywhere within the string
//****************************************************
function CCTrim(sString)
{
	var s = sString.replace(/-/g,"");  // remove dashes from string
	s = s.replace(/ /g,"");  // remove spaces from string
	return s;
}

//****************************************************
// IsPositiveInt
// Returns true if a string >= zero.
//****************************************************
function IsPositiveInt(sString)
{
	if (sString.length < 1) return false;
	
	for (var x=0; x<sString.length; x++)
	{
		// Make sure the tax rates are numeric only, with the exception of the '.'
		if (sString.charAt(x) < "0" || 
			sString.charAt(x) > "9")
		{
			return false;
		}
	}
	return true;
}
//*******************************
// IsValidCCNumber
//*******************************
function IsValidCCNumber(s) {
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
	x = s.charAt(i);
	if (v.indexOf(x,0) != -1)
	w += x;
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
	a = w.charAt(i*2+m) * 2;
	c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
}
//****************************************************
// AreDatesInSequence
// determines if from date is < = to date
//****************************************************
function AreDatesInSequence(strFROM, strTO)
{
	var dtFrom = new Date(strFROM);
	var dtTo = new Date(strTO);
	
	if (dtFrom.getFullYear() < dtTo.getFullYear()) { return true; }
	
	if (dtFrom.getFullYear() == dtTo.getFullYear()) 
	{
		if (dtFrom.getMonth() < dtTo.getMonth()) { return true; }
	}
	
	if (dtFrom.getFullYear() == dtTo.getFullYear()) 
	{
		if (dtFrom.getMonth() == dtTo.getMonth()) 
		{
			if (dtFrom.getDate() <= dtTo.getDate()) { return true; } 
		}
	}
	
	return false;
}
var popUpLinkWin=0;
//****************************************************
// popUpLinkWindow
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow(url)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	var nWidth=650;
	var nHeight=450;
	var nLeft=200;
	var nTop=10;
	
	if (popUpLinkWindow.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow.arguments[1])
	}
	if (popUpLinkWindow.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow.arguments[2])
	}
	if (popUpLinkWindow.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow.arguments[3])
	}
	if (popUpLinkWindow.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow.arguments[4])
	}
	
	popUpLinkWin = open(url, 'link', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
	popUpLinkWin.focus();
}

var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,height=510,width=510,copyhistory=0,"; 
var winopts2 = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=yes,height=460,width=700,copyhistory=0,"; 
var smallwindow = null;
function setEvent() {
     return false;
}
function historywin(filename) {
    fileURL=filename;
     if (parseInt(navigator.appVersion) < 4) {
        if (smallwindow != null) smallwindow.close();
   }  
    timerID= setTimeout('Opener(fileURL)',100);
                              }
function Opener(winname)
{
	var useopts = winopts;
  	filename = winname;
  
  	// if circlepix, set different window size
  	if (filename.indexOf("circlepix") != -1)
  	{
  		useopts = winopts2;
  	}
  
  	winname = "historywin"
 
  	smallwindow = window.open(filename,winname,useopts)
  
  	if( navigator.appVersion.indexOf("(X11") != -1 || 
  	navigator.appVersion.indexOf("(Mac") != -1)
  	{
       smallwindow = window.open(filename,winname,useopts)
  	}

  	if( navigator.appVersion.indexOf("MSIE") == -1 )
  	{
      smallwindow.mainWin = this;
  	}
    
	WindowFocus();
}

//*********************************************
// WindowFocus
//*********************************************
function WindowFocus()
{
  
	if( navigator.appVersion.indexOf("2.") == -1 &&  navigator.appVersion.indexOf("MSIE") == -1 )
	{
	   smallwindow.focus();
	}
}
//******* END VIRTUAL TOUR FUNCTIONS *************************************************************************
//*****************************
// IsAreaOccupied
// determines if the areas has any input, textarea or checkboxes that have content
//*****************************
function IsAreaOccupied(sArea)
{
	var bIsOccupied=false;
	var sScanArea="";
	
	// if the area is already visible, do not bother checking it.
	if ($(sArea).css("display")!="none") return false;
	
	// examine all input and text areas
	sScanArea = sArea + " input, " + sArea + " textarea";
	if (!bIsOccupied)
	{
		$(sScanArea).each(function(){
				if ($(this).val().length > 0)	
				{
					bIsOccupied=true;
					return false; // return false breaks out of jquery 'each' loop, return true jumps to the next iteration
				}	
			}); // each
	}
	
	// examine all radio and checkboxes
	sScanArea = sArea + " input:checkbox, " + sArea + " input:radio";
	if (!bIsOccupied)
	{
		$(sScanArea).each(function(){
				if ($(this).attr('checked') == true)	
				{
					bIsOccupied=true;
					return false; // return false breaks out of jquery 'each' loop, return true jumps to the next iteration
				}	
			}); // each
	}
	
	// examine all select boxes
	sScanArea = sArea + " select";
	if (!bIsOccupied)
	{
		$(sScanArea).each(function(){
				if ($(this).attr('selectedIndex') > 0)	
				{
					bIsOccupied=true;
					return false; // return false breaks out of jquery 'each' loop, return true jumps to the next iteration
				}	
			}); // each
	}
	
	return bIsOccupied;
}
//*****************************
// TurnOffMouseWheel
//*****************************
function TurnOffMouseWheel()
{
	$("select").each(function(){
				$(this).bind("mousewheel", function(e){
					//alert("mousewheel detected");
      				return false;
    			}); // bind
					
			}); // each
}
//*****************************
// ShowHide
//*****************************
function ShowHide(sID)
{
	var obj = $("#" + sID);
	if (obj.length < 1) return;
	
	obj.toggle();
}
//*****************************
// IsBrowseBooksSection
//*****************************
function IsBrowseBooksSection()
{
	if (g_sCurrentPage=="browse_books.asp") return true;
	if (g_sCurrentPage=="book.asp") return true;
	
	return false;
}
//*****************************
// IsBrowseAuthorsSection
//*****************************
function IsBrowseAuthorsSection()
{
	if (g_sCurrentPage=="browse_authors.asp") return true;
	if (g_sCurrentPage=="author.asp") return true;
	
	return false;
}
//*****************************
// IsBrowseBooksSection
//*****************************
function IsBrowseBroadsidesSection()
{
	if (g_sCurrentPage=="browse_broadsides.asp") return true;
	if (g_sCurrentPage=="broadside.asp") return true;
	
	return false;
}
//****************************************************
// IsOpera
//****************************************************
function IsOpera()
{
	var sString = navigator.userAgent.toLowerCase();
	if(sString.indexOf("opera") != -1)
	{
		return true;
	}
	return false;
}

//**********************************************************
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
//**********************************************************
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isFirefox     = (ua.indexOf('firefox') != -1);     //mjf
   this.isChrome     = (ua.indexOf('chrome') != -1);     //mjf
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

//---------------------------------------
// GetCSSFilename
// Returns the css file to use based on the user's browser
//---------------------------------------
function GetCSSFilename()
{
	//dim sBrowser
	var sPlatform = (browser.isMac) ? "mac_" : "pc_";
	var sFile="";
	var sBrowser="";
	
	// Determine running IE
	if (browser.isIE)
	{
		sBrowser = "ie";
	}
	
	// Determine running Safari
	if (browser.isSafari)
	{
		sBrowser = "safari";
	}
	
	// Determine running Chrome
	if (browser.isChrome)
	{
		sBrowser = "chrome";
	}
	
	// Determine running Opera
	if (browser.isFirefox)
	{
		sBrowser = "firefox";
	}
	
	// Determine running Opera
	if (browser.isOpera)
	{
		sBrowser = "opera";
	}
	
	// determine if user is on a Netscape 4.xx 
	if (browser.isNS4x)
	{
		sBrowser = "ns4";
	}
	
	// determine if user is on a Netscape 6.xx 
	if (browser.isNS6x)
	{
		sBrowser = "ns6";
	}
	
	// determine if user is on a Netscape 7.xx 
	if (browser.isNS7up)
	{
		sBrowser = "ns7";
	}
	
	// if no browser yet determined, attempt a default
	if (sBrowser=="")
	{
		if (browser.isNS)
		{
			sBrowser="ns7";
		}
	}

	// set the filename
	sFile = sPlatform + sBrowser + ".css";
	
	// build appropriate stylesheet link
	//alert(sBaseSite + "css/" + sFile);
	//alert("<link href=\"" + sBaseSite + "css/" + sFile + "\" rel=\"stylesheet\" type=\"text/css\" />");
	document.writeln("<link href=\"" + sBaseSite + "css/" + sFile + "\" rel=\"stylesheet\" type=\"text/css\" />");
}

