/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    ウィンドウマネージャー
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
//本番用 var SSL_BASE_URL = "http://192.168.1.148/paella/";
var BASE_URL = "http://www.tenseihonpo.com/Honpo/";
var SSL_BASE_URL = "https://www.tenseihonpo.com/Honpo/";

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
コンストラクタ
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_WindowManager() {
    //全ウィンドウ用
    WinMan_WindowManager.aoWin      = new Array();
    
    //リロード対象ウィンドウ用
    WinMan_WindowManager.aoReWin    = new Array();
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
定数
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
//区分:単一Window
WinMan_WindowManager.USER		= "OPEN_PAELLA_USER";       //ログインor会員登録
WinMan_WindowManager.CART		= "OPEN_PAELLA_CART";       //カート

//区分:複数indow
WinMan_WindowManager.BBS		= "OPEN_PAELLA_BBS_";       //掲示板
WinMan_WindowManager.TOKOU		= "OPEN_PAELLA_TOKOU_";     //投稿記事
WinMan_WindowManager.BRAND		= "OPEN_PAELLA_BRAND_";     //商品

WinMan_WindowManager.MAP		= "OPEN_PAELLA_MAP_";       //地図
WinMan_WindowManager.QUIZ		= "OPEN_PAELLA_QUIZ_";      //クイズ
WinMan_WindowManager.RANK_IN	= "OPEN_PAELLA_RANK_IN_";   //ランキング(投票)
WinMan_WindowManager.RANK_OUT	= "OPEN_PAELLA_RANK_OUT_";  //ランキング(参照)
WinMan_WindowManager.ARTICLE	= "OPEN_PAELLA_ARTICLE_";   //掲載記事一覧
WinMan_WindowManager.OPINION	= "OPEN_PAELLA_OPINION_";   //意見 投稿/閲覧
WinMan_WindowManager.VS			= "OPEN_PAELLA_VS_";        //対決(投票)

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
oForm   サブミットを行うFORM(POST)
sURL    遷移するURL(GET)
sKbn    上記、区分
sConID  コンテンツID(複数Windowの場合のみ必須)
返却値	正常に処理できた場合	true
		上記以外の場合			false
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
WinMan_WindowManager.openWindow = function openWindow(oForm, sURL, sKbn, sConID) {
    var oWin        = null;
    
    //本の名前(＝局コード) + 区分＋コンテンツID
    var sWinName    = ALL_BureauName + sKbn + sConID;
    
    var oChkWin     = null;
    var bFlg		= false;
	var sOpt		= "";
    
    //オープンチェック用ウィンドウインスタンス取得
    oChkWin = WinMan_WindowManager.aoWin[sWinName];
        

	//★SSL変換★
    //ログイン画面表示要求
    if (sURL.search("member_login.asp") != -1) {
		sURL=sURL.replace(BASE_URL,SSL_BASE_URL) 
   //user配下画面表示要求
    } else if (sURL.search("/user/") != -1) {
		sURL=sURL.replace(BASE_URL,SSL_BASE_URL) 
    }


     //ウィンドウオープンチェック
    if (typeof(oChkWin) != "undefined" &&   //オープンされていない かつ
        oChkWin.closed == false) {          //クローズされていない
        //オープンされている
        
        //ログインor登録の場合
        if (sKbn == WinMan_WindowManager.USER) {
            //ログイン画面表示要求
            if (sURL.search("member_login.asp") != -1) {
                if (oChkWin.location.href.search("member_login.asp") == -1) {
                    oChkWin.location.href(sURL);
                }
            //user配下画面表示要求
            } else if (sURL.search("/user/") != -1) {
				//忘れた画面表示要求
				if (sURL.search("user_forget_pass.asp") !== -1) {
					oChkWin.location.href(sURL);
				//会員登録画面表示要求
				} else if (oChkWin.location.href.search("/user/") !== -1) {
                    oChkWin.location.href(sURL);
                }
            }
        }
        
        //ウィンドウにフォーカスを設定
        oChkWin.focus();
        
        //カート、地図、関連記事一覧以外であれば、処理を終了させる
        if (sKbn != WinMan_WindowManager.CART && 
        	sKbn != WinMan_WindowManager.MAP &&
        	sKbn != WinMan_WindowManager.ARTICLE &&
        	sKbn != WinMan_WindowManager.OPINION) {
	        //終了
	        return true;
		}
		bFlg = true;
    }
    
    //ウィンドウオープン
    if (bFlg) {
		oWin = oChkWin;
	} else {
		sOpt += "directories=no,";	//[e3/N2] ユーザ設定ツールバーの表示。
		sOpt += "location=no,";		//[e3/N2] 場所ツールバーの表示。
		sOpt += "menubar=no,";	 	//[e3/N2] メニューバーの表示。
		sOpt += "status=yes,";	 	//[e3/N2] ステータスバーの表示。
		sOpt += "toolbar=no,";	 	//[e3/N2] ツールバーの表示。
		sOpt += "scrollbars=yes,";	//[e3/N2] スクロールバーの表示。
		//sOpt += "fullscreen=yes,";	//[e3/N2] フルスクリーンで表示。
		sOpt += "resizable=yes";	 	//[e3/N2] リサイズを可能にする。
	    oWin = window.open(BASE_URL + "ssl.html", sWinName, sOpt);
	}
	
	//フォーカス設定
	oWin.focus();

	var elements = Form.getElements('Form_Exec');
	var form=document.getElementById("Form_Exec");

	//ポップアップブロッカー対応
	if (oWin == null) {
		//ウィンドウが開けなかった場合
		alert("ポップアップブロッカーを無効にしてください。");
        //終了
        return false;
	}
    if (oForm == "") {      //GET
        oWin.location.href(sURL);
    } else {                //POST
        if (sURL != "") {
            oForm.action = sURL;
        }
        oForm.target = oWin.name;
        oForm.submit();
    }
    
    //登録済み
    if (bFlg) {
        //終了
        return true;
	}
    
    //リロード対象用ウィンドウ登録判定
    if (sKbn == WinMan_WindowManager.CART   ||
        sKbn == WinMan_WindowManager.BBS    ||
        sKbn == WinMan_WindowManager.TOKOU) {
        WinMan_WindowManager.aoReWin[oWin.name] = oWin;
    }
    
    //ウィンドウ登録
    WinMan_WindowManager.aoWin[oWin.name] = oWin;
    
    //終了
    return true;
};

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    対象ウィンドウリロード
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
WinMan_WindowManager.reLoad = function reLoad() {
    var sWinName    = null;
    var oWin        = null;
    
    for (sWin in WinMan_WindowManager.aoReWin) {
        oWin = WinMan_WindowManager.aoReWin[sWin];
        if (oWin.closed == false) {
            oWin.document.all.ReloadForm.submit();
        }
    }
};


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    全ウィンドウクローズ
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
WinMan_WindowManager.allClose = function allClose() {
    var sWinName    = null;
    var oWin        = null;
    
    for (sWin in WinMan_WindowManager.aoWin) {
        oWin = WinMan_WindowManager.aoWin[sWin];
        if (oWin.closed == false) {
            oWin.close();
        }
    }
};

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    対決(投票)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_vsIn(sBookNo, sPageNo, sKbn, sURL) {

	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    elements.book_no.value = sBookNo;
    elements.page_no.value = sPageNo;
    elements.kbn.value     = sKbn;

	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();

/*
    WinMan_WindowManager.openWindow(elements, 
                                    sURL, 
                                    WinMan_WindowManager.VS, 
                                    sBookNo + sPageNo + sKbn);
*/
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    クイズ
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_quiz(sBookNo, sPageNo, sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    elements.book_no.value = sBookNo;
    elements.page_no.value = sPageNo;

	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();

/*
    document.all.Form_Exec.method = "POST";
    
    document.all.Form_Exec.book_no.value = sBookNo;
    document.all.Form_Exec.page_no.value = sPageNo;
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.QUIZ, 
                                    sBookNo);
*/
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    地図
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_map(sUserID, sURL) {
	var elements=document.getElementById("Form_Exec");
//	elements.method = "POST";
	elements.user_id.value = sUserID;
	elements.action = sURL;
	elements.target = BASE_URL + "ssl.html";
	elements.submit();


/*
    document.all.Form_Exec.method = "POST";
    document.all.Form_Exec.user_id.value = sUserID;
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.MAP, 
                                    "");
*/
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    掲示板
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_bbs(sConID, sBkNoFlg, sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    elements.contents_id.value = sConID;
    elements.bk_no_flg.value = sBkNoFlg;

	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();


/*    
    document.all.Form_Exec.method = "POST";
    document.all.Form_Exec.contents_id.value = sConID;
    document.all.Form_Exec.bk_no_flg.value = sBkNoFlg;
    WinMan_WindowManager.openWindow(element, 
                                    sURL, 
                                    WinMan_WindowManager.BBS, 
                                    sConID);
*/
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    投稿
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_write(sConID, sBkNoFlg, sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    elements.contents_id.value = sConID;
    elements.bk_no_flg.value = sBkNoFlg;

	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();


/*
    document.all.Form_Exec.method = "POST";
    document.all.Form_Exec.contents_id.value = sConID;
    document.all.Form_Exec.bk_no_flg.value = sBkNoFlg;
    WinMan_WindowManager.openWindow(element, 
                                    sURL, 
                                    WinMan_WindowManager.TOKOU, 
                                    sConID);
*/
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    商品
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_brand(sConID, sURL) {
    document.all.Form_Exec.method = "POST";
    
    document.all.Form_Exec.contents_id.value = sConID;
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.BRAND, 
                                    sConID);
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    カート
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_cart(sURL) {
    document.all.Form_Exec.method = "GET";

    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.CART, 
                                    "");
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    ランキング(投票)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_rankingIn(sBookNo, sPageNo, sURL) {
    document.all.Form_Exec.method = "POST";
    
    document.all.Form_Exec.book_no.value = sBookNo;
    document.all.Form_Exec.page_no.value = sPageNo;

    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.RANK_IN, 
                                    sBookNo + sPageNo);
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    ランキング(参照)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_rankingOut(sBookNo, sPageNo, sInputName, sRnakNo, sURL) {
    document.all.Form_Exec.method = "POST";
    
    document.all.Form_Exec.book_no.value = sBookNo;
    document.all.Form_Exec.page_no.value = sPageNo;
    document.all.Form_Exec.input_name.value = sInputName;
    
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.RANK_OUT, 
                                    sBookNo + sPageNo + sRnakNo);
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    ログインor登録
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_user(sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

	elements.action = sURL;
    elements.target = SSL_BASE_URL + "ssl.html";
	elements.submit();


/*
//    document.all.Form_Exec.method = "GET";
    WinMan_WindowManager.openWindow(element, 
                                    sURL, 
                                    WinMan_WindowManager.USER, 
                                    "");
*/
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    関連記事一覧
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_articleList(sUserID, sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    document.all.Form_Exec.method = "POST";
    document.all.Form_Exec.user_id.value = sUserID;
	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();

/*
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.ARTICLE, 
                                    "");
*/
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
    意見 投稿/閲覧
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
function WinMan_opinion(sUserID, sURL) {
	var elements=document.getElementById("Form_Exec");
	elements.method = "POST";

    document.all.Form_Exec.method = "POST";
    document.all.Form_Exec.user_id.value = sUserID;
	elements.action = sURL;
    elements.target = BASE_URL + "ssl.html";
	elements.submit();

/*
    WinMan_WindowManager.openWindow(document.all.Form_Exec, 
                                    sURL, 
                                    WinMan_WindowManager.OPINION, 
                                    "");
*/
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
インスタンス
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
new WinMan_WindowManager();





