var Behaviour = {
  list: [],
  listOnce: [],
  
  register: function(sheet)
  {
    if (!$defined(sheet)) 
    {
      return;
    }
    
    Behaviour.list.push(sheet);
  },
  
  registerOnce: function(sheet)
  {
    Behaviour.listOnce.push(sheet);
  },
  
  start: function()
  {
    window.addEvent('domready', function()
    {
      Behaviour.apply();
      Behaviour.apply(Behaviour.listOnce);
    });
  },
  
  apply: function(Behaviours)
  {
    if (!$defined(Behaviours)) 
    {
      Behaviours = Behaviour.list;
    }
    
    for (h = 0; (sheet = Behaviours[h]); h++) 
    {
      for (selector in sheet) 
      {
        document.getElements(selector).each(sheet[selector]);
      }
    }
  }
};

Behaviour.start();





MTJax = {
  responded: function(Response)
  {
    eval('Response = ' + Response.responseText);
    
    if (Response.Actions) 
    {
      MTJax.Action.execute(Response.Actions);
    }
    
    Behaviour.apply();
  },
  indicateActivity: function()
  {
    var Indicator = $('jax_indicator');
    console.log(Indicator);
    Indicator.style.visibility = 'hidden';
    Indicator.style.display = 'block';
    Util.centerOnScreen(Indicator);
    Indicator.style.visibility = 'visible';
    MTJax.Overlay.showWrapper();
  }
};
MT_Jax = MTJax;








MT_Jax.FlowSelector = {
  options: {
    container: null,
    height: 300,
    width: 100,
    padding: 10
  },
  conTop: null,
  conBottom: null,
  conMiddle: null,
  getContainer: function()
  {
    return this.conMiddle;
  },
  evtMouseleave: function()
  {
    this.destroy();
  },
  evtMousemove: function(e)
  {
    coords = this.getParent().getCoordinates();
    coords.top    += 30;
    coords.height -= 40;
    mouseIn = e.page.y - coords.top;
    relative = coords.height / mouseIn;
    this.scrollTop = (this.scrollHeight - coords.height) / relative;
    this.lastPageCoords = e.page;
  },
  evtMousewheel: function(e)
  {
    e.stop();
    this.setStyle('top', (parseInt(this.getStyle('top')) + ((e.wheel * 8) * -1)) + 'px');
    e.page = this.lastPageCoords;
    this.fireEvent('mousemove', e);
  },
  show: function(e)
  {
    var posTop = e.page.y - 50;
    var posLeft = e.page.x - 50;
    
    var conHeight = this.options.height;
    
    checkY = window.getScroll().y + window.getSize().height;
    
    if (posTop + conHeight > checkY) 
    {
      posTop = checkY - this.options.height - 60 - (this.options.padding * 2);
    }
    
    this.container.setStyles({
      position: 'absolute',
      top: posTop,
      left: posLeft
    });
    this.container.injectInside(document.getElement('body'));
    
    this.container.addEvent('mouseleave', this.evtMouseleave.bind(this.container));
    
    this.conMiddle.addEvent('mousemove', this.evtMousemove.bindWithEvent(this.conMiddle));
    this.conMiddle.addEvent('mousewheel', this.evtMousewheel.bindWithEvent(this.container));
    this.conMiddle.addEvent('hide', function()
    {
      this.fireEvent('mouseleave')
    }.bind(this.container));
    this.conMiddle.fireEvent('mousemove', e);
  },
  initialize: function(options)
  {
    this.setOptions(options);
    
    if (window.ie && !window.ie7) 
    {
      this.conMiddle = this.container = new Element('div');
      this.container.setStyles({
        'background-color': 'white',
        border: '1px solid black',
        padding: 10,
        overflow: 'hidden',
        height: this.options.height,
        width: this.options.width
      });
    }
    else 
    {
    
      this.container = new Element('div');
      this.conTop = new Element('div');
      
      topCon = new Element('div');
      topLeft = new Element('div');
      topFill = new Element('div');
      topRight = new Element('div');
      
      botCon = new Element('div');
      botLeft = new Element('div');
      botFill = new Element('div');
      botRight = new Element('div');
      
      midCon = new Element('div');
      midLeft = new Element('div');
      this.conMiddle = midFill = new Element('div');
      midRight = new Element('div');
      
      topCon.adopt(topLeft);
      topCon.adopt(topFill);
      topCon.adopt(topRight);
      
      topLeft.set('html', '&nbsp;');
      topFill.set('html', '&nbsp;');
      topRight.set('html', '&nbsp;');
      
      topCon.setStyles({
        width: this.options.width + 60,
        height: 30
      });
      topLeft.setStyles({
        width: 30,
        height: 30,
        'float': 'left'
      });
      topFill.setStyles({
        width: this.options.width,
        height: 30,
        'float': 'left'
      });
      topRight.setStyles({
        width: 30,
        height: 30,
        'float': 'left'
      });
      
      botCon.adopt(botLeft);
      botCon.adopt(botFill);
      botCon.adopt(botRight);
      
      botLeft.set('html', '&nbsp;');
      botFill.set('html', '&nbsp;');
      botRight.set('html', '&nbsp;');
      
      botCon.setStyles({
        width: this.options.width + 60,
        height: 30
      });
      botLeft.setStyles({
        width: 30,
        height: 30,
        'float': 'left'
      });
      botFill.setStyles({
        width: this.options.width,
        height: 30,
        'float': 'left'
      });
      botRight.setStyles({
        width: 30,
        height: 30,
        'float': 'left'
      });
      
      midCon.adopt(midLeft);
      midCon.adopt(midFill);
      midCon.adopt(midRight);
      
      midLeft.set('html', '&nbsp;');
      midFill.set('html', '&nbsp;');
      midRight.set('html', '&nbsp;');
      
      midCon.setStyles({
        width: this.options.width + 60,
        height: this.options.height,
        overflow: 'hidden'
      });
      midLeft.setStyles({
        width: 30,
        height: this.options.height,
        'float': 'left'
      });
      midFill.setStyles({
        width: this.options.width,
        height: this.options.height,
        'float': 'left',
        overflow: 'hidden'
      });
      midRight.setStyles({
        width: 30,
        height: this.options.height,
        'float': 'left'
      });
      
      if (Browser.Engine.trident4) 
      {
        topLeft.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-top-left.png',sizingMethod='scale');");
        topFill.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-top-fill.png',sizingMethod='scale');");
        topRight.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-top-right.png',sizingMethod='scale');");
        
        botLeft.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-bottom-left.png',sizingMethod='scale');");
        botFill.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-bottom-fill.png',sizingMethod='scale');");
        botRight.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-bottom-right.png',sizingMethod='scale');");
        
        midLeft.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-fill-left.png',sizingMethod='scale');");
        midFill.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-fill-fill.png',sizingMethod='scale');");
        midRight.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/media/Image/Icons/pop-menu-fill-right.png',sizingMethod='scale');");
      }
      else 
      {
        topLeft.setStyle('background', 'url(/media/Image/Icons/pop-menu-top-left.png) no-repeat left top');
        topFill.setStyle('background', 'url(/media/Image/Icons/pop-menu-top-fill.png) repeat-x left top');
        topRight.setStyle('background', 'url(/media/Image/Icons/pop-menu-top-right.png) no-repeat left top');
        
        botLeft.setStyle('background', 'url(/media/Image/Icons/pop-menu-bottom-left.png) no-repeat left top');
        botFill.setStyle('background', 'url(/media/Image/Icons/pop-menu-bottom-fill.png) repeat-x left top');
        botRight.setStyle('background', 'url(/media/Image/Icons/pop-menu-bottom-right.png) no-repeat left top');
        
        midLeft.setStyle('background', 'url(/media/Image/Icons/pop-menu-fill-left.png) repeat-y left top');
        midFill.setStyle('background', 'url(/media/Image/Icons/pop-menu-fill-fill.png) left top');
        midRight.setStyle('background', 'url(/media/Image/Icons/pop-menu-fill-right.png) repeat-y left top');
      }
      
      this.container.adopt(topCon);
      this.container.adopt(midCon);
      this.container.adopt(botCon);
    }
  }
};
MT_Jax.FlowSelector = new Class(MT_Jax.FlowSelector);
MT_Jax.FlowSelector.implement(new Options);
MT_Jax.FlowSelector.implement(new Events);






/**
 * 
 */
Bank = {
    TimeOut: null,
    FetchStarted: false,
    SearchLocation: 0,
    Result: [],
    TargetPage: 'mitte.php',
    PopUpTarget: 'location_deteil.php',
    Trigger: null,
    LinkParam: {'href': '/order.dynamicdetail/currentOrder,##id##'},
//    LinkParamsDM: {
//        'href1': '/mail.customer/currentOrder,##id##',
//        'href2': '/order.dynamicdetail/currentOrder,##id##'
//    },
    
    probe: function(Elem, Value)
    {
        Bank.LinkParam = {
            'href': '/order.dynamicdetail/currentOrder,##id##'
        };
        Bank.Trigger = Elem;
        if (Bank.SearchLocation == Value)
          return;
          
        Bank.SearchLocation = Value;
        
//      if (Bank.SearchLocation.length > 0 && Bank.FetchStarted == false)
        if (Bank.TimeOut)
        {
            window.clearTimeout(Bank.TimeOut);
        }
        
//          Bank.TimeOut = window.setTimeout(Bank.hideJaxector, 10000);
        Bank.TimeOut = window.setTimeout(Bank.fetch, 500);
    },

    /**
     * Nochmal die gleiche Funktion, diesmal aber mit Setzen anderer
     * Parameter fuer den A-Tag in der angezeigten Liste.
     */
    probePosition: function(Elem, Value)
    {
        Bank.LinkParam = {
            'href': 'javascript:void(0);',
            'onclick': 'Bank.Trigger.value=\'##id##\';Bank.hideJaxector();Bank.Trigger.onchange();'
        };
        Bank.Trigger = Elem;
        if (Bank.SearchLocation == Value)
            return;

        Bank.SearchLocation = Value;
        if (Bank.TimeOut)
        {
            window.clearTimeout(Bank.TimeOut);
        }
        
        Bank.TimeOut = window.setTimeout(Bank.fetch, 500);
    },
    
    placeJaxector: function()
    {
        JaXector                    = $('jaxector');
        JaXector.style.width        = '440px';
        Pos                         = Util.getPos(Bank.Trigger);        
        JaXector.style.display       = 'block';
//        JaXector.style.left         = Pos.x + 'px';
//        JaXector.style.top          = (Pos.y + Bank.Trigger.offsetHeight + 10) + 'px';
        Util.snapTo(JaXector, Bank.Trigger, 'rbv', 0);
    },
    
    hideJaxector: function()
    {
        JaXector                    = $('jaxector');
        JaXector.style.display    = 'none';
    },
    
    fetch: function()
    {
        Bank.FetchStarted = true;
//      alert('Beeing here');
        new ajax('/plugin/de.masstisch.ajax/Order/SearchName.php', {
            method: 'post',
            postBody: 'name=' + encodeURIComponent(Bank.SearchLocation),
            onComplete: Bank.show
        });
    },
    
    show: function(Response)
    {
        Bank.FetchStarted       = false;
        
        eval('Response = ' + Response.responseText);

        JaXectorData            = $('jaxector_data');
        Bank.Result             = Response;
        console.log(Bank.Result.Liste);

        if (Bank.Result.Liste.length > 0)
        {
            JaXectorData.innerHTML = Bank.paintTable();
            Bank.placeJaxector();
        
            if (Bank.TimeOut)
                window.clearTimeout(Bank.TimeOut);
        
//          Bank.TimeOut = window.setTimeout(Bank.hideJaxector, 10000);
        }
        else
        {
            JaXectorData.innerHTML = Bank.paintBlank();
            Bank.placeJaxector();
        }
    }
    
    ,useResultLocation: function(ID)
    {
        var UseLocation = Bank.Result.Liste[ID];
        
        Bank.Trigger.goId(UseLocation.id);

        Bank.hideJaxector();
//      Bank.TimeOut = window.setTimeout(Bank.hideJaxector, 2000);
    }
    
    ,useResultCity: function(ID)
    {
        PGG.Search.showResults(Bank.Result.Cities[ID].id);
        Bank.TimeOut = window.setTimeout(Bank.hideJaxector, 2000);
    }
    
    ,paintBlank: function()
    {
        var Table = '';
        Table += 'Keine Einträge gefunden';
        return Table;
    }
    
    ,paintTable: function()
    {
        var Err;

        try
        {
            var Table = '';
            Table += '<table>\n';
            
            ClassNames = ['a', 'b'];
            
            for (OnCity = 0; OnCity < Bank.Result.Liste.length; OnCity ++)
            {
                CityNfo = Bank.Result.Liste[OnCity];
                stat = CityNfo.status.substr(0, 3).toUpperCase();
                prefix = '';
                switch (CityNfo.status.toLowerCase()) {
                    case 'auftrag':
                        break;
                    case 'el':
                    case 'korr':
                    case 'storno':
                        prefix = '<b class="order-status korrektur">'+stat+'</b> ';
                        break;
                    case 'lager':
                    case 'lageriv':
                    case 'eigen':
                        prefix = '<b class="order-status lager">'+stat+'</b> ';
                        break;
                    case 'angebot':
                        prefix = '<b class="order-status angebot">'+stat+'</b> ';
                        break;
                    case 'gutschrift':
                        prefix = '<b class="order-status gutschrift">'+stat+'</b> ';
                        break;
                    case 'sonstabr':
                        prefix = '<b class="order-status sonst">'+stat+'</b> ';
                        break;
                    case 'onhold':
                        prefix = '<b class="order-status onhold">'+stat+'</b> ';
                        break;
                }
    
//  onclick="Bank.useResultLocation(' + OnCity + ');"
                if (CityNfo.name != '')
                {
                    AnzeigeName = CityNfo.name + ', ' + CityNfo.vorname;
                    if (Bank.Result.Firma)
                    {
                        AnzeigeName = '<b>' + CityNfo.firma + ':</b> ' + AnzeigeName;
                    }
                }
                else
                {
                    if (CityNfo.firma != '')
                    {
                        AnzeigeName = CityNfo.firma;
                    }
                    else
                    {
                        AnzeigeName = '<i>[Name fehlt!]</i>';
                    }
                }
                linkParam = '';
//                switch (CityNfo.max_dm * 1)
//                {
//                    case 2:
//                        Bank.LinkParam['href'] = Bank.LinkParamsDM['href2'];
//                        break;
//                    default:
//                        Bank.LinkParam['href'] = Bank.LinkParamsDM['href1'];
//                        break;
//                }
                for (param in Bank.LinkParam)
                {
                    linkParam += ' ' + param + '="' + Bank.LinkParam[param].replace(/##id##/, CityNfo.id) + '"';
                }
                Table += '<tr class="' + ClassNames[OnCity % 2] + '">\n';
                    Table += '<td style="white-space: nowrap;">'+prefix+'<a' + linkParam + '>' + AnzeigeName + '</a></td>\n';
                    Table += '<td style="white-space: nowrap;"><a' + linkParam + '>' + CityNfo.id + '</a></td>\n';
                    Table += '<td style="white-space: nowrap;">' + CityNfo.datum + '</td>\n';
                    Table += '<td style="white-space: nowrap;">' + CityNfo.ag + '</td>\n';
                Table += '</tr>\n';
            }
            
            Table += '</table>\n';   
        }
        catch (e)
        {
            Err = e;
        }
        
        if (Err)
          console.log(Err);
        
        return Table;
    }
};

/**
 * Klasse zum Anzeigen von Auswahllisten fuer AJAX-Eingabehilfen, ...
 * In der angezeigten Liste kann ein Eintrag ueber die Cursortasten
 * ausgewaehlt werden.
 */
function MT_DynList(Field, List)
{
    // Array mit allen Listen-Eintraegen:
    this.List = List;
    this.listElem = false;
    this.staticTimeout = false;
    // Irgendwelche Parameter, die gebraucht werden:
    this.Param = {};
    
    // Liste fertig?:
    this.listShowed = false;

    // Eingabefeld, zu dem die Liste angezeigt werden soll (DOM-Element):
    this.Field = Field;
    this.lastValue = false;

    // markierter Listen-Eintrag:
    this.currentEntry = false;
    this.blurDisable = false;
    this.blurRequest = false;
    this.firstCall = true;
    this.Field.onfocus = this.showList.bind(this);
    this.Field.onblur = this.closeList.bind(this);
    this.Field.onkeydown = this.useBrowse.bindWithEvent(this);
    this.Field.onkeyup = this.useUpdateList.bind(this);
    this.Field.onchange = this.useChangedField.bind(this);
}
MT_DynList.prototype.alertChange = function()
{
//    alert('Change!');
    this.changedField();
}
/**
 * Parameter setzen:
 */
MT_DynList.prototype.getParam = function(key)
{
    if (this.Param[key])
    {
        return this.Param[key];
    }
    else
    {
        return false;
    }
}

/**
 * Parameter setzen:
 */
MT_DynList.prototype.setParam = function(key, val)
{
    this.Param[key] = val;
}

/**
 * List anzeigen:
 */
MT_DynList.prototype.showList = function()
{
    if (!this.listElem)
    {
        this.buildList();
    }
    this.listElem.style.display = 'block';
    Util.snapTo(this.listElem, this.Field, 'lbv');
    this.listShowed = true;
    this.blurDisable = false;
    this.updateList();
}

/**
 * Liste schliessen:
 */
MT_DynList.prototype.closeList = function()
{
    if (!this.blurDisable)
    {
        this.listElem.style.display = 'none';
        this.listShowed = false;
        this.executeEntry();
    }
}

/**
 * Irgendwas machen, wenn die Eingabe beendet ist:
 */
MT_DynList.prototype.executeEntry = function()
{
    //
}

/**
 * erlaube Schliessen:
 */
MT_DynList.prototype.enableBlur = function()
{
    this.blurDisable = false;
}

/**
 * verbiete Schliessen, gleichzeitig aktuellen Eintrag (MouseOver) markieren:
 */
MT_DynList.prototype.disableBlur = function(e)
{
    this.blurDisable = true;
    if (this.currentEntry)
    {
        this.currentEntry.removeClass('current');
    }
    this.currentEntry = e.target;
    this.currentEntry.addClass('current');
}

/**
 * Aufrufmethode fuer changedField, damit das bind auch nach
 * Neu-Implementierung funktioniert:
 */
MT_DynList.prototype.useChangedField = function()
{
    this.changedField();
}
/**
 * Aktion bei Aenderung des Feldinhaltes (bei Bedarf in Instanz ueberladen):
 */
MT_DynList.prototype.changedField = function()
{
    this.Field.changed = true;
}

/**
 * Aufrufmethode fuer browse, damit das bind auch nach
 * Neu-Implementierung funktioniert:
 */
MT_DynList.prototype.useBrowse = function(e)
{
    this.browse(e);
}
/**
 * Mit Cursortasten [oder MouseOver] durch Liste navigieren:
 */
MT_DynList.prototype.browse = function(e)
{
    if (this.listShowed)
    {
        // nur bei angezeigter Liste:
        this.enableBlur();
        switch (e.code)
        {
            case 13:
                // Enter:
                if (this.currentEntry)
                {
                    this.setFieldText(this.getText(this.currentEntry));
                    this.changedField();
                }
                this.closeList();
                break;

            case 38:
                // Cursor up:
                if (this.listElem.firstChild)
                {
                    if (!this.currentEntry)
                    {
                        this.currentEntry = this.listElem.firstChild;
                    }
                    this.currentEntry.removeClass('current');
                    if (next = this.currentEntry.previousSibling)
                    {
                        this.currentEntry = next;
                    }
                    else
                    {
                        this.currentEntry = this.currentEntry.parentNode.lastChild;
                    }
                    this.currentEntry.addClass('current');
                    this.setFieldText(this.getText(this.currentEntry));
                    this.changedField();
                }
                break;

            case 40:
                // Cursor down:
                if (this.listElem.firstChild)
                {
                    if (!this.currentEntry)
                    {
                        this.currentEntry = this.listElem.firstChild;
                    }
                    this.currentEntry.removeClass('current');
                    if (next = this.currentEntry.nextSibling)
                    {
                        this.currentEntry = next;
                    }
                    else
                    {
                        this.currentEntry = this.currentEntry.parentNode.firstChild;
                    }
                    this.currentEntry.addClass('current');
                    this.setFieldText(this.getText(this.currentEntry));
                    this.changedField();
                }
                break;

            default:
                this.updateList();
                break;
        }
    }
    else
    {
        this.updateList();
        this.showList();
    }
}

/**
 * Aus Listen-Array Anzeige-Liste generieren:
 */
MT_DynList.prototype.buildList = function()
{
    this.listElem = document.createElement('ul');
    feld = this.Field.getCoordinates();
    currentText = this.optimizeText(this.Field.value.toLowerCase());
    first = true;
    if (this.List.length > 0)
    {
        for (li = 0; li < this.List.length; li++)
        {
            liElem = document.createElement('li');
            liElem.innerHTML = this.List[li];
            if ((li % 2) != 0)
            {
                liElem.addClass('odd')
            }
            this.listElem.appendChild(liElem);
            if (this.List[li].toLowerCase().substr(0, currentText.length) == currentText)
            {
                this.currentEntry = liElem;
                first = false;
            }
    //        liElem.onclick = this.clickList.bindWithEvent(this);
        }
        if (first)
        {
            this.currentEntry = this.listElem.firstChild;
        }
        this.currentEntry.addClass('current');
    }
    this.listElem.style.display = 'none';
    this.listElem.style.width = feld.width + 'px';
    this.listElem.style.zIndex = 1000;
    this.listElem.addClass('mtDynList');
    document.body.appendChild(this.listElem);
    this.listElem.style.position = 'fixed';
    this.listGenerated = true;
    this.listElem.onclick = this.clickList.bind(this);
    this.listElem.onmouseover = this.disableBlur.bind(this);
    this.listElem.onmouseout = this.enableBlur.bind(this);
}

/**
 * Aus Listen-Array Anzeige-Liste neu generieren:
 */
MT_DynList.prototype.rebuildList = function()
{
    // alte Eintraege rauswerfen:
    
    while (this.listElem.firstChild)
    {
        this.listElem.removeChild(this.listElem.firstChild);
    }
    currentText = this.optimizeText(this.Field.value.toLowerCase());
    first = true;
    if (this.List.length > 0)
    {
        for (li = 0; li < this.List.length; li++)
        {
            liElem = document.createElement('li');
            liElem.innerHTML = this.List[li];
            if ((li % 2) != 0)
            {
                liElem.addClass('odd')
            }
            this.listElem.appendChild(liElem);
            if (this.List[li].toLowerCase().substr(0, currentText.length) == currentText)
            {
                this.currentEntry = liElem;
                first = false;
            }
        }
        if (first)
        {
            this.currentEntry = this.listElem.firstChild;
        }
        this.currentEntry.addClass('current');
    }
    this.listGenerated = true;
}

/**
 * Klicken auf Listen-Eintrag verarbeiten:
 */
MT_DynList.prototype.clickList = function(e)
{
    this.setFieldText(this.optimizeText(e.target.textContent));
    this.changedField();
    this.enableBlur();
    this.closeList();
}

/**
 * Liste aktualisieren (muss jeweils implementiert werden):
 */
MT_DynList.prototype.setList = function(List)
{
    if (!this.listElem)
    {
        this.buildList();
    }
    this.List = List;
    this.rebuildList();
}

/**
 * Aufrufmethode fuer changedField, damit das bind auch nach
 * Neu-Implementierung funktioniert:
 */
MT_DynList.prototype.useUpdateList = function()
{
    this.updateList();
}
/**
 * Liste aktualisieren (muss bei Bedarf implementiert werden):
 */
MT_DynList.prototype.updateList = function()
{
    this.updateListStatic();
}

/**
 * Liste aktualisieren (statische Liste ohne AJAX-Reload):
 */
MT_DynList.prototype.updateListStatic = function()
{
    if (this.staticTimeout)
    {
        window.clearTimeout(this.staticTimeout);
    }
    this.staticTimeout = window.setTimeout(this.updateListStaticDo.bind(this), 250);
}
MT_DynList.prototype.updateListStaticDo = function()
{
    // Bei Texteingaben passenden Eintrag aus Liste suchen oder
    // currentMarkierung entfernen...
    currentText = this.optimizeText(this.Field.value.toLowerCase());
    cTL = currentText.length;
    if (this.currentEntry)
    {
        currentEntryText = this.getText(this.currentEntry).toLowerCase();
        if (currentEntryText != currentText) // .substr(0, cTL)
        {
            this.currentEntry.removeClass('current');
            this.currentEntry = false;
        }
    }
    if (!this.currentEntry && (Elem = this.listElem.firstChild))
    {
        found = false;
        do {
            text = this.getText(Elem).toLowerCase();
            if (text.substr(0, cTL) == currentText)
            {
                found = true;
                this.currentEntry = Elem;
                this.currentEntry.addClass('current');
            }
        } while (!found && (Elem = Elem.nextSibling))
    }
}

/**
 * Text holen und zur Anpassung durch optimizeText schicken.
 */
MT_DynList.prototype.getText = function(element)
{
    return this.optimizeText(element.getText());
}

/**
 * Text holen und zur Anpassung durch optimizeText schicken.
 */
MT_DynList.prototype.setFieldText = function(text)
{
    this.Field.value = text;
}

/**
 * Funktion bei Bedarf modifizieren, wenn z.B. nicht der gesamte Text
 * des Listenelementes uebernommen werden soll
 */
MT_DynList.prototype.optimizeText = function(text)
{
    return text;
}









Blink = new Class();
Blink.prototype = {
  initialize: function(Elem)
  {
    this.Elem = Elem;
    this.OriginalColor = this.Elem.style.backgroundColor;
    this.OriginalTColor = this.Elem.style.color;
    //        this.doBlink();
    this.Interval = window.setTimeout(this.doBlink.bind(this), 100);
    this.Interval2 = window.setTimeout(this.doBlink.bind(this), 7000);
  },
  doBlink: function()
  {
    if (this.Highlighted) 
    {
      this.Elem.style.backgroundColor = this.OriginalColor;
      this.Elem.style.color = this.OriginalTColor;
      this.Highlighted = false;
      this.Count++;
    }
    else 
    {
      this.Elem.style.backgroundColor = this.BlinkColor;
      this.Elem.style.color = this.BlinkTColor;
      this.Highlighted = true;
    }
    
    if (this.Count >= 1) 
    {
      window.clearInterval(this.Interval);
    }
  },
  Elem: null,
  Highlighted: false,
  Count: 0,
  OriginalColor: null,
  OriginalTColor: null,
  BlinkColor: 'red',
  BlinkTColor: 'white',
  Interval: null
}



window.addEvent('domready', function()
{
  if ($('content')) 
  {
    switch ($('content').className)
    {
      case 'mail-address':
      case 'mail-calendar':
      case 'mail-collection':
      case 'mail-customer':
        keepAlive = window.setInterval(Util.keepAlive, 300000);
        break;
    }
  }
});
