// 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) {
	var janela = window.open("ver_produtos_artigo.php?id=" + id, "", "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) {
	var janela = window.open("ver_produtos_cores.php?id=" + id, "", "resizable=no,toolbar=no,status=no,menubar=no,maximize=no,scrollbars=no,width=615,height=280");
}

// 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);
}

// 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) {
	if(window.event.keyCode == 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");
}

// função para carregar o conteúdo da página
function carrega(valor, args) {
	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 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();



