//
//multi-functions 1.0
//F-NOTES WSS2.9B
//11/04/18
//script by Motohiro Iwatsuki(homepage@ipc-tokai.or.jp)


//Image Layer Open
function SUBILW(ac0siw, ac1siw, ac2siw, ac3siw){
	//ac0siw:img file(fullpath)
	//ac1siw:size-width
	//ac2siw:size-height
	//ac3siw:file type img|url|pdf|fla

	ie_flg = (navigator.userAgent.indexOf("MSIE") != -1) * 1;
	ac1siw = ac1siw *1;
	ac2siw = ac2siw *1;

	var win_width = 0;
	var win_height = 0;
	var win_scroll = 0;
	win_event = 0;
	if (document.body.clientWidth){
		win_width = document.body.clientWidth;
		win_height = document.body.clientHeight;
	}
	else if (document.documentElement.clientWidth){
		win_width = document.documentElement.clientWidth;
		win_height = document.documentElement.clientHeight;
	}
	else if (window.innerWidth){
		win_width = window.innerWidth;
		win_height = window.innerHeight;
	}

	if (window.pageYOffset){
		win_scroll = window.pageYOffset;
	}
	else if (document.body.scrollTop){
		win_scroll = document.body.scrollTop;
	}
	else if (document.documentElement.scrollTop){
		win_scroll = document.documentElement.scrollTop;
	}
	else if (window.window.scrollY){
		win_scroll = window.window.scrollY;
	}

	var elm_posx = Math.floor((win_width - ac1siw) / 2);
	//var elm_posy = Math.floor((win_height - ac2siw) / 2) - win_scroll;
	//var elm_posy = win_scroll + Math.floor(ac2siw / 2);
	var elm_posy = win_scroll + 30;

	if (ac3siw == "img"){
		var htm_tag = "<img src='" + ac0siw + "' width='" + ac1siw + "' heigt='" + ac2siw + "' onClick='SUBILC();return false;'/>";
	}

	document.getElementById('BOX-GLOBA-LAY1-FRM').style.visibility = 'visible';
	document.getElementById('comm-box-lay1-frm').style.width =  ac1siw + "px";
	document.getElementById('comm-box-lay1-frm').style.height = ac2siw + "px";
	document.getElementById('comm-box-lay1-frm').style.top = elm_posy + "px";
	document.getElementById('comm-box-lay1-frm').style.left = elm_posx + "px";
	document.getElementById('comm-box-lay1-frm').innerHTML = htm_tag;
}

//Image Layer Close
function SUBILC(){
	document.getElementById('BOX-GLOBA-LAY1-FRM').style.visibility = 'hidden';
	document.getElementById('comm-box-lay1-frm').innerHTML = "";
}

//HTML Layer Open
function SUBHLW(ac0shw, ac1shw, ac2shw, ac3shw){
	//ac0shw:file(fullpath) |html
	//ac1shw:size-width
	//ac2shw:size-height
	//ac3shw:file|html

	ie_flg = (navigator.userAgent.indexOf("MSIE") != -1) * 1;
	ac1shw = ac1shw *1;
	ac2shw = ac2shw *1;

	var win_width = 0;
	var win_height = 0;
	var win_scroll = 0;
	win_event = 0;
	if (parent.document.body.clientWidth){
		win_width = parent.document.body.clientWidth;
		win_height = parent.document.body.clientHeight;
	}
	else if (parent.document.documentElement.clientWidth){
		win_width = parent.document.documentElement.clientWidth;
		win_height = parent.document.documentElement.clientHeight;
	}
	else if (parent.window.innerWidth){
		win_width = parent.window.innerWidth;
		win_height = parent.window.innerHeight;
	}

	if (parent.window.pageYOffset){
		win_scroll = parent.window.pageYOffset;
	}
	else if (parent.document.body.scrollTop){
		win_scroll = parent.document.body.scrollTop;
	}
	else if (parent.document.documentElement.scrollTop){
		win_scroll = parent.document.documentElement.scrollTop;
	}
	else if (parent.window.window.scrollY){
		win_scroll = parent.window.window.scrollY;
	}

	var elm_posx = Math.floor((win_width - ac1shw) / 2);
	//var elm_posy = Math.floor((win_height - ac2shw) / 2) - win_scroll;
	//var elm_posy = win_scroll + Math.floor(ac2shw / 2);
	var elm_posy = win_scroll + 30;

	parent.document.getElementById('BOX-GLOBA-LAY2-FRM').style.visibility = 'visible';
	parent.document.getElementById('comm-box-lay2-frm').style.width =  ac1shw + "px";
	parent.document.getElementById('comm-box-lay2-frm').style.height = ac2shw + "px";
	parent.document.getElementById('comm-box-lay2-frm').style.top = elm_posy + "px";
	parent.document.getElementById('comm-box-lay2-frm').style.left = elm_posx + "px";

	if (ac3shw == "html"){
		htm_tag = ac0shw;
		parent.document.getElementById('comm-box-lay2-frm').innerHTML = htm_tag;
	}
}

//HTML Layer Close
function SUBHLC(){
	parent.window.document.getElementById('BOX-GLOBA-LAY2-FRM').style.visibility = 'hidden';
	parent.window.document.getElementById('comm-box-lay2-frm').innerHTML = "";
}

//HTML Direct Layer Open
function SUBHCD(ac0shd, ac1shd, ac2shd){
	//ac0shd:targetBoxId
	//ac1shd:size-width
	//ac2shd:size-height

	ie_flg = (navigator.userAgent.indexOf("MSIE") != -1) * 1;
	ac1shd = ac1shd *1;
	ac2shd = ac2shd *1;

	var win_width = 0;
	var win_height = 0;
	var win_scroll = 0;
	win_event = 0;
	if (document.body.clientWidth){
		win_width = document.body.clientWidth;
		win_height = document.body.clientHeight;
	}
	else if (document.documentElement.clientWidth){
		win_width = document.documentElement.clientWidth;
		win_height = document.documentElement.clientHeight;
	}
	else if (window.innerWidth){
		win_width = window.innerWidth;
		win_height = window.innerHeight;
	}

	if (window.pageYOffset){
		win_scroll = window.pageYOffset;
	}
	else if (document.body.scrollTop){
		win_scroll = document.body.scrollTop;
	}
	else if (document.documentElement.scrollTop){
		win_scroll = document.documentElement.scrollTop;
	}
	else if (window.window.scrollY){
		win_scroll = window.window.scrollY;
	}

	var elm_posx = Math.floor((win_width - ac1shd) / 2);
	//var elm_posy = Math.floor((win_height - ac2shd) / 2) - win_scroll;
	//var elm_posy = win_scroll + Math.floor(ac2shd / 2);
	var elm_posy = win_scroll + 30;

	document.getElementById(ac0shd).style.visibility = 'visible';
	document.getElementById(ac0shd).style.width =  ac1shd + "px";
	document.getElementById(ac0shd).style.height = ac2shd + "px";
	document.getElementById(ac0shd).style.top = elm_posy + "px";
	document.getElementById(ac0shd).style.left = elm_posx + "px";
}

//HTML Direct Layer Close
function SUBHCC(ac0shc){
	document.getElementById(ac0shc).style.visibility = 'hidden';
}


//Image Window Open
function SUBIGW(ac0swp, ac2swp, ac3swp){
	//ac0swp:img file(fullpath)
	//ac2swp:size-width
	//ac3swp:size-height

	IMGWIN = window.open("", "IMGWIN", "toolbar=no,location=no,directories=no,status=yes,nemubar=no,scrollbars=no,resizable=yes");
	ac2swp+=24;
	ac3swp+=72;
	IMGWIN.resizeTo(ac2swp, ac3swp);
	IMGWIN.focus();
	IMGWIN.location.href = ac0swp;
}


//Input Values for Form
function SUBIVF(ac0svf, ac1svf, ac2svf){
	//ac0svf:form id
	//ac1svf:element id
	//ac2svf:value

	document.forms[ac0svf].elements[ac1svf].value = ac2svf;
}


//Like a sprintf
function SUBSPF(ac0spf,ac1spf){
	//ac0spf:num
	//ac1spf:length

	var num_len = String(ac0spf).length;
	var num_lop = ac1spf - num_len;
	if (num_lop < 0){num_lop = 0;}

	var nun_str = "";
	var loopc;
	for (loopc = 0; loopc < num_lop; loopc++){
		nun_str += "0";
	}

	var nun_ret = nun_str + ac0spf;
	return nun_ret;
}


//Hide & View
function SUBDHV(ac0sdv, ac1sdv){
	var dsp = new Array();
	var flg = ac1sdv * 1;

	dsp[0] = "none";
	dsp[1] = "block";
	document.getElementById(ac0sdv).style.display = dsp[flg];
}

//Open Check Window
function SUBCHF(){
	CHKWIN = window.open("", "CHKWIN", "toolbar=no,location=no,directories=no,status=yes,nemubar=no,scrollbars=yes,resizable=yes");
	CHKWIN.resizeTo(320,320);
	CHKWIN.moveTo(0,0);
	CHKWIN.focus();
}


//Send GetParam
function SUBSGP(ac0ssg){
	url = encodeURI(ac0ssg);
	location.href = url;
	return true;
}


//Accept GetParam
function SUBAGP(ac0asg, ac1asg, ac2asg){
	//ac0asg：仕切りパラメータ（?***=）
	//ac1asg：値を入力するフォーム名
	//ac2asg：値を入力するフォームの要素名

	ureasg = new Array();
	urlasg = document.URL;
	ureasg = urlasg.split(ac0asg);
	ureasg[1] = decodeURI(ureasg[1]);
	if (ureasg[1] == "undefined"){ureasg[1] = "";}
	document.forms[ac1asg].elements[ac2asg].value = ureasg[1];
}


//Replace Func Altanative
function SUBRFA(ac0sfa, ac1sfa, ac2sfa){
	var strelm = new Array();
	var rstrerep = "";

	strelm = ac0sfa.split(ac1sfa);
	rstrerep = strelm.join(ac2sfa);

	return rstrerep;
}


//Form Checker
function SUBSMC(ac0lsc,ac1lsc,ac2lsc,ac3lsc) {
	var accbuf = new Array();

	for (var pstnam in chkprm[ac0lsc]){
		var chktyp = (document.forms[ac0lsc].elements[pstnam].length > 0) * 1;
		if (chktyp == 1 && document.forms[ac0lsc].elements[pstnam][0].type == "radio"){
			accbuf[pstnam] = "0";
			var chkcnt = document.forms[ac0lsc].elements[pstnam].length;
			for (loopc = 0; loopc < chkcnt; loopc++){
				if (document.forms[ac0lsc].elements[pstnam][loopc].checked === true){
					accbuf[pstnam] = "1";
					break;
				}
			}
		}

		else if (document.forms[ac0lsc].elements[pstnam].type == "checkbox"){
		}

		else {
			accbuf[pstnam] = document.forms[ac0lsc].elements[pstnam].value;
		}
	}


	resflg = 0;
	for (var name in chkprm[ac0lsc]){
		chkprd = new Array();
		chkprd = chkprm[ac0lsc][name].split(",", 3);
		chkpre1 = new Array();
		chkpre1 = chkprd[1].split("&&", 3);

		if (chkprd[0] == "asc"){
			chkflg = 0;
			chklng0 = chkpre1[1];
			chklng1 = chkpre1[2];
			eptflg = (accbuf[name] == "" && chkpre1[0] == "1") * 1;
			cmpflg = (accbuf[name] != "" && (accbuf[name].length < chklng0 || accbuf[name].length > chklng1)) * 1;
			if (eptflg > 0 || cmpflg > 0){resflg = 1;chkflg = 1;}
			if (chkflg == 0){document.getElementById(chkprd[2]).className = ac1lsc;}
			if (chkflg == 1){document.getElementById(chkprd[2]).className = ac2lsc;}
		}

		else if (chkprd[0] == "knj"){
			chkflg = 0;
			chklng0 = chkpre1[1];
			chklng1 = chkpre1[2];
			eptflg = (accbuf[name] == "" && chkpre1[0] == "1") * 1;
			cmpflg = (accbuf[name] != "" && (accbuf[name].length < chklng0 || accbuf[name].length > chklng1)) * 1;
			if (eptflg > 0 || cmpflg > 0){resflg = 1;chkflg = 1;}
			if (chkflg == 0){document.getElementById(chkprd[2]).className = ac1lsc;}
			if (chkflg == 1){document.getElementById(chkprd[2]).className = ac2lsc;}
		}

		else if (chkprd[0] == "num"){
			chkflg = 0;
			cmpnum0 = chkpre1[1];
			cmpnum1 = chkpre1[2];
			chknum = accbuf[name].replace(/[^0-9A-Za-z]/,"");
			eptflg = (accbuf[name] == "" && chkpre1[0] == "1") * 1;
			cmpflg = (accbuf[name] != "" && ((chknum < cmpnum0) === true || (chknum > cmpnum1) === true)) * 1;
			if (eptflg > 0 || cmpflg > 0){resflg = 1;chkflg = 1;}
			if (chkflg == 0){document.getElementById(chkprd[2]).className = ac1lsc;}
			if (chkflg == 1){document.getElementById(chkprd[2]).className = ac2lsc;}
		}

		else if (chkprd[0] == "chk"){
			chkflg = 0;
			cmpnum0 = chkpre1[1];
			cmpnum1 = chkpre1[2];
			eptflg = (accbuf[name] == "0" && chkpre1[0] == "1") * 1;
			if (eptflg > 0){resflg = 1;chkflg = 1;}
			if (chkflg == 0){document.getElementById(chkprd[2]).className = ac1lsc;}
			if (chkflg == 1){document.getElementById(chkprd[2]).className = ac2lsc;}
		}

		else if (chkprd[0] == "vlc"){
			chkflg = 0;
			chklng0 = chkpre1[1];
			eptflg = (accbuf[name] == "" && chkpre1[0] == "1") * 1;
			cmpflg = (accbuf[name] != "" && (accbuf[chklng0] != accbuf[name])) * 1;
			if (eptflg > 0 || cmpflg > 0){resflg = 1;chkflg = 1;}
			if (chkflg == 0){document.getElementById(chkprd[2]).className = ac1lsc;}
			if (chkflg == 1){document.getElementById(chkprd[2]).className = ac2lsc;}
		}
	}


	if (resflg == 0){
		return true;
	}
	if (resflg == 1){
		alert(ac3lsc);
		return false;
	}
}


//Image Swap & Recover
function SUBIMS(ac0sim){
	if (!imgbuf){return;}
	imgrec = document.getElementById(ac0sim.id).src;
	document.getElementById(ac0sim.id).src = imgbuf[ac0sim.id].src;
}
function SUBIMR(ac0sir){
	document.getElementById(ac0sir.id).src = imgrec;
}

