//**************************************************
//*   Title: Class for Drop Down Menu              *
//*                                                *
//*  Author: George Zahakos                        *
//*                                                * 
//*  17/10/02                                      *
//*                                                *
//*  ATC                                           *
//*                                                *
/**************************************************/



function Menu(name){


		//**************************************************
		//********** αρχικοποιήσεις μεταβλητών *************
		//**************************************************/
		
		this.type = "Menus";
		Menus[Menus.length] = name;
		this.id=Menus.length-1;
		this.name=name;
		var name=this.name;
		this.top=1;
		this.left=1;
		this.bodyId="";
		
		this.menuWidth = 100;
		this.fontSize = 11;
		this.menuItemHeight = 19; // ~= this.fontSize * 1.82
		
		this.firstState='visible';
		this.onmouseoutAction='hidden';// *** visible/hidden *****
		this.fontWeight = "normal";  // *** bold / normal ****
		this.fontFamily = "Verdana, Geneva, Arial, Helvetica, sans-serif";
		this.fontColor = "#ffffff";
		this.fontColorHilite = "#ff0000";
		this.bgColor = "#555555";
		this.bgColorHilite = "#cccccc";
		this.menuBorder = 1;
		this.mainMenuBorder = 1;
		this.borderColor = "#ccffcc";
		this.borderColorHilite = "#33dd99";
		this.mainMenuBorderColor = "#ff0000";
		this.currentPage=0;// η πρώτη σελ του paging
		this.itemsPerPage=0;// αν είναι >0 τότε γίνεται paging,και τότε καθορίζει τον αριθμό των αντικειμένων σε κάθε σελ.
		this.ActivateAutoOrizontalPozision=0; //Αν =1 τότε αν το μενού βρεί έξω απο το αριστερό άκρο της οθόνης τότε αυτόματα μετακινείται προς τα μέσα.
		
		this.imgNextPage=""; //το image για το move next στο paging 
		this.imgPreviousPage="";//το image για το move previous στο paging 
		this.imgMenuChild="";//το image για το μενου παιδί
		
		this.parents="";//τα πατρικά μενού χωρισμένα με κόμμα χωρίς κενά
		
		this.openRight=1;// αν =1 τοτε το μενυ παιδι ανοιγει απο δεξια/  =0 ανοιγει απο αριστερα
		
		this.firstStr="";  //o κώδικας του layer που περιέχει το menu 
		this.lastStr="";  //o κώδικας του layer που περιέχει το menu (το τέλος του πχ </div>)
		this.holeMenu=""; //ο κωδικας όλου του menu
		
		
		this.items = new Array();
		this.actions = new Array();
		this.actionsWindow = new Array();
		this.images = new Array();
		this.childrens = new Array();
		this.parentsArray=new Array(); //πίνακας με τα πατρικά μενου που παράγεται απο το this.parents (γίνεται στο createContainer())
		
		this.addMenuItem = addMenuItem;
	    this.createMenu = createMenu;
	    this.showMenu = showMenu;
		this.makeVisible= makeVisible;
		this.makeHidden= makeHidden;
		this.goNextPage= goNextPage;
		this.goPreviousPage= goPreviousPage;
		this.createContainer= createContainer;
		this.mouseOut=mouseOut;
		this.handleMouseOver=handleMouseOver;
		this.HiddenAllChildrensExceptMine=HiddenAllChildrensExceptMine;
		
		this.first=0;
		this.last=0;
		this.mouseover=2;
		this.makeVisibleByNameStr="";
		this.makeHiddenByNameStr="";
		this.maxlen=0;
		
		var pages,nullItemsInLastPage;
		nullItemsInLastPage=0;
		var zindex="60100";
		
		
		
		
		function addMenuItem(label, action, actionWindow,img, child) {
			//υπολογίζει το μήκος σε χαρ της μεγαλύτερης επιλογής, ώστε στην *1* να αυξήσει το πλάτος του μενού αν αυτό είναι μικρό.
			this.items[this.items.length] = label;
			if (label.length>this.maxlen)this.maxlen=label.length; 
			this.actions[this.actions.length] = action;
			if (this.actions[this.actions.length-1]=="")this.actions[this.actions.length-1]="#";
			this.actionsWindow[this.actionsWindow.length]=actionWindow;
			if (this.actionsWindow[this.actionsWindow.length-1]=="")this.actionsWindow[this.actionsWindow.length-1]=="_self";
			this.images[this.images.length]=img;
			this.childrens[this.childrens.length]=child;
		}
		
		
		/*****************************************************************************************
		******** Δημιουργεί το layer-περιέκτη μέσα στο οποίο θα μπούν  ***************************
		********   όλα τα υπόλοιπα αντικείμενα του μενού               ***************************
		******************************************************************************************/
		function createContainer(){
			//****    γεμίζεται ο πίνακας this.parentsArray
			var str8=new String("");
			str8=this.parents;
			this.parentsArray=str8.split(",");
			this.childrens[this.childrens.length]="";
			
			//*****    *1*  αν το πλάτος του μενού είναι μικρό, τότε αυξάνεται αυτόματα
			if ((this.maxlen*this.fontSize/1.28)>(this.menuWidth))this.menuWidth=(this.maxlen*this.fontSize/1.28);
			
			//****    υπολογίζει συνολικό πλάτος και ύψος του μενού
			var width=eval(this.menuWidth+this.mainMenuBorder*2+this.menuBorder);
			var height=eval((this.menuItemHeight+this.menuBorder)*(this.last-this.first)+this.mainMenuBorder*2+this.menuBorder*2);
			if (!document.all){
				width=eval(this.menuWidth+this.menuBorder*2+this.menuBorder);
							height=eval((this.menuItemHeight+this.menuBorder)*(this.last-this.first)+this.mainMenuBorder*2+this.menuBorder-1);
			}
			
			if (document.getElementById){
				if (this.parents.length>0){
				   //****    δημιουργεί ένα string με το οποίο όλα τα πατρικά μενού θα είναι ορατά όταν βρισκόμαστε πάνω σε θυγατρικό μενού
					for(var j=0;j<this.parentsArray.length;j++){
						this.makeVisibleByNameStr=this.makeVisibleByNameStr+"makeVisibleByName('"+this.parentsArray[j]+"');";
						this.makeHiddenByNameStr=this.makeHiddenByNameStr+"makeHiddenByName('"+this.parentsArray[j]+"');";
					}
				}
				
				//****     αν ActivateAutoOrizontalPozision=1 τότε ελέγχει αν το μενού φεύγει εκτός οθόνης αριστερα και το μετακινεί  πάλι μέσα
				if(this.ActivateAutoOrizontalPozision==1)
					if(document.getElementById(this.bodyId))	
						if((parseInt(document.getElementById(this.bodyId).offsetWidth)-parseInt(this.left)-width)<0)
							this.left=(document.getElementById(this.bodyId).offsetWidth-width-this.mainMenuBorder*2-this.menuBorder*2-18);
				if(this.parents>"")zindex="60400";
				//****   δημιουργεί το layer-περιέκτη (DIV) ο οποίος θα έχει όνομα το όνομα του μενού. ***
				this.firstStr=this.firstStr+"<div id=\""+this.name+"\" name=\""+this.name+"\" style=\"visibility:"+this.firstState+"; left:"+this.left+"; top:"+this.top+"; position:absolute; background-color: "+this.bgColor+"; border: "+this.mainMenuBorder+"px solid "+this.mainMenuBorderColor+"; width: "+width+"px; height: "+height+"px; z-index: "+zindex+";\"  onmouseout=\""+this.name+".mouseOut("+this.name+");\" align=\"center\" onmouseover=\""+this.name+".makeVisible();"+this.makeVisibleByNameStr ;
				
				
				this.firstStr=this.firstStr+this.makeVisibleByNameStr;// αφήνει ορατά τα πατρικά μενού όταν είμαστε πάνω σε θυγατρικο ***
				this.firstStr=this.firstStr+"\">\n"
				this.lastStr="</div>\n";
			}else{
				this.firstStr="";
				this.lastStr="";
				alert("Required atleast Internet Explorer 5 or Netscape 6 to see this page.");
				return;
			}
			
			document.open("text/html");
			document.write(this.firstStr+" "+this.lastStr);
			document.close;
		}
		
		
		
		/***********************************************************************************
		 *********************    δημιουργεί  τον κώδικα του μενού    **********************
		 **********************************************************************************/
		function createMenu() {
			if (!document.getElementById)return;
			
			var str,count,top,left,childLeft,widht,mouseout;
			var str0=new String;
			
			//*******    ελέγχει αν θα γίνεται paging    *********
			if (this.itemsPerPage==0){//χωρίς paging.
				this.first=0;
				this.last=this.items.length;
			}else{				
			   //***    **2** με paging: υπολογίζει πόσα και ποιά items του μενού θα εμφανιστούν και υπολογίζει τον αριθμό των σελίδων που θα εμφανιστούν.
			   //***    εμφανίζονται κα΄θε φορά οι επιλογές μεταξύ των θέσεων this.first και this.last.
			   //***    Αν δεν θέλουμε paging τότε this.first=0 και this.last=this.items.length;
				this.first=this.currentPage*this.itemsPerPage;
				this.last=this.first+this.itemsPerPage+1;
				pages=parseInt(this.items.length*1.0/this.itemsPerPage);
				if (this.items.length%this.itemsPerPage!=0) {//αν στην τελευταία σελίδα, δεν υπάρχουν τόσες επιλογές ώστε να γεμίσει το μενού, τότ προστήθονται κενές.
					pages++;
					nullItemsInLastPage=this.itemsPerPage-this.items.length%this.itemsPerPage;
					for (var j=0;j<nullItemsInLastPage;j++) this.addMenuItem("&nbsp;","","","","");//<--οι κενές εγγραφές
				}
			}
			
			//******       Αν το ύψος κάθε επιλογης είναι πολύ μικρό τοτε αυξάνεται αυτόματα    ********
			if (this.menuItemHeight/this.fontSize<1.43) this.menuItemHeight=parseInt(this.fontSize*1.49);
			
			str="";count=-1;
			if (this.firstStr=="")this.createContainer();//****   η createContainer καλείται μόνο την πρώτη φορά που καλούμε την createMenu
			widht=eval(this.menuWidth+this.menuBorder);  //****   το πλάτος κάθε επιλογης
			childLeft=eval(widht+this.left);
			
			//****     Δημιουργεί τον κώδικα για κάθε επιλογή του μενού.
			//****     κάθε επιλογη είναι ένα  μέσα σε ένα DIV με όνομα : div + όνομα μενου + i (όπου i= this.first έως  this.last.  βλ  **2**)
			//****     και κάθε ένα απο αυτά τα DIV περιέχει table για την σωστή μορφοποίηση των επιλογών και των εικόνων τους.
			
			for (var i=this.first;i<this.last;i++){
				count++;
				if (document.getElementById){
				top=eval((this.menuItemHeight+this.menuBorder)*count);
				left=0;
				mouseout="window.document.getElementById('div"+this.name+i+"').style.color='"+this.fontColor+"\';this.style.backgroundColor='"+this.bgColor+"'";
					str=str+"<div id=\"div"+this.name+i+"\" name=\"div"+this.name+i+"\"  onmouseover=\""+this.makeVisibleByNameStr+"this.style.backgroundColor='"+this.bgColorHilite+"'\; window.document.getElementById('tdb"+this.name+i+"').style.color='"+this.fontColorHilite+"\';\""
 
					str=str+"  onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+");"+mouseout+";makeHiddenByName('"+this.childrens[i]+"');"+this.makeVisibleByNameStr+"this.style.backgroundColor='"+this.bgColor+"'\; window.document.getElementById('tdb"+this.name+i+"').style.color='"+this.fontColor+"\';"+this.name+".HiddenAllChildrensExceptMine("+this.first+","+this.last+","+eval(i-1)+");\"      style=\"width: "+widht+"px; height: "+eval(this.menuItemHeight+this.menuBorder)+"px; left:"+left+"; top:"+top+"; position:absolute;          border: "+this.menuBorder+"px solid "+this.borderColor+";   visibility:inherit; background-color: "+this.bgColor+"; z-index: "+zindex+";vertical-align: middle;cursor:hand;cursor:pointer\" >\n"
					str=str+"<table width='"+eval(this.menuWidth-this.mainMenuBorder)+"px'   onmouseover=\""+this.makeVisibleByNameStr;
					
					//****     Αν η επιλογή οδηγεί σε θυγατρικό μενού, τότε έμφανίζει ένα εικονίδιο δεξιά της επιλογής ή αν δεν υπάρχει τον χαρ > *****
					if(!this.childrens[i] )
						str=str+"\"" ;
					else
	 					str=str+"moveByName('"+this.name+"','"+this.childrens[i]+"','"+i+"','"+this.bodyId+"',"+this.openRight+");makeVisibleByName('"+this.childrens[i]+"');\""; 
						 str=str+"onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+");\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ><tr onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+");\">";
						str0=this.images[i];
						if (!str0)str=str+"<td id=\"tda"+this.name+i+"\" name=\"tda"+this.name+i+"\"  onmouseover=\""+this.makeVisibleByNameStr+"\"  onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+");"+mouseout+"\" ></td>"; else str=str+"<td onmouseover=\""+this.makeVisibleByNameStr+"\" align=\"center\" valign=\"middle\" id=\"tdb"+this.name+i+"\" name=\"tdb"+this.name+i+"\" onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+")\"><img src=\""+this.images[i]+"\"  border=\"0\" align=\"middle\"  id=\"imga"+this.name+i+"\" name=\"imga"+this.name+i+"\"  onmouseover=\""+this.makeVisibleByNameStr+"\" onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+");\"></td>";
						str=str+"<td   id=\"tdb"+this.name+i+"\" name=\"tdb"+this.name+i+"\"  style=\"font-family:"+this.fontFamily+"; font-size: "+this.fontSize+"px; font-weight: "+this.fontWeight+"; text-decoration: none;color: "+this.fontColor+";\"  ";
						if ((this.actions[i]!="")&&(this.actions[i]!="#"))str=str+"onclick=\"window.open(\'"+this.actions[i]+"\',\'"+this.actionsWindow[i]+"\')\"  ";
	
	 					str=str+"   onmouseout=\""+this.name+".mouseOut("+this.childrens[i]+")\" height=\""+this.menuItemHeight+"\" valign=\"middle\"  style=\"  width: "+this.menuWidth+"px;   vertical-align: middle;\" >&nbsp;"+this.items[i]+"</td>"
						//*******    εμφάνιση θυγατρικών μενού    *********
						if(this.childrens[i] ) {
							var imgChild="&nbsp;>&nbsp;";
							if (this.imgMenuChild!="")  imgChild="<img src=\""+this.imgMenuChild+"\"    hspace=\"0\" vspace=\"0\" border=\"0\" align=\"botton\"   name=\"btd"+this.name+i+"\" id=\"btd"+this.name+i+"\">  ";
							str=str+"<td id=\"ctd"+this.name+i+"Ch\" name=\"ctd"+this.name+i+"Ch\" align=\"right\" valign=\"bottom\"  >"+imgChild+"</td>";
							}
						str=str+"</tr></table>\n</div>\n";
					}
			}
			
			//****    αν γινεται paging τότε στο τέλος εμφανίζονται τα δύο βελάκια < και > για την μετακίνηση από σελ σε σελ.
			var nextImg=">",previousImg="<";
			if (this.itemsPerPage!=0){
				if (document.getElementById){
					if (this.imgNextPage!="") nextImg="<img src='"+this.imgNextPage+"' alt='Next' border=\"0\" onmouseover=\"this.mouseover=1;\">"	;
					if (this.imgPreviousPage!="") previousImg="<img src='"+this.imgPreviousPage+"' alt='Back' border=\"0\">"	;
					str=str+"<div id=\""+this.name+"p\" name=\""+this.name+"p\" onmouseover=\""+this.name+".makeVisible();"+this.name+".HiddenAllChildrensExceptMine("+this.first+","+this.last+",-2);\"   style=\" width: "+eval(this.menuWidth+this.menuBorder)+"px; height: "+eval(this.menuItemHeight+this.menuBorder)+"px; left:0; top:"+eval((this.menuItemHeight+this.menuBorder)*count)+"; position:absolute;  border:"+this.menuBorder+"px solid "+this.borderColor+";  visibility:inherit; background-color: "+this.bgColor+"; z-index: "+zindex+";vertical-align: middle;\" >\n"
			
					str=str+"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width='"+eval(this.menuWidth-this.mainMenuBorder)+"px'  ><tr><td align=\"middle\"   height=\""+eval(this.menuItemHeight+this.menuBorder)+"\" valign=\"middle\" style=\"  width: "+eval(this.menuWidth+this.menuBorder)+"px;   vertical-align: middle;font-family:"+this.fontFamily+"; font-size: "+this.fontSize+"px; font-weight: "+this.fontWeight+"; text-decoration: none;color: "+this.fontColor+";\"  name=\"td"+this.name+"p\" id=\"td"+this.name+"p\" >"
					if (this.currentPage>0)str=str+" <a style=\"cursor:hand;cursor:pointer\"  onclick=\""+this.name+".goPreviousPage();\" >"+previousImg+"</a> "; else str=str+"&nbsp;";
					if (this.currentPage<pages-1)str=str+" <a style=\"cursor:hand;cursor:pointer\"  onclick=\""+this.name+".goNextPage();\" >&nbsp;"+nextImg+"</a> "; else str=str+"&nbsp;";
					str=str+"</td></tr></table>\n</div>\n";
				}
			}
			this.holeMenu=str;
		}
		
		
		
		
		/*****************************************************************************
		****                 Γράφει το μενου μέσα στη σελίδα                      ****
		**** (Αν έχουμε επιλέψει το μενου να είναι hidden τότε δεν θα εμφανιστεί) ****
		******************************************************************************/
		
		function showMenu() {
			if (!document.getElementById)return;
			document.getElementById(this.name).innerHTML=this.holeMenu;
			
		}
		
		
		
		/******************************************************************************************************
		********   δίνει στη mouseId το id του αντικειμένου πάνω από το οποίο βρίσκεται το ποντίκι    *********
		*******************************************************************************************************/
		function handleMouseOver(evt){
			var id="";
			 evt = (evt) ? evt : ((window.event) ? window.event : "");
			 //IE: window.event και το evt δεν χρειάζεται,   N6: evt 
			if (document.all)id=evt.srcElement.id; 
			else{
			if (evt.target.id)id=evt.target.id; else 
			if (evt.target.parentNode.id)id=evt.target.parentNode.id;}
			mouseId=id;
		}
		document.onmouseover=this.handleMouseOver;
		var myStr;
		
		/************************************************************************************************************
		********      Οταν το ποντίκι φύγει πάνω από το μενού, ελέγχει αν αυτό θα πρέπει να γίνει hidden    *********
		*************************************************************************************************************/
		function mouseOut(s){
				if (s)s=s.name;
			myStr=new String();
			myStr=mouseId;
			var f=0;
			for (var i=0;i<this.childrens.length;i++)
				if (myStr.search(this.childrens[i])>-1) f=1; 
			if (((this.onmouseoutAction=="hidden")&& (myStr.search(this.name)<0)  &&(mouseId!=""))||(f==1)) {
				this.makeHidden(this.name)};
			
		}
		
		
		
		/***********************************************
		********     κάνει το μενου visible    *********
		************************************************/

		function makeVisible(){
			this.mouseover=1;
			
			for (var i=this.first;i<this.last;i++)
			document.getElementById("div"+this.name+i).style.visibility='visible';
			document.getElementById(this.name).style.visibility='visible';
		}
		
		
		
		
		/***********************************************
		********     κάνει το μενου hidden     *********
		***********************************************/
		function makeHidden(n){
			for (var i=this.first;i<this.last;i++)
			document.getElementById("div"+this.name+i+"").style.visibility='hidden';
			document.getElementById(this.name).style.visibility='hidden';
		}
		
		
		
		
		/*************************************************************************************
		********      πηγαίνει στην επόμενη σελίδα (αν έχουμε επιλέψει το paging)    *********
		*************************************************************************************/
		function goNextPage(){
			this.currentPage++;
			this.createMenu();
			this.showMenu();
		}

		
		/***************************************************************************************
		******       πηγαίνει στην προϊγούμενη σελίδα (αν έχουμε επιλέψει το paging)    ********
		***************************************************************************************/
		function goPreviousPage(){//πηγαίνει στην  σελίδα
			this.currentPage--;
			this.createMenu();
			this.showMenu();
		}
	
	
	
		/******************************************************************************************
		******       κάνει hidden όλα να θυγατρικά μενού εκτος από αυτό τις επιλογής mine  ********
		******************************************************************************************/
	
	   function HiddenAllChildrensExceptMine(first,last,mine){
	   	for (var i=first;i<last;i++)if(i!=mine)makeHiddenByName(this.childrens[i])
	   }
	
}  
//***********************************************************************************************************
//***********************************************************************************************************
//*****************************************     End of Class Menu     ***************************************
//***********************************************************************************************************
//***********************************************************************************************************/




var mouseId="";
var Menus= new Array();

		/**************************************************************************
		******       κάνει hidden ένα μενου δίνοντας μόνο το όνομά του     ********
		***************************************************************************/
function makeHiddenByName(name){
			if (!eval(name))return
		
			for (var i=eval(name).first;i<eval(name).last;i++)
			
			document.getElementById("div"+eval(name).name+i).style.visibility='hidden';
			document.getElementById(eval(name).name).style.visibility='hidden';
}
		



		/***************************************************************************
		******       κάνει visible ένα μενου δίνοντας μόνο το όνομά του     ********
		***************************************************************************/
function makeVisibleByName(name){
			for (var i=eval(name).first;i<eval(name).last;i++)	
			document.getElementById("div"+eval(name).name+i).style.visibility='visible';
			document.getElementById(eval(name).name).style.visibility='visible';
}
		
		
		

		/***********************************************************************************************************
		******       όταν από μία επιλο΄γη του μενού εμνφανίζεται ένα θυγατρικό,                            ********
		******       τότε αυτό μετακινείται αυτόματα δίπλα του (δεξια ή αριστερά ανάλογα την openRight)     ********
		************************************************************************************************************/
function moveByName(current,child,count,bodyId,openRight){
	if(!document.getElementById(child))return;
	if(!document.getElementById(bodyId))return;
	document.getElementById(child).style.top=parseInt(document.getElementById(current).style.top)+parseInt(document.getElementById("div"+current+count).style.top);
	if (eval(child).openRight==1)
		document.getElementById(child).style.left=parseInt(document.getElementById(current).style.left)+parseInt(document.getElementById(current).style.width)-parseInt(document.getElementById(child).style.borderWidth)-parseInt(document.getElementById(current).style.borderWidth)-1;
	else{
		eval(child).openRight=0;
		document.getElementById(child).style.left=parseInt(document.getElementById(current).style.left)-parseInt(document.getElementById(child).style.width)+1;
	}
	if ((document.getElementById(bodyId))&&(eval(child).openRight==1))
	if (parseInt(document.getElementById(bodyId).offsetWidth)-parseInt(document.getElementById(current).style.left)-parseInt(document.getElementById(child).style.width)-parseInt(document.getElementById(current).style.width)<0){
		eval(child).openRight=0;
		document.getElementById(child).style.left=parseInt(document.getElementById(current).style.left)-parseInt(document.getElementById(child).style.width)+1;
	}
}



		/*********************************************************
		******       μετακινεί ένα μενου στη θεση χ,y     ********
		**********************************************************/

function moveMenuTo(name,x,y){
	if(!document.getElementById(name))return;
	document.getElementById(name).style.top=x;
	document.getElementById(name).style.left=y;
}



		/*********************************************************
		******           κάνει hide όλα τα μενού          ********
		**********************************************************/
function HideAllMenus(){
		for (var i=0;i<Menus.length;i++)
					if (document.getElementById(Menus[i]).onmouseoutAction!='hidden')
						makeHiddenByName(Menus[i]);
		}


function changeMouseover(x,j){
document.getElementById(x).mousemove=j;document.form1.y.value=x+"="+document.getElementById(x).mousemove;
}



