
function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}

function ShowCepPopup() {
    OpenWindow('http://m.correios.com.br/movel/buscaCep.do', 350, 450, true)
}

function validateCpf(val, args) 
{
            var cpf = args.Value;
            args.IsValid = false;
            var soma, i, resultado, digitos_iguais;
            var numeros, digitos;
            if (cpf.length != 11) return;
            digitos_iguais = 1;
            for (i = 0; i < cpf.length - 1; i++)
                if (cpf[i] != cpf[i + 1])
                {
                    digitos_iguais = 0;
                    break;
                }
            if (digitos_iguais == 1) return; 
            numeros = cpf.substring(0, 9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--) {
                j = 10 - i;
                soma += numeros[j] * i;
            }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos[0]) return; 

            numeros = cpf.substring(0, 10);
            soma = 0;
            for (i = 11; i > 1; i--) {
                j = 11 - i;
                soma += (numeros[j]) * i;
            }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos[1]) return;
            args.IsValid = true;
}
