function __eventShowDetails(data, params)
{
  var obj;
  obj = document.getElementById(params[0]+'_det');
  if (obj !== null) {
    main = document.getElementById(params[0]);
    main.removeChild(obj);
    main.style.backgroundColor = '';
  } else {
    obj = document.getElementById(params[0]);
    if (obj !== null) {
      var details = document.createElement('div');
      details.id = params[0]+'_det';
      details.innerHTML = data.responseText;
      obj.style.backgroundColor = CalculaCor(cor);
      obj.appendChild(details);
    }
  }
  reloadRodape();
}

function openEdital(id)
{
  $(document).location = '/editais/?c=index&id='+id;
}

function getDetails(eid, cor)
{
  if ($('eve_'+eid).opened) {
    var cc = $('event_det_'+eid).innerHTML;
    $('event_det_'+eid).innerHTML = ($('event_det_'+eid).closedContent)?$('event_det_'+eid).closedContent:'';
    $('event_det_'+eid).closedContent = cc;
    reloadRodape();
  } else {
    new Ajax.Updater('event_det_'+eid,'/go/get_search_details.php', {
      method: 'get',
      onComplete: function(request, json){
        $('event_indicator'+eid).hide();
        reloadRodape();
      },
      onCreate: function(request, json){
        $('event_indicator'+eid).show()
      },
      parameters: { id: eid, uri: escape(document.location), cor: cor }
    });
    $('eve_'+eid).opened = true;
    $('eve_'+eid).onclick = '';
  }
}
function getResultado(enq,COR)
{
	opcoes = document.getElementById('enqueteForm_'+enq).opcoes;
	marcado = false;
	for(i=0; i<opcoes.length; i++) {
		if (opcoes[i].checked) {
			marcado = true;
			resposta = opcoes[i].value
		}
	}
	if(marcado)
		new Ajax.Updater('enquete_'+enq,'/assets/inc/xtra_enquete.inc.php?a=add&enq='+enq+'&opcao='+resposta+'&COR='+COR, {asynchronous:true, evalScripts:false});
}
function sendInterativo(campo,source){
		new Ajax.Updater(campo,'/go/'+source, {asynchronous:true, evalScripts:false});
}

function getEnqueteResultado(enq)
{
	marcado = false;
	$$("input[type=radio]").each(
  	function(e){
	    if(e.checked == true){
	      resposta = e.value;
	      marcado = true;
	    }
    }
  );
  if(marcado)
  {
  	new Ajax.Updater('enquetef','/idosoempreendedor/mods/enquete.php?a=add&enq='+enq+'&opcao='+resposta, {asynchronous:true, method: 'get', evalScripts:false});
  }
}
function loadingAdd(div){
   width = $(div).getWidth() - 15;
   height = $(div).getHeight();
   block = '<div class="loading" style="position:absolute;width: '+width+'px;text-align:center;background-color: #FFF;padding:'+(Math.round( height / 2 )-8)+'px 0;opacity:0.7;filter:alpha(opacity=70)" onclick="return false;">';
   block += '<img src="/assets/img/icones/indicator.gif" /> Carregando';
   block += '</div>';
   new Insertion.Top($(div),block);
}
function loadingRemove(div) {
  $$('#'+div+' .loading').each(function(e){
    e.remove();
  })
}

function curriculoAdd(form) {
	//div = form.name;
	/*
	loadingAdd(div+'_list');
	loadingAdd(div+'_form');
  $(form).request({
    encoding: 'UNICODE',
    onComplete: function(r) {
    	loadingRemove(div+'_list');
    	loadingRemove(div+'_form');
      eval(r.responseText);
    }
  });
  form.reset();
  return false;
  */
	$("#" + form.id).ajaxSubmit({
	  dataType: 'xml'
	});
}

function curriculoEdit(div, id, error) {
  d = new Date();
  $.ajax({
	  type: 'get',
	  url: '/go/rh/'+ div +'/get_form.php?id='+ id +'&time='+ d.getTime(),
	  dataType: 'xml'
  });
}

function curriculoRemove(div, id) {
  //new Ajax.Updater(div+'_list','/go/rh/'+div+'/remove.php?id='+id, {asynchronous:true, method: 'get'});
  d = new Date();
  $.ajax({
	  type: 'get',
	  url: '/go/rh/'+ div +'/remove.php?id='+ id +'&time='+ d.getTime(),
	  dataType: 'xml'
  });
}

function inputHideShow(element,campo,value) {
  if ($(element).value == value || $(element).value == '') {
    $(campo).hide();
  } else {
    $(campo).show();
  }
}
function curriculoVagaStatus(id,COR,is_list) {
  new Ajax.Updater('vaga_'.concat(id,'_status'),'/go/rh/rechumanos/inscrever.php', {
    parameters: {
      id: id,
      COR: COR
    },
    asynchronous:true,
    method: 'get',
    evalScripts: true
  });
}

function loginAndSetHist(url) {
  $('formMeuSesc').userhist.value = url;
  EscondeMostraBloco('formMeuSesc');
  $('formMeuSesc').focusFirstElement();
}

function checkNews(quant){
  var count = 0;
  $$('[id=tmpId2]').each(function(e){
    if (e.checked){
      count++;
    }
  });
  if (quant <= count) {
    return confirm("ATENÇÃO:\n * Você receberá informações de cada unidade selecionada acima.\n * Isso poderá acarretar um volume de e-mails indesejado.\n * Deseja Continuar assim mesmo?");
  }
  return true;
}

function changeNecEsp(el,alvo)
{
	if (el.value != 1) {
		$(alvo).value = '';
		$(alvo).disable();
	} else {
		$(alvo).enable();
	}
}

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function signUpScripts()
{
	$("input.mask_cpf").mask("999.999.999-99");
	$("input.mask_cnpj").mask("99.999.999/9999-99");
	$("input#nascimento").mask("99/99/9999");
	
	$("#estado_id").change(function () {
	  $.get("/go/get_cidades.php", { eid: $(this).val(), field: "cidade_id" });
	});
	
	$("#area_id").change(function () {
	  $.get("/go/get_ramos.php", { aid: $(this).val(), field: "ramo_id" });
	});
	
	$("#addRamo").click(function (e) {
	  e.preventDefault();
	  var el = $('<div class="type-button"><span class="remove ui-icon ui-icon-circle-close ico_float_left"></span>'
	    +  $($("#ramo_id").find("option:selected").get(0)).text()
	    + '<input type="hidden" name="ramo[]" value="' + $(this).val() + '"></div>');
	    el.find(".remove").click(function () { $(this).parent().remove(); });
	    $("#ramosList").append(el);
	});
}

function submitCurriculo()
{
	error = '';
	if(Trim($('cli_nome').value).length == 0) {
		error += "\n * Campo nome é obrigatório";
	}
	/*if($('naturalidade_id').value == 0 || $('naturalidade_id').value == "") {
		error += "\n * Campo Naturalidade é obrigatório";
	}*/
	if(Trim($('nome_pai').value).length == 0) {
		error += "\n * Campo nome do pai é obrigatório";
	}
	if(Trim($('nome_mae').value).length == 0) {
		error += "\n * Campo nome da mãe é obrigatório";
	}
	if(Trim($('cli_doc_no').value).length == 0) {
		error += "\n * Campo CPF é obrigatório";
	}
	if(Trim($('rg').value).length == 0) {
		error += "\n * Campo RG é obrigatório";
	}
  if(Trim($('cli_cidade_id').value).length == 0) {
    error += "\n * Campo cidade é obrigatório";
  }
  if(Trim($('cli_endereco').value).length == 0) {
    error += "\n * Campo endereço é obrigatório";
  }
  if(Trim($('cli_bairro').value).length == 0) {
    error += "\n * Campo bairro é obrigatório";
  }
  if(Trim($('cli_email').value).length == 0) {
    error += "\n * Campo e-mail é obrigatório";    
  }
  if(Trim($('fone_contato').value).length == 0) {
  	error += "\n * Campo telefone para contato é obrigatório";
  }
  if(Trim($('interesse_area').value).length == 0) {
    error += "\n * Campo érea de interesse profissional é obrigatório";
  }
  if(Trim($('interesse_cidade_id').value).length == 0) {
    error += "\n * Campo cidade de interesse profissional é obrigatório";
  }
  if(Trim($('informatica').value).length == 0) {
    error += "\n * Campo conhecimentos em informática é obrigatório";
  }
  if(Trim($('meio_contato').value).length == 0) {
    error += "\n * Campo meio que proporcionou contato com o SESC é obrigatório";
  }
  if(Trim(error).length > 0) {
	   alert("Os dados que você forneceu parecem estar incorretos.\nPor favor, corrija os seguintes problemas e tente novamente:\n"+error);
  } else {
  	$('do_public_clientes').submit();
  }
}
