function cookieHelper(/*limitDays : Number, path : String, secure : Boolean, domain : String*/) {
	var argv = cookieHelper.arguments;
	var argc = cookieHelper.arguments.length;

	if (argc > 0)
		this.setExpires(argv[0]);
	if (argc > 1)
		this.path = argv[1];
	else {
		this.path = location.pathname;
		this.path = this.path.substring(0, this.path.lastIndexOf('/')) + '/';
	}
	if (argc > 2)
		this.secure = argv[2];
	if (argc > 3)
		this.domain = argv[3];
}

cookieHelper.prototype = {
	domain : null
,
	secure : false
,
	_expires : null
,
	path : null
,
	getCookie : function(name) {
		var matchKey = new RegExp('(?:[ \r\t\n;]|^)' + name + '=([^ \r\t\n;]*)', '');
		var matchs = matchKey.exec(document.cookie);

		return matchs ? unescape(matchs[1]) : null;
	}
,
	setCookie : function(name, value) {
		document.cookie =
			name + '=' + escape(value) +
			((this._expires == null) ? '' : ('; expires=' + this._expires.toGMTString())) +
			((this.path == null) ? '' : ('; path=' + this.path)) +
			((this.domain == null) ? '' : ('; domain=' + this.domain)) +
			((this.secure == true) ? '; secure' : '');
	}
,
	//get expries()
	getExpires : function() {
		return this._expires;
	}
,
	//set expries(limitDays)
	setExpires : function(limitDays) {
		if (limitDays > 0) {
			this._expires = new Date();
			this._expires.setTime(this._expires.getTime() + (1000 * 60 * 60 * 24 * limitDays));
		}
		else
			this._expires = null;
	}
}

gCookie = new cookieHelper(365);

function setStyleSheet(sName) {
	var count = document.styleSheets.length;
	var i, theStyleSheet;
	for (i = 0; i < count;i++) {
		theStyleSheet = document.styleSheets[i];
		theStyleSheet.disabled = (theStyleSheet.title != '' && theStyleSheet.title != sName);
	}
}

function switchStyleSheet(sName) {
	setStyleSheet(sName);
	gLastStyle = sName;
	gCookie.setCookie('stylesheet', sName);
}

function layoutStyleSwitch(ssList) {
	var sslen = ssList.length;
	var resultString = '';

	if (sslen > 0) {
		var i;
		resultString = ('<select onchange="switchStyleSheet(this.options[this.selectedIndex].value)">');
		for (i = 0;i < sslen;i++)
			resultString += '<option value="' + ssList[i] + '" ' + ((gLastStyle == ssList[i]) ? 'selected' : '') + '>' + ssList[i] + '</option>';
		resultString += '</select>';
	}

	return resultString;
}

function getThemes() {
	var count = document.styleSheets.length;
	var i, j = 0, theStyleSheet;
	var themes = new Array();
	for (i = 0; i < count;i++) {
		theStyleSheet = document.styleSheets[i];
		if (theStyleSheet.title != null && theStyleSheet.title != '' && !themes[theStyleSheet.title]) {
			themes[theStyleSheet.title] = true;
			themes[j++] = theStyleSheet.title;
		}
	}
	return themes;
}

gLastStyle = gCookie.getCookie('stylesheet');
gThemes = getThemes();

if (gLastStyle && gThemes[gLastStyle])
	setStyleSheet(gLastStyle);
