/* **** This file permanently resides at <http://mikaels.net/archives/public/application/x-javascript/ua/v3.3/ua.3_3_1.js>
  
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Netscape code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2001
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Bob Clary <bclary@netscape.com>
 *		   Lars P M <larspeemm@netscape.net>

 * This script source file is a Contributor Version of the script source file 
 * formerly located at <http://devedge.netscape.com/toolbox/examples/2002/xb/ua/ua.js> 
 * but then moved to <http://devedge-temp.mozilla.org/toolbox/examples/2002/xb/ua/ua.js>

 * This version (v3.3.1) was published 2007-05-20. 
 * The latest version is named /ua.js/ and located in the same directory.
    
 * The Modifications of the Original Code are documented in the uajs_modifications.html file
 * located at <http://mikaels.net/records/memo/html3/uajs_modifications.html>

 * This file should be safe with all known versions of JavaScript counting from 1.0. 
 * **** */

function getVersion(sPV){
//NOTE: This function requires JS1.1
//conversion from a version string to a numeric version
var Z = 0 , R = new Array('.','_',',','-');
   for (var j=0;j<4;j++){
    var x=R[j];
    if (sPV.indexOf(x) > -1){sPV=sPV.split(x);break}
    else sPV=sPV+'-'
    }

    if(sPV.length>=2 && sPV[1]!=''){
    	var exp     = 1;

    	for (var k = 0; k < sPV.length; k++)
    	{
      	var val = parseInt(sPV[k]);
      	Z += val / exp;
      	exp *= 100;
    	}
    	}
 
    else {
	Z='';
    	for (var k=1;k<sPV.length;k++){
    	var y=sPV[k]; Z+=y;}
	Z=parseFloat('0'+sPV[0]+'.'+Z)
    	}

return Math.round(Z*1000000)/1000000;
}

function xbDetectBrowser()
{
  var oldOnError = window.onerror;

  window.onerror = null;
  
  var nVersion = 0.01 , sPVersion = '0.01';
  var appV = window.navigator.appVersion;
  navigator['version']  = parseFloat(appV);
  navigator['family']  = '';

  var i = 0;
  var uAg = window.navigator.userAgent;
  var ua = uAg.toLowerCase();
  
  var sPName = window.navigator.appCodeName;
  navigator['prettyVersion'] = ''; var i=uAg.indexOf('/')
  if (i>-1){ 
  	sPName = uAg.substring(0,i); 
  	var sb = uAg.substring(i+1)+' ';
	navigator.prettyVersion=sb.substring(0, sb.indexOf(' '))
  	}
  var appN = window.navigator.appName;

  //decision on the browser kinship, simplifying Internet Explorer for safer checkings
  if (appN == 'Microsoft Internet Explorer') navigator['kin'] = 'MSIE/'+parseInt(appV, 10);
  else navigator['kin'] = appN+'/'+parseInt(appV, 10);

  //preliminary decision on the browser engine, trying to use navigator.product
  if (navigator.product) navigator.family = navigator.product.toLowerCase();
  if (navigator.productSub) navigator.version = parseFloat(navigator.productSub);
  navigator['rversion'] = 0; navigator['rv'] = '';
  navigator['js'] = 0; var JScript = '';

  //identifying JS1.0 browsers
  if (!Array('test')) navigator.js = 1.0

  if (ua.indexOf("khtml") != -1 || ua.indexOf("konqueror") != -1 || ua.indexOf("applewebkit") != -1)
  { //KDE products
    if( ua.indexOf('applewebkit') != -1 )
    { //OmniWeb and Safari is part of the AppleWebKit family
        i = ua.indexOf('applewebkit');
        navigator.family = 'applewebkit'; 
        navigator.version = parseFloat('0' + ua.substring(i+12));
        if (navigator.js==0){ 
    	  //the version property is the AppleWebKit build version converted to double floating points
          navigator.version = getVersion(ua.substring(i+12,ua.indexOf('(khtml')-1))
          }
    	if( ua.indexOf("omniweb") != -1 )
    	{
        sPName = 'omniWeb';
        sPVersion = ua.substring(ua.lastIndexOf('/')+2); 
    	}
    	else if( ua.indexOf('safari/') != -1 )
    	{
        sPName = 'safari';
        sPVersion = ua.substring(ua.lastIndexOf('/')+1); 
    	}
    }
    else if( ua.indexOf("konqueror") != -1 )
    { //Konqueror
        i = ua.indexOf('konqueror');
        sPName = 'konqueror'; 
    	sPVersion = ua.substring(i+10);
    }
  }

  else if (navigator.family == 'gecko')
  { //Gecko products
    	if (ua.indexOf("rv:") != -1)
    	{
    	var rvStart = ua.indexOf('rv:');
    	var rvEnd   = ua.indexOf(')', rvStart);
    	var rv      = ua.substring(rvStart+3, rvEnd);
    	//navigator.rv is the original string (e.g. "1.9.0.1")
    	navigator.rv = rv;
    	//the rversion property is the /rv/ converted to double floating points (e.g. 1.090001)
    	navigator.rversion = getVersion(rv);
    	}

    	if (ua.indexOf("galeon") != -1 )
    	{
        sPName = 'galeon';
        sPVersion = ua.substring(ua.indexOf('galeon') + 7);
    	}
    	//according to the proposal at http://www.mozilla.org/build/revised-user-agent-strings.html
    	else if (ua.indexOf('mozilla') != -1 && ua.lastIndexOf('/')-5 != ua.indexOf('gecko') && ua.lastIndexOf('/')-7 != 0)
    	{ //branded browsers based on Mozilla
        sPName = uAg.substring(ua.indexOf('gecko')+15,ua.lastIndexOf('/'));
        sPVersion = ua.substring(ua.lastIndexOf('/')+1); 
    	} 
	else if (ua.indexOf("msie") != -1) 
	{ //making version number spoof friendly 	
	navigator.prettyVersion=ua.substring(ua.indexOf("msie") + 5, ua.indexOf("msie") + 8)
	} 
  }

  else if (ua.indexOf('opera') != -1)
  { //Opera products
    i = ua.indexOf('opera');
    navigator.family  = 'opera';
    sPName    = 'opera';
    sPVersion = ua.substring(i+6);
    navigator.version  = parseFloat('0' + sPVersion);
    if (navigator.version >= 7) navigator.family = 'presto';
  }

  else if (ua.indexOf('compatible') != -1 && ua.indexOf('msie') != -1)
  { //Internet Explorer and the Trident rendering engine
    i = ua.indexOf('msie')
    sPName = 'internet Explorer'; 
    sPVersion = ua.substring(i+5);
    if (navigator.version < 4)
    	{ //IE 3
      	navigator.family = 'ie3';
   	  if(navigator.js > 0) JScript = '1.0';
    	  else JScript = '2.0';
    	}
    else  if (window.clientInformation)
    	{ //IE 4
      	navigator.family = 'ie4';
	  JScript = '3.0';
	  if (typeof(ScriptEngine) =='function'){
	  JScript = ScriptEngineMajorVersion() + ".";
	  JScript += ScriptEngineMinorVersion();
	  }
   	if 	(ua.indexOf('netscape') != -1) 
    		{ //Netscape Browser
      		sPName = 'netscape'; 
      		sPVersion = ua.substring(ua.indexOf('netscape')+9);
      		}
    	else if (ua.indexOf('america online browser') != -1)
    		{ //AOL
    		sPName = 'aOL Explorer';
    		sPVersion = ua.substring(ua.indexOf('rev')+3);
    		}
      	}
	//the version adapted to navigator.engine
    	  navigator.version  = parseFloat('0' + JScript);
  }

  else if (ua.indexOf("icab") != -1 )
  {
    sPName = " iCab";
    sPVersion = ua.substring(ua.indexOf("icab") + 5);
  }
  
  else if (ua.indexOf('java') != -1 )
  { //NOTE: no corresponding version set to the java family
    navigator.family  = 'java';
    if (ua.indexOf('ice') != -1 )
    { // ICEbrowser
    sPName = appN;
    sPVersion = ua.substring(ua.indexOf('/') + 2);
    }
    else if (ua.indexOf('hotjava') != -1 )
    { // HotJava
    sPName = 'hotJava';
    }
  }

  else if ((ua.indexOf('mozilla') == 0) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv')==-1) && (ua.indexOf('gecko')==-1))
  { //Netscape Navigator and Communicator
    i = ua.lastIndexOf('/');
    navigator.family = 'nn' + parseInt(appV, 10);
    sPName = 'netscape';
    sPVersion = ua.substring(i+1);
  }

  //We need to convert version strings into numbers and a pretty look, thereby calling a predefined function. 
  if (navigator.js != 1.0){
	nVersion= getVersion(sPVersion); 
	//decision on the pretty version string
	var R = new Array(';',')',' ','(');
   	for (var j=0;j<4;j++){
    	var x=R[j];
    	if (sPVersion.indexOf(x) > -1){sPVersion=sPVersion.substring(0, sPVersion.indexOf(x))}
    	}
	if (nVersion != 0.01) navigator.prettyVersion = sPVersion;


//JavaScript Client-Side language and ECMAScript Core language check  
//make global variables
  navigator_examined = new Array(3); navigator_examined[0] = parseFloat('0'+JScript);
  js1_1 = (typeof(Date.prototype.getTimezoneOffset));  //checking core syntax


if (js1_1 && ((navigator_examined[0] >= 2) || (typeof(navigator.javaEnabled) !='undefined')) &&
        (typeof(navigator.mimeTypes) !='undefined') && (typeof(navigator.plugins) !='undefined')){
        navigator.js = 1.1;
        }  //checking client-side scripting

if (navigator.js == 1.1 && 
        (typeof(navigator.language) != 'undefined' || typeof(navigator.userLanguage) != 'undefined' 
        || typeof(navigator.browserLanguage) != 'undefined') && (typeof(navigator.platform) != 'undefined')
        && (typeof(screen) != 'undefined') && (typeof(screen) != 'null')){
        navigator.js = 1.2;
        }  //checking client-side scripting and if appliable for the envir object

navigator_examined[1] = false;  //preparing to check ECMAScript edition 1
navigator_examined[2] = false; //preparing to check ECMAScript edition 3
if (js1_1){ delete js1_1; navigator_examined[1] = /* checking core scripting */
        (typeof(js1_1) == 'undefined' && (typeof(Infinity) =='number') && (typeof(NaN) =='number') && 
        (typeof(isFinite) !='undefined') && (typeof(Date.prototype.getMilliseconds) !='undefined') && 
        (typeof(Date.prototype.setFullYear) !='undefined') && (typeof(Date.prototype.toUTCString) !='undefined') && 
        (typeof(arguments) !='null'));
        }  

        //checking advanced methods of functions; NOTE that getVersion was defined far above
var FMethods = (typeof(getVersion.call) !='undefined' && typeof(getVersion.apply) !='undefined');
if (FMethods && navigator_examined[1]){ navigator_examined[2] = /* checking core scripting */
        (typeof(Error) != 'undefined') && (typeof(Number.prototype.toExponential) =='function') &&
        (typeof(Number.prototype.toFixed) =='function') && (typeof(Number.prototype.toPrecision) =='function');
        if (navigator.js == 1.2) navigator.js = 1.3;    
        }  //checking client-side scripting
//The check for js 1.5 might cause a syntax error with old browsers and is not included

}  //end of not js1.0 clause

//pretty names
var prettyfirst=sPName.charAt(0).toUpperCase();
navigator.prettyName=prettyfirst+sPName.substring(1);
  if (nVersion == 0.01 && navigator.family=='gecko')
	{ //correcting pretty names and versions
	if (navigator.rv.length > 0){navigator.prettyVersion = navigator.rv}
 	else if (ua.indexOf("msie") != -1){navigator.prettyName='Internet Explorer'}
 	}

//setting of navigator.engine to comply with uax.js set properties
navigator.family=='ie4'?navigator.engine='trident':navigator.engine=navigator.family;


  window.onerror = oldOnError;
}

xbDetectBrowser();
