// 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";
}

//Pa mover los iframes por ahí
var capaM = null;
difX=0;
difY=0;
var es_IE = navigator.userAgent.indexOf("MSIE") != -1;

if (!es_IE) document.addEventListener("mousemove", posicRatonXY, true);
document.onmousemove = posicRatonXY;
var posicX = 0;
var posicY = 0;
sigueme=false;
function posicRatonXY(e) {
	scrolTop=0;
	scrolLeft=0;
	if (es_IE) { 
		if (document.documentElement && document.documentElement.scrollTop){
		  // Explorer 6 Strict
		  scrolTop = document.documentElement.scrollTop;
		  scrolLeft = document.documentElement.scrollLeft;
		} else if (document.body){
		  // all other Explorers
		  scrolTop = document.body.scrollTop;
		  scrolLeft = document.body.scrollLeft;
		}
		miX = window.event.clientX + scrolLeft;
		miY = window.event.clientY + scrolTop;
		posicX = window.event.screenX;
		posicY = window.event.screenY;
	} else { 
		miX = e.pageX;
		miY = e.pageY;
		posicX = e.screenX;
		posicY = e.screenY;
	}
	if (posicX < 0) posicX = 0;
	if (posicY < 0) posicY = 0;
	if (sigueme){ //pa mover la capilla
		document.getElementById('capilla').style.top=(posicY+3)+"px";
		document.getElementById('capilla').style.left=(posicX+14)+"px";
	}
	muevete();
	return true;
} 

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 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;
}

ultSubMenu=0;
function verSubMenu(ese){
	clearTimeout(rapTime);
	if (ultSubMenu!=0){ //quitar anterior
		document.getElementById('capaOpcion'+ultSubMenu).style.visibility='hidden';
	}
	//posicion top
	posT=dameTop(document.getElementById('opcion'+ese))+document.getElementById('opcion'+ese).offsetHeight;
	posT=posT-document.getElementById('capaGeneral').offsetTop-2; //
	//posicion Left
	posL=dameLeft(document.getElementById('opcion'+ese));
	posL=posL-document.getElementById('capaGeneral').offsetLeft; //
	document.getElementById('capaOpcion'+ese).style.top=posT+'px';
	document.getElementById('capaOpcion'+ese).style.left=posL+'px';
	ultSubMenu=ese;
	document.getElementById('capaOpcion'+ese).style.visibility='visible';

}

rapTime=-1;
function tiempoFuera()
{
	if (ultSubMenu!=0)
		document.getElementById('capaOpcion'+ultSubMenu).style.visibility='hidden';
}
function quitarCapa(esa)
{
	rapTime=setTimeout('tiempoFuera();',200);
}

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');
}

//Funciones del select lista
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 ponNoches() {
	//Restar las fechas para saber dias introducidos
	fi=document.f1.fechai.value;
	ff=document.f1.fechaf.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 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");
}
