/*
RULES FOR USE:
a) Add this javascript to you program
b) Create a DIV exactly as follows. This is the popup window. 
   You can change the height and width
	<DIV class="submenu" onMouseOver="clearTimeout(popupIntervalID)" onMouseOut="javascript:hidePopupTimer()" 
		onClick="javascript:hidePopup()" id="Popup" name="Popup" 
		style="border:1px solid; height:80; width:280; overflow:auto; z-index:2; position:absolute; top: 0px; left:-200px; visibility:hidden">
	</DIV>

c) For each pop-up you require.
   There is an IDMain for the main link and an IDSub for the DIV containing the specific menu
   If you use more than one pop-up, you must have a unique ID.
   i.e <a id="A001_Main" ... showPopup('A001')">
   	<div ... id="A001_Sub">

   Example:   	
	<a id="ID_Main" href="javascript:void(0)" onmouseout="hidePopupTimer();" 
					onClick="showPopup('ID')" xonmouseover="showPopup('ID')">
		Substitute you text here
	</a>						
	<div class="submenu" id="ID_Sub" style="Display:none">
		<table width="100%" height="100%" cellspacing="0" cellpadding="0" style="border:0px none" class="submenu">												
		<tr height="1" class="submenu"><td class="submenu" valign="top">
			<A onMouseOut="swapPopupMenu('out',this)" onMouseOver="swapPopupMenu('over',this)" class="submenu" href="javascript:alert('some action')" >
				Your link
			</A>
		</td></tr>
		<tr><td style="font-size:1px">&#160;</td></tr>
		</table>
	</div>
	
   If you require a click to open the pop-up, just remove the onmouseover in <a> (as shown above)

d) Notes:
   Uses the following CSS classes:
	A.submenu
	A.submenu:hover
	DIV.submenu
	TABLE.submenu
	TD.submenuover
	TD.submenu
*/
var popupIntervalID	

function hidePopupTimer() {
	clearTimeout(popupIntervalID)
	popupIntervalID = setTimeout("hidePopup()",250)
}
function hidePopup() {
	var obj = document.getElementById("Popup")
	obj.style.display = "none"
}

function getPopupPosition(pTag,pMinWidth,pOffsetWidth, pOffsetHeight) {
	var c=new Object();						
	var o=document.getElementById(pTag);	
	
	c.availHeight=600
	c.availWidth=800
	
	if (is_ie) {
		c.availHeight= document.body.clientHeight
		c.availWidth= document.body.clientWidth - 20 // take into account the scrollbar
	} else {
		try {	c.availHeight = window.innerHeight
			c.availWidth = window.innerWidth - 17 // take into account the scrollbar
		} catch (e) {}
	}

	c.height=o.offsetHeight; c.width=o.offsetWidth	
	c.x=o.offsetLeft; c.y=o.offsetTop;
	while ((o=o.offsetParent) != null) { c.x += o.offsetLeft; c.y += o.offsetTop; }	
	c.y -= pOffsetHeight	
	c.x += pOffsetWidth
	c.maxWidth = c.availWidth - c.x + 1
	if (c.maxWidth < pMinWidth) c.x = c.availWidth - pMinWidth;
	if (c.x < 0) c.x = 0;
	c.y += c.height
	
	return c;
}
function showPopupMenu(pMenuId, pSubMenuId, pOffsetWidth, pOffsetHeight) {	
	clearTimeout(popupIntervalID)
	var obj = document.getElementById("Popup")
	var zWidth = obj.style.width
	if (zWidth.substr(zWidth.length-2)=="px") zWidth = zWidth.substr(0,zWidth.length-2)
	obj.innerHTML = document.getElementById(pSubMenuId).innerHTML

	var objPos = getPopupPosition(pMenuId,zWidth, pOffsetWidth, pOffsetHeight)
	//Si on ne veut pas changer posX, deuxieme param=0
	
	// Centralise
	if (zWidth <= objPos.width) {
		try {objPos.x = objPos.x + Math.abs((zWidth - objPos.width)/2)} catch(e){}
	}

	obj.style.pixelLeft = objPos.x + 'px'
	obj.style.left = objPos.x
	obj.style.pixelTop = objPos.y + 'px'
	obj.style.top = objPos.y
	obj.style.display = ""	// Netscape bug causes scrollbar back to 0,0
}					
function showPopup(pId,pScrollName) {
	zOffsetHeight = 0
	zOffsetWidth  = 0
	if (pScrollName!='') {
		try {zOffsetHeight = document.getElementById(pScrollName).scrollTop} catch (e) {}
		try {zOffsetWidth  = document.getElementById(pScrollName).scrollLeft} catch (e) {}
	}
	
	showPopupMenu(pId+"_Main",pId+"_Sub",zOffsetWidth,zOffsetHeight); 
	window.status=' ';
	
	if (!is_ie) {
		if (pScrollName!='') {
			try {document.getElementById(pScrollName).scrollTop = zOffsetHeight} catch (e) {}
			try {document.getElementById(pScrollName).scrollLeft = zOffsetWidth} catch (e) {}
		}
	}
		
	return true;
}
function swapPopupMenu(pType, obj) {
	switch (pType) {
	case 'over':
		try {obj.parentElement.className="submenuover"} catch(e) {}
		break
	default:
		try {obj.parentElement.className="submenu"} catch(e) {}
		break
	}
}
