/**
 * @fileOverview
 * ウィンドウ操作ライブラリ
 */

/*----------------------------
  オープン
-----------------------------*/
/**
 * サブウィンドウOpen
 * @access	public
 * @param	string		src		対象アドレス
 * @param	string		pram	パラメータ(省略可、複数時は｢&｣で連結)
 * @param	string		name	ウィンドウ名(省略可)
 * @param	string		width	width(省略可)
 * @param	string		height	height(省略可)
 * @param	string		scroll	スクロール可否(省略可、指定時は｢yes/no｣)
 * @return	なし
 * @desc	なし
 */
function win_open(src, pram, name, width, height, scroll) {
	if (!pram) pram = "";
	if (!name || name=="") name = "win_sub";
	if (!width || width=="") width = "1024";
	if (!height || height=="") height = "768";
	if (!scroll || scroll=="") scroll = "yes";

	var target = src;
	if (pram != "") target += "?" + pram;
	var option = 'width=' + width;
	option += ',height=' + height;
	option += ',scrollbars=' + scroll;
	option += ',resizable=no';
	option += ',location=no';		// 運用時はno、デバック時はyes
	option += ',status=no';		    // 運用時はno、デバック時はyes
	option += ',toolbar=no';
	option += ',menubar=no';
	option += ',directories=no';
	var top  = Math.floor((screen.availHeight - parseInt(height))  / 2) - (screen.height - screen.availHeight); // TaskBar
	var left = Math.floor((screen.availWidth  - parseInt(width)) / 2) - (screen.width - screen.availWidth);     // TaskBar
	if (top  < 0) top  = 0;
	if (left < 0) left = 0;
	top -= 2;   // Luna
	left -= 2;  // Luna
	option += ',top=' + top;
	option += ',left=' + left;
	var subwin = window.open(target, name, option);
	subwin.window.focus();
	
}

/*----------------------------
  チェック
-----------------------------*/
/**
 * 親ウィンドウ確認
 * @access	public
 * @param	なし
 * @return	なし
 * @desc	なし
 */
function is_opener() {
	var ua = navigator.userAgent;
	if (!!window.opener) {
		if (ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1) {
			return !window.opener.closed;
		} else {
			return typeof window.opener.document  == 'object';
		}
	} else {
		return false;
	}
}

/*----------------------------
  リロード
-----------------------------*/
/**
 * 親ウィンドウリロード
 * @access	public
 * @param	なし
 * @return	なし
 * @desc	なし
 */
function reload_mainwin(close) {
	if (is_opener()) {
		window.opener.location.reload();
	}
	if (close) window.close();
}
/**
 * 自ウィンドウリロード
 * @access	public
 * @param	なし
 * @return	なし
 * @desc	なし
 */
function restartOwn() {
	var urls = location.href.split("?");
	var target = urls[0];
	if (urls.length > 1) {
		var prams = urls[1].split("&");
		for (i=0;i<prams.length;i++) {
			if (prams[i].indexOf("M=") >= 0) {
				target += "?" + prams[i];
				break;
			}
		}
	}
	location.href = target;
}

