function DNIANIF() {
var DNI = document.getElementById('dni').value;
   if (DNI.length > 7 ) {
     verificaDNI(errors);
     document.getElementById('dni').focus();
	 }
}

errors = "";

function ValidaPerro() {
	if ($('Perro').value == "") {
		alert('Introduzca el nombre del perro');
		$('Perro').focus();
		return false;
	}
	if ($('chipPerro').value == "") {
		alert('Introduzca el Chip del perro');
		$('chipPerro').focus();
		return false;
	}
	if ($('edadPerro').value == "") {
		alert('Introduzca la edad del perro');
		$('edadPerro').focus();
		return false;
	}
	if ($('aliasPerro').value == "") {
		alert('Introduzca un alias para personalizar el dorsal');
		$('aliasPerro').focus();
		return false;
	}
	document.getElementById('Submit').disabled=true;
	document.getElementById('Tarjeta').disabled=true;
	document.getElementById('Submit').style.visibility='hidden';
	document.getElementById('Tarjeta').style.visibility='hidden';
	return true;
}

function ValidaPerroEU() {
	if ($('Perro').value == "") {
		alert('Sartu txakurraren izena');
		$('Perro').focus();
		return false;
	}
	if ($('chipPerro').value == "") {
		alert('Sartu txakurraren Chip-a');
		$('chipPerro').focus();
		return false;
	}
	if ($('edadPerro').value == "") {
		alert('Sartu txakurraren urteak');
		$('edadPerro').focus();
		return false;
	}
	if ($('aliasPerro').value == "") {
		alert('Sartu alias bat dortsala pertsonalizatzeko');
		$('aliasPerro').focus();
		return false;
	}
	document.getElementById('Submit').disabled=true;
	document.getElementById('Tarjeta').disabled=true;
	return true;
}

function ValidaPerroFR() {
	if ($('Perro').value == "") {
		alert('Nom du chien');
		$('Perro').focus();
		return false;
	}
	if ($('chipPerro').value == "") {
		alert('Chip du chien');
		$('chipPerro').focus();
		return false;
	}
	if ($('edadPerro').value == "") {
		alert('Âge du chien');
		$('edadPerro').focus();
		return false;
	}
	if ($('aliasPerro').value == "") {
		alert('Entrez un pseudonyme pour personnaliser la dorsale');
		$('aliasPerro').focus();
		return false;
	}
	document.getElementById('Submit').disabled=true;
	document.getElementById('Tarjeta').disabled=true;
	return true;
}

function DNIANIFrances() {
var DNI = document.getElementById('Dni').value;
   if (DNI.length > 7 ) {
     verificaDNIFrances(errors)
     document.form.Apellido1.focus()
   } else {
     document.form.Dni.focus()
   }
}


function verificaDNIFrances(errors) 
{
	var ch = document.getElementById('dni').value;
	var ch = ch.substring(0,9);
	
	if (!/^\d{9}$/.test ( ch ))
	{
		document.getElementById('dni').focus();

		return errors+='- DNI il nest pas correct\n';
	}
	
	var letras = '';
	
	var numero = ch%23;
	var letra = letras.substring(numero,numero+1).toUpperCase();
	document.getElementById('dni').maxLength = 9;
	document.getElementById('dni').value = "" + ch + letra;
	
	return errors;
}

function verificaDNI(errors) 
{
	var ch = document.getElementById('dni').value;
	var ch = ch.substring(0,8);
	if (!/^\d{8}$/.test ( ch ))
	{
		document.getElementById('dni').focus();

		return errors+='- DNI no es correcto\n';
	}
	
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	
	var numero = ch%23;
	var letra = letras.substring(numero,numero+1).toUpperCase();
	var new_dni=ch + letra;
	document.getElementById('dni').maxLength = 9;
	document.getElementById('dni').value = new_dni;
	
	return errors;
}

function verificaDNIEusk(errors) 
{
	var ch = document.getElementById('dni').value;
	var ch = ch.substring(0,8);
	if (!/^\d{8}$/.test ( ch ))
	{
		document.getElementById('dni').focus();

		return errors+='- NAN ez da zuzena\n';
	}
	
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	
	var numero = ch%23;
	var letra = letras.substring(numero,numero+1).toUpperCase();
	var new_dni=ch + letra;
	document.getElementById('dni').maxLength = 9;
	document.getElementById('dni').value = new_dni;
	
	return errors;
}

function selecciona_producto(id) {
	//Ventana padre
	var p=opener.document;
	p.getElementById('club').value=id;
	window.close();
}

function selecciona_dniMarca(id) {
	//Ventana padre
	var p=opener.document;
	p.getElementById('dni').value=id;
	window.close();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una dirección de correo.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- El '+nm+' no lo has introducido.\n'; }

  } 
  
  errors = verificaDNI(errors);

  if (errors) alert('Atención:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_validateFormEuskera() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormEuskera.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' posta elektroniko helbidea izan behar da.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' ez duzu sartu.\n'; }

  } 
  
  errors = verificaDNIEusk(errors);

  if (errors) alert('Kontuz:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function MM_validateFormFrances() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateFormFrances.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' Doit exister une adresse email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatoire.\n'; }

  } 
  
  errors = verificaDNIFrances(errors);

  if (errors) alert('Atención:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_validateForm2() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm2.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una dirección de correo.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- El '+nm+' no lo has introducido.\n'; }

  } if (errors) alert('Atención:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function passaAlSiguiente(e) {
   if (window.event != null)				//IE4+
      tecla = window.event.keyCode;
   else if ( e != null ) 				//N4+ o W3C compatibles
      tecla = e.which;
   else
      return;

   if (tecla == 13) { 					//se pulso enter
      if (siguienteCampo == 'fin') {			//fin de la secuencia, hace el submit
         alert('Envio del formulario...Pinchar..Boton Enviar.')			//eliminar este alert para uso normal
         return false					//sustituir por return true para hacer el submit
      } else { 						//da el foco al siguiente campo
         eval('document.form.' + siguienteCampo + '.focus()')
         return false
      }
   }
}

function verificaFecha(errors)
{ 
  caja=document.getElementById('fechanac').value;
  
   if (caja)
   {  
      borrar = 0;
      
      
      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))
      {      
        
        for (i=0; i<10; i++)
	     {	
            if (((caja.substr(i,1)<0) || (caja.substr(i,1)>9)) && (i != 2) && (i != 5))
			{
               borrar = 1;
               
               break;  
			}  
         }
	     if (borrar==0)
	     { 
	        a = caja.substr(6,4);
		    m = caja.substr(3,2);
		    d = caja.substr(0,2);
		    if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
		     {
		       borrar = 1;
		         
		      } 
		    else
		    {
		       if((a%4 != 0) && (m == 2) && (d > 28))	  // Año no viciesto y es febrero y el dia es mayor a 28
		        {
		          borrar = 1; 
		         
		        }  
			   else	
			   {
		          if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
		           {
			         borrar = 1;	      				  	 
			          
			       }  
			   }  // else
		    } // fin else
         } // if (error)
         
      } // if ((caja.substr(2,1) == \"/\") && (caja.substr(5,1) == \"/\"))			    			
	  else
	     borrar = 1;
	  if (borrar == 1)
	  {
	     
	     errors+='Fecha erronea';
	   }  
	   
   } // if (caja)   
   
   
   return errors;
} 

function VerAutonomia (cual) {
	OcultarZona ("andalucia");
	OcultarZona ("aragon");
	OcultarZona ("asturias");
	OcultarZona ("baleares");
	OcultarZona ("cantabria");
	OcultarZona ("canarias");
	OcultarZona ("cyl");
	OcultarZona ("clm");
	OcultarZona ("euskadi");
	OcultarZona ("galicia");
	OcultarZona ("catalunya");
	OcultarZona ("melilla");
	OcultarZona ("murcia");
	OcultarZona ("valencia");
	OcultarZona ("madrid");
	OcultarZona ("rioja");

	var obj=cual
	if (obj) document.getElementById(cual).style.display='';

}

function OcultarZona (Tipo) {
	document.getElementById(Tipo).style.display='none';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function resizeImage(im,dim,posim) {
	// Ejemplo de HTML: <div id="dv1"><img src="exprimidito.jpg" id="img1"></div>
	// im: las imagenes tienen un id en el formato img1, img2, etc. im indica el numero ('img' + im)
	// dim: la dimension que debe tener la imagen en su dimension mas corta
	// posim [no | 0 | valor (px)] :
	//		no: no mueve la imagen
	//		0: centrado
	//		valor: mueve la imagen para centrarla en la dirección de su dimensión mas larga. En pixels

	x=document.getElementById("img" + im);
	y=document.getElementById("dv" + im);

	if (!x.complete)
	{
		temporizadorResize=setTimeout("resizeImage("+im+","+dim+","+posim+")", 100);
	}
	else {
		//Tamaño de la imagen
		if (x.width >= x.height) {
			x.height = dim;
		}
		else {
			//alert(x.width);
			x.width = dim;
		}
		//Tamaño del layer
		y.style.width=dim+"px";
		y.style.height=dim+"px";
		//Posicion
		//x.style.position="relative";
		y.style.overflow="hidden";
		
		if (posim == "no") return;
		if (posim == 0) {
		//Centrado por defecto
			if (x.width >= x.height) {
				x.style.left=-(((x.width*100/x.height) - 100)/2) + '%';
			}
			else {
				x.style.top=-(((x.height*100/x.width) - 100)/2) + '%';
			}
		}
		else {
			//Posición indicada
			if (x.width >= x.height) {
				x.style.left=-posim + 'px';
			}
			else {
				x.style.top=-posim + 'px';
			}
		}
	}
}

