﻿if(document.all) document.onkeydown = onKeyPress;
else if (document.layers || document.getElementById) document.onkeypress = onKeyPress;

function onKeyPress(evt) {
	var oEvent = (window.event) ? window.event : evt;

	var nKeyCode = oEvent.keyCode ? oEvent.keyCode :
	oEvent.which ? oEvent.which : 
	void 0;
	
	if(oEvent.charCode == null || oEvent.charCode == 0){ 
		if(nKeyCode==37) vai(-1);
		if(nKeyCode==39) vai(+1);
	}
	
	return true;
}

function $(objeto){
	return document.all? document.all[objeto] : document.getElementById(objeto);
}

var url = self.location.href.replace(/\\/, "/").split("/");
var pgatual = parseInt(url[url.length-1].replace(".htm", ""), 10);
var pasta = url[url.length-2];
var idioma = url[url.length-3];

var ferramenta = pasta=="ferramentas"? "&ferramenta=sim" : "";

function z(qual){
	return qual < 10? ("0" + qual) : qual;
}

var paginas = [];
	paginas["ra"] = 29;
	paginas["df"] = 30;	

var titulo = document.title.replace("&", "%26").replace("Eternit - Relatório Anual 2007 - ", "").replace("Eternit - Annual Report 2007 - ", "");
if(!isNaN(pgatual)) titulo = pgatual + ". " + titulo;
else {
	pgatual = 0;
	pasta = "ra";
}

pgtotal = paginas[pasta];

function vai(x){
	pgatual += x;
	if(pgatual==0) location = "../" + pasta + "/" + z(pgtotal) + ".htm";
	else if(pgatual > pgtotal) location = "../" + pasta + "/01.htm";
	else location = "../" + pasta + "/" + z(pgatual) + ".htm";
}

var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ieVer = 0;
var podefscommand = false;

if (iePos !=-1) {
	ieVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
	if(ieVer > 5.5) podefscommand = true;
}

function topo(){
    AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','780','height','500','src','../imagens/topo_interna','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','movie','../imagens/topo_interna', 'FlashVars', 'img=' + pasta + '_' + z(pgatual) + '&pasta=' + pasta + '&pgatual=' + z(pgatual) + '&pgtotal=' + pgtotal + '&titulo=' + titulo + ferramenta + (podefscommand? "&podefscommand=sim" : ""));
}

var apagar;

function acende(){
	if(apagar) clearTimeout(apagar);
	$("div_topo").style.zIndex = 1000;
}

function apaga(){
	apagar = setTimeout(function(){ $("div_topo").style.zIndex = 2; }, 1000);
}

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;
	}
}

function ajusta(){
	$("div_tudo").style.height = Math.max(window.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight), ($("div_conteudo").offsetHeight + 315)) + "px";
}

var docTips;

addEvent(window, "load", function(){
	ajusta();
	docTips = new TipObj('docTips');
	with (docTips){
	 doFades = false;
	 showDelay = 0;
	 hideDelay = 0;
	 tipStick = 0.2;
	 template = '<div style="border: solid 1px #ec1c24; background-color: #fafafa; width: %2%px; padding: 10px; filter: progid:DXImageTransform.Microsoft.Shadow(Color=#000000,Direction=135,Strength=2);">%3%</div>';
	}
}, false);


function pdf(){
	window.open("../download/Eternit_" + pasta.toUpperCase() + "_" + z(pgatual) + ".pdf", "_blank");
}

function imprimir(){
	window.print();
}

function recomende(){
	if(idioma=="port"){
		open("mailto:?Subject=" + escape("Eternit - Relatório Anual On-line 2007") + "&Body=" + escape("Veja esta página interessante: \n\n" + document.title + ":\n") + self.location.href);
	}
	else {
		open("mailto:?Subject=" + escape("Eternit - Annual Report 2007") + "&Body=" + escape("See this interessant page: \n\n" + document.title + ":\n") + self.location.href);
	}
}

function mostraGRI(indicador){
	docTips.newTip("indic" + indicador.replace(".", "_"), 10, -30, 300, "<b>" + GRI[indicador][0] + "</b><br>" + GRI[indicador][1]);
}

function apagaGRI(){
	docTips.hide();
}
