// 共用JavaScript

function pageJump(uri) {
	if (uri != "#") {
		document.getElementById('jumpForm').action = uri;
		document.getElementById('jumpForm').submit();
	}
}

/**
 * 呼び出し
 *
 * @param i 属性名
 * @param j 属性値
 * @param k 呼出先
 * @param l ターゲット
 */
function doPost(i,j,k,l) {
	document.codeForm.elements[0].name  = i;
	document.codeForm.elements[0].value = j;
	document.codeForm.action = k;
	if (l) {
		document.codeForm.target = l;
	} else {
		document.codeForm.target = "_self";
	}
	document.codeForm.submit();
}

/**
 * 呼び出し(3)
 *
 * @param n1 属性名(1)
 * @param v1 属性値(1)
 * @param n2 属性名(2)
 * @param v2 属性値(2)
 * @param n3 属性名(3)
 * @param v3 属性値(3)
 * @param k 呼出先
 * @param l ターゲット
 */
function doPost3(n1,v1,n2,v2,n3,v3,k,l) {
	document.codeForm2.elements[0].name  = n1;
	document.codeForm2.elements[0].value = v1;
	if (n2) {
		document.codeForm2.elements[1].name  = n2;
		document.codeForm2.elements[1].value = v2;
	}
	if (n3) {
		document.codeForm2.elements[2].name  = n3;
		document.codeForm2.elements[2].value = v3;
	}
	document.codeForm2.action = k;
	if (l == 'CONF') {
		if (confirm("このまま処理を続けてよろしいですか？")) {
			document.codeForm2.target = "_self";
			document.codeForm2.submit();
		}
	} else if (l) {
		document.codeForm2.target = l;
		document.codeForm2.submit();
	} else {
		document.codeForm2.target = "_self";
		document.codeForm2.submit();
	}
}

/**
 * 登録・修正
 *
 * @param i モード
 * @param j タイプ
 */
function myAddSubm(i,j) {
	document.fm.mode.value  = i;
	if (j == 2) {
		if (confirm("処理を反映いたします。\nこのまま処理してよろしいですか？")) {
			document.fm.submit();
		}
	} else {
		document.fm.submit();
	}
}

/**
 * ボタン色変更
 *
 * @param i 対象
 */
function myBtnOver(i) {
	i.style.backgroundColor = "#609d48";
	i.style.color = "#FFFFFF";
}
function myBtnOut(i) {
	i.style.backgroundColor = "#e9f6e7";
	i.style.color = "#609d48";
}

/**
 * ページ変更
 */
function changePage(i,j) {
	if (i == "page") {
		document.pageForm.action = "pageShw.php";
	} else if (i == "papg") {
		document.pageForm.action = "papgShw.php";
		document.pageForm.modeId.value = j;
	} else if (i == "pcar") {
		document.pageForm.action = "pcarShw.php";
		document.pageForm.carrId.value = j;
	} else if (i == "pdet") {
		document.pageForm.action = "pdetShw.php";
		document.pageForm.kgrpId.value = j;
	} else if (i == "tmpl") {
		document.tmplForm.action = "tmplShw.php";
	} else if (i == "tcar") {
		document.tmplForm.action = "tcarShw.php";
		document.tmplForm.carrId.value = j;
	} else if (i == "tmpg") {
		document.tmplForm.action = "tmpgShw.php";
		document.tmplForm.modeId.value = j;
	} else if (i == "tdet") {
		document.tmplForm.action = "tdetShw.php";
		document.tmplForm.kgrpId.value = j;
	} else {
		return false;
	}
	if (i.charAt(0) == "p") {
		document.pageForm.submit();
	} else {
		document.tmplForm.submit();
	}
}

/**
 * 編集画面呼出(編集画面)
 */
var _type = "";
var winASP = "";
var winPview = "";
function myPage(i) {
	_type = i;
	if (typeof window.winASP.document == "object") {
		winASP.close();
	}
	winASP = "";
	_sta = "scrollbars=1,toolbar=0,location=0,directories=0,status=1,menubar=no,resizable=1,width=760,height=600";
	winASP = window.open('../view/pageMak.php','winASP',_sta);
	winASP.moveTo(0,0);
	winASP.focus();
}


/**
 * 編集画面呼出(プレビュー)
 */
function myPv9(v1,v2) {
	if (typeof window.winPview.document == "object") {
		winPview.close();
	}
	winPview = "";
	_sta = "scrollbars=1,toolbar=0,location=0,directories=0,status=1,menubar=no,resizable=1,width=830,height=650";
	winPview = window.open('','winPview',_sta);
	winPview.moveTo(0,0);
	winPview.focus();

	document.codeForm.target = "winPview";
	document.codeForm.action = "../view/pagePre.php";
	document.codeForm.elements[0].name  = v1;
	document.codeForm.elements[0].value = v2;
	document.codeForm.submit();
}

/**
 * 別ウィンドウで検索
 */
var _sWin = "";
var _sTbl = "";
function swo(i,j,k) {
	if (typeof window._sWin.document == "object" && _sTbl == i) {
		_sWin.focus();
	} else {
		_sWin = "";
		_stat = "scrollbars=1,toolbar=0,location=0,directories=0,status=1,menubar=no,resizable=1,width=750,height=600";
		_sWin = window.open('/mu.html','_sWin',_stat);
		_sWin.moveTo(0,0);
		_sWin.focus();
		document.codeForm2.target = "_sWin";
		document.codeForm2.action = "../../searWin/" + i + "Win.php";
		document.codeForm2.elements[0].name  = 'code';
		document.codeForm2.elements[0].value = j;
		document.codeForm2.elements[1].name  = 'name';
		document.codeForm2.elements[1].value = k;
		document.codeForm2.submit();
		_sTbl = i;
	}
}

function svl(i,j,k,l) {
	if (typeof opener.top.main != "object") {
		alert("呼び出し元がありません。");
	} else {
		opener.top.main.document.fm[i].value = k;
		if (l) {
			opener.top.main.document.fm[j].value = l;
//			opener.top.main.document.getElementById(j).innerHTML = l;
		}
		opener.top.main.focus();
	}
}

/**
 * インラインフレームで呼び出し
 *
 * @param i 呼び出し元テキストエリア
 * @param j 出力先ID
 * @param k 横幅
 * @param l 縦幅
 */
function myTextComm(i,j,k,l) {
	var _html = document.fmcomm[i].value;
	var iframe = document.createElement('IFRAME');
	if (k) {
		iframe.style.width  = k + "px";
	} else {
		iframe.style.width  = "260px";
	}
	if (l) {
		iframe.style.height = l + "px";
	} else {
		iframe.style.height = "400px";
	}

	document.getElementById(j).appendChild(iframe);
	var doc = frames[frames.length - 1].document;
	doc.open();
	doc.write(_html);
	doc.close();
}

/**
 * オプション取得
 */
var r_xmlHttpObj = 
		this.XMLHttpRequest ? 
			new XMLHttpRequest() : 
			new ActiveXObject("Msxml2.XMLHTTP") || 
			new ActiveXObject("Microsoft.XMLHTTP");

var a_xmlHash = {};

function parseText(text) {
	text = text.replace(/\r\n?/g, "\n");
	var hash = {};
	var list = text.split("&");
	for (var i=0; i<list.length; i++) {
		var eq = list[i].indexOf("=");
		if (eq >= 0) {
			var ky1 = decodeURIComponent(list[i].substr(0,eq).replace("+","%20"));
			var vl1 = decodeURIComponent(list[i].substr(eq+1).replace("+","%20"));
			hash[ky1] = vl1;
		} else {
			hash[list[i]] = "";
		}
	}
	return hash;
}

function optionChange2(n1,n2,n3) {
	var url = "../../searWin/" + n3 + "Get.php";
	var cur = n1;
	var nex = n2;
	var s = document.fm[cur].selectedIndex;
	var n = document.fm[cur].options[s].value;
	if (n == 0) {
		return;
	}

	if (!document.fm[nex]) {
		return;
	}

	r_xmlHttpObj.open("POST",url,false);
	r_xmlHttpObj.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	r_xmlHttpObj.onreadystatechange = function() {
		if (r_xmlHttpObj.readyState == 4) {
			if (r_xmlHttpObj.status == 200) {
				a_xmlHash = parseText(r_xmlHttpObj.responseText);
				if (a_xmlHash["status"] != "OK") {
					alert("取得に失敗しました。\n" + a_xmlHash["errormessage"]);
				} else {
					setOption2(nex);
				}
			} else {
				alert("通信に失敗しました。ごめんなさい。");
			}
		}
	}
	var body = cur + "=" + n;
	r_xmlHttpObj.send(body);
}

function setOption2(n) {
	var sel = new Array();
	sel.push(n);

	for (var i=0; i<sel.length; i++) {
		var s = document.fm[sel[i]];
		if (!s) {
			continue;
		}
		var c = s.options.length - 1;
		for (var x=c; x>=0; x--) {
			s.remove(x);
		}
	}

	var el = document.createElement("OPTION");
	el.text = "指定なし";
	el.value = "";
	document.fm[n].add(el);

	for (var i in a_xmlHash) {
		if (i != "status" && i != "errormessage" && i != "count") {
			el = document.createElement("OPTION");
			el.text = a_xmlHash[i];
			el.value = i;
			document.fm[n].add(el);
		}
	}
}


