/************************************************************************************************************
Ajax tooltip
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com

************************************************************************************************************/




/* Custom variables */

/* Offset position of tooltip */
var x_offset_tooltip = 5;
var y_offset_tooltip = 5;

/* Don't change anything below here */


var ajax_tooltipObj = false;
var ajax_tooltipObj_iframe = false;

var ajax_tooltip_MSIE = false;
var ie8 = false;
if(navigator.userAgent.indexOf('MSIE 6')>=0)ajax_tooltip_MSIE=true;
if(navigator.userAgent.indexOf('MSIE 8')>=0)ie8=true;
function ajax_showTooltip(content,inputObj, height, width, topPos, leftPos)
{	
	if (ajax_tooltipObj) {
		document.getElementById('ajax_tooltipObj').parentNode.removeChild(document.getElementById('ajax_tooltipObj'));
	}
	// if(!ajax_tooltipObj)	/* Tooltip div not created yet ? */
	// {
		ajax_tooltipObj = document.createElement('DIV');
        ajax_tooltipObj.style.position = 'absolute';
        ajax_tooltipObj.id = 'ajax_tooltipObj';
        if (ie8) {
            ajax_tooltipObj.style.background = '#E8E9E0';
        }
		document.body.appendChild(ajax_tooltipObj);
		var leftDiv = document.createElement('DIV');	/* Create arrow div */
		leftDiv.className='ajax_tooltip_arrow';
		leftDiv.id = 'ajax_tooltip_arrow';
		ajax_tooltipObj.appendChild(leftDiv);
		var contentDiv = document.createElement('DIV'); /* Create tooltip content div */
		contentDiv.className = 'ajax_tooltip_content';
		ajax_tooltipObj.appendChild(contentDiv);
		contentDiv.id = 'ajax_tooltip_content';
        if (ie8) {
            contentDiv.style.border = '1px solid #333333';
            contentDiv.style.overflow = 'visible';
        }
		if(ajax_tooltip_MSIE){	/* Create iframe object for MSIE in order to make the tooltip cover select boxes */
			ajax_tooltipObj_iframe = document.createElement('iframe');
		      			ajax_tooltipObj_iframe.setAttribute('id','TooltipFrame');
		      			ajax_tooltipObj_iframe.style.border    = '0px';
			ajax_tooltipObj_iframe.style.position        = 'absolute';
			ajax_tooltipObj_iframe.frameborder           = 0;
			ajax_tooltipObj_iframe.style.backgroundColor = '#FFFFFF';
			ajax_tooltipObj_iframe.src                   = 'about:blank';
			ajax_tooltipObj.appendChild(ajax_tooltipObj_iframe);
			ajax_tooltipObj_iframe.style.left = '5px';
			ajax_tooltipObj_iframe.style.top = '5px';
		}
	// }
	// Find position of tooltip
	ajax_tooltipObj.style.display='block';
	document.getElementById('ajax_tooltip_content').innerHTML = content;
	if (!leftPos) {
		if (width != undefined) {
			document.getElementById('ajax_tooltip_content').style.width = width + 'px';
		} else {
			width = 0;
		}
		if (height != undefined) {
			document.getElementById('ajax_tooltip_content').style.height = height + 'px';
		} else {
			height = 0;
		}
	}
	if(ajax_tooltip_MSIE){
		document.getElementById('TooltipFrame').style.width = (width -(-10)) + 'px';
		document.getElementById('TooltipFrame').style.height = (height -(-10)) + 'px';
		document.getElementById('TooltipFrame').style.display = 'block';
	}
	ajax_positionTooltip(inputObj, height, width, topPos, leftPos);
}

function ajax_positionTooltip(inputObj, height, width, topPos, leftPos)
{
	browserSize();
	if (!leftPos) {
		var leftPos = (ajaxTooltip_getLeftPos(inputObj) + inputObj.offsetWidth);
	}
	if (!topPos) {
		var topPos = ajaxTooltip_getTopPos(inputObj);
	}
	if (height > 200 || height == 0 ) { height = 200; }
	if (width == 0 ) { width = 300; }
	if (topPos > 500) { topPos = topPos - height; }
	if (leftPos > (browserWidth-width-40)) { leftPos = leftPos - width - 30 ; }

	/*
	var rightedge=ajax_tooltip_MSIE? document.body.clientWidth-leftPos : window.innerWidth-leftPos
	var bottomedge=ajax_tooltip_MSIE? document.body.clientHeight-topPos : window.innerHeight-topPos
	*/
	if (!leftPos) {
		var tooltipWidth = document.getElementById('ajax_tooltip_content').offsetWidth;
	}
	// Dropping this reposition for now because of flickering
	//var offset = tooltipWidth - rightedge;
	//if(offset>0)leftPos = Math.max(0,leftPos - offset - 5);
	ajax_tooltipObj.style.left = leftPos + 'px';
	ajax_tooltipObj.style.top = topPos + 'px';


}


function ajax_hideTooltip()
{
	ajax_tooltipObj.style.display='none';
}

function ajaxTooltip_getTopPos(inputObj)
{
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function ajaxTooltip_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
output = inputObj.tagName + ' - ' + inputObj.offsetLeft + '; ';
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML' ) {
		if (inputObj.id == 'main' && inputObj.offsetLeft > 500 ) { offsetLeft = inputObj.offsetLeft - 712; } else { offsetLeft = inputObj.offsetLeft; }
		returnValue += offsetLeft;
		output += inputObj.id + ':' + inputObj.tagName + ' - ' + offsetLeft + '; ';
	}
  }
  return returnValue;
}

