var url = self.location.href.replace(/\\/, "/").split("/");
var pg = url[url.length-1];
var pgatual = parseInt(pg.replace(".htm", ""), 10);
var pasta = url[url.length-2];
var idioma = url[url.length-3];
var comparar = "nao";
var idioma = "port";

var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ffPos  = navigator.userAgent.toLowerCase().indexOf('firefox');
var ieVer = 0;
var podefscommand = "nao";
var iebug = false;
var ffbug = false;

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer < 7) iebug = true;
	if(ieVer > 5.5) podefscommand = "sim";
}

if(podefscommand=="sim") document.write('<scr' + 'ipt for="menu" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');


function pagina(pasta, pg){
	location = "../" + pasta + "/" + z(pg) + ".htm";
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
}


/*////////  FECHA MENU   //////////// */

var tempo;

tempo = setTimeout(fechamenu, 100);

function abremenu(){
	if(tempo) clearTimeout(tempo);
	document.getElementById("menu").style.clip = "rect(0 1000px 715px 0)";
}

function fechamenu(){
	tempo = setTimeout(fechamenuAgora, 100);
}

function fechamenuAgora(){
	try { document.getElementById("menu").style.clip = "rect(0 1000px 90px 0)"; }
	catch(e){}
}

function construcao(){
	alert("Em Breve")
	//window.open("download/PDFs/" + (pasta) + "_" + z(pgatual) + ".pdf");
}


function trocaidioma(idioma){
	if(idioma=="" || idioma=="port")
	{
		location = "../../ra/index.htm";
	}
	else
	{
		location = "../../" + idioma + "/ra/index.htm";
	}
}


/*////////  PAGINAÇÃO   //////////// */

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer < 7) iebug = true;
	if(ieVer > 5.5) podefscommand = "sim";
}

if (ffPos !=-1) {
	ffbug = true;
}

if(isNaN(pgatual)) pgatual = 0;

var pgtotal = [];
	pgtotal["ra"] = 47;
	pgtotal["df"] = 41;
	

var paginacao;

if(pasta=="ferramentas") paginacao = "";
else paginacao = z(pgatual) + " | " + z(pgtotal[pasta]);

if(podefscommand) document.write('<scr' + 'ipt for="menu_flash" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');
var tags = { "select":iebug, "applet":true };
var apagou = [];

function vai(x){
	temppg = pgatual + x;
	
	if(temppg<=0 || temppg > pgtotal[idioma]) location = "index.htm";
	else location = z(temppg) + ".htm";

}

function z(numero){
	return numero<10? ("0"+numero) : numero;
}


/*////////  FLASH   //////////// */

function flash(movie, flashvars, width, height, retorna){
	swfid = movie.split("/");
	swfid = swfid[swfid.length-1].replace(".swf", "");
	flashvars += "&podefscommand=" + podefscommand;
	strSWF= '<object id="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">'+
			'<param name="movie" value="' + movie + '">'+
			'<param name="quality" value="high">'+
			'<param name="wmode" value="transparent">'+
			'<param name="FlashVars" value="' + flashvars + '">'+
			'<embed name="' + swfid + '" src="' + movie + '" width="' + width + '" height="' + height + '" flashvars="' + flashvars + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'+
			'</object>';
	if(!retorna) this.document.write(strSWF);
	else return(strSWF);
}

function TheFlash(moviename) {
    if(document.all) return document.all[moviename];
	else return document.embeds[moviename];
}


/*////////  FERRAMENTAS   //////////// */

function $(id){
	return document.all? document.all[id] : document.getElementById(id);
}

function ferramentas(qual, titulo){
	$("iframe_ferramenta").src = "../ferramentas/" + qual;
	$("div_fundao").innerHTML = flash("../imagens/ferramentas.swf", "titulo=" + titulo, document.documentElement.clientWidth, document.documentElement.clientHeight, true);
	$("div_fundao").style.top = document.documentElement.scrollTop + "px";
	$("div_fundao").style.display = "block";	
	$("div_fundao").style.visibility = "";
}

function MostraFerramenta(){
	$("iframe_ferramenta").style.top = document.documentElement.scrollTop + (((document.documentElement.clientHeight - 600) / 2) + 62) + "px";
	$("iframe_ferramenta").style.left = (((document.documentElement.clientWidth - 630) / 2)) + "px";
	$("iframe_ferramenta").style.display = "block";
}

function ApagaFerramenta(){
	$("iframe_ferramenta").style.display = "none";
	setTimeout(function()
	{
		$("div_fundao").style.display = "block";
		$("div_fundao").style.visibility = "hidden";
		$("div_fundao").innerHTML = "";
	}, 300);
}

function AbreHistorico(idioma)
{
	// Cria Objetos
	var url;
	var W = 767;
	var H = 620;

	// Checa URL
	switch(idioma.toLowerCase())
	{
		case 'en-us': url = 'http://quotes.enfoque.com.br/itauri/cot_hist/cotacaohistorica.aspx?versao=ingles'; break;
		case 'es-es': url = 'http://quotes.enfoque.com.br/itauri/cot_hist/cotacaohistorica.aspx?versao=espanhol'; break;
		default: url = 'http://quotes.enfoque.com.br/itauri/cot_hist/cotacaohistorica.aspx'; break;
	}

	window.open(url, '_blank', 'left=0,top=0,resizable=no,scrollbars=yes,width=' + W + ',height=' + H + ',menubar=no');
}




function AbreAnalise(idioma)
{
	// Cria Objetos
	var url;
	var W = 806;
	var H = 530;

	// Checa URL
	switch(idioma.toLowerCase())
	{
		case 'en-us': url = 'http://quotes2.enfoque.com.br/itauri/flash/holding/en/index.asp'; break;
		case 'es-es': url = 'http://quotes2.enfoque.com.br/itauri/flash/holding/es/index.asp'; break;
		default: url = 'http://quotes2.enfoque.com.br/itauri/flash/holding/pt/index.asp'; break;
	}

	window.open(url, '_blank', 'top=0,left=0,resizable=no,scrollbars=no,width=' + W + ',height=' + H + ',menubar=no');
}


