// JavaScript Document


var posicY;
var posicX;
 
/* 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-50; //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";
	capita.style.zIndex="1000";
}

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
}


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 != undefined && posicX != undefined){
		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 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 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";
}

function laEspera(){
	posiTop=220+document.documentElement.scrollTop;
	posiLeft=500;
	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";
} 
function quitalaEspera(){
	document.getElementById('imgEspera').style.display="none";
}

function msgJS(etiquetaIdioma) {
	lang=$("#idiomaCliente").val();
	tradu="";
	$.ajax({
		type: "GET",
		url: "/productos/idioma_"+lang+".xml",
		async: false, //modo sincrono, osea se para el proceso hasta que acabe
		success: function(xml) {
			$(xml).find("traducciones").each(function(){
				eti=$(this).find('etiqueta').text();
				if (eti==etiquetaIdioma) {
					tradu=$(this).find('traduccion').text();
					return false; //sale del bucle each
				}
			});
		}
	});
	return tradu;
}
