	
	function setStyleSheet(title,type)
	{
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
		{
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && isStyleSheetType(a.getAttribute("title"),type))
			{
				a.disabled = true;
				if(a.getAttribute("title") == title)
				{
					a.disabled = false;
				}
				
				if( type == "fontsize" )
				{
					set_cookie('fontsize',title);				
				}
				else if( type == "width" )
				{
					set_cookie('width',title);
				}
			}
		}
	}


	function isStyleSheetType(str,type) 
	{
		if( str == "" )
		{ 
			return true; 
		}
		else if( type == "width" && str.match(/\d/) )
		{ 
			return true; 
		}
		else if( type != "width" && str.match(/^\D*$/) ) 
		{ 
			return true; 
		}
		
		return false;
	}
	
	function loadSelectedStyleSheet()
	{
		if (get_cookie( 'fontsize' ) != null)
		{
			setStyleSheet( get_cookie( 'fontsize' ), 'fontsize' );
		}
		
		if (get_cookie( 'width' ) != null)
		{
			setStyleSheet( get_cookie( 'width' ), 'width' );
		}
	}

	function get_cookie( _cookie_name )
	{
		var results = document.cookie.match( _cookie_name + '=(.*?)(;|$)' );

		if ( results )
			return ( unescape ( results[1] ) );
		else
			return null;
	}

	function set_cookie( _name, _value )
	{
		var expires = "";
		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
		expires = "; expires=" + date.toGMTString();

		var cookie_string = _name + "=" + escape ( _value ) + expires + ";";

		document.cookie = cookie_string;
	}	
	
window.onload = function(e) {
	loadSelectedStyleSheet();
}

window.onunload = function(e) {
	loadSelectedStyleSheet();
}	

loadSelectedStyleSheet();