<!-- oculto para navegadores antiguos

var agshort; var map; var pt = false; var scs = false;
var gm = false;
var mb = false;
var resizeMap = false;
var rutaIcono = "";
var Red = new Array();
var Paradas = new Array();
var paradasCentradas = new Array();
var buscaParadasOriginal;
var gmAPI = "ABQIAAAA-VL-awqfhyD90bPvP-kAdRTlHxLgc1aiSVxQk_GIL4iMIdmw0xSgTJYnIqFPC4FBOUyRJZhoTbylXw";
var pestana;
var FoldUnfold;
var limit = 15000;
var Limites;
var Desde;
var Hasta;
var CircDesde;
var CircHasta;
var enrutando=false;
var CircPunto;
var CircPuntoAspa;
var miAspa;
var miAspaDesp;
var miInfo;
var polilineasEnrutado=new Array();
var pedestrian1,pedestrian2;
var walking1,walking2;
var nodosTransfer=new Array();
var directionsService;


function cargarMapa(proy,resizeM,rutaIco,gMapsApi) {
    agshort = proy;
    resizeMap = resizeM;
    rutaIcono = rutaIco;
    if (gMapsApi) gmAPI = gMapsApi;
            var nodoPrototype = document.createElement("script");
    nodoPrototype.src = "http://www.zurbantes.com/SJScripts/123456789015prototype.js";
    nodoPrototype.type = "text/javascript";
    document.body.appendChild(nodoPrototype);     }



function cargado(fichero) {
    if (fichero=='prototype') pt = true;
    else if (fichero=='scriptaculous') scs = true;
    else if (fichero=='modalbox') mb = true;
    else if (fichero=='APIgmaps') gm = true;                               if (pt && !scs && !gm && !mb) {
                        $('ZurbantesMap').innerHTML = "<div class='cargando'>Cargando Zurbantes..</div>";
        DefineClases();
        var nodoScriptaculous = document.createElement("script");
        nodoScriptaculous.src = "http://www.zurbantes.com/SJScripts/123456784512scriptaculousPack.js";
        nodoScriptaculous.type = "text/javascript";
        document.body.appendChild(nodoScriptaculous);
    }
        else if (pt&&scs&&!gm && !mb) {
        $('ZurbantesMap').innerHTML = "<div class='cargando'>Cargando Zurbantes...</div>";
        var nodoModalBox = document.createElement("script");
        nodoModalBox.src = "http://www.zurbantes.com/SJScripts/123456784512modalbox.js";
        nodoModalBox.type = "text/javascript";
        document.body.appendChild(nodoModalBox);
    }
        else if (pt&&scs&&mb&&!gm) {
        $('ZurbantesMap').innerHTML = "<div class='cargando'>Cargando Zurbantes....</div>";
        var nodoGMaps = document.createElement("script");
        nodoGMaps.src = "http://maps.google.com/maps/api/js?sensor=false&callback=CargarGMaps";
        nodoGMaps.type = "text/javascript";
        document.getElementsByTagName("head")[0].appendChild(nodoGMaps);     }
            else if (pt&&scs&&mb&&gm) {
        $('ZurbantesMap').innerHTML = "<div class='cargando'>Cargando Zurbantes.....</div>";
                new Ajax.JSONRequest('http://www.zurbantes.com/Ajax/AjaxMapaInteractivo',
        {
            method: 'post',
            callbackParamName: "jsoncallbak",
            parameters: {accion: "obtener_html", proyecto: agshort},             onSuccess: function(transport) {
                                                $('ZurbantesMap').innerHTML =  transport.responseJSON[0].innerHTML;
                buscaParadasOriginal = $("BuscaParada").innerHTML;

                pestana = new FoldUnfold('Mapa','MapaInteractivoIzda');

                                var parame = transport.responseJSON[1];
                var myLatlng = new google.maps.LatLng(parame.lat,parame.lon);
                var myOptions = {
                  zoom: parame.zoom,
                  center: myLatlng,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                }
                map = new google.maps.Map(document.getElementById("Mapa"), myOptions);
                directionsService = new google.maps.DirectionsService();

                                                                if (resizeMap) {
                    Event.observe(document.onresize ? document : window, 'resize', function() {ajustarTamanoMapa();});
                    ajustarTamanoMapa();                 }

                                                                new Ajax.JSONRequest('http://www.zurbantes.com/Ajax/AjaxMapaInteractivo',
                {
                    method: 'post',
                    callbackParamName: "jsoncallbak",
                    parameters: {accion: "obtener_datos", proyecto: agshort},                     onSuccess: function(transport) {

                        Red = new Red(transport.responseJSON[0],transport.responseJSON[1]);
                        Red.generarSelectorLineas();
                        generarBuscaLineas();
                        generarAutocompleterParadas();
                        Event.observe($('selectorBuscadorLineas'),'click',function(){
                            $("resultadosBuscaLinea").toggle();
                            if ($('resultadosBuscaParada')) {
                                if ($("resultadosBuscaParada").visible()) $("resultadosBuscaParada").hide();
                            }
                        });
                        Event.observe($('inputBuscaLinea'),'click',function(){
                            $("resultadosBuscaLinea").toggle();
                            if ($('resultadosBuscaParada')) {
                                if ($("resultadosBuscaParada").visible()) $("resultadosBuscaParada").hide();
                            }
                        });
                        Event.observe($('selectorBuscadorParadas'),'click',function(){alert("tienes que seleccionar primero una linea");});
                        Event.observe($('inputBuscaParada'),'click',function(){alert("tienes que seleccionar primero una linea");});
                        Event.observe($('IcoLocalizar'),'click',localizar);

                                                MyOverlay.prototype = new google.maps.OverlayView;

                        function contains(node1, node2)
                            {
                                if(node2 == node1) { return true; }
                                if(node2 == null) { return false; }
                                else { return contains(node1, node2.parentNode); }
                            }

                        MyOverlay.prototype.onAdd = function() {
                            var pane = this.getPanes().floatPane;
                            this.INNERDIV = new Element('div',{'id':'innerDivContextual'});
                            this.COPIADESDE = new Element('div',{'class':'OpcionContextual'}).update('Ruta desde aquí');
                            this.COPIAHASTA = new Element('div',{'class':'OpcionContextual'}).update('Ruta hasta aquí');
                            this.LIMPIAR = new Element('div',{'class':'OpcionContextual'}).update('Limpiar Mapa');
                            this.LIMPIAR.observe('click',function(){CapaContextual.ocultar();QuitarIndicaciones();});
                            var DIVV = Element.extend(this.div_);
                            this.INNERDIV.insert(this.COPIADESDE).insert(this.COPIAHASTA).insert(this.LIMPIAR)
                            DIVV.appendChild(this.INNERDIV);
                            pane.appendChild(DIVV);
                            DIVV.style.display = 'none';
                            if (/MSIE (4|5|6|7)/i.test(navigator.userAgent)) {
                                DIVV.onmouseout = function(e) {
                                    var target = e ? e.relatedTarget : event.toElement;
                                    if(contains(this, target))
                                    {
                                       DIVV.style.display = 'none';
                                    }
                                };
                            }
                            else {
                                DIVV.onmouseout = function(e) {
                                    var target = e ? e.relatedTarget : event.toElement;
                                    if(!contains(this, target))
                                    {
                                       DIVV.style.display = 'none';
                                    }
                                };
                            }
                        }

                        MyOverlay.prototype.onRemove = function() {
                            this.div_.parentNode.removeChild(this.div_);
                        }

                        MyOverlay.prototype.draw = function() {
                            var projection = this.getProjection();
                            var position = projection.fromLatLngToDivPixel(this.getMap().getCenter());
                            var div = this.div_;
                            div.style.left = position.x + 'px';
                            div.style.top = position.y + 'px';
                            div.style.display = 'none';
                        }
                        MyOverlay.prototype.mostrar = function(latLng) {
                            this.COPIADESDE.stopObserving('click');
                            this.COPIAHASTA.stopObserving('click');
                            this.COPIADESDE.observe('click',function(){CapaContextual.ocultar();CopiaLatLng(latLng,'desde');});
                            this.COPIAHASTA.observe('click',function(){CapaContextual.ocultar();CopiaLatLng(latLng,'hasta');});
                            var projection = this.getProjection();
                            var position = projection.fromLatLngToDivPixel(latLng);
                            $('idDivContextual').style.left = eval(position.x-3) + 'px';
                            $('idDivContextual').style.top = eval(position.y-3) + 'px';
                            this.div_.style.display = 'block';
                            
                        }
                        MyOverlay.prototype.ocultar = function(latLng) {
                            this.div_.style.display = 'none';
                        }
                        var CapaContextual = new MyOverlay({map:map});
                        google.maps.event.addListener(map,'rightclick',function(event){                            
                            CapaContextual.mostrar(event.latLng);
                        });

                        $('MapaInteractivoIzda').observe('mouseout',function(){CapaContextual.ocultar();});

                                                $('inputDesde').observe('blur',origenCompletado);
                        $('inputHasta').observe('blur',destinoCompletado);
                        $('enrutar').observe('click',ChuscoDesdeHasta);
                        $('quitarEnrutado').observe('click',QuitarIndicaciones);
                        new Draggable('indicacionesEnrutado', { scroll: window,zindex:9999 });
                        $('enrutar').hide();
                        Red.repintar();
                        $('msg').innerHTML = transport.responseJSON[2].msg;
                        $('infoUser').show();
                        $('idProcesando').hide();
                        $('Mapa').style.overflow = 'visible';
                        var PuntoOrigen = new google.maps.LatLng(Red.agency.conf.lat_defecto,Red.agency.conf.lon_defecto);
                        Limites = new google.maps.LatLngBounds(
                            getLatLngFrom(PuntoOrigen, limit/2 , 225),
                            getLatLngFrom(PuntoOrigen, limit/2 , 45)
                        );
                        miAspa = new google.maps.MarkerImage('http://www.zurbantes.com/Imagenes/Iconos/aspaCerrar.gif',
                                new google.maps.Size(12, 12),
                                new google.maps.Point(0,0),
                                new google.maps.Point(6,6));

                        miAspaDesp = new google.maps.MarkerImage('http://www.zurbantes.com/Imagenes/Iconos/aspaCerrar.gif',
                                new google.maps.Size(12, 12),
                                new google.maps.Point(0,0),
                                new google.maps.Point(-3,12));

                        miInfo = new google.maps.MarkerImage('http://www.zurbantes.com/Imagenes/Iconos/Info32.png',
                                new google.maps.Size(32, 32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(16,16));
                        miPedestrian = new google.maps.MarkerImage('http://www.zurbantes.com/Imagenes/Iconos/pedestrian.png',
                                new google.maps.Size(24,32),
                                new google.maps.Point(0,0),
                                new google.maps.Point(24,32));
                    },
                    onFailure: function() {
                        $('idProcesando').hide();
                        mensajeEnPantalla("Ha ocurrido algún error al intentar Obtener los datos de esta red. Por favor refresca la PÁGINA.");
                    },
                    onCreate: function() {
                          $('idProcesando').show();
                    },
                    onComplete: function() {
                    }
                });

            },
            onFailure: function() {
                mensajeEnPantalla("Ha ocurrido algún error al intentar cargar el api de Zurbantes");
            },
            onCreate: function() {
            },
            onComplete: function() {
            }
        });
    }

}



function CargarGMaps() {
    cargado('APIgmaps');
}



function DefineClases() {

        Red = Class.create({
        initialize: function(jsonTotal,jsonAgen) {
            this.mostrarParadas = true;
            this.lineas = new Array();
            this.agency = jsonAgen;
            jsonTotal.each(function(cadaLinea,index){
                this.lineas[index] = new Linea(cadaLinea);
            },this);         },
        generarSelectorLineas: function() {
            var titulo = new Element('div',{'id':'tituloSelector','class':'selector'}).update('Ver en el plano líneas y paradas <span> &#9660;</span>');
            titulo.observe('click',function(){cambiarSelector();});
            var bloque = new Element('div', {'id':'tablaCapas'});
            var tabla = new Element('table',{'class':'tselli'});
            var tbody = new Element('tbody');

            var elem = new Element('tr');
            var nomb = new Element('td');
            var inp = new Element('input',{'id':'checkParadas','type':'checkbox','defaultChecked':true,'checked':true});
            inp.observe('click',function(){Red.toggleVisibilidadParadas();});
            nomb.appendChild(inp);
            var nomb2 = new Element('td').update('<b>Mostrar Paradas</b>');
            elem.appendChild(nomb);
            elem.appendChild(nomb2);
            tbody.appendChild(elem);

            Red.lineas.each (function(elemento,index) {
                  var elem = new Element('tr');
                  var nomb = new Element('td').setStyle({'backgroundColor':elemento.route_color});
                  var inp = new Element('input',{'id':'check'+elemento.route_id,'type':'checkbox','defaultChecked':true,'checked':true});
                  inp.observe('click',function(){Red.lineas[index].toggleVisibilidad();});
                  nomb.appendChild(inp);
                  var nomb2 = new Element('td',{'title':'doble click para ver sólo esta línea'}).update(elemento.route_long_name).setStyle({'cursor':'pointer','color':elemento.route_color});
                  nomb2.observe('dblclick',function(){
                    $('idProcesando').show();
                    Red.lineas.each(function(lin,indicito) {
                        if (index == indicito) {
                            if ($('check'+lin.route_id).checked == false) {
                                $('check'+lin.route_id).checked = true;
                                Red.lineas[indicito].repintar();
                            }
                        } else {
                            if ($('check'+lin.route_id).checked == true) {
                                $('check'+lin.route_id).checked = false;
                                Red.lineas[indicito].ocultar();
                            }
                        }
                    });
                    $('idProcesando').hide();
                  });
                  elem.appendChild(nomb);
                  elem.appendChild(nomb2);
                  tbody.appendChild(elem);
            });

            var tere = new Element('tr');
            var tede = new Element('td',{'colspan':'2'}).update('<b><u>Mostrar toda la red</u></b>').setStyle({'cursor':'pointer'});
            tede.observe('click',function() {
                $('idProcesando').show();
                Red.lineas.each(function(lin,indicito) {
                    if ($('check'+lin.route_id).checked == false) {
                        $('check'+lin.route_id).checked = true;
                        Red.lineas[indicito].repintar();
                    }
                });
                if ($('checkParadas').checked == false) {
                    $('checkParadas').checked = true;
                    Red.toggleVisibilidadParadas();
                }
                $('idProcesando').hide();
            });
            tere.appendChild(tede);
            tbody.appendChild(tere);

            tabla.appendChild(tbody);
            bloque.appendChild(tabla);
            $("SelectorLineas").appendChild(titulo);
            $("SelectorLineas").appendChild(bloque);

            $('tablaCapas').hide();
        },
        repintar: function() {
            this.lineas.each(function(lin,indice) {
                lin.repintar();
            },this);
        },
        toggleVisibilidadParadas: function() {
            if (this.mostrarParadas) {
                this.lineas.each(function(linea,index) {
                    linea.ocultaParadas();
                });
            } else {
                this.lineas.each(function(linea,index) {
                    linea.muestraParadas();
                });
            }
            this.mostrarParadas = !this.mostrarParadas;
        },
        getParada: function(nombre) {
            var par=null;
            this.lineas.each(function(linea,index){
                linea.paradas.each(function(parada,indice) {
                    if (parada.stop_name == nombre) {par=parada;}
                });
            });
            if (par) {
                return par;
            } else {
                return false;
            }
        }
    });

    FoldUnfold = Class.create({
            initialize: function(idanchor,idfoldable) {
                this.anchor = $(idanchor);
                this.pestana = new Element('div',{'id':'idfoldunfold'}).update('<<').setStyle({paddingTop:'10px',width:'16px',paddingBottom:'10px',cursor:'pointer',color:'#EDF2F7', background:'#6284AB',position:'absolute'});
                this.foldable = $(idfoldable);
                this.anchoFoldableOriginal = this.foldable.offsetWidth;
                this.pestana.style.top = '-2px';
                this.pestana.style.left = '-'+this.pestana.style.width;
                this.pestana.observe('click',this.foldUnf.bind(this));
                this.anchor.parentNode.appendChild(this.pestana);
            },
            foldUnf: function() {
                if (this.foldable.visible()) {
                    this.foldable.style.overflow = 'hidden';
                    var fdb = this.foldable;
                    var anc = this.anchor;
                    new Effect.Morph(this.foldable,{
                        style: 'width:0px;',
                        duration: 0.5,
                        afterFinish: function() {
                            fdb.hide();
                        }
                    });
                    new Effect.Morph(anc.parentNode,{
                        style: 'margin-left:1.5em;',
                        duration: 0.5,
                        delay: 0.1
                    });
                    pestana.pestana.innerHTML='>>';
                } else {
                    var orig = this.anchoFoldableOriginal;
                    new Effect.Morph(this.anchor.parentNode,{
                        style: 'margin-left:27em;',
                        duration: 0.5
                    });
                    this.foldable.show();
                    new Effect.Morph(this.foldable,{
                        style: 'width:'+orig+'px;',
                        duration: 0.5,
                        delay: 0.1
                    });
                    pestana.pestana.innerHTML='<<';
                }
                google.maps.event.trigger(map, 'resize');
            },
            posicionaTe: function() {
                var arriba = this.anchor.offsetTop;
                var leff = this.anchor.offsetLeft;
                leff -= parseInt(this.pestana.style.width.replace('px',''));
                this.pestana.style.top = arriba + 'px';
                this.pestana.style.left = leff + 'px';
            }
    });

        Linea = Class.create({
      initialize: function(jsonRecibido) {
        this.route_id = jsonRecibido.route_id;
        this.agency_id = jsonRecibido.agency_id;
        this.route_short_name = jsonRecibido.route_short_name;
        this.route_long_name = jsonRecibido.route_long_name;
        this.route_desc = jsonRecibido.route_desc;
        this.route_type = jsonRecibido.route_type;
        this.route_url = jsonRecibido.route_url;
        this.route_color = jsonRecibido.route_color;
        this.route_text_color = jsonRecibido.route_text_color;
        this.shapes = new Array();
        this.shapes = jsonRecibido.polilineas;
        this.paradas = new Array();
        this.polilineas = new Array();
        var cont = 0;
        this.shapes.each(function(polilinea,indice) {
            if (polilinea.mostrar == 1 || polilinea.mostrar == 2) {
                this.polilineas[cont] = new Object();
                this.polilineas[cont].lati_longo = new Array();
                polilinea.puntos.each(function(tramo,index) {
                    this.polilineas[cont].lati_longo[index] = new google.maps.LatLng(tramo.shape_pt_lat,tramo.shape_pt_lon);
                },this);
                if (polilinea.mostrar == 1) {
                    this.polilineas[cont].mostrar = 1;
                    this.polilineas[cont].polilinea = new google.maps.Polyline({
                        path: this.polilineas[cont].lati_longo,
                        strokeColor: this.route_color,
                        strokeOpacity: 1,
                        strokeWeight: 5
                    });
                } else {
                    this.polilineas[con].mostrar = 2;
                    this.polilineas[cont].polilinea = new google.maps.Polyline({
                        path: this.polilineas[cont].lati_longo,
                        strokeColor: this.route_color,
                        strokeOpacity: 0.4,
                        strokeWeight: 5
                    });
                }
                cont++;
            }
        },this);

                        this.isVisible = false;

        jsonRecibido.paradas.each(function(par,indice) {
            this.paradas[indice] = new Parada(par);
        },this);

      },
      dameURL: function() {
        var url = "http://www.zurbantes.com/" + agshort  + "/Lineas/" + this.route_short_name;
        return url;
      },
        repintar: function() {
            this.polilineas.each (function (poli,indice) {
                poli.polilinea.setMap(map);
            });
            this.isVisible = true;

                        this.polilineas.each (function (poli,indice) {
                var infoW = '<div>hola</div>';
                google.maps.event.addListener(poli.polilinea,'click',function(event){
                    var infowindow = new google.maps.InfoWindow({
                        content:infoW
                    });
                    infowindow.setPosition(event.latLng);
                    infowindow.open(map);
                });
             },this);
            if(Red.mostrarParadas) {
                this.paradas.each(function(parad,indic) {
                    parad.repintar();
                },this);
            }
        },
        ocultar: function() {
            this.polilineas.each (function (poli,indice) {
                poli.polilinea.setMap(null);
             },this);
            this.isVisible = false;
            this.paradas.each(function(parad,indic) {
                parad.ocultar();
            },this);
        },
        toggleVisibilidad: function() {
            if (this.isVisible)
                this.ocultar();
            else
                this.repintar();
        },
        ocultaParadas: function() {
            if(this.isVisible) {
                this.paradas.each(function(para,indice){
                    para.ocultar();
                });
            }
        },
        muestraParadas: function() {
            if(this.isVisible) {
                this.paradas.each(function(para,indice){
                    para.repintar();
                });
            }
        }

    });

    Parada = Class.create({
        initialize: function(jsonparada) {
            this.stop_id = jsonparada.stop_id;
            this.stop_code = jsonparada.stop_code;
            this.stop_name = jsonparada.stop_name;
            this.stop_desc = jsonparada.stop_desc;
            this.stop_lat = jsonparada.stop_lat;
            this.stop_lon = jsonparada.stop_lon;
            this.zone_id = jsonparada.zone_id;
            this.stop_url = jsonparada.stop_url;
            this.location_type = jsonparada.location_type;
            this.parent_station = jsonparada.parent_station;
            this.marcadorParada = new google.maps.Marker({
                position: new google.maps.LatLng(this.stop_lat, this.stop_lon),
                icon: rutaIcono,
                title: this.stop_name
            });
            this.isVisible = false;
        },
        repintar: function() {
            this.marcadorParada.setMap(map);
            this.isVisible = true;
            var parId = this.stop_id;
            // Le asocio la parada el vento click para que muestre la información de infoWindow

            var mark = this.marcadorParada;
            var latilongi = new google.maps.LatLng(this.stop_lat,this.stop_lon);
            google.maps.event.addListener(this.marcadorParada,'click',function(event){
                new Ajax.JSONRequest('http://www.zurbantes.com/Ajax/AjaxMapaInteractivo',
                {
                    method: 'post',
                    callbackParamName: "jsoncallbak",
                    parameters: {accion: "get_infoparada", proyecto: agshort, stop_id:parId },
                    onSuccess: function(transport) {
                        $('idProcesando').hide();
                        $('infoUser').innerHTML = transport.responseJSON[1].msg;
                        var infowindow = new google.maps.InfoWindow({
                            content:transport.responseJSON[0].infoWParada
                        });

                        google.maps.event.addListener(infowindow, 'domready',function() {

                            var geocoder = new google.maps.Geocoder();
                            geocoder.geocode(
                                    {'latLng':latilongi},
                                    function(resultadosGeo,status) {
                                        if (status == google.maps.GeocoderStatus.OK) {
                                            if (resultadosGeo.length == 1) {
                                                $('DirPar').innerHTML = '<b>Dirección:</b> <i>' + resultadosGeo[0].formatted_address + '</i>';
                                            } else {
                                                $('infoUser').innerHTML = 'La dirección mostrada es aproximada';
                                                $('DirPar').innerHTML = '<b>Dirección:</b> <i>' + resultadosGeo[0].formatted_address + '</i>';
                                            }
                                        } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                                            $('infoUser').innerHTML = 'No hemos podido obtener la dirección';
                                        } else {
                                            $('infoUser').innerHTML = 'Ha ocurrido algún error al intentar obtener la dirección: ' + status;
                                        }
                                    });
                                });
                             infowindow.open(map,mark);
                    },
                    onFailure: function() {
                        $('idProcesando').hide();
                        mensajeEnPantalla("Ha ocurrido algún error al intentar Obtener los datos de esta red. Por favor refresca la PÁGINA.");
                    },
                    onCreate: function() {
                          $('idProcesando').show();
                    },
                    onComplete: function() {
                    }
                });
            }); 
        },
        ocultar: function() {
            this.marcadorParada.setMap(null);
            this.isVisible = false;
        },
        centrarEnMapa: function(radio) {
            var paradaCentrada = new Array();
            var ll = new google.maps.LatLng(this.stop_lat, this.stop_lon);
            map.setZoom(16);
            map.panTo(ll);
            paradaCentrada[0] = new google.maps.Marker({
                position: ll,
                map: map,
                title: this.stop_name
            });
            paradaCentrada[0].setIcon(miInfo);
            paradaCentrada[0].setZIndex(9998);
            var infoW = this.ParadaInfoW;
            google.maps.event.addListener(paradaCentrada[0],'click',function(event){
                var infowindow = new google.maps.InfoWindow({
                    content:infoW
                });
                infowindow.open(map,paradaCentrada[0]);
            });
            paradaCentrada[1] = generarCirculo(radio,ll);
            paradaCentrada[1].setMap(map);
            paradaCentrada[2] = new google.maps.Marker({
                position: ll,
                map: map,
                title: 'ocultar'
            });
            paradaCentrada[2].setIcon(miAspaDesp);
            paradaCentrada[2].setZIndex(9999);
            google.maps.event.addListener(paradaCentrada[2],'click',function(event){
                paradaCentrada[0].setMap(null);
                paradaCentrada[1].setMap(null);
                paradaCentrada[2].setMap(null);
                var indexEl=-1;
                paradasCentradas.each(function(parad,index){
                    if (paradaCentrada[0].getPosition().lat() == parad[0].getPosition().lat() &&
                        paradaCentrada[0].getPosition().lng() == parad[0].getPosition().lng()) {
                            indexEl = index;
                            throw $break;
                        }
                });
                if (indexEl>=0) {
                    paradasCentradas.splice(indexEl,1);
                }
            });
            paradasCentradas[paradasCentradas.length] = paradaCentrada;

            if (paradasCentradas.length > 1) {
                var maxLat,minLat,maxLon,minLon;
                paradasCentradas.each(function(para,index) {
                    if (!maxLat && !minLat && !maxLon && !minLon) {
                        maxLat = para[0].getPosition().lat();
                        minLat = maxLat;
                        maxLon = para[0].getPosition().lng();
                        minLon = maxLon;
                    } else {
                        maxLat = para[0].getPosition().lat() > maxLat? para[0].getPosition().lat() : maxLat;
                        minLat = para[0].getPosition().lat() < minLat? para[0].getPosition().lat() : minLat;
                        maxLon = para[0].getPosition().lng() > maxLon? para[0].getPosition().lng() : maxLon;
                        minLon = para[0].getPosition().lng() < minLon? para[0].getPosition().lng() : minLon;
                    }
                });
                var ampliado = new google.maps.LatLngBounds(
                    new google.maps.LatLng(minLat,minLon),
                    new google.maps.LatLng(maxLat,maxLon)
                );
                map.fitBounds(ampliado);
            }
        }
    });


}

function generarCirculo(radio,puntoCentral) {
    var radius = radio * 0.62;
    var d2r = Math.PI / 180;
    var circleLatLngs = new Array();
    var circleLat = radius * 0.014483;  // Convert statute miles into degrees latitude
    var circleLng = circleLat / Math.cos(puntoCentral.lat() * d2r);
    var numPoints = 40;


    // 2PI = 360 degrees, +1 so that the end points meet
    for (var i = 0; i < numPoints + 1; i++) {
        var theta = Math.PI * (i / (numPoints / 2));
        var vertexLat = puntoCentral.lat() + (circleLat * Math.sin(theta));
        var vertexLng = puntoCentral.lng() + (circleLng * Math.cos(theta));
        var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
        circleLatLngs.push(vertextLatLng);
    }

    var circulito = new google.maps.Polygon({
        paths: circleLatLngs,
        strokeColor: '#336699',
        strokeOpacity: 1,
        strokeWeight: 1,
        fillColor: '#336699',
        fillOpacity: 0.25
    });

    return circulito
}



function ajustarTamanoMapa() {
    $('MapaInter').style.height = eval(document.viewport.getDimensions().height - 100) + "px";
    $('Mapa').style.height = eval(document.viewport.getDimensions().height - 100) + "px";
    google.maps.event.trigger(map, 'resize');
}



function cambiarSelector() {

    $('tablaCapas').toggle();
    if ($('tablaCapas').visible()) {
        $('tituloSelector').addClassName('TituloSelected');
    }
    else {
        $('tituloSelector').removeClassName('TituloSelected');
    }
}




function generarBuscaLineas() {
    var div = new Element('div',{'id':'resultadosBuscaLinea','class':'resultados'}).setStyle({'z-index':'999999'});
    Red.lineas.each(function(lin,index) {
        var divv = new Element('div',{'class':'ItemResultado'}).update(lin.route_long_name);
        divv.observe('mouseover',function(){this.className='ItemResultadoSeleccionado'});
        divv.observe('mouseout',function(){this.className='ItemResultado'});
        divv.observe('click',function(){lineaSeleccionada(index);});
        div.appendChild(divv);
    });
    $("BuscaLinea").appendChild(div);
    $("resultadosBuscaLinea").hide();
    zIndexTrucoIE($("resultadosBuscaLinea"));
}

function zIndexTrucoIE(elemento)
{
    if(navigator.userAgent.match(/MSIE \d\.\d+/))
    {
        elemento.setStyle({'top':'2.3em'});
        elemento.ancestors().each(function (a) {
            var pos = a.getStyle("position");
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
                a.addClassName("on-top");
            }
        });
    }
}

function lineaSeleccionada(indexLinea) {
    $('inputBuscaLinea').value = Red.lineas[indexLinea].route_long_name;
    $("resultadosBuscaLinea").toggle();

    generarBuscaParadas(indexLinea);
}

function generarBuscaParadas(indexLinea) {
    var listaParadas = new Array();
    Red.lineas[indexLinea].paradas.each(function(par,index) {
        listaParadas[index] = par.stop_name;
    });
    listaParadas.sort();

    if($('resultadosBuscaParada')) $('BuscaParada').removeChild($('resultadosBuscaParada'));

    var div = new Element('div',{'id':'resultadosBuscaParada','class':'resultados'}).setStyle({'z-index':'999999'});

    listaParadas.each(function(par,index) {
        var divv = new Element('div',{'class':'ItemResultado'}).update(par);
        divv.observe('mouseover',function(){this.className='ItemResultadoSeleccionado'});
        divv.observe('mouseout',function(){this.className='ItemResultado'});
        divv.observe('click',function(){paradaSeleccionada(par);});
        div.appendChild(divv);
    });
    $("BuscaParada").appendChild(div);
    zIndexTrucoIE($("resultadosBuscaParada"));
    Event.stopObserving($('selectorBuscadorParadas'),'click');
    Event.stopObserving($('inputBuscaParada'),'click');
    Event.observe($('selectorBuscadorParadas'),'click',function(){$("resultadosBuscaParada").toggle();});
    Event.observe($('inputBuscaParada'),'click',function(){$("resultadosBuscaParada").toggle();});
}

function paradaSeleccionada(stop_name) {
    $('inputBuscaParada').value = stop_name;
    $('resultadosBuscaParada').hide();
    Red.getParada(stop_name).centrarEnMapa(0.3);
}



function generarAutocompleterParadas() {
    Paradas.clear();
    var j=0;
    Red.lineas.each(function(linea,indice) {
        linea.paradas.each(function(parada,index) {
            Paradas[j++]=parada.stop_name;
        });
    });
    Paradas.sort();
    Paradas = Paradas.uniq(true);
    new Autocompleter.Local(
        'idParadaBuscada',
        'resultadosAutoComplete',
        Paradas,
        {fullSearch:true,afterUpdateElement:function(){Red.getParada($('idParadaBuscada').value).centrarEnMapa(0.3);}}
    );
}







function abrefichaParada() {
    var destino = "http://www.zurbantes.com/"+agshort+"/Paradas/"+$('idParadaBuscada').value;
    window.location.href=destino;
}








function valorSeleccionado(text,li) {
    centraEnParada(text);
}




function poblarLineasJSON(listado) {
        Lineas.clear();
    var numlineas = 0;

        var sololineas = listado;

            sololineas.each(function(item, indice) {
        var linea = new Linea();
        linea.shape_id = item.shape_id;
        linea.route_id = item.route_id;
        linea.agency_id = item.agency_id;
        linea.route_short_name = item.route_short_name;
        linea.route_long_name = item.route_long_name;
        linea.route_desc = item.route_desc;
        linea.route_type = item.route_type;
        linea.route_url = item.route_url;
        linea.route_color = item.route_color;
        linea.route_text_color = item.route_text_color;

        Lineas[numlineas++] = linea;

    });
}

function mensajeEnPantalla(msg) {
    alert(msg);
}

function localizar() {
    var isGeocod = true;
    var direccion = $('idParadaBuscada').value;
        Red.lineas.each(function(lin,indice) {
        lin.paradas.each(function(para,index) {
            if (para.stop_name.toUpperCase() == direccion.toUpperCase()) {
                para.centrarEnMapa(0.3);
                isGeocod = false;
            }
        });
    });
    
        if (isGeocod) CentrarEn(direccion);

}


function CentrarEn(direcc) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode(
            {'address':direcc,
             'bounds':Limites},
            function(resultadosGeo,status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (resultadosGeo.length == 1) {
                        $('idParadaBuscada').value = resultadosGeo[0].formatted_address;
                        map.setCenter(resultadosGeo[0].geometry.location);
                        if(CircPunto) CircPunto.setMap(null);
                        CircPunto = generarCirculo(0.2,resultadosGeo[0].geometry.location);
                        CircPunto.setMap(map);
                        if (CircPuntoAspa) CircPuntoAspa.setMap(null);
                        CircPuntoAspa = new google.maps.Marker({
                            position: resultadosGeo[0].geometry.location,
                            map: map,
                            title: 'ocultar'
                        });
                        CircPuntoAspa.setIcon(miAspa);
                        CircPuntoAspa.setZIndex(999);
                        google.maps.event.addListener(CircPuntoAspa,'click',function(event){
                            CircPuntoAspa.setMap(null);
                            CircPunto.setMap(null);
                        });
                    } else {
                        var elegido = desambiguar($('idParadaBuscada'),resultadosGeo);
                    }
                } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                    alert('No hemos encontrado la dirección');
                } else {
                    alert('No se puede realizar la petición por el siguiente motivo: ' + status);
                }
            });
}

function desambiguar(origen, arrRes) {
    Modalbox.show('<div id=\'desambiguar\'></div>',{title: 'Por favor, selecciona una de las siguientes direcciones:',
        slideDownDuration:0.1,
        slideUpDuration:0.1,
        overlayDuration:0.1,
        width: 600,
        overlayClose:true,
        overlayOpacity:0.01,
        afterLoad:function(){
            var ul = new Element('ul',{'id':'ulDesambig'});
            arrRes.each(function (resul,index) {
                var li = new Element('li',{'class':'liDesambig'}).update(resul.formatted_address).setStyle({'cursor':'pointer'});
                ul.appendChild(li);
                li.observe('click',function(){
                    Modalbox.hide({afterHide:function(){desambiguado(origen,arrRes[index])}});
                });
            });
            $('desambiguar').appendChild(ul);
            Modalbox.resizeToContent();
        },
        afterHide:function(){
            if (origen.getAttribute('id')=='inputDesde') {
                Desde = null;
            } else if (origen.getAttribute('id')=='inputHasta') {
                Hasta = null;
            }
        }
    });
}

function desambiguado(origen, resultado) {
    origen.value = resultado.formatted_address;
    if (origen.getAttribute('id')=='inputDesde') {
        Desde = resultado;
        $('enrutar').show();
        if (Desde && Hasta) ChuscoDesdeHasta();
    } else if (origen.getAttribute('id')=='inputHasta') {
        Hasta = resultado;
        $('enrutar').show();
        if (Desde && Hasta) ChuscoDesdeHasta();
    } else if (origen.getAttribute('id')=='idParadaBuscada') {
        CentrarEn(resultado.formatted_address);
    }
}

Number.prototype.toRad = function() {  // convierte grados en radianes
  return this * Math.PI / 180;
}

Number.prototype.toDeg = function() {  // convert radians to degrees (signed)
  return this * 180 / Math.PI;
}

function distanciaEntre(origen,destino) {
  var lat1 = origen.lat();
  var lon1 = origen.lon();
  var lat2 = destino.lat();
  var lon2 = destino.lon();
  var R = 6371; // radio medio de la tierra en km
  var dLat = (lat2-lat1).toRad();
  var dLon = (lon2-lon1).toRad();
  lat1 = lat1.toRad();
  lat2 = lat2.toRad();

  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
          Math.cos(lat1) * Math.cos(lat2) *
          Math.sin(dLon/2) * Math.sin(dLon/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c * 1000;
  return d;
}

function getLatLngFrom(origen, d, brng) {
  d = d/1000;
  var R = 6371; // radio medio de la tierra en km
  var lat1 = origen.lat().toRad();
  var lon1 = origen.lng().toRad();
  brng = brng.toRad();

  var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
  var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
  lon2 = (lon2+Math.PI)%(2*Math.PI) - Math.PI;  // se normaliza a -180...+180

  if (isNaN(lat2) || isNaN(lon2)) return null;
  var resultado = new google.maps.LatLng(lat2.toDeg(),lon2.toDeg());
  return resultado;
}



function origenCompletado() {
    if ($('inputDesde').value == 'Origen (nombre, dirección o punto de interés)') {
        Desde = null;
        if (!Hasta) $('enrutar').hide();
        enrutando = false;
    } else if ($('inputDesde').value == '') {
        $('inputDesde').value = 'Origen (nombre, dirección o punto de interés)';
        Desde = null;
        if (!Hasta) $('enrutar').hide();
        enrutando = false;
    } else {
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode(
                {'address':$('inputDesde').value,
                 'bounds':Limites},
                function(resultadosGeo,status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (resultadosGeo.length == 1) {
                            Desde = resultadosGeo[0];
                            $('inputDesde').value = resultadosGeo[0].formatted_address;
                            if (enrutando) ChuscoDesdeHasta();
                        } else {
                            var elegido = desambiguar($('inputDesde'),resultadosGeo);
                        }
                    } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                        Desde = null;
                        alert('No hemos encontrado la dirección');
                    } else {
                        Desde = null;
                        alert('No se puede realizar la petición por el siguiente motivo: ' + status);
                    }
                    if(Desde) $('enrutar').show();
                    else {
                       if (!Hasta) $('enrutar').hide();
                    }
                });
    }
}

function destinoCompletado() {
    if ($('inputHasta').value == 'Destino (nombre, dirección o punto de interés)') {
        Hasta = null;
        if (!Desde) $('enrutar').hide();
        enrutando = false;
    } else if ($('inputHasta').value == '') {
        $('inputHasta').value = 'Destino (nombre, dirección o punto de interés)';
        Hasta = null;
        if (!Desde) $('enrutar').hide();
        enrutando = false;
    } else {
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode(
                {'address':$('inputHasta').value,
                 'bounds':Limites},
                function(resultadosGeo,status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (resultadosGeo.length == 1) {
                            Hasta = resultadosGeo[0];
                            $('inputHasta').value = resultadosGeo[0].formatted_address;
                            if (enrutando) ChuscoDesdeHasta();
                        } else {
                            var elegido = desambiguar($('inputHasta'),resultadosGeo);
                        }
                    } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                        Hasta = null;
                        alert('No hemos encontrado la dirección');
                    } else {
                        Hasta = null;
                        alert('No se puede realizar la petición por el siguiente motivo: ' + status);
                    }
                    if(Hasta) $('enrutar').show();
                    else {
                        if (!Desde) $('enrutar').hide();
                    }
                });
    }
}

function ChuscoDesdeHasta() {
    QuitarIndicaciones();
    enrutando = true;
    if (Desde && Hasta) {

        if ((Desde.formatted_address == $('inputDesde').value) && (Hasta.formatted_address == $('inputHasta').value)) {

            enrutando = false;
            $('complicado').show();
            $('idProcesando').show();
            if (CircDesde) CircDesde.setMap(null);
            if (CircHasta) CircHasta.setMap(null);

            CircDesde = generarCirculo(0.2,Desde.geometry.location);
            CircDesde.setMap(map);
            CircHasta = generarCirculo(0.2,Hasta.geometry.location);
            CircHasta.setMap(map);

            var SWCornerLat = Desde.geometry.location.lat() < Hasta.geometry.location.lat()? Desde.geometry.location.lat() : Hasta.geometry.location.lat();
            var SWCornerLon = Desde.geometry.location.lng() < Hasta.geometry.location.lng()? Desde.geometry.location.lng() : Hasta.geometry.location.lng();
            var NECornerLat = Desde.geometry.location.lat() > Hasta.geometry.location.lat()? Desde.geometry.location.lat() : Hasta.geometry.location.lat();
            var NECornerLon = Desde.geometry.location.lng() > Hasta.geometry.location.lng()? Desde.geometry.location.lng() : Hasta.geometry.location.lng();

            var SWCorner = new google.maps.LatLng(SWCornerLat,SWCornerLon);
            var NECorner = new google.maps.LatLng(NECornerLat,NECornerLon);

            var esquinas = new google.maps.LatLngBounds(
                SWCorner,
                NECorner
            );

            $('complicado').hide();
            $('idProcesando').hide();
            $('quitarEnrutado').show();

            var OrigenDestino=new Array();
            Desde.lat = Desde.geometry.location.lat();
            Desde.lon = Desde.geometry.location.lng();
            Hasta.lat = Hasta.geometry.location.lat();
            Hasta.lon = Hasta.geometry.location.lng();
            OrigenDestino[0] = Desde;
            OrigenDestino[1] = Hasta;

            new Ajax.JSONRequest('http://www.zurbantes.com/Ajax/AjaxMapaInteractivo',
            {
                method: 'post',
                callbackParamName: "jsoncallbak",
                parameters: {accion: "enrutar", proyecto: agshort, json:OrigenDestino.toJSON() },
                onSuccess: function(transport) {
                    $('idProcesando').hide();
                    $('infoUser').innerHTML = transport.responseJSON[1].msg;
                    Red.lineas.each(function(linea,index) {
                        linea.polilineas.each(function(poli,indice) {
                            poli.polilinea.setOptions({strokeOpacity: 0.2});
                        });
                    });
                    polilineasEnrutado = transport.responseJSON[0].polilineas;
                    polilineasEnrutado.each(function(polilinea,index) {
                        var colorPoli='000000';
                        for (var j=0;j<Red.lineas.length;j++) {
                            if (Red.lineas[j].route_id == polilinea.route_id) {
                                colorPoli = Red.lineas[j].route_color;
                            }
                        }
                        polilinea.lati_longo = new Array();
                        polilinea.puntos.each(function(tramo,index) {
                            polilinea.lati_longo[index] = new google.maps.LatLng(tramo.shape_pt_lat,tramo.shape_pt_lon);
                        });
                        polilinea.polilinea = new google.maps.Polyline({
                            path: polilinea.lati_longo,
                            strokeColor: colorPoli,
                            strokeOpacity: 1,
                            strokeWeight: 5
                        });
                        polilinea.polilinea.setMap(map);
                    });
                    nodosTransfer.clear();
                    nodosTransfer = transport.responseJSON[0].nodosTransfer;
                    for (var index=0; index<nodosTransfer.length; index++) {
                        nodosTransfer[index].marcador = new google.maps.Marker({
                            position: new google.maps.LatLng(nodosTransfer[index].parada.stop_lat, nodosTransfer[index].parada.stop_lon),
                            icon: 'http://www.zurbantes.com/Imagenes/Iconos/Transfer.png',
                            map: map,
                            title: nodosTransfer[index].parada.stop_name
                        });
                    }
                    map.fitBounds(esquinas);
                    $('cindicacionesEnrutado').innerHTML = transport.responseJSON[0].indicaciones;

                    var peticionOrigen = {
                        origin: Desde.geometry.location,
                        destination: new google.maps.LatLng(nodosTransfer[0].parada.stop_lat,nodosTransfer[0].parada.stop_lon),
                        travelMode: google.maps.DirectionsTravelMode.WALKING,
                        unitSystem: google.maps.DirectionsUnitSystem.METRIC,
                        provideTripAlternatives: false
                    };

                    directionsService.route(peticionOrigen,function(result,status) {
                        if (status == google.maps.DirectionsStatus.OK) {
                            var latilongi = new Array();
                            for (var i=0;i<result.trips[0].routes.length;i++) {
                                for (var j=0;j<result.trips[0].routes[i].steps.length;j++) {
                                    var estep = result.trips[0].routes[i].steps[j];
                                    if (latilongi.length==0) {
                                        pedestrian1 = new google.maps.Marker({
                                            position:estep.start_point,
                                            icon: miPedestrian,
                                            map: map,
                                            title: 'salida'
                                        });
                                    }
                                    latilongi[latilongi.length] = estep.start_point;
                                    latilongi[latilongi.length] = estep.end_point;
                                }
                            }
                            walking1 = new google.maps.Polyline({
                                path: latilongi,
                                strokeColor: '#000000',
                                strokeOpacity: 1,
                                map: map,
                                strokeWeight: 2
                            });
                        }
                    });

                    var peticionDestino = {
                        origin: new google.maps.LatLng(nodosTransfer[nodosTransfer.length-1].parada.stop_lat,nodosTransfer[nodosTransfer.length-1].parada.stop_lon),
                        destination: Hasta.geometry.location,
                        travelMode: google.maps.DirectionsTravelMode.WALKING,
                        unitSystem: google.maps.DirectionsUnitSystem.METRIC,
                        provideTripAlternatives: false
                    };

                    directionsService.route(peticionDestino,function(result,status) {
                        if (status == google.maps.DirectionsStatus.OK) {
                            var latilongi = new Array();
                            var estep;
                            for (var i=0;i<result.trips[0].routes.length;i++) {
                                for (var j=0;j<result.trips[0].routes[i].steps.length;j++) {
                                    estep = result.trips[0].routes[i].steps[j];
                                    latilongi[latilongi.length] = estep.start_point;
                                    latilongi[latilongi.length] = estep.end_point;
                                }
                            }
                            walking2 = new google.maps.Polyline({
                                path: latilongi,
                                strokeColor: '#000000',
                                strokeOpacity: 1,
                                map: map,
                                strokeWeight: 2
                            });
                            pedestrian2 = new google.maps.Marker({
                                position:estep.end_point,
                                icon: miPedestrian,
                                map: map,
                                title: 'llegada'
                            });
                        }
                    });

                    $('indicacionesEnrutado').show();
                },
                onFailure: function() {
                    $('idProcesando').hide();
                    mensajeEnPantalla("Ha ocurrido algún error al intentar Obtener la ruta óptima.");
                },
                onCreate: function() {
                      $('idProcesando').show();
                },
                onComplete: function() {
                }
            });
       }
    }

}

function QuitarIndicaciones() {
    if (CircDesde) CircDesde.setMap(null);
    if (CircHasta) CircHasta.setMap(null);
    Red.lineas.each(function(linea,index) {
        linea.polilineas.each(function(poli,indice) {
            if (poli.mostrar==1) {
                poli.polilinea.setOptions({strokeOpacity: 1});
            }
            else {
                poli.polilinea.setOptions({strokeOpacity: 0.4});
            }
        });
    });
    for (var i=0;i<polilineasEnrutado.length;i++) {
        polilineasEnrutado[i].polilinea.setMap(null);
    }
    for (var j=0;j<nodosTransfer.length;j++) {
        nodosTransfer[j].marcador.setMap(null);
    }
    if (pedestrian1) pedestrian1.setMap(null);
    if (pedestrian2) pedestrian2.setMap(null);
    if (walking1) walking1.setMap(null);
    if (walking2) walking2.setMap(null);
    $('indicacionesEnrutado').hide();
    $('quitarEnrutado').hide();
}


function MyOverlay(options) {
    this.setValues(options);
    var div = this.div_= document.createElement('div');
    div.id = "idDivContextual";
    div.className = "div_contextual";
}

function CopiaLatLng(latilongi,tipo) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode(
            {'latLng':latilongi},
            function(resultadosGeo,status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (resultadosGeo.length >= 1) {
                        if (tipo.toUpperCase()=='DESDE') {
                            Desde = resultadosGeo[0];
                            $('inputDesde').value = resultadosGeo[0].formatted_address;
                        }
                        else if (tipo.toUpperCase()=='HASTA') {
                            Hasta = resultadosGeo[0];
                            $('inputHasta').value = resultadosGeo[0].formatted_address;
                        }
                    }
                } else if(status == google.maps.GeocoderStatus.ZERO_RESULTS) {
                    alert('No hemos encontrado la dirección');
                } else {
                    alert('No se puede realizar la petición por el siguiente motivo: ' + status);
                }
                if(Desde&&Hasta) {
                    ChuscoDesdeHasta();
                    $('enrutar').show();
                }
                else $('enrutar').hide();
            });
}

// fin de ocultación -->
