// awstats_misc_tracker.js
//-------------------------------------------------------------------
// You can add this file onto some of your web pages (main home page can
// be enough) by adding the following HTML code to your page body:
//
// <script language=javascript src="/js/awstats_misc_tracker.js"></script>
// <noscript><img src="/js/awstats_misc_tracker.js?nojs=y" height=0 width=0 border=0 style="display: none"></noscript>
//
// * This must be added after the <body> tag, not placed within the
//   <head> tags, or the resulting tracking <img> tag will not be handled
//   correctly by all browsers.  Internet explorer will also not report
//   screen height and width attributes until it begins to render the
//   body.
//
// This allows AWStats to be enhanced with some miscellanous features:
// - Screen size detection (TRKscreen)
// - Browser size detection (TRKwinsize)
// - Screen color depth detection (TRKcdi)
// - Java enabled detection (TRKjava)
// - Macromedia Director plugin detection (TRKshk)
// - Macromedia Shockwave plugin detection (TRKfla)
// - Realplayer G2 plugin detection (TRKrp)
// - QuickTime plugin detection (TRKmov)
// - Mediaplayer plugin detection (TRKwma)
// - Acrobat PDF plugin detection (TRKpdf)
//-------------------------------------------------------------------

/**
 * Tracking of silverlight.
 * Code by http://www.garchibald.com/blog/2008/08/10/TrackingSilverlightAndMoonlightEnabledBrowsersViaGoogleAnalytics.aspx
 */
function getSilverlightVersion() 
{ 
   var version = '0'; 
   var container = null; 
 
   try 
   { 
      var control = null; 
      var product = 'Silverlight'; 
 
      if (navigator.userAgent.indexOf("Linux") != -1) 
         product = "Silverlight (Moonlight)"; 
 
      if (window.ActiveXObject) 
         control = new ActiveXObject('AgControl.AgControl'); 
      else 
      { 
         if (navigator.plugins['Silverlight Plug-In']) 
         { 
            container = document.createElement('div'); 
            document.body.appendChild(container); 
            container.innerHTML = '<embed type="application/x-silverlight" src="data:," />'; 
            control = container.childNodes[0]; 
         } 
      } 
         
      if (control) 
      { 
         if (control.isVersionSupported('6.0')) 
            version = product + '/6.0'; 
         else if (control.isVersionSupported('5.0')) 
            version = product + '/5.0'; 
         else if (control.isVersionSupported('4.0')) 
            version = product + '/4.0'; 
         else if (control.isVersionSupported('3.0')) 
            version = product + '/3.0'; 
         else if (control.isVersionSupported('2.0')) 
            version = product + '/2.0'; 
         else if (control.isVersionSupported('1.0')) 
            version = product + '/1.0'; 
      } 
   } 
   catch (e) { } 
 
   if (container) 
      document.body.removeChild(container); 
 
   return version; 
}

function awstats_setCookie(TRKNameOfCookie, TRKvalue, TRKexpirehours) {
        var TRKExpireDate = new Date ();
        TRKExpireDate.setTime(TRKExpireDate.getTime() + (TRKexpirehours * 3600 * 1000));
        document.cookie = TRKNameOfCookie + "=" + escape(TRKvalue) + "; domain=" + cookie_path + "; path=/" + ((TRKexpirehours == null) ? "" : "; expires=" + TRKExpireDate.toGMTString());
}

function awstats_detectIE(TRKClassID) {
        TRKresult = false;
        document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n on error resume next \n TRKresult = IsObject(CreateObject("' + TRKClassID + '"))</SCR' + 'IPT>\n');
        if (TRKresult) return 'y';
        else return 'n';
}

function awstats_detectIE_flash_version() {
        version = "0";

        document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n');
        document.write('on error resume next\n');
        document.write('For i = 2 to 8\n');
        document.write('        If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then\n');
        document.write('        Else\n');
        document.write('               version = i\n');
        document.write('        End If\n');
        document.write('Next\n');
        document.write('</SCR' + 'IPT>\n');

        return version;
}

function awstats_detectNS_flash_version() {
        version = "0";
        x = navigator.plugins["Shockwave Flash"];
        if (x)
        {
                if (x.description)
                {
                        y = x.description;
                        version = y.charAt(y.indexOf('.')-1);
                }
        }
        return version;
}

function awstats_detectNS(TRKClassID) {
        TRKn = "n";
        if (TRKnse.indexOf(TRKClassID) != -1) if (navigator.mimeTypes[TRKClassID].enabledPlugin != null) TRKn = "y";
        return TRKn;
}

function awstats_getCookie(TRKNameOfCookie){
	if (document.cookie.length > 0){
		TRKbegin = document.cookie.indexOf(TRKNameOfCookie+"=");
	    if (TRKbegin != -1) {
			TRKbegin += TRKNameOfCookie.length+1; 
			TRKend = document.cookie.indexOf(";", TRKbegin);
			if (TRKend == -1) TRKend = document.cookie.length;
    	  	return unescape(document.cookie.substring(TRKbegin, TRKend));
		}
		return null; 
  	}
	return null; 
}

if (window.location.search == "" || window.location.search == "?") {
        // If no query string
        TRKnow = new Date();
        TRKscreen=screen.width+"x"+screen.height;
        if (navigator.appName != "Netscape") {TRKcdi=screen.colorDepth}
        else {TRKcdi=screen.pixelDepth};
        TRKjava=navigator.javaEnabled();
        
        var TRKagt=navigator.userAgent.toLowerCase();
        var TRKie  = (TRKagt.indexOf("msie") != -1);
        var TRKns  = (navigator.appName.indexOf("Netscape") != -1);
        var TRKwin = ((TRKagt.indexOf("win")!=-1) || (TRKagt.indexOf("32bit")!=-1));
        var TRKmac = (TRKagt.indexOf("mac")!=-1);

        // Detect the browser internal width and height
        if (document.documentElement && document.documentElement.clientWidth)
                TRKwinsize = document.documentElement.clientWidth + 'x' + document.documentElement.clientHeight;
        else if (document.body)
                TRKwinsize = document.body.clientWidth + 'x' + document.body.clientHeight;
        else
                TRKwinsize = window.innerWidth + 'x' + window.innerHeight;

        TRKflv = 0;
        if (TRKie && TRKwin) {
                var TRKshk = awstats_detectIE("SWCtl.SWCtl.1")

                var TRKfla = awstats_detectIE("ShockwaveFlash.ShockwaveFlash.1")
		if (typeof(flash_version) === 'undefined')
			flash_version = awstats_detectIE_flash_version();
                if (TRKfla=='y') TRKflv = flash_version;

                var TRKrp  = '?';
                var TRKwma = '?'; 
                var TRKpdf = 'n'; 
                if (awstats_detectIE("PDF.PdfCtrl.1") == 'y') { TRKpdf = 'y'; }
                if (awstats_detectIE('PDF.PdfCtrl.5') == 'y') { TRKpdf = 'y'; }
                if (awstats_detectIE('PDF.PdfCtrl.6') == 'y') { TRKpdf = 'y'; }
        }
        if (TRKns || !TRKwin) {
                TRKnse = ""; for (var TRKi=0;TRKi<navigator.mimeTypes.length;TRKi++) TRKnse += navigator.mimeTypes[TRKi].type.toLowerCase();
                var TRKshk = awstats_detectNS("application/x-director")

                var TRKfla = awstats_detectNS("application/x-shockwave-flash")

		if (typeof(flash_version) === 'undefined')
			flash_version = awstats_detectNS_flash_version();
                if (TRKfla=='y') TRKflv = flash_version;

                var TRKrp  = awstats_detectNS("audio/x-pn-realaudio-plugin")
                var TRKwma = awstats_detectNS("application/x-mplayer2")
                var TRKpdf = awstats_detectNS("application/pdf");
        }
	
	var flash_version_full = flash_ver['major'] +"."+ flash_ver['minor'] +"."+ flash_ver['rev'];
        var TRKsilverlight = getSilverlightVersion();
        
        var misc_txt =  '!!SCR:'+TRKscreen+'!!WIN:'+TRKwinsize+'!!CDI:'+TRKcdi+'!!JAVA:'+TRKjava+'!!SHK:'+TRKshk+
                        '!!FLA:'+TRKfla+'!!RPL:'+TRKrp+'!!WMA:'+TRKwma+'!!PDF:'+TRKpdf+
                        '!!IE:'+TRKie+'!!NS:'+TRKns+'!!WIN:'+TRKwin+'!!MAC:'+TRKmac+'!!FLV:'+TRKflv+'!!FLVFULL:'+flash_version_full+
                        '!!SVL:'+TRKsilverlight+'!!';
        awstats_setCookie("bit_misc", misc_txt, 9000);
}
