// idbrowser.js
// Identify platform, browser, and browser version
// Produces an object "bd" with the following fields: 
// bd.platform => Win , Mac , Unix , WebTV , Unknown
// bd.browser => Safari, Konqueror , Opera , WebTV , AOL , MSIE , Netscape , Mozilla , Unknown
// bd.version => M.N
// bd.majorver => M
// bd.minorver => N

function BrowserDetector()
{
// Initialize local vars
  this.browser = "Unknown";
  this.platform = "Unknown";
  this.version = "0";
  this.majorver = "0";
  this.minorver = "0";
  i = 0;

// Determine platform
rex1 = new RegExp(".*Win.*", "g");
rex2 = new RegExp(".*Mac.*", "g");
rex3 = new RegExp(".*X11.*", "g");
rex3b = new RegExp(".*Linux.*", "g");
rex4 = new RegExp(".*WebTV.*", "g");

if ( navigator.userAgent.match(rex1) ) {
	this.platform = "Win";
}
else if ( navigator.userAgent.match(rex2) ) {
	this.platform = "Mac";
}
else if ( navigator.userAgent.match(rex3) || navigator.userAgent.match(rex3b) ) {
	this.platform = "Unix";
}
else if ( navigator.userAgent.match(rex4) ) {
	this.platform = "WebTV";
}
else {
	this.platform = "Unknown";
}; 


// Determine browser
re6 = new RegExp(".*Safari.*", "g");
re5 = new RegExp(".*Konqueror.*", "g");
re4 = new RegExp(".*Opera.*", "g");
re3 = new RegExp(".*WebTV.*", "g");
re2 = new RegExp(".*AOL.*", "g");
re1 = new RegExp(".*MSIE.*", "g");
re0 = new RegExp(".*Mozilla.*", "g");


if ( navigator.userAgent.match(re6) ) {
	// document.writeln("Safari");
	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) ) {
	// document.writeln("Konqueror");
	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) ) {
	// document.writeln("Opera");
	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(re3) ) {
	// document.writeln("WebTV");
	this.browser = "WebTV";
	i = navigator.userAgent.indexOf("WebTV") + "WebTV".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(re2) ) {
	// document.writeln("AOL");
	this.browser = "AOL";
	i = navigator.userAgent.indexOf("AOL") + "AOL".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) ) {
	// document.writeln("MSIE");
	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";
		i = navigator.userAgent.indexOf("rv:") + "rv:".length;
		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 { 
	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 , WebTV , Unknown
// bd.browser => Safari, Konqueror , Opera , WebTV , AOL , MSIE , Netscape , Mozilla , 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");
