// Default Closer

function DefaultCloser(str) {
	var arr = str.split(",");
	for (var i=0; i<arr.length-1; i++) {
		if (arr[i] == "0"||arr[i] == "") {
			CloseTree("ctg" + i);
		}
	}
}

// Category Tree

function CategoryTree(id) {
	var cid = id.substr(3);
	if(document.getElementById) {
		if(document.getElementById(id).style.display == "block") {
			SetCategory(cid, "0");
			CloseTree(id);
		}else if(document.getElementById(id).style.display == "none") {
			SetCategory(cid, "1");
			OpenTree(id);
		}
	}
}

function CloseTree(id) {
	var iid = id + "-icon";
	var aid = id + "-anchor";
	var ttl = document.getElementById(aid).title;
	document.getElementById(id).style.display = "none";
	document.images[iid].src  = "/images/interface-icon/open-38x12.png";
	document.images[iid].alt = "あける";
	ttl = ttl.replace("閉じます","開けます");
	document.getElementById(aid).title = ttl;
}

function OpenTree(id) {
	var iid = id + "-icon";
	var aid = id + "-anchor";
	var ttl = document.getElementById(aid).title;
	document.getElementById(id).style.display = "block";
	document.images[iid].src  = "/images/interface-icon/close-38x12.png";
	document.images[iid].alt = "とじる";
	ttl = ttl.replace("開けます","閉じます");
	document.getElementById(aid).title = ttl;
}

// Set Category

function SetCategory(id, fl) {
	var dmp = GetCookie("ctg");
	var arr = dmp.split(",");
	arr[id] = fl;
	var str = arr.join(",");
	SetCookie("ctg", str);
}

// Get Cookie

function GetCookie(name) {
	var regexp = new RegExp('; ' + name + '=(.*?);');
	var match  = ('; ' + document.cookie + ';').match(regexp);
	return match ? decodeURIComponent(match[1]) : '';
}

// Set Cookie

function SetCookie(name, value) {
	var buf = name + '=' + encodeURIComponent(value);
	document.cookie = buf + '; expires=Sun, 13-Feb-2028 23:59:59 JST';
}