function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GoVerify(p_url)
{
    if (confirm("Are You Sure?") == true) {
	    window.location = p_url;
	}
}
function GoDirect(p_url)
{
    window.location = p_url;
}
function GoClose(p_url)
{
    window.opener.location = p_url;
	window.close();
}
function Dialog(p_url,p_width,p_height,p_name,x_start,y_start,p_scroll)
{
	if (Dialog.arguments.length < 2) {
	    p_width = 500;
		p_height = 400;
	}

	if (Dialog.arguments.length < 4) {
		p_name = "dialog";
	}
	if (Dialog.arguments.length < 6) {
		x_start = 200;
		y_start = 200;
	}
	if (Dialog.arguments.length < 7) {
		p_scroll = "no";
	}	
}	

function HideDialog(p_url)
{
	newwin = window.open(p_url,null, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=10,height=10,screenX=0,left=0,screenY=0,top=0"); 
	if (newwin.focus) newwin.focus();
	if (!newwin.opener) {
		newwin.opener = self;
	}
}

function wclose() {
self.close();
}

function closeform() {
opener.document.Form1.submit();
window.close();
}

function Popup(p_url,p_width,p_height,p_scroll,p_name) {	
	var ScrWidth = screen.width;
	var ScrHeight = screen.height;
	var x = ((ScrWidth - p_width)/2);
	var y = ((ScrHeight - p_height)/2);
	if (Popup.arguments.length < 5) {
		p_name = "name"+x;
	}
	if (Popup.arguments.length < 4) {
		p_scroll = "no";
	}
	 
	newwin = window.open(p_url,p_name, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars="+p_scroll+",status=no,toolbar=no,width="+p_width+",height="+p_height+",screenX="+x+",left="+x+",screenY="+y+",top="+y); 
	if (newwin.focus) newwin.focus();
	if (!newwin.opener) {
		newwin.opener = self;
	}
}

function Popup2(p_url,p_width,p_height,p_scroll,p_name) {	
	var ScrWidth = screen.width;
	var ScrHeight = screen.height;
	var x = ((ScrWidth - p_width)/2);
	var y = ((ScrHeight - p_height)/2);
	if (Popup2.arguments.length < 5) {
		p_name = "name"+ x;
	}

	if (Popup2.arguments.length < 4) {
		p_scroll = "no";
	}
	 
	window.open(p_url,p_name, "channelmode=no,dependent=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars="+p_scroll+",status=no,toolbar=no,width="+p_width+",height="+p_height+",screenX="+x+",left="+x+",screenY="+y+",top="+y); 
}

function PopFull(p_url,p_name) {
	var ScrWidth = screen.width - 40;
	var ScrHeight = screen.height - 40;	
	window.open(p_url,p_name,"width="+ScrWidth+",height="+ScrHeight+"screenX=0,screenY=0,left=0,top=0,menubar=no,location=no,scrollbars=yes,toolbar=no,status=no");
}

function DeleteVerify(p_url)
{
    if (confirm("Are You Sure You want to Delete?") == true) {
	    window.location = p_url;
	}
}

function CheckAll(Field, LoopMax, TrueFalse)
{	
	for(var loopndx = 0; loopndx < LoopMax; loopndx++)
	{
	Field(loopndx).checked = TrueFalse;
	}
}

function GetBrowser(){
	var DOM ,NS4, IE, IE4, Mac, IE4M, IE5M, IE5W, NS6;

	DOM = (document.getElementById) ? true : false;
	NS4 = (document.layers) ? true : false;
	IE = (document.all) ? true : false;
	IE4 = IE && !DOM;
	Mac = (navigator.appVersion.indexOf("Mac") != -1);
	IE4M = IE4 && Mac;

	if (DOM) {
		IE5M = IE && Mac;
		IE5W = IE && !Mac;
		NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
	}

	if(NS4 || NS6){
		return "NS";
	}
	if(Mac){
		return "Mac";
	}
	if(IE){
		return "IE";
		
	return "??";
	}
}

function textCounter(field, countfield, maxlimit) 
	//
	// use this function to limit a text area to a certain number of characters
	// on the keyup and keydown event
	//
	// Field is the text area, count field is a counter on the page that
	// the user sees as they are typing, and maxlimit is the max size of 
	// the textarea
	// 
	{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function HtmlEditReady(inText) 
	{
	var temp = inText;
	temp = replaceSubstring(temp,"#","%23")
	return temp;
}


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

