﻿
function showTip(divid, e, state) {
    try {
        
        var dialog = document.getElementById(divid);
        
        if (dialog != null) {
            
            if (state == 'visible') {

                xPos = 200;
                yPos = -3; //110;
				
				if (e.target) {
					targ = e.target;
				} else if (e.srcElement) {
					targ = e.srcElement;
				}
				if (targ.nodeType == 3) {// defeat Safari bug
					targ = targ.parentNode;
				}

				var coords = findPos(targ);

				//dialog.style.left = xPos + "px";
				dialog.style.left = ((coords[0] - xPos) + targ.offsetWidth) + "px";
                dialog.style.top = ((coords[1] - yPos) + targ.offsetHeight) + "px";
			}

			dialog.style.visibility = state;
			dialog.style.display = (state == 'visible') ? 'inline' : 'none';
			closeOtherDivs(divid);
        }
	


     }
    catch (ex) {
        // alert("showTip: " + ex.message);
    }
}

function findPos2(obj) {
    var curleft = curtop = 0;

    if (obj.offsetParent) {

        do {

            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;

        } while (obj = obj.offsetParent);
        
    }

    return [curleft, curtop];
}

function findPos(obj) {
    var curleft = 0; 
    var curtop = 0;

    //var sDebug = "";

    // Can't count the body tag, so stop when the obj offsetParent is null
    do {

        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;

        //sDebug += obj.tagName + ": " + obj.offsetLeft + ", " + obj.offsetTop + "\n";

        obj = obj.offsetParent;

    } while (obj.offsetParent)

    //window.alert(sDebug);

    return [curleft, curtop];
}

function closeOtherDivs(divid) {
	var arrayOfDivs = document.getElementsByTagName('div');
	var howMany = arrayOfDivs.length - 1;

	for (var i=0; i < howMany; i++)
	{
		var thisDiv = arrayOfDivs[i];
		var styleClassName = thisDiv.className;
		var curID = thisDiv.id;
		if (styleClassName == 'Popup' && divid != curID)
		{
		    thisDiv.style.visibility = 'hidden';
		    thisDiv.style.display = 'none';
		}
	}
}
function ScrollTop() {
    var ScrollTop = document.body.scrollTop;

    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    return ScrollTop
}
function OpenWindow(path, width, height) {

    var oWindow = window.open(path, "ImagePreview", "menubar=no, status=no, titlebar=no, toolbar=no, resizable=yes");
    oWindow.resizeTo(width, height);

}

function ImageView(source, path, width, height) {

    var img = document.getElementById("ImagePreview");
    img.src = path;

    var target = document.getElementById("ImagePreview_Container");

    target.style.width = width + "px";

    //Center the Image within the Screen (1000 px wide - width - padding)
    var iLeft = (1000 - width - 30) / 2
    target.style.left = iLeft + "px";

    var iTop = ScrollTop() + Math.max((768 - 150 - height - 30) / 2, 0);
    iTop = Math.max(iTop, 120); // Don't cover top navigation

    target.style.top = iTop + "px";


    //Make Visible !!!
    target.style.display = "block";


    //Copy the Title & Text from the HTML into the Image Preview 

    var oParSib = source.parentNode.parentNode.getElementsByTagName("TD")[1]; //source.parentNode.nextSibling;

    var sTitle = oParSib.getElementsByTagName("H3")[0].innerHTML;
    var sDescription = oParSib.getElementsByTagName("P")[0].innerHTML;

    document.getElementById("ImagePreview_Title").innerHTML = sTitle;
    document.getElementById("ImagePreview_Description").innerHTML = sDescription;

}
function ImageClose() {
    var target = document.getElementById("ImagePreview_Container");
    target.style.display = "none";
}

/* Windows Media Player Control -- Full Screen */
function FullScreen(ID) {

    var oPlayer = document.getElementById(ID);

    if (oPlayer.playState == 3) // check wmplayer status
    {
        oPlayer.fullScreen = true;
    }
}
