var ua   = navigator.userAgent.toLowerCase();
var divw = 0;
var divh = 0;

if (document.getElementById || document.all){
	document.write('<div id="imgtrailer" class="TableToolTipMaster" style="z-index: 999; position:absolute; width: 180px; background-color: #ff9933; layer-background-color: #ff9933; border: 1px solid #ff5c00; padding: 5px;"></div>');
}

function gettrailobject(){
	if (document.getElementById){
		return document.getElementById("imgtrailer");
	}else if (document.all){
		return document.all.trailimagid;
	}
}

function gettrailobj(){
	if (document.getElementById){
		return document.getElementById("imgtrailer").style;
	}else if (document.all){
		return document.all.trailimagid.style;
	}
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function trailOff(){
	document.onmousemove     = '';
	gettrailobj().visibility = "hidden";
}

function trailOn(thumbimg,imgtitle,username,imgid,imgsize,credit,level,thw,thh){
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1){
		gettrailobj().left="-500px";
		divthw = parseInt(thw) + 2;
		gettrailobject().innerHTML = '<div style="background-color: #ff5c00; layer-background-color: #ff5c00; border: 1px solid #808080; padding:10px; width:'+divthw+'px;"><div style="background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px solid #808080;background-image: url(img/lloading.gif);"><img src="'+thumbimg+'" border="0" width="'+thw+'" height="'+thh+'"><div style="padding:3px">'+imgtitle+'&copy; '+username+' Geoprocessamento<br>&nbsp;&nbsp;&nbsp;&nbsp;Goodcard.com.br<br></div></div><!--- <div class=h2 style="padding:1px;"> '+level+'<br>'+imgsize+'</div> ---></div>';
		gettrailobj().visibility="visible";
		divw = parseInt(thw);
		divh = parseInt(thh)+130;
		document.onmousemove=followmouse;
	}
}

function ValidaAltura(STRING){
	MaxLength  = 0;
	MaxText    = '';
	CurrLength = 0;
	CurrText   = 0;
	Message    = STRING;
	ExitWhile  = false;
	StartChar  = 0;
	if(Message.indexOf('<br>') != -1){
		EndChar = Message.indexOf('<br>');
	}else{
		EndChar = Message.length;
	}
	TotalChar  = Message.length;
	BreakCount = 0;
	while(ExitWhile == false){
		CurrText   = Message.substring(StartChar, EndChar);
		CurrLength = CurrText.length;
		if(CurrLength > MaxLength){
			MaxLength = CurrLength;
			MaxText   = CurrText;
		}
		StartChar  = EndChar + 4;
		TestChar   = (Message.substring(StartChar, TotalChar)).indexOf('<br>');
		if(TestChar == -1){
			if(StartChar < TotalChar){
				CurrText   = Message.substring(StartChar, TotalChar);
				CurrLength = CurrText.length;
				if(CurrLength > MaxLength){
					MaxLength = CurrLength;
					MaxText   = CurrText;
				}
			}
			ExitWhile = true;
		}
		EndChar = StartChar + TestChar;
	}
	TotalSpaces = 0;
	for(i = 0; i < MaxText.length; i++){
		ord = STRING.substring(i,i+1).charCodeAt(0);
		if(ord == 32){
			TotalSpaces++;
		}
	}
	return TotalSpaces * 10;
}

function ValidaLargura(STRING){
	MaxLength  = 0;
	CurrLength = 0;
	Message    = STRING;
	ExitWhile  = false;
	StartChar  = 0;
	if(Message.indexOf('<br>') != -1){
		EndChar = Message.indexOf('<br>');
	}else{
		EndChar = Message.length;
	}
	TotalChar  = Message.length;
	BreakCount = 0;
	while(ExitWhile == false){
		CurrLength = (Message.substring(StartChar, EndChar)).length;
		if(CurrLength > MaxLength){
			MaxLength = CurrLength;
		}
		StartChar  = EndChar + 4;
		TestChar   = (Message.substring(StartChar, TotalChar)).indexOf('<br>');
		if(TestChar == -1){
			if(StartChar < TotalChar){
				CurrLength = (Message.substring(StartChar,TotalChar)).length;
				if(CurrLength > MaxLength){
					MaxLength = CurrLength;
				}
			}
			ExitWhile = true;
		}
		EndChar = StartChar + TestChar;
	}
	return MaxLength * 3.3;
}

//Giuliano Riboni 09/11/06
//onmouseover="SimpleToolTip('');" onmouseout="trailOff();"
function SimpleToolTip(TEXT){
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1){
		gettrailobj().left         = "-500px";
		gettrailobject().innerHTML = '<div id="SimpleToolTip" class="TableToolTip"><font class="TextToolTip">' + TEXT + '</font></div>';
		gettrailobj().visibility   = "visible";
		LarguraDiv                 = ValidaLargura(TEXT);
		LarguraDiv                 = parseInt(LarguraDiv);
		divw                       = '100px';//LarguraDiv;
		AlturaDiv                  = ValidaAltura(TEXT);
		divh                       = AlturaDiv + 100;
		//document.onmousemove       = followmouseNoVertival;
		document.onmousemove       = followmouse;
	}
}

function FixSizeToolTip(TEXT, W, H){
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1){
		gettrailobj().left         = "-500px";
		gettrailobject().innerHTML = '<div style="width: '+W+';  height:'+H+';" id="SimpleToolTip" class="TableToolTip">' + TEXT + '</div>';
		gettrailobj().visibility   = "visible";
		divw                       = W;
		divh                       = H;
		document.onmousemove       = followmouse;
	}
}

function followmouse(e){
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	if(typeof e != "undefined"){
	//FIREFOX
		if(docwidth < 15+e.pageX+divw){
			xcoord = e.pageX-divw-5;
		}else{
			xcoord = 15+e.pageX;
		}
		if(docheight < 15+e.pageY+divh){
			ycoord = 15 + e.pageY-Math.max(0,(divh + e.pageY - docheight - truebody().scrollTop - 40));
		}else{
			ycoord = 15 + e.pageY;
		}
	}else if (typeof window.event != "undefined"){
	//IE
		if(docwidth < 15+truebody().scrollLeft+event.clientX+divw){
			xcoord = truebody().scrollLeft-5+event.clientX-divw;
		}else{
			xcoord = truebody().scrollLeft+15+event.clientX;
		}
		if(docheight < 15+truebody().scrollTop+event.clientY+divh){
			ycoord = 15+truebody().scrollTop+event.clientY-Math.max(0,(divh + event.clientY - docheight - 60));
		}else{
			ycoord = truebody().scrollTop+15+event.clientY;
		}
	}
	gettrailobj().left = xcoord + "px"
	gettrailobj().top  = (ycoord - 5) + "px"
}

function followmouseNoVertival(e){
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	if(typeof e != "undefined"){
	//FIREFOX
		xcoord = docwidth/2-(divw/2)-50;
		ycoord = e.pageY - document.getElementById("imgtrailer").scrollHeight;
	}else if (typeof window.event != "undefined"){
	//IE
		xcoord = docwidth/2-(divw/2)-50;
		ycoord = event.clientY - document.getElementById("imgtrailer").scrollHeight;
	}
	gettrailobj().left = xcoord + "px"
	gettrailobj().top  = (ycoord - 5) + "px"
}