// JavaScript Document
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";
}
function dameNoches(ini,fin) {
	//Restar las fechas para saber dias introducidos
	diaI=ini.substring(0,2);
	mesI=ini.substring(3,5)-1;
	anyI=ini.substring(6,10);
	da1=new Date(anyI,mesI,diaI);
	da2=new Date(fin.substring(6,10),fin.substring(3,5)-1,fin.substring(0,2));
  if (da1>=da2 )
	return 0;
  else
	{
	dife=da2.getTime() - da1.getTime()+10800000; //se añade  10800000 pa evitar el error de marzo
	return parseInt(dife/ (1000 * 60 * 60 * 24));
	}
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = posicRatonXY;
var posicX = 0;
var posicY = 0;
function posicRatonXY(e) {
	if (IE) { 
		posicX = event.clientX + document.documentElement.scrollLeft;
		posicY = event.clientY + document.documentElement.scrollTop;
	}else{
		posicX = e.pageX;
		posicY = e.pageY;
	}
	if (posicX < 0) {posicX = 0};
	if (posicY < 0) {posicY = 0};
}

var rapTime;
var ultLista="lista";
function verLista(laLista){
	clearTimeout(rapTime);
	document.getElementById(laLista).style.visibility='visible';
	ultLista=laLista;
}
function quitaLista(){
	rapTime=setTimeout('fueraLista();',400);
	//document.getElementById('lista').style.visibility='hidden';
}
function fueraLista()
{
	topLista=dameTop(document.getElementById(ultLista));
	YMaxLista=topLista+document.getElementById(ultLista).offsetHeight; //posicion y max en la lista top
	leftLista=dameLeft(document.getElementById(ultLista));
	XMaxLista=leftLista+document.getElementById(ultLista).offsetWidth; //posicion x max en la lista left
	//alert("la Y Max:"+YMaxLista+"\n la X Max:"+XMaxLista);
	//alert("la Y :"+posicY+"\n la X :"+posicX);
	if (posicY>YMaxLista || posicX>XMaxLista || posicY<topLista || posicX<leftLista)
		document.getElementById(ultLista).style.visibility='hidden';
	else
		rapTime=setTimeout('fueraLista();',400);

}

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 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" : "");
}

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 ponFecha(){
	fini=document.frsv01.diaE.value+"/"+document.frsv01.mesE.value.substring(4,6)+"/"+document.frsv01.mesE.value.substring(0,4);
	ffin=document.frsv01.diaS.value+"/"+document.frsv01.mesS.value.substring(4,6)+"/"+document.frsv01.mesS.value.substring(0,4);
	//alert(fini);
	document.frsv01.fini.value=fini;
	document.frsv01.ffin.value=ffin;
}

function ponSelec(){
	fi=document.frsv01.fini.value;
	diaI=fi.substring(0,2);
	mesI=fi.substring(6,10)+fi.substring(3,5);
	document.frsv01.diaE.value=diaI;
	document.frsv01.mesE.value=mesI;

	ff=document.frsv01.ffin.value;
	diaF=ff.substring(0,2);
	mesF=ff.substring(6,10)+ff.substring(3,5);
	document.frsv01.diaS.value=diaF;
	document.frsv01.mesS.value=mesF;

}

function cargarDestino(form, destinoCompacto){
    form.codagrdest.value=""; form.coddest.value=""; form.codagrzon.value=""; form.codzon.value="";
    arrayDestino = destinoCompacto.split(',');
    if(arrayDestino.length < 2){ return false; } form.nomdest.value =arrayDestino[0]; 
    if(arrayDestino[1]!=""){ form.codagrdest.value = arrayDestino[1]; return true; }
    if(arrayDestino.length >= 3)
    {
        if(arrayDestino[2]!="")
        {
            form.coddest.value = arrayDestino[2];
            if(arrayDestino.length >= 4 && arrayDestino[3]!=""){ form.codagrzon.value = arrayDestino[3]; }
            if(arrayDestino.length == 5 && arrayDestino[4]!=""){ form.codzon.value =  arrayDestino[4]; }
            return true;
        }
    }
    return false;
}

function validaFechas(form){
	
	if(parseInt(form.mesE.value,10)==parseInt(form.mesS.value,10) && parseInt(form.diaE.value,10)>=parseInt(form.diaS.value,10)){
	   return false;
	}
	return true;
 }

function check_frsv01(form) {
	codigo = "Mallorca,PMI,PMI,,"; //sólo mallorca
	if(!cargarDestino(form, codigo)){
		return false;
	}
	var godest = form.destino.value.split(',');
    if (godest[2]!=''){
		document.getElementById('goto').value= 'HDD-'+godest[2];
	}else{
		document.getElementById('goto').value= 'HDD-'+godest[1];
	}
	if(parseInt(form.nnins.value,10)>0) {dinsNnis(form);return;}
	form.submit();
}

 if(document.getElementById('h_avtot')){
	 altini=document.getElementById('h_avtot').offsetHeight;
	 onCos='h_avtot';
}
else onCos=0;

		
function foraNnins(){
	noDiss('xiquets');
	for(i=1;document.getElementById('rumi'+i)!==null;i++){
		for(x=1;document.getElementById('anysde'+x)!==null;x++){
			var removeObject = document.getElementById('anysde'+x);
			removeObject.parentNode.removeChild(removeObject);
		}
		var remObject = document.getElementById('rumi'+i); 
		remObject.parentNode.removeChild(remObject);
	}
		document.getElementById('selxnnins').parentNode.removeChild(document.getElementById('selxnnins'));
		document.getElementById('capsal').parentNode.removeChild(document.getElementById('capsal'));
		document.getElementById('adxiq').parentNode.removeChild(document.getElementById('adxiq'));
		document.getElementById('xiquets').parentNode.removeChild(document.getElementById('xiquets'));
		if(document.getElementById('h_avtot')){
			document.getElementById('h_avtot').style.height= 270+'px';}
		//Diss('destino');Diss('avguest');
		//Diss('go_search');

}

function GroupEdades(form){
	form.edad.value = "";
	var e = document.getElementById('xiquets').getElementsByTagName('select')
	if(e.length!=zagals*habitacul){ window.status="Error nins - contact to Hotelopia"; return; }
	for(f=0;f<e.length;f++){ form.edad.value += e[f].options[e[f].selectedIndex].text+'#'; }
}


