﻿<!--

  // ログアウトアクション☆
  function logout(){    
    if (confirm("ログアウトします。","OK","キャンセル")) { 
      document.logoutform.action="https://www.lib-sakai.jp/licsxp-opac/WOpacPwdLogoutAction.do";
      document.logoutform.submit();
    }
  }

  // ログインアクション☆
  function login(){
    document.logoutform.action="https://www.lib-sakai.jp/licsxp-opac/WOpacInitLoginActiontemp.do?subSystemFlag=0&gamenid=tiles.WMnuTop";
    document.logoutform.submit();
    swapLoginStatus(1); //new
  }

  // ログイン状態による表示切替
  // (menu2.jsより移行)
  //function swapLogging(type){
  function swapLoginStatus(type){  //rename

    var element;

    element = document.getElementById("stat-logout");
    if( element!=null ){
      element.style.display = type ? "none" : "block";
    }
    element = null;

    element = document.getElementById("stat-login");
    if( element!=null ){
      element.style.display = type ? "block" : "none";
    }
    element = null;

    if( type=1 ){
      element = document.getElementById("personal-info");
      if( element!=null ){
        element.style.display = "block";
      }
      element = null;
    } else {
      element = document.getElementById("personal-info");
      if( element!=null ){
        element.style.display = "none";
      }
      element = null;
    }

  }


  var spaceFlg = false;  //入力文字数制限フラグ

  //蔵書検索実行☆ kensaku_keyword、junlCodeのkeyPressで
  //function search(schType) {
  function searchBib(schType) {
    //trim();
    keyTrim(document.SearchForm.kensaku_keyword.value);
    if (spaceFlg == true){
      alert("2文字以上で検索して下さい。");
    } else {
      document.SearchForm.action="https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=tifschcmpdpre&SchType=" + schType;
        document.SearchForm.submit();
    }
  }

  //検索キーワードトリミング ◎内部のみ
  //function trim(){   
  function keyTrim( strData ){   
    //var strData = document.SearchForm.kensaku_keyword.value;
    var i;   
    for (i = 0; i < strData.length  && (strData.charCodeAt(i) == 32 || strData.charCodeAt(i) == 12288); i++);
    strData = strData.substring(i, strData.length);   
    for (i = strData.length - 1; i >= 0 && (strData.charCodeAt(i) == 32 || strData.charCodeAt(i) == 12288); i--);
    strData = strData.substring(0, i + 1);  
    if (strData.length == 1){
        spaceFlg = true;
    } else {
      spaceFlg = false;
    }
  }
 

  //表示情報初期化(堺市立図書館オリジナル) 2011.02.28
  // body.onLoad()で呼出
  // ログイン状態の確認と利用状況概要表示
  // callLoadXMLFile() および loadXMLFile()を融合
  function loadInitStatus() {
//    new Ajax.Request("http://www.lib-sakai.jp/licsxp-opac/WPwdLoginCheckAction.do", { method: 'post', onComplete: displayStatus });
    new Ajax.Request("licsxp-opac/WPwdLoginCheckAction.do", { method: "get", onComplete: displayStatus });
//    new Ajax.Request("licsxp-opac/WPwdLoginCheckAction.do", { method: "post", onComplete: displayStatus });
  }


  //初期情報表示(堺市立図書館オリジナル) 2011.02.28
  // ログイン状態の初期化および
  // displayData()から不要部分除去
  // 要素不在時のエラーハンドリング追加  2011.07.16
  function displayStatus(req, json) {

    var element; //要素代入先

    if( json.isLogin==false ){
      //ログインしていない場合
      element=document.getElementById("stat-logout");
      if( element!=null ){
        element.style.display = "block";
      }
      element=null;

      element=document.getElementById("stat-login");
      if( element!=null ){
        element.style.display = "none";
      }
      element=null;

      element=document.getElementById("pcfsdi");
      if( element!=null ){
        element.style.display = "none";
      }
      element=null;

      element=document.getElementById("pcfsdi");
      if( element!=null ){
        element.style.display = "none";
      }
      element=null;

      element=document.getElementById("usrlendid");
      if( element!=null ){
        element.href ="https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrlend";
      }
      element=null;

      element=document.getElementById("usrrsvid");
      if( element!=null ){
        element.href="https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrrsv";
      }
      element=null;

      element=document.getElementById("usrmybook_li");
      if( element!=null ){
        element.style.display = "none";
      }
      element=null;

    }
    else {
      //ログイン中の場合

      element=document.getElementById("stat-logout");
      if( element!=null ){
        element.style.display = 'none';
      }
      element=null;

      element=document.getElementById("stat-login");
      if( element!=null ){
        element.style.display = 'block';
      }
      element=null;

      element=document.getElementById("onLoan");
      if( element!=null ){
        element.innerHTML = json.cntLend;
      }
      element=null;

      element=document.getElementById("delayed");
      if( element!=null ){
        element.innerHTML = json.cntEntai;
      }
      element=null;

      element=document.getElementById("reservation");
      if( element!=null ){
        element.innerHTML = json.cntYoyk;
      }
      element=null;

      element=document.getElementById("assignment");
      if( element!=null ){
        element.innerHTML = json.cntWariate;
      }
      element=null;

      document.getElementById("personal-info");
      if( element!=null ){
        element.style.display = 'block';
      }
      element=null;

      if( json.serchname ){
        // デコード
        var deSerchname = decodeURI(json.serchname);
        // split関数を使って文字列から配列を返す
        var pcfsdipk = deSerchname.split(";");
        for( var i=0; i< pcfsdipk.length; i++){
          var strs = pcfsdipk[i].split(",");
          // サイズをチェックする
          if( strs.length > 1){
            // ULのIDを取得する
            var pcfsdi_ul = document.getElementById("pcfsdi_ul");
            if( pcfsdi_ul!=null ){
              var pcfsdi_li = document.createElement("li");
              pcfsdi_ul.appendChild( pcfsdi_li );
              pcfsdi_li.innerHTML = "<a href=\"https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=pcfsdi&groupid="+
              strs[1]+"\"><strong>"+ strs[0] + "</strong></a>";
              pcfsdi_li = null;
            }
            pcfsdi_ul = null;
          }
        }
      }
      var pcfsdi_a = document.getElementById("pcfsdi_a");
      if( pcfsdi_a!=null ){
        if( json.pcfsdiserch==0 ){  
          pcfsdi_a.href = "https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=newpcfsdi";
          pcfsdi_a.disabled = false;
        } else if( json.pcfsdiserch==1 ){
          pcfsdi_a.disabled = true;
        } else if( json.pcfsdiserch==2 ){
          if( json.serchname ){
            var nopcfsdi_ul = document.getElementById("nopcfsdi_ul");
            if( nopcfsdi_ul!=null ){
              var nopcfsdi_li = document.createElement("li");
              nopcfsdi_ul.appendChild(nopcfsdi_li);
              nopcfsdi_li.innerHTML = decodeURI(json.serchname);
              nopcfsdi_li = null;
            }
          }
          pcfsdi_a.href = "https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=newpcfsdi";
          pcfsdi_a.disabled = false;
        }
      }
      pcfsdi_a = null;

      if( json.loginshu==2 ){
        document.getElementById("usrlendid");
        if( element!=null ){
          element.href = "javascript:alert('仮パスワードでは利用できません。利用者情報メンテナンスからパスワードの変更を行なってください。')";
        }
        element=null;

        document.getElementById("usrrsvid");
        if( element!=null ){
          element.href = "javascript:alert('仮パスワードでは利用できません。利用者情報メンテナンスからパスワードの変更を行なってください。')";
        }
        element=null;

        document.getElementById("usrmybook_li");
        if( element!=null ){
          element.style.display = 'none';
        }
        element=null;

      } else if( json.loginshu==3 ){
        document.getElementById("usrlendid");
        if( element!=null ){
          element.href = "javascript:alert('予約パスワードでは利用できません。図書館の窓口でパスワードを申請してください。')";
        }
        element=null;

        document.getElementById("usrrsvid");
        if( element!=null ){
          element.href = "javascript:alert('予約パスワードでは利用できません。図書館の窓口でパスワードを申請してください。')";
        }
        element=null;

        document.getElementById("usrmybook_li");
        if( element!=null ){
          element.style.display = 'block';
        }
        element=null;

      } else {
        document.getElementById("usrlendid");
        if( element!=null ){
          element.href = "https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrlend";
        }
        element=null;

        document.getElementById("usrrsvid");
        if( element!=null ){
          element.href = "https://www.lib-sakai.jp/licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrrsv";
        }
        element=null;

        document.getElementById("usrmybook_li");
        if( element!=null ){
          element.style.display = 'block';
        }
        element=null;

      }

    }

  }



  //初期情報ロード　→使わんでええようにした body.onLoad()で呼んでいた
  function callLoadXMLFile() {
    var url = "WPwdLoginCheckAction.do";

    //ログインチェック関数を呼出
    loadXMLFile(url);
  }


  //初期情報ロード用Ajax呼び出し
  //(weblogincheck.jsより移行)
  function loadXMLFile(inUrl) {
    var url = inUrl;
    new Ajax.Request(url, { method: "post", onComplete: displayData });
  }


  //表示項目の制御  ▲
  //オリジナル版
  function displayData(req, json) {
    if (json.isLogin) {
      document.getElementById("stat-logout").style.display = 'none';
      document.getElementById("stat-login").style.display = 'block';

      document.getElementById("lend").innerHTML = json.cntLend;
      document.getElementById("entai").innerHTML = json.cntEntai;
      document.getElementById("yoyk").innerHTML = json.cntYoyk;
      document.getElementById("wari").innerHTML = json.cntWariate;

      document.getElementById("personal-info").style.display = 'block';

      if (json.serchname) {
        // デコード
        var deSerchname = decodeURI(json.serchname);
        // split関数を使って文字列から配列を返す
        var pcfsdipk = deSerchname.split(";");
        for (var i = 0;i< pcfsdipk.length; i++) {
          var strs = pcfsdipk[i].split(",");
          // サイズをチェックする
          if (strs.length > 1) {
            // ULのIDを取得する
            var pcfsdi_ul = document.getElementById("pcfsdi_ul");
            if (pcfsdi_ul) {
              var pcfsdi_li = document.createElement("li");
              pcfsdi_ul.appendChild(pcfsdi_li);
              pcfsdi_li.innerHTML = "<a href=\"licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=pcfsdi&groupid="+
              strs[1]+"\"><strong>"+ strs[0] + "</strong></a>";
              pcfsdi_li = null;
            }
            pcfsdi_ul = null;
          }
        }
      }
      var pcfsdi_a = document.getElementById("pcfsdi_a");
      if (json.pcfsdiserch==0) {  
        pcfsdi_a.href = "licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=newpcfsdi";
        pcfsdi_a.disabled = false;
      } else if (json.pcfsdiserch==1) {
        pcfsdi_a.disabled = true;
      } else if (json.pcfsdiserch==2) {
        if (json.serchname) {
          var nopcfsdi_ul = document.getElementById("nopcfsdi_ul");
          if (nopcfsdi_ul) {
            var nopcfsdi_li = document.createElement("li");
            nopcfsdi_ul.appendChild(nopcfsdi_li);
            nopcfsdi_li.innerHTML = decodeURI(json.serchname);
            nopcfsdi_li = null;
          }
        }
        pcfsdi_a.href = "licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=newpcfsdi";
        pcfsdi_a.disabled = false;
      }
      pcfsdi_a = null;

      if (json.loginshu==2) {
        document.getElementById("usrlendid").href = "javascript:alert('仮パスワードでは利用できません。利用者情報メンテナンスからパスワードの変更を行なってください。')";
        document.getElementById("usrrsvid").href = "javascript:alert('仮パスワードでは利用できません。利用者情報メンテナンスからパスワードの変更を行なってください。')";
        document.getElementById("usrmybook_li").style.display = 'none';
      } else if (json.loginshu==3) {
        document.getElementById("usrlendid").href = "javascript:alert('予約パスワードでは利用できません。図書館の窓口でパスワードを申請してください。')";
        document.getElementById("usrrsvid").href = "javascript:alert('予約パスワードでは利用できません。図書館の窓口でパスワードを申請してください。')";
        document.getElementById("usrmybook_li").style.display = 'block';
      } else {
        document.getElementById("usrlendid").href ="licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrlend";
        document.getElementById("usrrsvid").href="licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrrsv";
        document.getElementById("usrmybook_li").style.display = 'block';
      }
    } else {
      document.getElementById("stat-login").style.display = 'none';
      document.getElementById("stat-logout").style.display = 'block';

      document.getElementById("personal-info").style.display = 'none';
      document.getElementById("pcfsdi-info").style.display = 'none';
      document.getElementById("pcfsdi").style.display = 'none';
      document.getElementById("usrlendid").href ="licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrlend";
      document.getElementById("usrrsvid").href="licsxp-opac/WOpacMnuTopInitAction.do?WebLinkFlag=1&moveToGamenId=usrrsv";
      document.getElementById("usrmybook_li").style.display = 'none';
    }
  }


// -->



