var ns            = (document.layers) ? 1 : 0;
var ie            = (document.all) ? 1 : 0;
var dom           = (document.getElementById) ? 1 : 0;
var mac           = (navigator.platform.indexOf("Mac") != -1) ? 1 : 0;
var gecko         = (navigator.userAgent.indexOf("Gecko") != -1) ? 1 : 0;
var geckoVers     = parseFloat(navigator.userAgent.replace(/.*rv:(\d+\.\d+).*/, '$1'));
var ieVers        = navigator.appVersion.substring(navigator.appVersion.lastIndexOf("MSIE") + 4,navigator.appVersion.lastIndexOf("MSIE") + 8);
var focusMessage  = 'false';

var isShownDialog     = false;
var isShownMessageBox = false;
var doc               = document;
var nodeList;
var clickEvents       = new Array();

if(!TEXT_MESSAGEBOX_TITLE){
  var TEXT_MESSAGEBOX_TITLE   = null;
}
if(!TEXT_MESSAGEBOX_OK){
  var TEXT_MESSAGEBOX_OK      = null;
}
if(!TEXT_MESSAGEBOX_CANCEL){
  var TEXT_MESSAGEBOX_CANCEL  = null;
}
if(!TEXT_MESSAGEBOX_YES){
  var TEXT_MESSAGEBOX_YES     = null;
}
if(!TEXT_MESSAGEBOX_ALLWAYS){
  var TEXT_MESSAGEBOX_ALLWAYS = null;
}
if(!TEXT_MESSAGEBOX_NOT){
  var TEXT_MESSAGEBOX_NOT     = null;
}
if(!TEXT_MESSAGEBOX_BACK){
  var TEXT_MESSAGEBOX_BACK    = null;
}
if(!TEXT_MESSAGEBOX_ADAPT){
  var TEXT_MESSAGEBOX_ADAPT   = null;
}
if(!TEXT_MESSAGEBOX_NOADAPT){
  var TEXT_MESSAGEBOX_NOADAPT = null;
}



function initDialog(id, title, text, buttons, icon, variable, buttontext) {
  isShownMessageBox = true;

  if(buttontext !== undefined){
    var textButton = buttontext.split("|");

    for(var i= 0; i < textButton.length; i++){
      if(i == 0){
        TEXT_MESSAGEBOX_OK      = textButton[i];
      }
      else if(i == 1){
        TEXT_MESSAGEBOX_CANCEL  = textButton[i];
      }
      else if(i == 2){
        TEXT_MESSAGEBOX_YES     = textButton[i];
      }
      else if(i == 3){
        TEXT_MESSAGEBOX_ALLWAYS = textButton[i];
      }
      else if(i == 4){
        TEXT_MESSAGEBOX_BACK    = textButton[i];
      }
      else if(i == 5){
        TEXT_MESSAGEBOX_ADAPT   = textButton[i];
      }
      else if(i == 6){
        TEXT_MESSAGEBOX_NOADAPT = textButton[i];
      }
    }
  }

  
  
  text = text.replace(/<br \/>/g, '<br/>');  
  text = text.replace(/<div /g, '<div~');
  var parts       = text.split(' ');
  var texts       = '';
  var textsLine   = '';
  var j           = 1;
  var length      = 0;

  if(parts.length != 0){
    for(var i= 0; i < parts.length; i++){
      if(i+1 == parts.length){
        texts     += textsLine+' '+parts[i];
        
        j++;
        var tmpLength = (textsLine+parts[i]).length;
        if(tmpLength > length){
          length = tmpLength;
        }
      }
      else if(parts[i].search(/<br\/>/) != -1){
        texts     += textsLine+' '+parts[i].replace(/<br\/>/, '<br />');
        j++;
        var tmpLength = textsLine.length+parts[i].replace(/<br\/>/, '<br />').length+1;
        if(tmpLength > length){
          length = tmpLength;
        }
        textsLine = '';
      }
      else if((textsLine + parts[i]).length > 90 && parts[i].length <= 90){
        texts     += textsLine+'<br />\n';
        j++;
        textsLine = parts[i];
        length = 100;
      }
      else if(parts[i].length > 90){
        for(var k = 0; k < Math.round(parts[i].length/80); k++){
          texts += parts[i].substr(k*80, 80)+'<br />\n';
          j++;
        }
        length = 100;
      }
      else{
        textsLine += ' '+parts[i];
      }
    }
  }
  else{
    length = text.length;
    texts = text;
  }

  if(length < 50){
    length = 50;
  }
  else if(length > 120){
	length = 120;
  }   
  
  texts = texts.replace(/~/, ' ');

  
  if(title != '') {
    var dialogTitle = title;
  }
  else {
    if(TEXT_MESSAGEBOX_TITLE && TEXT_MESSAGEBOX_TITLE != ''){
      var dialogTitle = TEXT_MESSAGEBOX_TITLE;
    }
    else{
      var dialogTitle = 'Weblication Hinweis';
    }
  }
 
  if(TEXT_MESSAGEBOX_OK && TEXT_MESSAGEBOX_OK != ''){
    var buttonOKTxt       = TEXT_MESSAGEBOX_OK;
  }
  else{
    var buttonOKTxt       = 'Ok';
  }
  if(TEXT_MESSAGEBOX_CANCEL && TEXT_MESSAGEBOX_CANCEL != ''){
    var buttonCATxt       = TEXT_MESSAGEBOX_CANCEL;
  }
  else{
    var buttonCATxt       = 'Abbrechen';
  }
  if(TEXT_MESSAGEBOX_YES && TEXT_MESSAGEBOX_YES != ''){
    var buttonYESTxt      = TEXT_MESSAGEBOX_YES;
  }
  else{
    var buttonYESTxt      = 'Ja';
  }
  if(TEXT_MESSAGEBOX_ALLWAYS && TEXT_MESSAGEBOX_ALLWAYS != ''){
    var buttonALLWAYSTxt  = TEXT_MESSAGEBOX_ALLWAYS;
  }
  else{
    var buttonALLWAYSTxt  = 'Ja, alle';
  }
  if(TEXT_MESSAGEBOX_NOT && TEXT_MESSAGEBOX_NOT != ''){
    var buttonNOTxt       = TEXT_MESSAGEBOX_NOT;
  }
  else{
    var buttonNOTxt       = 'Nein';
  }

  if(TEXT_MESSAGEBOX_ADAPT && TEXT_MESSAGEBOX_ADAPT != ''){
    var buttonADAPTxt     = TEXT_MESSAGEBOX_ADAPT;
  }
  else{
    var buttonADAPTxt     = 'Ja, mit Linkanspassung';
  }
  if(TEXT_MESSAGEBOX_NOADAPT && TEXT_MESSAGEBOX_NOADAPT != ''){
    var buttonNOADAPTxt   = TEXT_MESSAGEBOX_NOADAPT;
  }
  else{
    var buttonNOADAPTxt   = 'Ja, ohne Linkanspassung';
  }

  if(TEXT_MESSAGEBOX_BACK && TEXT_MESSAGEBOX_BACK != ''){
    var buttonBACKTxt     = TEXT_MESSAGEBOX_BACK;
  }
  else{
    var buttonBACKTxt     = 'Schließen';
  }
  

  if(icon == 'install'){
    var iconpath          = 'http://download.weblication.de/weblication/grid5/gui/images/wMessagebox/loading.gif';
  }
  else{  
    var iconpath          = '/weblication/grid5/gui/images/wMessagebox/'+icon+'.gif';
  }

  var iconOk              = '/weblication/grid5/gui/images/icon_small/ok.gif';
  var iconCancel          = '/weblication/grid5/gui/images/icon_small/cancel.gif';
  var iconYes             = '/weblication/grid5/gui/images/icon_small/ok.gif';
  var iconAdapt           = '/weblication/grid5/gui/images/icon_small/adapt_urls.gif';    
  var iconNo              = '/weblication/grid5/gui/images/icon_small/cancel.gif';
  var iconBACK            = '/weblication/grid5/gui/images/icon_small/cancel.gif';

  if(parent.frames.length < 1) {
    var docBody           = document.body;
  }
  else{
    if(parent.document.body.tagName != 'FRAMESET') {
      if(ie){
        var docBody       = document.body;
      }
      else{
        var docBody       = document.body;
      }
    }
    else{
      var docBody         = document.body;
    }
  }

  if(window.removeEventListener){   
    window.removeEventListener("KeyDown", keyPressed, false );
    window.onkeydown      = keyPressedMessageBox;     
  } 
  else if (window.detachEvent){
    document.detachEvent("KeyDown", keyPressed);
    document.onkeydown    = keyPressedMessageBox;     
  }
  
  var blocker             = document.createElement("div");
  blocker.className       = "blockerClass";
  blocker.id              = "blocker";
  docBody.appendChild(blocker);
  if(ie && ieVers < 7){
	  docBody.firstChild.insertAdjacentHTML('afterEnd', "<iframe src='about:blank' id='blockerFrame' style='width:100%; height: 100%;z-index:999; position:absolute; filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)' />");
  }
  
  var dialog              = document.createElement('div');
  dialog.id               = 'dialog';
  dialog.style.display    = "block";
  
  dialog.style.marginTop  = -(j*10+80)/2+'px';
  dialog.style.marginLeft = -((length*5+75)/2)+'px';
  dialog.style.width      = length*5+75+"px";
  
  if(text.indexOf('errorblockMessagebox') != -1){
    dialog.style.height     = j*10+120+"px";	  
  }
  else{
	dialog.style.height     = j*10+80+"px";	 
  }
  
  docBody.appendChild(dialog);

  var d_head              = document.createElement('div');
  d_head.id               = 'd_head';
  d_head.style.width      = '100%';
  dialog.appendChild(d_head);

  var headline            = document.createElement('h1');
  headline.innerHTML      = dialogTitle;
  headline.id             = 'headline';
  headline.style.width    = dialog.offsetWidth+'px';
  
  d_head.appendChild(headline);

  if(icon) {

    var d_body            = document.createElement('div');
    d_body.innerHTML      = texts;
    d_body.id             = 'd_body_icon';
    dialog.appendChild(d_body);

    var d_icon            = document.createElement('div');
    d_icon.id             = 'd_icon';
    d_icon.style.top      = '40%';
    dialog.appendChild(d_icon);

    var d_icon_img        = document.createElement('img');
    d_icon_img.id         = 'd_icon_img';
    d_icon_img.src        = iconpath;
    d_icon.appendChild(d_icon_img);
  }
  else{
    var d_body            = document.createElement('div');

    d_body.innerHTML      = texts;
    d_body.id             = 'd_body';
    dialog.appendChild(d_body);
  }


  var d_shadow_right                            = document.createElement('div');

  d_shadow_right.style.position                 = 'absolute';
  d_shadow_right.style.top                      = 0+'px';
  d_shadow_right.style.width                    = 5+'px';
  d_shadow_right.style.left                     = dialog.offsetWidth-1+'px';
  d_shadow_right.style.height                   = dialog.offsetHeight+'px';
  var d_shadow_right_top                        = document.createElement('div');
  d_shadow_right_top.id                         = 'd_shadow_right_top';
  d_shadow_right_top.style.height               = 3+'px';
  d_shadow_right_top.style.backgroundImage      = 'url("/weblication/grid5/gui/images/wShadows/messagebox_right_top.png")';
  d_shadow_right_top.style.backgroundRepeat     = 'no-repeat';
  d_shadow_right.appendChild(d_shadow_right_top);
  var d_shadow_right_middle                     = document.createElement('div');
  d_shadow_right_middle.id                      = 'd_shadow_right_middle';
  if(ieVers < 7){
    d_shadow_right_middle.style.marginTop       = - 11+'px';
  }
  d_shadow_right_middle.style.height            = dialog.offsetHeight - 1+'px';
  d_shadow_right_middle.style.backgroundImage   = 'url("/weblication/grid5/gui/images/wShadows/messagebox_right_middle.png")';
  d_shadow_right_middle.style.backgroundRepeat  = 'repeat-y';
  d_shadow_right.appendChild(d_shadow_right_middle);
  dialog.appendChild(d_shadow_right);

  var d_shadow_bottom                           = document.createElement('div');

  d_shadow_bottom.style.position                = 'absolute';
  d_shadow_bottom.style.width                   = dialog.offsetWidth+2+'px';
  d_shadow_bottom.style.top                     = dialog.offsetHeight+'px';
  d_shadow_bottom.style.height                  = 5+'px';
  var d_shadow_bottom_left                      = document.createElement('div');
  d_shadow_bottom_left.id                       = 'd_shadow_bottom_left';
  d_shadow_bottom_left.style.width              = 3+'px';
  d_shadow_bottom_left.style.cssFloat           = 'left';
  d_shadow_bottom_left.style.styleFloat         = 'left';
  d_shadow_bottom_left.style.height             = 5+'px';
  d_shadow_bottom_left.style.backgroundImage    = 'url("/weblication/grid5/gui/images/wShadows/messagebox_bottom_left.png")';
  d_shadow_bottom_left.style.backgroundRepeat   = 'no-repeat';
  d_shadow_bottom.appendChild(d_shadow_bottom_left);
  var d_shadow_bottom_middle                    = document.createElement('div');
  d_shadow_bottom_middle.id                     = 'd_shadow_bottom_middle';
  d_shadow_bottom_middle.style.width            = dialog.offsetWidth - 4 +'px';
  d_shadow_bottom_middle.style.cssFloat         = 'left';
  d_shadow_bottom_middle.style.styleFloat       = 'left';
  d_shadow_bottom_middle.style.height           = 5+'px';
  d_shadow_bottom_middle.style.backgroundImage  = 'url("/weblication/grid5/gui/images/wShadows/messagebox_bottom_middle.png")';
  d_shadow_bottom_middle.style.backgroundRepeat = 'repeat-x';
  d_shadow_bottom.appendChild(d_shadow_bottom_middle);
  var d_shadow_bottom_right                     = document.createElement('div');
  d_shadow_bottom_right.id                      = 'd_shadow_bottom_right';
  d_shadow_bottom_right.style.width             = 3 +'px';
  d_shadow_bottom_right.style.cssFloat          = 'left';
  d_shadow_bottom_right.style.styleFloat        = 'left';
  d_shadow_bottom_right.style.height            = 5+'px';
  d_shadow_bottom_right.style.backgroundImage   = 'url("/weblication/grid5/gui/images/wShadows/messagebox_bottom_right.png")';
  d_shadow_bottom_right.style.backgroundRepeat  = 'no-repeat';
  d_shadow_bottom.appendChild(d_shadow_bottom_right);
  dialog.appendChild(d_shadow_bottom);


  var d_buttons                                 = document.createElement('div');
  d_buttons.id                                  = 'd_buttons';
  if(document.all){

  }
  else{

  }
  dialog.appendChild(d_buttons);
  
  if(buttons.toLowerCase().indexOf('yes') != '-1') {
    var d_bYES                                  = document.createElement('div');

    var newAttrOnMouseOver                      = "this.className='d_b_hi';";
    d_bYES.onmouseover                          = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut                       = "this.className='d_b';";
    d_bYES.onmouseout                           = new Function('F',newAttrOnMouseOut);

    var newAttronclick                          = "button_YES_onclick('"+id+"','"+variable+"');";
    clickEvents.push(newAttronclick);
    d_bYES.onclick                              = new Function('F',newAttronclick);

    d_bYES.className                            = 'd_b';
    d_bYES.id                                   = 'YES';
    if(ie){
      d_bYES.innerHTML                          = '<table style="display:inline; margin-top:1px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="yes_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="yes_txt" style="padding-top:1px;">'+buttonYESTxt+'</td></tr></table>';
    }
    else{
      d_bYES.innerHTML                          = '<table style="display:inline; margin-top:-2px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="yes_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="yes_txt" style="padding-top:1px;">'+buttonYESTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bYES);

    var button_YES                              = d_bYES;
    button_YES.name                             = variable;
    button_YES.id                               = id;
    if(ie){

    }
    else{

    }
  }
  
  if(buttons.toLowerCase().indexOf('allways') != '-1') {
    var d_bALLWAYS                              = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bALLWAYS.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bALLWAYS.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_ALLWAYS_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bALLWAYS.onclick  = new Function('F',newAttronclick);

    d_bALLWAYS.className         = 'd_b';
    d_bALLWAYS.id                = 'ALLWAYS';
    if(ie){
      d_bALLWAYS.innerHTML         = '<table style="display:inline; margin-top:1px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="allways_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="allways_txt"style="padding-top:1px;">'+buttonALLWAYSTxt+'</td></tr></table>';
    }
    else{
      d_bALLWAYS.innerHTML         = '<table style="display:inline; margin-top:-2px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="allways_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="allways_txt"style="padding-top:1px;">'+buttonALLWAYSTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bALLWAYS);

    var button_ALLWAYS           = d_bALLWAYS;
    button_ALLWAYS.name          = variable;
    button_ALLWAYS.id            = id;
    if(ie){

    }
    else{

    }
  }

  if(buttons.toLowerCase().indexOf('adapt') != '-1') {
  	var d_bADAPT               = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bADAPT.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bADAPT.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_ADAPT_onclick('"+id+"','"+variable+"');";
    clickEvents.push(newAttronclick);
    d_bADAPT.onclick  = new Function('F',newAttronclick);

    d_bADAPT.className         = 'd_b';
    d_bADAPT.id                = 'ADAPT';
    if(ie){
      d_bADAPT.innerHTML         = '<table style="display:inline; margin-top:1px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="adapt_icon" style="margin-right:3px; margin-top:1px;" src="'+iconAdapt+'"/></td><td id="adapt_txt" style="padding-top:1px;">'+buttonADAPTxt+'</td></tr></table>';
    }
    else{
      d_bADAPT.innerHTML         = '<table style="display:inline; margin-top:-2px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="adapt_icon" style="margin-right:3px; margin-top:1px;" src="'+iconAdapt+'"/></td><td id="adapt_txt" style="padding-top:1px;">'+buttonADAPTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bADAPT);

    var button_ADAPT           = d_bADAPT;
    button_ADAPT.name          = variable;
    button_ADAPT.id            = id;
    if(ie){

    }
    else{

    }
  }
  
  if(buttons.toLowerCase().indexOf('keep') != '-1') {
    var d_bNOADAPT               = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bNOADAPT.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bNOADAPT.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_NOADAPT_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bNOADAPT.onclick  = new Function('F',newAttronclick);

    d_bNOADAPT.className         = 'd_b';
    d_bNOADAPT.id                = 'NOADAPT';
    if(ie){
      d_bNOADAPT.innerHTML         = '<table style="display:inline; margin-top:1px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="yes_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="adapt_txt"style="padding-top:1px;">'+buttonNOADAPTxt+'</td></tr></table>';
    }
    else{
      d_bNOADAPT.innerHTML         = '<table style="display:inline; margin-top:1px; margin-bottom:30px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="yes_icon" style="margin-right:3px; margin-top:1px;" src="'+iconYes+'"/></td><td id="adapt_txt"style="padding-top:1px;">'+buttonNOADAPTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bNOADAPT);

    var button_NOADAPT           = d_bNOADAPT;
    button_NOADAPT.name          = variable;
    button_NOADAPT.id            = id;
    if(ie){

    }
    else{

    }
  }

  if (buttons.toLowerCase().indexOf('no') != '-1') {
    var d_bNO               = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bNO.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bNO.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_NO_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bNO.onclick  = new Function('F',newAttronclick);


    d_bNO.className         = 'd_b';
    d_bNO.id                = 'NO';
    if(ie){
      d_bNO.innerHTML         = '<table style="display:inline; margin-top:1px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="no_icon" style="margin-right:3px; margin-top:1px;" src="'+iconNo+'"/></td><td id="no_txt"style="padding-top:1px;">'+buttonNOTxt+'</td></tr></table>';
    }
    else{
      d_bNO.innerHTML         = '<table style="display:inline; margin-top:-2px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="no_icon" style="margin-right:3px; margin-top:1px;" src="'+iconNo+'"/></td><td id="no_txt"style="padding-top:1px;">'+buttonNOTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bNO);

    var button_NO           = d_bNO;
    button_NO.name          = variable;
    button_NO.id            = id;
    if(ie){

    }
    else{

    }
  }

  if (buttons.toLowerCase().indexOf('ok') != '-1') {
    var d_bOK               = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bOK.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bOK.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_OK_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bOK.onclick  = new Function('F',newAttronclick);

    d_bOK.className         = 'd_b';
    d_bOK.id                = 'OK';
    if(ie){
      d_bOK.innerHTML         = '<table style="display:inline; margin-top:1px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="ok_icon" style="margin-right:3px; margin-top:1px;" src="'+iconOk+'"/></td><td id="ok_txt" style="padding-top:1px;">'+buttonOKTxt+'</td></tr></table>';
    }
    else{
      d_bOK.innerHTML         = '<table style="display:inline; margin-top:-2px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="ok_icon" style="margin-right:3px; margin-top:1px;" src="'+iconOk+'"/></td><td id="ok_txt" style="padding-top:1px;">'+buttonOKTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bOK);

    var button_OK           = d_bOK;
    button_OK.name          = variable;
    button_OK.id            = id;
    if(ie){

    }
    else{

    }
  }

  if (buttons.toLowerCase().indexOf('cancel') != '-1') {

    var d_bCANCEL           = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bCANCEL.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bCANCEL.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_CANCEL_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bCANCEL.onclick  = new Function('F',newAttronclick);

    d_bCANCEL.className     = 'd_b';
    d_bCANCEL.id            = 'CANCEL';
    if(ie){
      d_bCANCEL.innerHTML     = '<table style="display:inline; margin-top:1px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="cancel_icon" style="margin-right:3px; margin-top:1px;" src="'+iconCancel+'"/></td><td id="cancel_txt" style="padding-top:1px;">'+buttonCATxt+'</td></tr></table>';
    }
    else{
      d_bCANCEL.innerHTML     = '<table style="display:inline; margin-top:-2px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="cancel_icon" style="margin-right:3px; margin-top:1px;" src="'+iconCancel+'"/></td><td id="cancel_txt" style="padding-top:1px;">'+buttonCATxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bCANCEL);

    var button_CANCEL       = d_bCANCEL;
    button_CANCEL.name      = variable;
    button_CANCEL.id        = id;
    if(ie){
      button_CANCEL.attachEvent("onclick", button_CANCEL_onclick);
    }
    else{
      button_CANCEL.addEventListener("click", button_CANCEL_onclick, false);
    }
  }

  if (buttons.toLowerCase().indexOf('back') != '-1') {

    var d_bBACK               = document.createElement('div');

    var newAttrOnMouseOver = "this.className='d_b_hi';";
    d_bBACK.onmouseover = new Function('F',newAttrOnMouseOver);

    var newAttrOnMouseOut  = "this.className='d_b';";
    d_bBACK.onmouseout  = new Function('F',newAttrOnMouseOut);

    var newAttronclick  = "button_BACK_onclick('"+id+"','"+variable+"')";
    clickEvents.push(newAttronclick);
    d_bBACK.onclick  = new Function('F',newAttronclick);


    d_bBACK.className         = 'd_b';
    d_bBACK.id                = 'BACK';
    if(ie){
      d_bBACK.innerHTML         = '<table style="display:inline; margin-top:1px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="back_icon" style="margin-right:3px; margin-top:1px;" src="'+iconBACK+'"/></td><td id="back_txt" style="padding-top:1px;">'+buttonBACKTxt+'</td></tr></table>';
    }
    else{
      d_bBACK.innerHTML         = '<table style="display:inline; margin-top:-2px; border:0;" cellpadding="0" cellspacing="0"><tr><td><img id="back_icon" style="margin-right:3px; margin-top:1px;" src="'+iconBACK+'"/></td><td id="back_txt" style="padding-top:1px;">'+buttonBACKTxt+'</td></tr></table>';
    }
    d_buttons.appendChild(d_bBACK);

    var button_BACK           = d_bBACK;
    button_BACK.name          = variable;
    button_BACK.id            = id;
    if(ie){

    }
    else{

    }
  }

  var pClear              = document.createElement('p');
  pClear.style.clear      = 'both';
  d_buttons.appendChild(pClear);

  nodeList = d_buttons.getElementsByTagName("div");
  if(nodeList.length > 0){
    nodeList[0].className = "d_b_hi";
  }
  
  isShownDialog = true;
}


function button_OK_onclick(id, value){

  hideMessagebox();
  if(id!=''){
    eval ('if(typeof messagebox_' + id + '_onConfirm == \'function\') {messagebox_' + id + '_onConfirm("ok","' + value + '");}');
  }
 
}

function button_YES_onclick(id, value){
  
  hideMessagebox();
  if(id != '' && typeof eval('messagebox_' + id + '_onConfirm') == 'function'){
    eval ('messagebox_' + id + '_onConfirm("yes","' + value + '")');
  }
  
}

function button_ADAPT_onclick(id, value){
  
  if(ie){


  }
  else{


  }

  if(parent.frames.length < 1){
    docBody                 = document.body;
    blocker                 = document.getElementById('blocker');
    dialog                  = document.getElementById('dialog');
  }
  else{
    if(parent.document.body.tagName != 'FRAMESET'){
      if(ie){
        var docBody                 = document.body;
        var blocker                 = document.getElementById('blocker');
        var dialog                  = document.getElementById('dialog');
      }
      else{
        docBody                 = document.body;
        blocker                 = document.getElementById('blocker');
        dialog                  = document.getElementById('dialog');
      }
    }
    else{
      docBody                 = document.body;
      blocker                 = document.getElementById('blocker');
      dialog                  = document.getElementById('dialog');
    }
  }

  if(window.removeEventListener){
    window.removeEventListener("KeyDown", keyPressedMessageBox, false );
    window.onkeydown = keyPressed;     
  } 
  else if (window.detachEvent){
    document.detachEvent("KeyDown", keyPressedMessageBox);
    window.onkeydown = keyPressed;
  }    
  
  docBody.removeChild(blocker);
  docBody.removeChild(dialog);
  if(ie && ieVers < 7){
  	docBody.removeChild(document.getElementById('blockerFrame'));
  }
  clickEvents = new Array();
  if(id!=''){
    eval ('messagebox_' + id + '_onConfirm("adapt","' + value + '")');
  }
  isShownDialog = false;
  isShownMessageBox = false;
}

function button_NOADAPT_onclick(id, value){
	
  if(ie){


  }
  else{


  }

  if(parent.frames.length < 1){
    docBody                 = document.body;
    blocker                 = document.getElementById('blocker');
    dialog                  = document.getElementById('dialog');
  }
  else{
    if(parent.document.body.tagName != 'FRAMESET'){
      if(ie){
        var docBody                 = document.body;
        var blocker                 = document.getElementById('blocker');
        var dialog                  = document.getElementById('dialog');
      }
      else{
        docBody                 = document.body;
        blocker                 = document.getElementById('blocker');
        dialog                  = document.getElementById('dialog');
      }
    }
    else{
      docBody                 = document.body;
      blocker                 = document.getElementById('blocker');
      dialog                  = document.getElementById('dialog');
    }
  }

  if(window.removeEventListener){
    window.removeEventListener("KeyDown", keyPressedMessageBox, false );
    window.onkeydown = keyPressed;     
  } 
  else if (window.detachEvent){
    document.detachEvent("KeyDown", keyPressedMessageBox);
    window.onkeydown = keyPressed;
  }    
  
  docBody.removeChild(blocker);
  docBody.removeChild(dialog);
  if(ie && ieVers < 7){
  	docBody.removeChild(document.getElementById('blockerFrame'));
  }
  clickEvents = new Array();
  if(id!=''){
    eval ('messagebox_' + id + '_onConfirm("noadapt","' + value + '")');
  }
  isShownDialog = false;
  isShownMessageBox = false;
}

function button_ALLWAYS_onclick(id, value){

  hideMessagebox();
  if(id != '' && typeof eval('messagebox_' + id + '_onConfirm') == 'function'){
    eval ('messagebox_' + id + '_onConfirm("allways","' + value + '")');
  }  
  
}

function button_CANCEL_onclick(id, value){

  hideMessagebox();
  if(window.detachEvent){
    document.attachEvent("onkeydown", keyPressed);
  }  
  
  if(id != '' && typeof id == 'string' && typeof eval('messagebox_' + id + '_onConfirm') == 'function'){
    eval ('messagebox_' + id + '_onConfirm("cancel","' + value + '")');
  }
  
}

function button_NO_onclick(id, value){

  hideMessagebox();
  if(id != '' && typeof eval('messagebox_' + id + '_onConfirm') == 'function'){
    eval ('messagebox_' + id + '_onConfirm("no","' + value + '")');
  }
  
}

function button_BACK_onclick(id, value){

  hideMessagebox();    
  if(id != '' && typeof eval('messagebox_' + id + '_onConfirm') == 'function'){
    eval ('messagebox_' + id + '_onConfirm("back","' + value + '")');
  }
  
}

function hideMessagebox(){
  
  if(focusMessage == 'true'){
    return true;
  }

  if(parent.frames.length < 1){
    docBody                 = document.body;
    blocker                 = document.getElementById('blocker');
    dialog                  = document.getElementById('dialog');
  }
  else{
    if(parent.document.body.tagName != 'FRAMESET'){
      if(ie){
        var docBody                 = document.body;
        var blocker                 = document.getElementById('blocker');
        var dialog                  = document.getElementById('dialog');
      }
      else{
        docBody                 = document.body;
        blocker                 = document.getElementById('blocker');
        dialog                  = document.getElementById('dialog');
      }
    }
    else{
      docBody                 = document.body;
      blocker                 = document.getElementById('blocker');
      dialog                  = document.getElementById('dialog');
    }
  }

  if(window.removeEventListener){
    window.removeEventListener("KeyDown", keyPressedMessageBox, false );
    window.onkeydown = keyPressed;     
  } 
  else if (window.detachEvent){
    document.detachEvent("KeyDown", keyPressedMessageBox);
    window.onkeydown = keyPressed;
  }  
  
  if(blocker){
    blocker.parentNode.removeChild(blocker);
  }
  if(dialog){
    dialog.parentNode.removeChild(dialog);
  }
  if(ie && ieVers < 7){
  	document.getElementById('blockerFrame').parentNode.removeChild(document.getElementById('blockerFrame'));
  }
  
  clickEvents = new Array();  
  
  isShownDialog = false;
  isShownMessageBox = false;
}



function resetMessageBoxButton(){
  for(var i=0;i<nodeList.length;i++){
    nodeList[i].className == 'd_b_hi';
  }
}



function keyPressedMessageBox(e){

  
  var ascii = (doc.all) ? event.keyCode  : e.which;
  var ctrl  = (doc.all) ? event.ctrlKey  : e.ctrlKey;
  var shift = (doc.all) ? event.shiftKey : e.shiftKey;
  
  switch(ascii){
    case 9:  //TAB
    
      if(ie){
        window.event.returnValue = false;
      }
      else{
        e.preventDefault();    
      }  

      for(var i=0;i<nodeList.length;i++){
        if(nodeList[i].className == 'd_b_hi' && i<(nodeList.length-1)){
          nodeList[i].className = 'd_b';
          nodeList[i+1].className = 'd_b_hi';
          nodeList[i+1].focus();
          break;
        }
        else if(nodeList[i].className == 'd_b_hi' && i==(nodeList.length-1)){
          nodeList[i].className = 'd_b';
          nodeList[0].className = 'd_b_hi';
          nodeList[0].focus();
          break;
        }
        else if(nodeList[nodeList.length-1].className == 'd_b'){
          nodeList[0].className = 'd_b_hi';
          nodeList[0].focus();
          break;
        }
      }
    
      break;    
    case 13:  //Enter
      for(var i=0;i<nodeList.length;i++){

        if(nodeList[i].className == 'd_b_hi'){   
          eval(clickEvents[i]);
          break;
        }
        else if(nodeList[nodeList.length-1].className == 'd_b'){


        }      
      }
      break;
      
    case 32:  //SPACE
      for(var i=0;i<nodeList.length;i++){
        if(nodeList[i].className == 'd_b_hi'){
          eval(clickEvents[i]);
          break;
        }
        else if(nodeList[nodeList.length-1].className == 'd_b'){
          eval(clickEvents[0]);
          break;
        }      
      }
      break;      
      
    case 27:  //ESC
      for(var i=0;i<nodeList.length;i++){
        if(nodeList[nodeList.length-1].className == 'd_b'){
          eval(clickEvents[nodeList.length-1]);
          break;
        }      
      }
      break;

    case 37:   //Links

      if(ie){
        window.event.returnValue = false;
      }
      else{
        e.preventDefault();    
      }      
    
      for(var i=0;i<nodeList.length;i++){
        if(nodeList[i].className == 'd_b_hi' && i>0){
          nodeList[i].className = 'd_b';
          nodeList[i-1].className = 'd_b_hi';
          break;
        }




      }
      break;
      
    case 39:   //Rechts
    
      if(ie){
        window.event.returnValue = false;
      }
      else{
        e.preventDefault();    
      }      
    
      for(var i=0;i<nodeList.length;i++){
        if(nodeList[i].className == 'd_b_hi' && i<(nodeList.length-1)){
          nodeList[i].className = 'd_b';
          nodeList[i+1].className = 'd_b_hi';
          break;
        }




      }
      break;

    default:
      break;
  }
}
