// idbrowser.js
// Identify platform, browser, and browser version
// Produces an object "bd" with the following fields: 
// bd.platform => Win , Mac , Unix , Unknown
// bd.browser => Safari, Konqueror , Opera , MSIE , Netscape , Mozilla , Gecko, Unknown
// bd.version => M.N
// bd.majorver => M
// bd.minorver => N

function BrowserDetector()
{
// Initialize local vars
  this.platform = "Unknown";
  this.browser = "Unknown";
  this.version = "0";
  this.majorver = "0";
  this.minorver = "0";
  i = 0;

// Determine platform
rex1 = new RegExp(".*Win.*", "g"); // Microsoft Windows
rex2 = new RegExp(".*Mac.*", "g"); // Apple Macintosh
rex3 = new RegExp(".*X11.*", "g"); // Unix or Linux
rex3b = new RegExp(".*Linux.*", "g"); // Unix or Linux

if ( navigator.userAgent.match(rex1) ) {
	this.platform = "Win"; // Microsoft Windows
}
else if ( navigator.userAgent.match(rex2) ) {
	this.platform = "Mac"; // Apple Macintosh
}
else if ( navigator.userAgent.match(rex3) || navigator.userAgent.match(rex3b) ) {
	this.platform = "Unix"; // Unix or Linux
}
else {
	this.platform = "Unknown";
}; 


// Determine browser
re6 = new RegExp(".*Safari.*", "g");
re5 = new RegExp(".*Konqueror.*", "g");
re4 = new RegExp(".*Opera.*", "g");
re1 = new RegExp(".*MSIE.*", "g");
re0 = new RegExp(".*Mozilla.*", "g");
re0b = new RegExp(".*Gecko/.*", "g");

if ( navigator.userAgent.match(re6) ) {
	this.browser = "Safari";
	i = navigator.userAgent.indexOf("Safari") + "Safari".length + 1; 
	this.version = navigator.userAgent.substring(i, i + 3);
	this.majorver = "Unknown";
	this.minorver = "Unknown";
}
else if ( navigator.userAgent.match(re5) ) {
	this.browser = "Konqueror";
	i = navigator.userAgent.indexOf("Konqueror") + "Konqueror".length + 1; 
	this.version = navigator.userAgent.substring(i, i + 3);
	this.majorver = navigator.userAgent.substring(i, i + 1);
	this.minorver = navigator.userAgent.substring(i + 2, i + 3);
}
else if ( navigator.userAgent.match(re4) ) {
	this.browser = "Opera";
	i = navigator.userAgent.indexOf("Opera") + "Opera".length + 1; 
	this.version = navigator.userAgent.substring(i, i + 3);
	this.majorver = navigator.userAgent.substring(i, i + 1);
	this.minorver = navigator.userAgent.substring(i + 2, i + 3);

}
else if ( navigator.userAgent.match(re1) ) {
	this.browser = "MSIE";
	i = navigator.userAgent.indexOf("MSIE") + "MSIE".length + 1; 
	this.version = navigator.userAgent.substring(i, i + 3);
	this.majorver = navigator.userAgent.substring(i, i + 1);
	this.minorver = navigator.userAgent.substring(i + 2, i + 3);

}
else if ( navigator.userAgent.match(re0) ) {
	this.browser = "Netscape";
	i = navigator.userAgent.indexOf("Mozilla") + "Mozilla".length + 1; 
	this.version = navigator.userAgent.substring(i, i + 3);
	this.majorver = navigator.userAgent.substring(i, i + 1);
	this.minorver = navigator.userAgent.substring(i + 2, i + 3);
	
	// Adjust for Mozilla 5.0 + 
	if ( this.majorver >= 5 ) { 
		this.browser = "Mozilla";
		if ( navigator.userAgent.match(re0b) ) {
			this.browser = "Gecko";
			i = navigator.userAgent.indexOf("Gecko/") + "Gecko/".length; 
			this.version = navigator.userAgent.substring(i, i + 8);
			this.majorver = navigator.userAgent.substring(i, i + 4);
			this.minorver = navigator.userAgent.substring(i + 4, i + 8);
		}
	}
	
}
else { 
	this.browser = "Unknown";
	this.version = "0";
	this.majorver = "0";
	this.minorver = "0";
}


}// end BrowserDetector

// Run BrowserDetector to create object "bd"
var bd = new BrowserDetector();

// Object "bd" should have the following fields: 
// bd.platform => Win , Mac , Unix , Unknown
// bd.browser => Safari, Konqueror , Opera , MSIE , Netscape , Mozilla , Gecko, Unknown
// bd.version => M.N
// bd.majorver => M
// bd.minorver => N

//alert(bd.platform + "\n" + bd.browser + " " + bd.version + "\n" + bd.majorver + "-" + bd.minorver + "\n");

