//****************************************************************************
// Copyright PROCIT B.V., The Netherlands, 2005
// The Netherlands
// info@procit.com

// This program is the intellectual property of Procit B.V., The Netherlands ("Procit").
// The program may be used, modified and/or copied only with the written permission of
// Procit or in accordance with the terms and conditions stipulated in the
// agreement/contract under which the program has been supplied.
//****************************************************************************

//****************************************************************************
//Project              : Intrum Justitia
//File                 : guiMenupages.js
//Description          : JS for Menu component
//****************************************************************************
//History
//
//
//Comments
// 
//****************************************************************************

var g_lngMenuPages_Current = -1;

function switchMenuPages(lngNewItem)
{
  var objTr;
  
  if (g_lngMenuPages_Current != -1) {
    objTr = eval('menugroup' + g_lngMenuPages_Current);
    
    objTr.style.display = 'none';
  }
  
  g_lngMenuPages_Current = lngNewItem;
  
  objTr = eval('menugroup' + g_lngMenuPages_Current);
  
  objTr.style.display = '';
}

function buildMenu()
{
  var element = tableMenu;
  var templateTd = element.children(0).cloneNode(false);
  var i;
  var newTd;

  while (element.children.length > 3)
    element.deleteCell(0);

  for (i = 0; i < arrMenu.length; i++) {
    newTd = templateTd.cloneNode(false);
    newTd.insertAdjacentHTML("afterBegin", arrMenu[i][0]);
    newTd.menuItem = i;
    
    element.insertBefore(newTd, element.children(element.children.length - 3));
  }
}

function Gui_BarMenuClick(item)
{
  if (g_blnLoaded != true)
    return;
    
	var menuItem = arrMenu[item.menuItem][1];
	var x = 0, y = 0, v;
	
	g_objItemThatOpened = item;
	
	v = item;
	for (;;) {
	  x += v.offsetLeft;
	  y += v.offsetTop;
	  if (v == document.body)
	    break;
	  v = v.offsetParent;
	}
	showMenu(x + 5, y + item.offsetHeight + 2, arrMenu[item.menuItem][2], menuItem);
}

function fnOpenSearch()
{
	window.open('organisation-search-main.asp','winOrgSrc','menubar=no,resizable=yes');
}

var g_objPopup = window.createPopup();
var g_objItemThatOpened = null;

function showMenu(x, y, width, arrMenu)
{
  var strContents, i, lngBars = 0;
  
  strContents = '<table style="border: solid 1px silver; background-color: f1f1f1;" cellspacing="0" cellpadding="0" id="menu" width="100%">';
  for (i = 0; i < arrMenu.length; i++) {
    if (arrMenu[i] == '-') {
      strContents += '<tr><td style="margin: 0px 0px 0px 0px; font-family: Tahoma; font-size: 8pt;"><hr noshade color="silver"></td></tr>';
      lngBars = lngBars + 1;
    } else 
    {
      strContents += '<tr><td style="border: solid 1px #f1f1f1; padding: 1px 3px 2px 3px; font-family: Tahoma; font-size: 8pt; cursor: default;" onclick="top.menuframe.g_objPopup.hide(); top.mainframe.document.location = \'' + arrMenu[i].split('\t')[1] + '\'; " onmouseover="javascript:this.style.backgroundColor=\'#cccccc\'; this.style.border=\'solid 1px #999999\';" onmouseout="javascript:this.style.backgroundColor=\'#f1f1f1\'; this.style.border=\'solid 1px #f1f1f1\';">' + arrMenu[i].split('\t')[0] + '</td></tr>';
    }
  }
  strContents += '</table>';
  
  var objBody = g_objPopup.document.body;
  objBody.style.backgroundColor = '#ffffe1';
  // objBody.style.border = 'solid 1px black';
  objBody.style.fontFamily = 'Tahoma';
  objBody.style.fontSize = '8pt';
  objBody.vLink = 'blue';
  objBody.aLink = 'blue';
  objBody.innerHTML = strContents;
  g_objPopup.show(x, y, width, 2+(18*arrMenu.length)-(lngBars*2), document.body);
}

function Gui_BarMenuOver(item, showMenu)
{
  item.style.backgroundColor='#7CC0CE';
  item.style.border='solid 1px #7CC0CE';
  
  if (g_objPopup.isOpen && g_objItemThatOpened != item) {
    g_objPopup.hide();
    if (showMenu)
      Gui_BarMenuClick(item);
  }
}

function Gui_BarMenuOut(item)
{
  item.style.backgroundColor='#2295AC';
  item.style.border='solid 1px #2295AC';
}



