<!--
function validarDOC(valor){
	var regexp = /^([0-9]{8,8}[a-zA-Z])$/;
	var regexp2 = /^([ABCDEFGHKLMNPQSabcdefghklmnpqs][0-9]{7,7}[0-9A-J])$/;
	if(regexp2.test(valor)) {
		return validarCIF(valor);
	}else if(regexp.test(valor)) 
	{
		return validarDNI(valor);
	}
	return false;
}
function validarDNI(valor)
{
	var letras = 'T,R,W,A,G,M,Y,F,P,D,X,B,N,J,Z,S,Q,V,H,L,C,K,E,T'.split(',');
	var pos = valor.substr(0,valor.length-1) % 23
	var letra = valor.substr(valor.length-1,valor.length);
	if (letra.toUpperCase() == letras[pos]) 
	{
		return true;
	}
	return false;
}
 function validarCIF(texto){
        var pares = 0;
        var impares = 0;
        var suma;
        var ultima;
        var unumero;
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
        var xxx;
        texto = texto.toUpperCase();
        var regular = new RegExp(/^[ABCDEFGHKLMNPQSabcdefghklmnpqs]\d\d\d\d\d\d\d[0-9,A-J]$/g);
         if (!regular.exec(texto)) return false;
         ultima = texto.substr(8,1);
         for (var cont = 1 ; cont < 7 ; cont ++){
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
             pares += parseInt(texto.substr(cont,1));
         }
         xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
         impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
         
         suma = (pares + impares).toString();
         unumero = parseInt(suma.substr(suma.length - 1, 1));
         unumero = (10 - unumero).toString();
         if(unumero == 10) unumero = 0;
         
         if ((ultima == unumero) || (ultima == uletra[unumero]))
             return true;
         else
             return false;
 }

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.id; if ((val=val.value)!="") {
      if (test.indexOf('DNI')!=-1) {
        if (!validarDNI(val))
          errors+='- En '+nm+' no hay un DNI válido.\n';
      } else

      if (test.indexOf('CIF')!=-1) {
        if (!validarCIF(val))
          errors+='- En '+nm+' no hay un CIF válido.\n';
      } else

      if (test.indexOf('isEmail')!=-1) {
        var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
        if (!filter.test(val)) errors+='- En '+nm+' no hay una dirección de correo válida.\n';
      } else if (test!='R') {
        val = val.replace(/,/,".");
        num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe contener un número.\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+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es un campo obligatorio.\n'; }
  } if (errors) alert('Errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

