/****** tcprofile cookie */


var tcprofile_cookie; // global var for cookie, set in body.onLoad()

	function getTcprofile(){ // get cookie from client machine
		var cookieArray;
		var cookiesArray = document.cookie.split(/;/);
		for(var i=0; i<cookiesArray.length; i++){
			if(cookiesArray[i].search(/tcprofile/) != -1){
				tcprofile = cookiesArray[i].split(/[=,]/);
				if(tcprofile.length == 4){
					return tcprofile;
				}
			}
		}
		return ["tcprofile",1,0,0]; // default value
	}
	
	function setTcprofile(){ // save cookie to client machine
		var t = tcprofile_cookie;
		if(t){
			var str;
			//save the updated cookie
			var expires = new Date();
			// set time 30 days into the future
			expires.setTime(expires.getTime() + (1000 * 3600 * 24 * 30));
			//set path to current site
			var path = "";
			// set the cookie
			str = t[0]+"="+t[1]+","+t[2]+","+t[3]+"; expires="+expires.toUTCString()+"; path="+path;
			document.cookie = str;
		}
	}
	
	function updateTcprofile(index,value){ // update the page variable. Indexes: m=[1] c=[2] t=[3]
		tcprofile_cookie[index] = value;
	}
	
/****** textsize and contrast */

	function textsize(t){ // onClick handler textsize
		var body = document.getElementsByTagName("body")[0];
		var nav = document.getElementById("nav");
		var findmore = document.getElementById("findmore");
		switch(t){
			case 0:
				body.style.fontSize = "90%";
			break;
			case 1:
				body.style.fontSize = "110%";
			break;
			case 2:
				body.style.fontSize = "140%";
			break;
		}
		//force reflow in some elements
		/*
		if(nav){
			nav.style.width = "0";nav.style.width = "14em";
		}
		if(findmore){
			findmore.style.width = "0";findmore.style.width = "16em";
		}
		*/
		//set local cookie var
		updateTcprofile(3,t);
	}
	function contrast(c){ // onClick handler contrast
		var body = document.getElementsByTagName("body")[0];
		var access = document.getElementById("access");
		if("access"){
			switch(c){
				case 0:
					access.href="def-access.css";
				break;
				case 1:
					access.href="black-yellow.css";
				break;
				case 2:
					access.href="green-black.css";
				break;
				case 3:
					access.href="yellow-black.css";
				break;
			}
		}
		//set local cookie var
		updateTcprofile(2,c);
		//force screen refresh
		body.style.height = "100%";
	}
	
/****** onload / unload */

	function bodyOnLoad(){
		//get the tcprofile cookie
		tcprofile_cookie = getTcprofile();
		if(tcprofile_cookie){
			var m = parseInt(tcprofile_cookie[1]);
			var c = parseInt(tcprofile_cookie[2]);
			var t = parseInt(tcprofile_cookie[3])
			contrast(c);
			textsize(t);;
		}
	}
	
	function bodyOnUnLoad(){
		setTcprofile();
	}