var undefined;
var CurrentMenuSelectorID;
var CurrentMenuFormID;

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function ActivateFlash(id)
{
	var object = document.getElementById(id);
	if (navigator.appName.indexOf("MSIE") != -1) {
		if (object) object.outerHTML = object.outerHTML;
	}
}

try {
	if (typeof(Node)!="undefined") {
		// try to extend the DOM definition of Element to include an insertAfter method
		Node.prototype.insertAfter = function (node, referenceNode) {
			var n = referenceNode.nextSibling;
			if (n) return this.insertBefore(node, n);
			else return this.appendChild(node);
		}
		Node.prototype.getChildrenByTagName = function (tagName) {
			var listing = this.getElementsByTagName(tagName);
			var retval = new Array();
			var x;
			for (x=0;x<listing.length;x++) {
				if (listing[x].parentNode == this) {
					retval.push(listing[x]);
				}
			}
			return retval;
		}
	}
} finally {
	// no matter what, define a helper function that can do the same
	function insertAfter(parent, node, referenceNode) {
		var n = referenceNode.nextSibling;
		if (n) return parent.insertBefore(node, n);
		else return parent.appendChild(node);
	}
	function getChildrenByTagName(parent, tagName) {
		var listing = parent.getElementsByTagName(tagName);
		var retval = new Array();
		var x;
		for (x=0;x<listing.length;x++) {
			if (listing[x].parentNode == parent) {
				retval.push(listing[x]);
			}
		}
		return retval;
	}
}
		
function PrintStyleLinks(el) {
	var a = el.getElementsByTagName("A");
	var x;
	var href;
	for (x=0;x<a.length;x++) {
		if (a[x].href) {
			var t = document.createElement("SPAN");
			t.className = "PrintOnly";
			href = a[x].href+"";
			t.innerHTML = " ["+href.replace(/\//g, "/ ")+"] ";
			// try to do this the DOM style way
			if (a[x].parentNode.insertAfter) a[x].parentNode.insertAfter(t, a[x]);
			// if that's not avialable, use the helper function
			else insertAfter(a[x].parentNode, t, a[x]);
		}
	}
}
		


		function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

        function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get
                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }

		function InStr(strSearch, charSearchFor)
		/*
		InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
		was found in the string str.  (If the character is not found, -1 is returned.)
		Requires use of:
			Mid function
			Len function
		*/
		{  
			for (i=0; i < String(strSearch).length; i++)
			{
				if (charSearchFor == Mid(strSearch, i,  String(charSearchFor).length))
				{
					return i;
				}
			}
			return -1;
		}

		function GetURLToken(url, token) {
			retval = "";
			startpos = InStr(url, token+"=");
			if (startpos==-1) return null;
			startpos += String(token+"=").length;
			endpos = startpos;
			while ((url.charAt(endpos)!='&')&&(url.charAt(endpos)!='#')&&(endpos<url.length)) {
				retval = retval+url.charAt(endpos);
				endpos++;
			}
			return retval;
		}
		
		
/* ***********************************************
	AJAX FUNCTIONS
   *********************************************** */
   
function GetHTTPObject(){
	var xmlhttp;
	if (window.ActiveXObject)
	{
		xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : null;
		return xmlhttp;
	}
	// code for Mozilla, etc.
	else if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = null;
		}
		return xmlhttp;
	} else {
		//alert('Your browser cannot handle this script');
		return null;
	}
}

function AJAXGenericLoad(TargetObject, URL) {
	if (TargetObject && URL) {
		var xmlhttp = GetHTTPObject();
		xmlhttp.open("GET", URL);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				TargetObject.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

/* ***********************************************
    MENU ITEM EDITING FUNCTIONS
   *********************************************** */
   
function CMSClearMenu()
{
	var menudiv = document.getElementById("Menu");
	if (menudiv) {
		menudiv.innerHTML = "";
	}
}

function CMSMenuAddToTop(url)
{
	var menudiv = document.getElementById("Menu");
	if (menudiv && url) {
		var tempdiv = document.createElement("DIV");
		if (menudiv.firstChild) {
			menudiv.insertBefore(tempdiv, menudiv.firstChild);
		} else {
			menudiv.appendChild(tempdiv);
		}
		AJAXGenericLoad(tempdiv, url);
	}
}

function CMSMenuAddToBottom(url)
{
	var menudiv = document.getElementById("Menu");
	if (menudiv && url) {
		var tempdiv = document.createElement("DIV");
		menudiv.appendChild(tempdiv);
		AJAXGenericLoad(tempdiv, url);
	}
}

function CMSMenuLoginForm()
{
	CMSMenuAddToTop("/php/loginform.php");
}

function popUp(URL, w, h) {
	winProp = 'width='+w+',height='+h+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	day = new Date();
	id = day.getTime();
	//eval("page" + id + " = window.open(URL, '" + id + "', winProp);");
	eval("page" + id + " = window.open(URL, 'pwin', winProp);");
}