strJSVer=navigator.appVersion.substring(0,4);

function navToFrameHash(hashName, frameName){
	var targetFrame;
	
	if(window.parent){
		// This document is a child.
		if(window.parent.frames){
			// The parent document has other children.
			targetFrame = window.parent.frames[frameName];
		}
	}else{
		// This document is not a child.
		if(document.frames){
			// This document has children.
			targetFrame = document.frames[frameName];
		}
	}

	if(targetFrame){
		// We were able to locate the requested frame.
		
		if(!(hashName.indexOf('#') > -1)){
			// The hashName param does not contain a #.
			hashName = '#' + hashName;
		}
		
		targetFrame.location.hash = hashName;
		//alert(targetFrame.location.hash);
	}
}

function PopUpWindow(sUrl, iWidth, iHeight)
{
	var sWindowString;
	var dNew = new Date();
	var sRandName = dNew.getUTCMilliseconds();
	sRandName = sRandName.toString();

	sWindowString = "width=" + iWidth + ",height=" + iHeight + ",toolbar=0,scrollbars=no,location=0,directories=0,status=0,menubar=0,resizable=yes";
	window.open(sUrl, sRandName, sWindowString);
}

function PopUpCenterWindow(sUrl, iWidth, iHeight, sScroll)
{
	var sWindowString;
	var dNew = new Date();
	var sRandName = dNew.getUTCMilliseconds();
	sRandName = sRandName.toString();

	var Xpos= Math.floor((screen.availWidth - iWidth)/2);
	var Ypos= Math.floor((screen.availHeight - iHeight)/2)-10;

	if (sScroll == "")
		{
		sScroll = "no";
		}

	sWindowString = "width=" + iWidth + ",height=" + iHeight + ",left=" + Xpos + ",top="  + Ypos + ",toolbar=0,scrollbars=" + sScroll + ",location=0,directories=0,status=0,menubar=0,resizable=yes";
	return window.open(sUrl, sRandName, sWindowString);
}

function PopUpFloatingWindow(sUrl, iWidth, iHeight, Xpos, Ypos)
{
	var sWindowString;
	var dNew = new Date();
	var sRandName = dNew.getUTCMilliseconds();
	sRandName = sRandName.toString();

	Xpos = Xpos + window.screenLeft
	Ypos = Ypos + window.screenTop
	//
	// Had to use left and top for IE positioning. Netscape, FF and mozilla use screenX and screenY.
	sWindowString = "width=" + iWidth + ",height=" + iHeight + ",screenX=" + Xpos + ",left=" + Xpos + ",screenY="  + Ypos +",top=" + Ypos + ",toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,resizable=no";
	window.open(sUrl, sRandName, sWindowString);
	//newwindow.moveTo(Xpos, Ypos);
	// Line commented out because the sUrl would be loaded twice.
	// Once by the open() statement and once by this line.
	// This would mess up printing work authorizations in the custom changes maint.
	// newWindow.location=sUrl;
}

function CenterWindow()
{
	var Xpos= (screen.availWidth - 475)/2;
	var Ypos= (screen.availHeight - 750)/2;
	window.moveTo(Xpos, Ypos);
}

function CB_showHideLayers() {
  var i, visStr, args, theObj;
  args = CB_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
    visStr   = args[i+2];
    if (navigator.appName == 'Netscape' && document.layers != null && strJSVer<5) { //NN
      theObj = eval(args[i]);
      if (theObj) theObj.visibility = visStr;
    } else if (document.all != null) { //IE & NS6
      if (visStr == 'show') visStr = 'visible'; //convert vals
      if (visStr == 'hide') visStr = 'hidden';
      theObj = eval(args[i+1]);
      if (theObj) theObj.style.visibility = visStr;
  } }
}

function ReplaceFirst(sString, sSubString, sReplString){
	var oStr = new String(sString);
	var oSub = new String(sSubString);
	var oRepl = new String(sReplString);
	var iFirst, iLast;

	iFirst = oStr.indexOf(oSub);
	iLast = iFirst + oSub.length;
	if(iFirst > -1 && iLast > -1){
		return (oStr.substring(0, iFirst) + oRepl + oStr.substring(iLast, oStr.length));
	}else{
		return sString;
	}
}

function Replace(sString, sSubStr, sReplStr){
	var oStr = new String(sString);
	do{
		oStr = ReplaceFirst(oStr, sSubStr, sReplStr);
	}while(oStr.indexOf(sSubStr) > 0)
	return oStr;
}

function ClearCheckBoxes(sFormName, sCheckBoxName){
	// RESET ALL CHECKBOXES OF A PARTICULAR NAME
	var oCheckBox = eval("document." + sFormName + "." + sCheckBoxName);
	for(var i = 0; i < oCheckBox.length; i++){
		oCheckBox[i].checked = false;
	}
}

function ClearSelectList(sFormName, sSelectName){
	// DE-SELECT ALL OPTIONS IN A PARTICULAR SELECT LIST
	var oSel = eval("document." + sFormName + "." + sSelectName);
	for(var i = 0; i < oSel.options.length; i++){
		oSel.options[i].selected = false;
	}
}

function LTrim(sString){
	/* MIMIC THE ASP 'LTrim' FUNCTION BY REMOVING ALL LEADING WHITESPACES */
	var oStr = new String(sString), sOut;
	// DUMMY CHECK STRING
	if(oStr.length < 1){
		return "";
	}
	// COPY STRING AS-IS
	sOut = oStr.toString();
	// ITERATE STRING CHARS FROM LEFT TO RIGHT
	for(var i = 0; i < oStr.length; i++){
		if(oStr.charAt(i) == " "){
			// RE-COPY STRING, REMOVING CURRENT CHAR
			sOut = oStr.substring(i + 1, oStr.length);
		}else{
			// NON-WHITESPACE ENCOUNTERED; RETURN
			return sOut;
		}
	}
	// REDUNDANT RETURN, JUST IN CASE
	return sOut;
}

function RTrim(sString){
	/* MIMIC THE ASP 'RTrim' FUNCTION BY REMOVING ALL TRAILING WHITESPACES */
	var oStr = new String(sString), sOut;
	// DUMMY CHECK STRING
	if(oStr.length < 1){
		return "";
	}
	// COPY STRING AS-IS
	sOut = oStr.toString();
	// ITERATE STRING CHARS FROM RIGHT TO LEFT
	for(var i = oStr.length-1; i >= 0; i--){
		if(oStr.charAt(i) == " "){
			// RE-COPY STRING, REMOVING CURRENT CHAR
			sOut = oStr.substring(0, i);
		}else{
			// NON-WHITESPACE ENCOUNTERED; RETURN
			return sOut;
		}
	}
	// REDUNDANT RETURN, JUST IN CASE
	return sOut;
}

function Trim(sString){
	sString = LTrim(sString);
	sString = RTrim(sString);
	return sString;
}

function InStr(sHost, sTarg){
	/* MIMIC THE ASP 'InStr' FUNCTION, INCLUDING BASE-1 POSITIONING */
	if(sHost.indexOf(sTarg) > -1){
		return (sHost.indexOf(sTarg) + 1);
	}
	return 0;
}

function InStrRev(sHost, sTarg){
	/* MIMIC THE ASP 'InStrRev' FUNCTION, INCLUDING BASE-1 POSITIONING */
	if(sHost.lastIndexOf(sTarg) > -1){
		return (sHost.lastIndexOf(sTarg) + 1);
	}
	return 0;
}

function KeepLeft(sHost, sTarget){
	// REMOVE EVERYTHING IN sHost THAT'S TO THE RIGHT OF sTarget
	var oHost = new String(sHost);
	var iStart = oHost.indexOf(sTarget);
	if(iStart > -1){
		return oHost.substring(0, iStart);
	}else{
		return sHost;
	}
}

function KeepRight(sHost, sTarget){
	// REMOVE EVERYTHING IN sHost THAT'S TO THE LEFT OF sTarget
	var oHost = new String(sHost);
	var oTarget = new String(sTarget);
	var iStart = oHost.indexOf(sTarget);
	if(iStart > -1){
		iStart += oTarget.length;
		return oHost.substring(iStart, oHost.length);
	}else{
		return sHost;
	}
}

function Getfilename(sHost, sTarget){
	// REMOVE EVERYTHING IN sHost THAT'S TO THE LEFT OF THE FILENAME W/ EXT AT THE END
	var oHost = new String(sHost);
	var oHost_temp = new String(sHost);
	var oTarget = new String(sTarget);
	var iStart;
	oHost_temp = oHost;
	while(InStr(oHost_temp,"/"))
	{
		iStart = oHost_temp.indexOf(sTarget)+1;
		oHost_temp = oHost_temp.substring(iStart, oHost_temp.length);
	};
	return oHost_temp;
}

// 10/28/02 CTB
function isHexColor(Value)
{
  var Start,Runner;
  var HEX="0123456789abcdefABCDEF";
  var Is_ok=true;
  
  if(Value.charAt(0)=="#")
  {
    Start=1;
  }else{
    Start=0;
  };
  for(Runner=Start; Runner<Value.length; Runner++)
  {
    if(InStr(HEX,Value.charAt(Runner))==0)
    {
      Is_ok=false;
    };
  };
  if(Value.length-Start!=6 && Value.length>0)
  {
    Is_ok=false;
  };
  return Is_ok;
};

function writeCookie(name, value){
	var newCookie = '';
	var expirationDate = new Date();
	
	if(name.length > 0){
		expirationDate.setMonth(10);
		expirationDate.setDate(18);
		expirationDate.setYear(2023);
		
		newCookie = name + '=' + escape(value)
		newCookie += "; expires=" + expirationDate.toGMTString();
		document.cookie = newCookie;
	}
}

function writeSessionCookie(name, value){
	var newCookie = '';
	
	if(name.length > 0){
		newCookie = name + '=' + escape(value) + ";"
		document.cookie = newCookie;
	}
}
//---------------------------------------
//
//	swapspan(fromspan, fromindex, toindex, elements)
//
//	step 1.
//		Swaps the text in the 
//		fromspan with the tospan.
//
//	step 2.
//		Swaps the value from fromindex (hidden)
//		with the value in toindex(hidden)
//
//
// Parameters
// ----------
//
// fromspan: 		spanid to swap. 
//
// tospan: 		spanid to swap. 
//
// fromindex:		hidden control frow swap id values			
//
// toindex:		hidden control to swap id values			
//
// elements:		hidden control
//
//-------------------------------------------
			 
function swapspan(fromspan, tospan, fromindex, toindex, elements, elementname)
{

	if (!fromindex)
	{
		return;
	}

	if (!toindex)
	{
		return;
	}
	
//Step 1
	var holdspan = document.createElement('span');
	holdspan.innerHTML = document.getElementById(fromspan).innerHTML;
	document.getElementById(fromspan).innerHTML = document.getElementById(tospan).innerHTML;
	document.getElementById(tospan).innerHTML = holdspan.innerHTML;

	//Recolor elements black
	for(i=0;i<elements.length;i++)
	{
		document.getElementById(elementname+(i+1)).style.color='black';
	}

	//Highlight moved element in red
	document.getElementById(tospan).style.color='red';
	
//Step 2
	var holdvalue = fromindex.value;
	fromindex.value = toindex.value;
	toindex.value = holdvalue;

}

/*
Author	: AW 
Date	: 1/30/2006
Desc	: Dynamically builds a 2D array for you without having to do the for loops 
*/
function buildMultiDimensionalArray(Rows,Cols)
{
	var i;
	var j;
   var tempArray = new Array(Rows);
   for (i=0; i < Rows; i++)
   {
       tempArray[i] = new Array(Cols);
       for (j=0; j < Cols; j++)
       {
			//initializes empty string in the position
           tempArray[i][j] = "";
       }
   }
   return(tempArray);
} 

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return "";
}

/*String Prototypes for easy string trimming*/
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.ltrim=function(){
    return this.replace(/^\s*/g,'');
}

String.prototype.rtrim=function(){
    return this.replace(/\s*$/g,'');
}

