var req;
var g_m;
var g_y;


function navigate(month,year) {
		g_m = month;
		g_y = year;
		
		
        var url = "/acalendar/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 = function(){
			callback();
			//GrabUpcomingEvents(g_m,g_y)
			$("a.view-large").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
		}
        req.send(null);
}

function GrabUpcomingEvents()
{
	var req_upcoming;
	 var url = "/global/ajax/grab_upcoming.php?month="+g_m+"&year="+g_y;
        if(window.XMLHttpRequest)
		{
                req_upcoming = new XMLHttpRequest();
        } else if(window.ActiveXObject)
		{
                req_upcoming = new ActiveXObject("Microsoft.XMLHTTP");
        }
        req_upcoming.open("GET", url, true);
        req_upcoming.onreadystatechange = function()
		{
			document.getElementById("upcoming_events").innerHTML = req_upcoming.responseText;
		}
        req_upcoming.send(null);
}


function callback() {        
        obj = document.getElementById("calendar");
        setFade(0);
        
		if(req.readyState == 4) {
                if(req.status == 200) {
                        response = req.responseText;
                        obj.innerHTML = response;
                        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 ShowEventInfo(eid)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var return_string;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			return_string = ajaxRequest.responseText;
		//	alert(return_string);
			document.getElementById("event_info_window").innerHTML = return_string;
			document.getElementById("event_info_window").style.display = "";
		}
	}
	var queryString = "?eid="+eid;
	ajaxRequest.open("GET", "/global/ajax/grab_event_info.php" + queryString, true);
	ajaxRequest.send(null); 
}

function CloseEventInfo()
{
	document.getElementById("event_info_window").style.display = "none";
}	
