var _info = navigator.userAgent;
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);

var _ns = (navigator.appName.indexOf("Netscape") > -1 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0) ||
(_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0) ||
(_info.indexOf("AIX") > 0) || (_info.indexOf("OS/2") > 0)));
	
_ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));
var browser_vers = ((_ns6 == true)? '6' : ((_ie == true)? '' : '4'));
var browser = ((_ie == true)? 'ie' : 'netscape');

var cookiename = "sitetheme";

function getsitestyle() {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return "1"; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function doStyleImport()
{
	var sitestyle = getsitestyle();
	var sheet1 = '';
	var sheet2 = '';
	
	if(sitestyle == "0")
	{
		sheet1 = '/css/themes/scaleable.css';
		sheet2 = '';
	}
	else if(sitestyle == "1")
	{
		sheet1 = '/css/nomis.css';
		sheet2 = '/css/themes/standard.css';
	}
	else if(sitestyle == "2")
	{
		sheet1 = '/css/themes/scaleable.css';
		sheet2 = '/css/themes/pastel.css';
	}
	else if(sitestyle == "3")
	{
		sheet1 = '/css/nomis.css';
		sheet2 = '/css/themes/purplehaze.css';
	}
	else
	{
	    sheet1 = '/css/nomis.css';
		sheet2 = '/css/themes/standard.css';
	}

	if(!_ie && browser_vers == '4')
	{
		if(sheet1 != '') document.writeln('<link rel="stylesheet" href="' + sheet1 + '" type="text/css">');
		if(sheet2 != '') document.writeln('<link rel="stylesheet" href="' + sheet2 + '" type="text/css">');
	}
	else
	{
		document.writeln("\n<style>\n");
		
		if(sheet1 != '') document.writeln("<!-- @import url(" + sheet1 + "); -->\n");
		if(sheet2 != '') document.writeln("<!-- @import url(" + sheet2 + "); -->\n");
		
		document.writeln("</style>\n");
	}
	
	if(!_ie) // FIX FOR NETSCAPE LIST INDENT DIFFERENT TO IE
	{
		document.writeln("<style>\n<!-- @import url(/css/netscape.css); -->\n</style>\n");
	}
}

doStyleImport();

function setStyleCookie(value) {
    document.cookie = cookiename + "=" + value + "; path=/";
    document.location.reload();
}

//
// FIX for IE6 problems with text selection in absolutely positioned DIV tags
// Taken directly from:
//       http://blog.tom.me.uk/2003/07/23/boie6selecta.php
//
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat")
{
  document.onreadystatechange = onresize = function fixIE6AbsPos()
  {
    if (!document.body) return;
    if (document.body.style.margin != "0px") document.body.style.margin = 0;
    onresize = null;
    document.body.style.height = 0;
    setTimeout(function(){ document.body.style.height = document.documentElement.scrollHeight+'px'; }, 1);
    setTimeout(function(){ onresize = fixIE6AbsPos; }, 100);
  }
}