// CADSS General JavaScript file, containing all needed code.

// Revised on 8 June 2000

// Author:  Daniel Lee Osiecki


// General pop-up function, takes a URL, width, height, and frame reference.  Puts them in a bare-bones window

var bName = navigator.appName;

function popup_bare( site, width, height, whichFr ) {

    if (site != "") {

        if (bName != "Netscape") {

                height=height-20;

        } // of if

        var popupwindow = window.open( site, whichFr, "resizable=no,menubar=no,status=no,location=no,scrollbars=no,width="+width+",height="+height );
        popupwindow.focus();

    } // of if

} // of popup()

function popup_bare_scroll( site, width, height, whichFr ) {

    if (site != "") {

        if (bName != "Netscape") {

                height=height-20;

        } // of if

        var popupwindow = window.open( site, whichFr, "resizable=no,menubar=no,status=no,location=no,scrollbars=yes,width="+width+",height="+height );
        popupwindow.focus();

    } // of if

} // of popup()


// General pop-up function, takes a URL, and frame reference.  Puts them in a regular-bones window

function popup_reg( site, whichFr ) {

    var newwin = window.open( site, whichFr, "resizable=yes,directories=no,menubar=yes,status=yes,location=yes,scrollbar=yes,toolbar=yes" );
    newwin.focus();

} // of popup()



// Special full-screen open function.  Opens a page to be as 'full-screen' as possible:  maximum size, and no menus, buttons, etc.

function openFullscreen(page, fName) {

    var yes = 1;
    var no = 0;

    var menubar = no;      // Menus
    var scrollbars = no;   // Horizontal and vertical scrollbars
    var locationbar = no;  // The location box with the site URL
    var directories = no;  // the "What's New", "What Cool" links
    var resizable = no;    // Can the window be resized?
    var statusbar = no;    // Status bar
    var toolbar = no;      // Back, Forward, Home, Stop toolbar

    windowprops = "width=" + (screen.width-25) + ",height=" + (screen.height-70) + ",top=20,left=7";

    windowprops += (menubar ? ",menubar" : "") +
    (scrollbars ? ",scrollbars" : "") +
    (locationbar ? ",location" : "") +
    (directories ? ",directories" : "") +
    (resizable ? ",resizable" : "") +
    (statusbar ? ",status" : "") +
    (toolbar ? ",toolbar" : "");

    var newwin = window.open(page, fName, windowprops);
    newwin.focus();

} // of openFullscreen()

// Special part-screen open function.  Opens a page to be a smaller floating window, which, like it's full screen counterpart, has reduced  funcionalilty.

function openPartScreen(page, fName) {

    var pctX = .67;
    var pctY = .70;

    var WINw = Math.round( (screen.width)*pctX ) - 25;
    var WINh = Math.round( (screen.height)*pctY ) - 70;

    var WINt = Math.round( ( screen.width - WINw ) / 2 );
    var WINl = Math.round( ( screen.height - WINh ) / 2 );

    var yes = 1;
    var no = 0;

    var menubar = no;      // Menus
    var scrollbars = no;   // Horizontal and vertical scrollbars
    var locationbar = no;  // The location box with the site URL
    var directories = no;  // the "What's New", "What Cool" links
    var resizable = no;    // Can the window be resized?
    var statusbar = no;    // Status bar
    var toolbar = no;      // Back, Forward, Home, Stop toolbar

    windowprops = "width=" + (WINw) + ",height=" + (WINh) + ",top=" + (WINt) + ",left=" + (WINl) + "";

    windowprops += (menubar ? ",menubar" : "") +
                   (scrollbars ? ",scrollbars" : "") +
                   (locationbar ? ",location" : "") +
                   (directories ? ",directories" : "") +
                   (resizable ? ",resizable" : "") +
                   (statusbar ? ",status" : "") +
                   (toolbar ? ",toolbar" : "");

    var indexOfSplit = page.indexOf( "page=" );

    if( indexOfSplit != -1 ) {

        var goodPart = page.slice( 0, (indexOfSplit+5) );
        var badPart  = page.slice( (indexOfSplit+5), (page.length) );

        page = goodPart + escape( badPart );

    } // of if

    var newwin = window.open(page, fName, windowprops);
    newwin.focus();

} // of openPartScreen()



// Special pop-up function.  Maximises the height of the window, makes it very bare-bones, and centers it based on it's width, which is specified.

function openTallWindow( loc, frm, Wwidth ) {

    var xRes = screen.width;
    var yRes = screen.height;
    var Wheight = yRes;

    if (navigator.appName.indexOf("Microsoft") != -1) {

        Wheight = yRes - 31;

    } // of if

    if (navigator.appName.indexOf("Netscape") != -1) {

        Wheight = yRes - 34;
        Wwidth = Wwidth + 10;

    } // of if

    var newWin = window.open( loc, frm, "resizable=no,menubar=no,status=no,status=no,location=no,scrollbar=no,width=" + Wwidth + ",height=" + Wheight );

    var xPos = Math.round( (xRes/2)-(Wwidth/2) );

    newWin.moveTo( xPos, 1 );
    newWin.focus();

} // of openTallWindow()

// Cookies!

function checkCookieValue() {

    var allcookies = document.cookie;
    var pos = allcookies.indexOf( "ErgoTMC_flag=");

    if( pos == -1 ) {

        return 0;

    } else {

        var start = pos + 13;
        var end = allcookies.indexOf( ";", start );
        if( end == -1 ) {
            end = allcookies.length;
        } // of if
        var val = allcookies.substring( start, end );

        if( val == "yes" ) {

            return 1;

        } else {

            return 0;

        } // of if-else

    } // of if-else

} // of checkCookieValue()


function checkForCookie() {

    var allcookies = document.cookie;
    var pos = allcookies.indexOf( "ErgoTMC_flag=");

    if( pos == -1 ) {

        return 0;

    } else {

        return 1;

    } // of if-else

} // of checkForCookie()

function setCookie( val ) {

    var muchLater = new Date();
    muchLater.setFullYear(muchLater.getFullYear() + 10);
    document.cookie = "ErgoTMC_flag=" + val + "; expires=" + muchLater.toGMTString();

} // of setCookie()

function detectRes() {

    var val = "low";

    if( screen.width > 800 ) {

        val = "med";

    } // of if

    if( screen.width > 1024 ) {

        val = "high";

    } // of if

    if( screen.width > 1152 ) {

        val = "xhigh";

    } // of if

    if( screen.width > 1280 ) {

        val = "xxhigh";

    } // of if

    var muchLater = new Date();
    muchLater.setFullYear(muchLater.getFullYear() + 10);
    document.cookie = "ErgoTMC_res=" + val + "; expires=" + muchLater.toGMTString() + "; path=/";

} // of detectRes()

detectRes(); //call it whenever JS is loaded.
