﻿// JScript File
function associateWithEvent(obj, methodName) {
	return (function(e) {
		 e = e || window.event;
		 e = e ? e : null;
		 return obj[methodName](e, this);
	} );
}

function msjs_errorDialog() {
  this.scrollDirection = 0;
  this.OverlayBackgroundColor = "#333333";
  this.OverlayOpacity = 60;
  this.prefix = "msjs_error_dialog_";
  this.divOverlay = null;
  this.divConfirmer = null;
  this.blnFoundBody = false;
  this.outputObject = null;
  this.errLabel = null;
  var instance = this;

  var div = $('<div id="' + this.prefix + '"overlay" style="position:absolute;top:100px;left:100px;width:300px;height:300px;z-index:9998;background-color:' + this.OverlayBackgroundColor + ';opacity:' + (this.OverlayOpacity / 100) + ';alpha(opacity=' + this.OverlayOpacity + ');">&nbsp;</div>');
  
  $('body').append(div);

  this.divOverlay = div;
  div.hide();

  var divConf = $('<div id="' + this.prefix + 'confirmer" style="position:absolute;top:150px;left:150px;width:400px;height:150px;display:none;border:solid 1px #000000;background: #ffffff url(\'img/conf_bg_error.jpg\') no-repeat bottom right;padding:20px;cursor:pointer;z-index:9999;">&nbsp;</div>');

  $('body').append(divConf);

  this.divConfirmer = divConf;
  this.divConfirmer.onclick = associateWithEvent(this, "hide");
  	
	var label = $('<div style="font-size:18px;"></div>');
	this.errLabel = label;
	this.divConfirmer.append(label);

	this.show = function (showWhat) {
		var scrollTop = document.documentElement.scrollTop;
		this.errLabel.html(showWhat);

		this.divOverlay.show().width($(window).width()).height($(window).height()).css('top', '0px').css('left', '0px');
		this.divConfirmer.show();

		this.divConfirmer.css('left', (($(window).width() - this.divConfirmer.width()) / 2) + "px");
		this.divConfirmer.css('top', (($(window).height() - this.divConfirmer.height()) / 2) + "px").css('z-index', 9999);
		$(document).css('overflow', 'hidden');

		setTimeout("window.scroll(0, " + scrollTop + ");", 50);
	}
	
	this.hide = function(instance) {
		$(document).css('overflow', 'auto');
		instance.divOverlay.hide();
		instance.divConfirmer.hide();
	}
	
	this.keyup = function(event) {
		var evt = event || window.event;
		if(evt.keyCode == 27) { // escape key
			this.hide(this);
		}
	}

	$(this.divConfirmer).click(function () {
		instance.hide(instance);
	});

	$(document).keyup(function (event) {
		var evt = event || window.event;
		if (evt.keyCode == 27) // escape key
			instance.hide(instance);
	});
}
