// Scripts check for browser version, JavaScript, Flash and QuickTime.
// Built from scripts by Macromedia and others. Each section have copyright
//  info attaached.
//
// Created 22 March 2002 by Buzu.
// Revised 26 March 2002 by Buzu
//       Change scripts to use a consistent object model.
//       Change API to access.
//
// There are no restrictions as-is. To have restrictions you must set them up.
// All these methods do are restrict if component does not exists on a platform,
// by platform basis. These scripts don't set what is allowed.
//  
// lpl_requireCookies (platform,required,altURL)    - platform = browser sniff vars for platform (ie, is_mas, is_win, is_unix)
//                                                    required = true if component is required
//                                                    altURL   = where to go if requirement not met
// lpl_requireJavaScript (platform,required,altURL) - same as lpl_requireCookies ()
// lpl_requireBrowser (platform,required,altURL)    - same as lpl_requireCookies ()
// lpl_requireFlash (platform,required,
//                   updateURL,installURL)          - platform = same as lpl_requireCookies ()
//                                                    required = tsame as lpl_requireCookies ()
//                                                    updateURL= where to go if component is there, but older version
//                                                    installURL= where to go if component is missing
// lpl_requireQuickTime (platform,required,updateURL,installURL) - same as lpl_requireFlash()
//
// Then we have the methods that tell the object model what we *do* need. These
// are the methods we use to set the minimum requirements for component.
//
// lpl_allowFlash (platform, version)               - platform = browser sniff vars for platform (ie, is_mas, is_win, is_unix)
//                                                    version = minimum version needed ('5.0.1', '6.0.1', '5', etc.)
// lpl_allowQuickTime (platform, version)           - platform = browser sniff vars for platform (ie, is_mas, is_win, is_unix)
//                                                    version = minimum version needed ('5.0.1', '6.0.1', '5', etc.)
//  lpl_allowBrowser (platform, browser)            - platform = browser sniff vars for platform (is_mas, is_win, is_unix)
//                                                    browser = browser sniff vars for browser (is_ie,is_nav,is_ie5up)
//  lpl_allowJavaScript (platform, version)         - platform = browser sniff vars for platform (is_mas, is_win, is_unix)
//                                                    version = version of JavaScript needed ('1.1','1.2')
//
// And we need to a method to check to see everything is there after we let it know what is needed.
//
// lpl_checkComponents ()



// ---------------------------------------------------------------------
// Begin browser sniff
// ---------------------------------------------------------------------

// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater") 
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var 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));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) 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 (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var 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.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // 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".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 || 
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);    
    var is_aix2  = (agt.indexOf("aix 2") !=-1);    
    var is_aix3  = (agt.indexOf("aix 3") !=-1);    
    var is_aix4  = (agt.indexOf("aix 4") !=-1);    
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    var is_mpras    = (agt.indexOf("ncr")!=-1); 
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var 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)); 
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || 
                 is_sco ||is_unixware || is_mpras || is_reliant || 
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

	var is_any   = true;                       // 22 Mar 2002 buzu
	
	
// ---------------------------------------------------------------------
// ActiveX detection
// 27 March 2002 buzu from http://www.dithered.com/archives/200110.html
// ---------------------------------------------------------------------

function activeXDetect(componentClassID) {
	if (is_win && is_ie) {
		componentVersion = document.body.getComponentVersion('{'+componentClassID+'}','ComponentID');
		if (componentVersion != null) {
			return componentVersion;
		}
		return false;
	} else {
		return false;
	}
}

if (is_win && is_ie) {
	document.body.addBehavior("#default#clientCaps");
} 

// ---------------------------------------------------------------------
// Begin Flash sniff
// ---------------------------------------------------------------------


/*********************************************************************
 *
 * Macromedia Flash Dispatcher -- a scriptable detector for Flash Player
 *
 *
 * copyright (c) 2000 Macromedia, Inc.
 *
 *********************************************************************/

// Revised 26 March 2002 by buzu
//    Changed so that it complies with the component object model
//    No longer supports Mac IE 4
//    Removed documentation from file. See the original FlashDispatcher.js for 
//      the documentation

var MM_FlashControlInstalled;	// is the Flash ActiveX control installed?
var MM_FlashControlVersion;	// ActiveX control version if installed

function lpl_flashInfo() {
    this.flashRequired=false;
    this.valid=false;
    var has_flashActiveX = activeXDetect('D27CDB6E-AE6D-11CF-96B8-444553540000');
    
    if (navigator.plugins && navigator.plugins.length > 0) {
		this.implementation = "Plug-in";
		this.autoInstallable = false;	// until Netscape SmartUpdate supported

		// Check whether the plug-in is installed:

		if (navigator.plugins["Shockwave Flash"]) {
	    	this.installed = true;

	    	// Get the plug-in version and revision:

	   		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    	for (var i = 0; i < words.length; ++i) {
				if (isNaN(parseInt(words[i]))) continue;
				this.version = words[i];
				this.minorRevision = parseInt(words[i + 1].substring(1));
    			this.majorRevision = parseInt(this.version.split('.')[1]);
    			this.version = parseInt(this.version.split('.')[0]);
	    	}
		} else {
	    	this.installed = false;
		}
    } else if (has_flashActiveX) {
		this.implementation = "ActiveX control";
		this.installed = true;
		this.version = has_flashActiveX;
    	this.minorRevision = parseInt(this.version.split(',')[2])
    	this.majorRevision = parseInt(this.version.split(',')[1]);
    	this.version = parseInt(this.version.split(',')[0]);
		this.autoInstallable = true;
    }
}

// canPlay method

lpl_flashInfo.prototype.canPlay = function (version) {
	// version provided in format of 6.0.1 or 6.0 r22
	if (! version || (parseInt(version)==NaN)) {return true}
	var parts = version.split ('r');
	var vers,maj=0,min=0;
	if (parts.length > 1) {min = parseInt(parts[1])}
	var parts=parts[0].split('.');
	vers = parseInt(parts[0]);
	maj = parseInt(parts[1]);
	if (parts.length > 2) {min = parseInt(parts[2])}
	if (isNaN(maj)) {maj=0}
	if (isNaN(min)) {min=0}
	
	if (this.version < vers) {
		return false;
	} else if (this.version==vers && this.majorRevision < maj) {
		return false;
	} else if (this.version==vers && this.majorRevision==maj && this.minorRevision < min) {
		return false;
	} else {
		return true;
	}
}


// isValid method

lpl_flashInfo.prototype.isValid = function () {
	if (this.flashRequired) {
		return this.valid;
	} else {
		return true;
	}
}

lpl_flashInfo.prototype.setRequired = function (platform,required) {
	if (platform) {
		this.flashRequired=required;
	}
}

lpl_flashInfo.prototype.addAcceptable = function (platform, version) {
	// version provided in format of 6.0.1 or 6.0 r22
	if (platform) {
		if (this.canPlay (version)) {this.valid=true}
	}
}

lpl_flashInfo.prototype.getVersion = function () {
	var rtnStr = String(this.version);
	if (this.majorRevision!=null) {
		rtnStr += '.'+String(this.majorRevision);
		if (this.minorRevision) {rtnStr += '.'+String(this.minorRevision)}
	}
	
	return rtnStr;
}



// ---------------------------------------------------------------------
// Begin QuickTime sniff
// ---------------------------------------------------------------------

// 26 March 2002 buzu
//    Changed to use component object model
//    Simplified - no longer looks for the latest version

var lpl_QuickTimeControlInstalled;	// is the Flash ActiveX control installed?
var lpl_QuickTimeControlVersion;	// ActiveX control version if installed

function lpl_quickTimeInfo () {
	var verStr;
	var verArr;
	this.quickTimeRequired=false;
	this.valid=false;
	if (navigator.plugins && navigator.plugins.length > 0) {
		this.implementation  = 'Plug-in';
		this.autoInstallable = false; // does QuickTime do SmartUpdate???
	
		var qtPlugin = lpl_getQTPlugin ();
		if (qtPlugin) { // plugin found
			this.installed=true;
			var words = qtPlugin.name.split(' ');
			verStr = words[words.length-1];
		} else { // plugin based, no QuickTime detected
			this.installed=false;
			this.valid=false;
		}
	} else if (detectQuickTimeActiveXControl()) {
		this.implementation='ActiveX control';
		this.installed=true;
		verStr=0;
		this.valid=true;
		this.autoInstallable=true;
	}
	if (verStr) {
		verArr = verStr.split ('.');
		this.version=verArr[0];
		this.majorRevision=verArr[1];
		this.minorRevision=verArr[2];
	}
}

// See if we can play a certain version

lpl_quickTimeInfo.prototype.canPlay = function (whichVersion) {
	// version provided in format of 6.0.1 or 6.0 r22
	if (! whichVersion || (parseInt(whichVersion)==NaN)) {return true}
	if (! this.installed) {return false}
	var parts = whichVersion.split ('r');
	var vers,maj=0,min=0;
	if (parts.length > 1) {min = parseInt(parts[1])}
	var parts=parts[0].split('.');
	vers = parseInt(parts[0]);
	maj = parseInt(parts[1]);
	if (parts.length > 2) {min = parseInt(parts[2])}
	if (isNaN(maj)) {maj=0}
	if (isNaN(min)) {min=0}
	if (this.version < vers) {
		return false;
	} else if (this.version==vers && this.majorRevision < maj) {
		return false;
	} else if (this.version==vers && this.majorRevision==maj && this.minorRevision < min) {
		return false;
	} else {
		return true;
	}
}

// isValid method

lpl_quickTimeInfo.prototype.isValid = function () {
	if (this.quickTimeRequired) {
		return this.valid;
	} else {
		return true;
	}
}

lpl_quickTimeInfo.prototype.setRequired = function (platform,required) {
	if (platform) {
		this.quickTimeRequired=required;
	}
}

lpl_quickTimeInfo.prototype.addAcceptable = function (platform, version) {
	// version provided in format of 6.0.1 or 6.0 r22
	if (platform) {
		if (this.canPlay (version)) {this.valid=true}
	}
}

lpl_quickTimeInfo.prototype.getVersion = function () {
	var rtnStr = String(this.version);
	if (this.majorRevision!=null) {
		rtnStr += '.'+String(this.majorRevision);
		if (this.minorRevision) {rtnStr += '.'+String(this.minorRevision)}
	}
	
	return rtnStr;
}

// get Plugin object

function lpl_getQTPlugin () {
	var numPlugins = navigator.plugins.length;
	var currentPlugin;
	for (i=0;i<numPlugins;i++) {
		currentPlugin = navigator.plugins[i];
		if (currentPlugin.name.substring(0,9)=="QuickTime") {
			return currentPlugin;		
		}	
	}
	return false;
}

// ---------------------------------------------------------------------
// VBScript detection
// ---------------------------------------------------------------------


var detectableWithVB = false;
var pluginFound = false;

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}


// ---------------------------------------------------------------------
// Begin Little Planet versioning scripts
// ---------------------------------------------------------------------

// (c) 2002 Little Planet Learning, http://www.littleplanet.com
// Utilities and glue to bring together disparate sniffer scripts to work 
// together.
// Created 22 March 2002 buzu
// 26 March 2002 buzu
//    Changed it so that each component has an info object. The component object
//    handles validation

/********************************************************
 * Browser info object
 * Object for browser detection that complies with the way other components are
 * exposed.
 * 26 March 2002 buzu
 *******************************************************/

 function lpl_browserInfo () {
 	this.valid = false;
 	this.browserRequired = false;
 }
 
 // isValid method

lpl_browserInfo.prototype.isValid = function () {
	if (this.browserRequired) {
		return this.valid;
	} else {
		return true;
	}
}

// setRequired method

lpl_browserInfo.prototype.setRequired = function (platform, required) {
	if (platform && required) {
		this.browserRequired = true;
	}
}

// addAcceptable
lpl_browserInfo.prototype.addAcceptable = function (platform, browser) {
	if (platform && browser) {
		this.valid=true;
	}
}


lpl_browserInfo.prototype.getVersion = function ( ) {
	return is_minor;
}


/********************************************************
 * Cookie info object
 * Object for cookie detection that complies with the way other components are
 * exposed.
 * 26 March 2002 buzu
 *******************************************************/
 
function lpl_cookieInfo () {
	var count=60;
	var units = "days";
	
	var msecs = new Object ();
	
	msecs.minute = msecs.minutes = 60000;
	msecs.hour = msecs.hours = 60 * msecs.minute;
	msecs.day = msecs.days = 24 * msecs.hour;
	
	var expires = new Date ();
	expires.setTime (expires.getTime ()+ (count * msecs[units]));
	document.cookie = 'lpl_cookie=true ; expires=' + expires.toGMTString ();
	
	this.valid = (document.cookie.indexOf ("lpl_cookie") != -1);
	this.requiresCookies = false;
}

// isValid method

lpl_cookieInfo.prototype.isValid = function () {
	if (this.requiresCookies) {
		return this.valid;
	} else {
		return true;
	}
}

// required method

lpl_cookieInfo.prototype.setRequired= function (platform, required) {
	if (platform) {
		this.requiresCookies = required;
	}
}

/********************************************************
 * Javascript info object
 * Object for js detection that complies with the way other components are
 * exposed.
 * 26 March 2002 buzu
 *******************************************************/

function lpl_javaScriptInfo () {
	this.valid = false; // large number
	this.requireJS=false;
}

// isValid method

lpl_javaScriptInfo.prototype.isValid = function () {
	if (this.requireJS) {
		return this.valid;
	} else {
		return true;
	}
}

// required method

lpl_javaScriptInfo.prototype.setRequired = function (platform, required) {
	if (platform) {
		this.requireJS = required;
	}
}

lpl_javaScriptInfo.prototype.addAcceptable = function (platform, version) {
	var requiredNum = parseFloat (version)
	if (platform && requiredNum != NaN && (requiredNum <= is_js)) {
		this.valid=true;
	}
}

lpl_javaScriptInfo.prototype.getVersion = function ( ) {
	return is_js;
}

/********************************************************
 * Create detection objects
 *******************************************************/
 
var lpl_cookieObj = new lpl_cookieInfo ();
var lpl_javaScriptObj = new lpl_javaScriptInfo ();
var lpl_browserInfoObj = new lpl_browserInfo ();
var lpl_flashInfoObj = new lpl_flashInfo ();
var lpl_quickTimeInfoObj = new lpl_quickTimeInfo ();


/********************************************************
 * Create detection objects
 *******************************************************/
 
var jsErrorURL='';
var cookieErrorURL='';
var browserErrorURL='';
var flashUpdateURL='';
var flashInstallURL='';
var quickTimeUpdateURL='';
var quickTimeInstallURL='';

function lpl_allowFlash (platform, version) {
 	lpl_flashInfoObj.addAcceptable (platform,version);
}
 
function lpl_allowQuickTime (platform, version) {
 	lpl_quickTimeInfoObj.addAcceptable (platform,version);
}

function lpl_allowBrowser (platform, browser) {
 	lpl_browserInfoObj.addAcceptable (platform,browser);
}

function lpl_allowJavaScript (platform, version) {
 	lpl_javaScriptObj.addAcceptable (platform,version);
}

function lpl_requireCookies (platform,required,altURL) {
	if (platform) {
		lpl_cookieObj.setRequired (platform,required);
		cookieErrorURL=altURL;
	}
}

function lpl_requireJavaScript (platform,required,altURL) {
	if (platform) {
		lpl_javaScriptObj.setRequired (platform,required);
		jsErrorURL=altURL;
	}
}

function lpl_requireBrowser (platform,required,altURL) {
	if (platform) {
		lpl_browserInfoObj.setRequired (platform,required);
		browserErrorURL=altURL;
	}
}

function lpl_requireFlash (platform,required,updateURL,installURL) {
	if (platform) {
		lpl_flashInfoObj.setRequired (platform,required);
		flashUpdateURL=updateURL;
		flashInstallURL=installURL;
	}
}

function lpl_requireQuickTime (platform,required,updateURL,installURL) {
	if (platform) {
		lpl_quickTimeInfoObj.setRequired (platform,required);
		quickTimeUpdateURL=updateURL;
		quickTimeInstallURL=installURL;
	}
}

function lpl_checkComponents () {
	if (! lpl_browserInfoObj.isValid()) {
		document.location = browserErrorURL;
		return false;
	} else if (! lpl_javaScriptObj.isValid()) {
		document.location = jsErrorURL;
		return false;
	} else if (! lpl_cookieObj.isValid()) {
		document.location = cookieErrorURL;
		return false;
	} else if (! lpl_flashInfoObj.isValid()) {
		if ( ! lpl_flashInfoObj.installed) {
			document.location = flashInstallURL;
			return false;
		} else { //if (! lpl_flashInfoObj.autoInstallable ) {
			document.location = flashUpdateURL;
			return false;
		}
	} else if (! lpl_quickTimeInfoObj.isValid()) {
		if ( ! lpl_quickTimeInfoObj.installed && ! lpl_quickTimeInfoObj.autoInstallable) {
			document.location = quickTimeInstallURL;
			return false;
		} else if (! lpl_quickTimeInfoObj.autoInstallable ) {
			document.location = quickTimeUpdateURL;
			return false;
		}
	}
	return true;
}



