﻿var ModalPopup = function(body, mask, textCapture, isPostPage) {
    var _mask = mask;
    var _body = body;
    var _textCapture = textCapture;
    var _isPostPage = isPostPage;

    var get = function(id) {
        return document.getElementById(id);
    };

    var getBrowserWidthHeight = function() {
        var intH = 0;
        var intW = 0;
        intH = $(document).height();
        intW = $(document).width();

        return { width: parseInt(intW), height: parseInt(intH) };
    };

    var mask = get(_mask);
    var body = get(_body);
    var textArea = get(_textCapture);

    var show = function(el) { el.style.display = 'block'; }
    var hide = function(el) { el.style.display = 'none'; }
    var setX = function(el, x) { el.style.left = x + "px"; }
    var setY = function(el, y) { el.style.top = y + "px"; }

    var _text = '';

    return {


        PostComment: function() {
            textArea.value = _text;

            var bWidthHeight = getBrowserWidthHeight();
            mask.style.width = bWidthHeight.width + "px";
            mask.style.height = bWidthHeight.height + "px";

            show(mask);
            show(body);

            var x = 0;
            if (_isPostPage) {
                x = (mask.offsetWidth - body.offsetWidth) / 2;
            }

            var y = 180 + document.documentElement.scrollTop;

            setX(body, x);
            setY(body, y);
        }

		, CommitChanges: function() {
		    _text = textArea.value;

		    textArea.value = '';
		    this.CancelComment();

		    return _text;
		}

		, CancelComment: function() {
		    hide(mask);
		    hide(body);
		}

		, GetText: function() {
		    return _text;
		}

		, SetText: function(text) {
		    _text = text;
		}
    }
};