/**
 * This class is used to open mock dialog.
 */
Dialog = function() {

  var dialogX;
  var dialogY;
  var dialogWidth;
  var dialogHeight;

  /**
   * Gets the location of DIV which is will be display.
   */
  var getDialogLocation = function() {
    var windowWidth, windowHeight, pageX, pageY;
    var docElement = document.documentElement;

    if (window.innerWidth) {
      windowWidth = window.innerWidth;
      windowHeight = window.innerHeight;
      pageX = window.pageXOffset;
      pageY = window.pageYOffset;
    } else {
      windowWidth = docElement.offsetWidth;
      windowHeight = docElement.offsetHeight;
      pageX = docElement.scrollLeft;
      pageY = docElement.scrollTop;
    }
    dialogX = (pageX + ((windowWidth - dialogWidth) / 2));
    dialogY = (pageY + ((windowHeight - dialogHeight) / 2));
  }

  /**
   * This method is used to show the dialog which can be set location and size by user.
   */
  this.showDialog = function(showContent, offsetWidth, offsetHeigth, width, height) {
    convertScreen();
    var objDialog = document.getElementById("dialog");

    if (!objDialog) {
      objDialog = document.createElement("div");
    }
    objDialog.innerHTML = showContent;

    dialogWidth = width;
    dialogHeight = height;
    getDialogLocation();
    objDialog.id = "dialog";

    var objDialogStyle = objDialog.style;
    objDialogStyle.display = "block";
    objDialogStyle.top = dialogY + "px";
    objDialogStyle.left = dialogX + "px";
    objDialogStyle.width = width + "px";
    objDialogStyle.height = height + "px";
    objDialogStyle.margin = "0px";
    objDialogStyle.padding = "0px";
    objDialogStyle.position = "absolute";
    objDialogStyle.zIndex = "5";
    objDialogStyle.background = "#FFFFFF";
    objDialogStyle.border = "solid #000000 1px";
    objDialogStyle.color = "#000000";

    document.body.appendChild(objDialog);
  }

  /**
   * This method is used to make transparent DIV converts the whole screen.
   */
  var convertScreen = function() {
    var objScreen = document.getElementById("ScreenOver");

    if (!objScreen) {
      objScreen = document.createElement("div");
    }
    objScreen.id = "ScreenOver";

    var objScreenStyle = objScreen.style;
    objScreenStyle.display = "block";
    objScreenStyle.top = "0px";
    objScreenStyle.left = "0px";
    objScreenStyle.margin = "0px";
    objScreenStyle.padding = "20px";
    objScreenStyle.paddingTop  = "0px";
    objScreenStyle.paddingLeft  = "0px";
    objScreenStyle.paddingRight  = "0px";

    var windowHeight;

    if (document.body.clientHeight) {
      windowHeight = document.body.clientHeight + "px";
    } else if (window.innerHeight) {
      windowHeight = window.innerHeight + "px";
    } else {
      windowHeight = "100%";
    }

    objScreenStyle.width = "100%";
    objScreenStyle.height = windowHeight;
    objScreenStyle.position = "absolute";
    objScreenStyle.zIndex = "3";
    objScreenStyle.background = "#CCCCCC";
    objScreenStyle.filter = "alpha(opacity=50)";
    objScreenStyle.opacity = 40/100;
    objScreenStyle.MozOpacity = 40/100;

    document.body.appendChild(objScreen);
  }

  /**
   * This method is used to clean the convert screen DIV.
   */
  var cleanScreen = function() {
    var objScreen = document.getElementById("ScreenOver");

    if (objScreen) {
      objScreen.style.display = "none";
    }
  }

  /**
   * This method is used to hide the dialog.
   */
  this.hideDialog = function() {
    cleanScreen();
    var objDialog = document.getElementById("dialog");

    if (objDialog) {
      objDialog.style.display = "none";
    }
  }
}