var checkBox = {

	conf : {
		ids1 : ["set-area1", "set-subject1", "set-area2", "set-subject2"],
		ids2 : ["set-mychk1", "set-mychk2"]
	},

	start : function(){
		try {
			window.addEventListener('load', this.setup, false);
		} catch (e) {
			window.attachEvent('onload', this.setup);
		}
	},

	setup : function(){
		for(n = 0; n < checkBox.conf.ids1.length; n++){
			if(document.getElementById(checkBox.conf.ids1[n])){
				var tmptxt = "";
				var str = "...";
				var curId_n = document.getElementById(checkBox.conf.ids1[n] + "_n");
				var elm     = document.getElementById(checkBox.conf.ids1[n]);
				var inputList = elm.getElementsByTagName("input");
				var cnt = inputList.length;

				for(i = 0; i < cnt; i++){
					if(inputList[i].type == 'checkbox' && inputList[i].checked == true){

						if(inputList[i].nextSibling.tagName == "LABEL"){
							curtxt = inputList[i].nextSibling.innerHTML;
						}else{
							curtxt = inputList[i].nextSibling.nodeValue;
						}
						if(tmptxt.length + curtxt.length > 10){
							if(tmptxt.indexOf(str) == -1){
								tmptxt += str;
							}
						}else{
							if(tmptxt != ""){
								tmptxt += "、";
							}
							tmptxt += curtxt;
						}
						checkBox.setColor(inputList[i]);  // ラベルの背景色・文字色を変更
					}
					inputList[i].onclick = function(){
						checkBox.setColor(this);  // ラベルの背景色・文字色を変更
					}
				}
				if(tmptxt == ""){
					tmptxt = curId_n.parentNode.title;
				}
				curId_n.innerHTML = tmptxt;
			}
		}

		for(n = 0; n < checkBox.conf.ids2.length; n++){
			if(document.getElementById(checkBox.conf.ids2[n])){
				var inputs = document.getElementById(checkBox.conf.ids2[n]).getElementsByTagName("input");
				for(i = 0; i < inputs.length; i++){
					if(inputs[i].type == 'checkbox' || inputs[i].type == 'radio' && inputs[i].checked == true){
						if(inputs[i].nextSibling.childNodes[0].nodeValue != 'こだわらない'){
							checkBox.setColor(inputs[i]);  // ラベルの背景色・文字色を変更
						}
					}
					inputs[i].onclick = function(){
						if(this.type == 'checkbox' || this.type == 'radio'){
							if(this.nextSibling.childNodes[0].nodeValue != 'こだわらない'){
								checkBox.setColor(this);  // ラベルの背景色・文字色を変更
							}
							if(this.type == 'radio'){
								var radios = this.parentNode.getElementsByTagName("input");
								for(c = 0; c < radios.length; c++){
									if(radios[c].nextSibling.childNodes[0].nodeValue != 'こだわらない'){
										checkBox.setColor(radios[c]);  // ラベルの背景色・文字色を変更
									}
								}
							}
						}
					}
				}
			}
		}
	},

	checkAll : function(obj){
		flag = checkBox.chex(obj);
		inputEle = obj.parentNode.parentNode.getElementsByTagName('input');
		for(var i = 0; i < inputEle.length; i++){
			if(inputEle[i].type == 'checkbox'){
				inputEle[i].checked = flag;  //チェックボックスをONにする
				checkBox.setColor(inputEle[i]);  // ラベルの背景色・文字色を変更
			}
		}
	},

	setColor : function(Myid){
		if(Myid.checked == true){
			Myid.nextSibling.style.color = '#000000';
			Myid.nextSibling.style.backgroundColor = '#FFD15A';
		}else{
			Myid.nextSibling.style.color = '#000000';
			Myid.nextSibling.style.backgroundColor = 'transparent';
		}
	},

	chex : function(obj){
		var flag = false;
		inputEle = obj.parentNode.parentNode.getElementsByTagName('input');
		for(var i = 0; i < inputEle.length; i++){
			if(!inputEle[i].checked && inputEle[i].type == 'checkbox'){
				flag = true;
			}
		}
		return flag;
	}
}

checkBox.start()
