function r_origenes(valor,nombre,nombre2,idi,clase,estilo,capa,capa2)
{  
  hazPeticion("./turismo.funciones.origenes?idioma="+idi+"&nombre="+nombre+"&destino="+valor+"&clase="+clase+"&estilo="+estilo,capa);
  hazPeticion2("./turismo.funciones.destinos_carretera?idioma="+idi+"&nombre="+nombre2+"&destino=0&clase="+clase+"&estilo="+estilo,capa2);
}

function r_destinos_carretera(valor,nombre,idi,clase,estilo,capa)
{  
  hazPeticion("./turismo.funciones.destinos_carretera?idioma="+idi+"&nombre="+nombre+"&destino="+valor+"&clase="+clase+"&estilo="+estilo,capa);
}

function r_destinos_avion(valor,nombre,idi,clase,estilo,capa)
{  
  hazPeticion("./turismo.funciones.destinos_avion?idioma="+idi+"&nombre="+nombre+"&destino="+valor+"&clase="+clase+"&estilo="+estilo,capa);
}

function r_destinos_tren(valor,nombre,idi,clase,estilo,capa)
{  
  hazPeticion("./turismo.funciones.destinos_tren?idioma="+idi+"&nombre="+nombre+"&destino="+valor+"&clase="+clase+"&estilo="+estilo,capa);
}

function buscar_transportes()
{  
  var medio = document.getElementById("medio").value;
  var origen = document.getElementById("origen").value;
  var destino = document.getElementById("destino").value;
  var url = "";

  if (medio == ""){
    alert("ERROR: Debe seleccionar un medio de transporte.");
  }else{
    if (medio == "por-carretera"){
      if (origen != "" && destino != "")
        location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen+"&destino="+destino;
      else
        alert("ERROR: Debe seleccionar origen y destino.");
    }else if (medio == "por-avion"){
      location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen+"&destino="+destino;
    }else if (medio == "en-tren"){
      location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen+"&destino="+destino;
    }else if (medio == "en-autobus"){
      location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen;
    }else if (medio == "en-taxi"){
      location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen;
    }else if (medio == "en-coche-de-alquiler"){
      location.href = document.getElementById("formulario").action + "?medio="+medio+"&origen="+origen;
    }
  }
}

function buscar_trenes()
{  
  var medio = document.getElementById("medio").value;
  var origen = document.getElementById("origen").value;
  var destino = document.getElementById("destino").value;
  var url = "";

  location.href = document.getElementById("url").value + "?medio="+medio+"&origen="+origen+"&destino="+destino;
}

function buscar_aviones()
{  
  buscar_trenes();
}

function buscar_trayectos()
{  
  var medio = document.getElementById("medio").value;
  var origen = document.getElementById("origen").value;
  var destino = document.getElementById("destino").value;
  var url = "";

  if (origen != "" && destino != "")
    location.href = document.getElementById("url").value + "?medio="+medio+"&origen="+origen+"&destino="+destino;
  else
    alert("ERROR: Debe seleccionar origen y destino.");
}

function trim(cadena){ 
  for(i=0; i<cadena.length; )
  {
    if(cadena.charAt(i)==" ")
      cadena=cadena.substring(i+1, cadena.length);
    else break; 
  }
  for(i=cadena.length-1; i>=0; i=cadena.length-1)
  {
    if(cadena.charAt(i)==" ") cadena=cadena.substring(0,i);
    else break;
  }
  return cadena;
}

function r_buscar(valor,objeto,capa)
{  
  if (valor != "" && valor.length >= 3)
  {
    document.getElementById(capa).style.display = "block";
    hazPeticion("./turismo.sugerencias_buscador?input="+valor+"&campo="+objeto+"&capa="+capa,capa);
  }else{
    document.getElementById(capa).style.display = "none";
  }
}
  
function seleccionar(objeto,texto,capa)
{
  document.getElementById(objeto).value = texto;
  document.getElementById(capa).style.display = "none";
}

function buscar_todo()
{  
  var texto = document.getElementById("texto").value;
  var tipo = document.getElementById("tipo").value;
  var pdestino = "";
  var url = "";

  if (document.getElementById("localidad").value != "") pdestino = document.getElementById("localidad").value;
  else if (document.getElementById("destino").value != "") pdestino = document.getElementById("destino").value;

  if (pdestino != "") url = url + "localidad="+pdestino;
  if (texto != "") if (url != "") url = url + "&texto="+texto; else url = url + "texto="+texto; 
  if (tipo != "") if (url != "") url = url + "&tipo="+tipo; else url = url + "tipo="+tipo; 
  if (url != ""){
    url = "?" + url;
    location.href = document.getElementById("formulario").action + url;
  }else{
    alert("ERROR: Debe seleccionar al menos un parámetro en su búsqueda.");
  }
}

function buscar_rutas()
{  
  var texto = document.getElementById("texto").value;
  var tipo_ruta = document.getElementById("tipo_ruta").value;
  var duracion = document.getElementById("duracion").value;
  var dificultad = document.getElementById("dificultad").value;
  var pdestino = "";
  var url = "";
  var accion = "";

  if (document.getElementById("localidad").value != "") pdestino = document.getElementById("localidad").value;
  else if (document.getElementById("destino").value != "") pdestino = document.getElementById("destino").value;

  if (pdestino != "") url = url + "localidad="+pdestino;
  if (texto != "") if (url != "") url = url + "&texto="+texto; else url = url + "texto="+texto; 
  if (tipo_ruta != "") if (url != "") url = url + "&tipo_ruta="+tipo_ruta; else url = url + "tipo_ruta="+tipo_ruta; 
  if (duracion != "") if (url != "") url = url + "&duracion="+duracion; else url = url + "duracion="+duracion; 
  if (dificultad != "") if (url != "") url = url + "&dificultad="+dificultad; else url = url + "dificultad="+dificultad; 
  if (url != "")  url = "?" + url;

  if (tipo_ruta == "1") accion = document.getElementById("url_3").value;
  else if (tipo_ruta == "2") accion = document.getElementById("url_2").value;
  else if (tipo_ruta == "8") accion = document.getElementById("url_4").value;
  else if (tipo_ruta == "") accion = document.getElementById("formulario").action;
  else accion = accion = document.getElementById("url_1").value;

  location.href = accion + url;
}

function buscar_puntos_de_interes()
{  
  var texto = document.getElementById("texto").value;
  var tipo = document.getElementById("tipo").value;
  var pruta = document.getElementById("pruta").value;
  var sesion = document.getElementById("sesion").value;
  var pdestino = "";
  var url = "";

  if (document.getElementById("localidad").value != "") pdestino = document.getElementById("localidad").value;
  else if (document.getElementById("destino").value != "") pdestino = document.getElementById("destino").value;

  if (pdestino != "") url = url + "localidad="+pdestino;
  if (texto != "") if (url != "") url = url + "&texto="+texto; else url = url + "texto="+texto; 
  if (tipo != "") if (url != "") url = url + "&tipo="+tipo; else url = url + "tipo="+tipo; 
  if (sesion != "") if (url != "") url = url + "&sesion="+sesion; else url = url + "sesion="+sesion; 
  if (pruta != "") if (url != "") url = url + "&pruta="+pruta; else url = url + "pruta="+pruta; 
  if (url != "")  url = "?" + url;

  location.href = document.getElementById("formulario").action + url;
}
