function chamaFechaDivs(){
		x= setTimeout("fechaDivs()",1500 );
	}
function chamaFechaDivProd(){
		x= setTimeout("fechaDivProd()",1500 );
	}
	
function zeraTimer(){
	if(typeof(x) != 'undefined'){
		clearTimeout(x);
	}
}
function fechaDivProd(){
	document.getElementById('prod2').style.display = 'none';
}
function fechaDivs(){
	document.getElementById('categoria').style.display = 'none';
	document.getElementById('subcategoria').style.display = 'none';
}
function setComboClass(id,state) {
	if(state == '1') {
		document.getElementById(id).className = "comboHover";
		document.getElementById('lnk_' + id).className = "comboLink";
	} else {
		document.getElementById(id).className = "comboInactive";
		document.getElementById('lnk_' + id).className = "";
	}
}

/***/

var categoria = false;
var subcategoria = false;

function mostraDiv(id){
	
	var div = document.getElementById(id);
	var d = div.style.display;
	if (id =='subcategoria' || id =='prod') {
		
		if(categoria == true && id=='subcategoria'){
			
			if(d == "block"){
				d = "none";
			} else {
				div.style.display = "block";
				document.getElementById('categoria').style.display = 'none';
			}
			
		}
		
		if(subcategoria == true && id =='prod'){
			if(d == "block"){
				div.style.display = "none";
			} else {
				div.style.display = "block";
				document.getElementById('subcategoria').style.display = 'none';
			 	document.getElementById('categoria').style.display = 'none';
			}
		}
	}
	
	else
	
	{
		
		
		if(d == "none"){
			div.style.display = "block"; // bug, nao pega a var 'd'
			 document.getElementById('subcategoria').style.display = 'none';
		} else {
			d = "none";
		}
		
	}
}

function sendForm(id) {
	var f = document.getElementById(id);
	if(f.linha.selectedIndex != -1) {
		return (true);
	} else {
		return (false);	 
	}
}
		
function changeSelect(cid,nome){
	var xid = cid;
	var gw = JSGateway.Create();
	gw.setOutput('DivProduto');
							gw.onLoading = function(){
		return '<table width=100% height=100%><tr><td align=center><div><img src="../images/ajax.gif" /></div></td></tr></table>';
	}
							gw.onLoad = function(){
							 jsGetProdDiv(cid,nome);
							}
	gw.load('/index.php/clsProduto.getProdutos,'+xid);
}
function chama(id,nome){
	changeSelect(id,nome);
	//setTimeout("jsGetProd("+id+")",100);
}

function jsGetSubCat(id_sub) {
		var conn = JSGateway.Create();
		var ul = document.getElementById("ul_sub");
		var divCat = document.getElementById("categoria");
		var divSub = document.getElementById("subcategoria");
		if(id_sub != 0) {
			conn.onLoading = function(){
				return '<div>Carregando...<div><img src="../images/ajax.gif" /></div></div>';
			}
			conn.load('/index.php/clsProduto.getSubCat,' + id_sub);
			conn.onLoad = function (s) {
				ul.innerHTML = s;
				divCat.style.display = "none";
				document.getElementById("sel_subcat").innerHTML = "Selecione a Sub-Categoria";
				divSub.style.display = "";
				categoria = true;
			}
		}
	}
	function jsGetSubCatDiv(id_sub,nome) {
		var conn = JSGateway.Create();
		var ul = document.getElementById("ul_sub");
		var divCat = document.getElementById("categoria");
		var divSub = document.getElementById("subcategoria");
		if(id_sub != 0) {
			conn.onLoading = function(){
				return '<div>Carregando...<div><img src="../images/ajax.gif" /></div></div>';
			}
			conn.load('/index.php/clsProduto.getSubCat,' + id_sub);
			conn.onLoad = function (s) {
				ul.innerHTML = s;
				divCat.style.display = "none";
				document.getElementById("sel_cat").innerHTML = nome;
				document.getElementById("sel_subcat").innerHTML = "Selecione a Sub-Categoria";
				divSub.style.display = "";
				categoria = true;
			}
		}
	}
	function jsGetSubCatDivInt(id_sub,nome) {
		var conn = JSGateway.Create();
		var ul = document.getElementById("ul_sub");
		var divCat = document.getElementById("categoria");
		var divSub = document.getElementById("subcategoria");
		if(id_sub != 0) {
			conn.onLoading = function(){
				return '<div>Carregando...<div><img src="../images/ajax.gif" /></div></div>';
			}
			conn.load('/index.php/clsProduto.getProd,' + id_sub);
			conn.onLoad = function (s) {
				ul.innerHTML = s;
				divCat.style.display = "none";
				document.getElementById("sel_cat").innerHTML = nome;
				document.getElementById("sel_subcat").innerHTML = "Selecione o Produto";
				divSub.style.display = "";
				categoria = true;
			}
		}
	}
function jsGetProd(id,nome) {
	var connP = JSGateway.Create();
	var ul = document.getElementById('ul_prod');
	var divCat = document.getElementById("categoria");
	var divSub = document.getElementById("subcategoria");
	if(id != 0) {
		connP.onLoading = function(){
				return '<div>Carregando...<div><img src="../images/ajax.gif" /></div></div>';
			}
		connP.load('/index.php/clsProduto.getProd,' + id);
		connP.onLoad = function (s) {					
			ul.innerHTML = s;
			divCat.style.display = "none";
			divSub.style.display = "none";
			document.getElementById("sel_subcat").innerHTML = nome;
			document.getElementById("sel_prod").innerHTML = "Selecione o Produto";
			subcategoria = true;
		}
	}
}
function jsGetProdDiv(id,nome) {
	var conn2 = JSGateway.Create();
	var ul = document.getElementById('ul_prod');
	var divCat = document.getElementById("categoria");
	var divSub = document.getElementById("subcategoria");
	if(id != 0) {
		conn2.onLoading = function(){
				return '<div>Carregando...<div><img src="../images/ajax.gif" /></div></div>';
			}
		conn2.load('/index.php/clsProduto.getProd,' + id);
		conn2.onLoad = function (s) {					
			ul.innerHTML = s;
			divCat.style.display = "none";
			divSub.style.display = "none";
			document.getElementById("sel_subcat").innerHTML = nome;
			document.getElementById("sel_prod").innerHTML = "Selecione o Produto";
			subcategoria = true;
		}
	}
}
function openImage(srcImg,id){
	var img = new Image();
	img.src = srcImg;
	var width = img.width;
	var height = img.height;
	window.open('$link:popimagenot/id/'+id,'imagem', 'width='+width+', height='+height+', resizable=no, scrollbars=yes');
}