// Menú desplegable ok
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();


// Faq desplegable
 $(document).ready(function()
        {
            $("div> div> div> div> div >  div.faqr:visible").hide();
            $("a.faqt").click(function()
            {
                $("div> div> div> div> div > div >  div.faqr:visible").slideUp();
                var div_medio = $(this).parent();
                var div_inferior_oculto = "div#" + div_medio.attr("id") + " > div:hidden";
                $(div_inferior_oculto).slideDown();
                return false;
            });
        });
		
		
		 $(document).ready(function()
        {
            $("div >  div.faqr:visible").hide();
            $("a.faqt2").click(function()
            {
                $("div >  div.faqr:visible").slideUp();
                var div_medio = $(this).parent();
                var div_inferior_oculto = "div#" + div_medio.attr("id") + " > div:hidden";
                $(div_inferior_oculto).slideDown();
                return false;
            });
        });
// Fin Faq desplegable

function cambiar(esto)
{
	vista=document.getElementById(esto).style.display;
	if (vista=='none')
		vista='block';
	else
		vista='none';

	document.getElementById(esto).style.display = vista;
}



function abrir_ventana (pagina) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1024, height=800";
window.open(pagina,"",opciones);
}

//*********************************************************************************  
// Valida que se seleccione una talla
//*********************************************************************************  
   
//busca caracteres que no sean espacio en blanco en una cadena  
 function vacio(q) {  
        for ( i = 0; i < q.length; i++ ) {  
                 if ( q.charAt(i) != " " ) {  
                         return true  
                 }  
         }  
         return false  
 }  
   
 //valida que el campo no este vacio y no tenga solo espacios en blanco  
 function valida(B) {  
           
	var er_dni = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_nsec = /^([0-9]{3,3})+$/						//numeros, espacios, + o -
	var er_ntarjeta = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
    var er_telefono = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_cp = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -	
	var er_email = /^(.+\@.+\..+)$/ 	
           
    if( vacio(B.talla.value) == false ) 
	{  
        alert("Debe seleccionar una talla.")  
        return false  
    } 




	
	else 
	{   
        return true  
    }  
      
}  



//*********************************************************************************  
// valida el formulario de contacto
//*********************************************************************************  
   
   
 //valida que el campo no este vacio y no tenga solo espacios en blanco  
 function valida2(B) {  
           
	var er_dni = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_nsec = /^([0-9]{3,3})+$/						//numeros, espacios, + o -
	var er_ntarjeta = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
    var er_telefono = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_cp = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -	
	var er_email = /^(.+\@.+\..+)$/ 	
           
    if( vacio(B.nombre.value) == false ) 
	{  
        alert("Debe introducir su nombre.")  
        return false  
    } 
	 if( vacio(B.apellidos.value) == false ) 
	{  
        alert("Debe introducir sus apellidos.")  
        return false  
    } 
	if(!er_email.test(B.mail.value)) { 
		alert('Introduzca un email vÃ¡lido.')
		return false
	}  
	if( !er_telefono.test(B.telefono.value) ) {
		alert('Introduzca un telÃ©fono vÃ¡lido.')
		return false
	}
	 if( vacio(B.asunto.value) == false ) 
	{  
        alert("Debe introducir un asunto.")  
        return false  
    }
	 if( vacio(B.contenido.value) == false ) 
	{  
        alert("Introduzaca su consulta, por favor.")  
        return false  
    } 
	else 
	{   
        return true  
    }  
      
} 


 //valida que el campo no este vacio y no tenga solo espacios en blanco  
 function valida3(B) {  
           
	var er_dni = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_nsec = /^([0-9]{3,3})+$/						//numeros, espacios, + o -
	var er_ntarjeta = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
    var er_telefono = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -
	var er_cp = /^([0-9\s\+\-])+$/						//numeros, espacios, + o -	
	var er_email = /^(.+\@.+\..+)$/ 	
           
    if( vacio(B.nombre.value) == false ) 
	{  
        alert("You have to introduce your name.")  
        return false  
    } 
	 if( vacio(B.apellidos.value) == false ) 
	{  
        alert("You have to introduce your surname.")  
        return false  
    } 
	if(!er_email.test(B.mail.value)) { 
		alert('You have to introduce a valid email.')
		return false
	}  
	if( !er_telefono.test(B.telefono.value) ) {
		alert('You have to introduce a valid phone number.')
		return false
	}
	 if( vacio(B.asunto.value) == false ) 
	{  
        alert("You have to introduce a subject.")  
        return false  
    }
	 if( vacio(B.contenido.value) == false ) 
	{  
        alert("Insert your question, please.")  
        return false  
    } 
	else 
	{   
        return true  
    }  
      
} 

function salir($id)
	  {
           var respuesta=confirm("Si elimina la categoría desaparecerán los productos asociados a dicha categoría.\n ¿Desea continuar de todos modos?");
           if(respuesta==true)
               window.location="eliminar_cat.php?id="+$id;
          else
               return 0;

      }
