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()
{
	$("#Menu").empty();
}

function CMSMenuAddToTop(url)
{
	var menudiv = $("#Menu");
	if (menudiv && url) {
		$.get(url, function(data){
			menudiv.prepend(data)
		});
	}
}

function CMSMenuAddToBottom(url)
{
	var menudiv = $("#Menu");
	if (menudiv && url) {
		var rnd = Math.floor(Math.random()*1100) 
		menudiv.append('<div id='+rnd+'></div>')
		$.get(url, function(data){
			menudiv.find("#"+rnd).append(data)
		})
	}
}

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'>"
		+"	<div id='ie'>"
		+"		<div class='OverlayDivActive'></div>"
		+"		<div class='AJAXVideoPlayer'></div>"
		+"	</div>"
		+"	<div id='AJAXVideoPlayer' class='AJAXVideoPlayer'>"
		+"		<div id='AJAXVideoPlayerClose'>"
		+"			<a href='#' onclick='javascript:document.getElementById(\"OverlayDiv\").innerHTML=\"\"' ;><img src='/flash/drewtubeplayer/close.gif' /></a>"
		+"		</div>"
		+"		<div id='AJAXVideoPlayerSWF'></div>"
		+"	</div>"
		+"</div>"
		);

	var so = new SWFObject("/flash/AjaxVideoPlayer/VideoPlayer.swf", "VideoPlayer", "100%", "100%", "7", "#ffffff");
		so.addVariable("import_url", videoURL);
		so.addParam('allowfullscreen','true');
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.addParam("menu", "true");
		so.write("AJAXVideoPlayerSWF");
	*/
	Shadowbox.open({
		content:    videoURL,
		player:     "flv",
		width:		720,
		height:     415
	});
	
	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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

/* ***********************************************
			EMPTY P TAG REMOVER
*********************************************** */

$(document).ready(function(){
	$("p").each(function(){
		if($(this).html() == "&nbsp;") $(this).remove();
		if($(this).html() == "&#160;") $(this).remove();
	});
});


/* ***********************************************
			Image Captions
*********************************************** */

$(document).ready(function(){
	$(".caption").each(function(){
		var w = $(this).width();
		var al = $(this).attr('align');
		$(this).wrap("<span class='caption'></span>");
		$(this).parent().css({
			width: w
			,float: al
		});
		var cap = false;
		if ($(this).attr('title')) cap = $(this).attr('title');
		if ($(this).attr('alt')) cap = $(this).attr('alt');
		cap = cap.replace(/&lt;/g, "<");
		cap = cap.replace(/&gt;/g, ">");
		if (cap) $(this).parent().append("<span>"+ cap +"</span>");
		$(this).removeClass('caption');
	});
});


/* ***********************************************
			Table Row Coloring
*********************************************** */


$(document).ready(function(){
	$("table.altrow tbody tr:odd").addClass('table-alt-row');
});
