/////////////////*PG ATUAL*////////////////////////////////////

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 ffPos  = navigator.userAgent.toLowerCase().indexOf('firefox');
var ieVer = 0;
var podefscommand = "nao";
var iebug = false;
var ffbug = false;
var isIE = false;

if (iePos !=-1) {
	isIE = true;
	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 toposwf = pgatual==0? pg.replace(".htm", "").replace(".asp", "").split("?")[0] : z(pgatual);

var pgtotal = [];
	pgtotal["port"] = 22;
	pgtotal["eng"] = 22;

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[idioma]) location = "index.htm";
	else location = z(temppg) + ".htm";
}

function z(numero){
	return numero<10? ("0"+numero) : numero;
}

var tempo;


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;
  }
}

var docTips;

addEvent(window, "load", function(){

  if(idioma!="cases"){
	  try {
		docTips = new TipObj('docTips');
		with (docTips){
		 doFades = false;
		 showDelay = 0;
		 hideDelay = 0;
		 tipStick = 0.2;
		 template = '<table bgcolor="#ffffff" cellpadding="1" cellspacing="0" width="%2%" border="0">' +
		  '<tr><td><table bgcolor="#5ab74c" cellpadding="5" cellspacing="0" width="100%" border="0">' +
		  '<tr><td style="color:#ffffff">%3%</td></tr></table></td></tr></table>';
		}
	  }
	  catch(e){}
  }

}, false);


function mostraGRI(indicador){
	indicador = indicador.replace(" ", "");
	docTips.newTip("indic" + indicador, 20, -10, 350, GRI[indicador][0].bold() + "<br>" + GRI[indicador][1]);
}

function apagaGRI(){
	docTips.hide();
}

function vaiGRI(indicador){
	location = "19.htm#" + indicador.toUpperCase().replace(".", "_").replace("GRI ", "");
}


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.");
	}
}

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=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];
}

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/Bunge_" + z(pgatual) + ".pdf");
}

function download(){
	if(idioma=="ferramentas") window.print();
	else window.open("../download/PDFs/" + idioma.toUpperCase() + "_" + z(pgatual) + ".pdf");
}

function imprimir(){
	if(idioma=="ferramentas") window.print();
	else $("div_imprimir").style.display = "block";
}

function imprimir_fechar(){
	$("div_imprimir").style.display = "none";
}

function imprimir_texto(){
	imprimir_fechar();
	setTimeout(function(){ window.print(); }, 100);
}

function imprimir_capitulo(){
	imprimir_fechar();
	setTimeout(download, 100);
}

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=VCP - " + txt + ": " + escape("\n\n" + document.title + "\n" + self.location.href));
}

function trim(str){ 
	return str.replace(/^\s+|\s+$/g,""); 
}

tit = document.title.split(String.fromCharCode(187));
try { titulo = trim(tit[2]).replace("&", "%26"); }
catch(e){}

function cases(qualid){
	w = screen.availWidth-10;
	h = screen.availHeight-50;
	jan = open("cases/index.htm?" + qualid, "", "width=" + w + ",height=" + h + ",left=0,top=2,resize=true");
	jan.focus();	
}

function MostraConteudo(){
	$("capa").innerHTML = "";
	$("capa").style.display = "none";
	$("site").style.display = "block";
}



/* ########## MENU LATERAL #### */

var tempoMenu;
var yMenu = 10; 

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 = t - ($("lateral").offsetHeight + 400);
		h = Math.ceil(yMenu + ((h + 10 - yMenu) / 8));
		h = h<10? 10 : h;
		yMenu = h;
		$("div_menu_lateral").style.top = yMenu + "px";
	}
	catch(e){}		
}

if(pgatual > 0){
	
	addEvent(window, "load", function(){
	
		try {
			moveMenu();
		}
		catch(e){}
		
	}, false);
}