<!--funciones.js-->
function SetCookie (name, value){
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function cambiaMoneda(esa){
	SetCookie("coin",esa,null,"/"); //esta funcion esta en cookies.js
	SetCookie("miCambio","0",null,"/"); //esta funcion esta en cookies.js
	window.location.reload();
}
function abreCalendarIF(esaFecha,idioma){
	if (esaFecha == 'fini'){
		LaQueLlama= '#afini';
	}
	else{
		LaQueLlama= '#affin';
	}

	lafecha=eval("document.fb."+esaFecha+".value");
	laurl="calendario.asp?lang="+idioma+"&elForm=fb&valor="+esaFecha+"&"+esaFecha+"="+lafecha;

	posi = $(LaQueLlama).offset();
	
	ptop=posi.top;
	pleft=posi.left+100;
	
	palIframe(document.getElementById('verCalendario'),220,120,ptop,pleft,laurl);
}
function validarEMail(ese){ //pos eso
	if (ese.search(/^[^@]+@([a-zA-Z0-9-_\-]+\.)+[a-zA-Z]+$/)<0)
  		return false;
	
	return true;
}

function fechaValidaASP(laFecha){ //formato dd/mm/aaaa
	if (laFecha!=undefined) {
		laFecha=laFecha.replace(/-/g,"/"); //cambia el - por /
		separa=laFecha.split("/");
		if (separa[0].length==1) //el dia viene en 1 numero
			separa[0]="0"+separa[0];
		if (separa[1].length==1) //el mes viene en 1 numero
			separa[1]="0"+separa[1];
		if (separa[2].length==2) //el año viene en 2 numeros
			separa[2]="20"+separa[2]; //le pongo el 2000, esta funcion no vale para el 2100
		
		laFecha=separa[0]+"/"+separa[1]+"/"+separa[2];
		plantilla=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/;
		if (laFecha.length==0 || !plantilla.exec(laFecha)) 
			return false;

		/* pasamos la fecha a un objeto Date */
		var d = new Date()
		d.setFullYear(laFecha.substring(6,10),laFecha.substring(3,5)-1,laFecha.substring(0,2));
		/*si la fecha es correcta será igual al original en caso contrario el javascript crea una fecha aproximada*/
		if (d.getMonth()!=laFecha.substring(3,5)-1 || d.getDate()!=laFecha.substring(0,2))
			return false;
		
		return laFecha; //es valida si llega hasta aquí
				
	} else { //no viene nada
		return false;
	}
}

/* Ajax Clasico */
function nuevoAjax() {
	var nuevoAjax = false;
	try {
		nuevoAjax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			nuevoAjax= new ActiveXObject ("Microsoft.XMLHTTP");
		} catch (E) {
			nuevoAjax= false;
		}
	}
	if (!nuevoAjax && typeof XMLHttpRequest!= 'undefined') {
		nuevoAjax = new XMLHttpRequest();
	}
	return nuevoAjax;
}

function centrarCapa(laCapa,miAncho,miAlto,posiTop,posiLeft){
	elancho=screen.availWidth;
	elalto=screen.availHeight;
	if(posiLeft==0){
		l=(elancho/2)-(parseInt(miAncho/2)); //Pos. izquierda
		l=l-15;
		posiLeft=l;
	}
	if (posiTop==0){
		t=(elalto/2)-(parseInt(miAlto/2)); //Pos. superior
		t=t-90; //Quito por la barra del navegador
		//añadir scroll
		t=t+document.body.scrollTop;
		if (es_IE)
			t=t+document.documentElement.scrollTop;
		else
			t=t+self.pageYOffset;
		posiTop=t;
	}
	laCapa.style.left=posiLeft+"px";
	laCapa.style.top=posiTop+"px";
}

/* Funcion AjaxXocolait */
function palIframe(capita,ancho,alto,posiTop,posiLeft,url){
	capita.style.height=alto+"px";
	capita.style.width=ancho+"px";
	if (posiTop==0 || posiLeft==0){
		centrarCapa(capita,ancho,alto,posiTop,posiLeft);
	}else{
		capita.style.top=posiTop+"px";
		capita.style.left=posiLeft+"px";
	}
	capita.src=url;
	capita.style.display="block";
}

function encogeCapa(esa){
	esa.style.width="1px";
	esa.style.height="1px";
}

//Pa mover los iframes por ahí
var capaM = null;
difX=0;
difY=0;
var es_IE = navigator.userAgent.indexOf("MSIE") != -1;

function ponEti(miTexto){
	document.getElementById('capilla').innerHTML=miTexto;
	document.getElementById('capilla').style.top=(posicY+3)+"px";
	document.getElementById('capilla').style.left=(posicX+14)+"px";
	document.getElementById('capilla').style.visibility='visible';
	sigueme=true;
}
function quitaEti(){
	document.getElementById('capilla').style.visibility='hidden';	
	sigueme=false;
}


function liberaCapa() {
	capaM = null;
}

function marcaCapa(obj) {
	capaM = obj; // obj.parentNode;
	difX=posicX;
	difY=posicY;
}

function muevete() {
	if (capaM != null) {
		capaM.style.top = (parseInt(capaM.style.top,10)+(posicY-difY))+"px";
		capaM.style.left = (parseInt(capaM.style.left,10)+(posicX-difX))+"px";
	}
}

var ultimaVisible="";
function verCapa(esa){
	if (ultimaVisible!="")
		document.getElementById(ultimaVisible).style.visibility='hidden';
	
	document.getElementById(esa).style.visibility='visible';
	ultimaVisible=esa;
}

function abreSub(cualo){
	if (document.getElementById(cualo).style.height=="1px") {
		document.getElementById(cualo).style.height='52px';
	}else{
		document.getElementById(cualo).style.height='1px';
	}
}
function cambiaFoto(cualo,cuala){ //id de la imagen y la foto
	document.getElementById(cualo).src=cuala; //pos eso
}


function dameTop(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent)
		{
		curtop += obj.offsetTop;
		obj = obj.offsetParent;
		}
	}else if (obj.y){
		curtop += obj.y;
	}
	return curtop;
}
function dameLeft(obj){
	var curLeft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent)
		{
		curLeft += obj.offsetLeft;
		obj = obj.offsetParent;
		}
	}else if (obj.x){
		curLeft += obj.x;
	}
	return curLeft;
}
function abreVentana(url,ptop,pleft,ancho,alto){
	if (ptop==0 && pleft==0){ //centrarla
		ptop=parseInt((parseInt(screen.height)-alto)/2);
		pleft=parseInt((parseInt(screen.width)-ancho)/2);
	}
	window.open(url,"","top="+ptop+",left="+pleft+",width="+ancho+",height="+alto+",statusBar=no,resize=no");
}

function runSWF(archivo, ancho, alto, version, bgcolor, id, menu, FlashVars, quality, allowScriptAccess) { // tutorial by IVI CONCEPT - www.ivi-concept.com
if(version!=""){
var version_data=version;
}else{
var version_data="6,0,0,0";
}
if(menu!=""){
menu_data=menu;
}else{
menu_data=false;
}
if(bgcolor!=""){
var bgcolor_data=bgcolor;
}else{
var bgcolor_data="#FFFFFF";
}
if(id!=""){
id_data=id;
}else{
id_data="flashMovie";
}
if(quality!=""){
quality_data=quality;
}else{
quality_data="high";
}
if(allowScriptAccess!=""){
allowScriptAccess_data=allowScriptAccess;
}else{
allowScriptAccess_data="always";
}
var quality="high"; // calidad de visualización de la peli
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= '+version_data+'" width='+ancho+' height='+alto+' id='+id_data+'>\n');
document.write('<param name="movie" value='+archivo+'>\n');
document.write('<param name= "allowScriptAccess" value= '+allowScriptAccess_data+'>\n');
document.write('<param name="quality" value='+quality_data+'>\n');
document.write('<param name="FlashVars" value='+FlashVars+'>\n');
document.write('<param name="bgcolor" value='+bgcolor_data+'>\n');
document.write('<param name="wmode" value="transparent">\n');
document.write('<param name="menu" value='+menu_data+' >\n');
document.write('<embed src='+archivo+' bgcolor='+bgcolor_data+' FlashVars='+FlashVars+' menu='+menu_data+' allowScriptAccess='+allowScriptAccess_data+' quality='+quality_data+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width='+ancho+' height='+alto+' swLiveConnect=true name='+id_data+' wmode="transparent"></embed>');
document.write('</object>\n');
}

function validarBoletin(msgError){
  //comprobar si acepta condiciones
  if (!document.fboletin.aceptoBoletin.checked){
    alert(msgError);
    return;
  }
  document.fboletin.submit();
}

function validarEmpleo(msgError){
  //lo validamos en el ASP
  document.FEmpleo.submit();
}

function ponTexto(ese){
	texto=ese; //ese.title;
	document.getElementById('lostextos').innerHTML=texto;
	document.getElementById('lostextos').style.display='block';
}
function quitaTexto(){
	document.getElementById('lostextos').innerHTML="";
	document.getElementById('lostextos').style.display='none';
}

function laEspera(){
	posiLeft=(screen.width/2)-(parseInt(258/2)); //Pos. izquierda
	posiTop=(screen.height/2)-(parseInt(56/2)); //Pos. arriba
	posiTop=posiTop+document.documentElement.scrollTop-150;
	if (posiTop<0) posiTop=0;
	document.getElementById('imgEspera').style.top=posiTop+"px";
	document.getElementById('imgEspera').style.left=posiLeft+"px";
	document.getElementById('imgEspera').style.display="block";
	document.getElementById('imgEspera').style.zIndex=100;
}
function quitalaEspera(){
	document.getElementById('imgEspera').style.display="none";
}

function closeInfo() {
   document.getElementById("info1").style.display = "none";
}
function loadInfo() {
   document.getElementById("info1").style.display = "block";
}

/*funcion para controlar capas DIV como select HTML */

function quitaLista(esa){
	$(esa).css("display",'none');
}

var idReloj;
var listaActual="";
function montarSelect() {
	$("div.capa_lista").click(function(){
		if ($("div#"+this.id+" div.lista").css("display")=='none' || $("div#"+this.id+" div.lista").css("display")=='') { //no está visible
			$("div#"+this.id+" div.lista").css("display","block");
			listaActual=this.id; //para controlar el cierre
			//esto es por culpa del IE
			ancho=this.offsetWidth-4; //lista[i].offsetWidth-4;
			$("div#"+this.id+" a").css("minWidth",ancho+"px");
		}else{ //ya está visible
			$("div#"+this.id+" div.lista").css("display","none");
			listaActual="";
		}
	});

	$("div.capa_lista").hover(function(){
		if (listaActual==this.id)
			clearTimeout(idReloj); //detiene el reloj si hay un mouseout
	}, function(){
		idReloj=setTimeout("quitaLista('#"+this.id+" div.lista')",200);
	});

}
<!--buscador.js-->
// JavaScript Document
function getCookieVal (offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
			break; 
	}
	return null;
}

function compruebaBusca(){
	lang=$("#idioma").attr("value");
	cuantas=parseInt(document.fb.nhabis.value,10);
	ad=parseInt(document.fb.ad.value,10);
	ni=parseInt(document.fb.ni.value,10);
	esazona=parseInt(document.fb.bzona.value,10);
	if (cuantas==1 || ni==0) {
		//pasar las variables
		document.fb.ad_0.value=ad;
		document.fb.ni_0.value=ni;
	}

	if (cuantas>1 || ni>0) {
		laurl="distribucion.asp?lang="+lang+"&nhabis="+cuantas+"&ad="+ad+"&ni="+ni+"&idz="+esazona;
		ptop=205;
		pleft=50;
		palIframe(document.getElementById('verCalendario'),300,160,ptop,pleft,laurl);
		return;
	} //cuantas
	
	enviaBusca();
}

//para mostrar mensajes en diferentes idiomas
function mostrarMensaje(variableIdioma,lang) {
	document.getElementById('verCalendario').src="mensajes.asp?lang="+lang+"&variable="+variableIdioma;
}
function enviaBusca() {
	if (document.fb.bzona.value=="0") {
		mostrarMensaje("i_seleccionezona",document.getElementById("idioma").value);
		$("#verCalendario").css("display","none"); //por si está visible
		return;
	}
	//Guarda las cookies
	SetCookie("bzona",document.fb.bzona.value,null,"/");
	SetCookie("bhotel",document.fb.bhotel.value,null,"/");
	SetCookie("bfini",document.fb.fini.value,null,"/");
	SetCookie("bffin",document.fb.ffin.value,null,"/");
	SetCookie("nhabis",document.fb.nhabis.value,null,"/");
	
	SetCookie("bninos",document.fb.ni.value,null,"/");
	SetCookie("badultos",document.fb.ad.value,null,"/");

	//laEspera(); //imagen de espera
	
	//aquí imagino que habrá que validar algún campo
	document.fb.submit();
}

function fechaWeb(lafecha){
	Fdia=lafecha.getDate();
	if (Fdia<10)
		Fdia="0"+Fdia;
	Fmes=lafecha.getMonth()+1;
	if (Fmes<10)
		Fmes="0"+Fmes;
	Fany=lafecha.getFullYear();
	return Fdia+"/"+Fmes+"/"+Fany;
}

//Cargar desde las cookies
if (GetCookie("badultos")!=null)
	document.fb.ad.value=GetCookie("badultos");

if (GetCookie("bninos")!=null)		
	document.fb.ni.value=GetCookie("bninos");

if (GetCookie("nhabis")!=null)		
	document.fb.nhabis.value=GetCookie("nhabis");


function abreCalendar(esaFecha,elObj,idioma){
	lafecha=eval("document.fb."+esaFecha+".value");
	laurl="calendario.asp?lang="+idioma+"&elForm=fb&valor="+esaFecha+"&"+esaFecha+"="+lafecha;
	ptop=198;
	pleft=30;
	palIframe(document.getElementById('verCalendario'),220,120,ptop,pleft,laurl);
    
}

function cargaTelefonos(idioma){
	laurl="contactoTelefono.asp?lang="+idioma;
	ptop=200;
	pleft=80;
	palIframe(document.getElementById('paProcesos'),400,220,ptop,pleft,laurl);
}

function avisoOferta(idioma){
	laurl="avisoOferta.asp?lang="+idioma;
	ptop=250;
	pleft=0;
	palIframe(document.getElementById('paProcesos'),400,150,ptop,pleft,laurl);
}


function ponNoches() {
	//Restar las fechas para saber dias introducidos
	fi=document.fb.fini.value;
	ff=document.fb.ffin.value;
	da1=new Date(fi.substring(6,10),fi.substring(3,5)-1,fi.substring(0,2));
    da2=new Date(ff.substring(6,10),ff.substring(3,5)-1,ff.substring(0,2));
  if (da1>=da2 )
    document.fb.txtdias.value="**";
  else
  	{
	dife=da2.getTime() - da1.getTime()+10800000; //se añade 10800000 pa evitar el error de marzo, años bisiestos
	bnoches=parseInt(dife/ (1000 * 60 * 60 * 24));
    document.fb.txtdias.value=bnoches;
	}
}

function CompruebaCap(mensaje){
	limite=4;
	ad=parseInt(document.fb.ad.value,10);
	ni=parseInt(document.fb.ni.value,10);
	if (limite<(ad+ni)) {
		alert(mensaje+": "+limite);
		document.fb.ni.value='0'; //dejo cantidad a cero
		return;
	}
}

function sumaDias(){
	//la fecha viene en formato dd/mm/aaaa
	laFecha=document.fb.fini.value;
	losDias=parseInt(document.fb.txtdias.value,10);
	if (!isNaN(losDias)) {
		fdia=laFecha.substring(0,2);
		fmes=parseInt(laFecha.substring(3,5),10)-1;
		fany=laFecha.substring(6,10);
		midia=new Date(fany,fmes,fdia);
	
		milisegundos=parseInt(losDias*24*60*60*1000);
		tiempo=midia.getTime();
		total=midia.setTime(parseInt(tiempo+milisegundos));
		
		//retorno en el mismo formato
		return fechaWeb(midia);
	} else 
		return false;
}
function sumaNoches(){
	fin=sumaDias();
	if (fin) {
		document.fb.ffin.value=fin;
		textoFechas();
	}
}

function cargaHoteles() {
	//Cambia la zona, borrar la cookie de la moneda
	SetCookie("miCambio","0",null,"/");
	lazona=parseInt(document.fb.bzona.value,10);
	lang=$("#idioma").attr("value");
	lasubcat=$("#idsubcat").attr("value");
	elhotel=$("#idhotel").attr("value");
	laurl="cargaHotelesZona.asp?idz="+lazona+"&idsubcat="+lasubcat+"&idhotel="+elhotel+"&lang="+lang;
	document.getElementById("verCalendario").src=laurl;
	//alert(document.getElementById("verCalendario").src);
}

function verificaZona() {
	//Cambia la zona, borrar la cookie de la moneda
	SetCookie("miCambio","0",null,"/");
	elHotel=parseInt(document.fb.bhotel.value,10);
	if (!isNaN(elHotel)) {
		lang=$("#idioma").attr("value");
		laurl="cargaZona.asp?idh="+elHotel+"&lang="+lang;
		document.getElementById("verCalendario").src=laurl;
		//alert(document.getElementById("verCalendario").src);
	}
}

function verificaFecha(esa) { //paso el objeto
	//comprueba si la fecha es valida
	lang=$("#idioma").attr("value");
	esafecha=esa.value;
	if (esafecha.substring(0,1).toLowerCase()=="d")
		return false; //todavía no ha puesto fecha
		
	laFecha=fechaValidaASP(esafecha);
	if (!laFecha) {
		mostrarMensaje("i_fechanovalida",lang);
		return false;
	}
	esa.value=laFecha;
	if (esa.id=="selectLlegada")
		$("#fini").attr("value",laFecha);
	if (esa.id=="selectSalida")
		$("#ffin").attr("value",laFecha);

	ponNoches();
}

function textoFechas() { //pone las fechas en los inputs visibles
	$("#selectLlegada").attr("value",$("#fini").attr("value"));
	$("#selectSalida").attr("value",$("#ffin").attr("value"));
}
//preparar las capa del select del idioma
function ponListaIdioma() {
	document.getElementById("opcionesLang").style.display="block";
}
function quitaListaIdioma(){
	document.getElementById("opcionesLang").style.display="none";
}

//titulo select
$("#capaTituloLang").click(ponListaIdioma);
$("#capaTituloLang").mouseout(quitaListaIdioma);
//opciones select
$("#opcionesLang").mouseover(ponListaIdioma);
$("#opcionesLang").mouseout(quitaListaIdioma);

$("#txtdias").keyup(sumaNoches);

//nuevo control sobre las fechas
$("#selectLlegada").focus(function() {
	$("#selectLlegada").select(); //marca todo el texto
});
$("#selectLlegada").blur(function() {
	verificaFecha(this);
});
$("#selectSalida").focus(function() {
	$("#selectSalida").select(); //marca todo el texto
});
$("#selectSalida").blur(function() {
	verificaFecha(this);
});

function ponAdultos(esos) {
	document.fb.ad.value=esos;
	var lista=$("#adultos span.titulo_lista");
	for (i=0;i<lista.length;i++)
		lista[i].innerHTML=esos; //poner la seleccion
}
function ponAdultos2(esos) {
	document.fbc.ad.value=esos;
	var lista=$("#adultos2 span.titulo_lista");
	for (i=0;i<lista.length;i++)
		lista[i].innerHTML=esos; //poner la seleccion
}

function ponNinos(esos) {
	document.fb.ni.value=esos;
	var lista=$("#ninos span.titulo_lista");
	for (i=0;i<lista.length;i++)
		lista[i].innerHTML=esos; //poner la seleccion
}
function ponNinos2(esos) {
	document.fbc.ni.value=esos;
	var lista=$("#ninos2 span.titulo_lista");
	for (i=0;i<lista.length;i++)
		lista[i].innerHTML=esos; //poner la seleccion
}
 
function actualizaManda(){
	lacookie = GetCookie("IdAgencia");
	document.fb.idAgencia.value = lacookie;
}

