// A reference to the currently-displayed popup window
var mdivPopup = null;

/*******************************************************************************
 * Displays a popup window with the specified HTML contents.  The anchorElement
 * parameter specifies the element to which the popup is positioned.
 ******************************************************************************/
function showPopup(anchorElement, spTITLE, spDEFINITION) {
	try {
		// Remove any existing popups
		if (mdivPopup != null)
			forceHidePopup();
			
		// Create the popup 
		mdivPopup = document.createElement('div');
		mdivPopup.style.position = 'absolute';
		mdivPopup.style.width = '250px';
		mdivPopup.onmouseout = hidePopup;

		
		var text = '<div class="sdpopup"><span style="padding-left: 5px;" class="title" id="top">' + spTITLE + '</span><div class="submenu">' + spDEFINITION + '</div></div>';
		mdivPopup.innerHTML = text; /*"<table width='100%' cellpadding='2' cellspacing='1' border='0' class='forumline'><tr><th class='catHead' height='25'><span class='genmed'><b><font color='white'>"+spTITLE+"</font></b></span></th></tr><tr><td class='row1' align='left'><span class='gensmall' style='line-height:150%'>"+spDEFINITION+"</span></td></tr></table>";*/
		
		// Position the popup
		mdivPopup.style.top = (getAbsoluteTop(anchorElement) + anchorElement.offsetHeight + 5) + 'px';
		mdivPopup.style.left = (getAbsoluteLeft(anchorElement) - 10) + 'px';
		
		// Show the popup
		document.body.appendChild(mdivPopup);
	}
	catch (x) {} 
}


/*******************************************************************************
 * Hides a popup window that was shown via the showPopup function.  If the mouse
 * cursor is over the popup window, it is not hidden.
 ******************************************************************************/
function hidePopup() {
	try {
		if (mdivPopup != null) {
			// if (!isUnderCursor(mdivPopup))
				forceHidePopup();
		}
	}
	catch (x) {}
}


/*******************************************************************************
 * Hides a popup window that was shown via the showPopup function, regardless of
 * whether the cursor is still over the popup window.
 ******************************************************************************/
function forceHidePopup() {
	try {
		if (mdivPopup != null) {
			document.body.removeChild(mdivPopup);
			mdivPopup = null;
		}
	}
	catch (x) {}
}


/*******************************************************************************
 * Provides a safe way to obtain an element reference.
 ******************************************************************************/
function safeGetElement(elementID) {
	try {
		return document.getElementById(elementID);
	}
	catch (x) {
		return null;
	}
}


/*******************************************************************************
 * Toggles the display property of the specified HTML element
 ******************************************************************************/
function toggleDisplay(element) {
	try {
		element.style.display = element.style.display == 'none' ? '' : 'none';
	}
	catch (x) {}
}


/*******************************************************************************
 * Toggles the visibility property of the specified HTML element
 ******************************************************************************/
function toggleVisibility(element) {
	try {
		element.style.visibility = element.style.display == 'visible' ? 'hidden' : 'visible';
	}
	catch (x) {}
}


/******************************************************************************
 * Returns true if the mouse cursor is currently over the specified element;
 * otherwise, returns false.
 *****************************************************************************/
function isUnderCursor(element) {
	try {
		var intTop = getAbsoluteTop(element) - document.body.scrollTop;
		var intLeft = getAbsoluteLeft(element) - document.body.scrollLeft;
		var intBottom = intTop + element.offsetHeight + 1;
		var intRight = intLeft + element.offsetWidth + 1;
		
		if (((event.clientX >= intLeft) && (event.clientX <= intRight))
		&& ((event.clientY >= intTop) && (event.clientY <= intBottom)))
			return true; 
		else
			return false; 
	}
	catch (x) {}
}


/******************************************************************************
 * Returns the absolute position of the left edge of the specified element.
 *****************************************************************************/
function getAbsoluteLeft(element) {
	try {
		var intLeft = 0;
		var objParent = element;
		
		do {
			intLeft += objParent.offsetLeft;
			objParent = objParent.offsetParent;
		}
		while (objParent != null);
		
		return intLeft; 
	}
	catch (x) {}
}


/******************************************************************************
 * Returns the absolute position of the top edge of the specified element.
 *****************************************************************************/
function getAbsoluteTop(element) {
	try {
		var intTop = 0;
		var objParent = element;

		do {
			intTop += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		while (objParent != null);
		
		return intTop; 
	}
	catch (x) {}
}


/******************************************************************************
 * Hides all windowed elements that are beneath the specified element.
 *****************************************************************************/
function hideOverlappingWindowedElements(element) {
	hideOverlappingElements(element, "select");
	hideOverlappingElements(element, "applet");
	hideOverlappingElements(element, "iframe");
	hideOverlappingElements(element, "object");
}


/******************************************************************************
 * Makes all windowed elements visible.
 *****************************************************************************/
function showWindowedElements() {
	showElements("select");
	showElements("applet");
	showElements("iframe");
	showElements("object");
}


/******************************************************************************
 * Hides all elements with the specified tagName that that overlap the 
 * specified element.
 *****************************************************************************/
function hideOverlappingElements(element, tagName) {
	try {
		var intElementTop = getAbsoluteTop(element) - document.body.scrollTop;
		var intElementLeft = getAbsoluteLeft(element) - document.body.scrollLeft;
		var intElementBottom = intElementTop + element.offsetHeight;
		var intElementRight = intElementLeft + element.offsetWidth;

		var arrElements = document.getElementsByTagName(tagName);
		for (var i = 0; i < arrElements.length; i++) {
			var intSelectTop = getAbsoluteTop(arrElements[i]) - document.body.scrollTop;
			var intSelectLeft = getAbsoluteLeft(arrElements[i]) - document.body.scrollLeft;
			var intSelectBottom = intSelectTop + arrElements[i].offsetHeight;
			var intSelectRight = intSelectLeft + arrElements[i].offsetWidth;
	  
			if (((intElementTop <= intSelectBottom) && (intElementBottom >= intSelectTop))
			&& ((intElementLeft <= intSelectRight) && (intElementRight >= intSelectLeft)))
				arrElements[i].style.visibility = "hidden";
		}
	}
	catch (x) {}
}


/******************************************************************************
 * Makes all elements with the specified tagName visible.
 *****************************************************************************/
function showElements(tagName) {
	try {
		var arrElements = document.getElementsByTagName(tagName);
		for (var i = 0; i < arrElements.length; i++) {
			arrElements[i].style.visibility = "visible";
		}
	}
	catch (x) {}
}


/*
Search clear form
*/
var has_clicked = false;
function clearSearch()
{
	if (!has_clicked)
	{
		document.searchform.search.value = "";
		has_clicked = true;
	}
}

var has_clicked_page = false;
function clearSearchPage()
{
	if (!has_clicked_page)
	{
		document.searchformpage.search.value = "";
		has_clicked_page = true;
	}
}

