/* TRIM */
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}

/*
- Mascara de Numeros para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskNumeros;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskNumeros;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 13;
*/
function getMaskNumeros(){ this.value = maskNumeros( this.value ); }
function maskNumeros( string ){
	string	= string.replace( /\D/g ,"");
    return string;
}

/*
- Mascara de RG para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskRG;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskRG;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 13;
*/
function getMaskRG(){ this.value = maskRG( this.value ); }
function maskRG( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /(\d{2})(\d)/ ,"$1.$2");
    string	= string.replace( /(\d{3})(\d)/ ,"$1.$2");
    string	= string.replace( /(\d{3})(\d)/ ,"$1-$2");
    if ( string.length > 13 ) string = string.substr(0, 13);
    return string;
}

/*
- Mascara de Telefone c/ DDD para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskTelefoneComDDD;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskTelefoneComDDD;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 12;
*/
function getMaskTelefoneComDDD(){ this.value = maskTelefoneComDDD( this.value ); }
function maskTelefoneComDDD( string ){
	string	= string.replace( /\D/g ,"");
	string	= string.replace( /^(\d)/ ,"($1");
	string	= string.replace( /^(\(\d{2})(\d)/ ,"$1) $2");
    string	= string.replace( /^(\d{2})(\d)/ ,"$1 $2");
    string	= string.replace( /(\d{4})(\d)/ ,"$1-$2");
    if ( string.length > 14 ) string = string.substr(0, 14);
    return string;
}

/*
- Mascara de Telefone para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskTelefone;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskTelefone;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 9;
*/
function getMaskTelefone(){ this.value = maskTelefone( this.value ); }
function maskTelefone( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /(\d{4})(\d)/ ,"$1-$2");
    if ( string.length > 9 ) string = string.substr(0, 9);
    return string;
}

/*
- Mascara de CPF para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskCPF;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskCPF;
- Deve ser setado o maxlength. Ex: form.texto.maxLength	= 14;
*/
function getMaskCPF(){ this.value = maskCPF( this.value ); }
function maskCPF( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /(\d{3})(\d)/ ,"$1.$2");
    string	= string.replace( /(\d{3})(\d)/ ,"$1.$2");
    string	= string.replace( /(\d{3})(\d{1,2})$/ ,"$1-$2");
	if ( string.length > 14 ) string = string.substr(0, 14);
    return string;
}

/*
- Mascara de Data para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskDate;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskDate;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 10;
*/
function getMaskDate(){ this.value = maskDate( this.value ); }
function maskDate( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /(\d{2})(\d)/ ,"$1/$2");
    string	= string.replace( /(\d{2})(\d)/ ,"$1/$2");
    if ( string.length > 10 ) string = string.substr(0, 10);
    return string;
}

/*
- Mascara de CEP para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskCEP;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskCEP;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 10;
*/
function getMaskCEP(){ this.value = maskCEP( this.value ); }
function maskCEP( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /^(\d{2})(\d)/ ,"$1.$2");
    string	= string.replace( /^(\d{2})\.(\d{3})(\d)/ ,"$1.$2-$3");
    if ( string.length > 10 ) string = string.substr(0, 10);
    return string;
}

/*
- Mascara de Money para campo input[text].
- Deve ser colocado no onkeyup. Ex: form.texto.onkeyup	= getMaskMoney;
- Deve ser colocado no onblur. Ex: form.texto.onblur	= getMaskMoney;
- Deve ser setado o maxLength. Ex: form.texto.maxLength	= 10;
*/
function getMaskMoney(){ this.value = maskMoney( this.value ); }
function maskMoney( string ){
	string	= string.replace( /\D/g ,"");
    string	= string.replace( /(\d)(\d{2}$)/ ,"$1,$2");
    string	= string.replace( /(\d)(\d{3})\,(\d{2}$)/ ,"$1.$2,$3");
    string	= string.replace( /(\d)(\d{3})\./g ,"$1.$2.");
    if ( string.length > 12 ) string = string.substr(0, 12);
    return string;
}

// função que verifica se a string passada é um e-mail válido.
function isEmail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string" && er.test(mail))
		return true;
	else if(typeof(mail) == "object" && er.test(mail.value))
		return true;
	else
		return false;
}

