var req;

function navigate(month,year) {
	var url = "calendar.asp?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);
}

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("Problema na captura da data:\n" + req.statusText);
		}
	}

	$(document).ready(function()
	{
		
	   // Use the each() method to gain access to each elements attributes
	   $('#calendar a[rel]').each(function()
	   {
		  $(this).qtip(
		  {
			 content: $(this).attr('rel'),/*{
				url: $(this).attr('rel') // Use the rel attribute of each element for the url to load*/
			 /*},*/
			 position: {
				corner: {
				   target: 'bottomMiddle', // Position the tooltip above the link
				   tooltip: 'topLeft'
				},
				adjust: {
				   screen: true // Keep the tooltip on-screen at all times
				}
			 },
			 show: { 
				solo: true // Only show one tooltip at a time
			 },
			 style: {
				tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
				border: {
				   width: 0,
				   radius: 4,
				   color: '#4A77A8'
				},
				background: '#BFD8F2',
				width: 600 // Set the tooltip width
			 }
		  })
	   });
	});
}

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;
}
