// JavaScript Document
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);
	}
	venti=window.open(url,"","top="+ptop+",left="+pleft+",width="+ancho+",height="+alto+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
}

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";
}

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 ponNoches() {
	//Restar las fechas para saber dias introducidos
	fi=document.f1.fini.value;
	ff=document.f1.ffin.value;
	diaI=fi.substring(0,2);
	mesI=fi.substring(3,5)-1;
	anyI=fi.substring(6,10);
	da1=new Date(anyI,mesI,diaI);
    da2=new Date(ff.substring(6,10),ff.substring(3,5)-1,ff.substring(0,2));
  if (da1>=da2 )
    document.f1.txtdias.value="***";
  else
  	{
	dife=da2.getTime() - da1.getTime()+10800000; //se aņade  10800000 pa evitar el error de marzo
	bnoches=parseInt(dife/ (1000 * 60 * 60 * 24));
    document.f1.txtdias.value=bnoches;
	}
}
function ponNochesB() {
	//Restar las fechas para saber dias introducidos
	fi=document.buscador.fini.value;
	ff=document.buscador.ffin.value;
	diaI=fi.substring(0,2);
	mesI=fi.substring(3,5)-1;
	anyI=fi.substring(6,10);
	da1=new Date(anyI,mesI,diaI);
    da2=new Date(ff.substring(6,10),ff.substring(3,5)-1,ff.substring(0,2));
  if (da1>=da2 )
    document.buscador.noches.value="**";
  else
  	{
	dife=da2.getTime() - da1.getTime()+10800000; //se aņade  10800000 pa evitar el error de marzo
	bnoches=parseInt(dife/ (1000 * 60 * 60 * 24));
    document.buscador.noches.value=bnoches;
	}
}
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 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");
}