	// Pop-up window management
	var ChildWindow = null;

	var MetaOnWindowLoad = new Array();
	var MetaOnWindowUnload = new Array();
	
	
	function OnWindowLoad() {
		<!---alert("OnWindowLoad");--->
		for (var i = 0; i < MetaOnWindowLoad.length; i++) {
			MetaOnWindowLoad[i]();
		}
	}
	
	function OnWindowUnload() {
		<!---alert("ChildWindow " +ChildWindow);--->
		if (ChildWindow && !ChildWindow.closed) {
			ChildWindow.close();
		}

		for (var i = 0; i < MetaOnWindowUnload.length; i++) {
			MetaOnWindowUnload[i]();
		}
	}
	
	function PopupChildWindow(url, name, features, replace) {
		OnWindowUnload();
		
		if (!url) {
			ChildWindow = window.open();
		} else if (!name) {
			ChildWindow = window.open(url);
		} else if (!features) {
			ChildWindow = window.open(url, name);
		} else if (!replace) {
			ChildWindow = window.open(url, name, features);
		} else {
			ChildWindow = window.open(url, name, features, replace);
		}
		
		return ChildWindow;
	}
	
	function noenter() {
  		return !(window.event && window.event.keyCode == 13); 
	}
	
	function nochar(code) {
  		return !(window.event && window.event.keyCode == code); 
	}
	
	function getCookieData(label) 
	{
		var cEnd = label.indexOf("=");
		if (cEnd == -1 || cEnd == "") {
			label = label + "=";
		}
		label = label.toUpperCase();
		var labelLen = label.length;
		var cLen = document.cookie.length;
		var i = 0;
		while (i < cLen) {
			var j = i + labelLen;
			//alert(i + ', ' + j + ', ' + document.cookie.substring(i,j) + ', ' + (document.cookie.substring(i,j) == label));
			if (document.cookie.substring(i,j).toUpperCase() == label) {
				var cEnd = document.cookie.indexOf(";", j)
				if (cEnd == -1) {
					cEnd = document.cookie.length;
				}
				//alert('Found: ' + cEnd + ', ' + unescape(document.cookie.substring(j, cEnd)));
				return unescape(document.cookie.substring(j, cEnd));
			}
			i = document.cookie.indexOf(";", i) + 2;
			if (i == 1) {
				i = cLen;
			}
		}
		return "";
	}
	
	function replaceSubstring(inputString, fromStr, toStr) {
	   // Goes through the inputString and replaces every occurrence of fromStr with toStr
	   var temp = inputString;
	   if (fromStr == "") {
		  return inputString;
	   }
	   if (toStr.indexOf(fromStr) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
		  while (temp.indexOf(fromStr) != -1) {
			 var toTheLeft = temp.substring(0, temp.indexOf(fromStr));
			 var toTheRight = temp.substring(temp.indexOf(fromStr)+fromStr.length, temp.length);
			 temp = toTheLeft + toStr + toTheRight;
		  }
	   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
		  var midStrings = new Array("~", "`", "_", "^", "#");
		  var midStringLen = 1;
		  var midString = "";
		  // Find a string that doesn't exist in the inputString to be used
		  // as an "inbetween" string
		  while (midString == "") {
			 for (var i=0; i < midStrings.length; i++) {
				var tempMidString = "";
				for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
				if (fromStr.indexOf(tempMidString) == -1) {
				   midString = tempMidString;
				   i = midStrings.length + 1;
				}
			 }
		  } // Keep on going until we build an "inbetween" string that doesn't exist
		  // Now go through and do two replaces - first, replace the "fromStr" with the "inbetween" string
		  while (temp.indexOf(fromStr) != -1) {
			 var toTheLeft = temp.substring(0, temp.indexOf(fromStr));
			 var toTheRight = temp.substring(temp.indexOf(fromStr)+fromStr.length, temp.length);
			 temp = toTheLeft + midString + toTheRight;
		  }
		  // Next, replace the "inbetween" string with the "toStr"
		  while (temp.indexOf(midString) != -1) {
			 var toTheLeft = temp.substring(0, temp.indexOf(midString));
			 var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
			 temp = toTheLeft + toStr + toTheRight;
		  }
	   } // Ends the check to see if the string being replaced is part of the replacement string or not
	   return temp; // Send the updated string back to the user
	} // Ends the "replaceSubstring" function

	function setCookieData(label,value) 
	{
		document.cookie=label.toUpperCase()+"="+escape(value)+";";
	}

	function openInPopupMessage() {
		alert("Tab+Hold on link, then select 'Open in New Window' from the context menu");
		return false;
	}
	var HasNowButtonMessageBeenDisplayed=false;
	function nowButtonMessage() {
		if (!HasNowButtonMessageBeenDisplayed)
			alert("Now button is not supported on the Pocket PC at this time");
		HasNowButtonMessageBeenDisplayed=true;
	}
	
	// delare it, in case the dependencies are not met.  If it's already declared and defined, 
	//  redelaring it will not change the original.
	var is;
	if ((!is || !is.pie2002) && ! window.onunload && OnWindowUnload) {
		window.onunload=OnWindowUnload;
	}
	if (this.DebugWindow && ! DebugWindow.closed) {
		<!---alert("Setting ChildWindow to DebugWindow");--->
		ChildWindow=DebugWindow;
	}
	
// <!--- Copyright 2003, The MedWiz Corp.  All rights reserved.. --->

