var OS;
var BrowserVersion;
var BrowserType;

/*determine OS*/
OS = gOS();

/*determine browser type*/
BrowserType = gBrowserType();

/*determine browser version*/
BrowserVersion = gBrowserVersion();

function LoadScripts(path) {
	if (OS == "MAC") {
		if (BrowserType == "NS") {
			if (BrowserVersion >= 5) {
				document.writeln('<link rel="stylesheet" href="' + path + '"/core/framework/style/framework/MAC-NS.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/MAC-NS.css"></link>');
			}
		} else {
		document.writeln('<link rel="stylesheet" href="' + path + '/core/framework/style/framework/MAC.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/MAC.css"></link>');
		}
	} else if (OS == "WIN") {
		if (BrowserType == "NS") {
			if (BrowserVersion >= 5) {
				document.writeln('<link rel="stylesheet" href="' + path + '/core/framework/style/framework/WIN-NS.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/WIN-NS.css"></link>');
			}
		} else {
			if (BrowserVersion > 6) {
				document.writeln('<link rel="stylesheet" href="' + path + '/core/framework/style/framework/WIN.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/IE7.css?20110509"></link>');
			} else {
			document.writeln('<link rel="stylesheet" href="' + path + '/core/framework/style/framework/WIN.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/WIN.css"></link>');
			document.writeln('<script type="text/javascript" defer="defer" src="' + path + '/core/framework/clientside/pngfix.js"></script>');
			}
		}
	} else {
	document.writeln('<link rel="stylesheet" href="' + path + '/core/framework/style/framework/WIN.css"></link><link rel="stylesheet" href="' + path + '/site/framework/style/WIN.css"></link>');
	}
}

function gBrowserType() {
	if (navigator.appName.indexOf("Netscape") >= 0) {
		return "NS";
	} else if (navigator.appName.indexOf("Explorer") >= 0) {
		if (navigator.userAgent.indexOf("Opera") >= 0) {
			return "OP";
		} else {
			return "IE";
		}
	} else {
		return "NA";
	}
}

function gBrowserVersion() {
	switch (gBrowserType()) {
		case "NS":
			return parseInt(navigator.appVersion.substr(0, 1));
			break;

		case "IE":
			return parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE") + 5, 1));
			break;

		case "OP":
			return parseInt(navigator.userAgent.substr(navigator.userAgent.indexOf("Opera") + 6, 1));
			break;

		default:
			return 4;
	}
}

function gOS() {
	if (navigator.platform.indexOf("Mac") >= 0)
		return "MAC";
	else
		return "WIN";
}

function bookmarkSite() {

	if (OS == "MAC") {
		if (BrowserType == "OP") {
			alert("To bookmark this page, click OK, and then press COMMAND+T.");
		} else {
			alert("To bookmark this page, click OK, and then press COMMAND+D.");
		}
	} else if (OS == "WIN") {
		if (BrowserType == "OP") {
			alert("To bookmark this page, click OK, and then press CTRL-T.");
		} else if (BrowserType == "NS") {
			alert("To bookmark this page, click OK, and then press CTRL-D.");
		} else {
			window.external.AddFavorite(location.href, document.title);
		}
	}
}

function printNow() {
	if (OS == "MAC") {
		alert("To print this page, click OK, and then press COMMAND+P.");
		top.frames[1].focus();
	} else {
		if (BrowserType == "IE") {
			top.frames[1].focus(); top.frames[1].print();
		} else {
			alert("To print this page, click OK, and then press CTRL-P.");
			top.frames[1].focus();
		}
	}
}

var OSDetectForStyleSheet = {
	require: function(libraryName) {
		// inserting via DOM fails in Safari 2.0, so brute force approach
		document.write('<script type="text/javascript" src="' + libraryName + '"></script>');
	},
	load: function() {
		var scripts = document.getElementsByTagName("script");
		for (var i = 0; i < scripts.length; i++) {
			if (scripts[i].src.match(/osdetectforstylesheet.*\.js(\?.*)?$/i)) {
				var r = /^(?:https?:\/\/)?[^\/]*(\/.*)$/i.exec(scripts[i].src)[1];
				LoadScripts(scripts[i].src.replace(r, ''));
				break;
			}
		}
	}
}

OSDetectForStyleSheet.load();
