/*
* File Name     : browser.js
* Dependencies  : none
* Description   : Comprehensive browser sniffing. 
*                 Creates a global variable gBrowser that contains all information about the user system.
* Version       : 1.2.1
* Date Modified : 8/9/2007
* Usage         : Copyright 2007 Craig Phares. All rights reserved.
*/

/*
* Name: BrowserInfo()
* Desc: saves all browser info into a global variable
*/
function BrowserInfo() {
	
	// get the app name and user agent
	var navAppName = navigator.appName.toLowerCase();
	var navUserAgent = navigator.userAgent.toLowerCase();
	
	// internet explorer
	if ((navAppName.indexOf("microsoft")>=0) && !(navUserAgent.indexOf("opera")>=0)) {
		
		this.ie = true; // using internet explorer
		
		// get the version
		var startPos = navUserAgent.indexOf("msie")+4; // sets string position
		this.majorVersion = parseInt(navUserAgent.substring(startPos));
		this.minorVersion = parseFloat(navUserAgent.substring(startPos+2));
		
		// set browser/version flag
		if (this.majorVersion == 6) this.ie6 = true;      // using internet explorer 6
		else if (this.majorVersion == 5) this.ie5 = true; // using internet explorer 5
		else if (this.majorVersion == 4) this.ie4 = true; // using internet explorer 4 
		else if (this.majorVersion == 3) this.ie3 = true; // using internet explorer 3
	
	// netscape
	} else if ((navAppName.indexOf("netscape")>=0) && !(navUserAgent.indexOf("opera")>=0) && !(navUserAgent.indexOf("safari")>=0)) {
	
		this.ns = true; // using netscape
		
		if (parseInt(navigator.appVersion) == 5) { // netscape 6 or 7
	
			if ((navAppName.indexOf("netscape")>=0) && !(navUserAgent.indexOf("aol")>=0)) { // netscape standalone

				// get the version
				var startPos = navUserAgent.indexOf("netscape") + 8; // sets string position
				if (navUserAgent.charAt(startPos) == "/") { // if string netscape/[n]
					this.majorVersion = parseInt(navUserAgent.substring(startPos+1));
					this.minorVersion = parseFloat(navUserAgent.substring(startPos+1));
	  			} else if (navUserAgent.charAt(startPos + 1) == "/") { // if string netscape[n]/[n]
					this.majorVersion = parseInt(navUserAgent.substring(startPos+2));
					this.minorVersion = parseFloat(navUserAgent.substring(startPos+2));
				} else { // if string netscape[n]
					this.majorVersion = parseInt(navUserAgent.substring(startPos)); 
					this.minorVersion = parseFloat(navUserAgent.substring(startPos+2)); 
				}
				
			} else if ((navAppName.indexOf("netscape")>=0) && (navUserAgent.indexOf("aol")>=0)) { // netscape aol
			
				// get the version
				var startPos = navUserAgent.indexOf("aol") + 3; // sets string position
				if (navUserAgent.charAt(start_pos) == "/") {// if string aol/[n]
					this.majorVersion = parseInt(navUserAgent.substring(startPos+1));
					this.minorVersion = parseFloat(navUserAgent.substring(startPos+3));
	  			}
			}
			
		} else if (parseInt(navigator.appVersion) == 4 || parseInt(navigator.appVersion) == 3) { // netscape 3 or 4
			this.majorVersion = parseInt(navigator.appVersion); 
			this.minorVersion = parseFloat(navigator.appVersion%1); 	 
		}
		
		if (this.majorVersion == 7) this.ns7 = true; // using netscape 7
		else if (this.majorVersion == 6) this.ns6 = true; // using netscape 6
		else if (this.majorVersion == 4) this.ns4 = true; // using netscape 4
		else if (this.majorVersion == 3) this.ns3 = true; // using netscape 3
		
	// safari
	} else if ((navUserAgent.indexOf("safari")>=0)) {
		
		this.safari = true;
		
		// get the version
		var startPos = navUserAgent.indexOf("safari/") + 7;
		this.majorVersion = parseInt(navUserAgent.substring(startPos));
		this.minorVersion = parseFloat(navUserAgent.substring(startPos+2));
	
		if (this.majorVersion == 85) this.safari85 = true; // using safari 1.0.3(v85.8)
		else if (this.majorVersion == 125) this.safari125 = true; // using safari 1.2.4(v125.11)
		
	// opera
	} else if (navUserAgent.indexOf("opera")>=0) {
		this.opera = true;
		var startPos = navUserAgent.indexOf("opera") + 6;
		this.majorVersion = parseInt(navUserAgent.substring(startPos));
		this.minorVersion = parseFloat(navUserAgent.substring(startPos+2));
		
		if (this.opera && this.majorVersion == 5) this.opera5 = true; // using opera 5
		else if (this.opera && this.majorVersion == 7) this.opera7 = true; // using opera 7
	}

	// identify platform
	var browserPlatform = navigator.platform.toLowerCase();
	if (browserPlatform.indexOf("win")>=0) this.win = true;
	else if (browserPlatform.indexOf("mac")>=0) this.mac = true;
	else this.win = true; // default to win platform if platform is not identified
	
}

// create the global browser info object
gBrowser = new BrowserInfo();





