// Para crear la lista desplegable de mis deseos
var listasMenu=new Array()
var listas = new String();
function crearListasDesplegable (listas)  {
	listasMenu=listas.split("--");
} 
// Para crear el enlace al que debe irse al pinchar en una lista del desplegable mis deseos
var idLista = new Array();
function crearSubmit(identLista,pName) {
	var idcapa = document.getElementById("productoAnadir").value;
	document.getElementById("nombreProducto").value = pName;
	document.getElementById("giftlistAnadir").value = identLista;
	document.getElementById("deseos-"+idcapa).onsubmit();
}

function crearSubmitListaUnica(identLista,idCapa,pName){
	document.getElementById("nombreProducto").value = pName;
	document.getElementById("productoAnadir").value = idCapa;
	document.getElementById("giftlistAnadir").value = identLista;
	document.getElementById("deseos-"+idCapa).onsubmit();
}

function crearSubmitSinLista(idCapa,pName){
	document.getElementById("nombreProducto").value = pName;
	document.getElementById("productoAnadir").value = idCapa;
	document.getElementById("giftlistAnadir").value = "-1";
	document.getElementById("deseos-"+idCapa).onsubmit();
}

var errorAjax;
function crearMenuDesplegable(obj,e,idCapa){
	document.getElementById("productoAnadir").value = idCapa;
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()

	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	dropmenuobj.innerHTML = "";
	dropmenuobj.innerHTML = document.getElementById("dropmenudivTMP-"+idCapa).innerHTML;

	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden")

		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	return clickreturnvalue()
}

function doConsulta_deseos(formulario) {
	if (document.getElementById("mi_cuenta") != null) {
		// Ponemos el flag a true para saber que es una recarga
		document.getElementById('recarga').value = "true";
		iden = "lista-" + document.getElementById("productoAnadir").value;
		document.getElementById(iden).value = document.getElementById("giftlistAnadir").value
	 var opts = {
	      method:'post',
		  postBody: preparePostData(formulario.id, 'boton'),
		  //onInteractive:mostrarImgLoading_deseos,
		  onSuccess: handleDoConsulta_deseos,
		  on404: handleError_deseos,
		  onFailure: handleError_deseos
	   }
	   var url=document.getElementById(formulario.id).action;
	   new Ajax.Request(url,opts);
   }
}
var mostrarImgLoading_deseos = function(){
	p=$('preload_2');
	p.style.display='inline';
	imagen = new Image();
	imagen.src="images/indicator_arrows.gif"
	p.appendChild(imagen)
	p.innerHTML = p.innerHTML + "  Cargando Datos ..." ;
}

var handleDoConsulta_deseos = function(transport){
	if(!errorAjax){
			p=$('preloadDiv_2');
			pp=$('preload_2');
			d=$('datosDeseos');
			p.style.display='none';
			pp.style.display='none';
			d.style.display='inline';
			d.innerHTML = transport.responseText;
			doConsulta_boton_deseos();
	}
}


function doConsulta_boton_deseos() {
// PARA QUE PINTE EN BLANCO LA CAPA ANTES DE RECARGARLO
 //  var d=$('capaRecargar-'+document.getElementById("productoAnadir").value);
  // d.innerHTML = "";
  if (document.getElementById("mi_cuenta") != null) {
	 var opts = {
	      method:'post',
		  postBody: preparePostData(document.getElementById('formBotonDeseos').id, ''),
		  //onInteractive:mostrarImgLoading_deseos,
		  onSuccess: handleDoConsulta_boton_deseos,
		  on404: handleError_deseos,
		  onFailure: handleError_deseos
	   }
	    new Ajax.Request("/noalimentacion/BotonDeseos.aspx",opts);
   }
}

var handleDoConsulta_boton_deseos = function(transport){
	if(!errorAjax){
			var idcapa = document.getElementById("productoAnadir").value;
			var pName = document.getElementById("nombreProducto").value;
			b=$('capaRecargar-'+ idcapa);
			b.style.display='inline';
			b.innerHTML = transport.responseText;
			document.getElementById("productoAnadir").value = idcapa;
			document.getElementById("nombreProducto").value = pName;
			//para lanzar el mensaje
			var texto = "Se ha incluido " + document.getElementById("nombreProducto").value + " correctamente en su lista de deseos";
			var textoBoton = "Aceptar";
			abrirPopUpAviso(80,200,texto,textoBoton);
			//fin lanzar mensaje
			// si la pagina tiene link se actualiza tambien
			if (document.getElementById("capaRecargarLink-" + idcapa) != null)
			{

				doConsulta_link_deseos()();
			}
	}
}

var hidemenu_onclick="yes" //oculta el men? cuando el usuario "clicka" fuera de ?l

var ie4=document.all
var ns6=document.getElementById&&!document.all



function doConsulta_link_deseos() {
// PARA QUE PINTE EN BLANCO LA CAPA ANTES DE RECARGARLO
// var d=$('capaRecargarLink-'+ document.getElementById("productoAnadir").value);
	if (document.getElementById("mi_cuenta") != null) {
	document.getElementById('recarga').value = "true";
	 var opts = {
	      method:'post',
		  postBody: preparePostData(document.getElementById('formBotonDeseos').id, ''),
		  onSuccess: handleDoConsulta_link_deseos,
		  on404: handleError_deseos,
		  onFailure: handleError_deseos
	   }
	    new Ajax.Request("/noalimentacion/LinkDeseos.aspx",opts);
	}
}

var handleDoConsulta_link_deseos = function(transport){
	if(!errorAjax){
			var idcapa = document.getElementById("productoAnadir").value;
			b=$('capaRecargarLink-'+ idcapa);
			b.style.display='inline';
			b.innerHTML = transport.responseText;

	}
}
var handleError_deseos = function() {
	if(document.getElementById("noEsError")!= null) {
	  if(document.getElementById("noEsError").value!= "true" ){
	     alert("Vuelva a intentarlo en unos minutos o dir\u00edjase \na nuestro Departamento de Atenci\u00f3n al Cliente.");
	     errorAjax = true;
	  }
	}
}

