var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false

function filtra(obj, padrao) {
	tk    = (ie4) ? event.keyCode : event.which;
	letra = String.fromCharCode(tk);

	for (x = 0; x < padrao.length; x++) {
		if (padrao.slice(x, x + 1) == letra) {
			return true;
		}
	}
	return false;
}

function maximo(obj, valor) {
	if (obj.value.length >= valor) return false;
}

function popup (url, nome, largura, altura, pos, scroll, barras) {
	if (pos == 0) {
		posleft = 20;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 1) {
		posleft = (screen.width) ? (screen.width - largura) / 2 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 2) {
		posleft = (screen.width) ? (screen.width - largura) - 28 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	}
	if (barras == true) opbarras = "yes"; else opbarras = "no";

	settings = 'width=' + largura + ', height=' + altura + ', top=' + postop + ', left=' + posleft + ', scrollbars=' + opbarras + ', location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=' + scroll;
	window.open(url, nome, settings);
}

function imprimir (url) {
	settings = 'width=' + 400 + ', height=' + 200 + ', top=' + 200 + ', left=' + 1600 + ', scrollbars=no, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no';
	window.open(url, 'imprimindo', settings);
}

function busca_cep () {
	settings = 'width=' + 550 + ', height=' + 400 + ', top=' + 100 + ', left=' + 100 + ', scrollbars=yes, location=no, directories=no, status=yes, menubar=yes, toolbar=no, resizable=yes';
	window.open("http://www.correios.com.br/servicos/cep/default.cfm", 'busca_cep', settings);
}

function escreve(id, txt) {
	if (ns4) {
		var lyr = document.layers[id].document;
		lyr.write(txt);
		lyr.close();
	} else
		document.getElementById(id).innerHTML = txt;
}

function semTab() {
	checatab = false;
}

function comTab() {
	checatab = true;
} 

checatab = true;

function pula(origem, tamanho, destino) {
	if ((origem.value.length == tamanho) && checatab)
		destino.focus();
}

function aviseme(id_produto) {
	popup ("/catalogo/aviseme.phtml?id_produto=" + id_produto, "aviseme", 450, 450, 1, false, false);
}


function popup(url,largura,altura) {
	window.open(url,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width='+largura+',height='+altura);
}

function hide(id) {
	if (ns4) document.layers[id].visibility = "hide"
	else document.getElementById(id).style.display="none";
}
function show(id) {	
	if (ns4) document.layers[id].visibility = "show"
 	else document.getElementById(id).style.display="";
}
function habilita(obj) {
	if (ns4) document.layers[obj].disabled = false;
	else document.getElementById(obj).disabled= false;
}
function desabilita(obj) {
	if (ns4) document.layers[obj].disabled = true;
	else document.getElementById(obj).disabled= true;
}
function redireciona (obj) {
	if (obj[obj.selectedIndex].value != "") {
		var url = obj[obj.selectedIndex].value;
		self.location = url;
	}
}

