function swiDetail(id) {
	if (document.getElementById(id+'mais').style.display == 'block') {
		document.getElementById(id+'mais').style.display = 'none';
		document.getElementById(id+'menos').style.display = 'block';
	} else {
		document.getElementById(id+'mais').style.display = 'block';
		document.getElementById(id+'menos').style.display = 'none';
	}
	sRedimension('conteudo');
}

function mostra(id) {
	if (document.getElementById(id).style.display == 'table') {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'table';
	}
	sRedimension('conteudo');
}

function toLvl(level) {
	return Math.floor(((50/3)*Math.pow(level,3))-(100*Math.pow(level,2))+((850/3)*level)-200);
}

function myLevel(ex) {
	var level = 1;
	while (true) {
		if (ex >= toLvl(level) && ex < toLvl(level + 1)) {
			return level;
		}
		level = level + 1;
	}
}

function number_format(num,decs,mils) {
	var n = '', v = 0,tp = 0;
	var text = new String(num);
	var nump = Math.ceil(text.length / 3) - 1;
	for (var i = 0;i < text.length;i++) {
		n = text.substr(text.length - i - 1,1) + n;
		v++;
		if (v == 3 && tp < nump) {
			n = mils+n;
			v = 0;
			tp++;
		}
	}
	return n;
}

function calcLevel(param,div) {
	param = param.split('\\_');
	var ex = parseInt(param[0]);
	var d = parseInt(param[1]);
	if ((!ex && ex !== 0) || !d) {
		res = "Erm... Tem certeza que isso é um número?";
		document.getElementById(div).innerHTML = res;
		return false;
	}
	var a = myLevel(ex);
	var res = '';
	var res2 = '';
	if (d < a) {
		res = "Grr! Se você quiser regredir, é mais fácil se matar...";
	} else if (d == a) {
		res = "Você já está no level "+d+", erm.";
	} else if (d == 666) {
		res = "Eu hein! Vai fazer pacto em outro lugar!";
	} else if (d == 999) {
		res = "Quem você ta pensando que é? Chuck Norris?";
	} else if (a < 1 || d < 1) {
		res = "Ops, você não pode \"avançar\" pra um level menor que 1!";
	} else {
		res = toLvl(d) - ex;
		res = number_format(res,',','.');
		res2 = toLvl(d);
		res2 = number_format(res2,',','.');
		res = "Falta "+res+" de exp para o level "+d+" ("+res2+").";
	}
	document.getElementById(div).innerHTML = res;
}

function redimension(fraId){
	if(document.getElementById){
		if(!document.all){
			parent.document.getElementById(fraId).style.height = 0;
		}	
		parent.document.getElementById(fraId).style.height = document.body.scrollHeight;
	}
	else{
		parent.document.all(fraId).height = document.body.scrollHeight;
	}
	parent.unSetLoad();
}

function sRedimension(fraId){
	if(document.getElementById){
		if(!document.all){
			parent.document.getElementById(fraId).style.height = 0;
		}	
		parent.document.getElementById(fraId).style.height = document.body.scrollHeight;
	}else{
		parent.document.all(fraId).height = document.body.scrollHeight;
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function bookm () {
	xajax_waypoint_init();
}

function startReverse() {
	var buff,side;
	side = readCookie('lado');
	if (side == 1) {
		document.getElementById('coluna_esquerda').className = 'coluna_direita';
		document.getElementById('coluna_direita').className = 'coluna_esquerda';
	} else {
		document.getElementById('coluna_esquerda').className = 'coluna_esquerda';
		document.getElementById('coluna_direita').className = 'coluna_direita';
	}
	createCookie('lado',side,'365');
}

function inverter() {
	var buff;
	buff = document.getElementById('coluna_esquerda').className;
	if (buff == 'coluna_esquerda') {
		createCookie('lado',1,'365');
	} else {
		createCookie('lado',0,'365');
	}
	document.getElementById('coluna_esquerda').className = document.getElementById('coluna_direita').className;
	document.getElementById('coluna_direita').className = buff;
}

function setMiniLoad(div,word) {
	if (word == undefined) {
		word = "Carregando";
	}
	document.getElementById(div).innerHTML = '<center><h1><img src="/img/lay/miniload.gif" border="0" /> '+word+'...</h1></center>';
}

function abreMapa() {
	window.open("maps.php?w=748&h=480", "JANELA", "height = 520, width = 768, scrollbars = no, status = no, titlebar = no,location = yes");
}

function recarrega() {
	var sURL = unescape(window.location.pathname);
	window.location.href = sURL;
	window.location.reload( false );
}

function lowLight(id) {
	//document.getElementById(id).style.display = 'block';
}

function highLight(id) {
	//document.getElementById(id).style.display = 'none';
}

function carregando() {
	var carDiv = document.getElementById('carregar')
	window.scroll(0,0);
	carDiv.style.display = "block";
	setMiniLoad('online');
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}