// JavaScript Document


	function validar()
	{
		
		var exclude=/[^@\-\.\w]|^[@\.\-]|[\.\-]{2}|[@\.]{2}|(@)[^@]*\1/;
		var check=/@[\w\-]+\./;
		var checkend=/\.[a-zA-Z]{2,3}$/;
		var msg;
		
		msg="";
		
		if(document.miform.chkLssi.checked == false)
		{
			alert("Si quiere continuar, debe aceptar el Aviso Legal");
		}//fin if
		
		else
		{		
			if (document.miform.usuario.value.length == 0)
			{
				msg=msg+"Debe introducir un nombre de usuario\n";
			}
			if (document.miform.pass.value.length == 0)
			{
				msg=msg+"Debe introducir una contraseña\n";
			}
			if (document.miform.nombre.value.length == 0)
			{
				msg=msg+"Debe introducir su nombre\n";
			}
			if (document.miform.apellido1.value.length == 0)
			{
				msg=msg+"Debe introducir su primer apellido\n";
			}
			if (document.miform.direccion.value.length == 0)
			{
				msg=msg+"Debe introducir su dirección\n";
			}
			if (document.miform.cpostal.value.length == 0)
			{
				msg=msg+"Debe introducir su código postal\n";
			}
			if (document.miform.poblacion.value.length == 0)
			{
				msg=msg+"Debe introducir su población\n";
			}
			if (document.miform.provincia.selectedIndex == 0)
			{
				msg=msg+"Debe introducir su provincia\n";
			}
			if (document.miform.telefono.value.length == 0)
			{
				msg=msg+"Debe introducir su teléfono\n";
			}
			if (document.miform.email.value.length == 0)
			{
				msg=msg+"Debe introducir su E-mail\n";
			}
			else
			{
				if(((document.miform.email.value.search(exclude) != -1)||(document.miform.email.value.search(check)) == -1)||(document.miform.email.value.search(checkend) == -1))
				{
					msg=msg+"Debe introducir un email correcto\n";
				}//fin if
			}//fin else
			
			if(msg)
			{
				alert(msg);
			}//fin if
			else
			{
				enviar2();
			}//fin else
		}//fin else
	}//fin funcion
	
	function comprobar()
	{
		if(document.miform.pass.value != "" && document.miform.repPass.value != "")
		{
			if(document.miform.pass.value != document.miform.repPass.value)
			{
				alert("Los campos de password deben ser iguales!");
				document.miform.pass.value = "";
				document.miform.repPass.value = "";
				document.miform.pass.focus();
			}//fin if
		}//fin if
	}//fin funcion
	
	function comprobarNgatos(gato)
	{
		if(document.miform.ngatos.value=="" || document.miform.ngatos.value==0)
		{	
			alert("Primero debe decirnos cuántos gatos tiene.");
			document.miform.ngatos.focus();
		}//fin if
		else
		{
			if(document.miform.ngatos.value<gato)
			{
				alert("No tiene tantos gatos.");
				document.miform.ngatos.focus();
			}//fin if
		}//fin else
	}//fin funcion
	
	function validarNumero(n)
	{ 	 
		switch(n)
		{
			case 1:
				if(document.miform.telefono.value!="")
				{
					valor = parseInt(document.miform.telefono.value) ;
				
					if (isNaN(valor))
					{ 
					   alert("\"Teléfono\" debe ser un número!");
					   document.miform.telefono.value="";
					   document.miform.telefono.focus();		   
					}//fin if
				}//fin si
				break;
				
			case 2:
				if(document.miform.movil.value!="")
				{
					valor = parseInt( document.miform.movil.value) ;
				
					if (isNaN(valor))
					{ 
					   alert("\"Móvil\" debe ser un número!");
					   document.miform.movil.value="";
					   document.miform.movil.focus();		   
					}//fin if
				}//fin si
				break;		
			
			case 3:
				if(document.miform.cpostal.value!="")
				{
					valor = parseInt( document.miform.cpostal.value) ;
				
					if (isNaN(valor))
					{ 
					   alert("\"Código postal\" debe ser un número!");
					   document.miform.cpostal.value="";
					   document.miform.cpostal.focus();		   
					}//fin if
				}//fin si
				break;		
				
			case 4:
				if(document.miform.nperros.value!="")
				{
					valor = parseInt( document.miform.nperros.value) ;
				
					if (isNaN(valor))
					{ 
					   alert("\"Número de perros\" debe ser un número!");
					   document.miform.nperros.value="";
					   document.miform.nperros.focus();		   
					}//fin if
				}//fin si
				break;		
				
			case 5:
				if(document.miform.ngatos.value!="")
				{
					valor = parseInt( document.miform.ngatos.value) ;
				
					if (isNaN(valor))
					{ 
					   alert("\"Número de gatos\" debe ser un número!");
					   document.miform.ngatos.value="";
					   document.miform.ngatos.focus();		   
					}//fin if
				}//fin si
				break;		
		}//fin switch
	} //fin funcion
	
	
	function enviar2()
	{
		var i, i2, sw;		
		
		if (document.miform.ngatos.value.length != 0 || document.miform.ngatos.value != 0)
		{
			var arrayDatos = new Array();
			
			for(i=0;i<9;i++)
			{
				arrayDatos[i] = new Array();
			}//fin para
			
			arrayDatos[0][0]=document.miform.nom1.value;
			arrayDatos[0][1]=document.miform.raza1.value;
			document.miform.hdnSexo1.value=getRadioButtonSelectedValue(document.miform.sexo1);
			arrayDatos[0][2]=document.miform.hdnSexo1.value;
			arrayDatos[0][3]=document.miform.mes1.value;
			arrayDatos[0][4]=document.miform.agno1.value;
			
			arrayDatos[1][0]=document.miform.nom2.value;
			arrayDatos[1][1]=document.miform.raza2.value;
			document.miform.hdnSexo2.value=getRadioButtonSelectedValue(document.miform.sexo2);
			arrayDatos[1][2]=document.miform.hdnSexo2.value;
			arrayDatos[1][3]=document.miform.mes2.value;
			arrayDatos[1][4]=document.miform.agno2.value;
			
			arrayDatos[2][0]=document.miform.nom3.value;
			arrayDatos[2][1]=document.miform.raza3.value;
			document.miform.hdnSexo3.value=getRadioButtonSelectedValue(document.miform.sexo3);
			arrayDatos[2][2]=document.miform.hdnSexo3.value;
			arrayDatos[2][3]=document.miform.mes3.value;
			arrayDatos[2][4]=document.miform.agno3.value;
			
			arrayDatos[3][0]=document.miform.nom4.value;
			arrayDatos[3][1]=document.miform.raza4.value;
			document.miform.hdnSexo4.value=getRadioButtonSelectedValue(document.miform.sexo4);
			arrayDatos[3][2]=document.miform.hdnSexo4.value;
			arrayDatos[3][3]=document.miform.mes4.value;
			arrayDatos[3][4]=document.miform.agno4.value;
			
			arrayDatos[4][0]=document.miform.nom5.value;
			arrayDatos[4][1]=document.miform.raza5.value;
			document.miform.hdnSexo5.value=getRadioButtonSelectedValue(document.miform.sexo5);
			arrayDatos[4][2]=document.miform.hdnSexo5.value;
			arrayDatos[4][3]=document.miform.mes5.value;
			arrayDatos[4][4]=document.miform.agno5.value;
			
			arrayDatos[5][0]=document.miform.nom6.value;
			arrayDatos[5][1]=document.miform.raza6.value;
			document.miform.hdnSexo6.value=getRadioButtonSelectedValue(document.miform.sexo6);
			arrayDatos[5][2]=document.miform.hdnSexo6.value;
			arrayDatos[5][3]=document.miform.mes6.value;
			arrayDatos[5][4]=document.miform.agno6.value;
			
			arrayDatos[6][0]=document.miform.nom7.value;
			arrayDatos[6][1]=document.miform.raza7.value;
			document.miform.hdnSexo7.value=getRadioButtonSelectedValue(document.miform.sexo7);
			arrayDatos[6][2]=document.miform.hdnSexo7.value;
			arrayDatos[6][3]=document.miform.mes7.value;
			arrayDatos[6][4]=document.miform.agno7.value;
			
			arrayDatos[7][0]=document.miform.nom8.value;
			arrayDatos[7][1]=document.miform.raza8.value;
			document.miform.hdnSexo8.value=getRadioButtonSelectedValue(document.miform.sexo8);
			arrayDatos[7][2]=document.miform.hdnSexo8.value;
			arrayDatos[7][3]=document.miform.mes8.value;
			arrayDatos[7][4]=document.miform.agno8.value;
			
			numeroGatos = (document.miform.ngatos.value > 8) ? 8 : document.miform.ngatos.value;
			
			for(i=0;i<numeroGatos; i++)
			{
				for (i2=0; i2<5; i2++)
				{
					if(arrayDatos[i][i2]=="" || arrayDatos[i][1]==0)
					{
						sw=1;
						break;
					}//fin if
				}//fin para
			}//fin para
		}//fin si




		for(i=0;i<document.miform.ngatos.value; i++)
		{
			if(arrayDatos[i][4] < 1900 || arrayDatos[i][4] > 2040)
			{
				sw=2;
				break;
			}
		}






		
		if(sw==1)
		{
			alert("Falta algún campo de rellenar de los gatos!");
			sw=0;
		}//fin if
		else if(sw==2)
		{
			alert("El año de nacimiento de tu gato debe tener el formato yyyy.");
			sw=0;
		}
		else
		{
			document.miform.mascotas.value=""; //para asegurarnos que se va a guardar lo que viene ahora sin repeticiones.
			
			if (document.miform.ngatos.value.length != 0 || document.miform.ngatos.value != 0)
			{
				numeroGatos = (document.miform.ngatos.value > 8) ? 8 : document.miform.ngatos.value;
				
				for (i=0; i<numeroGatos; i++)
				{
					for (i2=0; i2<5; i2++)
					{
							document.miform.mascotas.value=document.miform.mascotas.value+arrayDatos[i][i2]+"|";
					}//fin para
					
					document.miform.mascotas.value=document.miform.mascotas.value+";";
				}//fin para	
			}//fin si
			else
			{
				document.miform.ngatos.value=0;
			}//fin else
			
			if(document.miform.chkRevista.checked==false)
			{
				document.miform.suscripcionrevista.value="no";
			}//fin if
			else
			{
				document.miform.suscripcionrevista.value="si";
			}//fin else
			
			document.miform.submit();
		}//fin else
	}//fin funcion
	
	function getRadioButtonSelectedValue(ctrl)
	{
		for(i=0; i<ctrl.length; i++)
		{
			if(ctrl[i].checked) 
			{
				return ctrl[i].value;
			}//fin if
		}//fin for
	}//fin funcion
	
	function mostrarMensajeSuscripcion()
	{
		if(document.miform.chkRevista.checked)
		{
			alert("\"El gato en Casa\" es una revista trimestral que se edita los meses de diciembre, marzo, junio y septiembre. Su suscripción comienza a partir del próximo número.");
		}
	}//fin funcion
	
