// JavaScript Document

function balao( cmd ){
	
	obj = document.getElementById('balao');
	if(cmd == 'show'){
		if(document.all){
			obj.style.top = (event.clientY + 5);
			obj.style.left = (event.clientX - 30);
		}else{
			obj.style.top = document.images['bt_balao'].y + 15;
			obj.style.left = document.images['bt_balao'].x - 30;
		}
		obj.style.visibility = 'visible';
	}else{
		if(cmd == 'hide'){
			i = setInterval(hide,1000);
		}else{
			clearInterval(i);
			obj.style.visibility = 'visible';
		}
	}
	
}

function hide(){
	obj = document.getElementById('balao');
	obj.style.visibility = 'hidden';	
}

function del_star(msg){

	if(confirm(msg)){
		GravaCookie('');
		document.location.reload();
	}
	

}

function star( id ){

	obj = document.getElementById('star'+id);
	
	if( ! FindStarred(id) ){
		AddStar(id);
		obj.src = 'images/starred.gif';
	}else{
		DelStar(id);
		obj.src = 'images/star.gif';
	}

	return;

}
function FindStarred( id ){

	stars = GetCookie('star');

	if( stars.indexOf('\''+id+'\'') != -1 ){
		return true;
	}else{
		return false;
	}

}
function AddStar( id ){

	stars = GetCookie('star');
	GravaCookie( stars + '\'' + id + '\',' );

}
function DelStar( id ){

	stars = GetCookie('star');
	stars = stars.replace('\''+id+'\',','');
	GravaCookie( stars );

}

var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // valido por um ano
function GravaCookie( id ) { 
	document.cookie = "star=" + id + "; expires=" + expdate.toGMTString();
}
function FixCookieDate (date) {
	var base = new Date(0);
	var skew = base.getTime(); // dawn of (Unix) time - should be 0
	if (skew > 0)  // Except on the Mac - ahead of its time
		 date.setTime (date.getTime() - skew);
}
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	 var j = i + alen;
	 if (document.cookie.substring(i, j) == arg)
	   return getCookieVal (j);
	 i = document.cookie.indexOf(" ", i) + 1;
	 if (i == 0) break; 
	}
	return '';
}
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	 endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}