
function nuevoAjax(){  
  var xmlhttp=false; 
  var ids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
  for(var i=0; !xmlhttp && i<ids.length; i++) {
      try{
		xmlhttp = new ActiveXObject(ids[i]);
	  }catch(ex){	
		//alert("i"+i);
    	xmlhttp = false;
	  }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
  	 xmlhttp = new XMLHttpRequest(); 
  }
  return xmlhttp; 
} 

function altaBoletin(usuario, email){
	var xml_doc="";
	div_alerta = document.getElementById('resultado_boletin');
	div_alerta.innerHTML = "<font color='#FF3333'>Hold on a minute please</font><img src='Images/puntos.gif' width='14' height='6' align='absmiddle'>";
	ajax=nuevoAjax(); 
	xml_doc='type_element=boletin&action=insert';
	xml_doc+='&email='+email;
	xml_doc+='&nombre='+usuario;
	for (i=0;i<document.formulario_boletin.idioma.length;i++){
       if (document.formulario_boletin.idioma[i].checked)
          break;
    }
	xml_doc+='&idioma='+document.formulario_boletin.idioma[i].value;
 	var format = "";
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   format = ajax.responseText.split("&");
		    if (format.length>3){
				 if (format[2] == "0"){
					 alert("El email indicado ya se encuentra registrado, por favor, elija otro");
					 div_alerta = document.getElementById('resultado_boletin');
			   		 div_alerta.innerHTML = "<font color='#FF3333'>Already registered e-mail.</font>";
				 }else{
					 div_alerta = document.getElementById('resultado_boletin');
					 div_alerta.innerHTML = "<font color='#FF3333'>Successfully register.</font>";
					 div_alerta = document.getElementById('resultado_boton');
					 div_alerta.innerHTML = "<img src='Images/usuarios-enviar.gif' alt='Send' name='enviar' width='156' height='19' border='0' id='enviar' onMouseOver=\"MM_swapImage('enviar','','Images/usuarios-enviaron.gif',1)\" onMouseOut='MM_swapImgRestore()'>";
				 } 
			}else{
				alert("ko");
			}
		}
	} 
}

function deleteBoletin(email){
	var xml_doc="";
	ajax=nuevoAjax(); 
	xml_doc='type_element=boletin&action=delete';
	xml_doc+='&email='+email;
 	var format = "";
	div_alerta = document.getElementById('resultado_boletin');
	div_alerta.innerHTML = "<font color='#FF3333'>Hold on while we process your drop out</font><img src='Images/puntos.gif' width='14' height='6' align='absmiddle'>";
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   format = ajax.responseText.split("&");
		  // alert(ajax.responseText);
		    if (format.length>3){
				 if (format[2] == "0"){
					 div_alerta = document.getElementById('resultado_boletin');
			   		 div_alerta.innerHTML = "<font color='#FF3333'>An error happen when deleting your register</font>";
				 }else{
					 div_alerta = document.getElementById('resultado_boletin');
					 div_alerta.innerHTML = "<font color='#FF3333'>Register drop out</font>";
					 div_alerta = document.getElementById('resultado_boton');                     
					 div_alerta.innerHTML = "<img src='Images/usuarios-enviar.gif' alt='Enviar' name='enviar1' width='156' height='19' border='0' id='enviar1' onMouseOver=\"MM_swapImage('enviar1','','Images/usuarios-enviaron.gif',1)\" onMouseOut=\"MM_swapImgRestore()\">";
				 } 
			}else{
				alert("ko");
			}
		}
	} 
}

function altaUsuario(){
	//alert("Alta");
	if (!validacion()){
		return false;
	}
	var xml_doc="";
	var datos,contenedor, enlaces;
	//Ajax_divProductos = document.getElementById('divProductos');
	ajax=nuevoAjax(); 
	xml_doc='email='+document.formulario.email.value;
	xml_doc+='&password='+document.formulario.password.value;
	xml_doc+='&nombre='+document.formulario.nombre.value;
	xml_doc+='&primer_apellido='+document.formulario.primer_apellido.value;
	//xml_doc+='&segundo_apellido='+document.formulario.segundo_apellido.value;
	xml_doc+='&fecha_nacimiento='+document.formulario.anio.value+"-"+document.formulario.mes.value+"-"+document.formulario.dia.value;
	xml_doc+='&cp='+document.formulario.cp.value;
	xml_doc+='&ciudad='+document.formulario.ciudad.value;
	xml_doc+='&direccion='+document.formulario.direccion.value;
	xml_doc+='&pais='+document.formulario.pais.value;
	xml_doc+='&profesion='+document.formulario.profesion.value;
	xml_doc+='&donde_n_h_conocido='+document.formulario.donde_n_h_conocido.value;
	xml_doc+='&telefono_movil='+document.formulario.telefono_movil.value;
	
	if ( (document.formulario.sexo[0].checked) ){
		xml_doc+='&sexo=m';
	}else{
		xml_doc+='&sexo=h';
	}
	
	xml_doc+='&boletin_email='+document.formulario.boletin_email.checked;
	xml_doc+='&boletin_sms='+document.formulario.boletin_sms.checked;
	
	//alert(xml_doc);
 	
	ajax.open("POST", "../filtros/usuario_alta_web.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   //alert(ajax.responseText);
		   text = ajax.responseText.split(",");
			if(text.length==2){
				//alert("Usuario repetido");
				 alert("A user with the email you specified already exists.");					 				
				div = document.getElementById('usuario_repetido');
			    div.style.visibility ="visible";
			}else{
				//alert(text[0]);
				div = document.getElementById('usuario_repetido');
			    div.style.visibility ="hidden";
				div = document.getElementById('formulario_alta');
			    div.innerHTML ="";
				div = document.getElementById('texto');
			    div.innerHTML ="Welcome to Lazaro Foods!! You are a registered user, log in an enjoy our products!. You can access your <a href='usuario_login.php'>USER AREA </a> and find out  <a href='usuario_ventajas.php'>the advantages of being a registered user.</a> ";
			}
		   
		}
	} 
}


function updateUsuario(id_usuario){
	//alert("Alta");
	if (!validacionUpdate()){
		return false;
	}
	var xml_doc="";
	var datos,contenedor, enlaces;
	//Ajax_divProductos = document.getElementById('divProductos');
	ajax=nuevoAjax();
	xml_doc+='&id_user='+id_usuario;
	xml_doc+='&password='+ponerAcentos(document.formulario.password.value);
	xml_doc+='&nombre='+ponerAcentos(document.formulario.nombre.value);
	xml_doc+='&primer_apellido='+ponerAcentos(document.formulario.primer_apellido.value);
	//xml_doc+='&segundo_apellido='+ponerAcentos(document.formulario.segundo_apellido.value);
	xml_doc+='&fecha_nacimiento='+document.formulario.fecha_nacimiento.value;
	xml_doc+='&cp='+document.formulario.cp.value;
	xml_doc+='&ciudad='+ponerAcentos(document.formulario.ciudad.value);
	xml_doc+='&direccion='+ponerAcentos(document.formulario.direccion.value);
	xml_doc+='&pais='+ponerAcentos(document.formulario.pais.value);
	xml_doc+='&profesion='+ponerAcentos(document.formulario.profesion.value);
	xml_doc+='&donde_n_h_conocido='+ponerAcentos(document.formulario.donde_n_h_conocido.value);
	xml_doc+='&telefono_movil='+document.formulario.telefono_movil.value;
	xml_doc+='&boletin_email_session='+document.formulario.boletin_email_session.value;
	xml_doc+='&email='+ponerAcentos(document.formulario.email.value);
	//alert(document.formulario.email.value);
	if ( (document.formulario.sexo[0].checked) ){
		xml_doc+='&sexo=m';
	}else{
		xml_doc+='&sexo=h';
	}
	//alert(document.formulario.boletin_email.checked);
	xml_doc+='&boletin_email='+document.formulario.boletin_email.checked;
	xml_doc+='&boletin_sms='+document.formulario.boletin_sms.checked;
	
	//alert(xml_doc);
 	
	div = document.getElementById('formulario_update');
	div.innerHTML ="Updating...";
	
	ajax.open("POST", "../filtros/usuario_update_web.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   //alert(ajax.responseText);
		   text = ajax.responseText.split(",");
			if(text.length==2){
				alert("Already registered user");
			}else{
				alert("Your personal information has been updated.");
				div = document.getElementById('formulario_update');
			    div.innerHTML ="Your personal information has been updated.";
			}
		   
		}
	} 
}


function validacion(){
	if (!isInteger(document.formulario.cp.value)){
		alert("You must enter a zip-code");
		return false;
	}
	if (document.formulario.email.value==""){
		alert("enter your e-mail");
		return false;
	}
	if (document.formulario.email_r.value==""){
		alert("Re-enter your e-mail");
		return false;
	}
	if (document.formulario.password.value==""){
		alert("Enter your password");
		return false;
	}
	if (document.formulario.password_r.value==""){
		alert("Re-enter your password");
		return false;
	}
	if (document.formulario.nombre.value==""){
		alert("Enter your name");
		return false;
	}
	if (document.formulario.primer_apellido.value==""){
		alert("Enter your last name");
		return false;
	}
	/*if (document.formulario.segundo_apellido.value==""){
		alert("Introduzca su segundo apellido");
		return false;
	}*/
	if (document.formulario.direccion.value==""){
		alert("Enter your address");
		return false;
	}
	if (document.formulario.cp.value==""){
		alert("Enter your zip code");
		return false;
	}
	if (document.formulario.email.value!=document.formulario.email_r.value){
		alert("Ensure your e-mail is correct");
		return false;
	}
	if (document.formulario.password.value!=document.formulario.password_r.value){
		alert("Ensure your password is correct");
		return false;
	}
	
	return true;
}

//// INICIO METODOS COMPROBACION DIGITOS





// s es vacio
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// c es un digito
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

//// FIN METODOS COMPROBACION DIGITOS


function validarLogin(){
	if (document.formulario_usuario.username.value == ""){
		alert("Introduce tu login");
		return false;
	}else if (document.formulario_usuario.password.value == ""){
		alert("Introduce tu password");
		return false;
	}
	return true;
}

function validacionUpdate(){
	if (document.formulario.password.value == ""){
		alert("Enter your password");
		return false;
	}
	if (document.formulario.password_r.value == ""){
		alert("Re-enter your password");
		return false;
	}
	if (document.formulario.nombre.value == ""){
		alert("Enter your name");
		return false;
	}
	if (document.formulario.cp.value == ""){
		alert("Re-enter your zip-code");
		return false;
	}
	if (document.formulario.password.value!=document.formulario.password_r.value){
		alert("Ensure your password is correct");
		return false;
	}
	
	return true;
}

function login(url_origen,tokens){
	//alert("1");
	if (validarLogin()){
		var url = "sesion_login.php?";
		url+='username='+document.formulario_usuario.username.value;
		url+='&recordar='+document.formulario_usuario.recordar.checked;
		url+='&password='+document.formulario_usuario.password.value;
		url+='&tokens='+tokens;
		url+='&url_origen='+url_origen;
		//alert(url);
		//url+='&url_origen='+document.formulario_url.url_origen.value;
		goToUrl(url);
	}
}

function loginR(url_origen,tokens){
	//alert("2");
	var url = "sesion_login_receta.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;		
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	goToUrl(url);
}

function loginM(url_origen,tokens){
	//alert("3");
	var url = "sesion_login_menu.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;	
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	//alert(url);
	goToUrl(url);
}

function loginUP(url_origen,tokens){
	var url = "sesion_login_usuario_pedidos.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;	
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	goToUrl(url);
}

function loginDesdeProducto(url_origen,tokens, titulo, descripcion, informacion_nutricional, consejos_preparacion, recetas_asociadas, producto_asociado, testimonios_asociados, promociones_asociadas, id_referencia, id_producto, precio, marca, ahorro, ingredientes, ingrediente_principal, nombre_categoria, peso_neto, peso_escurrido, tipo_categoria ){
	var url = "sesion_login.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;	
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	url+='&titulo='+titulo;
	url+='&descripcion='+descripcion;
	url+='&informacion_nutricional='+informacion_nutricional;
	url+='&consejos_preparacion='+consejos_preparacion;
	url+='&recetas_asociadas='+recetas_asociadas;
	url+='&producto_asociado='+producto_asociado;
	url+='&testimonios_asociados='+testimonios_asociados;
	url+='&promociones_asociadas='+promociones_asociadas;
	url+='&id_referencia='+id_referencia;
	url+='&id_producto='+id_producto;
	url+='&precio='+precio;
	url+='&marca='+marca;
	url+='&ahorro='+ahorro;
	url+='&ingredientes='+ingredientes;
	url+='&ingrediente_principal='+ingrediente_principal;
	url+='&nombre_categoria='+nombre_categoria;
	url+='&peso_neto='+peso_neto;
	url+='&peso_escurrido='+peso_escurrido;
	url+='&tipo_categoria='+tipo_categoria;
	goToUrl(url);
}

function loginDesdeReceta(get,id_receta,url_origen,tokens, id_receta, titulo, numero_personas, dificultad, tiempo_preparacion, ingredientes, ingredientes_t, propiedades, informacion_nutricional, descripcion, video, id_referencia, nombre_categoria, id_categoria, tipo_categoria){
	var url = "sesion_login_receta.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;	
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	url+='&id_receta='+id_receta;
	url+='&titulo='+titulo;
	url+='&numero_personas='+numero_personas;
	url+='&dificultad='+dificultad;
	url+='&tiempo_preparacion='+tiempo_preparacion;
	url+='&ingredientes='+ingredientes;
	url+='&ingredientes_t='+ingredientes_t;
	url+='&propiedades='+propiedades;
	url+='&informacion_nutricional='+informacion_nutricional;
	url+='&descripcion='+descripcion;
	url+='&video='+video;
	url+='&id_referencia='+id_referencia;
	url+='&nombre_categoria='+nombre_categoria;
	url+='&id_categoria='+id_categoria;
	url+='&tipo_categoria='+tipo_categoria;
	url+='&get='+get;
	url+='&id_receta='+id_receta;
	//alert(url);
	goToUrl(url);
}

function loginDesdeMenu(get,id_menu,url_origen,tokens, titulo, descripcion, informacion_nutricional, consejos_preparacion, id_referencia, precio, oferta, categoria, id_categoria){
	var url = "sesion_login_menu.php?";
	url+='username='+document.formulario_usuario.username.value;
	url+='&recordar='+document.formulario_usuario.recordar.checked;	
	url+='&password='+document.formulario_usuario.password.value;
	url+='&tokens='+tokens;
	url+='&url_origen='+url_origen;
	url+='&id_menu='+id_menu;
	url+='&titulo='+titulo;
	url+='&descripcion='+descripcion;
	url+='&id_referencia='+id_referencia;
	url+='&categoria='+categoria;
	url+='&id_categoria='+id_categoria;
	url+='&get='+get;
	url+='&oferta='+oferta;
	url+='&precio='+precio;
	//alert(url);
	goToUrl(url);
}


function login1(modulo){
	var xml_doc="";
	ajax=nuevoAjax(); 
	xml_doc='type_element=user&action=isUserWeb';
	xml_doc+='&username='+document.formulario_usuario.username.value;
	xml_doc+='&password='+document.formulario_usuario.password.value;
	//alert(xml_doc);
 	
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   //alert(ajax.responseText);
		   resultado = ajax.responseText.split("&");
		   if (resultado.length>3){ 
			  var url = "sesion_login.php?";
			  url+='username='+document.formulario_usuario.username.value;
			  url+='&password='+document.formulario_usuario.password.value;
			  url+='&url_origen='+document.formulario_url.url_origen.value;
			  goToUrl(url);
		   	  //location.href = document.formulario_usuario.url_origen.value;
		   }else{
			   alert("Your ID is not correct");
		   }
		  // goToUrl("productos_categoria.php");
		}
	} 
}

function usuario_p(vector){
	var tokens="|";
	for (i=2; i < (vector.length)-1; i++){
		aux = vector[i].split("\$");
		tokens+=aux[10]+"|";
	}
	return tokens;
}


function getSolapaProductoLogin(usuario){
	var tabla ="<table width='400' height='34' border='0' align='right' cellpadding='0' cellspacing='0'";
	tabla+= "background='Images/blog-recetas_000.gif'><tr>";
	tabla+= "<td width='200' class='productos-texto-normal' align='center'>&nbsp;Bienvenido "+usuario+"</td>";
	tabla+= "<td width='200' class='productos-texto-normal' align='center'><a href='logout.php'>Cerrar Sesion</a></td>";
	tabla+= "</tr></table>";
	return tabla;
}

function getSolapaRecetaLogin(usuario){
	var tabla ="<table width='400' height='34' border='0' align='right' cellpadding='0' cellspacing='0'";
	tabla+= "background='Images/blog-recetas_00.gif'><tr>";
	tabla+= "<td width='200' class='marron' align='center'>&nbsp;Bienvenido "+usuario+"</td>";
	tabla+= "<td width='200' class='marron' align='center'><a href='logout.php'>Cerrar Sesion</a></td>";
	tabla+= "</tr></table>";
	return tabla;
}
function getSolapaUsuarioLogin(usuario){
	var tabla ="<table width='400' height='34' border='0' align='right' cellpadding='0' cellspacing='0'";
	tabla+= "background='Images/solapasazuluser.gif'><tr>";
	tabla+= "<td width='200' class='productos-texto-normal' align='center'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bienvenido: "+usuario+"</td>";
	tabla+= "<td width='200' class='marron' align='center'><a href='logout.php'><img src='Images/cerrarazul.gif' width='67' height='13' border=`0` /></a></td>";
	tabla+= "</tr></table>";
	return tabla;
}

///////////////////////////////////    FAVORITOS   ///////////////////////////////////////

function alertaZU(){
	var tabla="<table width='562' height='49' border='0' cellpadding='0' cellspacing='0'>";
	tabla+="<tr><td width='30'>&nbsp;</td>";
	tabla+="<td width='40' class='productos-texto-normal'><img src='Images/estrellamov.gif' width='25' height='25' align='absmiddle'></td>";
	tabla+="<td width='500' class='productos-texto-normal'><span class='azu-bold-peque'>Searching in process</span> <span class='productos-texto-normal'><img src='Images/lupares.gif' width='36' height='42' align='absmiddle'></span></td>";
	tabla+="<td width='37'>&nbsp;</td></tr></table>";
	return tabla;
}

function alertaZU_r(){
	var tabla="<table width='562' height='49' border='0' cellpadding='0' cellspacing='0'>";
	tabla+="<tr><td width='30'>&nbsp;</td>";
	tabla+="<td width='40' class='productos-texto-normal'><img src='Images/estrellatreansmov.gif' width='25' height='25' align='absmiddle'></td>";
	tabla+="<td width='500' class='productos-texto-normal'><span class='azu-bold-peque'>Searching in process </span> <span class='productos-texto-normal'><img src='Images/lupatrans.gif' width='36' height='42' align='absmiddle'></span></td>";
	tabla+="<td width='37'>&nbsp;</td></tr></table>";
	return tabla;
}

function paginacionZU(paginaactual, paginastotales, usuario_p_favoritos, usuario_id){
		var paginaAnterior=parseInt(paginaactual)-1;
		var paginaSiguiente=parseInt(paginaactual)+1;
		var tabla="<tr><td bgcolor='#C0E21B'><table width='300' border='0' align='center' cellpadding='0' cellspacing='0'>";
		tabla+="<td width='19'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/primerouser.gif' onclick=\"mostrarProductosFavoritos('"+usuario_p_favoritos+"','"+usuario_id+"','1');return false;\" name='primer' width='19' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('primer','','Images/primerouserover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='80'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/anterioruser.gif' onclick=\"mostrarProductosFavoritos('"+usuario_p_favoritos+"','"+usuario_id+"','"+paginaAnterior+"');return false;\" name='anter' width='80' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('anter','','Images/anterioruserover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td>";
		tabla+="<td width='73' class='productos-texto-blanco-pequeno'><div align='center'>Page "+paginaactual+" / "+paginastotales+" </div></td>";
		tabla+="<td width='72'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/siguientuser.gif' onclick=\"mostrarProductosFavoritos('"+usuario_p_favoritos+"','"+usuario_id+"','"+paginaSiguiente+"');return false;\" name='sigu' width='72' height='20' border='0' id='sigu' onMouseOver=\"MM_swapImage('sigu','','Images/siguientuserover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='20'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/ultimuser.gif' name='ultim' onclick=\"mostrarProductosFavoritos('"+usuario_p_favoritos+"','"+usuario_id+"','"+paginastotales+"');return false;\" width='20' height='20' border='0' id='ultim' onMouseOver=\"MM_swapImage('ultim','','Images/ultimuserover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a></td>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td></tr>";
		tabla+="</table></td></tr>";
		tabla+= "</tr></table>";
		return tabla;
}

function paginacionZU_m(paginaactual, paginastotales, usuario_m_favoritos, usuario_id){
		var paginaAnterior=parseInt(paginaactual)-1;
		var paginaSiguiente=parseInt(paginaactual)+1;
		var tabla="<tr><td bgcolor='#666504'><table width='300' border='0' align='center' cellpadding='0' cellspacing='0'>";
		tabla+="<td width='19'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/primeromenu.gif' onclick=\"mostrarMenusFavoritos('"+usuario_m_favoritos+"','"+usuario_id+"','1');return false;\" name='primer' width='19' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('primer','','Images/primeromenuover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='80'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/anteriormenu.gif' onclick=\"mostrarMenusFavoritos('"+usuario_m_favoritos+"','"+usuario_id+"','"+paginaAnterior+"');return false;\" name='anter' width='80' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('anter','','Images/anteriormenuover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td>";
		tabla+="<td width='73' class='productos-texto-blanco-pequeno'><div align='center'>Page "+paginaactual+" / "+paginastotales+" </div></td>";
		tabla+="<td width='72'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/siguientemenu.gif' onclick=\"mostrarMenusFavoritos('"+usuario_m_favoritos+"','"+usuario_id+"','"+paginaSiguiente+"');return false;\" name='sigu' width='72' height='20' border='0' id='sigu' onMouseOver=\"MM_swapImage('sigu','','Images/siguientemenuover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='20'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/ultimomenu.gif' name='ultim' onclick=\"mostrarMenusFavoritos('"+usuario_m_favoritos+"','"+usuario_id+"','"+paginastotales+"');return false;\" width='20' height='20' border='0' id='ultim' onMouseOver=\"MM_swapImage('ultim','','Images/ultimomenuover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a></td>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td></tr>";
		tabla+="</table></td></tr>";
		return tabla;
}


function paginacionZU_r(paginaactual, paginastotales, usuario_r_favoritos, usuario_id){
	    var paginaAnterior=parseInt(paginaactual)-1;
		var paginaSiguiente=parseInt(paginaactual)+1;
		var tabla="<tr><td bgcolor='#4c5a0a'><table width='300' border='0' align='center' cellpadding='0' cellspacing='0'>";
		tabla+="<td width='19'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/primerorecet.gif' onclick=\"mostrarRecetasFavoritas('"+usuario_r_favoritos+"','"+usuario_id+"','1');return false;\" name='primer' width='19' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('primer','','Images/primerorecetover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='80'>";
		if (paginaAnterior>0){
			tabla+="<a href='#'><img src='Images/anteriorrecet.gif' onclick=\"mostrarRecetasFavoritas('"+usuario_r_favoritos+"','"+usuario_id+"','"+paginaAnterior+"');return false;\" name='anter' width='73' height='20' border='0' id='anter' onMouseOver=\"MM_swapImage('anter','','Images/anteriorrecetover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td>";
		tabla+="<td width='73' class='productos-texto-blanco-pequeno'><div align='center'>Page"+paginaactual+" / "+paginastotales+" </div></td>";
		tabla+="<td width='72'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/siguienterecet.gif' onclick=\"mostrarRecetasFavoritas('"+usuario_r_favoritos+"','"+usuario_id+"','"+paginaSiguiente+"');return false;\" name='sigu' width='72' height='20' border='0' id='sigu' onMouseOver=\"MM_swapImage('sigu','','Images/siguienterecetover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td><td width='20'>";
		if (paginaSiguiente<=paginastotales){
			tabla+="<a href='#'><img src='Images/ultimorecet.gif' name='ultim' onclick=\"mostrarRecetasFavoritas('"+usuario_r_favoritos+"','"+usuario_id+"','"+paginastotales+"');return false;\" width='20' height='20' border='0' id='ultim' onMouseOver=\"MM_swapImage('ultim','','Images/ultimorecetover.gif',1)\" onMouseOut='MM_swapImgRestore()'></a></td>";
		}else{
			tabla+="&nbsp;";
		}
		tabla+="</td></tr>";
		tabla+="</table></td></tr>";
		return tabla;
}


function deleteMultipleFavoriteElement(usuario_id,ids,paginaABuscar, elementos_favoritos){
	//limpiar();
	var xml_doc;
	var new_usuario_p_favoritos;
	
	ajax=nuevoAjax(); 
	//alert(tokens+"\n"+categoria_propia+"\n"+cuidate);
	xml_doc='type_element=user&action=deleteMultipleFavoriteElement';
	xml_doc+='&tokens='+ids;
	xml_doc+='&id_user='+usuario_id;
	xml_doc+='&name_favorite='+elementos_favoritos;
 	//alert(xml_doc);
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
			//alert(ajax.responseText);
			format = ajax.responseText.split("&");
			aux = format[2].split("\$");
			// En aux[0] deben estar los tokens 
			new_usuario_p_favoritos = aux[0];
			//alert(new_usuario_p_favoritos);
			setSesion(new_usuario_p_favoritos,elementos_favoritos);
			selectAllOptions = false;
			mostrarElementosFavoritos(elementos_favoritos,aux[0],usuario_id,paginaABuscar);
		}
	} 
	
}

function mostrarElementosFavoritos(elementos_favoritos,aux,usuario_id,paginaABuscar){
	 if (elementos_favoritos=="productos_favoritos"){
		  mostrarProductosFavoritos(aux, usuario_id, paginaABuscar);
	 }else if (elementos_favoritos=="recetas_favoritas"){
		  mostrarRecetasFavoritas(aux, usuario_id, paginaABuscar);
	 }else if (elementos_favoritos=="menus_favoritos"){
		  mostrarMenusFavoritos(aux, usuario_id, paginaABuscar);
	 }
}

function setSesion(new_usuario_p_favoritos, elemento){
	var userAgent=navigator.userAgent;
	if (userAgent.indexOf('MSIE') != -1) {
			//alert("new_usuario_p_favoritos: "+new_usuario_p_favoritos);
  			document.frames["iframeOculto"].location = 'sesion_favoritos.php?'+elemento+'=true&tokens='+new_usuario_p_favoritos;
	}else if (userAgent.indexOf('Firefox') != -1){
			parent.iframeOculto.location='sesion_favoritos.php?'+elemento+'=true&tokens='+new_usuario_p_favoritos;
	}
}

function limpiar(){
	/*div_resultados_tabla = document.getElementById('resultados_tabla_s');
	div_resultados_tabla.innerHTML = ""
	
	div_paginacion = document.getElementById('resultados_paginacion');
	div_paginacion.innerHTML = "";
			   		   
	div_resultados = document.getElementById('resultados');
	div_resultados.innerHTML = "";
	
	div_resultados = document.getElementById('div_favoritos');
	div_resultados.innerHTML = "";
	
	div_alerta = document.getElementById('resultados_alerta');
    div_alerta.innerHTML = "";*/
	
	/*div_alerta = document.getElementById('todo');
    div_alerta.innerHTML = "";*/
}


function mostrarProductosFavoritos(usuario_p_favoritos, id_usuario, paginaABuscar){
	//alert(usuario_p_favoritos+" "+id_usuario+" "+paginaABuscar);
	limpiar();
	var xml_doc;
	var datos,contenedor, enlaces;
	var new_usuario_p_favoritos="";
	var paginacion = "";
	var favoritos = "";
	//Ajax_divProductos = document.getElementById('divProductos');
	ajax=nuevoAjax(); 
	//alert(tokens+"\n"+categoria_propia+"\n"+cuidate);
	xml_doc='type_element=product&action=getProductosFavoritosZU';
	xml_doc+='&tokens='+usuario_p_favoritos;
	xml_doc+='&page='+paginaABuscar;
	xml_doc+='&images_bool=true';
	div_alerta = document.getElementById('resultados_alerta');
    div_alerta.innerHTML = alertaZU();
 	//alert(xml_doc);
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
			//alert(ajax.responseText);
		    format = ajax.responseText.split("&");
			//new_usuario_p_favoritos = usuario_p(format);
			//alert(new_usuario_p_favoritos);
		    if (format.length>3){
			   
		// En el array en la posicion 0 esta la pagina actual y en la posicion 1 las paginas totales con el filtro de busqued
			   //alert(text);
			   
				format[0] = format[0].replace(" ","");
				format[0] = format[0].replace("\r","");
				format[0] = format[0].replace("\n","");
				format[0] = format[0].replace("\t","");   
			   
			   div_alerta = document.getElementById('resultados_alerta');
			   //div_alerta.innerHTML = resultadosBusquedaZU("Resultados de la búsqueda");
			   div_alerta.innerHTML = "";
			   
			   //div_resultados_tabla = document.getElementById('resultados_tabla_s');
			   //div_resultados_tabla.innerHTML = tabla_productosZU();
			   text = formatearProductosZU(format);
			   paginacion = paginacionZU(format[0],format[1],usuario_p_favoritos, id_usuario);
			   favoritos = tablaFavoritosZU(id_usuario,paginaABuscar);
			   
			   div_resultados_tabla = document.getElementById('todo');
			   //alert(div_resultados_tabla.innerHTML);
			   div_resultados_tabla.innerHTML = tabla_productosZU(text,paginacion,favoritos);
			   //alert(div_resultados_tabla.innerHTML);

			   //div_paginacion = document.getElementById('resultados_paginacion');
			   //div_paginacion.innerHTML = paginacionZU(format[0],format[1],usuario_p_favoritos, id_usuario);
			   
			   //div_resultados = document.getElementById('resultados');
			   //div_resultados.innerHTML = text;
			   
			   //div_resultados_f = document.getElementById('div_favoritos');
			   //div_resultados_f.innerHTML = tablaFavoritosZU(id_usuario,paginaABuscar);
		   }else{
			   div_alerta = document.getElementById('resultados_alerta');
			   div_alerta.innerHTML = resultadosBusquedaZU("No matches found");
			   div_resultados_tabla = document.getElementById('todo');
			   div_resultados_tabla.innerHTML = "";
		   }
		}
	} 
}

function mostrarMenusFavoritos(usuario_m_favoritos, id_usuario, paginaABuscar){
	//alert(usuario_m_favoritos+" "+id_usuario+" "+paginaABuscar);
	limpiar();
	var xml_doc;
	var datos,contenedor, enlaces;
	var new_usuario_m_favoritos="";
	var paginacion = "";
	var favoritos = "";
	ajax=nuevoAjax(); 
	xml_doc='type_element=menu&action=getMenusFavoritosZU';
	xml_doc+='&tokens='+usuario_m_favoritos;
	xml_doc+='&page='+paginaABuscar;
	xml_doc+='&images_bool=true';
	div_alerta = document.getElementById('resultados_alerta');
    div_alerta.innerHTML = alertaZU();
 	//alert(xml_doc);
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
			//alert(ajax.responseText);
		    format = ajax.responseText.split("&");
		    if (format.length>3){
			   //alert(text);   
				format[0] = format[0].replace(" ","");
				format[0] = format[0].replace("\r","");
				format[0] = format[0].replace("\n","");
				format[0] = format[0].replace("\t","");   
			   
			   div_alerta = document.getElementById('resultados_alerta');
			   div_alerta.innerHTML = "";
			   text = formatearMenusZU(format);
			   paginacion = paginacionZU_m(format[0],format[1],usuario_m_favoritos, id_usuario);
			   favoritos = tablaFavoritosZU_m(id_usuario,paginaABuscar);
			   
			   div_resultados_tabla = document.getElementById('todo');
			   //alert(div_resultados_tabla.innerHTML);
			   div_resultados_tabla.innerHTML = tabla_menusZU(text,paginacion,favoritos);
			   //alert(div_resultados_tabla.innerHTML);
		   }else{
			   div_alerta = document.getElementById('resultados_alerta');
			   div_alerta.innerHTML = resultadosBusquedaZU("No matches found");
			   div_resultados_tabla = document.getElementById('todo');
			   div_resultados_tabla.innerHTML = "";
		   }
		}
	} 
}


function mostrarRecetasFavoritas(usuario_r_favoritos, id_usuario, paginaABuscar){
	limpiar();
	var xml_doc;
	var datos,contenedor, enlaces;
	var paginacion = "";
	var favoritos = "";
	var new_usuario_p_favoritos="";
	//Ajax_divProductos = document.getElementById('divProductos');
	ajax=nuevoAjax(); 
	//alert(tokens+"\n"+categoria_propia+"\n"+cuidate);
	xml_doc='type_element=receta&action=getRecetasFavoritasZU';
	xml_doc+='&tokens='+usuario_r_favoritos;
	xml_doc+='&page='+paginaABuscar;
	xml_doc+='&images_bool=true';
	div_alerta = document.getElementById('resultados_alerta');
    div_alerta.innerHTML = alertaZU_r();
 	//alert(xml_doc);
	ajax.open("POST", "../filtros/ajaxCorella.php",true); 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(xml_doc);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==4) { 
		   // alert(ajax.responseText);
		    format = ajax.responseText.split("&");
			//new_usuario_p_favoritos = usuario_p(format);
			//alert(new_usuario_p_favoritos);
		    if (format.length>3){
			   		   
			// En el array en la posicion 0 esta la pagina actual y en la posicion 1 las paginas totales con el filtro de busqueda

			   //alert(text);
			   
				format[0] = format[0].replace(" ","");
				format[0] = format[0].replace("\r","");
				format[0] = format[0].replace("\n","");
				format[0] = format[0].replace("\t","");   
			   
			   div_alerta = document.getElementById('resultados_alerta');
			   //div_alerta.innerHTML = resultadosBusquedaZU("Resultados de la búsqueda");
			   div_alerta.innerHTML = "";
			   
			   text = formatearRecetasZU(format);
			   paginacion = paginacionZU_r(format[0],format[1],usuario_r_favoritos, id_usuario);
			   favoritos = tablaFavoritosZU_r(id_usuario,paginaABuscar);
			   div_resultados_tabla = document.getElementById('todo');
			   div_resultados_tabla.innerHTML = tabla_recetasZU(text,paginacion,favoritos);   
		   }else{
			   div_alerta = document.getElementById('resultados_alerta');
			   div_alerta.innerHTML = resultadosBusquedaZU_r("No matches found");
			   div_resultados_tabla = document.getElementById('todo');
			   div_resultados_tabla.innerHTML = "";
		   }
		}
	} 
}


function resultadosBusquedaZU(texto){
	var tabla="<table width='562' height='49' border='0' cellpadding='0' cellspacing='0'>";
	tabla+="<tr><td width='30'>&nbsp;</td>";
	tabla+="<td width='40' class='productos-texto-normal'><img src='Images/estrella.gif' width='25' height='25' align='absmiddle'></td>";
	tabla+="<td width='500' class='productos-texto-normal'><span class='productos-texto-normal'>"+texto+"</span> <span class='productos-texto-normal'><img src='Images/lupares.gif' width='36' height='42' align='absmiddle'></span></td>";
	tabla+="<td width='37'>&nbsp;</td></tr></table>";
	return tabla;
}

function resultadosBusquedaZU_r(texto){
	var tabla="<table width='562' height='49' border='0' cellpadding='0' cellspacing='0'>";
	tabla+="<tr><td width='30'>&nbsp;</td>";
	tabla+="<td width='40' class='productos-texto-normal'><img src='Images/estrellatrasn.gif' width='25' height='25' align='absmiddle'></td>";
	tabla+="<td width='500' class='productos-texto-normal'><span class='productos-texto-normal'>"+texto+"</span> <span class='productos-texto-normal'><img src='Images/lupatrans.gif' width='36' height='42' align='absmiddle'></span></td>";
	tabla+="<td width='37'>&nbsp;</td></tr></table>";
	return tabla;
}

function tabla_productosZU(contenidos, paginacion, favoritos){
	var table="<form name='formulario_ch'><table width='532' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="";
	table+="<tr><td width='535' bgcolor='#70A611'><img src='Images/productosfav.gif' width='138' height='19'></td>";
	table+="</tr><tr><td><table width='527' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="<tr><td width='70' valign='top'><img src='Images/imagenre.gif' width='103' height='19'></td>";
	table+="<td width='97' valign='top'><img src='Images/productore.gif' width='251' height='19'></td>";
	table+="<td width='62' valign='top'><img src='Images/preciore.gif' width='50' height='19'></td>";
	table+="<td width='64' valign='top'><img src='Images/comprarre.gif' width='54' height='19'></td>";
	table+="<td width='170' valign='top'><img src='Images/favoritosre.gif' width='70' height='19'></td>";
	table+="</tr></table></td>";
	table+="</tr>";
	table+=contenidos;
	table+=favoritos;
	table+=paginacion;
	table+="</table></form>";
	return table;
}

function tabla_menusZU(contenidos, paginacion, favoritos){
	var table="<form name='formulario_ch'><table width='532' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="";
	table+="<tr><td width='535' bgcolor='#4B1C16'><img src='Images/menusfav.gif' width='138' height='19'></td>";
	table+="</tr><tr><td><table width='527' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="<tr><td width='70' valign='top'><img src='Images/imagenmenus.gif' width='103' height='19'></td>";
	table+="<td width='97' valign='top'><img src='Images/productomenus.gif' width='251' height='19'></td>";
	table+="<td width='62' valign='top'><img src='Images/preciomenus.gif' width='50' height='19'></td>";
	table+="<td width='64' valign='top'><img src='Images/comprarmenus.gif' width='54' height='19'></td>";
	table+="<td width='170' valign='top'><img src='Images/favoritosmenus.gif' width='70' height='19'></td>";
	table+="</tr></table></td>";
	table+="</tr>";
	table+=contenidos;
	table+=favoritos;
	table+=paginacion;
	table+="</table></form>";
	return table;
}

function tabla_recetasZU(contenidos, paginacion, favoritos){
	var table="<form name='formulario_ch'><table width='532' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="";
	table+="<tr><td width='532' bgcolor='#FF7900'><img src='Images/recetasfavoritas.gif' width='125' height='19'></td>";
	table+="</tr><tr><td><table width='532' border='0' align='center' cellpadding='0' cellspacing='1'>";
	table+="<tr><td width='103' valign='top'><img src='Images/imagenre.gif' width='103' height='19'></td>";
	table+="<td width='251' valign='top'><img src='Images/recetare.gif' width='251' height='19'></td>";
	table+="<td width='54' valign='top'><img src='Images/comprarre.gif' width='54' height='19'></td>";
	table+="<td width='70' valign='top'><img src='Images/favoritosre.gif' width='70' height='19'></td>";
	table+="<td width='54' valign='top'><img src='Images/videore.gif' width='50' height='19'></td>";
	table+="</tr></table></td>";
	table+="</tr>";
	
	table+=contenidos;
	table+=favoritos;
	table+=paginacion;
	table+="</table></form>";
	
	return table;
}

function cambio(modulo){
	if (modulo=='producto'){
		div = document.getElementById('formulario_div');
		div.innerHTML = getSolapaProductoLogin(resultado[1]);
	}else  if (modulo=='receta'){
		div = document.getElementById('formulario_div');
		div.innerHTML = getSolapaRecetaLogin(resultado[1]);
	}else  if (modulo=='usuario'){
		div = document.getElementById('formulario_div');
		div.innerHTML = getSolapaUsuarioLogin(resultado[1]);
	}
}

function recuperarAcentos(palabra_old){
	if ( (palabra_old!="") && (palabra_old!=null) && (palabra_old!=undefined) ){
		palabra = palabra_old.replace(/t_20/gi,"ñ");
		palabra = palabra.replace(/t_10/gi,"Ú");
		palabra = palabra.replace(/t_9/gi,"Ó");
		palabra = palabra.replace(/t_8/gi,"Í");
		palabra = palabra.replace(/t_7/gi,"É");
		palabra = palabra.replace(/t_6/gi,"Á");
		palabra = palabra.replace(/t_5/gi,"ú");
		palabra = palabra.replace(/t_4/gi,"ó");
		palabra = palabra.replace(/t_3/gi,"í");
		palabra = palabra.replace(/t_2/gi,"é");
		palabra = palabra.replace(/t_1/gi,"á");
		return palabra;
	}
}

function ponerAcentos(palabra_old){
	palabra = palabra_old.replace(/ñ/gi,"t_20");
	palabra = palabra.replace(/Ú/gi,"t_10");
	palabra = palabra.replace(/Ó/gi,"t_9");
	palabra = palabra.replace(/Í/gi,"t_8");
	palabra = palabra.replace(/É/gi,"t_7");
	palabra = palabra.replace(/Á/gi,"t_6");
	palabra = palabra.replace(/ú/gi,"t_5");
	palabra = palabra.replace(/ó/gi,"t_4");
	palabra = palabra.replace(/í/gi,"t_3");
	palabra = palabra.replace(/é/gi,"t_2");
	palabra = palabra.replace(/á/gi,"t_1");
	return palabra;
}

function redondear(cantidad, decimales) {
	var cantidad = parseFloat(cantidad);
	var decimales = parseFloat(decimales);
	decimales = (!decimales ? 2 : decimales);
	return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
} 

function formatearProductosZU(vector){
	var table ="";
	var table_end ="";
	var table_name ="";
	var table_precio ="";
	var cabecera="";
	var info_carrito = "";
	//var table_begin ="<tr onMouseOver=\"this.style.backgroundColor='#98e347';\" onmouseout=\"'this.style.backgroundColor='\"><td><table width='532' border='0' cellpadding='0' cellspacing='0'>";
	var table_begin ="<tr><td><table width='532' border='0' cellpadding='0' cellspacing='0'>";
	var table_end = "</table></td></tr>";
	/*var table_begin= "<table width='523' border='0' cellspacing='0' cellpadding='0'>";
	table_begin+="<tr bgcolor='#f6fbf1' onMouseOver=\"this.style.backgroundColor='#98e347';\" onmouseout=\"this.style.backgroundColor=''\"";
	table_begin+="onClick=''>";
	table_begin+="<td width='103' bgcolor='#f6fbf1' class='usuario-bordeverdebajo'><img src='Images/pimientosmarron.jpg' width='103' height='64'>";
	table_begin+="</td>";
	table_name="<td  width='248' class='verde-bold-sangrlista'><a href='dsd'>titulo del producto</a></td>";
	table_precio="<td width='68' class='usuario-bordeverdebajo'><div align='center'><span class='dieta-texto-naranja'>12,00&euro;</span></div></td>";
	table_end="<td width='54' align='center' bgcolor='#98e347' class='usuario-bordeverdebajo'><a href='#'";
	table_end+="onMouseOver=\"MM_swapImage('carr','','Images/listacarroon.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src='Images/listacarro.gif' name='carr' width='40' height='25' border='0' id='carr'></a></td>";
	table_end+="<td width='50' align='center' bgcolor='#98e347' class='usuario-bordeverdebajo'><a href='#' onMouseOver='MM_swapImage('favv','','Images/listafavon.gif',1)' onMouseOut='MM_swapImgRestore()'><img src='Images/listafav.gif' name='favv' width='40' height='25' border='0' id='favv'></a></td></tr></table>";
	var param = "";*/
	var aux = new Array();
	//Los beans se devuelven a partir del indice 2 en el array
	var contador=0;
	for (i=2; i < (vector.length)-1; i++){
		aux = vector[i].split("\$");
		cabecera= "'"+recuperarAcentos(aux[0])+"'";
		cabecera+=",'"+recuperarAcentos(aux[1])+"'";
		cabecera+=",'"+recuperarAcentos(aux[2])+"'";
		cabecera+=",'"+recuperarAcentos(aux[3])+"'";
		cabecera+=",'"+recuperarAcentos(aux[4])+"'";
		cabecera+=",'"+recuperarAcentos(aux[5])+"'";
		cabecera+=",'"+recuperarAcentos(aux[6])+"'";
		cabecera+=",'"+recuperarAcentos(aux[7])+"'";
		cabecera+=",'"+recuperarAcentos(aux[8])+"'";
		var split_referencia = recuperarAcentos(aux[9]).split(";");
		cabecera+=",'"+recuperarAcentos(split_referencia[0])+"'";
		cabecera+=",'"+recuperarAcentos(aux[9])+"'";
		cabecera+=",'"+recuperarAcentos(aux[10])+"'";
		cabecera+=",'"+recuperarAcentos(aux[11])+"'";
		cabecera+=",'"+recuperarAcentos(aux[12])+"'";
		cabecera+=",'"+recuperarAcentos(aux[13])+"'";
		cabecera+=",'"+recuperarAcentos(aux[14])+"'";
		cabecera+=",'"+recuperarAcentos(aux[15])+"'";
		//cabecera+=",'"+recuperarAcentos(aux[16])+"'";
		cabecera+=",'"+recuperarAcentos("Favorite product")+"'";
		//cabecera+=",'"+categoria_propia[1])+"'";
		//cabecera+=",'"+recuperarAcentos(aux[18])+"'";
		cabecera+=",'Productos Favoritos'";
		cabecera+=",'"+recuperarAcentos(aux[19])+"'";
		//alert(aux[0]+"\n1"+aux[1]+"\n2"+aux[2]+"\n3"+aux[3]+"\n4"+aux[4]+"\n5"+aux[5]+"\n6"+aux[6]+"\n7"+aux[7]+"\n8"+aux[8]+"\n9"+aux[9]+"\n10"+aux[10]+"\n11"+aux[11]+"\n12"+aux[12]+"\n13"+aux[13]+"\n14"+aux[14]+"\n15"+aux[15]+"\n16"+aux[16]+"\n17"+aux[17]+"\n18"+aux[18]+"\n19"+aux[19]);
		info_carrito = "id_referencia="+recuperarAcentos(aux[9])+"&precio="+recuperarAcentos(aux[11])+"&ahorro="+recuperarAcentos(aux[13])+"&titulo="+recuperarAcentos(aux[0])+"&peso_neto="+recuperarAcentos(aux[17])+"&es_alimento="+recuperarAcentos(aux[19]);
		/*<table width="224" border="0" align="center" cellpadding="0" cellspacing="0">
                            <tr>
                              <td><a href="#"  onClick="goToPC(<?PHP echo $cabecera;?>);"><span class="dieta-texto-verde-bold-sangr"><?PHP echo $titulo;?>pimientos</span></a></td>
                            </tr>
                        </table>*/
		if (split_referencia[1] == "0"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#98e347';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103'><img src='fotosproductos/nodisp.jpg' width='103' height='61'></td>";
		}else if (split_referencia[1] == "1"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#98e347';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103'><img src='fotosproductos/"+split_referencia[0]+".jpg' width='103' height='61'></td>";
		}
		table+="<td width='252' align='center' class='usuario-bordeverdebajo'>";
		table+="<table width='224' border='0' align='center' cellpadding='0' cellspacing='0'>";
		table+="<tr><td>";
		table+="<span class='dieta-texto-verde-bold-sangr'><a href='#' onClick=\"goToPC("+cabecera+");return false;\">"+recuperarAcentos(aux[0])+"</span></a>";
		table+="</td></tr>";
		table+="</table>";
		table+="</td>";
		//if (aux[11]=="lazaro_foods"){aux[11]="0";}
		table+="<td width='52' align='center' class='usuario-bordeverdebajo'><span class='dieta-texto-naranja'><strong>$"+redondear(recuperarAcentos(aux[11]),2)+"</strong></span></td>";
		table+="<td width='56' align='center' bgcolor='#98e347' class='usuario-bordeverdebajo'><a href='tienda_carrito.php?"+info_carrito+"' onMouseOver=\"MM_swapImage('carr"+i+"','','Images/listacarroon.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src='Images/listacarro.gif' name='carr"+i+"' width='40' height='25' border='0' id='carr"+i+"'></a></td>";
		table+="<td width='69' align='center' class='usuario-bordeverdebajo' bgcolor='#98e347'>";
		table+="<div align='center'>";
		table+="<input type='checkbox' name='"+recuperarAcentos(aux[10])+"' value='checkbox' onClick=\"check(this)\";></td>";
		table+="</div></td>";
		table+="</tr>"+table_end;
		/*table+=table_begin+"<td  width='248' class='verde-bold-sangrlista'><a href='#' onClick=\"goToPC("+cabecera+");return false;\">"+aux[0]+"</a></td>";
		table+="<td width='68'  class='usuario-bordeverdebajo'><div align='center'><span class='dieta-texto-naranja'>"+aux[11]+"€</span></div></td>";
		table+="<td width='54' align='center' bgcolor='#98e347' class='usuario-bordeverdebajo'><a href='#'";
		table+="onMouseOver=\"MM_swapImage('carr"+i+"','','Images/listacarroon.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src='Images/listacarro.gif' name='carr"+i+"' width='40' height='25' border='0' id='carr"+i+"'></a></td>";
		//alert(param);		
		table+="<td width='50' align='center' bgcolor='#98e347' class='usuario-bordeverdebajo'><input type='checkbox' name='"+aux[10]+"' value='checkbox' onClick=\"check(this)\";></td>";*/
	}
	 var userAgent=navigator.userAgent;
  	 /*if (userAgent.indexOf('Firefox') != -1) {
		alert("firefox");
		alert(table);
	 }else{
		 alert(userAgent);
	 }*/
	return table;
}

function formatearMenusZU(vector){
	var table ="";
	var table_end ="";
	var table_name ="";
	var table_precio ="";
	var cabecera="";
	var info_carrito = "";
	var table_begin ="<tr><td><table width='532' border='0' cellpadding='0' cellspacing='0'>";
	var table_end = "</table></td></tr>";
	
	var aux = new Array();
	//Los beans se devuelven a partir del indice 2 en el array
	var contador=0;
	for (i=2; i < (vector.length)-1; i++){
		aux = vector[i].split("\|");
		//alert(aux[0]+"\n1"+aux[1]+"\n2"+aux[2]+"\n3"+aux[3]+"\n4"+aux[4]+"\n5"+aux[5]+"\n6"+aux[6]+"\n7"+aux[7]);
		cabecera= "'"+recuperarAcentos(aux[0])+"'";
		cabecera+=",'"+recuperarAcentos(aux[1])+"'";
		cabecera+=",'"+recuperarAcentos(aux[2])+"'";
		cabecera+=",'"+recuperarAcentos(aux[3])+"'";
		cabecera+=",'"+recuperarAcentos(aux[4])+"'";
		cabecera+=",'"+recuperarAcentos(aux[5])+"'";
		var split_referencia = recuperarAcentos(aux[6]).split(";");
		cabecera+=",'"+recuperarAcentos(split_referencia[0])+"'";
		cabecera+=",'"+recuperarAcentos(aux[7])+"'";
		info_carrito = "id_referencia="+recuperarAcentos(split_referencia[0])+"&precio="+recuperarAcentos(aux[2])+"&ahorro="+recuperarAcentos(aux[3])+"&titulo="+recuperarAcentos(aux[1])+"&peso_neto="+recuperarAcentos(aux[4])+"&es_alimento=1";
		if (split_referencia[1] == "0"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#b8b80e';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103'><img src='fotosmenus/nodisp.jpg' width='103' height='61'></td>";
		}else if (split_referencia[1] == "1"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#b8b80e';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103'><img src='fotosmenus/"+split_referencia[0]+".jpg' width='103' height='61'></td>";
		}
		table+="<td width='252' align='center' class='menus-bordeverdebajo'>";
		table+="<table width='224' border='0' align='center' cellpadding='0' cellspacing='0'>";
		table+="<tr><td>";
		table+="<span ><a href='menus.php?"+info_carrito+"' class='verdemenus-bold-sangr'>"+recuperarAcentos(aux[1])+"</span></a>";
		table+="</td></tr>";
		table+="</table>";
		table+="</td>";
		//if (aux[11]=="lazaro_foods"){aux[11]="0";}
		table+="<td width='52' align='center' class='menus-bordeverdebajo'><span class='dieta-texto-naranja'><strong>$"+redondear(recuperarAcentos(aux[2]),2)+"</strong></span></td>";
		table+="<td width='56' align='center' bgcolor='#b8b80e' class='menus-bordeverdebajo'><a href='tienda_carrito.php?"+info_carrito+"' onMouseOver=\"MM_swapImage('carr"+i+"','','Images/carritomenuson.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src='Images/carritomenus.gif' name='carr"+i+"' width='40' height='25' border='0' id='carr"+i+"'></a></td>";
		table+="<td width='69' align='center' class='menus-bordeverdebajo' bgcolor='#b8b80e'>";
		table+="<div align='center'>";
		table+="<input type='checkbox' name='"+recuperarAcentos(aux[0])+"' value='checkbox' onClick=\"check(this)\";></td>";
		table+="</div></td>";
		table+="</tr>"+table_end;
	}
	return table;
}


function formatearRecetasZU(vector){
	var table="";
	var cabecera="";

	var table_begin ="<tr><td><table width='532' border='0' cellpadding='0' cellspacing='0'>";
	var table_end="</table></td></tr>";
	
	var aux = new Array();
	//Los beans se devuelven a partir del indice 2 en el array
	var contador=0;
	var info_carrito = "";
	for (i=2; i < (vector.length)-1; i++){
		aux = vector[i].split("\$");
		//alert(aux);
		cabecera= "'"+recuperarAcentos(aux[0])+"'";
		cabecera+=",'"+recuperarAcentos(aux[1])+"'";
		cabecera+=",'"+recuperarAcentos(aux[2])+"'";
		cabecera+=",'"+recuperarAcentos(aux[3])+"'";
		cabecera+=",'"+recuperarAcentos(aux[4])+"'";
		cabecera+=",'"+recuperarAcentos(aux[5])+"'";
		cabecera+=",'"+recuperarAcentos(aux[6])+"'";
		cabecera+=",'"+recuperarAcentos(aux[7])+"'";
		cabecera+=",'"+recuperarAcentos(aux[8])+"'";
		cabecera+=",'"+recuperarAcentos(aux[9])+"'";
		cabecera+=",'"+recuperarAcentos(aux[10])+"'";
		var split_referencia = recuperarAcentos(aux[11]).split(";");
		cabecera+=",'"+recuperarAcentos(split_referencia[0])+"'";
		cabecera+=",'Favorites recipes'";
		info_carrito = getInfoCarritoRU(aux[5]);
		if (split_referencia[1] == "0"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#b2ca4c';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103'><img src='fotosrecetas/nodisp.jpg' width='103' height='69'></td>";
		}else if (split_referencia[1] == "1"){
			table+=table_begin+"<tr onMouseOver=\"this.style.backgroundColor='#b2ca4c';\" onmouseout='this.style.backgroundColor=\"\"'><td width='103' bgcolor='#f6fbf1'  class='usuario-bordeverdebajo'><img src='fotosrecetas/"+split_referencia[0]+".jpg' width='103' height='69'></td>";
		}
		table+="<td width='251' class='usuario-bordeverdebajo'><a href='#' class='productos-texto-oscuro' onClick=\"goToPC("+cabecera+");return false;\">"+recuperarAcentos(aux[1])+"</a></td>";
		table+="<td width='54' bgcolor='#97b11f' class='usuario-bordeverdebajo' align='center'><a href='tienda_carrito.php?"+info_carrito+"' onMouseOver=\"MM_swapImage('carr4"+i+"','','Images/carrritoon.gif',1);\" onMouseOut=\"MM_swapImgRestore();\"><img src='Images/carrrito.gif' name='carr4"+i+"' width='40' height='25' border='0' id='carr4"+i+"'></a></td>";
		table+="<td width='70' bgcolor='#b2ca4c' class='usuario-bordeverdebajo' align='center'><input type='checkbox' name='"+recuperarAcentos(aux[0])+	"' id='"+recuperarAcentos(aux[0])+"' value='checkbox' onClick=\"check(this)\";></td>";
		if (split_referencia[1] == "0"){
			table+="<td width='50' bgcolor='#97b11f' class='usuario-bordeverdebajo' align='center'>&nbsp;</td>";
		}else if (split_referencia[1] == "1"){
			table+="<td width='50' bgcolor='#97b11f' class='usuario-bordeverdebajo' align='center'><a href='#' onMouseOver=\"MM_swapImage('vid01"+i+"','','Images/videoon.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src='Images/video.gif' name='vid01"+i+"' width='40' height='25' border='0' id='vid01"+i+"' onClick=\"popup('"+recuperarAcentos(aux[1])+"','"+split_referencia[0]+"',760,547,'recetas_video_peq.php');return false;\"></a></td>";
		}
		table+="</tr>"+table_end;
		//alert(table);
	}
	//alert(table);
	return table;
}

function getInfoCarritoRU(carrito){
	var el_split = carrito.split(',');
	//alert("");
	var el_split_1;
	var carrito = "";
	var cont = 0;
	for (k=0;k<el_split.length;k++){
		if ( (el_split[k].indexOf("|"))>0){
			el_split_1 = el_split[k].split("|");
			if (el_split_1[1]!=""){
				cont++;
			}
		}
	}
	var info_carrito= "n_p="+cont;
	cont = 0;
	for (k=0;k<el_split.length;k++){
		if ( (el_split[k].indexOf("|"))>0 ){
			el_split_1 = el_split[k].split("|");
			if (el_split_1[1]!=""){
				cont++;
				info_carrito+= "&id_referencia_"+cont+"="+el_split_1[1]+"&precio_"+cont+"="+el_split_1[2]+"&ahorro_"+cont+"=0&titulo_"+cont+"="+el_split_1[0]+"&peso_neto_"+cont+"="+recuperarAcentos(el_split_1[3])+"&es_alimento_"+cont+"="+recuperarAcentos(el_split_1[4]);
			}
		}
	}
	return info_carrito;
}

function tablaFavoritosZU(usuario_id,paginaABuscar){
	var tabla = "<tr><td bgcolor='#98E347'><table bgcolor='#98E347' width='533' border='0' align='center' cellpadding='0' cellspacing='0'>";
	tabla+= "<form name='form_activacion'>";
	tabla+= "<tr><td width='97' height='25' class='usuario-bordeverdebajo'>&nbsp;</td>";
	tabla+= "<td width='360' height='25' class='usuario-bordeverdebajo'><div align='right' class='productos-texto-blanco-pequeno'>Select all </div></td>";
	tabla+= "<td width='66' height='25' class='usuario-bordeverdebajo'><div align='center'>";
	tabla+= "<input name='manager' type='checkbox' value='' onClick='selectAll();'>";
	tabla+= "</div></td></tr>";
	tabla+= "<tr><td height='50'><div align='right' class='productos-texto-blanco-pequeno'></div></td>";
	tabla+= "<td height='50'><div align='right' class='productos-texto-oscuro'>Remove selected products from favorites</div></td>";
	tabla+= "<td width='66' height='50'><div align='center'>";
	tabla+= "<a href='#' onMouseOver=\"MM_swapImage('favv91','','Images/listafavon.gif',1)\" onMouseOut='MM_swapImgRestore()'>";
	tabla+= "<img src='Images/listafav.gif' name='favv91' width='40' height='25' border='0' id='favv91' onClick=\"actualizarFavoritosZU('"+usuario_id+"','"+paginaABuscar+"','productos_favoritos');return false;\"></a></div></td>";
    tabla+= "</tr></form></table></td></tr>";
	return tabla;
}

function tablaFavoritosZU_m(usuario_id,paginaABuscar){
	var tabla = "<tr><td bgcolor='#B8B80E'><table width='523' border='0' align='center' cellpadding='0' cellspacing='0'>";
	tabla+= "<form name='form_activacion'>";
	tabla+= "<tr><td width='97' height='25' class='menus-bordeverdebajo'>&nbsp;</td>";
	tabla+= "<td width='360' height='25' class='menus-bordeverdebajo'><div align='right' class='productos-texto-blanco-pequeno'>Select all </div></td>";
	tabla+= "<td width='66' height='25' class='menus-bordeverdebajo'><div align='center'>";
	tabla+= "<input name='manager' id='manager' type='checkbox' value='' onClick='selectAll();'>";
	tabla+= "</div></td></tr>";
	tabla+= "<tr><td height='50'><div align='right' class='productos-texto-blanco-pequeno'></div></td>";
	tabla+= "<td height='50'><div align='right' class='productos-texto-oscuro'>Remove selected menus from favorites</div></td>";
	tabla+= "<td width='66' height='50'><div align='center'>";
	tabla+= "<a href='#' onMouseOver= \"MM_swapImage('favv91','','Images/listafavmenuson.gif',1)\" onMouseOut='MM_swapImgRestore()'>";
	tabla+= "<img src='Images/listafavmenus.gif' name='favv91' width='40' height='25' border='0' id='favv91' onClick=\"actualizarFavoritosZU('"+usuario_id+"','"+paginaABuscar+"','menus_favoritos');return false;\"></a></div></td>";
    tabla+= "</tr></form></table></td></tr>";
	return tabla;
}


function tablaFavoritosZU_r(usuario_id,paginaABuscar){
	var tabla = "<tr><td bgcolor='#b2ca4c'><form name='form_activacion'><table width='523' border='0' align='center' cellpadding='0' cellspacing='0'>";
	tabla+= "";
	tabla+= "<tr><td width='97' height='25' class='usuario-bordeverdeoscbajo'>&nbsp;</td>";
	tabla+= "<td width='360' height='25' class='usuario-bordeverdeoscbajo'><div align='right' class='productos-texto-blanco-pequeno'>Select all </div></td>";
	tabla+= "<td width='66' height='25' class='usuario-bordeverdeoscbajo'><div align='center'>";
	tabla+= "<input name='manager' type='checkbox' value='' onClick=\"selectAll();\">";
	tabla+= "</div></td></tr>";
	tabla+= "<tr><td height='50'><div align='right' class='productos-texto-blanco-pequeno'></div></td>";
	tabla+= "<td height='50'><div align='right' class='productos-texto-oscuro'>Remove selected recipes from favorites</div></td>";
	tabla+= "<td width='66' height='50'><div align='center'>";
	tabla+= "<a href='#' onMouseOver=\"MM_swapImage('favv91','','Images/listafavon.gif',1)\" onMouseOut='MM_swapImgRestore()'> ";
	tabla+= "<img src='Images/listafav.gif' name='favv91' width='40' height='25' border='0' id='favv91' onClick=\"actualizarFavoritosZU('"+usuario_id+"','"+paginaABuscar+"','recetas_favoritas');return false;\"></a></div></td>";
    tabla+= "</tr></table></form></td></tr>";
	return tabla;

}


function actualizarFavoritosZU(usuario_id,paginaABuscar, elemento){
	if ( (usuario_id!="") && (usuario_id!=null ) ){ 
		var ids="";
		for (i=0;i<document.formulario_ch.elements.length;i++){
		  if (document.formulario_ch.elements[i].type == "checkbox"){
			  //alert("ck: "+document.formulario_ch.elements[i].name);
			if (document.formulario_ch.elements[i].checked){
				if (document.formulario_ch.elements[i].name!="manager"){
					ids+=document.formulario_ch.elements[i].name+"|";
					//alert(ids);
				}
			}
		  }
		}
		if (ids!=""){
			deleteMultipleFavoriteElement(usuario_id,ids,paginaABuscar,elemento);
		}else{
			alert("There is no selection "+elemento);
		}
	}else{
		alert("You must be registered to add favorite items to your account!");
	}
}