/*
This file is part of pDAF.
Copyright (c) 2005-2008 by Gregorcic & Helger IT systems OEG.
All rights reserved.
http://www.phloc.com
 */


// constructor
//========================================================
function pDAFUIExtClass() 
//========================================================
{
  this.m_nMinWaitingTime = 700;
  this.m_nImmediateWaitingTime = 200;
  this.m_nModalDialogHeight = 50;
  this.m_nModalDialogWidth = 300;
  this.m_bProgress = false;
}

//========================================================
pDAFUIExtClass.prototype = 
//========================================================
{
    
  //------------------------------------------------------
  startProgress : function(sMsg) 
  //------------------------------------------------------
  {
    if (sMsg && sMsg != "")
    {
      this.m_bProgress = true;  
      window.setTimeout("pDAFUIExt._startProgressInternal('" + sMsg + "')", this.m_nMinWaitingTime);
    }
  },
  
  //------------------------------------------------------
  startProgressNow : function(sMsg) 
  //------------------------------------------------------
  {
    if (sMsg && sMsg != "")
    {
      this.m_bProgress = true;  
      window.setTimeout("pDAFUIExt._startProgressInternal('" + 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");
      aCellMessage.appendChild(document.createTextNode(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();