function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function numeros(e)
{

	tecla		= new Number(0);
	
	if (!e) var e = window.event;
	
	if (e.keyCode) tecla = e.keyCode;  	
	else if (e.which) tecla = e.which; // Netscape 4.?
	else if (e.charCode) tecla = e.charCode; // Mozilla

	// numeros de 0 a 9 e a vírgula
	if ( tecla < 20 ||  (tecla > 47 && tecla < 58 ) || (tecla > 95 && tecla < 106 ) )
		return true;
	else
		return true;
	
}

function numeros_virgula(e , nome)
{

	tecla		= new Number(0);
	
	if (!e) var e = window.event;
	if (!nome) nome = this;
	
	if (e.keyCode) tecla = e.keyCode;  	
	else if (e.which) tecla = e.which; // Netscape 4.?
	else if (e.charCode) tecla = e.charCode; // Mozilla

	var virgula = nome.value.indexOf(",");
	
	// numeros de 0 a 9 e a vírgula
	if ( tecla < 20 ||  (tecla > 47 && tecla < 58 ) || (tecla > 95 && tecla < 106 ) || ( ( tecla == 188 || tecla == 110 ) && virgula == -1 && nome.value.length > 0 ) )
		return true;
	else
	{
		if (tecla != 8) // backspace
			return false;
		else
			return true;
	}
}

function validarEmail(email, tipo){
	
	if (!tipo) tipo = 2;
	
	reEmail		= new Array(3);
	reEmail[1]	= /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	reEmail[2]	= /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	reEmail[3]	= /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if ( reEmail[tipo].test(email) )
		return true;
	else
		return false;
	
}