// JavaScript Document

/* FUNCIONES PARA LAS COOKIES */
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 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" : "");
}

/*
GetCookie("visit");

expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
SetCookie("visit", visit, expdate, "/", null, false);
*/


/* FUNCIONES PARA EL IFRAME DEL CALENDARIO */
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-100; //Quito por la barra del navegador
		//aņadir scroll
		t=t+document.body.scrollTop;
		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.visibility="visible";
}

function encogeCapa(esa){
	esa.style.width="1px";
	esa.style.height="1px";
}

/* posicion raton */
difX=0;
difY=0;
var es_IE = navigator.userAgent.indexOf("MSIE") != -1;

if (!es_IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = posicRatonXY;
var posicX = 0;
var posicY = 0;
function posicRatonXY(e) {
	if (es_IE) { 
		if (document.documentElement && document.documentElement.scrollTop){
		  // Explorer 6 Strict
		  scrolTop = document.documentElement.scrollTop;
		} else if (document.body){
		  // all other Explorers
		  scrolTop = document.body.scrollTop;
		}
		posicX = window.event.clientX + document.body.scrollLeft;
		posicY = window.event.clientY + scrolTop;
	} else { 
		posicX = e.pageX;
		posicY = e.pageY;
	}
	if (posicX < 0) posicX = 0;
	if (posicY < 0) posicY = 0;
	return true;
} 


/* FUNCIONES DEL BUSCADOR */
function enviaBusca(){
	//ponEspera();
	//Guarda las cookies
	SetCookie("bfini",document.buscador.fini.value,null,"/");
	SetCookie("bffin",document.buscador.ffin.value,null,"/");
	SetCookie("bninos",document.buscador.ninos.value,null,"/");
	SetCookie("badultos",document.buscador.adultos.value,null,"/");

	document.buscador.submit();
}

//cargar por defecto
if (GetCookie("badultos")==null || GetCookie("badultos")=="")
	document.buscador.adultos.value=2;
else
	document.buscador.adultos.value=GetCookie("badultos");

if (GetCookie("bninos")==null || GetCookie("bninos")=="")		
	document.buscador.ninos.value=0;
else
	document.buscador.ninos.value=GetCookie("bninos");

if (GetCookie("bfini")==null || GetCookie("bfini")==""){ //poner fecha actual
	hoy=new Date(); 
	document.buscador.fini.value=sumaDias(fechaWeb(hoy),0);
	document.buscador.ffin.value=sumaDias(fechaWeb(hoy),1);

}else{
	document.buscador.fini.value=GetCookie("bfini");
	document.buscador.ffin.value=GetCookie("bffin");
}

function abreCalendar(esaFecha,elObj,idioma,elTop,elLeft){
	lafecha=eval("document.buscador."+esaFecha+".value");
	laurl="/calendario.asp?lang="+idioma+"&elForm=buscador&valor="+esaFecha+"&"+esaFecha+"="+lafecha;
	//ptop=posicY+16; //dameTop(elObj);
	//pleft=posicX-20; //dameLeft(elObj)+20;

	//posicion fija
	if (elTop==undefined)
		ptop=170;
	else
		ptop=elTop;
		
	if (elLeft==undefined)
		pleft=720;
	else
		pleft=elLeft;
		
	palIframe(document.getElementById('verCalendario'),220,120,ptop,pleft,laurl);
}

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;
}

function sumaDias(laFecha,losDias){
	//la fecha viene en formato dd/mm/aaaa
	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);
}


-->
