var msgBoxDEBUG = 0;
var _basicBoxPrefix  = 'basicBox';
var _msgBoxPrefix    = 'msgBox';
var _modalGrayPrefix = 'modalGray';
var _loginBoxPrefix  = 'loginBox';

var g_msgBox_isIE6;

// Check whether this browser is IE6
function MSBisIE6() {
//return false;
  if (g_msgBox_isIE6 == null) {
    g_msgBox_isIE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
  }
  return g_msgBox_isIE6;
}




// Msg box handling // 
function generateGuid()
{
  var result, i, j;
  result = '';
  for(j=0; j<32; j++)
  {
	if( j == 8 || j == 12|| j == 16|| j == 20)
	  result = result + '_';
	i = Math.floor(Math.random()*16).toString(16).toUpperCase();
	result = result + i;
  }
  return result
}

function MSBdeletePx(aString) {
  var retval
  try {
    retval  = parseInt(aString);
  } catch (e) { if (msgBoxDEBUG > 0) { alert(e+' '+aString); } }
  try {
    retval = parseInt(aString.replace(/px/g,""));  
  } catch (e) {}
  return retval;
  
}

pmb = function (aElement) {
  aElement.className = "festoreset";
  aElement.style.margin = '0px';
  aElement.style.padding = '0px';
  aElement.style.border = '0px none black';
  aElement.style.lineHeight = '1';
  aElement.style.borderCollapse = 'separate';
  aElement.style.borderSpacing = '0';
}

function getScrollPos(aWindow) {
  // Muss ja richtig sein, wenn von einem MVP since 1997 kopiert wurde.... //
  aWindow = window.isNullDefault(aWindow,top);
  var ScrollTop = aWindow.document.body.scrollTop;
  if (ScrollTop == 0)
  {
    if (aWindow.pageYOffset) {
      ScrollTop = aWindow.pageYOffset; 
    } else {
      ScrollTop = (aWindow.document.body.parentElement) ? aWindow.document.body.parentElement.scrollTop : 0;
    }
  }
  return ScrollTop;
}

function getBrowserSize(aTopWin) {
  var bodyWidth;
  var bodyHeight;
  var topWin = __topWindow.isNullDefault(aTopWin,__topWindow);
  var topDoc;
  try { 
    topDoc = topWin.document;
  } catch (err) {
    topWin = __topWindow;
    topDoc = __topWindow.document;
  }
  if (topDoc.documentElement == undefined) {
    // We arerunning  assumably in an iframe //
    bodyWidth = topWin.width;
    bodyHeight = topWin.height;
  } else {
    var bodyWidth = topDoc.documentElement.clientWidth;
    var bodyHeight = topDoc.documentElement.clientHeight;
    if (topWin.innerHeight){ // all except Exploder 
       bodyWidth = topWin.innerWidth; 
       bodyHeight = topWin.innerHeight; 
    }  else if (topDoc.documentElement && topDoc.documentElement.clientHeight) {
       // Exploder		 
       bodyWidth = topWin.document.documentElement.clientWidth; 
       bodyHeight = topWin.document.documentElement.clientHeight; 
    } else if (topDoc.body) {// other Browsers 		 
       bodyWidth = topDoc.body.clientWidth; 
       bodyHeight = topDoc.body.clientHeight; 
    } 
  }
  return [bodyWidth,bodyHeight];		
}

function repositionBackgrounds(aGID) 
{
  var aIF = document.getElementById("IF"+aGID);
  var aBG = document.getElementById("bkg"+aGID);
  var aTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
  var aLeft = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
  var brSize = getBrowserSize();
  var bodyWidth = brSize[0];
  var bodyHeight = brSize[1];
  aIF.style.top = aTop;
  aIF.style.left = aLeft;
  aBG.style.top = aTop;
  aBG.style.left = aLeft;
  aIF.style.width = bodyWidth+'px';
  aIF.style.height = bodyHeight+'px';
  aBG.style.width = bodyWidth+'px';
  aBG.style.height = bodyHeight+'px';  
}


function addEvent( obj, type, fn ) {
  if ( !obj.attachEvent ) {
    obj.addEventListener( type, fn, false );
  } else {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  }
}
function removeEvent( obj, type, fn ) {
  if ( !obj.detachEvent ) {
    obj.removeEventListener( type, fn, false );
  } else {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  }
}

function __mygetxDKILocation() {
  try {
    return getxDKILocation();
  } catch (e) {
    return '';
  }
}

// Our event factory for IE7 as he does not handle multiple attached events (the etach is mor an 'empty') //
// Beware that one factory handles one event! One object! and one function! //
// All subsequent events are attached/detached to/from that one! //
function _eventFactory(aObj, aType, aId) {
  this.ownerId        = new Object; // this is where our Owner IDs are stored //
  this.ownerFunc      = new Object; // and the corrsponding functions //
  this.eventsCount    = 0;           // counter how much are connected //
  this.object         = aObj;
  this.type           = aType;
  this.Id             = aId;
  var factoryId       = this;
  this.event          = function (anE) { factoryId._processEvent(anE,factoryId); };
//  RegisterObject(aId,this);
};

_eventFactory.prototype = {
  Try : function () {
    return 'Succeeded';
  },
  
  addEvent : function ( aId, aFunc ) {
    if (this.ownerFunc[aId] != undefined) { if (msgBoxDEBUG > 0) { alert("Warning! That Id already attached a function on "+this.type) } };
    this.ownerFunc[aId] = aFunc;
    this.eventsCount += 1
    if (this.eventsCount == 1) this._addEventToObject();
  },
  
  removeEvent : function ( aId ) {
    if (this.ownerFunc[aId] == undefined) { if (msgBoxDEBUG > 0) { alert("Warning! That Id has no attached function on "+this.type); return } };
    delete this.ownerFunc[aId];
    this.eventsCount -= 1;
    if (this.eventsCount <= 0) this._removeEventFromObject();
  },
  
  _addEventToObject : function () {
    __topWindow.addEvent(this.object, this.type, this.event);
  },
  
  _removeEventFromObject : function () {
    __topWindow.removeEvent(this.object, this.type, this.event);
  },
  
  _processEvent : function (e,_this) {
    for (i in _this.ownerFunc) {
      var aFunc = this.ownerFunc[i];
      try {
        aFunc(e,i);
      } catch (err) { if (msgBoxDEBUG > 0) { alert('_processEvent '+_this.Id+'  failed on '+i+'   '+aFunc);} }
    }
  }
}

// All public functions start with a lower-case alphanumeric char, all private ones start with an underscore _ //

// Box Object: The Objcet that can be dragged around //
// Access the content via 'content' or let you give back the contentID //
// optional is aBody,xPos,yPos,width,height // 
// aBody :                            append Object to that body instead of document.body //
// aAddElementsLater:       add Elements to the body in a separate call, this will speed up processing //

function basicBox(aBody,axPos,ayPos,aWidth,aHeight,aAddElementsLater,aStyle,aExternalId) {
  try {
//    _messageBox_init();
  } catch (e) { if (msgBoxDEBUG > 0) { alert(e); } };
  // public properties //
  this.movable        = true;
  // our properties //
  this.xPos           = axPos;
  this.yPos           = ayPos;
  this.AutoWidth      = window.isEmptyOrNullDefault(aWidth,-1); 
  this.AutoHeight     = window.isEmptyOrNullDefault(aHeight,-1);
  this.Width          = window.isNullDefault(aWidth,300); 
  this.Height         = window.isNullDefault(aHeight,-1); // as we dynamically change that one anyway //
  this.Id             = window.isNullDefault(aExternalId,generateGuid());
  this.createEventsCallback = function () { };
  this.deleteEventsCallback = function () { };
  this.OriginWindow   = self;
  this.IFrame         = null;
  this.Div            = null;
  this.Body           = getBody(aBody,__topWindow.document.body)
  this.DivContent     = null;
  this.DivRight       = null;
  this.DivBottom      = null;
  this.SizeTable      = null;
  this.SizeTBody      = null;
  this.SizeTR         = null;
  this.SizeTDL        = null;
  this.SizeTDR        = null;
  this.isModal        = false;
  this.SaveMouseX     = null;
  this.SaveMouseY     = null;
  this.Style          = aStyle;
  this.MoveEventAdded = false;
  this.hidden         = false;
  var bs              = getBrowserSize(__topWindow);
  this.winWidth       = bs[0];
  this.winHeight      = bs[1];
  this.AddElementsLater = window.isNullDefault(aAddElementsLater,false);
  // our Events //
  var CurrentBoxId = this.Id
  this._mouseDownEvent = function (e) { try { return __topWindow.getObjArray(CurrentBoxId).__mouseDownEvent(e,CurrentBoxId); } catch (e) { if (msgBoxDEBUG > 0) { alert('basicBox _mouseDownEvent: '+e); }; return true; } };
  this._mouseUpEvent  = function (e) { try { return __topWindow.getObjArray(CurrentBoxId).__mouseUpEvent(e,CurrentBoxId); } catch (e) { if (msgBoxDEBUG > 0) { alert('basicBox _mouseUpEvent: '+e); }; return true; } };
  this._mouseMoveEvent = function (e) { try { return __topWindow.getObjArray(CurrentBoxId).__mouseMoveEvent(e,CurrentBoxId); } catch (e) { if (msgBoxDEBUG > 0) { alert('basicBox _mouseMoveEvent: '+e); }; return true; } };
  this.onRepositionCallback = function () { };  // your vent if the box is dragged around. Parameters are (aId,posX,posY) { }
  // some private vars //
  this._nextOpacityStep = true;  
  // and our methods in the cosntructor //
  RegisterObject(this.Id,this);
  this._createBox();
};

basicBox.prototype = {

  close : function (aId) {
    // first delete our events, after that the objects can be removed! //
    var _this;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this._deleteEvents();
    try { _this.Body.removeChild(_this.IFrame); } catch (e) {};
    // for IE6 "input no more clickable" problem //
    try { var adummy = document.createElement("input"); adummy.type = "text"; _this.Div.appendChild(adummy); adummy.focus(); adummy.blur(); } catch (e) {};
    try { _this.Body.removeChild(_this.Div); } catch (e) {};
    __topWindow.UnregisterObject(_this.Id);
  },
  
  hide : function (aId) {
    var _this;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.Div.style.display= 'none';
    _this.IFrame.style.display= 'none';
    _this.hidden = true;
  },
  
  unhide : function (aId) {
    var _this;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.Div.style.display= '';
    _this.IFrame.style.display= '';
    _this.hidden = false;
  },
  
  fadeIn : function (aId,aMaxOp) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    if (aMaxOp == undefined) aMaxOp = 80;
    this._setOpacity(aId,0,0,null);
    _this.unhide();
    _this._increaseOpacityBy(aId,0,5,aMaxOp);
  },

  fadeOut : function (aId,aMaxOp) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = this.aId;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    if (aMaxOp == undefined) aMaxOp = 80;
    _this.hidden = true;
    _this._increaseOpacityBy(aId,aMaxOp,-5,0);
  },

  immobilize : function (aId) {
    // call for input fields //
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    var _aId = aId; // <= Important to do this as a separate var as we would lose our reference.... //
    try {
      var _elem = _this.DivContent.getElementsByTagName('input');
      for (var i=0; i<_elem.length; i++ ) {
        try{
          if (_elem[i].type == 'text') {
            _elem[i].onmousedown = function () { var aBox = getObjArray(_aId); aBox.movable = false; aBox.startSelect(); };  
          }
        } catch(err) { }
      }
    } catch (err) {};
  },

  _increaseOpacityBy : function (aId,aValue,aDelta,aEndValue) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    aValue += aDelta;
    window.setTimeout('__topWindow.getObjArray("'+aId+'")._setOpacity("'+aId+'",'+aValue+','+aEndValue+',function () {__topWindow.getObjArray("'+aId+'")._increaseOpacityBy("'+aId+'",'+aValue+','+aDelta+','+aEndValue+')});',25);
  },
  
  _setOpacity : function (aId,aOpacity,aEndValue,callFunction) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    try {
      setOpacity(_this.Div,aOpacity);
      _this.Div.style.display = '';
      if ((aOpacity != aEndValue) && (callFunction)) {     
        callFunction(); 
      } else {
        if (aEndValue == 0) _this.hide();
      }
    } catch (e) { 
      // do nothing, its a useless function anyway // 
    }
  },    
      
  addElements : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.Body.appendChild(_this.IFrame);
    _this.Body.appendChild(_this.Div);
    _this.AddElementsLater = false;
  },

  // Position message box, optional on axPos, ayPos, aId //
  position : function(axPos,ayPos,aId) {
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.xPos = window.isNullDefault(axPos,_this.xPos);
    _this.yPos = window.isNullDefault(ayPos,_this.yPos);
    if ((_this.xPos == undefined) || (_this.xPos == '')) {   
      if (_this._positionInScreen() ) 
        _this.position(_this.xPos,_this.yPos,aId);
    }
    _this._getPosition(false);
    _this.Div.style.left = MSBdeletePx(_this.xPos)+'px';
    _this.Div.style.top = MSBdeletePx(_this.yPos)+'px';
    _this.IFrame.style.left = MSBdeletePx(_this.xPos)+'px';
    _this.IFrame.style.top = MSBdeletePx(_this.yPos)+'px';
  },

  resize : function(aWidth,aHeight,aId) {
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this._onResize(aWidth,aHeight);
  },
  
  displayPos : function () {
    alert('l:'+this.xPos+'   t:'+this.yPos+'   w:'+this.Width+'    h:'+this.Height);
  },

  // prohibit selection of text within the box  //
  stopSelect : function () {
    this.Div.onselectstart = function() { return false };
    this.Div.ondragstart = function() { return false };		
    NoSelect(this.Div);
    NoSelect(this.IFrame);
  },

  // permit selection of text within the box //
  startSelect : function () {   
    this.Div.onselectstart = function() { return true };
    this.Div.ondragstart = function() { return true };		
    CanSelect(this.Div);
    CanSelect(this.IFrame);
  },
  
  // If you like to put new content into DivContent on the fly this function //
  // comes in handy because it resets the size                                                  //
  prepareForNewContent : function () {
    this.Width = '';
    this.Height = '';
    this.Div.style.width = '10%';
    this.Div.style.height = '';
    this.DivContent.innerHTML = '';
    this.DivContent.style.width = '';
    this.DivContent.style.height = '';
  },

  manuallyResize : function (aNewWidth) {
    this.SizeTable.style.height='100%';
    this.SizeTable.style.width='100%'; 
    this.SizeTable.style.width=MSBdeletePx(aNewWidth)+'px';
    this.DivContent.style.height='100%';
    this.DivContent.style.width='';
    this.Div.style.height='';
    this.Div.style.width=MSBdeletePx(aNewWidth)+'px';
    this.Height='';
    this.Width='';
  },
  
  _createBox : function () {
    this._createBackIFrame();
    this._createDiv(); 
    this._createSizeDivs();
    this.stopSelect(); // default behaviour //
    this._createEvents();
    if (!this.AddElementsLater) {
      this.addElements(); 
      this._onResize();
      this.position();
    }
  },

  _createBackIFrame : function () {
  // IFrame, just for 'perfect' IE behaviour with combo boxes etc. so no other elements will glance  through //
    this.IFrame = __topWindow.document.createElement("iframe");
    pmb(this.IFrame);
    this.IFrame.className = 'messageBoxIFrame';
    with (this.IFrame.style) {
      position='absolute';
      padding='0px';
      margin='0px';
      zIndex='800';
      backgroundColor='transparent';
      border='#000000 none 0px';
      /* Transparency for IE */
      filter='alpha(opacity=0)';
      opacity='.0';
      // plus those: //
      left = '0px';
      top = '0px';
    }
    this.IFrame.frameBorder = "100";
    this.IFrame.id = "IF"+this.Id;
    this.IFrame.src = getxDKILocation().replace(/xdki.asp/gi,'') + 'empty.html';
//    this.IFrame.src = 'images/1x1_trans.gif';
  },

  _createDiv : function () {
    this.Div = __topWindow.document.createElement('div');
    pmb(this.Div);
    this.Div.id = this.Id;
    if (this.Style) {
      this.Div.className = this.Style;
      this.Div.style.position = 'absolute'; // in case the stylesheet guy forgot //
      this.Div.style.padding = '0px';  // everything else leads to catastrophic errors while moving the box //
      this.Div.style.margin = '0px';   // everything else leads to catastrophic errors while moving the box //
      this.Div.style.width = this.Width;
      this.Div.style.filter='alpha(opacity=100)';
      this.Div.style.opacity='1';
      this.Div.style.top = '0px';
      this.Div.style.left = '0px';
    } else {
      with (this.Div.style) {
        pmb(this.Div);
        position='absolute';
        backgroundColor='#F8F8F8';
        border='black solid 1px';
        padding='0px';  
        margin='0px'; 
        zIndex='999';
        textAlign='center';    
        // plus those: //
        width = this.Width;
        filter='alpha(opacity=100)';
        opacity='1';
        top = '0px';
        left = '0px';
      }
    }
    this._setZIndexHi();
  },

  _createSizeDivs : function (useOrigDivContent,aId) {
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    if (!useOrigDivContent) {
      _this.DivRight  = __topWindow.document.createElement('div');
      _this.DivBottom = __topWindow.document.createElement('div');
      _this.DivContent = __topWindow.document.createElement('div');
      _this.SizeTable = __topWindow.document.createElement('table');
      _this.SizeTBody = __topWindow.document.createElement('tbody');
      _this.SizeTR  = __topWindow.document.createElement('tr');
      _this.SizeTDL = __topWindow.document.createElement('td');
      _this.SizeTDR = __topWindow.document.createElement('td');
      _this.SizeTDB = __topWindow.document.createElement('td');
      pmb(_this.DivRight);
      pmb(_this.DivBottom);
      pmb(_this.DivContent);
      pmb(_this.SizeTable);
      pmb(_this.SizeTBody);
      pmb(_this.SizeTR);
      pmb(_this.SizeTDL);
      pmb(_this.SizeTDR);
      pmb(_this.SizeTDB);
    }

    pmb(_this.SizeTable);

    if (!useOrigDivContent) {
      _this.SizeTable.appendChild(_this.SizeTBody);
      _this.SizeTBody.appendChild(_this.SizeTR);
      _this.SizeTR.appendChild(_this.SizeTDL);
      _this.SizeTR.appendChild(_this.SizeTDR);
    }
    
    _this.DivContent.id = 'ContentDIV'+_this.Id;
    _this.DivRight.id = 'RightDIV'+_this.Id;
    _this.DivBottom.id = 'BottomDIV'+_this.Id;
    pmb(_this.DivContent);
    if (_this.Style) {
      _this.DivContent.className = _this.Style;
    } else {
    }
    _this.DivContent.style.width = '100%'; 
    _this.DivContent.style.height = '100%';
    pmb(_this.DivRight);
    _this.DivRight.style.height = "100%";
    _this.DivRight.style.width = '0px';
    pmb(_this.DivBottom);
    _this.DivBottom.style.width = "100%";
    _this.DivBottom.style.height = "0px";
    _this.DivBottom.innerHTML = '&nbsp;';
    pmb(_this.SizeTable);
    _this.SizeTable.style.width = '100%';
    _this.SizeTable.style.height = '100%';
    pmb(_this.SizeTR);
    _this.SizeTR.style.width = '100%';
    _this.SizeTR.style.height = '100%';
    pmb(_this.SizeTDL);
    _this.SizeTDL.style.width = '100%';
    _this.SizeTDL.style.height = '100%';
    pmb(_this.SizeTDR);
    _this.SizeTDR.style.width = '0%';
    _this.SizeTDR.style.height = '0%';
    if (!useOrigDivContent) {
      _this.SizeTDL.appendChild(_this.DivContent);
      _this.SizeTDR.appendChild(_this.DivRight);
      _this.Div.appendChild(_this.SizeTable);
      _this.Div.appendChild(_this.DivBottom);
    }
  },

  // this gives the real position and the real width of the box //
  // I had no better idea for a name..... //
  _getPosition :function (withSize,aId) {
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    if (withSize) {
      _this.DivContent.style.display='none';
      var sDummy = __topWindow.document.createElement('div');
      pmb(sDummy);
      _this.SizeTDL.appendChild(sDummy);
      sDummy.innerHTML = _this.DivContent.innerHTML;
      if (_this.AutoWidth == -1) {
        _this.Width = '';
        _this.Div.style.width = '10%';
      }
      if (_this.AutoHeight == -1) {
        _this.Height = '';
        _this.Div.style.height = '';
      } else { sDummy.style.height = MSBdeletePx(this.Height)+'px'; }
      _this._createSizeDivs(true,aId);
    }
    var xPos = MSBdeletePx(window.isNullDefault(this.xPos,0));
    var yPos = MSBdeletePx(window.isNullDefault(this.yPos,0));
    _this.Div.style.left = MSBdeletePx(xPos)+'px';
    _this.Div.style.top = MSBdeletePx(yPos)+'px';
    var IFright = -1;
    var IFbottom = -1;
    if (withSize) {
      _this.SizeTDR.style.display = '';
      _this.DivBottom.style.display = '';
      _this.Div.style.display = '';  // unhide our div or we wont get any results//
      IFright = window.findPosX(_this.DivRight);
      IFbottom = window.findPosY(_this.DivBottom);
      _this.SizeTDL.removeChild(sDummy);
      _this.DivContent.style.display='';
      _this.DivBottom.style.display = 'none';
      _this.SizeTDR.style.display = 'none';
    }
    return [xPos,yPos,IFright, IFbottom];
  },

  _onResize : function(aWidth, aHeight) {
    if (!__topWindow.document.getElementById(this.Id)) return;
    var res = this._getPosition(true);
    var xPos = res[0];
    var yPos = res[1];
    var IFright = res[2];
    var IFbottom = res[3];
    var Width = IFright - xPos + 1;
    var Height = IFbottom - yPos - 2;
    if (msgBoxDEBUG > 5) { alert('mb.js: _onResize1: '+this.AutoWidth+' '+this.AutoHeight+'<    local w/h>'+Width+' '+Height+'<    this.w/h>'+this.Width+' '+this.Height+'<'); }
    if (this.AutoWidth == -1) {
      this.Width = Width;
      this.Div.style.width = (Math.floor(this.Width) + 1) +'px';
    } else {
      // use the width which is specified //
      Width = this.Width;
    }
    if (this.AutoHeight == -1) {
      this.Height = Height;
    } else {
      Height = this.Height
    }
    if (msgBoxDEBUG > 5) {alert('mb.js: _onResize2: Auto w/h>'+this.AutoWidth+' '+this.AutoHeight+'<    local w/h>'+Width+' '+Height+'<    this.w/h>'+this.Width+' '+this.Height+'<'); }
    if (Height < 0) { Height = '100%'; }
    this.SizeTable.style.height=Height+'px'; // 5 padding //
    this.SizeTable.style.width=Width+'px';
    this.IFrame.style.width = this.Width+3+'px';
    this.IFrame.style.height = this.Height+4+'px';
  },

  _positionInScreen : function(force) {
    if ((!force) && (this.AddElementsLater) || (MSBdeletePx(this.Height) < 0)) { return false; }
    this.xPos = ( (this.winWidth / 2) - (this.Width / 2) )+'px';
    this.yPos = ( (this.winHeight / 2) - (this.Height / 2) + getScrollPos(__topWindow) )+'px';
    return true;
  },

  _setZIndexHi : function () {
    if ( this.isModal )  {
      this.Div.style.zIndex = 999;
    } else {
      this.Div.style.zIndex = 899;
    }
  },

   _setZIndexLo : function () {
    if ( this.isModal )  {
      this.Div.style.zIndex = 998;
    } else {
      this.Div.style.zIndex = 898;
    }
  },

  _createEvents : function () {
    var aId = this.Id;
    addEvent(this.Div,'mousedown',this._mouseDownEvent )
    addEvent(this.Div,'mouseup',this._mouseUpEvent  );
    __topWindow.eventFactory_topmouseup.addEvent(aId,this._mouseUpEvent );
  },

  _deleteEvents : function () {
    removeEvent(this.Div,'mousedown',this._mouseDownEvent);
    removeEvent(this.Div,'mouseup',this._mouseUpEvent);
    __topWindow.eventFactory_topmouseup.removeEvent(this.Id);
    if (this.MoveEventAdded) {
      __topWindow.eventFactory_topmousemove.removeEvent(this.Id);
    }
  },

  __mouseUpEvent : function (e,aId) {
    var _this = __topWindow.getObjArray(aId);
    if ( _this == undefined) return true;
    if (_this.MoveEventAdded) {
      _this.MoveEventAdded = false;
      __topWindow.eventFactory_topmousemove.removeEvent(aId);
    }
    return false;
  },

  __mouseDownEvent : function (e,aId) {
    var _this = __topWindow.getObjArray(aId);
    if ( _this == undefined) return true;
   	var posx = 0;
   	var posy = 0;
    var aArray = __topWindow.getObjArray();
    for (var i in aArray) {
      if (i != aId)
        if ( aArray[i]._setZIndexLo != undefined) {
          // I hate to do that..... but in favour of just one ObjArray..... //
          aArray[i]._setZIndexLo(); 
        }
    }
    _this._setZIndexHi();
   	if (!e) var e = __topWindow.event;
    if (e) {
     	if ((e.pageX) || (e.pageY)) {
     		posx = e.pageX;
     		posy = e.pageY;
     	} else {
     		posx = e.clientX + _this.Body.scrollLeft
     			+ __topWindow.document.documentElement.scrollLeft;
     		posy = e.clientY + _this.Body.scrollTop
     			+ __topWindow.document.documentElement.scrollTop;
     	}
      _this.SaveMouseX = posx-MSBdeletePx(_this.xPos);
      _this.SaveMouseY = posy-MSBdeletePx(_this.yPos);
    }
    if (_this.movable) {
      _this.MoveEventAdded = true;
      __topWindow.eventFactory_topmousemove.addEvent(aId,_this.__mouseMoveEvent);
    }
    return false;
  },

  __mouseMoveEvent : function (e,aId) {
    var _this= __topWindow.getObjArray(aId);
    if ( _this == undefined) return true;
    if (_this.MoveEventAdded == false) return true;
   	var posx = 0;
   	var posy = 0;
   	if (!e) var e = __topWindow.event;
   	if ((e.pageX) || (e.pageY)) {
   		posx = e.pageX;
   		posy = e.pageY;
   	} else {
  		posx = e.clientX + _this.Body.scrollLeft
   			+ __topWindow.document.documentElement.scrollLeft;
   		posy = e.clientY + _this.Body.scrollTop
   			+ __topWindow.document.documentElement.scrollTop;
   	}
    _this.position(posx-_this.SaveMouseX,posy-_this.SaveMouseY);
    _this.onRepositionCallback(aId,posx-_this.SaveMouseX,posy-_this.SaveMouseY);
    return false;
  }
} // end of box prototype


function messageBox(aMessage, aCaption, aBtn1Txt, aBtn1Fkt, aBtn2Txt, aBtn2Fkt, aBodyId, isModal, aPosX, aPosY, aWidth, aNoFocus) {
  try {
//    alert(document.domain);
    _messageBox_init();
  } catch (e) { if (msgBoxDEBUG > 0) { alert(e); } };
  this.modalGray      = null;
  this.Message        = aMessage;
  this.Caption        = aCaption;
  this.Btn1Txt        = aBtn1Txt;
  this.Btn1Fkt        = window.isNullDefault(aBtn1Fkt,null);
  this.Btn2Txt        = aBtn2Txt;
  this.Btn2Fkt        = window.isNullDefault(aBtn2Fkt,null);
  this.OriginWindow   = self;
  this.Body           = getBody(aBodyId,__topWindow.document.body)
  this.Width          = window.isNullDefault(aWidth,300);
  this.AutoWidth      = this.Width <= 10;
  if (this.Width < 0) this.Width = 0;
  var myWidth         = this.Width;
  var myBody          = this.Body;
  this.basicBox       = __topWindow.__festoMsgBoxGiveMeA(function () { return new basicBox(myBody,aPosX,aPosY,myWidth,'',true) } );
  this.Id             = _msgBoxPrefix+this.basicBox.Id;
  this.isModal        = window.isNullDefault(isModal,true);
  this.xPos           = aPosX;
  this.yPos           = aPosY;
  this.AutoPos        = window.isEmptyOrNullDefault(aPosX,-1);
  this.Width          = window.isNullDefault(aWidth,10);
  this.NoFocus        = window.isNullDefault(aNoFocus,false);
  var CurrentBoxId    = this.Id;
  this.MouseOnButtonDown = 0;
  this.mouseDownEvent = function (e) { try { return __topWindow.getObjArray(CurrentBoxId)._mouseDown(e,CurrentBoxId); } catch(e) { return true; } };
  this.mouseUpEvent   = function (e) { try { return __topWindow.getObjArray(CurrentBoxId)._mouseUp(e,CurrentBoxId);  } catch(e) { return true; } };
  this._generateBox();
}

messageBox.prototype = {
 
  close : function (aId) {
    // should kill events first //
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }    
    _this.basicBox.close(_this.basicBox.Id);
    if (_this.isModal) {
      _this.modalGray.close(_this.modalGray.Id);
    }
    _this._deleteEvents();
    window.UnregisterObject(aId);
  },

  resize : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.basicBox.resize(this.Width, this.Height);
  },  

  positionInScreen : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.basicBox._positionInScreen(true);
    _this.basicBox.position();
  },

  prepareForNewContent : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this.Width = 0;
    _this.height = 0;
  },
  
  immobilize : function (aId) {
    // call for input fields //
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    try {
      var _elem = _this.basicBox.immobilize();
    } catch (err) {};
  },
  
  _generateBox : function () {
    this._createMessage();
    this._createContent();
    this._drawBox();
    this._executeDynamicFill();
    this._addEvents();
    var aId = this.Id;
    this.basicBox.createEventsCallback = function (mId) { __topWindow.getObjArray(aId)._addEvents(); };
    this.basicBox.deleteEventsCallback = function (mId) { __topWindow.getObjArray(aId)._deleteEvents(); };
    this._setFocus(this.Id);
    this._drawBox();
  },
  
  _createMessage : function () {
    RegisterObject(this.Id,this);
    this.basicBox.isModal = this.isModal;
    if (this.isModal) {
      this.modalGray = new modalGray(_modalGrayPrefix+this.basicBox.Id,this.Body);
    }
    this.basicBox._setZIndexHi();
  },
  
  _createContent : function () {
    var ButtonStyle = 'background-color: #0091DC; border:0pt none; color:#FFFFFF; cursor:pointer; font-size:11px; cursor:pointer; cursor:hand;'
    var StyleBoxIFTable, StyleBoxIF, StyleButtonDiv, StyleCaption, StyleText;
    if (__topWindow.document.createStyleSheet) {
      // IE //
      StyleBoxIFTable = 'width:100%; height: 100%; background-color: #F8F8F8; color: #ff00ff; border: black none 0px; padding: 0px 0px 0px 0px; margin: 0px; text-align: center;';
      StyleBoxIF = 'background-color: #FFFFFF; border: #999999 solid 1px; padding: 0px; white-space: normal; margin: -1px -1px -1px -1px;';
    } else {
      // FF and others //
      StyleBoxIFTable = 'width:100%; height: 100%; background-color: #F8F8F8; color: #ff00ff; border: black none 0px; padding: 0px 2px 2px 2px; margin: 0px; text-align: center;';
      StyleBoxIF = 'background-color: #FFFFFF; border: #999999 solid 1px; padding: 0px; margin: 0px; white-space: normal;';
  }
    StyleButtonDiv = 'padding: 10px 0px 0px 0px; text-align: center; width: 100%;'
    StyleCaption =  'font-family: Arial, Geneva, Helvetica, sans-serif; color:#666666; font-size:11px; font-weight : bold; border-color:#AAAAAA; text-align: center; padding: 5px 2px 4px 2px;';
    StyleText = 'font-family: Arial, Geneva, Helvetica, sans-serif; color:#000000; font-size:11px; font-weight : normal; border-color:#AAAAAA; padding: 0px 3px 3px 3px;'; 
    var aId = this.Id;
    // Draw message box's message (or let it draw by JavaScript)
    var sDummy = '<table class="festoreset" style="'+StyleBoxIFTable+'"><thead class="festoreset" style="padding: 0px; margin: 0px;"></thead><tbody class="festoreset" style="padding: 0px; margin: 0px;"><tr class="festoreset" style="padding: 0px; margin: 0px;"><td class="festoreset" style="width:100%; padding:1px 1px 1px 1px; margin: 0px" >'+
      '<div class="festoreset" style="'+StyleBoxIF+'" id="messageBoxInnerDiv'+aId+'">'+
      '<table class="festoreset" style="width: 100%;height:100%; text-align: center; padding: 0px; margin: 0px;"><tbody class="festoreset"><tr class="festoreset" style="height:100%;padding:0px; margin:0px">';
    if (this.Caption!="JavaScript") {
      if (this.Caption != 'undefined') {
        sDummy += '<td class="festoreset" align="center" style="text-align: center; "><b class="festoreset" id="messageBoxCaption'+aId+'" style="'+StyleCaption+'">'+this.Caption+'</b></td></tr><tr class="festoreset">';  
      }
      sDummy += '<td class="festoreset" id="messageBoxInnerMessage'+aId+'" style="'+StyleText+'">'+this.Message;
    } else {
      // Inner stuff will be drawn by JS function in aMessage()
      sDummy += '<td class="festoreset" id="messageBoxInnerMessage'+aId+'" style="'+StyleText+'">'+this.Message(aId,0);
    }
    sDummy += '</td></tr><tr class="festoreset" style="text-align: center;"><td class="festoreset" align="middle" id="ButtonDiv'+aId+'" style="'+StyleButtonDiv+'">';
    // Draw the buttons //
    sDummy += '<table class="festoreset" style="text-align: center; width: 100%;"><thead class="festoreset"></thead><tbody class="festoreset" style="width: 100%;text-align: center;"><tr class="festoreset" style="text-align: center"><td class="festoreset" style="width:50%">&nbsp;</td><td class="festoreset" style="text-align: center">';; 
    if (this.Btn1Txt) {
      if (this.Btn1Fkt) {
        sDummy += '<span class="festoreset" id="Button1'+aId+'" style="width: 100%">' + roundedButtonStyled('blue','<input type="button" value="'+this.Btn1Txt+'" class="rounded_button_blue" style="'+ButtonStyle+'" id="BTN1'+aId+'" onclick="javascript: try { __topWindow.getObjArray(\''+aId+'\').Btn1Fkt(\''+aId+'\'); } catch (e) { alert(\'OnClick action excepted! \'+e); }">',__mygetxDKILocation())+'</span>';
      } else {
        sDummy += '<span class="festoreset" id="Button1'+aId+'" style="width: 100%">' + roundedButtonStyled('blue','<input type="button" value="'+this.Btn1Txt+'" class="rounded_button_blue" style="'+ButtonStyle+'" id="BTN1'+aId+'" onclick="new function() { try { __topWindow.getObjArray(\''+aId+'\').close(); } catch (e) { alert(\'--default click action excepted: \'+e); } }">',__mygetxDKILocation())+'</span>';
      }
    }
    if (this.Btn2Txt) {   
      sDummy += '</td><td class="festoreset" style="width: 6px"></td><td class="festoreset">';
      if (this.Btn2Fkt) {
        sDummy += '<span id="Button2'+aId+'">' + roundedButtonStyled('blue','<input type="button" value="'+this.Btn2Txt+'" class="rounded_button_blue" style="'+ButtonStyle+'" id="BTN2'+aId+'" onclick="javascript: __topWindow.getObjArray(\''+aId+'\').Btn2Fkt(\''+aId+'\');">',__mygetxDKILocation())+'</span>';
      } else {
        sDummy += '<span id="Button2'+aId+'">' + roundedButtonStyled('blue','<input type="button" value="'+this.Btn2Txt+'" class="rounded_button_blue" style="'+ButtonStyle+'" id="BTN2'+aId+'" onclick="new function() { __topWindow.getObjArray(\''+aId+'\').close(); }">',__mygetxDKILocation())+'</span>'; 
      }
    }
    sDummy += '</td><td class="festoreset" style="width:50%"></td></tr></tbody></table>';
    // ^^ Buttons ^^ //
    // close the surrounding dongxi //
    sDummy += '</td></tr></tbody></table></div></td></tr></tbody></table>';
    this.basicBox.DivContent.innerHTML = sDummy;
    this.basicBox.addElements();  
  },
  
  _drawBox : function () {  
    // Renders the box to screen //
    if (this.AutoPos == -1) {
      this.basicBox._positionInScreen(true);
    }
    this.basicBox._onResize();  // thx explorer, one time may not be enough on fast(?) computers //
    this.basicBox._onResize();
    this.basicBox.position();
  },
    
  _executeDynamicFill : function () {
    if (this.Caption=="JavaScript") {
      this.Message(this.Id,1);
      this._drawBox();
    }
  },

  _setFocus : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
      aId = this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }    
    if (!this._noFocus) {
      try { 
        if (__topWindow.document.getElementById('BTN1'+aId)) {
          __topWindow.document.getElementById('BTN1'+aId).focus(); 
        } 
      } catch (e) {};
    }
  },
  
  _mouseDown : function (e,aId) {
    var _this = __topWindow.getObjArray(aId);
    if (_this == undefined) return true;
    _this.basicBox.movable = false;
    return false;
  },

  _mouseUp : function (e,aId) {
    var _this = __topWindow.getObjArray(aId);
    if (_this == undefined) return true;
    _this.basicBox.movable = true;
    return false;
  },
  
  _addEvents : function (mId) {
    var aId = mId;
    if (mId == undefined)
      aId = this.Id;
    try { addEvent(__topWindow.document.getElementById("BTN1"+aId),'mousedown', this.mouseDownEvent ); } catch (e) {};
    try { addEvent(__topWindow.document.getElementById("BTN2"+aId),'mousedown', this.mouseDownEvent ); } catch (e) {};
    try { __topWindow.eventFactory_topmouseup.addEvent(aId, this.mouseUpEvent ); } catch (e) {};
  },
  
  _deleteEvents : function (mId) {
    var aId = mId;
    if (mId == undefined)
      aId = this.Id;
    try { removeEvent(__topWindow.document.getElementById("BTN1"+aId),'mousedown', this.mouseDownEvent ); } catch (e) {};
    try { removeEvent(__topWindow.document.getElementById("BTN2"+aId),'mousedown', this.mouseDownEvent ); } catch (e) {};
    try { __topWindow.eventFactory_topmouseup.removeEvent(aId ); } catch (e) {};
  }
} // end of messageBox prototype




function modalGray (aId,aBody) {
  this.bkgDiv       = null;
  this.bkgIF        = null;
  this.Id           = window.isNullDefault(aId,generateGuid());
  this.Body         = getBody(aBody,__topWindow.document.body);
  this.onMBFadedIn = function () {}; // your event for checking when the box faded in
  this.onMBFadedOut = function () {}; // your event for checking when the box faded out
  try {
    this.scrollEvent  = function (e,aId) { try { __topWindow.getObjArray(aId)._repositionBackgrounds(aId); } catch (e) { if ( msgBoxDEBUG > 0 ) { alert('mG: scroll event: '+e ); } }; return true; }
  } catch (e) { if (msgBoxDEBUG > 0) { alert('new modalGray: register scroll event: '+e); } }
  this._register();
  this._show();
}

modalGray.prototype = {

  close : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }    
    _this._deleteEvents();
    _this.fadeOut();       
  },

  _close : function (aId) {
    var _this = null;
    if (aId == undefined) {
      _this = this;
    } else {
      _this = __topWindow.getObjArray(aId);
    }    
    _this.Body.removeChild(_this.bkgDiv);
    _this.Body.removeChild(_this.bkgIF);
    window.UnregisterObject(_this.Id);  
  },

  _show : function () {
    this.bkgDiv = __topWindow.document.createElement('div');
    this.bkgDiv.id = 'bkg'+this.Id;
    this.bkgDiv.style.top = '0px';
    this.bkgDiv.style.left = '0px';
    with (this.bkgDiv.style) {
      position="absolute";
      top="0px";
      left="0px";
      width="100%";
      height="100%";
      zIndex="901";
      backgroundColor="#000000";
      opacity=0;
      filter="alpha(opacity=0)";
    }
    setOpacity(this.bkgDiv,0);
    this.Body.appendChild(this.bkgDiv);
    this.bkgIF = __topWindow.document.createElement("iframe"); 
    this.bkgIF.src = getxDKILocation().replace(/xdki.asp/gi,'') + 'empty.html';
    with (this.bkgIF.style) {
      position="absolute";
      padding="0px";
      margin="0px";
      zIndex="800";
      backgroundColor="transparent";
      border="#000000 none 0px";
    }
    setOpacity(this.bkgIF,0);
//    this.bkgIF.src="____images/1x1_trans.gif";  // der Name ist verunstaltet um den IE6 freeze zu verifizieren, nur wenn das Bild nicht gefunden wird haengt sich der IE6 auf.
    this.bkgIF.frameBorder = "0";
    this.bkgIF.id = "IF"+this.Id;
    this.bkgIF.style.left = 0;
    this.bkgIF.style.top = 0;
    this.bkgIF.zIndex = 900;
    this.Body.appendChild(this.bkgIF);
    this._repositionBackgrounds(this.Id);
    this._createEvents();
    this.fadeIn(this.Id);
  },

  _register : function () {
    RegisterObject(this.Id,this);  
  },
 
  _createEvents : function () {
    var aId = this.Id;  
    __topWindow.eventFactory_topscroll.addEvent(this.Id, this.scrollEvent );
  	__topWindow.eventFactory_topresize.addEvent(this.Id, this.scrollEvent );    
  },

  _deleteEvents : function () {
    var aId = this.Id;
    __topWindow.eventFactory_topscroll.removeEvent(this.Id);
  	__topWindow.eventFactory_topresize.removeEvent(this.Id);    
  },

  fadeIn : function (aId) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this._increaseOpacityBy(aId,0,5,35);
  },

  fadeOut : function (aId) {
  var _this;
    if (aId == undefined) {
      _this = this;
      aId = this.aId;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    _this._increaseOpacityBy(aId,35,-5,0);
  },

  _increaseOpacityBy : function (aId,aValue,aDelta,aEndValue) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    aValue += aDelta;
    window.setTimeout('__topWindow.getObjArray("'+aId+'")._setOpacity("'+aId+'",'+aValue+','+aEndValue+',function () {__topWindow.getObjArray("'+aId+'")._increaseOpacityBy("'+aId+'",'+aValue+','+aDelta+','+aEndValue+')});',25);
  },
  
  _setOpacity : function (aId,aOpacity,aEndValue,callFunction) {
    var _this;
    if (aId == undefined) {
      _this = this;
      aId = _this.Id;
    } else {
      _this = __topWindow.getObjArray(aId);
    }
    try {
      setOpacity(_this.bkgDiv,aOpacity);
      if ((aOpacity != aEndValue) && (callFunction != undefined)) {
        callFunction(); 
      } else {
        if (aEndValue == 0) {
          _this._close();
          _this.onMBFadedOut();
        } else {
          _this.onMBFadedIn();
        }
      }
    } catch (e) { 
      // do nothing, its a useless function anyway // 
    }
  },    
  
  _repositionBackgrounds : function (aGID) {
    var _this = __topWindow.getObjArray(aGID);
    var aIF = _this.bkgIF;
    var aBG = _this.bkgDiv;
    var topDoc = __topWindow.document;
    var aTop = Math.max(_this.Body.scrollTop,topDoc.documentElement.scrollTop) + 'px';
    var aLeft = Math.max(_this.Body.scrollLeft,topDoc.documentElement.scrollLeft) + 'px';
    var brSize = getBrowserSize(top);
    var bodyWidth = brSize[0];
    var bodyHeight = brSize[1];
    aIF.style.top = aTop;
    aIF.style.left = aLeft;
    aBG.style.top = aTop;
    aBG.style.left = aLeft;
    aIF.style.width = bodyWidth+'px';
    // HHON: this freezes IE6 with 100% CPU load when running xDKI in portal context
    if (!MSBisIE6()) {
      aIF.style.height = bodyHeight+'px';
    }
    aBG.style.width = bodyWidth+'px';
    aBG.style.height = bodyHeight+'px';    
  }
}


RegisterObject = function (aId,ObjReference) {
  var aArray = __topWindow.getObjArray();
  var sError = '';
  if (aArray[aId] != undefined) {
    sError = "Object register collission!";
  }
  if (aArray[aId] == ObjReference) {
    sError += " Attempt to registered object more than once not executed.";
  }
  aArray[aId] = ObjReference;
  if (sError != '') {
    if (msgBoxDEBUG > 0) { alert(sError); }
    return false;
  }
  return true;
} 

UnregisterObject = function (aId,ObjReference) {
  var aArray = __topWindow.getObjArray();
  var sError = '';
  if (aArray[aId] == undefined) {
    sError = "Object to unregister not found! "+aId;
  }
  if (sError != '') {
    if (msgBoxDEBUG > 0) { alert(sError); }
    return false;
  }
  delete aArray[aId];
  return true;
} 

function getObjArray(aId) {
  try {
    if (aId == 'Try') {
      if (msgBoxDEBUG > 6) alert('getObjArray: now');
      return 'Succeeded';
    }
    var aWin = top;
    var aResult;
    if (aWin.__ObjArray == undefined) {
      if (aId == undefined) {
  	    aResult = window.__ObjArray;
      } else {
        aResult = window.__ObjArray[aId];
      }
    } else {
      if (aId == undefined) {
  	    aResult = aWin.__ObjArray;
      } else {
        aResult = aWin.__ObjArray[aId];
      }
    }
  } catch (e) {
    try {
      if (aId == undefined) {
    	  aResult = __topWindow.__ObjArray;
      } else {
        aResult = __topWindow.__ObjArray[aId];
      }
    } catch (err) {
      if (msgBoxDEBUG > 0) { alert('getObjArray('+aId+'): '+err.message); }
    }
  }
  if ( msgBoxDEBUG > 1 ) { 
    if ((aResult == null) || ( aResult == undefined) ) {
      if (msgBoxDEBUG > 0) { alert('Requested object to Id "'+aId+'" is null!'); }
    }
  }
  return aResult;
}

function __festoMsgBoxGiveMeA(aFunc) {
  if (aFunc == 'Try')  {
    if (msgBoxDEBUG > 6) alert('__festoMsgBoxGiveMeA: now');
    return 'Succeeded';
  }
  if (aFunc != undefined) { return aFunc() }
}

function isNullDefault(aValue,aDefaultValue) {
  return ((aValue == undefined) || (aValue == null)) ? aDefaultValue : aValue;
}

function isNullDefaultString(aValue,aDefaultValue) {
  return ((aValue == undefined) || (aValue == '')) ? aDefaultValue : aValue;
}

function isEmptyOrNullDefault(aValue,aDefaultValue) {
  return ((aValue == '') || (aValue == undefined) || (aValue == null)) ? aDefaultValue : aValue;
}

function getBody(aBody,aDefaultBody) {
  var theBody = null;
  try {
    theBody = document.getElementById(aBody);
  } catch (err) {};
  if (!theBody) {  // is specified as BodyId?
    theBody = window.isNullDefaultString(aBody,aDefaultBody);   // or is specified as Object / null?
  }
  return theBody;
}

function NoSelect(aElement) {
  aElement.onselectstart = function() {
      return false;
  };
  aElement.unselectable = "on";
  aElement.style.MozUserSelect = "none";
  aElement.style.cursor = "default";
}

function CanSelect(aElement) {
  aElement.onselectstart = function() {
      return true;
  };
  aElement.unselectable = "true";
  aElement.style.MozUserSelect = "";
  aElement.style.cursor = "";
}
// Supply an HTML element  and a number value to set the opacity //
function setOpacity(aElement, aOpacity) {
  if (aOpacity > 90) aOpacity = 100;
  if (aOpacity < 10) aOpacity = 0; 
  var Opacity100 = aOpacity / 100;
  with (aElement.style) {
    try {
      if (Mozopacity!=undefined) {
        Mozopacity=Opacity100;      
      }
    } catch (e) { };
    try {
      if (KhtmlOpacity!=undefined) {
         KhtmlOpacity=Opacity100;
      }
    } catch (e) { };
    try {
      if (opacity!=undefined) { 
        opacity=Opacity100;
      }
    } catch (e) { };
    try {
      if (filter!=undefined) { 
        filter="alpha(opacity="+aOpacity+")";
      }
    } catch (e) {};
  }
}

function messageBoxSearchTop() {
  // iterate through parents until error occurs //
  var aParent = __topWindow;
  var aSaveParent = __topWindow;
  var sDummy;
  while ((aParent != top) && (aParent != undefined)) {  
    aParent = aParent.parent;
    try {
      sDummy = aParent.__festoMsgBoxGiveMeA('Try');
      if (sDummy == 'Succeeded') {
        if (msgBoxDEBUG > 5) { alert('found a working copy of messagebox in parent'); }
      }
      aSaveParent = aParent; // the last one we have a MessageBox.
    } catch (err) {
      // that did not do it ;-) //
    }
  }
  return aSaveParent;
}

function _messageBox_init() {
  if (!Inited) {
    TestPNF();
    if (msgBoxDEBUG > 5) { alert('Now initializing'); }
    if (msgBoxDEBUG > 0) {
      try {
        if ( roundedButton == undefined) { 
          throw "messageBoxNotLoadedError";
        }
      } catch (e) {
        alert('MessageBox.js: please include roundedInputs.js before using this box'); 
      }
    }
    // GLOBALLY allocated ObjArray //
    var aWin = messageBoxSearchTop();
    try {
      var aDummy = aWin.__festoMsgBoxGiveMeA('Try');
      if (aDummy != 'Succeeded') {
        if (msgBoxDEBUG > 6) { alert('Ättentschn! a function named giveMeA already exists! '+aDummy); };
        throw "Menno";
      }
    } catch (e) {
      try {
        aWin.__festoMsgBoxGiveMeA = function (aFunc) { return __festoMsgBoxGiveMeA(aFunc) };
      } catch (e) {
        aWin = self;
        if (msgBoxDEBUG > 0) { alert('msgBoxInit error: '+e+'  Window set to self') };
      } 
    }
    try {
      if (aWin.__ObjArray == undefined) {
        aWin.__ObjArray = aWin.__festoMsgBoxGiveMeA(function () { return new Object } );
      }
    }
    catch (e) { 
      if (msgBoxDEBUG > 0) { alert('msgBoxInit cannot add __ObjArray to top: '+e+' '+document.domain ); };
    	try {
    		__ObjArray = new Object;
    	} catch (e) {
        if (msgBoxDEBUG > 0) { alert('msgBoxInit error while adding __ObjArray: '+e+' '+document.domain ); };
      }
    }
    try {
      var aDummy = aWin.getObjArray('Try');
      if ( aDummy != 'Succeeded') {
        if (msgBoxDEBUG > 6) { alert('Ättentschn! a function named getObjArray already exists! '+aDummy); };
        throw "Menno";
      }       
    } catch (e) {
      try {
        aWin.getObjArray = function (aId) { return getObjArray(aId); };
      }
      catch (e) { 
        if (msgBoxDEBUG > 0) { alert('msgBoxInit error: '+e) };
      } 
    }
  	try {
      if (aWin.messageBox == undefined) {
        if (msgBoxDEBUG > 3) alert('adding messageBox to \'my\' window');
      aWin.messageBox = messageBox;
      }
      if (aWin.basicBox == undefined) {
        if (msgBoxDEBUG > 3) alert('adding basicBox to \'my\' window');
      aWin.basicBox = basicBox;
      }
      if (aWin.modalGrayBox == undefined) {
        if (msgBoxDEBUG > 3) alert('adding modalGrayBox to \'my\' window');
      aWin.modalGrayBox = modalGray;
      }
      if (aWin._eventFactory == undefined) {
        if (msgBoxDEBUG > 3) alert('adding _eventFactory to \'my\' window');
      aWin._eventFactory = _eventFactory;
      }
  	} catch (e) { 
      if (msgBoxDEBUG > 0) { 
        alert('msBoxInit could not add Objects to window '+e);
      }; 
    }
    try {
      try {
        if (aWin.eventFactory_topmouseup.Try() != 'Succeeded') throw 'Menno';
      } catch(e) {
        if (msgBoxDEBUG > 5) { 
          alert('Adding events to topmost window');
        }
        aWin.eventFactory_topmouseup = aWin.__festoMsgBoxGiveMeA( function () { return new aWin._eventFactory(__topWindow.document.documentElement, 'mouseup', 'top_mouseup'); } ); // create our top-element mouseup factory with name 'top_mouseup'//
        aWin.eventFactory_topmousemove = aWin.__festoMsgBoxGiveMeA( function () { return new aWin._eventFactory(__topWindow.document.documentElement, 'mousemove', 'top_mousemove'); } ); // create our top-element mousemove factory with name 'top_mousemove'//
        aWin.eventFactory_topscroll = aWin.__festoMsgBoxGiveMeA( function () { return new aWin._eventFactory(__topWindow, 'scroll', 'top_scroll'); } ) ;
        aWin.eventFactory_topresize = aWin.__festoMsgBoxGiveMeA( function () { return new aWin._eventFactory(__topWindow, 'resize', 'top_resize'); } ); 
        aWin.addEvent = addEvent;
        aWin.removeEvent = removeEvent;
      }
    } catch(f) {
      if (msgBoxDEBUG > 0) { alert('Check / create event facory: '+f); }
    }
    __topWindow = aWin;
    Inited = true;  // IE7 need this everytime  a JS is loaded, so dont prevent teh init routine from being executet a thousand times...
  }
  TryLoadingStyleSheet();
  
}

function injectCSS(aWin,aCSSPath,aId) {
  if (aWin.document.createStyleSheet) {
    for (var i=0; i<aWin.document.styleSheets.length; i++) {
      if (aWin.document.styleSheets[i].href==aCSSPath) {
        return;
      }
    }      
    var ass = aWin.document.createStyleSheet(aCSSPath);
  } else {
    if ((aWin.document.getElementById('myCheatedStyleSheet1') == undefined) || (aWin.document.getElementById('myCheatedStyleSheet1') == null)) {    
      var styles = "@import url('"+aCSSPath+"');";
      var aHref = aCSSPath;
      var newSS=aWin.document.createElement('link');
      newSS.id = aId;
      newSS.rel='stylesheet';
      newSS.href=aHref;
      aWin.document.getElementsByTagName("head")[0].appendChild(newSS);
    }
  }
}

function TryLoadingStyleSheet() {
  if (pnf=="false") {
    var aURL = document.location.protocol+'//'+document.location.host;
    injectCSS(__topWindow,aURL+'/xdki/css/reset.css','myCheatedStyleSheet1');
  } else {
    injectCSS(__topWindow,'/cat/de_de/css/reset.css','myCheatedStyleSheet1');
  }
}

function TestPNF() {
  var createPNF = false;
  try {
    if (pnf == undefined) { createPNF = true }
  } catch (e) {
    createPNF = true;
  }
  if (createPNF) {
    var s = document.location.toString();
    s = s.toLowerCase();
    if ((s.indexOf('/cat/')>0) || (s.indexOf('/pnf/')>0) || (s.indexOf('/cms/')>0) || (s.indexOf('/net/')>0) || (s.indexOf('/ptl/')>0)) {
      pnf = "true"; 
    } else {
      pnf = "false";
    }
  }  
}

var Inited = false;
var __topWindow = self;

_messageBox_init();
