var req;
var myFun;
var isFirstOpen=false;
var isSecondOpen=false;

function openCalender(month,year) {
        var url = "calendar/calendar.php?month="+month+"&year="+year;
        if(window.XMLHttpRequest) {
                req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req.open("GET", url, true);
        req.onreadystatechange = calenderCallback;
        req.send(null);
		
		isSecondOpen=true;
		
		if(isFirstOpen==true)
			hideFirstCalendar();
			
		return false;
}

function calenderCallback() {        
        obj = document.getElementById("secondCalender");
        setFade2(0);
        
		if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
                        obj.innerHTML = response;
						obj.style.display="block";
                        fade2(0);
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}

function navigate(month,year) {
        var url = "calendar/calendar.php?month="+month+"&year="+year;
        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);
		
		isFirstOpen=true;

	if(isSecondOpen==true)
		hideSecondCalendar();
		
	 return false;	
}

function callback() {        
        obj = document.getElementById("calendar");
        setFade(0);
        
		if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
                        obj.innerHTML = response;
						obj.style.display="block";
                        fade(0);
                } else {
                        alert("There was a problem retrieving the data:\n" + req.statusText);
                }
        }
}

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

function setFade(amt) {
	obj = document.getElementById("calendar");
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}

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

function setFade2(amt) {
	obj = document.getElementById("secondCalendar");
	
	amt = (amt == 100)?99.999:amt;
  
	// IE
	obj.style.filter = "alpha(opacity:"+amt+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = amt/100;
  
	// Mozilla and Firefox
	obj.style.MozOpacity = amt/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = amt/100;
}

function addTask(fun)
{
	myFun=fun;
}

function hideFirstCalendar()
{

	document.getElementById("calendar").style.display="none";
	isFirstOpen=false;	
}

function hideSecondCalendar()
{	
	document.getElementById("secondCalendar").style.display="none";
	isSecondOpen=false;	
}
