﻿// global.js


//-------------------------------------------------------
// Flash detection and alternate content handling
//-------------------------------------------------------
AC_FL_RunContent = 0; 
DetectFlashVer = 0;

var requiredMajorVersion = 6;	//Major version flash requied
var requiredMinorVersion = 0; // Minor version flash required
var requiredRevision = 0;	// REvision flash required


function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}









// Based on And King, et. al., 
// Converted to object
// Nathan Whelchel, 10-4-2005 
function Browser()
{
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***
    this.is_minor = parseFloat(appVer);
    this.is_major = parseInt(this.is_minor);

    this.is_opera = (agt.indexOf("opera") != -1);
    this.is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1); // new 020128- abk
    this.is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1); // new 021205- dmr
    this.is_opera5up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4);
    this.is_opera6up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4 && !this.is_opera5); // new020128
    this.is_opera7up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4 && !this.is_opera5 && !this.is_opera6); // new021205 -- dmr

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string
    // And on Mac IE5+, we look for this.is_minor in the ua; since 
    // it appears to be more accurate than appVersion - 06/17/2004

    this.is_mac = (agt.indexOf("mac")!=-1);
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       if(this.is_mac) {
           var iePos = agt.indexOf('msie');
           this.is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
       }
       else this.is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       this.is_major = parseInt(this.is_minor);
    }

    // ditto Konqueror
                                      
    this.is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       this.is_konq  = true;
       this.is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       this.is_major = parseInt(this.is_minor);
    }                                 

    this.is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
    this.is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
    this.is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

    this.is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    this.is_khtml  = (this.is_safari || this.is_konq);

    this.is_gecko = ((!this.is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    this.is_gver  = 0;
    if (this.is_gecko) this.is_gver=navigator.productSub;

    this.is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                    (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                    (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                    (this.is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
    this.is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (this.is_gecko) && (navigator.vendor=="Firebird"));
    this.is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
                 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
                 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
                 (this.is_gecko) && (navigator.vendor=="Firefox"));
    if ((this.is_moz)||(this.is_fb)||(this.is_fx)) {  // 032504 - dmr
       this.is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(this.is_moz_ver)) {
           this.is_moz_ver = agt.indexOf('rv:');
           this.is_moz_ver = agt.substring(this.is_moz_ver+3);
           this.is_paren   = this.is_moz_ver.indexOf(')');
           this.is_moz_ver = this.is_moz_ver.substring(0,this.is_paren);
       }
       this.is_minor = this.is_moz_ver;
       this.is_major = parseInt(this.is_moz_ver);
    }
   this.is_fb_ver = this.is_moz_ver;
   this.is_fx_ver = this.is_moz_ver;

    this.is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
                && (!this.is_khtml) && (!(this.is_moz)) && (!this.is_fb) && (!this.is_fx));

    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    // Changed this to use navigator.vendor/vendorSub - dmr 060502   
    // var nav6Pos = agt.indexOf('netscape6');
    // if (nav6Pos !=-1) {
    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (this.is_nav)) {
       this.is_major = parseInt(navigator.vendorSub);
       // here we need this.is_minor as a valid float for testing. We'll
       // revert to the actual content before printing the result. 
       this.is_minor = parseFloat(navigator.vendorSub);
    }

    this.is_nav2 = (this.is_nav && (this.is_major == 2));
    this.is_nav3 = (this.is_nav && (this.is_major == 3));
    this.is_nav4 = (this.is_nav && (this.is_major == 4));
    this.is_nav4up = (this.is_nav && this.is_minor >= 4);  // changed to this.is_minor for
                                                // consistency - dmr, 011001
    this.is_navonly      = (this.is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );

    this.is_nav6   = (this.is_nav && this.is_major==6);    // new 010118 mhp
    this.is_nav6up = (this.is_nav && this.is_minor >= 6); // new 010118 mhp

    this.is_nav5   = (this.is_nav && this.is_major == 5 && !this.is_nav6); // checked for ns6
    this.is_nav5up = (this.is_nav && this.is_minor >= 5);

    this.is_nav7   = (this.is_nav && this.is_major == 7);
    this.is_nav7up = (this.is_nav && this.is_minor >= 7);

    this.is_ie   = ((iePos!=-1) && (!this.is_opera) && (!this.is_khtml));
    this.is_ie3  = (this.is_ie && (this.is_major < 4));

    this.is_ie4   = (this.is_ie && this.is_major == 4);
    this.is_ie4up = (this.is_ie && this.is_minor >= 4);
    this.is_ie5   = (this.is_ie && this.is_major == 5);
    this.is_ie5up = (this.is_ie && this.is_minor >= 5);
    
    this.is_ie5_5  = (this.is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
    this.is_ie5_5up =(this.is_ie && this.is_minor >= 5.5);                // 020128 new - abk

    this.is_ie6   = (this.is_ie && this.is_major == 6);
    this.is_ie6up = (this.is_ie && this.is_minor >= 6);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables this.is_aol, this.is_aol3, and this.is_aol4 aren't 100% reliable.

    this.is_aol   = (agt.indexOf("aol") != -1);
    this.is_aol3  = (this.is_aol && this.is_ie3);
    this.is_aol4  = (this.is_aol && this.is_ie4);
    this.is_aol5  = (agt.indexOf("aol 5") != -1);
    this.is_aol6  = (agt.indexOf("aol 6") != -1);
    this.is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
    this.is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

    this.is_webtv = (agt.indexOf("webtv") != -1);
    
    // new 020128 - abk
    
    this.is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    this.is_AOLTV = this.is_TVNavigator;

    this.is_hotjava = (agt.indexOf("hotjava") != -1);
    this.is_hotjava3 = (this.is_hotjava && (this.is_major == 3));
    this.is_hotjava3up = (this.is_hotjava && (this.is_major >= 3));

    // end new

    // *** JAVASCRIPT VERSION CHECK ***
    // Useful to workaround Nav3 bug in which Nav3
    // loads <SCRIPT LANGUAGE="JavaScript1.2">.
    // updated 020131 by dragle
    this.is_js;
    if (this.is_nav2 || this.is_ie3) this.is_js = 1.0;
    else if (this.is_nav3) this.is_js = 1.1;
    else if ((this.is_opera5)||(this.is_opera6)) this.is_js = 1.3; // 020214 - dmr
    else if (this.is_opera7up) this.is_js = 1.5; // 031010 - dmr
    else if (this.is_khtml) this.is_js = 1.5;   // 030110 - dmr
    else if (this.is_opera) this.is_js = 1.1;
    else if ((this.is_nav4 && (this.is_minor <= 4.05)) || this.is_ie4) this.is_js = 1.2;
    else if ((this.is_nav4 && (this.is_minor > 4.05)) || this.is_ie5) this.is_js = 1.3;
    else if (this.is_nav5 && !(this.is_nav6)) this.is_js = 1.4;
    else if (this.is_hotjava3up) this.is_js = 1.4; // new 020128 - abk
    else if (this.is_nav6up) this.is_js = 1.5;

    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.

    else if (this.is_nav && (this.is_major > 5)) this.is_js = 1.4;
    else if (this.is_ie && (this.is_major > 5)) this.is_js = 1.3;
    else if (this.is_moz) this.is_js = 1.5;
    else if (this.is_fb||this.is_fx) this.is_js = 1.5; // 032504 - dmr
    
    // what about ie6 and ie6up for js version? abk
    
    // HACK: no idea for other browsers; always check for JS version 
    // with > or >=
    else this.is_js = 0.0;
    // HACK FOR IE5 MAC = js vers = 1.4 (if put inside if/else jumps out at 1.3)
    if ((agt.indexOf("mac")!=-1) && this.is_ie5up) this.is_js = 1.4; // 020128 - abk
    
    // Done with this.is_minor testing; revert to real for N6/7
    if (this.is_nav6up) {
       this.is_minor = navigator.vendorSub;
    }

    // *** PLATFORM ***
    this.is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    this.is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    this.is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    this.is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));
	
	this.is_winme = ((agt.indexOf("win 9x 4.90")!=-1));    // new 020128 - abk
    this.is_win2k = ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1)); // 020214 - dmr
    this.is_winxp = ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1)); // 020214 - dmr

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    this.is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    this.is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    this.is_win32 = (this.is_win95 || this.is_winnt || this.is_win98 ||
                    ((this.is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    this.is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    this.is_mac    = (agt.indexOf("mac")!=-1);
    if (this.is_mac) { this.is_win = !this.is_mac; } // dmr - 06/20/2002
    this.is_mac68k = (this.is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    this.is_macppc = (this.is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    this.is_sun   = (agt.indexOf("sunos")!=-1);
    this.is_sun4  = (agt.indexOf("sunos 4")!=-1);
    this.is_sun5  = (agt.indexOf("sunos 5")!=-1);
    this.is_suni86= (this.is_sun && (agt.indexOf("i86")!=-1));
    this.is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    this.is_irix5 = (agt.indexOf("irix 5") !=-1);
    this.is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    this.is_hpux  = (agt.indexOf("hp-ux")!=-1);
    this.is_hpux9 = (this.is_hpux && (agt.indexOf("09.")!=-1));
    this.is_hpux10= (this.is_hpux && (agt.indexOf("10.")!=-1));
    this.is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    this.is_aix1  = (agt.indexOf("aix 1") !=-1);
    this.is_aix2  = (agt.indexOf("aix 2") !=-1);
    this.is_aix3  = (agt.indexOf("aix 3") !=-1);
    this.is_aix4  = (agt.indexOf("aix 4") !=-1);
    this.is_linux = (agt.indexOf("inux")!=-1);
    this.is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    this.is_unixware = (agt.indexOf("unix_system_v")!=-1);
    this.is_mpras    = (agt.indexOf("ncr")!=-1);
    this.is_reliant  = (agt.indexOf("reliantunix")!=-1);
    this.is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    this.is_sinix = (agt.indexOf("sinix")!=-1);
    this.is_freebsd = (agt.indexOf("freebsd")!=-1);
    this.is_bsd = (agt.indexOf("bsd")!=-1);
    this.is_unix  = ((agt.indexOf("x11")!=-1) || this.is_sun || this.is_irix || this.is_hpux ||
                 this.is_sco ||this.is_unixware || this.is_mpras || this.is_reliant ||
                 this.is_dec || this.is_sinix || this.is_aix || this.is_linux || this.is_bsd || this.is_freebsd);

    this.is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
// additional checks, abk
    this.is_anchors = (document.anchors) ? "true":"false";
    this.is_regexp = (window.RegExp) ? "true":"false";
    this.is_option = (window.Option) ? "true":"false";
    this.is_all = (document.all) ? "true":"false";
// cookies - 990624 - abk
    document.cookie = "cookies=true";
    this.is_cookie = (document.cookie) ? "true" : "false";
    this.is_images = (document.images) ? "true":"false";
    this.is_layers = (document.layers) ? "true":"false"; // gecko m7 bug?
// new doc obj tests 990624-abk
    this.is_forms = (document.forms) ? "true" : "false";
    this.is_links = (document.links) ? "true" : "false";
    this.is_frames = (window.frames) ? "true" : "false";
    this.is_screen = (window.screen) ? "true" : "false";

// java
    this.is_java = (navigator.javaEnabled());

// Flash checking code adapted from Doc JavaScript information; 
// see http://webref.com/js/column84/2.html

   this.is_Flash        = false;
   this.is_FlashVersion = 0;

   if ((this.is_nav||this.is_opera||this.is_moz||this.is_fb||this.is_fx)||
       (this.is_mac&&this.is_ie5up)) {
      var plugin = (navigator.mimeTypes && 
                    navigator.mimeTypes["application/x-shockwave-flash"] &&
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
//      if (plugin) {
      if (plugin&&plugin.description) {
         this.is_Flash = true;
         this.is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
      }
   }

   if (this.is_win&&this.is_ie4up)
   {
      document.write(
         '<scr' + 'ipt language=VBScript>' + '\n' +
         'Dim hasPlayer, playerversion' + '\n' +
         'hasPlayer = false' + '\n' +
         'playerversion = 10' + '\n' +
         'Do While playerversion > 0' + '\n' +
            'On Error Resume Next' + '\n' +
            'hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion)))' + '\n' +
            'If hasPlayer = true Then Exit Do' + '\n' +
            'playerversion = playerversion - 1' + '\n' +
         'Loop' + '\n' +
         'this.is_FlashVersion = playerversion' + '\n' +
         'this.is_Flash = hasPlayer' + '\n' +
         '<\/sc' + 'ript>'
      );
   }
   
}
browser = new Browser();



//-------------------------------------------------------
// preconfigured window openers
//-------------------------------------------------------

//--------------------------------------------
// In NS4, force a reload when the window is 
//   resize so styles aren't lost
//--------------------------------------------
if(browser.is_ns4)
{
  window.onresize = function() { location.reload(); };
}



//--------------------------------------------
// window extensions
//--------------------------------------------

window.getFeatureScreenX = function(x)
{
    if (browser.is_ie4up)
        return ("left=" + x);
    else //all others
        return ("screenX=" + x);
}

window.getFeatureScreenY = function(y)
{
    if (browser.is_ie4up)
        return ("top=" + y);
    else //all others
        return ("screenY=" + y);
}


window.openCentered = function(url, name, features, replace, width, height)
{
    var x = Math.round(screen.availWidth/2) - Math.round(width/2);
    var y = Math.round(screen.availHeight/2) - Math.round(height/2);
        
    var theseFeatures = this.getFeatureScreenX(x) + "," + this.getFeatureScreenY(y) + ",width=" + width + ",height=" + height + "," + features;
    return window.open(url, name, theseFeatures);
}


function openRedirect(targetURL)
{
    window.openCentered(
        '../resources/php/redirect.php?url=' + escape(targetURL), 
        'redirect', 
        'status=no,scrollbars=no,resize=no,toolbar=no,menubar=no,directories=no', 
        false, 
        230, 250);
}

function openImageViewer(targetURL,targetHeight,targetWidth)
{
    var height=targetHeight+135;
    var width=targetWidth+100;
    window.openCentered(
        '../page/imageViewer.php?url=' + escape(targetURL), 
        'ImageViewer', 
        'status=no,scrollbars=yes,resize=yes,toolbar=no,menubar=no,directories=no', 
        false, 
        width, height);
}
    

function playClassicGame(gamename) 
{
    window.openCentered(
        'ClassicGamePlayer.php?game=' + escape(gamename), 
        'ClassicGame', 
        'status=no,scrollbars=no,resize=no,toolbar=no,menubar=no,directories=no', 
        false, 
        790,553);
}
