﻿/*
// Super Popup: when using this function on multiple links across a site its best to define a 'type' with your options
if you are defining a popup on a single page you can pass in the options you want as object arguments.
*/

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function superPopup(args) {
    var url, type, directories, location, menubar, resizable, scrollbars, status, toolbar, top, left, width, height, winName;

    // URL is the only required field.
    if (args.url) { url = args.url; } else { alert('Error: Link URL Missing'); };

    if (args.type) { type = args.type; };

    // test to see if we have set a window option on the function or in a profile above, if not then set the value to be a default.
    // option = (if it was passed in as an argument)? use that value : [IF NOT] use this default value;
    directories = (args.directories) ? args.directories : directories = "no";
    location = (args.location) ? args.location : location = "no";
    menubar = (args.menubar) ? args.menubar : menubar = "no";
    resizable = (args.resizable) ? args.resizable : resizable = "no";
    scrollbars = (args.scrollbars) ? args.scrollbars : scrollbars = "auto";
    status = (args.status) ? args.status : status = "yes";
    toolbar = (args.toolbar) ? args.toolbar : toolbar = "no";
    top = (args.top) ? args.top : top = "50";
    left = (args.left) ? args.left : left = "50";
    width = (args.width) ? args.width : width = "250";
    height = (args.height) ? args.height : height = "400";
    winName = (args.winName) ? args.winName : winName = "popup";

    // type will set some basic options to make the function cleaner -- otherwise all values can be set
    if (type == "_blank") {	//used to generate a window the same size as the previous
        var windowWidth = f_clientWidth();
        var windowHeight = f_clientWidth();

        //used to generate original "window names"
        var randomNumber = Math.floor(Math.random() * 1000);
        winName = "blank" + randomNumber; width = windowWidth; height = windowHeight;
        scrollbars = "yes"; menubar = "yes"; toolbar = "yes"; directories = "yes";
        location = "yes"; top = "0"; left = "0";
    }

    // build our complete window options statement
    windowOptions = "width=" + width + ", height=" + height + ", directories='" + directories + "', location='" + location + "', menubar='" + menubar + "', resizable='" + resizable + "', scrollbars='" + scrollbars + "', toolbar='" + toolbar + "', status='" + status + "', toolbar='" + toolbar + "', top='" + top + "', left='" + left + "'";

    var newWindow = window.open(url, winName, windowOptions);

    if (newWindow == null) {
        //alert('A popup containing important information was blocked by your browser. Please enable popups for this site in order to view this information.');
        return true;
    } else {
        if (window.focus && newWindow) { newWindow.focus() }
    }
}
/* 
// End Super Popup:
*/