var req;

function navigate(month,year,evt) {
	setFade(0);
	var url = "super_calendar.php?month="+month+"&year="+year+"&event="+evt;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);		
}

function callback() {
	if(req.readyState == 4) {
		var response = req.responseXML;
		var resp = response.getElementsByTagName("response");
		getObject("calendar").innerHTML = resp[0].getElementsByTagName("content")[0].childNodes[0].nodeValue;
		//fade(70);
		fadeIn(getObject("calendar"), 100);
	}
}

function getObject(obj) {
	var o;
	if(document.getElementById) o = document.getElementById(obj);
	else if(document.all) o = document.all.obj;	
	return o;	
}

function fade(amt) {
	if(amt <= 100) {
		setFade(amt);
		amt += 10;
		setTimeout("fade("+amt+")", 5);
    }
}

function setFade(amt) {
	var obj = getObject("calendar");
	amt = (amt == 100)?99.999:amt;
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
}
/* fade function*/
_in = function(){
	var i = Math.ceil((this.tarOpac-(this.objct.style.opacity*100))/this.speed)+(this.objct.style.opacity*100);
	this.objct.style.opacity = i/100;
	this.objct.style.filter = 'alpha(opacity='+i+')';
	if(i >= this.tarOpac){
		clearInterval(this.fadeIn_int);
	}
}
_out = function(){
	var i = Math.floor((0 - (this.objct.style.opacity*100))/this.speed)+(this.objct.style.opacity*100);
	this.objct.style.opacity = i/100;
	this.objct.style.filter = 'alpha(opacity='+i+')';
	if(i<= 0){
		clearInterval(this.fadeOut_int);
		if(this.remove){
			this.objct.parentNode.removeChild(this.objct);	
		}
	}
}
fadeIn = function(objct, tarOpac){
	this.objct = objct;
	this.speed = 1;
	this.tarOpac = tarOpac;	
	this.objct.style.opacity = 0;
	this.objct.style.visibility = 'visible';
	this.objct.style.filter = "alpha(opacity=0)";	
	tf = this;
	this.fadeIn_int = setInterval("tf._in()", 20);
}
fadeOut = function(objct, remove){
	if(this.fadeIn_int){ clearInterval(this.fadeIn_int);}
	this.objct;
	this.speed = 3;
	tf = this;
	this.remove = remove;
	this.fadeOut_int = setInterval("tf._out()", 20);
}

function showJump(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var jump = document.createElement("div");
	jump.setAttribute("id","jump");
	jump.style.position = "absolute";
	jump.style.top = curtop+15+"px";
	jump.style.left = curleft+"px";
	var output = '<select id="month">\n';
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var n;
	for(var i=0;i<12;i++) {
		n = ((i+1)<10)? '0'+(i+1):i+1;
		output += '<option value="'+n+'">'+months[i]+'&nbsp;&nbsp;</option>\n';
	}
	output += '</select>\n&nbsp;&nbsp;<select id="year">\n';
	for(var i=0;i<=15;i++) {
		n = (i<10)? '0'+i:i;
		output += '<option value="20'+n+'">20'+n+'&nbsp;&nbsp;&nbsp;</option>\n';
	}
	output += '</select>&nbsp;&nbsp;&nbsp;<a href="javascript:jumpTo()"><img src="calimages/calGo.gif" alt="go" /></a>&nbsp;&nbsp;&nbsp;<a href="javascript:hideJump()"><img src="calimages/calStop.gif" alt="close" class="close" /></a>';
	jump.innerHTML = output;
	document.body.appendChild(jump);
}
function hideJump() {
	document.body.removeChild(getObject("jump"));	
}

function jumpTo() {
	var m = getObject("month");
	var y = getObject("year");
	navigate(m.options[m.selectedIndex].value,y.options[y.selectedIndex].value,'');
	hideJump();
}