﻿//function ValidatorFCKEditor(sender, args) {    
//    var oEditor = FCKeditorAPI.__Instances["ctl00_ContentPlaceHolder1_ftbPosEvento"];
//    if (oEditor.GetHTML().length > 0)
//        args.IsValid = true;
//    else
//        args.IsValid = false;
//}

function popitup(url, tamanho) {
    newwindow = window.open(url, 'name', tamanho, scrollbars = 'yes');
    if (window.focus)
        newwindow.focus();
    return false;
}

function chkall(objControl) {
    var elem = document.getElementsByTagName("input");
    for (i = 0; i < elem.length; i++) {
        if (elem[i].type == "checkbox") {
            if (!elem[i].disabled) {
                if (objControl.checked) { elem[i].checked = 1; }
                else { elem[i].checked = 0; }
            }
        }
    }
}

function ApenasNumeros(e) {
    var key;

    if (window.event) {
        key = e.keyCode;
    }
    else if (e.which) {
        key = e.which;
    }
    return (key >= 48 && key <= 57);
}

//adiciona mascara
function formatar(src, mask) {
    var i = src.value.length;
    var saida = mask.substring(i, i + 1);
    var ascii = event.keyCode;

    if (saida == "A") {
        if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }
        else { event.keyCode = 0; }
    } else if (saida == "0") {
        if ((ascii >= 48) && (ascii <= 57)) { return }
        else { event.keyCode = 0 }
    } else if (saida == "#") {
        return;
    } else {
        src.value += saida;

        if ((saida != "A") && (saida != "0") && (saida != "#")) {
            if ((ascii >= 48) && (ascii <= 57)) { return }
            else { event.keyCode = 0 }
            if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }
            else { event.keyCode = 0; }
        }

        if (saida == "A") {
            if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }

        } else { return; }
    }
}

function mascara_num(obj, e) {
    var whichCode = e.keyCode;

    if (whichCode != 37 && whichCode != 39 && whichCode != 8 && whichCode != 46) {
        valida_num(obj)
        if (obj.value.match("-")) {
            mod = "-";
        }
        else {
            mod = "";
        }
        valor = obj.value.replace("-", "");
        valor = valor.replace(",", "");

        if (valor.length >= 3) {
            valor = poe_ponto_num(valor.substring(0, valor.length - 2)) + "," + valor.substring(valor.length - 2, valor.length);
        }
        obj.value = mod + valor;
    }
}

function poe_ponto_num(valor) {
    valor = valor.replace(/\./g, "");

    if (valor.length > 3) {
        valores = "";

        while (valor.length > 3) {
            valores = "." + valor.substring(valor.length - 3, valor.length) + "" + valores;
            valor = valor.substring(0, valor.length - 3);
        }
        return valor + "" + valores;
    }
    else {
        return valor;
    }
}

function valida_num(obj) {
    numeros = new RegExp("[0-9]");

    while (!obj.value.charAt(obj.value.length - 1).match(numeros)) {
        if (obj.value.length == 1 && obj.value == "-") {
            return true;
        }
        if (obj.value.length >= 1) {
            obj.value = obj.value.substring(0, obj.value.length - 1)
        }
        else {
            return false;
        }
    }
}

function isCpf(sender, args) {
    if (args.Value.length != 11 || args.Value == "00000000000" || args.Value == "11111111111" || args.Value == "22222222222" || args.Value == "33333333333" || args.Value == "44444444444" || args.Value == "55555555555" || args.Value == "66666666666" || args.Value == "77777777777" || args.Value == "88888888888" || args.Value == "99999999999") {
        //args.isValid == false; 
        return false;
    }
    
    add = 0;
    for (i = 0; i < 9; i++)
        add += parseInt(args.Value.charAt(i)) * (10 - i);

    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;

    if (rev != parseInt(args.Value.charAt(9))) {
        args.isValid == false; return;
    }

    add = 0;
    for (i = 0; i < 10; i++)
        add += parseInt(args.Value.charAt(i)) * (11 - i);

    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;

    if (rev != parseInt(args.Value.charAt(10))) {
        args.isValid == false; return;
    }

    args.isValid == true;
    return;
}

function isCnpj(cnpj) {
    var b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], c = cnpj;
    if ((c = c.replace(/[^\d]/g, "").split("")).length != 14) { return false; }
    for (var i = 0, n = 0; i < 12; n += c[i] * b[++i]);
    if (c[12] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for (var i = 0, n = 0; i <= 12; n += c[i] * b[i++]);
    if (c[13] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
}

function ValidateChkList(source, arguments) {
    arguments.IsValid = IsCheckBoxChecked() ? true : false;
}

function IsCheckBoxChecked() {
    var isChecked = false;

    var list = document.getElementById('<%= CheckBoxList1.ClientID %>');
    if (list != null) {
        for (var i = 0; i < list.rows.length; i++) {
            for (var j = 0; j < list.rows[i].cells.length; j++) {
                var listControl = list.rows[i].cells[j].childNodes[0];
                if (listControl.checked) {
                    isChecked = true;
                }
            }
        }
    }
    return isChecked;

}

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        document.getElementById('contador').innerHTML = maxlimit - field.value.length;
}

function MM_openBrWindow(theURL,winName,features) {
    window.open(theURL,winName,features);
}

/*
   <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem Text="First" ></asp:ListItem>
            <asp:ListItem Text="Second"></asp:ListItem>
        </asp:CheckBoxList>
        <asp:CustomValidator ID="CustomValidator1" ClientValidationFunction="ValidateChkList"
            runat="server" >Required.</asp:CustomValidator>
    </div>

*/

/*
function ApagaTextoPreDefinido(txt) {
textBox = document.getElementById(txt);
textBox.value = "";
}


function SetaTextoPreDefinido(txt, strPredefinido) {
textBox = document.getElementById(txt);
if (textBox.value.length == 0)
textBox.value = strPredefinido;
}  
*/