var url = self.location.href.replace(/\\/, "/").split("/");
var pg = parseInt(url[url.length-1].replace(".htm", ""), 10);
var pasta = url[url.length-2];
var pdf_file = self.location.href.replace(pasta + "/", "download/PDFs/" + pasta.toUpperCase() + "_").replace("htm", "pdf");

var titulo = document.title.split("::")[2];

var sequencia = [];
sequencia.push(["pasta", "pagina"]);
sequencia.push(["ra", 1]);
sequencia.push(["ra", 2]);
sequencia.push(["ra", 3]);
sequencia.push(["ra", 4]);
sequencia.push(["ra", 5]);
sequencia.push(["ra", 6]);
sequencia.push(["ra", 7]);
sequencia.push(["ra", 8]);
sequencia.push(["ra", 9]);
sequencia.push(["ra", 10]);
sequencia.push(["ra", 11]);
sequencia.push(["ra", 12]);

sequencia.push(["mda", 1]);
sequencia.push(["mda", 2]);
sequencia.push(["mda", 3]);
sequencia.push(["mda", 4]);
sequencia.push(["mda", 5]);

sequencia.push(["df", 1]);
sequencia.push(["df", 2]);
sequencia.push(["df", 3]);
sequencia.push(["df", 4]);
sequencia.push(["df", 5]);

sequencia.push(["ra", 13]);


var pgatual = "";

for(x = 1; x < sequencia.length; x++){
	if(sequencia[x][0]==pasta && sequencia[x][1]==pg){
		pgatual = x;
		break;
	}
}


function z(n){
	return n<10?("0"+n):n;
}

function $(oque){
	return document.all? document.all[oque] : document.getElementById(oque);
}

function vai(oque){
	
	pgatual += oque;

	if(pgatual<=0 || pgatual>=sequencia.length) location = "index.htm";
	else location = "../" + sequencia[pgatual][0] + "/" + z(sequencia[pgatual][1]) + ".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;
	}
}

var tags = ["select"];

function abremenu(){
	document.getElementById("div_menu").style.clip = "rect(0 615px 20000px 0)";
	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";
				}
			}
		}
	}
}

function fechamenu(){
	document.getElementById("div_menu").style.clip = "rect(0 250px 20000px 0)";
	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 = "";
			}
		}
	}
}


function flash(movie, flashvars, width, height){
	return '<object 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 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>';
}


function pdf_download(){
	if(pasta=="ferramentas") location = "../ferramentas/download.htm";
	else window.open(pdf_file, "_blank");
}

function pdf_email(){
	if(pasta=="ferramentas" || isNaN(pg)){
		alert("This page cannot be sent.");
	}
	else {
		window.open("mailto:?Subject=" + document.title + "&Body=See this document:" + escape("\n\n") + pdf_file);
	}
}

var d = document.createElement("div");

function busca(txt){
	location = "../ferramentas/busca.htm?" + txt;
}

function pdf_fecha(){
	document.body.removeChild(d);
}

function pdf_criar(){
	w = document.body.offsetWidth;
	h = document.body.offsetHeight;
	d.style.position = "absolute";
	d.style.top = "0px";
	d.style.left = "0px";
	d.style.width = w + "px";
	d.style.height = h + "px";
	d.style.zIndex = 10000;
	d.innerHTML = '<div style="position:absolute; left: 0; top: 0;">' + flash("../includes/transparencia.swf", "", w, h) + '</div>' +
				  '<iframe src="../ferramentas/pdf.htm" width="708" marginwidth="0" height="500" marginheight="0" scrolling="no" frameborder="0" style="position:absolute; left: ' + ((w-708) / 2) + 'px; top: 100px;"></iframe>';

	document.body.appendChild(d);
}