//
// 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 );

var sci = [ '/files/js/common/jgallery.js', '/files/js/common/jeventcover.js' ];
var ssi = [ '/files/css/common/jgallery.css', '/files/css/common/jeventcover.css' ];

(function() {
	var h = document.location.hostname.substr(document.location.hostname.indexOf('adrenaline.'));
	if(h.indexOf('.uol.com.br') == -1) h = 'www.' + h;
	var d = new Date();
	var s;
	var sc;
	
	for(var i = 0; i < sci.length; i++) {
		s = document.createElement('script');
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://' + h + sci[i] + '?' + d.getTime();
		sc = document.getElementsByTagName('script')[0];
		sc.parentNode.insertBefore(s, sc);
	}
	
	for(var i = 0; i < ssi.length; i++) {
		s = document.createElement('link');
		s.rel = 'stylesheet';
		s.type = 'text/css';
		s.async = true;
		s.href = 'http://' + h + ssi[i] + '?' + d.getTime();
		sc.parentNode.insertBefore(s, sc);
	}
})();

//
// 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;
}

function limitaTamanho( obj, contador, len ) {
	obj.value = obj.value.substring( 0, len );
	
	escreve( contador, ( len - obj.value.length ) );
} 
