<!--
/*
  var sActDialog = ''
  var sActDialogSuf = '';
  var ahOpenDialogs = new Array();
*/
var bfDialog = {};
bfDialog.hDialog = {};
bfDialog.cssWidth   = 0;
bfDialog.bGhostEver = 0;
bfDialog.getDlgById = function(sId){
  var sRet = null;
  if (sId.length > 7){
    var sDialog = sId.substr(8);
    if (typeof(bfDialog.hDialog[sDialog]) != 'undefined'){
      sRet = sDialog;
    }
  }
  return sRet;
}
bfDialog.add = function(hTpl){
  var sId = '_dialog_'+hTpl['data']['key'];
  var oDlg;
  if (oDlg = document.getElementById(sId)){
    return null;
  }else{
    var oPage = document.getElementById('_page');
    var oDlg = bfPage.createElement('div',{
      'className': 'dialog dialog_'+hTpl['data']['color'],
      'id':        sId,
      'style':     {'display':'none'}
    });
    oPage.parentNode.insertBefore(oDlg,oPage);
    jsHelper.setEvent(oDlg,'onmousedown','bfDialog.setActive(\''+hTpl['data']['key']+'\')','bfDialog::add');
    if (typeof(hTpl['data']['width']) != 'undefined' && hTpl['data']['width']){
      oDlg.style.width = hTpl['data']['width']+'px';
    }
    var oTbl = bfPage.createElement('table',{
      'id':        '_dialog_status_'+hTpl['data']['key'],
      'className': 'table_plain',
      'style':     {'width':'100%','display':'none'}
    });
    oDlg.appendChild(oTbl);
    var oTBdy = bfPage.createElement('tbody');
    oTbl.appendChild(oTBdy);
    var oTr = bfPage.createElement('tr');
    oTBdy.appendChild(oTr);
    var oTd = bfPage.createElement('td');
    oTr.appendChild(oTd);
    return oDlg;
  }
}
bfDialog._add = function(sDialog,sPrt,sType,sDisplayMode,hStyle){
  var sPrt         = sPrt || null;
  var sType        = sType || 'green';
  var sDisplayMode = sDisplayMode || 'dialog';
  var hStyle = hStyle || {'display':'none'};
  if (typeof(hStyle['display']) == 'undefined'){
    hStyle['display'] = 'none';
  }
  var oPage = document.getElementById('_page');
  var sNewDialogSuf = ((sDialog) ? '_'+sDialog : '');
  var sNewDialog = ((sDialog) ? sDialog : '');
  var oDlg = bfPage.createElement('div',{
    'id': '_dialog'+sNewDialogSuf,
    'className': 'dialog dialog_'+sType,
    'style': hStyle
  });
  var oTblStatus = bfPage.createElement('table',{
    'id': '_dialog_status'+sNewDialogSuf,
    'className': 'table_plain',
    'style': {'width':'100%','display':'none'}
  });
  oDlg.appendChild(oTblStatus);
  var oTBdy = bfPage.createElement('tbody');
  oTblStatus.appendChild(oTBdy);
  var oTr = bfPage.createElement('tr');
  oTBdy.appendChild(oTr);
  var oTd = bfPage.createElement('td');
  oTr.appendChild(oTd);
  oPage.parentNode.insertBefore(oDlg,oPage);
  bfDialog.hDialog[sDialog] = {
    'name':    sDialog,
    'parent':  sPrt,
    'childs':  [],
    'active':  0,
    'visible': 0,
    'id':      '_dialog'+sNewDialogSuf,
    'mode':    sDisplayMode,
    'oDlg':    oDlg
  };
  jsHelper.setEvent(oDlg,'onmousedown','bfDialog.setActive(\''+sDialog+'\')','bfDialog::add');
  if (sPrt != null){
    bfDialog.addChild(sPrt,sDialog);
  }
  return oDlg;
}
bfDialog.addChild = function(sPrt,sChild){
  bfDialog.hDialog[sPrt]['childs'].push(bfDialog.hDialog[sChild]);
}
bfDialog.setActive = function(sDialog){
  for (var sAct in bfDialog.hDialog){
    bfDialog.hDialog[sAct]['active'] = 0;
  }
  bfDialog.hDialog[((sDialog) ? sDialog : 'default')]['active'] = 1;
  sActDialogSuf = ((sDialog) ? '_'+sDialog : '');
  sActDialog = ((sDialog) ? sDialog : '');
}
bfDialog.show = function(bDisplay,sDialog,sDisplayMode,xOnClose){
  if (typeof(sDialog) == 'undefined'){
    var sDialog = null;
  }
  var sDlgIdent = (sDialog) ? sDialog : 'default';
  var fctOnClose = (typeof(xOnClose) == 'string') ? new Function('sDialog',xOnClose) : ((typeof(xOnClose) == 'function') ? xOnClose : function(){return 1});
  if (typeof(bfDialog.hDialog[sDlgIdent]) != 'undefined'){
    bfDialog.hDialog[sDlgIdent]['visible'] = bDisplay;
    bfDialog.hDialog[sDlgIdent]['active']  = bDisplay;
    if (typeof(sDisplayMode) == 'undefined'){
      var  sDisplayMode = bfDialog.hDialog[sDlgIdent]['mode'];
    }else{
      bfDialog.hDialog[sDlgIdent]['mode'] = sDisplayMode;
    }
    var oDialog = bfDialog.hDialog[sDlgIdent]['oDlg'];
  }else{
    var sDisplayMode = (typeof(sDisplayMode) != 'undefined') ? sDisplayMode : 'dialog';
    bfDialog.hDialog[sDlgIdent] = {
      'name':    sDialog,
      'parent':  null,
      'childs':  [],
      'visible': bDisplay,
      'active':  bDisplay,
      'id':      '_dialog'+((sDialog) ? '_'+sDialog : ''),
      'mode':    sDisplayMode,
      'onClose': fctOnClose
    };
    var oDialog = document.getElementById(bfDialog.hDialog[sDlgIdent]['id']);
    bfDialog.hDialog[sDlgIdent]['oDlg'] = oDialog;
    jsHelper.setEvent(oDialog,'onmousedown','bfDialog.setActive('+((sDialog) ? '\''+sDialog+'\'' : 'null')+')','bfDialog::show');
  }
  if (bDisplay){
    if (sDisplayMode != 'widget'){
      bfDialog.showGhost(1);
    }
    bfDialog.setActive(sDialog);
    oDialog.style.display= '';
    if (sDisplayMode == 'dialog'){
      if (typeof(oDialog.marginCache)=='undefined'){
        oDialog.marginCache = jsHelper.getRealStyle(oDialog,'margin-top',1);
      }
      if (bfDialog.cssWidth == 0){
        for(var i=0; i<document.styleSheets.length; i++){
          for(var j=0; j<document.styleSheets[i][sRules].length; j++){
            if (document.styleSheets[i][sRules][j].selectorText == '.dialog'){
              bfDialog.cssWidth = document.styleSheets[i][sRules][j].style['width'];
              bfDialog.cssWidth = parseInt(bfDialog.cssWidth.substr(0,bfDialog.cssWidth.length-2));
            }
          }
        }
      }
      var iTmpWidth = parseInt(oDialog.style.width.substr(0,oDialog.style.width.length-2));
      if (isNaN(iTmpWidth) || bfDialog.cssWidth > iTmpWidth){
        oDialog.style.width = bfDialog.cssWidth+'px';
      }
      if (100 + oDialog.offsetHeight > document.documentElement.offsetHeight){
        if (oDialog.offsetHeight > document.documentElement.offsetHeight){
          var iTop = 0;
        }else{
          var iTop = document.documentElement.offsetHeight - (oDialog.offsetHeight + oDialog.marginCache);
        }
      }else{
        var iTop = 100;
      }
      oDialog.style.top = iTop + jsHelper.getBodyScrollTop()+'px';
      oDialog.style.left = ((document.documentElement.offsetWidth - oDialog.offsetWidth)/2)+'px';
    }
    if (sDisplayMode == 'widget'){
      if (typeof(oDialog.style.zIndex) == 'undefined'){
        oDialog.style.zIndex = 2;
      }
      if (typeof(oDialog.style.position) == 'undefined' || oDialog.style.position.length == 0){
        oDialog.style.position = 'fixed';
      }
      if (typeof(oDialog.style.width) == 'undefined' || oDialog.style.width.length == 0){
        oDialog.style.width = '240px';
      }
      if (typeof(oDialog.style.top) == 'undefined' || oDialog.style.top.length == 0){
        oDialog.style.top = 0+'px';
        oDialog.style.right = '0px';
      }
    }
    var aoScroll = bfPage.getElementsByClassName(oDialog,'scroll');
    if (aoScroll.length){
      var iNewWidth = parseInt(oDialog.style.width);
      for (var i=0;i<aoScroll.length;i++){
        aoScroll[i].style.width = iNewWidth+'px';
        bfPage.fixHScroll(aoScroll[i]);
      }
    }
    if (bfDialog.hasXClose(oDialog) && jsHelper.getEvent(document,'onkeydown','bfDialog::closeByEsc').length == 0){
      jsHelper.setEvent(document,'onkeydown',bfDialog.closeByEsc,'bfDialog::closeByEsc');
    }
    if (ahOpenDialogs[ahOpenDialogs.length - 1] != oDialog){
      ahOpenDialogs.push(oDialog);
    }
  }else{
    var oDialogStatusTbl = document.getElementById('_dialog_status'+sActDialogSuf);
    var oMainStatusTbl = document.getElementById('_dialog_status');
    var oNewStatusTbl = oDialogStatusTbl.cloneNode(true);
    var sIdCache = oMainStatusTbl.id;
    oMainStatusTbl.parentNode.replaceChild(oNewStatusTbl,oMainStatusTbl);
    jsHelper.setClass(oNewStatusTbl,1,'table_data_width');
    oNewStatusTbl.style.width = '';
    oNewStatusTbl.style.tableLayout = 'fixed';
    oNewStatusTbl.id = sIdCache;
    shStatus.reset();

    var bClose = bfDialog.hDialog[sDlgIdent]['onClose'](sDialog);
    if (typeof(bClose) != 'undefined' && !bClose){
      return;
    }
    if (sDisplayMode != 'widget'){
      bfDialog.showGhost(0);
    }

    var hDlg = bfDialog.hDialog[sDlgIdent];
    oDialog.style.display = 'none';
    for (var i=0;i<hDlg['childs'].length;i++){
      var hSubDlg = hDlg['childs'][i];
      if (hSubDlg['visible']){
        bfDialog.sub.close(hSubDlg['name']);
      }
    }
    if (hDlg['parent']){
      var sPrt = (hDlg['parent'].length > 0) ? hDlg['parent'] : 'default';
      var hPrtDlg = bfDialog.hDialog[sPrt];
      bfDialog.setActive(hPrtDlg['name']);
      bfDialog.enable(sActDialog);
      var bAllClosed = 0;
      var bShowGhost = 0;
      for (var sDlg in bfDialog.hDialog){
        if (bfDialog.hDialog[sDlg]['visible'] && bfDialog.hDialog[sDlg]['mode'] != 'widget'){
          var bShowGhost = 1;
        }
      }
    }else{
      var bAllClosed = 1;
      var bShowGhost = 0;
      for (var sDlg in bfDialog.hDialog){
        if (bfDialog.hDialog[sDlg]['visible']){
          bAllClosed = 0;
          if (bfDialog.hDialog[sDlg]['mode'] != 'widget'){
            bShowGhost = 1;
          }
          var sLastDlg = sDlg;
        }
      }
      if (!bAllClosed){
        bfDialog.setActive(sLastDlg);
      }
    }
    if (bAllClosed){
      sActDialogSuf = '';
      sActDialog    = '';
    }else if (bShowGhost){
      bfDialog.showGhost(1);
    }
    ahOpenDialogs.pop();

    if (typeof(bfSmarty) == 'object' && (oDatePicker = document.getElementById(bfSmarty.jsDatepicker.sDivID))){
      oDatePicker.style.display = 'none';
      oDatePicker.style.visibility = 'hidden';
    }
    if (document.body.style.cursor=='help'){
      bfInfo.switchHelpMode();
    }
  }
}
bfDialog.close = function(sDialog,bResetStatus){
  if (typeof(sDialog) == 'undefined'){
    sDialog = sActDialog;
  }
  if (typeof(bResetStatus) != 'undefined' && bResetStatus == 1){
    shStatus.reset();
  }
  this.show(0,sDialog);
}
bfDialog.enable = function(sDialog){
  if (oGhost = document.getElementById(sDialog+'_ghost_dlg')){
    oGhost.style.display = 'none';
  }
}
bfDialog.disable = function(sDialog){
  var oGhost;
  if (!(oGhost = document.getElementById(sDialog+'_ghost_dlg'))){
    oGhost = document.createElement('div');
    oGhost.className = 'ghost_layer';
    oGhost.id = sDialog+'_ghost_dlg';
    oGhost.style.position = 'absolute';
    oGhost.style.top = '0px';
    oGhost.style.left = '0px';
    oGhost.style.zIndex = '5';
  }
  var oDlg = this.get(sDialog);
  oDlg.appendChild(oGhost);
  oGhost.style.display = 'block';
  oGhost.style.width = oDlg.clientWidth+'px';
  oGhost.style.height = oDlg.clientHeight+'px';
}
bfDialog.showGhost = function(bYep,bEver){
  var bYep = (typeof(bYep) == 'undefined') ? 1 : bYep;
  bfDialog.bGhostEver = (typeof(bEver) == 'undefined') ? bfDialog.bGhostEver : bEver;
  if (bfDialog.bGhostEver && !bYep){
    return;
  }
  var oGhost = document.getElementById('ghost');
  if (bYep){
    oGhost.style.display = 'block';
    if(typeof(window.innerWidth) == 'number'){
      var iWidth = window.innerWidth;
      var iHeight = window.innerHeight;
    }else{
      var iWidth = document.documentElement.clientWidth;
      var iHeight = document.documentElement.clientHeight;
    }
    oGhost.style.height = iHeight+'px';
    oGhost.style.width  = iWidth+'px';
  }else{
    oGhost.style.display = 'none';
  }
}
bfDialog.hasXClose = function(oDialog){
  var iRet = 0;
  if (oDialog){
    var aoTables = oDialog.getElementsByTagName('table');
    var oTable = null;
    for (var i=0;i < aoTables.length;i++){
      if (aoTables[i].lang && aoTables[i].lang == 'dialog_head'){
        oTable = aoTables[i];
        break;
      }
    }
    if (oTable){
      var aoDiv = oTable.getElementsByTagName('div');
      for (var i=0;i<aoDiv.length;i++){
        if (aoDiv[i].className && aoDiv[i].className.match(/close_button/)){
          iRet = 1;
          break;
        }
      }
    }
  }
  return iRet;
}
bfDialog.closeByEsc = function(e){
  if (!e && window.event) {
    e = window.event;
  }
  if (e.type == 'keydown' && (e.which == 27 || e.keyCode == 27)){
    if (e.preventDefault) {
      e.preventDefault();
    } else {
      e.returnValue = false;
    }
    var oDialog = document.getElementById('_dialog'+sActDialogSuf);
    if (bfDialog.hasXClose(oDialog)){
      bfDialog.close(sActDialog,1);
      bfInfo.closeHelp();
    }
  }
}
bfDialog.hide = function(sDialog){
  document.getElementById('_dialog'+(sDialog ? '_'+sDialog : '')).style.display='none';
}
bfDialog.unhide = function(sDialog){
  document.getElementById('_dialog'+(sDialog ? '_'+sDialog : '')).style.display='';
  if (bfDialog.bGhostEver){
    bfDialog.disable(sDialog);
  }
}
bfDialog.getTop = function(bRetObj){
  var bRetObj = (typeof(bRetObj) == 'undefined' || bRetObj) ? 1 : 0;
  var xRet = '';
  for (var sDialog in bfDialog.hDialog){
    if (bfDialog.hDialog[sDialog]['active']){
      xRet = (bRetObj) ? bfDialog.hDialog[sDialog]['oDlg'] : sDialog;
    }
  }
  return xRet;
}
bfDialog.setTitel = function(sDialog,sTitel){
  var oDialog = document.getElementById('_dialog'+((sDialog) ? '_'+sDialog : ''));
  var aoTables = oDialog.getElementsByTagName('table');
  var oTable = null;
  for (var i=0;i < aoTables.length;i++){
    if (aoTables[i].lang && aoTables[i].lang == 'dialog_head'){
      oTable = aoTables[i];
      break;
    }
  }
  if (oTable){
    var oTd = oTable.getElementsByTagName('td')[0];
    var oCntr = (oTd.getElementsByTagName('span').length)
      ? oTd.getElementsByTagName('span')[0]
      : oTd;
    oCntr.innerHTML = sTitel;
  }
}
bfDialog.setDates = function(sDialog,hData){
  var oDialog = document.getElementById('_dialog'+((sDialog) ? '_'+sDialog : ''));
  var aoTables = oDialog.getElementsByTagName('table');
  var oTable = null;
  for (var i=0; i<aoTables.length; i++){
    if (aoTables[i].lang && aoTables[i].lang == 'dialog_header'){
      oTable = aoTables[i];
      break;
    }
  }
  if (oTable){
    oTable.rows[2].cells[0].innerHTML = hData['gen_date'];
    oTable.rows[2].cells[1].innerHTML = hData['upd_date'];
  }
}
bfDialog.setSpan = function(sDialog,sVal,iNum){
  if (typeof(iNum) == 'undefined'){
    iNum = 0;
  }
  document.getElementById('_dialog_'+sDialog).getElementsByTagName('span')[iNum].innerHTML = sVal;
}
bfDialog.get = function(sDialog){
  return document.getElementById('_dialog_'+sDialog);
}
bfDialog.titleDrag = function(oEl, oEvent){
  var bGhosted = (document.getElementById('ghost').style.display == 'block') ? 1 : 0;
  var startX = oEvent.clientX;
  var startY = oEvent.clientY;
  var origX  = oEl.offsetLeft;
  var origY  = oEl.offsetTop;
  var deltaX = startX - origX;
  var deltaY = startY - origY;
  var iPageHeight      = document.documentElement.scrollHeight;
  var iPageWidth       = document.documentElement.scrollWidth;
  var iPageInnerHeight = document.documentElement.offsetHeight;
  var iPageInnerWidth  = document.documentElement.offsetWidth;
  var iPageScrollTop   = (oEl.style.position == 'fixed') ? 0 : jsHelper.getBodyScrollTop();
  var iPageScrollLeft  = (oEl.style.position == 'fixed') ? 0 : jsHelper.getBodyScrollLeft();
  var iHeadHeight = oEl.getElementsByTagName('td')[0].offsetHeight 
    + getRealStyle(oEl,'padding-top',1)
    + getRealStyle(oEl.getElementsByTagName('table')[0],'margin-top',1);
  if (document.addEventListener){
    document.addEventListener("mousemove", dialogMoveHandler, true);
    document.addEventListener("mouseup", dialogUpHandler, true);
  }else if (document.attachEvent){
    oEl.setCapture();
    oEl.attachEvent("onmousemove", dialogMoveHandler);
    oEl.attachEvent("onmouseup", dialogUpHandler);
    oEl.attachEvent("onlosecapture", dialogUpHandler);
  }
  bfDialog.setActive(oEl.id.replace(/^_dialog_/,''));
  if (oEvent.stopPropagation){
    oEvent.stopPropagation();
  }else{
    oEvent.cancelBubble = true;
  }
  if (oEvent.preventDefault){
    oEvent.preventDefault();
  }else{
    oEvent.returnValue = false;
  }
  function dialogMoveHandler(e){
    if (!e) {
      e = window.event;
    }
    var iLeft = e.clientX - deltaX;
    var iTop  = e.clientY - deltaY;
    if (iLeft < iPageScrollLeft){
      iLeft = iPageScrollLeft;
    }else if ((iLeft + oEl.offsetWidth) >= (iPageScrollLeft + iPageInnerWidth)){
      iLeft = iPageScrollLeft + iPageInnerWidth - oEl.offsetWidth;
    }else if (iLeft < 0){
      iLeft = 0;
    }else if ((iLeft + oEl.offsetWidth) >= iPageWidth){
      iLeft = iPageWidth - oEl.offsetWidth;
    }
    if (bGhosted){
      if (iTop < iPageScrollTop){
        iTop = iPageScrollTop;
      }else if ((iTop + iHeadHeight) >= (iPageScrollTop + iPageInnerHeight)){
        iTop = iPageScrollTop + iPageInnerHeight - iHeadHeight;
      }else if (iTop < 0){
        iTop = 0;
      }else if ((iTop + oEl.offsetHeight) >= iPageHeight){
        iTop = iPageHeight - oEl.offsetHeight;
      }
    }else{
      if (iTop < 0){
        iTop = 0;
      }
    }
    oEl.style.left  = (iLeft) + "px";
    oEl.style.right = '';
    oEl.style.top   = (iTop) + "px";
    if (e.stopPropagation){
      e.stopPropagation();
    }else{
      e.cancelBubble = true;
    }
  }
  function dialogUpHandler(e){
    if (!e) {
      e = window.event;
    }
    if (document.removeEventListener){
      document.removeEventListener("mouseup", dialogUpHandler, true);
      document.removeEventListener("mousemove", dialogMoveHandler, true);
    }else if (document.detachEvent){
      oEl.detachEvent("onlosecapture", dialogUpHandler);
      oEl.detachEvent("onmouseup", dialogUpHandler);
      oEl.detachEvent("onmousemove", dialogMoveHandler);
      oEl.releaseCapture();
    }
    if (e.stopPropagation){
      e.stopPropagation();
    }else{
      e.cancelBubble = true;
    }
  }
}
bfDialog.getParent = function(oSrc){
  var oDialog = oSrc;
  while (oDialog != null && (oDialog.id == null || oDialog.id.substr(0,7) != '_dialog')){
    oDialog = oDialog.parentNode;
  }
  return oDialog;
}
bfDialog.sub = {};
bfDialog.sub.show = function(bDisplay,sDialog,bResize,sDisplayMode,xOnClose){
  var bResize = (typeof(bResize) != 'undefined') ? bResize : 1;
  var fctOnClose = (typeof(xOnClose) == 'string') ? new Function('sDialog',xOnClose) : ((typeof(xOnClose) == 'function') ? xOnClose : function(){return 1});
  if (typeof(bfDialog.hDialog[sDialog]) == 'undefined'){
    var sParent = sActDialog;
    var oParent = document.getElementById('_dialog'+sActDialogSuf);
    var sDisplayMode = sDisplayMode || 'dialog';
    bfDialog.hDialog[sDialog] = {
      'name':    sDialog,
      'parent':  sParent,
      'childs':  [],
      'visible': bDisplay,
      'id':      '_dialog'+(sDialog ? '_'+sDialog : ''),
      'mode':    sDisplayMode,
      'onClose': fctOnClose
    };
    var oDialog = document.getElementById(bfDialog.hDialog[sDialog]['id']);
    bfDialog.hDialog[sDialog]['oDlg'] = oDialog;
    bfDialog.addChild(sParent,sDialog);
  }else{
    var oDialog = bfDialog.hDialog[sDialog]['oDlg'];
    var sParent = bfDialog.hDialog[sDialog]['parent'];
    var oParent = bfDialog.hDialog[sParent]['oDlg'];
    if (typeof(sDisplayMode) == 'undefined'){
      var sDisplayMode = bfDialog.hDialog[sDialog]['mode'];
    }
  }
  var bWidget = (typeof(sDisplayMode) == 'string' && sDisplayMode == 'widget') ? 1 : 0;
  bfDialog.show(bDisplay,sDialog,sDisplayMode);
  if (!bWidget){
    bfDialog.disable(sParent);
  }
  if (bDisplay){
    if (typeof(oDialog.style) == 'undefined' || typeof(oDialog.style.zIndex) == 'undefined'){
      oDialog.style.zIndex = 2;
    }
    if (!bWidget){
      oDialog.style.top = (oParent.offsetTop+20)+'px';
      oDialog.style.left = (oParent.offsetLeft+25)+'px';
    }
    if (bResize){
      oDialog.style.width = (oParent.offsetWidth-100)+'px';
    }
    var aoScroll = bfPage.getElementsByClassName(oDialog,'scroll');
    if (aoScroll.length){
      for (var i=0;i<aoScroll.length;i++){
        aoScroll[i].style.width = oDialog.style.width;
        bfPage.fixHScroll(aoScroll[i]);
      }
    }
  }
}
bfDialog.sub.close = function(sDialog){
  bfDialog.show(0,sDialog);
}

-->
