var http = objetoAjax();
//var archivo = "rpc.php?";
var archivo = "libs/calendario/rpc.php?";
var pathrelativo = "";

function iniciaCalendario(month, year, path){
	pathrelativo = path;
	divDatos = document.getElementById('calendarInternal');
	divDatos.innerHTML = '';
	http.open("GET", path+archivo + 'action=startCalendar&month='+month+'&year='+year+'&path='+path + "&nocache=" + Math.random(), true);
	http.onreadystatechange = iniciaCalendarioHttpResponse;
	http.send(null);
}

function iniciaCalendarioHttpResponse(){
    if (http.readyState == 1){
		//divResultado = document.getElementById('calendarInternal');
        document.getElementById('eventList').innerHTML = '';
        document.getElementById('work').innerHTML = '<img src="' + pathrelativo + 'templates/default/img/loading1.gif" />';
    }
    if (http.readyState == 4){
        results = http.responseText;
        document.getElementById('work').innerHTML = '';
        document.getElementById('calendarInternal').innerHTML = results;
    }
}

function mostrarEventos(day, month, year, path) {
	pathrelativo = path;
	divDatos = document.getElementById('eventList');
	divDatos.innerHTML = '';
	http.open("GET", path+archivo + 'action=listEvents&d='+day+'&m='+month+'&y='+year+'&path='+path + "&nocache=" + Math.random(), true);
	http.onreadystatechange = mostrarEventosHttpResponse;
	http.send(null);
}

function mostrarEventosHttpResponse(){
    if (http.readyState == 1){
		divResultado = document.getElementById('eventList');
        document.getElementById('work').innerHTML = '<img src="' + pathrelativo + 'templates/default/img/loading.gif" />';
    }
    if (http.readyState == 4){
        results = http.responseText;
        document.getElementById('work').innerHTML = '';
        document.getElementById('eventList').innerHTML = results;
    }
}

function highlightCalendarCell(element) {
	$(element).style.border = '1px solid #bbbbbb';
}

function resetCalendarCell(element) {
	$(element).style.border = '1px solid #000000';
}

function highlightEvent(day) {
	Element.hide('addEventForm');
	$('calendarDay_'+day+'').style.background = '#<?= $eventColor ?>';
}

function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
