﻿var	ie = document.all;
var	dom = document.getElementById;
var	ns4 = document.layers;
var	interestStyleObj;
var interestObj;
var	locationStyleObj;
var locationObj;
var	bPageLoaded = false;
var panelHeight = 0;
var panelSlide;

/* hides <select> and <applet> objects (for IE only) */
function hideElement(elmID, overDiv)
{
	if (ie)
	{
		for (i = 0; i < document.all.tags( elmID ).length; i++)
		{
			obj = document.all.tags( elmID )[i];
			if( !obj || !obj.offsetParent )
			{
				continue;
			}

			// Find the element's offsetTop and offsetLeft relative to the BODY tag.
			objLeft   = obj.offsetLeft;
			objTop    = obj.offsetTop;
			objParent = obj.offsetParent;

			while ((objParent != null) && (objParent.tagName.toUpperCase() != "BODY"))
			{
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}

			objHeight = obj.offsetHeight;
			objWidth = obj.offsetWidth;

			if ((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft)
				;
			else if ((overDiv.offsetTop + overDiv.offsetHeight) <= objTop)
				;
			else if (overDiv.offsetTop >= (objTop + objHeight))
				;
			else if (overDiv.offsetLeft >= (objLeft + objWidth))
				;
			else
			{
				obj.style.visibility = "hidden";
			}
		}
	}
}

/* unhides <select> and <applet> objects (for IE only)*/
function showElement(elmID)
{
	if (ie)
	{
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];

			if(!obj || !obj.offsetParent)
			{
				continue;
			}

			obj.style.visibility = "";
		}
	}
}

function init()
{
	if (!ns4)
	{
		interestStyleObj = (dom) ? document.getElementById("InterestPopup").style : ie ? document.all.InterestPopup : document.InterestPopup;
		interestObj = (dom) ? document.getElementById("InterestPopup") : ie ? document.all.InterestPopup : document.InterestPopup;
		hideInterestPopup();

		locationStyleObj = (dom) ? document.getElementById("LocationPopup").style : ie ? document.all.LocationPopup : document.LocationPopup;
		locationObj = (dom) ? document.getElementById("LocationPopup") : ie ? document.all.LocationPopup : document.LocationPopup;
		hideLocationPopup();

		bPageLoaded = true;
	}
}

function hideInterestPopup()
{
	interestStyleObj.visibility = "hidden";
	interestStyleObj.display = "none";
	showElement('SELECT');
	showElement('APPLET');
}

function hideLocationPopup()
{
	locationStyleObj.visibility = "hidden";
	locationStyleObj.display = "none";
	showElement('SELECT');
	showElement('APPLET');
}

function showInterestPopup(ctl, align)
{
	if (!bPageLoaded)
	    init();

	var	leftPos = 0;
	var	topPos = 0;

	if (bPageLoaded)
	{
	    hideLocationPopup();
		if (interestStyleObj.visibility == "hidden")
		{
			aTag = ctl;
			do
			{
				aTag = aTag.offsetParent;
				leftPos += aTag.offsetLeft;
				topPos += aTag.offsetTop;
			} while ((aTag.tagName != "BODY") && (aTag.offsetParent != null));

			interestStyleObj.display = "";
            var panelLeft = ctl.offsetLeft + leftPos - ((align == "right") ? (interestObj.offsetWidth - ctl.offsetWidth) : 0);
            var panelTop = ctl.offsetTop + topPos + ctl.offsetHeight + 2;
			interestStyleObj.left = panelLeft.toString() + "px";
			interestStyleObj.top = panelTop.toString() + "px";
			interestStyleObj.visibility = (dom || ie) ? "visible" : "show";

            //for sliding
			//panelHeight = interestObj.offsetHeight;
			//interestStyleObj.height = "1px";
			//interestStyleObj.visibility = (dom || ie) ? "visible" : "show";
			//panelSlide = setInterval("slideInterest()", 10);

			hideElement('SELECT', document.getElementById("InterestPopup"));
			hideElement('APPLET', document.getElementById("InterestPopup"));
		}
		else
		{
			hideInterestPopup();
			//showInterestPopup(ctl, align);
		}
	}
}

function slideInterest()
{
    if (interestObj.offsetHeight < panelHeight)
        interestStyleObj.height = (interestObj.offsetHeight + 10).toString() + "px";
    else
        clearInterval(panelSlide);
}

function showLocationPopup(ctl, align)
{
	if (!bPageLoaded)
	    init();

	var	leftPos = 0;
	var	topPos = 0;

	if (bPageLoaded)
	{
	    hideInterestPopup();
		if (locationStyleObj.visibility == "hidden")
		{
			aTag = ctl;
			do
			{
				aTag = aTag.offsetParent;
				leftPos += aTag.offsetLeft;
				topPos += aTag.offsetTop;
			} while ((aTag.tagName != "BODY") && (aTag.offsetParent != null));

			locationStyleObj.display = "";
            var panelLeft = ctl.offsetLeft + leftPos - ((align == "right") ? (locationObj.offsetWidth - ctl.offsetWidth) : 0);
            var panelTop = ctl.offsetTop + topPos + ctl.offsetHeight + 2;
			locationStyleObj.left = panelLeft.toString() + "px";
			locationStyleObj.top = panelTop.toString() + "px";
			locationStyleObj.visibility = (dom || ie) ? "visible" : "show";

            //for sliding
			//panelHeight = locationObj.offsetHeight;
			//locationStyleObj.height = "1px";
			//locationStyleObj.visibility = (dom || ie) ? "visible" : "show";
			//panelSlide = setInterval("slideLocation()", 10);

			hideElement('SELECT', document.getElementById("LocationPopup"));
			hideElement('APPLET', document.getElementById("LocationPopup"));
		}
		else
		{
			hideLocationPopup();
			//showLocationPopup(ctl, align);
		}
	}
}

function slideLocation()
{
    if (locationObj.offsetHeight < panelHeight)
        locationStyleObj.height = (locationObj.offsetHeight + 10).toString() + "px";
    else
        clearInterval(panelSlide);
}

function toggleMoreOptions()
{
    var moreOptionsStyleObj = (dom) ? document.getElementById("MoreSearchOptions").style : ie ? document.all.MoreSearchOptions : document.MoreSearchOptions;
	var moreOptionsButtonObj = (dom) ? document.getElementById("MoreOptionsButton") : ie ? document.all.MoreOptionsButton : document.MoreOptionsButton;
	var moreOptionsImageObj = (dom) ? document.getElementById("MoreOptionsImage") : ie ? document.all.MoreOptionsImage : document.MoreOptionsImage;
	if (moreOptionsStyleObj.visibility == "hidden")
	{
	    moreOptionsStyleObj.visibility = (dom || ie) ? "visible" : "show";
	    moreOptionsStyleObj.display = "";
//	    moreOptionsButtonObj.innerHTML = "Less options";
//	    moreOptionsImageObj.src = "/Images/QuickNav/arrowUp.gif";
	}
    else
    {
	    moreOptionsStyleObj.visibility = "hidden";
	    moreOptionsStyleObj.display = "none";
//	    moreOptionsButtonObj.innerHTML = "More options";
//	    moreOptionsImageObj.src = "/Images/QuickNav/arrowDown.gif";
    }
}