function isValidNif(abc){
	dni=abc.substring(0,abc.length-1);
	let=abc.charAt(abc.length-1);
	if (!isNaN(let)) {
		//alert('Falta la letra');
		return false;
	}else{ 
		cadena = "TRWAGMYFPDXBNJZSQVHLCKET";
		posicion = dni % 23;
		letra = cadena.substring(posicion,posicion+1);
		if (letra!=let.toUpperCase()){
			//alert("Nif no válido");
			return false;
		}
	}
	//alert("Nif válido")
	return true;
}



function formato(cif) {
  
        var resul = false;
        // pasar a mayúsculas
        var temp = cif.toUpperCase(); 

        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
                resul = true;
   
   return resul;
}




function isValidCif(cif)
{
par = 0
non = 0
letras="ABCDEFGHKLMNPQS"
let=cif.charAt(0)

if (!isNaN(let))
  {
  nif=cif
  if (isValidNif(nif))
  {
    return true
  }
  else
  {
    return false
  }
  }

if (cif.length!=9)
  {
  
  return false
  }

if (letras.indexOf(let.toUpperCase())==-1)
  {
  
  return false
  }

for (zz=2;zz<8;zz+=2)
  {
  par = par+parseInt(cif.charAt(zz))
  }

for (zz=1;zz<9;zz+=2)
  {
  nn = 2*parseInt(cif.charAt(zz))
  if (nn > 9) nn = 1+(nn-10)
  non = non+nn
}

parcial = par + non

control = (10 - ( parcial % 10))

if (control==10) control=0

if (control!=cif.charAt(8))
  {
  //alert("El Cif no es válido")
  return false
  }
return true
}  


function isValidEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return (filter.test(str));
}
 
/*function isValidTelef(num){
	if(num.length < 9){
		return false;
	}else if(isNaN( num )){
		return false;
	}else{
		return true;
	}
}*/


function validarLongitud(campo,lon){
  var cad 
  if (document.getElementById(campo).value.length>lon)
  {
    //cad=document.getElementById(campo).value;
    //document.getElementById(campo).value=substr(cad,0,lon-1);
    document.getElementById(campo).focus();
    return false; 
  }      
  else
    return true; 
   
}



/* function addelemento(fichero,numero)
 {
 

            var siguiente=numero+1;
            document.getElementById("file"+siguiente.toString()).innerHTML=
			  "<input id='onf'"+siguiente.toString()+" type='file' onchange='addelemento("+fichero+","+siguiente.toString()+")'/>";
            document.getElementById("onf"+numero.toString()).value=fichero;

 }*/
