﻿// JavaScript ファイル

	  ////////////////////////////
	 // ログアウトボタンの押下 //
	////////////////////////////
	
	function LogoutSubmit() {
	    return window.confirm("ログアウトし、TOPへ戻ります。\nよろしいですか？");
	}


     
      ////////////////////////////////////////
	 // 用途組み合わせお知らせを別窓で表示 //
	////////////////////////////////////////
    function showInfoWindow(target) {
        var targetPage;
        var url01;
        targetPage = "";
        url01 = "http://www.e-meitetsu.com/e-shop/guide/";
        
        if (target == "i") {
            targetPage = url01 + "select_condition.html";
        } else if (target == "c") {
            targetPage = url01 + "select_condition_gift1.html";
        } else if (target == "s") {
            targetPage = url01 + "select_condition_gift2.html";
        } else if (target == "shiharai") {
            targetPage = url01 + "view_shiharai.html";
        } else if (target == "card") {
            targetPage = url01 + "view_shiharai.html#card";
        } else {
            targetPage = target;
        }
        
        if (targetPage != "") {
            try {
                if(!info_s || info_s.closed){
                    // Info窓がない場合 //
                    info_s = window.open(targetPage, "Info", "toolbar=no, status=no, resizable=yes, scrollbars=yes, menubar=no, location=no, width=680, height=500");
                    info_s.focus();
                } else {
                    // Info窓がある場合 //
                    info_s.location = targetPage;
                    info_s.focus();
                }
            } catch(e) {
                // 一部のブラウザで window.closed がこける件の対応 //
                info_s = window.open(targetPage, "Info", "toolbar=no, status=no, resizable=yes, scrollbars=yes, menubar=no, location=no, width=680, height=500");
                info_s.focus();
            }
        }
    }

	

	  ////////////////////////
	 // 用途組み合わせ制御 //
	////////////////////////

	// 初期化
    function MakeArray(n) {
        this.length = n;
        for (i = 1; i <= n; i++) {
            this[i] = "";
        }
        return(this);
    }

    // セレクトボックスの配列
    function SelList(value,text){
       this.value = value;
       this.text = text;
    }



    ////////////////////////////////////////////////////////////////// 
    // Listの中身を変える ギフト用                                  //
    // Input : pk  = 包装のドロップダウンリストのオブジェクト       //
    //       : ns  = のしのドロップダウンリストのオブジェクト       //
    //       : sd  = 発送時期のドロップダウンリストのオブジェクト   //
    //       : ptn = 配送パターン                                   //
    //       : type= 配送パターンによる変更か、のしによる変更か     //
    //////////////////////////////////////////////////////////////////
    function input_List_for_G(pk, ns, sd, ptn, type){
        var noshi_list;
        var send_list;
        var obj_pack;
        var obj_noshi;
        var obj_send;

        if (pk != null || ns != null || sd != null) {
            obj_pack  = pk;
            obj_noshi = ns;
            obj_send  = sd;


            // どの包装が選択されていたら、どののし・届時期リストを表示するか
            for (i = 0;i <= obj_pack.options.length - 1;i++){
                if(obj_pack.options[i].selected == true) {
                    if (obj_pack.options[i].value == "01") {
                        // 簡易包装
                        if (ptn == "00") {
                            noshi_list = noshi_for_01_00;  // 配送パターン:簡易通常
                        } else if (ptn == "15" || ptn == "14") {
                            noshi_list = noshi_for_01_15;  // 配送パターン:クール
                        } else if (ptn == "16" || ptn == "17" || ptn == "18" || ptn == "19") {
                            noshi_list = noshi_for_01_1619;  // 配送パターン:産直
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_01_00;  // 配送パターン:ギフト券(簡易通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;  // 配送パターン:規定外(簡易通常扱い)
                        }
                    } else if (obj_pack.options[i].value == "02") {
                        // 全包装
                        if (ptn == "00") {
                            noshi_list = noshi_for_02_00;  // 配送パターン:全包装通常
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_02_00;  // 配送パターン:ギフト券(全包装通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;  // 配送パターン:規定外(簡易通常扱い)
                        }
                    } else if (obj_pack.options[i].value == "04") {
                        // 二重手付
                        if (ptn == "00") {
                            noshi_list = noshi_for_04_00;  // 配送パターン:二重手付通常
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_04_00;  // 配送パターン:ギフト券(二重手付通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;  // 配送パターン:規定外(簡易通常扱い)
                        }
                    }
                    break;
                }
            }


            // お届け時期、デフォルトは    send1 : 通常「届け時期マスタに準拠」
            // 暑中御見舞(02)              send1 : 通常「届け時期マスタに準拠」
            // 御年賀(02)・残暑御見舞(19)  send2 : 1月届のみ／8月届のみ
            // 寒中御見舞(19)                  なし
            send_list = send1;
        
            for (i = 0;i < obj_noshi.options.length;i++) {
                if (obj_noshi.options[i].selected == true) {
                    if (obj_noshi.options[i].value == "02") {
                        // 暑中・年賀
                        var now = new Date();
                        var mm  = now.getMonth()+1;
                        if (5 <= mm && mm <= 9) {
                            // 暑中
                            send_list = send1;
                            break;
                        } else {
                            // 年賀
                            send_list = send2;
                            break;
                        }
                    } else if (obj_noshi.options[i].value == "19") {
                        // 残暑・寒中
                        send_list = send2;
                        break;
                    } else {
                        send_list = send1;
                        break;
                    }
                }
            }
            
            // 選択値を初期化
            //if (type == "P") {
            //    send_list = send1;
            //}
            
            // DropdownListに項目を設定 -- のし
            obj_noshi.length = noshi_list.length + 1;
            for (i = 0;i <= noshi_list.length ;i++){
                obj_noshi.options[i].value = noshi_list[i].value;
                obj_noshi.options[i].text = noshi_list[i].text;
            }
            
            // DropdownListに項目を設定 -- 届け時期
            obj_send.length = send_list.length + 1;
            for (j = 0;j <= send_list.length;j++){
                obj_send.options[j].value = send_list[j].value;
                obj_send.options[j].text = send_list[j].text;
            }
        
            // 選択値を初期化
            if (type == "P") {
                obj_noshi.selectedIndex = 0;
                obj_send.selectedIndex  = 0;
            }
         }
    }


    //////////////////////////////////////////////////////////////////
    // Listの中身を変える 一般用                                    //
    // Input : pk  = 包装のドロップダウンリストのオブジェクト       //
    //       : ns  = のしのドロップダウンリストのオブジェクト       //
    //       : sd  = 発送時期のドロップダウンリストのオブジェクト   //
    //       : ptn = 配送パターン                                   //
    //       : cd  = 商品コード                                     //
    //       : type= 配送パターンによる変更か、のしによる変更か     //
    //////////////////////////////////////////////////////////////////
    function input_List_for_I(pk, ns, sd, ptn, cd, type){
        var noshi_list;
        var send_list;
        var obj_pack;
        var obj_noshi;
        var obj_send;

        if (pk != null || ns != null || sd != null) {
            obj_pack  = pk;
            obj_noshi = ns;
            obj_send  = sd;


            // どの包装が選択されていたら、どののし・届時期リストを表示するか
            for (i = 0;i <= obj_pack.options.length - 1;i++){
                if(obj_pack.options[i].selected == true) {
                    if (obj_pack.options[i].value == "01") {
                        // 簡易包装
                        if (ptn == "00") {
                            noshi_list = noshi_for_01_00;    // 配送パターン:通常
                        } else if (ptn == "15" || ptn == "14") {
                            noshi_list = noshi_for_01_15;    // 配送パターン:クール
                        } else if (ptn == "16" || ptn == "17" || ptn == "18" || ptn == "19") {
                            noshi_list = noshi_for_01_1619;  // 配送パターン:産直
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_01_00;    // 配送パターン:ギフト券(簡易通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;    // 配送パターン:規定外(簡易通常扱い)
                        }
                    } else if (obj_pack.options[i].value == "02") {
                        // 全包装
                        if (ptn == "00") {
                            noshi_list = noshi_for_02_00;  // 配送パターン:通常
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_02_00;  // 配送パターン:ギフト券(全包装通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;  // 配送パターン:規定外(簡易通常扱い)
                        }
                    } else if (obj_pack.options[i].value == "04") {
                        // 二重手付
                        if (ptn == "00") {
                            noshi_list = noshi_for_04_00;  // 配送パターン:通常
                        } else if (ptn == "33") {
                            noshi_list = noshi_for_04_00;  // 配送パターン:ギフト券(二重手付通常扱い)
                        } else {
                            noshi_list = noshi_for_01_00;  // 配送パターン:規定外(簡易通常扱い)
                        }
                    }
                    break;
                }
            }
        
            // お届け時期、デフォルトは send4 : 通常「今日を含めて8日-30日ただし年末年始は除く」
            // のし01が来た時は　       send1 : 歳暮「11/1-12/29」/ 中元「6/1-7/31」
            // のし02が来た時は　       send2 : 年賀「1/5 -1/7  」/ 暑中「7/1-7/31」
            // のし19が来た時は　       send3 : 寒中「1/5 -2/3  」/ 残暑「8/1-8/20」

            send_list = eval("send4_" + cd);
            for (i = 0;i < obj_noshi.options.length;i++) {
                if (obj_noshi.options[i].selected == true) {
                    if (obj_noshi.options[i].value == "01") {
                        send_list = eval("send1_" + cd);
                        break;
                    } else if (obj_noshi.options[i].value == "02") {
                        send_list = eval("send2_" + cd);
                        break;
                    } else if (obj_noshi.options[i].value == "19") {
                        send_list = eval("send3_" + cd);
                        break;
                    } else {
                        send_list = eval("send4_" + cd);
                        break;
                    }
                }
            }
            
            // 選択値を初期化
            if (type == "P") {
                send_list = eval("send4_" + cd);
            }
            
            // DropdownListに項目を設定 -- のし
            obj_noshi.length = noshi_list.length + 1;
            for (i = 0;i <= noshi_list.length ;i++){
                obj_noshi.options[i].value = noshi_list[i].value;
                obj_noshi.options[i].text = noshi_list[i].text;
            }
            
            // DropdownListに項目を設定 -- 届け時期
            obj_send.length = send_list.length + 1;
            for (j = 0;j <= send_list.length;j++){
                obj_send.options[j].value = send_list[j].value;
                obj_send.options[j].text = send_list[j].text;
            }
        
            // 選択値を初期化
            if (type == "P") {
                obj_noshi.selectedIndex = 0;
                obj_send.selectedIndex  = 0;
            }
        }
    }
    
    
      ////////////////////
	 // 配送料金窓表示 //
	////////////////////
    function subWin(html){
        window.open(html,"winSou","resizable=yes,menubar=no,directories=no,status=no,location=no,scrollbars=1,height=400,width=500");
    }
    
    
      ////////////////////
	 // 最終確認＞登録 //
	////////////////////
	function submitLastData(inTarget) {
	    document.forms[0].action  = inTarget;
        document.forms[0].method  = "post";
        document.forms[0].submit();
	}


    /////////////////////////////////////////////////////////////////////////////// 
    // 「自宅お届け+非二重配送」があった場合に、それでいいのか確認のダイアログ   //
    // Input : pk  = 包装のドロップダウンリストのオブジェクトの配列              //
    //       : dl  = お届け先のドロップダウンリストのオブジェクトの配列          //
    //       : tp  = 購入タイプ(１=ギフト、２=一般)                              //
    ///////////////////////////////////////////////////////////////////////////////
    function chkDPack(pk, dl, tp){
        if (pk != null && dl != null) {
            var outcnt
            var pjcnt
            var djcnt
            outcnt = pk.length

            for (tmp=0; tmp<outcnt; tmp++) {  // お届先（外殻）
                pjcnt = pk[tmp].options.length
                djcnt = dl[tmp].options.length

                for (tmp2=0; tmp2<djcnt; tmp2++) {  // お届先（内殻）
                    if(dl[tmp].options[tmp2].selected == true && dl[tmp].options[tmp2].value == "0") {
                        // お届先が自宅だった場合
                        for (tmp3=0; tmp3<pjcnt; tmp3++) {  // 包装（内殻）
                            if(pk[tmp].options[tmp3].selected == true && pk[tmp].options[tmp3].value != "04") {
                                if  (pk[tmp].options[tmp3].value != "00") { // 包装指定なし(おせち等のイレギュラー)を除く
                                    if (tp == "1") {
                                        // ギフト購入
                                        alert(" こちらの商品は、ご自宅届けでは二重包装のみ承ります。");
                                        return false;
                                    } else {
                                        // 一般購入
                                        return window.confirm('ご進物でご自宅届けの場合は、「二重包装」をお選びください。\n' + 
				                                              '現在の設定のままでよろしいでしょうか。\n\n' + 
				                                              'ご自宅使い＝[OK]　　ご贈答品＝[キャンセル]\n' +
				                                              '※キャンセルをお選び頂きますと、再度包装形態等ををご選択頂けます。\n'
			                                                 )
                                    }
                                    
                                }
                            }
                        } // 包装
                    } // 自宅届の場合
                } // お届先(内殻)のFor
            }  // お届先(外殻)のFor
        }
    }


