function setCookie(key, value) {
	document.cookie = key + "=" + escape(value)+";path=/";
}

function clearCookie(key) {
	document.cookie = key + "=; expires=Tue, 1-Jan-1980 00:00:00 GMT; path=/";
}

function hasCookie(key) {
	var value = document.cookie;
	var pattern = "^\\s*" + key + "(=|)|;\\s*" + key + "(=|)";
	return value.match(pattern) != null;
}

function selectShiryo(name) {
	var object = document.shiryoForm.elements[name];
	if (object.checked) {
		setCookie(name, "");
	} else {
		clearCookie(name);
	}
}

function showSelections() {
	with (document.shiryoForm) {
		for (i = 0; i < elements.length; i++) {
			var object = elements[i];
			if (object.type != "checkbox") continue;

			var key = object.name;
			if (key.match(/^tci_/) && hasCookie(key)) object.checked = true;
		}
	}
}

function clearPageSelections() {
	with (document.shiryoForm) {
		for (i = 0; i < elements.length; i++) {
			var object = elements[i];
			if (object.type != "checkbox") continue;

			var key = object.name;
			if (key.match(/^tci_/)) clearCookie(key);
		}
	}
	location.reload();
}

function clearAllSelections() {
	var selections = document.cookie;
	var tokens = selections.split(";");
	for (i = 0; i < tokens.length; i++) {
		var values = tokens[i].split("=");
		if (values.length != 2) continue;

		var key = values[0].replace(/^\s+|\s+$/, "");
		if (key.match(/^tci_/)) clearCookie(key);
	}
	location.reload();
}

