// fun��o para ampliar fotos

function foto(arquivo) {

	var janela = window.open("popup.htm?" + arquivo, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=50,height=50");

}



// funa��o para verificar o login dos usu�rios

function usuario_logar() {

	var args = "l=" + document.getElementById("login_login").value + "&s=" + document.getElementById("login_senha").value;

	carrega('usuario_logar', args);

}



function setLogado(value) {

	window.document.flashMenu.SetVariable("var_logado", value);

}



// fun��o para visualizar o texto descritivo de cada homologado

function homologados_texto(id) {

	var janela = window.open("ver_homologados_texto.php?id=" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=615,height=280");

}



// fun��o para visualizar as malhas relacionadas � cada homologado

function homologados_malhas(id) {

	var janela = window.open("ver_homologados_malhas.php?id=" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=615,height=280");

}



// fun��o para visualizar os artigos relacionadas � cada produto

function produtos_artigos(id,col) {

	var janela = window.open("ver_produtos_artigo.php?id=" + id + "&col=" + col, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=615,height=280");

}



// fun��o para visualizar a cartela de cores relacionada � cada produto

function produtos_cartela(id,col) {

	var janela = window.open("ver_produtos_cores.php?id=" + id + "&col=" + col, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=615,height=280");

}



// fun��o para visualizar a cartela de cores relacionada � cada produto

function acessorios_produto(id,col,tipo) {

	var janela = window.open("ver_acessorios_produto.php?id=" + id + "&col=" + col+ "&tp=" + tipo, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=640,height=310");

	janela.focus();

}



// fun��o para visualizar os representantes de cada UF

function ver_representante(uf) {

	var janela = window.open("ver_representante.php?id=" + uf, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=yes,width=340,height=350");

}



// fun��o para visualizar a cartela de cores relacionada � cada produto

function ver_artigos(id) {

	var janela = window.open("ver_artigos.php?id=" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=yes,width=400,height=300");

}



// fun��o para realizar a consulta dos homologados por malhas

function homologados_consulta(txt) {

	var args = "malha=" + document.getElementById("malha").value;

	if(txt) {

		carrega('produtos_homologados_consulta_texto', args);

	} else {

		carrega('produtos_homologados_consulta', args);

	}

}



// fun��o para alterar os dados de cadastro do usuario

function alterar_cadastro() {

	var continuar = true;

	var obrigatorios = Array(document.getElementById("razao"), document.getElementById("nome"), document.getElementById("nascimento"), document.getElementById("telefone_ddd"), document.getElementById("telefone_numero"), document.getElementById("email"), document.getElementById("cidade"));

	for(i = 0; i < obrigatorios.length; i++) {

		if(obrigatorios[i].value == "") {

			alert("* Campos de preenchimento obrigat�rio.");

			continuar = false;

			break;

		}

	}

	if(continuar) {

		var args = "razao=" + document.getElementById("razao").value + "&nome_fantasia=" + document.getElementById("nome_fantasia").value + "&nome=" + document.getElementById("nome").value + "&nascimento=" + document.getElementById("nascimento").value + "&telefone_ddd=" + document.getElementById("telefone_ddd").value + "&telefone_numero=" + document.getElementById("telefone_numero").value + "&ramal=" + document.getElementById("ramal").value + "&email=" + document.getElementById("email").value + "&cidade=" + document.getElementById("cidade").value + "&uf=" + document.getElementById("uf").value + "&rua=" + document.getElementById("rua").value + "&bairro=" + document.getElementById("bairro").value + "&cep=" + document.getElementById("cep").value;

		carrega("alterar_cadastro_enviar", args);

	}

}



// fun��o para cadastrar um cliente

function cadastrar_cliente() {

	var continuar = true;

	var obrigatorios = Array(document.getElementById("cli_razao"), document.getElementById("cli_codigo_cliente"), document.getElementById("cli_nome"), document.getElementById("cli_telefone_ddd"), document.getElementById("cli_telefone_numero"), document.getElementById("cli_ramal"), document.getElementById("cli_email"), document.getElementById("cli_login"));

	for(i = 0; i < obrigatorios.length; i++) {

		if(obrigatorios[i].value == "") {

			alert("Todos os campos s�o de preenchimento obrigat�rio.");

			continuar = false;

			break;

		}

	}

	if(continuar) {

		var args = "razao=" + document.getElementById("cli_razao").value + "&codigo_cliente=" + document.getElementById("cli_codigo_cliente").value + "&nome=" + document.getElementById("cli_nome").value + "&telefone_ddd=" + document.getElementById("cli_telefone_ddd").value + "&telefone_numero=" + document.getElementById("cli_telefone_numero").value + "&ramal=" + document.getElementById("cli_ramal").value + "&email=" + document.getElementById("cli_email").value + "&login=" + document.getElementById("cli_login").value;

		carrega("cadastrar_cliente_enviar", args);

	}

}



// fun��o para consultar os clientes

function consultar_cliente() {

	var args = "nome=" + document.getElementById("cli_nome").value + "&razao=" + document.getElementById("cli_razao").value + "&nome_fantasia=" + document.getElementById("cli_nome_fantasia").value + "&ult_acesso1=" + document.getElementById("cli_ult_acesso1").value + "&ult_acesso2=" + document.getElementById("cli_ult_acesso2").value + "&acessos1=" + document.getElementById("cli_acessos1").value + "&acessos2=" + document.getElementById("cli_acessos2").value + "&cidade=" + document.getElementById("cli_cidade").value;

	carrega("consulta_cliente_enviar", args);

}



// fun��o para cadastrar uma noticia

function cadastrar_noticia() {

	var continuar = true;

	var obrigatorios = Array(document.getElementById("not_assunto"), document.getElementById("not_chamada"), document.getElementById("not_texto"), document.getElementById("not_link"), document.getElementById("not_fonte"));

	for(i = 0; i < obrigatorios.length; i++) {

		if(obrigatorios[i].value == "") {

			alert("Todos os campos s�o de preenchimento obrigat�rio.");

			continuar = false;

			break;

		}

	}

	if(continuar) {

		var args = "assunto=" + document.getElementById("not_assunto").value + "&chamada=" + document.getElementById("not_chamada").value + "&texto=" + document.getElementById("not_texto").value + "&link=" + document.getElementById("not_link").value + "&fonte=" + document.getElementById("not_fonte").value;

		carrega("cadastrar_noticia_enviar", args);

	}

}



// fun��o para visualizar o mural

function alterar_foto(id) {

	var conteudo = document.getElementById("foto");

	conteudo.src = "images/galeriamural/" + id + "_g.jpg";

}



// fun��o para visualizar o mural

function abrir_mural(id) {

	var janela = window.open("ver_mural.php?id=" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=742,height=554");

}



// fun��o para cadastrar no mural

function cadastrar_mural() {

	var continuar = true;

	var obrigatorios = Array(document.getElementById("mur_chamada"), document.getElementById("mur_texto"));

	for(i = 0; i < obrigatorios.length; i++) {

		if(obrigatorios[i].value == "") {

			alert("Todos os campos s�o de preenchimento obrigat�rio.");

			continuar = false;

			break;

		}

	}

	if(continuar) {

		var args = "chamada=" + document.getElementById("mur_chamada").value + "&texto=" + document.getElementById("mur_texto").value;

		carrega("cadastrar_mural_enviar", args);

	}

}



// fun��o para alterar a senha do usuario

function alterar_senha() {

	if(document.getElementById("nova_senha1").value == document.getElementById("nova_senha2").value) {

		var args = "senha=" + document.getElementById("senha_atual").value + "&nova_senha=" + document.getElementById("nova_senha1").value;

		carrega("alterar_senha_enviar", args);

	} else {

		alert("Confirma��o da nova senha n�o confere.");

	}

}



// fun��o para reenviar o login do usuario

function esqueci_login() {

	var args = "email=" + document.getElementById("login_email").value;

	carrega('reenviar_login', args);

}



// fun��o para reenviar a senha do usuario

function esqueci_senha() {

	var args = "login=" + document.getElementById("senha_login").value + "&email=" + document.getElementById("senha_email").value;

	carrega('reenviar_senha', args);

}



// fun��o para enviar o formul�rio de contato

function contato_enviar(txt) {

	var args = "setor=" + document.getElementById("setor").value + "&voce=" + document.getElementById("voce").value + "&nome=" + document.getElementById("nome").value + "&email=" + document.getElementById("email").value + "&empresa=" + document.getElementById("empresa").value + "&profissao=" + document.getElementById("profissao").value + "&sexo=" + document.getElementById("sexo").value + "&endereco=" + document.getElementById("endereco").value + "&cep=" + document.getElementById("cep").value + "&cidade=" + document.getElementById("cidade").value + "&bairro=" + document.getElementById("bairro").value + "&uf=" + document.getElementById("uf").value + "&pais=" + document.getElementById("pais").value + "&telefone_ddd=" + document.getElementById("telefone_ddd").value + "&telefone=" + document.getElementById("telefone").value + "&nascimento_dia=" + document.getElementById("nascimento_dia").value + "&nascimento_mes=" + document.getElementById("nascimento_mes").value + "&nascimento_ano=" + document.getElementById("nascimento_ano").value + "&opiniao=" + document.getElementById("opiniao").value + "&mensagem=" + document.getElementById("mensagem").value + "&noticias=" + document.getElementById("noticias").value;

	carrega('contato_enviar', args);

}

function contatorepresentante(txt) {

	var args = 
	"nome=" + document.getElementById("nome").value + 
	"&email=" + document.getElementById("email").value + 
	"&empresa=" + document.getElementById("empresa").value + 
	"&cnpj=" + document.getElementById("cnpj").value + 
	"&endereco=" + document.getElementById("endereco").value + 
	"&cidade=" + document.getElementById("cidade").value + 
	"&bairro=" + document.getElementById("bairro").value + 
	"&uf=" + document.getElementById("uf").value + 
	"&telefone_ddd=" + document.getElementById("telefone_ddd").value + 
	"&telefone=" + document.getElementById("telefone").value + 
	"&mensagem=" + document.getElementById("mensagem").value;

	carrega('contatorepresentante_enviar', args);

}


// fun��o para visualizar as noticias

function ver_noticia(id) {

	carrega("noticias_visualizar", "id=" + id);

}



// fun��o para votar na enquete

function enquete_votar() {

	var opcao = 0;

	for(i = 0; i < document.forms[0].opt_enquete.length; i++) {

		if(document.forms[0].opt_enquete[i].checked) {

			opcao = document.forms[0].opt_enquete[i].value;

		}

	}

	if(opcao == 0) {

		alert("Voc� precisar escolher uma op��o para votar na enquete.");

	} else {

		carrega("enquete", "opcao=" + opcao);

	}

}



// fun��o para adicionar foto na noticia cadastrada

function adicionar_fotos(tipo) {

	var janela = window.open("adicionar_fotos.php?tipo="+tipo, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=400,height=120");

}



// fun��o para verificar se foi pressionado o ENTER para ativar a fun��o passada

function trySubmit(responseFunction,e) {

if(window.event)

	keyPressed = window.event.keyCode; // IE hack

else

	keyPressed = e.which; // standard method



	if(keyPressed == 13) {

		eval(responseFunction);

	} 

}



// fun��o para alterar o src da imagem

function swapPic(obj, image) {

	obj.src = image;

}



// fun��o para scroll da p�gina ao topo

function topo() {

	window.scrollTo(0, 0);

}



// fun��o para visualizar a �rea de ecologia

function ecologia() {

	var janela = window.open("sga.html", "_blank","resizable=yes,toolbar=yes,status=yes,menubar=yes,maximize=yes,scrollbars=yes");

}



function listaFicha(op) {

	objpro = document.getElementById("pro");

	objfrm = document.getElementById("listar");

	objfld = document.getElementById("opcao");

	objfrm.action = "../admin/view_coresprod_disp.php";

	

	if (objpro.value == "") {

		alert("Selecione um produto");

		objpro.focus();

	} else {

		objfld.value = op;

		objfrm.submit();

	}



}



function listaFichaPdf() {

	objpro = document.getElementById("pro");

	objfrm = document.getElementById("listar");

	objfld = document.getElementById("opcao");

	if (objpro.value == "") {

		alert("Selecione um produto");

		objpro.focus();

	} else {

		objfrm.action = "../admin/view_etiqueta_pdf.php";

		objfrm.submit();

	}



}



// fun��o para carregar o conte�do da p�gina

function carrega(valor, args) {

	//alert(valor);

	var conteudo = document.getElementById("content");

	conteudo.innerHTML = '<div style="background-color: #FFFFFF; padding: 75px; text-align: center;"><img src="images/site_loader.gif" /></div>';

	if(valor == "principal") {

		carregaLogin();

	} else {

		document.getElementById("area_login").innerHTML = "";

	}

	if(args == undefined) {

		http.open("GET", "functions.php?n=" + valor, true);

	} else {

		http.open("GET", "functions.php?n=" + valor + "&" + args, true);

	}

	// addStat(1350, valor);

	if((valor == "usuario_logar") || (valor == "usuario_sair")) {

		http.onreadystatechange = handleHttpResponseDoLogin;

	} else {

		http.onreadystatechange = handleHttpResponse;

	}

	http.send(null);

}



// fun��o chamada ap�s carregar o conte�do

function handleHttpResponse() {

	var conteudo = document.getElementById("content");

	if (http.readyState == 4) {

		texto = http.responseText;

		texto = texto.replace(/\+/g," ");

		texto = unescape(texto);

		conteudo.innerHTML = texto;

		topo();

	}

}



// fun��o chamada ap�s carregar o conte�do

function handleHttpResponseDoLogin() {

	var conteudo = document.getElementById("content");

	if (http.readyState == 4) {

		texto = http.responseText;

		texto = texto.replace(/\+/g," ");

		texto = unescape(texto);

		conteudo.innerHTML = texto;

		if(conteudo.childNodes[0].id == "logado_true") {

			setLogado("true");

		} else {

			setLogado("false");

		}

		topo();

	}

}



// fun��o para carregar a �rea de login

function carregaLogin() {

	var conteudo = document.getElementById("area_login");

	conteudo.innerHTML = "";

	httpLogin.open("GET", "_login_index.php", true);

	httpLogin.onreadystatechange = handleHttpResponseLogin;

	httpLogin.send(null);

}



// fun��o para carregar a �rea de login

function carregaAjax(ender,div,aguarde) {

	var conteudo = document.getElementById(div);

	divAux = div;

	conteudo.innerHTML = aguarde;

	httpGeral.open("GET", ender, true);

	httpGeral.onreadystatechange = handleHttpResponseGeral;

	httpGeral.send(null);

}



// fun��o chamada ap�s carregar a �rea de login

function handleHttpResponseGeral() {

	var conteudo = document.getElementById(divAux);



	if (httpGeral.readyState == 4) {

		texto = httpGeral.responseText;

		texto = texto.replace(/\+/g," ");

		texto = unescape(texto);

		conteudo.innerHTML = texto;

	}

}

// fun��o chamada ap�s carregar a �rea de login

function handleHttpResponseLogin() {

	var conteudo = document.getElementById("area_login");

	if (httpLogin.readyState == 4) {

		texto = httpLogin.responseText;

		texto = texto.replace(/\+/g," ");

		texto = unescape(texto);

		conteudo.innerHTML = texto;

	}

}



// fun��o complementar para o carregamento do conte�do

function getHTTPObject() {

	var xmlhttp;

	/*@cc_on

	@if (@_jscript_version >= 5)

		try {

			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

		try {

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (e) {

			xmlhttp = false;

		}

	}

	@else

	xmlhttp = false;

	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {

			xmlhttp = new XMLHttpRequest();

		} catch (e) {

			xmlhttp = false;

		}

	}

	return xmlhttp;

}



// cria o objeto para carregar o conte�do

var http = getHTTPObject();

var httpLogin = getHTTPObject();

var httpGeral = getHTTPObject();

var divAux = "";
