/**
 * @author Admin
 */
 function AutoComplete(aParentObj,anInput, aName, aLoader, aStyleArray)
 {
	this.styleArray = null;
	if (aStyleArray)
	{
		this.styleArray = aStyleArray;
	}
	this.parentObject = aParentObj;
	this.inputField=anInput;
	this.loader=aLoader;
	this.name = aName;
    if (this.name == null || this.name.length ==0)
	{
		this.name="autocomplete";
	}
    
	this.array=null;
    this.pos=0;	
	var theArray;
	if (window.autoCompleteList)
	{
		theArray=window.autoCompleteList;
		this.pos=theArray.length;
	}
	else
	{
		theArray=new Array();
		window.autoCompleteList=theArray;	
	}
	
	theArray[theArray.length]=this;
	this.id=this.name+"_"+this.pos;
	
	this.onKeyDownFunction=null;
	this.onKeyUpFunction=null;
	this.focus=false;
	this.valueReader=new AirportReader();
	this.addDocumentEvents();
	this.selectedObject = null;
	
	this.itemLister = this.buildMenuLister(aParentObj);
	this.listener = new Array();
	this.creationLength=1;
	this.checkList=new Array();
	this.checkList[0]=1;
	this.checkList[1]=4;
	this.listBuilder = new DefaultListBuilder();
	this.listBuilder.setDefaultExpressionMatcher(new AirportExpressionMatcher());
	this.loader.addLoadListener(this);
	this.word=null;
 }


 AutoComplete.prototype.initMenuStyle=function(anArray)
 {
 	this.inputField.value='';
 	this.closeList();
 }
 
 
 AutoComplete.prototype.setArray=function(aValue)
 {
 	this.array=aValue;
 }
 
 
 AutoComplete.prototype.setFocus=function(aValue)
 {
 	this.focus=aValue;
	if (aValue==false)
	{
		this.closeList();
		updateInActiveInputStyle(this.inputField.id);
	} else {
		updateActiveInputStyle(this.inputField.id);
		deactAllCalendars();
	}
 }
 
 AutoComplete.prototype.addFocusListener=function(anObject)
 {
 	var theHandler = this;
 	this.inputField.onfocus=function(anEvent)
	{
		theHandler.setFocus(true);
	}
 	this.inputField.onblur=function(anEvent)
	{	  
	  window.setTimeout('window.autoCompleteList['+theHandler.pos+'].setFocus(false)', 100);
	  updateInActiveInputStyle(this.id);
	  //hier muss das Event rein
	}
	var theMouseFunction = this.inputField.onclick;
	this.inputField.onclick=function(anEvent){ theHandler.onInputClick(anEvent); if (theMouseFunction){theMouseFunction(anEvent);}};
 }

 AutoComplete.prototype.onInputClick=function(aParentObject)
 {
 	this.inputField.value='';
 	this.closeList();
 }
 
 
 AutoComplete.prototype.buildMenuLister=function(aParentObject)
 {
 	var theComList = new MenuList(this.id+"_l", aParentObject);
 	theComList.addSelectionListener(this);
	theComList.setContentBuilder(new AirportMenuItemBuilder());
	if (this.styleArray)
	{
		theComList.initStyle(this.styleArray);
	}
	theComList.init();
 	return theComList;
 }
 
 AutoComplete.prototype.addDocumentEvents=function()
 {
    this.addFocusListener(this.inputField);	
 
 	if (document.onkeydown)
	{
		this.onKeyDownFunction=document.onkeydown;		
	}
	var theHandler = this;
	document.onkeydown=function(anEvent){theHandler.onKeyDownEvent(anEvent);};
	
	if (document.onkeyup)
	{
		this.onKeyUpFunction=document.onkeyup;		
	}
	
	document.onkeyup=function(anEvent){theHandler.onKeyUpEvent(anEvent);};
 }
 
 AutoComplete.prototype.onKeyDownEvent=function(anEvent)
 {
 	//alert('On key down pressed '+anEvent+'');
 	if (this.focus)
	{
		this.processEvent(0,anEvent);
	}
	if (this.onKeyDownFunction)
	{
		this.onKeyDownFunction(anEvent);
	}
 }
 
 AutoComplete.prototype.onKeyUpEvent=function(anEvent)
 {
 	//alert('On key down pressed '+anEvent+'');
 	if (this.focus)
	{
		this.processEvent(1,anEvent);
	}
	if (this.onKeyUpFunction)
	{
		this.onKeyUpFunction(anEvent);
	}
 }
 
 AutoComplete.prototype.moveUp=function()
 {
 	if (this.itemLister.isVisible())
	{
		this.itemLister.selectPrev();
	}
 }
 
 AutoComplete.prototype.moveDown=function()
 {
 	if (this.itemLister.isVisible())
	{
		this.itemLister.selectNext();
	}
 }
 
 
 AutoComplete.prototype.moveRight=function()
 {
 	if (this.itemLister.isVisible())
	{
		this.itemLister.goRight();
	}
 }
 
 AutoComplete.prototype.moveLeft=function()
 {
 	if (this.itemLister.isVisible())
	{
		this.itemLister.goLeft();
	}
 }
 AutoComplete.prototype.takeInputWithoutList=function()
 {
 	var inputValue = this.inputField.value;
	if(inputValue.length == 3)
	{
		var airport = new Airport('',inputValue);
		var theSelectionEvent = new CompletionEvent(airport, this, airport);
		this.notifyListener(theSelectionEvent);
	}
 }
 /**
  * Holt sich den ausgesuchten Airport aus der Liste. 
  * Wenn es eine Auswahl gibt, dann wird true zurueck gegeben. 
  * Wenn nicht, dann false.
  * @author Markus Hanses
  */
 AutoComplete.prototype.copySelectedWord=function()
 {
 	var selectedElement = this.itemLister.getSelectedElement();
	if (selectedElement != null)
	{
		this.updateField(selectedElement);
		return true;
	} else {
		return false;
	}
 }
 
 AutoComplete.prototype.updateField=function(aObject)
 {
  if (aObject)
  { 
    this.inputField.value=this.valueReader.read(aObject);
		var theSelectionEvent = new CompletionEvent(aObject, this,aObject);
		this.notifyListener(theSelectionEvent);
	}
	this.closeList();
	this.selectedObject = null;
 }
 
 /**
  * Implementation of the Listener interface to listen to SelectionEvents of the MenuList object. 
  */ 
AutoComplete.prototype.selectionDone=function(aListSelEvent)
{
  if (aListSelEvent)
  {
    var theSelected = aListSelEvent.selectionObject;
    this.updateField(theSelected);
  }  
}
 
 AutoComplete.prototype.closeList=function()
 {
 	var theHandler = this;
 	window.setTimeout('window.autoCompleteList['+theHandler.pos+'].itemLister.close()', 100);
 }
 
 AutoComplete.prototype.buildList=function(aWord, aKeyCode, aMode)
 {
 	
	//document.formular.ausgabe.value = "Key:" + aKeyCode+" word="+aWord+" aMode="+aMode;
	if (aMode==1)
	{
		this.buildArray(aWord,aKeyCode);
	} 
	return true;
 }
 
 AutoComplete.prototype.updateCheck=function(aWord,aKeycode)
 {
  if (aWord==this.word)
  {
    return false;
  }
  else if (aKeycode==8)
  {
    return false;
  }
  if(aWord.length==this.creationLength)
  {
    return true;
  }
  
  if (this.checkList)
  {
    var theL =aWord.length;
    for (var i = 0;i<this.checkList.length;i++)
    {
      if (theL == this.checkList[i])
        return true;
    }
  }
  
  return false;
 }
 
 AutoComplete.prototype.buildArray=function(aWord, aKeyCode)
 {
 	if (aWord==null || aWord.length==0)
  {
			this.closeList();
			return;
  }
  if (this.updateCheck(aWord, aKeyCode))
	{
		//this.array=null;
		this.word=aWord;
		this.createAsync(aWord);
	}
	else if(aWord.length<this.creationLength)
	{
		//doing nothing
		return;
	}
	else
	{
		this.refreshList(this.array, aWord);
	}
 }
 
 
 AutoComplete.prototype.createAsync=function(aWord)
 {
  // here the ajax request must be implemented
  // when the ajax result is received the airport (object) list must be created and
  // the refreshList method must be called.
  // please note the aWord parameter hat to be hold within the ajax calling routine.
  
  var theHandler = this;
  //window.setTimeout('window.autoCompleteList['+theHandler.pos+'].itemLister.block()', 10);
  this.itemLister.block();
  this.loader.loadAsync(aWord);
  
  //this.loader.load(aWord);
  //this.refreshList(this.array, aWord);
 }
 
 AutoComplete.prototype.updateList=function(anArray)
 {
 	this.refreshList(anArray,this.word);
 }
 
 AutoComplete.prototype.refreshList=function(anArray, aWord)
 {
  	this.array=anArray;
	if (anArray!=null)
	{
	  var theSelection = this.buildSelection(anArray, aWord);
		this.itemLister.rebuild(theSelection);
		
	}
 }
 
 AutoComplete.prototype.getArray=function(aWord)
 {
 	return this.array;
 }
 
 
 AutoComplete.prototype.buildSelection=function(anArray, aWord)
 {
 	var theList = this.listBuilder.matchList(anArray, aWord);
 	return theList;
 }
 
 AutoComplete.prototype.processEvent=function(aMode, anEvent)
 {
 	 if(aMode==0)
	 {
	 	return;
	 }
		if (!anEvent) anEvent = event;
		var theKeyCode = anEvent.keyCode;
		if (document.formular)
			document.formular.keys.value = "Key:" + theKeyCode;
		switch (theKeyCode){
			case 13:
				if (this.itemLister.isVisible()){
					var copied = this.copySelectedWord();
					if (copied == false)
					{
						this.takeInputWithoutList();
						this.closeList();
					}
				} else {
					if (this.focus) 
					{
						this.takeInputWithoutList();
						return false;
					}
				}
				break;	
			case 9:
				if (this.itemLister.isVisible()){
					var copied = this.copySelectedWord();
					if (copied == false)
					{
						this.takeInputWithoutList();
						this.closeList();
					}
				} else {
					if (this.focus) 
					{
						this.takeInputWithoutList();						
						return false;
					}
				}
				break;	
			case 38:
				this.moveUp();
				return false;
				break;
			case 40:
				this.moveDown();
				return false;
				break;
			case 27:
				this.closeList();
				return false;
				break;
			case 39:
				this.moveRight();
				return false;
				break;
			case 37:
				this.moveLeft();
				return false;
				break;	
			default:
				this.buildList(this.inputField.value,theKeyCode,aMode);
				break;
		}
 }
 
 AutoComplete.prototype.addCompletionListener=function(aListener)
 {  
   this.listener[this.listener.length]=aListener; 
 }

 AutoComplete.prototype.notifyListener=function(aCompletionEvent)
 {
  
  	for (var i = 0; i< this.listener.length; i++)
 	{
   		this.listener[i].completionChanged(aCompletionEvent);
 	}
 }

 function CompletionEvent(aNewCompletion, aActbObject, anSelectionObject)
 {
 	this.completion=aNewCompletion;
  	this.actbObject = aActbObject;
	this.selectionObject=anSelectionObject;
 }

 function ListSelectionEvent(aSource, aSelectionObject)
 {
	this.source=aSource;
  this.selectionObject=aSelectionObject;
 }
 
 function MenuList (anId, aRootObject)
 {
 	this.rootObject=aRootObject;
 	this.parentElement = null;

	this.visibleFlag=false;
	this.id=anId;
	window[this.id]=this;
	this.childId=this.id+"_child";
	
    this.pList=null;
	this.nodes=null;
	
	this.selectionListener=new Array();
	this.size=0;
	this.currentSelected=-1;
	this.selectedElement=null;
	this.backElement = null;
	this.forwardElement=null;
	this.currOffset=0;
	this.maxDisplayed=5;
	this.listener=new Array();
	this.reader=new HtmlReader(null);
	this.builder=new StringMenuItemBuilder();
	this.hasFocusFlag =false;
	this.child=null;
	
	this.bgcolor='white';
	this.highBgcolor='black';
	this.nonFocusBgColor='gray';
	this.imgBgcolor='gray';
	this.zIndex=800;
	this.left=0;
	this.top=20;
	this.width=130;
	this.fontFamily='Arial, Helvetica, sans-serif';
	this.fontSize='11';
	this.fontBSize='6';
	this.fontColor='red';
	
	this.bFontStyle=null;
	this.fontStyle=null;
	this.parent=null;
	this.isOnFocus=false;
    
	
 }
 
 /**
  * parameter:
  * bgcolor='white';
	highBgcolor='black';
	nonFocusBgColor='gray';
	imgBgcolor='gray';
	zIndex=800;
	left=0;
	top=20;
	width=130;
	fontFamily='Arial, Helvetica, sans-serif';
	fontSize='11';
	fontBSize='6';
	fontColor='red';	
  * 
  * @param {Object} anArray
  */
 MenuList.prototype.initStyle=function(anArray)
 {
 	if (anArray)
	{
	 	for (theId in anArray)
		{
			this[theId]=anArray[theId];
		}
	}
 }
 
 MenuList.prototype.setOnFocus=function(aValue)
 {
  this.isOnFocus=aValue;
 }
 
 
 MenuList.prototype.getOnFocus=function()
 {
  return this.isOnFocus;
 }
 
 
 
 MenuList.prototype.createChild=function()
 {
  this.child=new MenuList(this.id+"_c", this.rootObject);
  this.child.selectionListener=this.selectionListener;
	this.child.builder=this.builder;
	this.child.left = this.left+this.width;
	this.child.bgcolor=this.highBgcolor;
	this.child.highBgcolor=this.bgcolor;
	this.child.parent=this;
	this.child.init();
 }
 
 MenuList.prototype.init=function()
 {
 	this.parentElement=this.createContainer();
  this.rootObject.appendChild(this.parentElement);
 }

 MenuList.prototype.createContainer=function()
 {
  var theParent = document.createElement('div');
	theParent.id=this.id;
	theParent.style.position='absolute';
	theParent.style.top=this.top+'px';
	theParent.style.left=this.left+'px';
	
	theParent.style.zIndex =this.zIndex;
	theParent.style.zindex =this.zIndex;
	theParent.style.visibility='hidden';
	var theHandler = this;
	theParent.onfocus=new function (anEvent){theHandler.onFocusGain(anEvent, true);};
	theParent.onblur=new function (anEvent){theHandler.onFocusGain(anEvent, false);};
	return theParent;
 }
   
 MenuList.prototype.onFocusGain=function(anEvent, aBool)
 {
 	this.hasFocusFlag=aBool;
 }
 
 MenuList.prototype.hasFocus=function()
 {
 	return this.hasFocusFlag;
 }
 
 MenuList.prototype.setContentBuilder=function(aBuilder)
 {
 	this.builder = aBuilder;
 	if (this.child)
 	{ 
 	  this.child.builder=aBuilder;
  }
 }

 MenuList.prototype.handleMovement=function(aMove)
 {
 	if (aMove=='back')
	{
		this.onBackClick();
	}
	else 
	{
		this.onForwardClick();
	}
 }

 MenuList.prototype.getSelectedElement=function()
 {
  if (this.child && this.child.isVisible() && this.child.getOnFocus())
  {
    return this.child.getSelectedElement();
  }
 	if(this.selectedElement)
	{
		var theNo = this.reader.getNodeAttributeValue(this.selectedElement, 'name')
		if (theNo == null)
		{
			return null;
		}
		if (theNo=='back'||theNo=='forward')
		{
			this.handleMovement(theNo);
			return null;
		}
	 	var theRow = Number(theNo);
	 	var theValue= this.pList[theRow];
		if (!theValue)
		{
			alert("No value found for "+theRow);
			return null;
		}
		return theValue;
		
	}
	return null;
 } 
 
 MenuList.prototype.getSelectedNode=function()
 {
 	if(this.selectedElement)
	{
		var theNo = this.reader.getNodeAttributeValue(this.selectedElement, 'name')
		if (theNo == null)
		{
			return null;
		}
		if (theNo=='back'||theNo=='forward')
		{
			return null;
		}
	 	var theRow = Number(theNo);
	 	var theValue= this.nodes[theRow];
		if (!theValue)
		{
			alert("No node found for "+theRow);
			return null;
		}
		return theValue;
		
	}
	return null;
 }
 
 
 MenuList.prototype.setVisible=function(aBool)
 {
 	if (this.parentElement=null)
	{
		this.parentElement = document.getElementById(this.id);
	}
	if(this.parentElement!=null)
	{
		if (aBool)
		{
			this.parentElement.style.visibility='visible';
			this.visibleFlag=true;
		}
		else
		{
		    this.parentElement.style.visibility='hidden';
			this.visibleFlag=false;
		}
			
		
	}
 } 
 

 MenuList.prototype.setChildOnFocus=function(aBool)
 {
 	if (this.child&&this.child.isVisible())
 	{
 	  if (aBool)
 	  {
   	  this.selectedElement.style.backgroundColor=this.nonFocusBgColor;
      this.child.setOnFocus(true);
    }
    else
    {
      this.child.setOnFocus(false);
      this.child.unselectElement();
    }
  }
 }
 
 
 MenuList.prototype.goRight=function()
 {
 	if (this.child&&this.child.isVisible())
 	{
 	  this.setChildOnFocus(true);
    this.child.currOffset=0;
    this.child.currentSelected=-1;
    this.child.selectNext();
  }
 }


 MenuList.prototype.goLeft=function()
 {
 	if (this.child&&this.child.isVisible())
 	{
 	  this.setChildOnFocus(false);
    this.selectedElement.style.backgroundColor=this.highBgcolor;
  }
 	
 }

 
 MenuList.prototype.selectNext=function()
 {
  if (this.child&&this.child.isVisible()&&this.child.getOnFocus())
  {
    this.child.selectNext();
    return;
  }
 	//alert("Select Next called: Selected="+this.currentSelected+" Offset="+this.currOffset+" List="+this.pList);
 	if (this.currentSelected == (this.pList.length-1))	
	{
		//alert("Select Next called: Selected="+this.currentSelected+" Offset="+this.currOffset+" List="+this.pList.length);
		return;
	}
	var theEnd = this.currOffset+this.maxDisplayed;
    if ((this.currentSelected==theEnd) && theEnd<this.pList.length )	
	{
		this.onForwardClick();
		this.selectedElement=null;
	}

	this.currentSelected++;
	this.selectElement(this.getChildId(this.currentSelected));
 }
 
 /// element selection
 MenuList.prototype.selectElement=function(anId)
 {
  var theElement = document.getElementById(anId);
	if (theElement)
	{
		this.unselectElement();
		theElement.style.backgroundColor=this.highBgcolor;
		this.selectedElement=theElement;
		this.openChild();
		return true;
	}
	return false;
 }
 
 MenuList.prototype.unselectElement=function()
 {
  if (this.selectedElement)
	{
		this.selectedElement.style.backgroundColor=this.bgcolor;
		this.selectedElement=null;
	}
 }
 
 MenuList.prototype.openChild=function()
 {
      var theNode = this.getSelectedNode();
      var theFlag = theNode.hasSubNodes();
      
      if(this.child!=null && !theFlag)
			{
			 this.child.close();
      }
      if(theFlag)
      {
        if (this.child==null)
        {
          this.createChild();
        }
        
        var theTop = this.parentElement.style.top;
        var theOutPos = theTop.replace('px', '');
        theOutPos = Number(theOutPos);
        theOutPos+=theNode.getTopPos();

        this.child.parentElement.style.top=theOutPos+'px';
        this.child.rebuild(theNode.getSubList());
      }
      
 }
 
 MenuList.prototype.selectPrev=function()
 {
 	
 	if (this.child&&this.child.isVisible()&&this.child.getOnFocus())
  {
    this.child.selectPrev();
    return;
  }
    if (this.currOffset>0 && (this.currentSelected == this.currOffset))	
	{
		this.onBackClick();
		this.selectedElement=null;
	}
    else if (this.currentSelected == 0)	
	{
		return;
	}

    this.currentSelected--;
	
	this.selectElement(this.getChildId(this.currentSelected));
 }
 
 MenuList.prototype.getChildId=function(aListNumber)
 {
 	return this.childId+"_"+aListNumber;
 }
 
 MenuList.prototype.isVisible=function()
 {
 	return this.visibleFlag;
 }
 
 MenuList.prototype.close=function()
 {
 	if (this.parentElement)
	{
		this.parentElement.style.visibility='hidden';
		/*if (this.rootObject.getElementById(this.id))
		{
			this.rootObject.removeChild(this.id);
		}*/
 		this.currentSelected=-1;
		this.size=null;
		//this.pList=null;
		this.selectedElement = null;
		this.visibleFlag=false;
		this.setOnFocus(false);
	}
	if (this.child)
	{
		this.child.close();
		
	}
 }
 
 MenuList.prototype.rebuild=function(aList)
 {
   if (this.parent != null && !this.parent.visibleFlag)
   {
    return;
   }
   this.currentSelected=-1;
	 this.size=null;
	 this.pList=null;
	 this.selectedElement = null;
	 this.visibleFlag=false;
	
 	 this.buildUp(aList,0);
 }
 
 
 
 MenuList.prototype.buildUp=function(aList, aOffset)
 {
 	this.pList = aList;
	if (aList==null || aList.length ==0)
	{
		this.close();
		return;
	}
	this.nodes=new Array();
	this.currOffset=aOffset;
	var theParent = new DIVElement();
	theParent.addAttribute('id', this.childId);
	theParent.addStyleElement('position', 'absolute');
	theParent.addStyleElement('top',0+'px' );
	theParent.addStyleElement('left',0+'px' );
	theParent.addStyleElement('width',this.width+'px' );
	
	theParent.addStyle(this.getStyle());
	
	this.addChildren(theParent, aList, aOffset);
	if (!this.parentElement)
	{
		this.parentElement = document.getElementById(this.id);
	}
    if (this.parentElement)
	{		
		this.parentElement.innerHTML=theParent.write();
		this.parentElement.style.visibility='visible';
		this.visibleFlag=true;
	}
	else alert("parent is null");
 }
 
 MenuList.prototype.addChildren=function(aParent, aList, aOffset)
 {
 	var theCount = 0;
	var thePOS = 0;
	var theTop=10;
	var theHeight=15;
	var theBackElement=this.getBackElement(aOffset,10);
	aParent.addElement(theBackElement);
	thePOS=1;
	
    var i=aOffset;
 	for(i=aOffset; i<aList.length && theCount<=this.maxDisplayed; i++)
	{
	  
		var theElement = new DIVElement();
		theElement.addAttribute('id', this.childId+"_"+i);
		theElement.addAttribute('name', i);
		theElement.addStyleElement('position', 'absolute');
		theElement.addStyleElement('top',(theTop)+'px' );
		theElement.addStyleElement('width',this.width+'px' );
		theElement.addStyleElement('height',15+'px' );
		theElement.addStyleElement("background-color", this.bgcolor);
		theElement.addAttribute('onclick','return window.'+this.id+'.elementSelected(\''+this.childId+"_"+i+'\',\''+i+'\');');
		theElement.addAttribute('onmouseover','return window.'+this.id+'.overElement(\''+this.childId+"_"+i+'\',\''+i+'\');');
		theElement.addAttribute('onmouseout','return window.'+this.id+'.outElement(\''+this.childId+"_"+i+'\',\''+i+'\');');
		theElement.addStyle(this.getStyle());
		var thePElement = new PElement();
		var theNode = this.builder.buildContent(aList[i],i, theTop);
		this.nodes[i]=theNode;
		thePElement.addContent(theNode.getName());
		theElement.addElement(thePElement);
		aParent.addElement(theElement);
		
		theCount++;
		thePOS++;
   	theTop+=theHeight;    
	}
	///alert("Count="+theCount+" Max="+this.maxDisplayed+" i="+i+" Offset="+aOffset);
		//this.currOffset=i;
	aParent.addElement(this.getForwardElement(theCount, i<aList.length-1,theTop, 10))
	
 }
 
MenuList.prototype.getBackElement=function(aOffset, aHeight)
 {
 	if (this.backElement == null)
	{
		
		var theElement = new DIVElement();
		theElement.addAttribute('id', this.childId+"_back");
		theElement.addAttribute('name', "back");
		theElement.addStyleElement('position', 'absolute');
		theElement.addStyleElement('top',(0)+'px' );
		theElement.addStyleElement('width',this.width+'px' );
		theElement.addStyleElement('height',aHeight+'px' );
		theElement.addStyleElement("background-color", this.imgBgcolor);
		theElement.addStyle(this.getBStyle());
		theElement.addStyleElement('text-align', 'center');
    	theElement.addStyleElement('vertical-align','middle');
    theElement.addAttribute('onmouseover','return window.'+this.id+'.onBackClick();');
		
		this.backElement = theElement;
	}
	this.backElement.removeElements()
	var thePElement = new PElement();
	if (aOffset > 0)
	{
		thePElement.addContent("Back");
		thePElement.addAttribute('onclick','return window.'+this.id+'.onBackClick();');
	}
	
	this.backElement.addElement(thePElement);
	return this.backElement;
}

MenuList.prototype.getElement=function (anId)
{
	var theElement = document.getElementById(anId)
	if (!theElement)
	{
		return null;
	}
	return theElement;
}

MenuList.prototype.getForwardElement=function(aCount, aNotAtEndFlag,aTop, aHeight)
 {
 	if (this.forwardElement == null)
	{
		
		var theElement = new DIVElement();
		theElement.addAttribute('id', this.childId+"_Forw");
		theElement.addAttribute('name', "forward");
		theElement.addStyleElement('position', 'absolute');
		theElement.addStyleElement('width',this.width+'px' );
		theElement.addStyleElement('height',aHeight+'px' );
		theElement.addStyleElement("background-color", this.imgBgcolor);
		theElement.addStyle(this.getBStyle());
	    theElement.addStyleElement('text-align', 'center');
    	theElement.addStyleElement('vertical-align','middle');
    theElement.addAttribute('onmouseover','return window.'+this.id+'.onForwardClick();');
		var thePElement = new PElement();
		
		theElement.addElement(thePElement);
		this.forwardElement=theElement;
	}
	this.forwardElement.addStyleElement('top',aTop+'px' );
	this.forwardElement.removeElements()
	var thePElement = new PElement();
    if (aCount >= this.maxDisplayed && aNotAtEndFlag)
	{
		thePElement.addContent("Forward");
		thePElement.addAttribute('onclick','return window.'+this.id+'.onForwardClick();');

	} 
	
	this.forwardElement.addElement(thePElement);
	return this.forwardElement;
}



MenuList.prototype.block=function()
{
 if (document.formular)
	document.formular.ausgabe.value = "writing wait... visible=" +this.visibleFlag;
	if(true)//!this.visibleFlag)
	{
		
	var theParent = new DIVElement();
	theParent.addAttribute('id', this.childId);
	theParent.addStyleElement('position', 'absolute');
	theParent.addStyleElement('top',(0)+'px' );
	theParent.addStyleElement('left',(0)+'px' );
	theParent.addStyleElement('width',100+'px' );
	theParent.addStyleElement('height',100+'px' );
	theParent.addStyleElement("background-color", this.bgcolor);
	
	theParent.addStyle(this.getStyle());
	var theImageElement = new DIVElement();
	theImageElement.addStyleElement('position', 'absolute');
	theImageElement.addStyleElement('top',(20)+'px' );
	theImageElement.addStyleElement('left',(20)+'px' );
	theImageElement.addStyleElement('width',80+'px' );
	theImageElement.addStyleElement('height',80+'px' );
	var theP = new PElement();
	theP.addContent("bitte warten ...");
	theImageElement.addElement(theP);
	theParent.addElement(theImageElement);
	
	if (!this.parentElement)
	{
		this.parentElement = document.getElementById(this.id);
	}
    if (this.parentElement)
	{		
		this.parentElement.innerHTML=theParent.write();
		this.parentElement.style.visibility='visible';
		this.visibleFlag=true;
	}
	else alert("parent is null");
	if (document.formular)
	 document.formular.ausgabe.value = "writing wait... ready visible="+this.visibleFlag;
	}
}

MenuList.prototype.elementSelected=function(anId, aNo)
{
	 if (this.selectElement(anId))
	 {
	   this.notifySelectionListener(new ListSelectionEvent(this, this.getSelectedElement()));
	}
}
 
MenuList.prototype.notifySelectionListener=function(anEvent)
{
  if(this.listener)
  {
    for (var i =0; i< this.listener.length; i++)
    { 
      this.listener[i].selectionDone(anEvent);
    }
  }
}

MenuList.prototype.addSelectionListener=function(aListener)
{
  this.listener[this.listener.length]=aListener;
}
 
MenuList.prototype.overElement=function(anId, aNo)
{
  
  if (this.parent)
  {
    this.parent.setChildOnFocus(true);
  }
  if (this.child && this.child.isVisible())
  {
    this.child.setChildOnFocus(false);
  }
  this.selectElement(anId);
} 
 
MenuList.prototype.outElement=function(anId, aNo)
{
  this.selectElement(anId);
}
 
MenuList.prototype.onBackClick=function()
{
	if (this.currOffset > 0)
	{
		if (this.currOffset<=this.maxDisplayed)
		{
			this.currOffset=0;
		}
		else{
			this.currOffset-=this.maxDisplayed;
		}
		this.buildUp(this.pList, this.currOffset);
	}
	
}

MenuList.prototype.onForwardClick=function()
{
  	if ((this.currOffset+this.maxDisplayed)<this.pList.length)
  	{
      this.currOffset+=this.maxDisplayed;
    	this.buildUp(this.pList, this.currOffset);
    }
}


MenuList.prototype.getStyle=function()
{
	
  if (this.fontStyle==null)
  {
  	this.fontStyle = 'font-family:'+this.fontFamily+';'+' font-size:'+this.fontSize+'px;'+' color:'+this.fontColor+';';
  }	
	
  return this.fontStyle;
  //'font-family:'+this.fontFamily+';'+' font-size:'+this.fontSize+'px;'+' color:'+this.fontColor+';';
  
  //"font-family:Arial, Helvetica, sans-serif; font-size:11px; color:red;";
}

MenuList.prototype.getBStyle=function()
{
  if (this.bFontStyle==null)
  {
  	this.bFontStyle = 'font-family:'+this.fontFamily+';'+' font-size:'+this.fontBSize+'px;'+' color:'+this.fontColor+';';
  }	
  return this.bFontStyle;
  
  //return "font-family:Arial, Helvetica, sans-serif; font-size:6px; color:red;";
}

 MenuList.prototype.addSelectionListener=function(aListener)
 {
 	this.selectionListener[this.selectionListener.length]=aListener;
 }
 
 MenuList.prototype.notifySelectionListener=function(aEvent) 
 {
 	for(var i = 0; i< this.selectionListener.length; i++)
	{
 		this.selectionListener[i].selectionDone(aEvent);
	}
 }
 
 
 function StringMenuItemBuilder()
 {
 	
 }
 
 StringMenuItemBuilder.prototype.buildContent=function(anObject, aRow, aTop)
 {
 	return new StringItem(anObject.toString(), aRow);
 }
 


 function AirportMenuItemBuilder()
 {
 	
 }
 
 AirportMenuItemBuilder.prototype.buildContent=function(anObject, aRow, aTop)
 {
 	return new AirportItem(anObject, anObject.name,aRow, aTop);
 }
 
 
 function AirportItem(anObject, aName, aNo, aTop)
 {
 	this.airport=anObject;
	this.name = aName;
	this.no=aNo;
	this.topPos=aTop;
 }

 AirportItem.prototype.getName=function()
 {
 	return this.name;
 }

 AirportItem.prototype.hasSubNodes=function()
 {
 	return this.airport.hasSub();
 }
 
 AirportItem.prototype.getSubList=function()
 {
 	return this.airport.getSubports();
 }

 AirportItem.prototype.getTopPos=function()
 {
 	return this.topPos;
 }


 function StringItem(aName, aNo)
 {
	this.name = aName;
	this.no=aNo;
 }
 StringItem.prototype.getName=function()
 {
 	return this.name;
 }

 StringItem.prototype.hasSubNodes=function()
 {
 	return false;
 }
 StringItem.prototype.getSubList=function()
 {
 	return null;
 }
 
 
 function AirportReader()
 {
 	
 }
 
 AirportReader.prototype.read=function(aValue)
 {
 	if(aValue ==null)
	{
		return '';
	}
 	return aValue.name;
 }
