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);
	}
}


function AJAXGenericLoadNew(TargetObject, URL, f) {
	if (TargetObject && URL) {
		var xmlhttp = GetHTTPObject();
		xmlhttp.open("GET", URL);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (TargetObject == "return"){
					return xmlhttp.responseText;
					f();
				}else if (TargetObject == "function"){
					f(xmlhttp.responseText);
				} else {
					TargetObject.innerHTML = xmlhttp.responseText;
					f();
				}
				
			}
		}
		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()
{

/*
	$(document).ready(function(){
		$(".login").nyroModal({
			height: 475,
			width: 640,
		});
	});	
*/

/*
		$(document).ready(function(){
			$(".container").nyroModal();
		});
*/
/*  $('#manual2').click(function(e) {
    e.preventDefault();
    $.nyroModalManual({
      url: 'demoSent.php'
    });
    return false;
  });
*/

	ecmPopUpWindow("/WorkArea/login.aspx?action=autologin", "Login", 650, 500, 0, 0);

/*    $.nyroModalManual({
		type: 'iframe',
		url: '/WorkArea/login.aspx?action=autologin',
		height: 475,
		width: 640
    });
*/
}

// 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);


/* ***********************************************
	INLINE FLASH VIDEO POPUP WITH GOOGLE TRACKING
   *********************************************** */

function PlayVideo(TargetObject, videoURL) {
	var TargetDiv = document.getElementById(TargetObject);
	TargetDiv.innerHTML = "<div id='OverlayDivActive'>	\n\t<div id='ie'>		\n\t\t<div class='OverlayDivActive'></div>		\n\t\t<div class='AJAXVideoPlayer'></div>	\n\t</div>	\n\t<div id='AJAXVideoPlayer' class='AJAXVideoPlayer'>		\n\t\t<div id='AJAXVideoPlayerClose'><a href='#' onclick='javascript:document.getElementById(\"OverlayDiv\").innerHTML=\"\"' ;><img src='/flash/drewtubeplayer/close.gif' /></a></div></div>\t</div>";

	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		document.getElementById('AJAXVideoPlayer').innerHTML = document.getElementById('AJAXVideoPlayer').innerHTML + AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '100%',
			'height', '100%',
			'src', '/flash/AjaxVideoPlayer/VideoPlayer',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'VideoPlayer',
			'bgcolor', '#ffffff',
			'name', 'VideoPlayer',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '/flash/AjaxVideoPlayer/VideoPlayer',
			'salign', '',
			'FlashVars', 'import_url='+videoURL
		); //end AC code
		pageTracker._trackPageview(videoURL.replace("rtmp://", ""));
	}
}

function ResizeFlashPlayer(width,height) {
	document.getElementById("AJAXVideoPlayer").style.width = width + "px";
	document.getElementById("AJAXVideoPlayer").style.height = height + 14 + "px";
	document.getElementById("AJAXVideoPlayer").style.margin = "-" + (height + 14) /2  + "px"  + " 0px 0px -" + width / 2  + "px";
}


/* ***********************************************

	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
	
 *********************************************** */


function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};
