/*
Function Index:
	
	PopupWindow(URL, Height, Width)    * This function will do a popup window to the URL with No Headers
	toggle(IDofDiv)					   * This function will reverse the visable property of the Div
	getObj(name)					   * A replacement for getElementById which is cross browser supported
	getObjNN4(obj, name)			   * Used internally to the getObj method
	getObjStyle(name)				   * get the Style property of a Object.  
	parseHTML(HTMLwithJavascript)	   * this method will return the HTML and run the javascript
	isNumeric(someValue)			   * returns false if the string contains anything other then 0-9
	isFileNameValid(filename)		   * Returns true or false if the filename is a valid filename or not
	isValidEmail(emailAddress)		   * Returns true or false if the email address is valid or not
	maxLengthHandler(TextArea, length) * This is a keydown event that will take the text area and trim it to the length
	replaceSubstring(inputString, fromString, toString)  * this will replace like in VB Script
	hideRow(rowToHide)				   * Hides a row in a table
	showRow(row,displayString)
	showCell(cell,displayString)
	hideCell(cell)
	ButtonMouseOver
	ButtonMouseOut
*/

	function isDate(aDate){
		var tmpDate, result;
		var tmpDate = new Date(aDate);
		isNaN(tmpDate)? result=false : result=true ;
		return result ;
	}
// ---------------------------------------------------------------
//  This function will take a URL a Height and Width and
//  Will do a Window.Open to that window with no Options.
//  The height/Width of the window will be what is passed in
//  Name is not manditory.
// ---------------------------------------------------------------
	function PopupWindow(URL, height, width, name)
	{
		if (URL==""){  
			alert("The URL for the popup function cannot be blank"); 
			return;
		}
		//If the height and width are null then default them to 500
		if (height==null)  height=500;
		if (width==null)   width=500;
		if (name==null)    name = "CommonPopupWindow";
		var returnWindow
		returnWindow=window.open(URL,name,'width=' + width + ',height=' + height +',menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=yes,top=0,left=0');
		return returnWindow;
	}
	function popup(URL, height, width, name)
	{
		if (URL==""){  
			alert("The URL for the popup function cannot be blank"); 
			return;
		}
		var returnWindow
		if ((height==null)||width==null) {
			returnWindow=window.open(URL,name);
			
		}else{
			returnWindow=window.open(URL,name,'width=' + width + ',height=' + height +',resizable=yes,top=0,left=0');
			
		}
		
		
		
	}


// ---------------------------------------------------------------
//toggle(ID)
//	-  This method will hide or show the div
//  -  If it is visable thus style.display="" it will make it style.display="none"
//  -  if the visabliity is style.display="none"  it will make it style.display=""
// ---------------------------------------------------------------
	function toggle(ID){
		var element = getObj(ID);
		if (element!=null){
			if (element.style.display=="")
				element.style.display="none";
			else
				element.style.display="";
		}
	}
	
	
// ---------------------------------------------------------------
//  getObj(name)
//	-  This method is a replacement for GetElementById.  It is
///    cross browser and will return a pointer to the instance of the object
// ---------------------------------------------------------------
	function getObj(name){
		if(document.getElementById){
			return document.getElementById(name);
		}else if(document.all){
			return document.all[name];
		}else if(document.layers && document.layers[name] != null){
			return getObjNN4(document, name);
		}else{
			return false;
		}
	}

// ---------------------------------------------------------------
//getObjNN4(obj, name)
//	- This method should not be called directly.  it is used
//    internally to all the other GetObj methods.  And is used for netscape
// ---------------------------------------------------------------
	function getObjNN4(obj, name)
	{
		var x = obj.layers;
		var foundLayer;
		for(var i=0;i<x.length;i++)
		{
			if(x[i].id == name)
			{
				foundLayer = x[i];
			}
			else if (x[i].layers.length)
			{
				var tmp = getObjNN4(x[i],name);
			}
			if(tmp)
			{
				foundLayer = tmp;
			}
		}
		if(foundLayer)
		{
			return foundLayer;
		}
		else
		{
			return false;
		}
	}

// ---------------------------------------------------------------
// getObjStyle(name)
//	- This method will get the Style property of the object in question
//  -  This is cross browser supported
// ---------------------------------------------------------------
	function getObjStyle(name)
	{
		if(document.getElementById)  
		{
			return document.getElementById(name).style;
		}
		else if(document.all)
		{
			return document.all[name].style;
		}
		else if(document.layers)
		{
			return getObjNN4(document, name);
		}
	}

// ---------------------------------------------------------------
//  showRow(rowToShow, optional DisplayString block or inline)
//  -  This method takes in a javascript row object and makes it
//		visible using the display property.  This should work
//		on all platforms and most browsers including firefox,
//		ie6, ie7, and safari
// ---------------------------------------------------------------
	function showRow(row,displayString){
		try{
			row.style.display="table-row";
		} catch (e) {
			if (displayString == null){
				displayString = "block";
			}
			row.style.display = displayString;
		}
	}

// ---------------------------------------------------------------
//  hideRow(rowToHide)
//  -  This method takes in a javascript row object and makes it
//		invisible using the display property. 
// ---------------------------------------------------------------
	function hideRow(row){
		row.style.display="none";
	}

// ---------------------------------------------------------------
//  showCell(cellToShow, optional DisplayString block or inline)
//  -  This method takes in a javascript cell object and makes it
//		visible using the display property.  This should work
//		on all platforms and most browsers including firefox,
//		ie6, ie7, and safari
// ---------------------------------------------------------------
	function showCell(cell,displayString){
		try{
			cell.style.display="table-cell";
		} catch (e) {
			if (displayString == null){
				displayString = "block";
			}
			cell.style.display = displayString;
		}
	}

// ---------------------------------------------------------------
//  hideCell(cellToHide)
//  -  This method takes in a javascript Cell object and makes it
//		invisible using the display property. 
// ---------------------------------------------------------------
	function hideCell(cell){
		cell.style.display="none";
	}


// ---------------------------------------------------------------
//  parseHTML(HTMLwithJavascript)
//  -  This method will take in some HTML that is typically returned from an Ajax Call
//    and then it will look for Javascript in the string and run it.  parse out the javascript
//   then just return the HTML
// ---------------------------------------------------------------
	function parseHTML(result){
		//var re = new RegExp('\<scr'+'ipt\\b\[\^\>\]\*\>(.*)<\/sc'+'ript\>', "g");
		var re =new RegExp('<scr'+'ipt [\\S+].*>([^<]+|.*?)?</scr'+'ipt>', "g");
		var Javascript = re.exec(result);
		
		//<(\S+).*>(.*)<

		var HTML	   = result.replace(re, "")
		if (Javascript!=null){
			for (var i=1;i<Javascript.length;i++){
			//alert(Javascript[i]);
				eval(Javascript[i]);
			}
		}
		
		return HTML;
	}
// ---------------------------------------------------------------
//  This method takes a script tag as a string like
// <scr ipt>  someJavascriptHere() </scr ipt>  and then
//  executes the code between the script tags
// ---------------------------------------------------------------
	function parseJavascript(result){

		var re = new RegExp('\<scr'+'ipt\\b\[\^\>\]\*\>\(\.\*\?\)\<\/sc'+'ript\>', "g");
		var Javascript = re.exec(result)[1];
		
		return Javascript;
		
	}
 
// ---------------------------------------------------------------
//  This method insures that its only a number either whole
//  number or a floating point number.  Thus the string must
//  contain 0 to 9 or a .
// ---------------------------------------------------------------
	function isNumeric(sText)
		{
		var ValidChars =	"0123456789.";
		var IsNumber=true;
		var Char;  
		for (i =	0; i < sText.length	&& IsNumber	== true; i++)
			{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
				{
				IsNumber =	false;
				}
			}
		return IsNumber;
		}  

// ---------------------------------------------------------------
//   This method tells us if a file name is in a valid format or not
//  It cannot contain spaces, or some special charactesr.  so we
//  are only allowing a-z 0-9 . and a .htm extention
// ---------------------------------------------------------------
	function isFileNameValid(valin){
				// \W - any non ASCII word character (not a-z, 0-9)
			var strCompare = /\W*\s/;
			var result = valin.match(strCompare);
			
			var strCompareII = /((\?)|(\))|(\()|(\*)|(\&)|(\^)|(\%)|(\$)|(\#)|(\@)|(\!))/;
			var resultII = valin.match(strCompareII);
			
			var strCompareIII = /^(.*(\.)htm)/;
			var resultIII = valin.match(strCompareIII);
			
			var strResult = "";
			
			if ((valin == null) || (valin == '')) {
				strResult = "bad";
			}
			if ((result != null) && (result != 'index.html')) {
				strResult = "bad";
			}
			if (resultII != null) {
				strResult = "bad";
			}
			if (resultIII == null) {
				strResult = "bad";
			}
			if (strResult != "") {
				//alert ('The value entered is not of the correct format');
				return false;
			}
			else {
				//alert ('The value entered is of the correct format');
				return true;
			}
		}

// ---------------------------------------------------------------
//  This method will return true if the email is in a valid format
//  and will return false if it is not.
// ---------------------------------------------------------------
	function isValidEmail(emailAddress){
		//var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		if(emailAddress.search(/^([0-9a-zA-Z]+([_&\.-]?[0-9a-zA-Z]+[_]?)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,\.,-]*(\.){1}[a-zA-Z]{2,4})$/i) == -1){
			return false;
		}
		return true;
		//var regex = new RegExp(emailReg);
		//return regex.test(emailAddress);
	}

// ---------------------------------------------------------------
// THis function is a Handler for the max length.  you can put it on the onchange
// event of some text area and it will ensure that the length isn't longer then that.
// ---------------------------------------------------------------
	function maxLengthHandler(textarea, length, showmessage){
		if (!showmessage) showmessage=false;
		var x = new String();
		
		if (textarea.value.length>length){
			textarea.value = textarea.value.substr(0, length);
			if (showmessage){
				alert("The number of characters was too long.  \nIt has been trimmed to " + length + " characters")
			}
		}
	}
	
	/***********************************************************************************/
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

function ButtonMouseOver(obj){
	obj.style.backgroundColor='#1B334E'
	 
}
function ButtonMouseOut(obj){
	obj.style.backgroundColor='#7194BA'
}
