function esEmail(valor, necesario )
{
emailPatt = /^\s*[\w\.=-]+@[\w\.-]+\.[a-z]{2,3}\s*$/;
emailCorrecto = valor.match(emailPatt)!=null;
return ((necesario!=null)?emailCorrecto:emailCorrecto||valor=="");
}
function esNumero(s)
{
	for(var i=0; i<s.length; ++i)
		if (!isDigit(s.charAt(i))) return false;
return true;
}

function esCP(valor, necesario)
{
cppatt = /^\d{5}$/;
CPCorrecto = valor.match(cppatt)!=null;
return ((necesario!=null)?CPCorrecto:CPCorrecto||valor=="");
}

function esISBN(valor, necesario)
{
valor = valor.toUpperCase();
cppatt = /^(\d{1,7})-(\d{1,7})-(\d{1,7})-(\d{1,7}|X)$/
ISBNCorrecto = valor.match(cppatt)!=null && valor.length == 13;
return ((necesario!=null)?ISBNCorrecto:ISBNCorrecto||valor=="");
}

function esVacio(valor)
{
return valor=="";
}

function textoLongitudMaxima(texto, numcar, necesario)
{
// los retornos de carro cuentan como 1 y no como 2, valido para textareas...
//contenido = texto.replace(/\r\n/g,"e") + "$fin$";
contenido = texto + "$fin$";
var esMenor = (numcar>=contenido.lastIndexOf("$fin$"));
return((necesario!=null)?esMenor:esMenor||texto=="");
}

function textoLimitado(campo, numero)
{
if (campo.value.length>numero){
//campo.value = campo.value.substr(0,numero)
//alert("Máximo " + numero + " caracteres");
//this.focus
return true;
}
}

function esNIF(txt)
{
 var i,j;
 var dni="";
 var letra,cod;
 var c="";
 i=txt.length;

 if (i!=9) return false;
 
 for (j=0;j<i-1;j++)
 {
  var c = txt.charAt(j);
  dni=dni+c;
  if (!isDigit(c)) return false;
 }
 
 cod=eval(dni%23)+1; 
 
 switch(cod)
 {
		case 1:
            letra="T"; break; 
        case 2:
            letra="R"; break;  
        case 3:
            letra="W"; break; 
        case 4:
			letra="A"; break; 
        case 5:
            letra="G"; break; 
        case 6:
            letra="M"; break; 
        case 7:
			letra="Y"; break; 
        case 8:
            letra="F"; break; 
        case 9:
            letra="P"; break; 
        case 10:
            letra="D"; break; 
        case 11:
            letra="X"; break; 
        case 12:
            letra="B"; break; 
        case 13:
            letra="N"; break; 
        case 14:
            letra="J"; break; 
        case 15:
            letra="Z"; break; 
        case 16:
            letra="S"; break; 
        case 17:
            letra="Q"; break; 
        case 18:
            letra="V"; break; 
        case 19:
            letra="H"; break; 
        case 20:
            letra="L"; break; 
        case 21:
            letra="C"; break; 
        case 22:
            letra="K"; break; 
        case 23:
            letra="E"; break; 
     }
     
 
 
 c = txt.charAt(i-1);
 c=c.toUpperCase();
 if (!isLetter(c)) return false;
 
 if (c!=letra) return false;
 return true;
 
}


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isCIF(txt)
{ 
//if (txt != ""){
	var Suma,Control;
	var n;
	var cif=""; 
 	cif=txt.toUpperCase(); 
	//La letra inicial debe ser una de las posibles
	var posibles="ABCDEFGHKLMPQSX";
	var numeros="0123456789"
	var letra = cif.charAt(0);
	if (posibles.indexOf(letra)==-1) return false;
	//El cif debe ser de 9 cifras
	i=txt.length;
 	if (i!=9) return false;
	if ((numeros.indexOf(cif.charAt(1))==-1) || (numeros.indexOf(cif.charAt(2))==-1) || (numeros.indexOf(cif.charAt(3))==-1) || (numeros.indexOf(cif.charAt(4))==-1) || (numeros.indexOf(cif.charAt(5))==-1) || (numeros.indexOf(cif.charAt(6))==-1) || (numeros.indexOf(cif.charAt(7))==-1) || (numeros.indexOf(cif.charAt(8))==-1))return false;

 	//suma de los dígitos pares
	Suma= eval(cif.charAt(2))+eval(cif.charAt(4))+eval(cif.charAt(6)); 
	for (n=1;n<8;n=n+2)
	{ 
		Suma=Suma+((2*eval(cif.charAt(n)))%10)+(Math.floor((2*eval(cif.charAt(n)))/10)); 
	}
	if ((cif.charAt(0).indexOf("XP")==-1))
	{ 
		//Control tipo número 
		if (eval(cif.charAt(8)) != (10-(Suma%10))) return false; 
	}
	else	
	{
		//Control tipo letra
		if (cif.charAt(8) != String.fromCharCode(64+(10-(Suma%10)))) return false; 		
	}		
	
	return true;	 
/*}//del if añadido
else
{
	return false;
}*/

}

function stateChecker(boton) {
//	var botonsin="";
    
   for (var i = 0; i < boton.length; i++) {
      if (boton[i].checked) {
//         botonsin=boton[i].value;
	return true;
      }
     }
   if(boton.checked)
     {
         return true;
     }

//   alert("checkedBoton:"+checkedBoton);
//   if(botonsin==""){//no se ha seleccionado ninguna opcion
//   	return false;
//   }
//   	return true;	
}


