function Bubble(targetObj){
	this.targetObj = targetObj;
	this.Obj;
	this.bubbleObj = false;
	this.txt = "";
}  

Bubble.prototype.invertVisibility = function(objectId, isVisible){
  if(this.Obj){
		this.ObjStyle.visibility = isVisible;
		return true;
  }
  else
		return false;
}

Bubble.prototype.moveObj = function(){
  if(this.Obj){
		this.ObjStyle.left = this.xCoordinate;
		this.ObjStyle.top = this.yCoordinate;
		return true;
  }
  else
		return false;
}

Bubble.prototype.editBubble = function(eventCoor, content, divId, xCoor, yCoor, mouseCoorX, mouseCoorY, placement){
	this.hideBubble();
	this.set();
	
	if(divId)
		this.Obj = document.getElementById(divId);
	else
		{
		this.Obj = document.getElementById('npinfobubble');
		this.Obj.className = "";
		this.Obj.style.position = "absolute";
		}
	this.bubbleObj = this.Obj;
	this.ObjStyle = this.bubbleObj.style;
	this.addX = xCoor;
	this.addY = yCoor;
	this.placement = placement;
	
	if(eventCoor && content){
		this.hideBubble();
		eventCoor.cancelBubble = true;
		var bubbleContent = (document.getElementById(content))? document.getElementById(content).innerHTML : content;
		this.Obj.innerHTML = this.balloon(bubbleContent);

		if(((event.y + eventCoor.offsetHeight + this.Obj.offsetHeight + yCoor) > document.body.clientHeight) || this.placement == "up"){
			this.yCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.Y]-this.Obj.offsetHeight+yCoor-30;
			if((event.x + this.Obj.offsetWidth + xCoor) > document.body.clientWidth){
				this.xCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.X]-this.Obj.offsetWidth+xCoor+this.addX;
				this.cbr = "bubbr1";
				}
			else
				{
				this.xCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.X]+xCoor;
				this.cbl = "bubbl1";
				}
			}
		else
			{
			this.yCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.Y]+eventCoor.offsetHeight+yCoor;
			if((event.x + this.Obj.offsetWidth + xCoor) > document.body.clientWidth){
				this.xCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.X]-this.Obj.offsetWidth+xCoor+this.addX;
				this.ctr = "bubtr1";
				}
			else
				{
				this.xCoordinate = NPTool.getOffsetCoor(eventCoor)[NPTool.coor.X]+8+xCoor;		
				this.ctl = "bubtl1";
				}
			}
		if (mouseCoorX){
				this.xCoordinate = mouseCoorX + this.addX;
				this.set();
				if(placement == "up") this.cbl = "bubbl1";
				else this.ctl = "bubtl1";
			}
		if (mouseCoorY){
			 this.yCoordinate = mouseCoorY + this.addY;
			 this.set(); this.ctl = "bubtl1";
			}
		this.Obj.innerHTML = this.balloon(bubbleContent);
		
		this.moveObj(this.xCoordinate, this.yCoordinate);
		if (this.invertVisibility(this.targetObj,'visible')){
			this.bubbleObj = this.Obj;
			this.bubbleObj.style.zIndex = ++g_zindex;
			return true;
			}
			else
				return false;
	}
	else
		return false;  
}

Bubble.prototype.hideBubble = function(){      
	if(this.bubbleObj){
		this.invertVisibility(this.bubbleObj, 'hidden'); 
		this.bubbleObj = false;
		}
}
Bubble.prototype.balloon = function(content){
	str = '<table cellpadding="0" cellspacing="0" border="0">\n<tr>\n<td><img src="img/clear.gif" border="0" class="'+this.ctl+'"></td>\n<td class="bubtop">&nbsp;</td>\n<td><img src="img/clear.gif" border="0" class="'+this.ctr+'"></td>\n</tr>\n';
	str += '<tr>\n<td class="bubl">&nbsp;</td>\n';
	str += '<td id="bubblecontent" class="bubc">' + content + '</td>\n';
	str += '<td class="bubr">&nbsp;</td>\n</tr>\n';
	str += '<tr>\n<td><img src="img/clear.gif" border="0" class="'+this.cbl+'"></td>\n<td class="bubbottom">&nbsp;</td>\n<td><img src="img/clear.gif" border="0" class="'+this.cbr+'"></td>\n</tr>\n</table>';
	return(str);
}

Bubble.prototype.set = function(){this.ctl = "bubtl"; this.ctr = "bubtr"; this.cbl = "bubbl"; this.cbr = "bubbr";}

function bub(event,content,dest,x,y,mouseCoorX,mouseCoorY,placement){
	x = (x != null)? x : 15;
	y = (y != null)? y : 15;
	var event = (ie)? window.event.srcElement : event.target;
	while (event.tagName != "TD") event = event.parentNode;
	if(g_bubble) g_bubble.editBubble(event,content,dest,x,y,mouseCoorX,mouseCoorY,placement);
}

function warning(event,content,dest,x,y,mouseCoorX,mouseCoorY,placement){
	x = (x != null)? x : 15;
	y = (y != null)? y : 15;
	var event = (ie)? window.event.srcElement : event.target;
	mouseCoorX = (ie)? window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft : event.clientX + window.scrollX;
	while (event.tagName != "TD") event = event.parentNode;
	if(g_bubble) g_bubble.editBubble(event,content,dest,x,y,mouseCoorX,mouseCoorY,placement);
}

function mousebub(event,content,dest,x,y,mouseCoorX,mouseCoorY){
	var event = (ie)? window.event.srcElement : event.target;
	x = (x != null)? x : 15;
	y = (y != null)? y : 15;
	mouseCoorX = (ie)? window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft : event.clientX + window.scrollX;
	mouseCoorY = (ie)? window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop : event.clientY + window.scrollY;
	if(g_bubble) g_bubble.editBubble(event, content, dest, x, y, mouseCoorX, mouseCoorY);
}
