<!--
// JavaScript Document
//
// SUPER MEGA HIPER SIMPLES ATIVADOR DE CONTEUDO FLASH
// desenvolvimento: Felipe Peternella
// versão: 1.00 / 19.06.2006
// contato: felipevex@gmail.com
// salvador bahia brasil
function ativaActive(fcValor) {
	var conteudo = document.getElementById(fcValor).innerHTML;
	document.getElementById(fcValor).innerHTML = conteudo;
}

//OBJETO AJAX
var http_request = false;

function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } 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('Seu browser não suporta a tecnologia AJAX. Por favor, entre em contato com nosso suporte.');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
}

function alertContents()
{
	//document.getElementById('loading').style.display="block";
	document.getElementById('newsmsg').innerHTML = "verificando, aguarde...";
      if (http_request.readyState == 4) {
         if (http_request.status == 200)
		 {
			//alert(http_request.responseText);
			//document.getElementById('cadnews').style.display="none";
            result = http_request.responseText;
           	document.getElementById('cadstatus').value = result;
			document.getElementById('newsmsg').innerHTML = "&nbsp;";
			checkCadNewsletter();
		 }
		 else
		 {
            alert('Erro ao acessar banco de dados. Por favor, tente novamente.');
         }
     }
}

//cria objeto ajax
//sempre passar campo/valor como array
//nomedocampo = valor
function cadNewsletter()
{
	var nome = document.getElementById("newsNome");
	var email = document.getElementById("newsEmail");
	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	
	if(nome.value == "")
	{
		alert("Por favor, informe seu NOME.");
		nome.focus();
	}
	else if(email.value == "")
	{
		alert("Por favor, informe seu E-MAIL.");
		email.focus();
	}
	else if(((email.value.search(exclude) != -1)||(email.value.search(check)) == -1)||(email.value.search(checkend) == -1))
	{
		alert ("O campo E-MAIL deve ser um endereço eletrônico válido!");
		email.focus();
	}
	else
	{
		//variavel com o e-mail informado para verificar no php
		var checar = "email=" + email.value + "&nome=" + nome.value;
		makePOSTRequest('source/include/cadastronewsletter.inc.php', checar);
	}
}

function checkCadNewsletter()
{
		var nome = document.getElementById("newsNome");
		var email = document.getElementById("newsEmail");
		var getstatus = document.getElementById("cadstatus");
	
			if(getstatus.value == "inseriu")
			{
				alert("Cadastro efetuado com sucesso!\nEm breve você receberá nossa newsletter.");
				nome.value = "";
				email.value = "";
				getstatus.value = "";
			}
			else if(getstatus.value == "naoinseriu")
			{
				alert("Não foi possível realizar o cadastro.\nPor favor, tente novamente.");
				getstatus.value = "";
			}
			else if(getstatus.value == "jaexiste")
			{
				alert("O e-mail " + email.value + " já está cadastrado.\nPor favor informe outro.");
				getstatus.value = "";
			}	
}



function validaForm(){
		d = document.contato;
		
			if (d.nome.value == ""){
				alert("Por favor, digite seu NOME!");
				d.nome.focus();
				return false;
			}
			
         	if (d.email.value == ""){
            	alert("O campo E-MAIL deve ser preenchido!");
                d.email.focus();
                return false;
         	}
         
         	parte1 = d.email.value.indexOf("@");
         	parte2 = d.email.value.indexOf(".");
         	parte3 = d.email.value.length;
			
        		if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)){
                   alert ("O campo E-MAIL deve ser um endereço eletrônico válido!");
                   d.email.focus();
                   return false;
         		}
				
			if (d.assunto.value == ""){
				alert("Por favor, informe o ASSUNTO!");
				d.assunto.focus();
				return false;
			}
			
			if (d.mensagem.value == ""){
				alert("Por favor, digite a MENSAGEM!");
				d.mensagem.focus();
				return false;
			}
			
			if (d.departamento.value == ""){
				alert("Por favor, clique na foto dos funcionários abaixo para selecionar o DEPARTAMENTO!");
				d.departamento.focus();
				return false;
			}
		
		return true;
}

function openPost(cod){
	
	altura = 400;
	largura = 450;
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;
	
	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	
	//abre a nova janela, já com a sua devida posição
	window.open('post_blog.php?codigo='+cod,'comentario','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+',location=no,status=no,scrollbars=yes');
}

function validaPost(){
	d = document.inserecomentario;
		
	if (d.nome.value == ""){
		alert("Por favor, digite seu NOME!");
		d.nome.focus();
		return false;
	}
	
	if (d.comentario.value == ""){
		alert("Por favor, digite seu COMENTÁRIO!");
		d.comentario.focus();
		return false;
	}
	d.checkpost.value = "ok";
	d.submit();
	return true;
}

function valFiltro(){
	d = document.blog;
	var myindex = d.filtro.selectedIndex;
	var valor = d.filtro.options[myindex].value;
	window.location = "?filtro="+valor;
}


function selDepto(email){
	d = document.contato;
	d.departamento.value = email;
}

function retorna(){
	history.back();	
}


function getCategoria(n)
{
	var a = document.getElementById("categoria");
	var b = document.getElementById("consulta");
	
	if(n != ""){
		a.value = n;
		if(a.value != ""){
			b.submit();	
		}else{
			window.location = "?section=start";
		}
	}else{

		if(a.value == 0){
			alert("Por favor, selecione uma Categoria");
		}else{
			b.submit();
		}
	}
}


function viewProduto(valor)
{
	var a = document.getElementById("codigo");
	var b = document.getElementById("visualizar");
	a.value = valor;
		if(a.value != '')
		{
			b.submit();
		}
	
}

function leThumb(id)
{
	var getalvo = document.getElementById("ampliada");
	var getid = document.getElementById(id);
	getalvo.src = getid.value;
}
//-->
