// JavaScript Document

function mostra_flash(id, src, width, height) {
    document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\">");
    document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
    document.write("<param name=\"movie\" value=\"" + src + "\" />");
    document.write("<param name=\"quality\" value=\"high\" />");
    document.write("<param name=\"scale\" value=\"noborder\" />");
	document.write("<param name=\"wmode\" value=\"transparent\" />");
    document.write("<param name=\"devicefont\" value=\"true\" />");
	document.write("<param name=\"allowFullScreen\" value=\"true\" />");
    document.write("<param name=\"bgcolor\" value=\"#ffffff\" />");
    document.write("<embed src=\"" + src + "\" quality=\"high\" scale=\"noborder\" wmode=\"transparent\" devicefont=\"true\" bgcolor=\"#ffffff\" width=\"" + width + "\" height=\"" + height + "\" id=\"" + id + "\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
    document.write("</object>");
}
function valida(d){
         if (d.refino.value == 0){
                   alert("Selecione como quer filtrar sua busca!");
                   d.refino.focus();
                   return false;
          }
}
function on(menu){
    botao = document.getElementById(menu);
    botao.src="../img/menu_on/"+menu+".jpg";
}
function off(menu){
    botao = document.getElementById(menu);
    botao.src="../img/btn_"+menu+".gif";
}
function on2(menu){
    botao = document.getElementById(menu);
    botao.src="../img/"+menu+"_on.jpg";
}
function off2(menu){
    botao = document.getElementById(menu);
   botao.src="../img/"+menu+".jpg";
}

function onOK(menu){
    botao = document.getElementById(menu);
    botao.src="../img/"+menu+"_on.gif";
}
function offOK(menu){
    botao = document.getElementById(menu);
   botao.src="../img/"+menu+".gif";
}
function mudaBg(){
	var titulo = document.getElementById('titulo_clientes');
	var meu_select = document.getElementById('cb_clientes');
	var selecao = meu_select.options[meu_select.selectedIndex].value;

	if(selecao == 1){
		titulo.style.backgroundImage = "url('../img/tit_atuais.jpg')";
	}else{
		titulo.style.backgroundImage = "url('../img/tit_ja_atendidos.jpg')";	
	}
}
function abreLink(combo_selecionado){
	var meu_select = document.getElementById(combo_selecionado);
	var selecao = meu_select.options[meu_select.selectedIndex].value;
	window.open(selecao);
}
function mes(){
	var rm = document.getElementById('resposta_mes');
	var meu_select = document.getElementById('cb_arquivo');
	var selecao = meu_select.options[meu_select.selectedIndex].value;
	if(selecao != 'Meses'){
		rm.innerHTML = selecao;
	}
}
function alteraValor(div){	
	var atual = document.getElementById(div);
	var muda = document.getElementById('destaque_site_img_g');
	
	if(atual.id == "destaque_site_img_p1"){
		muda.style.backgroundImage = "url('../img/foto_g1.gif')";
	}else if(atual.id == "destaque_site_img_p2"){
		muda.style.backgroundImage = "url('../img/foto_g2.gif')";
	}else if(atual.id == "destaque_site_img_p3"){
		muda.style.backgroundImage = "url('../img/foto_g3.gif')";
	}
}

function trocaImgOn(id,on){
   document.getElementById(id).src = on;
}
function trocaImgOff(id,off){
   document.getElementById(id).src = off;
}

// AJAX

var conteudo;
function createXMLHTTP()
	{
	var ajax;
		try
		{
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			   try
			   {
				   ajax = new ActiveXObject("Msxml2.XMLHTTP");
				   alert(ajax);
			   }
			   catch(ex)
				   {
					   try
						   {
								ajax = new XMLHttpRequest();
						   }
						   catch(exc)
						   {
								alert("Esse browser não tem recursos para uso do Ajax");
								ajax = null;
						   }
				   }
			return ajax;
		}
   	   var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
	   for (var i=0; i < arrSignatures.length; i++) {
					  try {
						 var oRequest = new ActiveXObject(arrSignatures[i]);
						 return oRequest;
					  } catch (oError) {
			  }
		  }
  
		  throw new Error("MSXML não está instalado em seu sistema.");
	}

function filtroConteudo(url,div){
	conteudo = document.getElementById(div);
	var http_request = createXMLHTTP(); 
	http_request.onreadystatechange = function() {alertContents(http_request);};
	http_request.open('GET', url, true);
	http_request.send(null);
}
function alertContents(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var texto = http_request.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto);
			conteudo.innerHTML = texto;
		}
	}
}
 
function filtroParent(div, id, tipo){
	conteudo2 = parent.document.getElementById(div);
	var http_request = createXMLHTTP(); 
	http_request.onreadystatechange = function() {alertContents2(http_request);};
	http_request.open('GET', 'clientes_c.php?seg='+id+'&tipo='+tipo, true);
	http_request.send(null);
}
function alertContents2(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var texto2 = http_request.responseText;
			texto2 = texto2.replace(/\+/g," ");
			texto2 = unescape(texto2);
			conteudo2.innerHTML = texto2;
		}
	}
}

function ajax(url,div){
	conteudo3 = document.getElementById(div);
	var http_request = createXMLHTTP(); 
	http_request.onreadystatechange = function() {alertContents3(http_request);};
	http_request.open('GET', url, true);
	http_request.send(null);
}
function alertContents3(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var texto3 = http_request.responseText;
			texto3 = texto3.replace(/\+/g," ");
			texto3 = unescape(texto3);
			conteudo3.innerHTML = texto3;
		}
	}
}
var chamadaIdAnterior;
var sobre = false;
$(document).ready(function() {
	//Twee					   	
	$("#twee").tweet({
		join_text: "auto",
		avatar_size: 40,
		count: 4 ,
		auto_join_text_default: "",
		auto_join_text_ed: "",
		auto_join_text_ing: "",
		auto_join_text_reply: "",
		auto_join_text_url: "",
		loading_text: "carregando..."
	});
	//Inicio - Funções Destaque Ajax
	$("#ImgDestaqueLoad").css("visibility","hidden");
	$("#destaque_site_img_p1,#destaque_site_img_p2,#destaque_site_img_p3").click(function () { 
		  $("#ImgDestaqueLoad").css("visibility","visible");		  
		  if (chamadaIdAnterior!=this.id.charAt(19)){
			  sobre=true;
			  chamaChamada(this.id.charAt(19));	 
			  chamadaIdAnterior = this.id.charAt(19);
		  }
    });
	function chamaChamada(idChamada){
	 $.post("carrega_destaque.php?",{id: idChamada},function(returnedAjax){
		$("#foto_interna").fadeOut(300,function(){$("#ImgDestaqueLoad").css("visibility","hidden");document.getElementById("foto_interna").innerHTML=returnedAjax});
       	if(sobre==true){
			$("#foto_interna").fadeIn(300,function(){sobre=false});	
			 $("#destaque_site_img_p"+idChamada).css({'background-color' : '#5ad1db'});
			 if(idChamada){
				$("#destaque_site_img_p"+idChamada).css({'background-color' : '#696969'});
			 }	
		}
     });
	}
	//Fim - Funções Destaque Ajax 

	$("img[name='btn_entra']").click(function () {  
		setorSelecionado = $("select[name='tipo_login2'] option:selected").text();
		if(setorSelecionado!="Selecione aqui sua área desejada"){
			window.location='banco_talentos.php?area='+setorSelecionado;
		}
	});	
	$("#resutMail").hide();//Esconde o alerta inicialmente.					   
	//Botão de cadastrar
	$("#ok_preto").click(function () {
		var str_nome = $("#nome").attr("value");//Pega o valor do campo nome
		var str_email = $("#email").attr("value");//Pega o valor do campo email							
		//Verifica o nome e o e-mail antes de enviar
		if(str_nome.length==0 || str_nome=='nome'){
			AbreAlerta("Preencha o seu nome");
		}else{
			if(str_email.length==0 || str_email=='email'){
				AbreAlerta("Preencha o seu e-mail");
			}else{
				if (!checkMail(str_email)) {
					AbreAlerta("E-mail inválido!");
				} else {
					//Se o nome e o e-mail estiverem corretos, envie
					$.post("controla_newsletter.php", {nomeMail: str_nome,emailMail: str_email,mod:1}, function(returned_data){
						AbreAlerta(returned_data);
					});
				}
			}
		}
	});
	//Botão de remove, que faz a mesma validação do que envia
	$("#x_preto").click(function () {
		var str_nome = $("#nome").attr("value");
		var str_email = $("#email").attr("value");							
		if(str_nome.length==0 || str_nome=='nome'){
			AbreAlerta("Preencha o seu nome");
		}else{
			if(str_email.length==0 || str_email=='email'){
				AbreAlerta("Preencha o seu e-mail!");
			}else{
				if (!checkMail(str_email)) {
					AbreAlerta("E-mail inválido!");
				} else {
					$.post("controla_newsletter.php", {nomeMail: str_nome,emailMail: str_email,mod:2}, function(returned_data){
						AbreAlerta(returned_data);
					});
				}
			}
		}
	});
});
function AbreAlerta(texto){
//alert(navigator.appVersion.substring(17,25));
	//IF para IE 6 e inferiores
	if (navigator.appName=="Microsoft Internet Explorer"){
		if (navigator.appVersion.substring(17,25)=="MSIE 6.0")	{
				alert(texto);
		}else{
			$("#resutMail").html(texto);
			$("#resutMail").slideDown("normal");
			window.setTimeout(fechaAlerta, 2000);
		}
	}else if (navigator.appName=="Netscape"){
			$("#resutMail").html(texto);
			$("#resutMail").slideDown("normal");
			window.setTimeout(fechaAlerta, 2000);
	}
}
//Função esconde alerta
function fechaAlerta() {
	$("#resutMail").slideUp("normal");
}

function vercpf (cpf) 
{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
alert('O CPF INFORMADO É VÁLIDO.');return true;
}

function valida_form(d){
         if (d.nome.value == ''){
                   d.nome.value = 'Preencha o campo nome';
                   d.nome.focus();
                   return false;
          }	
		  if (d.rg.value == ''){
			    d.rg.value = 'Preencha o campo RG';
                d.rg.focus();
                return false;
		  }
		  if (d.cpf.value == ''){
			    d.cpf.value = 'Preencha o campo CPF';
                d.cpf.focus();
                return false;
		  }
		  if (d.telefone.value == ''){
			    d.telefone.value = 'Preencha o campo telefone';
                d.telefone.focus();
                return false;
		  }
		  if (d.email.value == ""){
                   d.email.value = "O campo " + d.email.name + " deve ser preenchido!";
                   d.email.focus();
                   return false;
         }
         //validar email(verificao de endereco eletrônico)
         parte1 = d.email.value.indexOf("@");
         parte2 = d.email.value.indexOf(".");
         parte3 = d.email.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                   d.email.value = "O campo " + d.email.name + " deve ser conter um endereco eletronico!";
                   d.email.focus();
                   return false;
         }

		  if (d.cpf.value == ''){
			    d.cpf.value = 'Preencha o campo cpf';
                d.cpf.focus();
                return false;
		  }
}