var handlerFunc = function(t) {
	if($('ajax_carregando')) {
		Element.remove($('ajax_carregando'));
	}
	eval(t.responseText);
}

var errFunc = function(t) {
	if($('ajax_carregando')) {
		Element.remove($('ajax_carregando'));
	}
	alert('Erro: '+t.status+' - '+t.statusText);
}

function executaAjax(url, parametros) {
	new Ajax.Request(url, {parameters:parametros, onSuccess:handlerFunc, onFailure:errFunc});
}

function contato() {
	var onde = '';
	if(arguments.length) {
		onde = arguments[0];
	}
	if(!$(onde+'nome').value) {
		alert('Informe um nome.');
		$(onde+'nome').focus();
	}
	else if(!$(onde+'email').value) {
		alert('Informe um e-mail.');
		$(onde+'email').focus();
	}
	else if(!$(onde+'mensagem').value) {
		alert('Informe a mensagem.');
		$(onde+'mensagem').focus();
	}
	else {
		$(onde+'formulario').submit();
	}
}

function fale_conosco() {
	if(!$('nome').value) {
		alert('Informe um nome.');
		$('nome').focus();
	}
	else if(!$('email').value) {
		alert('Informe um e-mail.');
		$('email').focus();
	}
	else if(!$('mensagem').value) {
		alert('Informe a mensagem.');
		$('mensagem').focus();
	}
	else {
		$('formulario').submit();
	}
}

function trabalhe_conosco() {
	if(!$('nome').value) {
		alert('Informe seu nome.');
		$('nome').focus();
	}
	else if(!$('email').value) {
		alert('Informe seu e-mail.');
		$('email').focus();
	}
	else if(!$('sexo1').checked && !$('sexo2').checked) {
		alert('Informe seu sexo.');
		$('sexo1').focus();
	}
	else if(!$('endereco').value) {
		alert('Informe seu endereço.');
		$('endereco').focus();
	}
	else if(!$('bairro').value) {
		alert('Informe seu bairro.');
		$('bairro').focus();
	}
	else if(!$('cidade').value) {
		alert('Informe sua cidade.');
		$('cidade').focus();
	}
	else if(!$('estado').options[$('estado').selectedIndex].value) {
		alert('Selecione seu estado.');
		$('estado').focus();
	}
	else if(!$('area_atuacao').value) {
		alert('Informe sua área de atuação.');
		$('area_atuacao').focus();
	}
	else if(!$('area_especializacao').value) {
		alert('Informe sua área de aespecialização.');
		$('area_especializacao').focus();
	}
	else if(!$('horario1').checked && !$('horario2').checked && !$('horario3').checked) {
		alert('Informe sua disponibilidade de horário.');
		$('horario1').focus();
	}
	else if(!$('viagens1').checked && !$('viagens2').checked && !$('viagens3').checked) {
		alert('Informe sua disponibilidade para viagens.');
		$('viagens1').focus();
	}
	else if(!$('curriculo').value) {
		alert('Informe seu currículo.');
		$('curriculo').focus();
	}
	else if(!$('salario_pretendido').value) {
		alert('Informe o salário pretendido.');
		$('salario_pretendido').focus();
	}
	else if(!$('vaga_pretendida').value) {
		alert('Informe a vaga pretendida.');
		$('vaga_pretendida').focus();
	}
	else {
		$('formulario').submit();
	}
}

function atendimento_online(tipo) {
	switch(tipo) {
		case 'fechar':
			$('atendimento_online_janela').hide();
			$('atendimento_online_botao').show();
		break;
		//
		case 'abrir':
			$('atendimento_online_janela').show();
			$('atendimento_online_botao').hide();
		break;
	}
}

function produtoInfo(produto) {
	var fundo = document.createElement('div');
	fundo.setAttribute('id', '_pif');
	document.body.appendChild(fundo);
	Element.setStyle(fundo, {position: 'fixed', top: '0px', left: '0px', width: '100%', height: '100%', backgroundColor: 'black', opacity: '0.75', zIndex: 10});
	fundo.setAttribute('class', 'conteudo_aba_produto_fundo');
	Event.observe(fundo, 'click', function() { Element.remove('_pif'); Element.remove('_pii') });

	var info = document.createElement('div');
	info.setAttribute('id', '_pii');
	document.body.appendChild(info);
	Element.setStyle(info, {position: 'fixed', top: '0px', left: '0px', marginTop: '100px', width: '500px', minHeight: '300px', left: '50%', marginLeft: '-255px', padding: '5px', border: 'gray solid 1px', backgroundColor: 'white', zIndex: '11'});
	info.innerHTML = '<div style="margin-top: 120px; text-align: center; font-weight: bold"><img src="imagens/carregando.gif" /><br />Carregando...</div>';
	Event.observe(info, 'click', function() { Element.remove('_pif'); Element.remove('_pii') });

	executaAjax('ajax/produtoInfo.php', 'produto='+produto);
}

function findString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (window.find) {

  // CODE FOR BROWSERS THAT SUPPORT window.find

  strFound=self.find(str);
  if (!strFound) {
   strFound=self.find(str,0,1);
   while (self.find(str,0,1)) continue;
  }
 }
 else if (navigator.appName.indexOf("Microsoft")!=-1) {

  // EXPLORER-SPECIFIC CODE

  if (TRange!=null) {
   TRange.collapse(false);
   strFound=TRange.findText(str);
   if (strFound) TRange.select();
  }
  if (TRange==null || strFound==0) {
   TRange=self.document.body.createTextRange();
   strFound=TRange.findText(str);
   if (strFound) TRange.select();
  }
 }
 else if (navigator.appName=="Opera") {
  alert ("Opera browsers not supported, sorry...")
  return;
 }
 if (!strFound) alert ("String '"+str+"' not found!")
 return;
}
