(function(k){"use strict";var n={data:undefined,lang:"cn",multiple:false,pagination:true,dropButton:true,listSize:10,multipleControlbar:true,maxSelectLimit:0,selectToCloseList:false,initRecord:undefined,dbTable:"tbl",keyField:"id",showField:"name",thumbField:undefined,searchField:undefined,andOr:"AND",orderBy:false,pageSize:10,params:undefined,formatItem:undefined,autoFillResult:false,autoSelectFirst:false,noResultClean:true,selectOnly:false,inputDelay:.5,eSelect:undefined,eOpen:undefined,eAjaxSuccess:undefined,eAjaxMethod:undefined,defaultWidth:150,defaultZindex:1101,containerWidth:null,defaultAjaxResult:{list:[],pageSize:10,pageNumber:1,totalRow:0,totalPage:0},eTagRemove:undefined,eClear:undefined};var u=function(e,t){this.setOption(t);this.setLanguage();this.setCssClass();this.setProp();this.setElem(e);this.setButtonAttrDefault();this.setInitRecord();this.eDropdownButton();this.eInput();this.eWhole()};u.version="2.19";u.dataKey="selectPageObject";u.prototype.setOption=function(e){e.searchField=e.searchField||e.showField;e.andOr=e.andOr.toUpperCase();if(e.andOr!=="AND"&&e.andOr!=="OR")e.andOr="AND";var t=["searchField"];for(var i=0;i<t.length;i++){e[t[i]]=this.strToArray(e[t[i]])}if(e.orderBy!==false)e.orderBy=this.setOrderbyOption(e.orderBy,e.showField);if(e.multiple&&!e.selectToCloseList){e.autoFillResult=false;e.autoSelectFirst=false}if(!e.pagination)e.pageSize=200;if(k.type(e.listSize)!=="number"||e.listSize<0)e.listSize=10;this.option=e};u.prototype.strToArray=function(e){return e?e.replace(/[\s　]+/g,"").split(","):""};u.prototype.setOrderbyOption=function(e,t){var i=[],a=[];if(typeof e==="object"){for(var n=0;n<e.length;n++){a=k.trim(e[n]).split(" ");if(a.length)i.push(a.length===2?a.concat():[a[0],"ASC"])}}else{a=k.trim(e).split(" ");i[0]=a.length===2?a.concat():a[0].toUpperCase().match(/^(ASC|DESC)$/i)?[t,a[0].toUpperCase()]:[a[0],"ASC"]}return i};u.prototype.setLanguage=function(){var e,t=this.option;switch(t.lang){case"de":e={add_btn:"Hinzufügen-Button",add_title:"Box hinzufügen",del_btn:"Löschen-Button",del_title:"Box löschen",next:"Nächsten",next_title:"Nächsten"+t.pageSize+" (Pfeil-rechts)",prev:"Vorherigen",prev_title:"Vorherigen"+t.pageSize+" (Pfeil-links)",first_title:"Ersten (Umschalt + Pfeil-links)",last_title:"Letzten (Umschalt + Pfeil-rechts)",get_all_btn:"alle (Pfeil-runter)",get_all_alt:"(Button)",close_btn:"Schließen (Tab)",close_alt:"(Button)",loading:"lade...",loading_alt:"(lade)",page_info:"page_num von page_count",select_ng:"Achtung: Bitte wählen Sie aus der Liste aus.",select_ok:"OK : Richtig ausgewählt.",not_found:"nicht gefunden",ajax_error:"Bei der Verbindung zum Server ist ein Fehler aufgetreten.",clear:"Löschen Sie den Inhalt",select_all:"Wähle diese Seite",unselect_all:"Diese Seite entfernen",clear_all:"Alles löschen",max_selected:"Sie können nur bis zu max_selected_limit Elemente auswählen"};break;case"en":e={add_btn:"Add button",add_title:"add a box",del_btn:"Del button",del_title:"delete a box",next:"Next",next_title:"Next"+t.pageSize+" (Right key)",prev:"Prev",prev_title:"Prev"+t.pageSize+" (Left key)",first_title:"First (Shift + Left key)",last_title:"Last (Shift + Right key)",get_all_btn:"Get All (Down key)",get_all_alt:"(button)",close_btn:"Close (Tab key)",close_alt:"(button)",loading:"loading...",loading_alt:"(loading)",page_info:"Page page_num of page_count",select_ng:"Attention : Please choose from among the list.",select_ok:"OK : Correctly selected.",not_found:"not found",ajax_error:"An error occurred while connecting to server.",clear:"Clear content",select_all:"Select current page",unselect_all:"Clear current page",clear_all:"Clear all selected",max_selected:"You can only select up to max_selected_limit items"};break;case"es":e={add_btn:"Agregar boton",add_title:"Agregar una opcion",del_btn:"Borrar boton",del_title:"Borrar una opcion",next:"Siguiente",next_title:"Proximas "+t.pageSize+" (tecla derecha)",prev:"Anterior",prev_title:"Anteriores "+t.pageSize+" (tecla izquierda)",first_title:"Primera (Shift + Left)",last_title:"Ultima (Shift + Right)",get_all_btn:"Ver todos (tecla abajo)",get_all_alt:"(boton)",close_btn:"Cerrar (tecla TAB)",close_alt:"(boton)",loading:"Cargando...",loading_alt:"(Cargando)",page_info:"page_num de page_count",select_ng:"Atencion: Elija una opcion de la lista.",select_ok:"OK: Correctamente seleccionado.",not_found:"no encuentre",ajax_error:"Un error ocurrió mientras conectando al servidor.",clear:"Borrar el contenido",select_all:"Elija esta página",unselect_all:"Borrar esta página",clear_all:"Borrar todo marcado",max_selected:"Solo puedes seleccionar hasta max_selected_limit elementos"};break;case"pt-br":e={add_btn:"Adicionar botão",add_title:"Adicionar uma caixa",del_btn:"Apagar botão",del_title:"Apagar uma caixa",next:"Próxima",next_title:"Próxima "+t.pageSize+" (tecla direita)",prev:"Anterior",prev_title:"Anterior "+t.pageSize+" (tecla esquerda)",first_title:"Primeira (Shift + Left)",last_title:"Última (Shift + Right)",get_all_btn:"Ver todos (Seta para baixo)",get_all_alt:"(botão)",close_btn:"Fechar (tecla TAB)",close_alt:"(botão)",loading:"Carregando...",loading_alt:"(Carregando)",page_info:"page_num de page_count",select_ng:"Atenção: Escolha uma opção da lista.",select_ok:"OK: Selecionado Corretamente.",not_found:"não encontrado",ajax_error:"Um erro aconteceu enquanto conectando a servidor.",clear:"Limpe o conteúdo",select_all:"Selecione a página atual",unselect_all:"Remova a página atual",clear_all:"Limpar tudo",max_selected:"Você só pode selecionar até max_selected_limit itens"};break;case"ja":e={add_btn:"追加ボタン",add_title:"入力ボックスを追加します",del_btn:"削除ボタン",del_title:"入力ボックスを削除します",next:"次へ",next_title:"次の"+t.pageSize+"件 (右キー)",prev:"前へ",prev_title:"前の"+t.pageSize+"件 (左キー)",first_title:"最初のページへ (Shift + 左キー)",last_title:"最後のページへ (Shift + 右キー)",get_all_btn:"全件取得 (下キー)",get_all_alt:"画像:ボタン",close_btn:"閉じる (Tabキー)",close_alt:"画像:ボタン",loading:"読み込み中...",loading_alt:"画像:読み込み中...",page_info:"page_num 件 (全 page_count 件)",select_ng:"注意 : リストの中から選択してください",select_ok:"OK : 正しく選択されました。",not_found:"(0 件)",ajax_error:"サーバとの通信でエラーが発生しました。",clear:"コンテンツをクリアする",select_all:"当ページを選びます",unselect_all:"移して当ページを割ります",clear_all:"選択した項目をクリアする",max_selected:"最多で max_selected_limit のプロジェクトを選ぶことしかできません"};break;case"cn":default:e={add_btn:"添加按钮",add_title:"添加区域",del_btn:"删除按钮",del_title:"删除区域",next:"下一页",next_title:"下"+t.pageSize+" (→)",prev:"上一页",prev_title:"上"+t.pageSize+" (←)",first_title:"首页 (Shift + ←)",last_title:"尾页 (Shift + →)",get_all_btn:"获得全部 (↓)",get_all_alt:"(按钮)",close_btn:"关闭 (Tab键)",close_alt:"(按钮)",loading:"读取中...",loading_alt:"(读取中)",page_info:"第 page_num 页(共page_count页)",select_ng:"请注意：请从列表中选择.",select_ok:"OK : 已经选择.",not_found:"无查询结果",ajax_error:"连接到服务器时发生错误！",clear:"清除内容",select_all:"选择当前页项目",unselect_all:"取消选择当前页项目",clear_all:"清除全部已选择项目",max_selected:"最多只能选择 max_selected_limit 个项目"};break}this.message=e};u.prototype.setCssClass=function(){var e={container:"sp_container",container_open:"sp_container_open",re_area:"sp_result_area",result_open:"sp_result_area_open",control_box:"sp_control_box",element_box:"sp_element_box",navi:"sp_navi",results:"sp_results",re_off:"sp_results_off",select:"sp_over",select_ok:"sp_select_ok",select_ng:"sp_select_ng",selected:"sp_selected",input_off:"sp_input_off",message_box:"sp_message_box",disabled:"sp_disabled",button:"sp_button",caret_open:"sp_caret_open",btn_on:"sp_btn_on",btn_out:"sp_btn_out",input:"sp_input",clear_btn:"sp_clear_btn",align_right:"sp_align_right"};this.css_class=e};u.prototype.setProp=function(){this.prop={disabled:false,current_page:1,max_page:1,is_loading:false,xhr:false,key_paging:false,key_select:false,prev_value:"",selected_text:"",last_input_time:undefined,init_set:false};this.template={tag:{content:'<li class="selected_tag" itemvalue="#item_value#">#item_text#<span class="tag_close"><i class="sp-iconfont if-close"></i></span></li>',textKey:"#item_text#",valueKey:"#item_value#"},page:{current:"page_num",total:"page_count"},msg:{maxSelectLimit:"max_selected_limit"}}};u.prototype.elementRealSize=function(e,t){var i={absolute:false,clone:false,includeMargin:false,display:"block"};var a=i,n=e.eq(0),l,o,s=[],r="",c;l=function(){c=n.parents().addBack().filter(":hidden");r+="visibility: hidden !important; display: "+a.display+" !important; ";if(a.absolute===true)r+="position: absolute !important;";c.each(function(){var e=k(this),t=e.attr("style");s.push(t);e.attr("style",t?t+";"+r:r)})};o=function(){c.each(function(e){var t=k(this),i=s[e];if(i===undefined)t.removeAttr("style");else t.attr("style",i)})};l();var p=/(outer)/.test(t)?n[t](a.includeMargin):n[t]();o();return p};u.prototype.setElem=function(e){var t={},i=this.option,a=this.css_class,n=this.message,l=k(e);var o=l.outerWidth();if(o<=0)o=this.elementRealSize(l,"outerWidth");if(o<150)o=i.defaultWidth||150;t.combo_input=l.attr({autocomplete:"off"}).addClass(a.input).wrap("<div>");if(i.selectOnly)t.combo_input.prop("readonly",true);t.container=t.combo_input.parent().addClass(a.container);if(t.combo_input.prop("disabled")){if(i.multiple)t.container.addClass(a.disabled);else t.combo_input.addClass(a.input_off)}if(!i.containerWidth){t.container.width(o)}else{t.container.css("width",i.containerWidth)}t.button=k("<div>").addClass(a.button);t.dropdown=k('<span class="sp_caret"></span>');t.clear_btn=k("<div>").html(k("<i>").addClass("sp-iconfont if-close")).addClass(a.clear_btn).attr("title",n.clear);if(!i.dropButton)t.clear_btn.addClass(a.align_right);t.element_box=k("<ul>").addClass(a.element_box);if(i.multiple&&i.multipleControlbar)t.control=k("<div>").addClass(a.control_box);t.result_area=k("<div>").addClass(a.re_area);if(i.pagination)t.navi=k("<div>").addClass("sp_pagination").append("<ul>");t.results=k("<ul>").addClass(a.results);var s="_text",r=t.combo_input.attr("id")||t.combo_input.attr("name"),c=t.combo_input.attr("name")||"selectPage",p=c,u=r;t.hidden=k('<input type="hidden" class="sp_hidden" />').attr({name:p,id:u}).val("");t.combo_input.attr({name:c+s,id:r+s});t.container.append(t.hidden);if(i.dropButton){t.container.append(t.button);t.button.append(t.dropdown)}k(document.body).append(t.result_area);t.result_area.append(t.results);if(i.pagination)t.result_area.append(t.navi);if(i.multiple){if(i.multipleControlbar){t.control.append('<button type="button" class="btn btn-default sp_clear_all" ><i class="sp-iconfont if-clear"></i></button>');t.control.append('<button type="button" class="btn btn-default sp_unselect_all" ><i class="sp-iconfont if-unselect-all"></i></button>');t.control.append('<button type="button" class="btn btn-default sp_select_all" ><i class="sp-iconfont if-select-all"></i></button>');t.control_text=k("<p>");t.control.append(t.control_text);t.result_area.prepend(t.control)}t.container.addClass("sp_container_combo");t.combo_input.addClass("sp_combo_input").before(t.element_box);var d=k("<li>").addClass("input_box");d.append(t.combo_input);t.element_box.append(d);if(t.combo_input.attr("placeholder"))t.combo_input.attr("placeholder_bak",t.combo_input.attr("placeholder"))}this.elem=t};u.prototype.setButtonAttrDefault=function(){if(this.option.dropButton)this.elem.button.attr("title",this.message.close_btn)};u.prototype.setInitRecord=function(e){var a=this,n=a.option,t=a.elem,i="";if(k.type(t.combo_input.data("init"))!="undefined")n.initRecord=String(t.combo_input.data("init"));if(!e&&!n.initRecord&&t.combo_input.val())n.initRecord=t.combo_input.val();t.combo_input.val("");if(!e)t.hidden.val(n.initRecord);i=e&&t.hidden.val()?t.hidden.val():n.initRecord;if(i){if(typeof n.data==="object"){var l=new Array;var o=i.split(",");k.each(o,function(e,t){for(var i=0;i<n.data.length;i++){if(n.data[i][n.keyField]==t){l.push(n.data[i]);break}}});if(!n.multiple&&l.length>1)l=[l[0]];a.afterInit(a,l)}else{var s=n.params,r={};var c={searchTable:n.dbTable,searchKey:n.keyField,searchValue:i};if(s&&k.isFunction(s)){var p=s.call(a);if(p&&k.isPlainObject(p)){r=k.extend({},c,p)}else r=c}else r=c;k.ajax({dataType:"json",type:n.eAjaxMethod||"POST",url:n.data,data:r,success:function(e){var t=null;if(n.eAjaxSuccess&&k.isFunction(n.eAjaxSuccess)){t=n.eAjaxSuccess(e)}if(!t)t=n.defaultAjaxResult;a.afterInit(a,t.list)},error:function(e,t,i){a.ajaxErrorNotify(a,i)}})}}};u.prototype.afterInit=function(a,e){if(!e||k.isArray(e)&&e.length===0)return;if(!k.isArray(e))e=[e];var n=a.option,t=a.css_class;var l=function(e){var t=e[n.showField];return t};if(n.multiple){a.prop.init_set=true;a.clearAll(a);k.each(e,function(e,t){var i={text:l(t),value:t[n.keyField]};if(!a.isAlreadySelected(a,i))a.addNewTag(a,t,i)});a.tagValuesSet(a);a.inputResize(a);a.prop.init_set=false}else{var i=e[0];var o=l(i);a.elem.combo_input.val(o);a.elem.hidden.val(i[n.keyField]);a.prop.prev_value=o;a.prop.selected_text=o;if(n.selectOnly){a.elem.combo_input.attr("title",a.message.select_ok).removeClass(t.select_ng).addClass(t.select_ok)}a.putClearButton()}};u.prototype.eDropdownButton=function(){var t=this;if(t.option.dropButton){t.elem.button.mouseup(function(e){e.stopPropagation();if(t.elem.result_area.is(":hidden")&&!t.elem.combo_input.prop("disabled")){t.elem.combo_input.focus()}else t.hideResults(t)})}};u.prototype.eInput=function(){var i=this,a=i.option,n=i.elem,e=i.message;var l=function(){i.prop.page_move=false;i.suggest(i);i.setCssFocusedInput(i)};var t=false;n.combo_input.on("compositionstart",function(e){t=true});n.combo_input.on("compositionend",function(e){t=false;i.processKey(i,e)});n.combo_input.on("paste",function(e){i.processKey(i,e)});n.combo_input.keyup(function(e){if(!t)i.processKey(i,e)}).keydown(function(e){if(!t)i.processControl(i,e)}).focus(function(e){if(n.result_area.is(":hidden")){e.stopPropagation();i.prop.first_show=true;l()}});n.container.on("click.SelectPage","div."+i.css_class.clear_btn,function(e){e.stopPropagation();if(!i.disabled(i)){i.clearAll(i,true);if(a.eClear&&k.isFunction(a.eClear))a.eClear(i);i.elem.combo_input.trigger("input")}});n.result_area.on("mousedown.SelectPage",function(e){e.stopPropagation()});if(a.multiple){if(a.multipleControlbar){n.control.find(".sp_select_all").on("click.SelectPage",function(e){i.selectAllLine(i)}).hover(function(){n.control_text.html(e.select_all)},function(){n.control_text.html("")});n.control.find(".sp_unselect_all").on("click.SelectPage",function(e){i.unSelectAllLine(i)}).hover(function(){n.control_text.html(e.unselect_all)},function(){n.control_text.html("")});n.control.find(".sp_clear_all").on("click.SelectPage",function(e){i.clearAll(i,true)}).hover(function(){n.control_text.html(e.clear_all)},function(){n.control_text.html("")})}n.element_box.on("click.SelectPage",function(e){var t=e.target||e.srcElement;if(k(t).is("ul"))n.combo_input.focus()});n.element_box.on("click.SelectPage","span.tag_close",function(){var e=k(this).closest("li"),t=e.data("dataObj");i.removeTag(i,e);l();if(a.eTagRemove&&k.isFunction(a.eTagRemove))a.eTagRemove([t])});i.inputResize(i)}};u.prototype.eWhole=function(){var e=this,a=e.css_class;var n=function(e){e.elem.combo_input.val("");if(!e.option.multiple)e.elem.hidden.val("");e.prop.selected_text=""};k(document.body).off("mousedown.selectPage").on("mousedown.selectPage",function(e){var t=e.target||e.srcElement;var i=k(t).closest("div."+a.container);k("div."+a.container+"."+a.container_open).each(function(){if(this==i[0])return;var e=k(this),t=e.find("input."+a.input).data(u.dataKey);if(!t.elem.combo_input.val()&&t.elem.hidden.val()&&!t.option.multiple){t.prop.current_page=1;n(t);t.hideResults(t);return true}if(t.elem.results.find("li").not("."+a.message_box).length){if(t.option.autoFillResult){if(t.elem.hidden.val())t.hideResults(t);else if(t.elem.results.find("li.sp_over").length){t.selectCurrentLine(t,true)}else if(t.option.autoSelectFirst){t.nextLine(t);t.selectCurrentLine(t,true)}else t.hideResults(t)}else t.hideResults(t)}else{if(t.option.noResultClean)n(t);else{if(!t.option.multiple)t.elem.hidden.val("")}t.hideResults(t)}})})};u.prototype.eResultList=function(){var t=this,i=this.css_class;t.elem.results.children("li").hover(function(){if(t.prop.key_select){t.prop.key_select=false;return}if(!k(this).hasClass(i.selected)&&!k(this).hasClass(i.message_box)){k(this).addClass(i.select);t.setCssFocusedResults(t)}},function(){k(this).removeClass(i.select)}).click(function(e){if(t.prop.key_select){t.prop.key_select=false;return}e.preventDefault();e.stopPropagation();if(!k(this).hasClass(i.selected))t.selectCurrentLine(t,false)})};u.prototype.eScroll=function(){var e=this,p=this.css_class;k(window).on("scroll.SelectPage",function(e){k("div."+p.container+"."+p.container_open).each(function(){var e=k(this),t=e.find("input."+p.input).data(u.dataKey),i=t.elem.result_area.offset(),a=k(window).scrollTop(),n=k(document).height(),l=k(window).height(),o=t.elem.result_area.outerHeight(),s=i.top+o,r=n>l,c=t.elem.result_area.hasClass("shadowDown");if(r){if(c){if(s>l+a)t.calcResultsSize(t)}else{if(i.top<a)t.calcResultsSize(t)}}})})};u.prototype.ePaging=function(){var t=this;if(!t.option.pagination)return;t.elem.navi.find("li.csFirstPage").off("click").on("click",function(e){e.preventDefault();t.firstPage(t)});t.elem.navi.find("li.csPreviousPage").off("click").on("click",function(e){e.preventDefault();t.prevPage(t)});t.elem.navi.find("li.csNextPage").off("click").on("click",function(e){e.preventDefault();t.nextPage(t)});t.elem.navi.find("li.csLastPage").off("click").on("click",function(e){e.preventDefault();t.lastPage(t)})};u.prototype.ajaxErrorNotify=function(e,t){e.showMessage(e.message.ajax_error)};u.prototype.showMessage=function(e,t){if(!t)return;var i='<li class="'+e.css_class.message_box+'"><i class="sp-iconfont if-warning"></i> '+t+"</li>";e.elem.results.empty().append(i).show();e.calcResultsSize(e);e.setOpenStatus(e,true);e.elem.control.hide();if(e.option.pagination)e.elem.navi.hide()};u.prototype.scrollWindow=function(e,t){var i=e.getCurrentLine(e),a=i&&!t?i.offset().top:e.elem.container.offset().top,n;e.prop.size_li=e.elem.results.children("li:first").outerHeight();n=e.prop.size_li;var l,o=k(window).height(),s=k(window).scrollTop(),r=s+o-n;if(i.length){if(a<s||n>o){l=a-s}else if(a>r){l=a-r}else return}else if(a<s)l=a-s;window.scrollBy(0,l)};u.prototype.setOpenStatus=function(e,t){var i=e.elem,a=e.css_class;if(t){i.container.addClass(a.container_open);i.result_area.addClass(a.result_open)}else{i.container.removeClass(a.container_open);i.result_area.removeClass(a.result_open)}};u.prototype.setCssFocusedInput=function(e){};u.prototype.setCssFocusedResults=function(e){};u.prototype.checkValue=function(e){var t=e.elem.combo_input.val();if(t!=e.prop.prev_value){e.prop.prev_value=t;e.prop.first_show=false;if(e.option.selectOnly)e.setButtonAttrDefault();if(!e.option.multiple&&!t){e.elem.combo_input.val("");e.elem.hidden.val("");e.elem.clear_btn.remove()}e.suggest(e)}};u.prototype.processKey=function(e,t){if(k.inArray(t.keyCode,[37,38,39,40,27,9,13])===-1){if(t.keyCode!=16)e.setCssFocusedInput(e);e.inputResize(e);if(k.type(e.option.data)==="string"){e.prop.last_input_time=t.timeStamp;setTimeout(function(){if(t.timeStamp-e.prop.last_input_time===0)e.checkValue(e)},e.option.inputDelay*1e3)}else{e.checkValue(e)}}};u.prototype.processControl=function(e,t){if(k.inArray(t.keyCode,[37,38,39,40,27,9])>-1&&e.elem.result_area.is(":visible")||k.inArray(t.keyCode,[13,9])>-1&&e.getCurrentLine(e)){t.preventDefault();t.stopPropagation();t.cancelBubble=true;t.returnValue=false;switch(t.keyCode){case 37:if(t.shiftKey)e.firstPage(e);else e.prevPage(e);break;case 38:e.prop.key_select=true;e.prevLine(e);break;case 39:if(t.shiftKey)e.lastPage(e);else e.nextPage(e);break;case 40:if(e.elem.results.children("li").length){e.prop.key_select=true;e.nextLine(e)}else e.suggest(e);break;case 9:e.prop.key_paging=true;e.selectCurrentLine(e,true);break;case 13:e.selectCurrentLine(e,true);break;case 27:e.prop.key_paging=true;e.hideResults(e);break}}};u.prototype.abortAjax=function(e){if(e.prop.xhr){e.prop.xhr.abort();e.prop.xhr=false}};u.prototype.suggest=function(e){var t,i=k.trim(e.elem.combo_input.val());if(e.option.multiple)t=i;else{if(i&&i===e.prop.selected_text)t="";else t=i}t=t.split(/[\s　]+/);if(e.option.eOpen&&k.isFunction(e.option.eOpen))e.option.eOpen.call(e);e.abortAjax(e);var a=e.prop.current_page||1;if(typeof e.option.data=="object")e.searchForJson(e,t,a);else e.searchForDb(e,t,a)};u.prototype.setLoading=function(e){if(e.elem.results.html()===""){e.setOpenStatus(e,true)}};u.prototype.searchForDb=function(n,l,o){var s=n.option;if(!s.eAjaxSuccess||!k.isFunction(s.eAjaxSuccess))n.hideResults(n);var e=s.params,t={},i=s.searchField;if(l.length&&l[0]&&l[0]!==n.prop.prev_value)o=1;var a={q_word:l,pageNumber:o,pageSize:s.pageSize,andOr:s.andOr,searchTable:s.dbTable};if(s.orderBy!==false)a.orderBy=s.orderBy;a[i]=l[0];if(e&&k.isFunction(e)){var r=e.call(n);if(r&&k.isPlainObject(r)){t=k.extend({},a,r)}else t=a}else t=a;n.prop.xhr=k.ajax({dataType:"json",url:s.data,type:s.eAjaxMethod||"POST",data:t,success:function(e){if(!e||!k.isPlainObject(e)){n.hideResults(n);n.ajaxErrorNotify(n,errorThrown);return}var t={},i={};try{t=s.eAjaxSuccess(e);if(!t)t=s.defaultAjaxResult;i.originalResult=t.list;i.cnt_whole=t.totalRow}catch(e){n.showMessage(n,n.message.ajax_error);return}i.candidate=[];i.keyField=[];if(typeof i.originalResult!="object"){n.prop.xhr=null;n.notFoundSearch(n);return}i.cnt_page=i.originalResult.length;for(var a=0;a<i.cnt_page;a++){if(i.originalResult[a]===undefined)break;if(s.keyField in i.originalResult[a]){i.keyField.push(i.originalResult[a][s.keyField])}if(s.showField in i.originalResult[a]){i.candidate.push({text:i.originalResult[a][s.showField],thumb:s.thumbField&&s.thumbField in i.originalResult[a]?i.originalResult[a][s.thumbField]:""})}}n.prepareResults(n,i,l,o)},error:function(e,t,i){if(t!="abort"){n.hideResults(n);n.ajaxErrorNotify(n,i)}},complete:function(){n.prop.xhr=null}})};u.prototype.searchForJson=function(e,t,i){var a=e.option,n=[],l=[],o=[],s={},r=0,c=[];do{l[r]=t[r].replace(/\W/g,"\\$&").toString();c[r]=new RegExp(l[r],"gi");r++}while(r<t.length);for(var r=0;r<a.data.length;r++){var p=false,u=a.data[r],d;for(var f=0;f<c.length;f++){d=u[a.searchField];if(d.match(c[f])){p=true;if(a.andOr=="OR")break}else{p=false;if(a.andOr=="AND")break}}if(p)n.push(u)}if(a.orderBy===false)o=n.concat();else{var _=new RegExp("^"+l[0]+"$","gi"),m=new RegExp("^"+l[0],"gi"),g=[],h=[],v=[];for(var r=0;r<n.length;r++){var b=a.orderBy[0][0];var y=String(n[r][b]);if(y.match(_)){g.push(n[r])}else if(y.match(m)){h.push(n[r])}else{v.push(n[r])}}if(a.orderBy[0][1].match(/^asc$/i)){g=e.sortAsc(e,g);h=e.sortAsc(e,h);v=e.sortAsc(e,v)}else{g=e.sortDesc(e,g);h=e.sortDesc(e,h);v=e.sortDesc(e,v)}o=o.concat(g).concat(h).concat(v)}s.cnt_whole=o.length;if(!e.prop.page_move){if(!a.multiple){var x=e.elem.hidden.val();if(k.type(x)!=="undefined"&&k.trim(x)!==""){var C=0;k.each(o,function(e,t){if(t[a.keyField]==x){C=e+1;return false}});i=Math.ceil(C/a.pageSize);if(i<1)i=1;e.prop.current_page=i}}}else{if(o.length<=(i-1)*a.pageSize){i=1;e.prop.current_page=1}}var S=(i-1)*a.pageSize,w=S+a.pageSize;s.originalResult=[];for(var r=S;r<w;r++){if(o[r]===undefined)break;s.originalResult.push(o[r]);if(a.keyField in o[r]){if(s.keyField===undefined)s.keyField=[];s.keyField.push(o[r][a.keyField])}if(a.showField in o[r]){if(s.candidate===undefined)s.candidate=[];s.candidate.push({text:o[r][a.showField],thumb:a.thumbField&&a.thumbField in o[r]?o[r][a.thumbField]:""})}}if(s.candidate===undefined)s.candidate=[];s.cnt_page=s.candidate.length;e.prepareResults(e,s,t,i)};u.prototype.sortAsc=function(n,e){e.sort(function(e,t){var i=e[n.option.orderBy[0][0]],a=t[n.option.orderBy[0][0]];return k.type(i)==="number"?i-a:String(i).localeCompare(String(a))});return e};u.prototype.sortDesc=function(n,e){e.sort(function(e,t){var i=e[n.option.orderBy[0][0]],a=t[n.option.orderBy[0][0]];return k.type(i)==="number"?a-i:String(a).localeCompare(String(i))});return e};u.prototype.notFoundSearch=function(e){e.elem.results.empty();e.calcResultsSize(e);e.setOpenStatus(e,true);e.setCssFocusedInput(e)};u.prototype.prepareResults=function(e,t,i,a){if(e.option.pagination)e.setNavi(e,t.cnt_whole,t.cnt_page,a);if(!t.keyField)t.keyField=false;if(e.option.selectOnly&&t.candidate.length===1&&t.candidate[0].text==i[0]){e.elem.hidden.val(t.keyField[0]);this.setButtonAttrDefault()}var n=false;if(i&&i.length&&i[0])n=true;e.displayResults(e,t,n)};u.prototype.setNavi=function(e,t,i,a){var c=e.message;var n=function(t,e,i,a){var n=function(){var e=c.page_info;return e.replace(t.template.page.current,i).replace(t.template.page.total,a)};if(e.find("li").length===0){e.hide().empty();var l="sp-iconfont if-first",o="sp-iconfont if-previous",s="sp-iconfont if-next",r="sp-iconfont if-last";e.append('<li class="csFirstPage" title="'+c.first_title+'" ><a href="javascript:void(0);"> <i class="'+l+'"></i> </a></li>');e.append('<li class="csPreviousPage" title="'+c.prev_title+'" ><a href="javascript:void(0);"><i class="'+o+'"></i></a></li>');e.append('<li class="pageInfoBox"><a href="javascript:void(0);"> '+n()+" </a></li>");e.append('<li class="csNextPage" title="'+c.next_title+'" ><a href="javascript:void(0);"><i class="'+s+'"></i></a></li>');e.append('<li class="csLastPage" title="'+c.last_title+'" ><a href="javascript:void(0);"> <i class="'+r+'"></i> </a></li>');e.show()}else{e.find("li.pageInfoBox a").html(n())}};var l=e.elem.navi.find("ul"),o=Math.ceil(t/e.option.pageSize);if(o===0)a=0;else{if(o<a)a=o;else if(a===0)a=1}e.prop.current_page=a;e.prop.max_page=o;n(e,l,a,o);var s="disabled",r=l.find("li.csFirstPage"),p=l.find("li.csPreviousPage"),u=l.find("li.csNextPage"),d=l.find("li.csLastPage");if(a===1||a===0){if(!r.hasClass(s))r.addClass(s);if(!p.hasClass(s))p.addClass(s)}else{if(r.hasClass(s))r.removeClass(s);if(p.hasClass(s))p.removeClass(s)}if(a===o||o===0){if(!u.hasClass(s))u.addClass(s);if(!d.hasClass(s))d.addClass(s)}else{if(u.hasClass(s))u.removeClass(s);if(d.hasClass(s))d.removeClass(s)}if(o>1)e.ePaging()};u.prototype.displayResults=function(e,t,i){var a=e.option,n=e.elem;n.results.hide().empty();if(a.multiple&&k.type(a.maxSelectLimit)==="number"&&a.maxSelectLimit>0){var l=n.element_box.find("li.selected_tag").length;if(l>0&&l>=a.maxSelectLimit){var o=e.message.max_selected;e.showMessage(e,o.replace(e.template.msg.maxSelectLimit,a.maxSelectLimit));return}}if(t.candidate.length){var s=t.candidate,r=t.keyField,c=n.hidden.val(),p=c?c.split(","):new Array,u="",d="";for(var f=0;f<s.length;f++){if(a.formatItem&&k.isFunction(a.formatItem)){try{u=a.formatItem(t.originalResult[f])}catch(e){console.error("formatItem内容格式化函数内容设置不正确！");u=s[f].text;d=s[f].thumb}}else{u=s[f].text;d=s[f].thumb}var _='<span class="sp_item_text">'+u+"</span>";if(d)_='<img class="sp_item_thumb" src="'+d+'" />'+_;var m=k("<li>").html(_).attr({pkey:r[f]});if(!a.formatItem)m.attr("title",u);if(k.inArray(r[f].toString(),p)!==-1){m.addClass(e.css_class.selected)}m.data("dataObj",t.originalResult[f]);n.results.append(m);if(d){m.on("mouseover",function(){var e=k(this).children(".sp_item_thumb");var t=k('<div class="sp_item_thumb_lg"><img src="'+e.attr("src")+'" /></div>');k(this).prepend(t);var i=t.height()/2-e.height()/2;var a={left:-t.width(),top:e.position().top-i};var n=k(this).closest(".sp_result_area").position();var l=n.left;if(l<t.width()){var o=l;t.children("img").css({maxWidth:o});a.left=-t.width();i=t.height()/2-e.height()/2;a.top=e.position().top-i}t.css(a)}).on("mouseout",function(){k(this).children(".sp_item_thumb_lg").remove()})}}}else{var g='<li class="'+e.css_class.message_box+'"><i class="sp-iconfont if-warning"></i> '+e.message.not_found+"</li>";n.results.append(g)}n.results.show();if(a.multiple&&a.multipleControlbar)n.control.show();if(a.pagination)n.navi.show();e.calcResultsSize(e);e.setOpenStatus(e,true);e.eResultList();e.eScroll();if(i&&t.candidate.length&&a.autoSelectFirst)e.nextLine(e)};u.prototype.calcResultsSize=function(e){var g=e.option,h=e.elem;var t=function(){if(h.container.css("position")==="static"){var e=h.combo_input.offset();h.result_area.css({top:e.top+h.combo_input.outerHeight()+"px",left:e.left+"px",zIndex:g.defaultZindex})}else{if(!g.pagination){var t=h.results.find("li:first").outerHeight(true),i=t*g.listSize;h.results.css({"max-height":i,"overflow-y":"auto"})}var a=k(document).width(),n=k(document).height(),l=k(window).height(),e=h.container.offset(),o=k(window).scrollTop(),s=h.result_area.outerWidth(),i=h.result_area.outerHeight(),r=e.left,c=h.container.outerHeight(),p=e.left+s>a?r-(s-h.container.outerWidth()):r,u=e.top,d=0,f=5,_=u+c+i+f,m=n>l;if(u-o-f>i&&(m&&_>l+o)||!m&&_>l){d=e.top-i-f;h.result_area.removeClass("shadowUp shadowDown").addClass("shadowUp")}else{d=e.top+(g.multiple?h.container.outerHeight():c);h.result_area.removeClass("shadowUp shadowDown").addClass("shadowDown");d+=f}return{top:d+"px",left:p+"px",zIndex:g.defaultZindex}}};if(h.result_area.is(":visible")){h.result_area.css(t())}else{var i=t();h.result_area.css(i).show(1,function(){var e=t();if(i.top!==e.top||i.left!==e.left)h.result_area.css(e)})}};u.prototype.hideResults=function(e){if(e.prop.key_paging){e.scrollWindow(e,true);e.prop.key_paging=false}e.setCssFocusedInput(e);if(e.option.autoFillResult){}e.elem.results.empty();e.elem.result_area.hide();e.setOpenStatus(e,false);k(window).off("scroll.SelectPage");e.abortAjax(e);e.setButtonAttrDefault()};u.prototype.disabled=function(e,t){var i=e.option,a=e.elem;if(k.type(t)==="undefined")return a.combo_input.prop("disabled");if(k.type(t)==="boolean"){a.combo_input.prop("disabled",t);if(t)a.container.addClass(e.css_class.disabled);else a.container.removeClass(e.css_class.disabled)}};u.prototype.firstPage=function(e){if(e.prop.current_page>1){e.prop.current_page=1;e.prop.page_move=true;e.suggest(e)}};u.prototype.prevPage=function(e){if(e.prop.current_page>1){e.prop.current_page--;e.prop.page_move=true;e.suggest(e)}};u.prototype.nextPage=function(e){if(e.prop.current_page<e.prop.max_page){e.prop.current_page++;e.prop.page_move=true;e.suggest(e)}};u.prototype.lastPage=function(e){if(e.prop.current_page<e.prop.max_page){e.prop.current_page=e.prop.max_page;e.prop.page_move=true;e.suggest(e)}};u.prototype.afterAction=function(e,t){e.inputResize(e);e.elem.combo_input.change();e.setCssFocusedInput(e);if(e.prop.init_set)return;if(e.option.multiple){if(e.option.selectToCloseList){e.hideResults(e);e.elem.combo_input.blur()}if(!e.option.selectToCloseList&&t){e.suggest(e);e.elem.combo_input.focus()}}else{e.hideResults(e);e.elem.combo_input.blur()}};u.prototype.selectCurrentLine=function(e,t){e.scrollWindow(e,true);var i=e.option,a=e.getCurrentLine(e);if(a){var n=a.data("dataObj");if(!i.multiple){e.elem.combo_input.val(a.text());e.elem.hidden.val(a.attr("pkey"))}else{e.elem.combo_input.val("");var l={text:a.text(),value:a.attr("pkey")};if(!e.isAlreadySelected(e,l)){e.addNewTag(e,n,l);e.tagValuesSet(e)}}if(i.selectOnly)e.setButtonAttrDefault();if(i.eSelect&&k.isFunction(i.eSelect))i.eSelect(n,e);e.prop.prev_value=e.elem.combo_input.val();e.prop.selected_text=e.elem.combo_input.val();e.elem.combo_input.trigger("input");e.putClearButton()}e.afterAction(e,true)};u.prototype.putClearButton=function(){if(!this.option.multiple&&!this.elem.combo_input.prop("disabled"))this.elem.container.append(this.elem.clear_btn)};u.prototype.selectAllLine=function(l){var o=l.option,s=new Array;l.elem.results.find("li").each(function(e,t){var i=k(t),a=i.data("dataObj");var n={text:i.children("span.sp_item_text").text(),value:i.attr("pkey")};if(!l.isAlreadySelected(l,n)){l.addNewTag(l,a,n);l.tagValuesSet(l)}s.push(a);if(k.type(o.maxSelectLimit)==="number"&&o.maxSelectLimit>0&&o.maxSelectLimit===l.elem.element_box.find("li.selected_tag").length){return false}});if(o.eSelect&&k.isFunction(o.eSelect))o.eSelect(s,l);l.elem.combo_input.trigger("input");l.afterAction(l,true)};u.prototype.unSelectAllLine=function(n){var e=n.option,l=[];n.elem.results.find("li").each(function(e,t){var i=k(t).attr("pkey");var a=n.elem.element_box.find('li.selected_tag[itemvalue="'+i+'"]');if(a.length)l.push(a.data("dataObj"));n.removeTag(n,a)});n.afterAction(n,true);if(e.eTagRemove&&k.isFunction(e.eTagRemove))e.eTagRemove(l)};u.prototype.clearAll=function(e,t){var i=e.option,a=[];if(i.multiple){e.elem.element_box.find("li.selected_tag").each(function(e,t){a.push(k(t).data("dataObj"));t.remove()});e.elem.element_box.find("li.selected_tag").remove()}e.reset(e);e.afterAction(e,t);if(i.multiple){if(i.eTagRemove&&k.isFunction(i.eTagRemove))i.eTagRemove(a)}else e.elem.clear_btn.remove()};u.prototype.reset=function(e){e.elem.combo_input.val("");e.elem.hidden.val("");e.prop.prev_value="";e.prop.selected_text="";e.prop.current_page=1};u.prototype.getCurrentLine=function(e){if(e.elem.result_area.is(":hidden"))return false;var t=e.elem.results.find("li."+e.css_class.select);if(t.length)return t;else return false};u.prototype.isAlreadySelected=function(e,t){var i=false;if(t.value){var a=e.elem.hidden.val();if(a){var n=a.split(",");if(n&&n.length&&k.inArray(t.value,n)!=-1)i=true}}return i};u.prototype.addNewTag=function(t,e,i){if(!t.option.multiple||!e||!i)return;var a=t.template.tag.content,n,l=i.text,o=t.option;if(o.formatItem&&k.isFunction(o.formatItem))l=o.formatItem(e);var s='<span class="sp_item_text">'+l+"</span>";if(o.thumbField&&o.thumbField in e)s='<img class="sp_item_thumb" src="'+e[o.thumbField]+'" />'+s;a=a.replace(t.template.tag.textKey,s);a=a.replace(t.template.tag.valueKey,i.value);n=k(a);n.prop("draggable",true);n.data("dataObj",e);n.children("*").prop("draggable",false);if(t.elem.combo_input.prop("disabled"))n.find("span.tag_close").hide();t.elem.combo_input.closest("li").before(n);if(!t.elem.element_box.data("inited")){t.elem.element_box.data("inited",true);r(t.elem.element_box[0],function(e){t.tagValuesSet(t)})}n.children(".sp_item_thumb").on("mouseover",function(){var e=k(this);var t=k('<div class="sp_item_thumb_lg"><img src="'+e.attr("src")+'" /></div>');k(this).before(t);var i=k(this).position().left-t.width()-e.width()/2;var a=e.position().top-(t.height()/2-e.height()/2);var n=k(this).closest(".sp_container_combo").offset();var l=n.left+k(this).position().left-e.width()/2;if(l<t.width()){var o=l;t.children("img").css({maxWidth:o});i=k(this).position().left-t.width()-e.width()/2;a=e.position().top-(t.height()/2-e.height()/2)}var s={left:i,top:a};t.css(s)}).on("mouseout",function(){k(this).prev(".sp_item_thumb_lg").remove()})};u.prototype.draggable=r;function r(e,t){var n=null;e.ondragstart=function(e){n=e.target};e.ondragover=function(e){e.preventDefault();var t=e.target;if(t.nodeName==="LI"&&t!==n){var i=t.getBoundingClientRect();var a=n.getBoundingClientRect();if(t.animated)return;if(l(n)<l(t)){t.parentNode.insertBefore(n,t.nextSibling)}else{t.parentNode.insertBefore(n,t)}o(a,n);o(i,t)}};if(t)e.ondrop=t;function l(e){var t=0;if(!e||!e.parentNode){return-1}while(e&&(e=e.previousElementSibling)){t++}return t}function o(e,t){var i=300;if(!i)return;var a=t.getBoundingClientRect();if(e.nodeType===1)e=e.getBoundingClientRect();s(t,"transition","none");s(t,"transform","translate3d("+(e.left-a.left)+"px,"+(e.top-a.top)+"px,0)");t.offsetWidth;s(t,"transition","all "+i+"ms");s(t,"transform","translate3d(0,0,0)");clearTimeout(t.animated);t.animated=setTimeout(function(){s(t,"transition","");s(t,"transform","");t.animated=false},i)}function s(e,t,i){var a=e&&e.style;if(!a)return;if(i===void 0){if(document.defaultView&&document.defaultView.getComputedStyle){i=document.defaultView.getComputedStyle(e,"")}else if(e.currentStyle){i=e.currentStyle}return t===void 0?i:i[t]}if(!(t in a)){t="-webkit-"+t}a[t]=i+(typeof i==="string"?"":"px")}}u.prototype.removeTag=function(e,t){var i=k(t).attr("itemvalue");var a=e.elem.hidden.val();if(k.type(i)!="undefined"&&a){var n=a.split(","),l=k.inArray(i.toString(),n);if(l!=-1){n.splice(l,1);e.elem.hidden.val(n.toString())}}k(t).remove();e.inputResize(e)};u.prototype.tagValuesSet=function(e){if(!e.option.multiple)return;var t=e.elem.element_box.find("li.selected_tag");if(t&&t.length){var a=new Array;k.each(t,function(e,t){var i=k(t).attr("itemvalue");if(k.type(i)!=="undefined")a.push(i)});if(a.length){e.elem.hidden.val(a.join(","))}}};u.prototype.inputResize=function(e){if(!e.option.multiple)return;var t=e.elem.combo_input.closest("li");var i=function(e,t){t.removeClass("full_width");var i=e.elem.combo_input.val().length+1,a=i*.75+"em";e.elem.combo_input.css("width",a).removeAttr("placeholder")};if(e.elem.element_box.find("li.selected_tag").length===0){if(e.elem.combo_input.attr("placeholder_bak")){if(!t.hasClass("full_width"))t.addClass("full_width");e.elem.combo_input.attr("placeholder",e.elem.combo_input.attr("placeholder_bak")).removeAttr("style")}else i(e,t)}else i(e,t)};u.prototype.nextLine=function(e){var t=e.getCurrentLine(e),i;if(!t)i=-1;else{i=e.elem.results.children("li").index(t);t.removeClass(e.css_class.select)}i++;if(i<e.elem.results.children("li").length){var a=e.elem.results.children("li").eq(i);a.addClass(e.css_class.select);e.setCssFocusedResults(e)}else e.setCssFocusedInput(e);e.scrollWindow(e,false)};u.prototype.prevLine=function(e){var t=e.getCurrentLine(e),i;if(!t)i=e.elem.results.children("li").length;else{i=e.elem.results.children("li").index(t);t.removeClass(e.css_class.select)}i--;if(i>-1){var a=e.elem.results.children("li").eq(i);a.addClass(e.css_class.select);e.setCssFocusedResults(e)}else e.setCssFocusedInput(e);e.scrollWindow(e,false)};function e(a){return this.each(function(){var e=k(this),t=e.data(u.dataKey),i=k.extend({},n,e.data(),t&&t.option,typeof a==="object"&&a);if(!t)e.data(u.dataKey,t=new u(this,i))})}function l(e){return k(e).closest("div.sp_container").find("input.sp_input")}function t(){return this.each(function(){var e=l(this),t=e.data(u.dataKey);if(t){t.prop.init_set=true;t.clearAll(t);t.prop.init_set=false}})}function i(){return this.each(function(){var e=l(this),t=e.data(u.dataKey);if(t&&t.elem.hidden.val())t.setInitRecord(true)})}function a(i){return this.each(function(){if(i&&k.isArray(i)){var e=l(this),t=e.data(u.dataKey);if(t){t.clearAll(t);t.option.data=i}}})}function o(i){var a=false;this.each(function(){var e=l(this),t=e.data(u.dataKey);if(t){if(k.type(i)!=="undefined")t.disabled(t,i);else a=t.disabled(t)}});return a}function s(){var a="";this.each(function(){var e=l(this),t=e.data(u.dataKey);if(t){if(t.option.multiple){var i=[];t.elem.element_box.find("li.selected_tag").each(function(e,t){i.push(k(t).text())});a+=i.toString()}else{a+=t.elem.combo_input.val()}}});return a}var c=k.fn.selectPage;k.fn.selectPage=e;k.fn.selectPage.Constructor=u;k.fn.selectPageClear=t;k.fn.selectPageRefresh=i;k.fn.selectPageData=a;k.fn.selectPageDisabled=o;k.fn.selectPageText=s;k.fn.selectPage.noConflict=function(){k.fn.selectPage=c;return this}})(window.jQuery);