// JavaScript Document
var allLoaded = false;
var menuArray = new Array("lifeScience", "highTech", "partners", "company"); 

function showMenu(idName){
	changeOpac(0, idName);
	document.getElementById(idName).style.visibility = "visible";
	opacity(idName, 0, 100, 400);
	for(var i=0; i < menuArray.length; i++){
		if(idName != menuArray[i]){
			document.getElementById(menuArray[i]).style.visibility = "hidden";
		}
	}
}
function secondaryEffect(idName){
	changeOpac(0, idName);
	document.getElementById(idName).style.visibility = "visible";
	opacity(idName, 0, 100, 800);	
}
function hideAll(){
	if(!allLoaded){return;}
	for(var i=0; i < menuArray.length; i++){
		document.getElementById(menuArray[i]).style.visibility = "hidden";
	}		
}
function hlight(object){
	object.style.backgroundColor = "#f3f3f3";
	object.style.color = "#558888";	
}
function unHlight(object){
	object.style.backgroundColor = "#eaeaea";	
	object.style.color = "#556666";
}
function sideLight(object){
	object.style.color = "#CCCCCC";	
}
function unSideLight(object){	
	object.style.color = "#354346";
}
function portalLight(object){
	object.style.color = "#558888";
	object.style.textDecoration = "underline";
}
function unPortalLight(object){	
	object.style.color = "#666";
	object.style.textDecoration = "none";
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
//Portal top menu controls
var portalArray = new Array("portals","myModeln","contact","siteMap"); 

function showPortal(idName){
	changeOpac(0, idName);
	document.getElementById(idName).style.visibility = "visible";
	opacity(idName, 0, 100, 400);
	for(var i=0; i < portalArray.length; i++){
		if(idName != portalArray[i]){
			document.getElementById(portalArray[i]).style.visibility = "hidden";
		}
	}
}
function hideAllPortals(){
	if(!allLoaded){return;}
	for(var i=0; i < portalArray.length; i++){
		document.getElementById(portalArray[i]).style.visibility = "hidden";
	}		
}
function parsePortalXML(xml){
	var portalItems = "";
	var spaceType;
	var valueArray = xml.getElementsByTagName("portalItem");
	for(var i = 0; i < valueArray.length; i ++){
		if(i == valueArray.length -1){
			spaceType = "";
		}else{
			spaceType = " | ";	
		}
		var idname = valueArray[i].getElementsByTagName("IdName")[0].firstChild.nodeValue;
		portalItems +=
		"<div style=\"display:inline; position:relative\">\n" +
		"<a href=\"" + valueArray[i].getElementsByTagName("link")[0].firstChild.nodeValue + "\" onmouseover=\"showPortal('" + idname + 
		"'); portalLight(this)\" onmouseout=\"unPortalLight(this)\">" + 
		valueArray[i].getElementsByTagName("value")[0].firstChild.nodeValue + "</a>" + spaceType + "\n" +
		"<div id=\"" + idname + "\"" + 
		"style=\"position:absolute; left: 0px; top: 25px; font-weight: normal; visibility:hidden; width: 1000px; background: white\">\n";
		var tiers = valueArray[i].getElementsByTagName("tier");
		for(var j = 0; j < tiers.length; j ++){
			if(j == tiers.length -1){
				spaceType = "";
			}else{
				spaceType = " | ";	
			}
			var theValue = tiers[j].getElementsByTagName("value")[0].firstChild.nodeValue;
			var theLink = tiers[j].getElementsByTagName("link")[0].firstChild.nodeValue;
			if(theValue == "Login"){
				var logged = getCookie("Authenticated");
				if(logged == "true"){
					theValue = "Logout";
					theLink = "javascript:killCookie();"
				}
			}
			portalItems += 
			"<a href=\"" + theLink + 
			"\" onmouseover=\"portalLight(this)\" onmouseout=\"unPortalLight(this)\">" + 
			theValue 
			+ "</a>" + spaceType + "\n";
		}
		portalItems += "</div></div>";
	}
	document.getElementById("portalNav").innerHTML = portalItems;
}
function parseXML(xml){
	var menuItems ="";
	var navItems = xml.getElementsByTagName("navItem");
	var position = 133;
	for(var i = 0; i < navItems.length; i++){
		var idName = navItems[i].getElementsByTagName("IdName")[0].firstChild.nodeValue;
		var subNavItems = navItems[i].getElementsByTagName("subNav");
		menuItems += 
		"<div style=\"position:absolute; left: " + (position * i)  + "px\">\n" +
		"<div style=\"position:relative\">\n" +
		"<a href=\"" + navItems[i].getElementsByTagName("link")[0].firstChild.nodeValue + "\" onmouseover=\"showMenu('" + idName 
		+ "')\"><img src=\"" + navItems[i].getElementsByTagName("image")[0].firstChild.nodeValue + "\" border=\"0\" /></a>\n" +
		"<div id=\"" + idName + "\" class=\"aMenu\">\n" +
		"<table cellpadding=\"0\" cellspacing=\"0\">\n";
		for(var j =0; j < subNavItems.length; j++){	
			menuItems += 
			"<tr><td valign=\"top\"><a href=\"" + subNavItems[j].getElementsByTagName("link")[0].firstChild.nodeValue + "\">\n" +
			"<div class=\"dropDownMenu\" onmouseover=\"hlight(this)\" onmouseout=\"unHlight(this)\">" +
			subNavItems[j].getElementsByTagName("value")[0].firstChild.nodeValue
			+ "</div>\n" +
			"</a></td></tr>\n";	
		}
		menuItems += "</table>\n" + "</div></div></div>";
	}
	menuItems += "<div style=\"position:absolute; left: 670px\">" +
				 "<div style=\"position:relative; padding-top: 3px\">" +
				 "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">" +
			     "<tr><td><input id=\"searchForm\" onKeyPress=\"checkEnter(event)\" onclick=\"this.value=''\" type=\"text\" style=\"width:110px\" class=\"smallerFont\" value=\"Search Model N\" /></td>" +
				 "<td><img src=\"/images/go.gif\" border=\"0\" style=\"margin-left: 1px; cursor: hand; cursor: pointer\" onclick=\"searchForm()\" /></td></tr>" + 
                 "</table></div></div></div>";
	document.getElementById("mainNavigation").innerHTML = menuItems;
}
function searchForm(){
	if(document.getElementById("searchForm").value != "" && document.getElementById("searchForm").value != "Search Model N"){
		location.href = "/searchResults.html?" + document.getElementById("searchForm").value; 
	}
}
function checkEnter(e){
	var characterCode;
	if(e && e.which){
		e = e;
		characterCode = e.which;
	}else{
		e = event;
		characterCode = e.keyCode;	
	}
	if(characterCode == 13){
		searchForm();
		return false;
	}else{
		return true;
	}
}
var secondaryItems = "";
var pathArray;
var tier;
var padding;
var width;
var path = document.location.pathname;
var xml;
var dontDrop = true;
function changePathCollapseMenu(){
	pathArray.pop();
	pathArray.pop();
	dontDrop = false;
	navItem = xml.getElementsByTagName(pathArray[1]);
	subNav = navItem[0].getElementsByTagName(pathArray[2]);
	tier = 3;
	padding = 10;
	width =100;
	secondaryItems = "";
	secondaryItems += "<table cellpadding=\"0\" cellspacing=\"0\" style=\"position:relative\">\n";
	xmlChildren(subNav[0].firstChild);
	secondaryItems += "</table>\n";
	document.getElementById("sideNav").innerHTML = secondaryItems;
	secondaryEffect("sideNav");
	dontDrop = true;
}
function parseSecondaryXML(xml){
	
	pathArray = path.split('/');
	if(pathArray.length > 3){
		navItem = xml.getElementsByTagName(pathArray[1]);
		subNav = navItem[0].getElementsByTagName(pathArray[2]);
		tier = 3;
		padding = 10;
		width =100;
		secondaryItems += "<table cellpadding=\"0\" cellspacing=\"0\" style=\"position:relative\">\n";
		xmlChildren(subNav[0].firstChild);
		secondaryItems += "</table>\n";
		document.getElementById("sideNav").innerHTML = secondaryItems;
	}
}
function xmlChildren(object){
	if(object != null){
		if(object.nodeName == "tier"){
			xmlChildren(object.firstChild);
		}
		if(object.nodeName == "value"){
			var theValue = object.firstChild.nodeValue;
			var findLink = object.nextSibling;
			while(findLink != null){
				if(findLink.nodeName == "link"){
					findLink = findLink.firstChild.nodeValue;
					break;
				}else{
					findLink = findLink.nextSibling;
				}
			}
			var linkPath = findLink.split('/');
			if(object.parentNode.childNodes.length == 3 || object.parentNode.childNodes.length > 5){
				if(path.indexOf(linkPath[linkPath.length - 2]) >= 0 && dontDrop){
					arrowType = downArrow;
					findLink = "javascript: changePathCollapseMenu()";
				}else{
					arrowType = passiveArrow;
				}
			}else{
				arrowType = "";	
			}
			if((findLink == path && object.firstChild.nodeValue == "Overview") || 
				 ((linkPath[linkPath.length -1] == pathArray[pathArray.length -1]) && linkPath[linkPath.length -1] != "" && 
					arrowType != downArrow) || 
				 ((linkPath[linkPath.length -1] == pathArray[pathArray.length -1]) && (/[0-9]{4}/.test(object.firstChild.nodeValue)))
				|| (pathArray[pathArray.length - 2] == "careers")
				|| ((object.firstChild.nodeValue == pathArray[pathArray.length -2]) && (/[0-9]{4}/.test(pathArray[pathArray.length -2])))
				|| ("Calendar" == pathArray[pathArray.length -2] && object.firstChild.nodeValue == "Course Schedule")
				 ){
				colorType = color;
				eventsType = "";
			}else{
				colorType = "";
				eventsType = events;
			}
			var visible;
			if(padding == 10){
				visible = "hidden";
			}else{
				visible = "visible";
			}
			var indentArrow = padding - 12;
			secondaryItems +=
			"<tr><td valign=\"top\"><a href=\"" + findLink + "\">\n" +
			"<div class=\"SideNavMenu\" style=\"padding-left:" + padding + 
			"px; width:" + width + "px" + colorType + "\"" +  eventsType + ">" + 
			"<div style=\"position: absolute; left: " + indentArrow + "px; top: 10px; visibility: "+ visible +"\">" + 
			"<img src=\"/images/bullet_level_on.gif\" border=\"0\"/></div>"
			+ theValue + arrowType + "</div>\n" + "</a></td></tr>\n";
		}
		if(object.nodeName == pathArray[tier]){
			tier += 1;
			padding += 13;
			width -= 13;
			xmlChildren(object.firstChild);
			tier -= 1;
			padding -= 13;	
			width += 13;
		}
		xmlChildren(object.nextSibling);
	}
}
function parseFooter(xml){
	var footerString = "<div style=\"position: absolute; left: 20px; top: 30px\">";
	var footer = xml.getElementsByTagName("footerItem");
	for( var i = 0; i < footer.length; i++){
		var value = footer[i].getElementsByTagName("value")[0].firstChild.nodeValue;
		var footerLink = footer[i].getElementsByTagName("link")[0].firstChild.nodeValue;
		footerString += "<a href=\"" + footerLink + "\">" + value + "</a>";
		if(i != footer.length - 1){
			footerString += " | ";
		}
	}
	footerString += "</div>" +
	"<div style=\"position: absolute; right: 2px; top: 30px\">&copy;" + 
	xml.getElementsByTagName("footerCopyright")[0].firstChild.nodeValue + "</div>";
	document.getElementById("footer").innerHTML = footerString;
}
function offSite(url){
	window.open(url);	
}
function getCookie(Name){
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
	 
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}
function killCookie(){
	var cookie_name = "Authenticated";
  	var cookie_date = new Date ( );  // current date & time
  	cookie_date.setTime ( cookie_date.getTime() - 1 );
  	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
	document.location.href = location.href;
	
}

/*************************************string variables*****************************/
var passiveArrow = "<div style=\"position: absolute; left: 115px; top: 8px;\">" + 
									 "<img src=\"/images/whiteArrow.gif\" border=\"0\" /></div>";
var downArrow = 	"<div style=\"position: absolute; left: 115px; top: 8px;\">" + 
									 "<img src=\"/images/arrowDown.gif\" border=\"0\" /></div>";
var events =  "onmouseover=\"sideLight(this)\" onmouseout=\"unSideLight(this)\"";
var color = ";color: #336677; background: #ffcc00; font-weight: bold";

/*************************************ajax routines***********************************/	


var XMLHttp;
function sendAdminRequest(url){
	XMLHttp = getXMLHttp();
	XMLHttp.open("GET",url);
	XMLHttp.onreadystatechange=handlerGet;
	XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	XMLHttp.send(null);
}
function sendRequest(url){
	XMLHttp = getXMLHttp();
	XMLHttp.open("GET",url);
	XMLHttp.onreadystatechange=handlerFunk;
	XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	XMLHttp.send(null);
}
function handlerGet(){
	if(XMLHttp.readyState == 4){
		xml = XMLHttp.responseXML;
		parseXML(xml);
		parsePortalXML(xml);
		parseFooter(xml);
		allLoaded = true;
	}
}
function handlerFunk(){
	if(XMLHttp.readyState == 4){
		xml = XMLHttp.responseXML;
		parseXML(xml);
		parseSecondaryXML(xml);
		parsePortalXML(xml);
		parseFooter(xml);
		allLoaded = true;
	}
}

function getXMLHttp() {
  var XMLHttp = null;
  if (window.XMLHttpRequest) {
    try {
      XMLHttp = new XMLHttpRequest();
    } catch (e) { }
  } else if (window.ActiveXObject) {
    try {
      XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) { }
    }
  }
  return XMLHttp;
}




