/////////////////////////////////////////////////////////////////
// Assign global Javascript stuff

vVersion = new String(navigator.appVersion)
vLocation = new String(document.location)

vLocation = vLocation.toLowerCase()

vWidth = screen.availwidth - 10
vHeight = screen.availheight - 50

function jsSingleton_Field(vSQL,vField,vDB) {
  // 6/10/2002 TGIL
  // 10/21/2003 TGIL: wrap vSQL with escape
  var result = showModalDialog(vBaseAddress + "/Pickers/Singleton_Field.asp?SQL=" + escape(vSQL) + "&DB=" + vDB + "&Field=" + vField + "&Session_Key=" + Get_Session_Key(),null,"dialogWidth:0px;dialogHeight:0px;dialogLeft:9999px;dialogTop:9999px;help:no;center:no;")
  return result;
}

function Session_Set(vVariable_Name,vValue,vOnSet) {
  // 1/23/2003 TGIL
  if (typeof(document.thisForm.SV_Variable_Name) == "undefined")
    document.all.thisForm.insertAdjacentHTML("beforeEnd","<input type=hidden name=SV_Variable_Name value=\"" + vVariable_Name + "\">")
  else
    document.thisForm.SV_Variable_Name.value = vVariable_Name
   
  if (typeof(document.thisForm.SV_Variable_Value) == "undefined")
    document.all.thisForm.insertAdjacentHTML("beforeEnd","<textarea style='visibility:hidden;position:absolute' name=SV_Variable_Value>" + vValue + "</textarea>")
  else
    document.thisForm.SV_Variable_Value.value = vValue

  if (typeof(document.thisForm.SV_OnSet) == "undefined")
    document.all.thisForm.insertAdjacentHTML("beforeEnd","<input type=hidden name=SV_OnSet value=\"" + vOnSet + "\">")
  else
    document.thisForm.SV_OnSet.value = vOnSet

  if (typeof(document.all.SV_IFrame) == "undefined")
    document.body.insertAdjacentHTML("afterBegin","<iframe style='position:absolute;visibility:hidden;width:1;height:1;' id=SV_IFrame></iframe>")

  document.all.SV_IFrame.src = vBaseAddress + "/Plexus_Control/Client_Side_Session_Var_Form.asp?Session_Key=" + vSession_Key
}

function Get_Session_Key() {
  if (typeof(vSession_Key) == "undefined") {
    if (window.top.frames[0])
      vSession_Key = Find_Session_Key(window.top.frames[0]) // recurse frames from the top
    else
      return ""
  }
  return vSession_Key
}

function Create_PDF(vURL) {
  // Created: 6/17/2003 TGIL
  // Called from any page via the popup menu
  
  Create_PDF_From_HTML("body")
  
  // If the PDF_IFrame IFRAME doesn't exist yet, create it.
//  if (typeof(document.all.PDF_IFrame) == "undefined")
//    document.body.insertAdjacentHTML("afterBegin","<iframe style='position:absolute;visibility:visible;width:600;height:600;' id=PDF_IFrame></iframe>")
//    document.body.insertAdjacentHTML("afterBegin","<iframe style='position:absolute;visibility:hidden;width:1;height:1;' id=PDF_IFrame></iframe>")

//  document.all.PDF_IFrame.src = vURL
}

function Create_PDF_From_HTML(vID) {
  // Created: 6/27/2003 TGIL
  // Called from any page via the popup menu
  
  // If the PDF_IFrame IFRAME doesn't exist yet, create it.
  if (typeof(document.all.PDF_IFrame) == "undefined")
//    document.body.insertAdjacentHTML("afterBegin","<iframe style='width:600;height:600;' id=PDF_IFrame></iframe>")
    document.body.insertAdjacentHTML("afterBegin","<iframe style='position:absolute;visibility:hidden;width:1;height:1;' id=PDF_IFrame></iframe>")

  document.all.PDF_IFrame.src = vBaseAddress + "/Plexus_Control/PDF_Download_HTML_Form.asp?ID=" + vID
}


function plUpload_Progress(vProgress_ID) {
	OpenWinCentered(vBaseAddress + "/Plexus_Control/Upload_Progress.asp?Progress_ID=" + vProgress_ID,"ProgressWin","",400,130)
}

function Find_Session_Key(oFrame) {
  if (typeof(oFrame.vSession_Key) != "undefined")
    return oFrame.vSession_Key
  
  for (var i=0;i<oFrame.frames.length;i++) {   
    var vRet = Find_Session_Key(oFrame.frames[i]) // recurse frames
    if (vRet != "")
      return vRet
  }
  return ""
}
function Ask_Password(vURL,vSession_Key) {
  // Open a modal window with a dialog requesting the password. The result is then assigned the
  // form value of this page.
  // The password and forwarding URL information is posted to "Verify.asp", which verifies
  // the password against the one stored in ss.SessionDB("Password"). If good, it redirects to the
  // given URL, if not, the user is alerted that the password was not correct, and the page
  // uses a Request.ServerVariables("HTTP_REFERER") to return to the menu.

  var vPass = showModalDialog(vBaseAddress + "/Ask.asp",null,"dialogWidth:300px;dialogHeight:160px;scroll:no;help:no;status:no")

  if (vPass) {
    if (typeof(document.thisForm.Pass) == "undefined") {
      var oPass = document.createElement("<input type=hidden name=Pass>")
      document.thisForm.appendChild(oPass)
    }
    if (typeof(document.thisForm.URL) == "undefined") {
      var oPass = document.createElement("<input type=hidden name=URL>")
      document.thisForm.appendChild(oPass)
    }
    document.thisForm.Pass.value = vPass
    document.thisForm.URL.value = vURL
    document.thisForm.action = vBaseAddress + "/Verify.asp?Session_Key=" + vSession_Key
    document.thisForm.submit()
  }
}

function Help(Help_No,CustNo,vForce) {
  if (typeof(vForce) == "undefined") vForce = false
  var vPath_Filename = location.href.substr(vBaseAddress.length)
  var vQuerystring = vPath_Filename.indexOf("?")
  if (vQuerystring > -1)  // remove the querystring
    vPath_Filename = vPath_Filename.substr(0,vQuerystring)
  if (vPath_Filename == "/")
    vPath_Filename = "/index.asp"
  if (!vForce)
    Help_No = ""
  vHelpURL = vBaseAddressPOL + "/help/help.asp?Path_Filename=" + vPath_Filename + "&Help_No=" + Help_No + "&Customer_No=" + CustNo
	vHelpURL += "&Session_Key=" + Get_Session_Key()	
	HelpWindow=window.open(vHelpURL,"Help","left=50,top=50,screenX=50,screenY=50,height=400,width=600,status,scrollbars,resizable")
	HelpWindow.focus()
}

function LoginHelp(Help_No,CustNo) {
  // Use this function for the Help button on all custom login screens, such as GenuinePlus and Matrix
	if ( (vVersion.indexOf("MSIE 4") != -1) && (vLocation.indexOf("www.plexus-online.com") == -1) ) {
		vHelpURL = vBaseAddressPOL + "/Redirect_Help.asp?Help_No=" + Help_No + "&Customer_No=" + CustNo
	} else {
		vHelpURL = vBaseAddressPOL + "/help/help.asp?Help_No=" + Help_No + "&Customer_No=" + CustNo
	}
	HelpWindow=window.open(vHelpURL,"Help","left=50,top=50,screenX=50,screenY=50,height=400,width=600,status,scrollbars")
	HelpWindow.focus()
}

function GetDate(vForm,vField,vDigits) {
  var i // make sure we use a local variable for looping
  
	if (navigator.appName == "Netscape") {
		alert("This feature only works with Internet Explorer")
		return
	}

  // This first part searches for [] in vField,
  // which would indicate that is it part of an array of fields with the same name.
  var vArrayIndex
	var vTextBoxField
	if (vField.indexOf("[") > -1) {
	  vTextBoxField = vField.substr(0,vField.indexOf("["))
	  vArrayIndex = vField.substring(vField.indexOf("[")+1,vField.indexOf("]"))
	} else {
	  vTextBoxField = vField
	  vArrayIndex = -1
	}
  vArrayIndex*=1  // convert it to a numeric variable

  // 9/9/2003 TGIL: Find out which index number the form is, and use it instead of hard-coded form[0]
	Findex = -1;
	for (i=0; i < document.forms.length; i++)	
	  if (document.forms[i].name == vForm)			
	  	Findex = i;			

	if (Findex == -1) {
	  Notify(vFormName + " not found!");
	  return false;
	}

  // At this point, vArrayIndex will be -1 if this field is not in an array,
  // but will be the value of the array index if it is part of an array.
  var vCurrentIndex = 0   // keeps track of the current index number of the matched field if there is an array of them
	for (i=0;i<document.forms[Findex].length;i++) {
		if (document.forms[Findex].elements[i].name == vTextBoxField) {
		  if (vCurrentIndex == vArrayIndex || vArrayIndex == -1) {
		    if (IsValid_Date(i) == false)
		    	vStartDate = null
		    else {
		      vStartDate = document.forms[Findex].elements[i].value
		      break
		    }
		  } else {
		    vCurrentIndex++   // if we found a matching field name, but the index numbers don't match, increase to try again
		  }
		}
	}
	
	if (vDigits != 4) { vDigits = 2 }
	vURL = vBaseAddress + "/Pickers/Date_Picker.asp?Form=" + vForm + "&Field=" + vField + "&Digits=" + vDigits + "&Session_Key=" + Get_Session_Key()
	if (vStartDate) {
	  switch (vDateFormat)
	  {
	    case "usa":
		    aDate = vStartDate.split("/")
		    aDate[2] = MakeFourDigitYear(aDate[2])
		    vURL += "&day=" + aDate[1] + "&month=" + (aDate[0]-1) + "&year=" + aDate[2]
		    break
		
	    case "euro":
		    aDate = vStartDate.split("/")
		    aDate[2] = MakeFourDigitYear(aDate[2])
		    vURL += "&day=" + aDate[0] + "&month=" + (aDate[1]-1) + "&year=" + aDate[2]
		    break
		
		  case "dd-mon-yy":
		    aMonthNames = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
		    // Figure out which month number it we have based on the name.
		    aDate = vStartDate.split("-")
		    aDate[2] = MakeFourDigitYear(aDate[2])
		    for (i=0;i<12;i++) {
		      if (aMonthNames[i] == aDate[1].toLowerCase().substr(0,3)) {
		        break
		      }
		    }
		    vURL += "&day=" + aDate[0] + "&month=" + i + "&year=" + aDate[2]
		    break
		    
		  case "Www/yy":
		    aDate = vStartDate.split("/")
		    aDate[0] = aDate[0].substr(1) * 1
		    aDate[1] = MakeFourDigitYear(aDate[1])
		    var maxWeeks = WeekOfYear("12/31/" + aDate[1],1)
		    // Since the date is returned as the friday of the chosen week, find the first Friday of the year and go from there.
		    
		    for (i=1;i<8;i++) {
		      vCurDate = new Date("1/" + i + "/" + aDate[1])
		      if (vCurDate.getDay() == 5)
		        break
		    }

		    // Now that we found the first Friday, try each Friday date until we find the one currently picked.
		    for (i=0;i<375;i+=7) {
		      if (WeekOfYear((vCurDate.getMonth()+1) + "/" + vCurDate.getDate() + "/" + vCurDate.getYear(),1) == aDate[0]) {
		        // Found the week, so use the current date (vCurDate)
		        break
		      }
		      
		      vCurDate = new Date(vCurDate*1 + 7 * 86400000)  // skip ahead to the next week
		      
		      vNewWeek = WeekOfYear((vCurDate.getMonth()+1) + "/" + vCurDate.getDate() + "/" + vCurDate.getYear(),1)
		      if (vNewWeek == 0 && i > 14) {
		        // This week spills into the next year
		        aDate[0] = 0
		      }
		      
		    }
		    vURL += "&day=" + vCurDate.getDate() + "&month=" + vCurDate.getMonth() + "&year=" + MakeFourDigitYear(vCurDate.getYear())

		    break
		}
	}

	OpenWinCentered(vURL,"Calender","",280,275)
}

function MakeFourDigitYear(vYear) {
	vYear*=1
	if (vYear < 100) {
		if (vYear > 50) {	//If a 2 digit year greater than 50, add 1900 to it.
			vYear+=1900
		} else {	//Otherwise, add 2000.
			vYear+=2000
		}
	}
	return vYear
}

function IsLeapYear(yearCheck) {
  //Check for leap year:
  if (yearCheck % 4 == 0) { 
    if (( yearCheck % 100 == 0 ) && (yearCheck % 400 != 0))
      return false
    else
      return true
  }
  else
    return false
}

function DayOfYear(vDate) {
  // vDate is expected to be a string in the format "mm/dd/yyyy"
  var numdays = [,31,28,31,30,31,30,31,31,30,31,30,31]

  var vTemp = vDate.split("/")
  var year = MakeFourDigitYear(vTemp[2])

  if (IsLeapYear(year))
    numdays[2]++  //Is a leap year! Add one to February's day count

  var vDayOfYear = 0

  // Add the number of days for each month up to the current month
  for (i=1;i<vTemp[0]*1;i++) {
    vDayOfYear += numdays[i] * 1
  }
  // Now add the number of days into the current month
  vDayOfYear += vTemp[1] * 1
  return vDayOfYear
}

function WeekOfYear(vDate,vFirstDayOfWeek) {
  // vDate is expected to be a string in the format "mm/dd/yyyy"
  // vFirstDay is an integer representing a day of the week 0-6
  // Returns the week number from 0-53, where 0 is the final week of the previous year.
  var vTemp = vDate.split("/")
  var year = MakeFourDigitYear(vTemp[2])

  // Find out which day of the week the first day of the year is on
  vFirstDate = new Date("1/1/" + year)
  vFirstDayAdjust = vFirstDayOfWeek - vFirstDate.getDay()
  var vDayOfYear = DayOfYear(vDate) - vFirstDayAdjust - 1
  
  var vWeekOfYear = Math.floor((vDayOfYear) / 7)
  
  if (vFirstDayOfWeek >= vFirstDate.getDay())
  	vWeekOfYear++

  return vWeekOfYear
}

function OpenWinCentered( vURL, vName, vOptions, vWidth, vHeight ) { //TSCH 6-29-01: Recommended value for vOptions: "status,scrollbars,resizable"

	vTop = (screen.availheight - vHeight) / 2;
	vLeft = (screen.availwidth - vWidth) / 2;
	
	if (vOptions.length > 0)
		vOptions += ", ";
		
	vOptions += "top=" + vTop + ",left=" + vLeft + ",width=" + vWidth + ",height=" + vHeight

  var vWin = window.open( vURL, vName, vOptions );
  vWin.focus();

//TSCH 09/08/03 It was determined on the PO Form that calling this function with the following two lines erred when closing the resultant window and then clicking the link again. The above two lines offer same functionality without the error.
/*
	eval ( vName + " = window.open( vURL, vName, vOptions );" )
	eval ( vName + ".focus();" )
*/

}

function DateKeypress(vField,vDigits) {
  // This only works for US-style dates
  
  // Now using a string that hold the date format, instead of a boolean,
  // because there are more than 2 date formats to choose from. TGIL 6/18/2001
  if (typeof vDateFormat == 'undefined') //Added by TSCH, 5/14/01 because not all pages have this var defined
	  vDateFormat = "usa"
	
	Press = window.event.keyCode
	
	if (vDateFormat == "dd-mon-yy" && Press == 45) // 11/4/2003 TGIL: return true for this format so dashes are enterable.
	  return true
	else if (vDateFormat != "usa")
	  return false;
  
  // This first part searches for [] in vField,
  // which would indicate that is it part of an array of fields with the same name.
  var vArrayIndex
	var vTextBoxField
	if (vField.indexOf("[") > -1) {
	  vTextBoxField = vField.substr(0,vField.indexOf("["))
	  vArrayIndex = vField.substring(vField.indexOf("[")+1,vField.indexOf("]"))
	} else {
	  vTextBoxField = vField
	  vArrayIndex = -1
	}
  vArrayIndex*=1  // convert it to a numeric variable

  // At this point, vArrayIndex will be -1 if this field is not in an array,
  // but will be the value of the array index if it is part of an array.
  var vCurrentIndex = 0   // keeps track of the current index number of the matched field if there is an array of them
  var vFieldIndex = -1
	for (i=0;i<document.forms[0].length;i++) {
		if (document.forms[0].elements[i].name == vTextBoxField) {
		  if (vCurrentIndex == vArrayIndex || vArrayIndex == -1) {
		    vFieldIndex = i
		    break
		  } else {
		    vCurrentIndex++   // if we found a matching field name, but the index numbers don't match, increase to try again
		  }
		}
	}
  
  // 9/9/2003 TGIL: Since this function relies on the first form, make sure the field is in the first form
  if (vFieldIndex == -1)
    return false
	
	vForm = document.forms[0].elements[i].value
	vTemp = new Date(new Date(vForm))
	if (vTemp == "NaN")
	  return false
	
	//Here's the 2-digit to 4-digit year conversion kludge...
	aForm = vForm.split("/")
	if (aForm[2] < 50) {
	  aForm[2] = aForm[2]*1 + 2000
	}
	if (aForm[2] >= 50 && aForm[2] < 100) {
	  aForm[2] = aForm[2]*1 + 1900
	}

	//Re-assemble the date with the 4-digit year.
	vTemp = aForm[0] + "/" + aForm[1] + "/" + aForm[2]
	if (Press == 43) {
		vDate = new Date(new Date(vTemp)*1+86400000)
	} else {  // Press==45
		vDate = new Date(new Date(vTemp)-86400000)
	}
  
  if (vDigits == 4)
	  document.forms[0].elements[i].value = (vDate.getMonth()+1) + "/" + vDate.getDate() + "/" + vDate.getFullYear() // Return 4-digit year
	else
	  document.forms[0].elements[i].value = (vDate.getMonth()+1) + "/" + vDate.getDate() + "/" + vDate.getFullYear().toString().substr(2,2) // Return 2-digit year
	  
	if (document.forms[0].elements[i].onchange) document.forms[0].elements[i].onchange(); //TSCH 09/29/03 Before this, any onchange function was not being called although the field was being changed
  return false; //Return fales so that the chars that forced this function to be called do not get typed into form element.
}

function GetTime(vForm,vField,vTime) {
	for (i=0;i<document.forms[0].length;i++) {
		if (document.forms[0].elements[i].name == vField) {
			if (IsValid_Time(i,document.forms[0].elements[i].value) == false)
				vTime = ""
		}
	}

	vURL = vBaseAddress + "/Pickers/Time_Picker.asp?Form=" + vForm + "&Field=" + vField + "&Time=" + vTime
	OpenWinCentered(vURL,"Clock","",160,240)
}

function MenuKeypress() {
	Press = window.event
	vKey = Press.keyCode - 48
	if (vKey == 0) { vKey+=10 } // the zero key
	vKey--  // make sure the lowest value matches the first index of 0
	if (vKey < 0 || vKey > MenuOption.length - 1) { return }
	MenuOption[vKey].click()
}

function Keypress(vButton) {
	for (i=0;i<document.images.length;i++) {
		vFilename = document.images[i].src
		if (vFilename.indexOf("Plexus_Online.gif") > -1 || vFilename.indexOf("Contact") > -1) {
			break
		}
	}
	Press = window.event
	if (vButton == 0) {
		vKey = Press.keyCode - 48
	} else {
		vKey = vButton
	}
	if (vKey == 0) { vKey+=10 }
	vKey = vKey + i //Find the first button link by skipping the amount of buttons up to the "Contact" button
	vLocation = new String(document.location)
	vLocation = vLocation.toLowerCase()
	if ((vKey < 3) || (vKey > document.links.length) || (vLocation.indexOf("menu.asp") == -1)) { return }
	document.links[vKey].click()
}

function ContactPlexus() {
    
	if ( (vVersion.indexOf("MSIE 4") != -1) && (vLocation.indexOf("www.plexus-online.com") == -1) ) {
		vContactURL = vBaseAddressPOL + "/Plexus_Control/Redirect_Contact.asp?Page=" + vLocation.substr(0,(vLocation.indexOf(".asp")+4)) + "&OpenerServer=" + vBaseAddress
	} else {
		vContactURL = vBaseAddressPOL + "/Plexus_Control/Contact_Plexus_Form.asp?Page=" + vLocation.substr(0,(vLocation.indexOf(".asp")+4)) + "&OpenerServer=" + vBaseAddress
	}

	Contact = window.open(vContactURL ,"Contact","left=20,top=20,screenX=20,screenY=20,height=550,width=600,status,scrollbars,resizable");
	Contact.focus();
}

function Submit_To(vURL) {
  document.thisForm.action = vURL;
  document.thisForm.submit();
}

function Navigate_To(vURL,vTarget) {
  // Navigate to a page without posting.
  // By using the click() method instead of document.location,
  // the HTTP_REFERER is not blank on the next page.

  if (!vTarget) vTarget = "_top"

  var vOld_href = document.links[0].href      // save these so we can put them back when we're done clicking
  var vOld_target = document.links[0].target
  
  // Temporarily assign the first link on the page to the URL we want to navigate to, then click it.
  document.links[0].href = vURL
  document.links[0].target = vTarget
  document.links[0].click()
  
  // Restore the original link
  document.links[0].href = vOld_href
  document.links[0].target = vOld_target
}

function Main_Menu(vMainMenuNode)
{
	if (window.opener && window.name.substr(0,3) != "POL")
	{
    // Start a chain reaction until we are actually on the main window again.
		window.opener.top.Main_Menu(vMainMenuNode)
		window.close();
	}
	else
	{
    vURL = vBaseAddressPOL + "/menu.asp?Node=" + vMainMenuNode;
    Navigate_To(vURL)
	}
}

function ComposeMail(vAddress,vAttachments) {
// Changed to go to a page on the POL main site for session verification before
// forwarding to the compose mail screen. -tgil 3/8/2001

// Only the vAddress variable is necessary now because the other values are stored in SessionDB variables,
// but they are still in place for compatibility until I can fix all calls to ComposeMail(). -tgil 4/20/2001

// Removed vUserID and vCustomer arguments. -tgil 4/25/2001

// tgil 11/20/2001
// Added vAttachments argument. Can be a comma-delimited collection of attachments in the format:
// "full UNC path and filename|attachment filename,full UNC path and filename|attachment filename"

	// The "new Date()*1" is there to add the current millisecond value to the window name so it won't be duplicated
	vContactURL = "../Redirect_Compose_Email.asp?Address=" + vAddress + "&Force_Comm_Log=1"
	if (vAttachments)
	  vContactURL += "&Attachments=" + vAttachments
	OpenWinCentered(vContactURL ,"Compose" + (new Date()*1),"scrollbars,status",770,514)
}

function Scale_Image(i,x,y) {
	w = document.images[i].width
	h = document.images[i].height
//alert(document.images[i].height * (x/w))
	if (x/w > y/h) {	//Use width, because it's scaling percentage is greater
		document.images[i].width = document.images[i].width * (x/w)
//		document.images[i].height = Math.round(document.images[i].height * (x/w))
	} else {	//Use height
//		document.images[i].width = document.images[i].width * (y/h)
		document.images[i].height = document.images[i].height * (y/h)
	}
}


function Submit_on_Enter(SubmitString) {
	if (window.event.keyCode == 13) FormSubmit(SubmitString);
	//NS 4 wants the following instead		
	//if (window.event.which == 13) FormSubmit(SubmitString);		
}

//The following lines go with the MoveMenu function
vMenuY = 0
var vTimeoutID = setTimeout("MoveMenu()",50)
var CancelMoveMenu = false; //Implemented techniques here to cancel MoveMenu(), if necessary. TSCH, 10/22/01

function MoveMenu() {
	if (CancelMoveMenu) return;
  setTimeout("MoveMenu()",50)
  
 	vAppName = navigator.appName
	if (vAppName.indexOf("Netscape") > -1) {
    clearInterval()
	  return
	}

  if (!document.all.Menu) return;

  document.body.topMargin = 45
  //If scrolling up, put the menu at the very top so it doesn't hover above the actual screen.
  if (vMenuY - document.body.scrollTop > 0) { vMenuY = 0 }
  vDif = vMenuY - document.body.scrollTop
  if (vDif < -1) {
    vMenuY = Math.round(vMenuY - vDif * .25)  //the .25 is a throttle for how fast the menu moves back into place. 1 is full speed
  } else {
    vMenuY = document.body.scrollTop
  }
	document.all.Menu.style.top = vMenuY

//new experiment...8/22/2000
  if (vMenuY != document.body.scrollTop) {
    document.all.Menu.style.visibility = "hidden"
  } else {
    document.all.Menu.style.visibility = "visible"
  }

}

function SubmitOnReturn() {
	e = window.event
	if (e.keyCode == 13) {
    if (document.all.SubmitLink) {
      if (!document.all.SubmitLink.clicked) {
        document.all.SubmitLink.click()
	      document.all.SubmitLink.clicked = true // make sure it doesn't get clicked again
	    }
	  }
	}
}

function Enumerate(vObject) { //Storing this useful code. TSCH
//  enumerates all available properties of the given object then displays them
  vProperties = "";
  var j = 0;
  for (i in vObject) {
		vProperties += i + "\n";
		j++;
		if ( j % 25 == 0) {
		alert(vProperties);			
		vProperties = "";
		}
	}
	alert(vProperties);
}

function placeFocus( vSelect, vIndex ) {	//Added by TSCH, 3-14-01
																	//Extended to pass over disabled elements. TSCH, 3-29-01
																	//Extended to Radio Sets. TSCH, 5-30-01
																	//try statements for follow-up attempt. This catches case where elements in a hidden span, etc.
	if (typeof(vSelect) == 'undefined') vSelect = false;
	if (typeof(vIndex) == 'undefined') vIndex = 0;

	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = vIndex; i < field.length; i++) {
		  if (!field.elements[i].disabled && field.elements[i].style.visibility != "hidden") {
			  if ( (field.elements[i].type == "radio") && (field.elements[i].defaultChecked) ) {
			    try {field.elements[i].focus()} catch(e) {placeFocus( vSelect, ++i );}
			  	break;
			  }
			  if ( (field.elements[i].type == "checkbox") || (field.elements[i].type == "text") || (field.elements[i].type == "textarea") || ((field.elements[i].type.toString().charAt(0) == "s") && (field.elements[i].length)) ) {
			    try {field.elements[i].focus()} catch(e) {placeFocus( vSelect, ++i );}
			  	if ( ((field.elements[i].type == "text") || (field.elements[i].type == "textarea")) && vSelect )
			  		field.elements[i].select();
			  	break;
        }
      } // if not disabled and not hidden
    }
	}
}

function Show_Popup_Layer(vMessage) {
  if (document.all.PL_Wait_Message) {
    // Layer is already made, so do nothing yet
  } else {
    // build the layer
    var vHTML
    vHTML  = "<div ID=PL_Wait_Message style='Position:absolute; left:150; top:0; z-index: 5000; visibility:hidden;'>"
    vHTML += "<table border=2 bordercolor=#4a81aa bgcolor=white cellpadding=6 cellspacing=0 width=250 height=50>"
    vHTML += "<tr><td class=GridHeader>"
    vHTML += vMessage
    vHTML += "</td></tr></table></div>"
    document.body.insertAdjacentHTML("AfterBegin",vHTML)
  }
  document.all.PL_Wait_Message.style.left = (screen.availWidth - 250) / 2 // make sure the Wait_Message covers the middle button
  document.all.PL_Wait_Message.style.visibility = "visible"
}

function Hide_Popup_Layer() {
  if (document.all.PL_Wait_Message)
    document.all.PL_Wait_Message.style.visibility = "hidden"
}

function SelectReset( vSelectObj ) { //Resets a Select Object to the Default Select, TSCH 8/27/01

  if(!vSelectObj) return; // TSCH 11/04/02

	for(var i = 0; i < vSelectObj.length; i ++)
		vSelectObj.options[i].selected = vSelectObj.options[i].defaultSelected;
}

function plSelectBytext( vSelectObj, vText ) { //Reset a specified Select object to the value(s) bearing the specified text. TSCH 12/12/01

  if(!vSelectObj) return; // TSCH 11/04/02
  
	for( var i = 0; i < vSelectObj.length; i++ )
		vSelectObj.options[i].selected = (vSelectObj.options[i].text == vText);
}

function Open_In_New_Session(vURL,vKiosk) {
  // Launch any POL page in directly in a new session window.
  var vLoginURL = vBaseAddress + "/Index.asp?Session_Copy=" + Get_Session_Key()
  if (vKiosk) {
    // if requesting kiosk mode, add a querystring flag to the URL so Index.asp knows how to handle it.
    if (vURL.indexOf("?") == -1)
      vURL += "?"
    else
      vURL += "&"
    vURL += "Kiosk=true"
  }
  // Save the page info in a session variable to be retrieved in Login.asp
  Session_Set("New_Session_Page",vURL,"Launch_New_Session('" + vLoginURL + "'," + vKiosk + ")")
}

function Launch_New_Session(vURL,vKiosk) {
  try {
    var vLaunch = "iexplore.exe "
    if (vKiosk) vLaunch += " -k"
    vLaunch += vURL
    var Wsh=new ActiveXObject('WScript.Shell');
    Wsh.Run(vLaunch,3);
    Wsh=null;
  } catch (e) {
    var vTrusted = vBaseAddress.replace(/http:\/\/www/i,"*")
    vTrusted = vTrusted.replace(/http:\/\/dev/i,"*")
    if (confirm("In order to automatically launch a new session, you must add " + vTrusted + " to the Trusted Sites Zone in your browser's Internet Options/Security section.\n\nClick OK now to see more details in the COOKIES section of PC Setup Help."))
      Help(350,vCustomer,true)
  }
}

//TSCH 01/29/03 to enhance listboxes with client-like reaction to typed text
var timerid     = null;
var matchString = "";
var mseconds    = 1000;	// Length of time before search string is reset

function plListselect(keyCode,targ)
	{
	  if (navigator.appVersion.indexOf('Windows NT 5.1') == -1) return true; //Approach could not be found to work on OSes other than XP when combininb keyboarding and mouse usage. Note. NT 5.0 is Win2k, but it does not work there for the special mouse-tab combo. It must be XP, i.e. NT 5.1
	  if (keyCode*1 < 33) return true; //We do not want to treat TABs, ENTERs, etc. as characters
	  
		keyVal       = String.fromCharCode(keyCode); // Convert ASCII Code to a string
		matchString += keyVal; // Add to previously typed characters
		elementCnt   = targ.length - 1;	// Calculate length of array -1
		
		for (i = elementCnt; i > 0; i--) {
			selectText = targ.options[i].text.toLowerCase(); // convert text in SELECT to lower case
			if (selectText.substr(0,matchString.length) == 	matchString.toLowerCase())
				targ.options[i].selected = true; } // Make the relevant OPTION selected
		
		clearTimeout(timerid); // Clear the timeout
		timerid = setTimeout('matchString = ""',mseconds); // Set a new timeout to reset the key press string
    
		return false; // to prevent IE from doing its own highlight switching
	}