var timeout = 0;
var banners = 0;
var bannershow = 1;
function banner_make(tot){
	this.banners = tot;
	var top = -288;
	for(x=2; x<=tot; x++){
		gbid('box_l_' + x).style.top = top + 'px';
		gbid('box_l_' + x).style.left = '900px';
		top = top - 288;
	}
	gbid('home_pub_nav_bt1').style.backgroundPosition = '0px 0px';
	this.timeout = setTimeout('banner_launch(900, 2)', 5000);
}
function banner_launch(px, id){
	if(this.timeout)
		clearTimeout(this.timeout);
	if(id != this.bannershow){
		gbid('home_pub_nav_bt' + id).style.backgroundPosition = '0px 0px';
		px = px - 10;
		px2 = parseInt(gbid('box_l_' + this.bannershow).style.left) - 10;
		
		gbid('box_l_' + id).style.left = px + 'px';
		gbid('box_l_' + this.bannershow).style.left = px2 + 'px';
		
		if(px > 0)
			this.timeout = setTimeout('banner_launch(' + px + ', ' + id + ')', 1);
		else{
			if(this.timeout)
				clearTimeout(this.timeout);
			this.bannershow = id;
			for(x=1; x<=this.banners; x++){
				if(x != id){
					gbid('box_l_' + x).style.left = '900px';
					gbid('home_pub_nav_bt' + x).style.backgroundPosition = '20px 0px';
				}
			}
			id++;
			if(id > this.banners)
				id = 1;
			this.timeout = setTimeout('banner_launch(900, ' + id + ')', 5000);
		}
	}
}
function perfil(x, t){
	hide_o('full_bx');
	
	for(y=1; y<=t; y++){
		hide_o('full_bx' + y);
		hide_o('emp_i' + y);
	}
	
	show_o('full_bx' + x);
	show_o('emp_i' + x);
	
}
function contato_valida(){
	objform = document.getElementById("frm_contato");

	if(objform.nome.value.length < 4){
		alert('Digite seu nome corretamente');
		objform.nome.focus("");
	}
	else if(objform.email.value.length < 8){
		alert('Digite seu e-mail corretamente');
		objform.email.focus("");
	}
	else if(objform.email.value!='' && (objform.email.value.split("@").length <=1 || objform.email.value.split(".").length <=1)){
		alert('Digite seu e-mail corretamente');
		objform.email.focus("");
	}
	else if(objform.fone.value.length < 8){
		alert('Digite seu telefone corretamente');
		objform.fone.focus("");
	}
	else if(objform.mensagem.value==''){
		alert('Digite o comentario corretamente');
		objform.mensagem.focus("");
	}
	else
		objform.submit("");
}
function chamado_valida(){
	objform = document.getElementById("frm_chamado");

	if(objform.nome.value.length < 4){
		alert('Digite seu nome corretamente');
		objform.nome.focus("");
	}
	else if(objform.email.value.length < 8){
		alert('Digite seu e-mail corretamente');
		objform.email.focus("");
	}
	else if(objform.email.value!='' && (objform.email.value.split("@").length <=1 || objform.email.value.split(".").length <=1)){
		alert('Digite seu e-mail corretamente');
		objform.email.focus("");
	}
	else if(objform.fone.value.length < 8){
		alert('Digite seu telefone corretamente');
		objform.fone.focus("");
	}
	else if(objform.mensagem.value==''){
		alert('Digite o comentario corretamente');
		objform.mensagem.focus("");
	}
	else
		objform.submit("");
}
function cadastro_valida(){
	objform = document.getElementById("frm_cadastro");

	if(objform.TIPO_PESSOA.value == "J" && objform.NOME_FANTASIA.value < 2){
		alert("Digite corretamente o nome fantasia");
		objform.NOME_FANTASIA.focus();
	}
	else if(objform.TIPO_PESSOA.value == "J" && objform.RAZAO.value < 5){
		alert("Digite corretamente a razao");
		objform.RAZAO.focus();
	}
	else if(objform.TIPO_PESSOA.value == "J" && objform.CNPJ.value < 18){
		alert("Digite corretamente o cnpj.");
		objform.CNPJ.focus();
	}
	else if(objform.NOME.value < 2){
		alert("Digite corretamente o nome");
		objform.NOME.focus();
	}
	else if(objform.CPF.value < 14){
		alert("Digite corretamente o cpf.");
		objform.CPF.focus();
	}
	else if(validaCPF(objform.CPF.value) == 0){
		alert("CPF inválido");
		objform.CPF.focus();
	}
	else if(objform.CIDADE.value == ""){
		alert("Escolha a cidade");
		objform.CIDADE.focus();
	}
	else if(objform.DDD.value < 2){
		alert("Digite corretamente o ddd");
		objform.DDD.focus();
	}
	else if(objform.TEL.value < 7){
		alert("Digite corretamente o telefone");
		objform.TEL.focus();
	}
	else if(objform.EMAIL.value < 5){
		alert("Digite corretamente o e-mail");
		objform.EMAIL.focus();
	}
	else if(objform.EMAIL.value != "" && (objform.EMAIL.value.split("@").length <= 1 || objform.EMAIL.value.split(".").length <= 1)){
		alert("Email digitado é inválido");
		objform.EMAIL.focus();
	}
	else if(objform.USUARIO.value < 6){
		alert("Digite corretamente o usuário de 6 ŕ 20 digitos");
		objform.USUARIO.focus();
	}
	else if(objform.SENHA.value < 6){
		alert("Digite corretamente a senha de 6 ŕ 20 digitos");
		objform.SENHA.focus();
	}
	else
		objform.submit();
}
function cart_process(id, acao){
	frm = document.getElementById("frm_carrinho");
	frm.idp.value = id;
	frm.acao.value = acao;
	if(acao == 'rct'){
		frm.qtd.value = frm['qtd'+id].value;
		setTimeout('frm.submit()', 1000);
	}
	else
		frm.submit();
}
function cart_next(){
	document.location.href = 'carrinho_cadastro.php';
}
function end_next(){
	document.location.href = 'carrinho_pagamento.php';
}
function show_camposJ(x){
	hide_o('cad_1');
	hide_o('cad_2');
	hide_o('cad_3');
	show_o2('obrcpf');
	if(x == 'J'){
		show_o('cad_1');
		show_o('cad_2');
		show_o('cad_3');
		hide_o2('obrcpf');
	}
}
function validar(){
	objfrm = document.frm;
	if(objfrm.USUARIO.value == ""){
		alert("Digite o seu login");
		objfrm.USUARIO.focus();
	}
	else if(objfrm.SENHA.value == ""){
		alert("Digite a sua senha");
		objfrm.SENHA.focus();
	}
	else
		objfrm.submit();
}
function comprar(){
	objform = document.getElementById("frm_produto");
	if(objform.idp.value > 0)
		objform.submit();
}
//--- gal
var total, num, vet, vet_w, vet_h = "";

function initGal(tabela, id, ultimo_id){
	ajax = new ajax_engine;
	if(ajax){
		ajax.open("POST", "includes/window_nucleo.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4){
				if(ajax.responseXML)
					processXML(ajax.responseXML);
			}
		}
		var params = "tabela=" + tabela + "&id=" + id + "&ultimo_id=" + ultimo_id;
		ajax.send(params);
	}
}
function processXML(obj){
	var dataArray = obj.getElementsByTagName("sub");
	for(var i=0; i<dataArray.length; i++){
		var item      = dataArray[i];
		this.total    = item.getElementsByTagName("total")[0].firstChild.nodeValue;
		this.num      = item.getElementsByTagName("num")[0].firstChild.nodeValue;
		var temp_nome = item.getElementsByTagName("temp_nome")[0].firstChild.nodeValue;
		var temp_wid  = item.getElementsByTagName("temp_wid")[0].firstChild.nodeValue;
		var temp_hei  = item.getElementsByTagName("temp_hei")[0].firstChild.nodeValue;
		this.vet      = temp_nome.split("|up|");
		this.vet_w    = temp_wid.split("|up|");
		this.vet_h    = temp_hei.split("|up|");
		if(this.total == "" || this.total == "0" || this.total == "1" ){
			hide_o("bt_ant");
			hide_o("bt_pro");
		}
	}
	trocaImg('null');
}
function trocaImg(acao){ hide_o("imgFix");
	gbid("overlay").style.height =  document.body.scrollHeight + "px";
	if(parseInt(document.documentElement.scrollTop) > 0)
		gbid("molduraImg").style.top =  (parseInt(document.documentElement.scrollTop) + 50) + "px";
	if(parseInt(document.body.scrollTop) > 0)
		gbid("molduraImg").style.top =  (parseInt(document.body.scrollTop) + 50) + "px";
	show_o("overlay");
	show_o("molduraImg");
	show_o("imgLoading");

	if(acao == "previous")
		this.num--;
	if(acao == "next")
		this.num++;
	if(this.num > this.total - 1)
		this.num = 0;
	if(this.num < 0)
		this.num = this.total - 1;

	var w  = vet_w[this.num];
	var h  = vet_h[this.num];
	var w2 = parseInt(w) + 25;
	var h2 = parseInt(h) + 25;

	gbid("imgFix").src    = vet[this.num];
	gbid("imgFix").width  = w;
	gbid("imgFix").height = h;
	gbid("molduraImg").style.height = h2 + "px";
	gbid("molduraImg").style.width  = w2 + "px";
	gbid("molduraImg").style.left   =  parseInt(parseInt(document.body.clientWidth) / 2) - parseInt(w2 / 2) + "px"; hide_o("imgLoading");
	show_o("imgFix");
}
function closeGal(){ hide_o("molduraImg"); hide_o("overlay"); hide_o("imgFix");
	show_o("imgLoading");
	gbid("imgFix").src = "imgs/px-b.gif";
	gbid("molduraImg").style.width  = 50;
	gbid("molduraImg").style.height = 50;
}
//-- gal zoon lens
var galz_view   = 0;
var tmp_gztm    = 0;
var minisz_exec = 1;
var gzlens_w    = 100;
var gzlens_h    = 100;

function galzMuda(x){
	this.galz_view = x;
	this.gzlens_w = parseInt(800 / this.galz_ws[this.galz_view] * 100);
	if(this.gzlens_w > 260)
		this.gzlens_w = 260;
	this.gzlens_h = gzlens_w;
	if(this.gzlens_h > this.galz_hms[this.galz_view])
		this.gzlens_h = this.galz_hms[this.galz_view];
	gbid("galz_lens").style.width  = this.gzlens_w + "px";
	gbid("galz_lens").style.height = this.gzlens_h + "px";
	gbid("galz_lens").style.top    = returnPosElement("imgz_pro", "y");
	gbid("galz_lens").style.left   = returnPosElement("imgz_pro", "x");
	gbid("imgz_pro").src            = this.galz_ns[x];
	gbid("galz_zoom").style.background = "url(" + this.galz_ns[x] + ") no-repeat";
}
function galLens(e, on){
	if(this.tmp_gztm > 0)
		clearTimeout(this.tmp_gztm);
	this.tmp_gztm = setTimeout('galLens("' + e + '", 0)', 2000);
	var tempX = 0;
	var tempY = 0;
	var tempT = returnPosElement("imgz_pro", "y");
	var tempL = returnPosElement("imgz_pro", "x");
	var lens  = gbid("galz_lens").style;
	var iprow = gbid("imgz_pro").width;
	var iproh = gbid("imgz_pro").height;
	if(on == 1){
		show_o("galz_lens");
		gbid("galz_zoom").style.visibility = "visible";
		gbid("galz_zoom").style.display    = "inline-block";
		gbid("galz_zoom").style.width      = "314px";
		gbid("galz_zoom").style.height     = "314px";
	}
	else if(on == 0){
		hide_o("galz_lens");
		hide_o("galz_zoom");
		clearTimeout(this.tmp_gztm);
		return false;
	}
	if(document.all){
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else{
		document.captureEvents(Event.MOUSEMOVE);
		tempX = e.pageX;
		tempY = e.pageY;
	}
	tempX -= this.gzlens_w / 2;
	tempY -= this.gzlens_h / 2;
	if(tempX > iprow - this.gzlens_w - 2 + tempL)
		tempX = iprow - this.gzlens_w - 2 + tempL;
	if(tempX < tempL)
		tempX = tempL;
	if(tempY > iproh - this.gzlens_h - 2 + tempT)
		tempY = iproh - this.gzlens_h - 2 + tempT;
	if(tempY < tempT)
		tempY = tempT;
	tempX = tempX<0?0:tempX;
	tempY = tempY<0?0:tempY;
	lens.left = tempX + "px";
	lens.top  = tempY + "px";
	tempXg = (tempX - tempL) * (this.galz_ws[this.galz_view] / this.galz_wms[this.galz_view]);
	tempYg = (tempY - tempT) * (this.galz_hs[this.galz_view] / this.galz_hms[this.galz_view]);
	gbid("galz_zoom").style.backgroundPosition = "-" + tempXg + "px -" + tempYg + "px";
}

