/* 
 * function servOC:
 * got from isohunt: http://www.isohunt.com/
 * modified by Marcelo Salhab Brogliato
 */
function servOC(i, img) {
  var trObj = (document.getElementById) ? document.getElementById('det' + i) : eval("document.all['det" + i + "']");
  if (trObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
      imagem(i, img);
    }
    else {
	  trObj.style.display="none";
    }
  }
}

function add_item2(id, tabela) {
	var qtdeObj = (document.getElementById) ? document.getElementById('qtde' + id) : eval("document.all['qtde" + id + "']");
	return add_item(id, qtdeObj, tabela);
}

function add_item(id, qtde, tabela) {
	var trObj = (document.getElementById) ? document.getElementById('opt' + id) : eval("document.all['opt" + id + "']");
	var opcao = "";
	if (trObj != null) {
		opcao = trObj.options[trObj.selectedIndex].text;
		if (trObj.options[trObj.selectedIndex].value == '') {
			alert("Por favor, selecione uma opção.");
			return;
		}
	}

	// Preenche os dados do produto a ser adicionado no carrinho
	var frmCompra = (document.getElementById) ? document.getElementById('frmCompra') : eval("document.all['frmCompra']");
	frmCompra.id.value = id;
	frmCompra.qtde.value = qtde.value;
	frmCompra.opcao.value = opcao;
	frmCompra.table.value = tabela;

	// Abre janela
	open_window('', 'add_window', 300, 30);
	
	// Adiciona produto ao carrinho
	frmCompra.submit();
}

// Mostra imagem
function imagem(id, img) {
	var trObj = (document.getElementById) ? document.getElementById('opt' + id) : eval("document.all['opt" + id + "']");
	var imgObj = (document.getElementById) ? document.getElementById('img' + id) : eval("document.all['img" + id + "']");
	if (trObj == null) {
		src = 'imagens/' + img;
	}
	else {
		opcao = trObj.options[trObj.selectedIndex].value;
		if (opcao.length == 0) {
			src = 'imagens/selecione_opcao.gif';
		}
		else {
			src = 'imagens/' + opcao;
		}
	}
	if (imgObj.src != src) {
		imgObj.src = 'imagens/carregando.gif';
		imgObj.src = src;
	}
}

function open_window(url, name, width, height) {
	x = (screen.width - width) / 2;
	y = (screen.height - height) / 2;
	add_window = window.open(url, name, "toolbar=0,resizable=0,directories=0,status=0,menubar=0,scrollbars=0,location=0,width=" + width + ",height=" + height + ",left=" + x + ",top=" + y);
	add_window.focus();
}

