/**
 *  Javascript do zastapienia komendy alert na AlertBox w MULTIOPAC'u
 *
 *  Data utworzenia: 07.08.2008 
 */    
YAHOO.namespace("alertbox");

/* inicjalizacja */
function initAlertBox(btnName,fn,WH)
{  
  if(typeof(fn) == "function") {  
    var handleCloseAlert = fn;
  }else{
    /* uchwyt do przycisku */
    var handleCloseAlert = function() {
      this.cancel();
    };
  }
  if(typeof(YAHOO.alertbox.alertbox)== "object"){
  var abButtons = [ { text: btnName, handler:handleCloseAlert }]
   YAHOO.alertbox.alertbox.cfg.queueProperty("buttons", abButtons);    
  }else{
    YAHOO.alertbox.alertbox = new YAHOO.widget.SimpleDialog("alertbox", 
      { width : (WH ? WH: "30em"),
        fixedcenter : true, 
        modal : true,
        visible : false,         
        constraintoviewport : true,
        buttons : [ { text: btnName, handler:handleCloseAlert }]
      });
      
    } 
    YAHOO.alertbox.alertbox.render();
}

/* --- AlertBox --- 
 *  header - tresc naglowka
 *  message - tresc komunikatu
 *  btnName - nazwa przycisku
 *  go_function - funckja wywolywane po zamknieciu okienka
 *  WH - szerokosc okienka  
 */

function canc(){YAHOO.alertbox.alertbox.hide();} 
 
function AlertBox(header, message, btnName, go_function,WH)
{
  initAlertBox(btnName,go_function,WH);
  /* dodanie naglowka */
  YAHOO.alertbox.alertbox.setHeader(header);
  /* dodanie tresci komunikatu */
  YAHOO.alertbox.alertbox.setBody(message);
  YAHOO.alertbox.alertbox.cfg.queueProperty("close", true);
  
  /* renderowanie */
  YAHOO.alertbox.alertbox.show();
  
  YAHOO.util.Event.addListener(YAHOO.alertbox.alertbox.close, 'click',go_function);
  YAHOO.util.Event.addListener(YAHOO.alertbox.alertbox.firstButton, 'click',canc );
}

/*****************************************************************************
 *  Javascript do obslugi okienka QUESTIONBOX
 */ 
 
YAHOO.namespace("questionbox");

/* inicjalizacja */
function initQuestionBox(btnName1, btnName2, fn, fn2)
{   
    var handlePositive = fn;
    if(typeof(fn2) == "function"){
        var handleNegative = fn2
      }else{
        var handleNegative = function(){
        this.cancel();
      }
      };

  if(typeof(YAHOO.questionbox.questionbox)== "object"){
    var qbButtons = [ { text: btnName1, handler:handlePositive },
                  { text: btnName2, handler:handleNegative }]
       YAHOO.questionbox.questionbox.cfg.queueProperty("buttons", qbButtons);
       
      
  }else{

  YAHOO.questionbox.questionbox = new YAHOO.widget.SimpleDialog("questionbox", 
    { width : "390px",
      fixedcenter : true, 
      modal : true,
      visible : false,
      
      constraintoviewport : true,
      buttons : [ { text: btnName1, handler:handlePositive },
                  { text: btnName2, handler:handleNegative }]
    });
    
     
    }   
    YAHOO.questionbox.questionbox.render(); 
}

/* --- QuestionBox --- 
 *  header - tresc naglowka
 *  message - tresc komunikatu
 *  btnName1 - nazwa 1 przycisku (positive)
 *  btnName2 - nazwa 2 przycisku (negative)
 */
function questCanc(){YAHOO.questionbox.questionbox.cancel();  } 
function questionBox(header, message, btnName1, btnName2, go_function, go_function2)
{
  initQuestionBox(btnName1, btnName2, go_function, go_function2);
  /* dodanie naglowka */
  YAHOO.questionbox.questionbox.setHeader(header);
  /* dodanie tresci komunikatu */
  YAHOO.questionbox.questionbox.setBody(message);  
  /* renderowanie */   
  YAHOO.questionbox.questionbox.show();
  
  YAHOO.util.Event.addListener(YAHOO.questionbox.questionbox, 'click',questCanc);
  YAHOO.util.Event.addListener(YAHOO.questionbox.questionbox.firstButton, 'click', questCanc);
   if(typeof(go_function2) == "function"){
     YAHOO.util.Event.addListener(YAHOO.questionbox.questionbox.lastButton, 'click', questCanc);
  }
}

/*****************************************************************************
 *  Javascript do obslugi okienka QUESTIONBOX
 */ 

YAHOO.namespace("loadingbox");

/* inicjalizacja */
function initLoadingboxBox()
{   
  YAHOO.loadingbox.loadingbox = new YAHOO.widget.SimpleDialog("loadingbox", 
    { width : "390px",
      fixedcenter : true, 
      modal : true,
      visible : false,
      close : false,      
      constraintoviewport : true
    });
       
  YAHOO.loadingbox.loadingbox.render(); 
}

/* --- LoadingboxBox --- 
 */ 
function loadingboxBox()
{
  isModalOpen = true;  
  initLoadingboxBox();
  /* dodanie tresci komunikatu */
  /*YAHOO.loadingbox.loadingbox.setBody('<img src=\"\/MultiOpac\/prolib\/loader-black.gif\" width=\"16\" height=\"16\" /> Aktualizacja danych...');*/
  document.getElementById('loadcontent').innerHTML = "Aktualizacja danych. Proszę czekać...<br /><img src='/MultiOpac/prolib/img/loader-black.gif' width='16' height='16' />";  
  /* renderowanie */   
  YAHOO.loadingbox.loadingbox.show();
}

function loadingboxWaiting()
{
  isModalOpen = true;  
  initLoadingboxBox();
  /* dodanie tresci komunikatu */
  /*YAHOO.loadingbox.loadingbox.setBody('<img src=\"\/MultiOpac\/prolib\/loader-black.gif\" width=\"16\" height=\"16\" /> Aktualizacja danych...');*/
  document.getElementById('loadcontent').innerHTML = "Trwa oczekiwanie na wyniki. Proszę czekać...<br /><img src='/MultiOpac/prolib/img/loader-black.gif' width='16' height='16' />";  
  /* renderowanie */   
  YAHOO.loadingbox.loadingbox.show();
}
