//=======================================================================================
// STAR Information Technology
//
// Program Description: W.B. Mason Web Site
// File Description: browser_detect.js
//
//=======================================================================================

//Scroll window position
var scroll = (window.scrollTo) ? 1 : 0;

		function setCookie(name, value, expires, path, domain, secure) {
			var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
			document.cookie = curCookie;
			}

		function getCookie(name) {
			var dc = document.cookie;
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
			} else {
			begin += 2;
			}
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin + prefix.length, end));
			}

		function saveScroll() {
			var divDoc = document.getElementById('divHeight');
			if (!scroll) return;
			var now = new Date();
			//Cookie expires in 10 seconds.
			now.setTime(now.getTime() + 10 * 1000);
			//now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //Year from now
			var x = divDoc.scrollLeft;
			var y = divDoc.scrollTop;
			setCookie("xy", x + "_" + y, now);
			}

		function loadScroll() {
			var divDoc = document.getElementById('divHeight');
			if (!scroll) return;
			var xy = getCookie("xy");
			if (!xy) return;
			var ar = xy.split("_");
			if (ar.length == 2)
			{
			divDoc.scrollLeft = parseInt(ar[0]);
			divDoc.scrollTop = parseInt(ar[1]);
			}
		}
		
//-->

version_major=parseInt(navigator.appVersion); //major version
browser_name=navigator.appName; // name of the browser
browser_version=navigator.appVersion; // version of the browser

//MS IE
if (browser_name=="Microsoft Internet Explorer") {
	if ( browser_version.indexOf('MSIE 5.0; Macintosh;') != -1 )  
	{
		document.write("<link REL='stylesheet' href='styles/StylesIExplorer.css' type='text/css'>");
	}
	// major version is equals or higher than 4
	else if (version_major>=4)
	{
		document.write("<link REL='stylesheet' href='styles/StylesIExplorer.css' type='text/css'>");
	}
	else 
	{
		document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");
		//document.write("<link REL='stylesheet' href='styles/StyleNS.css' type='text/css'>");
	}
}

//Netscape
else if (browser_name=="Netscape") {
//version major = 4
	if (version_major>=5)	
	{	
		//document.write("<link REL='stylesheet' href='styles/StyleNS.css' type='text/css'>");
		document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");	
	}
	//version major is equals 5 or higher
	else if (version_major==4)
	{
		document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");
	}
	else 
	{
		//document.write("<link REL='stylesheet' href='styles/StyleNS.css' type='text/css'>");
		document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");
	}
}

//Opera
else if (browser_name=="Opera") {
	{
		//document.write("<link REL='stylesheet' href='styles/StyleNS.css' type='text/css'>");
		document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");
	}
}
//Mac
if (browser_version.indexOf('Mac') != -1) 
{
	//document.write("<link REL='stylesheet' href='styles/StyleNS.css' type='text/css'>");
	document.write("<link REL='stylesheet' href='styles/StylesCompatible.css' type='text/css'>");
}

//Netscape Resize
/**
 * resize.js 0.3 970811
 * by gary smith
 * js component for "reloading page onResize"
 *http://css.nu/faq/nn-resize.html
 */

if(!window.saveInnerWidth) {
  window.onresize = resizeIt;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resizeIt() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}
//-->

function getHeight()
{
	try
	{
		var scr_w = screen.availWidth;
		var scr_h = screen.availHeight;
		var browseWidth, browseHeight;
		var availableWidth, availableHeight;
	
		//IE
		if (document.all){
			browseWidth=document.body.clientWidth;
			browseHeight=document.body.clientHeight;
			availableWidth = browseWidth - 150;
			availableHeight = browseHeight - 150;	
		}
		else
		{
			browseWidth=window.innerWidth;
			browseHeight=window.innerHeight;
			availableWidth = browseWidth - 152;
			availableHeight = browseHeight - 150;	
		}

		//document.getElementById("tdWidth").width = availableWidth;
		document.getElementById("divHeight").style.width = availableWidth;
		document.getElementById("divHeight").style.height = availableHeight;	
	}
	catch(e)
	{}
}

window.onresize = getHeight;
getHeight();
		
//-->
