/*
 * Popup window management. Page must have a dedicated div
 * with at least following style :
 *	div.popup {
 *		visibility: hidden;
 *		position: fixed;
 *	}
 * Its id must be "popupbox" :
 *   <div class="popup" id="popupbox"></div>
 * Div popupbox will contain fist a paragraph with class title
 * to figure a window banner
 */

/**
 * search for div element by id
 * @param id id of div to search for
 * @return the first div found, null if none
 */
function getdivelem(id) {
	var popupelem=null;
	var divlist=document.getElementsByTagName("div");
	for (var i=0;i<divlist.length&&popupelem==null;i++) {
		var elem=divlist[i];
		if (elem.id==id) {
			popupelem=elem;
		}
	}
	return popupelem;  
}
/**
 * copy content of given div to popup div and show it.
 * @param contentid id of source data div
 */
function show_popup(contentid) {
	var popupelement=null;
	try {
		/* internet explorer (tested IE OK 6.0) */
		popupelem=popupbox;
		popupbox.style.position="absolute";
		popupelem.style.top = document.body.scrollTop+20;
	} catch (Exception) {
		/* mozilla/firefox */
		popupelem=getdivelem("popupbox");  
	}
	var contentElem=getdivelem(contentid);
	var content="";
	if (contentElem!=null) {
		content=contentElem.innerHTML;
	}	
	popupelem.innerHTML = 
		"<p class='title'><a href='javascript:hide_popup()'>[X]</a></p>"
		+content;  
	popupelem.style.left = "20%";
	popupelem.style.width = "30%";
	popupelem.style.visibility = "visible";
} 
/**
 * hide popup
 */
function hide_popup() {
	var popupelem=getdivelem("popupbox");  
	popupelem.innerHTML = "";  
	popupelem.style.visibility = "hidden";
}
