function FormataCampo(Campo,teclapres,mascara){ 

//pegando o tamanho do texto da caixa de texto com delay de -1 no event 
//ou seja o caractere que foi digitado não será contado. 
strtext = Campo.value 
tamtext = strtext.length 
//pegando o tamanho da mascara 
tammask = mascara.length 
//criando um array para guardar cada caractere da máscara 
arrmask = new Array(tammask) 
//jogando os caracteres para o vetor 
for (var i = 0 ; i < tammask; i++){ 
arrmask[i] = mascara.slice(i,i+1) 
} 
//alert (teclapres.keyCode) 
//começando o trabalho sujo 
if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) 
} 
else{ 
Detona_Event(Campo,strtext) 
} 
} 
else{//Aqui funcionaria a mascara para números mas eu ainda não implementei 
if ((arrmask[tamtext] == "A")) { 
charupper = event.valueOf() 
//charupper = charupper.toUpperCase() 
Detona_Event(Campo,strtext) 
masktext = strtext + charupper 
Campo.value = masktext 
} 
} 
} 
function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
if (((arrpos == "/") || (arrpos == ".") || (arrpos == "(") || (arrpos == ")") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
separador = arrpos 
masktext = strtext + separador 
Campo.value = masktext 
} 
} 
function Detona_Event(Campo,strtext){ 
event.returnValue = false 
if (strtext != "") { 
Campo.value = strtext 
} 
} 

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

