var Helper = {
	windowWidth:0,
	windowHeight:0,
	openOverlay:function(){
		if($('overlay')) document.body.removeChild($('overlay'));
		var overlay = document.createElement('DIV');
		overlay.setAttribute("id","overlay");
		//overlay.style.width = Helper.winWidth()+'px';
		if($('sbdiv')){
		overlay.style.height = ($('sbdiv').offsetHeight>Helper.winHeight()?
			document.getElementById('sbdiv').offsetHeight:
			Helper.winHeight())+20+'px';
			//alert(overlay.style.height);
		} else {
		   overlay.style.height = Helper.winHeight()+'px';
		   //alert('bang');
		}
		document.body.appendChild(overlay);
	},
	closeOverlay:function(){
		if($('overlay')) document.body.removeChild($('overlay'));
		if($('sbdiv')) document.body.removeChild($('sbdiv'));
	},
	createDiv:function(){
		if($('sbdiv')) document.body.removeChild($('sbdiv'));
		var sbdiv = document.createElement('DIV');
		sbdiv.setAttribute("id","sbdiv");
		document.body.appendChild(sbdiv);
	},
	win:function(){
		var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	},
	winHeight:function(){
		this.win();
		return pageHeight;
	},
	winWidth:function(){
		this.win();
		return pageWidth;
	}
}
function createXMLHttp(){
	if(typeof XMLHttpRequest != "undefined"){
		return new XMLHttpRequest();
	} else {
	var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
	for(var i=0;i<aVersions.length;i++){
		try {
			var oXmlHttp = new ActiveXObject(aVersions[i]);
			return oXmlHttp;
		} catch(oError){
		
		}
	}
	}
	throw new Error("XMLHttp could not be created");
}
function getSchedule($id){
	Helper.createDiv();
	var oXmlHttp = createXMLHttp();
    oXmlHttp.open("post",'getschedule.php',true);
    oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    oXmlHttp.onreadystatechange = function(){
  		if(oXmlHttp.readyState==4) {
				$('sbdiv').innerHTML = oXmlHttp.responseText;
				$('sbdiv').style.left = Helper.winWidth()/2-parseInt($('sbdiv').offsetWidth)/2+'px';

				Helper.openOverlay();
				$('sbdiv').getElementsByTagName('A')[0].onclick = function(){
					Helper.closeOverlay();
				}
    	}
    }
    oXmlHttp.send('id='+$id);
}
sb = function (){
	if(!document.getElementById('sbul')) return;
	var li = document.getElementById('sbul').getElementsByTagName('A');
	for(var i=0;i<li.length;i++){
		var fileid = li[i].search.replace("?id=","");
		li[i].setAttribute("fileid",fileid);
		li[i].onclick = function(){
			Helper.openOverlay();
			getSchedule(this.getAttribute("fileid"));

			return false;
		}
	}
}
window.attachEvent?window.attachEvent("onload",sb):window.addEventListener("load",sb, false);