var QSMode = ""
/*var dDate = new Date();
var dCurMonth = dDate.getMonth();
var dCurDayOfMonth = dDate.getDate();
var dCurYear = dDate.getFullYear();
var objPrevElement = new Object();
var datField;
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false*/
var PatternLib = new Object();
PatternLib.containsUpperCase = /[A-Z]/;
//contains an lower case character
PatternLib.containsLowerCase = /[a-z]/;
//contains a digit
PatternLib.containsDigits = /[0-9]/;

var bChangedFlag = false;
var tempChangedFlag = false;
var bConfirmed = false;
var bSupportsChangeWarning = true;
function setChanged(bValue)
{
		    bChangedFlag = bValue;
}

function displayClientPicList(iHiddenID,sDivTagID, sScriptName, iAppID)
{
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 760)/2;
	yOffset = (yMax - 300)/2;

	billingClient = window.open("../../common/groupsclients/client_select.asp?id= " + iHiddenID + "&fieldnm=" + sDivTagID + "&script=" + sScriptName + "&appID=" + iAppID,"loading","width=760, height=300,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no,scrollbars=yes",true);
}        

function displaySaveWarning()
{
		   var sPrompt = "";
		    if (bChangedFlag && bSupportsChangeWarning) {

			    return "You have edited this page. Are you sure you want to leave without saving?"
			}

}
function confirmSearch() {

	var sPrompt =  "Are you sure you want to navigate away from this page? \n\nYou have edited this page. Are you sure you want to leave without saving?\n\nPress OK to continue, or Cancel to stay on the current page."
	bConfirmed = confirm(sPrompt);
	
	bChangedFlag = false;
	if (bConfirmed) {		
		return true;
	}else{
		return false;
	}
}

if (! bConfirmed) {
	window.onbeforeunload = displaySaveWarning;
}



//verify that the password contains upper case characters
function Jcontainsuppercase(password)
{
	if (password != '')
	{
		if (PatternLib.containsUpperCase.exec(password) == null)
		{
			return false;
		}
		else
		{			
			return true;
		}
	}
	else
	{
		return false;
	}
}

//verify that the password contains lower case characters
function Jcontainslowercase(password)
{
	
	if (password != '')
	{
		if (PatternLib.containsLowerCase.exec(password) == null)
		{
			return false;
		}
		else
		{			
			return true;
		}
	}
	else
	{
		return false;
	}
}

//verify that the password contains digits
function Jcontainsdigits(field)
{
	
	if (field != '')
	{
		if (PatternLib.containsDigits.exec(field) == null)
		{
			return false;
		}
		else
		{			
			return true;
		}
	}
	else
	{
		return false;
	}
}

/*function layerWrite(id,text,win) {
	
	if (ns4) {
		var lyr = document.layers[id].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
	else if (ie4) {
		if (win == "") {
			win = "window";
		}
		s = eval(win + ".document.all." + id);
		s.innerHTML = text;
	}
}
*/
function selectDay(pObj)
{

	if (pObj.style.background == "#c1cee7")
	{
		pObj.style.background="#e4e6f1"
		pObj.style.color="#c1cee7"
		
		switch(pObj.name) {
			case "sunday":
				document.all.chkDaysun.value = "";
				break;
			case "monday":
				document.all.chkDaymon.value = "";
				break;
			case "tuesday":
				document.all.chkDaytue.value = "";
				break;
			case "wednesday":
				document.all.chkDaywed.value = "";
				break;
			case "thursday":
				document.all.chkDaythu.value = "";
				break;
			case "friday":
				document.all.chkDayfri.value = "";
				break;
			case "saturday":
				document.all.checkDaysat.value = "";
				break;
		}
	}
	else
	{
		pObj.style.background="#c1cee7"
		pObj.style.color="#08083a"

		switch(pObj.name) {
			case "sunday":
				document.all.chkDaysun.value = 1;
				break;
			case "monday":
				document.all.chkDaymon.value = 1;
				break;
			case "tuesday":
				document.all.chkDaytue.value = 1;
				break;
			case "wednesday":
				document.all.chkDaywed.value = 1;
				break;
			case "thursday":
				document.all.chkDaythu.value = 1;
				break;
			case "friday":
				document.all.chkDayfri.value = 1;
				break;
			case "saturday":
				document.all.chkDaysat.value = 1;
				break;
		}
	}
}

function overDay(pObj)
{
		pObj.style.color="#08083a"
}

function offDay(pObj)
{
	if (pObj.style.background == "#e4e6f1" || pObj.style.background == "")
		pObj.style.color="#c1cee7"
}

function simpleSearch(pLogin)
{
	if (document.searchForm.searchType[0].checked)
	{
		if (pLogin)
			document.location.href="search_results_login.htm"
		else
			document.location.href="search_results.htm"
	}
	else
	{
		document.location.href="public_fac_results.htm"
	}
}

var isNS = (navigator.appName == "Netscape");
var layerObj,styleObj,tHTML;

//layer object definitions
layerObj = (isNS) ? 'document' : 'document.all';
styleObj = (isNS) ? '' : '.style';

function showIt(val1,val2) {
	var n;

	eval(layerObj + "['" + val1 + "']" + styleObj + ".visibility = 'visible'");
	if (val2 != '' && typeof(val2) != "undefined") {
		eval(layerObj + "['" + val2 + "']" + styleObj + ".visibility = 'visible'");
	}
}

function hideIt(val1,val2) {
	var n;

	eval(layerObj + "['" + val1 + "']" + styleObj + ".visibility = 'hidden'");
	if (val2 != '' && typeof(val2) != "undefined") {
		eval(layerObj + "['" + val2 + "']" + styleObj + ".visibility = 'hidden'");
	}
}

function showGroupScreen()
{
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 400)/2;
	yOffset = (yMax - 150)/2;

	groupSelect = window.open("group_select.htm","loading","width=400, height=150,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no",true);
}


/*function showCalendar(y)
{
	if (typeof(bChangedFlag) != "undefined")
	{
		tempChangedFlag = bChangedFlag;
		bChangedFlag = false;
	}
	
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 188)/2;
	yOffset = (yMax - 184)/2;

	datField = y;
	calWin = window.open("../../Common/calendar.htm","calendar","width=188, height=184,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=yes,status=yes",true);
	var dCurDate = new Date();
	fDrawCal(dCurDate.getFullYear(), dCurDate.getMonth()+1, 16, 16, "11px", "bold", 0);

}*/


function fSetSelectedDay(myElement){

	if (myElement.id == "calCell") {
		if (!isNaN(parseInt(myElement.children["calDateText"].innerText))) {
			myElement.bgColor = "#c0c0c0";
			//objPrevElement.bgColor = "";
			calWin.document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText);
			t = eval("document.all." + datField)
			t.value = calWin.document.all.tbSelMonth.value + "/" + calWin.document.all.calSelectedDate.value + "/" + calWin.document.all.tbSelYear.value;
			//objPrevElement = myElement;
			calWin.close();
			calWin = "";
			datField = "";
	    }
	}
}

function fGetDaysInMonth(iMonth, iYear) {
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

function fBuildCal(iYear, iMonth, iDayStyle) {
	var aMonth = new Array();
	aMonth[0] = new Array(7);
	aMonth[1] = new Array(7);
	aMonth[2] = new Array(7);
	aMonth[3] = new Array(7);
	aMonth[4] = new Array(7);
	aMonth[5] = new Array(7);
	aMonth[6] = new Array(7);
	var dCalDate = new Date(iYear, iMonth-1, 1);
	var iDayOfFirst = dCalDate.getDay();
	var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
	var iVarDate = 1;
	var i, d, w;
	if (iDayStyle == 2) {
		aMonth[0][0] = "Sunday";
		aMonth[0][1] = "Monday";
		aMonth[0][2] = "Tuesday";
		aMonth[0][3] = "Wednesday";
		aMonth[0][4] = "Thursday";
		aMonth[0][5] = "Friday";
		aMonth[0][6] = "Saturday";
	} else if (iDayStyle == 1) {
		aMonth[0][0] = "Sun";
		aMonth[0][1] = "Mon";
		aMonth[0][2] = "Tue";
		aMonth[0][3] = "Wed";
		aMonth[0][4] = "Thu";
		aMonth[0][5] = "Fri";
		aMonth[0][6] = "Sat";
	} else {
		aMonth[0][0] = "Su";
		aMonth[0][1] = "Mo";
		aMonth[0][2] = "Tu";
		aMonth[0][3] = "We";
		aMonth[0][4] = "Th";
		aMonth[0][5] = "Fr";
		aMonth[0][6] = "Sa";
	}
	for (d = iDayOfFirst; d < 7; d++) {
		aMonth[1][d] = iVarDate;
		iVarDate++;
	}
	for (w = 2; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			if (iVarDate <= iDaysInMonth) {
				aMonth[w][d] = iVarDate;
				iVarDate++;
		    }
	    }
	}
	return aMonth;
}

/*function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
	var myMonth;
	myMonth = fBuildCal(iYear, iMonth, iDayStyle);
	drwCells = "<table border='0' width='100%' valign='top'>"
	+ "<tr>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][0] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][1] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][2] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][3] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][4] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][5] + "</td>"
	+ "<td class='calTitle' align='center' width='16' nowrap>" + myMonth[0][6] + "</td>"
	+ "</tr>";
	for (w = 1; w < 7; w++) {
		drwCells += "<tr>";
		for (d = 0; d < 7; d++) {
			drwCells += "<td id=calCell align='center' valign='top' width='" + iCellWidth + "' class='calDay' style='CURSOR:Hand;' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=opener.fSetSelectedDay(this)>";
				if (!isNaN(myMonth[w][d])) {
					drwCells += "<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=opener.fSetSelectedDay(this)>" + myMonth[w][d] + "</font>";
				} else {
					drwCells += "<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=opener.fSetSelectedDay(this)> &nbsp;</font>";
				}
			drwCells += "</td>";
		}
		drwCells += "</tr>";
		}
		drwCells += "</table>";
		layerWrite("tableCells", drwCells, "calWin");
	}

*/
function showVerifyScreen()
{
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 400)/2;
	yOffset = (yMax - 400)/2;

	verifyWin = window.open("../../common/help/verifycard.htm","verify","width=400, height=400,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no,scrollbars=auto",true);
}

function showConfirmRemoveEventScreen()
{
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 400)/2;
	yOffset = (yMax - 150)/2;

	groupSelect = window.open("confirm_remove_event.htm","confirm","width=400, height=150,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no",true);
}

function showConfirmRemovePartScreen(pObj)
{
	if (pObj.checked == false)
	{
		if (document.all)
		{
			xMax = screen.width;
			yMax = screen.height;
		}
		else if (document.layers)
		{
			xMax = window.outerWidth;
			yMax = window.outerHeight;
		}
		else
		{
			xMax = 800;
			yMax = 400;
		}
	//The values you subtract from xMax and yMax should be the same size of the window you are creating.
		xOffset = (xMax - 400)/2;
		yOffset = (yMax - 150)/2;

		groupSelect = window.open("confirm_remove_part.htm","confirm","width=400, height=150,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no",true);
	}
}

function showEventDescription(id,soroot)
{
	var url = soroot + "/events/event_desc.aspx?id=" + id;
	
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 400)/2;
	yOffset = (yMax - 200)/2;

	evtDetail = window.open(url,"search","width=400, height=200,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no,scrollbars=yes",true);
}

function selectAcctMgr(vPath,vReturnPath, vGrpID)
{
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 400;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 250)/2;
	yOffset = (yMax - 220)/2;

	evtDetail = window.open(vPath + "acctmgr_select.asp?rPath=" + vReturnPath + "&grp_id=" + vGrpID,"search","width=250, height=220,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no,scrollbars=auto",true);
}

function setAllChecks(pCheckName, pValue)
{

	var checkboxArray = eval("document.all." + pCheckName)

	var numElements = checkboxArray.length;

	if (typeof(numElements) == "undefined") {
		checkboxArray.checked = !(checkboxArray.checked);
	}else {
		
		for (var i = 0; i < numElements; i++)
		{	
			checkboxArray[i].checked = pValue
		}
	}
}	

function CheckViewPerms(pName, pCount, pChecked, pAccess)
{
	if (pChecked == "toggle")
		pChecked = eval("document.all." + pName + "v" + pCount + ".checked");
	if (pChecked != true)
		{
			alert("The user must have VIEW access first.");
		}
	return pChecked;
}

function UncheckOtherAccess(pName, pCount, pChecked, pAccess)
{
	if (pChecked == "toggle")
		pChecked = eval("document.all." + pName + "v" + pCount + ".checked");
	if (pChecked == false) // && pName.substr(pName.length - 1, pName.length) == "v")
	{
		eval("document.all." + pName + "c" + pCount + ".checked=" + pChecked);
		eval("document.all." + pName + "e" + pCount + ".checked=" + pChecked);
	}
}

function setAllUserPerm(pName, pCount, pChecked)
{
	if (pName.substr(pName.length - 1, pName.length) != "v")
	{
		if (pChecked == "toggle")
		{
			if (eval("document.all." + pName.substr(0,pName.length - 1) + "v" + pCount + "All.checked") != true)
			{
				alert("The user must have VIEW access first.");
				return false;
			}
		}
	}

	if (pCount == "" || typeof(pCount) == "undefined") {
		fldName = pName.substr(0,pName.length - 1);

		t = eval("document.all." + fldName + "counter.value");
		pCount = t;
	}

	if (pChecked == "toggle")
		pChecked = eval("document.all." + pName + "All.checked");

	for (var i=1; i<=pCount; i++)
	{
		eval("document.all." + pName + i + ".checked=" + pChecked);
	}
	if (pChecked == false && pName.substr(pName.length - 1, pName.length) == "v")
	{
		eval("document.all." + pName.substr(0,pName.length - 1) + "c" + "All.checked=" + pChecked);
		eval("document.all." + pName.substr(0,pName.length - 1) + "e" + "All.checked=" + pChecked);
		for (var i=1; i<=pCount; i++)
		{
			eval("document.all." + pName.substr(0,pName.length - 1) + "c" + i + ".checked=" + pChecked);
		}
		for (var i=1; i<=pCount; i++)
		{
			eval("document.all." + pName.substr(0,pName.length - 1) + "e" + i + ".checked=" + pChecked);
		}
	}
}

//function setAllUserPerm(pName, pCount, pChecked)
//{
//	if (pCount == "" || typeof(pCount) == "undefined") {
//		fldName = pName.substr(0,pName.length - 1);
//
//		t = eval("document.all." + fldName + "counter.value");
//		pCount = t;
//	}
//
//	if (pChecked == "toggle")
//		pChecked = eval("document.all." + pName + "All.checked");
//	for (var i=1; i<=pCount; i++)
//	{
//		eval("document.all." + pName + i + ".checked=" +pChecked);
//	}
//}

function printQuickReport(pID,pScriptName)
{
	var url = "../../common/quickreports/" + pScriptName + "?id=" + pID
		
	if (document.all)
	{
		xMax = screen.width;
		yMax = screen.height;
	}
	else if (document.layers)
	{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
	}
	else
	{
		xMax = 800;
		yMax = 600;
	}
//The values you subtract from xMax and yMax should be the same size of the window you are creating.
	xOffset = (xMax - 800)/2;
	yOffset = (yMax - 600)/2;

	printWin = window.open(url,"confirm","width=800, height=600,screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",resizable=no,scrollbars=yes",true);
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	if(dtStr == "") //ignore if no date, only ensure required datefields through ASP
		return true;
		
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
function trimall(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


//refresh the current script with a new quick jump index
function refreshWithNewQuickJumpIndex(pObj, currentSript)
{
	parent.document.location=currentSript + "?newIndex=" + pObj[pObj.selectedIndex].value
}

//refresh the current script with a new quick jump index
function refreshWithNewEventQuickJumpIndex(pObj, currentSript)
{
	parent.document.location=currentSript + "?nid=" + pObj[pObj.selectedIndex].value
}

function refreshNavNewEventQuickJumpIndex(pObj, val) {
	objNav = eval("document.all." + pObj);
	
	if (objNav[0].selectedIndex != 0 || parseInt(val) == 1) {
		objNav[0].selectedIndex += parseInt(val);
		objNav[0].fireEvent("onchange");
	}		
}
function sortOrder(vField, vSort, currentSript) {
	document.write("<form action='" + currentSript + "' method='post' name='orderEvt'>");
	document.write("	<input type='hidden' name='f' value='" + vField + "'>");
	document.write("	<input type='hidden' name='s' value='" + vSort + "'>");
	document.write("</form>");
	document.orderEvt.submit();
}

function deleteConfirm(LocEquip){
	confirmValue = confirm("This action will remove this item.");
	if (confirmValue == true){
		document.form1.deletedID.value = LocEquip;
		//alert(document.form1.deletedID.value);
		document.form1.deleted.value = "1";
		form1.submit();
	}

		
}

// This function is shared between event staff personal info and facilities staff personal info
function ValidateStaffPersonalInfoForm()
{
	var isPrimarySelected = false;
	var isCompletePhoneEntered = false;
	var arPhones = new Array(4);
	var phonePart1;
	var phonePart2;
	var phoneIndex;
	
	for(i = 0; i < 4; i++)
	{
		phoneIndex = i + 1;
		phoneArea = eval("document.staffForm.phone" + phoneIndex + "_areaCode.value")
		phonePart1 = eval("document.staffForm.phone" + phoneIndex + "_Pt1.value")
		phonePart2 = eval("document.staffForm.phone" + phoneIndex + "_Pt2.value")
		if(phoneArea.length > 0 && phonePart1.length > 0 && phonePart2.length > 0)
		{
			isCompletePhoneEntered = true;
			arPhones[i] = i;
			
		} 
		/*
		if(phoneArea.length == 0 && phonePart1.length > 0 && phonePart2.length > 0) {
			alert("Please enter a complete phone number, including area code.");
		return false;
		}
		*/
	}
		
	if(isCompletePhoneEntered == true)
	{
		for(i = 0; i < document.staffForm.primaryPhone.length; i++)
		{
			isPrimarySelected = document.staffForm.primaryPhone[i].checked
			if(isPrimarySelected == true) //primary radio button is checked
			{
				//now make sure it is selected on a complete phone
				if (arPhones[0] == i || arPhones[1] == i ||
					arPhones[2] == i || arPhones[3] == i)
				{
					break;				
				}
				else
				{
					isPrimarySelected = false
					break;
				}
			}
		}
	}
	
	if(isCompletePhoneEntered == true && isPrimarySelected == false)
	{
		alert("You must mark one phone as the primary phone.")
		return false
	}
	
	var isPrimaryEmergSelected = false;
	var isCompleteEmergPhoneEntered = false;
	var arEmergPhones = new Array(2);
	var emergphonePart1;
	var emergphonePart2;
	var emergphoneIndex;
	
	for(j = 0; j < 2; j++)
	{
		emergphoneIndex = j + 1;
		emergphoneArea = eval("document.staffForm.emerg_phone" + emergphoneIndex + "_areaCode.value")
		emergphonePart1 = eval("document.staffForm.emerg_phone" + emergphoneIndex + "_pt1.value")
		emergphonePart2 = eval("document.staffForm.emerg_phone" + emergphoneIndex + "_pt2.value")
		if(emergphoneArea.length > 0 && emergphonePart1.length > 0 && emergphonePart2.length > 0)
		{
			isCompleteEmergPhoneEntered = true;
			arEmergPhones[j] = j;
			
		} 
		
	}
		
	if(isCompleteEmergPhoneEntered == true)
	{
		for(j = 0; j < document.staffForm.primaryEmergPhone.length; j++)
		{
			isPrimaryEmergSelected = document.staffForm.primaryEmergPhone[j].checked
			if(isPrimaryEmergSelected == true) //primary radio button is checked
			{
				//now make sure it is selected on a complete phone
				if (arEmergPhones[0] == j || arEmergPhones[1] == j)
				{
					break;				
				}
				else
				{
					isPrimaryEmergSelected = false
					break;
				}
			}
		}
	}
	
	if(isCompleteEmergPhoneEntered == true && isPrimaryEmergSelected == false)
	{
		alert("You must mark one emergency phone as the primary phone.")
		return false
	}

	return true;
}

//this function is shared between event and facilities staff pages which is why its in common
function genderRadioButtonClicked(pGenderString)
{
	var otherGenderString;
	var genderClickedObj;
	var otherGenderObj;
	var TAB_KEY = 9
		
	if(event.keyCode == TAB_KEY) //dont do anything if tab key pressed
	{
		return;		
	}
		
	if(pGenderString == "male")
	{
		otherGenderString = "female"
	}
	else
	{
		otherGenderString = "male"
	}
		
	genderClickedObj = eval("document.staffForm." + pGenderString)
	otherGenderObj = eval("document.staffForm." + otherGenderString)
		
	if(genderClickedObj.checked == false)
	{	
		genderClickedObj.checked = true
		otherGenderObj.checked = false
	}
}

function GetSelSelectedValue(sel)
{
	for (var i = 0; i < sel.options.length; i++)
	{
		if (sel.options[i].selected)
			return sel.options[i].value;
	}
}

function textMax(pTextArea,iSize)
{
	if (pTextArea.value.length > iSize) {pTextArea.value = pTextArea.value.substring(0,iSize-1)}
}
