
////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                    //
// Copyright www.interakt.ro 2000-2002                                                                //
// Menus.js v2.0                                                                                      //
//                                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////

parentWindow = this;
lastElement = this;

NS = !(document.all);
DOM = !!(document.getElementById);
if (DOM) {
	NS = false;
}

fii = new Array();
layerN = 0;


function KT_parseInt(i){
	i+="px";
	return parseInt(i.replace(/px/g, ""));
}

function show(l){
	if(NS && !DOM){
		l.visibility = "show";
    }else{
		l.style.visibility = "visible";
	}
}

function hide(l){
	if(NS && !DOM){
		l.visibility = "hide";
	} else {
		l.style.visibility = "hidden";
	}
}

function scrie(l, text){
	if(DOM || !NS){
		l.innerHTML = text;
	} else {
		l.document.open();
		l.document.write(text);
		l.document.close();
	}
}

function Leiar(x, tata){
	var temp, el1;
	if(DOM || !NS){
		if(tata == parentWindow){
			el1 =  document.body;
		} else {
			el1 = tata;
		}
		temp =  document.createElement('div');
		if(!temp){
			src = "<div id=leiar"+parentWindow.layerN+" class=ieLeiar/>";
			el1.innerHTML+=src;
			temp = el1.getElementById("leiar"+parentWindow.layerN);
		} else {
			temp.id = "leiar"+parentWindow.layerN;
			temp.className = "ieLeiar";
			el1.appendChild(temp);
		}
		parentWindow.layerN++;
		return(temp);
	}else{
		temp = new Layer(x, tata);
		return temp;
	}
}

function arrayPush(a, l){
	if(DOM || !NS){
		a[a.length]=l;
	}
	else{
		a.push(l);
	}
}

function addMenu(eSusParam, text, exe, w, mw, x, y){
	if(!w){
		w = text.length * 9;
		if (this.fii && this.fii.length && this.fii.length !=0) {
			var max = 0;
			for ( var i = 0; i<this.fii.length; i++) {
				if ( max < KT_parseInt(getAttrs(this.fii[i]))) {
					max = KT_parseInt(getAttrs(this.fii[i]));
				}
			}
			for ( var i = 0; i<this.fii.length; i++) {
				if (NS) {
					this.fii[i].clip.right = max;
				} else {
					this.fii[i].style.width = max;
				}
			}
		}
		//w = 60;
		if (w < max)
			w = max;
	}
	if(!mw){
		mw = text.length * 6 + 4;
		if (this.fii && this.fii.length && this.fii.length !=0) {
			var max = 0;
			for ( var i = 0; i<this.fii.length; i++) {
				if ( max < KT_parseInt(getAttrs(this.fii[i]))) {
					max = KT_parseInt(getAttrs(this.fii[i]));
				}
			}
			for ( var i = 0; i<this.fii.length; i++) {
				if (NS) {
					this.fii[i].clip.right = max;
				} else {
					this.fii[i].style.width = max;
				}
			}
		}
		//mw = 40;
		if ( mw < max)
			mw = max;
	}
	if(this.fiu){
		return this.fiu.addMenu(0, text, exe, w, mw, x, y);
	}
	var aux;
	if (this == parentWindow) {
		if(!x){
			if(this.fii.length != 0){
				aux = this.fii[this.fii.length-1];
				if (eSusParam) {
					x = (NS)?(aux.pageX + aux.clip.right):(KT_parseInt(aux.style.left) + KT_parseInt(aux.style.width));
					y = (NS)?(aux.pageY):(KT_parseInt(aux.style.top));
				} else {
					x = (NS)?(aux.pageX):(KT_parseInt(aux.style.left));
					y = (NS)?(aux.pageY + aux.clip.bottom):(KT_parseInt(aux.style.top) + aux.offsetHeight);
				}
			} else{
				x=0;
				y=0;
			}
		}
		aux = new MenuButton(text, x, y, mw, this, exe);
		aux.eSus = eSusParam;
		show(aux);
		if(NS){
			auxx = new Menu(w, this);
		} else{
			auxx = new Menu(w, this)
		}
		aux.fiu = auxx;
		aux.addMenuItem = addMenuItem;
		aux.addMenu = addMenu;
		aux.addMenuSeparator = addMenuSeparator;
		auxx.tata = aux;
		arrayPush(this.fii, aux);
		show(aux);
	} else {
	aux = this.addMenuItem("<table border=0 cellspacing=0 cellpadding=0 class=mnu_table_item><tr><td width=100% class=mnu_td_item nowrap=true>"+text+"</td><td valign=left class=mnu_td_item>"+menuNext+"</td></tr></table>", exe);
		auxx = new Menu(w, parentWindow);
		aux.fiu = auxx;
		auxx.tata = aux;
		aux.addMenuItem = addMenuItem;
		aux.addMenu = addMenu;
		aux.addMenuSeparator = addMenuSeparator;
	}
	return aux;
}

function addMenuItem(text, exe){
	if(this.fiu){
		return this.fiu.addMenuItem(text, exe);
	}
	var aux;
	aux = new MenuItem(text, this, exe);
	arrayPush(this.fii, aux);
	return aux;
}

function addMenuSeparator(ceFel){
	var aux = new MenuSeparator(this.fiu, this.fiu.latsime-2, ceFel);
	if(NS){
		arrayPush(this.fiu.fii, aux);
	}
}

function showMenu(l){
	show(l);
	for(i=0;i<l.fii.length;i++){
		show(l.fii[i]);
	}
}

function hideFii(fii){
	for(i=0;i<fii.length;i++){
		hide(fii[i]);
	}
}

function Menu(w, tata){
	var aux;
	aux = new Leiar(w, tata);
	aux.fii = new Array();
	if(NS){
		aux.clip.bottom=2;
		aux.clip.right=w;
		txt = "<table border=0 cellspacing=0 cellpadding=0 width=100% height=100% class=mnu_table_item><tr><td class=mnu_td_item colspan=2 bgcolor="+parentWindow.menuFgColor+" height="+parentWindow.spacingBegin+"><img src=img/nimic.gif height="+parentWindow.spacingBegin+" width=1></td></tr><tr><td bgcolor="+parentWindow.menuFgColor+" height=100% width="+parentWindow.spacingLeft+" class=mnu_td_item><img src=img/nimic.gif width="+parentWindow.spacingLeft+" height=1></td><td bgcolor="+parentWindow.menuBgColor+" width=100% height=1 class=mnu_td_item>td3-215<img src=img/nimic.gif height=1></td></tr><tr><td colspan=2 bgcolor="+parentWindow.menuBgColor+" height="+parentWindow.spacingEnd+" class=mnu_td_item><img src=img/nimic.gif height="+parentWindow.spacingEnd+"></td></tr></table>";
	} else {
		aux.style.width=w;
		//separatori - inainte, stanga, jos
		txt = "<table cellspacing=0 cellpadding=0 bgcolor='"+parentWindow.menuFgColor+"' id='tablou'  class=mnu_table_item><tr><td colspan=3 height="+parentWindow.spacingBegin+" class=mnu_td_item><img src='img/nimic.gif' height="+parentWindow.spacingBegin+" width=1></td></tr><tr><td width="+parentWindow.spacingLeft+" height=1 class=mnu_td_item><img src=img/nimic.gif width="+parentWindow.spacingLeft+" height=1></td><td colspan=2 bgcolor="+parentWindow.menuBgColor+" height="+parentWindow.spacingEnd+" class=mnu_td_item><img src=img/nimic.gif height="+parentWindow.spacingEnd+"></td></tr></table>";
	}
	scrie(aux, txt);
	aux.addMenuItem = parentWindow.addMenuItem;
	aux.addMenu = parentWindow.addMenu;
	aux.addMenuSeparator = addMenuSeparator;
	aux.onmouseover = menuMouseOver;
	aux.onmouseout = menuMouseOut;
	aux.tata = tata;
	aux.tip = "Menu";
	aux.latsime=w;
	return aux;
}

function MenuItem(text, tata, exe){
	var aux;
	var w;
	text = "<a class=mnu_item2>"+text+"</a>";
	if(NS){
		w = tata.latsime - 2;
		aux = new Leiar(w, tata);
		aux.bgColor=parentWindow.itemOffColor;
		aux.clip.right = w;
		aux.moveTo(1, tata.clip.bottom - 1);
		scrie(aux, text);
		tata.clip.bottom += aux.clip.bottom;
	} else {
		if(DOM){
			var tt = tata.getElementsByTagName('table');
			for(i=0;i<tt.length;i++) {
				if (tt[i].id=='tablou') {
					var nr = tt[i].rows.length;
					var tr = tt[i].insertRow(nr-1);
				}
			}
		} else {
			var nr = tata.all.tablou.rows.length;
			var tr = tata.all.tablou.insertRow(nr-1);
		}
		var cel = tr.insertCell(0);
		cel.innerHTML = "<img src=img/nimic.gif width="+parentWindow.spacingLeft+" height=1>";
		cel.style.width="180px";
		cel.style.height=""+parentWindow.spacingItemVert;
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		var cel1 = tr.insertCell(1);
		cel1.innerHTML = text;
		cel1.style.backgroundColor = parentWindow.itemOffColor;
		cel1.style.width="180px";
		cel1.style.borderLeftWidth = "0px";
		cel1.style.borderRightWidth = "0px";
		cel1.style.borderTopWidth = "0px";
		cel1.style.borderBottomWidth = "0px";
		cel1.noWrap = true;
		cel = tr.insertCell(2);
		cel.innerHTML = "<img src=img/nimic.gif width="+parentWindow.spacingItemRight+" height=1>";
		cel.style.backgroundColor = parentWindow.menuBgColor;
		cel.style.width="180px";
		cel.style.height="1";
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		if(!(tata.ien)){
			tata.ien = 0;
		}
		cel1.ien = tata.ien;
		tata.ien++;
		aux = cel1;
	}
	aux.onmouseover=menuItemMouseOver;
	aux.onmouseout=menuItemMouseOut;
	if (NS) {
		aux.captureEvents(Event.MOUSEDOWN);
		aux.onmousedown=click;
	} else {
		aux.onmouseup=click;
	}
	if(exe){
		aux.exe = exe;
	}
	aux.tata = tata;
	aux.tip = "MenuItem";
	return aux;
}

function MenuSeparator(tata, x, ceFel){
	if(NS){
		var aux = new Leiar(x, tata);
		aux.clip.right = x;
		aux.moveTo(1, tata.clip.bottom - 1);
		if(ceFel==1){
			scrie(aux, "<table border=0 cellspacing=0 cellpadding=0 width=100% class=mnu_td_item><tr><td bgcolor="+parentWindow.menuBgColor+" width=1 height=3 class=mnu_td_item><img src=img/nimic.gif height=3></td></tr><tr><td bgcolor="+parentWindow.menuFgColor+" width=1 height=3 class=mnu_td_item><img src=img/nimic.gif height=3></td></tr></table>");
		}else{
		scrie(aux, "<table border=0 cellspacing=0 cellpadding=0 width=100% class=mnu_td_item><tr><td bgcolor="+parentWindow.itemOffColor+" width=3 height=3 class=mnu_td_item><img src=img/nimic.gif height=3></td></tr><tr><td bgcolor="+parentWindow.itemOffColor+" width=3 height=3 class=mnu_td_item><img src=img/nimic.gif height=3></td></tr></table>");
		}
		tata.clip.bottom += aux.clip.bottom;
		return aux;
	} else{
		if(DOM){
			var tt = tata.getElementsByTagName('table');
			for(i=0;i<tt.length;i++) {
				if (tt[i].id=='tablou') {
					var nr = tt[i].rows.length;
					var tr = tt[i].insertRow(nr-1);
				}
			}
		} else {
			var nr = tata.all.tablou.rows.length;
			var tr = tata.all.tablou.insertRow(nr-1);
		}
		var cel = tr.insertCell(0);
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.width = "1";
		cel.style.height = "1";
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		cel = tr.insertCell(1);
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		if(ceFel!=0){
			cel.style.backgroundColor = parentWindow.menuBgColor;
		}else{
			cel.style.backgroundColor = parentWindow.itemOffColor;
		}
		cel.style.width="100%";
		cel = tr.insertCell(2);
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		cel.style.backgroundColor = parentWindow.menuBgColor;
		cel.style.width = "1";
		cel.style.height = "1";

		if(DOM){
			var tt = tata.getElementsByTagName('table');
			for(i=0;i<tt.length;i++) {
				if (tt[i].id=='tablou') {
					tr = tt[i].insertRow(nr);
				}
			}
		} else {
			tr = tata.all.tablou.insertRow(nr);
		}
		cel = tr.insertCell(0);
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.width = "1";
		cel.style.height = "1"; 
		cel = tr.insertCell(1);
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		if(ceFel==0){
			cel.style.backgroundColor = parentWindow.itemOffColor;
		}
		cel.style.width="100%";
		cel = tr.insertCell(2);
		cel.style.borderLeftWidth = "0px";
		cel.style.borderRightWidth = "0px";
		cel.style.borderTopWidth = "0px";
		cel.style.borderBottomWidth = "0px";
		cel.innerHTML = "<img src=img/nimic.gif height=3 width=1>";
		cel.style.backgroundColor = parentWindow.menuBgColor;
		cel.style.width = "1";
		cel.style.height = "1";
	}
}

function MenuButton(text, x, y, w, tata, exe){
	var aux;
	aux = new Leiar(w, tata);
  text = "<a class=mnu_item>"+text+"</a>";

	if(NS && !DOM){
		aux.bgColor=parentWindow.itemOffColor;
		aux.moveTo(x, y);
	} else{
		aux.style.backgroundColor=parentWindow.itemOffColor;
		aux.style.top = y;
		aux.style.left = x;
	}
	if(w){
		if(NS){
			aux.clip.right = w;
		} else{
			aux.style.width = w;
		}
	}
	scrie(aux, "<table border=0 cellspacing=0 cellpadding=0 class=mnu_table_item width=100%><tr><td colspan=3 bgcolor="+parentWindow.menuFgColor+" height="+parentWindow.spacingLzeroItemBegin+" class=mnu_td_item><img src=img/nimic.gif height="+parentWindow.spacingLzeroBegin+"></td></tr><tr><td bgcolor="+parentWindow.menuFgColor+" height=100% width=1 class=mnu_td_item><img src=img/nimic.gif width=1></td><td width=100% align=left class=mnu_td_item oncontextmenu='return false;' onselectstart='return false;' nowrap='true'>"+text+"</td><td bgcolor="+parentWindow.menuBgColor+" class=mnu_td_item width="+parentWindow.spacingLzeroRight+"><img src=img/nimic.gif width="+parentWindow.spacingLzeroRight+" height=3></td></tr><tr><td colspan=3 bgcolor="+parentWindow.menuBgColor+" height="+parentWindow.spacingLzeroEnd+" class=mnu_td_item><img src=img/nimic.gif height="+parentWindow.spacingLzeroEnd+"></td></tr></table>");
	aux.onmouseover=menuButtonMouseOver;
	if (NS) {
		aux.captureEvents(Event.MOUSEDOWN);
		aux.onmousedown=click;
	} else {
		aux.onmouseup=click;
	}
	aux.onmouseout=menuButtonMouseOut;
	aux.menuItemMouseOut = menuItemMouseOut;
	aux.menuItemMouseOver = menuItemMouseOver;
	aux.menuMouseOut = menuMouseOut;
	aux.menuMouseOver = menuMouseOver;
	aux.exe=exe;
	aux.tip = "MenuButton";
	return aux;
}

function hideRec(ce, panaUnde){
	if(ce.tip != "MenuButton"){
		if(ce.tata != panaUnde){
			if(ce.fii){
				hideFii(ce.fii);
			}
			hide(ce);
			hideRec(ce.tata, panaUnde);
		}
	}
}

function menuItemMouseOver(e){
	// set the left and top properties for the sub-menu if there is one
	if(this.fiu && this.tip=="MenuItem"){
		if(NS && !DOM){
			this.fiu.pageX=this.pageX + this.clip.right + 1 + parentWindow.newMenuXDepl;
			this.fiu.pageY=this.pageY - 1 + parentWindow.newMenuYDepl;
		} else{
			this.fiu.style.left = KT_parseInt(this.tata.style.left) + KT_parseInt(this.tata.offsetWidth) + parentWindow.newMenuXDepl;
			var a = this.offsetTop;
			if(a==0){
				a=this.tata.clientHeight/(this.tata.ien)*this.ien + 1;
			}
			this.fiu.style.top = KT_parseInt(this.tata.style.top) + a - 1 + parentWindow.newMenuYDepl;
		}
	}

	// set the bgcolor for the current menuitem
	if(NS && !DOM){
		this.bgColor=parentWindow.itemOnColor;
	} else {
		if (this.tata && this.tata.tata) {
			this.tata.tata.style.backgroundColor=parentWindow.itemOnColor;
			var d = this.tata.tata.getElementsByTagName("A");
			if(this.tata.tata.tip=="MenuItem"){
				if (d.length) d[0].className="mnu_item2_hover";
			} else {
				if (d.length) d[0].className="mnu_item_hover";
			}
		}
		this.style.backgroundColor=parentWindow.itemOnColor;
    var d = this.getElementsByTagName("A");
    if(this.tip=="MenuItem"){
      if (d.length) d[0].className="mnu_item2_hover";
    }else{
      if (d.length) d[0].className="mnu_item_hover";
    }
	}

	// close other sub-menus if they are open
	if(parentWindow.lastElement != parentWindow){
		if(this.tip == "MenuButton"){
			if(parentWindow.lastElement != this){
				if(parentWindow.lastElement.fiu){
					hideFii(parentWindow.lastElement.fiu.fii);
					hide(parentWindow.lastElement.fiu);
				}
				hideRec(parentWindow.lastElement, this);
			}
		} else {
			if(this.tata.tata != parentWindow.lastElement){
				if(parentWindow.lastElement.fiu){
					hideFii(parentWindow.lastElement.fiu.fii);
					hide(parentWindow.lastElement.fiu);
				}
				if(parentWindow.lastElement.tata != this.tata){
					hideRec(parentWindow.lastElement, this.tata);
				}
			}
		}
		parentWindow.lastElement = this;
	}

	// if we have a sub-menu, show it
	if(this.fiu){
		if(this.fiu.fii.length != 0){
			showMenu(this.fiu);
		}
	}
}

function menuItemMouseOut(e){
	if(NS && !DOM){
		this.bgColor=parentWindow.itemOffColor;
	} else{
		this.style.backgroundColor=parentWindow.itemOffColor;
    var d = this.getElementsByTagName("A");
    if(this.tip=="MenuItem"){
      if (d.length) d[0].className="mnu_item2";
    } else {
      if (d.length) d[0].className="mnu_item";
    }
	}
	if (this.tata && this.tata.tata) {
		this.tata.tata.style.backgroundColor=parentWindow.itemOffColor;
		var d = this.tata.tata.getElementsByTagName("A");
		if(this.tata.tata.tip=="MenuItem"){
			if (d.length) d[0].className="mnu_item2";
		} else {
			if (d.length) d[0].className="mnu_item";
		}
	}
	parentWindow.lastElement = this;
}

function menuMouseOver(){
	if(parentWindow.toID != -1){
		clearTimeout(parentWindow.toID);
		parentWindow.toID = -1;
	}
}

function menuMouseOut(){
	parentWindow.toID = setTimeout("timeout();", 1000);
}

function timeout(){
	if(parentWindow.lastElement != parentWindow){
		if(parentWindow.lastElement.fiu){
			hideRec(parentWindow.lastElement.fiu, parentWindow);
		} else{
			hideRec(parentWindow.lastElement, parentWindow);
		}
	}
	parentWindow.toID = -1;
}

function menuButtonMouseOut(){
	if(myStatus == 1){
		this.menuItemMouseOut();
		this.menuMouseOut();
	}
}

function menuButtonMouseOver(){
	if(myStatus == 1){
		if(NS && !DOM){
			if(this.eSus){
				this.fiu.pageX = this.pageX;
				this.fiu.pageY = this.pageY + this.clip.bottom;
			}else{
				this.fiu.pageX = this.pageX + this.clip.right;
				this.fiu.pageY = this.pageY;
			}
		}
		else{
			if(this.eSus){
				this.fiu.style.left = this.style.left;
				this.fiu.style.top  = KT_parseInt(this.style.top) + this.offsetHeight;
			}else{
				this.fiu.style.left = KT_parseInt(this.style.left) + this.offsetWidth;
				this.fiu.style.top  = KT_parseInt(this.style.top);
			}
		}
		this.menuMouseOver();
		this.menuItemMouseOver();
	}
}

function click(){
	if(this.exe){
		timeout();
		eval(this.exe);
	}
	return false;
}

function getAttrs(o) {
	if (NS) {
		return o.clip.right;
	} else {
		return o.style.width;
	}
}
