function validateLength(oSrc, args){
   args.IsValid = (args.Value.length >= 8);
}

function validateInput(oInput, sMask, lConsiderLength, sMessage)
{	
	if (typeof(sMessage)=="undefined")
	{
		sMessage = "The value does not have the expected format: "+sMask+" !";
	}
	if (typeof(lConsiderLength)=="undefined")
	{
		lConsiderLength = false;
	}
	var sInput = oInput.value;
	var bRes = validateString(sInput, sMask, lConsiderLength);
	if (!bRes){
		alert(sMessage);
		doSelection(oInput);
		return false;
	}
	
	return true;
}

function validateString(sInput, sMask, lConsiderLength)
{
	var i;
	var n = sInput.length;
	var c;
	
	if (sInput == "")
	{
		return true;
	}
	if (lConsiderLength && (sMask.length != n))
	{
		return false;
	}
	for (i = 0; i < n; i ++)
	{
		c = sInput.charAt(i);
		if ((c >= '0') && (c <= '9'))
		{
			c = '9';
		}
		if ((c >= 'A') && (c <= 'Z'))
		{
			c = 'X';
		}		
		if ((c >= 'a') && (c <= 'z'))
		{
			c = 'X';
		}
		if (c != sMask.charAt(i))
		{
			return false;
		}
	}	
	
	return true;
}

function allowOnlyRange(evt, sFrom, sTo, bCase, bAndNumbers, cException)
{
	var charCode = evt.keyCode;
	var charFrom = sFrom.charCodeAt(0);
	var charTo = sTo.charCodeAt(0);
	var bResultA = false;
	var bResult1 = false;
	var bResultE = false;
	if (charCode > 31)
	{
		if (typeof(cException) != "undefined")
		{			
			bResultE = (charCode == cException.charCodeAt(0));
		}	
		if (!bResultE)
		{
			if (typeof(bCase) != "undefined")
			{
				charFrom &= 223;
				charTo &= 223;
				charCode &= 223;
			}	
			bResultA = (charCode <= charTo) && (charCode >= charFrom);		
			if (!bResultA)
			{
				if (typeof(bAndNumbers) != "undefined")
				{
					charCode += 48;
					bResult1 = (charCode <= charTo) && (charCode >= charFrom);
				}				
			}		
		}
		
		if (bResult1 || bResultA || bResultE)
		{
			if (evt.which)
			{
				evt.which = charCode;
			}
			else
			{
				event.keyCode = charCode;
			}		

			return true;		
		}
		else
		{
			return false;
		}				
	}
	
	return true;
}

function justPhoneCaracters(evt)
{	
	var charCode = (evt.which) ? evt.which : event.keyCode;	
	//alert( charCode );
	if( charCode > 31 )
	{
		return (charCode == 32) // space
		|| (charCode == 40) || (charCode == 41) // ()
		|| (charCode == 45) //-
		|| (charCode == 46) //.
		|| (charCode == 47) // /
		|| ((charCode >= 48) && (charCode <= 57)); //numbers
	}
	return true;
}

function justNum(evt, decimals){	
	if (typeof(decimals) == "undefined"){
		decimals = false;
	}
	var charCode = (evt.which) ? evt.which : event.keyCode;	
	if (charCode > 31){
		return ((charCode <= 57) && (charCode >= 48))  || ((charCode == 46) && decimals)
	}
	return true;
}

function dropJustNum(evt, decimals)
{	
	if( typeof(decimals) == "undefined" )
		decimals = false;
	var initialData = window.event.dataTransfer.getData( "Text" );
	evt.srcElement.focus();
 	var tr = document.selection.createRange();
 	tr.text = filterJustNum( initialData, decimals );
 	tr.select();
 	evt.returnValue = false;
 	return false;
}

function pasteJustNum(evt, decimals)
{	
	if( typeof(decimals) == "undefined" )
		decimals = false;
	var initialData = window.clipboardData.getData( "Text" );
	window.clipboardData.setData( "Text", filterJustNum( initialData, decimals ) );
 	return true;
}

function filterJustNum( initialData, decimals )
{
	var finalData = "";
	if( initialData != null )
	{
		for( i=0; i<initialData.length; i++ )
		{
			var charCode = initialData.charCodeAt(i);
			if( ( charCode <= 57 && charCode >= 48 )  || (charCode == 46 && decimals) )
				finalData += initialData.charAt(i)
		}
	}
	return finalData;
}

function isEmpty(cStr){
	if (cStr == null || trimstr(cStr) == ""){
		return true;
	}
	return false;
}

function validNumberRange(fld, low, high, message){
	if (typeof(message) == "undefined"){
		message = true;
	}
	if ((fld.value >= low) && (fld.value <= high)){
		return true;
	}
	else{				
		if (message){
			// focus/select
			alert("The field does not satisfy the range ["+ low+ ":"+high+']');
			setTimeout("doSelection(document.forms['" +	fld.form.name + "'].elements['" + fld.name + "'])", 0)
		}
		return false;
	}	
}

function makeProper(cStr){
	re = /(\S+)/g;
	cStr = cStr.replace(re, function($0, $1){
					return $0.substr(0,1).toUpperCase() + $0.substr(1).toLowerCase();
				}
			);
	return cStr;
}

function upcaseValue(oCtrl)
{
	oCtrl.value = oCtrl.value.toUpperCase();
}

function doSelection(fld, lWait){
	lWait = (typeof(lWait)=="undefined"?false:lWait);
	if (lWait){
		setTimeout("doSelection(document.forms['" +	fld.form.name + "'].elements['" + fld.name + "'])", 0);
	}else{				
		try{
			fld.focus();
			fld.select();
		}
		catch(e){			
			return false;
		}
	}
}