﻿// JScript File
var transparency = 100;
var wnd_width;
var wnd_height;
var tooltip_height;
var tooltip_shown = false;
var timer_id;
var tooltip_width;
var FADINGTOOLTIP;

window.onload = WindowLoading;

function DisplayTooltip1(tooltip_text, delay)
{

    if (!FADINGTOOLTIP)
        return;
        
    FADINGTOOLTIP.style.visibility = "hidden";
    clearTimeout(timer_id);
    FADINGTOOLTIP.innerHTML = tooltip_text;
	tooltip_shown = (tooltip_text != "")? true : false;
	if(tooltip_text != "")
	{
		tooltip_height = (FADINGTOOLTIP.style.pixelHeight)? FADINGTOOLTIP.style.pixelHeight : FADINGTOOLTIP.offsetHeight;
		tooltip_width = FADINGTOOLTIP.offsetWidth > Math.round(wnd_width / 3) ? Math.round(wnd_width / 3) : FADINGTOOLTIP.offsetWidth;
		FADINGTOOLTIP.style.width = tooltip_width + "px";
		timer_id = setTimeout('FADINGTOOLTIP.style.visibility="visible"', 0);
		//FADINGTOOLTIP.style.height = tooltip_height + "px";
		//transparency=0;
		//ToolTipFading();
	}
	else
	{ 
	    FADINGTOOLTIP.style.width = "";
	}
}

function DisplayTooltip(obj, tooltip_text, delay)
{
    if (!FADINGTOOLTIP)
        return;
        
    FADINGTOOLTIP.style.visibility = "hidden";
    clearTimeout(timer_id);
    FADINGTOOLTIP.innerHTML = "<table cellpadding='0' cellspacing='0' style='width:222px;height:7px;'><tr><td style='background-color:#027DCA;'><img src='img/1px.gif' /></td><td style='width:7px'><img src='img/tipTopCorner.gif' /></td></tr></table>";
    FADINGTOOLTIP.innerHTML += "<div style='padding:5px 10px 5px 10px;background-color:#027DCA'>" + tooltip_text + "</div>";
    FADINGTOOLTIP.innerHTML += "<table cellpadding='0' cellspacing='0' style='width:222px;height:7px;'><tr><td style='background-color:#027DCA;'><img src='img/1px.gif' /></td><td style='width:7px'><img src='img/tipBotCorner.gif' /></td></tr></table>";
	tooltip_shown = (tooltip_text != "")? true : false;
	if(tooltip_text != "")
	{
	    if (obj.className.indexOf('selected') == 0)
	        obj.className = 'selected hover';
	    else
	        obj.className = 'unselected hover';
	    
	    tooltip_height = (FADINGTOOLTIP.style.pixelHeight)? FADINGTOOLTIP.style.pixelHeight : FADINGTOOLTIP.offsetHeight;
		tooltip_width = FADINGTOOLTIP.offsetWidth > Math.round(wnd_width / 3) ? Math.round(wnd_width / 3) : FADINGTOOLTIP.offsetWidth;
		//FADINGTOOLTIP.style.width = tooltip_width + "px";
		if (delay)
		    timer_id = setTimeout('FADINGTOOLTIP.style.visibility="visible"', delay);
		else
		    timer_id = setTimeout('FADINGTOOLTIP.style.visibility="visible"', 0);
		//FADINGTOOLTIP.style.height = tooltip_height + "px";
		//transparency=0;
		//ToolTipFading();
	}
	else
	{ 
	    if (obj.className.indexOf('selected') == 0)
	        obj.className = 'selected';
	    else
	        obj.className = 'unselected';
	    //FADINGTOOLTIP.style.width = "";
	}
}

function AdjustToolTipPosition(e)
{
    if (tooltip_shown == true)
	{
	    //offset_y = (clientY(e) + tooltip_height - document.documentElement.scrollTop + 10 >= wnd_height) ? - 10 - tooltip_height/2 : -tooltip_height/2;
	    
	    //FADINGTOOLTIP.style.right = Math.min(wnd_width - tooltip_width + 15 , Math.max(3, wnd_width - clientX(e) + 15)) + 'px';
	    //FADINGTOOLTIP.style.top = clientY(e) + offset_y + document.documentElement.scrollTop + 'px';
	    FADINGTOOLTIP.style.top = Math.max(Math.min(clientY(e) + document.documentElement.scrollTop - tooltip_height/2, wnd_height + document.documentElement.scrollTop - tooltip_height), document.documentElement.scrollTop) + 'px';
	}
	else
	{
	    clearTimeout(timer_id);
	    FADINGTOOLTIP.style.visibility="hidden";
	}
	
}

function WindowLoading()
{
	FADINGTOOLTIP = document.getElementById('FADINGTOOLTIP');
    
    // Get tooltip  window width				
	tooltip_width = Math.round(getScreenWidth() / 3);
	
	// Get tooltip window height
	tooltip_height = (FADINGTOOLTIP.style.pixelHeight)? FADINGTOOLTIP.style.pixelHeight : FADINGTOOLTIP.offsetHeight;

    window.onresize = UpdateWindowSize;
    document.onmousemove = AdjustToolTipPosition;
    
	UpdateWindowSize();
}

function UpdateWindowSize() 
{
    wnd_height = document.documentElement.clientHeight;
	wnd_width = document.documentElement.clientWidth;
}

function getScreenHeight()
{
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
			
function getScreenWidth()
{
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

function ToolTipFading()
{
	if(transparency <= 100)
	{
		FADINGTOOLTIP.style.filter="alpha(opacity="+transparency+")";
		transparency += 5;
		timer_id = setTimeout('ToolTipFading()', 35);
	}
}

function clientX(e)
{
    if (e == null)
        return event.clientX
    else 
        return e.clientX
}

function clientY(e)
{
    if (e == null)
        return event.clientY
    else 
        return e.clientY
}
