﻿var windowObjectReference;

function AbrirPopupMaximizado(url, target, features) {
    var width, height, left, top;

    if (typeof window.screenX == "number" && typeof screen.availWidth == "number") {
        width = screen.availWidth;
        height = screen.availHeight;
        left = window.screenX + width;
        top = window.screenY + height;
    }
    else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
        width = document.documentElement.offsetWidth;
        height = document.documentElement.offsetHeight;
        left = window.screenLeft + width;
        top = window.screenTop - 5;
    }
    else {
        width = 800;
        height = 600;
        left = 10;
        top = 10;
    };

    AbrirPopup(url, target, top, left, width, height, features);
}

function AbrirPopupCentralizado(url, target, width, height, features) {
    var left, top;

    if (typeof window.screenX == "number" && typeof screen.availWidth == "number") {
        left = (screen.availWidth - (window.screenX + width)) / 2;
        top = (screen.availHeight - (window.screenY + height)) / 2;
    }
    else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
        left = (screen.availWidth - (window.screenLeft + width)) / 2;
        top = window.screenTop - 5;
    }
    else {
        left = 10;
        top = 10;
    };

    AbrirPopup(url, target, top, left, width, height, features);
}

function AbrirPopup(url, target, top, left, width, height, features) {
    var aux;
    if (!features) {
        features = "";
        aux = "menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,status=0";
    }
    
    features += "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + "," + aux;

    if (windowObjectReference != null && !windowObjectReference.closed && windowObjectReference.name == target) {
        windowObjectReference.focus();
    }
    else {
        windowObjectReference = window.open(url, target, features);
    };
    /*if (windowObjectReference == null || windowObjectReference.closed) {
    windowObjectReference = window.open(url, target, features);
    }
    else {
    windowObjectReference.focus();
    };*/
}
