var Site = {
	'loadPagina': function(pagina) {
		MenuBar.init(pagina);
	}
}

var Restrita = {
	'login': function() {
		if ($('restritaUsuario').value != '' && $('restritaSenha').value != '') {
			$('formRestrita').submit();
		}
		else {
			Msg.show('ATENÇÃO: informe os dados corretamente para entrar na área restrita.');
		}
	}
}

var Msg = {
	'obj': null,
	
	'show': function(msg, obj) {
		if (!obj)
			Msg.obj = 'divMsgBox';
		else
			Msg.obj = obj;
		
		if ($(Msg.obj).style.display != 'none')
			$(Msg.obj).style.display = 'none';
		Msg.efeito = new Effect.toggle($(Msg.obj));
		$(Msg.obj).innerHTML = msg;
	},
	
	'hide': function(msg) {
		Msg.efeito = new Effect.toggle($(Msg.obj));
	}
}

var MenuBar = {
	'paginas': new Array(),
	'opcoes': new Array(),
	
	'init': function(pagina) {
		MenuBar.opcoes = $A($('ulMenuBar').getElementsByTagName('a'));
		MenuBar.opcoes.each(function(obj) {
			if (obj.getAttribute('id') != 'link_' + pagina) {
				obj.onmouseover = function() {
					obj.style.color = '#FFFFFF';
					obj.style.backgroundColor = '#E77817';
				}
				obj.onmouseout = function() {
					obj.style.color = '';
					obj.style.backgroundColor = '';
				}
			} else {
					obj.style.color = '#FFFFFF';
					obj.style.backgroundColor = '#E77817';
			}
		});
	}
}

var Produtos = {
	'goPagina': function(acao_pagina, pagina, codcategoria, palavra_chave) {
		document.location = 'produtos.php?codcategoria=' + codcategoria + '&num_pagina=' + pagina + '&acao_pagina=' + acao_pagina + '&palavra_chave=' + palavra_chave;
	},
	
	'changeCategoria': function(codcategoria) {
		document.location = 'produtos.php?codcategoria=' + codcategoria;
	},
	
	'goBusca': function(palavra) {
		document.location = 'produtos.php?palavra_chave=' + palavra;
	}
}

var Cadastro = {
	enviar: function() {
		var box = 'divMsgCadastro';
		
		if ($('nome_empresa').value == '') {
			Msg.show('Informe o nome da empresa.', box);
			$('nome_empresa').focus();
			return false;
		}
		else
		if ($('cnpj').value == '') {
			Msg.show('Informe o CNPJ de sua empresa.', box);
			$('cnpj').focus();
			return false;
		}
		else
		if ($('email').value == '') {
			Msg.show('Informe seu e-mail.', box);
			$('email').focus();
			return false;
		}
		else
		if ($('endereco').value == '') {
			Msg.show('Informe o endereço de sua empresa.', box);
			$('endereco').focus();
			return false;
		}
		else
		if ($('cidade').value == '') {
			Msg.show('Informe a cidade de sua empresa.', box);
			$('cidade').focus();
			return false;
		}
		else
		if ($('estado').value == '0') {
			Msg.show('Selecione um estado.', box);
			return false;
		}
		else
		if ($('telefone').value == '') {
			Msg.show('Informe o telefone para contato.', box);
			$('telefone').focus();
			return false;
		}
		else
			return true;
	}
}

var Contato = {
	enviar: function() {
		var box = 'divMsgContato';
		
		if ($('nome').value == '') {
			Msg.show('Informe seu nome.', box);
			$('nome').focus();
			return false;
		}
		else
		if ($('email').value == '') {
			Msg.show('Informe seu e-mail.', box);
			$('email').focus();
			return false;
		}
		else
		if ($('assunto').value == '') {
			Msg.show('Informe o assunto.', box);
			$('assunto').focus();
			return false;
		}
		else
		if ($('mensagem').value == '') {
			Msg.show('Informe a mensagem.', box);
			$('mensagem').focus();
			return false;
		}
		else
			return true;
	}
}

var Banner = {
	getAnuncie: function() {
		document.location = 'anuncie.php';
	},
	
	
	verBanner: function(id, url, target, isJAH) {
		if (url)
			strLink = url;
		else
		if (id)
		{
			if (document.getElementById('f_' + id))
				strLink = document.getElementById('f_' + id).getAttribute("link_banner");
			else
				strLink = url;
		}
		else
			strLink = url;
		
		if (target)
			strTarget = target;
		else
		{
			if (document.getElementById('f_' + id))
				strTarget = document.getElementById('f_' + id).getAttribute("link_target");
			else
				strTarget = null;
		}
		
		if (id)
			jah("../site/_banner_click.php?codbanner=" + id, "divClicks");
			
		if (isJAH)
			eval(url);
	
		if (strTarget)
			var w = window.open(strLink, strTarget);
		else
			document.location = strLink;
		
	}
}