
Event.observe(window, 'load', centrosSinJs);
    function funcionCallbackLocalidades() {
		// Comprobamos si la peticion se ha completado (estado 4)
		if( ajax.readyState == 4 ) {
			// Comprobamos si la respuesta ha sido correcta (resultado HTTP 200)
			if( ajax.status == 200 ) {
				// Escribimos el resultado en la pagina HTML mediante DHTML
				cargaLocalidades(ajax.responseText);
			}
		}
	}

	function buscarLocalidades(combo, operacion, base_internal_path) {
		// Creamos el control XMLHttpRequest segun el navegador en el que estemos
		if( window.XMLHttpRequest )
			ajax = new XMLHttpRequest(); // No Internet Explorer
		else
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer

		// Almacenamos en el control al funcion que se invocara cuando la peticion cambie de estado
		ajax.onreadystatechange = funcionCallbackLocalidades;



		// Enviamos la peticion
		ajax.open("POST", base_internal_path + "/ajax.do?operacion=" + operacion + "&idCounty=" + combo[combo.selectedIndex].value, true );
		ajax.send("" );
	}

	function cargaLocalidades(cadenaProvincias) {
		var provincias =  cadenaProvincias.split("@");

		var nombres = provincias[0].split("|");
		var ids = provincias[1].split("|");

		var comboLocalidades = document.getElementById("localidadCentro");

		comboLocalidades.options.length=ids.length+1;

		comboLocalidades.options[0]=new Option("Seleccione","-1");

		for(i=1;(i<ids.length+1);i++) {
			comboLocalidades.options[i]=new Option(nombres[i-1],ids[i-1]);
		}
	}

	function funcionCallbackNumero() {
		// Comprobamos si la peticion se ha completado (estado 4)
		if( ajax.readyState == 4 ) {
			// Comprobamos si la respuesta ha sido correcta (resultado HTTP 200)
			if( ajax.status == 200 ) {
				// Escribimos el resultado en la pagina HTML mediante DHTML
				setNumLocalidades(ajax.responseText);
			}
		}
	}

    function calculaNumAct(){
        calculaNumActividades(calcNum,base);
    }

	function calculaNumActividades(operacion, base_internal_path) {
        if (document.getElementById("nombreCentro") == null) {return;}
		var nombreActividad = document.getElementById("nombreCentro").value;
        var dia1 			= document.getElementById("dia1").value;
		var mes1 			= document.getElementById("mes1").value;
		var year1 			= document.getElementById("year1").value;

		var tipoActividadCombo 	= document.getElementById("tipoActividad");
		var tipoActividad = tipoActividadCombo[tipoActividadCombo.selectedIndex].value;
        var listaOpt = document.getElementsByTagName("input");
        var centroActividad = -1;
        for (var t = 0 ; t < listaOpt.length ; t++ ){
            if ( listaOpt[t].type == "radio" && listaOpt[t].checked == true ){
                centroActividad = listaOpt[t].value;
            }
        }
		//var centroActividad = centroActividadCombo[centroActividadCombo.selectedIndex].value;
		// Creamos el control XMLHttpRequest segun el navegador en el que estemos
		if( window.XMLHttpRequest )
			ajax = new XMLHttpRequest(); // No Internet Explorer
		else
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer

		// Almacenamos en el control al funcion que se invocara cuando la peticion cambie de estado
		ajax.onreadystatechange = funcionCallbackNumero;

		//alert("centroActividad: " + centroActividad);
		// Enviamos la peticion

        //var operacion = "2";
        //var base_internal_path = "/ba";
        ajax.open("POST", base_internal_path + "/ajax.do?operacion=" + operacion + "&nombreActividad=" + nombreActividad + "&dia1="+dia1 + "&mes1="+ mes1 + "&year1="+ year1 + "&tipoActividad="+ tipoActividad + "&centroActividad="+centroActividad, true );
		ajax.send("");

	}

	function setNumLocalidades(num) {
        if (document.getElementById("numActividadesText") != null){
            document.getElementById("numActividadesText").innerHTML = num;
        }
	}

	//<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

	function funcionCallbackConte() {
		//Comprobamos si la peticion se ha completado (estado 4)
		if( ajax.readyState == 4 ) {
			//Comprobamos si la respuesta ha sido correcta (resultado HTTP 200)
			if( ajax.status == 200 ) {
				//Escribimos el resultado en la pagina HTML mediante DHTML
				if(ajax.responseText == "ok")
					alert("Se han guardado los registros marcados");
				else
					alert("No se han podido guardar los registros marcados");
			}
		}
	}

/*	function marcaEjemplares(cookie, url) {

		if( window.XMLHttpRequest )
			ajax = new XMLHttpRequest(); // No Internet Explorer
		else
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer

		ajax.onreadystatechange = funcionCallbackConte;

		checksValue = "";
		var chkIndex = 0;
		var checkBox;*/

		/*<c:forEach items="${elementos}" var="ejemplar" varStatus="status">
			checkBox = document.getElementById("<c:out value="${ejemplar.namecheck}"/>");
			if(checkBox.checked) {
				checksValue += checkBox.id + "|";
			}
		</c:forEach>*/

/*		if(checksValue != "") {
			ajax.open("POST", BASE_INTERNAL_PATH + "/ajax.do?operacion=" + OPERACION_MARCAR_EJEMPLARES+"&checks=" + checksValue + "&cookie=" + cookie + "&url=" + url);
			ajax.send("");
		} else {
			alert("No ha seleccionad ning&uacute;n ejemplar");
		}
	}*/

/* funciones utilizadas en plantilaPortada.jsp */
    function irNumero1(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            irAEjemplar(document.getElementById('ubicar1').value);
        }
    }
    function irNumero2(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            irAEjemplar(document.getElementById('ubicar2').value);
        }
    }
    function submitonEnter(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            document.forms[1].submit();
        }
    }

    function submitonformEnter(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            document.forms["formEnter"].submit();
        }
    }

    function submitonformSolic(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            document.forms["formSolic"].submit();
        }
    }

    function onEnterAvz(evt,prefix){
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if(charCode == "13"){
            envio(prefix);
        }
    }

    function numeroResultados () {
    //alert("anulado");
    }

    function selecciona_value(objInput) {
        var valor_input = objInput.value;
        var longitud = valor_input.length;

        if (objInput.setSelectionRange) {
                objInput.focus();
                objInput.setSelectionRange (0, longitud);
        } else if (objInput.createTextRange) {
            var range = objInput.createTextRange();
            range.collapse(true);
            range.moveEnd('character', longitud);
            range.moveStart('character', 0);
            range.select();
        }
    }

/* plantilla BusqAvanzadoCatalogo.jsp */
function envio(ruta){
    var frm = document.getElementById("usuario");
    var opAutor = document.getElementById("operador-1");
    var opTitulo = document.getElementById("operador-2");

    if ( frm.autor.value != ""){
        ruta = ruta + "a:(" + frm.autor.value + ")";

        if ( frm.autor.value != "" && frm.titulo.value != ""  && frm.materia.value != "" ){
            ruta = ruta + "+" + opAutor[opAutor.selectedIndex].value + "+"  + "t:(" + frm.titulo.value + ")"+ "+" + opTitulo[opTitulo.selectedIndex].value + "+"  + "d:(" + frm.materia.value + ")";
        }else if ( frm.autor.value != ""  && frm.titulo.value != "" && frm.materia.value == ""  ){
            ruta = ruta + "+" + opAutor[opAutor.selectedIndex].value + "+"  + "t:(" + frm.titulo.value + ")";
        }else if ( frm.autor.value != "" && frm.materia.value != "" &&  frm.titulo.value == ""  ){
            ruta = ruta + "+" + opAutor[opAutor.selectedIndex].value + "+"  + "d:(" + frm.materia.value + ")";
        }
    }else if (frm.titulo.value != ""){
        ruta = ruta + "t:(" + frm.titulo.value + ")";
        if ( frm.materia.value != "" ){
            ruta = ruta + "+" + opTitulo[opTitulo.selectedIndex].value + "+" + "d:(" + frm.materia.value + ")";
        }
    }

    var bibliotecas = document.getElementById("biblioteca");
    if (bibliotecas.selectedIndex > 0){
        ruta = ruta + "%26b="+ bibliotecas[bibliotecas.selectedIndex].value;
    }

    var idioma = document.getElementById("idioma");
    if (idioma.selectedIndex > 0){
        ruta = ruta + "%26l="+ idioma[idioma.selectedIndex].value;
    }

    var tipoMaterial = document.getElementById("tipoMaterial");
    if (tipoMaterial.selectedIndex > 0){
        ruta = ruta + "%26m="+ tipoMaterial[tipoMaterial.selectedIndex].value;
    }

    var editorial = document.getElementById("editorial");
    if (editorial.value != ""  ){
        ruta = ruta + "%26p="+ editorial.value;
    }

    var anoHasta = document.getElementById("anoHasta");
    if (anoHasta.value != "" && anoHasta.value != "aaaa" && anoHasta.value != "yyyy" && anoHasta.value != "null"  ){
        ruta = ruta + "%26Da="+ anoHasta.value;
    }

    var anoDesde = document.getElementById("anoDesde");
    if (anoDesde.value != "" && anoDesde.value != "aaaa"  && anoHasta.value != "yyyy" && anoHasta.value != "null" ){
        ruta = ruta + "%26Db="+ anoDesde.value;
    }
    
    var ejemplares = document.getElementById("ejemplares");
    if (ejemplares.checked){
        document.getElementById("formBusq").disponibles.value = "1";
    }else{
        document.getElementById("formBusq").disponibles.value = "0";
    }

    buscaUrl(ruta);
    }

    function buscaUrl(url) {
        document.getElementById("formBusq").url.value = url;
        document.getElementById("formBusq").submit();
    }

    //Event.observe(window, 'load', centrosSinJs);
    function centrosSinJs(){
        //alert();
        if ($('cmb1')) {
            document.getElementById("cmb1").style.display = "block";
            document.getElementById("cmb2").style.display = "block";
            document.getElementById("txt").style.display = "none";
        }
    }

