/*
This file is part of pDAF.
Copyright (c) 2005-2010 by Gregorcic & Helger IT systems OEG.
All rights reserved.
http://www.phloc.com
 */
  
// FIXME: this has a dependency to app-config/phloc-config-toolbar.js
function pdafRemoveNodeAfterTimeout(sID, nWait) {
  window.setTimeout("jphloc.removeNodeByID('" + sID + "');pdaf_onScreenResize();", nWait); 
}

// constructor
function pDAFUIExtClass() {
  this.m_nMinWaitingTime = 700;
  this.m_nImmediateWaitingTime = 200;
  this.m_nModalDialogHeight = 250;
  this.m_nModalDialogWidth = 350;
  this.m_bProgress = false;
}

pDAFUIExtClass.prototype = {
  startProgress : function(sMsg) {
    if (sMsg && sMsg != "") {
      this.m_bProgress = true;  
      window.setTimeout("pDAFUIExt._startProgressInternal('" + jphloc.escapeLinebreaks(jphloc.escapeLiteral(sMsg)) + "')", this.m_nMinWaitingTime);
    }
  },
  
  startProgressNow : function(sMsg) {
    if (sMsg && sMsg != "") {
      this.m_bProgress = true;  
      window.setTimeout("pDAFUIExt._startProgressInternal('" + jphloc.escapeLinebreaks(jphloc.escapeLiteral(sMsg)) + "')", this.m_nImmediateWaitingTime);
    }
  },
  
  modalPopup : function(sXHTML, sCloseMsg, nWidth, nHeight) {
    if (sXHTML && sXHTML != "") {
      var aContainer = document.createElement("div");
      aContainer.innerHTML = sXHTML;
      $.modal(aContainer, {minHeight: nHeight,
                           minWidth: nWidth,
                           closeHTML: "<a class=\"modalCloseImg simplemodal-close\" title=\"" + sCloseMsg + "\"/>"});    
    }
  },
  
  _startProgressInternal : function(sMsg) {
    if (this.m_bProgress) {
      var aContainer = document.createElement("div");
      aContainer.setAttribute("id", "modal_progress");
      var aTable = document.createElement("table");
      var aTBody = document.createElement("tbody");
      aTable.appendChild(aTBody);
      aContainer.appendChild(aTable);
      var aRow = document.createElement("tr");
      aTBody.appendChild(aRow);
      var aCellIndicator = document.createElement("td");
      aRow.appendChild(aCellIndicator);
      var aCellMessage = document.createElement("td");
      aRow.appendChild(aCellMessage);
      jphloc.addClass(aCellIndicator, "pdaf_progress_indicator");
      jphloc.addClass(aCellMessage, "pdaf_progress_info");
      jphloc.appendTextWithBR(aCellMessage, sMsg);
      $.modal(aContainer, {minHeight: 30,
                           maxHeight: this.m_nModalDialogHeight,
                           minWidth: 200,
                           maxWidth: this.m_nModalDialogWidth,
                           closeHTML: ''});
    }
  },  
  
  stopProgress : function () {
    if (this.m_bProgress) {
      $.modal.close();
    }
    this.m_bProgress = false;
  }
}

var pDAFUIExt = window.pDAFUIExt = new pDAFUIExtClass();