/* *****************************************************************************************************
	[Page Name]
		jsSniffer.js
	
	[Developer Notes]
		This page will verify that the user has not 'turned off' their browser's ability to allow
		cookies and run javascript code.  It will also confirm that the user is using at least a 4.0
		browser (either IE or Netscape).
		
	[Created]
		08 August 2000
		
	[Revision History]

***************************************************************************************************** */

/*
	Ultimate client-side JavaScript client sniff.
   	(C) Netscape Communications 1998.  Permission granted to reuse and distribute.
   	see: http://developer.netscape.com/docs/examples/javascript/browser_type.html
   	for full code
   	Revised 20 April 98 to add is.nav4up and is.ie4up (see below).
	
   	Everything you always wanted to know about your JavaScript client
   	but were afraid to ask ... "Is" is the constructor function for "is" object, 
   	which has properties indicating:
   	(1) browser vendor:
    	   is.nav, is.ie, is.opera
   	(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.ie3, is.ie4, is.ie4up
   	(4) JavaScript version number:
       	   is.js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
*/
function Is () {
   	// convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase()

    // *** BROWSER VERSION ***
    this.major = parseInt(navigator.appVersion)
    this.minor = parseFloat(navigator.appVersion)

    this.nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)))
    this.nav2 = (this.nav && (this.major == 2))
    this.nav3 = (this.nav && (this.major == 3))
    this.nav4 = (this.nav && (this.major == 4))
    this.nav4up = (this.nav && (this.major >= 4))
    this.navonly = (this.nav && (agt.indexOf(";nav") != -1))

    this.ie = (agt.indexOf("msie") != -1)
    this.ie3 = (this.ie && (this.major == 2))
    this.ie4 = (this.ie && (this.major == 4))
    this.ie4up = this.ie  && (this.major >= 4)

    this.opera = (agt.indexOf("opera") != -1)
    /* 
	   *** JAVASCRIPT VERSION CHECK *** 
       Useful to workaround Nav3 bug in which Nav3 loads SCRIPT LANGUAGE="JavaScript1.2".
	  
	   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.2 capable. Always check for JS version compatibility 
       with > or >=.
	*/
    if (this.nav2 || this.ie3) this.js = 1.0
    else if (this.nav3 || this.opera) this.js = 1.1
    else if (this.nav4 || this.ie4) this.js = 1.2
    else if ((this.nav && (this.minor > 4.05)) || (this.ie && (this.major > 4))) this.js = 1.2
    else this.js = 0.0 // HACK: always check for JS version with > or >=
}

// "Internal" function to return the decoded value of a cookie.
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

/*
   	Function to correct for 2.x Mac date bug.  Call this function to fix a date object prior
	to passing it to SetCookie. IMPORTANT:  This function should only be called *once* for
   	any given date object!
*/
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

/*
	Function to return the value of the cookie specified by "name". name - String object
	containing the cookie name. returns - String object containing the cookie value, or null if
	the cookie does not exist.
*/
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

/*
  	Function to create or update a cookie.
	name - String object containing the cookie name.
    value - String object containing the cookie value.  May contain any valid string characters.
	[expires] - Date object containing the expiration data of the cookie.  If omitted or null,
		expires the cookie at the end of the current session.
    [path] - String object indicating the path for which the cookie is valid. If omitted or null,
		uses the path of the calling document.
    [domain] - String object indicating the domain for which the cookie is valid.  If omitted or
		null, uses the domain of the calling document.
    [secure] - Boolean (true/false) value indicating whether cookie transmission requires a secure
		channel (HTTPS).  

	The first two parameters are required.  The others, if supplied, must be passed in the order
	listed above.  To omit an unused optional field, use null as a place holder.
*/
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

/*
  	Function to delete a cookie. (Sets expiration date to start of epoch)
	name -   String object containing the cookie name.
	path -   String object containing the path of the cookie to delete.  This MUST be the same as the
		path used to create the cookie, or null/omitted if no path was specified when creating the cookie.
    domain - String object containing the domain of the cookie to delete.  This MUST be the same as the
		domain used to create the cookie, or null/omitted if no domain was specified when creating the cookie.
*/
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

