/**
 * Memorix javascript functions
 * @package Memorix 4 Mambo
 * @Copyright (c) 2003 - Pictura Database Publishing bv
 * @version 1.0
 */

function popUpWin(URL, width, height) {
    LeftPosition=(screen.width)?(screen.width-width)/2:100;
    TopPosition=(screen.height)?(screen.height-height)/2:100;
    PopUpWin = window.open(URL,'WindowWithoutButtons', 'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1');
    PopUpWin.opener.name = 'opener';
    PopUpWin.focus()
}



/**
 * Image swap functions, used for the action buttons
 *
 */
 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



/**
 * OptionMenu-Lite v0.1
 *		writen by: 		me@daantje.nl
 * 		filename: 		OptionMenu-Lite.js
 *		last update: 	Tue Oct 28 21:47:53 CET 2003
 *
 *	Documentation:
 *		This file contains the script to handle a simple
 *		option menu with dynamic/variable content.
 *
 *	License:
 *		Free for everyone but SCO. For SCO employees it's
 *		$10.000.000,- per char.
 */


///////////////////////////////////////////////////////////////////////
//
//   D E C L A R E   G L O B A L S
//
///////////////////////////////////////////////////////////////////////

//declare vars we need!
var oml_config = new Array();
var oml_menu = new Array();
var oml_tmr = null;


///////////////////////////////////////////////////////////////////////
//
//   F U N C T I O N S   T O   C A L L
//
///////////////////////////////////////////////////////////////////////

/**
* initOptionMenu()
*	Build all stuff we need to use this menu.
*	Useualy called on onLoad...
*/
function initOptionMenu(){
	//no conrainer? write line with container...
	if(!document.getElementById('optionMenuContainer'))
		document.writeln('<div id=optionMenuContainer style="top:100px;z-index:10000;visibility:hidden;position:absolute;" onMouseover="showOptionMenu(false);" onmouseout="hideOptionMenu();">menu</div>');
}


/**
* showOptionMenu(OBJECT obj, STRING menu)
*	Pop menu under the object 'obj'...
*	When the object is set 'false', the current
*	popped menu will be set visible again, even
*	after a hideOptionMenu() call.
*/
function showOptionMenu(obj,menu){
	//gen new menu?
	if(menu)
		lastmenu = menu;

	//begin...
	if(oml_menu[lastmenu].length > 0){
		//build menu items...
		str = "<table border='0' cellspacing='0' cellpadding='1' class=omlBlockStyle>";
		for(i=0;i<oml_menu[lastmenu].length;i++){
			p = oml_menu[lastmenu][i].split('^');
			str+= "<tr><td id=item" + i + " class=omlItemStyle onclick=\"_oml_doClick('" + lastmenu + "'," + i + ")\" onmouseover=\"this.setAttribute('bgcolor',oml_config['mouseOver'],0);\" onmouseout=\"this.setAttribute('bgcolor',oml_config['mouseOut'],0);\" bgcolor='" + oml_config['mouseOut'] + "'>" + p[0] + "</td></tr>";
		}
		str+= "</table>";

		//placement of container
		oml_container = document.getElementById('optionMenuContainer');
		if(oml_container){
			if(obj){
				//set position
				//t = _oml_getRealPos(obj,'top') + obj.offsetHeight - 10; // from the bottom
				t = _oml_getRealPos(obj,'top') - (obj.offsetTop / 2); //from the middle...
				oml_container.style.top = t + 'px'; //NEEDS px IN MOZILLA!!!
				l =  _oml_getRealPos(obj,'left'); // obj.offsetWidth
				oml_container.style.left = l + 'px';

				//set menu content
				oml_container.innerHTML = str;

				//make it visible
				oml_container.style.visibility = 'visible';
			}
			_oml_clearDelay(); //kill timeout...
		}else{
			alert('Developer error!\n\nYour HTML file has not called \'initOptionMenu()\'.\nPlease call this at the bottom of your HTML.');
		}
	}else{
		alert('Developer error!\n\nMenu config for \''+menu+'\' is not defined.\nPlease set the \'oml_menu[\''+menu+'\']\' array.');
	}
}


/**
* hideOptionMenu()
*	Hide current poped menu...
*/
function hideOptionMenu(){
	if(oml_tmr){
		oml_container = document.getElementById('optionMenuContainer');
		oml_container.style.visibility = 'hidden';
		_oml_clearDelay();
	}else{
		_oml_delay();
	}
}


///////////////////////////////////////////////////////////////////////
//
//   I N T E R N A L   F U N C T I O N S
//
///////////////////////////////////////////////////////////////////////


/**
* _oml_doClick(STRING label, INT id)
*	Determin clicked link from config and do it...
*/
function _oml_doClick(label,id){
	p = oml_menu[label][id].split('^');
	if(!p[2])
		self.location.href = p[1]; //no target given
	else
		p[2].location.href = p[1]; //given JS target...
}


/**
* _oml_clearDelay()
*	Internal function, used in other functions.
*	Reset hiding timer, so we can use the timer again.
*	Also used to unset initialised hider, so the popup
*	stayes on, even after we have called the
*	hideOptionMenu() function...
*/
function _oml_clearDelay(){
	clearTimeout(oml_tmr);
	oml_tmr = null;
}


/**
* _oml_delay()
*	Internal function, used in other functions.
*	Delay popup hiding
*/
function _oml_delay(){
	if(oml_tmr)
		_oml_clearDelay();
	oml_tmr = setTimeout('hideOptionMenu()',oml_config['delayTime']);
}


/**
* INT position = _oml_getRealPos(OBJECT obj, STRING what)
*	Returns the position of the object 'obj' on this page.
*	'what' can be filled with 'left' or 'top' to get the
*	mesurements you need. Mesurements are in pixels.
*/
function _oml_getRealPos(obj,what){
	w = null;
	if(what.toLowerCase()=='left')
		w = 'Left';
	else if(what.toLowerCase()=='top')
		w = 'Top';

	if(w){
		eval('newPos = obj.offset' + w + ';');
		tmpObj = obj.offsetParent;
		while(tmpObj != null) {
			eval('newPos+= tmpObj.offset'+ w +';');
			tmpObj = tmpObj.offsetParent;
		}
		return newPos;
	}else{
		return false;
	}
}

