//Aumentar e diminuir fonte
var hits = 5;
$fs = 14; //Aqui você específica qual o tamanho inicio da sua fonte
function fontSize(action, container){
container = typeof(container) != 'undefined' ? container : 'div.texto'; //se não for especificado um container será 'div.texto'
var hitIncrease = 0;
var hitDecrease = 0;

if (action == 'plus' && hits<9) {
	$fs += 1;
	hitIncrease = 1;
}
else if (action == 'minus' && hits>5){
	$fs -= 1;
	hitDecrease = 1;
}
jQuery(container).css('font-size', $fs);

if (hitIncrease == 1)hits+=1;
else if (hitDecrease == 1)hits-=1;
}
jQuery(function(){
jQuery('#decrease').click(function(){ fontSize('minus', '.wrapperfont') }).blur();
jQuery('#increase').click(function(){ fontSize('plus', '.wrapperfont') }).blur();
});
//Fim: Aumentar e diminuir fonte



$(document).ready(function(){
						
						
						

/************************
  VALIDA FORMULARIO
  *********************/
//Trigger função validaFormulario
    //Carreagando Engine para COntato/Trabalhe conosco
    //Carreagando Engine para COntato/Trabalhe conosco
    $('.formular').validationEngine({
      scroll:true,
      isError:true,
      scroll:true,
      showArrow:true,
      validationEventTriggers: 'blur'
    });   
    
  $('.enviarFormulario').click(function(e){
	  /*===================================
		@setor = formulario a ser postado
	  */										
      setor = $(this).attr('rel');
	  
      if($('.formular').validationEngine({returnIsValid:true})){
		
		switch(setor){ 
		 case 'trabalheconosco':
		  $.ajax({
			  url: 'emailTrabalheAqui.ashx',
			  type: 'post',
			  data:
			  {
				  nome: $('#nome').val(),
				  dtnascimento: $('#dtnascimento').val(),
				  sexo: $('#sexo').val(),
				  email: $('#email').val(),
				  celular: $('#celular').val(),
				  telefone: $('#telefone').val(),
				  cidade: $('#cidade').val(),
				  estado: $('#estado').val(),
				  cnh: $('#cnh').val(),
				  escolaridade: $('#escolaridade').val(),
				  descFormacao1: $('#descFormacao1').val(),
				  descFormacao2: $('#descFormacao2').val(),
				  empresa01: $('#empresa01').val(),
				  periodode: $('#periodode').val(),
				  periodoate: $('#periodoate').val(),
				  funcao01: $('#funcao01').val(),
				  descAtrib01: $('#descAtrib01').val(),
				  empresa02: $('#empresa02').val(),
				  periodo02de: $('#periodo02de').val(),
				  periodo02ate: $('#periodo02ate').val(),
				  funcao02: $('#funcao02').val(),
				  descAtrib02: $('#descAtrib02').val(),
				  empresa03: $('#empresa03').val(),
				  periodo03de: $('#periodo03de').val(),
				  periodo03ate: $('#periodo03ate').val(),
				  funcao03: $('#funcao03').val(),
				  descAtrib03: $('#descAtrib03').val(),
				  idiomas: $('#idiomas').val(),
				  conhecInformatica: $('#conhecInformatica').val(),
				  cursoExtraCurriculares: $('#cursoExtraCurriculares').val(),
				  pretensaoSalarial: $('#pretensaoSalarial').val(),
				  areaHabilidade: $('#areaHabilidade').val(),
				  essencial: $('#essencial').val()
			  },
			  beforeSend: function() {
				  makeOverlay(function(){
					$('#carregando').fadeIn('slow');
				  })
			  },
			  success: function() {
				  $('#emailSucesso').fadeIn().delay(4000).fadeOut();
			  },
			  error: function() {
				  $('#emailErro').fadeIn().delay(4000).fadeOut();
			  },
			  complete: function() {
				  removeOverlay();
				  $('#carregando').fadeOut().hide(function(){														   
                     $('.formular select, .formular input, .formular textarea').val('');	   
                  });
				  
			  },
			  timeout: 60000
		  });
		  break;
	  
		//
	   //Formulário contato
		case 'contato':
		$.ajax({
			  url: 'emailContato.php',
			  type: 'post',
			  data:
			  {
				  nome: $('#nome').val(),
				  email: $('#email').val(),
				  celular: $('#celular').val(),
				  telefone: $('#telefone').val(),
				  cidade: $('#cidade').val(),
				  estado: $('#estado').val(),
				  oquedeseja: $('#oquedeseja').val(),
				  setor: $('#setor').val(),
				  assunto: $('#assunto').val(),
				  mensagem: $('#mensagem').val()
			  },
			  beforeSend: function() {
				  makeOverlay(function(){
                    $('#carregando').fadeIn('slow')
				  })
			  },
			  success: function() {
				  $('#emailSucesso').fadeIn().delay(4000).fadeOut(function(){
                    removeOverlay();
				  });
			  },
			  error: function() {
				  $('#emailErro').fadeIn().delay(4000).fadeOut(function(){
                    removeOverlay();
				  });
			  },
			  complete: function() {
				    $('#carregando').fadeOut().hide(function(){
                      //Limpando dados
					  $('.formular input,.formular textarea').val('');
					  $('.formular select').val('MG');
					});
			  },
			  timeout: 60000
		  });
		  break;
	   //Formulário contato
		case 'inscricaoCurso':
		$.ajax({
			  url: 'emailInscricaoCurso.ashx',
			  type: 'post',
			  data:
			  {
				  nome: $('#txtNome').val(),
				  email: $('#txtEmail').val(),
				  nomedopai: $('#txtNomeDoPai').val(),
				  nomedamae: $('#txtNomeDaMae').val(),
				  profissao: $('#txtProfissao').val(),
				  estado: $('#txtEstado').val(),
				  sexo: $('#txtSexo').val(),
				  telefone: $('#txtTelefone').val(),
				  rg: $('#txtRG').val(),
				  cpf: $('#txtCPF').val(),
				  rua: $('#txtRua').val(),
				  bairro: $('#txtBairro').val(),
				  cidade: $('#txtCidade').val(),
				  cep: $('#txtCEP').val(),
				  curso: $('#txtCurso').val(),
				  turno: $('#txtTurno').val(),
				  nomeAvalista: $('#txtNomeAvalista').val(),
				  telAvalista: $('#txtTelefoneAvalista').val(),
				  sexoAvalista: $('#txtSexoAvalista').val(),
				  rgAvalista: $('#txtRGAvalista').val(),
				  cpfAvalista: $('#txtCPFAvalista').val(),
				  ruaAvalista: $('#txtRuaAvalista').val(),
				  bairroAvalista: $('#txtBairroAvalista').val(),
				  cidadeAvalista: $('#txtCidadeAvalista').val(),
				  estadoAvalista: $('#txtEstadoAvalista').val(),
				  CEPAvalista: $('#txtCEPAvalista').val()				  
			  },
			  beforeSend: function() {
				  makeOverlay(function(){
                    $('#carregando').fadeIn('slow')
				  })
			  },
			  success: function() {
				  $('#emailSucesso').fadeIn().delay(4000).fadeOut(function(){
                    removeOverlay();
				  });
			  },
			  error: function() {
				  $('#emailErro').fadeIn().delay(4000).fadeOut(function(){
                    removeOverlay();
				  });
			  },
			  complete: function() {
				    $('#carregando').fadeOut().hide(function(){
                      //Limpando dados
					  $('.formular input,.formular textarea, .formular select').val('');
					  $('#txtEstado,#txtEstadoAvalista').val('MG');
                    });
			  },
			  timeout: 60000
		  });
		  break;
		default:
		  return false;
		}//fim:switch
      }else{
       // alert('FALSO');
		return false;
      }
      e.preventDefault()
  });
/************************
  FIM:VALIDA FORMULARIO
  *********************/

//Função de poll para hashtag navigation. Se restar duvida, dê uma lida neste artigo -> http://ajaxpatterns.org/Unique_URLs
$(window).load(function() {
    var recentHash = "";
    function pollHash() {
        if (window.location.hash == recentHash || window.location.hash == '#') {
            return; // Nothing's changed since last polled.
        }
        recentHash = window.location.hash;

        // Se a URL Mudou, caminhar para o menu correto
        abrirPainel(recentHash);
    }
    //Executa o hash no load da página, e depois fica executando de 100 em 100 milisegundos para evitar overhead.
    //pollHash();
    //setInterval(pollHash, 100);
    //setInterval(setClique, 1000);
});


/*******************
    FORMATA INPUTS
	*******************/
$('.formataData').mask('99/99/9999');
$('.formataDataMesAno').mask('99/9999');
$('.formataTelefone').mask('(99) 9999-9999');
$(".formataCPF").mask("999.999.999-99");
$(".formataCEP").mask("99999-999");
})//Fim:WINDOW.LOAD





$.fn.clearForm = function() {
    this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input',this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.setAttribute('value', '');
        else if (type == 'checkbox' || type == 'radio')
            this.removeAttribute('checked');
        else if (type == 'select-one' || tag == 'select')
            $('option', this).each(function(){
                this.removeAttribute('selected');
            });
    });
};


// Início da Função FormataReais


/******
fld -> field
milSep -> separador de mil
deSep -> separador de centavos
e -> evento
  
**************/

function FormataReais(fld, milSep, decSep, 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) || (whichCode == 8) || (whichCode == 22)) return true;

key = String.fromCharCode (whichCode);// Valor para o código da Chave

if (strCheck.indexOf(key) == -1) return false; // Chave inválida

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != '0') && ( fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += milSep;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

fld.value = '';

len2 = aux2.length ;

for (i = len2 - 1; i >= 0; i--)

fld.value += aux2.charAt(i);

fld.value += decSep + aux.substr(len - 2, len);

}

return false;

}


