// LogLog
// This file collects the available data on the client and will be included via InsertThis.txt.
// HOW TO USE: See ReadMe.html


// KNOWN PROBLEMS:
// After Testing Opera7.11 + Netscape6 and Netscape7 + IE6 on W2000 with system lang. en-us and lang. no (Norway):
// Only IE detects ShockWave and Windows Media Player.
// Netscape6 doesn't detect Flash 6, only Flash 5. And doesn't detect QuickTime. Netscape 7 is doing fine.
// Netscape 6 and 7 do not detect Operative System.
// Only IE detects System Language.


var lng                      = 'unknown';
var sysLang               = 'unknown';
var uri                       = location.pathname;
var scCD                   = screen.colorDepth;
var detectableWithVB = false;
var pluginFound         = false;
var scW                     = screen.width;
var scH                     = screen.height;
var pl                        = navigator.platform;
var flash2Installed     = false;    
var flash3Installed     = false;    
var flash4Installed     = false;   
var flash5Installed     = false;    
var flash6Installed     = false;  
var maxVersion         = 6; 
var FlashVersion        = 0;
var gotflash               = 0;
var Shockwave         = false;
var QuickTime          = false;
var Real                   = false;
var Media                 = false;
var AppN                  = navigator.appName;
var ref                     = "n/a";
if (document.referrer!='') ref = escape(document.referrer);
if (ref.length>=252) ref=ref.substring(0,252)+"...";

// Check browser...we're looking for ie/win
  var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    
  var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
  
// Write vbscript detection on ie/win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
  if(isIE && isWin){
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
    document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
    document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
    document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
    document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'); 
    document.write('</SCR' + 'IPT\> \n');
  }

function isCookieEnabled()
{
    var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    var curCookie = 'CookieCheck=LogLog; path=/; expires=' + now.toGMTString();
    document.cookie = curCookie;

    var dc = document.cookie;
    if(dc.indexOf("CookieCheck") == -1){
	    return false;
	}else{
	    return true;
  }
}

function getLang() {
// navigator.language (Netscape), navigator.browserLanguage (IE)
// We are defining this one in the loglog.js instead of using HTTP_ACCEPT_LANGUAGE.
    if(navigator.language)
        lng = navigator.language;
    else if(navigator.browserLanguage)
        lng = navigator.browserLanguage;

// ------------------- System Language (IE only)
	if (typeof navigator.systemLanguage != "undefined") {
	  sysLang = navigator.systemLanguage;
  }
}
getLang();

function getOS(){
           var v = navigator.appVersion.toUpperCase();
   // ================ WINDOWS ====================
           if (0<=v.indexOf('WIN95') || 0<=v.indexOf('WINDOWS 95') || 0<=v.indexOf('WIN32')) return 'Win95';
           if (0<=v.indexOf('WIN98') || 0<=v.indexOf('WINDOWS 98')) return 'Win98';
           if (0<=v.indexOf('WINNT') || 0<=v.indexOf('WINDOWS NT')) return 'WinNT';
		   if (0<=v.indexOf('NT 5.1') || 0<=v.indexOf('WINDOWS XP')) return 'WinXP';
		   if (0<=v.indexOf('NT 5.2')) return 'Windows Server 2003';
		   if (0<=v.indexOf('WINDOWS NT 6')) return 'Windows Vista';
           if (0<=v.indexOf('WINDOWS 3.1')) return 'Win3.1';
           if (0<=v.indexOf('WINDOWS 3')) return 'Win3';
           if (0<=v.indexOf('WIN16')) return 'Win16'; // might be 3.x or NT.
   // ================== MAC ======================
           if((0<=v.indexOf('MAC')) && (0<=v.indexOf('PPC') || 0<=v.indexOf('POWERPC'))) return 'Mac ppc'; 
           if (0<=v.indexOf('MAC')) return 'Mac68K';
   // ================== X11 ======================
           if (0<=v.indexOf('SUNOS'))       return 'Sun';
           if (0<=v.indexOf('LINUX'))        return 'Linux';
           if (0<=v.indexOf('IRIX'))           return 'Irix';
           if (0<=v.indexOf('HP-UX'))        return 'HP-UX';
           if (0<=v.indexOf('OSF'))           return 'OSF';
           if (0<=v.indexOf('AIX'))            return 'AIX';
   // ================== Other ======================
           if (0<=v.indexOf('OS/2'))        return 'OS/2';
		   if (0<=v.indexOf('WEBTV'))        return 'WebTV';
           return 'unknown';
}

function getBrowser(){
           var b = navigator.userAgent.toUpperCase();
 
           if (0<=b.indexOf('MSIE')) return 'IE';
		   if (0<=b.indexOf('NETSCAPE')) return 'Netscape';
		   if (0<=b.indexOf('FIREBIRD')) return 'Firebird';
		   if (0<=b.indexOf('FIREFOX')) return 'FireFox';
		   if (0<=b.indexOf('OPERA')) return 'Opera';
		   if (0<=b.indexOf('AOL')) return 'Aol';
		   if (0<=b.indexOf('KONQUEROR')) return 'Konqueror';
		   if (0<=b.indexOf('SAFARI')) return 'Safari';
		   if (0<=b.indexOf('GOOGLEBOT')) return 'Googlebot';
		   if (0<=b.indexOf('GALEON')) return 'Galeon';
		   if (0<=b.indexOf('JAVA')) return 'Java';
		   if (0<=b.indexOf('CAMINO')) return 'Camino';
		   if (0<=b.indexOf('PHOENIX')) return 'Phoenix';
		   if (0<=b.indexOf('SCOOTER')) return 'Scooter';
		   if (0<=b.indexOf('LYNX')) return 'Lynx';
           return 'unknown';
}

// Adapted from Adobe.com
 function detectFlash() {  
   // If navigator.plugins exists...
   if (navigator.plugins) {
     // ...then check for flash 2 or flash 3+.
     if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
       var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
       var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
       // alert("Flash plugin description: " + flashDescription);
       var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
      
       flash2Installed = flashVersion == 2;    
       flash3Installed = flashVersion == 3;
       flash4Installed = flashVersion == 4;
       flash5Installed = flashVersion == 5;
       flash6Installed = flashVersion >= 6;
     }
   }
   
   // Loop through all versions we're checking, and
   // set actualVersion to highest detected version.
   for (var i = 2; i <= maxVersion; i++) {  
     if (eval("flash" + i + "Installed") == true) gotflash = i;
   
   }
 }
detectFlash();  // call our detector now that it's safely loaded.  


// Plugin detection code adapted from: http://developer.apple.com/internet/javascript/detectplugins.html
function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectDirector() { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    return pluginFound;
}

function detectQuickTime() {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return pluginFound;
}

function detectReal() {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return pluginFound;
}

function detectWindowsMedia() {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return pluginFound;
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
}

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<scr'+'ipt 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>');
}

if(canDetectPlugins()) {
      Shockwave = detectDirector();
	  QuickTime  = detectQuickTime();
	  Real           = detectReal();
	  Media         = detectWindowsMedia();
}

var os              = getOS();
var br              = getBrowser();
var bCookie     = isCookieEnabled();
