//顏色選擇器
function neillibrary_colorpicker(dcolor, pickerid,colorid) {
//defaultColor 預設顏色
//pickerid 選擇器ID
//colorid 返回色碼input ID
//使用方法<input id="color" ><input type="color" id="colorWell"  value="#ff0000" placeholder="背景顏色">

let colorWell;
const defaultColor = dcolor; 
window.addEventListener('load', startup, false);
function startup() {
  colorWell = document.querySelector(pickerid);
  colorWell.value = defaultColor;
  colorWell.addEventListener('input', updateFirst, false);
  colorWell.addEventListener('change', updateAll, false);
  colorWell.select();
}
function updateFirst(event) {
   $(colorid).val(event.target.value);
}
function updateAll(event) {
    $(colorid).val(event.target.value);
}
}

//以文字空格切格左右兩塊等齊排版
function neillibrary_Alignleftandright(boxid, spacing) {
  //boxid=遍歷起始ID
  //spacing=左右空格間距
  //neillibrary_Alignleftandright(boxid="#about #tabs-1 li",spacing="30");	
  $(boxid).each(function() {
    var text = $(this).html();
    var splitIndex = text.indexOf(' ');
    if (splitIndex !== -1) {
      var leftText = text.substring(0, splitIndex).trim();
      var rightText = text.substring(splitIndex + 1).trim();
      var alignedText = '<div class="aligned-text">';
      alignedText += '<span class="leftbox">' + leftText + '</span>';
      alignedText += '<div class="rightbox">' + rightText + '</div>';
      alignedText += '</div>';
      $(this).html(alignedText);
    }
  });
  var maxWidth = 0;
  $(boxid + ' .aligned-text .leftbox').each(function() {
    var width = $(this).width();
    if (width > maxWidth) {
      maxWidth = width;
    }
  });
  if ($("body.computer").length == '1') { //電腦版
    $(boxid + ' .aligned-text .leftbox').css({
      "display": "block",
      "float": "left",
      "width": "" + (maxWidth + +Number(spacing)) + "px"
    });
   $(boxid + ' .aligned-text .rightbox').css({
      "padding-left": (maxWidth + +Number(spacing)) + "px",
   });      
  } else { //手機版
    $(boxid + ' .aligned-text .leftbox').css({
      "display": "block"
    });
    $(boxid + ' .aligned-text .rightbox').css({
      "margin-left": "8px"
    });
  }
}

//多語言標籤產生區塊
function neillibrary_llanguagetext(afterid) {
  $.ajax({
    url: xoopsjsurl + '/modules/neillibrary/ajax.php',
    type: 'POST',
    data: {
      id: 189
    },
    success: function(response) {
      $(afterid).after(response);
      neillibrary_llanguageoperate();
    },
    error: function() {
      console.log('ajax error!');
    }
  })
}
//建立語言標籤操作
function neillibrary_llanguageoperate() {
  var $text = JSON.parse(corparr);
  $('body').on('click', '#langbox  #langoperate', function() {
    var results = [];
    $('#langbox .inputeach').each(function(index) {
      var $langbox = '[' + $(this).attr("name") + ']' + $(this).val() + '[/' + $(this).attr("name") + ']';
      results.push($langbox);
    });
    var resultStr = results.join(''); // 將陣列中的值連接起來
    $("#langbox #lang_textarea").val(resultStr);
  });
  
  // 初始化 Clipboard.js
  var clipboard = new ClipboardJS('#lang_copy', {
    text: function() {
      // 獲取要複製的內容
      var content = $('#langbox #lang_textarea').val();
      return content;
    }
  });
  // 複製成功時的回調函式
  clipboard.on('success', function(e) {
    swal($text['text1']);
    e.clearSelection();
  });
  // 複製失敗時的回調函式
  clipboard.on('error', function(e) {
    swal('copy fail');
  });
  //複製內容
  $('body').on('click', '#langbox  #lang_copy', function() {
    // 獲取要複製的內容
    clipboard.onClick(event);
  });
  //清除內容
  $('body').on('click', '#langbox  #lang_clear', function() {
    $("#langbox .inputeach").val('');
    $("#langbox #lang_textarea").val('');
    var str = " ";
    var $temp = $('<input>');
    $('body').append($temp);
    $temp.val(str).select();
    document.execCommand('copy');
    $temp.remove();
    swal($text['text2']);
  });
}


//滑鼠鎖右鍵
function neillibrary_lockrightbutton() {
    $(document)[0].oncontextmenu = function() { return false; }
    $(document).mousedown(function(e) {
        if( e.button == 2 ) {
         //   alert('Sorry, this functionality is disabled!');
            return false;
        } else {
            return true;
        }
    });
}



//AJAX自訂欄位全體取值
function neillibrary_allfieldvalues(id, modulesid, btn, eachid, foundid, returnid, formtype, blockeach, required) {
  $('body').on('click', btn, function() {
    $(this).hide();
    var number = neillibrary_latestnumber(eachid, foundid);
    var material = {};
    var fsetup = {};
    var fieldArr = {};
    var optionsname = {};
    $('' + eachid + '').each(function(i) {
      material[i] = {};
      material[i]['fieldtitle'] = $('#fieldtitle' + $(this).attr("name") + '').val(); //欄位名稱
      material[i]['fypeoption'] = $('#fypeoption' + $(this).attr("name") + '').find(':selected').attr('data-id'); //欄位類型
      material[i]['fnumber'] = $(this).attr("name"); //fnumber
      material[i]['fwidthoption'] = $('#fwidthoption' + $(this).attr("name") + '').find(':selected').attr('data-id'); //欄位寬度
      material[i]['frequired'] = $('.frequired' + $(this).attr("name") + ':checked').val(); //是否必填  
      material[i]['fdirections'] = $('#fdirections' + $(this).attr("name") + '').val(); //欄位說明   */ 	  
      fsetup[i] = {};
      fsetup[i]['0'] = $('.fsetup' + $(this).attr("name") + '0:checked').val(); //設定0
      fsetup[i]['1'] = $('.fsetup' + $(this).attr("name") + '1').val(); //設定1    	
      material[i]['fsetup'] = fsetup[i]; //設定Arr
      fieldArr[i] = {};
      $('#optionsbox' + $(this).attr("name") + ' #fieldArreach' + $(this).attr("name") + '').each(function(index) {
        fieldArr[i][index] = {};
        fieldArr[i][index] = $(this).val();
      });
      optionsname[i] = {};
      $('#optionsbox' + $(this).attr("name") + ' #optionsnameeach' + $(this).attr("name") + '').each(function(index) {
        optionsname[i][index] = {};
        optionsname[i][index] = $(this).val();
      });
      material[i]['fieldArr'] = fieldArr[i];
      material[i]['optionsname'] = optionsname[i];
    });
    $.ajax({
      url: xoopsjsurl + '/modules/' + modulesid + '/ajax.php',
      type: 'POST',
      data: {
        id: id,
        formtype: formtype, //空值(全部欄位) 1->精簡欄位不顯示上傳
        material: material
      },
      cache: false,
      ifModified: true,
      async: false,
      success: function(response) {
        $(returnid).append(response); //建構內容     
        $.fancybox.close(); //關閉浮動框
        switch (modulesid) {
          case 'neilproduct':
            neilproduct_emptyfieldneilproduct_emptyfield(blockeach, required);
            break;
        }
      },
      error: function() {
        console.log('ajax error!');
      }
    })
  })
}






//建立自訂欄位
function neillibrary_customfield(id, modulesid, btn, eachid, foundid, types, oldnumber,fromtype,storebtn) {
    $("body").on("click", "" + btn + "", function() {
      //取得number最大值
      var $number =neillibrary_latestnumber(eachid, foundid);
         	  
        $.ajax({
            url: xoopsjsurl + '/modules/' + modulesid + '/ajax.php',
            type: 'POST',
            data: {
                id: id,
                va1: $(this).attr("name"),
                types: types,
                oldnumber: oldnumber,
                fromtype: fromtype, //空值(全部欄位) 1->精簡欄位不顯示上傳
                number: Number($number) + 1
            },
            cache: false,
            ifModified: true,
            async: false,
            success: function(response) {
                $(foundid).attr('count', (Number($number) + 1));
                $("" + foundid + "").prepend(response); //建構內容
                if($(storebtn) &&  $(eachid).length == '1') $(storebtn).show();
            },
            error: function() {
                console.log('ajax error!');
            }
        })
    })
}

//取得最新number
function neillibrary_latestnumber(eachid, foundid) {
    //遍歷contentbox
    var $contentbox = new Array();
    $('' + eachid + '').each(function(i) {
        $contentbox[i] = $(this).attr("name");
    });
    var $numberMath = Math.max.apply(null, $contentbox); //取得最大值
    var $count = (typeof($(foundid).attr("count")) == 'undefined') ? "0" : $(foundid).attr("count");
    var $number = (typeof($('' + eachid + ':last').attr("name")) == 'undefined') ? $count : (typeof($(foundid).attr("count")) == 'undefined') ? $numberMath : $(foundid).attr("count");
    return $number;
}



    //刪除區塊代表圖
    function neillibrary_deleterblockimg() {
        $("body").on("click", ".blockdeletebtn", function() {
            var $btnname = $(this).attr("name");
            var $btn_arr = $btnname.split(','); //切割陣列
            $.ajax({
                url: xoopsjsurl + '/modules/neillibrary/ajax.php',
                type: 'POST',
                data: {
                    id: $btn_arr[0],
                    var1: $btn_arr[1]
                },
                success: function(response) {
                    $('.deletebox').remove();
                    swal("代表圖已刪除", "Representative image deleted");
                },
                error: function() {
                    console.log('ajax error!');
                }
            })
        })
    }
//按鈕顯示內容
function neillibrary_buttondisplaycontent() {
    $(".btn-operation .groupeach").each(function(index) {
        var $index = index + 1;
        $("body").on("click", ".btn-operation #btn0" + $(this).attr("name") + "", function() {
            $(".conetntbox").hide();           
            $("#conetnt0" + $index + "").fadeOut(100);
           if ($index == $(this).attr("name")) $("#conetnt0" + $index + "").fadeIn(500).show();
        })
    });
}

//去除TTML標籤
function neillibrary_removeHTMLTag(str) {
  str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
  str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
  str = str.replace(/\n[\s| | ]*\r/g, '\n'); //去除多餘空行
  str = str.replace(/&nbsp;/ig, ''); //去掉&nbsp;
  str = str.replace(/\s/g, ''); //將空格去掉
  return str;
}
//開啟管理區
function neillibrary_openadminfunction() {
  $('.openboxArr').hide();
  $(".openadmin").each(function(index) {
    var $topindex = index;
    var $openbtn = '.openbtn' + (index + 1);
    var $openbox = '.openbox' + (index + 1);
 //   var $anchored = '.anchored' + (index + 1);
    $("body").on("click", $openbtn, function(e) {
      //非點擊區隱藏內容 	
      $(".openboxArr").each(function(index) {
        if ($topindex != index) $('.openbox' + (index + 1)).hide();
      });
      $($openbox).slideToggle("fast");
    //  if ($($anchored).length == '1') { SmoothScrollTo($anchored, 300);   }   
    })
  });
}
//標籤樣式
function neillibrary_labelstylefunction() {
  $(".labelcssArr").each(function(index) {
    var $labelstyle = $(this).attr("name");
    var $labelstyle_arr = $labelstyle.split(','); //切割陣列 	
    if ($labelstyle_arr[2] != '1') {
      $("#labelcss").attr('id', 'labelcss' + index); //ID加上新編號    
    } else {
      $("#labelcss").attr('id', 'labelcss_continue'); //使用新同ID接續之前編號 
    }
    var $boxid = "#" + $(this).attr("id"); //取得加上編號後的ID    

    $("" + $boxid + " >  " + $labelstyle_arr[1] + "").each(function(index) {
      var $number = index + 1;
      switch ($labelstyle_arr[0]) {
        case '1':
          var $label = "•"; //樣式 •
          var $lineheight = "180%";
          var $margintop = "0px";
          $("" + $boxid + " > " + $labelstyle_arr[1] + "").css({
            "position": "relative",
            "padding": "0px 0px 10px 22px"
          });
          break;
        case '2':
          var $label = "(" + digitaltoenglish($number, type = '') + ")、 "; //樣式 (一)、
          var $lineheight = "180%";
          var $margintop = "0px";
          if (themefolder == 'computer') {
            $paddingvar = ($number > 10) ? "0px 0px 10px 80px" : "0px 0px 10px 60px";
            if (($number >= 10) && $labelstyle_arr[1] == 'dt') {
              $("#xo-content .formatbox " + $boxid + "  dd").css({
                "padding": "0px 0px 10px 81px"
              });
            }
          } else {
            $paddingvar = ($number > 10) ? "0px 0px 10px 122px" : "0px 0px 10px 105px";
            if (($number >= 10) && $labelstyle_arr[1] == 'dt') {
              $("#xo-content .formatbox " + $boxid + "  dd").css({
                "padding": "0px 0px 10px 125px"
              });
            }
          }
          $("" + $boxid + " > " + $labelstyle_arr[1] + "").css({
            "position": "relative",
            "line-height": $lineheight,
            "padding": $paddingvar
          });
          break;
        case '3':
          $label = +$number + "、"; //樣式 1、
          var $lineheight = "180%";
          var $margintop = "0px";
          if (themefolder == 'computer') {
            $paddingvar = ($number >= 10) ? "0px 0px 10px 50px" : "0px 0px 10px 35px";
          } else {
            $paddingvar = ($number >= 10) ? "0px 0px 10px 80px" : "0px 0px 10px 60px";
          }
          $("" + $boxid + " > " + $labelstyle_arr[1] + "").css({
            "position": "relative",
            "padding": $paddingvar
          });
          break;
        case '4':
          var $label = "◎"; //樣式 •
          var $lineheight = "180%";
          var $margintop = "0px";
          if (themefolder == 'computer') {
            $paddingvar = "0px 0px 10px 22px";
          } else {
            $paddingvar = "0px 0px 10px 50px";
          }          
          $("" + $boxid + " > " + $labelstyle_arr[1] + "").css({
            "position": "relative",
            "padding": $paddingvar
          });
          break;
        case '5':
          var $label = "" + digitaltoenglish($number, type = '1') + "、 "; //樣式 壹、
          var $lineheight = "180%";
          var $margintop = "0px";
          if (themefolder == 'computer') {
            var $fontsize = "105%";
            $paddingvar = ($number > 10) ? "0px 0px 10px 80px" : "0px 0px 10px 50px";
            if (($number >= 10) && $labelstyle_arr[1] == 'dt') {
              $("#xo-content .formatbox " + $boxid + "  dd").css({
                "padding": "0px 0px 10px 81px"
              });
            }
          } else {
            var $fontsize = "100%";
            $paddingvar = ($number > 10) ? "0px 0px 10px 125px" : "0px 0px 10px 80px";
            if (($number >= 10) && $labelstyle_arr[1] == 'dt') {
              $("#xo-content .formatbox " + $boxid + "  dd").css({
                "padding": "0px 0px 10px 125px"
              });
            }
          }
          $("" + $boxid + " > " + $labelstyle_arr[1] + "").css({
            "position": "relative",
            "line-height": $lineheight,
            "padding": $paddingvar
          });
          break;
        default:
      }
      if ($labelstyle_arr[3] != 'jump') {
        $(this).before("<span id='labelbox" + $number + "' class='labelbox'>" + $label + "</span>"); //去除jump元件建構標籤
      }
      if (themefolder == 'computer') {
        $("" + $boxid + "  #labelbox" + $number + "").css({
          "position": "relative",
          "float": "left",
          "line-height": $lineheight,
          "font-size": $fontsize,
          "margin-top": $margintop
        });
      } else {
        $("" + $boxid + "  #labelbox" + $number + "").css({
          "position": "relative",
          "float": "left",
          "font-size": $fontsize,
          "line-height": $lineheight,
          "margin-top": $margintop
        });
      }
    });
  });
}
//1-99英文數字轉中文
function digitaltoenglish(num, type) {
  var numStr = Math.round(num).toString().split('')
  switch (type) {
    case '1':
      var digitChar = ['', '壹', '貳', '參', '肆', '伍', '陸', '柒', '捌', '玖', '拾']
      break;
    default:
      var digitChar = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
  }
  var result = numStr.map(function(char, index) {
    var res = digitChar[char]
    if (char === '0' && numStr[0] == 1) {
      res = digitChar[num]
    }
    if (char === '0' && numStr[0] > 1) {
      res = digitChar[10]
    }
    return res
  })
  if (numStr[0] == 1 && numStr[1] == 0) {
    return result[1];
  } else if (numStr[0] == 1 && numStr[1]) {
    return digitChar[10] + result[1]
  } else {
    return result.join('')
  }
}



//年級班級-ajax讀取選單
function neillibrary_classmenufunction() {
  var $selectid = $(this).find(':selected').data('id');
  var $selectboxname = $("#classselectboxname").attr("name");
  if (typeof($selectboxname) != 'undefined') {
    var $selectboxname_arr = $selectboxname.split(','); //切割陣列	
    var $selectidedit = $selectboxname_arr[0];
    var $status = $selectboxname_arr[1];
    var $of_sortid = $selectboxname_arr[2];
    if ($selectboxname_arr[0] != '') {
      ajaxcode($selectid, $status, $exchange, $selectidedit, $of_sortid);
    }
    var $exchange = false;
  }

  function ajaxcode($selectid, $status, $exchange, $selectidedit, $of_sortid) {
    var $selectboxname = $("#classselectboxname").attr("name");
    if (typeof($selectboxname) != 'undefined') {
      var $selectboxname_arr = $selectboxname.split(','); //切割陣列
      var $status = $selectboxname_arr[1];
      var $namevar = $selectboxname_arr[3];
      var $title = $selectboxname_arr[4];
    }
    $.ajax({
      url: xoopsjsurl + '/modules/neillibrary/ajax.php',
      type: 'POST',
      data: {
        id: '173',
        dbid: $selectid,
        selectid: 'classdefault1',
        status: $status,
        exchange: $exchange,
        selectidedit: $selectidedit,
        of_sortid: $of_sortid,
        var1: $namevar,
        var2: $title,
        xoopsmodule: 'neillibrary'
      },
      success: function(response) {
        $('#classselectbox').html(response);
      },
      error: function() {
        console.log('ajax error!');
      }
    })
  }
  //取得選單中數值
  $("body").on("change", "#classdefault", function() {
    $selectid = $(this).find(':selected').data('id');
    if ($selectid != '0') {
      ajaxcode($selectid, $status = "", $exchange = true);
    } else {
      $selectid = 0;
      ajaxcode($selectid);
    }
  });
}
//SmoothScrollTo("#elementId", 1000);滾動到ID或NAME的任何元素：
function SmoothScrollTo(id_or_Name, timelength) {
  var timelength = timelength || 1000;
  $('html, body').animate({
    scrollTop: $(id_or_Name).offset().top - 70
  }, timelength, function() {
    window.location.hash = id_or_Name;
  });
}
//區塊標題指定文字數變色
function textcolorexchange() {
  $(".exchangeArr").each(function(index) {
    var $exchangetext = $(this).attr("name"); //由0開始到擷取位置字元數
    //擷取指定字元 
    var $substrbefore = $(this).html().substr(0, $exchangetext);
    //擷取剩餘字元
    var $substrRear = $(this).html().substr($exchangetext);
    //輸出
    $(this).html('<span id="textcolor">' + $substrbefore + '</span>' + $substrRear + '');
  });
}
//區塊代表圖AJAX上傳
function blocksimgajaxupload() {
  $("body").on("click", "#submitblock", function(e) {
    cancelHandler(); //加上鎖住外連設定   
    var $blockimgname = $("#blockimgname").attr("name");
    var $blockimgname_arr = $blockimgname.split(','); //切割陣列	
    //alert($blockimgname);
    var file_data = $('#blockimg').prop('files')[0];
    var form_data = new FormData();
    //上傳檔案變數
    form_data.append('file', file_data); //檔案
    //自訂變數
    form_data.append('id', $blockimgname_arr[0]); //id
    form_data.append('var1', $blockimgname_arr[1]); //圖檔尺寸
    form_data.append('var2', $blockimgname_arr[2]); //存放資料夾    
    form_data.append('var3', $blockimgname_arr[3]); //圖檔檔名
    form_data.append('imguploader', true);
    $.ajax({
      url: xoopsjsurl + '/modules/neillibrary/ajax.php',
      cache: false,
      contentType: false,
      processData: false,
      data: form_data,
      type: 'post',
      success: function(response) {
        $("#blockimgname").html("<input type='hidden' name='" + $blockimgname_arr[4] + "'  value='" + $blockimgname_arr[3] + "'> "); //圖檔檔名存options         	
        $('#blockform').submit(); //啟用submit();  
      },
      error: function() {
        console.log('ajax error!');
      }
    })
  })
  //加上鎖住外連設定   	 
  function cancelHandler(event) {
    var event = event || window.event; //兼容IE 
    //取消事件相關的預設行為
    if (event.preventDefault) //標準技術 
      event.preventDefault();
    if (event.returnValue) //兼容IE9之前的IE 
      event.returnValue = false;
    return false; //用於處理使用對象屬性註冊的處理程序
  }
}
//分類刪除
function deletecategory(failtext) {
//failtext->刪除失敗說明文字

  $(".deleteeachArr").each(function(index) {
    var $deletname = $(this).attr("name");
    if (typeof($deletname) != 'undefined') {
      var $deletname_arr = $deletname.split(','); //切割陣列
      var $centerid = $deletname_arr[1];
    }
    //迴圈刪除
    var $btn = "#deletebotton" + $centerid + "";
    $($btn).click(function() {
      $ajaxsetup = $(this).attr("name");
      if ($ajaxsetup != undefined) {
        var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
      }
      var $id = $ajaxsetup_arr[0]; //ajax-ID
      var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
      var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文字  	
      var $var2 = $ajaxsetup_arr[4]; //db刪除欄位參數-分類
      var $var3 = $ajaxsetup_arr[5]; //db刪除欄位參數-內容
      var $var5 = $ajaxsetup_arr[6]; //db刪除內容底層物件->DBname
      var $var4 = $ajaxsetup_arr[7]; //db刪除內容欄位-key
      var $var6 = $ajaxsetup_arr[8]; 
      var $xoopsmodule = $ajaxsetup_arr[9];
      var $var7 = $ajaxsetup_arr[10]; //db刪除欄位參數-key    
      var $var8 = $ajaxsetup_arr[11]; //sortretorted類型
      var  $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
      swal({
        title: $deletetext + $title ,
        text: "這將會刪除這筆資料內容",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "Delete 刪除",
        cancelButtonText: "Cancel 取消！",
        confirmButtonColor: "#ec6c62"
      }, function(isConfirm) {
        if (isConfirm) {
          $.ajax({
            url: xoopsjsurl + '/modules/neillibrary/ajax.php',
            type: 'POST',
            data: {
              id: $id,
              dbid: $dbid,
              var2: $var2,
              var3: $var3,
              var4: $var4,
              var5: $var5,
              xoopsmodule: $xoopsmodule,
              var6: $var6,
              var7: $var7,
              var8: $var8
            },
            dataType: 'json', //設為json
            async: false, //設為false	 		
          }).done(function(data) {
            if (data == false) {
              if(failtext){
              swal(failtext, "刪除操作失敗了！", "error");
              }else{
              swal("OMG", "刪除操作失敗了！", "error");              
              }	              
            } else {
              swal("操作成功!", "已成功刪除資料！", "success");
              getMyArtic($deletetrid = data);
            }
          }).error(function(data) {
            swal("OMG", "刪除操作失敗了！", "error");
          });
        } else {
          swal("取消！", "你的資料是安全的:)", "error");
        }

        function getMyArtic($deletetrid) {
          $(this).click(function() {
            //	 location.reload()
            $t = $($deletetrid);
            $t.remove();
          });
        }
      });
    });
  });
}
//城市鄉鎮-ajax讀取選單
function citymenufunction($text_w) {
  var $selectid = $(this).find(':selected').data('id');
  var $selectboxname = $("#cityselectboxname").attr("name");
  if (typeof($selectboxname) != 'undefined') {
    var $selectboxname_arr = $selectboxname.split(','); //切割陣列	
    var $selectidedit = $selectboxname_arr[0];
    var $status = $selectboxname_arr[1];
    var $of_sortid = $selectboxname_arr[2];
    if ($selectboxname_arr[0] != '') {
      ajaxcode($selectid, $status, $exchange, $selectidedit, $of_sortid);
    }
    var $exchange = false;
  }

  function ajaxcode($selectid, $status, $exchange, $selectidedit, $of_sortid) {
    var $selectboxname = $("#cityselectboxname").attr("name");
    if (typeof($selectboxname) != 'undefined') {
      var $selectboxname_arr = $selectboxname.split(','); //切割陣列
      var $status = $selectboxname_arr[1];
      var $namevar = $selectboxname_arr[3];
    }
    $.ajax({
      url: xoopsjsurl + '/modules/neillibrary/ajax.php',
      type: 'POST',
      data: {
        id: '169',
        dbid: $selectid,
        selectid: 'citydefault1',
        status: $status,
        exchange: $exchange,
        selectidedit: $selectidedit,
        of_sortid: $of_sortid,
        var1: $namevar
      },
      success: function(response) {
        $('#cityselectbox').html(response);
        if($text_w)  $('.citybox #of_cityid2').css({"width": $text_w });  
        },
      error: function() {
        console.log('ajax error!');
      }
    })
  }
  //取得選單中數值
  $("body").on("change", "#citydefault", function() {
    $selectid = $(this).find(':selected').data('id');
    if ($selectid != '0') {
      ajaxcode($selectid, $status = "", $exchange = true);
    } else {
      $selectid = 0;
      ajaxcode($selectid);
    }
  });
}
//管理後台-選單按鈕收合
function menucollapsefunction() {
  $(".boxbuteach").each(function(index) {
    var index = index + 1;
    var $boxbut = ".box" + index + "";
    var $boxbutton = ".boxbutton" + index + "";
    // alert($boxbut);
    $($boxbutton).click(function() {
      $($boxbut).slideToggle("fast");
      var $openboxtextvar = $($boxbutton).text();
      if ($openboxtextvar == "展開") {
        $($boxbutton).text("收合");
      } else {
        $($boxbutton).text("展開");
      }
    });
  });
}
//拖曳選單-存AJAX
function dragmenufunction() {
    $(".sortable").sortable({
        items: itemsvar, //指定拖曳元件或ID及CLASS    
        cursor: "move",
        opacity: 0.6, //拖動時，透明度為0.6
        revert: false, //釋放時，增加動畫
        scroll: true, //元素被拖動到頁面邊緣時，會自動滾動。 
        scrollSpeed: 20, //設置頁面滾動的速度	    
        forceHelperSize: true, //強制幫助器具有大小
        update: function(event, ui) { //更新排序之後
            $toArray = $(this).sortable("toArray"); //更新排序取ID值
         // alert($toArray);
            var $ajaxsetup = $('.sortable').attr("name");
             var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
            //AJAX開始    
            $.ajax({
                url: xoopsjsurl + '/modules/neillibrary/ajax.php',
                type: 'POST',
                data: {
                    id: $ajaxsetup_arr[0],
                    xoopsmodule: $ajaxsetup_arr[1],
                    type: $ajaxsetup_arr[2], //type
                    dbid: $ajaxsetup_arr[3], //pageid
                    var1: $ajaxsetup_arr[4], //typesid
                    var2: $ajaxsetup_arr[5], //sortid
                    var3: $ajaxsetup_arr[6], //suid
                    var4: $ajaxsetup_arr[7], //DBname
                    var5: $ajaxsetup_arr[8], //DBKEY
                    var6: $ajaxsetup_arr[9], //typesort
                    var7: $ajaxsetup_arr[10], //Arr-id && img name         
                    Arr: $toArray,
                    var8: $ajaxsetup_arr[11] //排序name
                },
                success: function(response) {
               //    swal(+response+"已更動內容排序", "Content sorting changed");
                },
                error: function() {
                    console.log('ajax error!');
                }
            }) //AJAX結束         
        }
    });
}


//拖曳選單-只拖曳無儲存-ck兼容
function dragmenufunctionnoajax(itemsvar, handlevar, axisvar,editor,cktype,sortableid) {
	$sortableid=(typeof(sortableid) == 'undefined') ? ".sortable" : sortableid;
    $($sortableid).sortable({
        items: itemsvar, //指定拖曳元件或ID及CLASS
        scroll: true,
        scrollSpeed: 20,
        forceHelperSize: true,
        handle: handlevar,
        axis: axisvar,
        cursor: "move",
        distance: 5,
        forcePlaceholderSize: true,
        start: function(event, ui) {
            var textareaId = ui.item.find(editor).attr('id');
            if (typeof textareaId != 'undefined') {
                var editorInstance = CKEDITOR.instances[textareaId];
                editorInstance.destroy();
                CKEDITOR.remove(textareaId);
            }
        },
        stop: function(event, ui) {
            var textareaId = ui.item.find(editor).attr('id');
            if (typeof textareaId != 'undefined') {            	
            	if(cktype=='1'){
                neillibrary_ckeditorlist(editorvar=textareaId,xoopsjsurl,moduleid);    	
            	}else{
                CKEDITOR.replace(textareaId);  	
            	}
            }
        }
    });
}

//製作預覽圖(單張)
function previewfunction() {
  function preview(input) {
    if (input.files && input.files[0]) {
      var reader = new FileReader();
      reader.onload = function(e) {
        var $img = "<div class='thumbnail'><button type='button' id='emptybtn' class='btn btn-success btn-block'><span class='glyphicon glyphicon-remove' aria-hidden='true'></span>清除上傳圖檔</button><img src=" + e.target.result + "></div>";
        $(".preview").html($img);
      }
      reader.readAsDataURL(input.files[0]);
    }
  }
  $("body").on("change", "#blockimg", function() {
    preview(this);
    $("#imgtextbox").hide();  
  })
  $("body").on("click", "#emptybtn", function() {
    $("#blockimg").val("");
    $(".preview").html("");
    $("#imgtextbox").show();    
  })
}



//製作預覽圖(迴圈)
function previeweachfunction() {
    $(".previeweach").each(function(index) {
        function preview(input, index) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function(e) {
                    var $img = "<div class='thumbnail'><button type='button' id='emptybtn" + index + "' class='btn btn-success btn-block'><span class='glyphicon glyphicon-remove' aria-hidden='true'></span>清除上傳圖檔</button><img src=" + e.target.result + "></div>";
                    var $preview = '.preview' + index;
                    $($preview).html($img);
                }
                reader.readAsDataURL(input.files[0]);
            }
        }
        $("body").on("change", "#blockimg" + index + "", function() {
            preview(this, index);
        })
        $("body").on("click", "#emptybtn" + index + "", function() {
            $("#blockimg" + index + "").val("");
            $(".preview" + index + "").html("");
        })
    });
}







//群組管理
function xoopsgroupadminfunction() {
  var $ajaxsetup = $('#groupoperating').attr("name");
  var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
  $.ajax({
    url: xoopsjsurl + '/modules/neillibrary/ajax.php',
    type: 'POST',
    data: {
      id: $ajaxsetup_arr[0],
      groupid: $ajaxsetup_arr[1]
    },
    success: function(response) {
      $("#groupoperating").html(response);
    },
    error: function() {
      console.log('ajax error!');
    }
  })
}
//加入移除群組
function xoopsgroupadminoperating() {
  //加入群組
  $("body").on("click", "#joinbtn", function() {
    //取得選單值	
    var $selectedValues = $('select[name="unpaid"]').val() || [];
    if ($selectedValues == '') {
      swal("請選擇要加入的會員", "Please choose to join user");
    } else {
      var $ajaxsetup = $(this).attr("name");
      var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
      xoopsgroupadminoperating_ajax($ajaxsetup_arr, $selectedValues, $type = '1');
    };
  })
  //移除群組
  $("body").on("click", "#removebtn", function() {
    //取得選單值	
    var $selectedValues = $('select[name="paid"]').val() || [];
    if ($selectedValues == '') {
      swal("請選擇要移除的會員", "Please select to remove user");
    } else {
      var $ajaxsetup = $(this).attr("name");
      var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
      xoopsgroupadminoperating_ajax($ajaxsetup_arr, $selectedValues, $type = '2');
    }
  })
}

function xoopsgroupadminoperating_ajax($ajaxsetup_arr, $selectedValues, $type) {
  $.ajax({
    url: xoopsjsurl + '/modules/neillibrary/ajax.php',
    type: 'POST',
    data: {
      id: $ajaxsetup_arr[0],
      groupid: $ajaxsetup_arr[1],
      Arr: $selectedValues,
      type: $type
    },
    cache: false,
    ifModified: true,
    async: false,
    success: function(response) {
      swal("已完成會員群組變更操作", "user group change operation completed");
      xoopsgroupadminfunction();
    },
    error: function() {
      console.log('ajax error!');
    }
  })
}
//禁止返回上一頁
function prohibitpreviouspage() {
  if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6) {
    //Firefox
    setTimeout("fn_forward()", 1);
    window.history.go(1);
  } else { //IE.Chrome.Edge
    window.history.forward();
  }
}

function fn_forward() {
  history.forward();
  setTimeout("fn_forward()", 1);
}
//讀取狀態操作
function readtruetypefunction() {
  //預設判斷
  if ($(".readtruebox").val() == 'true') {
    $(".enablebox").css("display", "block");
    $('select[name=enable]').attr('disabled', false);
  }
  //影片判斷
  $("body").on("change", ".readtruebox", function() {
    if ($(this).find(':selected').attr('data-id') == 'true') {
      $(".enablebox").css("display", "block");
      $('select[name=enable]').attr('disabled', false);
    } else {
      $(".enablebox").css("display", "none");
      $('select[name=enable]').attr('disabled', true);
    }
  })
}
//影片類型說明	
function moviefunctiontypebtn() {
  $("body").on("change", "#selecttype", function() {
    $id = $(this).find(':selected').attr('data-id');
    moviefunctiontype($type = $id);
  })
  //預設判斷
  if ($("#selecttype").val() == 'null') {
    $("#movie").attr('disabled', true);
  }
  //影片判斷
  $("body").on("change", "#selecttype", function() {
    $("#movie").val("");
    if ($(this).find(':selected').attr('data-id') == 'null') {
      $("#movie").attr('disabled', true);
    } else {
      $("#movie").attr('disabled', false);
    }
  })
}

function moviefunctiontype($type) {
  var $urlname = $("#urldescription").attr("name");
  if (typeof($urlname) == 'undefined') return false; //空值終止程式     	
  var $url_arr = $urlname.split(','); //切割陣列	
  if (typeof($type) != 'undefined') {
    $url_arr[1] = $type;
  }
  $.ajax({
    url: xoopsjsurl + '/modules/neillibrary/ajax.php',
    type: 'POST',
    data: {
      id: $url_arr[0],
      type: $url_arr[1]
    },
    cache: false,
    ifModified: true,
    async: false,
    success: function(response) {
      $('#urldescription').slideToggle("fast").html(response).slideToggle("fast");
    },
    error: function() {
      console.log('ajax error!');
    }
  })
}
//全部選取/取消選取-舊版
$(document).ready(function() {
  $('input[name=checkboxall]').click(function() {
    if ($('input[name=checkboxall]').prop("checked")) { //如果全選按鈕有被選擇的話（被選擇是true）   	   
      $("input#checkbox").prop("checked", true); //把所有的核取方框的property都變成勾選
      	  
    } else {
      $("input#checkbox").prop("checked", false); //把所有的核取方框的property都取消勾選
    }
  })	  
})
	
//核取變換區塊樣式//全部選取/取消選取-新版	
function neillibrary_checkboxtransform(color, types) {
  //全部選取/取消選取
  $('input[name=newcheckboxall]').click(function() {
    if ($('input[name=newcheckboxall]').prop("checked")) { //如果全選按鈕有被選擇的話（被選擇是true）   	   
      $(".checkbox-inline input").prop("checked", true); //把所有的核取方框的property都變成勾選
      $('.readtruestyle').css('background-color', color);
    } else {
      $(".checkbox-inline input").prop("checked", false); //把所有的核取方框的property都取消勾選
      $('.readtruestyle').css('background-color', 'initial');
    }
  })
  //核取變換區塊樣式
  $(".checkboxstyle input").each(function(index) {
    switch (types) {
      case '1':
        var $btn = $(this).attr("id");
        $('#' + $btn).click(function() {
          if ($('#' + $btn).prop("checked")) { //如果全選按鈕有被選擇的話（被選擇是true） 
            $('.' + $btn).css('background-color', color);
          } else {
            $('.' + $btn).css('background-color', 'initial');
          }
        })
        break;
      default:
        var $btn = $(this).attr("name");
        $('.' + $btn).click(function() {
          if ($('input[name=' + $btn + ']').prop("checked")) { //如果全選按鈕有被選擇的話（被選擇是true）   	   
            $('.' + $btn).css('background-color', color);
          } else {
            $('.' + $btn).css('background-color', 'initial');
          }
        })
    }
  });
}
	
//列印功能
/*function printHtml(html) {
  var bodyHtml = document.body.innerHTML;
  document.body.innerHTML = html;
  window.print();
  document.body.innerHTML = bodyHtml;
  window.location.reload();
}

function onprint() {
  //去除超連結
  $('a').each(function(index) {
    $(this).replaceWith($(this).html());
  });
  //隱藏列印區塊
  $('#orderstatusbox').hide();
  var html = $("#printArea").html();
  printHtml(html);
}*/


function printHtml(html) {
  // 建立一個新的iframe元素
  var iframe = document.createElement('iframe');
  iframe.style.position = 'absolute';
  iframe.style.width = '0';
  iframe.style.height = '0';
  iframe.style.border = 'none';
  document.body.appendChild(iframe);
  
  // 在iframe中寫入要列印的HTML內容以及頁面中的樣式表連結和內聯樣式
  var doc = iframe.contentWindow.document;
  doc.open();
  // 複製頁面中的樣式表鏈接
  var stylesheets = document.querySelectorAll('link[rel="stylesheet"]');
  stylesheets.forEach(function(sheet) {
    doc.write(sheet.outerHTML);
  });
  // 複製頁面中的內聯樣式
  var styleTags = document.querySelectorAll('style');
  styleTags.forEach(function(style) {
    doc.write(style.outerHTML);
  });
  doc.write(html);
  doc.close();

  // 等待iframe完全載入後再進行列印
  iframe.onload = function() {
    iframe.contentWindow.focus();
    iframe.contentWindow.print();
    // 確保列印完成後移除iframe
    iframe.parentNode.removeChild(iframe);
  };
}

function onprint() {
  // 去除超連結
  $('a').each(function(index) {
    $(this).replaceWith($(this).html());
  });
  // 隱藏不需要列印的區塊
  $('#orderstatusbox').hide();
  // 只擷取特定区域的HTML内容
  var htmlContent = $("#printArea").html();
  //呼叫列印函數
  printHtml(htmlContent);
}






//js日曆-年月日時分秒
$(document).ready(function() {
  $(".mydate").each(function(index) {
    var index = index + 1;
    var $mydate = '#mydate' + index;
    $($mydate).datetimepicker({
      "dateFormat": "yy-mm-dd",  
      "timeFormat": "HH:mm:ss"
    });
  });
});
//CK編輯器-舊
$(document).ready(function() {
  var $editorzoom=($("#toplayerdiv").attr("zoom") == '' || typeof($("#toplayerdiv").attr("zoom")) == 'undefined') ? "1" : $("#toplayerdiv").attr("zoom");   
  var codemirror=($editorzoom==1) ? ',codemirror' : '';
  $(".editor").each(function(index) {
    var index = index + 1;
    var editorvar = 'editorvar' + index;    
   CKEDITOR.replace(editorvar, {
      skin: 'moono',
      width: '100%',
      height: '350',
      language: languagevar,
      toolbar: 'my',
      contentsCss: [xoopsjsurl + '/modules/neillibrary/css/bootstrap3/css/bootstrap.css', xoopsjsurl + '/modules/neillibrary/css/font-awesome/css/font-awesome.css'],
      extraPlugins: 'syntaxhighlight,dialog,eqneditor,quicktable,imagerotate,fakeobjects,widget,lineutils,widgetbootstrap,widgettemplatemenu,pagebreak,fontawesome,prism,embed,embedsemantic,codesnippet'+codemirror,
      //  extraPlugins: 'syntaxhighlight,dialog,eqneditor,quicktable,imagerotate,fakeobjects,widget,lineutils,widgetbootstrap,widgettemplatemenu,pagebreak,fontawesome,prism,codesnippet,codemirror,embed,embedsemantic,mediaembed',

      filebrowserBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=file&mod_dir=' + moduleid,
      filebrowserImageBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=image&mod_dir=' + moduleid,
      filebrowserFlashBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=flash&mod_dir=' + moduleid,
      /*=========取消CK編輯器上傳功能===============*/
      /*filebrowserUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=file&mod_dir=' + moduleid,
      filebrowserImageUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=image&mod_dir=' + moduleid,
      filebrowserFlashUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=flash&mod_dir=' + moduleid,
      */
      qtRows: 10, // Count of rows
      qtColumns: 10, // Count of columns
      qtBorder: '1', // Border of inserted table
      qtWidth: '100%', // Width of inserted table
      qtStyle: {
        'border-collapse': 'collapse'
      },
      qtClass: 'table table-bordered table-hover table-condensed', // Class of table
      qtCellPadding: '0', // Cell padding table
      qtCellSpacing: '0', // Cell spacing table
      qtPreviewBorder: '1px double black', // preview table border
      qtPreviewSize: '15px', // Preview table cell size
      qtPreviewBackground: '#c8def4' // preview table background (hover)
    });
    CKEDITOR.dtd.$removeEmpty['span'] = false;
  });
});


//CK編輯器-單筆建構用
function neillibrary_ckeditorlist(editorvar, xoopsjsurl, moduleid) {
  var $editorzoom=($("#toplayerdiv").attr("zoom") == '' || typeof($("#toplayerdiv").attr("zoom")) == 'undefined') ? "1" : $("#toplayerdiv").attr("zoom");   
  var codemirror=($editorzoom==1) ? ',codemirror' : '';	
    CKEDITOR.replace(editorvar, {
        skin: 'moono',
        width: '100%',
        height: '350',
        language: languagevar,
        toolbar: 'my',
        contentsCss: [xoopsjsurl + '/modules/neillibrary/css/bootstrap3/css/bootstrap.css', xoopsjsurl + '/modules/neillibrary/css/font-awesome/css/font-awesome.css'],
      //  extraPlugins: 'syntaxhighlight,dialog,eqneditor,quicktable,imagerotate,fakeobjects,widget,lineutils,widgetbootstrap,widgettemplatemenu,pagebreak,fontawesome,prism,codesnippet,codemirror,dialog,embed,embedsemantic',
        extraPlugins: 'syntaxhighlight,dialog,eqneditor,quicktable,imagerotate,fakeobjects,widget,lineutils,widgetbootstrap,widgettemplatemenu,pagebreak,fontawesome,prism,embed,embedsemantic,codesnippet'+codemirror,
        filebrowserBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=file&mod_dir=' + moduleid,
        filebrowserImageBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=image&mod_dir=' + moduleid,
        filebrowserFlashBrowseUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/elfinder.php?type=flash&mod_dir=' + moduleid,
        /*=========取消CK編輯器上傳功能===============*/
        /*
        filebrowserUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=file&mod_dir=' + moduleid,
        filebrowserImageUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=image&mod_dir=' + moduleid,
        filebrowserFlashUploadUrl: xoopsjsurl + '/modules/neillibrary/class/elFinder/upload.php?type=flash&mod_dir=' + moduleid,
        */	
        qtRows: 10, // Count of rows
        qtColumns: 10, // Count of columns
        qtBorder: '1', // Border of inserted table
        qtWidth: '100%', // Width of inserted table
        qtStyle: {
            'border-collapse': 'collapse'
        },
        qtClass: 'table table-bordered table-hover table-condensed', // Class of table
        qtCellPadding: '0', // Cell padding table
        qtCellSpacing: '0', // Cell spacing table
        qtPreviewBorder: '1px double black', // preview table border
        qtPreviewSize: '15px', // Preview table cell size
        qtPreviewBackground: '#c8def4' // preview table background (hover)
    });
    CKEDITOR.dtd.$removeEmpty['span'] = false;
}


//迴圈刪除
function eachboxArrfunction() {
  $(".eachboxArr").each(function(index) {
    var $namevar = $(this).attr("name");
    if (typeof($namevar) != 'undefined') {
      var $namevar_arr = $namevar.split(','); //切割陣列
      var $centerid = $namevar_arr[0];
    }
    //迴圈刪除
    $("#deletebotton" + $centerid + "").click(function() {
      $ajaxsetup = $(this).attr("name");
      if ($ajaxsetup != undefined) {
        var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
      }
      var $id = $ajaxsetup_arr[0]; //ajax-ID
      var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
      var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文字  	
      var $uid = $ajaxsetup_arr[4]; //uid  	
      var $pageid = $ajaxsetup_arr[5]; //pageid  	  
      var $xoopsModule = $ajaxsetup_arr[6]; //模組ID  	  
      var $enfunction = $ajaxsetup_arr[7]; //enfunction 
      var $var1 = $ajaxsetup_arr[8]; //var1  
      var  $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
      swal({
        title: $deletetext + $title,
        text: "這將會刪除這筆資料內容  his will delete this profile",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "Delete 刪除",
        cancelButtonText: "Cancel 取消！",
        confirmButtonColor: "#ec6c62"
      }, function(isConfirm) {
        if (isConfirm) {
          $.ajax({
            url: xoopsjsurl + '/modules/neillibrary/ajax.php',
            type: 'POST',
            data: {
              id: $id,
              dbid: $dbid,
              uid: $uid,
              pageid: $pageid,
              xoopsmodule: $xoopsModule,
              enfunction: $enfunction,
              var1: $var1
            },
          }).done(function(data) {
            if (data != false) {
              swal(data, "success");
            } else {
              swal("操作成功!", "已成功刪除資料！", "success");
              getMyArtic();
            }
          }).error(function(data) {
            swal("OMG", "刪除操作失敗了！", "error");
          });
        } else {
          swal("取消！", "你的資料是安全的:)", "error");
        }

        function getMyArtic() {
          $(this).click(function() {
            $t = $("#deletebottonbox" + $centerid + "");
            $t.remove();
          });
        }
      });
    });
  });
}
//按鈕刪除
function btndeletefunction(centerid) {
    $("#deletebotton" + centerid + "").click(function() {
        $ajaxsetup = $(this).attr("name");
        if ($ajaxsetup != undefined) {
            var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
        }
        var $id = $ajaxsetup_arr[0]; //ajax-ID
        var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
        var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文字  	
        var $uid = $ajaxsetup_arr[4]; //uid  	
        var $pageid = $ajaxsetup_arr[5]; //pageid  	  
        var $xoopsModule = $ajaxsetup_arr[6]; //模組ID  	  
        var $enfunction = $ajaxsetup_arr[7]; //enfunction 
        var $var1 = $ajaxsetup_arr[8]; //var1   
        var $var2 = $ajaxsetup_arr[9]; //var2
        var $var3 = $ajaxsetup_arr[10]; //var3
        var $var4 = $ajaxsetup_arr[11]; //var4
        var $var5 = $ajaxsetup_arr[12]; //var5
        var $var6 = $ajaxsetup_arr[13]; //var6   
        var $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
        swal({
            title: $deletetext + $title,
            text: "這將會刪除這筆資料內容  his will delete this profile",
            type: "warning",
            showCancelButton: true,
            closeOnConfirm: false,
            confirmButtonText: "Delete 刪除",
            cancelButtonText: "Cancel 取消！",
            confirmButtonColor: "#ec6c62"
        }, function(isConfirm) {
            if (isConfirm) {
                $.ajax({
                    url: xoopsjsurl + '/modules/neillibrary/ajax.php',
                    type: 'POST',
                    data: {
                        id: $id,
                        dbid: $dbid,
                        uid: $uid,
                        pageid: $pageid,
                        xoopsmodule: $xoopsModule,
                        enfunction: $enfunction,
                        var1: $var1,
                        var2: $var2,
                        var3: $var3,
                        var4: $var4,
                        var5: $var5,
                        var6: $var6
                    },
                }).done(function(data) {
                    if (data != false) {
                        swal(data, "success");
                    } else {
                        swal("操作成功!", "已成功刪除資料！", "success");
                        getMyArtic();
                    }
                }).error(function(data) {
                    swal("OMG", "刪除操作失敗了！", "error");
                });
            } else {
                swal("取消！", "你的資料是安全的:)", "error");
            }

            function getMyArtic() {
                $(this).click(function() {
                    $t = $("#deletebottonbox" + centerid + "");
                    $t.remove();
                });
            }
        });
    });
}
//迴圈刪除-key值
$(document).ready(function() {
  $(".deleteeach").each(function(index) { //刪除關鍵字	  
    var index = index + 1;
    $("#deletebotton" + index + "").click(function() {
      $ajaxsetup = $("#deletebotton" + index + "").attr("mane");
      if ($ajaxsetup != undefined) {
        var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
      }
      var $id = $ajaxsetup_arr[0]; //ajax-ID
      var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
      var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文字  	
      var $uid = $ajaxsetup_arr[4]; //uid  	
      var $pageid = $ajaxsetup_arr[5]; //pageid  	  
      var $xoopsModule = $ajaxsetup_arr[6]; //模組ID  	  
      var $enfunction = $ajaxsetup_arr[7]; //enfunction 
      var $var1 = $ajaxsetup_arr[8]; //var1
      var $var2 = $ajaxsetup_arr[9]; //var2
      var $var3 = $ajaxsetup_arr[10]; //var3
      var $var4 = $ajaxsetup_arr[11]; //var4
      var $var5 = $ajaxsetup_arr[12]; //var5
      var $var6 = $ajaxsetup_arr[13]; //var6
      
      
      
      var  $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
      swal({
        title: $deletetext + $title,
        text: "這將會刪除這筆資料內容  This will delete this profile",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "Delete 刪除",
        cancelButtonText: "Cancel 取消！",
        confirmButtonColor: "#ec6c62"
      }, function(isConfirm) {
        if (isConfirm) {
          $.ajax({
            url: xoopsjsurl + '/modules/neillibrary/ajax.php',
            type: 'POST',
            data: {
              id: $id,
              dbid: $dbid,
              uid: $uid,
              pageid: $pageid,
              xoopsmodule: $xoopsModule,
              enfunction: $enfunction,
              var1: $var1,
              var2: $var2,
              var3: $var3,
              var4: $var4,
              var5: $var5,
              var6: $var6
            },
          }).done(function(data) {
            if (data != false) {
              swal(data, "success");
            } else {
              swal(""+data+"操作成功!", "已成功刪除資料！", "success");
              getMyArtic();
            }
          }).error(function(data) {
            swal("OMG", "刪除操作失敗了！", "error");
          });
        } else {
          swal("取消！", "你的資料是安全的:)", "error");
        }

        function getMyArtic() {
          $(this).click(function() {
           if($("#deletetr" + index + "").length == '1')   $("#deletetr" + index + "").remove();
           if($("#deletetr2" + index + "").length == '1')  $("#deletetr2" + index + "").remove();
           if($(".deletetr" + index + "").length == '1')   $(".deletetr" + index + "").remove();
           if($(".deletetr2" + index + "").length == '1')  $(".deletetr2" + index + "").remove();
          });
        }
      });
    });
  });
});
//單頁刪除
$(document).ready(function() {
  $("#deletebotton").click(function() {
    $ajaxsetup = $("#deletebotton").attr("mane");
    if ($ajaxsetup != undefined) {
      var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
    }
    var $id = $ajaxsetup_arr[0]; //ajax-ID
    var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
    var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文  
    var $url = $ajaxsetup_arr[4]; //刪除後返回網址
    var $pageid = $ajaxsetup_arr[5]; //自訂變數
    var $xoopsmodule = $ajaxsetup_arr[6]; //xoopsmodule
    var $enfunction = $ajaxsetup_arr[7]; //enfunction  
    var  $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
    swal({
      title: $deletetext + $title,
      text: "這將會刪除這筆資料內容 This will delete this profile",
      type: "warning",
      showCancelButton: true,
      closeOnConfirm: false,
      confirmButtonText: "Delete 刪除",
      cancelButtonText: "Cancel 取消！",
      confirmButtonColor: "#ec6c62"
    }, function(isConfirm) {
      if (isConfirm) {
        $.ajax({
          url: xoopsjsurl + '/modules/neillibrary/ajax.php',
          type: 'POST',
          data: {
            id: $id,
            dbid: $dbid,
            pageid: $pageid,
            xoopsmodule: $xoopsmodule,
            enfunction: $enfunction
          },
        }).done(function(data) {
          if (data != false) {
            swal(data, "success");
          } else {
            swal("操作成功!", "已成功刪除資料！", "success");
            getMyArtic();
          }
        }).error(function(data) {
          swal("OMG", "刪除操作失敗了！", "error");
        });
      } else {
        swal("取消！", "你的資料是安全的:)", "error");
      }

      function getMyArtic() {
        $(this).click(function() {
          //	 location.reload()
          window.location.href = xoopsjsurl + $url;
        });
      }
    });
  });
});
//單頁刪除-新
function singlepagedeletefunction($btn,$modulesid) {	
  $btn=(typeof($btn) == 'undefined') ? "#deletebtn" : $btn;
  $modulesid=((typeof($modulesid) == 'undefined') || $modulesid=="")  ? "neillibrary" : $modulesid;
  $($btn).click(function() {
    $ajaxsetup = $(this).attr("name");
    if ($ajaxsetup != undefined) {
      var $ajaxsetup_arr = $ajaxsetup.split(','); //切割陣列
    }
    var $id = $ajaxsetup_arr[0]; //ajax-ID
    var $dbid = $ajaxsetup_arr[1]; //db刪除欄位參數
    var $title = $ajaxsetup_arr[2] + $ajaxsetup_arr[3]; //刪除標題+說名文  
    var $url = $ajaxsetup_arr[4]; //刪除後返回網址
    var $pageid = $ajaxsetup_arr[5]; //自訂變數
    var $xoopsmodule = $ajaxsetup_arr[6]; //xoopsmodule
    var $enfunction = $ajaxsetup_arr[7]; //enfunction  
    var $var1 = $ajaxsetup_arr[8]; //keyvar
    var $deletetext=(typeof(deletetext) == 'undefined') ? "您確定要刪除" : deletetext;
    swal({
      title: $deletetext + $title,
      text: "這將會刪除這筆資料內容 This will delete this profile",
      type: "warning",
      showCancelButton: true,
      closeOnConfirm: false,
      confirmButtonText: "Delete 刪除",
      cancelButtonText: "Cancel 取消！",
      confirmButtonColor: "#ec6c62"
    }, function(isConfirm) {
      if (isConfirm) {
        $.ajax({
          url: xoopsjsurl + '/modules/'+$modulesid+'/ajax.php',
          type: 'POST',
          data: {
            id: $id,
            dbid: $dbid,
            pageid: $pageid,
            xoopsmodule: $xoopsmodule,
            enfunction: $enfunction,
            var1: $var1
          },
        }).done(function(data) {
          if (data != false) {
            swal(data, "success");
          } else {
            swal("操作成功!", "已成功刪除資料！", "success");
            getMyArtic();
          }
        }).error(function(data) {
          swal("OMG", "刪除操作失敗了！", "error");
        });
      } else {
        swal("取消！", "你的資料是安全的:)", "error");
      }

      function getMyArtic() {
        $(this).click(function() {
          window.location.href = xoopsjsurl + $url;
        });
      }
    });
  });
}