// carregar paginas externas tipo pop_up
function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

// marcara numeros
function Mascara(tipo, campo, teclaPress) {
    if (window.event)
    {
        var tecla = teclaPress.keyCode;
    } else {
        tecla = teclaPress.which;
    }

    var s = new String(campo.value);
    // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
    s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

    tam = s.length + 1;

    if ( tecla != 9 && tecla != 8 ) {
        switch (tipo)
        {
        case 'CPF' :
            if (tam > 3 && tam < 7)
                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
            if (tam >= 7 && tam < 10)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
            if (tam >= 10 && tam < 12)
                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
        break;

        case 'CNPJ' :

            if (tam > 2 && tam < 6)
                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
            if (tam >= 6 && tam < 9)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
        break;

        case 'TEL' :
            if (tam > 2 && tam < 4)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
            if (tam >= 7 && tam < 11)
                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
        break;

        case 'DATA' :
            if (tam > 2 && tam < 4)
                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
            if (tam > 4 && tam < 11)
                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
        break;
        
        case 'CEP' :
            if (tam > 5 && tam < 7)
                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
        break;
        }
    }
}

//Função para verificar se o valor digitado é número
function digitos(event){
    if (window.event) {
        // IE
        key = event.keyCode;
    } else if ( event.which ) {
        // netscape
        key = event.which;
    }
    if ( key != 8 || key != 13 || key < 48 || key > 57 )
        return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) || ( key == 13 ) );
    return true;
}

// Mascara para formatar moeda
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); 
    if (strCheck.indexOf(key) == -1) return false; 
    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;
}

// mask de cpf e cnpj
function v_NR(tecla)
{
if(typeof(tecla) == 'undefined')
var tecla = window.event;
var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
// permite números, 8=backspace, 46=del e 9=tab
if ( (codigo >= 48 && codigo <= 57) || (codigo >= 96 && codigo <= 105) || codigo == 8 || codigo == 46 || codigo == 9 )
{ return true; }
else
{ alert("Apenas números são permitidos !"); return false; }
}
//-----> máscara cnpj:
function m_CNPJ(campo,tammax) {
var vr = campo.value;
vr = vr.replace( "-", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
var tam = vr.length;
if (tam < tammax) { tam = vr.length + 1 ; }
tam = tam - 1;
if ( (tam > 2) && (tam <= 5) ) {
vr = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ) {
vr = vr.substr( 0, tam - 5 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }
if ( (tam >= 9) && (tam <= 11) ) {
vr = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }
if ( (tam >= 12) && (tam < 14) ) {
vr = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '/' + vr.substr( tam - 5, 4 ) + '-' + vr.substr( tam - 1, tam ) ; }
campo.value = vr;
}
//-----> máscara cpf:
function m_CPF(campo,tammax) {
var vr = campo.value;
vr = vr.replace( "-", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
var tam = vr.length;
if (tam < tammax) { tam = vr.length + 1; }
tam = tam - 1;
if ( (tam > 2) && (tam <= 11) ) {
vr = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ); }
if ( (tam == 10) ) {
vr = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, tam ); }
campo.value = vr;
}

// checa o preenchimento do campo cpf
function adm_cpf_checa_campos(){
    if(document.form_cpf.cpf_post.value == ""){
    alert("Preencha o campo CPF!");
    document.form_cpf.cpf_post.focus();
    return false;
   }
}

// checa os campos de inscricao
function checar_campos_inscricao(){
    if(document.inscricao.nome_curso.value == ""){
    alert("Por favor, Escolha um Curso!");
    document.inscricao.nome_curso.focus();
    return false;
   }
    if(document.inscricao.dia_semana.value == ""){
    alert("Por favor, Escolha um Dia da Semana!");
    document.inscricao.dia_semana.focus();
    return false;
   }
    if(document.inscricao.unidade_ensino.value == ""){
    alert("Por favor, Escolha uma Unidade de Ensino!");
    document.inscricao.unidade_ensino.focus();
    return false;
   }
    if(document.inscricao.forma_pagamento.value == ""){
    alert("Por favor, Escolha uma Forma de Pagamento!");
    document.inscricao.forma_pagamento.focus();
    return false;
   }
    if(document.inscricao.nome.value == ""){
    alert("Por favor, Preencha o campo Nome!");
    document.inscricao.nome.focus();
    return false;
   }
    if(document.inscricao.email.value == ""){
    alert("Por favor, Preencha o campo Email!");
    document.inscricao.email.focus();
    return false;
   }
    if(document.inscricao.data_nascimento.value == ""){
    alert("Por favor, Preencha o campo Data de Nascimento!");
    document.inscricao.data_nascimento.focus();
    return false;
   }
    if(document.inscricao.cpf.value == ""){
    alert("Por favor, Preencha do campo CPF!");
    document.inscricao.cpf.focus();
    return false;
   }
    if(document.inscricao.como_soube.value == ""){
    alert("Por favor, Escolha como Soube de Nossos Cursos!");
    document.inscricao.como_soube.focus();
    return false;
   }
}


