function TooltipFactory(){
/* Custom variables */

/* Offset position of tooltip */
this.x_offset_tooltip = 5;
this.y_offset_tooltip = 0;

/* Don't change anything below here */
this.tooltipObj = false;
this.iframe = false;
this.leftDiv = null;
this.contentDiv =null;
this.clientWidth =null;
this.clientHeight =null;
this.currentInput=null;
this.ajax_tooltip_MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
this.idContent="ajax_tooltip_content";
this.active=false;
}
var  tooltipFactory = new TooltipFactory();

TooltipFactory.prototype.showTooltip= function (mouseevent,externalFile,inputObj,width,height){
if(tooltipFactory.active === true){
this.currentInput = inputObj;
var obj = tooltipFactory.tooltipObj;
var factory = tooltipFactory;
this.clientWidth =document.body.clientWidth;
this.clientHeight =document.body.clientHeight;
if(!obj)	/* Tooltip div not created yet ? */
	{
		obj= document.createElement('DIV');
		obj.style.position = 'absolute';
		obj.id = 'ajax_tooltipObj';		
		

		this.leftDiv = document.createElement('DIV');	/* Create arrow div */
		this.leftDiv.className='ajax_tooltip_arrow';
		this.leftDiv.id = 'ajax_tooltip_arrow';
		
		
		this.contentDiv = document.createElement('DIV'); /* Create tooltip content div */
		this.contentDiv.className =this.idContent;
		this.contentDiv.id = this.idContent;
		
		
		document.body.appendChild(obj);
		obj.appendChild(this.leftDiv);
		obj.appendChild(this.contentDiv);
		
		
		
		/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
		
		if(this.ajax_tooltip_MSIE ===  true ){	
			factory.iframe = document.createElement('<iframe frameborder="0">');
			factory.iframe.style.position = 'absolute';
			factory.iframe.border='0';
			factory.iframe.frameborder=0;
			factory.iframe.style.backgroundColor='#FFF';
			factory.iframe.src = '/jsp/session/blank.htm';
			this.contentDiv.appendChild(factory.iframe);
			factory.iframe.style.left = '0px';
			factory.iframe.style.top = '0px';
		}
	

			factory.tooltipObj = obj;
	}
		
	// Find position of tooltip
	obj.style.display='block';
	tool.ajax_loadContent('ajax_tooltip_content',externalFile,true);
	if(this.ajax_tooltip_MSIE.ajax_tooltip_MSIE){
		factory.iframe.style.width = tooltipObj.clientWidth + 'px';
		factory.iframe.style.height = tooltipObj.clientHeight + 'px';
	}

	tooltipFactory.positionTooltip(mouseevent);
}
};

TooltipFactory.prototype.positionTooltip= function(mouseevent) {
    var factory = tooltipFactory ;
   
 if(applimediaconfig.browser.isIE){
	var leftPos = (tool.getElementX(factory.currentInput) + this.currentInput.offsetWidth);
	var topPos = tool.getElementY(factory.currentInput);
	var tooltipWidth = tool.getElementWidth(factory.idContent) +   tool.getElementWidth("ajax_tooltip_arrow"); 
	var tooltipHeight = tool.getElementHeight(factory.idContent) ; 
	var rigthMax = tooltipWidth + leftPos;
	var bottomMax = tooltipHeight + topPos;
	//	alert("rigthMax =" + rigthMax + " clientWidth =" + this.clientWidth +" clientHeight =" + this.clientHeight);
   if(this.clientWidth <rigthMax ){
   leftPos = leftPos - (rigthMax - this.clientWidth);
   //	alert("leftPos =" + leftPos );
   }
 // alert("bottomMax =" + bottomMax + " clientHeight =" + this.clientHeight);
    var delta = bottomMax - this.clientHeight;
    if(delta > 0 ){
  //  alert("topPos bef =" + topPos );
   topPos = topPos - delta;
   }
   
	tooltipFactory.tooltipObj.style.left = leftPos + 'px';
	tooltipFactory.tooltipObj.style.top = topPos + 'px';	
	var newTop  =0 ;
	var newTopContent =0 ;
	
	  if(delta > 0){
	    var last = 0 ;
	 last =  tool.getElementY(factory.idContent) ; 
   newTop =last + delta;
   newTopContent = newTop  ;
  // alert("last  =" + last + " newTop =" + newTop + " delta =" + delta  );
	}
	
	else{
	newTopContent = newTop;
	}
	  
	     
	   var newValue = newTop + "px";
	     var newContentValue = newTopContent + "px";
	   tooltipFactory.leftDiv.style.top =   newValue;
	   tooltipFactory.contentDiv.style.top =   newContentValue;
	 }else{
	 if(mouseevent && mouseevent.pageY){
	 var y =mouseevent.pageY - 15;
	    var x =mouseevent.pageX +5;
	    
	   tooltipFactory.tooltipObj.style.left = x + 'px';
	   tooltipFactory.tooltipObj.style.top = y + 'px';	
	   tooltipFactory.leftDiv.style.top =     "0px";
	   tooltipFactory.contentDiv.style.top =   "0px";
	}
	   }
};

TooltipFactory.prototype.hideTooltip= function() {
var obj= tooltipFactory.tooltipObj;
if(obj){obj.style.display='none';}
};
setTimeout("tooltipFactory.active =true",1000);
