var wizardWindow;
var wizardTimer;
var helpWindow;
var dialogWindow;
var printWindow;

function showDialog(divId, dialogTitle, url) {
	$("#" + divId).load(url);
	$("#" + divId).dialog({
		modal: true,
		resizable: false,
		minWidth: 800,
		title: dialogTitle,
		buttons: { 
			"Close": function() { 
				$(this).dialog("close"); 
			} 
		} 
	});
}

function showParentWindow(url) {
	window.opener.location.replace(url);
}

function showHelpWindow(url) {
    helpWindow=window.open(url,
            "APIR_HELP",
            "menubar=no,scrollbars=yes,width=800,height=600,"
            + "top=0,left=" + (screen.width - 800)
            + ",status=no,resizable=yes");
    helpWindow.focus();
}

function showDialogWindow(url) {
    if (dialogWindow == null || dialogWindow.closed) {
        dialogWindow = window.open(url,
                "",
                "menubar=no,scrollbars=yes,width=1024,height=768,"
                + "top=" + ((screen.height - 768) / 2)
                + ",left=" + ((screen.width - 1024) / 2)
                + ",status=no,resizable=yes");
    } else if (!dialogWindow.closed) {
        alert("Dialog box already open.  The content in the dialog box will not be changed.");
    }
    dialogWindow.focus();
}

function showSmallDialogWindow(url) {
    if (dialogWindow == null || dialogWindow.closed) {
        dialogWindow = window.open(url,
                "",
                "menubar=no,scrollbars=yes,width=680,height=480,"
                + "top=" + ((screen.height - 480) / 2)
                + ",left=" + ((screen.width - 680) / 2)
                + ",status=no,resizable=yes");
    } else if (!dialogWindow.closed) {
        alert("Dialog box already open.  The content in the dialog box will not be changed.");
    }
    dialogWindow.focus();
}

function showPopupWindow(url) {
    popupWindow=window.open(url,
            "APIR_POPUP",
            "menubar=no,scrollbars=yes,width=800,height=600,"
            + "left=0,top=" + (screen.height - 600)
            + ",status=no,resizable=yes");
    popupWindow.focus();
}

function isWizardOpen() {
    var f = true;
    if (wizardWindow == null || wizardWindow.closed) {
        f = false;
    }
    return f;
}

function showWizardWindow(url) {
    if (!isWizardOpen()) {
        wizardWindow=window.open(url,
                "APIR_WIZARD",
                "menubar=no,scrollbars=yes,width=900,height=700,"
                + "top=" + ((screen.height - 600) / 2)
                + ",left=" + ((screen.width - 800) / 2)
                + ",status=no,resizable=yes");
        wizardWindow.focus();
    } else {
        alert("Window is already active!");
        wizardWindow.focus();
    }
}


function showPrintWindow(url) {
    printWindow=window.open(url,
            "APIR_PRINT",
            "menubar=no,scrollbars=yes,width=800,height=600,"
            + "left=0,top=0,resizable=yes"
            + ",status=no");
    printWindow.focus();
}

function checkPopup() {
    if (wizardWindow != null && !wizardWindow.closed) {
        wizardWindow.opener.blur();
        wizardWindow.focus();
    }
}

function submitWizardWindow(form) {
    if (!isWizardOpen()) {
        showWizardWindow("");
        form.submit();
    }
}

function showABNPopupWindow(abn) {
    showPopupWindow("http://www.abr.business.gov.au/SearchByAbn.aspx?SearchText=" + abn);
}

function showSFNPopupWindow(sfn) {
    showPopupWindow("/public/formSubmitter.jsp?url=http://www.ato.gov.au/super/scripts/search.asp?sid=42&action=Search&state=&searchtype=sfnumber&queryvalue=" + sfn);
}

function showRSENumberPopupWindow(rse) {
    showPopupWindow("http://www.apra.gov.au/RSE/Pages/RSEResults.aspx?abn=&rnum=" + rse);
}

function showRSELicenceNumberPopupWindow(rse) {
    showPopupWindow("http://www.apra.gov.au/rse/Pages/LicenseeResults.aspx?abn=&rnum=" + rse);
}

function showASICLicenceNumberPopupWindow(n) {
    showPopupWindow("http://www.search.asic.gov.au/cgi-bin/gfs010c?origin=flb&licence_no=" + n + "&role_type=FK&cond_sdate=&cond_stime=&rep_no=");
}

function showASICPopupWindow(n) {
    showPopupWindow("http://www.search.asic.gov.au/cgi-bin/gfs010c?origin=far&licence_no=" + n + "&role_type=FC&cond_sdate=&cond_stime=&rep_no=");
}

