/* ======================================================
-  Little Tiny Browser Detect (LT) version 1.0a August 23, 2004
-     written by mattgarvin@hotmail.com
-  (C)opyright Notice
-     This script may be used by anyone in any way so long 
-     as this comment in it's entirety -- especially my
-     email address ;) -- is not removed
-  Description
-     The purpose of this script is to have one external
-     javascript file that detects all of the important
-     browser information that web designers need to 
-     know, and to organize that info in an easy to use
-     manner.
-  UPDATED DEC.09,2003
-     Changed all "wm" references to "LT"
-  UPDATED DEC.12,2003
-    fixed bugs
-    
-    added firstvisitdate and datediff to CUSTOM cookie
-
-    datediff is set to 0, but in the future it will be the
-    number of days since this vist and the last visit
-
-    changed date format (now is "Dec 12, 2003"
========================================================= */

// -----------------------------------------------------------------
// FUNCTIONS
// -----------------------------------------------------------------

   // --------------------------------------------------------------
   // GETNUMBER returns a number from a string,
    function getNumber(xString,x)
   {
    var tempStr, newStr
    var allowedStr="0123456789."
    
    tempStr = ""
    newStr = ""
    
    for(j=0; j<= xString.length; j++)
    	{
    	 tempStr += xString.charAt(x+j)
    	}
    if(tempStr!="")
    	{
	  while((allowedStr.indexOf(xString.charAt(x)) != -1) && (x<xString.length))
	    {
	     newStr += xString.charAt(x)
	     x++
	    }
	}    
    	 
    return newStr	
   }
   
   // --------------------------------------------------------------
   // FINDSTRING returns the location of a string, or -1 
   // if not found	
    function findString(lookStr, inStr)
   {
    var tempStr, i, flag
    
    tempStr = ""
    flag = false
    i=0

    i = inStr.indexOf(lookStr)	
    if(i>-1) {i = i + lookStr.length }
    return i	   
   }	

   // --------------------------------------------------------------
   // DETECT PLUGIN
   // is the plugin present?
		     function detectPlugin(PluginType)
			{
			 var Found = false
			 tempVal = ""
			 
			     numPlugins = navigator.plugins.length;
			
			     for(i=0; i < numPlugins; i++)
			        {
			         tempVal = navigator.plugins[i].description.indexOf(PluginType)
			         if (tempVal > -1)
			         	Found = true
			        }
			 return Found       
			}


// -----------------------------------------------------------------
// MAIN PROGRAM begins
// -----------------------------------------------------------------

	// First, make a new object for which to attach
	// the browser properties

     	var LT = new Object();
	
	// LT Info
		
	LT.info = "1.0Aa"
	
	// Set all vars to 0

	LT.appName = 0		// These first 4 mirror the navigator object
	LT.appVersion = 0
	LT.platform = 0
	LT.userAgent = 0

	LT.Browser = "--"	// The name of the browser (--,IE,NN,OP)
	LT.FlashVersion = 0		// Flash version
	LT.QuicktimeVersion = 0	// Quicktime present? (1=yes, 0=no)
	LT.RealplayerVersion = 0	// Realplayer present? (1=yes, 0=no)
	LT.JSVersion = jsver   // Version of javascript
	LT.IP = ip	       // I.P. Address	

	
	isIE = false		// These are boolean values for browser names
	isNN = false		// (so you can check "is this browser IE?")
	isOP = false
	
	// First, mirror the navigator object properties

	LT.appName = navigator.appName
	LT.appVersion = navigator.appVersion
	LT.platform = navigator.platform
	LT.userAgent = navigator.userAgent
	
	
	if(findString("MSIE",LT.userAgent) > -1)
	   {
	    LT.Browser="IE"
	    isIE=true	
	   }
	if(navigator.appName=="Netscape")
	   {
	    LT.Browser="NN"
	    isNetscape=true
	   }

	if(findString("Opera",LT.userAgent) > -1)
	   {
	    LT.Browser="OP"
	    isOpera=true	
	   }

	if(LT.Browser=="IE")
		{
	  	 LT.Version = getNumber(LT.userAgent,findString("MSIE ",LT.userAgent))
		}

	if(LT.Browser=="NN")
		{
		 LT.Version = getNumber(LT.userAgent,findString("Mozilla/",LT.userAgent))
		 if(LT.Version>=5)
		 	{
		 	 LT.Version = getNumber(LT.userAgent,findString("Netscape",LT.userAgent)+2)	
		 	}	
		}

	if(LT.Browser=="OP")
		{
		 LT.Version = getNumber(LT.userAgent,findString("Opera ",LT.userAgent))
		}
		
	// Is JAVA enabled?
	navigator.javaEnabled() ? LT.java=1 : LT.java=0

	// Get verison of Javascript (It is AT LEAST verison 1.1
	// since it can handle external javascript)

	// PLUGIN DETECTION FOR NETSCAPE (and OPERA)
	// it must be Netscape, version 4 or later, on windows
	// OR opera, version 5.12+, on windows
	if( ((LT.Browser=="NN") && (LT.platform="Win32")) || ((LT.Browser=="OP") && (LT.Version>=4.02) && (LT.platform=="Win32")) )
	     {
		// FIRST CHECK FOR FLASH
		if(detectPlugin("Shockwave Flash 7") == true)
		   { LT.FlashVersion = 7 }
		else
		   {	
			if(detectPlugin("Shockwave Flash 6") == true)
			   { LT.FlashVersion = 6 }
			else
			   {
				if(detectPlugin("Shockwave Flash 5") == true)
				   { LT.FlashVersion = 5 }
				else
				   {
				    if(detectPlugin("Shockwave Flash 4") == true)
				 	{ LT.FlashVersion = 4 }		
				    else
					{
				         if(detectPlugin("Shockwave Flash 3") == true)
				             { LT.FlashVersion = 3 }		
					}
				   }
			    }		   
		    }	    
		// NOW CHECK FOR QUICKTIME
		if(detectPlugin("QuickTime Plugin") == true)
			{ LT.QuicktimeVersion = 1 }
		// NOW CHECK FOR REALPLAYER
		if(detectPlugin("RealPlayer(tm)") == true)
			{ LT.RealplayerVersion = 1 }
              }	

	// IE Plugin detection (using VBSCRIPT)
	if( (LT.Browser=="IE") && (LT.Version>=4.0) && (LT.platform=="Win32") )
	       {
	 	document.writeln('<SCRIPT LANGUAGE="VBSCRIPT" TYPE="TEXT/VBSCRIPT">')              
		document.writeln('	Function DetectObject(activeXname)')
		document.writeln('	  on error resume next')
		document.writeln('		FoundStatus = False')
		document.writeln('		FoundStatus = IsObject(CreateObject(activeXname))')
		document.writeln('		If (err) then')
		document.writeln('		   FoundStatus = False')
		document.writeln('		End If')
		document.writeln('	  DetectObject = FoundStatus')
		document.writeln('	End Function')	
		document.writeln(' 	PluginStatus = DetectObject("ShockwaveFlash.ShockwaveFlash.7")')
		document.writeln(' 	If PluginStatus = True Then')
		document.writeln(' 		LT.FlashVersion = 7')
		document.writeln('	Else')
		document.writeln(' 		PluginStatus = DetectObject("ShockwaveFlash.ShockwaveFlash.6")')
		document.writeln(' 		If PluginStatus = True Then')
		document.writeln(' 			LT.FlashVersion = 6')
		document.writeln('		Else')
		document.writeln(' 			PluginStatus = DetectObject("ShockwaveFlash.ShockwaveFlash.5")')
		document.writeln(' 				If PluginStatus = True Then')
		document.writeln(' 					LT.FlashVersion = 5')
		document.writeln('				Else')
		document.writeln('					PluginStatus = DetectObject("ShockwaveFlash.ShockwaveFlash.4")	')
		document.writeln('	 				If PluginStatus = True Then')
		document.writeln('	 					LT.FlashVersion = 4')
		document.writeln('					Else')
		document.writeln('						PluginStatus = DetectObject("ShockwaveFlash.ShockwaveFlash.3")')
		document.writeln('			 			If PluginStatus = True Then')
		document.writeln('			 				LT.FlashVersion = 3')
		document.writeln('						End If			')
		document.writeln('					End If')
		document.writeln('				End If')
		document.writeln('		End If')
		document.writeln('	End If')
		document.writeln(' 	PluginStatus = DetectObject("QuickTimeCheckObject.QuickTimeCheck")')
		document.writeln(' 	If PluginStatus = True Then')
		document.writeln(' 		LT.QuicktimeVersion = 1')
		document.writeln(' 	End If	')
		document.writeln(' 	PluginStatus = DetectObject("RealPlayer")')
		document.writeln(' 	If PluginStatus = True Then')
		document.writeln(' 		LT.RealplayerVersion = 1')
		document.writeln(' 	End If	')
		document.writeln('</SCRIPT>')
               }      
               
// SCREEN REZ Detection 

	LT.ScreenRez = 640
	if(jsver>=1.2)
		LT.ScreenRez = screen.width

// PLATFORM Detection
	if(jsver>=1.2)
		LT.OS = navigator.platform
	               
// Set empty values for whatever we couldn't glean
	if(LT.Browser == "")
		LT.Browser = "xx" 
	if(LT.Version == "")
		LT.Version = "0" 
	if(LT.jsver == "")
		LT.jsver = "0" 
	if(LT.FlashVersion == "")
		LT.FlashVersion = "0" 
	if(LT.QuicktimeVersion == "")
		LT.QuicktimeVersion = "0" 
	if(LT.RealplayerVersion == "")
		LT.RealplayerVersion = "0" 
	if(LT.ScreenRez == "")
		LT.ScreenRez = "640" 
	if(LT.OS == "")
		LT.OS = "Unknown" 
		

// Write Default cookie with the values!

	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() +1);																						
	document.cookie="default=" + LT.info + "^" + LT.Browser + "^" + LT.Version + "^" + jsver + "^" + LT.FlashVersion + "^" + LT.QuicktimeVersion + "^" + LT.RealplayerVersion + "^" + LT.ScreenRez + "^" + LT.OS + "^" + LT.IP + "; expires=" + nextyear.toGMTString();






// Examine Custom cookie with the values!

	 if(document.cookie!='')
	{
		m = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
		var cookie_array = document.cookie.split("; ")
	        var cookie_pair, cookie_val1, cookie_val2, counter, numvisits
	        var lastvisitdate, firstvisitdate, datediff
		var customFound = -1;
		
		for(counter = 0; counter < cookie_array.length; counter++)
		{
		 cookie_pair = cookie_array[counter].split("=")
		 if(cookie_pair[0]=='custom')
		 	{
			 customFound = counter;	
			 break	
			}
		}
		
		// If no CUSTOM cookie was found, write a fresh custom cookie!
		if(customFound != -1)
			{	
		 	 cookie_val2 = cookie_pair[1].split("^")
		 	 numvisits = parseInt(cookie_val2[0])
		 	 lastvisitdate = cookie_val2[1]
		 	 datediff = cookie_val2[2]
		 	 firstvisitdate = cookie_val2[3]		 	 
		 	 //alert('0]' + cookie_val2[0] + '\n1]' + cookie_val2[1]+ '\n2]' + cookie_val2[2]+ '\n3]' + cookie_val2[3])
		 	 
			 
			 // Is Today's Date Different than the one in the cookie?
			 var today = new Date()
			 var year = today.getYear();
				if (year < 2000)    
				year = year + 1900;
	                 var ThisDate = m[today.getMonth()] + "-" + today.getDate() + "-" + year;

	                 if(ThisDate != lastvisitdate)
	                 	{
	                 	 //alert('no date match\n0]' + cookie_val2[0] + '\n1]' + cookie_val2[1]+ '\n2]' + cookie_val2[2]+ '\n3]' + cookie_val2[3])	
	               	 	 var nextyear = new Date();
				 nextyear.setFullYear(nextyear.getFullYear() +1);
	                 	 numvisits++
	                 	 document.cookie="custom=" + numvisits + "^" + ThisDate + "^0^" + firstvisitdate + "; expires=" + nextyear.toGMTString();
	                 	} 	
			}	
		else
			{
				//alert('cookie yes, custom no!')
				var today = new Date()
				var ThisDate = m[today.getMonth()] + "-" + today.getDate() + "-" + today.getYear();		
			        document.cookie="custom=1^" + ThisDate + "^0^" + ThisDate +"; expires=" + nextyear.toGMTString();
			        // Note: This cookie is set with a ^ after tge equals because of the way it is
			        //       split later in /_includes/common_javascript.js
			}	
		
	}
	