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;
			}
			set_cookie('ss',title, '/');
			set_cookie('st',type, '/');
		}
	}
}

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( 'ss' ) != null)
	{
		setStyleSheet( get_cookie( 'ss' ) , get_cookie( 'st' ) );
	}
}

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, _path )
{
	var cookie_string = _name + "=" + escape ( _value );

	if ( _path )
	cookie_string += "; path=" + escape ( _path );

	document.cookie = cookie_string;
}
