//
// Descricao: Funcoes de uso comum
// Ultima atualizacao: 19/05/2007
// Versao: 1.1
// Versao YUI: 2.2.0
// Versao YUI-ext: 0.33
//
// v.1.1: incluida a funcao "goPress" que executa a funcao especificada caso a tecla tambem especificada seja pressionada

// Definicoes de browser
var ns4   = ( document.layers ) ? true : false
var iens6 = document.all || document.getElementById;
var ua    = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test( ua );
var ie    = !opera && /MSIE/.test( ua );
var ie50  = ie && /MSIE 5\.[01234]/.test( ua );
var ie6   = ie && /MSIE [6789]/.test( ua );
var ieBox = ie && ( document.compatMode == null || document.compatMode != "CSS1Compat" );
var nn6   = !opera && /netscape.*6\./i.test( ua );

//
// Retorna a largura da tela
//
getWindowWidth = function() {
	return iens6 ? ( ieBox ? ( document.body.clientWidth  + document.body.scrollLeft ) : ( document.documentElement.clientWidth + document.documentElement.scrollLeft ) ) : window.innerWidth;
}

//
// Retorna a altura da tela
//
getWindowHeight = function() {
	if ( iens6 ) {
		if ( ieBox )
			pos = document.body.clientHeight + document.body.scrollTop;
		else
			pos = document.documentElement.clientHeight + document.documentElement.scrollTop;
	
	} else
		pos   = window.innerHeight;
}

//
// Recupera um elemento
//
getElement = function( id ) {
	if ( ns4 )
		return document.layers[id].document;
	else
		return document.getElementById( id );
}

//
// Faz uma pergunta
//
function question( str_question ) {
	if ( confirm( str_question ) )
		return true;
	else
		return false;
}

//
// Abre uma popup
//
function popup( url, nome, largura, altura, posicao, recize, barras ) {
	if (posicao == 0) {
		posleft = 20;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (posicao == 1) {
		posleft = (screen.width) ? (screen.width - largura) / 2 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (posicao == 2) {
		posleft = (screen.width) ? (screen.width - largura) - 28 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	}
	opBarras = (barras) ? "yes" : "no";
	opRecize = (recize) ? "yes" : "no";

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

function dumpProps(obj, parent) {
	for (var i in obj) {
		if (parent) { msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
		if (!confirm(msg)) { return; }
		if (typeof obj[i] == "object") { 
			if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
		}
	}
}

// BLOQUEIA CARACTERES EXCEDENTES EM TEXTAREAS
function maximo(obj, valor) {
	if (obj.value.length >= valor) return false;
}

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

//
// Funcao que adiciona o site aos favoritos
//
addFavorites = function( str_url, str_title ) {
	if ( window.external.addPanel )
		// Firefox
		window.external.addPanel( str_title, str_url, '' );
	
	else
		if ( window.external )
			// IE
			window.external.AddFavorite( str_url, str_title );
}