﻿
var rutaBD=0;
var abiertas=0;
var puntosabiertos=0;


function aLineas(idLinea){
	document.getElementById("idLineaParaLineas").value=idLinea;
	document.envioALineas.submit();
}

function getElementsByClass(theClass){
    var allPageTags = new Array(); 
    var myPageTags = new Array();
    var j=0;

    var allPageTags=document.getElementsByTagName("input");
    
    for (i=0; i<allPageTags.length; i++) {
        if (allPageTags[i].className==theClass) {
            myPageTags[j]=allPageTags[i];
            j++;
        }
    }
    
    return myPageTags;
} 

function getElementsByName(theClass){

    var allPageTags = new Array(); 
    var myPageTags = new Array();
    var j=0;

    var allPageTags=document.getElementsByTagName("input");
    
    for (i=0; i<allPageTags.length; i++) {
        var tags=allPageTags[i].name.split('|');
        for (z=0; z<tags.length; z++){
          if (tags[z]==theClass) {
              myPageTags[j]=allPageTags[i];
              j++;
          }
        }

    }
    
    return myPageTags;
}


function deseleccionaTodasLineasPuntos(){
	var nombres = new Array();
	nombres[0]="checkleyendalineasT";
	nombres[1]="checkleyendalineasN";
	nombres[2]="checkleyendalineasV";
	nombres[3]="checkleyendalineas";
	nombres[4]="checkleyendapuntosT";
	nombres[5]="checkleyendapuntosN";
	nombres[6]="checkleyendapuntosV";
	nombres[7]="checkleyendapuntos";

	var elementos;
	
	for (j in nombres){
		elementos = getElementsByClass(nombres[j]);
		for (i=0; i<elementos.length; i++){
			elementos[i].checked=false;
		}
	}
}

function seleccionaParadas(linea){
	//var elementos = getElementsByName(linea);
	//elementos[1].checked=true;
	//if(elementos[2]!=null) elementos[2].checked=true;
	
	if($("_checklinea_"+linea)) $("_checklinea_"+linea).checked=true;
	if( $("_checkparada_"+linea)) $("_checkparada_"+linea).checked=true;	
}

function seleccionaLinea(linea, nombrelinea){

	if(objetusOcupado==1) return;
	//objetusOcupado=1;
	
	oEstadisticas.setEstadisticasLinea(linea);

	document.getElementById("cartel").style.visibility="visible";

	if($("_checklinea_"+linea)) $("_checklinea_"+linea).checked=true;
	if( $("_checkparada_"+linea)) $("_checkparada_"+linea).checked=true;
	
	var aleatorio = Math.random();
	var ruta= _URL_linePanelsInterpret+"?sec=getLineExtent&lineNumber="+nombrelinea+"&direction=0&incidencesFlag=1&language=es&nocache="+aleatorio;
	new Ajax.Request(ruta,
	{
	    method:'get',
	    onSuccess: function(transport){
		    var response = transport.responseText || "no response text";
		    //alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			document.getElementById("extentMinx").value=equisemeele.getElementsByTagName("lineextent").item(0).getAttribute("minx");
			document.getElementById("extentMiny").value=equisemeele.getElementsByTagName("lineextent").item(0).getAttribute("miny");
			document.getElementById("extentMaxx").value=equisemeele.getElementsByTagName("lineextent").item(0).getAttribute("maxx");
			document.getElementById("extentMaxy").value=equisemeele.getElementsByTagName("lineextent").item(0).getAttribute("maxy");
			
			// No funciona con los nuevos esquemas...
			//document.getElementById("extentMinx").value=equisemeele.getElementsByTagName("lineextent_minx").item(0).firstChild.data;
			//document.getElementById("extentMiny").value=equisemeele.getElementsByTagName("lineextent_miny").item(0).firstChild.data;
			//document.getElementById("extentMaxx").value=equisemeele.getElementsByTagName("lineextent_maxx").item(0).firstChild.data;
			//document.getElementById("extentMaxy").value=equisemeele.getElementsByTagName("lineextent_maxy").item(0).firstChild.data;
			generaOpcionesConCentro();
			
		},
	    onFailure: function(){ 
			alert(txtErrorProcesandoPeticion[idioma]);
			getRealRouteID(linea);
	        generaOpcionesConCentro();
		}
		
	});
}


function selectLineaEnTuristicas(linea){

    var turisticas = getElementsByClass("checkleyendalineasT");
    
    for (i=0; i<turisticas.length; i++){
        if (turisticas[i].name==linea){
            if (turisticas[i].checked){
                turisticas[i].checked=false;
            }   
            else{
                turisticas[i].checked=true;
            }
        }
    }
}

function selectParadaEnTuristicas(linea){

    var turisticas = getElementsByClass("checkleyendapuntosT");
    
    for (i=0; i<turisticas.length; i++){
        if (turisticas[i].name==linea){
            if (turisticas[i].checked){
                turisticas[i].checked=false;
            }   
            else{
                turisticas[i].checked=true;
            }
        }
    }
}

function selectLineaEnVerano(linea){

    var verano = getElementsByClass("checkleyendalineasV");
    
    for (i=0; i<verano.length; i++){
        if (verano[i].name==linea){
            if (verano[i].checked){
                verano[i].checked=false;
            }   
            else{
                verano[i].checked=true;
            }
        }
    }
}

function selectParadaEnVerano(linea){

    var verano = getElementsByClass("checkleyendapuntosV");
    
    for (i=0; i<verano.length; i++){
        if (verano[i].name==linea){
            if (verano[i].checked){
                verano[i].checked=false;
            }   
            else{
                verano[i].checked=true;
            }
        }
    }
}

function selectLineaEnNocturnas(linea){

    var nocturnas = getElementsByClass("checkleyendalineasN");
    
    for (i=0; i<nocturnas.length; i++){
        if (nocturnas[i].name==linea){
            if (nocturnas[i].checked){
                nocturnas[i].checked=false;
            }   
            else{
                nocturnas[i].checked=true;
            }
        }
    }
}

function selectParadaEnNocturnas(linea){

    var nocturnas = getElementsByClass("checkleyendapuntosN");
    
    for (i=0; i<nocturnas.length; i++){
        if (nocturnas[i].name==linea){
            if (nocturnas[i].checked){
                nocturnas[i].checked=false;
            }   
            else{
                nocturnas[i].checked=true;
            }
        }
    }
}

function selectLineaEnTodas(linea){

    var todas = getElementsByClass("checkleyendalineas");
    
    for (i=0; i<todas.length; i++){
        if (todas[i].name==linea){
            if (todas[i].checked){
                todas[i].checked=false;
            }   
            else{
                todas[i].checked=true;
            }
        }
    }
}

function selectParadaEnTodas(linea){

    var todas = getElementsByClass("checkleyendapuntos");
    
    for (i=0; i<todas.length; i++){
        if (todas[i].name==linea){
            if (todas[i].checked){
                todas[i].checked=false;
            }   
            else{
                todas[i].checked=true;
            }
        }
    }
}



function selectTodasLineasT(){
    var todas = getElementsByClass("checkleyendalineasT");
    checked=document.getElementById("selectTodasLineasT").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }

    otras = getElementsByClass("checkleyendalineas");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}

function selectTodasParadasT(){
    var todas = getElementsByClass("checkleyendapuntosT");
    checked=document.getElementById("selectTodasParadasT").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }

    otras = getElementsByClass("checkleyendapuntos");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}

function selectTodasLineasV(){
    var todas = getElementsByClass("checkleyendalineasV");
    checked=document.getElementById("selectTodasLineasV").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    otras = getElementsByClass("checkleyendalineas");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}

function selectTodasParadasV(){
    var todas = getElementsByClass("checkleyendapuntosV");
    checked=document.getElementById("selectTodasParadasV").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    otras = getElementsByClass("checkleyendapuntos");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}

function selectTodasLineasN(){
    var todas = getElementsByClass("checkleyendalineasN");
    checked=document.getElementById("selectTodasLineasN").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    otras = getElementsByClass("checkleyendalineas");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}


function selectTodasParadasN(){
    var todas = getElementsByClass("checkleyendapuntosN");
    checked=document.getElementById("selectTodasParadasN").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    otras = getElementsByClass("checkleyendapuntos");
    for (j=0; j<otras.length; j++){
        for (k=0; k<todas.length; k++){
            if (todas[k].name==otras[j].name){
                if (checked){
                    otras[j].checked=true;
                }
                else{
                    otras[j].checked=false;
                }
            }
        }
    }
}

function selectTodasLineasTD(){
    var todas = getElementsByClass("checkleyendalineas");
    checked=document.getElementById("selectTodasLineasTD").checked;
    
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    if (checked){
        document.getElementById("selectTodasLineasT").checked=true;
        document.getElementById("selectTodasLineasV").checked=true;
        document.getElementById("selectTodasLineasN").checked=true;
    }else{
        document.getElementById("selectTodasLineasT").checked=false;
        document.getElementById("selectTodasLineasV").checked=false;
        document.getElementById("selectTodasLineasN").checked=false;
    }
    
    
    selectTodasLineasT();
    selectTodasLineasV();
    selectTodasLineasN();

}



function selectTodasParadasTD(){
    var todas = getElementsByClass("checkleyendapuntos");
    checked=document.getElementById("selectTodasParadasTD").checked;
	
    for (i=0; i<todas.length; i++){
        if (checked){
            todas[i].checked=true;
        }
        else{
            todas[i].checked=false;
        }
    }
    
    if (checked){
        document.getElementById("selectTodasParadasT").checked=true;
        document.getElementById("selectTodasParadasV").checked=true;
        document.getElementById("selectTodasParadasN").checked=true;
    }else{
        document.getElementById("selectTodasParadasT").checked=false;
        document.getElementById("selectTodasParadasV").checked=false;
        document.getElementById("selectTodasParadasN").checked=false;
    }
    
    
    selectTodasParadasT();
    selectTodasParadasV();
    selectTodasParadasN();

}

function selectTodosPoi(){
    var todos = getElementsByClass("checkleyendaPoi");
    checked=document.getElementById("selectTodosPoi").checked;
    
    for (i=0; i<todos.length; i++){
        if (checked){
            todos[i].checked=true;
        }
        else{
            todos[i].checked=false;
        }
    }

}

function abreLineasTD(){
    if (document.getElementById("lineasTD").style.display=="inline"){
        document.getElementById("lineasTD").style.display="none";
        document.getElementById("abreLineasTDClick").innerHTML="+";
		document.getElementById("abreLineasTDClick").title= titleAbrirArbolLineas[idioma];
    }else{
        document.getElementById("lineasTD").style.display="inline";
        document.getElementById("abreLineasTDClick").innerHTML="-";
		document.getElementById("abreLineasTDClick").title=titleCerrarArbolLineas[idioma];
        document.getElementById("abreLineasNClick").innerHTML="+";
		document.getElementById("abreLineasNClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasVClick").innerHTML="+";
		document.getElementById("abreLineasVClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasTClick").innerHTML="+";
		document.getElementById("abreLineasTClick").title=titleAbrirArbolLineas[idioma];
    }
    document.getElementById("lineasT").style.display="none";
    document.getElementById("lineasV").style.display="none";
    document.getElementById("lineasN").style.display="none";
}

function abreLineasT(){
    if (document.getElementById("lineasT").style.display=="inline"){
        document.getElementById("lineasT").style.display="none";
        document.getElementById("abreLineasTClick").innerHTML="+";
		document.getElementById("abreLineasTClick").title=titleAbrirArbolLineas[idioma];
    }
    else{
        document.getElementById("lineasT").style.display="inline";
        document.getElementById("abreLineasTDClick").innerHTML="+";
		document.getElementById("abreLineasTDClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasNClick").innerHTML="+";
		document.getElementById("abreLineasNClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasVClick").innerHTML="+";
		document.getElementById("abreLineasVClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasTClick").innerHTML="-";
		document.getElementById("abreLineasTClick").title=titleCerrarArbolLineas[idioma];
    }
    document.getElementById("lineasTD").style.display="none";
    document.getElementById("lineasV").style.display="none";
    document.getElementById("lineasN").style.display="none";
}

function abreLineasV(){
    if (document.getElementById("lineasV").style.display=="inline"){
        document.getElementById("lineasV").style.display="none";
        document.getElementById("abreLineasVClick").innerHTML="+";
		document.getElementById("abreLineasVClick").title=titleAbrirArbolLineas[idioma];
    }
    else{
        document.getElementById("lineasV").style.display="inline";
        document.getElementById("abreLineasTDClick").innerHTML="+";
		document.getElementById("abreLineasTDClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasNClick").innerHTML="+";
		document.getElementById("abreLineasNClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasVClick").innerHTML="-";
		document.getElementById("abreLineasVClick").title=titleCerrarArbolLineas[idioma];
        document.getElementById("abreLineasTClick").innerHTML="+";
		document.getElementById("abreLineasTClick").title=titleAbrirArbolLineas[idioma];
    }
    document.getElementById("lineasTD").style.display="none";
    document.getElementById("lineasT").style.display="none";
    document.getElementById("lineasN").style.display="none";
}

function abreLineasN(){
    if (document.getElementById("lineasN").style.display=="inline"){
        document.getElementById("lineasN").style.display="none";
        document.getElementById("abreLineasNClick").innerHTML="+";
		document.getElementById("abreLineasNClick").title=titleAbrirArbolLineas[idioma];
    }
    else{
        document.getElementById("lineasN").style.display="inline";
        document.getElementById("abreLineasTDClick").innerHTML="+";
		document.getElementById("abreLineasTDClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasNClick").innerHTML="+";
		document.getElementById("abreLineasNClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasVClick").innerHTML="+";
		document.getElementById("abreLineasVClick").title=titleAbrirArbolLineas[idioma];
        document.getElementById("abreLineasTClick").innerHTML="+";
		document.getElementById("abreLineasTClick").title=titleCerrarArbolLineas[idioma];
    }
    document.getElementById("lineasTD").style.display="none";
    document.getElementById("lineasT").style.display="none";
    document.getElementById("lineasV").style.display="none";
}

function comprobarHoraAccesosCiudad(){
	
	var lahora = new Date()
    var dia = lahora.getDate()
    var mes = lahora.getMonth() +1
    var anyo = lahora.getFullYear()
    var hora = lahora.getHours()
    var min = lahora.getMinutes()
    if (hora < 10)
        hora = "0" + hora;
    if (min < 10)
        min = "0" + min;
    if (dia < 10)
        dia = "0" + dia;
    if (mes < 10)
        mes = "0" + mes;
		
	//SELECCIONO LOS DIA/MES/AÑO DE LAS FECHAS DEL INPUT DEL USUARIO
	var day = $("fechaOA").value.substr(0, 2);
	var Separador1 = $("fechaOA").value.substr(2, 1);
	var month = $("fechaOA").value.substr(3, 2);
	var Separador2 = $("fechaOA").value.substr(5, 1);
	var year = $("fechaOA").value.substr(6);
		
	var hour = $("horaAC").value.substr(0, 2);
	var minute = $("horaAC").value.substr(3, 2);

	 //valido el formato de la hora
	if(!validarHora($("horaAC").value)){
		$("horaAC").value= hora + ":" + min;
		$('fechaNoValidaAccesoCiudad').innerHTML= txtHoraInvalida[idioma];
		setTimeout("document.getElementById('fechaNoValidaAccesoCiudad').innerHTML='<br />';", 8000);
	}
	//valido que la fecha sea mayor a la actual si la fecha es el dia de hoy. Si es un dia futuro, da igual la hora que sea, son todas validas.
	if((anyo==year && mes==month && dia==day)){
		if((hora==hour && min>minute) || hora>hour){
			$("horaAC").value= hora + ":" + min;
			$('fechaNoValidaAccesoCiudad').innerHTML= txtHoraInvalida[idioma];
			setTimeout("document.getElementById('fechaNoValidaAccesoCiudad').innerHTML='<br />';", 8000);
		}
	}
}

function comprobarFechayHora(opcion){

    var lahora = new Date()
    var dia = lahora.getDate()
    var mes = lahora.getMonth() +1
    var anyo = lahora.getFullYear()
    var hora = lahora.getHours()
    var min = lahora.getMinutes()
    if (hora < 10)
        hora = "0" + hora;
    if (min < 10)
        min = "0" + min;
    if (dia < 10)
        dia = "0" + dia;
    if (mes < 10)
        mes = "0" + mes;
    

    if(opcion=='hora'){
	
		//SELECCIONO LOS DIA/MES/AÑO DE LAS FECHAS DEL INPUT DEL USUARIO Y DEL HIDDEN DE VIGENCIA MAXIMAS
	    var day = $("fechaOA_pyr").value.substr(0, 2);
	    var Separador1 = $("fechaOA_pyr").value.substr(2, 1);
	    var month = $("fechaOA_pyr").value.substr(3, 2);
	    var Separador2 = $("fechaOA_pyr").value.substr(5, 1);
	    var year = $("fechaOA_pyr").value.substr(6);
			
		var hour = $("horaOA_pyr").value.substr(0, 2);
		var minute = $("horaOA_pyr").value.substr(3, 2);
	
        //valido el formato de la hora
		if(!validarHora($("horaOA_pyr").value)){
            $("horaOA_pyr").value= hora + ":" + min;
            $('errorAvanzadas').innerHTML= txtHoraInvalida[idioma];
            setTimeout("document.getElementById('errorAvanzadas').innerHTML='<br />';", 8000);
        }
		
		//valido que la fecha sea mayor a la actual si la fecha es el dia de hoy. Si es un dia futuro, da igual la hora que sea, son todas validas.
		if((anyo==year && mes==month && dia==day)){
			if((hora==hour && min>minute) || hora>hour){
				$("horaOA_pyr").value= hora + ":" + min;
				$('errorAvanzadas').innerHTML= txtHoraInvalida[idioma];
				setTimeout("document.getElementById('errorAvanzadas').innerHTML='<br />';", 8000);
			}
		}
    }
	

    if(opcion=='fecha'){
	
		//SELECCIONO LOS DIA/MES/AÑO DE LAS FECHAS DEL INPUT DEL USUARIO Y DEL HIDDEN DE VIGENCIA MAXIMAS
	    var day = $("fechaOA_pyr").value.substr(0, 2);
	    var Separador1 = $("fechaOA_pyr").value.substr(2, 1);
	    var month = $("fechaOA_pyr").value.substr(3, 2);
	    var Separador2 = $("fechaOA_pyr").value.substr(5, 1);
	    var year = $("fechaOA_pyr").value.substr(6);
		
		var dayVigenciaMaxima = $('fechaVigenciaMaxima').value.substr(0, 2);
	    Separador1 = $('fechaVigenciaMaxima').value.substr(2, 1);
	    var monthVigenciaMaxima = $('fechaVigenciaMaxima').value.substr(3, 2);
	    Separador2 = $('fechaVigenciaMaxima').value.substr(5, 1);
	    var yearVigenciaMaxima = $('fechaVigenciaMaxima').value.substr(6);
	
        if(!validarCampoFecha("fechaOA_pyr")){
            $("fechaOA_pyr").value= dia + "-" + mes + "-" + anyo;
			$("horaOA_pyr").value= hora + ":" + min;
            $('errorAvanzadas').innerHTML= txtFechaInvalida[idioma];
            setTimeout("document.getElementById('errorAvanzadas').innerHTML='<br />';", 8000);
        }
		//SI LA FECHA DEL INPUT DE USUARIO ES MAYOR A LA DE VIGENCIA MAXIMA, ENTONCES SE RESTABLECE LA FECHA ACTUAL
		else if(yearVigenciaMaxima < year || (yearVigenciaMaxima==year && monthVigenciaMaxima<month) || (yearVigenciaMaxima==year && monthVigenciaMaxima==month && dayVigenciaMaxima<day)){
			$("fechaOA_pyr").value= dia + "-" + mes + "-" + anyo;
			$("horaOA_pyr").value= hora + ":" + min;
            $('errorAvanzadas').innerHTML= '<span style="background-color: #FFDC50">'+txtFechaVigenciaSobrepasada[idioma]+'</span>';
            setTimeout("document.getElementById('errorAvanzadas').innerHTML='<br />';", 8000);
		}
		//COMPROBAR QUE LA FECHA DEL INPUT NO SEA UNA FECHA PASADA
		else if(anyo>year || (anyo==year && mes>month) || (anyo==year && mes==month && dia>day)){
			$("fechaOA_pyr").value= dia + "-" + mes + "-" + anyo;
			$("horaOA_pyr").value= hora + ":" + min;
			$('errorAvanzadas').innerHTML= txtFechaInvalida[idioma];
            setTimeout("document.getElementById('errorAvanzadas').innerHTML='<br />';", 8000);
		}
	}

}

function ponerFechaHOY(campo1){
	
	var lahora = new Date()
	var dia = lahora.getDate()
	var mes = lahora.getMonth() +1
	var anyo = lahora.getFullYear()
	if (dia < 10)
		dia = "0" + dia;
	if (mes < 10)
		mes = "0" + mes;
	document.getElementById("fechaOA").value = dia+"-"+mes+"-"+anyo
	
	document.getElementById('fechaOA').style.backgroundColor= '#FFFFFF';
	//document.getElementById('fechaPasadaNoValida').innerHTML=''; //quito el boton
	document.getElementById('botonHOY').innerHTML=''; //quito el boton
	
	abiertas=0;
    getEncuadreLinea();
}

function preValidarFecha(campo){

	if(validarCampoFecha(campo)){
		guardaLineasSeleccionadas();
		
		var lahora = new Date()
		var dia = lahora.getDate()
		var mes = lahora.getMonth() +1
		var anyo = lahora.getFullYear()
		if (dia < 10)
			dia = "0" + dia;
			if(dia)
		if (mes < 10)
			mes = "0" + mes;
		
		var aux= document.getElementById("fechaOA").value
		dia_ = aux.substr(0, 2);
	    Separador1 = aux.substr(2, 1);
	    mes_ = aux.substr(3, 2);
	    Separador2 = aux.substr(5, 1);
	    anyo_ = aux.substr(6);
	    
	    if(anyo_>anyo || (anyo_==anyo && mes_>mes) || (anyo_==anyo && mes_==mes && dia_>dia)){
			//DIA FUTURO. ACTIVAR BOTON "HOY"
	    	//alert('valida--> '+anyo+'-'+anyo+' '+mes_+'-'+mes+' '+dia_+'-'+dia)
	    	document.getElementById('fechaOA').style.backgroundColor= '#CCFF00';
	    	
			if(anyo_>anyo+1){
				$('fechaOA').value=dia+'-'+mes+'-'+(anyo+1);
				$('fechaPasadaNoValida').innerHTML= txtFechaMaximaUnAnyoAPartirDeHoy[idioma];
				setTimeout("$('fechaPasadaNoValida').innerHTML= ''", 6000);
	    	}
			$('botonHOY').innerHTML='<input type="button" value="'+txtHoy[idioma]+'" class="boton" onclick="ponerFechaHOY(\''+campo+'\')" />';

			abiertas=0;
			cargaChecksLineas();
	    }else if(anyo_==anyo && mes_==mes && dia_==dia){
			//DIA ACTUAL. QUITAR BOTON "HOY"
	    	//alert('valida2--> '+anyo+'-'+anyo+' '+mes_+'-'+mes+' '+dia_+'-'+dia)
	    	document.getElementById('fechaPasadaNoValida').innerHTML='';
	    	document.getElementById('botonHOY').innerHTML='';
	    	document.getElementById('fechaOA').style.backgroundColor= '#FFFFFF';

			abiertas=0;
			cargaChecksLineas();
		}
		else{
			//FECHA PASADA. ACTIVAR BOTON "HOY"
			//alert('no valida--> '+anyo+'-'+anyo+' '+mes_+'-'+mes+' '+dia_+'-'+dia)
			document.getElementById('fechaOA').style.backgroundColor= '#FFCC00';
			document.getElementById('botonHOY').innerHTML='<input type="button" value="'+txtHoy[idioma]+'" class="boton" onclick="ponerFechaHOY(\''+campo+'\')" />';
			$('fechaPasadaNoValida').innerHTML= txtUseFechaActual[idioma];
	        setTimeout("document.getElementById('fechaPasadaNoValida').innerHTML='';", 6000);
		}
	}
	else{
			var lahora = new Date()
			var dia = lahora.getDate()
			var mes = lahora.getMonth() +1
			var anyo = lahora.getFullYear()
			if (dia < 10)
				dia = "0" + dia;
				if(dia)
			if (mes < 10)
				mes = "0" + mes;
				
			$('botonHOY').innerHTML='';
			$('fechaOA').value=dia+'-'+mes+'-'+anyo;
			$('fechaPasadaNoValida').innerHTML= txtFechaInvalida[idioma];
			setTimeout("$('fechaPasadaNoValida').innerHTML= ''", 6000);
		}
}


// comprueba la validez de una fecha.
function validarCampoFecha(campo){

    var Dia, Mes, Anyo, Dia_Mes_Mal = false;

    Dia = $(campo).value.substr(0, 2);
    Separador1 = $(campo).value.substr(2, 1);
    Mes = $(campo).value.substr(3, 2);
    Separador2 = $(campo).value.substr(5, 1);
    Anyo = $(campo).value.substr(6);
    

    if( Dia !="" && Mes !="" && Anyo !="" && (Separador1 == "-" || Separador1 == "/") && (Separador2 == "-" || Separador2 == "/")) {

       // Dia = parseInt(Dia);
       // Mes = parseInt(Mes);
       // Anyo = parseInt(Anyo);

        if( !isNaN(Dia) && !isNaN(Mes) && !isNaN(Anyo) && Dia >= 1 && Anyo >= 1900){

            /* Los meses de Enero, Marzo, Mayo, Julio, Agosto,  Octubre y Diciembre tienen 31 días */
            if((Mes==1 || Mes==3 || Mes==5 || Mes==7 || Mes==8 || Mes==10 || Mes==12) && Dia>31)
                Dia_Mes_Mal = true;

            if( Mes > 12 ) Dia_Mes_Mal = true;

            /* Los meses de Mayo, Junio, Septiembre  y Noviembre tienen 30 días */
            if((Mes==4 || Mes==6 || Mes==9 || Mes==11) && Dia>30)
                Dia_Mes_Mal = true;

            /* Febrero tiene 28 ó 29 días, dependiendo de si es bisiesto o no. Un año es bisiesto si es m&uacute;ltiplo de 4 pero no de
				100 salvo que sea m&uacute;ltiplo de 400. Por ejemplo, 12 y 400 son bisiestos, pero 100 y 700 no. */
            if( Mes == 2 && 
                ( Dia > 29 ||
                  ( Dia == 29 &&
                    ( 
                      (Anyo % 400 != 0)
                      && (
                         (Anyo % 4 != 0) || (Anyo % 100 == 0)
                         )
                    )
                  )
                )
               )  Dia_Mes_Mal = true;
    
            if(Dia_Mes_Mal)
                return false;
            else
                return true;
        }   
        /* Si la fecha está fuera del rango razonable... */
        else{
            return false;
        }
    }
    else
        return false;
}

// comprueba la validez de una fecha.
function validarFecha(campo){

    var Dia, Mes, Anyo, Dia_Mes_Mal = false;

    Dia = $(campo).value.substr(0, 2);
    Separador1 = $(campo).value.substr(2, 1);
    Mes = $(campo).value.substr(3, 2);
    Separador2 = $(campo).value.substr(5, 1);
    Anyo = $(campo).value.substr(6);
    

    if( Dia !="" && Mes !="" && Anyo !="" && (Separador1 == "-" || Separador1 == "/") && (Separador2 == "-" || Separador2 == "/")) {

        Dia = parseInt(Dia);
        Mes = parseInt(Mes);
        Anyo = parseInt(Anyo);

        if( !isNaN(Dia) && !isNaN(Mes) && !isNaN(Anyo) && Dia >= 1 && Anyo >= 1900){

            /* Los meses de Enero, Marzo, Mayo, Julio, Agosto,  Octubre y Diciembre tienen 31 días */
            
            if((Mes==1 || Mes==3 || Mes==5 || Mes==7 || Mes==8 || Mes==10 || Mes==12) && Dia>31)
                Dia_Mes_Mal = true;
              
            if( Mes > 12 ) Dia_Mes_Mal = true;
            
            /* Los meses de Mayo, Junio, Septiembre  y Noviembre tienen 30 días */
            
            if((Mes==4 || Mes==6 || Mes==9 || Mes==11) && Dia>30)
                Dia_Mes_Mal = true;
            
            /* Febrero tiene 28 ó 29 días, dependiendo de si es bisiesto o no. Un año es bisiesto si es m&uacute;ltiplo de 4 pero no de
				100 salvo que sea m&uacute;ltiplo de 400. Por ejemplo, 12 y 400 son bisiestos, pero 100 y 700 no. */
    
            if( Mes == 2 && 
                ( Dia > 29 ||
                  ( Dia == 29 &&
                    ( 
                      (Anyo % 400 != 0)
                      && (
                         (Anyo % 4 != 0) || (Anyo % 100 == 0)
                         )
                    )
                  )
                )
               )  Dia_Mes_Mal = true;
    
            if(Dia_Mes_Mal){
                return false;
            }
            else{ 
				abiertas=0;
                getEncuadreLinea();

                return true;    
            }
        }   
        /* Si la fecha está fuera del rango razonable... */
        else{
            return false;
        }
    }
    else
        return false;
}


function getEncuadreLinea(){

	var aleatorio = Math.random();
	new Ajax.Request(_URL_mapUtilsPetitions+"?sec=getEncuadreLinea&idUsuario="+$("idUsuario").value+"&nocache="+aleatorio,
	{
	    method:'get',
	    onSuccess: function(transport){
		    var response = transport.responseText || "no response text";
		    //alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			
			if ($("fromSchemesPage").value=="PARADA"){
				setCheckDeLinea(equisemeele);
			}else{
				setEncuadreLinea(equisemeele);
			}

			abreLineasEMT();
		},
	    onFailure: function(){ 
			alert(txtErrorProcesandoPeticion[idioma]);
	        
			abreLineasEMT();
		}
		
	});

}

function setCheckDeLinea(xmldata){
	if(xmldata.getElementsByTagName('encuadreLinea').length>0){
		
        try{
            var idLinea= xmldata.getElementsByTagName('idLinea').item(0).firstChild.data;
				
			$('extentMinx').value= 0;
			$('extentMiny').value= 0;
			$('extentMaxx').value= 0;
			$('extentMaxy').value= 0;
            $('lineaSeleccionada').value= idLinea;
            
        }catch(e){
			//alert("Error procesando su peticion, vuelva a intentarlo por favor.2");
            //alert(idLinea+' - '+minx+' - '+miny+' - '+maxx+' - '+maxy)
        }
    }
    else{
        $('extentMinx').value= 0;
        $('extentMiny').value= 0;
        $('extentMaxx').value= 0;
        $('extentMaxy').value= 0;
        $('lineaSeleccionada').value= 0;
    }
}

function setEncuadreLinea(xmldata){

    if(xmldata.getElementsByTagName('encuadreLinea').length>0){
		
        try{
            var idLinea= xmldata.getElementsByTagName('idLinea').item(0).firstChild.data;
				
			var minx= parseFloat(xmldata.getElementsByTagName('minx').item(0).firstChild.data);
			var miny= parseFloat(xmldata.getElementsByTagName('miny').item(0).firstChild.data);
			var maxx= parseFloat(xmldata.getElementsByTagName('maxx').item(0).firstChild.data);
			var maxy= parseFloat(xmldata.getElementsByTagName('maxy').item(0).firstChild.data);

            //alert(idLinea+' - '+minx+' - '+miny+' - '+maxx+' - '+maxy)
            
            $('extentMinx').value= minx;
            $('extentMiny').value= miny;
            $('extentMaxx').value= maxx;
            $('extentMaxy').value= maxy;
            $('lineaSeleccionada').value= idLinea;
            
        }catch(e){
			//alert("Error procesando su peticion, vuelva a intentarlo por favor.2");
            //alert(idLinea+' - '+minx+' - '+miny+' - '+maxx+' - '+maxy)
        }
    }
    else{
        $('extentMinx').value= 0;
        $('extentMiny').value= 0;
        $('extentMaxx').value= 0;
        $('extentMaxy').value= 0;
        $('lineaSeleccionada').value= 0;
    }
}

function cargaChecksLineas(){

    _URL=_URL_mapUtilsPetitions+"?sec=getlines&date="+$('fechaOA').value;

	var aleatorio=Math.random();
	new Ajax.Request(_URL+"&nocache="+aleatorio,
	{
	    method:'get',
	    onSuccess: function(transport){
		    var response = transport.responseText || "no response text";
		    //alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);
			
			lineas=equisemeele.getElementsByTagName("line");

			//iniciamos los grupos de lineas
			document.getElementById("todas").innerHTML='';
			document.getElementById("verano").innerHTML='';
			document.getElementById("nocturnas").innerHTML='';
			document.getElementById("turisticas").innerHTML='';
				
			var todasstr='';
			var veranostr='';
			var nocturnasstr='';
			var turisticasstr='';
			var flagT=0;
			var flagR=0;
			var flagN=0;
			var flagV=0;

			todasstr+='<div><div><table width="350" style="border:0px; margin: 0px; padding: 0px;"><tbody><tr style="background-color: red; color: white; margin: 0px; padding: 0px; border: 0px;" height="15"><th width="20" height="15" id="abreLineasTDClick" onclick="abreLineasTD()" style="background-color: red; color: white; margin: 0px; padding: 0px; border: 0px;" class="mano" title="'+titleAbrirArbolLineas[idioma]+'">+</th><th width="45" height="15" style="background-color: red; color: white; margin: 0px; padding: 0px; border: 0px;" ><input type="checkbox" id="selectTodasLineasTD" onclick="selectTodasLineasTD()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoTodasLineas[idioma]+'" /><input type="checkbox" id="selectTodasParadasTD" onclick="selectTodasParadasTD()" style="margin:0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoTodasParadas[idioma]+'" /></th><th style="text-align: left; background-color: red; color: white; margin: 0px; padding: 0px; border: 0px;"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+txtTodas[idioma]+'</th></tr></tbody></table></div><div id="lineasTD" style="margin: 0px; padding: 0px; border: 0px;"><table width="350"><tbody>';
			veranostr+='<div><div><table width="350" style="border:0px; margin: 0px; padding: 0px;"><tbody><tr style="background-color: orange; color: white; margin: 0px; padding: 0px; border: 0px;" height="15"><th width="20" height="15" id="abreLineasVClick" onclick="abreLineasV()" style="background-color: orange; color: white; margin: 0px; padding: 0px; border: 0px;" class="mano" title="'+titleAbrirArbolLineas[idioma]+'">+</th><th width="45" height="15" style="background-color: orange; color: white; margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" id="selectTodasLineasV" onclick="selectTodasLineasV()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoLineasVerano[idioma]+'" /><input type="checkbox" id="selectTodasParadasV" onclick="selectTodasParadasV()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoParadasVerano[idioma]+'" /></th><th style="text-align: left; background-color: orange; color: white; margin: 0px; padding: 0px; border: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+txtVerano[idioma]+'</th></tr></tbody></table></div><div id="lineasV" style="margin: 0px; padding: 0px; border: 0px;" ><table width="350"><tbody>';
			nocturnasstr+='<div><div><table width="350" style="border:0px; margin: 0px; padding: 0px;"><tbody><tr style="background-color: blue; color: white; margin: 0px; padding: 0px; border:0px;" ><th width="20" height="15" id="abreLineasNClick" onclick="abreLineasN()" style="background-color: blue; color: white; margin: 0px; padding: 0px; border: 0px;" class="mano" title="'+titleAbrirArbolLineas[idioma]+'">+</th><th width="45" height="15" style="background-color: blue; color: white; margin: 0px; padding: 0px; border: 0px;" ><input type="checkbox" id="selectTodasLineasN" onclick="selectTodasLineasN()" style="margin: 0px; border: 0px; padding: 0px;" title="'+titleActivaDesactivaTrazadoLineasNocturnas[idioma]+'" /><input type="checkbox" id="selectTodasParadasN" onclick="selectTodasParadasN()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoParadasNocturnas[idioma]+'" /></th><th height="15" style="text-align: left; background-color: blue; color: white; margin: 0px; border: 0px; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+txtNocturnas[idioma]+'</th></tr></tbody></table></div><div id="lineasN" style="margin: 0px; padding: 0px; border: 0px;"><table width="350"><tbody>';
			turisticasstr+='<div><div><table width="350" style="border:0px; margin: 0px; padding: 0px;"><tbody><tr style="background-color: green; color: white; margin: 0px; padding: 0px; border: 0px;" ><th width="20" height="15" id="abreLineasTClick" onclick="abreLineasT()" style="background-color: green; color: white; border: 0px; margin: 0px; padding: 0px;" class="mano" title="'+titleAbrirArbolLineas[idioma]+'">+</th><th width="45" height="15" style="background-color: green; color: white; margin: 0px; padding: 0px; border: 0px;" ><input type="checkbox" id="selectTodasLineasT" onclick="selectTodasLineasT()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoLineasTuristicas[idioma]+'" /><input type="checkbox" id="selectTodasParadasT" onclick="selectTodasParadasT()" style="margin: 0px; padding: 0px; border: 0px;" title="'+titleActivaDesactivaTrazadoParadasTuristicas[idioma]+'" /></th><th style="text-align: left; background-color: green; color: white; margin: 0px; padding: 0px; border: 0px;" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+txtTuristicas[idioma]+'</th></tr></tbody></table></div><div id="lineasT" style="border: 0px; margin: 0px; padding: 0px;" ><table width="350"><tbody>';
		   
			if (lineas.length>0){
				
				var lineaSeleccionada=document.getElementById("lineaSeleccionada").value;

				for (i=0; i<lineas.length; i++){
					if (lineas[i].childNodes[3].firstChild.nodeValue=='R'){
						//alert("identificador: "+lineas[i].childNodes[0].firstChild.nodeValue+" | ruta: "+lineas[i].childNodes[1].firstChild.nodeValue+" | denom: "+lineas[i].childNodes[2].firstChild.nodeValue+" | tipo: "+lineas[i].childNodes[3].firstChild.nodeValue)
						flagR++;
						todasstr+='<tr height="15" style="margin:0px; padding:0px; border: 0px;"><td heigth="15" width="25" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" border="0" /></a></td>';
						
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						
						todasstr+='</td><td style="font-size: 10px;" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'"  >'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
					}
					if (lineas[i].childNodes[3].firstChild.nodeValue=='T'){
						
						flagT++;
						turisticasstr+='<tr height="15" style="margin: 0px; padding: 0px; border: 0px;"><td heigth="15" width="25" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'"  border="0" /></a></td>';
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							turisticasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineasT" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntosT" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							turisticasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;" ><input type="checkbox" class="checkleyendalineasT" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntosT" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						turisticasstr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'" >'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
						
						todasstr+='<tr height="15"><td width="25" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'"  border="0" /></a></td>';                  
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTuristicas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTuristicas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTuristicas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTuristicas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						todasstr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px; "><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'">'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
					}
					if (lineas[i].childNodes[3].firstChild.nodeValue=='N'){
						
						flagN++;
						nocturnasstr+='<tr height="15" style="margin: 0px; padding: 0px; border: 0px;"><td height="15" width="25" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'"  border="0" /></a></td>';
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							nocturnasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px" ><input type="checkbox" class="checkleyendalineasN" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntosN" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked>';
						}else{
							nocturnasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px" ><input type="checkbox" class="checkleyendalineasN" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntosN" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						nocturnasstr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'">'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
						
						todasstr+='<tr height="15"><td width="25" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" border="0" /></a></td>';
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							todasstr+='<td width="40" height="15" style="border: 0px; padding: 0px; margin: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnNocturnas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnNocturnas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnNocturnas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnNocturnas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" >';
						}
						todasstr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px;" ><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'">'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
					}
					if (lineas[i].childNodes[3].firstChild.nodeValue=='V'){
						
						flagV++;
						veranostr+='<tr height="15" style="margin: 0px; padding: 0px; border: 0px;"><td width="25" height="15" style="margin: 0px; padding: 0px; border: 0px"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'"  border="0" /></a></td>';
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							veranostr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineasV" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntosV" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							veranostr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineasV" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntosV" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnTodas("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						veranostr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'">'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
					
						todasstr+='<tr height="15" style="margin: 0px; padding: 0px; border: 0px;"><td width="25" height="15" style="margin: 0px; padding: 0px; border: 0px;"><a href="#arribaMapa" onclick="aLineas(\''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" style="text-decoration: none; border: 0px;" ><img width="20" height="20" src="'+_URL_EmtServlet_graphics + lineas[i].childNodes[0].firstChild.nodeValue+'size20x20W.gif" alt="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" title="'+txtIrAEsquemaDeLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'"  border="0" /></a></td>';
						if (lineaSeleccionada!=0 && lineaSeleccionada==lineas[i].childNodes[0].firstChild.nodeValue){
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;"><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnVerano("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnVerano("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" checked />';
						}else{
							todasstr+='<td width="40" height="15" style="margin: 0px; padding: 0px; border: 0px;" ><input type="checkbox" class="checkleyendalineas" id="_checklinea_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectLineaEnVerano("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarLinea[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" /><input type="checkbox" class="checkleyendapuntos" id="_checkparada_'+lineas[i].childNodes[1].firstChild.nodeValue+'" name="'+lineas[i].childNodes[1].firstChild.nodeValue+'" onclick=selectParadaEnVerano("'+lineas[i].childNodes[1].firstChild.nodeValue+'") title="'+titleActivarDesactivarParadas[idioma]+' '+lineas[i].childNodes[0].firstChild.nodeValue+'" />';
						}
						todasstr+='</td><td style="font-size: 10px;" height="15" style="margin: 0px; padding: 0px; border: 0px;" ><a href="#arribaMapa" onclick="seleccionaLinea(\''+lineas[i].childNodes[1].firstChild.nodeValue+'\', \''+lineas[i].childNodes[0].firstChild.nodeValue+'\')" title="'+lineas[i].childNodes[2].firstChild.nodeValue+'">'+lineas[i].childNodes[2].firstChild.nodeValue+'</a></td></tr>' ;
					}
				}
				
				//si algun grupo no tiene lineas, se informa de ello.
				if(flagR==0) todasstr+='<tr><td>'+txtNoLineasEnEstaFecha[idioma]+'</td></tr>';
				if(flagV==0) veranostr+='<tr><td>'+txtNoLineasVeranoEnEstaFecha[idioma]+'</td></tr>';
				if(flagN==0) nocturnasstr+='<tr><td>'+txtNoLineasNocturnasEnEstaFecha[idioma]+'</td></tr>';
				if(flagT==0) turisticasstr+='<tr><td>'+txtNoLineasTuristicasEnEstaFecha[idioma]+'</td></tr>';
				
			}
			else{
				//No hay ninguna linea en la fecha elegida.
				todasstr+='<tr><td>'+txtNoLineasEnEstaFecha[idioma]+'</td></tr>';
				veranostr+='<tr><td>'+txtNoLineasVeranoEnEstaFecha[idioma]+'</td></tr>';
				nocturnasstr+='<tr><td>'+txtNoLineasNocturnasEnEstaFecha[idioma]+'</td></tr>';
				turisticasstr+='<tr><td>'+txtNoLineasTuristicasEnEstaFecha[idioma]+'</td></tr>';
			}

			//finalizamos las tablas y hacemos los innerHTML
			todasstr+='</tbody></table></div></div>';
			veranostr+='</tbody></table></div></div>';
			nocturnasstr+='</tbody></table></div></div>';
			turisticasstr+='</tbody></table></div></div>';
			
			document.getElementById("todas").innerHTML=todasstr;
			document.getElementById("verano").innerHTML=veranostr;
			document.getElementById("nocturnas").innerHTML=nocturnasstr;
			document.getElementById("turisticas").innerHTML=turisticasstr;
				
			abiertas=1;
			abreLineasTD();

			if (puntosabiertos==0){
				cargaChecksPoi();
			}   
			
			//funcion para guardar el estado de los checks de las lineas y paradas
			cargaLineasSeleccionadas();
			
			document.getElementById("abreLineasEMT").innerHTML="-";
            document.getElementById("abreLineasEMT").title=titleCerrarArbolLineas[idioma];
	    },
	    onFailure: function(){ 
			abiertas=0;
			alert(txtErrorProcesandoPeticion[idioma]);
		}
	});
}

function cargaChecksPoi(){
   
   document.getElementById("cartel").style.visibility="visible";
   
   _URL=_URL_mapUtilsPetitions+"?sec=getpoi&idioma="+$('idioma').value;
	var aleatorio = Math.random();
	
	new Ajax.Request(_URL+"&nocache="+aleatorio,
	{
	    method:'get',
	    onSuccess: function(transport){
		    var response = transport.responseText || "no response text";
		    //alert("Success! \n\n" + response);
			
			var equisemeele = getXMLObject(response);

			puntos=equisemeele.getElementsByTagName("poiitem");
			if (puntos.length>0){
				
				cuerpostr='<div><table width="350"><tbody>'
				for (i=0; i<puntos.length; i++){
					if (puntos[i].childNodes[1].firstChild.nodeValue==10) //id=10 es de los museos, que debe estar siempre activado en la carga inicial
						cuerpostr=cuerpostr+'<tr><td width="20"><input type="image" class="puntointeres" src="'+puntos[i].childNodes[2].firstChild.nodeValue+'" alt="'+puntos[i].childNodes[0].firstChild.nodeValue+'" title="'+puntos[i].childNodes[0].firstChild.nodeValue+'" /></td><td width="20"><input type="checkbox" class="checkleyendaPoi" name="'+puntos[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivar[idioma]+' '+puntos[i].childNodes[0].firstChild.nodeValue+'" checked /></td><td width="20"></td><td>'+puntos[i].childNodes[0].firstChild.nodeValue+'</td></tr>'	
					else
						cuerpostr=cuerpostr+'<tr><td width="20"><input type="image" class="puntointeres" src="'+puntos[i].childNodes[2].firstChild.nodeValue+'" alt="'+puntos[i].childNodes[0].firstChild.nodeValue+'" title="'+puntos[i].childNodes[0].firstChild.nodeValue+'" /></td><td width="20"><input type="checkbox" class="checkleyendaPoi" name="'+puntos[i].childNodes[1].firstChild.nodeValue+'" title="'+titleActivarDesactivar[idioma]+' '+puntos[i].childNodes[0].firstChild.nodeValue+'" /></td><td width="20"></td><td>'+puntos[i].childNodes[0].firstChild.nodeValue+'</td></tr>'	
				}
				cuerpostr=cuerpostr+'</tbody></table></div>'
				
				cuer=document.getElementById("cuerpoPoi");
				
				cuer.innerHTML=cuerpostr;
				
				document.getElementById("cuerpoPoi").style.display="none";
				document.getElementById("selectTodosPoi").checked=false;

				//selectTodosPoi();
			}

			document.getElementById("cartel").style.visibility="hidden";
			
			puntosabiertos=1;
            generaOpcionesConCentro();
			
		},
	    onFailure: function(){ 
	        abiertas=0;
	        alert(txtErrorProcesandoPeticion[idioma]);

	        document.getElementById("cartel").style.visibility="hidden";
		}
	});	

}

function abreLineasEMT(){

    if (abiertas==1){
        if (document.getElementById("cuerpoLineas").style.display=="inline"){
            document.getElementById("cuerpoLineas").style.display="none";
            document.getElementById("abreLineasEMT").innerHTML="+";
            document.getElementById("abreLineasEMT").title=titleAbrirArbolLineas[idioma];
        }
        else{
            document.getElementById("cuerpoLineas").style.display="inline";
            document.getElementById("abreLineasEMT").innerHTML="-";
            document.getElementById("abreLineasEMT").title=titleCerrarArbolLineas[idioma];
        }
    }
    else{
        cargaChecksLineas();
    }
}

function abrePuntosInteres(){
    if (puntosabiertos==1){
        if(document.getElementById("cuerpoPoi").style.display=="inline"){
            document.getElementById("cuerpoPoi").style.display="none";
            document.getElementById("abrePuntosInteres").innerHTML="+";
            document.getElementById("abrePuntosInteres").title= titleAbrirArbolPOI[idioma];
        }else{
            document.getElementById("cuerpoPoi").style.display="inline";
            document.getElementById("abrePuntosInteres").innerHTML="-";
            document.getElementById("abrePuntosInteres").title= titleCerrarArbolPOI[idioma];
        }
    }else{
        cargaChecksPoi()
    }
    
}

function expandeCampus(){
    var campus= document.getElementById("campus");
    if (campus.style.display=="none"){
        campus.style.display="block";
    }else{
        campus.style.display="none";
    }
}

