/* 	RippleFX Copyright 2002 */
/*--------------------------------------------------------------------------
File:		rfx_detect.js
Author:		Tim Tomanik

Purpose:	This file provides services for browser and browser capability 
			detection.
			
Version:	1.01

Updates
Dec 15, 2002	Tim Tomanik		Added basic OS detection for Mac and Windows
April 11, 2002	Tim Tomanik		Completed initial version						
						
-----------------------------------------------------------------------------*/

_d = document;

var navID=0;	// Provides details as to the browers type and version
var	isIE=0;		// True if an IE browser
var	isNS=0;		// True if a NS browser
var isWC6=0;	// True if the browser uses getElementByID
var isDOM=0;
var isNS4=0;	// True if a NS 4.x browser
var isIE4=0;	// True if a IE 4.x browser
var isOp=0;		// True if an Opera browser
var isDyn=0;	
var isWin=0;	// True if a Windows machine
var isMac=0;	// True if a Macintosh machine

var debug=0;	//	Set to 1 or true to enable debugging output

Detect_Initialize();

//Initializes the detection this library supports	
function Detect_Initialize() {
	Detect_Browser();
	Detect_OS();
}

//Gets the Browser type and version information
function Detect_Browser () {
	var agt=navigator.userAgent.toLowerCase();
    var is_major=parseInt(navigator.appVersion);
   	var is_minor=parseFloat(navigator.appVersion);

	isDOM=_d.getElementById?1:0;
	isIE=_d.all?1:0;
	//isIE=(agt.indexOf("msie") != -1);		
	isIE4=isIE&&!isDOM?1:0;

	if((navID==0) && isIE) {
   		var is_IE3  = (isIE && (is_major < 4))?1:0;
		var msie_vers_start = agt.indexOf("msie")+5;
		var msie_real_vers = parseFloat(agt.substring(msie_vers_start, msie_vers_start+3));
	    var is_IE4  = (isIE && (is_major == 4) && (msie_real_vers < 5))?1:0;
	    var is_IE4up  = (isIE  && (is_major >= 4))?1:0;
    	var is_IE5  = (isIE && (is_major == 4) && (agt.indexOf("msie 5.")!=-1))?1:0;
	    var is_IE5up  = (isIE  && !is_IE3 && !is_IE4)?1:0;
		var is_IE6  = (isIE  && (is_major == 6))?1:0;
		if(is_IE3)
			navID="IE_3";
		if(is_IE4 && !is_IE4up)
			navID="IE_4";
		if(is_IE4 && is_IE4up)
			navID="IE_45";				
		if(is_IE5 && !is_IE5up) {
			navID="IE_5";
			isWC6=true;	}				
		if(is_IE5 && is_IE5up) {
			navID="IE_55";			
			isWC6=true;	}					
		if(is_IE6 || (navID==0)) {
			navID="IE_6";	
			isWC6=true;	}	
	}
    isNS =((agt.indexOf('mozilla')!=-1)&&(agt.indexOf('spoofer')==-1)&&(agt.indexOf('compatible') == -1)&&(agt.indexOf('opera')==-1)&&(agt.indexOf('webtv')==-1))?1:0;    
    isNS4 = navigator.appName=='Netscape'&&!isDOM?1:0;
	if((navID==0) && isNS) {
	    var is_nav3=(isNS && (is_major==3))?1:0;
	    var is_nav4=(isNS && (is_major==4))?1:0;
	    var is_nav4up=(isNS && (is_major>=4))?1:0;
	    var is_navonly=(isNS && ((agt.indexOf(";nav")!=-1) || (agt.indexOf("; nav")!= -1)) );
		var is_nav6=(isNS && (agt.indexOf('netscape6')!=-1))?1:0; 
	    var is_nav5=(isNS && (is_major == 5) && !(is_nav6))?1:0;
		if(is_nav3)
			navID="NS_3";
		if(is_nav4 && !is_nav4up)
			navID="NS_4";
		if(is_nav4 && is_nav4up)
			navID="NS_45";	
		if(is_nav5)
			navID="NS_5";
		if(is_nav6 || (navID==0)) {
			navID="NS_6";					
			isWC6=true;	}	
	}			
		
    var is_aol=(agt.indexOf("aol")!=-1);
	if((navID==0) && is_aol) {
    	var is_aol3=(is_aol && is_isIE3)?1:0;		
	    var is_aol4=(is_aol && is_isIE4)?1:0;
		if(is_aol3)
			navID="AOL_3";
		if(is_aol4)
			navID="AOL_4";
	}				
	
	isOp=window.opera?1:0;
	if(navID==0) {
    	var is_opera=(agt.indexOf("opera")!=-1)?1:0;
		if(is_opera)
			navID="OPERA";
	}
	if(navID==0) {
	    var is_webtv=(agt.indexOf("webtv")!=-1)?1:0;
		if(is_webtv)
			navID="WEBTV";
	}			
	if(navID==0) {
		navID="UNKOWN";
	}

	isDyn=isDOM||isIE||isNS4;
	if(debug)
		if(debugWin)		
			ReportMsg("NavID"+navID+" isIE" +isIE +" isIE4" +isIE4+" isNS"+isNS+" isNS4"+isNS4+" isOp"+isOp+" isDOM"+isDOM+" isDyn"+isDyn);	
}

//Get the Operating System information
function Detect_OS() {
	var agt=navigator.userAgent.toLowerCase();
    isWin=((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1))?1:0;
    isMac=(agt.indexOf("mac")!=-1)?1:0;
	if(debug)
		if(debugWin)	
			ReportMsg("isWin"+isWin+" isMac"+isMac);	
}
