﻿function getKeyPressedCode(e) 
{
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	return code;
}

jQuery.fn.center = function(absolute) {
	return this.each(function() {
		var t = jQuery(this);

		t.css({
			position: absolute ? 'absolute' : 'fixed',
			left: '50%',
			top: '50%'
		}).css({
			marginLeft: '-' + (t.outerWidth() / 2) + 'px',
			marginTop: '-' + (t.outerHeight() / 2) + 'px'
		});

		if (absolute) {
			t.css({
				marginTop: parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(),
				marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
			});
		}
	});
};

jQuery.fn.mgxModalShow = function() {
	var t = jQuery(this);
	t.center(badBrowser());
	t.css({
		zIndex: '50000'
	});
	t.show();
	var ediv = $("<div></div>");
	$(ediv).css({
		position: badBrowser() ? 'absolute' : 'fixed',
		top: '0',
		left: '0',
		width: '100%',
		height: '100%',
		zIndex: '49999'
	}).addClass("modalBackground");
	$(document.body).append($(ediv));
}

jQuery.fn.mgxModalHide = function() {
	var t = jQuery(this);
	t.hide();
	$(".modalBackground").hide();
}

function badBrowser() {
	if ($.browser.msie && parseInt($.browser.version) <= 6)
	{ return true; }
	return false;
}