var menuparent=new Array();
var menuid=new Array();
var popoldmousemove;
var inhandle=false;
var menuparentAA=new Array();
var menuidAA=new Array();
var popoldmousemoveAA;
var inhandleAA=false;
var rasi=false
function getwinw()
{
 if (!document.all) {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 else
 {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
return winW; 
}
function getwinH()
{
 if (!document.all) {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 else
 {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
return winH; 
}

function findPosAB(obj) {
	var curleft = curtop =0;
	cx=obj.offsetHeight;
	cy=obj.offsetWidth
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	curtop += cx;
	curleft+=cy
	return [curleft,curtop];
}

function display_menuAA2(parent,named,flag)//row,element
{
	//get the named menu
	var menu_element = document.getElementById(named);
	menuidAA=named;
	menuparentAA=parent;
	//override the 'display:none;' style attribute
	menu_element.style.display ="";
	//get the placement of the element that invoked the menu...
	var r=menu_element.offsetWidth;
	if(flag)
	{
	var placement = findPosAB(parent);
    menu_element.style.left = placement[0]-r + "px";
    }
	else
	{
	var placement = findPosAA(parent);
	//...and put the menu there
	menu_element.style.left = placement[0] + "px";
	}
	menu_element.style.top = placement[1]-128 + "px";
	
  popoldmousemoveAA=document.onmousemove;
	document.onmousemove = HandleMousemoveAA;

}
function display_menuAA(parent,named)//row,element
{
	//get the named menu
	var menu_element = document.getElementById(named);
	menuidAA=named;
	menuparentAA=parent;
	//override the 'display:none;' style attribute
	menu_element.style.display ="";
	//get the placement of the element that invoked the menu...
	var placement = findPosAA(parent);
	//...and put the menu there
	menu_element.style.left = placement[0] + "px";
	menu_element.style.top = placement[1] + "px";
  popoldmousemoveAA=document.onmousemove;
	document.onmousemove = HandleMousemoveAA;

}

function display_menuAA3(parent,named)//row,element
{

	//get the named menu
	var menu_element = document.getElementById(named);
	menuidAA=named;
	menuparentAA=parent;
	//override the 'display:none;' style attribute
	menu_element.style.display ="";
	//get the placement of the element that invoked the menu...
	var placement = findPosAA(parent);
	//...and put the menu there
	menu_element.style.left = placement[0] + "px";
	var windowW=document.body.offsetWidth
	var windowH=document.body.clientHeight+document.body.scrollTop
	//alert(placement[0]+300)
	if(placement[0]+300>windowW)
	{
	menu_element.style.left=placement[0]-235 + "px";
	}
	
	menu_element.style.top = placement[1] + "px";
	
	if(parseInt(placement[1]+menu_element.offsetHeight)>parseInt(windowH))
	{
	
	menu_element.style.top=placement[1]-menu_element.offsetHeight + "px";
	}
  popoldmousemoveAA=document.onmousemove;
	document.onmousemove = HandleMousemoveAA;

}

function findPosAA(obj) {
	var curleft = curtop =0;
	cx=obj.offsetHeight;
	cy=obj.offsetWidth
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	curtop += cx;
	
	return [curleft,curtop];
}


function findPos(obj,under,menu) {
	var curleft = curtop =0;
	cx=obj.offsetWidth;
	cy=obj.offsetHeight;
	var mx=menu.offsetWidth
	var my=menu.offsetHeight
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		 {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	if (under)
	{curtop += cy;

  if (curleft+mx>getwinw())
  {curleft=getwinw()-mx-20}
 
  }
	else
	{curleft += cx;}
	
  if ((curtop+my>getwinH())&& (rasi==true))
    {
    curtop=curtop-(my*0.75)}
  if (curtop<0){curtop=0}
 //alert(curtop)
	return [curleft,curtop];
}

//Display a named menu, at the position of another object
function display_menu(parent,named,under,rasit)
{
rasi=rasit
//alert(rasi)
	//get the named menu
	var menu_element = document.getElementById(named);
	for (var i=0;i<menuid.length;i++)
	{if (menu_element==menuid[i]) return }
	
  //override the 'display:none;' style attribute
	menu_element.style.display = "";
	//get the placement of the element that invoked the menu...
	var placement = findPos(parent,under,menu_element);
	//...and put the menu there
	menu_element.style.left = placement[0] + "px";
	menu_element.style.top = placement[1] + "px";
  popoldmousemove=document.onmousemove;
	document.onmousemove 	= HandleMousemove;
  menuid[menuid.length]=menu_element;
	menuparent[menuparent.length]=parent;
	
}
function display_menu11(parent,named,under)
{
	//get the named menu
	
	var menu_element = document.getElementById(named);
	for (var i=0;i<menuid.length;i++)
	{if (menu_element==menuid[i]) return }
	
  //override the 'display:none;' style attribute
	menu_element.style.display = "";
	//get the placement of the element that invoked the menu...
	var placement = findPos(parent,under,menu_element);
	//...and put the menu there
	menu_element.style.left = placement[0] -5+ "px";
	menu_element.style.top = placement[1] + "px";
	
}

//Hide a named menu
function hide_allmenu(frm)
{
if(frm==0)
{
mclikOutCt();
}
for (i=frm;i<menuid.length;i++)
{
var menu_element=menuid[i];
if (menu_element)
{menu_element.style.display = "none";}
}
menuid.length=frm;
menuparent.length=frm;

}


function mclikOutCt()
{

var t=trim(curtree.split("|")[0])
//alert(t)
var ct;
var i;
   // if(curtree.indexOf("|")==-1)
   // {
        for (i=1;i<moneC+1;i++)
        {
       // alert(moneC)
        ct='ANC'+i;
        var ct2=trim(document.getElementById(ct).innerHTML.split("(")[0].split(">")[1])
        //alert(ct)
            if(t!=ct2)
            {
            document.getElementById(ct).className="categorR"
            document.getElementById(ct).style.backgroundColor='#ffffff'
            }
            else
            document.getElementById(ct).style.backgroundColor='#eeeeee'
        
        }
   // }
    }
    
function hide_menu(tgid)
{
alert("one")
	//get the named menu
	var menu_element = document.getElementById(menuid[menuid.length-1]);
	alert(menuid[menuid.length-1]+':'+tgid.parentNode);
	
	//hide it with a style attribute
	menu_element.style.display = "none";
//alert(menuparent.length);
	menuparent.length=menuparent.length-1;
//alert('after '+menuparent.length);	
	menuid.length=menuparent.length;
	
	//menuid='nothing';
	if (menuparent.length==0)
	{document.onmousemove 	= null;}//popoldmousemove;

	
}

function whatmenuchild(tg)
{
var i;
while (tg.parentNode &&tg.nodeName != 'BODY')
{
for (i=0;i<menuid.length;i++)
{if (menuid[i]==tg) {return i} 
}
tg= tg.parentNode;
}
return-1;

}
function isparent(tg,prnt)
{
while (tg.parentNode &&tg.nodeName != 'BODY')
{
if (tg==menuparent[prnt]) {return true};
 tg=tg.parentNode;
}
return false;
}
var mm=0;



	
function oHandleMousemove(e) {
if (inhandle) {return}
inhandle=true;
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	var sender=tg;
while (menuparent.length>0)
{	
var menutg=document.getElementById(menuid[menuid.length-1]);
	if (tg==menuparent[menuparent.length-1]){inhandle=false; return}
//while ((reltg != menutg) && (reltg.nodeName != 'BODY'))
while (tg.parentNode &&tg.nodeName != 'BODY'&& (tg.id!= menutg.id))
{alert(tg.id);tg= tg.parentNode;}
if (tg==menuparent[menuparent.length-1]){inhandle=false; return}

if ((!tg) ||(tg.id!= menutg.id)) {hide_menu(sender,tg)}
else
{inhandle=false;return}
}
	
	/*if (tg.nodeName != 'DIV') return;
	return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	// Mouseout took place when mouse actually left layer
	// Handle event
*/
inhandle=false;
}

//document.onmousemove 	= HandleMousemove;

//TIMER
var timerID = 0;

function UpdateTimer() 
{
   
    //alert("t")
    hide_allmenu(mm);      
 clearTimeout(timerID);
      clockID  = 0;

 } 
 
 
 function HandleMousemove(e) {

if (menuparent.length<1) {return}

	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;

if (isparent(tg,0)){return}

n=whatmenuchild(tg)
if (n==-1) {  mm=0; timerplay();}
else
if (!isparent(tg,n+1)) {  mm=n+1; timerplay(); }
} 
 
 function HandleMousemoveAA(e) {
var menutg=document.getElementById(menuidAA);
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg==menuparentAA){return}
//while ((reltg != menutg) && (reltg.nodeName != 'BODY'))

while (tg.parentNode &&tg.nodeName != 'BODY'&& (tg.id!= menutg.id))
{	tg= tg.parentNode;}
if ((!tg) ||(tg.id!= menutg.id)) {hide_menuAA(menuidAA);}
	}

function hide_menuAA(named)
{
	//get the named menu
	var menu_element = document.getElementById(named);
	//hide it with a style attribute
	menu_element.style.display = "none";
	menuparentAA=null;
	menuidAA='nothing';
	document.onmousemove 	= null;//popoldmousemove;

	
}
	
function timerplay() {
UpdateTimer()
return
  tStart   = new Date(); 

   timerID  = setTimeout("UpdateTimer()",1000);
}


//end timer//

//document.onmousemove 	= HandleMousemove;



