﻿function hideBox(idBox) {
    document.getElementById(idBox).style.display = 'none';
}

function showBox(idBox) {
    document.getElementById(idBox).style.display = '';
}

function ganhaFoco(txt, strLabel) {
    if (txt.value == strLabel) { txt.value = ""; }
}

function perdeFoco(txt, strLabel) {
    if (txt.value == "") { txt.value = strLabel; }
}

function checkthis(oSrc, args) {
    args.IsValid = validaCPF(args.Value);
}

function FormataCampo(Campo, teclapres, mascara) {
    strtext = Campo.value
    tamtext = strtext.length
    tammask = mascara.length
    arrmask = new Array(tammask)
    for (var i = 0; i < tammask; i++) {
        arrmask[i] = mascara.slice(i, i + 1)
    }
    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 {
        if ((arrmask[tamtext] == "A")) {
            charupper = event.valueOf()
            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 == "-")) && !(teclapres_key == 8)) {
        separador = arrpos
        masktext = strtext + separador
        Campo.value = masktext
    }
}

function Detona_Event(Campo, strtext) {
    event.returnValue = false
    if (strtext != "") {
        Campo.value = strtext
    }
}
