/*

''' Project	 : js
''' Class	 : common
'''

''' <summary>
''' 共通JavaScript
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	システムエルフ 川岸	2006/11/02	作成
''' </history>

*/

var appName = location.pathname;
var vals = appName.split("/");
if (vals.length > 1) {
	appName = vals[1];
} else {
	appName = "";
}

function openSubWindow(url, args) {
	return showModalDialog(url, args, 'status:false;dialogWidth:1024px;dialogHeight:700px');
}

function clickButton(buttonCtlId) {
	setTimeout("\$get('" + buttonCtlId + "').click()", 100);
}

function focusBody() {
	document.body.focus();
}

function setFocus(id) {
	try {
		$get(id).focus();
	} catch (e) {
	}
}

function rollover(obj, active, image) {
	if (active) {
		//obj.style.color = "white";
		//obj.style.backgroundColor = "#1066de";
		obj.style.fontWeight = "bold";
	} else {
		//obj.style.color = "black";
		//obj.style.backgroundColor = "";
		obj.style.fontWeight = "normal";
	}
//	obj.style.backgroundImage = "url(../../images/" + image + ")";
}

function getToday() {

	var now = new Date();

	var year = now.getYear();
	var month = now.getMonth() + 1;
	if (month < 10) {
		month = "0" + month;
	}
	var day = now.getDate();
	if (day < 10) {
		day = "0" + day;
	}

	return year + "/" + month + "/" + day;
}

function getNow() {

	var now = new Date();

	var hour = now.getHours();
	if (hour < 10) {
		hour = "0" + hour;
	}
	var minute = now.getMinutes();
	if (minute < 10) {
		minute = "0" + minute;
	}
	var second = now.getSeconds();
	if (second < 10) {
		second = "0" + second;
	}

	return getToday() + " " + hour + ":" + minute + ":" + second;
}

function setToday(obj) {
	obj.innerText = getToday();
}

/*
<summary>
メッセージボックスを表示する
</summary>
<param name="msgKbn">メッセージ区分</param>
<param name="ansKbn">応答区分</param>
<param name="title">タイトル</param>
<param name="msg">メッセージ</param>
<returns>OK/NG</returns>
<remarks>
</remarks>
*/
function showMsgBox(msgKbn, ansKbn, title, msg) {
	var ret = false;

	if (navigator.appName.charAt(0) == "M") {
		// IE

		var rst = VbsShowMsgBox(msgKbn, ansKbn, title, msg);

		if (rst == 0) {
			ret = true;
		} else {
			ret = false;
		}

	} else {
		// IE以外

		switch (ansKbn) {
			case "2":
			case "3":
				// ＯＫ＋キャンセル
				// はい＋いいえ
			
				ret = confirm(title + "\n\n" + msg);
				
				break;
			
			default:
				// 上記以外
				
				alert(title + "\n\n" + msg);
				ret = true;
				
		}

	}

	return ret;
}

function doAnswer(answerId, inputSts, actionCtlId, answerIdCtlId, inputStsCtlId) {

	$get(answerIdCtlId).value = answerId;
	$get(inputStsCtlId).value = inputSts;

	clickButton(actionCtlId);

}

function buildUrl(url, urlParams) {
	var ret = url;

	if (urlParams != null) {
		var i = 0;
		for (i = 0; i < urlParams.length; i++) {
			if (i == 0) {
				if (url.indexOf("?") >= 0) {
					ret += "&";
				} else {
					ret += "?";
				}
			} else {
				ret += "&";
			}
			ret += urlParams[i];
		}
	}

	ret = encodeURI(ret);

	return ret;
}
