/*
http://www.dynamicdrive.com/dynamicindex5/overlapcontent.htm

Example usage:

<a href="#" onClick="return overlay(this, 'subContent')">Show Search Popup</a>

<!--Sub content to overlay link when clicked on. Do not remove outermost <div id="subContent"> tag below. -->
<DIV id="subContent" style="position:absolute; display:none">

<div style="border: 2px solid black; background-color: white; width: 300px; padding: 8px">
<p><b>Search Dynamic Drive:</b></p>
<form method="get" action="http://search.freefind.com/find.html" id="topform">
<input type="HIDDEN" NAME="id" SIZE="-1" VALUE="6299074" />
<input type="HIDDEN" NAME="pageid" SIZE="-1" VALUE="r" />
<input type="HIDDEN" NAME="mode" SIZE="-1" VALUE="ALL" />
<input type="HIDDEN" name="n" value="0">
<input name="query" maxlength="255" style="width: 150px" id="topsearchbox" alt="Search" /> 
<input value="Search" class="topformbutton" type="submit" />
</form>
<div align="right"><a href="#" onClick="overlayclose('subContent'); return false">Close</a></div>
</div>

</DIV>

<p><b><a href="search.htm" onClick="return overlay(this, 'subcontent2')">Another example</a></b><br /></p>

<!--Sub content to overlay link when clicked on. Do not remove outermost <div id="subcontent2"> tag below. -->
<DIV id="subcontent2" style="position:absolute; display:none">

<div style="border: 9px solid black; background-color: lightyellow; width: 400px; height: 400px; padding: 8px">
Some content. Some content.
<div align="right"><a href="#" onClick="overlayclose('subcontent2'); return false">Close</a></div>
</div>

</DIV>
*/

// *****
// NOTE: this requires the elementPositioning.js file be loaded already.
// *****

function showPopup(currentObject, divName, optional_position) {
	var popupElement = document.getElementById(divName);
	overlay(currentObject, popupElement, optional_position);
	hideShowOverlappingSelects(popupElement, true);
}

function closePopup(divName) {
	var popupElement = document.getElementById(divName);
	hideShowOverlappingSelects(popupElement, false);
	closeOverlay(popupElement);
}

function getposOffset(overlay, offsettype) {
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null) {
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}

	return totaloffset;
}

function overlay(curobj, subobj, opt_position) {
	if (document.getElementById) {
		var xpos = getposOffset(curobj, "left");
		var ypos = getposOffset(curobj, "top");

		if (typeof opt_position != "undefined") {
			if (opt_position.indexOf("right") != -1) {
				xpos = xpos - (subobj.offsetWidth - curobj.offsetWidth);
			}
			if (opt_position.indexOf("bottom") != -1) {
				ypos = ypos + curobj.offsetHeight + 1;
			}
		}

		subobj.style.left = xpos+"px";
		subobj.style.top = ypos+"px"
		subobj.style.display="block";
		return false;
	} else {
		return true;
	}
}

function closeOverlay(subobj) {
	subobj.style.display="none";
}


