// scripts.js
var t
var m
function contractall(){
if (document.getElementById){
var inc=0
while (document.getElementById("sub"+inc)){
document.getElementById("sub"+inc).style.display="none"
inc++
}
}
}
function contractAllAbas(){
	document.getElementById("taba0").className = 'aba'
	document.getElementById("taba1").className = 'aba'
	document.getElementById("taba2").className = 'aba_large'
	document.getElementById("taba3").className = 'aba_large'
	document.getElementById("taba4").className = 'aba_large'
}
function aba1()
{
contractAllAbas()
document.getElementById("taba0").className = 'aba_hover aba'
}
function doAba(x, size)
{
	contractAllAbas()
	if (size == 1) 
	{
		document.getElementById("taba"+x).className = 'aba_large_hover aba_large'
	}
	else
	{
		document.getElementById("taba"+x).className = 'aba_hover aba'
	}
	expandone(x)
}
function expandone1(x) {clearTimeout(m); m = setTimeout('expandone(0)', 2000)}
function expandone(x){clearTimeout(m); contractall();
if (x == 0) aba1()
document.getElementById("sub"+x).style.display="block" 

}
	
// SCRIPTS GENÉRICOS

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
// -- fim scripts.js
// mostradiv.js
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=0 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function showhide(obj, e, visible, hidden){
if (ie5||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (e.type=="click" && obj.display==hidden || e.type=="mouseover")
{
	if(ieversion<=6) {
	document.getElementById('parametro').style.visibility ="hidden"
	}
obj.display=visible
//document.getElementById('googlebanner').style.display ="none"
}
else if (e.type=="click")
{
obj.display=hidden
}
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0;
	if (whichedge=="rightedge"){
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
				if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
					edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
}

function dropdownmenu(obj, e, dropmenuID){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
if (typeof dropmenuobj!="undefined") //hide previous menu
dropmenuobj.style.display="none"
clearhidemenu()
if (ie5||ns6){
obj.onmouseout=delayhidemenu
dropmenuobj=document.getElementById(dropmenuID)
if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.display='none';}
dropmenuobj.onmouseover=clearhidemenu
dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
showhide(dropmenuobj.style, e, "block", "none")
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.top=dropmenuobj.y+obj.offsetHeight+"px"
	if(ieversion<=6) {
		dropmenuobj.style.left=(980-dropmenuobj.clientWidth)/2+"px";
	} else {
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px";
	}
}
return clickreturnvalue()
}

function clickreturnvalue(){
if ((ie5||ns6) && !enableanchorlink) return false
else return true
}

function contains_ns6(a, b) {
if (b == null) return false
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie5&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function delayhidemenu(){
	//if(ieversion<=6) {
	//delayhide=setTimeout("dropmenuobj.style.display='none';document.getElementById('googlebanner').style.display='block';",disappeardelay)
	//} else {
	delayhide=setTimeout("dropmenuobj.style.display='none';",disappeardelay)
	//}
}


function clearhidemenu(){
	document.getElementById('parametro').style.visibility='visible';
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
// fim mostradiv.js
// ajax.js
var aguarde_ajax = "<img src='images/wait.gif' width='16' height='16' alt='...' />";
var ajaxResponse = "";
function callAjax(div, acao, params, aguarde, elMethod){
	if (div==undefined){}
	else{
		var objDiv	= document.getElementById(div);
	}
	if ( elMethod === undefined ) elMethod = 'get';
	//var elMethod	= "get";
	var varArquivo	= "http://www.letras.com.br/ajax.asp?acao=" + acao;
	//var varArquivo	= "http://servidor/letras/ajax.asp?acao=" + acao;
	if (params > "") varArquivo += "&" + params
	if (aguarde) objDiv.innerHTML = aguarde_ajax;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);
}
function tag2script(texto){
    var ini = 0;
    while ( ini!=-1 ){
        ini = texto.indexOf('<' + 'script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</' + 'script' + '>', ini);
            codigo = texto.substring(ini, fim);
            eval( codigo );
        }
    }
}


var Ajax = function(Objeto, Metodo, Arquivo){
	var xmlhttp;

	this.callAjax = function(){
		if (window.XMLHttpRequest){
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(E){
					xmlhttp = false;
				}
			}
		}
	}
	
	switch (Metodo){
		/*  
		'	ENVIANDO POR 'POST' NO AJAX
		*/
		case 'post':
		this.callAjax();
		xmlhttp.abort()
		//xmlhttp.open('POST', Arquivo+'?'+this.rand( 999 ), true);
		//xmlhttp.open('POST', Arquivo+'?'+ Math.floor(Math.random()*999), true);
		xmlhttp.open('POST', Arquivo+'&'+ Math.floor(Math.random()*999), true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;iso-8859-1");
		xmlhttp.setRequestHeader("CharSet", "iso-8859-1")
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		xmlhttp.setRequestHeader("Pragma", "no-cache");
		xmlhttp.send(null);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				var txtRetorno = xmlhttp.responseText;
				tag2script( txtRetorno );
				if (Objeto==null) ajaxResponse = txtRetorno;
				else Objeto.innerHTML =  txtRetorno;
			}
		}
		break;


		/*  
		'	ENVIANDO POR 'GET' NO AJAX
		*/	
		case 'get':
		this.callAjax();
		xmlhttp.abort();
		xmlhttp.open('GET', Arquivo,true);
		xmlhttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				var txtRetorno = xmlhttp.responseText;
				tag2script( txtRetorno );
				if (Objeto==null) ajaxResponse = txtRetorno;
				else Objeto.innerHTML =  txtRetorno;
			}
		}
		xmlhttp.send(null);
		break;
		
		/*  
		'	ENVIANDO POR 'AUTOCOMPLETE' NO AJAX
		*/
		case 'autocomplete':
		this.callAjax();
		xmlhttp.abort();
		var v2 = Arquivo;
		Arquivo = "http://www.letras.com.br/arquivos/autocomplete/artistas/" + v2.charAt(0) + "/_" + v2 + ".txt";
		//Arquivo = "http://servidor/letras/arquivos/autocomplete/artistas/" + v2.charAt(0) + "/_" + v2 + ".txt";
		xmlhttp.open('GET', Arquivo, true);
		xmlhttp.setRequestHeader("Content-Type","text/plain;charset=ISO-8859-1");
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4){
				var txtRetorno  = xmlhttp.responseText;
				if(txtRetorno.indexOf("<") == -1){
					tag2script(txtRetorno);
					ajaxResponse	= txtRetorno;
					var arrArts = ajaxResponse.split("\n");
					//alert(arrArts.length)
					for (var x=1;x<=arrArts.length-1;x++){
						addBusca(arrArts[x].split(" | ")[1],arrArts[x].split(" | ")[0]);
					}
					cacheBuscas[v2] = Buscas;
					terminaAutoCompletar(Objeto);
					LastSearch = v2;
					LastSearchRows = Buscas.length;
	//				alert("3: " + LastSearch + " - " + LastSearchRows)

					
						//document.getElementById("debug").value = "LastSearchRows:" + LastSearchRows + "\nLastSearch:" + LastSearch;
				}
				else{
					var v3 = "";
					if(v2.length > 2) v3 = v2.substr(0, v2.length-1)
					cacheBuscas[v2] = cacheBuscas[v3];
					chamaAutoCompletar2(v3);
					terminaAutoCompletar(Objeto);
					LastSearch = v3;
					LastSearchRows = Buscas.length;
					//alert("4: " + LastSearchRows)

				}
			}
		}
		xmlhttp.send(null);
		break;

		default:
			/* NADA */
		break;
	}			
}
// fim ajax.js
// showpersonalizar.js
function showPersonalizar(obj, e)
{
	
	if (document.getElementById("personalizar").innerHTML == "") callAjax("personalizar", "SHOW_PERSONALIZAR", "", true)
	dropdownmenu(obj, e, 'personalizar')
	
	
}
function cleanWallpaper()
{
	callAjax(null, "ALTERAR_BG", "p=1&p2=&p3=", false )
	document.getElementById('fundo').src='images/bg/bg_branco.png'
}
function cleanTopo()
{
	callAjax(null, "ALTERAR_BG", "p=2&p2=&p3=", false )
	document.getElementById('topo').style.backgroundImage='url(images/bg_topo_trans.png)'
}
function changeBG(obj)
{
	callAjax(null, "ALTERAR_BG", "p=1&p2=" + obj.id.substr(2) + "&p3=" + obj.value, false )
	document.getElementById('fundo').src='arquivos/bg/wallpapers/' + obj.value
}
function changeBG2(id, url)
{
	callAjax(null, "ALTERAR_BG", "p=1&p2=" + id + "&p3=" + url, false )
	document.getElementById('fundo').src= 'arquivos/bg/wallpapers/' + url
}
function changeTopo(obj)
{
	callAjax(null, "ALTERAR_BG", "p=2&p2=" + obj.id.substr(2) + "&p3=" + obj.value, false )
	document.getElementById('topo').style.backgroundImage='url(arquivos/bg/topo/' + obj.value + ')'
}
function changeTopoCookie(url)
{
	document.getElementById('topo').style.backgroundImage='url(arquivos/bg/topo/' + url + ')'
}
function changeWallpaperCookie(url)
{
	document.getElementById('fundo').src='arquivos/bg/wallpapers/' + url
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
// fim showpersonalizar.js
// autocomplete.js
var Buscas 		= new Array(); 	// Array que contem todos os buscas
var cacheBuscas		= new Array(); 	// Armazena um array com o cache das buscas ja realizadas
var Selecionado 	= ""; 		// Nome do Item da Tabela que estao com Selecao Ativa
var IdSelecionado 	= 0; 		// ID do Item selecionado 
var IdAnterior		= 0;		// ID do Item anterior selecionado
var Quantidade		= 0;		// Quantidade de itens encontrados	
var TotalSelecionados	= 0; 		// Total de Itens atualmente na lista de buscas
var LastSearch		= ""; 		// Ultima Busca realizada
var LastSearchRows	= 999;  	// Total de itens encontrados

String.prototype.trim		= function(){var x=this;x=x.replace(/^\s*(.*)/, "$1");x=x.replace(/(.*?)\s*$/, "$1");return x}
String.prototype.replaceAll 	= function(de,para){var str=this;var pos=str.indexOf(de);while (pos>-1){str=str.replace(de,para);pos=str.indexOf(de);}return (str);}
String.prototype.stripTags 	= function(){var v=this;var re=/<\S[^>]*>/g;v = v.replace(re,"");return v;}
String.prototype.replacesBusca	= function(){return this.stripAcentos().replace(/[^\w]/g,"")};
String.prototype.stripAcentos	= function(){var tmp=this.toLowerCase();tmp=tmp.replace(/[áàâãäÁÀÂÃÄ]/g,"a").replace(/[éèêëÉÈÊË]/g,"e").replace(/[íìîïÍÌÎÏ]/g,"i").replace(/[óòôõöÓÒÔÕÖ]/g,"o").replace(/[úùûüÚÙÛÜ]/g,"u").replace(/[çÇ]/g,"c").replace(/[ñÑ]/g,"n");return tmp};

function addBusca(T1,T2){
	var Busca = new Array();
	Busca[0] = T1; Busca[1] = T2;
	//Buscas[Buscas.length] = Busca;
	Buscas.push(Busca);
}

function doNegrito(T1,T2){
	var pos = 0;
	var v 	= T2.stripTags();
	v	= T2.split(' ');
	var T3 = T1;
	
	for(n in v){
		pos = T3.toLowerCase().stripAcentos().indexOf(v[n].toLowerCase().stripAcentos());
		if (pos != -1 && v[n].length >= 1){
			t = T3.substring(0, pos);
			t += 'kkkkkk' + T3.substring(pos, pos + v[n].length) + 'zzzzzz';
			T3 = t + T3.substring(pos + v[n].length);
		}
	}
	return T3;
}

function populaBusca(obj,o){
	var strLista	= "";
	var strItem	= "";
	var Cont	= 0;
	var Texto	= "";
	var Quantidade	= 0;
	var Ant		= "";
	var arrTexto	= new Array();
	var arrTmp	= new Array();

	arrTexto[0] 	= o.value.toString();
	Texto 		= arrTexto[0];

	// Se o texto estiver vazio, basta sair da funcao
	if (Texto == "") return false;

	// Preenchendo a DIV de acordo com Texto
	strLista = "<ul id='lstBuscas' class=\"autocomplete\">";

	for (Cont=0;Cont<Buscas.length;Cont++){
		// Verificando se o Texto existe na Busca
		if (Buscas[Cont][0].toString().toLowerCase().replacesBusca().indexOf(Texto.toLowerCase().replacesBusca())>-1){
			if (Ant != Buscas[Cont][0].toString()){
				arrTmp[Quantidade] = Buscas[Cont];
				Quantidade++;
				strItem = Buscas[Cont][0].toString();
				if (strItem.length > 24) strItem = strItem.substr(0, 24) + "...";
				strItem		= doNegrito(strItem, Texto);
				strLista	+= "<li id=\"itmBusca" + Quantidade + "\" onMouseOver=\"SetBuscaSelecionada(" + Quantidade + ")\"><a href=\"" + Buscas[Cont][1].toString() + "\" id=\"lnkBusca" + Quantidade + "\" style='font-weight:normal' onMouseDown='window.location.href=\"" + Buscas[Cont][1].toString() + "\"'>" + strItem + "</a></li>";
			}
			Ant = Buscas[Cont][0].toString();
		}
	}
	strLista += "</ul>";

	Buscas 			= arrTmp;
	TotalSelecionados 	= Quantidade;

	// Verificando se foram encontrados buscas para saber se sera mostrado a DIV ou nao
	if (TotalSelecionados > 0){
		// Mostrando a DIV
		obj.innerHTML = strLista.replaceAll("kkkkkk", "<B>").replaceAll("zzzzzz", "</B>");
		var oLst = document.getElementById("lstBuscas");
		//SetBuscaSelecionada(1);
		return true;
	}
	else return true;
}

function selectBusca(IdDestino, strOrigem, TextoDigitado){
	var objDestino = document.getElementById(IdDestino);

	//Escondendo a DIV
	unshowAutoCompletar(objDestino);

	//Redirecionando para a pagina do artista
	if (strOrigem!="") document.location.href = "http://www.letras.com.br/" + strOrigem;
	else document.formB.submit();
}

function SetBuscaSelecionada(IdSel){	
	var oInput	= document.getElementById("busca");
	var oSel 	= document.getElementById("itmBusca" + IdSel);
	var oLnk 	= document.getElementById("lnkBusca" + IdSel);
	var Artista;
	var codArtista;
	IdAnterior 		= IdSelecionado;
	IdSelecionado 	= IdSel;
	if (Buscas[IdSel-1] == undefined) return false
	Selecionado 	= Buscas[IdSel-1][1];
	oInput.value 	= Buscas[IdSel-1][0].toString().trim();
	oLnk.className 	= "autoHover";
	doScrollBusca(oSel, IdSelecionado);
	if (IdAnterior > 0){
		var oAnt = document.getElementById("lnkBusca" + IdAnterior);
		oAnt.className 	= "autoOut";
	}	
}

function AutoCompletar(o,e){
	var tecla 	= (window.event)?event.keyCode:e.which;
	var Texto	= "";
	var arrTexto	= new Array();
	var IdSelecionado2;

	// Se o texto estiver vazio, basta sair da funcao
	if (o.value == ""){
		unshowAutoCompletar(o);
		return false;
	}

	arrTexto[0] = o.value.toString();
	Texto = arrTexto[arrTexto.length-1];
	Texto = Texto.trim();

	// Verificando se a tecla digitada eh enter
	if (tecla==13){			
		selectBusca(o.id, Selecionado, Texto);
		return false;
	}
	else if (tecla==38 || tecla==40){
		// Nao Selecionado
		if (IdSelecionado<1){
			SetBuscaSelecionada(1);
			return false;
		}
		// Upper Key
		if(tecla==38){IdSelecionado2 = IdSelecionado - 1;}
		// Lower Key
		if(tecla==40){IdSelecionado2 = IdSelecionado + 1;}
		// Selecionando
		if(TotalSelecionados>=IdSelecionado){
			if (IdSelecionado2==0){IdSelecionado2=TotalSelecionados}
			else if(IdSelecionado2>TotalSelecionados){IdSelecionado2=1}
			SetBuscaSelecionada(IdSelecionado2)
		}
	}
	else if(tecla == 8 || (tecla >=48 && tecla <=57) || (tecla >=65 && tecla <=90) || (tecla >=97 && tecla <=122) || (tecla >=128 && tecla <=145) || (tecla >=128 && tecla <=165) || (e.type=="focus")){
		chamaAutoCompletar(o);
	}
	return true;
}

function chamaAutoCompletar(o){
	var v		= o.value
	var v2		= v.replacesBusca();
	var v3		= "";
	var total	= 20;
	var totalMax	= 70;
	var totalAnt 	= 0;
	Buscas.length 	= 0;
	//Buscas 		= new Array();
	if(v2.length>1)v3=v2.substr(0,v2.length-1);
	
	// Desfaz selecao
	IdAnterior 		= 0;
	IdSelecionado 	= 0;
	Selecionado 	= "";
	document.getElementById("lstbusca").scrollTop = 0;
	
	// Verifica primeiramente se a busca anterior retornou registros suficientes para continuar.
	if (LastSearchRows < 70 && v.toString().indexOf(LastSearch) > -1){
		Buscas = cacheBuscas[LastSearch];
		terminaAutoCompletar(o);
		return true;
	}
	
	// Verifica se a busca ja esta em cache
	if (cacheBuscas[v2]!=undefined){
		Buscas = cacheBuscas[v2];
		terminaAutoCompletar(o);
		LastSearch = v2;
		LastSearchRows = Buscas.length;
	}
	else{
		// Limita o maximo de caracteres para buscar via Ajax
		if (v2.length<=4){
			var oAjax	= new Ajax(o, "autocomplete", v2);
			return true;
		}
		else if (v2.length>4){
			v3 = v2.substr(0,4);
			if (cacheBuscas[v3]!=undefined){
				chamaAutoCompletar2(v3);
				terminaAutoCompletar(o);
			}
		}
		else if (v3!=""){
			if (cacheBuscas[v3]!=undefined){
				chamaAutoCompletar2(v3);
				terminaAutoCompletar(o);
			}
		}
	}
}

function chamaAutoCompletar2(v){
	var total	= 20;
	var totalMax	= 70;
	Buscas.length 	= 0;
	//Buscas 		= new Array();
	
	// Verifica se a busca ja esta em cache
	if (cacheBuscas[v]!=undefined){
		Buscas = cacheBuscas[v];
        	LastSearch = v;
		LastSearchRows = Buscas.length;		
	}
	TotalSelecionados = Buscas.length;	
}

function terminaAutoCompletar(o){
	var objSpan;
	var objDiv;
	var IdSelecionado2;
	var oPos;		
	var posTop  	= 0;
	var posLeft 	= 0;
	var posWith 	= 0;
	
	// Descobrindo a posicao do objeto Pai
	oPos		= getPosicaoElemento(o);
	posTop	= oPos.top + o.offsetHeight;
	posLeft	= oPos.left;
	posWith	= o.offsetWidth;

	// Criando a DIV
	objSpan = document.getElementById("lst" + o.id + "");
	
	// Reposicionando a DIV com os resultados
	objSpan.style.left = posLeft + "px";
	objSpan.style.top = posTop + "px";
	objSpan.style.width = posWith + "px";

	// Populando a DIV com as buscas
	if (populaBusca(objSpan, o)){
		objSpan.style.display = "block";
	}
	else {
		var oLst;
		oLst = document.getElementById("lstBuscas");
		if(oLst!=null){
			objSpan.style.display = "none";
			Selecionado = "";
		}
	}	
	return;
}

function showAutoCompletar(o){
	if (TotalSelecionados > 0) {
		document.getElementById("lst" + o.id + "").style.display = "block";
	}
}

function unshowAutoCompletar(o){
	var ret;
	//var t = window.setTimeout()
	if (TotalSelecionados>0){
		document.getElementById("lst" + o.id + "").style.display = "none";
		/*// Desfaz selecao
		IdAnterior 		= 0;
		IdSelecionado 	= 0;
		Selecionado 	= "";
		document.getElementById("lstbusca").scrollTop = 0;*/
	}
	
	return ret;
}

function getPosicaoElemento(elem){
    var offsetTrail = elem;
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
	//Ajuste IE6
	if (navigator.userAgent.indexOf("MSIE 6") > 0){offsetLeft = offsetLeft - 7};
	
    return {left:offsetLeft, top:offsetTop};
}

function getPos(o){
	var bo,x,y,b;
	x=y=0;
	if(o.getBoundingClientRect){
		bo=o.getBoundingClientRect();
		x=bo.left;
		y=bo.top;
		x+=document.documentElement.scrollLeft;
		y+=document.documentElement.scrollTop;
	}
	else{
		while(o&&o.nodeName!="BODY"){
			x+=o.offsetLeft;
			y+=o.offsetTop;
			if(window.opera){x--;y--}
			else{x++;y++}
			b=1;
			if(b>0){
				x+=b;y+=b
			}
			o=o.offsetParent
		}
	}	
	return{x:x,y:y}
}
function doScrollBusca(i,n){
	var oLst = document.getElementById("lstbusca");
	//var t = (oLst.scrollHeight / TotalSelecionados);
	var t = 24; // Altura Fixa
	if (IdSelecionado == TotalSelecionados){
		oLst.scrollTop = oLst.scrollHeight
	}
	else if (n<=6){
		oLst.scrollTop = 0;
	}
	else{
		// Up or Down
		if (IdAnterior < IdSelecionado) oLst.scrollTop += t;
		else oLst.scrollTop -= t;
	}
}
// fim autocomplete.js
// modalfiles/submodal.js
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;
var gHideSelects = false;
var moveableWindow = true;
var gTabIndexes = new Array();
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	
if (!document.all) {
	document.onkeypress = keyDownHandler;
}
function initPopUp() {
	
	theBody = document.getElementsByTagName('BODY')[0];
	popmask = document.createElement('div');
	popmask.id = 'popupMask';
	popcont = document.createElement('div');
	popcont.id = 'popupContainer';
	popcont.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle"></div>' +
				'<div id="popupControls">' +
					'<img src="/site/modalfiles/close.gif" onclick="hidePopWin(false);" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			'<iframe src="/site/modalfiles/loading.html" style="width:100%;height:100%;background-color:transparent;overflow-x:hidden" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
		'</div>';
	theBody.appendChild(popmask);
	theBody.appendChild(popcont);
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			elms[i].onclick = function(){
				var width = 400;
				var height = 200;
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				showPopWin(this.href,width,height,null); return false;
			}
		}
	}
}

addEvent(window, "load", initPopUp);
function showPopWin(url, width, height, returnFunc, showCloseBox) {
	if (showCloseBox == null || showCloseBox == true) {
		document.getElementById("popCloseBox").style.display = "block";
	} else {
		document.getElementById("popCloseBox").style.display = "none";
	}
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	centerPopWin(width, height);
	moveableWindow = false;
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	setMaskSize();
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	gPopFrame.src = url;
	gReturnFunc = returnFunc;
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	window.setTimeout("setPopTitle();", 600);
}
var gi = 0;
var isPagLetra = false;
function centerPopWin(width, height) {
	if (isPagLetra) mueve_cabecera();
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		var theBody = document.getElementsByTagName("BODY")[0];
		//theBody.style.overflow = "hidden";
		if (!document.all)
		{
			yOffSet = window.pageYOffset 
		}
		else
		{
			// internet explorer
			if (typeof(document.body.style.maxHeight) != "undefined")
				yOffSet = document.documentElement.scrollTop // IE7
			else
			yOffSet =  theBody.scrollTop // IE6
		}
		//yOffSet = (!document.all ? window.pageYOffset : 0 )
		var scTop = yOffSet //+ parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		if (document.all)
			gPopupMask.style.top = "0px";
		else
			gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
		//gPopupMask.style.height = windowHeight + "px"
		//alert(scTop)
		setMaskSize();
		var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		if (!moveableWindow) return false;	
		//gPopupContainer.style.top = (scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		
		// codigo novo
		var center = (scTop + ((fullHeight - (height+titleBarHeight)) / 2))
		if (document.all)
		{
			if (center < scTop) center = scTop
			gPopupContainer.style.top = center + "px";
		}
		else
		{		
			if (center < document.documentElement.scrollTop) center = document.documentElement.scrollTop
			gPopupContainer.style.top = center + "px";
		}
		// fim codigo novo


		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
	}
}
addEvent(window, "resize", centerPopWin);
window.onscroll = centerPopWin;
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = popWidth + "px";
}
function hidePopWin(callReturnFunc) {
	gPopupIsShown = false;
	moveableWindow = true;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popupFrame"].returnVal);
	}
	gPopFrame.src = '/site/modalfiles/loading.html';
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
	
}
function setPopTitle() {
	return;
	if (window.frames["popupFrame"].document.title == null) {
		window.setTimeout("setPopTitle();", 10);
	} else {
		document.getElementById("popupTitle").innerHTML = window.frames["popupFrame"].document.title;
	}
}
function chkSelo(){
	callAjax("selo", "SELO");
}
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}
function restoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}
// fim modalfiles/subModal.js