﻿//------ Versión FINCA LOS LLANOS (version completa javascript/validaciones.js)

function vacio(campo,nombre){
	if(document.getElementById(campo).value==""){alert("Debe rellenear el campo "+ nombre +".");document.getElementById(campo).focus();return true;}
	else return false;
}

function noemail(campo){// Que sea un correo
	if(document.getElementById(campo).value!=""){
	valor=document.getElementById(campo).value;
	if(valor=="") return false;
	n=valor.indexOf("@");
	m=valor.indexOf(".");
	if(n<0 || m<0){alert("Debe introducir una dirección de correo correcta.");document.getElementById(campo).focus();return true;}
	else return false;}
	else return false;
}

function cero(campo,nombre){// que no sea cero
	if(document.getElementById(campo).value=="0"){alert("Debe seleccionar una opcion del campo "+ nombre +".");document.getElementById(campo).focus();return true;}
	else return false;
}

function nonumero(campo,nombre){// que no sea un numero
	if(isNaN(document.getElementById(campo).value)){alert("Debe introducir un valor numérico en el campo "+ nombre +".");document.getElementById(campo).value="";document.getElementById(campo).focus();return true;}
	else return false;
}

function cero2(campo,nombre){// que no sea cero
	if(document.getElementById(campo).value=="0"){alert("Debe introducir un valor superior a 0 en "+ nombre +".");document.getElementById(campo).focus();document.getElementById(campo).value="";return true;}
	else return false;
}

function igual(campo,nombre,campo2,nombre2){// que no sean iguales
	if(document.getElementById(campo).value!=document.getElementById(campo2).value){alert("El campo " +  nombre + " debe ser igual al campo " + nombre2 + ".");document.getElementById(campo).focus();return true;}
	else return false;
}

function nofecha(d,m,a){ //Validar fecha

	
	        d = document.getElementById(d).value;
		    m = document.getElementById(m).value;
		    a = document.getElementById(a).value;
			
if(d!=0 &&  (m==0 || a==0)) {alert("Formato de fecha incorrecto."); return true;}
if(m!=0 &&  (d==0 || a==0)) {alert("Formato de fecha incorrecto."); return true;}
if(a!=0 &&  (m==0 || d==0)) {alert("Formato de fecha incorrecto."); return true;}

if(d!=0 && m!=0 && a!=0){
	
	  var meses= new Array("","enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre")
		       if((a%4 != 0) && (m == 2) && (d > 28)){
					alert("Error en la fecha: El año "+ a +" no es bisiesto o "+ meses[m] +" no tiene "+ d +" días.");
					
					paso=true;
					return true;
			   }	   
			   else	
			   {
		          if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29))){
			         alert("Error en la fecha: "+ meses[m] +" no tiene "+ d +" días.");
					 document.getElementById[d].focus();
					 paso=true;
					 return true;
			   }}  
}		
return false;
}

function nomarcado(campo,nombre){//Si la opcion seleccionad es esta
	if(!document.getElementById(campo).checked){ return true;}
	else return false;
}
