var id_producto;
var myrules = { 
   '.producto' : function(el){
      el.onclick = function(){
	  	
		id_producto= this.id.substr(9,this.id.length);
	  	$detalles = document.getElementById('contenedor_detalles');
		$altura = $detalles.offsetHeight;
	  	if($altura<300){
			t1 = new Tween($detalles.style,'height',Tween.elasticEaseOut,$altura,300,1,'px');
			t1.start();
			t1.onMotionFinished = function(){
				cargar('contenedor_detalles','ficha_producto.php','id='+id_producto);
			}
		} else {
			cargar('contenedor_detalles','ficha_producto.php','id='+id_producto);
		}
        // this.parentNode.removeChild(this); 
         return false; 
      }
	  el.onmouseover = function(){
	  	this.style.border ='2px solid #000000';
		return false;
	  }
	  el.onmouseout = function(){
	  	this.style.border ='2px solid #FFFFFF';
		return false;
	  } 
   },
   '#cerrar_ficha' : function(el){
   		el.onclick = function(el){
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
		}
   },
   '#boton_buscar' : function(el){
   		el.onclick = function(el){
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			$producto = document.getElementById('catalogo_productos').value;
			$formato =  document.getElementById('catalogo_formato').value;
			$talla = document.getElementById('catalogo_talla').value;
			cargar('listado','listado.php','producto='+$producto+'&formato='+$formato+'&talla='+$talla);			
		}
		el.onmouseover = function(el){
			this.src='imagenes/boton_buscar-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_buscar.gif';
		}
   },
    '#add_row' : function(el){
   		el.onclick = function(el){
			$tabla = document.getElementById('tabla_carrito');
			$n_filas =$tabla.rows.length;
			var $fila=$tabla.insertRow($n_filas-2);
			var $columna1 = $fila.insertCell(0);
			var $columna2 = $fila.insertCell(1);
			var $columna3 = $fila.insertCell(2);
			var $columna4 = $fila.insertCell(3);
			$columna1.innerHTML = 'Aqui el nombre';
			$columna2.innerHTML = 'Aqui la talla';
			$columna3.innerHTML = 'Aqui el precio';
			$columna4.innerHTML = 'Borrar';
			//alert("hola");
		}
   },
   '#boton_carrito': function(el){
   		el.onclick = function(el){
			$tallas= getElementsByClassName('radio_formulario');
			for (var i=0; i<$tallas.length; i++) {
				if ($tallas[i].checked){var $id=$tallas[i].value;}
			}
			if($id==undefined){
				alert("Indica una talla");
			}else{
				$listado= document.getElementById('listado_referencias');
				var $opcion = document.createElement("option");
				var params='';
				$opcion.innerHTML=$id;
				$opcion.value =$id;
				$listado.appendChild($opcion);
				for (var ind=0; ind<$listado.length; ind++) {
					//alert($listado[ind].value);
					params=params+"producto"+ind+"="+$listado[ind].value+"&";
				}
				//alert(params);
				cargar('contenedor_detalles','carrito.php',params);
			}
		}
		el.onmouseover = function(el){
			this.src='imagenes/boton_comprar-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_comprar.gif';
		}
   },
    '#boton_amigo': function(el){
   		/*el.onclick = function(el){
			//alert(el.fab);
			//window.open("recomendar.php","recomendar",'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=400');
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
		}*/
		el.onmouseover = function(el){
			this.src='imagenes/boton_amigo-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_amigo.gif';
		}
   },
    '#boton_comprar': function(el){
   		el.onclick = function(el){
			$total= (document.getElementById('precio_total').value)*1;
			if($total<15){
				alert("Lo sentimos, El pedido minimo es de 15€");
			}else{
				cargar('contenedor_detalles','formulario_compra.htm',null);
			}
			
		}
		el.onmouseover = function(el){
			this.src='imagenes/boton_comprar-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_comprar.gif';
		}
   },
    '#boton_volver': function(el){
   		el.onclick = function(){
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML="<div id='cargando'>Cargando...<br/><img src='imagenes/cargando.gif' /></div>"
			$altura = $detalles.offsetHeight;

			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,300,2,'px');
			t1.start();
			t1.onMotionFinished = function(){
				//cargar('contenedor_detalles','ficha_producto.php','id='+id_producto);
				$listado= document.getElementById('listado_referencias');
				var $opcion = document.createElement("option");
				var params='';
				for (var ind=0; ind<$listado.length; ind++) {params=params+"producto"+ind+"="+$listado[ind].value+"&";}
				cargar('contenedor_detalles','carrito.php',params);
			}
		}
		el.onmouseover = function(el){
			this.src='imagenes/boton_volver-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_volver.gif';
		}
   },
    '#boton_seguirmirando': function(el){
   		el.onclick = function(el){
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
		}
		el.onmouseover = function(el){
			this.src='imagenes/boton_seguirmirando-over.gif';
		}
		el.onmouseout = function(el){
			this.src='imagenes/boton_seguirmirando.gif';
		}
   },
   '.borrar_carrito': function(el){
   		el.onmouseover =function(el){
			this.style.backgroundColor="#EEEEEE";
			this.style.textDecoration ="line-through";
			this.style.cursor="pointer";
		}
		el.onmouseout =function(el){
			this.style.backgroundColor="#FFFFFF";
			this.style.textDecoration ="none";
		}
		el.onclick = function(el){
			//alert(this.id);
			$listado= document.getElementById('listado_referencias');
			$listado.remove(this.id);
			var params='';
			for (var ind=0; ind<$listado.length; ind++) {
				params=params+"producto"+ind+"="+$listado[ind].value+"&";
			}
			cargar('contenedor_detalles','carrito.php',params);
		}
   },
   '#info_agotado': function(el){
	   el.onmouseover=function(el){
		$aviso=document.getElementById('aviso');
		$aviso.style.display="block";
	  }
	  el.onmouseout=function(el){
		$aviso=document.getElementById('aviso');
		$aviso.style.display="none";
	  }
   },
   '.talla_agotada': function(el){
	   el.onmouseover=function(el){
		$formato=document.getElementById('catalogo_formato');
		$formato_index=$formato.selectedIndex;
		$formato_texto=$formato.options[$formato_index].text;
		//   
		$aviso=document.getElementById('aviso2');
		$aviso.style.display="block";
		$aviso.style.left="475px";
		$aviso.style.top=this.offsetTop+10+"px";
		$aviso.innerHTML="<p><br><strong>Pulsa aqui para obtener:</strong></p>"+$formato_texto+'<p><br><strong>Disponibles en la talla:</strong></p>'+this.id;
		//alert(this.offsetTop);
	  }
	  el.onmouseout=function(el){
		$aviso=document.getElementById('aviso2');
		$aviso.style.display="none";
	  }
	  el.onclick = function(el){
		  $aviso=document.getElementById('aviso2');
		 $formato=document.getElementById('catalogo_formato').value;
		$detalles = document.getElementById('contenedor_detalles');
		$detalles.innerHTML='';
		$altura = $detalles.offsetHeight;
		t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
		t1.start();
		cargar('listado','listado.php','&formato='+$formato+'&talla='+this.id);
		$aviso.style.display="none";
	}
   },   
   '#f_telefono' : function(el){
   		el .onkeyup = function(el){
			$numeros=new Array('0','1','2','3','4','5','6','7','8','9');
			$caracter=this.value[this.value.length-1];
			if($numeros.indexOf($caracter)==-1){
				$cadena=this.value;
				this.value= $cadena.substr(0,($cadena.length)-1);
			};
		}
   },
   '#f_cp' : function(el){
   		el .onkeyup = function(el){
			$numeros=new Array('0','1','2','3','4','5','6','7','8','9');
			$caracter=this.value[this.value.length-1];
			if($numeros.indexOf($caracter)==-1){
				$cadena=this.value;
				this.value= $cadena.substr(0,($cadena.length)-1);
			};
		}
   },
    '#boton_enviar': function(el){
   		el.onclick = function(el){
			//cargar('contenedor_detalles','formulario_compra.htm',null);
			$listado= document.getElementById('listado_referencias');
			$nombre= document.getElementById("f_nombre");
			$nombre.style.backgroundColor="#FFFFFF";
			$apellidos= document.getElementById("f_apellidos");
			$apellidos.style.backgroundColor="#FFFFFF";
			$direccion= document.getElementById("f_direccion");
			$direccion.style.backgroundColor="#FFFFFF";
			$poblacion= document.getElementById("f_poblacion");
			$poblacion.style.backgroundColor="#FFFFFF";
			$cp= document.getElementById("f_cp");
			$cp.style.backgroundColor="#FFFFFF";
			$pais=document.getElementById("f_pais");
			$telefono= document.getElementById("f_telefono");
			$telefono.style.backgroundColor="#FFFFFF";
			$email= document.getElementById("f_email");
			$email.style.backgroundColor="#FFFFFF";
			$password= document.getElementById("f_password");
			$password.style.backgroundColor="#FFFFFF";
			$repassword= document.getElementById("f_repassword");
			$repassword.style.backgroundColor="#FFFFFF";
			
			
			function trim(stringToTrim) {	return stringToTrim.replace(/^\s+|\s+$/g,"");	}
			function ltrim(stringToTrim) {return stringToTrim.replace(/^\s+/,"");}
			function rtrim(stringToTrim) {return stringToTrim.replace(/\s+$/,"");}
			if(trim($nombre.value)==''){alert('Indicanos tu nombre, por favor');$nombre.style.backgroundColor="#FF0000";return;}
			if(trim($apellidos.value)==''){alert('Indicanos tus apellidos, por favor');$apellidos.style.backgroundColor="#FF0000";return;}
			if(trim($direccion.value)==''){alert('Necesitamos una dirección para enviarte el pedido');$direccion.style.backgroundColor="#FF0000";return;}
			if(trim($poblacion.value)==''){alert('Indicanos la población, para ayudar al mensajero. Gracias');$poblacion.style.backgroundColor="#FF0000";return;}
			if(trim($email.value)==''){alert('Es necesario el e-mail para poder ponernos en contacto en caso necesario');$email.style.backgroundColor="#FF0000";return;}
			if(!isValidEmail($email.value)){alert("El email que has escrito no es correcto, por favor revisalo");$email.style.backgroundColor="#FF0000";return;}
			if(trim($password.value)==''){alert('Escribe una contraseña(y apuntala), la necesitaras mas adelante');$password.style.backgroundColor="#FF0000";return;}
			if(trim($repassword.value)==''){alert('Upss!! te falta poner de nuevo la contraseña');$repassword.style.backgroundColor="#FF0000";return;}
			if($password.value!=$repassword.value){alert('no coinciden las contraseñas, asegurate de escribirlas bien');$password.style.backgroundColor="#FF0000";$repassword.style.backgroundColor="#FF0000";return;}
			
			var params='';
			for (var ind=0; ind<$listado.length; ind++) {
				params=params+"producto"+ind+"="+$listado[ind].value+"&";
			}
			params= params +"nombre="+$nombre.value;
			params= params +"&apellidos="+$apellidos.value;
			params= params +"&direccion="+$direccion.value;
			params= params +"&poblacion="+$poblacion.value;
			params= params +"&cp="+$cp.value;
			params= params +"&pais="+$pais.options[$pais.selectedIndex].value;
			params= params +"&telefono="+$telefono.value;
			params= params +"&email="+$email.value;
			params= params +"&password="+$password.value;
			//alert(params);
			cargar('contenedor_detalles','alta_y_pedido.php',params);
			
		}
   },
   '#boton_enviar_r' : function(el){
   		el.onclick = function(){
			function trim(stringToTrim) {	return stringToTrim.replace(/^\s+|\s+$/g,"");	}
			function ltrim(stringToTrim) {return stringToTrim.replace(/^\s+/,"");}
			function rtrim(stringToTrim) {return stringToTrim.replace(/\s+$/,"");}
			$email=document.getElementById("r_email");
			$password=document.getElementById("r_password");
			$listado= document.getElementById('listado_referencias');
			// comprobar que no esten vacios!!!!!!!
			if(trim($email.value)==''){alert('El campo email esta vacio');return;}
			if(trim($password.value)==''){alert('El campo contraseña esta vacio');return;}
			var params='';
			for (var ind=0; ind<$listado.length; ind++) {
				params=params+"producto"+ind+"="+$listado[ind].value+"&";
			}
			$resultado=check_registrado($email.value,$password.value,params);
		}
   },
   '#menu_camisetas' : function(el){
   		el.onclick = function(){
			$formato =  document.getElementById('catalogo_formato');
			$formato.options[1].selected=true;
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------
			cargar('listado','listado.php','formato=1&producto=');
		}
   },
  '#menu_ofertas' : function(el){
   		el.onclick = function(){
		//------ cerrar ficha ------------
		$detalles = document.getElementById('contenedor_detalles');
		$detalles.innerHTML='';
		$altura = $detalles.offsetHeight;
		t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
		t1.start();
		//--------------------------------
		cargar('listado','grupos.php','id_grupo=2');
	}
   },
  '#menu_novedades' : function(el){
   		el.onclick = function(){
		//------ cerrar ficha ------------
		$detalles = document.getElementById('contenedor_detalles');
		$detalles.innerHTML='';
		$altura = $detalles.offsetHeight;
		t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
		t1.start();
		//--------------------------------
		cargar('listado','grupos.php','id_grupo=1');
		//alert("opción aun no disponible");
	}
   }, 
   '#menu_complementos' : function(el){
   		el.onclick = function(){
			$formato =  document.getElementById('catalogo_formato');
			$formato.options[1].selected=true;
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------			
			cargar('listado','listado.php','formato=11&producto=');
		}
   },
   '#menu_quienes' : function(el){
   		el.onclick = function(){
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------			
			cargar('listado','quienes.html',null);
		}
   },
   '#menu_contacto' : function(el){
   		el.onclick = function(){
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------			
			cargar('listado','contacto.html',null);
		}
   },
      '#menu_tallas' : function(el){
   		el.onclick = function(){
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------			
			cargar('listado','tallas.html',null);
		}
   },
   '#menu_carrito' : function(el){
   		el.onclick = function(){
			$detalles = document.getElementById('contenedor_detalles');
			$altura = $detalles.offsetHeight;

			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,300,2,'px');
			t1.start();
			t1.onMotionFinished = function(){
				//cargar('contenedor_detalles','ficha_producto.php','id='+id_producto);
				$listado= document.getElementById('listado_referencias');
				var $opcion = document.createElement("option");
				var params='';
				for (var ind=0; ind<$listado.length; ind++) {params=params+"producto"+ind+"="+$listado[ind].value+"&";}
				cargar('contenedor_detalles','carrito.php',params);
			}
		}
   },
      '#menu_suscribete' : function(el){
   		el.onclick = function(){
			//$email = document.getElementById('email_suscripcion');
			//if(!isValidEmail($email.value)){alert("El email que has escrito no es correcto, por favor revisalo");$email.style.backgroundColor="#FF0000";return;}
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------
			cargar('listado','suscribete.html',null);
		}
   },
    '#menu_costes' : function(el){
   		el.onclick = function(){
			//------ cerrar ficha ------------
			$detalles = document.getElementById('contenedor_detalles');
			$detalles.innerHTML='';
			$altura = $detalles.offsetHeight;
			t1 = new Tween($detalles.style,'height',Tween.strongEaseOut,$altura,0,1,'px');
			t1.start();
			//--------------------------------
			cargar('listado','costes_envio.html',null);
		}
   },
    '#pie_quienes' : function(el){
   		el.onmouseover = function(){
			this.src='imagenes/quien-over.gif';
		}
		el.onmouseout = function(){
			this.src='imagenes/quien.gif';
		}
	},
    '#pie_contacto' : function(el){
   		el.onmouseover = function(){
			this.src='imagenes/contacto-over.gif';
		}
		el.onmouseout = function(){
			this.src='imagenes/contacto.gif';
		}
	},
    '#pie_tallas' : function(el){
   		el.onmouseover = function(){
			this.src='imagenes/tallas-over.gif';
		}
		el.onmouseout = function(){
			this.src='imagenes/tallas.gif';
		}
	},
	'.n_pagina' : function(el){
		el.onclick = function(){
			$n_pagina= this.id.substr(9,this.id.length);
			$valores= this.id.split("-");
			$n_pagina=$valores[1];
			$producto =$valores[2];
			$formato = $valores[3];
			//$producto = document.getElementById('catalogo_productos').value;
			//$formato =  document.getElementById('catalogo_formato').value;
			cargar('listado','listado.php','producto='+$producto+'&formato='+$formato+'&n_pagina='+$n_pagina);
			//alert(id_pagina);
			return;
		}
		el.onmouseover = function(){
			this.style.textDecoration  ='underline';
		}
		el.onmouseout = function(){
			this.style.textDecoration  ='none';
		}
	},
    '.sugerencia_producto' : function(el){
   		el.onmouseover = function(){
			this.style.color="red";
		}
		el.onmouseout = function(){
			this.style.color="#000";
		}
		el.onclick = function(){
			//alert (this.id);
			cargar('listado','listado.php','producto='+$producto);
		}
	},
    '.sugerencia_formato' : function(el){
   		el.onmouseover = function(){
			this.style.color="red";
		}
		el.onmouseout = function(){
			this.style.color="#000";
		}
		el.onclick = function(){
			//alert (this.id);
			cargar('listado','listado.php','formato='+$formato);
		}
	},
    '#boton_suscribirse' : function(el){
		el.onclick = function(){
			$email = document.getElementById('email_suscripcion');
			if(!isValidEmail($email.value)){alert("El email que has escrito no es correcto, por favor revisalo");$email.style.backgroundColor="#FF0000";return;}
			cargar('listado','suscribete_alta.php','correo='+$email.value);
		}
	},
	'#boton_volver_suscripcion' : function(el){
		el.onmouseover = function(){
			//this.style.color="red";
			this.src='imagenes/boton_volver-over.gif';
		}
		el.onmouseout = function(){
			this.src='imagenes/boton_volver.gif';
		}
		el.onclick = function(){
			cargar('listado','listado.php','formato=1');
		}
	}
}; 

Behaviour.register(myrules);