var bNN4 = document.layers;
var bIE4 = document.all && document.all.item;
var bW3CDOM = document.getElementById;
var bDOMBrowser = bNN4 || bIE4 || bW3CDOM;
var timerID;
var tmd;
var menu_item_list = new Array;
var popup_menu_list = new Array;
var str = '';
var temp_top_level = '';
var dtr= '';
var img= '';
popup_menu_list[0] =new Array ("top_level",1);

function findPosX(obj)
{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
		curleft += obj.x;
		return curleft;
}

function findPosY(obj)
{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
}


function getObj(name)
{
	 if (document.getElementById)
	 {
		   this.obj = document.getElementById(name);
		   this.style = document.getElementById(name).style;
	 }
	 else if (document.all)
	 {
		   this.obj = document.all[name];
		   this.style = document.all[name].style;
	 }
	 else if (document.layers)
	 {
		   if (document.layers[name])
		   {
			this.obj = document.layers[name];
			this.style = document.layers[name];
		   }
		   else
		   {
			this.obj = document.layers.testP.layers[name];
			this.style = document.layers.testP.layers[name];
		   }
	 }

}



function setLyr(obj,lyr,typer,otstupfX,otstupfY)
{
		var newX = 0;
		var newY = 0;
		newX = findPosX(obj);
        newY = findPosY(obj);
		var x = new getObj(lyr);
		corX=0;
		corY=0;
		   if (document.all)
		   {
		   win_width = document.body.offsetWidth;
		   }
		   else if (document.layers)
		   {
		   win_width = window.innerWidth;
		   }
//		   alert(win_width)
		if(bDOMBrowser ==bW3CDOM)
			{
			if (typer=='down') {corX=0+otstupfX; corY=obj.offsetHeight+4+otstupfY;}
			if (typer=='right')
				{
					corX=obj.offsetWidth+otstupfX; corY=obj.offsetHeight+4-otstupfY;
				}
			if (typer=='left') {corX=0-document.getElementById(lyr).offsetWidth+otstupfX; corY=obj.offsetHeight+4-otstupfY;}
			if (typer=='up') {corX=0+otstupfX; corY=-document.getElementById(lyr).offsetHeight+4+otstupfY;}
			x.style.position = 'absolute';
			x.style.top = corY+newY+'px';
			x.style.left = corX+newX+'px';
			}
		else
			{
			if (typer=='down') {corX=-5+otstupfX; corY=obj.offsetHeight-17+otstupfY;}
			if (typer=='right')
				{
					corX=obj.offsetWidth+otstupfX; corY=obj.offsetHeight+4-otstupfY;
					zzz = corX+newX+document.getElementById(lyr).offsetWidth;
					if (zzz > win_width) corX=0-document.getElementById(lyr).offsetWidth+otstupfX; corY=obj.offsetHeight+4-otstupfY;
				}
			if (typer=='left') {corX=0-document.getElementById(lyr).offsetWidth+otstupfX; corY=obj.offsetHeight+4-otstupfY;}
			if (typer=='up') {corX=0+otstupfX; corY=-document.getElementById(lyr).offsetHeight+4+otstupfY;}
			x.style.position = 'absolute';
			x.style.top = corY+newY;
			x.style.left = corX+newX;
			}

}
function create_item(name, level, parent,img, text)
{
	menu_item_list[menu_item_list.length] = new Array(name,level,parent,img,text);
}

function create_array()
{
	for (i=0; i<menu_item_list.length; i++)
	{
	 	for (j=0; j<menu_item_list.length; j++)
		{
		 if  (menu_item_list[i][0] == menu_item_list[j][2])
		  {
	       menu_item_list[i][5] = "1";
	       j=menu_item_list.length;
	      }
	     else
	     {
   	       menu_item_list[i][5] = "0";
	     }
		}
	}
	last_menu_parant = '';
	str+="<div id=\"itm_"+menu_item_list[0][2]+"\" class=\"blockPopup\" style=\"visibility:hidden; width:110px;\"><table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"width:9px; height:9px; background-image:url(/img/popup1.gif); font-size:1px;\">&nbsp;</td><td style=\"height:9px; background-image:url(/img/popupborder.gif); background-color:#FAF1CB; background-position:top; background-repeat:repeat-x; font-size:1px;\"></td><td style=\"width:9px; height:9px; background-image:url(/img/popup2.gif); font-size:1px;\">&nbsp;</td> </tr><tr><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:left; background-repeat:repeat-y; font-size:1px;\">&nbsp;</td><td style=\"background-color:#FAF1CB;\">";
	for (i=0; i<menu_item_list.length; i++)
	{
	    if (menu_item_list[i][3] != '')  img = "<img src=\""+menu_item_list[i][3]+"\">";
	    else img = "&nbsp;&nbsp;&nbsp;";
		if ((last_menu_parant == menu_item_list[i][2]) || (last_menu_parant == ''))
		{   if ((menu_item_list[i][2] == "top_level") && (menu_item_list[i][1] == 2))
			{
				if (menu_item_list[i][5] == 1)
				temp_top_level+="<td width=\"11\" height=\"32\"><img id=\"img_"+menu_item_list[i][0]+"\" src=\"/img/menu1.gif\" width=\"11\" height=\"32\" border=\"0\" alt=\"\"></td><td class=\"menuItem2\" onMouseOver=\"show_popup_item_menu('"+menu_item_list[i][0]+"','down',"+menu_item_list[i][1]+");document.getElementById('img_"+menu_item_list[i][0]+"').src = '/img/menu1a.gif';document.getElementById('img2_"+menu_item_list[i][0]+"').src = '/img/menu3a.gif';document.getElementById('"+menu_item_list[i][0]+"').style.backgroundImage = 'url(/img/menu2a.gif)';\" onMouseOut=\"quit('"+menu_item_list[i][1]+"');\"  id=\""+menu_item_list[i][0]+"\">"+menu_item_list[i][4]+"</td><td width=\"11\" height=\"32\"><img id=\"img2_"+menu_item_list[i][0]+"\" src=\"/img/menu3.gif\" width=\"11\" height=\"32\" border=\"0\" alt=\"\"></td>";
				else
				temp_top_level+="<td width=\"11\" height=\"32\"><img id=\"img_"+menu_item_list[i][0]+"\" src=\"/img/menu1.gif\" width=\"11\" height=\"32\" border=\"0\" alt=\"\"></td><td class=\"menuItem2\" id=\""+menu_item_list[i][0]+"\" onMouseOver=\"hideall();document.getElementById('"+menu_item_list[i][0]+"').style.backgroundImage = 'url(/img/menu2a.gif)'; document.getElementById('img_"+menu_item_list[i][0]+"').src = '/img/menu1a.gif';document.getElementById('img2_"+menu_item_list[i][0]+"').src = '/img/menu3a.gif';\" onMouseOut=\"document.getElementById('img_"+menu_item_list[i][0]+"').src = '/img/menu1.gif';document.getElementById('"+menu_item_list[i][0]+"').style.backgroundImage = 'url(/img/menu2.gif)';document.getElementById('img2_"+menu_item_list[i][0]+"').src = '/img/menu3.gif';\">"+menu_item_list[i][4]+"</td><td width=\"11\" height=\"32\"><img id=\"img2_"+menu_item_list[i][0]+"\" src=\"/img/menu3.gif\" width=\"11\" height=\"32\" border=\"0\" alt=\"\"></td>";
			}
		    else
		    {
		        if (menu_item_list[i][5] == 1)
		        str+="<div onMouseOver=\"show_popup_item_menu('"+menu_item_list[i][0]+"','right',"+menu_item_list[i][1]+");\" onMouseOut=\"quit('"+menu_item_list[i][1]+"');\" id=\""+menu_item_list[i][0]+"\"><nobr>"+menu_item_list[i][4]+"</nobr></div>";
		        else
		    	str+="<div id=\""+menu_item_list[i][0]+"\" onMouseOver=\"hide_level("+menu_item_list[i][1]+")\"><nobr>"+menu_item_list[i][4]+"</nobr></div>";
		    }
			last_menu_parant = menu_item_list[i][2];
		}
		else
		{
	        str+="</td><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:right; background-repeat:repeat-y; font-size:1px;\"><img src=\"img/s.gif\" hight=\"1\" width=\"9\"></td></tr><tr><td style=\"width:9px; height:9px; background-image:url(/img/popup3.gif); font-size:1px;\">&nbsp;</td><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:bottom; background-repeat:repeat-x; font-size:1px;\"></td>    <td style=\"width:9px; height:9px; background-image:url(/img/popup4.gif); font-size:1px;\">&nbsp;</td></tr></table></div><div id=\"itm_"+menu_item_list[i][2]+"\" style=\"visibility:hidden; width:110px;\" class=\"blockPopup\" OnMouseOver=\"clrtimer();\"><table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"width:9px; height:9px; background-image:url(/img/popup1.gif); font-size:1px;\">&nbsp;</td><td style=\"height:9px; background-image:url(/img/popupborder.gif); background-color:#FAF1CB; background-position:top; background-repeat:repeat-x; font-size:1px;\"></td><td style=\"width:9px; height:9px; background-image:url(/img/popup2.gif); font-size:1px;\">&nbsp;</td> </tr><tr><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:left; background-repeat:repeat-y; font-size:1px;\"><img src=\"img/s.gif\" hight=\"1\" width=\"9\"></td><td style=\"background-color:#FAF1CB;\">";
	        img
	        if (menu_item_list[i][5] == 1)
	        str+="<div onMouseOver=\"show_popup_item_menu('"+menu_item_list[i][0]+"','right',"+menu_item_list[i][1]+");\" id=\""+menu_item_list[i][0]+"\">"+menu_item_list[i][4]+"</div>";
	        else
	    	str+="<div id=\""+menu_item_list[i][0]+"\">"+menu_item_list[i][4]+"</div>";
    		last_menu_parant = menu_item_list[i][2];
		}
	}
str+='</td><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:right; background-repeat:repeat-y; font-size:1px;\"><img src=\"img/s.gif\" hight=\"1\" width=\"9\"></td></tr><tr><td style=\"width:9px; height:9px; background-image:url(/img/popup3.gif); font-size:1px;\">&nbsp;</td><td style=\"height:9px; background-color:#FAF1CB; background-image:url(/img/popupborder.gif); background-position:bottom; background-repeat:repeat-x; font-size:1px;\"></td>    <td style=\"width:9px; height:9px; background-image:url(/img/popup4.gif); font-size:1px;\"><img src=\"img/s.gif\" hight=\"1\" width=\"9\"></td></tr></table></div>';
temp_top_level = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>"+temp_top_level+"</tr></table>";
document.getElementById('menu_table').innerHTML=temp_top_level;
document.getElementById('popup_menu_table').innerHTML=str;
}
function quit(level)
{
TimerId = setTimeout('hideall()', 200);
tmd = TimerId
}
function hideall()
{
    r = popup_menu_list.length-1;
    for (j=0; j<r; j++)
    {
		hidden_item_menu = popup_menu_list[popup_menu_list.length-1][0];
		hidden_item_menu_el = popup_menu_list.pop();
		visibleSelect(true, 'itm_'+hidden_item_menu);
		document.getElementById('img_'+hidden_item_menu).src = '/img/menu1.gif';
		document.getElementById('img2_'+hidden_item_menu).src = '/img/menu3.gif';
		document.getElementById(hidden_item_menu).style.backgroundImage = 'url(/img/menu2.gif)';
		document.getElementById('itm_'+hidden_item_menu).style.visibility='hidden';
	}
}
function hide_level(t)
{
    r = popup_menu_list.length;
    for (j=0; j<r; j++)
    {
		if (t <= popup_menu_list[j][1])
		{
			hidden_item_menu = popup_menu_list[j][0];
			hidden_item_menu_el = popup_menu_list[j].splice();
			document.getElementById('itm_'+hidden_item_menu).style.visibility='hidden';
      		visibleSelect(true, 'itm_'+hidden_item_menu);
		document.getElementById('img_'+hidden_item_menu).src = '/img/menu1.gif';
		document.getElementById('img2_'+hidden_item_menu).src = '/img/menu3.gif';
		document.getElementById(hidden_item_menu).style.backgroundImage = 'url(/img/menu2.gif)';
		document.getElementById('itm_'+hidden_item_menu).style.visibility='hidden';

        }
	}
}

function hide()
{
	hidden_item_menu = popup_menu_list[popup_menu_list.length-1][0];
	hidden_item_menu_el = popup_menu_list.pop();
	document.getElementById('itm_'+hidden_item_menu).style.visibility='hidden';
	visibleSelect(true, 'itm_'+hidden_item_menu);
		document.getElementById('img_'+hidden_item_menu).src = '/img/menu1.gif';
		document.getElementById('img2_'+hidden_item_menu).src = '/img/menu3.gif';
		document.getElementById(hidden_item_menu).style.backgroundImage = 'url(/img/menu2.gif)';
		document.getElementById('itm_'+hidden_item_menu).style.visibility='hidden';

}
function show_popup_item_menu(obj,typer,level)
{
	if ((popup_menu_list[popup_menu_list.length-1][0] != 'top_level') && (popup_menu_list[popup_menu_list.length-1][1] >= level)) hide_level(level);
   	timerID = tmd;
	clearTimeout(timerID);
	document.getElementById('itm_'+obj).style.visibility='visible';
	setLyr(document.getElementById(obj), 'itm_'+obj, typer, 0, 15);
	visibleSelect(false, 'itm_'+obj);
	if (popup_menu_list[popup_menu_list.length-1][0] != obj)
	popup_menu_list[popup_menu_list.length] = new Array (obj,level);
}
function shlapa()
{
	dtr = '';
	for (i=0; i<popup_menu_list.length; i++)
	{
	  dtr+=popup_menu_list[i][0]+' ';
    }
	alert(dtr);
}
function clrtimer()
{
	timerID = tmd;
	clearTimeout(timerID);
}
function stimer(level)
{
	timerID = setTimeout('hide('+level+')',1000);
	tmd = timerID;
}

function visibleSelect(state, givedata){

var obj;
var ok=false;
if (typeof(givedata)=='string'){
 obj=document.getElementById(givedata);
 if ((typeof(obj)=='object') && (obj!=null)) ok=true;
}else{
 if ((typeof(givedata)=='object') && (givedata!=null)){
  obj=givedata;
  ok=true;
 }
}

if (ok){
 var tmp=obj.offsetParent;
 moveX=0;
 moveY=0;
 while((typeof(tmp)=='object') && (tmp!=null) && (tmp!=window)){
  moveX+=tmp.offsetLeft;
  moveY+=tmp.offsetTop;
  tmp=tmp.offsetParent;
 }
 x1b=moveX+obj.offsetLeft;
 y1b=moveY+obj.offsetTop;
 x1e=x1b+obj.offsetWidth;
 y1e=y1b+obj.offsetHeight;
 var _span=document.createElement('SPAN');
 var _l=document.getElementsByTagName('SELECT');
 var n=_l.length;

 for(var i=0;i<n;i++){
  var tmp=_l[i].offsetParent;
  moveX=0;
  moveY=0;
  while((typeof(tmp)=='object') && (tmp!=null) && (tmp!=window)){
   moveX+=tmp.offsetLeft;
   moveY+=tmp.offsetTop;
   tmp=tmp.offsetParent;
  }
  x2b=moveX+_l[i].offsetLeft;
  y2b=moveY+_l[i].offsetTop;
  x2e=x2b+_l[i].offsetWidth;
  y2e=y2b+_l[i].offsetHeight;

  if (x2b<x1b) x2b=x1b;
  if (x2e>x1e) x2e=x1e;
  if (y2b<y1b) y2b=y1b;
  if (y2e>y1e) y2e=y1e;
  if ((x2b<=x2e) && (y2b<=y2e)){
   if (state){
    _l[i].style.visibility="visible";
   }else{
    _l[i].style.visibility="hidden";
   }
  }
 }
}
}
