/****************************************************/
/*    Global.js - used for global javascript        */
/*                                                  */
/*    Created by:  Frances Currit-Dhaseleer         */
/*    Last updated:  September 28, 2005             */
/*                                                  */
/****************************************************/


// function to display "new" graphic with expiration date
	function displayNew(theDate) {
		var currentDate = new Date();
		var expireDate = new Date(theDate);
			
		if (expireDate > currentDate) {
			document.write('<img src="/images/new.gif" width=31 height=12 alt="" border="0">');
		}
	}
	
	// function to display "updated" graphic with expiration date
	function displayUpdated(theDate) {
		var currentDate = new Date();
		var expireDate = new Date(theDate);
			
		if (expireDate > currentDate) {
			document.write('<img src="/images/updated.gif" width="50" height="12" alt="" border="0">');
		}
	}

// function to pop up a window without toolbars, scrollbars, etc.
   function popWindow(url,windowName,w,h){
      var popWindow;
	  popWindow = window.open(url,windowName,"toolbar=no,menubar=no,width="+w+",height="+h+",resizable=yes,status=no,scrollbars=no");
	  popWindow.focus();
   }   
   
// sets the entire navigation bar
// uses the id from the row and compares that to the thisPageName variable
	function setNav(theRow,theGroup,theSubGroup) {
		var bulletPic = "bullet_" + theRow;
		document.getElementById(bulletPic).src = '/images/arrow_navBar2.gif';
		//document.getElementById(theRow).style.color = "#38849F";
		//document.getElementById(theRow).style.fontWeight = "bold";
		if (document.getElementById(theGroup)) {
			document.getElementById(theGroup).style.display = "inline";
		}
		/*if (document.getElementById(theSubGroup)) {
			var browser = navigator.userAgent.toLowerCase();
			//alert(browser);
			if (browser.indexOf('gecko') != -1)
			{
				document.getElementById(theSubGroup).style.display = "table-row";
			} else {
				document.getElementById(theSubGroup).style.display = "inline";
			}		
		}*/
	}
	
// allows a replace function via JavaScript
	function replaceSubstring(inputString, fromString, toString) {
	   // Goes through the inputString and replaces every occurrence of fromString with toString
	   var temp = inputString;
	   if (fromString == "") {
	      return inputString;
	   }
	   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + toString + 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 (fromString.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 "fromString" with the "inbetween" string
	      while (temp.indexOf(fromString) != -1) {
	         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	         temp = toTheLeft + midString + toTheRight;
	      }
	      // Next, replace the "inbetween" string with the "toString"
	      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 + toString + 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
   
