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 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");
}


/* ***********************************************
	EKTRON CMS400 LOGIN/LOGOUT SHORTCUTS
   *********************************************** */
function ecmPopUpWindow(url, hWind, nWidth, nHeight, nScroll, nResize) {
	var popupwin,  cToolBar;
	cToolBar = 'toolbar=0,location=0,directories=0,status=' + nResize + ',menubar=0,scrollbars=' + nScroll + ',resizable=' + nResize + ',width=' + nWidth + ',height=' + nHeight;
	popupwin = window.open(url, hWind, cToolBar);
	return popupwin;
}

// call with "javascript: DoLogin();"
function DoLogin()
{
	ecmPopUpWindow("/WorkArea/login.aspx?action=autologin", "Login", 650, 500, 0, 0);
}

// call with "javascript: DoLogout();"
function DoLogout()
{
	ecmPopUpWindow("/ics_logout.html", "Login", 650, 500, 0, 0);
}
// This is for creating an iChain login on the page
function ICSInsertURL(obj)
{
	// obj = obj.parentNode;
	var url = obj.getElementsByTagName("INPUT");
	var x;
	for(x=0;x<url.length;x++) {
		if (url[x].name=="url") {
			url[x].value=document.location;
		}
	}
	return true;
}

function Iframefix () {
	var iframeid = "ektdmsiframe"; 
	var heightoffset=400;
		
	var winW = 0, winH = 0;

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
	var iFrames = document.getElementsByTagName("IFRAME");
	if (iFrames.length > 0) {
		iFrames[0].style.height = (winH-heightoffset)+"px";
		//alert((winH-heightoffset)+"px");
	}
}

addLoadEvent(Iframefix);
