﻿/* 
Window Launcher for Cairns Regional Council.
Author: Nathan McCarthy, October 2008.
    
    Use a HTML element's "onclick" event handler to launch the window.
    
    There are three parameters:
    
        1: window size: 'reg', 'large', or 'auto'.
        2: work context: Any valid work context. Specifying an invalid context appears to just load with the default.
        3: (optional) URL: pre-pends the url to the launcher to allow launching from other web locations
    
    Examples of basic links follow:
    
        <a href="#" onclick="javascript:launch_window();">
            Launches a window without specifying the size or the work context. A basic 'online maps' link.
        </a>

        <a href="#" onclick="javascript:launch_window('reg');">
            Launches a regular sized window without specifying context.
        </a>

        <a href="#" onclick="javascript:launch_window('large', 'Aerial Imagery');">
            Launches a large-sized window using the Aerial Imagery work context.
        </a>

*/
// These constants may be edited to control the output
var titleBar = 'no';
var scrollBars = 'no';
var statusBar = 'no';
var toolbar = 'no';
var menuBar = 'no';
var locationBar = 'no';
var resizable = 'no';
var context = '';

var targetPageReg = "CairnsMapping.aspx";
var targetPageLarge = "CairnsMapping_Large.aspx";

var widthReg = '940';
var heightReg = '670';
var widthLarge = '1200';
var heightLarge = '880';


// Default to basic values for the regular window.
var width = widthReg;
var height = heightReg;
var targetPage = "CairnsMapping.aspx";

var windowName = '_reg';

function launch_window(size, context, targetURL) {

    // Try for the large size. If it fauls or is smaller, then the reg values will be used.
    
    if (size == null || size == "auto") {
        size = "reg";
        try {
            if (screen.width >= 1280 ) {
                size = "large";
            }
        } catch (error) { }        
    }
    
    if (size == "reg") {
        width = widthReg;
        height = heightReg;
        windowName = "_reg";
        targetPage = targetPageReg;
    }

    if (size == "large") {
        width = widthLarge;
        height = heightLarge;
        windowName = "_large";
        targetPage = targetPageLarge;
    }

    if (targetURL == null) 
    {
	targetURL="";
    }

    window.open( targetURL + "PublicInvoker.aspx?Context=" + context + "&Page=" + targetPage, windowName, GetWindowFeatures());
}

function GetWindowFeatures() {
    retval = "";
    if (screen.width < width || screen.height < height) {
        retval = "scrollbars=1,titlebar=" + titleBar + ",status=" + statusBar + ",toolbar=" + toolbar + ",menubar=" + menuBar + ",location=" + location + ", resizable=" + resizable + ", width=" + width + ", height=" + height;
    }
    else {
        retval = "scrollbars=" + scrollBars + ",titlebar=" + titleBar + ",status=" + statusBar + ",toolbar=" + toolbar + ",menubar=" + menuBar + ",location=" + location + ", resizable=" + resizable + ", width=" + width + ", height=" + height;
    }
    return retval;
}
