/*
 * 同じウインドウからG-BOOKビューアを呼び出す
 */
function ContentsOpen(id) {
	contentsOpenCommon(top, "id", id);
}

/*
 * 別ウインドウからG-BOOKビューア呼び出し
 */
function ContentsOpenOtherWindow(id) {
	contentsOpenCommon(window.opener.top, "id", id);
	window.close();
}

/*
 * G-BOOKビューア呼び出し(URL指定)
 */
function ContentsOpenUrl(url) {
	contentsOpenCommon(top, "url", url);
}

/*
 * 別ウインドウからG-BOOKビューア呼び出し(URL指定)
 */
function ContentsOpenUrlOtherWindow(url) {
	contentsOpenCommon(window.opener.top, "url", url);
	window.close();
}

function contentsOpenCommon(topPos, key, value) {
	var i;
	var check;

//	window.close();

	check = false;
	if (topPos.document.getElementsByName("usersite_main").length >= 1) {
		check = true;
	}
	if (!check) {
		targetLocation(topPos, key, 0, value);
		return;
	}

	check = false;
	if (topPos.usersite_main.document.getElementsByName("viewer").length >= 1) {
		check = true;
	}
	if (!check) {
		targetLocation(topPos, key, 1, value);
	}
	else {
		targetLocation(topPos, key, 2, value);
	}
}

function targetLocation(topPos, key, mode, value) {
	switch(mode) {
		case 1:
			topPos.usersite_main.location.href = "/pc/members/myshortcut/ShortcutOut.asp?" + key + "=" + value;
			topPos.location.hash="top";
			break;
		case 2:
			topPos.usersite_main.viewer.location.href = "/pc/members/myshortcut/ShortcutIn.asp?" + key + "=" + value;
			topPos.location.hash="top";
			break;
		default:
			topPos.location.href = "/usersite/members/LoginAuth.aspx?" + key + "=" + value;
			break;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var ret;
  ret = window.open(theURL,winName,features);
  ret.focus();
}

function MM_openBrWindow_E(theURL,winName,features) { //v2.0
  var ret;
  ret = window.open(theURL,winName,features);
	x = (screen.width  - 535) / 2;
	y = (screen.height - 530) / 2;
	ret.moveTo(x,y);

  ret.focus();
}

function MM_openBrWindow_P(theURL,winName,features) { //v2.0
  var ret;
  ret = window.open(theURL,winName,features);
	x = (screen.width  - 800) / 2;
	y = (screen.height - 530) / 2;
	ret.moveTo(x,y);

  ret.focus();
}

// 旧バージョンの認証処理。不要
function idPass(func){
	sx = screen.width; 
	sy = screen.height; 
	x = (sx - 320) / 2; 
	y = (sy - 255) / 2; 
	password=window.open(func,"password","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=320,height=255,dependent=yes,left="+ x +",top="+ y + ",screenX="+ x +",screenY="+ y);
	password.focus();
}

	//ヒストリーバック時の不具合に対応
function openUsersite(target){
	top.document.all("usersite_main").src=target+"?back=2";
}

/*
 * 既にウィンドウが開いているか判断、開いていなければ新規ウィンドウで開く
 * 開いていればフォーカスを移す。
 */
function wopen(wurl,wn,feat){
	if (wn == "") {
		//opener.focus();
	} else {
		var w = window.open('',wn,feat);
		if (w.location.href == "about:blank") {
			window.open(wurl,wn,feat);
		}else{
			w.focus();
		}
	}
}
