var url = self.location.href.replace(/\\/, "/").split("/");
var pg = url[url.length-1];
var pgatual = parseInt(pg.replace(".htm", "").replace(".asp", ""), 10);
var pasta = url[url.length-2];
var idioma = url[url.length-3];
var capitulo = "";
var pagina = "";
var cor = "";
var swf = "";

if(isNaN(pgatual)) pgatual = 0;


var cores = ["EE3124", "2575AD", "EC1C24", "2BA9DB", "C5161D", "005AA3", "E76E25", "FCB813"];

if(pasta=="ferramentas") pasta = "ra";

if(pasta=="ra"){
	pgtotal = 59;
	if(pgatual >= 1  && pgatual <= 2)  cor = cores[0];
	if(pgatual >= 3  && pgatual <= 5)  cor = cores[1];
	if(pgatual >= 6  && pgatual <= 11)  cor = cores[2];
	if(pgatual >= 12  && pgatual <= 16) cor = cores[3];
	if(pgatual >= 17 && pgatual <= 24) cor = cores[4];
	if(pgatual >= 25 && pgatual <= 30) cor = cores[5];
	if(pgatual >= 31 && pgatual <= 36) cor = cores[6];
	if(pgatual >= 37 && pgatual <= 46) cor = cores[7];
	if(pgatual >= 47 && pgatual <= 59) cor = cores[5];
		
	swf = (pgatual % 10);
	if(swf==0) swf = 10;
	swf = "foto_" + z(swf) + ".swf";
}

if(pasta=="df"){
	pgtotal = 51;
}

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 trim(str){ 
	return str.replace(/^\s+|\s+$/g,""); 
}

function z(numero){
	return numero<10? ("0"+numero) : numero;
}

var docTips;

addEvent(window, "load", function(){
								  
	docTips = new TipObj('docTips');
	with (docTips){
	 doFades = false;
	 showDelay = 0;
	 hideDelay = 0;
	 tipStick = 0.2;
	 template = '<table bgcolor="#858585" cellpadding="1" cellspacing="0" width="%2%" border="0">' +
	  '<tr><td><table bgcolor="#858585" cellpadding="5" cellspacing="0" width="100%" border="0">' +
	  '<tr><td style="color:#ffffff">%3%</td></tr></table></td></tr></table>';
	}
	
	setTimeout(function(){
		for(x=0; x<document.images.length; x++){
			document.images[x].src = document.images[x].src;
		}
	}, 3000);
	
}, false);

function mostraGRI(indicador){
	try {
		docTips.newTip("indic" + indicador.replace(".", "_"), 20, -10, 350, GRI[indicador][1]);
	}
	catch(e){ 
		setTimeout(function(){ mostraGRI(indicador); }, 50); 
	}
}

function apagaGRI(){
	try { docTips.hide(); }
	catch(e){}
}

function vaiGRI(indicador){
	location = "55.htm#" + indicador.replace(".", "_");
}

function pdf(){
	alert("Ferramenta não disponível ainda.");
}

function recomende(){
	location = "../ferramentas/recomende.htm";
}

function planilhas(){
	open("../downloads/CPFL_Planilhas_2008.xls");
}

var tempo;

function abremenu(){
	if(tempo) clearTimeout(tempo);
	document.getElementById("div_menu").style.clip = "rect(0 800px 400px 0)";
}

function fechamenu(){
	if(tempo) clearTimeout(tempo);
	tempo = setTimeout(function(){ document.getElementById("div_menu").style.clip = "rect(0 250px 31px 0)"; }, 1000);
}

sep = String.fromCharCode(187);
titulo = document.title.split(sep);

if(titulo.length > 2) capitulo = trim(titulo[2]);
if(titulo.length > 3) pagina = trim(titulo[3]);
if(titulo.length > 4) pagina += " " + sep + " " + trim(titulo[4]);
