<!--

//
// Script    :   fes_gen_functions.js
// Author    :   C.E. Berry
// Version   :   1.3
// Notes     :   General Javascript function library for Flex-eSystems products
//
//               All material contained within is the intellectual property of Flex-eSystems Ltd.
//               and as such may not be reproduced in any way shape or form without the prior
//               consent of Flex-eSystems.
//
// Amendment Log
//
//      Version      Date           Author              Notes
//      -------      ----           ------              -----
//
//      1.3         24/02/2002     C.E. Berry           Added fncFesGetUrlParameters function.
//
//      1.2         16/12/2001     C.E. Berry           Added fncFesGetEnvironment function.
//                                                      Amended exisitng functions and variables
//                                                      to fit in with more logical naming
//                                                      convention.
//                                                      Amended mouseover functions to use
//                                                      associative array rather than indexed
//                                                      array.
//                                                      Added fncSelectFormElementText function.
//
//      1.1         21/09/2001     C.E. Berry           Added fncFesGetUrlParameters function.
//
//      1.0         04/03/2000     C.E. Berry           Creation
//
//=================================================================================================
//
// General functions
//
//=================================================================================================

function fncFesGetEnvironment()
//
// Function to return information about the client environment e.g. operating system, browser
// type etc.
//
//    Function based on Ultimate client-side JavaScript sniffer Version 3.03
//    (C) Netscape Communications 1999.  Permission granted to reuse and distribute.
//
// Function creates an object with the following properties which are true/false unless
// otherwise indicated:-
//
// Navigator Object Properties
//
// useragent        - useragent string
// appname          - application name
// appversion       - application version
//
// Browser Vendor:
//
// ns               - Netscape
// ie               - Microsoft Internet Explorer
// opera            - Opera
// hotjava          - HotJava (sun)
// webtv            - WebTV
// tvnavigator      - TV Navigator
// aoltv            - AOL TV
//
// Browser Version Numbers
//
// major_version    - Integer containing major Version Number e.g. 2, 3, 4 ...
// minor_version    - Float containing minor Version Number e.g. 2.06, 3.02, 4.05 ...
//
// Browser Vendor & Version
//
// ns2              - Netscape 2
// ns3              - Netscape 3
// ns4              - Netscape 4
// ns6              - Netscape 6
// gecko            - Gecko
// ie3              - Microsoft Internet Explorer 3
// ie4              - Microsoft Internet Explorer 4
// ie5              - Microsoft Internet Explorer 5
// ie5_5            - Microsoft Internet Explorer 5.5
// ie6              - Microsoft Internet Explorer 6
// aol3             - America Online 3
// aol4             - America Online 4
// aol5             - America Online 5
// aol6             - America Online 6
// opera2           - Opera 2
// opera3           - Opera 2
// opera4           - Opera 2
// opera5           - Opera 2
// hotjava3         - HotJava 3
//
// Browser Vendor and Version upward compatibility
//
// ns4up            - Netscape 4 or higher
// ns6up            - Netscape 6 or higher
// ie4up            - Microsoft Internet Explorer 4 or higher
// ie5up            - Microsoft Internet Explorer 5 or higher
// ie5_5up          - Microsoft Internet Explorer 5.5 or higher
// ie6up            - Microsoft Internet Explorer 6 or higher
// opera5up         - Opera 5 or higher
// hotjava3up       - HotJava 3 or higher
//
// Javascript version
//
// js               - float containing full Javascript version number
//
// Platform/Operating System
//
// win              - Microsoft Windows
// win16            - Microsoft Windows 16 bit
// win32            - Microsoft Windows 32 bit
// win31            - Microsoft Windows 3.1
// win95            - Microsoft Windows 95
// win98            - Microsoft Windows 98
// winme            - Microsoft Windows Millenium Edition
// winnt            - Microsoft Windows NT
// win2k            - Microsoft Windows 2000
// winxp            - Microsoft Windows XP
// os2              - IBM OS2
// mac              - Apple Macintosh
// mac68k           - Apple Macintosh 68K
// macppc           - Apple Macintosh Power PC
// unix             - Unix
// sun              - Sun
// sun4             - Sun 4
// sun5             - Sun 5
// suni86           - Sun for Intel 86
// irix             - Irix
// irix5            - Irix 5
// irix6            - Irix 6
// aix              - Aix
// aix1             - Aix 1
// aix2             - Aix 2
// aix3             - Aix 3
// aix4             - Aix 4
// linux            - Linux
// sco              - Sco Unix
// unixware         - Unixware
// mpras            - Mpras
// reliant          - Reliant Unix
// dec              - Digital (Compaq) Ultrix/Alpha
// sinix            - Sinix
// freebsd          - FreeBSD
// bsd              - BSD
// vms              - Digital (Compaq) VMS
//
{

// Get the Navigator properties

    this.useragent = navigator.userAgent;
    this.appname = navigator.appName;
    this.appversion = navigator.appVersion;

// Get the user agent string and convert all characters to lowercase to simplify testing

    var loc_usragt = navigator.userAgent.toLowerCase();

//=================================================================================================
//
// Browser Information
//
//=================================================================================================

// Get the browser major and minor version id's

    this.major_version = parseInt(navigator.appVersion);
    this.minor_version = parseFloat(navigator.appVersion);

// Set up browser values
//
// ns = Netscape Navigator

// Opera and WebTV spoof Navigator so have to eliminate them via specific search for the browser
// names in the user agent.

    this.ns  = ((loc_usragt.indexOf('mozilla')!= -1) &&
                (loc_usragt.indexOf('spoofer') == -1) &&
                (loc_usragt.indexOf('compatible') == -1) &&
                (loc_usragt.indexOf('opera') == -1) &&
                (loc_usragt.indexOf('webtv') == -1) &&
                (loc_usragt.indexOf('hotjava') == -1));

    this.ns2 = (this.ns &&
               (this.major_version == 2));

    this.ns3 = (this.ns &&
               (this.major_version == 3));

    this.ns4 = (this.ns &&
               (this.major_version == 4));

// Although Netscape 6 should have a major version of 6 it actually reports a major version of 5

    this.ns6 = (this.ns &&
               (this.major_version == 5));

    this.ns4up = (this.ns &&
                 (this.major_version >= 4));

    this.ns6up = (this.ns &&
                 (this.major_version >= 5));

    this.nsonly =  (this.ns &&
                  ((loc_usragt.indexOf(";nav") != -1) ||
                   (loc_usragt.indexOf("; nav") != -1)));

    this.gecko = (loc_usragt.indexOf('gecko') != -1);

// ie = Internet Explorer

    this.ie      = ((loc_usragt.indexOf("msie") != -1) &&
                    (loc_usragt.indexOf("opera") == -1));

    this.ie3     = (this.ie &&
                   (this.major_version < 4));

// Although Internet Explorer 4, 5, 5.5 and 6 should have a major versions of 4, 5, 5 and 6
// respectively they all report a major version of 4 so need to search the user agent string for
// specific names for each of them.

    this.ie4     = (this.ie &&
                   (this.major_version == 4) &&
                   (loc_usragt.indexOf("msie 4")!=-1));

    this.ie5     = (this.ie &&
                   (this.major_version == 4) &&
                   (loc_usragt.indexOf("msie 5.0")!=-1));

    this.ie5_5   = (this.ie &&
                   (this.major_version == 4) &&
                   (loc_usragt.indexOf("msie 5.5") !=-1));

    this.ie6     = (this.ie &&
                   (this.major_version == 4) &&
                   (loc_usragt.indexOf("msie 6.")!=-1) );

    this.ie4up   = (this.ie  &&
                   (this.major_version >= 4));

    this.ie5up   = (this.ie  &&
                   !this.ie3 &&
                   !this.ie4);

    this.ie5_5up = (this.ie &&
                   !this.ie3 &&
                   !this.ie4 &&
                   !this.ie5);

    this.ie6up   = (this.ie  &&
                   !this.ie3 &&
                   !this.ie4 &&
                   !this.ie5 &&
                   !this.ie5_5);

// aol = America Online - note that on AOL4 the test returns false if IE3 is the embedded browser
// or if this is the first browser window opened. Therefore the aol, aol3 and aol4 variables are
// not completely reliable

    this.aol   = (loc_usragt.indexOf("aol") != -1);

    this.aol3  = (this.aol &&
                  this.ie3);

    this.aol4  = (this.aol &&
                  this.ie4);

    this.aol5  = (loc_usragt.indexOf("aol 5") != -1);

    this.aol6  = (loc_usragt.indexOf("aol 6") != -1);

// opera = Opera

    this.opera =  (loc_usragt.indexOf("opera") != -1);

    this.opera2 = (loc_usragt.indexOf("opera 2") != -1 ||
                   loc_usragt.indexOf("opera/2") != -1);

    this.opera3 = (loc_usragt.indexOf("opera 3") != -1 ||
                   loc_usragt.indexOf("opera/3") != -1);

    this.opera4 = (loc_usragt.indexOf("opera 4") != -1 ||
                   loc_usragt.indexOf("opera/4") != -1);

    this.opera5 = (loc_usragt.indexOf("opera 5") != -1 ||
                   loc_usragt.indexOf("opera/5") != -1);

    this.opera5up = (this.opera &&
                    !this.opera2 &&
                    !this.opera3 &&
                    !this.opera4);

// webtv = WebTV

    this.webtv = (loc_usragt.indexOf("webtv") != -1);

    this.tvnavigator = ((loc_usragt.indexOf("navio") != -1) ||
                        (loc_usragt.indexOf("navio_aoltv") != -1));

    this.aoltv = this.tvnavigator;

// hotjava - HotJava (Sun)

    this.hotjava = (loc_usragt.indexOf("hotjava") != -1);

    this.hotjava3 = (this.hotjava &&
                    (this.major_version == 3));

    this.hotjava3up = (this.hotjava &&
                      (this.major_version >= 3));

//=================================================================================================
//
// Javascript Information
//
//=================================================================================================

    if (this.ns2 ||
        this.ie3)
    {
        this.js = 1.0;

    }

    if (this.ns3)
    {
        this.js = 1.1;

    }

    if (this.opera)
    {
        this.js = 1.1;

    }

    if (this.opera5up)
    {
        this.js = 1.3;

    }

    if ((this.ns4 &&
        (this.minor_version <= 4.05)) ||
         this.ie4)
    {
        this.js = 1.2;

    }

    if ((this.ns4 &&
        (this.minor_version > 4.05)) ||
         this.ie5)
    {
        this.js = 1.3;

    }

    if (this.hotjava3up)
    {
        this.js = 1.4;

    }

    if (this.ns6 ||
        this.gecko)
    {
        this.js = 1.5;

    }

    if (this.ns6up)
    {
        this.js = 1.5;

    }

    if (this.ie5up&
        loc_usragt.indexOf("mac") == -1)
    {
        this.js = 1.3;

    }


// On the Mac platform Javascript is Version 1.4 under Internet Explorer 5 and above

    if (this.ie5up&
        loc_usragt.indexOf("mac") != -1)
    {
        this.js = 1.4;
    }

//=================================================================================================
//
// Platform/OS Information
//
//=================================================================================================

// Microsoft Windows

    this.win = ((loc_usragt.indexOf("win") != -1) ||
                (loc_usragt.indexOf("16bit") != -1));

// On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all Win32 platforms so
// distnguishing between Windows 95 and NT is not possible

    this.win95 = ((loc_usragt.indexOf("win95") != -1) ||
                  (loc_usragt.indexOf("windows 95") != -1));

    this.win16 = ((loc_usragt.indexOf("win16") != -1) ||
                  (loc_usragt.indexOf("16bit") != -1) ||
                  (loc_usragt.indexOf("windows 3.1") != -1) ||
                  (loc_usragt.indexOf("windows 16-bit") != -1));

    this.win31 = ((loc_usragt.indexOf("windows 3.1") != -1) ||
                  (loc_usragt.indexOf("win16") != -1) ||
                  (loc_usragt.indexOf("windows 16-bit") != -1));

// Reliable detection of Windows 98 is not possible as on Ns4 and earlier you just get 'Windows'
// in the user agent string and on the Mercury client you get 'Win98' returned for the 32 bit
// version, but 'Win95' for the 16 bit version

    this.win98 = ((loc_usragt.indexOf("win98") != -1) ||
                  (loc_usragt.indexOf("windows 98") != -1));

    this.winnt = ((loc_usragt.indexOf("winnt") != -1) ||
                  (loc_usragt.indexOf("windows nt") != -1) ||
                  (loc_usragt.indexOf("windows 2000") != -1));

    this.win32 =  (this.win95 ||
                   this.winnt ||
                   this.win98 ||
                 ((this.major_version >= 4) &&
                  (navigator.platform == "Win32")) ||
                  (loc_usragt.indexOf("win32") != -1) ||
                  (loc_usragt.indexOf("32bit") != -1));

    this.winme = (loc_usragt.indexOf("win 9x 4.90") != -1);

    this.win2k = ((loc_usragt.indexOf("windows nt 5.0") != -1) ||
                  (loc_usragt.indexOf("windows 2000") != -1));

    this.winxp = (loc_usragt.indexOf("windows nt 5.1") != -1);

// IBM OS2

    this.os2   = ((loc_usragt.indexOf("os/2") != -1) ||
                  (navigator.appVersion.indexOf("OS/2") != -1) ||
                  (loc_usragt.indexOf("ibm-webexplorer") != -1));

// Apple Mac

    this.mac    = (loc_usragt.indexOf("mac") != -1);

    this.mac68k =  (this.mac &&
                  ((loc_usragt.indexOf("68k") != -1) ||
                   (loc_usragt.indexOf("68000") != -1)));

    this.macppc =  (this.mac &&
                  ((loc_usragt.indexOf("ppc") != -1) ||
                   (loc_usragt.indexOf("powerpc") != -1)));

// Various Unix and Linux derivatives

    this.sun   = (loc_usragt.indexOf("sunos") != -1);

    this.sun4  = (loc_usragt.indexOf("sunos 4") != -1);

    this.sun5  = (loc_usragt.indexOf("sunos 5") != -1);

    this.suni86 = (this.sun && (loc_usragt.indexOf("i86") != -1));

    this.irix  = (loc_usragt.indexOf("irix") != -1);

    this.irix5 = (loc_usragt.indexOf("irix 5") != -1);

    this.irix6 = ((loc_usragt.indexOf("irix 6") != -1) ||
                  (loc_usragt.indexOf("irix6") != -1));

    this.hpux  = (loc_usragt.indexOf("hp-ux")!=-1);

    this.hpux9 = (this.hpux &&
                 (loc_usragt.indexOf("09.") != -1));

    this.hpux10= (this.hpux &&
                 (loc_usragt.indexOf("10.") != -1));

    this.aix   = (loc_usragt.indexOf("aix") != -1);

    this.aix1  = (loc_usragt.indexOf("aix 1") != -1);

    this.aix2  = (loc_usragt.indexOf("aix 2") != -1);

    this.aix3  = (loc_usragt.indexOf("aix 3") != -1);

    this.aix4  = (loc_usragt.indexOf("aix 4") != -1);

    this.linux = (loc_usragt.indexOf("inux") != -1);

    this.sco   = (loc_usragt.indexOf("sco") != -1) ||
                 (loc_usragt.indexOf("unix_sv") != -1);

    this.unixware = (loc_usragt.indexOf("unix_system_v") != -1);

    this.mpras    = (loc_usragt.indexOf("ncr") != -1);

    this.reliant  = (loc_usragt.indexOf("reliantunix") != -1);

    this.dec   = ((loc_usragt.indexOf("dec") != -1) ||
                  (loc_usragt.indexOf("osf1") != -1) ||
                  (loc_usragt.indexOf("dec_alpha") != -1) ||
                  (loc_usragt.indexOf("alphaserver") != -1) ||
                  (loc_usragt.indexOf("ultrix") != -1) ||
                  (loc_usragt.indexOf("alphastation") != -1));

    this.sinix = (loc_usragt.indexOf("sinix") != -1);

    this.freebsd = (loc_usragt.indexOf("freebsd") != -1);

    this.bsd = (loc_usragt.indexOf("bsd") != -1);

    this.unix  = ((loc_usragt.indexOf("x11") != -1) ||
                   this.sun ||
                   this.irix ||
                   this.hpux ||
                   this.sco ||
                   this.unixware ||
                   this.mpras ||
                   this.reliant ||
                   this.dec ||
                   this.sinix ||
                   this.aix ||
                   this.linux ||
                   this.bsd ||
                   this.freebsd);

// Digital/Compaq VMS

    this.vms   = ((loc_usragt.indexOf("vax")!=-1) || (loc_usragt.indexOf("openvms")!=-1));
}

//=================================================================================================

function fncFesOpenWindow(prm_page_name,prm_target_name,prm_window_width,prm_window_height,prm_xoffset,prm_yoffset,prm_scrollbars,prm_toolbar,prm_location,prm_directories,prm_status,prm_menubar,prm_resizeable)
//
// Function to open a URL in a new window. User can specify height, width and position of window
//
// Arguments
//
//  prm_page_name       URL to be opened in new window
//  prm_target_name     name of new window
//  prm_window_width    window width in pixels
//  prm_window_height   window height in pixels
//  prm_xoffset         horizontal offset position in pixels that window will be displayed at
//                      (measured from centre)
//  prm_yoffset         vertical offset position in pixels that window will be displayed at
//                      (measured from centre)
//  prm_scrollbars      1 - scrollbars displayed, 0 - no scrollbars displayed
//  prm_toolbar         1 - toolbar displayed, 0 - no toolbar displayed
//  prm_location        1 - location displayed, 0 - no location displayed
//  prm_directories     1 - directories displayed, 0 - no directories displayed
//  prm_status          1 - status line displayed, 0 - no status line displayed
//  prm_menubar         1 - menubar displayed, 0 - no menubar displayed
//  prm_resizeable      1 - resizeable, 0 - not resizeable
//
{

    var loc_xpos = ((screen.width - prm_window_width) / 2) + prm_xoffset;
    var loc_ypos = ((screen.height - prm_window_height) / 2) + prm_yoffset;

// Get browser type

    var loc_environment = new fncFesGetEnvironment();

    if (loc_environment.ns4)
    {
        loc_win_features = "toolbar=" + prm_toolbar + ",location=" + prm_location + ",directories=" + prm_directories + ",status=" + prm_status + ",menubar=" + prm_menubar + ",scrollbars=" + prm_scrollbars +",resizable=" + prm_resizeable + ",screenX=" + loc_xpos + ",screenY=" + loc_ypos + ",width=" + prm_window_width + ",height=" + prm_window_height;
    }
    else
    {
        loc_win_features = "toolbar=" + prm_toolbar + ",location=" + prm_location + ",directories=" + prm_directories + ",status=" + prm_status + ",menubar=" + prm_menubar + ",scrollbars=" + prm_scrollbars +",resizable=" + prm_resizeable + ",left=" + loc_xpos + ",top=" + loc_ypos + ",width=" + prm_window_width + ",height=" + prm_window_height;
    }

    window.open(prm_page_name,prm_target_name,loc_win_features);

    return true;
}

//=================================================================================================

function fncFesGetUrlParameters()
//
// Function to split URL CGI style parameters into an associative array (key/value pairs)
//
// Arguments
//
//  None
//
{
    var loc_str = window.top.location.search.substr(1);

    if (loc_str.length > 0)
    {
        var loc_params_array = loc_str.split("&");

        for (var loc_ind1 in loc_params_array)
        {
            loc_params_array[loc_ind1] = loc_params_array[loc_ind1].split("=");

        }

    }

    else
    {
        var loc_params_array = new Array;

    }

    return loc_params_array;

}

//=================================================================================================
//
// Functions for image mouseover effects
//
//=================================================================================================


// pub_fes_mo_dir       - relative directory location of mouseover images
// pub_fes_mo_options   - associative array used to store image mouseover option information (e.g.
//                        button images)
// pub_fes_mo_preloaded - boolean to indicate whether all mouseover images are loaded into the
//                        image mouseover options array

var pub_fes_mo_dir  ='images/';
var pub_fes_mo_options = new Array();
var pub_fes_mo_preloaded = false;

// Preload images

// Parameters:

//      prm_id = name of image tag
//      prm_img = name of GIF to be associated
//      prm_status = text for the status line
//      prm_top = 1 for top level page, 0 for other

//=================================================================================================

function fncFesMoPreLoad(prm_id,prm_img,prm_status,prm_top)
//
// Function to preload images for mouseover effects
//
// Arguments
//
//  prm_id          string used to uniquely identify mouseover option in the array
//  prm_img         image name
//  prm_status      message to be displayed in window status bar when mouse is moved over image
//  prm_top         flag to indicate if page function being called from is at the same directory
//                  level as the image directory or a level up from it, 1 - same level, 0 - a
//                  level up
//
{

    if(!document.images)
    {
        return false;

    }

    else
    {
        pub_fes_mo_options[prm_id] = new fncFesMoCreateOptionArrayElement(prm_id,prm_img,prm_status,prm_top);
        return true;

    }

}

//=================================================================================================

function fncFesMoCreateOptionArrayElement(prm_id,prm_img,prm_status,prm_top)
//
// Function to create new image mouseover option array element and load image button objects
// accordingly
//
// Arguments
//
//  prm_id          string used to uniquely identify mouseover option in the array
//  prm_img         image name
//  prm_status      message to be displayed in window status bar when mouse is moved over image
//  prm_top         flag to indicate if page function being called from is at the same directory
//                  level as the image directory or a level up from it, 1 - same level, 0 - a
//                  level up
//
{
    this.Id = prm_id;
    this.Status = prm_status;
    this.ImgOff = new Image;
    this.ImgOn = new Image;

    if (prm_top)
    {
        this.ImgOff.src = pub_fes_mo_dir + prm_img + '.gif';
        this.ImgOn.src = pub_fes_mo_dir + prm_img + 'on.gif';

    }

    else
    {
        this.ImgOff.src = '../'+ pub_fes_mo_dir + prm_img + '.gif';
        this.ImgOn.src = '../'+ pub_fes_mo_dir + prm_img + 'on.gif';

    }

}

//=================================================================================================

function fncFesMoChangeState(prm_action, prm_id, prm_imgswap)
//
// Function to create perform image swapping for mouseover and mouseout events
//
// Arguments
//
//  prm_action      1 - mouseover, 0 - mouseout
//  prm_id          string used to uniquely identify menu option
//  prm_imgswap     1 - swap image, 0 - don't swap image (just alter window status text)
//
{
    if (document.images && pub_fes_mo_preloaded==true)
    {
        if (prm_action)
        {
            if (prm_imgswap)
            {
                document[prm_id].src = pub_fes_mo_options[prm_id].ImgOn.src;

            }

            window.status = pub_fes_mo_options[prm_id].Status;

        }

        else
        {
            if (prm_imgswap)
            {
                document[prm_id].src = pub_fes_mo_options[prm_id].ImgOff.src;

            }

            window.status = '';

        }

    }

    return true;

}

//=================================================================================================

function fncSelectFormElementText(prm_form_name,prm_element_name)
//
// Function to highlight all text in a specific form element (usually a textarea)
//
// Arguments
//
//  prm_form_name       name of form
//  prm_element_name    name of element in form
//
{
    document.forms[prm_form_name].elements[prm_element_name].focus();
    document.forms[prm_form_name].elements[prm_element_name].select();

}

//=================================================================================================

function fncFesGetUrlParameters()
//
// Function to get CGI paramter key/value pairs from URL of page
//
// Arguments
//
//  None
//
{

    var loc_str = window.top.location.search.substr(1);

    if (loc_str.length > 0)
    {
        var loc_array = loc_str.split("&");

        for (var loc_ind1 in loc_array)
        {
            loc_array[loc_ind1] = loc_array[loc_ind1].split("=");

        }

    }

    return loc_array;

}

//=================================================================================================

function fncFesPrintPage()
//
// Function to print current page
//
// Arguments
//
//  None
//
{

    if (window.print)
    {
        window.print();
    }

    else
    {
        var loc_web_browser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', loc_web_browser);
        WebBrowser1.ExecWB(6, 2); //Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";

    }

}

//-->
