var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function set_cookie (name, value, exp_y, exp_m, exp_d, path, domain) {
	var cookie_string = name + "=" + escape (value);

	if (exp_y) {
		var expires = new Date (exp_y, exp_m, exp_d);
    	cookie_string += "; expires=" + expires.toGMTString();
	}

	if (path)
		cookie_string += "; path=" + escape (path);

	if (domain)
		cookie_string += "; domain=" + escape (domain);
        
	document.cookie = cookie_string;
}

function get_cookie (cookie_name) {
  var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

  if (results)
    return (unescape(results[2]));
  else
    return null;
}

function setHeight() {
	var browserName=navigator.appName;
	if(window.innerHeight) {
		pageHeight = window.innerHeight;
		pageWidth = window.innerWidth;
	} else if(document.body.scrollHeight > document.body.offsetHeight) {
		pageHeight = document.body.clientHeight;
		pageWidth = document.body.clientWidth;
	} else { 
 		pageHeight = document.body.offsetHeight + document.body.offsetTop;
 		pageWidth = document.body.offsetWidth;
 	}
	// Set MainContent Height
	w=pageHeight;
	
	
	// Set Heights
	x=w - 190;
	y=x+"px";
	document.getElementById("maincenter").style.height=y;

	// Set TOC Height
	x2=w - 195;
	y2=x2 * .66;
	z2=y2+"px";
	document.getElementById("section_in").style.height=z2;

	// Set Results Height
	x3=w - 195;
	y3=x3 * .34;
	z3=y3+"px";
	document.getElementById("result").style.height=z3;

	
	// Set Results_Float Position
	x4=y2 + 145;
	z4=x4+"px";
	document.getElementById("results_float").style.top=z4;
	document.getElementById("results_float").style.paddingLeft='5px';

	// Set Widths
	e=pageWidth - 25;
	e2=pageWidth;
	if (e2 < 1060) {
		a1=e2 - 290;
		a2=a1+"px";
		b1=265;
		b2=b1+"px";
		a11=e2 - 290;
		a12=a11+"px";
	} else {
		a1=e * .75;
		b1=e * .25;
		a2=a1+"px";
		b2=b1+"px";
		a11=e2 * .75;
		a12=a11+"px";	
	}

	document.getElementById("maincenter").style.width=a2;
	document.getElementById("mainleft").style.width=b2;
	document.getElementById("print_bar").style.width=a12;
	totalWidth=pageWidth+"px";
	document.getElementById("footer").style.width=totalWidth;
	document.getElementById("nonFooter").style.width=totalWidth;
	document.getElementById("content_main").style.width=totalWidth;
	
}
function setHeight_Safari() {
	var browserName=navigator.appName;
	if(window.innerHeight) {
		pageHeight = window.innerHeight;
		pageWidth = window.innerWidth;
	} else if(document.body.scrollHeight > document.body.offsetHeight) {
		pageHeight = document.body.clientHeight;
		pageWidth = document.body.clientWidth;
	} else { 
 		pageHeight = document.body.offsetHeight + document.body.offsetTop;
 		pageWidth = document.body.offsetWidth;
 	}
	// Set MainContent Height
	w=pageHeight;
	
	// Set Heights
	x=w - 190;
	y=x+"px";
	document.getElementById("maincenter").style.height=y;

	// Set TOC Height
	x2=w - 165;
	y2=x2 * .66;
	z2=y2+"px";
	document.getElementById("search_left").style.height=z2;

	// Set Results Height
	x3=w - 160;
	y3=x3 * .34;
	z3=y3+"px";
	document.getElementById("result").style.height=z3;
		
	// Set Results_Float Position
	x4=y2 + 105;
	z4=x4+"px";
	document.getElementById("results_float").style.top=z4;

	// Set Widths
	e=pageWidth - 25;
	e2=pageWidth;
	if (e2 < 1060) {
		a1=e2 - 290;
		a2=a1+"px";
		b1=265;
		b2=b1+"px";
		a11=e2 - 290;
		a12=a11+"px";
	} else {
		a1=e * .75;
		b1=e * .25;
		a2=a1+"px";
		b2=b1+"px";
		a11=e2 * .75;
		a12=a11+"px";	
	}
	document.getElementById("results_float").style.paddingLeft='10px';
	document.getElementById("maincenter").style.width=a2;
	document.getElementById("mainleft").style.width=b2;
	document.getElementById("print_bar").style.width=a12;
	totalWidth=pageWidth+"px";
	document.getElementById("footer").style.width=totalWidth;
	document.getElementById("nonFooter").style.width=totalWidth;
	document.getElementById("content_main").style.width=totalWidth;
	
}
function setHeight_IE6() {
	var browserName=navigator.appName;
	if(window.innerHeight) {
		pageHeight = window.innerHeight;
		pageWidth = window.innerWidth;
	} else if(document.body.scrollHeight > document.body.offsetHeight) {
		pageHeight = document.body.clientHeight;
		pageWidth = document.body.clientWidth;
	} else { 
 		pageHeight = document.body.offsetHeight + document.body.offsetTop;
 		pageWidth = document.body.offsetWidth;
 	}
	// Set MainContent Height
	w=pageHeight;


	// Set Heights
	x=w - 190;
	y=x+"px";
	document.getElementById("maincenter").style.height=y;

	// Set TOC Height
	x2=w - 210;
	y2=x2 * .62;
	z2=y2+"px";
	document.getElementById("section_in").style.height=z2;

	// Set Results Height
	x3=w - 310;
	y3=x3 * .38;
	z3=y3+"px";
	document.getElementById("result_cont").style.height=z3;
		
	// Set Results_Float Position
	/*x4=y2 + 135;
	z4=x4+"px";
	document.getElementById("results_float").style.top=z4;
*/
	// Set Widths
	e=pageWidth - 25;
	e2=pageWidth;
	if (e2 < 1060) {
		a1=e2 - 290;
		a2=a1+"px";
		b1=265;
		b2=b1+"px";
		a11=e2 - 290;
		a12=a11+"px";
	} else {
		a1=e * .75;
		b1=e * .25;
		a2=a1+"px";
		b2=b1+"px";
		a11=e2 * .75;
		a12=a11+"px";	
	}
	document.getElementById("maincenter").style.width=a2;
	document.getElementById("mainleft").style.width=b2;
	document.getElementById("print_bar").style.width=a12;
	totalWidth=pageWidth+"px";	
	document.getElementById("footer").style.width=totalWidth;
	document.getElementById("nonFooter").style.width=totalWidth;
	document.getElementById("content_main").style.width=totalWidth;
	
}

function setHeight_IE7() {
	var browserName=navigator.appName;
	if(window.innerHeight) {
		pageHeight = window.innerHeight;
		pageWidth = window.innerWidth;
	} else if(document.body.scrollHeight > document.body.offsetHeight) {
		pageHeight = document.body.clientHeight;
		pageWidth = document.body.clientWidth;
	} else { 
 		pageHeight = document.body.offsetHeight + document.body.offsetTop;
 		pageWidth = document.body.offsetWidth;
 	}
	// Set MainContent Height
	w=pageHeight;
	
	
	// Set Heights
	x=w - 190;
	y=x+"px";
	document.getElementById("maincenter").style.height=y;

	// Set TOC Height
	x2=w - 200;
	y2=x2 * .66;
	z2=y2+"px";
	document.getElementById("section_in").style.height=z2;

	// Set Results Height
	x3=w - 200;
	y3=x3 * .34;
	z3=y3+"px";
	document.getElementById("result_cont").style.height=z3;

	// Set Results_Float Position
	x4=y2 + 145;
	z4=x4+"px";
	document.getElementById("results_float").style.top=z4;

	// Set Widths
	e=pageWidth - 25;
	e2=pageWidth;
	if (e2 < 1060) {
		a1=e2 - 290;
		a2=a1+"px";
		b1=265;
		b2=b1+"px";
		a11=e2 - 290;
		a12=a11+"px";
	} else {
		a1=e * .75;
		b1=e * .25;
		a2=a1+"px";
		b2=b1+"px";
		a11=e2 * .75;
		a12=a11+"px";	
	}
	document.getElementById("maincenter").style.width=a2;
	document.getElementById("mainleft").style.width=b2;
	document.getElementById("print_bar").style.width=a12;	
	totalWidth=pageWidth+"px";
	document.getElementById("footer").style.width=totalWidth;
	document.getElementById("nonFooter").style.width=totalWidth;
	document.getElementById("content_main").style.width=totalWidth;
}

function pageSetup() {
	browser_name=navigator.appName;
	browser_version=parseInt(navigator.appVersion);
	if (browser_name == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
    	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    	if (re.exec(ua) != null) {
      		rv = parseFloat( RegExp.$1 );
      	}
      	if (rv >= 5 && rv < 7) {
      		setHeight_IE6();
      	} else if (rv == 7 || rv > 7) {
      		setHeight_IE7();
      	}
	} else if (BrowserDetect.browser == 'Safari') {
		setHeight_Safari();
	} else {
		setHeight();
	}
}