//Título principal do site na barra de título do navegador.

var titulo_site = "FITTRN";


//Nome do servidor. Colocar barra / no final

if (document.domain == "localhost")

{

var url_site = "http://localhost/fittrn/site/";

}

else

{

var url_site = "http://www.novo.fittrn.org.br/";

}


//Instancia o objeto XMLHttpRequest

function Ajax()

{

var ajax;

try

{

ajax = new XMLHttpRequest();

}

catch(ee)

{

try

{

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

}

catch(e)

{

try

{

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

}

catch(E)

{

ajax = false;

}

}

}

return ajax;

}


//Chama a função carrega_funcoes ao carregar a página

window.onload = carrega_funcoes_gerais;


//Função que chama outras funções

function carrega_funcoes_gerais()

{

menu_cascata();

}


//Função para evitar digitar document.getElementById

function gE(ID)

{

return document.getElementById(ID);

}


//Função para evitar digitar document.getElementsByTagName

function gEs(tag)

{

return document.getElementsByTagName(tag);

}

function menu_categorias_produtos()

{

if (gE("menu_categorias_produtos").style.display == "")

{

gE("menu_categorias_produtos").style.display = "block";

}

else

{

gE("menu_categorias_produtos").style.display = "";

}

}


//Função para campo select automático

function menu_campo_select(pagina)

{

window.location = (pagina);

}


//Função para campo de pesquisa não preenchido

function verifica_formulario_pesquisa()

{

if (gE("campo_pesquisa_01").value  ==  "")

{

alert("Favor preencher o campo de pesquisa.");

gE("campo_pesquisa_01").focus();

return false;

}

}


//Função para marcar todos os checkbox de uma vez

function marcar_checkbox()

{

for (i=0;i<gE("seleciona_itens").elements.length;i++)

{

if(gE("seleciona_itens").elements[i].type  ==  "checkbox")

{

gE("seleciona_itens").elements[i].checked=1;

}

}

}


//Função para desmarcar todos os checkbox de uma vez

function desmarcar_checkbox()

{

for (i=0;i<gE("seleciona_itens").elements.length;i++)

{

if(gE("seleciona_itens").elements[i].type  ==  "checkbox")

{

gE("seleciona_itens").elements[i].checked=0;

}

}

}


//Função para menus em cascata no IE

function menu_cascata()

{

if (document.all&&document.getElementById)

{

navRoot = gE("nav");

for (i=0; i<navRoot.childNodes.length; i++)

{

node = navRoot.childNodes[i];

if (node.nodeName=="LI")

{

node.onmouseover=function()

{

this.className+=" over";

}

node.onmouseout=function()

{

this.className=this.className.replace(" over", "");

}

}

}

}

}


//Função para imagem/mensagem carregando Ajax

function carregando_ajax()

{

gE("carregando_ajax_01").style.top = (screen.availHeight /2) - 100 + "px";
gE("carregando_ajax_01").style.left = (screen.availWidth /2) - 100 + "px";
gE("carregando_ajax_01").style.display = "block";

}


//Função para exibir mensagem de erro Ajax

function erro_ajax()

{

gE("transparencia").style.display = "block";
gE("erro_ajax_01").style.top = (screen.availHeight /2) - 200 + "px";
gE("erro_ajax_01").style.left = (screen.availWidth /2) - 100 + "px";
gE("erro_ajax_01").style.display = "block";

}


//Função para fechar janelas de mensagem

function fechar()

{

gE("transparencia").style.display = "none";
gE("erro_ajax_01").style.display = "none";

}


//Funções para abrir páginas do menu do site no GreyBox

function cliente()

{

GB_showCenter(titulo_site, url_site + 'cadastro_cliente.php', 480, 680);

}


function orcamento()

{

GB_showCenter(titulo_site, url_site + 'orcamento_preencher.php', 480, 680);

}


function depoimento()

{

GB_showCenter(titulo_site, url_site + 'depoimento_escrever.php', 480, 680);

}

function contato(assunto_predefinido)

{

if (assunto_predefinido)

{

GB_showCenter(titulo_site, url_site + 'contato_escrever_mensagem.php?assunto_predefinido=' + assunto_predefinido, 480, 615);

}

else

{

GB_showCenter(titulo_site, url_site + 'contato_escrever_mensagem.php', 480, 615);

}

}


function login()

{

GB_showCenter(titulo_site, url_site + 'usuario_login.php', 280,545);

}


function logout()

{

GB_showCenter(titulo_site, url_site + 'usuario_encerrar_sessao.php', 280,545);

}


function inserir_produto()

{

GB_showCenter(titulo_site, url_site + 'produto_inserir.php', 480, 680);

}


//Formata número tipo moeda usando o evento onKeyDown

function formatar_moeda(campo, separador_milhar, separador_decimal, tecla) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Backspace
	//if (whichCode == 0) return true; // Teclas delete, setas, etc
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;
}
