/*
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
	
ControlVersion
GetSwfVer
DetectFlashVer
AC_AddExtension
AC_Generateobj
AC_FL_RunContent
AC_GetArgs

*/

	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 strCompareIIII = /[^m|^l]$/;
			var resultIIII = valin.match(strCompareIIII);
			
			var strResult = "";
			 
			if ((valin == null) || (valin == '')) {
				strResult = "bad";
			}
			if ((result != null) && (result != '/')) {
				strResult = "bad";
			}
			if (resultII != null) {
				strResult = "bad";
			}
			if (resultIII == null) {
				strResult = "bad";
			}
			if (resultIIII != 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'
}


/* FLASH DETECTION */

// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			//version = -1;
		}
	}
	
	if (!version){
		for (i=25;i>0;i--){
			document.write('<script language=VBScript>\n' + 
			'on error resume next\n' + 
			'Dim swControl, swVersion\n' + 
			'swVersion = 0\n' + 
			'set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\n' + 
			'if (IsObject(swControl)) then\n' + 
			'	swVersion = swControl.GetVariable("$version")\n' + 
			'end if\n' + 
			'</script>\n');
			try {
				if(swVersion != 0){
					version = swVersion;
					break;
				}else{
					version = -1;
				}
			} catch (e) {
				version = -1;
			}
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
		//alert(navigator.plugins.length);
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	//alert("flashVer="+flashVer);
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "id":
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


/* FLASH DETECTION */
