// IMPORTANT: Homepage Resizing Function

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
			func();
		}
	}
}

addLoadEvent(setheight);
addLoadEvent(function() {
	loadXML('1223890562001','Welcome to Distance Learning',1);
})

function addResizeEvent(func) {
	var et = window.onresize;
	if (typeof window.onresize != 'function') {
		window.onresize = func;
	} else {
		window.onresize = function() {
		if (et) {
			et();
		}
			func();
		}
	}
}

addResizeEvent(setheight);
	addResizeEvent(function() {
		/* more code to run on page load */ 
})

function setheight() {
	if(screen.height > 640) {
		if(document.getElementById) {
			available_height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
			document.getElementById('content').style.height = available_height-180 + "px";
			document.getElementById('content-left').style.height = available_height-180 + "px";
			document.getElementById('content-right').style.height = available_height-180 + "px";
			document.getElementById('content-middle').style.height = available_height-180 + "px";
			document.getElementById('dynamic-content').style.height = available_height-380 + "px";
		}
	}
	document.forms[0].webctid.focus();
}

// IMPORTANT: Homepage Tab Content Display Function

function expand(id) {
	var msg = document.getElementById(id);
	msg.style.display = (msg.style.display != 'block') ? 'block' : 'none';
}

// IMPORTANT: WebCT Required Functions

if (top != self) {
	top.location = window.location;
}

function limitImageHeight(img,maxHeight) {
	if(img.height > maxHeight)img.height = maxHeight;
}

function openHelp() {
	newin=window.open("help.dowebct?tool=entry&screenid=377", "HelpWin", "width=600,height=450,resizable=yes");
}

// IMPORTANT: AJAX External Content Loader/Parser

var prev_menu = 1;

function loadXML(url,title,menuid) {
	var req	= false;
	var link  = '/webct/RelativeResourceManager?contentID=' + url;
	if(window.XMLHttpRequest) {
		req	=	new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			req	=	new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req	=	new ActiveXObject("Microsoft.XMLHTTP");			
			} catch (e) {}
		}
	}
	if (!req) {
		alert('Taking too long: Cant create an XMLHTTP instance');
		return false;
	} else {
		req.onreadystatechange = function() { parseHTML(req,title); }
		req.open("GET", link, true);
		req.send(null);
		document.getElementById("menu" + menuid).style.backgroundImage = "url('/webct/RelativeResourceManager?contentID=1001042494001')";
		document.getElementById("link" + menuid).style.color = "#ffdf22";
		if(prev_menu != menuid) {
			document.getElementById("menu" + prev_menu).style.backgroundImage = "url('/webct/RelativeResourceManager?contentID=1131458868001')"
			document.getElementById("link" + prev_menu).style.color = "#ffffff";
			prev_menu = menuid;
		}
	}
}

function parseHTML(req,title) {
	if(req.readyState == 4) {
		if(req.status == 200) {
			if(title != "") {
				var	dtitle = document.getElementById("dynamic-title");
					dtitle.innerHTML = title;
				if(title == "Welcome to Distance Learning" || title == "Class Schedules") {
					document.getElementById("footer-index").style.top = "0px";
				} else {
					document.getElementById("footer-index").style.top = "-24px";
				}				
			}
			var	dcontent = document.getElementById('dynamic-info') ;
				dcontent.innerHTML = req.responseText;
				document.forms[0].webctid.focus();
		} else {
			alert("There was a problem retrieving the HTML page:\n" + req.statusText);
		}
	}
}

// Animation

var index_state = true;
var index_pos   = 0;
var index_timer = null;

function displayIndex() {
	if (index_state) { 
		index_obj = document.getElementById("footer-index");
		index_pos = index_obj.offsetTop;
		if(index_pos < 0) {
			index_obj.style.top = index_pos++ + "px";
			index_timer = setTimeout("displayIndex()",50);
		} else {
			clearTimeout(index_timer);
		}
	} else {
		index_obj.style.top = -24 + "px"
	}
} 

// Pop Window

function pop(page) {
	window.newpage = page;
	pop_url = "http://online.mhcc.edu/webct/RelativeResourceManager?contentID=8943185264001";
	window.open(pop_url, "course_description", "location=0,resizable=1,toolbar=0,status=1,scrollbars=1,menubar=1,width=620,height=520");
}

