/********************************/
/*** Pop-up menu component    ***/
/*** (c) REBEX CR s.r.o. 2001 ***/
/********************************/

// Configuration variables
var subMenuX = "100px";		// submenu X coordinate - fixed for all submenus.
						// WARNING - this value is being overwritten from ASP pages - see const SUB_MENU_SHIFT in functions.asp
var subMenuY = 0		// submenu Y coordinate - initialized by actual (cursorY - subMenuYShift) when submenu is opened
var subMenuYShift = 15	//  negative shift of submenu's top margin to menuitem's top margin
var subMenuCount = 0	// how many submenus are in the menu (should be incremented when adding menu)
var standStill=1500		// delay (in miliseconds) for automatic closing of submenu in NN


// AUX variables
var x,y					// actual cursor coordinates (updated by method handlerMM(e)
var timer				// timer for menu closing in NN
var yPos = new Array();	// array of yPositions of menu
var isLoaded = false;

function over(src,color)
{ 
	//if (!src.contains(event.fromElement))
	//{
    if(isLoaded)
    {
		src.style.cursor = 'pointer';
		src.style.background = color;
    }
	//}
}
function out(src, color) 
{ 
	//if (!event || !src.contains(event.toElement))
	//{
	if(isLoaded)
	{
		src.style.cursor = 'default';
		src.style.background = color;//color;
    }
	//}
}

function resetTimer(subMenuNR) {
    if(!isLoaded)
		return;
    clearTimeout(timer)
	timer=setTimeout("hideSubMenu("+subMenuNR+")",standStill)
}

function showSubMenu(subMenuNR) {
	if(!isLoaded)
		return;
	subMenuY=y;
	var i;
	var submenuId;
	var menuitemId;
	for (i=0; i<subMenuCount; i++) {
    /*
    if (document.all) {				// MSIE object model
			menuitem=eval("document.all.menuitem"+i)
			submenu=eval("document.all.submenu"+i+".style")
			if (subMenuNR == i) {
				over(menuitem,'#d7e3ec');
				submenu.posLeft=subMenuX
				if (yPos[i]==null) yPos[i] = subMenuY-subMenuYShift
				submenu.posTop=yPos[i]
				submenu.visibility="visible"
			}
			else {									// hide all other submenus
				out(menuitem,'#c1c1c1');
				submenu.visibility="hidden"
			}
		}
		if (document.layers) {			// Netscape object model
			resetTimer(subMenuNR)
			//submenu=eval("document.layers.submenu"+i)
			submenuId = "submenu" + i;
			submenu = document.getElementById(submenuId);
			if (subMenuNR == i) {
        /*
				submenu.left=subMenuX
				if (yPos[i]==null) yPos[i] = subMenuY-subMenuYShift
				submenu.top=subMenuY-subMenuYShift
				submenu.visibility="visible"
			}
			else									// hide all other submenus
				submenu.visibility="hidden"
		}
    */
    submenuId = "submenu" + i;
    menuitemId = "menuitem" + i;
    submenu = document.getElementById(submenuId);
    menuitem = document.getElementById(menuitemId);
    if (subMenuNR == i)
    {
      if (yPos[i]==null) yPos[i] = subMenuY-subMenuYShift
      submenu.style.left = "100px";
    	submenu.style.top= yPos[i];
     	submenu.style.visibility="visible";
     	submenu.style.display="block";
     	over(menuitem,'#d7e3ec');
    } else {
      submenu.style.visibility="hidden";
      submenu.style.display="none";
      over(menuitem,'#c1c1c1');
    }
  }
}

function hideSubMenu(subMenuNR) {
	if(!isLoaded)
		return;
		
 	var submenuId;
 	var menuitemId;
  submenuId = "submenu" + subMenuNR;
  menuitemId = "menuitem" + subMenuNR;
  submenu = document.getElementById(submenuId);
  menuitem = document.getElementById(menuitemId);
	out(menuitem, '#c1c1c1')
	submenu.style.visibility="hidden";
	submenu.style.display="none";
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = handlerMM;

function handlerMM(e){

  if(isLoaded==true)
  {
    if (IE) {
      x = event.clientX + document.body.scrollLeft
      y = event.clientY + document.body.scrollTop
    } else {
      x = e.pageX;
      y = e.pageY;
    }
    if (x < 0){x = 0}
    if (y < 0){y = 0}
  }
}
// encapsulates HTML code for submenu row
function wrtSMRow(content, link, actualMenuNr)	{
  document.write('<tr>');
	document.write('<td nowrap BGCOLOR=#d7e3ec onMouseOver="over(this,\'#f5f5f5\');" onMouseOut="out(this,\'#d7e3ec\');">');
	document.write('<a href="' + link + '" onMouseOver="resetTimer(' + actualMenuNr+ ');">' + content + '</a>');
	document.write('</td>');
	document.write('</tr>');
}

// ---------------------------------------------------------------------------------------

function MM_displayStatusMsg(msgStr)  { 
	status=msgStr; document.MM_returnValue = true;
}

function MM_findObj(n, d) {
  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); return x;
}

function MM_swapImage() {
  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];}
}

function MM_swapImgRestore() {
  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() { 
 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];}}
}