var W3CDOM = (document.createElement && document.getElementsByTagName);

//Se detectan los diferentes navegadores
var esIE = false
//Detectar el navegador explorer 5.01
if (navigator.appVersion.indexOf("MSIE") != -1) { esIE = true;}
swIE501 = (navigator.appVersion.indexOf("5.01") == (-1))?1:0;
//Detectar el navegador explorer 5.5
swIE55 = (navigator.appVersion.indexOf("5.5") != -1)?1:0;
//Se detecta si es opera
esOpera = (navigator.userAgent.indexOf("Opera") !=-1)?1:0;
esOpera9 = 0;
if(esOpera){ esOpera9 = (navigator.appVersion.indexOf("9")!=-1)? 1:0; }

	//esOpera9 = (navigator.appVersion.indexOf("Opera") !=-1)?1:0;

//Es Internet Explorer version 7.0
swIE70 = (navigator.appVersion.indexOf("7.0") == (-1))?1:0;
//Es Mac
swMac = (navigator.userAgent.indexOf("Macintosh") != (-1))?1:0;


		
// devuelve un array con todos los objetos que tengan la clase que se le pase como parametro (className)
// y esten contenidos dentro del contenedor especificado (container) que puede ser un literal o el propio objeto. Si no se le pasa este parametro, buscara dentro del contenedor "wrapper"
document.getElementsByClassName = function(className, container){
   var data = tags = [];
   var obj = document.getElementById("wrapper");
   var node = aux = null;		
	if(container) node = (typeof(container) == "object") ? container : document.getElementById(container);
	else node = (obj) ? obj : document;		   
	aux = node.getElementsByTagName("*");		
	tags = (document.all) ? node.all : aux;	
   for(var i=0;i<tags.length;i++) { if(tags[i].className == className || tags[i].className.indexOf(className) != -1) data[data.length]=tags[i];}
   return data;
}

var e = {
	addEvent : function(obj, evType, fn, useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evType, fn, useCapture);
			return true;
		}else if (obj.attachEvent){
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		}else {
			return false;
		}
	}
}
var realPosition={
	getLeft:function(objeto){
		xPos=objeto.offsetLeft;
		tempEl=objeto.offsetParent;
		while(tempEl!=null){
			xPos +=tempEl.offsetLeft;
			tempEl =tempEl.offsetParent;
		}
		return xPos;
	},
	getTop: function(objeto){
		yPos=objeto.offsetTop;
		tempEl=objeto.offsetParent;
		while(tempEl!=null){
			yPos +=tempEl.offsetTop;
			tempEl=tempEl.offsetParent;
		}
	return yPos;
	}
}

var cartografia = {
	init:function(url,windowName,windowProperties,url2){
		var nav = (esIE && esOpera==0)? true:false;
		if(nav){
			popUp.openWindowUser(url, windowName, windowProperties);
		}else{
			properties = "left=100,top=100,width=750,height=450";
			popUp.openWindowUser(url2,"requisitos",properties);
		}
	}
}

var navigationCombos={
	validaCmb:function(id){
		var form = document.getElementById(id);		
		var cmb = form.getElementsByTagName("select")[0];
		var sel= cmb[cmb.selectedIndex].value;				
		
		if (sel=="-1"){
			//cmb.setAttribute("class","backValidacion");
			cmb.style.backgroundColor = "#fdcd07";
			return false;
		}
		return true;
	}
}

var popUp = {
	winn : null, 	 
	openWindow : function (cual, scrol, wid, heig, windowName, atributos){ 
		var LeftP, TopP, wid, heig;
		var caracteristicas = "";
		
		LeftP = (screen.width) ? (screen.width-wid) / 2 : 0; 
		TopP = (screen.height) ? (screen.height-heig) / 2 : 0; 
		if(popUp.winn){ 
			if(!popUp.winn.closed) popUp.winn.close(); 
			popUp.winn = null; 
		}
		if(!windowName) windowName = "";
		if(atributos){
			caracteristicas = "Directories=yes, Location=yes , Menubar=yes, Status=yes, Titlebar=yes, Toolbar=yes,"
		}
		
		window.focus(); 
		popUp.winn=eval("open('"+cual+"','"+windowName+"','"+caracteristicas+"width="+wid+",height="+heig+",top="+TopP+",left="+LeftP+",scrollbars="+scrol+",resizable=yes')");  
	},
	openWindowUser : function (cual, windowName, properties){ 		
		popUp.winn=eval("open('"+cual+"','"+windowName+"','"+properties+"')");  
	},
	checkExternalLinks:function() { 		
		 if (!document.getElementsByTagName) return; 
		 var anchors = document.getElementsByTagName("a"); 		 
		 for(var i = 0; i < anchors.length; i++)
			   if (anchors[i].getAttribute("href") &&  anchors[i].getAttribute("rel") == "popup") 
			   		anchors[i].target = "_blank"; 		 
	},
	openParent:function(cual){
		window.opener.document.location.href = cual;
		self.close();
	},
	pintoHerramientas:function(){
		var layHerramientas = document.getElementById("headPopup");
		var listElement= document.createElement("ul");
		
		var liElementPrint = document.createElement("li");
		liElementPrint.className = "print";
		
		var lnkPrint = document.createElement("a");
		lnkPrint.setAttribute("href","#");	
		lnkPrint.onclick = function(){
			window.print();
			return false;
		}
		lnkPrint.appendChild(document.createTextNode(literal["Imprimir"]));
		liElementPrint.appendChild(lnkPrint);
		

		var liElementClose = document.createElement("li");
		liElementClose.className = "close";
		liElementClose.id = "cerrar";

		var lnkClose = document.createElement("a");
		lnkClose.setAttribute("href","#");	
		lnkClose.onclick = function(){
			window.close();
			return false;
		}
		lnkClose.appendChild(document.createTextNode(literal["Cerrar"]));
		liElementClose.appendChild(lnkClose);
		
		listElement.appendChild(liElementPrint);
		listElement.appendChild(liElementClose);

		layHerramientas.appendChild(listElement);
	}
}

var frmModifyDir={
	setEvent:function(){
		var cmoElem = document.getElementById("nPais");
		if(cmoElem.options[cmbo.returnSelItem(cmoElem)].value=="1"){
			document.getElementById("nProvincia").disabled = false;
		}else{
			document.getElementById("nProvincia").disabled = true;
		}
		
		cmoElem.onchange = function(){
			if(cmoElem.options[cmbo.returnSelItem(cmoElem)].value=="1"){
				document.getElementById("nProvincia").disabled = false;
			}else{
				var cmoElemProv = document.getElementById("nProvincia");
					cmoElemProv.options[0].selected = "selected";
					document.getElementById("nProvincia").disabled = true;
			}
		}		
	}
}

var frmNewAcount={
	frmArr: [
		["nDireccion","nCiudad","nProvincia","nCP","nPais"],
		["nDireccionF","nCiudadF","nProvinciaF","nCPF","nPaisF","grupoDirF"],
		["nDireccionE","nCiudadE","nProvinciaE","nCPE","nPaisE","grupoDirE"]
	],
	setEvent:function(){
		var cmoElem = document.getElementById("nPais");
			cmoElem.onchange = function(){
				if(cmoElem.options[cmbo.returnSelItem(cmoElem)].value=="1"){
					document.getElementById("nProvincia").disabled = false;
				}else{ document.getElementById("nProvincia").disabled = true; }
			}		

		var cmoElemF = document.getElementById("nPaisF");
		cmoElemF.onchange = function(){
			if(cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value=="1"){
				document.getElementById("nProvinciaF").disabled = false;
			}else{ document.getElementById("nProvinciaF").disabled = true; }
		}

		var cmoElemE = document.getElementById("nPaisE");
		cmoElemE.onchange = function(){
			if(cmoElemE.options[cmbo.returnSelItem(cmoElemE)].value=="1"){
				document.getElementById("nProvinciaE").disabled = false;
			}else{ document.getElementById("nProvinciaE").disabled = true; }
		}
	
	
		/************ Funcionalidad de los checkbox ***************/
		var objCheck1 = document.getElementById("nDireccionHF");
			objCheck1.onclick = function(){
				checkStatus = frmNewAcount.getStatus(objCheck1);
				if(checkStatus){
					frmNewAcount.form2form(1);
					frmNewAcount.disabElems(1,true)
				}else{
					frmNewAcount.disabElems(1,false);
					if(cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value!="1"){
						document.getElementById("nProvinciaF").disabled = true;
					}else{document.getElementById("nProvinciaF").disabled = false;}
				}
			}
			
		var objCheck2 = document.getElementById("nDireccionHE");
			objCheck2.onclick = function(){
				checkStatus = frmNewAcount.getStatus(objCheck2);
				if(checkStatus){
					frmNewAcount.form2form(2);
					frmNewAcount.disabElems(2,true)
				}else{
					frmNewAcount.disabElems(2,false);
					if(cmoElemE.options[cmbo.returnSelItem(cmoElemE)].value!="1"){
						document.getElementById("nProvinciaE").disabled = true;
					}else{document.getElementById("nProvinciaE").disabled = false;}
				}
		}
		//frmNewAcount.delItems();
		frmNewAcount.disabCBO();
		var specialValue = document.getElementById("datosEspeciales1").value.split("#");
		var newSpecial = "";
		var almoadilla = "";
		for(var i=0; i<specialValue.length; i++){
			if( specialValue[i].indexOf("checkSpecialElem") != -1 ){
				specialValue[i] = "specialValidations.valPais(0)~Ha de seleccionar un País en la dirección de facturación~nPaisF";
			}
			almoadilla = (i!=specialValue.length-1)? "#":"";
			newSpecial = newSpecial+specialValue[i]+almoadilla;
		}
		newSpecial = newSpecial+"#specialValidations.valPoblacion(0)~Ha de rellenar el campo Población en la dirección de facturación~nCiudadF#specialValidations.valProvincia(0)~Al seleccionar España ha de seleccionar una Provincia en la dirección de facturación~nProvinciaF#specialValidations.valCodPostal(0)~Ha de rellenar el campo Código Postal en la dirección de facturación~nCPF#specialValidations.valDir(0)~Ha de rellenar el campo Dirección en la dirección de facturación~nDireccionF";
		newSpecial = newSpecial+"#specialValidations.valPais(1)~Ha de seleccionar un País en la dirección de envío~nPaisE#specialValidations.valPoblacion(1)~Ha de rellenar el campo Población en la dirección de envío~nCiudadE#specialValidations.valProvincia(1)~Al seleccionar España ha de seleccionar una Provincia en la dirección de envío~nProvinciaE#specialValidations.valCodPostal(1)~Ha de rellenar el campo Código Postal en la dirección de envío~nCPE#specialValidations.valDir(1)~Ha de rellenar el campo Dirección en la dirección de envío~nDireccionE";
		document.getElementById("datosEspeciales1").value = newSpecial;
	},	
	disabCBO:function(){
		var cmoElem = document.getElementById("nPais");
		var valueCMBO = cmoElem.options[cmbo.returnSelItem(cmoElem)].value;	
		
		var cmoElemF = document.getElementById("nPaisF");
		var valueCMBOF = cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value;	

		var cmoElemE = document.getElementById("nPaisE");
		var valueCMBOE = cmoElemE.options[cmbo.returnSelItem(cmoElemE)].value;	

		
		if(valueCMBO!=1)
			document.getElementById("nProvincia").disabled = true;
			
		if(valueCMBOF!=1)
			document.getElementById("nProvinciaF").disabled = true;
			
		if(valueCMBOE!=1)
			document.getElementById("nProvinciaE").disabled = true;
	},	
	delItems:function(){
		var obj = document.getElementById("imageField");
		var parentObj = obj.parentNode;
		parentObj.removeChild(obj);
		
		var obj = document.getElementById("imageFieldF");
		var parentObj = obj.parentNode;
		parentObj.removeChild(obj);

		var obj = document.getElementById("imageFieldE");
		var parentObj = obj.parentNode;
		parentObj.removeChild(obj);
		
	},
	form2form:function(num){
		document.getElementById(frmNewAcount.frmArr[num][0]).value = document.getElementById(frmNewAcount.frmArr[0][0]).value;
		document.getElementById(frmNewAcount.frmArr[num][1]).value = document.getElementById(frmNewAcount.frmArr[0][1]).value;
		document.getElementById(frmNewAcount.frmArr[num][3]).value = document.getElementById(frmNewAcount.frmArr[0][3]).value;
		document.getElementById(frmNewAcount.frmArr[num][2]).options[cmbo.returnSelItem(document.getElementById(frmNewAcount.frmArr[0][2]))].selected = "selected";
		document.getElementById(frmNewAcount.frmArr[num][4]).options[cmbo.returnSelItem(document.getElementById(frmNewAcount.frmArr[0][4]))].selected = "selected";
	},
	disabElems:function(elem,statusElem){
		for(var i=0; i<frmNewAcount.frmArr[elem].length-1; i++){
			document.getElementById(frmNewAcount.frmArr[elem][i]).disabled = statusElem;
		}
		
		var displayGrupo = (statusElem==true)? "none":"block";
		document.getElementById(frmNewAcount.frmArr[elem][5]).style.display = displayGrupo;
	},
	getStatus:function(elem){
		return elem.checked;
	}
}

var orderStep={
	setEvent:function(){
		var lnkChange = document.getElementById("confirmElemPrice");
		var numCboDelete = document.getElementById("txtNumCount").value;
		
		lnkChange.parentNode.removeChild(lnkChange);
		
		for(var i=0; i<numCboDelete; i++){
			var elemCBO = document.getElementById("countElem"+i);
			var elemImput = document.createElement("input");
				elemImput.name = "countElem"+i;
				elemImput.id = "countElem"+i;
				
				elemImput.className = "txtCount";
				elemImput.value = elemCBO.options[cmbo.returnSelItem(elemCBO)].value;
				elemImput.maxLength = "2";
				elemImput.onchange = function(){ orderStep.calPrice(this.id); }
				if(navigator.appName == "Netscape"){
					elemImput.onkeypress = function(event){
						var charCode = event.which;
						if (charCode == 13){ return false; }					
					}
				}else{
					elemImput.onkeypress = function(e){
						var charCode = event.keyCode;
						if (charCode == 13){ return false; }					
					}
				}
			
			elemCBO.parentNode.appendChild(elemImput);
			elemCBO.parentNode.removeChild(elemCBO);
			
		}
	},
	calPrice:function(thisElem){
		var thisElem = document.getElementById(thisElem);
	
		var arrPrice = document.getElementById("priceH").value.split("#");
		var totalPrice = 0;
		var priceSumElem = 0;
		var str=""; 
		var i=-1; 
		
		if(isNaN(thisElem.value) || (thisElem.value<=0)) thisElem.value = "1";
		
		while(thisElem.value.charAt(++i)=="."); 
			str=thisElem.value.substring(i,thisElem.value.length); 
		
		thisElem.value = str;
		
		for(var i=0; i<arrPrice.length; i++){
			totalPrice = totalPrice + document.getElementById("countElem"+i).value * arrPrice[i];
			priceSumElem = document.getElementById("countElem"+i).value * arrPrice[i];
			
			
			priceSumElem = Math.round(priceSumElem*100)/100;
			priceSumElem = priceSumElem.toString();
			priceSumElem = priceSumElem.replace(".",",");
			priceSumElem = orderStep.setZero(priceSumElem);
			
			document.getElementById("tdPriceElem"+i).innerHTML = "<strong>"+priceSumElem+" &euro;</strong>";
			document.getElementById("price"+i).value = priceSumElem.replace(",",".");
		}
		
		totalPrice = Math.round(totalPrice*100)/100;
		totalPrice = totalPrice.toString();
		totalPrice = totalPrice.replace(".",",");
		totalPrice = orderStep.setZero(totalPrice);
		
		document.getElementById("elemPriceFinal").innerHTML = "Total: "+totalPrice+" &euro;";
		
		return false;
	},
	returnEvent:function(e){
		var charCode = (navigator.appName == "Netscape")? e.which:e.keyCode;
		alert("charCode: "+charCode);
		if (charCode == 13){
			
			alert("ENTRO")
			return false
		}
	},
	setZero:function(num){
		var numSplit = num.split(",");
		if(numSplit.length==1){ num = num+",00"; }
		else{ if(numSplit[1].length==1){ num = num+"0"; } }
		return num;
	}
}
// Validaciones especificas de formularios
var specialValidations = {
	arrCampos: [
		["nPaisF","nCiudadF","nProvinciaF","nCPF","nDireccionF","nDireccionHF"],
		["nPaisE","nCiudadE","nProvinciaE","nCPE","nDireccionE","nDireccionHE"]
	],

	// formularios nuevo usuario
	checkPassword:function(){
		var statusComp = document.forms.newAcount.password.value == document.forms.newAcount.repassword.value;
		if(statusComp==false){
			document.forms.newAcount.password.value = "";
			document.forms.newAcount.repassword.value = "";
		}
		return (document.forms.newAcount.password.value == document.forms.newAcount.repassword.value)
	},
	newPassword:function(){
	
		var actPassword = document.getElementById("actPassword").value;
		if(actPassword!=""){
			if( (document.forms.newAcount.password.value=="") || (document.forms.newAcount.repassword.value=="")){
				return false;
			}else{
				var statusComp = document.forms.newAcount.password.value == document.forms.newAcount.repassword.value;
				if(statusComp==false){
					document.forms.newAcount.password.value = "";
					document.forms.newAcount.repassword.value = "";
				}
				return statusComp;
			}	
		}else{
			if( (document.forms.newAcount.password.value=="") && (document.forms.newAcount.repassword.value=="") )
			{
				return true;
			}else {
				return false;
			}
		}
		return true;
	},
	checkProvincia:function(){
		var cmoElem = document.getElementById("nPais");
		var valueCMBO = cmoElem.options[cmbo.returnSelItem(cmoElem)].value;
		
		if(valueCMBO==1){
			var cboProvincia = document.getElementById("nProvincia");
			if(cboProvincia.options[cmbo.returnSelItem(cboProvincia)].value==-1){
				return false;
			}
		}
		return true;
	},
	checkSpecialElem:function(){
		var arrCampos = [
			["nPaisF","nCiudadF","nProvinciaF","nCPF","nDireccionF"],
			["nPaisE","nCiudadE","nProvinciaE","nCPE","nDireccionE"]
		];
		
		if(document.getElementById("nDireccionHF").checked==false){
			var cmoElemF = document.getElementById("nPaisF");
			var valueCMBOF = cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value;
		
			if(valueCMBOF==1){
				var cboProvinciaF = document.getElementById("nProvinciaF");
				if(cboProvinciaF.options[cmbo.returnSelItem(cboProvinciaF)].value==-1){
					return false;
				}
			}
			
			if(document.getElementById(arrCampos[0][1]).value==""){ return false; }
			if(document.getElementById(arrCampos[0][3]).value==""){ return false; }
			else{ if(document.getElementById(arrCampos[0][3]).value.length>7){ return false; } else if(valida.esTexto(document.getElementById(arrCampos[0][3]).value)==false) { return false; } }
			if(document.getElementById(arrCampos[0][4]).value==""){ return false; }
		}
		
		if(document.getElementById("nDireccionHE").checked==false){
			var cmoElemE = document.getElementById("nPaisE");
			var valueCMBOE = cmoElemE.options[cmbo.returnSelItem(cmoElemE)].value;
		
			if(valueCMBOE==1){
				var cboProvinciaE = document.getElementById("nProvinciaE");
				if(cboProvinciaE.options[cmbo.returnSelItem(cboProvinciaE)].value==-1){
					return false;
				}
			}
		
			if(document.getElementById(arrCampos[1][1]).value==""){ return false; }
			else{ if(document.getElementById(arrCampos[1][3]).value.length>7){ return false; } else if(valida.esTexto(document.getElementById(arrCampos[1][3]).value)==false) { return false; } }
			if(document.getElementById(arrCampos[1][4]).value==""){ return false; }
		}
		return true;
	},
	valPais:function(numElem){
		if(document.getElementById(specialValidations.arrCampos[numElem][5]).checked==false){
			var cmoElemF = document.getElementById(specialValidations.arrCampos[numElem][0]);
			var valueCMBOF = cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value;
			if(valueCMBOF==-1){ return false; }
		}
		return true;
	},
	valPoblacion:function(numElem){
		if(document.getElementById(specialValidations.arrCampos[numElem][5]).checked==false){
			if(document.getElementById(specialValidations.arrCampos[numElem][1]).value==""){ return false; }
		}	
		return true;
	},
	valProvincia:function(numElem){
		if(document.getElementById(specialValidations.arrCampos[numElem][5]).checked==false){
			var cmoElemF = document.getElementById(specialValidations.arrCampos[numElem][0]);
			var valueCMBOF = cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value;
	
			if(valueCMBOF==1){
				var cboProvinciaF = document.getElementById(specialValidations.arrCampos[numElem][2]);
				if(cboProvinciaF.options[cmbo.returnSelItem(cboProvinciaF)].value==-1){
					return false;
				}
			}
		}	
		return true;
	},
	valCodPostal:function(numElem){
		if(document.getElementById(specialValidations.arrCampos[numElem][5]).checked==false){
			if(document.getElementById(specialValidations.arrCampos[numElem][3]).value==""){
				return false;
			}else{
				if(document.getElementById(specialValidations.arrCampos[numElem][3]).value.length>7){
					return false;
				}else if(valida.esTexto(document.getElementById(specialValidations.arrCampos[numElem][3]).value)==false){
					return false;
				}
			}
		}	
		return true;
	},
	valDir:function(numElem){
		if(document.getElementById(specialValidations.arrCampos[numElem][5]).checked==false){
			if(document.getElementById(specialValidations.arrCampos[numElem][4]).value==""){ return false; }
		}	
		return true;
	},
	checkProvincia:function(){
		var cmoElemF = document.getElementById("nPais");
		var valueCMBOF = cmoElemF.options[cmbo.returnSelItem(cmoElemF)].value;
		
		if(valueCMBOF==1){
			var cboProvinciaF = document.getElementById("nProvincia");
			if(cboProvinciaF.options[cmbo.returnSelItem(cboProvinciaF)].value==-1){
				return false;
			}
		}
		return true;
	},
	checkConfirm:function(){
		var chkConfirm = document.getElementById("aceptaTrat").checked;
		return chkConfirm;
	}
}

/* Funcion que carga la direccion en la ventana padre */
var openerParent={
	setEvent:function(thisURL){
		window.opener.location.href = thisURL;
		self.close();
	}
}

/* Utilizamos esta funcion para retornar el elemento seleccionado en el combo box */
var cmbo={
	returnSelItem:function(cboID){
		for(var i=0; i<cboID.length; i++){
			if(cboID.options[i].selected){
				return [i];
			}
		}
	}
}

/* Elemento de impresion para las pantallas */
var getPrint={
	pageLoad:function(){
		var obj = document.getElementById("printElem");
		var listElement= document.createElement("ul");
			listElement.className = "printPage";
		
		var liElementPrint = document.createElement("li");
		var lnkPrint = document.createElement("a");
		lnkPrint.href = "#";	
		lnkPrint.onclick = function(){
			window.print();
			return false;
		}
		lnkPrint.appendChild(document.createTextNode(literal["Imprimir"]));
		liElementPrint.appendChild(lnkPrint);
		
		listElement.appendChild(liElementPrint);
		obj.appendChild(listElement);

		
	}
}

var layEventInfo= {
	getAbsolutePos:function(el) {
		var SL = 0, ST = 0;
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft)
			SL = el.scrollLeft;
		if (is_div && el.scrollTop)
			ST = el.scrollTop;
		var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
		if (el.offsetParent) {
			var tmp = this.getAbsolutePos(el.offsetParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	},
	getVisib:function(obj){
		var value = obj.style.visibility;
		if (!value) {
			if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
					value = document.defaultView.
						getComputedStyle(obj, "").getPropertyValue("visibility");
			} else if (obj.currentStyle) { // IE
				value = obj.currentStyle.visibility;
			} else
				value = '';
		}
		return value;
	},
	visivilityElem:function(elItem,status){
		/********** Funcionalidad ocultar elementos ************/
		var tags = new Array("applet", "iframe", "select");
		var el = elItem;
		
		var p = layEventInfo.getAbsolutePos(el);
		
		var EX1 = p.x;
		var EX2 = el.offsetWidth + EX1;
		var EY1 = p.y;
		var EY2 = el.offsetHeight + EY1;
		
		for (var k = tags.length; k > 0; ) {
			var ar = document.getElementsByTagName(tags[--k]);
			var cc = null;
			
			for (var i = ar.length; i > 0;) {
				cc = ar[--i];
				p = layEventInfo.getAbsolutePos(cc);
				
				var CX1 = p.x;
				var CX2 = cc.offsetWidth + CX1;
				var CY1 = p.y;
				var CY2 = cc.offsetHeight + CY1;
				
				if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
					if (!cc.__msh_save_visibility) {
						cc.__msh_save_visibility = layEventInfo.getVisib(cc);
					}
					cc.style.visibility = cc.__msh_save_visibility;
				} else {
					if (!cc.__msh_save_visibility) {
						cc.__msh_save_visibility = layEventInfo.getVisib(cc);
					}
					cc.style.visibility = (status==1)? "visible":"hidden";
				}
			}
		}
	
	}
	
}

var changeRoot={
	load:function(){
		var initRoot = "http://www14."
		var root1 = document.getElementById("Ds_Merchant_MerchantUrlOK").value;
		var root2 = document.getElementById("Ds_Merchant_MerchantUrlKO").value;
		var rootPrincipal = window.location.href;

		if(rootPrincipal.substring(0,13) == initRoot){
			document.getElementById("Ds_Merchant_MerchantUrlOK").value = "http://www14.aena.es"+root1.substring(18,root1.length);
			document.getElementById("Ds_Merchant_MerchantUrlKO").value = "http://www14.aena.es"+root2.substring(18,root2.length)
		}
	}
}

var popEnlarge={
	setEvent:function(){
		var minTamW = 300;
		var tamH    = (screen.height==600)? 454:550;
		var imgEl = document.getElementById("enlargeImg");
			imgElW = imgEl.offsetWidth;
			imgElH = imgEl.offsetHeight;
			
			if(imgElH<minTamW){ window.resizeTo(minTamW+20,tamH) }
			else{ window.resizeTo(imgElW+100,tamH); }
	}
}

var analytics = {
	
	load:function(){
		var htmlBody=document.getElementsByTagName("body")[0];
		var imgElement = document.createElement("img");
		imgElement.className = "imgAnalytics";
			if(sensorUri!=0){
				imgElement.src  = sensorUri;
				htmlBody.appendChild(imgElement);
			}
	
	}
}

/***********************************************************************************************************************/
/****************************************                                       ****************************************/
/****************************************           FUNCIONALIDADES AJAX        ****************************************/
/****************************************                                       ****************************************/
/***********************************************************************************************************************/
var msj={
	titLay:"",
	hrefLay:"",
	getMsj:function(typeMsj,thisElem){
		var titLay = "Título opcional";
		//Prueba
		msj.createLay(thisElem,typeMsj);
		
		if( (typeMsj==0) || (typeMsj==3) ) msj.titLay=literal["litGastos"];
		else if (typeMsj==1) msj.titLay=literal["litDirFac"];
		else msj.titLay=literal["litDirEnv"];

		var locationPage = document.location.href;
			locationPage = locationPage.split("?");
		
		
		var cidElem = thisElem.href.split("nota=");
		var cidElem02 = cidElem[1].split("&");
			
		var uri = locationPage[0]+"?nota="+cidElem02[0]+"&pagename=VentaPublicaciones/AJAX/GastosEnvio_VP&Language="+idioma;
		ajax.conection(uri,"msj.alertContent")
			
		msj.hrefLay = thisElem.href;
		//var arrPrueba = [titLay,"<p>Lorem ipsum dolor sit amet, ligula sed dolor non aenean tincidunt. Dui duis in congue sit justo, aliquam mattis orci luctus euismod sed, in sed morbi diam libero, ante vitae dignissim bibendum habitasse est.</p><p>Adipiscing porta ad placerat convallis id at, sed mauris. Maecenas ullamcorper. Sit dignissim. Nibh pede diam nulla dis ac.</p>",thisElem.href];
		//msj.paintLay(arrPrueba);
		
	},
	alertContent:function(){
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				var xmldoc = http_request.responseXML;
				var root_node = xmldoc.getElementsByTagName('item');
				msj.paintLay(root_node);
			} else {
				alert('There was a problem with the request.');
			}
		}
	},
	createLay:function(thisElem,typeMsj){
		if(!load.existeId("infoLay")){
			var obj = document.getElementById("wrapper");
			var infoLay = document.createElement("div");
				infoLay.id = "infoLay";			
			obj.appendChild(infoLay);			
		}
		var objLayInfo = document.getElementById("infoLay");
		var clickElemPos = layEventInfo.getAbsolutePos(thisElem);
		
		clickElemPos.y = clickElemPos.y +15;
		clickElemPos.x = (typeMsj==3)? clickElemPos.x-160:clickElemPos.x;
		
		objLayInfo.style.top = clickElemPos.y+"px";
		objLayInfo.style.left = clickElemPos.x+"px";
		objLayInfo.style.display = "block";
	},
	paintLay:function(elementoXML){
		var txt = "";
			txt+="<div class='bodyInfoLay'>";
				txt+="<div class='bodyClose'><a href='#' onclick='msj.closeLay();return false;'>"+literal["Cerrar"]+"</a></div>";
				txt+="<div class='bodyInfo'>";
						txt+="<p class='titInfo'><strong>"+msj.titLay+"</strong></p>";
						txt+="<p>"+elementoXML[0].childNodes[0].firstChild.nodeValue+"</p>";
						txt+="<ul><li><a href='"+msj.hrefLay+"'>"+literal["litMasInfo"]+"</a></li></ul>";
				txt+="</div>";
			txt+="</div>";
	
		document.getElementById("infoLay").innerHTML = txt;
		layEventInfo.visivilityElem(document.getElementById("infoLay"),0);
	},
	closeLay:function(){
		var objLayInfo = document.getElementById("infoLay");
		
		layEventInfo.visivilityElem(objLayInfo,1);
		objLayInfo.style.display = "none";
	}
}			

/* FUNCION PARA REALIZAR LAS LLAMDAS AJAX */

/* Formato del XML resultante
<channel>
	<item>
		<literal>0</literal>
	</item>
</channel>
*/

var ajax={
	conection:function(uri,nameAlerts){
		http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
		
		var urlLista = uri;
		eval("http_request.onreadystatechange = "+nameAlerts);
		http_request.open('GET', urlLista, true);
		http_request.send(null);	
	}
}
/***********************************************************************************************************************/
/****************************************                                       ****************************************/
/****************************************           FUNCIONALIDADES AJAX        ****************************************/
/****************************************                                       ****************************************/
/***********************************************************************************************************************/

/* ASIGNACION DE EVENTOS */
var load={
	existeId:function(cid){
		if(document.getElementById(cid)) return true;
		return false;
	},
	existeClass:function(className){
		var content = document.getElementById("content");
		var existsClass = false;
		if(content){			
			if(content.className.indexOf(className) != -1) existsClass = true;
		}	
		return existsClass;		
	},
	existeClassPop:function(className){
		var content = document.getElementById("contentPopup");
		var existsClass = false;
		if(content){			
			if(content.className.indexOf(className) != -1) existsClass = true;
		}	
		return existsClass;		
	},	
	existeName:function(cname){
		if(document.getElementsByName(cname)) return true;
		return false;
	},		
	setEvents:function(){
		popUp.checkExternalLinks();
		// Formulario de nueva cuenta
		if(load.existeId("newAcount")) frmNewAcount.setEvent();

		// Formulario de nueva cuenta
		if(load.existeId("modifyDir")) frmModifyDir.setEvent();

		// generacion para las validaciones de los formularios
		if(load.existeId("datosValidacion1") || load.existeId("datosDependencias1") 
			|| load.existeId("datosEspeciales1")) valida.generacionAutomatica();
		
		//impresion
		if(load.existeId("printElem")) getPrint.pageLoad();
		
		// Pintamos el listado de imprimir y cerrar
		if(load.existeId("headPopup")) popUp.pintoHerramientas();
		
		
		// Formulario Pedido
		if(load.existeId("frmOrederStep")) orderStep.setEvent();
		

		if(document.getElementsByClassName("msjGasto").length>0){
			var elemGastomsj = document.getElementsByClassName("msjGasto"); 
			for(var i=0; i<elemGastomsj.length; i++){
				elemGastomsj[i].onclick = function(){
					msj.getMsj(0,this);
					return false;
				}
			}
		}
		
		if(document.getElementsByClassName("msjGastoLat").length>0){
			var elemGastoLatmsj = document.getElementsByClassName("msjGastoLat"); 
			for(var m=0; m<elemGastoLatmsj.length; m++){
				elemGastoLatmsj[m].onclick = function(){
					msj.getMsj(3,this);
					return false;
				}
			}
		}
		
		
		
		if(document.getElementsByClassName("msjDirFac").length>0){
			var elemDirFacmsj = document.getElementsByClassName("msjDirFac"); 
			for(var j=0; j<elemDirFacmsj.length; j++){
				elemDirFacmsj[j].onclick = function(){
					msj.getMsj(1,this);
					return false;
				}
			}
		}
		
		if(document.getElementsByClassName("msjDirEnv").length>0){
			var elemDirEnvmsj = document.getElementsByClassName("msjDirEnv"); 
			for(var k=0; k<elemDirEnvmsj.length; k++){
				elemDirEnvmsj[k].onclick = function(){
					msj.getMsj(2,this);
					return false;
				}
			}
		}
		
		if(load.existeId("enlargeImg")){popEnlarge.setEvent();}
		
		if(load.existeId("password")){
			document.getElementById("password").value="";
		}
		if(load.existeId("repassword")){
			document.getElementById("repassword").value="";
		}
		
		if( (load.existeId("frmOrederStep2")) && (load.existeId("Ds_Merchant_MerchantUrlOK")) ){
			changeRoot.load();
		}		
		analytics.load();		
	}
}
if(W3CDOM) e.addEvent(window, "load", load.setEvents, false);
