/*      NAME:  g_menu_js.js
 *   PURPOSE:  Generic data functions
 *   HISTORY:  2.0, 2007-06-05
 *
 */

/*
var MN_BG 	  = '<?=$GLOBALS['BG_MENU']?>';
var MN_SUBMENU_BG = '<?=$GLOBALS['BG_SUBMENU']?>';
*/

MnIsOver=0; OpId = ''; OpId2 = ''; 

function getLeft(This){
  var el = This;var pL = 0;
  while(el){pL+=el.offsetLeft;el=el.offsetParent;}
  return pL;
}
function getTop(This){
  var el = This;var pT = 0;
  while(el){pT+=el.offsetTop;el=el.offsetParent;}
  return pT;
}
function MnFrame(obj,stat)
{
  var Ifr = document.getElementById('mnfr').style;
  if(stat) {
    Ifr.top  = getTop(obj); 
    Ifr.left = getLeft(obj);
    Ifr.width = obj.offsetWidth; 
    Ifr.height = obj.offsetHeight;
    Ifr.zIndex = obj.style.zIndex;
    Ifr.visibility = "visible";
  }
  else 
    Ifr.visibility = "hidden";
}
function MnShow(mnid) {
  MnHide();
  for (t=4; t< mnid.length; t+=2) {
    Mn = document.getElementById(mnid.substr(0,t) + '00');
    if (document.all) MnFrame(Mn,true);
    Mn.style.visibility = "visible";
  }
  MnPos=mnid;
  Mn = document.getElementById(mnid.substr(0,4));
  Mn.style.backgroundColor = MN_SUBMENU_BG;
  if (mnid.substr(0,4) != OpId.substr(0,4)) OpId = OpId2 = '';
  if (OpId.substr(0,2) == 'mn') {
    Mn = document.getElementById(OpId + '00');
    if (document.all) MnFrame(Mn,true);
    Mn.style.visibility = "visible";
  }
  if (OpId2.substr(0,2) == 'mn') {
    Mn = document.getElementById(OpId2 + '00');
    if (document.all) MnFrame(Mn,true);
    Mn.style.visibility = "visible";
  }
}
function MnHide() {
  var path_t =new Array(); var path_op = new Array();
  op=''; t=1; 
  for (; t < 100; t++) {
    if (t<10) op_c=op+'0'+t; else op_c=op+t;
    if ((obj=document.getElementById('mn'+op_c)) != null) {
 	if (op_c.length == 2) obj.style.backgroundColor = MN_BG;
 	obj=document.getElementById('mn'+op_c+'00');
	obj.style.visibility = 'hidden';
        if (document.all) MnFrame(obj,false);
	path_t.push(t); path_op.push(op);
	t=0; op=op_c; 
    }
    else if (document.getElementById('op'+op_c) == null) {
	if (path_t.length == 0) return;
	t=path_t.pop(); op=path_op.pop(); 
    }
  }
}
function MnOver()    { MnIsOver=1; }
function MnNotOver() { MnIsOver=0; }
function MnHideIf()  { if (MnIsOver==0) MnHide(); }
function MnOut()     { MnIsOver=0; MnHide(); }

function OpShow(obj) {
  MnHide();
  obj.style.backgroundColor=MN_SUBMENU_BG;
}
function OpHide(obj) {
  obj.style.backgroundColor=MN_BG;
}
function OpIn(obj) { 
 Op0 = obj.id.substr(2,obj.id.length-4);
 for (t= 1; t < 100; t++) {
    if (t<10) Op=Op0+'0'+t; else Op=Op0+t;
    if (((obj2=document.getElementById('op'+Op)) == null) &&
	((obj2=document.getElementById('mn'+Op)) == null)) 
       break;
    obj2.style.backgroundColor = MN_SUBMENU_BG;
  }
  obj.style.backgroundColor = MN_BG;
  if (obj.id.length == 6) OpId = obj.id; 
  else if (obj.id.length == 8) OpId2 = obj.id;
  if (obj.id.substr(0,2) == 'mn') MnShow(obj.id + '00');
}