

com._startup_items.push(function(){
	
	com.E("input.Z2H").addEventListener("blur",function(target,evt){
		if(target.value.length < 1) return;
		
		var url = "_javascript/mb_comvert_kana.php";
		com.B().Post(url,{
			str : encodeURI(target.value),
			opt : "asKV",
			enc : "UTF-8"
		},function(res){
			target.value = res.text;
		});
	});
	
	
	var TypeControl = {
		article : new com.Array(),
		Build : function(){
			var E = this;
			
			var but = com.E("div.about input");
			var box = com.E("div.target div.set");
			var lis = com.E("ul.cont-item");
			var anz = com.E("div.anzan")[0];
			
			but.each(function(index){
				var couple = {
					button : but[index],
					div : box[index],
					list : lis[index],
					Show : function(){
						this.div.setStyle({ display : "block" });
						this.list.setStyle({ display : "block" });
						anz.setStyle({ display : (index == 0) ? "block" : "none" });
					},
					Hide : function(){
						this.div.setStyle({ display : "none" });
						this.list.setStyle({ display : "none" });
						anz.setStyle({ display : (index == 0) ? "none" : "block" });
					}
				};
				couple.button.addEventListener("click",function(evt){
					E.Switch(index);
				});
				E.article.push(couple);
			});
			
			this.Init();
		},
		Init : function(){
			var E = this;
			this.article.each(function(index){
				if(this.button.checked == true){
					E.Switch(index);
				}
			});
		},
		Switch : function(index){
			var E = this;
			this.article.each(function(n){
				if(n == index) this.Show();
				else this.Hide();
			});
		}
	};
	TypeControl.Build();
	
	
	var AnzanControl = {
		ch : null,
		sel : null,
		Build : function(){
			var E = this;
			
			var div = com.E("div.anzan");
			if(div.length < 1) return;
			div = div[0];
			
			this.ch = div.E("input");
			if(this.ch.length < 1) return;
			this.ch = this.ch[0];
			
			this.sel = div.E("select");
			
			this.ch.addEventListener("click",function(target){
				E.Adjust();
			});
			
			this.Adjust();
		},
		Adjust : function(){
			if(this.ch.checked == true) this.Enable();
			else this.Disable();
		},
		Enable : function(){
			this.sel.each(function(index,item){
				item.disabled = false;
			});
		},
		Disable : function(){
			this.sel.each(function(index,item){
				item.disabled = true;
			});
		}
	};
	AnzanControl.Build();
	
	var CountControl = {
		counter : null,
		target1 : {
			tbody : null,
			count : 1
		},
		target2 : {
			tbody : null,
			count : 1
		},
		Build : function(){
			var E = this;
			
			var c = com.E("div.count select");
			if(c.length < 1) return;
			this.counter = c[0];
			
			var t1 = com.E("div.set-personel tbody");
			var t2 = com.E("div.set-corp tbody");
			
			if(t1.length > 0) this.target1.tbody = t1[0];
			if(t2.length > 0) this.target2.tbody = t2[0];
			
			this.target1.count = parseInt(this.counter.value);
			this.target2.count = parseInt(this.counter.value);
			
			this.counter.addEventListener("change",function(evt){
				if(!!E.target1.tbody) E.Adjust(E.target1,E.counter.value);
				if(!!E.target2.tbody) E.Adjust(E.target2,E.counter.value);
			});
			
			this.Init();
		},
		Init : function(){
			if(!!this.target1.tbody) this.ReAdjust(this.target1);
			if(!!this.target2.tbody) this.ReAdjust(this.target2);
		},
		ReAdjust : function(target){
			var tr = target.tbody.E("tr");
			var n = target.count;
			if(tr.length != n){
				target.count = tr.length;
				this.Adjust(target,n);
			}
		},
		Adjust : function(target,num){
			if(target.count >= num){
				var trs = target.tbody.E("tr");
				for(var i=target.count-1 ; i>num-1 ; i--){
					trs[i].Delete();
				}
			}
			else{
				var template = target.tbody.E("tr")[0];
				var si = template.E("select")[0].selectedIndex;
				for(var i=target.count ; i<num ; i++)(function(){
					var c = template.cloneNode(true);
					com.E("select",c)[0].selectedIndex = si;
					target.tbody.append(c);
				})();
			}
				target.count = num;
		}
	}
	CountControl.Build();
	
	
	
	
	var ReserveControl = {
		but : com.E("input.reserved"),
		box : com.E("td.rbox"),
		Build : function(){
			var E = this;
			this.but.each(function(index,item){
				item.addEventListener("click",function(){
					E.Switch(index);
				});
			});
			if(this.but.length > 0) this.Init();
		},
		Init : function(){
			var E = this;
			this.but.each(function(index,item){
				if(item.checked == true) E.Switch(index);
			});
		},
		Switch : function(index){
			this.box[index].E("select").each(function(n,item){
				item.disabled = false;
			});
			this.box[(index == 0) ? 1 : 0].E("select").each(function(n,item){
				item.disabled = true;
			});
		}
	};
	ReserveControl.Build();
	
	
	
	
	var ReserveDay = {
		article : new com.Array(),
		near : null,
		Build : function(){
			var E = this;
			var sel = com.E("td.newer select");
			
			if(sel.length < 1) return false;
			
			for(var i=0,l=sel.length ; i<l ; i+=4)(function(index,s1,s2,s3,s4){
				var obj = {
					sY : s1, sM : s2, sD : s3, sH : s4,
					date : new Date(s1.value +"/"+ s2.value +"/"+ s3.value +" "+ s4.value + ":00:00"),
					SetDate : function(){
						if(arguments.length > 0) this.date = arguments[0];
						else this.date = new Date(this.sY.value +"/"+ this.sM.value +"/"+ this.sD.value +" "+ this.sH.value + ":00:00");
					},
					GetDate : function(){
						return this.date;
					},
					ChangeSelect : function(cdate){
						if(cdate.getHours() >= 15) cdate = new Date(cdate.getFullYear(),cdate.getMonth(),cdate.getDate() + 1);
						var y = cdate.getFullYear();
						var m = cdate.getMonth() + 1;
						var d = cdate.getDate();
						var h = cdate.getHours();
						com.Array.prototype.each.call(this.sY.options,function(n){
							this.selected = false;
							if(this.value == y) this.selected = true;
						});
						com.Array.prototype.each.call(this.sM.options,function(n){
							this.selected = false;
							if(this.value == m) this.selected = true;
						});
						com.Array.prototype.each.call(this.sD.options,function(n){
							this.selected = false;
							if(this.value == d) this.selected = true;
						});
						com.Array.prototype.each.call(this.sH.options,function(n){
							this.selected = false;
							if(
								((15 <= h || h < 10) && this.value == 10) || 
								((10 <= h && h < 13) && this.value == 13) || 
								((13 <= h && h < 15) && this.value == 15)
							) this.selected = true;
						});
						this.SetDate();
					}
				};
				obj.sY.addEventListener("change",function(){ obj.SetDate(); E.Adjust(); });
				obj.sM.addEventListener("change",function(){ obj.SetDate(); E.Adjust(); });
				obj.sD.addEventListener("change",function(){ obj.SetDate(); E.Adjust(); });
				obj.sH.addEventListener("change",function(){ obj.SetDate(); E.Adjust(); });
				E.article.push(obj);
				if(index == 0) E.near = new Date(obj.date.getTime() - 1);
			})(i,sel[i],sel[i+1],sel[i+2],sel[i+3]);
			
			return true;
		},
		Adjust : function(){
			if(this.article[0].date.getTime() <= this.near.getTime()){
				this.article[0].ChangeSelect(new Date(this.near.getTime() + 1));
			}
			if(this.article[1].date.getTime() <= this.article[0].date.getTime()){
				this.article[1].ChangeSelect(this.article[0].date);
			}
			if(this.article[2].date.getTime() <= this.article[1].date.getTime()){
				this.article[2].ChangeSelect(this.article[1].date);
			}
			
		}
	};
	if(ReserveDay.Build()) ReserveDay.Adjust();
	
	
	
	
	com.E("img.backbutton").addEventListener("click",function(){
		var inp = com.G("input");
		inp.type = "hidden";
		inp.name = "force_confirm";
		inp.value = "yes";
		var f = com.E("form")[0];
		f.action = "confirm.php";
		f.append(inp);
		f.submit();
	});
	
	
	
});

