var lang=3;

if(location.search.search('lang=4')>0){lang=4;}
var IE = document.all?true:false;
	if (!IE) document.captureEvents(Event.MOUSEDOWN)
		document.onmousedown = getMouseXY;
		var tempX = 0;
		var tempY = 0;

var lastId = null;
function overCell(theid)
{
	document.getElementById(theid).style.backgroundImage = "url(calendario/images/bg-day-over.gif)";
}
function outCell(theid)
{
	document.getElementById(theid).style.backgroundImage = "url(calendario/images/bg-day.gif)";
}
function clickCell(theid)
{
	if(lastId != theid && lastId != null)
	{
		document.getElementById(lastId).style.backgroundImage = "url(calendario/images/bg-day.gif)";
	}
	document.getElementById(theid).style.backgroundImage = "url(calendario/images/bga-link.gif)";
	lastId = theid;
}

var http_request = false;

function makeRequest(data, lang) {

http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
	//http_request.overrideMimeType('text/xml');
	// See note below about this line
    }
} else if (window.ActiveXObject) { // IE
    try {
	http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
	try {
	    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {}
    }
}

if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('POST', 'calendario/calendario.php?data='+data+'&lang='+lang, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
    if (http_request.status == 200) {
	//alert(http_request.responseText);
	document.getElementById("calendario").innerHTML = http_request.responseText;
    } else {
	alert('There was a problem with the request.');
	
    }
}

}


function getMouseXY(e) {
		if (IE) {
			// IE: X e Y
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;

			// IE: W e H (-scrollbars)
			winW = document.body.offsetWidth-20;
			winH = document.body.offsetHeight-4;
		} else {
			// IE: X e Y
			tempX = e.pageX;
			tempY = e.pageY;

			// NS: W e H (-scrollbars)
			winW = window.innerWidth;
			winH = window.innerHeight;
		}

		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  

		return true;
	}

function showcalendar(){
	if(document.getElementById("calendario").style.visibility == "visible"){
		document.getElementById("calendario").style.visibility = "hidden";
	}else{
		
		document.getElementById("calendario").style.left = tempX;
		document.getElementById("calendario").style.top = tempY;
		document.getElementById("calendario").style.visibility = "visible";
	}
	
}
document.getElementById("calendario").style.visibility = "hidden";
makeRequest('',lang);
