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(){
		if (self.innerHeight) {	// all except Explorer
			this.windowWidth = self.innerWidth-18;
			this.windowHeight = (document.body.offsetHeight);
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			this.windowWidth = document.documentElement.clientWidth;
			this.windowHeight = document.body.offsetHeight+20;
		} else if (document.body) { // other Explorers
			this.windowWidth = document.body.clientWidth;
			this.windowHeight = document.body.clientHeight+(document.body.scrollHeight-document.body.clientHeight+20);
		}
	},
	winHeight:function(){
		this.win();
		return this.windowHeight;
	},
	winWidth:function(){
		this.win();
		return this.windowWidth;
	}
}
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);