﻿
/**** Estrutura que cria itens dinamicos para Informações Educacionais e Experiências Profissionais ****************************************/
var qtd_itens_profissional = 0;
var qtd_itens_educacional = 0;
function elemento_educacional()
{
    qtd_itens_educacional += 1;
    
    var lista = document.createElement("ul");
    lista.setAttribute("id","lista_educacional_"+ qtd_itens_educacional);
            
    var html    = "<li><label for=\"edu_nome_curso_"+ qtd_itens_educacional +"\"> Nome do curso:</label>";
    html    += "<input type=\"text\" name=\"edu_nome_curso_"+ qtd_itens_educacional +"\" id=\"edu_nome_curso_"+ qtd_itens_educacional +"\" class=\"txtfield\" onkeypress=\"return EnterCurriculo(event,'bt_enviarCurriculo');\" size=\"40\" maxlength=\"120\" /><span class=\"asterisco\">*</span>";
    html    += "<span id=\"erroedu_nome_curso_"+ qtd_itens_educacional +"\" class=\"messagererror\"></span></li>";
    
    html    += "<li><label for=\"edu_nivel_academico_"+ qtd_itens_educacional +"\">Nível acadêmico: </label>";
    html    += populaNivelAcademico('edu_nivel_academico_'+ qtd_itens_educacional)+"<span class=\"asterisco\">*</span>";
    html    += "<span id=\"erroedu_nivel_academico_"+ qtd_itens_educacional +"\" class=\"messagererror\"></span></li>";
    
    html    += "<li class=\"form_bith\"><label for=\"edu_data_inicio_"+ qtd_itens_educacional +"\">Data inicial:</label>";
    html    += "<input type=\"text\" name=\"edu_data_inicio_"+ qtd_itens_educacional +"\" id=\"edu_data_inicio_"+ qtd_itens_educacional +"\" class=\"txtfield\" size=\"12\" maxlength=\"10\" OnKeyDown=\"WBR_Formata_OnKeyDown(event, this);\" OnPaste=\"WBR_Formata_OnPaste(this);\" maskDisplay=\"_\" OnClick=\"WBR_Formata_OnClick(event, this);\" onBlur=\"trata_valor(this)\" OnInput=\"WBR_Formata_OnImput(event, this);\" onFocus=\"WBR_Formata_OnFocus(this);\" OnKeyPress=\"WBR_Formata_OnKeyPress(event, this);return EnterCurriculo(event,'bt_enviarCurriculo');\" mask=\"nn/nn/nnnn\" OnCut=\"WBR_Formata_OnCut(this);\" /><span class=\"asterisco\">*</span>";
    html    += "<span id=\"erroedu_data_inicio_"+ qtd_itens_educacional +"\" class=\"messagererror\"></span></li>";
    
    html    += "<li class=\"form_bith\"><label for=\"edu_data_final_"+ qtd_itens_educacional +"\">Data final:</label>";
    html    += "<input type=\"text\" name=\"edu_data_final_"+ qtd_itens_educacional +"\" id=\"edu_data_final_"+ qtd_itens_educacional +"\" class=\"txtfield\" size=\"12\" maxlength=\"10\" OnKeyDown=\"WBR_Formata_OnKeyDown(event, this);\" OnPaste=\"WBR_Formata_OnPaste(this);\" maskDisplay=\"_\" OnClick=\"WBR_Formata_OnClick(event, this);\" onBlur=\"trata_valor(this)\" OnInput=\"WBR_Formata_OnImput(event, this);\" onFocus=\"WBR_Formata_OnFocus(this);\" OnKeyPress=\"WBR_Formata_OnKeyPress(event, this);return EnterCurriculo(event,'bt_enviarCurriculo');\" mask=\"nn/nn/nnnn\" OnCut=\"WBR_Formata_OnCut(this);\" /><span class=\"asterisco\">*</span>";
    html    += "<span id=\"erroedu_data_final_"+ qtd_itens_educacional +"\" class=\"messagererror\"></span></li>";
    	
	html    += "<li><a href=\"javascript:;\" onclick=\"remove_elemento('estrutura_educacional','lista_educacional_"+ qtd_itens_educacional+"');\">Excluir</a></li>";
	html    += "<li><a href=\"javascript:;\" onclick=\"elemento_educacional();\">Clique aqui e adicione mais uma opção</a></li>";
	
	lista.innerHTML = html;
	document.getElementById('estrutura_educacional').appendChild(lista);
}

function elemento_experiencia_profissional()
{
    qtd_itens_profissional += 1;
    
    var lista = document.createElement("ul");
    lista.setAttribute("id","lista_exp_"+ qtd_itens_profissional);
    
    
    var html = "<li><label for=\"exp_nome_empresa_"+ qtd_itens_profissional +"\"> Nome da empresa:</label>";
    html    += "<input type=\"text\" name=\"exp_nome_empresa_"+ qtd_itens_profissional +"\" id=\"exp_nome_empresa_"+ qtd_itens_profissional +"\" class=\"txtfield\" onkeypress=\"return EnterCurriculo(event,'bt_enviarCurriculo');\" size=\"40\" maxlength=\"120\" /><span class=\"asterisco\">*</span>";
	html    += "<span id=\"erroexp_nome_empresa_"+ qtd_itens_profissional +"\" class=\"messagererror\"></span></li>";
	
	var optionsRamoAtividade = curriculo.RetornaRamoAtividade().value;
	var options = "";
	for(var i = 0; i < optionsRamoAtividade.length; i ++)
	{
	    options += "<option value=\"" + optionsRamoAtividade[i].Codigo_CurriculoRamoAtividade + "\" >" + optionsRamoAtividade[i].Ramo_atividade + "</option>"
	}
		
	html    += "<li>";
	html    += "<label for=\"exp_ramo_atividade_"+ qtd_itens_profissional + "\"> Ramo de Atividade: </label>";
	html    += "<select id=\"ramo_atividade_" + qtd_itens_profissional + "\" class=\"txtfield\" style=\"height: 100px; width: 200px;\" name=\"area_especializacao_" + qtd_itens_profissional + "\" multiple=\"multiple\" size=\"4\">";
	html    += options;
	html    += "</select>";
	html    += "<input  type=\"button\" onClick=\"return RemoveRamoAtividade('ramo_atividade_"+qtd_itens_profissional+"', 'ramo_atividade_selecionada_"+qtd_itens_profissional+"', 'valoresRamoAtividade_" + qtd_itens_profissional + "');\" value=\" << \" id=\"remover_ramoAtividade_" + qtd_itens_profissional + "\" />";
	html    += "<input  type=\"button\" onClick=\"return InsereRamoAtividade('ramo_atividade_"+qtd_itens_profissional+"', 'ramo_atividade_selecionada_"+qtd_itens_profissional+"', 'valoresRamoAtividade_" + qtd_itens_profissional + "');\" value=\" >> \" id=\"adicionar_ramoAtividade_" + qtd_itens_profissional + "\" />";
	html    += "<select id=\"ramo_atividade_selecionada_" + qtd_itens_profissional + "\" class=\"txtfield\" style=\"height: 100px; width: 200px;\" name=\"ramo_atividade_selecionada_" + qtd_itens_profissional + "\" multiple=\"multiple\" size=\"4\">";
	html    += "<input type=\"hidden\" id=\"valoresRamoAtividade_" + qtd_itens_profissional + "\" />";
	html    += "</li>";
	
	html    += "<li class=\"form_bith\"><label for=\"exp_data_admissao_"+ qtd_itens_profissional +"\">Data de admissão:</label>";
	html    += "<input type=\"text\" name=\"exp_data_admissao_"+ qtd_itens_profissional +"\" id=\"exp_data_admissao_"+ qtd_itens_profissional +"\" class=\"txtfield\" size=\"12\" maxlength=\"10\" OnKeyDown=\"WBR_Formata_OnKeyDown(event, this);\" OnPaste=\"WBR_Formata_OnPaste(this);\" maskDisplay=\"_\" OnClick=\"WBR_Formata_OnClick(event, this);\" onBlur=\"trata_valor(this)\" OnInput=\"WBR_Formata_OnImput(event, this);\" onFocus=\"WBR_Formata_OnFocus(this);\" OnKeyPress=\"WBR_Formata_OnKeyPress(event, this);return EnterCurriculo(event,'bt_enviarCurriculo');\" mask=\"nn/nn/nnnn\" OnCut=\"WBR_Formata_OnCut(this);\" /> <span class=\"asterisco\">*</span>";
	html    += "<span id=\"erroexp_data_admissao_"+ qtd_itens_profissional +"\" class=\"messagererror\"></span></li>";
	
	html    += "<li class=\"form_bith\"><label for=\"exp_data_desligamento_"+ qtd_itens_profissional +"\">Data de desligamento:</label>";
	html    += "<input type=\"text\" name=\"exp_data_desligamento_"+ qtd_itens_profissional +"\" id=\"exp_data_desligamento_"+ qtd_itens_profissional +"\" class=\"txtfield\" size=\"12\" maxlength=\"10\" OnKeyDown=\"WBR_Formata_OnKeyDown(event, this);\" OnPaste=\"WBR_Formata_OnPaste(this);\" maskDisplay=\"_\" OnClick=\"WBR_Formata_OnClick(event, this);\" onBlur=\"trata_valor(this)\" OnInput=\"WBR_Formata_OnImput(event, this);\" onFocus=\"WBR_Formata_OnFocus(this);\" OnKeyPress=\"WBR_Formata_OnKeyPress(event, this);return EnterCurriculo(event,'bt_enviarCurriculo');\" mask=\"nn/nn/nnnn\" OnCut=\"WBR_Formata_OnCut(this);\" />";
	html    += "<span id=\"erroexp_data_desligamento_"+ qtd_itens_profissional +"\" class=\"messagererror\"></span></li>";
	
	html    += "<li><label for=\"exp_cargo_ocupado_"+ qtd_itens_profissional +"\"> Cargo ocupado:</label>";
	html    += "<input type=\"text\" name=\"exp_cargo_ocupado_"+ qtd_itens_profissional +"\" id=\"exp_cargo_ocupado_"+ qtd_itens_profissional +"\" class=\"txtfield\" onkeypress=\"return EnterCurriculo(event,'bt_enviarCurriculo');\" size=\"40\" maxlength=\"120\" /> <span class=\"asterisco\">*</span>";
	html    += "<span id=\"erroexp_cargo_ocupado_"+ qtd_itens_profissional +"\" class=\"messagererror\"></span></li>";
	
	html    += "<li><label for=\"exp_descricao_atividades_"+ qtd_itens_profissional +"\">Descrição das atividades:</label>";
	html    += "<textarea name=\"exp_descricao_atividades_"+ qtd_itens_profissional +"\" id=\"exp_descricao_atividades_"+ qtd_itens_profissional +"\" cols=\"50\" class=\"txtfield\" title=\"Informe aqui suas atividades desempenhadas na empresa.\" rows=\"8\"></textarea> <span class=\"asterisco\">*</span>";
	html    += "<span id=\"erroexp_descricao_atividades_"+ qtd_itens_profissional +"\" class=\"messagererror\"></span></li>";
	
	html    += "<li><a href=\"javascript:;\" onclick=\"remove_elemento('estrutura_exp_profissional','lista_exp_"+ qtd_itens_profissional+"');\">Excluir</a></li>";
	html    += "<li><a href=\"javascript:;\" onclick=\"elemento_experiencia_profissional();\">Clique aqui e adicione mais uma opção</a></li>";
	
	lista.innerHTML = html;
	document.getElementById('estrutura_exp_profissional').appendChild(lista);
}

//Função que retorna o dropdown de Ramo de Atividade populado
function populaNivelAcademico(id)
{
    return curriculo.PopulaNivelAcademico(id).value;
}

//Função que retorna o dropdown de Ramo de Atividade populado
function populaRamoAtividade(id)
{
    return curriculo.PopulaRamoAtividade(id).value;
}

function remove_elemento(pai,filho)
{
    var elemento = document.getElementById(filho);
    document.getElementById(pai).removeChild(elemento);
}
/*******************************************************************************************************************************************/

/**** Estrutura que controla os itens do campo Área de Especialização **********************************************************************/
function RemoveAreaEspecializacao()
{
    var qtdOptions = $('area_especializacao_selecionada').options.length;
    
    $('valoresAreaEspecializacao').value = "";
    
    for(var i=qtdOptions-1; i >= 0; i--)
    {
        if($('area_especializacao_selecionada').options[i].selected)
        {
            var textSelected = $('area_especializacao_selecionada').options[$('area_especializacao_selecionada').options[i].index].text;
            var valueSelected = $('area_especializacao_selecionada').options[$('area_especializacao_selecionada').options[i].index].value;
            
            $('area_especializacao').options[$('area_especializacao').options.length] = new Option(textSelected , valueSelected);
                                                    
            $('area_especializacao_selecionada').remove($('area_especializacao_selecionada').options[i].index);
        }
    } 
    
    var qtdOptions2 = $('area_especializacao_selecionada').options.length;
    
    for(var i=qtdOptions2-1; i >= 0; i--)
    {
         $('valoresAreaEspecializacao').value += $('area_especializacao_selecionada').options[i].value+";";   
    }
    return false;
}

function InsereAreaEspecializacao()
{   
    var qtdOptions = $('area_especializacao').options.length;
    
    arrayRemove = new Array();
    
    for (var i = qtdOptions -1; i >= 0;i--)
    {
        
        if($('area_especializacao').options[i].selected)
        {
            var textSelected = $('area_especializacao').options[$('area_especializacao').options[i].index].text;
            var valueSelected = $('area_especializacao').options[$('area_especializacao').options[i].index].value;
            
            $('area_especializacao_selecionada').options[$('area_especializacao_selecionada').options.length] = new Option(textSelected , valueSelected);
            
            $('valoresAreaEspecializacao').value += valueSelected+";";
            
            $('area_especializacao').remove($('area_especializacao').options[i].index);
        }
    }
    return false;
}
/*******************************************************************************************************************************************/


/**** Estrutura que controla os itens do campo Ramo de Atividade**********************************************************************/
function RemoveRamoAtividade(campo, campoSelected, campoHidden)
{
    var qtdOptions = $(campoSelected).options.length;
    
    $(campoHidden).value = "";
    
    for(var i=qtdOptions-1; i >= 0; i--)
    {
        if($(campoSelected).options[i].selected)
        {
            var textSelected = $(campoSelected).options[$(campoSelected).options[i].index].text;
            var valueSelected = $(campoSelected).options[$(campoSelected).options[i].index].value;
            
            $(campo).options[$(campo).options.length] = new Option(textSelected , valueSelected);
                                                    
            $(campoSelected).remove($(campoSelected).options[i].index);
        }
    } 
    
    var qtdOptions2 = $(campoSelected).options.length;
    
    for(var i=qtdOptions2-1; i >= 0; i--)
    {
         $(campoHidden).value += $(campoSelected).options[i].value+";";   
    }
    return false;
}

function InsereRamoAtividade(campo, campoSelected, campoHidden)
{   
    var qtdOptions = $(campo).options.length;
    
    arrayRemove = new Array();
    
    for (var i = qtdOptions -1; i >= 0;i--)
    {
        
        if($(campo).options[i].selected)
        {
            var textSelected = $(campo).options[$(campo).options[i].index].text;
            var valueSelected = $(campo).options[$(campo).options[i].index].value;
            
            $(campoSelected).options[$(campoSelected).options.length] = new Option(textSelected , valueSelected);
            
            $(campoHidden).value += valueSelected+";";
            
            $(campo).remove($(campo).options[i].index);
        }
    }
    return false;
}
/*******************************************************************************************************************************************/




//Realização a validação das informações no Formulario
function ValidaFormCurriculo()
{
    var sucesso = true;
    
    // Define os estilos padrões
    document.getElementById('nome').className = 'txtfield';
    document.getElementById('erronome').style.display = 'none';
            
    document.getElementById('email').className = 'txtfield';
    document.getElementById('erroemail').style.display = 'none';
            
    document.getElementById('sexo').className = 'txtfield';
    document.getElementById('errosexo').style.display = 'none';
    
    document.getElementById('estado_civil').className = 'txtfield';
    document.getElementById('erroestado_civil').style.display = 'none';    
    
    document.getElementById('nascimento').className = 'txtfield';
    document.getElementById('erronascimento').style.display = 'none';
        
    document.getElementById('info_cep').className = 'txtfield';
    document.getElementById('erroinfo_cep').style.display = 'none';
    
    document.getElementById('info_endereco').className = 'txtfield';
    document.getElementById('erroinfo_endereco').style.display = 'none';
        
    document.getElementById('info_numero').className = 'txtfield';
    document.getElementById('erroinfo_numero').style.display = 'none';
        
    document.getElementById('info_complemento').className = 'txtfield';
    document.getElementById('erroinfo_complemento').style.display = 'none';
    
    document.getElementById('info_bairro').className = 'txtfield';
    document.getElementById('erroinfo_bairro').style.display = 'none';
    
    document.getElementById('info_estado').className = 'txtfield';
    document.getElementById('erroinfo_estado').style.display = 'none';
    
    document.getElementById('info_cidade').className = 'txtfield';
    document.getElementById('erroinfo_cidade').style.display = 'none';
    
    document.getElementById('fone_residencial').className = 'txtfield';
    document.getElementById('errofone_residencial').style.display = 'none';
    
    document.getElementById('fone_celular').className = 'txtfield';
    document.getElementById('errofone_celular').style.display = 'none';
    
    document.getElementById('remuneracao_pretendida').className = 'txtfield';
    document.getElementById('erroremuneracao_pretendida').style.display = 'none';
    
    document.getElementById('area_atuacao').className = 'txtfield';
    document.getElementById('erroarea_atuacao').style.display = 'none';
    
    document.getElementById('horario').className = 'txtfield';
    document.getElementById('errohorario').style.display = 'none';
        
        
    document.getElementById('outras_extra_curricular').className = 'txtfield';
    document.getElementById('errooutras_extra_curricular').style.display = 'none';        
        
        
        
    //Área de Especialização    
    document.getElementById('area_especializacao').className = 'txtfield';
    document.getElementById('area_especializacao_selecionada').className = 'txtfield';
    document.getElementById('erroarea_especializacao').style.display = 'none';
    
    var qtdEspecializacao = $('area_especializacao_selecionada').options.length;
    if(qtdEspecializacao < 1)
    {
        document.getElementById('area_especializacao').className = 'error';
        document.getElementById('area_especializacao_selecionada').className = 'error';
        
        document.getElementById('erroarea_especializacao').style.display = '';
        document.getElementById('erroarea_especializacao').innerHTML = 'Por favor, informe ao menos uma área de especialização.';
        
        sucesso = false;
    }
        
    //Realiza validação das informações de Educação
    //Chama a função 'valida_informacao_educacional' para realizar essa validação  por ser dinamico a criação dos campos
    if(valida_informacao_educacional() == false)
    {
        sucesso = false;
    }
    
    //Realiza validação das informações de Experiencia Profissional
    //Chama a função 'valida_informacao_experiencia_profissional' para realizar essa validação por ser dinamico a criação dos campos
    if(valida_informacao_experiencia_profissional() == false)
    {
        sucesso = false;
    }
    
    //Realiza validação das informações de Idiomas
    //Chama a função 'valida_informacao_experiencia_profissional' para realizar essa validação por ser dinamico a criação dos campos
    if(valida_idioma() == false)
    {
        sucesso = false;
    }
        
    if(EmptyField(document.getElementById('nome')))
    {
        sucesso = false;
        document.getElementById('nome').className = 'error';
        document.getElementById('erronome').style.display = '';
        document.getElementById('erronome').innerHTML = 'Por favor, informe seu nome.';  
    }
    
    
    if(EmptyField(document.getElementById('email')))
    {
        sucesso = false;
        document.getElementById('email').className = 'error';
        document.getElementById('erroemail').style.display = '';
        document.getElementById('erroemail').innerHTML = 'Por favor, informe um e-mail para contato.';  
    }
    else
    {
        if(!valida_email(document.getElementById('email')))
        {
            sucesso = false;
            document.getElementById('email').className = 'error';
            document.getElementById('erroemail').style.display = '';
            document.getElementById('erroemail').innerHTML = 'E-mail inválido.';  
        }
    }
                    
    if(document.getElementById('sexo').value == '0')
    {
        sucesso = false;
        document.getElementById('sexo').className = 'error';
        document.getElementById('errosexo').style.display = '';
        document.getElementById('errosexo').innerHTML = 'Por favor, informe seu sexo.';  
    }
    if(document.getElementById('estado_civil').value == '0')
    {
        sucesso = false;
        document.getElementById('estado_civil').className = 'error';
        document.getElementById('erroestado_civil').style.display = '';
        document.getElementById('erroestado_civil').innerHTML = 'Por favor, informe seu estado civil.';  
    }
    
    if(EmptyField(document.getElementById('nascimento')))
    {
        sucesso = false;
        document.getElementById('nascimento').className = 'error';
        document.getElementById('erronascimento').style.display = '';
        document.getElementById('erronascimento').innerHTML = 'Por favor, informe sua data de nascimento.';  
    }
    else
    {
        if(!valida_data(document.getElementById('nascimento')))
        {
            sucesso = false;
            document.getElementById('nascimento').className = 'error';
            document.getElementById('erronascimento').style.display = '';
            document.getElementById('erronascimento').innerHTML = 'Data em formato inválido.';  
        }
    }
        
    if(EmptyField(document.getElementById('info_cep')))
    {
        sucesso = false;
        document.getElementById('info_cep').className = 'error';
        document.getElementById('erroinfo_cep').style.display = '';
        document.getElementById('erroinfo_cep').innerHTML = 'Por favor, informe o CEP da residência.';  
    }
    else
    {
        if(!valida_CEP(document.getElementById('info_cep')))
        {
            sucesso = false;
            document.getElementById('info_cep').className = 'error';
            document.getElementById('erroinfo_cep').style.display = '';
            document.getElementById('erroinfo_cep').innerHTML = 'CEP em formato inválido.';      
        }   
    }
    if(EmptyField(document.getElementById('info_endereco')))
    {
        sucesso = false;
        document.getElementById('info_endereco').className = 'error';
        document.getElementById('erroinfo_endereco').style.display = '';
        document.getElementById('erroinfo_endereco').innerHTML = 'Por favor, informe o endereço da residência.';  
    }
    if(EmptyField(document.getElementById('info_numero')))
    {
        sucesso = false;
        document.getElementById('info_numero').className = 'error';
        document.getElementById('erroinfo_numero').style.display = '';
        document.getElementById('erroinfo_numero').innerHTML = 'Por favor, informe o número da residência.';  
    }
    if(EmptyField(document.getElementById('info_bairro')))
    {
        sucesso = false;
        document.getElementById('info_bairro').className = 'error';
        document.getElementById('erroinfo_bairro').style.display = '';
        document.getElementById('erroinfo_bairro').innerHTML = 'Por favor, informe o bairro da residência.';  
    }
    if(document.getElementById('info_estado').value == '0')
    {
        sucesso = false;
        document.getElementById('info_estado').className = 'error';
        document.getElementById('erroinfo_estado').style.display = '';
        document.getElementById('erroinfo_estado').innerHTML = 'Por favor, informe o estado em que reside.';  
    }
    if(document.getElementById('info_cidade').value == '0')
    {
        sucesso = false;
        document.getElementById('info_cidade').className = 'error';
        document.getElementById('erroinfo_cidade').style.display = '';
        document.getElementById('erroinfo_cidade').innerHTML = 'Por favor, informe a cidade em que reside.';  
    }
    
    if(EmptyField(document.getElementById('fone_residencial')) && EmptyField(document.getElementById('fone_celular')))
    {
        sucesso = false;
        document.getElementById('fone_residencial').className = 'error';
        document.getElementById('errofone_residencial').style.display = '';
        document.getElementById('errofone_residencial').innerHTML = 'Por favor, informe o telefone residencial ou telefone celular.'; 
    }else{
        if(!EmptyField(document.getElementById('fone_residencial')))
        {
            if(!valida_telefone(document.getElementById('fone_residencial')))
            {
                sucesso = false;
                document.getElementById('fone_residencial').className = 'error';
                document.getElementById('errofone_residencial').style.display = '';
                document.getElementById('errofone_residencial').innerHTML = 'Telefone em formato inválido.';  
            }
        }
        if(!EmptyField(document.getElementById('fone_celular')))
        {
           if(!valida_telefone(document.getElementById('fone_celular')))
           {
               sucesso = false;
               document.getElementById('fone_celular').className = 'error';
               document.getElementById('errofone_celular').style.display = '';
               document.getElementById('errofone_celular').innerHTML = 'Telefone em formato inválido.';  
           }
        }
    }
    
    if(document.getElementById('remuneracao_pretendida').value =='0')
    {
        sucesso = false;
        document.getElementById('remuneracao_pretendida').className = 'error';
        document.getElementById('erroremuneracao_pretendida').style.display = '';
        document.getElementById('erroremuneracao_pretendida').innerHTML = 'Por favor, informe a remuneração pretendida.';  
    }
    if(EmptyField(document.getElementById('area_atuacao')))
    {
        sucesso = false;
        document.getElementById('area_atuacao').className = 'error';
        document.getElementById('erroarea_atuacao').style.display = '';
        document.getElementById('erroarea_atuacao').innerHTML = 'Por favor, informe a área de atuação.';  
    }
        
    if(document.getElementById('horario').value == '0')
    {
        sucesso = false;
        document.getElementById('horario').className = 'error';
        document.getElementById('errohorario').style.display = '';
        document.getElementById('errohorario').innerHTML = 'Por favor, informe sua disponibilidade de horário.';  
    }

    if (!sucesso) {
        alert('Alguns campos não foram preenchidos da forma devida. Por favor, verifique os campos marcados em vermelho.'); 
        return false;
    }
    
    //Conjunto de Informações referente a tabela Curriculo
    var _nome = document.getElementById('nome').value;
    var _dtNascimento = document.getElementById('nascimento').value;
    var _email = document.getElementById('email').value;
    var _telResidencial = document.getElementById('fone_residencial').value;
    var _telCelular = document.getElementById('fone_celular').value;
    var _endereco = document.getElementById('info_endereco').value;
    var _numero = document.getElementById('info_numero').value; 
    var _bairro = document.getElementById('info_bairro').value;
    var _complemento = document.getElementById('info_complemento').value;
    var _cep = document.getElementById('info_cep').value;
    var _observacao_contato = document.getElementById('observacoes_contato').value;
    var _area_atuacao = document.getElementById('area_atuacao').value;
    var _upload_imagem = document.getElementById('upload_imagem').value;
    var _necessidade_especial = document.getElementById('necessidade_especial').value;
    var _remuneracao_pretendida = document.getElementById('remuneracao_pretendida').value;
    var _estado_civil = document.getElementById('estado_civil').value;
    var _cidade = document.getElementById('info_cidade').value;
    var _sexo = document.getElementById('sexo').value;
    var _horario = document.getElementById('horario').value;
    
    var vaga_pk_ = document.getElementById('vaga_pk').value;
        
    /*************************************************************************************************/
    /* Codigo responsavel por montar em um array os valores de da Area de Especilizacao selecionados */
    var qtdEspecializacao = $('area_especializacao_selecionada').options.length;
    var valores_especializacao = new Array();

    for(var i = 0; i < qtdEspecializacao; i++)
    {
        valores_especializacao[i] =  $('area_especializacao_selecionada').options[i].value;
    }
    
    /**************************************************************************************************/
    /* recupera os valores dos checkbox selecionados  - extra curriculares */
//    var qtd_itens_extracurriculares = document.getElementById('qtd_atividades').value;
//    var valores_extracurriculares = "";
//    var valoresEC = "";
//    for( var i = 1; i < qtd_itens_extracurriculares; i++)
//    {   
//        if(document.getElementById('at_'+i).checked == true)
//        {
//            valoresEC += document.getElementById('at_'+i).value + ";";
//            alert(document.getElementById('at_'+i).value);
//        }
//    }   
//    valores_extracurriculares = valoresEC;        
    
    
    /*************************************************************************************************/
    /* Codigo responsavel por montar um array dos valores de Idioma                                  */
    var qtd_idioma = document.getElementById('qtd_idioma').value;
    var qtd_habilidade = document.getElementById('qtd_habilidade').value;
    var valores_idioma = new Array();
    
    for(var i = 0; i < qtd_idioma; i++)
    {
        if(document.getElementById('drop_idioma_'+ i ).value != '0')
        {
            var valores = "";
            valores = document.getElementById('drop_idioma_'+ i ).value + ";";

            for(var x = 0; x < qtd_habilidade; x++)
            {   
                valores += document.getElementById('drop_nivel_'+ i +"_"+ x).value + ";";
            }
            valores_idioma[i] = valores;
        }
    }
    
    if(!EmptyField(document.getElementById('outro_idioma')))
    {
        var valores = "";
        valores = document.getElementById('outro_idioma' ).value + ";";

        for(var x = 0; x < qtd_habilidade; x++)
        {   
            valores += document.getElementById('drop_nivel_outro_'+ x).value + ";";
        }
        valores_idioma[parseInt(qtd_idioma) + 1] = valores;
    }
   
   
   /*************************************************************************************************/
   /* Codigo responsavel por montar um array dos valores de Nivel Educacional                       */
   var qtd_itens = qtd_itens_educacional;
   var valores_educacional = new Array();
    
   for(var i = 0; i <= qtd_itens; i++)
   {
        //Cria string que irá receber os valroes separados por ;
        var valores = "";
        
        //Verifica se este elemento existe, se sim entao valida
        if(document.getElementById('edu_nome_curso_'+ i) != null)
        {
            valores  = document.getElementById('edu_nome_curso_'+ i).value + ";";
            valores += document.getElementById('edu_nivel_academico_'+ i).value + ";";
            valores += document.getElementById('edu_data_inicio_'+ i).value + ";";
            valores += document.getElementById('edu_data_final_'+ i).value;
        }
        
        valores_educacional[i] = valores;
   }//Fim do For
   
   
   /*************************************************************************************************/
   /* Codigo responsavel por montar um array dos valores de Experiencia Profissional                */
   var qtd_itens2 = qtd_itens_profissional;
   var valores_experiencia = new Array();
   var valores_experiencia_ramo = new Array();
   
   var outras_extra_curricular = document.getElementById('outras_extra_curricular').value;    
   
   for(var i = 0; i <= qtd_itens2; i++)
   {
        var valores = "";
        var valoresRamo = "";
        //Verifica se este elemento existe, se sim entao valida
        if(document.getElementById('exp_nome_empresa_'+ i) != null)
        {
            valores  = document.getElementById('exp_nome_empresa_'+ i).value + ";";
            valores += document.getElementById('exp_cargo_ocupado_'+ i).value + ";";
            valores += document.getElementById('exp_descricao_atividades_'+ i).value + ";";
 
            valoresRamo += document.getElementById('valoresRamoAtividade_'+ i).value + ";";

            valores += document.getElementById('exp_data_admissao_'+ i).value + ";";
            valores += document.getElementById('exp_data_desligamento_'+ i).value;
        }
        valores_experiencia[i] = valores;
        valores_experiencia_ramo[i] = valoresRamo;
  
   }//Fim do For
                  
     //alert(valores_experiencia_ramo);
     
    //Executa a função no servidor para gravar as informações apenas da tabela curriculo
    sucesso_curriculo = curriculo.InserirCurriculo(vaga_pk_,_nome,_dtNascimento,_email,_telResidencial,_telCelular,_endereco,_numero,_bairro,_complemento,_cep,_observacao_contato,_area_atuacao,_upload_imagem,_necessidade_especial,_remuneracao_pretendida,_estado_civil,_cidade,_sexo,_horario, valores_especializacao, valores_idioma, valores_educacional, valores_experiencia, valores_experiencia_ramo,outras_extra_curricular).value;
    
    //Inserindo Pessoa Física.
    if(sucesso_curriculo)
    {
        document.getElementById('sucesso_cadastro_curriculo').style.display = '';
        document.getElementById('erro_cadastro_curriculo').style.display = 'none';
        
        document.getElementById('form_curriculo').style.display = 'none';
        document.getElementById('form_educacional').style.display = 'none';   
        document.getElementById('form_contato').style.display = 'none';
        document.getElementById('form_profissional').style.display = 'none';
        document.getElementById('form_experiencia_profissional').style.display = 'none';
        document.getElementById('form_curriculo_completo').style.display = 'none';
        document.getElementById('form_extra_curriculares').style.display = 'none';
    }
    else
    {
        document.getElementById('sucesso_cadastro_curriculo').style.display = 'none';
        document.getElementById('erro_cadastro_curriculo').style.display = '';
        
        document.getElementById('form_curriculo').style.display = 'none';
        document.getElementById('form_educacional').style.display = 'none';   
        document.getElementById('form_contato').style.display = 'none';
        document.getElementById('form_profissional').style.display = 'none';
        document.getElementById('form_experiencia_profissional').style.display = 'none';
        document.getElementById('form_curriculo_completo').style.display = 'none';
        document.getElementById('form_extra_curriculares').style.display = 'none';
        
    }
    
    window.scrollTo(0,0);
}


function valida_informacao_educacional()
{
    var qtd_itens = qtd_itens_educacional;
    
    var sucesso_edu = true;
    
    for(var i = 0; i <= qtd_itens; i++)
    {
        //Verifica se este elemento existe, se sim entao valida
        if(document.getElementById('edu_nome_curso_'+ i) != null)
        {
            //Primeiro limpa todos os estilos
            document.getElementById('edu_nome_curso_'+ i).className = 'txtfield';
            document.getElementById('erroedu_nome_curso_'+ i).style.display = 'none';
            
            document.getElementById('edu_nivel_academico_'+ i).className = 'txtfield';
            document.getElementById('erroedu_nivel_academico_'+ i).style.display = 'none';
            
            document.getElementById('edu_data_inicio_'+ i).className = 'txtfield';
            document.getElementById('erroedu_data_inicio_'+ i).style.display = 'none';
            
            document.getElementById('edu_data_final_'+ i).className = 'txtfield';
            document.getElementById('erroedu_data_final_'+ i).style.display = 'none';
                
        
            //Verifica se campo estao preenchidos, se não estiverem então retorna false e nem verifica o resto
            if(EmptyField(document.getElementById('edu_nome_curso_'+ i)))
            {
                document.getElementById('edu_nome_curso_'+ i).className = 'error';
                document.getElementById('erroedu_nome_curso_'+ i).style.display = '';
                document.getElementById('erroedu_nome_curso_'+ i).innerHTML = 'Por favor, informe o nome do curso.';  
                sucesso_edu = false;
            }
            
            if(document.getElementById('edu_nivel_academico_'+ i).value == '0')
            {
                document.getElementById('edu_nivel_academico_'+ i).className = 'error';
                document.getElementById('erroedu_nivel_academico_'+ i).style.display = '';
                document.getElementById('erroedu_nivel_academico_'+ i).innerHTML = 'Por favor, informe o nível acadêmico.';  
                sucesso_edu = false;
            }
            
            if(EmptyField(document.getElementById('edu_data_inicio_'+ i)))
            {
                document.getElementById('edu_data_inicio_'+ i).className = 'error';
                document.getElementById('erroedu_data_inicio_'+ i).style.display = '';
                document.getElementById('erroedu_data_inicio_'+ i).innerHTML = 'Por favor, informe a data inicial.';  
                sucesso_edu = false;
            }
            else
            {
                if(!valida_data(document.getElementById('edu_data_inicio_'+ i)))
                {
                    document.getElementById('edu_data_inicio_'+ i).className = 'error';
                    document.getElementById('erroedu_data_inicio_'+ i).style.display = '';
                    document.getElementById('erroedu_data_inicio_'+ i).innerHTML = 'Data em formato inválido.';  
                    sucesso_edu = false;
                }
            }
            
            if(EmptyField(document.getElementById('edu_data_final_'+ i)))
            {
                document.getElementById('edu_data_final_'+ i).className = 'error';
                document.getElementById('erroedu_data_final_'+ i).style.display = '';
                document.getElementById('erroedu_data_final_'+ i).innerHTML = 'Por favor, informe a data final.';  
                sucesso_edu = false;
            }
            else
            {
                if(!valida_data(document.getElementById('edu_data_final_'+ i)))
                {
                    document.getElementById('edu_data_final_'+ i).className = 'error';
                    document.getElementById('erroedu_data_final_'+ i).style.display = '';
                    document.getElementById('erroedu_data_final_'+ i).innerHTML = 'Data em formato inválido.';  
                    sucesso_edu = false;
                }
            }
        }
    }//Fim do For
    
    return sucesso_edu;
}

function valida_informacao_experiencia_profissional()
{
    var qtd_itens = qtd_itens_profissional;
    
    var sucesso_pro = true;
    
    for(var i = 0; i <= qtd_itens; i++)
    {
        
        //Verifica se este elemento existe, se sim entao valida
        if(document.getElementById('exp_nome_empresa_'+ i) != null)
        {
            //Primeiro limpa todos os estilos
            document.getElementById('exp_nome_empresa_'+ i).className = 'txtfield';
            document.getElementById('erroexp_nome_empresa_'+ i).style.display = 'none';
            
            document.getElementById('exp_cargo_ocupado_'+ i).className = 'txtfield';
            document.getElementById('erroexp_cargo_ocupado_'+ i).style.display = 'none';
            
            document.getElementById('exp_descricao_atividades_'+ i).className = 'txtfield';
            document.getElementById('erroexp_descricao_atividades_'+ i).style.display = 'none';
            
//            document.getElementById('exp_ramo_atividade_'+ i).className = 'txtfield';
//            document.getElementById('erroexp_ramo_atividade_'+ i).style.display = 'none';
            
            document.getElementById('exp_data_admissao_'+ i).className = 'txtfield';
            document.getElementById('erroexp_data_admissao_'+ i).style.display = 'none';
            
            document.getElementById('exp_data_desligamento_'+ i).className = 'txtfield';
            document.getElementById('erroexp_data_desligamento_'+ i).style.display = 'none';
                
        
            //Verifica se campo estao preenchidos, se não estiverem então retorna false e nem verifica o resto
            if(EmptyField(document.getElementById('exp_nome_empresa_'+ i)))
            {
                document.getElementById('exp_nome_empresa_'+ i).className = 'error';
                document.getElementById('erroexp_nome_empresa_'+ i).style.display = '';
                document.getElementById('erroexp_nome_empresa_'+ i).innerHTML = 'Por favor, informe o nome da empresa.';  
                sucesso_pro = false;
            }
            
            if(EmptyField(document.getElementById('exp_cargo_ocupado_'+ i)))
            {
                document.getElementById('exp_cargo_ocupado_'+ i).className = 'error';
                document.getElementById('erroexp_cargo_ocupado_'+ i).style.display = '';
                document.getElementById('erroexp_cargo_ocupado_'+ i).innerHTML = 'Por favor, informe o nome do cargo ocupado.';  
                sucesso_pro = false;
            }
            
            if(EmptyField(document.getElementById('exp_descricao_atividades_'+ i)))
            {
                document.getElementById('exp_descricao_atividades_'+ i).className = 'error';
                document.getElementById('erroexp_descricao_atividades_'+ i).style.display = '';
                document.getElementById('erroexp_descricao_atividades_'+ i).innerHTML = 'Por favor, descreva suas atividades.';  
                sucesso_pro = false;
            }            
            
            
//            if(document.getElementById('exp_ramo_atividade_'+ i).value == '0')
//            {
//                document.getElementById('exp_ramo_atividade_'+ i).className = 'error';
//                document.getElementById('erroexp_ramo_atividade_'+ i).style.display = '';
//                document.getElementById('erroexp_ramo_atividade_'+ i).innerHTML = 'Por favor, informe o ramo de atividade.';  
//                sucesso_pro = false;
//            }
            
            if(EmptyField(document.getElementById('exp_data_admissao_'+ i)))
            {
                document.getElementById('exp_data_admissao_'+ i).className = 'error';
                document.getElementById('erroexp_data_admissao_'+ i).style.display = '';
                document.getElementById('erroexp_data_admissao_'+ i).innerHTML = 'Por favor, informe a data de admissão.';  
                sucesso_pro = false;
            }
            else
            {
                if(!valida_data(document.getElementById('exp_data_admissao_'+ i)))
                {
                    document.getElementById('exp_data_admissao_'+ i).className = 'error';
                    document.getElementById('erroexp_data_admissao_'+ i).style.display = '';
                    document.getElementById('erroexp_data_admissao_'+ i).innerHTML = 'Data em formato inválido.';  
                    sucesso_pro = false;
                }
            }
            
//            if(EmptyField(document.getElementById('exp_data_desligamento_'+ i)))
//            {
//                document.getElementById('exp_data_desligamento_'+ i).className = 'error';
//                document.getElementById('erroexp_data_desligamento_'+ i).style.display = '';
//                document.getElementById('erroexp_data_desligamento_'+ i).innerHTML = 'Por favor, informe a data de desligamento.';  
//                sucesso_pro = false;
//            }
//            else
//            {
//                if(!valida_data(document.getElementById('exp_data_desligamento_'+ i)))
//                {
//                    document.getElementById('exp_data_desligamento_'+ i).className = 'error';
//                    document.getElementById('erroexp_data_desligamento_'+ i).style.display = '';
//                    document.getElementById('erroexp_data_desligamento_'+ i).innerHTML = 'Data em formato inválido.';  
//                    sucesso_pro = false;
//                }
//            }
        }
    }//Fim do For
    
    return sucesso_pro;
}


function valida_idioma()
{
    var qtd_idioma = document.getElementById('qtd_idioma').value;
    var qtd_habilidade = document.getElementById('qtd_habilidade').value;
    
    var sucesso_idi = true;
    
    for(var i = 0; i < qtd_idioma; i++)
    {
        for(var x = 0; x < qtd_habilidade; x++)
        {
            //Primeiro limpa todos os estilos
            document.getElementById('drop_nivel_'+ i +"_"+ x).className = 'txtfield';
            document.getElementById('drop_nivel_outro_'+ x).className = 'txtfield';
                                    
            if(document.getElementById('drop_idioma_'+ i ).value != '0')
            {
                if(document.getElementById('drop_nivel_'+ i +"_"+ x).value == '0')
                {
                    document.getElementById('drop_nivel_'+ i +"_"+ x).className = 'error';
                    sucesso_idi = false;
                }
            }     
                    
            if(!EmptyField(document.getElementById('outro_idioma')))
            {
                if(document.getElementById('drop_nivel_outro_'+ x).value == '0')
                {
                    document.getElementById('drop_nivel_outro_'+ x).className = 'error';
                    sucesso_idi = false;
                } 
            }            
        }
    }//Fim do For
    
    return sucesso_idi;
}


//Função assincrona do populaCidade.
function retorno_populaCidade(ret){
    var dt = ret.value;
    var cidade = document.getElementById('info_cidade');
    cidade.options.length = 0;
	cidade.options[cidade.options.length] = new Option("Selecione uma cidade","0");            
    for(var i = 0; i < dt.length; i++)
    {                
        cidade.options[cidade.options.length] = new Option(dt[i].Nome, dt[i].Codigo_Cidade);
    }
    document.getElementById('img_cidade').style.display = "none";
}

//Metodo responsável por popular as cidades de acordo com o estado selecionado.
function populaCidade(value)
{
    document.getElementById('img_cidade').style.display = "";
    curriculo.PopulaCidade(value,retorno_populaCidade);   
}

//Função para ao se dá um Enter cair sobre o evento de submit da pagina de contato
//param:evt = Evento do keyPress
//param:botao = Id do botão que dá o submit na página
function EnterCurriculo(evt,botao)
{
    //Verificando se o que é digitado é somente campos numéricos
    var charCode = (evt.which) ? evt.which : evt.keyCode;
  
    if(charCode==13)
    {
         document.getElementById(botao).onclick();		
         return false;
    }
    return true;
}

var resultadoCEP = null;

function makeRequestCEP(url,callback_function) {
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) {
		alert('Unfortunatelly you browser doesn\'t support this feature.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				eval('retornoXMLCep(http_request.responseXML, callback_function)');
			} else {
				alert('There was a problem with the request.(Code: ' + http_request.status + ')');
			}
		}
	}
	var Data = new Date();
	http_request.open('GET', url, true);
	http_request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	http_request.send(null);
}

function retornoXMLCep(xml, retorno){
	var result = new Object();
	var endereco="", bairro="", cidade="", estado="", cep = "";
	if (document.all){
		var nodes = xml.documentElement.childNodes;
		    endereco = result.endereco = nodes.item(0).text;
		    bairro   = result.bairro = nodes.item(1).text;
		    cidade   = result.cidade = nodes.item(2).text;
		    estado   = result.estado = nodes.item(3).text;
		    cep      = result.cep = nodes.item(4).text;
	}else{
		endereco = result.endereco = xml.getElementsByTagName("endereco")[0].childNodes[0].nodeValue;
		if(endereco != "")
		{
		    bairro   = result.bairro = xml.getElementsByTagName("bairro")[0].childNodes[0].nodeValue;
		    cidade   = result.cidade = xml.getElementsByTagName("cidade")[0].childNodes[0].nodeValue;
		    estado   = result.estado = xml.getElementsByTagName("estado")[0].childNodes[0].nodeValue;
		    cep      = result.cep = xml.getElementsByTagName("cep")[0].childNodes[0].nodeValue;
		}
	}
	
	if (estado== "" || cidade == "")
	{
	    DisabledElementos(false);
	    sucesso = false;
        document.getElementById('info_cep').className = 'error';
        document.getElementById('erroinfo_cep').style.display = '';
        document.getElementById('erroinfo_cep').innerHTML = 'Este CEP não foi encontrado no sistema dos Correios. Confira novamente os dados digitados. Caso esteja correto insira manualmente as informações sobre o seu endereço.';  
	}
	else
	{
	    //Limpando o campo caso seja necessário.
	    document.getElementById('info_cep').className = 'txtfield';
        document.getElementById('erroinfo_cep').style.display = 'none';
	
	    resultadoCEP = result;
	    eval(retorno +'(resultadoCEP)');
	 }
}

function buscaCEPCorreios(controle){
    if(valida_CEP(document.getElementById('info_cep')))
    {
        DisabledElementos(true);
    
        if (resultadoCEP==null || resultadoCEP.cep!=document.getElementById('info_cep').value){
		    makeRequestCEP('_CEP.aspx?cep='+controle.value.replace('.','').replace('-',''),'getCEPUsuario');
	    }else{
		    getCEPUsuario(resultadoCEP);
	    }
	}
}

function DisabledElementos(controle)
{
    document.getElementById('info_cep').disabled = controle;
    document.getElementById('info_endereco').disabled = controle;
    document.getElementById('info_estado').disabled = controle;
    document.getElementById('info_cidade').disabled = controle;
    document.getElementById('info_bairro').disabled = controle;
    if(!controle)
        document.getElementById('img_cep').style.display = 'none';
    else
        document.getElementById('img_cep').style.display = '';
}


function getCEPUsuario(resultadoCEP)
{
    DisabledElementos(false);
    
    document.getElementById('info_bairro').value = CharSet(resultadoCEP.bairro);
    document.getElementById('info_endereco').value = CharSet(resultadoCEP.endereco);
    
    var estadoAtual = curriculo.DevolveCodigoEstado(CharSet(resultadoCEP.estado)).value
    if(estadoAtual!= 0)
    {
    
        //Percorrendo os estado para se selecionar o estado correto.
        for(var i = 0; i < document.getElementById('info_estado').length; i++)
        {
            var x=document.getElementById("info_estado")
            if(x.options[i].value == estadoAtual)
            {
                document.getElementById('info_estado').selectedIndex = i;
                break;
            }
        }

        //Carregando as cidades...
        document.getElementById('img_cidade').style.display = "";
        var dt = curriculo.PopulaCidade(estadoAtual).value;   
        var cidade = document.getElementById('info_cidade');
        cidade.options.length = 0;
        cidade.options[cidade.options.length] = new Option("Selecione uma cidade","0");            
        for(var i = 0; i < dt.length; i++)
        {                
           cidade.options[cidade.options.length] = new Option(dt[i].Nome, dt[i].Codigo_Cidade);
        }
        document.getElementById('img_cidade').style.display = "none";
        //Fim carregando as cidades...


        //Percorrendo as cidades para se selecionar a cidade correta.
        for(var i = 0; i < document.getElementById('info_cidade').length; i++)
        {
            var x=document.getElementById("info_cidade")
            if(x.options[i].text == CharSet(resultadoCEP.cidade))
            {
                document.getElementById('info_cidade').selectedIndex = i;
                break;
            }
        }
    }
}

