
function picshow(s, o)
{
	HMTooltip.show('/bpstore/pictooltip.ashx?nr=' + s,o);
}

function pichide()
{
	HMTooltip.hide();
}




HMTooltip = new function ()
{
  var x_offset = 10;
  var y_offset = 0;
  var tt = false;
  var tt_iframe = false;
  var MSIE = false;
  var inp;
  if(navigator.userAgent.indexOf('MSIE')>=0) MSIE=true;

  var scrollx=0;
  var scrolly=0;

function CreateTooltip()
{
	tt = document.createElement('DIV');
	tt.style.position = 'absolute';
	tt.id = 'hmtObj';		
	document.body.appendChild(tt);
		
	/* Create tooltip content div */
	var contentDiv = document.createElement('DIV'); 
	contentDiv.className = 'hmt_content';
	tt.appendChild(contentDiv);
	contentDiv.id = 'hmt_content';
	
	//Standardstil setzen
	contentDiv.style.padding = "15px";
	contentDiv.style.border = "1px solid #c0c0c0";
	contentDiv.style.backgroundColor = "#FFF";
		
	if(MSIE)
	{	/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
		tt_iframe = document.createElement('<IFRAME frameborder="0">');
		tt_iframe.style.position = 'absolute';
		tt_iframe.border = '0';
		tt_iframe.frameborder = 0;
		tt_iframe.style.backgroundColor = '#FFF';
		tt_iframe.src = 'about:blank';
		contentDiv.appendChild(tt_iframe);
		tt_iframe.style.left = '0px';
		tt_iframe.style.top = '0px';
	}
}


this.show = function (externalFile, inputObj)
{
	if (!tt) CreateTooltip();

	//hm Tooltip außerhalb verschieben
	tt.style.left = -1000;
	tt.style.top = -1000;
	
	// Find position of tooltip
	tt.style.display='block';
	loadContent('hmt_content', externalFile);
	
	if(MSIE)
	{
		tt_iframe.style.width = tt.clientWidth + 'px';
		tt_iframe.style.height = tt.clientHeight + 'px';
	}
	
	inp = inputObj;
	
	//Scrollposiiton merken und Tooltip sofort verbergen, wenn Pos verändert wird
	scrollx = document.body.scrollLeft;
	scrolly = document.body.scrollTop;
	
	window.timid = window.setTimeout("HMTooltip.positionTooltip()", 1200);
}


this.positionTooltip = function ()
{
	if ((scrollx != document.body.scrollLeft) || (scrolly != document.body.scrollTop))
	{
		this.hide();
		return;
	}
	
	var leftpos = getLeftPos(inp) + inp.offsetWidth;
	var toppos = getTopPos(inp);
	var maxw = document.body.scrollLeft + (MSIE? document.body.clientWidth : window.innerWidth);
	var maxh = document.body.scrollTop  + (MSIE? document.body.clientHeight : window.innerHeight);
	var tooltipWidth = document.getElementById('hmt_content').offsetWidth; 
	var tooltipHeight = document.getElementById('hmt_content').offsetHeight; 
	var ttr = leftpos + tooltipWidth; 
	var ttu = toppos + tooltipHeight; 
	if (ttr > maxw) leftpos = Math.max(document.body.scrollLeft, maxw - tooltipWidth);
	if (ttu > maxh) toppos = Math.max(document.body.scrollTop,  maxh - tooltipHeight);
	tt.style.left = (x_offset + leftpos) + 'px';
	tt.style.top  = (y_offset + toppos) + 'px';	
}


this.hide = function ()
{
	if (window.timid) window.clearTimeout(window.timid);
	tt.style.display='none';
}



function getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null)
  {
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}



function getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)
  {
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}


//-------------
var enableCache = true;
var jsCache = new Array();
var arrajax = new Array();

function showContent(divId, ajaxIndex, url)
{	
	document.getElementById(divId).innerHTML = arrajax[ajaxIndex].response;
	if (enableCache) { jsCache[url] = 	arrajax[ajaxIndex].response; }
	arrajax[ajaxIndex] = false;
}


function loadContent(divId, url)
{
	if(enableCache && jsCache[url])
	{
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}
	
	var ajaxIndex = arrajax.length;
	document.getElementById(divId).innerHTML = 'Inhalt wird geladen - Bitte einen Moment Geduld';

	arrajax[ajaxIndex] = new HMAjax();
	arrajax[ajaxIndex].url = url;
	arrajax[ajaxIndex].onSuccess = function(){ showContent(divId, ajaxIndex, url); };
	arrajax[ajaxIndex].onError = function(){ document.getElementById(divId).innerHTML = "Bitte klicken für Details"; };
	arrajax[ajaxIndex].doRequest();
}


}
