var total_de_divs_de_cursos = 1;

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
    }
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
        }
}

function validaemail(email) {
    var objRegExp  = /^[A-Za-z0-9]([\w\.\-\_]*)@([A-Za-z0-9\.]*)\.(([A-Za-z]{3}\.[A-Za-z]{2}$)|([A-Za-z]{3}$)|([a-z]{2}$))/i ;
    return objRegExp.test(email);
}

function envia(param) {
    if (param == 1) {
        if (document.f1.nome.value.length < 3) {
            alert("Preencha o campo NOME!");
            document.f1.nome.focus();
        }
        else {
            if (!validaemail(document.f1.email.value)) {
                alert("Preencha o campo E-MAIL!");
                document.f1.email.focus();
            }
            else {
                document.f1.submit();
            }
        }
    }
    else if (param == 2) {
        if (!validaemail(document.f2.emai.value)) {
            alert("Preencha o campo E-MAIL!");
            document.f2.emai.focus();
        }
        else {
            document.f2.submit();
        }
    }
    else if (param == 4) {
        if (document.f2.nome.value.length < 3) {
            alert("Preencha o campo NOME!");
            document.f2.nome.focus();
        }
        else {
            if (!validaemail(document.f2.email.value)) {
                alert("Preencha o campo E-MAIL!");
                document.f2.email.focus();
            }
            else {
                document.f2.submit();
            }
        }
    }
    else if (param == 5) {
        if (document.f1.assunto_relacionado_a.selectedIndex == 0) {
            alert("Preencha o campo Assunto!");
            document.f1.assunto_relacionado_a.focus();
        }
        else {
            if (document.f1.mensagem.value.length < 3) {
                alert("Preencha o campo MENSAGEM!");
                document.f1.mensagem.focus();
            }
            else {
                document.f1.submit();
            }
        }
    }
    else if ( param == 3 ) {
        if (document.f1.nome.value.length < 3) {
            alert("Preencha o campo NOME!");
            document.f1.nome.focus();
        }
        else {
            if (!validaemail(document.f1.email.value)) {
                alert("Preencha o campo E-MAIL!");
                document.f1.email.focus();
            }
            else {
                if ( document.f1.mensagem.value.length < 3 )
                {
                    alert("Preencha o campo MENSAGEM!");
                    document.f1.mensagem.focus();
                } else {
                    document.f1.submit();
                }
            }
        }
    } else {
        if (document.f1.nome.value.length < 3) {
            alert("Preencha o campo NOME!");
            document.f1.nome.focus();
        }
        else {
            if (!validaemail(document.f1.email.value)) {
                alert("Preencha o campo E-MAIL!");
                document.f1.email.focus();
            }
            else {
                document.f1.submit();
            }
        }
    }
}

var res = screen.height;
if (res <= 600)
{
    document.write('<style type="text/css">#geral{min-height:100%;_height:100%;}<\/style>')
}
else if ( res == 768 )
{
    document.write('<style type="text/css">#geral{min-height:92%;_height:92%;}<\/style>')
}
else if ( res == 864 )
{
    document.write('<style type="text/css">#geral{min-height:93%;_height:93%;}<\/style>')
}
else if ( res == 1024 )
{
    document.write('<style type="text/css">#geral{min-height:94%;_height:94%;}<\/style>')
}
else if ( res == 1200 )
{
    document.write('<style type="text/css">#geral{min-height:95%;_height:95%;}<\/style>')
}
else
{
    document.write('<style type="text/css">#geral{min-height:16%;_height:96%;}<\/style>')
}

function abre_popup(foto) {
    window.open('foto.htm?'+foto,'imagem','width=100, height=100, status=no');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}
/*
    COMO USAR
    EX: onkeypress="return Mascaras ( event, 'FONE', 'nome_id' );"
*/
function Mascaras ( e, formato, objeto )
{
    var key;

    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>

    if ( keyPressed >= 48 && keyPressed <= 57 )
    {
        var campo = document.getElementById(objeto);
        
        /*
            DATA
            FORMATO: 00/00/0000
        */
        if ( formato == 'DATA' )
        {
            separador = '/'; 
            conjunto1 = 2;
            conjunto2 = 5;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador;
            
            return true;
        }
        
        /*
            HORA
            FORMATO: 00:00
        */
        if (formato == 'HORA')
        {
            separador = ':';
            conjunto1 = 2;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            return true;
        }
        
        /*
            CEP
            FORMATO: 00000-000
        */
        if (formato == 'CEP')
        {
            separador = '-';
            conjunto1 = 5;
            if (    campo.value.length == conjunto1 )
                campo.value = campo.value + separador;
            
            return true;
        } 
        
        /*
            CPF
            FORMATO: 000.000.000-00
        */
        if (formato == 'CPF')
        {
            separador = '.';
            separador1 = '-';
            conjunto1 = 3;
            conjunto2 = 7;
            conjunto3 = 11;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador;

            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador;

            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador1;
            
            return true;
        }
        
        /*
            CNPJ
            FORMATO: 00.000.000/0000-00
        */
        if (formato == 'CNPJ')
        {
            separador1 = '.';
            separador2 = '/';
            separador3 = '-';
            conjunto1 = 2;
            conjunto2 = 6;
            conjunto3 = 10;
            conjunto4 = 15;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador2;
            
            if ( campo.value.length == conjunto4 )
                campo.value = campo.value + separador3;
            
            return true;
        }
        
        /*
            FONE
            FORMATO: (00) 0000-0000
        */
        if ( formato == 'FONE' )
        {
            separador1 = '(';
            separador2 = ') ';
            separador3 = '-';
            conjunto1 = 0;
            conjunto2 = 3;
            conjunto3 = 9;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            if ( campo.value.length == conjunto2 )
                campo.value = campo.value + separador2;
            
            if ( campo.value.length == conjunto3 )
                campo.value = campo.value + separador3;
            
            return true;
        }
        
        /*
            FONE2
            FORMATO: 0000-0000
        */
        if ( formato == 'FONESIMPLES' )
        {
            separador1 = '-';
            conjunto1 = 4;
            if ( campo.value.length == conjunto1 )
                campo.value = campo.value + separador1;
            
            return true;
        }
    }
    else if ( keyPressed == 8 || keyPressed == 13 || keyPressed == 0 )
        return true;
    else
        return false;
}

/*
    COMO USAR
    EX: onkeypress="return TextoSimples ( event );"
*/
function TextoSimples ( e )
{
    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>

    if ( keyPressed == 8 || keyPressed == 95  || keyPressed == 13  || keyPressed == 0 ) return true;
    else if ( ( keyPressed >= 48 && keyPressed <= 57 ) || (keyPressed > 96 && keyPressed < 123) || keyPressed == 95 ) return true;
    else if ( ( keyPressed > 191 && keyPressed < 221 ) || ( keyPressed > 223 && keyPressed < 253 ) ) return true;
    
    return false;
}

/*
    COMO USAR
    EX: onkeypress="return Numeros ( event );"
*/
function Numeros ( e )
{
    if ( window.event ) keyPressed = window.event.keyCode; // IE hack
    else keyPressed = e.which; // <B>standard method</B>
    
    if ( keyPressed == 8 || keyPressed == 13 || keyPressed == 0 ) return true;
    else if ( keyPressed >= 48 && keyPressed <= 57 ) return true;
              
    return false;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}


$(function(){
    //reinicia o indice
    $('#qtde').val(1);
    $(".bt_adicionar_cursos").click(function(){
        var qtde = $('#qtde').val();
                
        qtde++; 
        if(qtde >= 6){
            alert('O máximo permitido são 5 cursos');
            return false;
        }
                
                
        var texto = ' <div id="item_'+qtde+'" class="linha_curso">'+
        '<div class="linha4">'+
        '<label for="curso_interesse'+qtde+'">Curso de interesse:</label>'+
        '<span>'+
        '<select name="curso_interesse'+qtde+'" id="curso_interesse'+qtde+'" class="campo ValidaRequerido curso_interesse" onfocus="this.className=\'campo_over ValidaRequerido curso_interesse\'" onblur="this.className=\'campo ValidaRequerido curso_interesse\'" style="width:450px; height:25px;">'+
        '<option value="">Selecione</option>'+
       	'<option value="Prog I Basico">Prog. I Básico</option>'+
        '<option value="Prog II Intermediaria">Prog. II Intermediária</option>'+
        '<option value="Prog I e II">Prog. I e II</option>'+
        '<option value="Prog III Avancada">Prog. III Avançada</option>'+
        '<option value="Prog SQL">Prog. SQL</option>'+
        '<option value="Macro I">Macro I</option>'+
        '<option value="Macro Avancado">Macro Avançado</option>'+
		'</select>'+
        '</span>'+
        '</div>';
        texto += '<div class="linha5">'+
        '<label for="mes'+qtde+'">Mês de realização do curso:</label>'+
        '<select name="mes'+qtde+'" id="mes'+qtde+'" class="campo ValidaRequerido mes" onfocus="this.className=\'campo_over ValidaRequerido mes\'" onblur="this.className=\'campo ValidaRequerido mes\'" style="width:175px; height:25px;">'+
        '<option value="">Selecione o curso</option>'+
        '</select>'+
        '</div>';
        texto += '<div class="linha6">'+
        '<label for="data'+qtde+'">Data:</label>'+
        '<span>'+
        '<select name="data'+qtde+'" id="data'+qtde+'" class="campo ValidaRequerido" onfocus="this.className=\'campo_over ValidaRequerido\'" onblur="this.className=\'campo ValidaRequerido\'" style="width:267px; height:25px;">'+
        '<option value="">Selecione o mês</option>'+
        '</select>'+
        '</span>'+
        '</div>';
        texto +='<div class="botao_remover_curso">'+
        '<a href="javascript:void(0)" rel="'+qtde+'" class="link_remover_2 bt_remover" title="Remover este curso" alt="Remover este curso" ></a>'+
        '</div>'+
        '</div>';
                                        
        $("#maisItens").append(texto);
                
        //atualiza o item de quantidade
        $('#qtde').val(qtde);
                
    })
            
    $('.bt_remover').live('click', function() {
        var qtde = $(this).attr('rel');
                
        //atualiza o item de quantidade
        var itens = $('#qtde').val();
               
        //atualiza o item de quantidade
        $('#qtde').val(itens - 1);
                
        //remove os itens
        $("#item_"+qtde).remove();
                
    })
    
   //---------------------------------------------------------------------------
   // change curso
   //---------------------------------------------------------------------------
        
    $('.curso_interesse').live('change',function(){
        var nome_input = $(this).attr("id");
        
        var quebra = nome_input.split('curso_interesse');
        
        //RESETA OS ITENS
        $('#mes'+ quebra[1]).find('option')
                .remove()
                .end()
                .append('<option value="">Aguarde...</option>');
                
        $('#data'+ quebra[1]).find('option')
                .remove()
                .end()
                .append('<option value="">Selecione o mês</option>');
       
        curso = $(this).val();
        $.ajax({
            async:false,
            type:'POST',
            data:{
                curso:curso,
                opcao:'curso'
            },
            url: "php/solucoes-inscricao.php",
            success: function(e){
                $('#mes'+ quebra[1]).find('option')
                .remove()
                .end()
                .append(e);

            }
        });
    })
    
    //--------------------------------------------------------------------------
    // change do botao mes
    //--------------------------------------------------------------------------
    
    $('.mes').live('change',function(){
        var nome_input = $(this).attr("id");
        
        var quebra = nome_input.split('mes');
                       
        $('#data'+ quebra[1]).find('option')
                .remove()
                .end()
                .append('<option value="">Aguarde...</option>');
                
        curso = $("#curso_interesse"+quebra[1]).val();
        mes = $(this).val();
        $.ajax({
            async:false,
            type:'POST',
            data:{
                mes:mes,
                curso:curso,
                opcao:'mes'
            },
            url: "php/solucoes-inscricao.php",
            success: function(e){
                $('#data'+ quebra[1]).find('option')
                .remove()
                .end()
                .append(e);

            }
        });
    })
    
  
    
})



