class MyTouch{
	constructor(){
		this.Menu = "lbMenu";
		this.IDDayTime = "DayTime";
		this.IDOrgasm = "Orgasm";
		this.CommandOrgasm = "OrgasmCommnd";
		this.CommandMove = "move";
		this.CommandTalk = "talk";
		this.CommandLock = "lock";
		this.CommandLock2 = "lock2";
		this.CommandItem = "item"
		this.CommandStore = "store";
		this.CommandSleep = "sleep";
		this.CommandSex = "sex";
		this.CommandEat = "eat";
		this.CommandOnani = "onani";
		this.CommandWaer = "waer";
		this.CommandWaer2 = "waer1";
		this.CommandWaer3 = "waer2";
		this.CommandWaer4 = "waer3";
		this.CommandUnder = "under";
		this.CommandUnder2 = "under2";
		this.CommandMakuru = "makuru";
		this.CommandMakuruW = "makuru1";
		this.CommandMakuruU = "makuru2";
		this.CommandMakuruR = "makuru3";
		this.CommandKigaeru = "kigaeru";
		this.CommandKigae1 = "kigae1";
		this.CommandNugu = "nugu";
		this.CommandNugasu = "nugasu";
		this.CommandSounyuu = "sounyuu";
		this.CommandShasei = "shahsei";
		this.CommandBoxnone = "boxnone";
		this.CommandBattle = "battle";
		this.CommandStatus = "Status";
		this.CommandNextDay = "nextday";
		this.CommandOption = "Option";
		this.CommandBtlAttack = "Attack";
		this.CommandBtlItem = "BattleItem";
		this.Commandjanken = "janken";
		this.CommandGuard = "Guard";
		this.CommandBtlEscape = "Escape";
		this.MenuMove = "movemenu";
		this.CommandReturn = "Return";
		this.CommandMenuReturn = "menuRetrun";
		this.MsgBox = "msgBox";
		this.messageCount = 0;
		this.Message = [];
		this.OpeningFlg = true;
		this.fontSize = "10.5pt";
		this.paddings = "5pt";
	}
	
	//枠＆タッチ設定
	setBoxTouch(parent){
		this.mainMenu(parent);
		this.messageBox(parent);
	}

	//ボックス生成共通
	setCommonBox(parent,menuId="",xpos="0px",ypos="0px"){
		var elm_div = _self.GetInitBox();
		elm_div.x = xpos;
		elm_div.y = ypos;
		elm_div = _self.SetBoxParam(elm_div,menuId,"120px");
		elm_div.linecolor = "solid 1px #C0C0C0";
		_self.AddBoxData(elm_div);
		if(Array.isArray(parent))_self.SettingBox(parent[0],elm_div.Name,"");
		if(!Array.isArray(parent))_self.SettingBox(parent,elm_div.Name,"");
		_self.Elm("."+menuId).style.fontSize = myBT.fontSize;
		_self.Elm("."+menuId).style.paddings = "2px;";
		_self.Elm("."+menuId).style.borderRadius="5px";
	}
	
	//メインメニュー
	mainMenu(parent){
		myBT.setCommonBox(parent,"debug","10px");
		myBT.setCommonBox(parent,"menu1","10px");
		_self.Elm("menu1",_self.TypeID).classList.add("mainmenu");
		_self.AddCommand("menu1",myBT.Menu,"コマンド");
		_self.AddCommand("menu1",myBT.CommandMove,"移動");
		_self.AddCommand("menu1",myBT.CommandTalk,"話す");
		_self.AddCommand("menu1",myBT.CommandLock,"見る");
		_self.AddCommand("menu1",myBT.CommandItem,"道具");
		_self.AddCommand("menu1",myBT.CommandStore,"買い物");
		_self.AddCommand("menu1",myBT.CommandSleep,"寝る");
		_self.AddCommand("menu1",myBT.CommandRest,"休憩");
		_self.AddCommand("menu1",myBT.CommandBattle,"敵を探す");
		_self.AddCommand("menu1",myBT.CommandSex,"押し倒す");
		_self.AddCommand("menu1",myBT.CommandEat,"食事");
		_self.AddCommand("menu1",myBT.CommandOnani,"オナニー");
		_self.AddCommand("menu1",myBT.CommandMakuru,"捲る");
		_self.AddCommand("menu1",myBT.CommandMakuruW,"シャツを捲る");
		_self.AddCommand("menu1",myBT.CommandMakuruU,"スカートを捲る");
		_self.AddCommand("menu1",myBT.CommandMakuruR,"戻る");
		_self.AddCommand("menu1",myBT.CommandKigaeru,"着替える");		
		_self.AddCommand("menu1",myBT.CommandKigae1,"ネグリジェ");		
		_self.AddCommand("menu1",myBT.CommandNugu,"衣服脱着");
		_self.AddCommand("menu1",myBT.CommandNugasu,"脱がす");
		_self.AddCommand("menu1",myBT.CommandSounyuu,"挿入");
		_self.AddCommand("menu1",myBT.CommandShasei,"射精");
		_self.AddCommand("menu1",myBT.CommandWaer,"ローブ");
		_self.AddCommand("menu1",myBT.CommandWaer2,"ブラウス");
		_self.AddCommand("menu1",myBT.CommandWaer3,"スカート");
		_self.AddCommand("menu1",myBT.CommandWaer4,"タイツ");
		_self.AddCommand("menu1",myBT.CommandUnder,"ブラジャー");
		_self.AddCommand("menu1",myBT.CommandUnder2,"パンティー");
		_self.AddCommand("menu1",myBT.CommandBoxnone,"枠を消す");
		_self.AddCommand("menu1",myBT.CommandStatus,"ステータス");
		_self.AddCommand("menu1",myBT.CommandNextDay,"次の日へ");
		_self.AddCommand("menu1",myBT.CommandOption,"オプション");
		_self.AddCommand("menu1",myBT.CommandBtlAttack,"戦う");
		_self.AddCommand("menu1",myBT.Commandjanken,"勝負！");
		_self.AddCommand("menu1",myBT.CommandLock2,"視姦");
		_self.AddCommand("menu1",myBT.CommandGuard,"守る");
		_self.AddCommand("menu1",myBT.CommandBtlItem,"アイテム");
		_self.AddCommand("menu1",myBT.CommandBtlEscape,"逃げる");		
		_self.AddCommand("menu1",myBT.CommandMenuReturn,"戻る");		
		//処理
		//メニュー非表示処理
		this.MenuViewHiddenProc = function(){
			if(_self.GetBoxStatus(myBT.CommandMove)||_self.GetBoxStatus(myBT.CommandSex)||_self.GetBoxStatus(myBT.CommandBtlAttack)||_self.GetBoxStatus(myBT.CommandWaer)||_self.GetBoxStatus(myBT.Commandjanken)||_self.GetBoxStatus(myBT.CommandEat)||_self.GetBoxStatus(myBT.CommandTalk)){
				myBT.MenuHidden();
			}else{
				if(!myRpg.BattleFlg)myBT.MenuView();
				if(myRpg.BattleFlg)myBT.BattleMenuView();
			}
		}
		_self.Elm(myBT.Menu,_self.TypeID).onmousedown = function(){
			if(!_self.CheckTouchEvent()){
				myBT.MenuViewHiddenProc();
			}
		}
		_self.Elm("."+myBT.Menu).ontouchdown = function(){
			myBT.MenuViewHiddenProc();
		}
		myBT.MenuHidden();//非表示
		if(!this.OpeningFlg)myBT.MenuView();//表示
	}
	
	//メニューボックス非表示
	MenuHidden(){
		_self.HiddenBox(myBT.CommandMove);
		_self.HiddenBox(myBT.CommandTalk);
		_self.HiddenBox(myBT.CommandLock);
		_self.HiddenBox(myBT.CommandItem);
		_self.HiddenBox(myBT.CommandStore);
		_self.HiddenBox(myBT.CommandSleep);
		_self.HiddenBox(myBT.CommandRest);
		_self.HiddenBox(myBT.CommandSex);
		_self.HiddenBox(myBT.CommandEat);
		_self.HiddenBox(myBT.CommandOnani);
		_self.HiddenBox(myBT.CommandMakuru);
		_self.HiddenBox(myBT.CommandMakuruW);
		_self.HiddenBox(myBT.CommandMakuruU);
		_self.HiddenBox(myBT.CommandMakuruR);			
		_self.HiddenBox(myBT.CommandNugasu);
		_self.HiddenBox(myBT.CommandSounyuu);
		_self.HiddenBox(myBT.CommandShasei);
		_self.HiddenBox(myBT.CommandWaer);
		_self.HiddenBox(myBT.CommandWaer2);
		_self.HiddenBox(myBT.CommandWaer3);
		_self.HiddenBox(myBT.CommandWaer4);
		_self.HiddenBox(myBT.CommandUnder);		
		_self.HiddenBox(myBT.CommandUnder2);		
		_self.HiddenBox(myBT.CommandMenuReturn);
		_self.HiddenBox(myBT.CommandKigaeru);
		_self.HiddenBox(myBT.CommandKigae1);
		_self.HiddenBox(myBT.CommandNugu);
		_self.HiddenBox(myBT.CommandWaer2);
		_self.HiddenBox(myBT.CommandBoxnone);
		_self.HiddenBox(myBT.CommandBattle);
		_self.HiddenBox(myBT.CommandStatus);
		_self.HiddenBox(myBT.CommandNextDay);
		_self.HiddenBox(myBT.CommandOption);
		_self.HiddenBox(myBT.CommandBtlAttack);
		_self.HiddenBox(myBT.Commandjanken);
		_self.HiddenBox(myBT.CommandLock2);		
		_self.HiddenBox(myBT.CommandBtlItem);
		_self.HiddenBox(myBT.CommandGuard);
		_self.HiddenBox(myBT.CommandBtlEscape);
	}
	//メニューボックス表示
	MenuView(){
		//if(!myST.SexFlg)_self.ViewBox(myBT.CommandMove);
		if(!myST.SexFlg)_self.ViewBox(myBT.CommandTalk);
		//if(!myST.SexFlg)_self.ViewBox(myBT.CommandLock);
		if(!myST.SexFlg)_self.ViewBox(myBT.CommandStatus);
		if((!myST.SexFlg)&&(myRpg.StoreFlg))_self.ViewBox(myBT.CommandStore);
		if((!myST.SexFlg)&&(myRpg.RestFlg))_self.ViewBox(myBT.CommandSleep);
		if((!myST.SexFlg)&&(myRpg.RestFlg))_self.ViewBox(myBT.CommandOnani);//寝るときにオナニーも出来るようにする。
		if(myST.SexFlg)_self.ViewBox(myBT.CommandMakuru);
		if(myST.SexFlg)_self.ViewBox(myBT.CommandNugasu);
		/*if(myST.SexFlg){
			if(myProc.moveIndex==1)_self.ViewBox(myBT.CommandSounyuu);
			if(_self.sample2_flg)_self.HiddenBox(myBT.CommandSounyuu);
			if(myST.ShaseiFlg)_self.ViewBox(myBT.CommandShasei);
			if(_self.sample2_flg)_self.HiddenBox(myBT.CommandShasei);
		}*/
		if(myProc.moveIndex==73)_self.ViewBox(myBT.CommandKigaeru);
		//if(myST.SexFunc==0x11)_self.ViewBox(myBT.CommandSex);
		if(myRpg.FieldFlg)_self.ViewBox(myBT.CommandBattle);
		_self.ViewBox(myBT.CommandEat);
		//_self.ViewBox(myBT.CommandItem);
		_self.ViewBox(myBT.CommandNugu);
		_self.ViewBox(myBT.CommandMakuru);
		_self.ViewBox(myBT.CommandNextDay);
		_self.ViewBox(myBT.CommandSounyuu);//イチャラブモード以外
		if(myST.EventSelect["win"]==8)_self.ViewBox(myBT.CommandLock2);
		//_self.ViewBox(myBT.Commandjanken);
		_self.ViewBox(myBT.CommandBoxnone);
		_self.ViewBox(myBT.CommandOption);
	}
	//着替えメニュー
	MenuKigae(){
		myBT.MenuHidden();
		_self.HiddenBox(myBT.Menu);
		_self.ViewBox(myBT.CommandKigae1);
		_self.ViewBox(myBT.CommandMenuReturn);
		if(myImg.GetIndexPos("shatu")!=imgNegurije){
			_self.Elm(myBT.CommandKigae1,_self.TypeID).innerText = "ネグリジェ";
		}else{
			_self.Elm(myBT.CommandKigae1,_self.TypeID).innerText = "魔導士の服";
		}
	}
	
	//メニューコマンド捲る
	MenuMakuru(){
		_self.HiddenBox(myBT.Menu);
		myBT.MenuHidden();
		_self.ViewBox(myBT.CommandMakuruW);
		_self.ViewBox(myBT.CommandMakuruU);
		_self.ViewBox(myBT.CommandMakuruR);		
	}
	
	//メニュー挿入
	MenuSounyuu2(){
		_self.HiddenBox(myBT.Menu);
		myBT.MenuHidden();
		_self.ViewBox(myBT.CommandSounyuu);	
	}	
	
	//メニューボックス表示
	MenuNugu(){
		myBT.MenuHidden();
		_self.HiddenBox(myBT.Menu);
		//GirlPrison2では使用しない
		//_self.ViewBox(myBT.CommandWaer);
		_self.ViewBox(myBT.CommandWaer2);
		_self.ViewBox(myBT.CommandWaer3);
		//_self.ViewBox(myBT.CommandWaer4);
		_self.ViewBox(myBT.CommandUnder);
		_self.ViewBox(myBT.CommandUnder2);
		_self.ViewBox(myBT.CommandBoxnone);
		_self.ViewBox(myBT.CommandMenuReturn);
	}	
	//メニューボックス表示
	MenuNugasu(){
		_self.HiddenBox(myBT.CommandMove);
		_self.HiddenBox(myBT.CommandTalk);
		_self.HiddenBox(myBT.CommandLock);
		_self.HiddenBox(myBT.CommandSex);
		_self.HiddenBox(myBT.CommandMakuru);
		_self.HiddenBox(myBT.CommandSounyuu);
		if(myST.SexFlg)_self.ViewBox(myBT.CommandWaer);
		if(myST.SexFlg)_self.ViewBox(myBT.CommandUnder);		
	}
	//メニューボックス表示
	MenuSounyuu(){
		_self.HiddenBox(myBT.CommandMove);
		_self.HiddenBox(myBT.CommandTalk);
		_self.HiddenBox(myBT.CommandLock);
		_self.ViewBox(myBT.CommandSex);
		_self.ViewBox(myBT.CommandMakuru);
		if(myST.SexFlg){
			if(myProc.moveIndex==1)_self.ViewBox(myBT.CommandSounyuu);
		}
		if(myST.SexFlg)_self.ViewBox(myBT.CommandWaer);
		if(myST.SexFlg)_self.ViewBox(myBT.CommandUnder);		
	}
	//戦闘用メニュー表示
	BattleMenuView(){
		myBT.MenuHidden();
		_self.ViewBox(myBT.CommandBtlAttack);
		_self.ViewBox(myBT.CommandGuard);
		_self.ViewBox(myBT.CommandBtlItem);
		_self.ViewBox(myBT.CommandBtlEscape);
	}
	
	//移動先メニュー
	moveMenu(parent,movedata){
		_self.Elm(myBT.Menu,_self.TypeID).onmousedown();
		_self.HiddenBox(myBT.Menu);
		myBT.setCommonBox(parent,myBT.MenuMove,"10px");
		_self.ViewBox(myBT.MenuMove);
		//移動メニューを一度クリア
		_self.Elm(myBT.MenuMove,_self.TypeID).innerHTML = "";
		for(var loop in movedata){
			var lcID = "move"+movedata[loop][0];
			var lcName = movedata[loop][1];
			_self.AddCommand(myBT.MenuMove,lcID,lcName);
			myBT.setCommandProcessing(lcID,function(){
				var spos = String("move").length;
				var no = this.id.substr(spos,this.id.length-spos);
				movedata[loop][2](no);
				_self.Elm(myBT.CommandReturn,_self.TypeID).onmousedown();
			});
		}
		_self.AddCommand(myBT.MenuMove,myBT.CommandReturn,"戻る");		
		//処理
		_self.Elm(myBT.CommandReturn,_self.TypeID).onmousedown = function(){
			_self.HiddenBox(myBT.MenuMove);
			_self.ViewBox(myBT.Menu);
		}		
	}
	
	//コマンド処理設定
	setCommandProcessing(key,func){
		var elmKey = "."+key;
		if(_self.CheckTouchEvent()) {
			//タッチ対応
			_self.Elm(elmKey).ontouchdown = func;
		} else {
			//タッチ非対応
			_self.Elm(elmKey).onmousedown = func;
		}
	}
	
	//メッセージボックス
	messageBox(parent){
		var boxWidth = (_self.width_hi-350)>=50?350:325;
		var x_pos = (_self.width_hi-boxWidth)/2+"px";
		var y_pos = _self.height_hi<500?"335px":"360px";
		this.setCommonBox(parent,myBT.MsgBox,x_pos,y_pos);
		var data = _self.GetBoxData(myBT.MsgBox);
		data.width = boxWidth+"px";
		data.height = "150px";
		_self.ChangeBox("msgBox");
	}
	
	//メッセージ表示
	setMessage(msg,mouseDown=true){
		if(myProc.talkLock){
			return;
		}
		//メッセージボックスが非表示なら先に行かない。
		if(!_self.GetBoxStatus(myBT.MsgBox)){
			return;
		}
		if(myBT.messageCount<msg.length){
			myBT.Message = msg;
			document.onmousedown = null;
			_self.setTimer(function(mouseDown){
				document.onmousedown = function(){
					if(mouseDown)myBT.setMessage(myBT.Message);
				}
			},100,mouseDown);
			var vCheck = msg[myBT.messageCount];
			if(!Array.isArray(vCheck)){
				myBT.showMessage(msg[myBT.messageCount]);
			}else if(vCheck[0]=="FUNC"){
				vCheck[1]();
			}
			myBT.messageCount++;
		}else{
			document.onmousedown = null;
			myBT.messageCount = 0;
		}
	}
	
	//デバッグメッセージ
	debugMessage(msg){
		if(_self.debug){
			console.log(msg);
			//debugView.innerText += msg;
		}
	}
	
	//メッセージ表示用
	showMessage(msg){
		if(myProc.OrgasmModeFlg)msg = msg+"<br>タッチ回数:"+myProc.TouchCount;
		_self.Elm(myBT.MsgBox,_self.TypeID).innerHTML = msg!=""?msg+"<br>▼":"▼";
		if(myProc.OutPutFlg){
			while(msg.indexOf("<br>")!=-1){
				msg = msg.replace("<br>","\n",msg);
			}
			myProc.MsgData += msg+"\n";
		}
	}
	
	//読み書きデータ枠作成
	saveLoadBox(parent,index){
		var boxWidth = 300;
		var x_pos = (_self.width_hi-boxWidth)/2+"px";
		var y_pos = 20+index*105+"px";		
		myBT.setCommonBox(parent,"saveLoad"+index,x_pos,y_pos);
		var data = _self.GetBoxData("saveLoad"+index);
		data.width = boxWidth+"px";
		data.height = 100+"px";
		_self.ChangeBox("saveLoad"+index);		
		return "saveLoad"+index;
	}
	
	//OptionMessage
	optionMessage(parent,msg){
		var elm = _self.Elm("OptionMessage",_self.TypeID);
		if(elm == undefined){
			var x_pos = "0px";
			var y_pos = "0px";		
			myBT.setCommonBox(parent,"OptionMessage",x_pos,y_pos);
			var data = _self.GetBoxData("OptionMessage");
			data.width = _self.width_hi+"px";
			data.height = _self.height_hi+"px";
			_self.ChangeBox("OptionMessage");
			elm = _self.Elm("OptionMessage",_self.TypeID);
			elm.style.textAlign = "center";
		}
		elm.innerHTML = null;
		elm.innerHTML += "<br><br><br><br><br><br>";
		elm.innerHTML += msg;
		elm.innerHTML += "<br>";
		elm.innerHTML += "画面タッチでメッセージを閉じます。<br>";
		myBT.setCommandProcessing("OptionMessage",function(){
			_self.HiddenBox("OptionMessage");
		});
		_self.ViewBox("OptionMessage");
		return "OptionMessage";		
	}	
	
	//YesNoBox
	yesNoBox(parent,msg,func,func2=null){
		var elm = _self.Elm("YesNoBox",_self.TypeID);
		if(elm == undefined){
			var x_pos = "0px";
			var y_pos = "0px";		
			myBT.setCommonBox(parent,"YesNoBox",x_pos,y_pos);
			var data = _self.GetBoxData("YesNoBox");
			data.width = _self.width_hi+"px";
			data.height = _self.height_hi+"px";
			_self.ChangeBox("YesNoBox");
			elm = _self.Elm("YesNoBox",_self.TypeID);
			elm.style.textAlign = "center";
		}
		elm.innerHTML = null;
		elm.innerHTML += "<br><br><br><br><br><br>";
		elm.innerHTML += msg;
		elm.innerHTML += "<br>";
		elm.innerHTML += "<span id='Yes'>はい</span>　　　<span id='No'>いいえ</span>";
		_self.AddEventForId("Yes",function(e){
			_self.HiddenBox("YesNoBox");
			func();
		});
		_self.AddEventForId("No",function(e){
			_self.HiddenBox("YesNoBox");
			if(func2!=null)func2();
		});			
		_self.ViewBox("YesNoBox");
		return "YesNoBox";		
	}
	
	//選択肢
	selectBox(parent,select){
		var idarray = [];
		var elm = _self.Elm("selectBox",_self.TypeID);
		if(elm == undefined){
			var x_pos = "0px";
			var y_pos = "0px";		
			myBT.setCommonBox(parent,"selectBox",x_pos,y_pos);
			var data = _self.GetBoxData("selectBox");
			data.width = _self.width_hi+"px";
			data.height = _self.height_hi+"px";
			_self.ChangeBox("selectBox");
			elm = _self.Elm("selectBox",_self.TypeID);
			elm.style.textAlign = "center";
		}
		elm.innerHTML = null;
		elm.innerHTML += "<br><br><br><br><br><br>";
		for(var loop in select){
			var serColor = "";
			if(select[loop][2]!==undefined){
				if(select[loop][2] == "color")serColor = "color:red;";
			}
			elm.innerHTML += "<span id='select"+loop+"' style='font-size:14pt;"+serColor+"'>【"+select[loop][0]+"】</span><br><br><br>";
			idarray[loop] = "select"+loop;
		}
		_self.ViewBox("selectBox");
		return idarray;		
	}
	//選択肢
	EndingBox(parent){
		var x_pos = "0px";
		var y_pos = "0px";		
		myBT.setCommonBox(parent,"EndingBox",x_pos,y_pos);
		var data = _self.GetBoxData("EndingBox");
		data.width = _self.width_hi+"px";
		data.height = _self.height_hi+"px";
		data.opacity = 0.5;
		_self.ChangeBox("EndingBox");
		var elm = _self.Elm("EndingBox",_self.TypeID);
		elm.style.textAlign = "center";
		elm.innerHTML += "<br><br><br><br><br><br><br><br><br>Thank you for playing!!";
		_self.ViewBox("EndingBox");		
	}

	DayTime(){
		var parent = _self.Elm("operation",_self.TypeID);
		var xpos = "250px";
		if(_self.width_hi<400)xpos = "200px";
		myBT.setCommonBox(parent,myBT.IDDayTime,xpos);
		myBT.chgDayTime = function(){
			var time = ["朝/昼","夕方","夜","深夜"];
			var len = myProc.movedata[0].length-1;
			var option = "行動回数:"+myProc.DayActCount+"回<br>";
			//_self.Elm(myBT.IDDayTime,_self.TypeID).innerHTML = myProc.Day+"Day："+time[myImg.backCorrect]+"<br>"+option;
			_self.Elm(myBT.IDDayTime,_self.TypeID).innerHTML = myProc.Day+"Day<br>"+option;
			_self.ViewBox(myBT.IDDayTime);
		}
		myBT.chgDayTime();
	}
	
	OrgasmFunc(){
		var parent = _self.Elm("operation",_self.TypeID);
		var xpos = "250px";
		var ypos = "46px";
		if(_self.width_hi<400)xpos = "200px";
		if(_self.Elm(myBT.IDOrgasm,_self.TypeID)==undefined){
			myBT.setCommonBox(parent,myBT.IDOrgasm,xpos,ypos);
			_self.AddCommandDiv(myBT.IDOrgasm,"OrgasmMode","タッチモード");
			_self.AddCommandDiv(myBT.IDOrgasm,myBT.CommandOrgasm,"【モード切替】");
			_self.ViewBox(myBT.IDOrgasm);
		}
	}
}
myBT = new MyTouch();