///
function isMail(_email) {
     var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
     return emailReg.test(_email);
  }
///
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 EsTextoFecha(objTexto, bolPermitirNulo)
{
	objTexto.value = Trim(objTexto.value);
	if (bolPermitirNulo && objTexto.value.length == 0) {
		return true;
	}
	if (EsFecha(objTexto.value)) {
		return true;
	}
	else {
		return false;
	}
}

function Trim(strValue) 
{
	/************************************************
	DESCRIPTION: Removes leading and trailing spaces.
	PARAMETERS: Source string from which spaces will  be removed;
	RETURNS: Source string with whitespaces removed.
	*************************************************/  
	var objRegExp = /^(\s*)$/;
    //check for all spaces    
	if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)          
	   		return strValue;    
	}    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;   
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
	}  
	return strValue;
}

function EsFecha(strValor)
{
 	var objRegExp = /^\d{2}\/\d{2}\/\d{4}$/ 
  	//check to see if in correct format  
	if(!objRegExp.test(strValor)) {
    	return false; //doesn't match pattern, bad date  
	}
	else{
    	//var strSeparator = strValor.substring(2,3) //find date separator
    	var arrayDate = strValor.split('/'); //split date into month, day, year
    	//create a lookup for months not equal to Feb.
    	var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        	'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		var intDay = parseInt(arrayDate[0], 10); 
    	//check if month value and day value agree
    	if(arrayLookup[arrayDate[1]] != null) {
      		if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        		return true; //found in lookup table, good date    
		}    
    	//check for February    
		var intYear = parseInt(arrayDate[2],10);
    	var intMonth = parseInt(arrayDate[1],10);
    	if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
      		return true; //Feb. had valid number of days  
    }
  	return false; //any other values, bad date
}

function EsTextoEntero(objTexto, bolPermitirNulo, intMinimo, intMaximo)
{
	objTexto.value = Trim(objTexto.value);
	if (bolPermitirNulo && objTexto.value.length == 0) {
		return true;
	}
	if (EsEntero(objTexto.value, intMinimo, intMaximo)) {
		objTexto.value = parseInt(objTexto.value,10);
		return true;
	}
	else {
		return false;
	}
}

function EsTextoNumeric(objTexto, bolPermitirNulo, intMinimo, intMaximo)
{
	objTexto.value = Trim(objTexto.value);
	objTexto.value = objTexto.value.replace(/,/g,".");
	if (bolPermitirNulo && objTexto.value.length == 0) {
		return true;
	}
	if (EsNumeric(objTexto.value, intMinimo, intMaximo)) {
		objTexto.value = parseFloat(objTexto.value);
		return true;
	}
	else {
		return false;
	}
}


function EsEntero(strValor, intMinimo, intMaximo)
{
	var objRegExp = /(^(\+|-)?\d\d*$)/;
	var intValor;
	
	if (objRegExp.test(strValor)) {
		intValor = parseInt(strValor,10);
		if (! isNaN(intMinimo)) {
			if (intValor < intMinimo)
				return false
		}
		if (! isNaN(intMaximo)) {
			if (intValor > intMaximo)
				return false;
		}
		return true;
	}
	else {
		return false;
	}
}

function EsNumeric(strValor, numMinimo, numMaximo)
{
	var objRegExp = /(^(\+|-)?\d\d*\.\d*$)|(^(\+|-)?\d\d*$)/; 
	var numValor;
	
	if (objRegExp.test(strValor)) {
		numValor = parseFloat(strValor);
		if (! isNaN(numMinimo)) {
			if (numValor < numMinimo)
				return false
		}
		if (! isNaN(numMaximo)) {
			if (numValor > numMaximo)
				return false;
		}
		return true;
	}
	else {
		return false;
	}
}
