﻿/*
 * PopupController.js: Utilities for popups (that are not handled with AJAX-extensions of ASP.NET).
 */

 /*
  * Constructs a new PopupController.
  */
function PopupController() {
  this.show = function(popupID) {
    var popup = document.getElementById(popupID);
    if (popup) {
      var height = 0;
      if (typeof(window.innerWidth) == 'number') {
        height = window.innerHeight;
      } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        height = document.documentElement.clientHeight;
      } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
        height = document.body.clientHeight;
      }      
      
      var yOffset = 0;
      if (self.pageYOffset){
        yOffset = self.pageYOffset;
      } else if (document.documentElement && document.documentElement.scrollTop) {
        yOffset = document.documentElement.scrollTop;
      } else if (document.body){ 
        yOffset = document.body.scrollTop;
      }
      
      var top = (height / 2 + yOffset) - (popup.clientHeight / 2);
      
      popup.style.top = top + 'px';
      popup.style.visibility = 'visible';
    }
  }

  this.hide = function(popupID) {
    var popup = document.getElementById(popupID);
    if (popup) {
      popup.style.visibility = 'hidden';
    }
  }
  
  this.showPopupWindow = function(url) {
    popupCentered(url, 'popup', 640, 600);
  }
}

var popupController = new PopupController();

