var calendarioMesActual;
var arrCaracteristicas = new Array();

function AllBoxs()
{
	for(var i=0; i < arrCaracteristicas.length; i++){
		if(document.getElementById("todos").checked == true){
			document.getElementById("tipoEvento_"+arrCaracteristicas[i]).checked = true;
			document.getElementById("otros").checked = true;
		} else {
			document.getElementById("tipoEvento_"+arrCaracteristicas[i]).checked = false;
			document.getElementById("otros").checked = false;
		}
	}
}

function traerResultados(sentido) {
	var form = document.forms['filtro'];
	document.getElementById('resetPaginador').value = 0;
	if(sentido == 'sgte') {
		form.paginaEvent.value = parseInt(form.paginaEvent.value) + 1;
	}
	if(sentido == 'ant') {
		form.paginaEvent.value = parseInt(form.paginaEvent.value) - 1;
	}
	if(sentido == 'resetPaginador'){
		document.getElementById('resetPaginador').value = 1;
		form.paginaEvent.value = 0;
	}
	if(arrCaracteristicas.length > 0){
		for(var i=0; i < arrCaracteristicas.length; i++){
			if(document.getElementById("tipoEvento_"+arrCaracteristicas[i]).checked == true){
				document.getElementById("carac_"+arrCaracteristicas[i]).value = arrCaracteristicas[i];
			} else {
				document.getElementById("carac_"+arrCaracteristicas[i]).value = 0;	
			}
		}
	}
	loadHttpRequest('../_post/hc_washington/filtroEventos.php', 'result', form);
}


function updateCalendario(up) {
	var mes = parseInt(calendarioMesActual) + (up? 1: -1);
	document.getElementById("calendarioLoading").style.display = "";
	document.getElementById("calendarioContent").style.display = "none";
	document.getElementById("calendarioFrame").src = "../_post/hc_washington/calendarioEventos.php?mes="+mes;
}

function showCalendario(mes, fecha) {
	calendarioMesActual = Number(mes);
	document.getElementById("calendarioMes").innerHTML = fecha;
	document.getElementById("calendarioLoading").style.display = "none";
	document.getElementById("calendarioContent").style.display = "";
}

function expandEvent(){
	 document.getElementById("newEvent").style.display="block";
	 //document.getElementById("cerrarEvent").style.display="block";
}

function collapseEvent(){
	 document.getElementById("newEvent").style.display="none";
	 //document.getElementById("cerrarEvent").style.display="none";
}


function buscador_eventos()
{
	document.getElementById("textEvent").value = document.getElementById("buscar_evento").value;
	traerResultados('resetPaginador');
}

/*AJAX HANDLER*/
function XmlHttpRequest(){
    var ajax = false;
    try {
        ajax = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        try {
            ajax = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {
            ajax = false;
        }
    }
    if (!ajax && typeof XMLHttpRequest != 'undefined') {
        ajax = new XMLHttpRequest();
    }
    return ajax;
}

function loadHttpRequest(url, div, form) {
    var ajax = XmlHttpRequest();
    var div = document.getElementById(div);
    var data = ((form != '') ? get_data(form.name) : '');
    var ID = Math.random();
    ajax.open("POST", url, true);
    ajax.onreadystatechange = function(){
        if (ajax.readyState == 0) {
            div.innerHTML = "Enviando la solicitud...";
        }
        if (ajax.readyState == 1 || ajax.readyState == 2 || ajax.readyState == 3) {
            div.innerHTML = "<div align='center' style='margin-top:50px'><img src='../_modulos/eventos/_imgs/hc_washington/loader.gif' alt='Loading...'></div>";
        }
        if (ajax.readyState == 4) {
            if (ajax.status == 200) {
                div.innerHTML = ajax.responseText
                var scripts = div.getElementsByTagName('script');
                for (var i = 0; i < scripts.length; i++) {
                	eval(scripts[i].innerHTML);
                }
            } else {
                if (ajax.status == 404) {
                    div.innerHTML = "La direccion no existe";
                } else {
                    div.innerHTML = "Error: " + ajax.status;
                    return true;
                }
            }
        }
    }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.setRequestHeader("Content-length", data.length);
    ajax.setRequestHeader("Connection", "close");
    ajax.send("ID=" + ID + data);
}

function get_data(form){
    var form_id = document.getElementById(form);
    var url_string = '';
    var delimiter = '&';
    for (var i = 0; i < form_id.elements.length; i++) {
        if (form_id.elements[i].type != 'reset' && form_id.elements[i].type != 'submit' && form_id.elements[i].type != 'button') {
            url_string += delimiter + form_id.elements[i].name + '=' + escape(encodeURI(get_value(form_id.elements[i])));
        }
    }
    return url_string;
}

function clean_form(form){
    var form_id = document.getElementById(form);
    for (var i = 0; i < form_id.elements.length; i++) {
        if (form_id.elements[i].type != 'reset' && form_id.elements[i].type != 'submit' && form_id.elements[i].type != 'button') {
            form_id.elements[i].value = '';
        }
    }
    form_id.elements[0].focus();
}

function get_value(obj){
    switch (obj.type) {
        case 'radio':
        case 'checkbox':
            if (obj.checked == true) {
                return obj.value;
            } else {
                return '';
            }
        break;
        case 'text':
        case 'hidden':
        case 'textarea':
        case 'password':
            return obj.value;
        break;
        case 'select-one':
        case 'select-multiple':
            if (obj.selectedIndex != 0) {
                return obj.value;
            } else {
                return '';
            }
		break;
    }
}

function imprimirCalendario(src){
	if( typeof(window.parent.objAdministratorBar) == "undefined" ){
		PopUpImprimir(src);
	}else{
		window.location	=	src;
	}
}

function closeprint() {
	window.parent.closePopUp();
} 

function goprint() {
	var newWin = window.parent.open("", "", "width=10,height=10");
	newWin.document.open("text/html");
	newWin.document.write(document.getElementById("detailprint").innerHTML);
	newWin.document.close();
	newWin.print();
	newWin.close();
}
