﻿var yPos = 0;
var xPos = 0;
var attachToObj = document.createElement("div");
var div = document.createElement("div");
var divWidth = 0;
var divHeight = 0;

var inlineObj = function(w, h, path, file, params, obj) {
    var url = "/_popups/";
    showAllSelects();
    divWidth = w;
    divHeight = h;
    if (path != '') {
        url = "/" + path + "/_popups/" + file + "?" + params;
    }
    else {
        url = "/_popups/" + file + "?" + params;
    }
    attachToObj = obj;
    $.ajax({ type: "GET", url: url, data: "{}", contentType: "application/x-www-form-urlencoded;", dataType: "html",
        success: function(e) {
            return renderInline(e);
        }
    });
}

$.inlineObjPost = function(url, data) {
    $.ajax({ type: "POST", url: url, data: data, contentType: "application/x-www-form-urlencoded;", dataType: "html",
        success: function(e) {
            return renderInline(e);
        }
    });
}

function renderInline(response) {
    response = replaceChars(response, '&lt;', '<');
    response = replaceChars(response, '&gt;', '>');
    response = replaceChars(response, '&amp;', '&');

    if (response.length != 0) {
        yPos = getTop(document.getElementById(attachToObj)) - 150;
        xPos = getLeft(document.getElementById(attachToObj)) - 50;
        if (yPos <= 0) {
            yPos = yPos + 100;
        }
        hideAllSelects();

        div.style.cssText = "z-Index:100;left:" + xPos + "px;" + "top:" + yPos + "px" + ";position:absolute;width:" + divWidth + "px;height:" + divHeight;
        div.innerHTML = response;
        document.body.appendChild(div);
    }
}

function escKey(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    if (evt.keyCode == 27) {
        hideDiv()
    }
}
document.onkeypress = escKey;

if (IE) {
    document.onclick = function() {
        if (document.getElementById(attachToObj) != null) {
            thisX = event.clientX + document.body.scrollLeft;
            if (thisX < xPos || thisX > (xPos + divWidth)) {
                hideDiv();
            }
        }
    };
}
else {
    document.onclick = function(e) {
        if (document.getElementById(attachToObj) != null) {
            thisX = e.pageX;
            if (thisX < xPos || thisX > (xPos + divWidth)) {
                hideDiv();
            }
        }
    }
}