function tieneDatos(Valor) { 
 for (var i=0; i<Valor.length; i++) { 
   if ((" \t\n\r").indexOf(Valor.charAt(i))==-1) return true; 
   } 
 return false; 
}
 
function esNumerico(Valor) { 
 return (!isNaN(Valor)); 
}

function esEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
   return (true)
  } else {
   return (false);
  }
 }

function esFecha(Valor) { 
 if (!tieneDatos(Valor)) return true; 
 var DatosFecha = Valor.split('/'); 
 var Fecha = new Date(); 
 Fecha.setFullYear(DatosFecha[2],DatosFecha[1]-1,DatosFecha[0]); 
 return (Fecha.getMonth()==DatosFecha[1]-1); 
}

//<label for="FechaNacimiento">Fecha de nacimiento: </label> 
//<input type="text" name="FechaNacimiento" class="Requerido Fecha"/>

function ChequearFormSolicita(elmFORM) { 
 var Mensaje = ''; 
 var cnjFORM = elmFORM.elements; 
 var elmLABEL; 
 var labels = document.getElementsByTagName('label');
 var txtcampos= new Array(13) 
 txtcampos[0]="Nombre"; 
 txtcampos[1]="Apellidos"; 
 txtcampos[2]="Empresa"; 
 txtcampos[3]="Sector"; 
 txtcampos[4]="Cargo"; 
 txtcampos[5]="Direccion"; 
 txtcampos[6]="CP"; 
 txtcampos[7]="Poblacion"; 
 txtcampos[8]="Pais"; 
 txtcampos[9]="Telefono"; 
 txtcampos[10]="Email"; 
 txtcampos[11]="Motivo"; 
 txtcampos[12]="Imagen"; 
 for (var i=0; i<cnjFORM.length; i++) { 
 		if (cnjFORM[i].className.indexOf('Requerido')!=-1) { 
//    		elmLABEL = cnjFORM[i].previousSibling; 
     		//elmLABEL.style.fontWeight='normal'; 
//				alert(i);
//    		alert("negro");
    		labels[i].style.color="black";
     		if (! tieneDatos(cnjFORM[i].value)) { 
  //    		elmLABEL.style.fontWeight='bold'; 
//       		Mensaje+='"' + elmLABEL.firstChild.nodeValue + '" debe ser cumplimentado.\n'; 
//    				alert("rojo");
    		    labels[i].style.color="red";
       			Mensaje+='"' + txtcampos[i] + '" debe ser cumplimentado.\n'; 
       	} 
    } 

 		if (cnjFORM[i].className.indexOf('Email')!=-1) { 
//    		elmLABEL = cnjFORM[i].previousSibling; 
     		//elmLABEL.style.fontWeight='normal'; 
    		labels[i].style.color="black";
     		if (! esEmail(cnjFORM[i].value)) { 
  //    		elmLABEL.style.fontWeight='bold'; 
//       		Mensaje+='"' + elmLABEL.firstChild.nodeValue + '" debe ser cumplimentado.\n'; 
    		    labels[i].style.color="red";
       			Mensaje+='"' + txtcampos[i] + '" no tiene formato correcto de email.\n'; 
       	} 
    } 

 		if (cnjFORM[i].className.indexOf('Numerico')!=-1) { 
//    		elmLABEL = cnjFORM[i].previousSibling; 
     		//elmLABEL.style.fontWeight='normal'; 
    		labels[i].style.color="black";
     		if ((! esNumerico(cnjFORM[i].value)) || (! tieneDatos(cnjFORM[i].value))) { 
  //    		elmLABEL.style.fontWeight='bold'; 
//       		Mensaje+='"' + elmLABEL.firstChild.nodeValue + '" debe ser cumplimentado.\n'; 
    		    labels[i].style.color="red";
       			Mensaje+='"' + txtcampos[i] + '" debe ser numérico.\n'; 
       	} 
    } 

 } 
 if (Mensaje != '') alert(Mensaje); 
 return (Mensaje == ''); 
}

function ChequearFormEnviar(elmFORM) { 
 var Mensaje = ''; 
 var cnjFORM = elmFORM.elements; 
 var elmLABEL; 
 var labels = document.getElementsByTagName('label');
 var txtcampos= new Array(4) 
 txtcampos[0]="Tu nombre"; 
 txtcampos[1]="Tu email"; 
 txtcampos[2]="Nombre de tu amigo"; 
 txtcampos[3]="Email de tu amigo"; 
 for (var i=0; i<cnjFORM.length; i++) { 
 		if (cnjFORM[i].className.indexOf('Requerido')!=-1) { 
    		labels[i].style.color="black";
     		if (! tieneDatos(cnjFORM[i].value)) { 
        		labels[i].style.color="red";
       			Mensaje+='"' + txtcampos[i] + '" debe ser cumplimentado.\n'; 
       	} 
    } 

 		if (cnjFORM[i].className.indexOf('Email')!=-1) { 
//    		elmLABEL = cnjFORM[i].previousSibling; 
     		//elmLABEL.style.fontWeight='normal'; 
    		labels[i].style.color="black";
     		if (! esEmail(cnjFORM[i].value)) { 
  //    		elmLABEL.style.fontWeight='bold'; 
//       		Mensaje+='"' + elmLABEL.firstChild.nodeValue + '" debe ser cumplimentado.\n'; 
    		    labels[i].style.color="red";
       			Mensaje+='"' + txtcampos[i] + '" no tiene formato correcto de email.\n'; 
       	} 
    } 

 } 
 if (Mensaje != '') alert(Mensaje); 
 return (Mensaje == ''); 
}

