
function SnifferObject(initExtras)
{

//http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
//and
//http://home.dobbelaere.com:7080/tim/client_sniffer.html
//JS: I added in Resolution Detection, cookies and popup detection
//and browser name and os name
//Requirements Checking

	    // convert all characters to lowercase to simplify testing
	    var agt=navigator.userAgent.toLowerCase();
	    //alert(agt);

		///////////////////////////////////////////////////////////////////////////
		//					RESOLUTION DETECTION							 	 //
		///////////////////////////////////////////////////////////////////////////
		this.screenheight=screen.height;
		this.availheight=screen.availHeight;
		this.screenwidth=screen.width;
		this.availwidth=screen.availWidth;
		this.colordepth=screen.colorDepth;
		this.pixeldepth=screen.pixelDepth;

		//set up defaults
		this.osOK=false;
		this.browserOK=false;
		this.os_name="";
		this.browser_name="";
		this.browser_version=1;
		this.unknown=false;

        
        if ((!agt) || (agt==""))
        {
            this.unknown=true;
            return;
        }


		///////////////////////////////////////////////////////////////////////////
		//					BROWSER DETECTION								 	 //
		///////////////////////////////////////////////////////////////////////////

	    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
	    this.is_major = parseInt(navigator.appVersion);
	    this.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.
	    this.is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	                && (agt.indexOf('compatible') == -1) && (agt.indexOf('hotjava')==-1));
	    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_major >= 4));
	    this.is_navonly      = (this.is_nav && ((agt.indexOf(";nav") != -1) ||
	                          (agt.indexOf("; nav") != -1)) );
	    this.is_nav5 = (this.is_nav && (this.is_major == 5));
	    this.is_nav5up = (this.is_nav && (this.is_major >= 5));
	    this.is_nav6 = (this.is_nav && (this.is_major == 6));
	    this.is_nav6up = (this.is_nav && (this.is_major >= 6));
	    this.is_nav7 = (this.is_nav && (this.is_major == 7));
	    this.is_nav7up = (this.is_nav && (this.is_major >= 7));

		if (this.is_nav)
		{
			if (agt.indexOf("netscape6") != -1)
		        this.browser_version = parseFloat(agt.substring( agt.indexOf('netscape') + 10 ) );
			else
		        this.browser_version = parseFloat(agt.substring( agt.indexOf('netscape') + 9 ) );
			this.browser_name="Netscape Navigator " + this.browser_version;
		}

		this.is_chrome = (agt.indexOf("chrome") != -1);
		if (this.is_chrome) {
		    this.browser_name = "Chrome";

		    this.is_safari = false; // Chrome's UserAgent also says Safari
		}
		else {
		    this.is_safari = (agt.indexOf('safari') != -1);
		    if (this.is_safari) {
		        //this.browser_version = parseFloat(agt.substring( agt.indexOf('safari') + 6 ) );
		        this.browser_name = "Safari"// + this.browser_version;
		    }
		}
		this.is_safari3exact = this.is_safari && (agt.indexOf("version/3 ") > -1)
		this.is_safari3up = this.is_safari && (agt.indexOf("version/3") > -1 || agt.indexOf("version/4") > -1 || agt.indexOf("version/5") > -1)
		
	    this.is_gecko = (agt.indexOf('gecko') != -1);
	    this.is_firefox = (agt.indexOf("firefox") != -1);
	    if (this.is_firefox)
	    {
	        this.browser_name = "Firefox";
	    }
	    this.is_firefox3 = this.is_firefox && (agt.indexOf("firefox/3") != -1);
	    this.is_firefox2 = this.is_firefox && (agt.indexOf("firefox/2") != -1);
	    this.is_firefox2up = this.is_firefox2 || this.is_firefox3;

	    this.is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	   	this.is_ie3    = (this.is_ie && (this.is_major < 4));
	    this.is_ie4    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	    this.is_ie4up  = (this.is_ie && (this.is_major >= 4));
	    this.is_ie5    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	    this.is_ie5_5  = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	    this.is_ie5up  = (this.is_ie && !this.is_ie3 && !this.is_ie4);
	    this.is_ie5_5up =(this.is_ie && !this.is_ie3 && !this.is_ie4 && !this.is_ie5);
	    this.is_ie6    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	    this.is_ie6up  = (this.is_ie && !this.is_ie3 && !this.is_ie4 && !this.is_ie5 && !this.is_ie5_5 && !this.is_ie6);

	    if (this.is_ie)
	    {
			this.browser_name="Internet Explorer";
			if (this.is_ie3)
			{
				this.browser_version=3;
				this.browser_name=this.browser_name + " 3";
			}
			if (this.is_ie4)
			{
				this.browser_version=4;
				this.browser_name=this.browser_name + " 4";
			}
			if (this.is_ie5)
			{
				this.browser_version=5;
				this.browser_name=this.browser_name + " 5";
			}
			if (this.is_ie5_5)
			{
				this.browser_version=5.5;
				this.browser_name=this.browser_name + " 5.5";
			}
			if (this.is_ie6)
			{
				this.browser_version=6;
				this.browser_name=this.browser_name + " 6";
			}
			if (this.is_ie6up)
			{
				this.browser_version=7;
				this.browser_name=this.browser_name + " 6 +";
			}
		}
	
	    // 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.
	    this.is_aol   = (agt.indexOf("aol") != -1);
	    this.is_aol3  = (this.is_aol && is_ie3);
	    this.is_aol4  = (this.is_aol && is_ie4);
	    this.is_aol5  = (agt.indexOf("aol 5") != -1);
	    this.is_aol6  = (agt.indexOf("aol 6") != -1);
	    if (this.is_aol)
	    {
	    	this.browser_name="AOL";
	    	if (this.is_aol3)
    			this.browser_name=this.browser_name + " 3";
	    	if (this.is_aol4)
    			this.browser_name=this.browser_name + " 4";
	    	if (this.is_aol5)
    			this.browser_name=this.browser_name + " 5";
	    	if (this.is_aol6)
    			this.browser_name=this.browser_name + " 6";
	    }

	    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_opera5up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4);
	    if (this.is_opera)
	    {
	    	this.browser_name="Opera";
	    	if (this.is_opera2)
    			this.browser_name=this.browser_name + " 2";
	    	if (this.is_opera3)
    			this.browser_name=this.browser_name + " 3";
	    	if (this.is_opera4)
    			this.browser_name=this.browser_name + " 4";
	    	if (this.is_opera5)
    			this.browser_name=this.browser_name + " 5";
	    	if (this.is_opera5up)
    			this.browser_name=this.browser_name + " 5 +";

	    }

	    this.is_webtv = (agt.indexOf("webtv") != -1); 
	    if (this.is_webtv)
	    {
	    	this.browser_name="WebTV";
	    }
	
	    this.is_hotjava = (agt.indexOf("hotjava") != -1);
	    if (this.is_hotjava)
	    {
	    	this.browser_name="HotJava";
	    }

	
		///////////////////////////////////////////////////////////////////////////
		//					OS DETECTION									 	 //
		///////////////////////////////////////////////////////////////////////////
	    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));
		this.os_name="Windows 95";
	    // 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.os_name="Windows 3.1";	
	    this.is_winme = ((agt.indexOf("win 9x 4.90")!=-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".
	    this.is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
		if (this.is_win98)
			this.os_name="Windows 98";
			
		this.is_winme= ((agt.indexOf("winme")!=-1) || (navigator.userAgent.indexOf("windows me")!=-1));
		if (this.is_winme)
			this.os_name="Windows ME";

	    this.is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1)
	    				&& (agt.indexOf("windows nt 5.1")==-1));
	    if (this.is_winnt)
			this.os_name="Windows NT";

	    this.is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));
	    if (this.is_win2k)
			this.os_name="Windows 2000";

	    this.is_winxp = (agt.indexOf("windows nt 5.1")!=-1);
	    
		if (this.is_winxp)
			this.os_name="Windows XP SP1";

		this.is_winxpsp2=(this.is_winxp && (agt.indexOf("sv1")!=-1));
		if (this.is_winxpsp2)
			this.os_name="Windows XP SP2";
			
	    this.is_winvista = ((agt.indexOf("windows nt 6.0")!=-1));
	    if (this.is_winvista )
			  this.os_name="Windows Vista";

	    this.is_win7 = ((agt.indexOf("windows nt 6.1") != -1));
	    if (this.is_win7)
	        this.os_name = "Windows 7";
			  			
		this.is_winXPplus = "";

//Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.2
//Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20050519 Netscape/8.0.1
//Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607) Netscape/8.0.1 
//Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607) 


		//TO DO: finish adding OS names
	    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));
	    if (this.is_os2)
	    	this.os_name="OS/2";

	    this.is_mac    = (agt.indexOf("mac")!=-1);
		this.macosx = (this.macos && ((agt.indexOf("os x") != -1) ||
                                  (agt.indexOf("osx") != -1)));
        if (this.macosx)
        	this.os_name="Mac OS X";

		// hack ie5 js version for mac
	    if (this.is_mac && this.is_ie5up) this.is_js = 1.4;
	    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)));
	    if (this.is_macppc)
	    	this.os_name="Mac OS 10.x";

	   	this.is_Mac1039=((this.is_mac) && (agt.indexOf("10.3.9"!=-1)))
	   	this.is_Mac1025=((this.is_mac) && (agt.indexOf("10.2.5"!=-1)))
	   	this.is_Mac102up=((this.is_mac) && (agt.indexOf("10.2"!=-1)))
	   	this.is_Mac10up=((this.is_mac) && (agt.indexOf("10."!=-1)))
	   	this.is_Mac92up=((this.is_mac) && ((agt.indexOf("9.2"!=-1)) || (agt.indexOf("10."!=-1)) || (this.macosx)))

	    this.is_sun   = (agt.indexOf("sunos")!=-1);
	    this.is_irix  = (agt.indexOf("irix") !=-1);    // SGI
	    this.is_hpux  = (agt.indexOf("hp-ux")!=-1);
	    this.is_aix   = (agt.indexOf("aix") !=-1);      // IBM
	    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);
	    if (this.is_unix)
	    	this.os_name="Unix";
	    if (this.is_linux)
	    	this.os_name="Linux";

	    this.is_redhatlinux=((this.is_linux) && (agt.indexOf("redhat")!=-1));
	   	this.is_redhat72=((this.is_redhatlinux) && (agt.indexOf("7.2"!=-1)))
	   	this.is_redhat8=((this.is_redhatlinux) && (agt.indexOf("8"!=-1)))

	    this.is_redhatlinux72up=(this.is_redhatlinux) && ((this.is_redhat72) || (this.is_redhat8))


	    if (this.os_name=="")
		{
			this.os_name="UnKnown";
			this.unknown=true;
	    }
	    if (this.browser_name=="")
	    {
			this.browser_name="UnKnown";
			this.unknown=true;
	    }

	    if (initExtras)
	    {
			///////////////////////////////////////////////////////////////////////////
			//					COOKIES DETECTION									 //
			///////////////////////////////////////////////////////////////////////////
			this.allowscookies=TestCookies();
			
			///////////////////////////////////////////////////////////////////////////
			//					POPUP DETECTION								 		 //
			///////////////////////////////////////////////////////////////////////////
			this.allowspopups=TestPopUps();
		}

}

function checkIE() 
{
    if (this.is_mac)
        return false;
	return (this.is_ie6up || this.is_ie6);
	 //|| this.is_ie5_5
}

function checkFirefox()
{
    return this.is_firefox2up; //this.is_gecko;  
    //can't use just gecko..it matches Netscape and versions we are trying to block
}

function checkSafari() 
{
    // disallow 3.0 and lower
    return this.is_safari3up && !this.is_safari3exact; //this.is_gecko;  
    //can't use just gecko..it matches Netscape and versions we are trying to block
}

function checkChrome() {
    return this.is_chrome;
}

function checkNET()
{
	return (this.is_nav) && (this.browser_version >= 7) && (this.browser_version!=8) && (this.browser_version!=7.1); 
}
function checkNET7()
{
	return (this.is_nav) && (this.browser_version >= 7) && (this.browser_version!=8) && (this.browser_version!=8) && (this.browser_version!=7.1); 
}
function checkNET6to8()
{
	return (this.is_nav) && (this.browser_version >= 6.2) && (this.browser_version < 8); 
}
function checkWIN()
{
	return (this.is_win98 || this.is_winme || this.is_winnt || this.is_winxp || this.is_winxpsp2 || this.is_win2k || this.is_winvista || this.iswin7);
}

function checkWIN2000()
{
    return (this.is_winnt || this.is_winxp || this.is_winxpsp2 || this.is_win2k || this.is_winvista || this.iswin7);
}
function checkMAC()
{
	//Mac OS 10.2.5* and 10.3.9*
	//return (this.is_Mac102up || this.is_Mac10up || this.is_macppc || this.macosx);
	return (this.is_Mac1039 || this.is_Mac1025);

}
function checkLINUX()
{
	//RedHat Linux v7.2**
	return this.is_redhatlinux72up;
}

SnifferObject.prototype.checkIE=checkIE;
SnifferObject.prototype.checkNET=checkNET;
SnifferObject.prototype.checkNET7=checkNET7;
SnifferObject.prototype.checkFirefox=checkFirefox;
SnifferObject.prototype.checkSafari=checkSafari;
SnifferObject.prototype.checkChrome=checkChrome;
SnifferObject.prototype.checkWIN=checkWIN;
SnifferObject.prototype.checkWIN2000=checkWIN2000;
SnifferObject.prototype.checkMAC=checkMAC;
SnifferObject.prototype.checkLINUX=checkLINUX;
SnifferObject.prototype.checkNET6to8=checkNET6to8;


function check_WinIE()
{

	var os=this.checkWIN();
	var brows=this.checkIE();

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;
}

function check_WinIENS()
{

	var os=this.checkWIN();
	var brows=this.checkIE() || this.checkNET();

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;	
}


function check_WinIENS72Only()
{
    
	var os=this.checkWIN();
	var brows=this.checkIE() || (this.checkNET7() && this.browser_version!=7.1);

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;	
	
}

function check_WinIENS7()
{

	var os=this.checkWIN();
	var brows=this.checkIE() || this.checkNET7();

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;	
}

function check_WinIENSMacLinux()
{

	var os=(this.checkWIN() || this.checkMAC() || this.checkLINUX());
	var brows=(this.checkIE() || this.checkNET());

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;	

}

function check_ABOnlyMacWindows()
{
	var os=(this.checkWIN2000() || this.is_Mac92up);
	var brows=(this.checkIE() || this.checkNET6to8());

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;	
	
}

function check_All()
{

	var os=(this.checkWIN() || this.checkMAC() || this.checkLINUX());
	var brows=(this.checkIE() || this.checkNET() || this.checkFirefox() || this.checkSafari() || this.checkChrome());

	if (os)
		this.osOK=true;
	if (brows)
		this.browserOK=true;
}

function anyMAC()
{
    return ((this.is_mac) || (this.macosx) || (this.is_mac68k) || (this.is_macppc) || (this.is_mac68k))
}

SnifferObject.prototype.anyMAC=anyMAC;
SnifferObject.prototype.check_WinIE=check_WinIE;
SnifferObject.prototype.check_WinIENS=check_WinIENS;
SnifferObject.prototype.check_WinIENS7=check_WinIENS7;
SnifferObject.prototype.check_WinIENSMacLinux=check_WinIENSMacLinux;
SnifferObject.prototype.check_All=check_All;
SnifferObject.prototype.check_WinIENS72Only=check_WinIENS72Only;
SnifferObject.prototype.check_ABOnlyMacWindows=check_ABOnlyMacWindows;


function UnKnownBrowser()
{
	var bdetect = new SnifferObject(false);
	return bdetect.unknown;
}

function TestBrowser()
{
	var bdetect = new SnifferObject(false);
	bdetect.check_All();
	return bdetect.browserOK;
}

function TestCookies()
{
   var bdetect = new SnifferObject(false);
   bdetect.check_All();

   // Safari doesn't work with client-side cookies set after text rendered, have to read a server-side one
   if (bdetect.is_safari)
   {
     chkcookie = "chkcookie_IPRO";
   }
   else
   {
     var tmpcookie = new Date();
     chkcookie = (tmpcookie.getTime() + '_IPRO');
     document.cookie = "chkcookie=" + chkcookie + "; path=/";
   }
   
   if (document.cookie.indexOf(chkcookie,0) < 0) 
   {
   	return false;
   }
   else 
   {
   	return true;
   }
}

function TestPopUps()
{
	var tmppopup;
    tmppopup = window.open("/blank.htm",'testpopups',"resizable=no,height=1,width=1,scrollbars=no");
	if (tmppopup != null && ! tmppopup.closed)
	{
    	tmppopup.close();
    	return true;
    }
    else
    {
    	return false;
    }
}


function doDetectPopups()
{
	var back=location;
	back=escape(back);
	var allowPopups=TestPopUps();

	if (!allowPopups)
		location="../Info/Detect.aspx?detecttype=3&redirect=" + back;
}

function doDetectCookies()
{
	var back=location;
	back=escape(back);

	var allowCookies=TestCookies();

	if (!allowCookies)
		location="../Info/Detect.aspx?detecttype=2&redirect=" + back;
}

function doDetectBoth()
{
	var back=location;
	back=escape(back);
	var allowPopups=TestPopUps();
	var allowCookies=TestCookies();

	if ((!allowPopups) || (!allowCookies))
		location="../Info/Detect.aspx?detecttype=1&redirect=" + back;
}

