<!--

/* 
*   +------------------------------------------------------------------------------+ 
*       COPUT   - linux -                                              
*   +------------------------------------------------------------------------------+ 
*       Descripción :                                                          
*       El objetivo de esta página es crear una serie de funciones genéricas      
*       para realizar las funciones javascript más frecuentes ( comprobación form...)
*   +------------------------------------------------------------------------------+ 
*       Autor: Christian Ferrer (Adapting)                                       
*   +------------------------------------------------------------------------------+ 
*/ 



/*
*   +------------------------------------------------------------------------------+ 
*       FUNCIONES   - Javascript -                                              
*   +------------------------------------------------------------------------------+ 
*
*	function		esString(str , maxCaracteres)
*	function		esEntero(str)
*	function		esFloat(str , numEnteros , numDecimales)
* 	function 		esMoneda(s)
*
*	function		isInteger(s)
*	function		stripCharsInBag(s, bag)
*	function		daysInFebruary (year)
*	function		DaysArray(n) 
*	function		isDate(dtStr)
*   function		esHora(hora)
*
*	function		ContieneSoloLetras( str )
*	function		comprueba_email (str)
*
*	function		comprueba_dni(dni_entrada)
*	function		comprueba_nDNI(strValor) 
*	function		comprueba_lDNI(strValor) 
*	function		valida_DNI(numeros_DNI,letra_DNI)
*
*/



/* 
*   Función: esString(str , maxCaracteres)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprobar si una le pasamos una cadena de longitud máxima maxCaracteres
*    Argumentos:         str , maxCaracteres
*    Devuelve:   		 true o false
*   +---------------------------------------------------------------------------------------------------------+
*/ 

function esString(str , maxCaracteres)
{
  var err = 0
  
  if (str.length >= maxCaracteres)
  {
  	return (false);
  }
  else
  {
  	return (true);
  }

}
  
  
/* 
*   Función: esEntero(str)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          comprueba si el valor que se le pasa como argumento es un entero
*    Argumentos:         str
*    Devuelve:   		 true o false
*   +---------------------------------------------------------------------------------------------------------+
*/ 
function esEntero(str)
  {
 
  var err = 0
  var valid = "0123456789"
  var ok = "yes";
  var temp;

  for (var i=0; i< str.length; i++)
    {
	temp = "" + str.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") err = 1;
	}
  
  if (err==1)
	{
	return (false);
	}
  else
    {
	return (true);
	}
  }  
  
  
  
  
/* 
*   Función: esFloat(str , numEnteros , numDecimales)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si el valor que se le pasa como argumento es un float 
*						 con un máximo de numEnteros en la parte entera y un máximo de numDecimales en la parte decimal
*    Argumentos:         str , numEnteros , numDecimales
*    Devuelve:   		 0 ( si es un float , cumple todas las condiciones )
*						 -1  ( no es un float o ha incumplido alguna condición : hay algun carácter , tiene demasiados decimales....)
*   +---------------------------------------------------------------------------------------------------------+
*/     
function esFloat(str , numEnteros , numDecimales)
 {
  var err = 0
  var valid = "0123456789.,"
  var ok = "yes";
  var temp;

  var numcomas=0;
  var numpuntos=0;  

  if (str=="")
  {
		err=1;
   }
   else
   {
		for (var i=0; i< str.length; i++)
   		{
			temp = "" + str.substring(i, i+1);
			if (temp==",") numcomas++;
			if (temp==".") numpuntos++;

			if (valid.indexOf(temp) == "-1") err = 1;
		 }
	
		if ( (numcomas + numpuntos) > 1 )
		{
			err = 1;
		}
		else
		{
				if (numcomas > 0) 
				{
					indiceComa = str.indexOf(",");
					if ( indiceComa > 0 )
					{
						antesdecoma = str.substring(0, indiceComa);
						despuesdecoma = str.substring(indiceComa+1, str.length);

						if (( antesdecoma.length > numEnteros ) || ( despuesdecoma.length > numDecimales ))
						err = 1;
					}
					
				}		
				

				if ( numpuntos > 0 )
				{
				
					indicePunto = str.indexOf(".");
					if ( indicePunto > 0 )
					{
						antesdepunto = str.substring(0, indicePunto);
						despuesdepunto = str.substring(indicePunto+1, str.length);

						if (( antesdepunto.length > numEnteros ) || ( despuesdepunto.length > numDecimales ))
						err = 1;
					}
					
				}
				

				if ((numcomas == 0) && (numpuntos == 0))
				{
					if (str.length > numEnteros)
						err = 1;
				}
		
			
		}
		
	}		
		


  if (err==1)
  {
		return (false);
  }
  else
  {
		return (true);
   }


 }  
 
 
 
 
 /*---------------------------------------------------------------------------*/
/* FUNCION: normalizar(formato_ant: Entero): Entero                          */
/* DESCRIPCION: Escribe valor en forma inglesa (1552,95 -> 1552.95) y dice   */
/*              la forma original.                                           */
/* COMENTARIOS: JavaScript 1.0.                                              */
/* PARAMETROS: formato_ant: Formato anterior (¿?, 0; 1,1, 1; 1.0, 2).        */
/* DEVUELVE: formato_act: Formato actual.                                    */
/* LLAMADO POR: euroconversor.                                               */
/*---------------------------------------------------------------------------*/
function normalizar(formato_ant)
{
  var formato_act = 0;            // Formato actual (¿?, 1,1, 1.0)
  var coma = valor.indexOf(',');  // Indice de ',' en valor
  var punto = valor.indexOf('.'); // Indice de '.' en valor

  if ((-1 == coma) && (-1 == punto)) // Valor 9999
  {
    formato_act = formato_ant;
    error = false;
  }
  else if (-1 != coma) // Valor 9999,99
  {
    formato_act = 1;
    error = 2 == formato_ant;
  }
  else // punto; valor 9999.99
  {
    formato_act = 2;
    error = 1 == formato_ant;
  }
  if ((1 == formato_act) && (-1 != coma)) // Pasa a formato ingles
    valor = valor.substring(0, coma) + '.' +
            valor.substring(coma + 1, valor.length);
  return formato_act;
}
 
 
 

  
/* 
*   Función: esMoneda(str , numEnteros , numDecimales)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si el valor que se le pasa como argumento es una moneda 
*						 con un máximo de numEnteros en la parte entera y un máximo de numDecimales en la parte decimal
*    Argumentos:         str , numEnteros , numDecimales
*    Devuelve:   		 0 ( si es un float , cumple todas las condiciones )
*						 -1  ( no es un float o ha incumplido alguna condición : hay algun carácter , tiene demasiados decimales....)
*   +---------------------------------------------------------------------------------------------------------+
*/     
function esMoneda(str , numEnteros , numDecimales)
 {
  var err = 0
  var valid = "0123456789."
  var ok = "yes";
  var temp;

  var numcomas=0;
  var numpuntos=0;  

  if (str=="")
  {
		err=1;
   }
   else
   {
		for (var i=0; i< str.length; i++)
   		{
			temp = "" + str.substring(i, i+1);
			if (temp==",") numcomas++;
			if (temp==".") numpuntos++;

			if (valid.indexOf(temp) == "-1") err = 1;
		 }
	
		if ( (numcomas + numpuntos) > 1 )
		{
			err = 1;
		}
		else
		{
				if (numcomas > 0) 
				{
					indiceComa = str.indexOf(",");
					if ( indiceComa > 0 )
					{
						antesdecoma = str.substring(0, indiceComa);
						despuesdecoma = str.substring(indiceComa+1, str.length);

						if (( antesdecoma.length > numEnteros ) || ( despuesdecoma.length > numDecimales ))
						err = 1;
					}
					
				}		
				

				if ( numpuntos > 0 )
				{
				
					indicePunto = str.indexOf(".");
					if ( indicePunto > 0 )
					{
						antesdepunto = str.substring(0, indicePunto);
						despuesdepunto = str.substring(indicePunto+1, str.length);

						if (( antesdepunto.length > numEnteros ) || ( despuesdepunto.length > numDecimales ))
						err = 1;
					}
					
				}
				

				if ((numcomas == 0) && (numpuntos == 0))
				{
					if (str.length > numEnteros)
						err = 1;
				}
		
			
		}
		
	}		
		


  if (err==1)
  {
		return (false);
  }
  else
  {
		return (true);
   }


 }  

 
 

 
 /* 
*   Funciones: isInteger , stripCharsInBag , daysInFebruary , DaysArray , isDate
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:         Comprobar si una fecha es válida ( en el formato dd/mm/yyyy )
*    Argumentos:        fecha
*    Devuelve:   		 true ( es una fecha valida )  o false ( no es una fecha valida )
*   +---------------------------------------------------------------------------------------------------------+
*/     


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
	{   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}




function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{ 
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
	{
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
	if ( dtStr.length != 10 ) {
		return false	
	}
	
return true
}

function esHora(valor) {

    var coma = valor.indexOf(':');  // Indice de ',' en valor		
    var hora = valor.substring(0, coma);
	var minutos = valor.substring(coma + 1, valor.length);

	
    if ( !(valor=="") && (isInteger(hora)) && (isInteger(minutos)) ) {	
	  if ( (hora>23) || (hora<0) || (minutos>59) || (minutos<0) ) {
	    return false;
	  }
	} else {
	  return false;	
	}

	return true;	

}


 
 
/* 
*   Función: ContieneSoloLetras( str )
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si el valores una cadena con únicamente letras
*    Argumentos:         str 
*    Devuelve:   		 true ( sólo existen letras )  o false ( existe algun carácter que no es una letra )
*   +---------------------------------------------------------------------------------------------------------+
*/     
function ContieneSoloLetras( str )
{
	if (str+"" == "undefined" || str+"" == "null" || str+"" == "")
		return false;
	var isValid = true;
	str += "";	// convert to a string for performing string comparisons.
  	for (i = 0; i < str.length; i++) {
		// Alpha must be between "A"-"Z", or "a"-"z"
		if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      			((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) ) {
         				isValid = false;
         				break;
      			}
   		}

	return isValid;
}

 
 

/* 
*   Función: comprueba_email (str)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si una cadena tiene formato de email correcto ( por ej: no hay 2 arrobas )
*    Argumentos:         str 
*    Devuelve:   		 true ( es una dirección de email valida )  o false ( no es una dirección de email valida )
*   +---------------------------------------------------------------------------------------------------------+
*/     
  
var defaultEmptyOK = false
var reEmail = /^.+@.+..+$/

function comprueba_email (str)
  {
	if (!reEmail.test(str))
	  {
	  return (false);
	  }
	else
	  {
	  return (true);
	  }
  }

  
  
  
  
  
  
  
/* 
*   Función: comprueba_nif_cif(entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si un dni/nif/cif es válido 
*    Argumentos:         str 
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/     

function comprueba_nif_cif(entrada)
{
var es_nif = false;
var es_cif = true;

var err=0;

string1 = entrada
if (string1.length<9 || string1.length>12)
{
	alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos más opcionalmente una barra separadora (/) y un número\npara cada una de las delegaciones. Por ejemplo A12345678, A12345678/4 ó A12345678/12');
//	alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos');
	return (false);
}


if (string1.length==10)
{
	alert('Formato incorrecto, un NIF/CIF consta de 9 dígitos más opcionalmente una barra separadora (/) y un número\npara cada una de las delegaciones. Por ejemplo A12345678, A12345678/4 ó A12345678/12');
//	alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos');
	return (false);
}


//alert("X10 "+string1.substring(9,10));
//alert("X1112 "+string1.substring(10,string1.length));

if ((string1.length==11) || (string1.length==12))
{
	if (string1.substring(9,10)!="/"){

//		alert(string1.substring(9,10));

		alert('Formato incorrecto, un NIF/CIF consta de 9 dígitos más opcionalmente una barra separadora (/) y un número\npara cada una de las delegaciones. Por ejemplo A12345678, A12345678/4 ó A12345678/12');	
	//	alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos');
		return (false);
	}
}


//alert("a "+string1.substring(9,10));
//alert("b "+string1.substring(10,11));
//alert("c "+string1.substring(11,12));

//alert("ojo resto "+string1.substring(10,string1.length));

if ((string1.length==11) || (string1.length==12))
{
	if (!isInteger(string1.substring(10,string1.length))){

//		alert(string1.substring(10,string1.length));

		alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos más opcionalmente una barra separadora (/) y un número\npara cada una de las delegaciones. Por ejemplo A12345678, A12345678/4 ó A12345678/12');
	//	alert('Longitud incorrecta, un NIF/CIF consta de 9 dígitos');
		return (false);
	}
}


string1 = string1.substring(0, 9) 


letraCIF = string1.substring(0, 1) 
numerosCIF = string1.substring(1, 9) 

numerosNIF = string1.substring(0, 8) 
letraNIF = string1.substring(8, 9) 



	if  ( letraCIF == "J" )
	{
		// ES DNI de JUZGADO
			if (!CompruebaesDNIjuzgado(string1)) return (false);
	}
	else if ( ContieneSoloLetras(letraCIF) && (esEntero(numerosCIF)) )
	{
		// ES CIF
			if (!comprueba_cif(string1)) return (false);
	}
	else if ( (esEntero(numerosNIF)) && ContieneSoloLetras(letraNIF) )
	{
		// ES NIF
			if (!comprueba_nif(string1)) return (false);
	}

	
return (true);
}





 /* 
*   Función: CompruebaesDNIjuzgado(entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si es un DNI de juzgado válido 
*    Argumentos:         entrada
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/     
function CompruebaesDNIjuzgado(entrada)
{

// Formato :  [1][2][3-9]
//
//			  [1] = letra1  ( debe ser la "J" )
//  		  [2] = letra juzgado  ( debe ser una de estas "CSIMF" ) 
//			  [3-9] = dni_juzgado ( tiene que ser numeros ) 

letra1 = entrada.substring(0, 1);
letra_juzgado = entrada.substring(1, 2);
dni_juzgado = entrada.substring(2, 9);


	var letra_juzgado_permitida = "CSIMF";
	var pos = letra_juzgado_permitida.indexOf(letra_juzgado)
	

	if (  (letra1 =="J") &&  (pos > 0) && (esEntero(dni_juzgado)) ) 
	{
		return true;
	}
	else
	{
		alert('DNI de juzgado no válido');
		return false;
	}
	
	
}



 /* 
*   Función: comprueba_cif(cif_entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si un cif es válido 
*    Argumentos:         str 
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/     
function comprueba_cif(cif_entrada) 
{
  var resul = false;
  var temp = cif_entrada.toUpperCase(); // pasar a mayúsculas

  if (!/^[A-Za-z0-9]{9}$/.test(temp))  // Son 9 dígitos? 
  {
     alert ("Longitud incorrecta, un CIF consta de 9 dígitos");
  }
  else if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) // Es una letra de las admitidas ?
  {
     alert("El primer dígito del CIF es incorrecto, debe ser una letra de las siguientes: A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S ");
  }
  else 
  {
			letraCIF = cif_entrada.substring(0, 1);
			numerosCIF = cif_entrada.substring(1, 9);
			ultimodigitoCIF = cif_entrada.substring(8, 9);			
			


			// Esto es muy importante , ya que varia bastante de validar por letra o por dígito de control
				validamos_por_letra = false;
			


			//   -------  Validación por LETRA  ----------
			
			if ( validamos_por_letra == true ) 
			{
				letraCIFValida = ValidaCIF_letra(cif_entrada);

					if ((letraCIF=="") || ( letraCIFValida != ultimodigitoCIF ) )
					{
					     alert("El último dígito del CIF no es correcto." + "La letra correcta es " +  letraCIFValida );
					}
					else
					{
						resul = true;
					}


			//   -------  Validación por NUMERO  ----------
			}
			else
			{
				numeroCIFValido = ValidaCIF_numero(cif_entrada);

					if ((letraCIF=="") || ( numeroCIFValido != ultimodigitoCIF ) )
					{
					     alert("El último dígito del  CIF no es correcto." + " El número correcto es " +  numeroCIFValido );
					}
					else
					{
						resul = true;
					}
				
			}

			
  }

   
  return resul;
}




  /* 
*   Función: ValidaCIF_letra(cif_entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Valida el cif 
*    Argumentos:         F
*    Devuelve:   		 devuelve la letra del CIF válida ( debería ser la misma que la primera letra del cif_entrada )
*   +---------------------------------------------------------------------------------------------------------+
*/    
function ValidaCIF_letra(cif_entrada) 
{

  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;

  
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(cif_entrada.substr(i-1,1)) ];
      temp = temp + parseInt(cif_entrada.substr(i,1));
    };

  temp = temp + v1[ parseInt(cif_entrada.substr(7,1)) ];

  temp = (10 - ( temp % 10));


  switch (temp)
  {
		  case 1:
		    resultado = "A";
		   break;

		  case 2:
		    resultado = "B";
		   break;

		  case 3:
		    resultado = "C";
		   break;

		  case 4:
		    resultado = "D";
		   break;

		  case 5:
		    resultado = "E";
		   break;

		  case 6:
		    resultado = "F";
		   break;

		  case 7:
		    resultado = "G";
		   break;

		  case 8:
		    resultado = "H";
		   break;
		   
		  case 9:
		    resultado = "I";
		   break;


		   
		  case 0:
		    resultado = "J";
		   break;		   
		   
		  case 10:
		    resultado = "J";
		   break;		   

	} 
			

  return resultado;
}






  /* 
*   Función: ValidaCIF_numero(cif_entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Valida el cif 
*    Argumentos:         F
*    Devuelve:   		 devuelve la letra del CIF válida ( debería ser la misma que la primera letra del cif_entrada )
*   +---------------------------------------------------------------------------------------------------------+
*/    
function ValidaCIF_numero(cif_entrada) 
{

  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;

  
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(cif_entrada.substr(i-1,1)) ];
      temp = temp + parseInt(cif_entrada.substr(i,1));
    };

  temp = temp + v1[ parseInt(cif_entrada.substr(7,1)) ];

  temp = (10 - ( temp % 10));

  if ( temp == 10 ) 
  {
  	  // no tengo ni idea de que hacer en este caso
	  resultado = temp;	  
	  alert('caso chungo');
  }
  else
  {
	  resultado = temp;
  }

  return resultado;
}






  /* 
*   Función: comprueba_nif(nif_entrada)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba si un dni/nif es válido 
*    Argumentos:         str 
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/     

function comprueba_nif(nif_entrada)
{
//al ser un texto de 15 cuando compruebo para español solo puede tener 9
//8 numeros y 1 letra

string1 = nif_entrada
if (string1.length!=9)
    {
      alert ("Longitud incorrecta, un NIF consta de 9 dígitos");
  	  return (false);
	}


numerosDNI = string1.substring(0, 8) // numeros dni
letrasDNI = string1.substring(8, 9) // letras dni


if (!comprueba_nDNI(numerosDNI)) return (false);
if (!comprueba_lDNI(letrasDNI)) return (false);
if (!valida_DNI(numerosDNI,letrasDNI)) return (false);

return (true);
}




/* 
*   Función: comprueba_nDNI(strValor) 
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba la parte de los numeros del DNI
*    Argumentos:         strValor 
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/  

function comprueba_nDNI(strValor) 
{
  string = strValor
  //alert(string);
  if (string == "")
    {
    alert('Introduzca los números del NIF');
	return (false);
	}
  else
	{
	//alert(string);
	if (!esEntero(string))
      {
      alert('La primera parte del NIF sólo puede contener números');
      return (false);
      }
    else
	  {
      if (string.length!=8)
        {
        alert('La primera parte del NIF debe tener 8 números');
        return (false);
        }
	  else
        {
        return (true);
        }
      }
	}
}






/* 
*   Función: comprueba_lDNI(strValor)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba la parte de las letras del DNI
*    Argumentos:         strValor 
*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/  
function comprueba_lDNI(strValor) 
{
  string = strValor
  if (string == "")
    {
    alert('Introduzca la letra del NIF del alumno');
	return (false);
	}
  else
	{
	if (!ContieneSoloLetras(string))
      {
      alert('La segunda parte del NIF sólo puede contener una letra');
      return (false);
      }
  else
      {
      return (true);
      }
    }
}


/* 
*   Función: valida_DNI(numeros_DNI,letra_DNI)
*   +---------------------------------------------------------------------------------------------------------+
*    Propósito:          Comprueba que la letra se corresponde con los numeros del DNI
*    Argumentos:         numeros_DNI, letra_DNI 
*
*    Objetivo  :		 Para validar el DNI hay que coger el numero en cuestion y dividirlo entre 23. 
*						 Al resultado de esa division se le quitan los decimales (sin redondear) y se vuelve a multiplicar por 23,
*						 con lo que se conseguira un numero entre 0 y 23 unidades mas bajo que el DNI original. 
*						 Solamente hay que restarlo y, consultando la tabla ya se tiene la letra.

*    Devuelve:   		 true  ( si es correcto ) o  false ( si no es correcto ) 
*   +---------------------------------------------------------------------------------------------------------+
*/  

function valida_DNI(numeros_DNI,letra_DNI)
{

letra_DNI=letra_DNI.toUpperCase()
numeros_DNI=parseInt(numeros_DNI)
aux=Math.floor(numeros_DNI/23)
aux=aux*23
res=numeros_DNI-aux

//obtengo la letra que se corresponde en teoria con los numeros
if (res==0) {letra_correcta="T"}
else if (res==1) {letra_correcta="R"}
else if (res==2) {letra_correcta="W"}
else if (res==3) {letra_correcta="A"}
else if (res==4) {letra_correcta="G"}
else if (res==5) {letra_correcta="M"}
else if (res==6) {letra_correcta="Y"}
else if (res==7) {letra_correcta="F"}
else if (res==8) {letra_correcta="P"}
else if (res==9) {letra_correcta="D"}
else if (res==10) {letra_correcta="X"}
else if (res==11) {letra_correcta="B"}
else if (res==12) {letra_correcta="N"}
else if (res==13) {letra_correcta="J"}
else if (res==14) {letra_correcta="Z"}
else if (res==15) {letra_correcta="S"}
else if (res==16) {letra_correcta="Q"}
else if (res==17) {letra_correcta="V"}
else if (res==18) {letra_correcta="H"}
else if (res==19) {letra_correcta="L"}
else if (res==20) {letra_correcta="C"}
else if (res==21) {letra_correcta="K"}
else if (res==22) {letra_correcta="E"}
else if (res==23) {letra_correcta="T"}

//compruebo la letra introducida
if (letra_DNI==letra_correcta)
  {
  return (true);
  }
else
  {
	  alert('La letra del NIF introducido no es correcta');
	  return (false);
  }
}  
  

