﻿
// 
// Browser.js
// 
// Copyright (C) 2003 Kody S. Brown. All rights reserved.
// 
// 

var Browser = new BrowserObject();

function BrowserObject()
{
// member variable
	this.Name = "";
	this.Version = 0.0;
	this.VersionStr = "";
	this.Major = 0;
	this.Minor = 0;
	this.Build = 0;
	this.Revision = 0;
	
	this.IsIE = false;
	this.IsFirefox = false;

// member function
	this.BookmarkPage = _BookmarkPage;
	this.DetectBrowser = _DetectBrowser;
	
// initialization
	this.DetectBrowser();
}

function _DetectBrowser()
{
	var agent = navigator.userAgent;
	var pos = -1;
	
	if ((pos = agent.indexOf("Firefox/")) > -1) {
		// Firefox
		this.Name = "Firefox";
		this.IsFirefox = true;
		this.VersionStr = agent.substring(pos+8);
	}
	else if ((pos = agent.indexOf("MSIE ")) > -1) {
		// Internet Explorer
		this.Name = "IE";
		this.IsIE = true;
		this.VersionStr = agent.substring(pos+5, agent.indexOf(";", pos));
	}
	else {
		// TODO:
		this.Name = "Unknown";
		this.VersionStr = "0.0";
		this.Version = 0.0;
	}

	this.Version = MyParseFloat(this.VersionStr);
	
	var temp = this.VersionStr.split('.');
	if (temp.length > 0) {
		this.Major = temp[0];
	}
	if (temp.length > 1) {
		this.Minor = temp[1];
	}
	if (temp.length > 2) {
		this.Build = temp[2];
	}
	if (temp.length > 3) {
		this.Revision = temp[3];
	}

	//alert("Name = " + this.Name + "\r\nVersionStr = " + this.VersionStr + "\r\nVersion = " + this.Version);
}

function MyParseFloat(value)
{
	var x = 0.0;
	var str = value.split('.');
	var out = "";
	
	for (var i = 0; i < str.length; i++) {
		if (i == 2) {
			break;
		}
		if (out != "") {
			out += ".";
		}
		out += str[i];
	}
	
	//alert("out = " + out);
	if (out == "") {
		x = 0.0;
	}
	else {
		var digits = out.split('.');
		//alert("digits.length = " + digits.length);
		if (digits.length == 1) {
			x = parseFloat(out);
		}
		else {
			var newval = parseFloat(digits[1]);
			//alert("digits[1] = " + digits[1]);
			//alert("newval = " + newval);
			if (newval > 0) {
				if ((newval + "").length == 1) {
					newval = newval / 10;
				}
				else if ((newval + "").length == 2) {
					newval = newval / 100;
				}
				else if ((newval + "").length == 3) {
					newval = newval / 1000;
				}
				else if ((newval + "").length == 4) {
					newval = newval / 10000;
				}
				else if ((newval + "").length == 5) {
					newval = newval / 100000;
				}
			}
			//alert("newval = " + newval);
			//alert("parseFloat(" + digits[0] + ") = " + parseFloat(digits[0]));
			x = parseFloat(digits[0]) + newval;
			//alert("x = " + x);
		}
	}
	
	return x;
}

function _BookmarkPage(title, url, querystring)
{
	var separator = "?";
	if ("" == url) {
		url = document.location.href;
		var pos = url.indexOf("?");
		if (pos > -1) {
			separator = "&";
		}
	}
	
	if (this.Name == "IE") {
		alert(url + separator + querystring);
		window.external.AddFavorite(url + separator + querystring, title);
	}
	else if (window.sidebar) {
		window.sidebar.addPanel(title, url + separator + querystring, "")
	}
}

