var url = self.location.href.replace(/\\/, "/").split("/");
var pg = url[url.length-1];
var pgatual = parseInt(pg.replace(".htm", ""), 10);
var idioma = url[url.length-2];

var appVer = navigator.appVersion.toLowerCase();
var iePos  = appVer.indexOf('msie');
var ieVer = 0;
var podefscommand = "nao";
var iebug = 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(isNaN(pgatual)) pgatual = 0;

if(podefscommand) document.write('<scr' + 'ipt for="menu_flash" event="FSCommand(funcao)">eval(funcao);</sc' + 'ript>');

function $(id){
	return document.all? document.all[id] : document.getElementById(id);
}

var tags = { "select":iebug, "applet":true };
var apagou = [];


function vai(x){
	temppg = pgatual + x;
	
	if(temppg<=0 || temppg > pgtotal[pasta]) location = "../ra/index.htm";
	else location = z(temppg) + ".htm";
}

function z(numero){
	return numero<10? ("0"+numero) : numero;
}

function abreMenu(){
	try {
		document.getElementById("div_menu_interna").style.clip = "rect(0 250px 615px 0px)";
		for(tag in tags){
			if(tags[tag]){
				items = document.getElementsByTagName(tag);
				for(x = 0; x < items.length; x++){
					if(items[x].style.visibility==""){
						apagou[tag+"-"+x] = true;
						items[x].style.visibility = "hidden";
					}
				}
			}
		}
	}
	catch(e){}
}

function fechaMenu(){
	try {
		document.getElementById("div_menu_interna").style.clip = "rect(0 58px 615px 0px)";
		for(tag in tags){
			if(tags[tag]){
				items = document.getElementsByTagName(tag);
				for(x = 0; x < items.length; x++){
					if(apagou[tag+"-"+x]) items[x].style.visibility = "";
				}
			}
		}
	}
	catch(e){}
}

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;
  }
}


if(ferramenta!="sim"){
	addEvent(window, "load", function(){ ConfiguraGRI(); enableTooltips(); }, false);
}

function form(campo){
	if(window.navigator.appName.toLowerCase().indexOf("microsoft") > -1){
		return document.formulario.item(campo);
	}
	else {
		return document.formulario[campo];
	}
}

function abrir(url){
	window.open(url, "_blank");
}

function janela(url, w, h){
	try {
		jan = open(url, "", "width=" + w + ",height=" + h + ",left=" + ((screen.availWidth-w)/2) + ",top=" + ((screen.availHeight-h)/2));
		jan.focus();
	}
	catch(e){
		alert(idioma=="port"? "Por favor desabilite seu anti-popup." : "Please disable your anti-popup.");
	}
}

String.prototype.trim = function() { 
	return this.replace(/^\s+|\s+$/, ''); 
};

function flash(movie, flashvars, width, height, retorna){
	swfid = movie.split("/");
	swfid = swfid[swfid.length-1].replace(".swf", "");
	strSWF= '<object id="' + swfid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,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];
}

function ValorRadio(radio){
	tempValorRadio = false;
	for(VR_x = 0; VR_x < radio.length; VR_x++){
		if(radio[VR_x].checked){ tempValorRadio = radio[VR_x].value; break; }
	}
	return tempValorRadio;
}

function checarTodos(checkbox, checkboxes){
	for(ct_x = 0; ct_x < checkboxes.length; ct_x++){
		checkboxes[ct_x].checked = checkbox.checked;
	}
}

function pdf(){
	window.open("download/PDFs/RA_" + z(pgatual) + ".pdf");
}

function recomende(){
	if(idioma=="port") txt = "Relatório Anual 2008&Body=Veja esta página interessante";
	else txt = "Annual Report 2008&Body=See this interessant page";
	open("mailto:?Subject=Iochpe-Maxion - " + txt + ": " + escape("\n\n" + document.title + "\n" + self.location.href));
}


function FechaFoto(){
	$("div_fotos").style.display = "none";	
}

function AbreFoto(){
	h = document.documentElement.clientHeight;
	w = document.documentElement.clientWidth;

	$("div_fotos").style.width = w + "px";
	$("div_fotos").style.height = h + "px";
	$("div_fotos").innerHTML = flash("../imagens/fotos.swf", "foto=../../imagens/gg_" + z(pgatual) + ".jpg", w, h, true);
	$("div_fotos").style.display = "block";
}


/*/////////////////////////////////////// */
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";	
}

function MostraFerramenta(){
	document.body.scroll="no";
	$("iframe_ferramenta").style.top = document.documentElement.scrollTop + (((document.documentElement.clientHeight - 600) / 2) + 62) + "px";
	$("iframe_ferramenta").style.left = (((document.documentElement.clientWidth - 700) / 2) + 35) + "px";
	$("iframe_ferramenta").style.display = "block";
}

function ApagaFerramenta(){
	document.body.style.overflow = "auto";
	$("iframe_ferramenta").style.display = "none";
	$("iframe_ferramenta").src = "about:blank";
	setTimeout(function()
	{
		$("div_fundao").innerHTML = "";
		$("div_fundao").style.display = "block";
	}, 300);
}

function entrar(){
	$("div_capa").style.display = "none";
	$("div_menu_interna").style.display = "block";
	$("div_enquadra").style.display = "block";
	$("div_interna").style.display = "block";
	$("div_rodape").style.display = "block";
}

/* ########## MENU LATERAL #### */

var tempoMenu;
var yMenu = 0; 

function moveMenu(){
	tempoMenu = setInterval("posicionaMenu()", 10);
}

function paraMenu(){
	if(tempoMenu) clearInterval(tempoMenu);
}

var doc = document.documentElement;
var body = document.body;

function posicionaMenu(){
	try {
		t = (window.pageYOffset? window.pageYOffset : ((doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0)));
		h = Math.ceil(yMenu + ((t - yMenu) / 8));
		h = h<0? 0 : h;
		yMenu = h;
		$("div_menu_interna").style.top = yMenu + "px";
	}
	catch(e){ alert(e.description) }		
}

if(pgatual > 0){
	
	addEvent(window, "load", function(){
	
		try {
			moveMenu();
		}
		catch(e){}
		
	}, false);
}