//******************************************************************************************
// Module Name: Ivey.js
//      Author: Alex Dlugokecki
//        Date: 11/15/04
//     Company: Concept Interactive
// Description: Ivey Template Scripts
//
//
//
// Revision History:
// 
// Date:      Author:   Description:
// 11/12/04   AD        1.0
// 01/06/05   AD        1.1 (Requested changes to top menu and obsolete browser redirect)
//******************************************************************************************

window.onresize = redo; 
var timerID = ""; 
var timerOn = false; 
var timecount = 300; 
var browser = ""; 
var newbrowser = true; 
var check = false;
var activemenu;
var loaded;

function init() 
{  
	if (detectBrowser() == true)
	{
		activemenu = document.getElementById("topmenuvalue").value;
		setActiveMenu(activemenu);
		positionTopMenus();
		
		if (document.getElementById) 
		{  
			layerRef = "document.getElementByID";  
			styleSwitch = ".style";  
			visibleVar = "visible";  
			browser = "dom1";  
		}  
		else 
		{  
			browser = "none"; 
			newbrowser = false;  
		}
		check = true; 
		hideAll();
		loaded = true;
	}
	else
	{
		window.location = "/mba/common/redirect.htm";
	}
}  

function detectBrowser()
{
	
	//misc old browsers
	if (!document.getElementById)
	{
		return false;
	}
	
	if (!document.images)
	{
		return false;
	}
	
	//opera 7 or higher
	if (navigator.userAgent.indexOf("Opera") != -1)
	{
		temp = navigator.userAgent.split("Opera");
		version = parseFloat(temp[1]);
		
		if (version < 7)
		{
			return false;
		}
	
		return true;
	}
	
	//Firefox
	if (navigator.userAgent.indexOf("Firefox") != -1)
	{
		return true;
	}

	//IE4 or higher
	version = 0;
	if (navigator.appVersion.indexOf("MSIE") != -1)
	{
		temp = navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
		
		if (version < 4)
		{
			return false;
		}
		
		return true;
	}
	
	//safari 1.2 or higher
	if (navigator.appVersion.indexOf("Safari") != -1)
	{
		temp = navigator.appVersion.split("Safari");
		version = parseFloat(temp[1]);
		
		if (version < 1.2)
		{
			return false;
		}
		
		return true;
	}
	
	//netscape 6 or higher
	if (navigator.appName == "Netscape" && parseFloat(navigator.appVersion) < 5.0)
	{
		return false;
	}
	
	return true;

}

function showLayer(layerName) 
{  
	if(check) 
	{  
		if (browser == "none") 
		{  
			return;  
		}  
		else if (browser == "dom1") 
		{  
			document.getElementById(layerName).style.visibility = "visible";  
		}  
		else 
		{  
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility = "visible"');  
		}  
	}  
	else 
	{  
	return;  
	}  
} 


function hideLayer(layerName) 
{  
	if(check) 
	{  
		if (browser == "none") 
		{ 
			return;  
		}  
		else if (browser == "dom1") 
		{  
			document.getElementById(layerName).style.visibility = "hidden";  
		}  
		else 
		{  
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility = "hidden"');  
		}  
	}  
	else 
	{  
		return;  
	}  
} 


function hideAll() 
{   
	hideLayer('degreemenu');
	hideLayer('executivedevmenu');
	hideLayer('researchmenu');
	hideLayer('hongkongmenu');
	hideLayer('alumnimenu');
	hideLayer('recruitersmenu');
	hideLayer('casesalesmenu');
	hideLayer('aboutmenu');
} 


function startTime() 
{  
	if (timerOn == false) 
	{  
		timerID = setTimeout("hideAll()", timecount);  
		timerOn = true;  
	}  
} 


function stopTime() 
{ 
	if (timerOn) 
	{  
		clearTimeout(timerID);  
		timerID = null;  
		timerOn = false;  
	}  
} 


function redo() 
{ 
	window.location.reload();  
} 


function setActiveMenu(menuitem)
{	
	if (menuitem == 8) {}
	else
	{
		if (activemenu != 8)
		{
			document.getElementById("menuitem" + activemenu).style.backgroundColor = "#FFCC00";
		}
		document.getElementById("menuitem" + menuitem).style.backgroundColor = "#FFCC00";
	}
}


function unsetActiveMenu(menuitem)
{
	document.getElementById("menuitem" + menuitem).style.backgroundColor = "#0D6145";
}


function openMenu(menu, menunum)
{
	setActiveMenu(menunum);
	hideAll(); 
	showLayer(menu); 
	stopTime();
}


function closeMenu(menunum)
{
	unsetActiveMenu(menunum); 
	setActiveMenu(activemenu);
	startTime();
}


function sideMenuOpenClose(section)
{
	if (document.getElementById(section + "content").style.display == "block")
	{
		document.getElementById(section + "content").style.display = "none";
		document.getElementById(section + "arrow").src = "/images/arrow_up.gif";
		document.getElementById(section + "bar").style.backgroundColor = "#F4F5E8";
		document.getElementById(section + "link").style.backgroundColor = "#F4F5E8";
		document.getElementById(section + "link").style.fontWeight = "normal";
	}
	else
	{
		sideMenuCloseAll();
		document.getElementById(section + "content").style.display = "block";
		document.getElementById(section + "arrow").src = "/images/arrow_down.gif";
		document.getElementById(section + "bar").style.backgroundColor = "#FFFFFF";
		document.getElementById(section + "link").style.backgroundColor = "#FFFFFF";
		document.getElementById(section + "link").style.fontWeight = "bold";
	}
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}




function positionTopMenus()
{
	var posX = findPosX(document.getElementById("tabcorner"));
	document.getElementById("degreemenu").style.left = posX + 3;
	document.getElementById("executivedevmenu").style.left = posX + 111;
	document.getElementById("researchmenu").style.left = posX + 260;
	document.getElementById("hongkongmenu").style.left = posX + 371;
	document.getElementById("alumnimenu").style.left = posX + 476;
	document.getElementById("recruitersmenu").style.left = posX + 530;
	document.getElementById("casesalesmenu").style.left = posX + 491;
	document.getElementById("aboutmenu").style.left = posX + 567;
}


function selectSideMenuLink(link)
{	
	var link = link.substring(0, link.length - 4);
	document.getElementById(link + "arrow").style.visibility = "visible";
	document.getElementById(link + "link").style.color = "#FF6600";
	document.getElementById(link + "link").style.textDecoration = "underline";
}

function sideMenuLink(section)

{

            document.getElementById(section + "bar").style.backgroundColor = "#F4F5E8";
            document.getElementById(section + "link").style.backgroundColor = "#F4F5E8";
            document.getElementById(section + "link").style.fontWeight = "normal";
            document.getElementById(section + "bar").style.backgroundColor = "#FFFFFF";
            document.getElementById(section + "link").style.backgroundColor = "#FFFFFF";
            document.getElementById(section + "link").style.fontWeight = "bold";

}



function sideMenuCloseAll()
{
	var counter = document.getElementsByTagName("div");
	
	for (x = 8; x<counter.length; x++)
	{
		var section = counter[x].id;	
		var section = section.substring(0, section.length - 7);
	
		document.getElementById(section + "content").style.display = "none";
		document.getElementById(section + "arrow").src = "/images/arrow_up.gif";
		document.getElementById(section + "bar").style.backgroundColor = "#F4F5E8";
		document.getElementById(section + "link").style.backgroundColor = "#F4F5E8";
		document.getElementById(section + "link").style.fontWeight = "normal";
	}
}




