var comprobador = function(){
	this.colorFondo = "#ACACAC";
	this.colorOriginal = "#FFFFFF";
	comprobador.prototype.vacio = function(campo, idioma){
		// FunciÃ³n para comprobar si los campos de texto requeridos estÃ¡n "llenos"
		var aux = document.getElementsByName(campo.name)[0];
		if (campo.value == ""){
			aux.style.backgroundColor = this.colorFondo; 
			aux.focus();
			return false;
		}
		aux.style.backgroundColor = this.colorOriginal;
		return true;
	}
	comprobador.prototype.valorNulo = function(campo, texto){
		// FunciÃ³n para comprobar si los campos de texto requeridos estÃ¡n "llenos"
		var aux = document.getElementsByName(campo.name)[0];
		if (campo.value == texto){
			aux.style.backgroundColor = this.colorFondo; 
			aux.focus();
			alert ("Rellene este campo con el texto a buscar");
			return false;
		}
		aux.style.backgroundColor = this.colorOriginal;
		return true;
	}
	comprobador.prototype.numero = function(campo){
		// FunciÃ³n para comprobar si el campo requerido tiene un número
		var aux = document.getElementsByName(campo.name)[0];
		valor = parseInt(campo.value);
      	if (isNaN(valor)) { 
			aux.style.backgroundColor = this.colorFondo; 
			aux.focus();
			alert ("Rellene este campo con un valor numerico");
			return false;
		}
		aux.style.backgroundColor = this.colorOriginal;
		return true;
	}
	comprobador.prototype.iguales = function (campo1, campo2, mensaje){
		// FunciÃ³n para comprobar que los campos pasados coinciden en su valor
		var aux = document.getElementsByName(campo2.name)[0];
		if (campo1.value != campo2.value){
			aux.style.backgroundColor = this.colorFondo;
			aux = document.getElementsByName(campo1.name)[0];
			aux.style.backgroundColor = this.colorFondo;
			aux.focus();
			alert (mensaje);
			return false;
		}
		aux.style.backgroundColor = this.colorOriginal;
		aux = document.getElementsByName(campo1.name)[0];
		aux.style.backgroundColor = this.colorOriginal;
		return true;
	}
	comprobador.prototype.seleccionValida = function (campo, valorNo){
		// FunciÃ³n para comprobar que el campo desplegable no estÃ¡ con la selecciÃ³n que se indica
		var aux = document.getElementsByName(campo.name)[0];
		if (campo.value == valorNo){
			aux.style.backgroundColor = this.colorFondo; 
			aux.focus();
			return false;
		}
		aux.style.backgroundColor = this.colorOriginal;
		return true;
	}
	comprobador.prototype.validarMail = function (campo){
		var aux = document.getElementsByName(campo.name)[0];
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo.value)){
			aux.style.backgroundColor = this.colorOriginal;
			return true;
		}else {
			aux.style.backgroundColor = this.colorFondo;
			aux.focus();
			campo.focus();
			return false;
		}
	}
	comprobador.prototype.validarDNI = function (campo){
		var aux = document.getElementsByName(campo.name)[0];
		dni = aux.value;
		numero = dni.substr(0,dni.length-1);
		let = dni.substr(dni.length-1,1).toUpperCase();
		numero = numero % 23;
		letra='TRWAGMYFPDXBNJZSQVHLCKET';
		letra=letra.substring(numero,numero+1);
		if (letra!=let){
			aux.style.backgroundColor = this.colorFondo;
			aux.focus();
			campo.focus();
			return false;
		}else{
			aux.style.backgroundColor = this.colorOriginal;
			return true;
		}
	}
	comprobador.prototype.validarCP = function (campo){
		var aux = document.getElementsByName(campo.name)[0];
		var RegExPattern = /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/;  
		if (aux.value.match(RegExPattern)) {  
			aux.style.backgroundColor = this.colorOriginal;
			return true;   
		} else {  
			aux.style.backgroundColor = this.colorFondo;
			aux.focus();
			campo.focus();
			return false;
		}   
	}
	comprobador.prototype.validarTelefono = function (campo){
		var aux = document.getElementsByName(campo.name)[0];
		var RegExPattern = /^[0-9]{2,3}-? ?[0-9]{6,7}$/;  
		if (aux.value.match(RegExPattern)) {  
			aux.style.backgroundColor = this.colorOriginal;
			return true;   
		} else {  
			aux.style.backgroundColor = this.colorFondo;
			aux.focus();
			campo.focus();
			return false;
		}   
	}
	comprobador.prototype.validarFecha = function(cadena){
		var Fecha= new String(cadena)  
		var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))  
		var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))  
		var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))  
		if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
			return false;
		}  
		if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
			return false;
		}  
		if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){    
			return false;
		}  
		if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
			if (Mes==2 && Dia > 28 || Dia>30) {    
				return false;
			}  
		}    
		return true;   
	}  
}

