// JavaScript Document
window.onload = function(){
	//seleciona todas as tabelas da página
	var tabelas = document.getElementsByTagName("table");
	//laço paa percorrer todas as tabelas
	for (var i=0;i<tabelas.length;i++) {	
		//guarda a variável da tabela atual
		var tabela = tabelas[i];	
		//verifica se a classe da tabela é 'tabela_qtde'
		if (tabela.className=="tabela_qtde") {
			//pega as imagens da tabela
			var links = tabela.getElementsByTagName("a");
			//adiciona o evento de onclick à primeira imagem
			links[0].onclick = function (){
				var linha = this.parentNode.parentNode.parentNode;
				var campo = linha.getElementsByTagName("input");
					campo = campo[0];
					campo.value++;
				return false;
			}
			//adiciona o evento de onclick à segunda imagem
			links[1].onclick = function (){
				var linha = this.parentNode.parentNode.parentNode;
				var campo = linha.getElementsByTagName("input");
					campo = campo[0];
					campo.value--;
					if (campo.value<0) campo.value=0;
				return false;
			}
			//pega os inputs das tabelas 'tabela_qtde'
			var campos = tabela.getElementsByTagName("input");
			campos[0].onkeypress = function(e){
				if (window.event) {
					var codCaracter = e.keyCode;
				} else {
					var codCaracter = e.which;
				}	
				if (codCaracter>31 && (codCaracter<48 || codCaracter>57)) {
					return false;
				}
			}
			campos[0].onblur = function(){
				if (this.value=="") {
					this.value = 0;	
				}
				if (isNaN(this.value)) {
					this.value = 0;	
				}
			}			
		}
	}	
}
function popUp(url, windowName, w, h, scroll) {		
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';	
	win = window.open(url, windowName, winprops);
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}