function enviar_formulario_informacion() {
	if (document.formulario.Nombre.value.length==0){
		alert("Debe cumplimentar los campos obligatorios");
		document.formulario.Nombre.focus();
		return;
	}
	if (document.formulario.Email.value.length==0){
		alert("Debe cumplimentar los campos obligatorios");
		document.formulario.Email.focus();
		return;
	}
	if ( (document.formulario.Email.value.indexOf ('@', 0) == -1) || (document.formulario.Email.value.length < 5) ) { 
    alert("Escriba una dirección de correo válida en el campo \"E-mail\".");
		document.formulario.Email.focus();
		document.formulario.Email.select();
  	return;
	}
	document.formulario.submit();
}

function mostrar_sucursal(id_sucursal) {
	if (document.getElementById || document.all || document.layers) {
		var tag_to_hide = eval('document.getElementById("' + id_sucursal + '").style');
	}
	
	if (tag_to_hide.display == "none")
		tag_to_hide.display="block"
	else
		tag_to_hide.display="none"
}


function go_to(box)
{
	window.open(box ,'_blank','');
}

	
function ver_mapa(ida,idd) {
  document.getElementById("ifrm_gmaps").src="https://www.aavv.com/gmap.php?ida=" + ida + "&idd=" + idd;
}

function redim(ifr,w,h) {

  //Redimensiona un iframe pasando su id como parametro y la anchura/altura
  var miIframe=document.getElementById(ifr);
  miIframe.style.height=h;
  miIframe.style.width=w;

}

/******* funciones del buscador de ofertas de bookingfax *******/
function ofertas1() {
	destinos_n0_value = document.getElementById('destinos_n0').value;
	window.location.href = 'index.shtm?destinos_n0=' + destinos_n0_value;
}
function ofertas2() {
	destinos_n0_value = document.getElementById('destinos_n0').value;
	destinos_n1_value = document.getElementById('destinos_n1').value;
	window.location.href = 'index.shtm?destinos_n0=' + destinos_n0_value + '&destinos_n1=' + destinos_n1_value;
}
function ofertas3() {
	destinos_n0_value = document.getElementById('destinos_n0').value;
	destinos_n1_value = document.getElementById('destinos_n1').value;
	destinos_n2_value = document.getElementById('destinos_n2').value;
	window.location.href = 'index.shtm?destinos_n0=' + destinos_n0_value + '&destinos_n1=' + destinos_n1_value + '&destinos_n2=' + destinos_n2_value;
}

function ofertas_categorias() {
	categorias_value = document.getElementById('categorias').value;
	window.location.href = 'index.shtm?categorias=' + categorias_value;
}

// funciones del buscador de vuelos de la HOME -------------------------------------------------------------
function getCheckedValue(radioObj) {
  if(!radioObj)
    return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return "";
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return "";
}

function check_origen(obj){
  if (document.buscador_vuelos.originAirport.value=="")
    obj.value="";
}
function check_destino(obj){
  if (document.buscador_vuelos.destinationAirport.value=="")
    obj.value="";
}

function check_fecha(cadena) {
/*
  if (cadena.length ==0) {
     return true;
  };
*/
  if (cadena.length !=10) {
    return false;
  }

  dia = cadena.substr(0,2)*1;
  mes = cadena.substr(3,2)*1;
  anyo = cadena.substr(6,4)*1;

  if ((mes >12) || (mes < 1)) {
     return false;
  }
  if ((dia >31) || (dia < 1)) {
     return false;
  }
  if ((anyo >2010) || (anyo < 2002)) {
     return false;
  }
  if ((mes == 2) && (dia > 28)) {
     return false;
  }
  if ((dia >30) && (mes != 1) && (mes != 3) && (mes != 5) && (mes != 7) && (mes != 8) && (mes != 10) && (mes != 12)) {
     return false;
  }
  return true;
}
function check_form_vuelos() {
  falta = "";

  if (document.buscador_vuelos.originAirportName.value == "" || document.buscador_vuelos.originCountryName.value == "") {
    falta += "\n     -  Origen";
  }

  if (document.buscador_vuelos.destinationAirportName.value == "" || document.buscador_vuelos.destinationCountryName.value=="") {
    falta += "\n     -  Destino";
  }

  if (document.buscador_vuelos.departureDate1AsString.value == "" || !check_fecha(document.buscador_vuelos.departureDate1AsString.value)) {
    falta += "\n     -  Fecha salida (o no es correcta)";
  }

  if(getCheckedValue(document.forms['buscador_vuelos'].elements['oneWay'])=="false") {
    if (document.buscador_vuelos.departureDate2AsString.value == "" || !check_fecha(document.buscador_vuelos.departureDate2AsString.value)) {
      falta += "\n     -  Fecha regreso (o no es correcta)";
    }

    if (document.buscador_vuelos.departureDate1AsString.value == document.buscador_vuelos.departureDate2AsString.value)
      document.buscador_vuelos.departureHour2.value="2300";
  }

  if (falta != "") {
    falta ="_____________________________\n" +
    "Te ha faltado introducir los siguientes datos:\n" +
    falta + "\n_____________________________" +
    "\n¡Por favor pulsa enter, rellena los datos y prueba de nuevo!";
    alert(falta);
    return false;
  } else {
    document.buscador_vuelos.totalTravellers.value=parseInt(document.buscador_vuelos.adults.options[document.buscador_vuelos.adults.selectedIndex].value)+parseInt(document.buscador_vuelos.children.options[document.buscador_vuelos.children.selectedIndex].value)+parseInt(document.buscador_vuelos.infants.options[document.buscador_vuelos.infants.selectedIndex].value);
    document.buscador_vuelos.submit();
  }
}

// boletines agencia **************************************************************************
function objetoAjax(){
  var xmlhttp=false;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function check_mail(ida,grp) {
  email = document.formulariodatos.Email.value;  
  url = "/auxiliar/check_user.php?email=" + email;
  if (ida!="")
    url = url + "&ida="+ida;

  if (grp!="")
    url = url +"&grupo="+grp;

  ajax = objetoAjax();
  ajax.open("GET", url);
  ajax.onreadystatechange = function() {
    if (ajax.readyState==4) {
      if (ajax.status == 200) {
        if (ajax.responseText=="0") {
          enviar_form_boletines();
        } else {
          document.formulariodatos.Email.value = "";
          alert (ajax.responseText);
          return false;
        }
      } else {
        alert("Se ha producido un error al procesar el alta.\nIntentelo de nuevo mas tarde.\n");
        return false;
      }
    }
  }
  ajax.send(null);
}

function enviar_form_boletines() {

   error_message="";
   length_mail = 0;

  if (document.formulariodatos.Password_usuario_1.value.length==0) {
    error_message = "- Contraseña\n" + error_message;
    document.formulariodatos.Password_usuario_1.focus();
    document.formulariodatos.Password_usuario_1.select();
  }

  if (document.formulariodatos.Email.value.length==0) {
    error_message = "- Email\n" + error_message;
    document.formulariodatos.Email.focus();
    document.formulariodatos.Email.select();
  }

  if (document.formulariodatos.Nombre.value.length==0) {
    error_message = "- Nombre\n" + error_message;
    document.formulariodatos.Nombre.focus();
    document.formulariodatos.Nombre.select();
  }

  if (document.formulariodatos.Password_usuario_1.value != document.formulariodatos.Password_usuario_2.value) {
    document.formulariodatos.Password_usuario_2.focus();
    document.formulariodatos.Password_usuario_2.select();
    error_message = "- Las contraseñas no coinciden\n" + error_message;
  }

  length_mail = document.formulariodatos.Email.value.length;
  length_mail = length_mail - 1;
  if ( (document.formulariodatos.Email.value.indexOf ('@', 0) < 1) || (document.formulariodatos.Email.value.length < 5) || (document
.formulariodatos.Email.value.lastIndexOf(".") < 2) || (document.formulariodatos.Email.value.charAt(length_mail) == "." ) ) {
    document.formulariodatos.Email.focus();
    document.formulariodatos.Email.select();
    error_message = "- Formato de email incorrecto\n"+ error_message;
  }

  if (error_message != "") {
    error_message = "Los siguientes campos son obligatorios:\n\n" + error_message;
    alert(error_message);
    return false;
  }

  document.formulariodatos.submit();
}

function baja_usuario_boletines() {
  if(confirm("Si se da de baja dejará de recibir boletines de ofertas. ¿Está seguro que desea continuar con el proceso de baja?")) {
    document.getElementById("desactivar").value = 1;
    document.formulariodatos.submit();
  }
}
