﻿

function OpenWindow(url) {
    var args = OpenWindow.arguments;  //make an array out of the arguments passed to the function
    if (args.length > 1) {
        x = args[1];
        y = args[2];
    }
    else {
        x = 720;
        y = 540;
    }
    window.open(url, '', 'status=0,width=' + x + ',height=' + y + ',toolbar=yes,menubar=no,location=no,resizable=yes,scrollbars=1');
}

function RefreshCaller(url) {
    if (opener.closed) {
        alert('The Main window was closed.  You will have to re-open this dialog to continue.');
    }
    else {
        opener.location = url
        self.close();
    }
}

function RefreshCaller1(paramName, paramValue) {
    // This strips out the old querystring and adds some new parameters to it.
    rawUrl = opener.location.toString();
    pageIndex = rawUrl.lastIndexOf(".aspx") + 5;
    url = rawUrl.replace(rawUrl.substring(pageIndex), "");

    if (opener.closed) {
        alert('The Main window was closed.  You will have to re-open this dialog to continue.');
    }
    else {
        opener.location = url + '?' + paramName + '=' + paramValue
        self.close();
    }
}

function RefreshCaller2(paramName1, paramValue1, paramName2, paramValue2) {
    // This strips out the old querystring and adds some new parameters to it.
    rawUrl = opener.location.toString();
    pageIndex = rawUrl.lastIndexOf(".aspx") + 5;
    url = rawUrl.replace(rawUrl.substring(pageIndex), "");

    if (opener.closed) {
        alert('The Main window was closed.  You will have to re-open this dialog to continue.');
    }
    else {
        var querystring = '?' + paramName1 + '=' + paramValue1 + '&amp;' + paramName2 + '=' + paramValue2;
        opener.location = url + querystring;
        self.close();
    }
}

function ClearFormWithAlert() {
    rawUrl = self.location.toString();
    pageIndex = rawUrl.lastIndexOf(".aspx") + 5;
    url = rawUrl.replace(rawUrl.substring(pageIndex), "");
    t = confirm("This will clear your current form, and any unsaved changes will be lost.\n\nIf you have saved your changes, click OK, otherwise click Cancel.")
    if (!t) {
        return false;
    }
    self.location = url
}

function PrintPage() {
    if (window.print) {
        window.print();
    }
    else {
        if (agt.indexOf("mac") != -1)
            alert("To print this page press Command-P.");
        else
            alert("To print this page press Control-P.");
    }
}

function Redirect(url) {
    window.location = url;
}

// Work around for setting focus in Mozilla
function setFocus(id) {
    var field = document.getElementById(id);
    if (field) {
        field.focus(); // May throw "Permission denied" (uncatchable)
    }
    else {
        alert('unknown element id ' + id);
    }
}