/**
 * Es una "clase" para crear objetos del tipo ValidatorClass estos objetos seran utilizados para validar cosas de los 
 * formularios como si es un numero valido, si es un correo valido, una fecha, etc, al final de este archivo se hace 
 * una instancia de esta clase ValidatorJS para que donde sea necesario acceder a algun metodo de esta clase se haga
 * de esta forma: ValidatorJS.METODO(PARAMETRO); ejem ValidatorJS.isDate(5,4,2005);
 */
function ValidatorClass(){
/**
 * Validacion de un correo para ver si es correctamente tecleado
 */
	this.isValidMail = function(sMail) {
		var regEmail	 = /^([A-Za-z0-9\-\_\.])+\@(([A-Za-z0-9\-\_])+\.)+([A-Za-z])+$/;
		if( !regEmail.test(sMail) ){
			return false;
		}
		return true;
	}
/**
 *	Valida si Es una fecha valida
 */
	this.isDate = function (day,month,year){
		var today = new Date();
		year = ((!year) ? this.y2k(today.getYear()):year);
		month = ((!month) ? today.getMonth():month-1);
		if (!day) return false
		var test = new Date(year,month,day);
		if ( (this.y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
			return true;
		else
			return false
	}
	this.y2k = function (number){
		return (number < 1000) ? number + 1900 : number; 
	}
/**
 * Funcion para ver si es Alfanumerico el texto que se pasa como parametro
 */
	this.isAlphanumeric = function (alphane){
		var numaric = alphane;
		for(var j=0; j<numaric.length; j++){
			var alphaa = numaric.charAt(j);
			var hh = alphaa.charCodeAt(0);
			if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==45) || (hh==95)){}
			else{
				return false;
			}
		}
	 	return true;
	}
/**
 * funcion para contar los caracteres k tiene el textarea del id que se manda como parametro y ver que no se pase del limite que se 
 * manda como parametro, te regresa el numero de caracteres que tiene este textarea
 */
	this.CountContTextArea = function (idTextArea, numLimit){
		var ObjTextArea = document.getElementById(idTextArea);
		if(ObjTextArea.value.length > numLimit){
			ObjTextArea.value = ObjTextArea.value.substring(0,numLimit);
		}
		return ObjTextArea.value.length
	}
/**
 * Si es un numero valido como primer parametro es el numero, el segundo es el 
 * numero minimo valido y el tercero es el numero maximo (solo valida enteros)
 */
	this.isValidNumber = function (dato,minimo,max){
		if (dato == ""){
			return false;
		}
		for (var i=0; i<dato.length; i++){
			var caracter = dato.substring(i,i+1);
			if (caracter < "0" || caracter > "9"){
				return false;
			}
		}
		var valor = parseInt(dato,10)
		if (valor<minimo || valor>max){
			return false;
		}
		return true
	}
	this.isValidName = function(texto){
		var regValid	 = /^(([^\-\.\?\'\!\´\?\<\>\¿\¡\_\!\r\n\t\*\~\`\(\)\/\\\&\%\$\#\"\=\{\}@\|¬°:;\"\+0-9])?([^\.\´\?\'\!\?\<\>\¿\¡\_\!\r\n\t\*\~\`\(\)\/\\\&\%\$\#\"\=\{\}@\|¬°:;\"\+0-9]*)[^\s\-\.\?\´\'\!\?\<\>\¿\¡\_\!\r\n\t\*\~\`\(\)\/\\\&\%\$\#\"\=\{\}@\|¬°:;\"\+0-9]){1,}$/;
		if( !regValid.test(texto) ){
			return false;
		}
		return true;
	}
}
var ValidatorJS = new ValidatorClass();