﻿//-----------------------------------------------------------------------------------
// JustisTop用Javascript
//-----------------------------------------------------------------------------------

// -----START----- 起動時用 -----START-----
        var j$ = jQuery;
        // 共通変数
        var url = document.getElementById("hdnNextPage").value;
       
        j$(function() {
            // ジャンル検索アコーディオン動作
            j$(".genreSearch_inner").each(function() {
                j$("li > div", this).each(function(index) {
                    var $this = j$(this);

                    // 中分類以下をhidden設定
                    $this.next().hide();

                    // 項目クリックイベント
                    $this.click(function() {

                        // 大分類をクリックされた時
                        if (j$(this).context.className.replace("btnGenrecat_top_select", "") == "btnGenrecat_top") {
                            // 選択スタイルを解除
                            $("div.btnGenrecat_top").removeClass("btnGenrecat_top_select");
                            // 選択スタイルを適応
                            $(this).addClass("btnGenrecat_top_select");
                        }

                        // 中分類をクリックされた時
                        if (j$(this).context.className.replace("btnGenerecat_sub_select", "") == "btnGenerecat_sub") {
                            // 選択スタイルを解除
                            $("div.btnGenerecat_sub").removeClass("btnGenerecat_sub_select");
                            // 選択スタイルを適応
                            $(this).addClass("btnGenerecat_sub_select");
                        }

                        // animateの引数
                        var params = { height: "toggle", opacity: "toggle" };
                        // 選択項目の次のタグをhidden、前回の開いた項目をhidden
                        j$(this).next().animate(params).parent().siblings().children("ul:visible").animate(params);
                        return false;
                    });
                });
            });

            // 他のカタログリストを表示する(スライド）
            $("#CatalogSearchListOther").slideToggle();
                        
            // キーワードチェックボックス初期処理
            $(document).ready(function() {
            inputImeChangeKeyword();
            });

            // カタログ検索アコーディオン初期処理
            $(document).ready(function() {
                if (0 < $("#txtCatalogId").val().length) {
                    ChangeAccordion($("#txtCatalogId").val()
                        , $("#txtImgCatalog").val()
                        , $("#txtCatalogName").val()
                        , $("#txtPublishingDate").val());
                } else {
                    $("#CatalogSearchList div div:first").click();
                }
            });

        });
        
// -----END----- 起動時用 -----END-----

    function ancOther() {
        // 他のカタログリストを表示する(スライド）
        $("#btnOther").hide();
        $("#btnOthercatalog").hide();
        $("#ancOther").hide();
        $("#CatalogSearchListOther").slideToggle();
    }

    function inputImeChangeKeyword() {
        // 品番の時のみIMEoff
        if (document.getElementById("rdoProductOrderNo").checked == true) {
            document.getElementById("txtKeyword").className = "search_word_input imeDisabled";
        }
        else {
            document.getElementById("txtKeyword").className = "search_word_input imeActive";
        }

        // 全体の時のみ オプション可能
        if (document.getElementById("rdoAll").checked == true) {
            document.getElementById("chkOption").disabled = false;
        }
        else {
            document.getElementById("chkOption").checked = false;
            document.getElementById("chkOption").disabled = true;
        }
    }
    
    function inputImeChangeCatalog() {
        // ページの時のみIMEoff
        if (document.getElementById("rdoPage").checked == true) {
            document.getElementById("txtCatalogKeyword").className = "catalog_wordsearch_txtinput imeDisabled";
        }
        else {
            document.getElementById("txtCatalogKeyword").className = "catalog_wordsearch_txtinput imeActive";
        }
    }
    
    // 品目分類(ジャンル)検索 アコーディオン
    // 小分類クリック時
    function inputClassSmall(stype, large, middle, small) {
        // ２重起動チェック
        if (checkDoublePost() == false) return;
        // 画面遷移
        url = url + "&stype=" + escape(stype) + "&large=" + escape(large) + "&middle=" + escape(middle) + "&small=" + escape(small);      
        nextTopPge(url);
    }
    
    // 掲載分類(カタログ)検索 アコーディオン
    // 中分類クリック時
    function inputCatalogMiddle(catalog, large, middle) {
        // ２重起動チェック
        if (checkDoublePost() == false) return;
        // 画面遷移
        url = url + "&stype=" + escape(document.getElementById("hdnPublish").value) + "&catalog=" + escape(catalog) + "&large=" + escape(large) + "&middle=" + escape(middle);
        nextTopPge(url);
    }
    // 大分類クリック時(中分類なしで遷移）
    function inputCatalog(catalog, large) {
        url = url + "&stype=" + escape(document.getElementById("hdnPublish").value) + "&catalog=" + escape(catalog) + "&large=" + escape(large);
        nextTopPge(url);
    }
    
    // 掲載カタログメニューの切り替え
    function ChangeAccordion(id, imgCatalog, catalogName, publishingDate) {
        $("#imgCatalog").attr("src", imgCatalog);
        $("#catalogName").html(catalogName);
        $("#publishingDate").html(publishingDate);
        $("#txtImgCatalog").val(imgCatalog);
        $("#txtCatalogName").val(catalogName);
        $("#txtPublishingDate").val(publishingDate);
        $("#txtCatalogId").val(id);

        //////////
        $("#accContainer").html($("#" + id + "_list").val());
        $("#acc .btnCataloggen").click(function () {
            var params = { height: "toggle", opacity: "toggle" };
            j$(this).next().animate(params).parent().siblings().children(".listCataloggen:visible").animate(params);
        });
        //////////

        /*
        $("#accContainer").load("GetCatalog.aspx #acc"
            , { id: id, format: "top" }
            , function () { $("#acc .btnCataloggen").click(function () {
                var params = { height: "toggle", opacity: "toggle" };
                j$(this).next().animate(params).parent().siblings().children(".listCataloggen:visible").animate(params);
            }); }
        );
        */
        
        location.hash = "#Head"; 
    }

    // カタログ検索
    function SearchChkCatalog() {
        // ２重起動チェック
        if (checkDoublePost() == false) return;
        
        if (document.getElementById("txtCatalogId").value == "") {
            alert("カタログが選択されていません。");
            return;
        }
        // カタログページの時
        if (document.getElementById("rdoPage").checked == true) {
            // 入力チェック
            if (document.getElementById("txtCatalogKeyword").value == "") {
                alert("掲載ページが入力されていません。");
                document.getElementById("txtCatalogKeyword").focus();
                return;
            }
            // 数値チェック
            value = document.getElementById("txtCatalogKeyword").value;

            if (isNaN(value) == true) {
                alert("掲載ページは、数値で入力してください。");
                document.getElementById("txtCatalogKeyword").focus();
                return;
            }
            // 最大桁数チェック
            if (checkMaxKeta(document.getElementById("txtCatalogKeyword"), 4) == false) {
                document.getElementById("txtCatalogKeyword").focus();
                return;
            }
            url = url + "&stype=" + escape(document.getElementById("rdoPage").value) + "&catalog=" + escape(document.getElementById("txtCatalogId").value) + "&page=" + escape(document.getElementById("txtCatalogKeyword").value);
        }

        // カタログキーワードの時
        if (document.getElementById("rdoKeyword").checked == true) {
            if (document.getElementById("txtCatalogKeyword").value == "") {
                alert("キーワードを入力してください。");
                document.getElementById("txtCatalogKeyword").focus();
                return;
            }
            // 最大桁数チェック
            if (checkMaxKeta(document.getElementById("txtCatalogKeyword"), 50) == false) {
                document.getElementById("txtCatalogKeyword").focus();
                return;
            }
            url = url + "&stype=" + escape(document.getElementById("rdoKeyword").value) +"&catalog=" + escape(document.getElementById("txtCatalogId").value) + "&keyword=" + escape(document.getElementById("txtCatalogKeyword").value);
        }
        nextTopPge(url);
    }

    // キーワード検索
    function SearchChkKeyWord() {
        // ２重起動チェック
        if (checkDoublePost() == false) return;
    
        // キーワード入力チェック（最大桁数）
        if (checkMaxKeta(document.getElementById("txtKeyword"), 50) == false) {
            return;
        }
                   
        // キーワード指定時
        if (document.getElementById("rdoAll").checked == true) {
            if (InputChkKeyword(document.getElementById("txtKeyword")) == false) {
                document.getElementById("txtKeyword").focus();
                return;
            }
            
            var prmOption;
            if (document.getElementById("chkOption").checked == true) {
                prmOption = "true";
            }else {
                prmOption = "false";
            }
            url = url + "&stype=" + escape(document.getElementById("rdoAll").value) + "&keyword=" + escape(document.getElementById("txtKeyword").value) + "&spec=" + escape(prmOption);
        }

        // 商品名指定時
        if (document.getElementById("rdoProduct").checked == true) {
            if (InputChkProduct(document.getElementById("txtKeyword")) == false) {
                document.getElementById("txtKeyword").focus();
                return;
            }
            url = url + "&stype=" + escape(document.getElementById("rdoProduct").value) + "&name=" + escape(document.getElementById("txtKeyword").value);
        }
        
        // 型番指定時
        if (document.getElementById("rdoModel").checked == true) {
            if (InputChkModel(document.getElementById("txtKeyword")) == false) {
                document.getElementById("txtKeyword").focus();
                return;
            }
            url = url +  "&stype=" + escape(document.getElementById("rdoModel").value) + "&model=" + escape(document.getElementById("txtKeyword").value);
        }
        
        // 品番注番指定時
        if (document.getElementById("rdoProductOrderNo").checked == true) {
            if (InputChkProductOrderNo(document.getElementById("txtKeyword")) == false) {
                document.getElementById("txtKeyword").focus();
                return;
            }
            url = url + "&stype=" + escape(document.getElementById("rdoProductOrderNo").value) + "&porder=" + escape(document.getElementById("txtKeyword").value);
        }
        nextTopPge(url);
    }

    function InputChkKeyword(selObj) {
        // 入力チェック
        if (selObj.value == "") {
            alert("キーワードを入力してください。");
            return false;
        }
    }
    function InputChkProduct(selObj) {
        // 入力チェック
        if (selObj.value == "") {
            alert("商品名を入力してください。");
            return false;
        }
    }
    function InputChkModel(selObj) {
        // 入力チェック
        if (selObj.value == "") {
            alert("型番を入力してください。");
            return false;
        }
        if (selObj.value.length < 2) {
            alert("型番検索は2桁以上で指定してください。");
            return false
        }
    }
    function InputChkProductOrderNo(selObj) {
        // 入力チェック
        if (selObj.value == "") {
            alert("商品コード（品番）を入力してください。");
            return false;
        }
        if (selObj.value.length < 4) {
            alert("商品コード（品番）検索は4桁以上で指定してください。");
            return false
        }

        var rexp = new RegExp(/[^ !\$'\(\)\+,\-;=@\[\]\^_`0-9A-Za-z]+/g);
        if (rexp.test(selObj.value)) {
            alert("各種カタログに記載のコードをそのまま（ハイフン等含む）入力下さい。");
            return false;
        }
    }
    
    // 数値チェック
    function NumericChk(selObj) {
        for (i = 0; i < selObj.length; i++) {
            if (selObj.substring(i, i + 1) < "0" || selObj.substring(i, i + 1) > "9")
                return false;
        }
        return true;
    }

    // 最大桁数チェック
    function checkMaxKeta(selObj, maxLnegth) {
        if (selObj.value.length > maxLnegth) {
            alert("" + maxLnegth + "桁以内で指定してください。");
            selObj.focus();
            return false
        }
    }

//    // カタログリストを選択に見せる
//    var bg;
//    function changeCatalog(id, y) {

//        if (y == 1) { bg = "catalog_box catalog_box_select"; }
//        else { bg = "catalog_box"; }

//        if (document.getElementById) {
//            document.getElementById(id).className = bg;
//        }

//    }
    // テキスト入力時Enter(キーワード検索)
    var setEnter=0;
    $("#txtKeyword").keypress(function(e) {
	    if (e.keyCode== 13) {
	        if(setEnter==0){
                setEnter=1;
                
	            theForm.onsubmit = function() {return false;};
	            var ret = SearchChkKeyWord();
	            if( ret == false){
	                setEnter=0;
	            }
           }
	    }
	    
    });
    
    // テキスト入力時Enter(カタログ検索)
    $("#txtCatalogKeyword").keypress(function(e) {
	    if (e.keyCode== 13) {
	        if(setEnter==0){
                setEnter=1;
                
	            theForm.onsubmit = function() {return false;};
	            var ret = SearchChkCatalog();
	            if( ret == false){
	                setEnter=0;
	            }
           }
	    }
    });
	    
    // 次画面遷移
    function nextTopPge(url) {
        doPost("frmHeader", url);
    }

    // ２重起動チェック処理
    function checkDoublePost() {
        if (isDocumentLoading()) {
            alert("処理中です…");
            return false;
        }
        return true;
    }
    function isDocumentLoading() {
      return (document.readyState != null &&
              document.readyState != "complete");
    }
