
// Standard New Window Function.
var scriptStartTime=new Date();

function alertExecutionTime() {
	var endTime=new Date();

	alert("Execution time is:" +  (endTime - scriptStartTime) / 1000 + " seconds.");
}

function openWin (url, width, height, windowName, featureString) {
    if (!windowName)
        windowName = '';
    if (!featureString)
        featureString = '';
    else
        featureString = ',' + featureString;

    var x = Math.round((screen.availWidth - width) / 2);
    var y = Math.round((screen.availHeight - height) / 4);

    featureString = 'scrollbars=yes,left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + featureString;
    window.open(url,windowName,featureString);
}

function openWinPerc (url, perc_width, perc_height, windowName, featureString) {
    if (!windowName)
        windowName = '';
    if (!featureString)
        featureString = '';
    else
        featureString = ',' + featureString;

    var width = Math.round(screen.availWidth * perc_width / 100);
    var height = Math.round(screen.availHeight * perc_height / 100);
    var x = Math.round((screen.availWidth - width) / 2);
    var y = Math.round((screen.availHeight - height) / 4);

    featureString = 'scrollbars=yes,left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + featureString;
    window.open(url,windowName,featureString);
}

function isAlien(a) {
    return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 



// Tooltip Handler.


var toolTipX= 20, toolTipY= 20; // pixel
var showDelay = 500, hideDelay = 100; // milisecond

// DO NOT CHANGE ANY THING BELOW

var agt=navigator.userAgent.toLowerCase();
var is_ie   = (agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
        && (agt.indexOf('webtv')==-1));
var is_opera = (agt.indexOf("opera") != -1) && (agt.indexOf("msie") == -1);

var tipTimeoutID;
var is_tipDisplayed = false;
var connectedEvents = false;

var tipScreen = {width: 0, height: 0, scrollTop: 0, scrollLeft: 0};

/*
if (window.attachEvent) {
    window.attachEvent("onload", injectTip);
} else if (window.captureEvents) {
    window.onload = injectTip;
    window.captureEvents(Event.LOAD);
}

function injectTip(event)
{
    if (is_ie) document.body.innerHTML += '<iframe id="tooltip_iframe" scrolling="no" frameborder="0"></iframe>';
    document.body.innerHTML += '<div id="tooltip"></div>';
}

*/

function connectEvents()
{
    if (!connectedEvents) {
        if (document.attachEvent) {
            document.attachEvent("onmousemove", moveTip);
            document.attachEvent("onmouseout", hideTip);
        } else if (document.captureEvents) {
            document.captureEvents(Event.MOUSEMOVE | Event.MOUSEOUT);
            document.onmousemove = moveTip;
            document.onmouseout = hideTip;
        }
        connectedEvents = true;
    }
}

function disconnectEvents()
{
    if (connectedEvents) {
        if (document.attachEvent) {
            document.detachEvent("onmousemove", moveTip);
            document.detachEvent("onmouseout", hideTip);
        } else if (window.captureEvents) {
            document.releaseEvents(Event.MOUSEMOVE | Event.MOUSEOUT);
            document.onmousemove = null;
            document.onmouseout = null;
        }
        connectedEvents = false;
    }
}

function moveTip(event)
{
    var pos = getEventPos(event);
    moveTipTo(pos.x, pos.y);
}

function moveTipTo(posX, posY)
{
    var element = document.getElementById("tooltip");
   
    var tipX = posX + toolTipX;
    var tipY = posY + toolTipY;
    
    if (tipScreen.width < (tipX + element.offsetWidth)) {
        tipX = posX - toolTipX - element.offsetWidth;
    }

    if (tipScreen.height < (tipY + element.offsetHeight)) {
        tipY = posY - toolTipY - element.offsetHeight;
    }
   
    element.style.left = tipX + "px";
    element.style.top = tipY + "px";
    
    if (is_ie) {
        var iframeObj = document.getElementById("tooltip_iframe");

        iframeObj.style.top    = element.offsetTop + "px";
        iframeObj.style.left   = element.offsetLeft + "px";
        iframeObj.style.width  = element.offsetWidth + 3 + "px";
        iframeObj.style.height = element.offsetHeight + 3 + "px";
    }
}

function getEventPos(event)
{
    var posX, posY;

    if (event.clientX || event.clientY) {
        posX = event.clientX;
        posY = event.clientY;
    } else if (event.pageX || event.pageY) {
        posX = event.pageX;
        posY = event.pageY;
    }

    posX += tipScreen.scrollLeft;
    posY += tipScreen.scrollTop;

    var pos = {x: posX, y: posY};  
    return pos;
}

function locateWindowSize()
{
    if (document.body && ( document.body.scrollTop || document.body.scrollLeft )) {
        tipScreen.scrollLeft = document.body.scrollLeft;
        tipScreen.scrollTop = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )) {
        tipScreen.scrollLeft = document.documentElement.scrollLeft;
        tipScreen.scrollTop = document.documentElement.scrollTop;
    }

    if (window.innerWidth || window.innerHeight) {
        tipScreen.width = window.innerWidth;
        tipScreen.height = window.innerHeight;
    } else if (document.body.clientWidth || document.body.clientHeight) {
        tipScreen.width = document.body.clientWidth;
        tipScreen.height = document.body.clientHeight;
    }
}

function showTip(tTitle, tContent, event)
{  
    locateWindowSize();
    var pos = getEventPos(event);
    showTipXY(tTitle, tContent, pos.x, pos.y);
}

function showTipXY(tTitle, tContent, posX, posY)
{
    locateWindowSize();

    if(element = document.getElementById("tooltip")) {
        element.innerHTML='<table class="tooltip" cellspacing="0" cellpadding="0">'+
            '<tr><td class="title">'+ tTitle + '</td></tr>'+
            '<tr><td class="content">'+ tContent + '</td></tr>'+
            '</table>';

        if (is_ie) document.getElementById("tooltip_iframe").style.visibility = "visible";

        element.style.visibility = "visible";
    } else {
        alert("Tool Tip cannot be displayed!")
        return;
    }
    
    moveTipTo(posX, posY);
    if (is_ie) document.getElementById("tooltip_iframe").style.visibility = "visible";
    element.style.visibility = "visible";

    is_tipDisplayed = true;
    if (!connectedEvents) connectEvents();
}

function resetTimerShowTip(tTitle, tContent, event) {
    connectEvents();
    
    var tipX, tipY, coord = new Object();
    var pos = getEventPos(event);
    
    clearTimeout(tipTimeoutID);
    tipTimeoutID = setTimeout("showTipXY('" + tTitle + "', '" + tContent + "', " + pos.x + ", " + pos.y + ")", showDelay);
} 

function timerShowTip(tTitle, tContent, event)
{
    if (!is_tipDisplayed) {
        resetTimerShowTip(tTitle, tContent, event);
    } else {
        clearTimeout(tipTimeoutID);
        showTip(tTitle, tContent, event);
    }
}

function hideTip()
{
    disconnectEvents();
    clearTimeout(tipTimeoutID);
    document.getElementById("tooltip").style.visibility = "hidden";

    if (is_ie) document.getElementById("tooltip_iframe").style.visibility = "hidden";
    is_tipDisplayed = false;
}

function resetTimerHideTip() {
    clearTimeout(tipTimeoutID);
    tipTimeoutID = setTimeout("hideTip()", hideDelay);
}

function timerHideTip()
{
    if (is_tipDisplayed) {
        resetTimerHideTip();
    } else {
        clearTimeout(tipTimeoutID);
    }
}

// ToolTip end
