text: function bringToFront(n){const r=$(".ui-dialog");let t=null,i=0;for(let u=0;u<r.length;++u){const f=r[u];if(typeof f!="undefined"&&f!=null){const e=$(f),s=parseInt(e.css("z-index"));s>i&&(i=s);const o=e.attr("aria-describedby");typeof o!="undefined"&&o!=null&&o===n&&(t=e)}}t!=null&&t.css({"z-index":i+1})}function getRouteByName(n){if(typeof n=="undefined"||n==null||n.length===0||typeof routes=="undefined"||window.routes==null)return null;for(let t=0;t<window.routes.length;++t){const i=window.routes[t];if(i.name===n)return i}return null}function getWidthOfText(n,t,i){getWidthOfText.c===undefined&&(getWidthOfText.c=document.createElement("canvas"),getWidthOfText.ctx=getWidthOfText.c.getContext("2d"));var r=i+" "+t;return getWidthOfText.ctx.font!==r&&(getWidthOfText.ctx.font=r),getWidthOfText.ctx.measureText(n).width}function addJqueryExtensions(){$.fn.filterByData=function(n,t){return this.filter(function(){return $(this).data(n)==t})}}function hexToRgbA(n){n.charAt(0)!=="#"&&(n="#"+n);var t;if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(n))return t=n.substring(1).split(""),t.length===3&&(t=[t[0],t[0],t[1],t[1],t[2],t[2]]),t="0x"+t.join(""),{r:t>>16&255,g:t>>8&255,b:t&255,w:1023};throw new Error("Bad Hex");}function toggleAllLocomotiveInformation(n){const i=$("div.locomotiveInfo");let t;const r=i.length;for(t=0;t<r;++t)n===!0?$(i[t]).show():$(i[t]).hide()}function toggleAllLocomotiveInformationOpacity(n){const i=$("div.locomotiveInfo");let t;const r=i.length;for(t=0;t<r;++t)n===!0?$(i[t]).css({opacity:"1.0"}):$(i[t]).css({opacity:"0.2"})}function toggleAllLabelInformation(n){$.localStorage.setItem("labelShown",JSON.stringify({shown:n}));const i=$("div.elementLabel");let t;const r=i.length;for(t=0;t<r;++t)n===!0?$(i[t]).show():$(i[t]).hide()}function toggleAllWebcamsVisibility(n){$.localStorage.setItem("webcamShown",JSON.stringify({shown:n}));const i=$("div.videoStream");let t;const r=i.length;for(t=0;t<r;++t)n===!0?$(i[t]).show():$(i[t]).hide()}function getAccByEcosAddr(n,t){if(typeof n=="undefined"||n==null||typeof t=="undefined"||t==null)return null;const i=n.length;for(let r=0;r<i;++r){const f=$(n[r]),u=f.data(constDataThemeItemObject);if(u!=null){const i=u.addresses;if(typeof i!="undefined"&&i!=null){const e=(i.Addr1-1)*4+i.Port1,o=(i.Addr2-1)*4+i.Port2;if(t===e||t===o){const n=parseInt(i.Addr1)>0&&parseInt(i.Port1)>0,t=parseInt(i.Addr2)>0&&parseInt(i.Port2)>0;return{planItem:f,themeData:u,ecosAddresses:[{ecosAddr:e,ecosAddrValid:n,inverse:i.Inverse1},{ecosAddr:o,ecosAddrValid:t,inverse:i.Inverse2}]}}}}}return null}function getFbByEcosAddr(n,t){if(typeof n=="undefined"||n==null||typeof t=="undefined")return null;const i=n.length;for(let r=0;r<i;++r){const u=$(n[r]),i=u.data(constDataThemeItemObject);if(i!=null&&typeof i.addresses!="undefined"&&i.addresses!=null){const f=i.addresses.Addr;if(f===t)return{planItem:u,themeData:i,ecosAddr:{Addr:i.addresses.Addr}}}}return null}function getDirpathOf(n){const t=n.replace("\\","/").lastIndexOf("/");return n.substr(0,t+1)}function getLabelOffsetBy(n){const t=n.editor.themeId;switch(t){case 10:return null;case 11:return null;case 13:return null;case 14:return null;case 17:return null;case 18:return null;case 19:return null;case 1013:return null}return{"font-size":"8px","z-index":1e4,position:"relative",top:"-12px",left:"0px"}}function getArrayOfFunctions2(n,t,i,r){return getArrayOfFunctions({oid:n,noOfFunctions:t,funcset:i,funcdesc:r})}function getArrayOfFunctions(n){const t=[],u=n.oid,f=n.noOfFunctions,i=n.funcset,e=n.funcdesc;var r=0;for(let n=0;n<i.length;++n){const o=e[n];if(typeof o!="undefined"&&o!=null&&typeof o.idx!="undefined"&&o.idx!=null){const s=o.idx,h=o.type;if(h!==0){const c={oid:u,idx:s,state:parseInt(i[s])===1,type:h};if(t.push(c),r++,r>=f)break}}}return t}function loadLocomotiveImageIntoHtml(n,t,i="100%"){if(typeof window.__cachedLocomotiveImages[t]!="undefined"&&window.__cachedLocomotiveImages[t]!=null){const i=$("img#"+n);i.get(0).src=window.__cachedLocomotiveImages[t]}const r=new Image;(typeof i=="undefined"||i==null)&&(i="100%");r.onload=function(){const r=$("img#"+n);r.get(0).src=this.src;r.css({width:i});window.__cachedLocomotiveImages[t]=this.src};t=t.replace("/","_");t=t.replace(".","_");const u="./images/locomotives/"+t+".png";r.src=u}function getCtrlOfPosition(n,t,i){if(n==null||t==null||i==null)return null;let r;const u=i.length;for(r=0;r<u;++r){const u=i[r];if(u!=="undefined"&&u!==null){const f=u.offsetTop,e=u.offsetLeft,o=u.getBoundingClientRect(),s=o.width,h=o.height,c=e+s,l=f+h;if(n>=e&&n<=c&&t>=f&&t<=l)return $(u)}}return null}function getCtrlOfCoord(n,t,i){if(n==null||t==null||i==null)return null;let r;const u=i.length;for(r=0;r<u;++r){const u=$(i[r]);if(typeof u!="undefined"&&u!==null){const e=u.data(constDataThemeItemObject);if(typeof e!="undefined"&&e!=null){const f=e.coord;if(typeof f=="undefined"||f==null)return null;if(f.x===n&&f.y===t)return u}}}return null}function getCtrlOfEvent(n,t,i){return getCtrlOfPosition(t.pageX-n.get(0).offsetLeft,t.pageY-n.get(0).offsetTop,i)}function getElementCoord(n,t){const u=n.get(0),f=u.offsetTop,e=u.offsetLeft,o=t.pageX-e,s=t.pageY-f;var i=o/constItemWidth,r=s/constItemHeight;return i=Math.floor(i),r=Math.floor(r),i<0&&(i=0),r<0&&(r=0),{x:i,y:r}}function getElementStartCoord(n,t,i){const f=n.get(0).offsetLeft,e=n.get(0).offsetTop,o=t-f,s=i-e;var r=o/constItemWidth,u=s/constItemHeight;return r=Math.floor(r),u=Math.floor(u),r<0&&(r=0),u<0&&(u=0),{x:r,y:u}}function coord2pixel(n){if(n!=null)return{x:n.x*constItemWidth,y:n.y*constItemHeight}}function getThemeJsonData(n){return n==null?null:n.data(constDataThemeItemObject)}function getThemeJsonDataById(n){const t=$("div.ctrlItemFeedback");for(let i=0;i<t.length;++i){const r=t[i],u=$(r).attr("id");if(u===n)return getThemeJsonData($(r))}return null}function setThemeJsonDataById(n,t){const i=$("div.ctrlItemFeedback");for(let r=0;r<i.length;++r){const u=i[r],f=$(u).attr("id");if(f===n)return $(u).data(constDataThemeItemObject,t),!0}return!1}function getItemRenderedSize(n){const u={w:constItemWidth,h:constItemHeight},t=getThemeJsonData(n);if(t==null||typeof t.dimensions=="undefined")return u;var i=n.data(constDataThemeDimensionIndex);typeof i=="undefined"&&(i=0);const r=t.dimensions[i];return{w:constItemWidth*r.w,h:constItemHeight*r.h}}function isButton(n){return n===71?!0:n===72?!0:n===73?!0:!1}function isSignal(n){return n?n>=100&&n<=125?!0:!1:!1}function isSwitchOrAccessory(n){return n?n>=50&&n<150&&n!==54&&n!==55?!0:!1:!1}function isAccessory(n){return n?n>=250&&n<=260?!0:!1:!1}function isDecoupler(n){return n?n===70?!0:!1:!1}function isBlock(n){return n===150?!0:n===151?!0:n===152?!0:!1}function isFeedback(n){return n?n>=200&&n<=210?!0:!1:!1}function changeLocomotive(n,t={}){var i=window.serverHandling;typeof i!="undefined"&&i!=null&&(t.mode=n,i.sendCommand({command:"locomotive",timestamp:Date.now(),cmddata:t}))}function accessoryExecute(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"accessory",timestamp:Date.now(),cmddata:n})}function accessoryTest(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"accessory",timestamp:Date.now(),cmddata:n})}function itemClicked(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"accessory",timestamp:Date.now(),cmddata:n})}function assignLocomotiveToBlock(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"routing",timestamp:Date.now(),cmddata:n})}function resetAssignment(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"routing",timestamp:Date.now(),cmddata:n})}function gotoBlock(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"routing",timestamp:Date.now(),cmddata:n})}function checkRoute(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"routing",timestamp:Date.now(),cmddata:n})}function changeSetting(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"setting",timestamp:Date.now(),cmddata:n})}function relayWebsocketCommand(n){var t=window.serverHandling;typeof t!="undefined"&&t!=null&&t.sendCommand({command:"relayCommand",timestamp:Date.now(),cmddata:n})}function removeTextfieldFromGlobalList(n){var i,t,r;if(n!=null){for(i=-1,t=0;t<window.textfieldElementInstances.length;++t)if(r=window.textfieldElementInstances[t],r.__uniqueId===n){i=t;break}i!==-1&&window.textfieldElementInstances.splice(i,1)}}function removeLocomotiveDialogFromGlobalList(n){for(var r,i=[],t=0;t<window.locomotiveCtrlDlgs.length;++t){if(r=window.locomotiveCtrlDlgs[t],r==null){i.push(t);continue}try{r.__dlgId===n&&i.push(t)}catch(f){}}const u=i.reverse();for(t=0;t<u.length;++t)window.locomotiveCtrlDlgs.splice(u[t],1)}function openLocomotiveControlDialogByOid(n){const t=window.locomotivesDlg.getLocomotiveRecord(n);openLocomotiveControlDialog(t)}function openLocomotiveControlDialog(n){const t=new LocomotiveControl,i=t.open(n);if(i){window.locomotiveCtrlDlgs.push(t);t.on("dialogClosed",function(n){removeLocomotiveDialogFromGlobalList(n.data.instance.id)});t.on("functionChanged",function(n){changeLocomotive("function",n.data)});t.on("speedChanged",function(n){changeLocomotive("speedstep",n.data)});t.on("directionChanged",function(n){changeLocomotive("direction",n.data)})}else console.log("Already open!")}function scrollDebugToEnd(){const n=document.getElementsByClassName("messageContainer");$(n).scroll();$(n).animate({scrollTop:n[0].scrollHeight},"fast")}function initDebugConsole(){const t=$("#statusBar div.logging"),n=$(".debugConsole");n.find(".clearDebug").click(function(){$(".messageContainer").html("")});n.find(".scrollTop").click(function(){const n=document.getElementsByClassName("messageContainer");$(n).scroll();$(n).animate({scrollTop:0},"slow")});n.find(".scrollBottom").click(function(){scrollDebugToEnd()});t.click(function(){n.is(":visible")?n.hide():(n.css({bottom:$("#statusBar").height()+1+"px",right:$("#sidebar").width()+"px"}),(typeof __ctrlDebugConsoleInitialized=="undefined"||window.__ctrlDebugConsoleInitialized==null||window.__ctrlDebugConsoleInitialized===!1)&&(window.__ctrlDebugConsoleInitialized=!0,n.resizable({handles:"n, w",stop:function(){realignDebugConsole()}})),n.show(),scrollDebugToEnd())})}function changeWorkspace(){const n=$("#w2ui-popup table#workspaceSelection").find("select :selected").val();typeof n=="undefined"||n==null||n.length<=0||window.open("?workspace="+n,"_self")}function createWorkspace(n){for(let t=0;t<n.length;++t){const i=$(n[t]).val();if(typeof i!="undefined"&&i!=null&&i.length>0){window.open("?workspace="+i,"_self");return}}}function handleWorkspace(){const n=$("#workspaceSelectionFrame");n.w2popup({title:"Workspace Selection",height:"200px",width:"450px",buttons:'<button class="w2ui-btn" onclick="w2popup.close();">Close<\/button>',onOpen:function(n){n.onComplete=function(){}}})}function realignDebugConsole(){const n=$(".debugConsole");n.css({inset:"",bottom:$("#statusBar").height()+1+"px",right:$("#sidebar").width()+"px",position:"absolute"})}function __formatDebugMessage(n){return typeof n=="undefined"?null:n==null?null:'<span class="dt">'+n.time+'<\/span><span class="msg">'+n.message+"<\/span>"}function isBlank(n){return!n||/^\s*$/.test(n)}function addDebugMessages(n,t="messageContainer"){const r=document.getElementsByClassName(t),i=r[0];for(let t=0;t<n.length;++t){let f=i.innerHTML;const u=JSON.parse(n[t]);if(u.message.length!==0){const r=__formatDebugMessage(u);r!=null&&(i.innerHTML=i.innerHTML.length===0||isBlank(i.innerHTML)?r:f+"<br>"+r)}}i.scrollTop=i.scrollHeight}function initWebcamsState(){const n=$.localStorage.getItem("webcamShown");if(typeof n!="undefined"&&n!=null){const t=JSON.parse(n);toggleAllWebcamsVisibility(t.shown);const i=w2ui.sidebar,r=i.get("cmdToggleWebcams");toggleLabelOnOff(r,"Webcams",null,null,t.shown)}}function initLabelState(){const n=$.localStorage.getItem("labelShown");if(typeof n!="undefined"&&n!=null){const t=JSON.parse(n);window.labelShown=t.shown;toggleAllLabelInformation(t.shown);const i=w2ui.sidebar,r=i.get("cmdToggleLabels");toggleLabelOnOff(r,"Labels",null,null,t.shown)}}function reinitAutoMode(n){(typeof __autoModeState=="undefined"||window.__autoModeState==null)&&(window.__autoModeState=n);n===!0&&$("#statusBar div.autoMode").addClass("fa-spin")}function toggleLabelOnOff(n,t,i,r,u){if(typeof u!="undefined"&&u!=null)n.text=u===!0?t+" (on)":t+" (off)";else{const i=n.text,u=i.includes("off");u?(n.text=t+" (on)",typeof r!="undefined"&&r!=null&&r(!0)):(n.text=t+" (off)",typeof r!="undefined"&&r!=null&&r(!1))}w2ui.sidebar.refresh(i)}var w2popup,_htmlEntities,loadSideBar;(function(n){typeof define=="function"&&define.amd?define(["jquery"],n):n(jQuery)})(function(n){"use strict";var r=0,u='<div class="ui-colorpicker ui-colorpicker-dialog ui-dialog ui-widget ui-widget-content ui-corner-all" style="display: none;"><\/div>',f='<div class="ui-colorpicker ui-colorpicker-inline ui-dialog ui-widget ui-widget-content ui-corner-all"><\/div>',e='<div class="ui-colorpicker ui-colorpicker-inline"><\/div>',i=function(n){var t=Math.round(n).toString(16);return t.length===1&&(t="0"+t),t.toLowerCase()},t={isPrint:function(n){return n==32||n>=48&&n<=57||n>=65&&n<=90||n>=96&&n<=111||n>=186&&n<192||n>=219&&n<222},isHex:function(n){return n>=48&&n<=57||n>=96&&n<=105||n>=65&&n<=70}},o=function(t,i){var s,r,u,e,h,v,p,w,f,o,c,l,a,y;for(t.sort(function(n,t){return n.pos[1]===t.pos[1]?n.pos[0]-t.pos[0]:n.pos[1]-t.pos[1]}),e=0,h=0,n.each(t,function(n,t){e=Math.max(e,t.pos[0]+t.pos[2]);h=Math.max(h,t.pos[1]+t.pos[3])}),s=[],r=0;r<e;++r)s.push([]);for(p=[],v=[],n.each(t,function(n,t){for(r=0;r<t.pos[2];r+=1)v[t.pos[0]+r]=!0;for(u=0;u<t.pos[3];u+=1)p[t.pos[1]+u]=!0}),o="",f=t[w=0],u=0;u<h;++u){for(o+="<tr>",r=0;r<e;)if(typeof f!="undefined"&&r===f.pos[0]&&u===f.pos[1]){for(o+=i(f,r,u),l=0;l<f.pos[3];l+=1)for(c=0;c<f.pos[2];c+=1)s[r+c][u+l]=!0;r+=f.pos[2];f=t[++w]}else{for(a=0,y=!1;r<e&&s[r][u]===undefined&&(f===undefined||u<f.pos[1]||u===f.pos[1]&&r<f.pos[0]);)v[r]===!0&&(a+=1),y=!0,r+=1;a>0?o+='<td colspan="'+a+'"><\/td>':y||(r+=1)}o+="<\/tr>"}return'<table cellspacing="0" cellpadding="0" border="0"><tbody>'+o+"<\/tbody><\/table>"};return n.colorpicker=new function(){this.regional={"":{ok:"OK",cancel:"Cancel",none:"None",button:"Color",title:"Pick a color",transparent:"Transparent",hsvH:"H",hsvS:"S",hsvV:"V",rgbR:"R",rgbG:"G",rgbB:"B",labL:"L",labA:"a",labB:"b",hslH:"H",hslS:"S",hslL:"L",cmykC:"C",cmykM:"M",cmykY:"Y",cmykK:"K",alphaA:"A"}};this.swatchesNames={html:"HTML"};this.swatches={html:[{name:"black",r:0,g:0,b:0},{name:"dimgray",r:.41176470588235292,g:.41176470588235292,b:.41176470588235292},{name:"gray",r:.50196078431372548,g:.50196078431372548,b:.50196078431372548},{name:"darkgray",r:.66274509803921566,g:.66274509803921566,b:.66274509803921566},{name:"silver",r:.75294117647058822,g:.75294117647058822,b:.75294117647058822},{name:"lightgrey",r:.82745098039215681,g:.82745098039215681,b:.82745098039215681},{name:"gainsboro",r:.86274509803921573,g:.86274509803921573,b:.86274509803921573},{name:"whitesmoke",r:.96078431372549022,g:.96078431372549022,b:.96078431372549022},{name:"white",r:1,g:1,b:1},{name:"rosybrown",r:.73725490196078436,g:.5607843137254902,b:.5607843137254902},{name:"indianred",r:.803921568627451,g:.36078431372549019,b:.36078431372549019},{name:"brown",r:.6470588235294118,g:.16470588235294117,b:.16470588235294117},{name:"firebrick",r:.69803921568627447,g:.13333333333333333,b:.13333333333333333},{name:"lightcoral",r:.94117647058823528,g:.50196078431372548,b:.50196078431372548},{name:"maroon",r:.50196078431372548,g:0,b:0},{name:"darkred",r:.54509803921568623,g:0,b:0},{name:"red",r:1,g:0,b:0},{name:"snow",r:1,g:.98039215686274506,b:.98039215686274506},{name:"salmon",r:.98039215686274506,g:.50196078431372548,b:.44705882352941179},{name:"mistyrose",r:1,g:.89411764705882357,b:.88235294117647056},{name:"tomato",r:1,g:.38823529411764707,b:.27843137254901962},{name:"darksalmon",r:.9137254901960784,g:.58823529411764708,b:.47843137254901963},{name:"orangered",r:1,g:.27058823529411763,b:0},{name:"coral",r:1,g:.49803921568627452,b:.31372549019607843},{name:"lightsalmon",r:1,g:.62745098039215685,b:.47843137254901963},{name:"sienna",r:.62745098039215685,g:.32156862745098042,b:.17647058823529413},{name:"seashell",r:1,g:.96078431372549022,b:.93333333333333335},{name:"chocolate",r:.82352941176470584,g:.41176470588235292,b:.11764705882352941},{name:"saddlebrown",r:.54509803921568623,g:.27058823529411763,b:.074509803921568626},{name:"sandybrown",r:.95686274509803926,g:.64313725490196083,b:.37647058823529411},{name:"peachpuff",r:1,g:.85490196078431369,b:.72549019607843135},{name:"peru",r:.803921568627451,g:.52156862745098043,b:.24705882352941178},{name:"linen",r:.98039215686274506,g:.94117647058823528,b:.90196078431372551},{name:"darkorange",r:1,g:.5490196078431373,b:0},{name:"bisque",r:1,g:.89411764705882357,b:.7686274509803922},{name:"burlywood",r:.87058823529411766,g:.72156862745098038,b:.52941176470588236},{name:"tan",r:.82352941176470584,g:.70588235294117652,b:.5490196078431373},{name:"antiquewhite",r:.98039215686274506,g:.92156862745098034,b:.84313725490196079},{name:"navajowhite",r:1,g:.87058823529411766,b:.67843137254901964},{name:"blanchedalmond",r:1,g:.92156862745098034,b:.803921568627451},{name:"papayawhip",r:1,g:.93725490196078431,b:.83529411764705885},{name:"orange",r:1,g:.6470588235294118,b:0},{name:"moccasin",r:1,g:.89411764705882357,b:.70980392156862748},{name:"wheat",r:.96078431372549022,g:.87058823529411766,b:.70196078431372544},{name:"oldlace",r:.99215686274509807,g:.96078431372549022,b:.90196078431372551},{name:"floralwhite",r:1,g:.98039215686274506,b:.94117647058823528},{name:"goldenrod",r:.85490196078431369,g:.6470588235294118,b:.12549019607843137},{name:"darkgoldenrod",r:.72156862745098038,g:.52549019607843139,b:.043137254901960784},{name:"cornsilk",r:1,g:.97254901960784312,b:.86274509803921573},{name:"gold",r:1,g:.84313725490196079,b:0},{name:"palegoldenrod",r:.93333333333333335,g:.90980392156862744,b:.66666666666666663},{name:"khaki",r:.94117647058823528,g:.90196078431372551,b:.5490196078431373},{name:"lemonchiffon",r:1,g:.98039215686274506,b:.803921568627451},{name:"darkkhaki",r:.74117647058823533,g:.71764705882352942,b:.41960784313725491},{name:"beige",r:.96078431372549022,g:.96078431372549022,b:.86274509803921573},{name:"lightgoldenrodyellow",r:.98039215686274506,g:.98039215686274506,b:.82352941176470584},{name:"olive",r:.50196078431372548,g:.50196078431372548,b:0},{name:"yellow",r:1,g:1,b:0},{name:"lightyellow",r:1,g:1,b:.8784313725490196},{name:"ivory",r:1,g:1,b:.94117647058823528},{name:"olivedrab",r:.41960784313725491,g:.55686274509803924,b:.13725490196078433},{name:"yellowgreen",r:.60392156862745094,g:.803921568627451,b:.19607843137254902},{name:"darkolivegreen",r:.33333333333333331,g:.41960784313725491,b:.18431372549019609},{name:"greenyellow",r:.67843137254901964,g:1,b:.18431372549019609},{name:"lawngreen",r:.48627450980392156,g:.9882352941176471,b:0},{name:"chartreuse",r:.49803921568627452,g:1,b:0},{name:"darkseagreen",r:.5607843137254902,g:.73725490196078436,b:.5607843137254902},{name:"forestgreen",r:.13333333333333333,g:.54509803921568623,b:.13333333333333333},{name:"limegreen",r:.19607843137254902,g:.803921568627451,b:.19607843137254902},{name:"lightgreen",r:.56470588235294117,g:.93333333333333335,b:.56470588235294117},{name:"palegreen",r:.596078431372549,g:.984313725490196,b:.596078431372549},{name:"darkgreen",r:0,g:.39215686274509803,b:0},{name:"green",r:0,g:.50196078431372548,b:0},{name:"lime",r:0,g:1,b:0},{name:"honeydew",r:.94117647058823528,g:1,b:.94117647058823528},{name:"mediumseagreen",r:.23529411764705882,g:.70196078431372544,b:.44313725490196076},{name:"seagreen",r:.1803921568627451,g:.54509803921568623,b:.3411764705882353},{name:"springgreen",r:0,g:1,b:.49803921568627452},{name:"mintcream",r:.96078431372549022,g:1,b:.98039215686274506},{name:"mediumspringgreen",r:0,g:.98039215686274506,b:.60392156862745094},{name:"mediumaquamarine",r:.4,g:.803921568627451,b:.66666666666666663},{name:"aquamarine",r:.49803921568627452,g:1,b:.83137254901960789},{name:"turquoise",r:.25098039215686274,g:.8784313725490196,b:.81568627450980391},{name:"lightseagreen",r:.12549019607843137,g:.69803921568627447,b:.66666666666666663},{name:"mediumturquoise",r:.28235294117647058,g:.81960784313725488,b:.8},{name:"darkslategray",r:.18431372549019609,g:.30980392156862746,b:.30980392156862746},{name:"paleturquoise",r:.68627450980392157,g:.93333333333333335,b:.93333333333333335},{name:"teal",r:0,g:.50196078431372548,b:.50196078431372548},{name:"darkcyan",r:0,g:.54509803921568623,b:.54509803921568623},{name:"darkturquoise",r:0,g:.807843137254902,b:.81960784313725488},{name:"aqua",r:0,g:1,b:1},{name:"cyan",r:0,g:1,b:1},{name:"lightcyan",r:.8784313725490196,g:1,b:1},{name:"azure",r:.94117647058823528,g:1,b:1},{name:"cadetblue",r:.37254901960784315,g:.61960784313725492,b:.62745098039215685},{name:"powderblue",r:.69019607843137254,g:.8784313725490196,b:.90196078431372551},{name:"lightblue",r:.67843137254901964,g:.84705882352941175,b:.90196078431372551},{name:"deepskyblue",r:0,g:.74901960784313726,b:1},{name:"skyblue",r:.52941176470588236,g:.807843137254902,b:.92156862745098034},{name:"lightskyblue",r:.52941176470588236,g:.807843137254902,b:.98039215686274506},{name:"steelblue",r:.27450980392156865,g:.50980392156862742,b:.70588235294117652},{name:"aliceblue",r:.94117647058823528,g:.97254901960784312,b:1},{name:"dodgerblue",r:.11764705882352941,g:.56470588235294117,b:1},{name:"slategray",r:.4392156862745098,g:.50196078431372548,b:.56470588235294117},{name:"lightslategray",r:.46666666666666667,g:.53333333333333333,b:.6},{name:"lightsteelblue",r:.69019607843137254,g:.7686274509803922,b:.87058823529411766},{name:"cornflowerblue",r:.39215686274509803,g:.58431372549019611,b:.92941176470588238},{name:"royalblue",r:.25490196078431371,g:.41176470588235292,b:.88235294117647056},{name:"midnightblue",r:.098039215686274508,g:.098039215686274508,b:.4392156862745098},{name:"lavender",r:.90196078431372551,g:.90196078431372551,b:.98039215686274506},{name:"navy",r:0,g:0,b:.50196078431372548},{name:"darkblue",r:0,g:0,b:.54509803921568623},{name:"mediumblue",r:0,g:0,b:.803921568627451},{name:"blue",r:0,g:0,b:1},{name:"ghostwhite",r:.97254901960784312,g:.97254901960784312,b:1},{name:"darkslateblue",r:.28235294117647058,g:.23921568627450981,b:.54509803921568623},{name:"slateblue",r:.41568627450980394,g:.35294117647058826,b:.803921568627451},{name:"mediumslateblue",r:.4823529411764706,g:.40784313725490196,b:.93333333333333335},{name:"mediumpurple",r:.57647058823529407,g:.4392156862745098,b:.85882352941176465},{name:"blueviolet",r:.54117647058823526,g:.16862745098039217,b:.88627450980392153},{name:"indigo",r:.29411764705882354,g:0,b:.50980392156862742},{name:"darkorchid",r:.6,g:.19607843137254902,b:.8},{name:"darkviolet",r:.58039215686274515,g:0,b:.82745098039215681},{name:"mediumorchid",r:.72941176470588232,g:.33333333333333331,b:.82745098039215681},{name:"thistle",r:.84705882352941175,g:.74901960784313726,b:.84705882352941175},{name:"plum",r:.8666666666666667,g:.62745098039215685,b:.8666666666666667},{name:"violet",r:.93333333333333335,g:.50980392156862742,b:.93333333333333335},{name:"purple",r:.50196078431372548,g:0,b:.50196078431372548},{name:"darkmagenta",r:.54509803921568623,g:0,b:.54509803921568623},{name:"magenta",r:1,g:0,b:1},{name:"fuchsia",r:1,g:0,b:1},{name:"orchid",r:.85490196078431369,g:.4392156862745098,b:.83921568627450982},{name:"mediumvioletred",r:.7803921568627451,g:.082352941176470587,b:.52156862745098043},{name:"deeppink",r:1,g:.0784313725490196,b:.57647058823529407},{name:"hotpink",r:1,g:.41176470588235292,b:.70588235294117652},{name:"palevioletred",r:.85882352941176465,g:.4392156862745098,b:.57647058823529407},{name:"lavenderblush",r:1,g:.94117647058823528,b:.96078431372549022},{name:"crimson",r:.86274509803921573,g:.0784313725490196,b:.23529411764705882},{name:"pink",r:1,g:.75294117647058822,b:.796078431372549},{name:"lightpink",r:1,g:.71372549019607845,b:.75686274509803919}]};this.writers={"#HEX":function(n,t){return t._formatColor("#rxgxbx",n)},"#HEX3":function(t){var i=n.colorpicker.writers.HEX3(t);return i===!1?!1:"#"+i},HEX:function(n,t){return t._formatColor("rxgxbx",n)},HEX3:function(n){var t=n.getRGB(),i=Math.round(t.r*255),r=Math.round(t.g*255),u=Math.round(t.b*255);return i>>>4==(i&=15)&&r>>>4==(r&=15)&&u>>>4==(u&=15)?i.toString(16)+r.toString(16)+u.toString(16):!1},"#HEXA":function(n,t){return t._formatColor("#rxgxbxax",n)},"#HEXA4":function(t,i){var r=n.colorpicker.writers.HEXA4(t,i);return r===!1?!1:"#"+r},HEXA:function(n,t){return t._formatColor("rxgxbxax",n)},HEXA4:function(t,i){var r=Math.round(t.getAlpha()*255);return r>>>4==(r&=15)?n.colorpicker.writers.HEX3(t,i)+r.toString(16):!1},RGB:function(n,t){return n.getAlpha()>=1?t._formatColor("rgb(rd,gd,bd)",n):!1},RGBA:function(n,t){return t._formatColor("rgba(rd,gd,bd,af)",n)},"RGB%":function(n,t){return n.getAlpha()>=1?t._formatColor("rgb(rp%,gp%,bp%)",n):!1},"RGBA%":function(n,t){return t._formatColor("rgba(rp%,gp%,bp%,af)",n)},HSL:function(n,t){return n.getAlpha()>=1?t._formatColor("hsl(hd,sd,vd)",n):!1},HSLA:function(n,t){return t._formatColor("hsla(hd,sd,vd,af)",n)},"HSL%":function(n,t){return n.getAlpha()>=1?t._formatColor("hsl(hp%,sp%,vp%)",n):!1},"HSLA%":function(n,t){return t._formatColor("hsla(hp%,sp%,vp%,af)",n)},NAME:function(n,t){return t._closestName(n)},EXACT:function(n,t){return t._exactName(n)}};this.parsers={"":function(t){if(t==="")return new n.colorpicker.Color},NAME:function(t,i){var r=i._getSwatch(n.trim(t));if(r)return new n.colorpicker.Color(r.r,r.g,r.b)},RGBA:function(t){var i=/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(t);if(i)return new n.colorpicker.Color(i[1]/255,i[2]/255,i[3]/255,parseFloat(i[4]))},"RGBA%":function(t){var i=/^rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(t);if(i)return new n.colorpicker.Color(i[1]/100,i[2]/100,i[3]/100,i[4]/100)},HSLA:function(t){var i=/^hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(t);if(i)return(new n.colorpicker.Color).setHSL(i[1]/255,i[2]/255,i[3]/255).setAlpha(parseFloat(i[4]))},"HSLA%":function(t){var i=/^hsla?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)$/.exec(t);if(i)return(new n.colorpicker.Color).setHSL(i[1]/100,i[2]/100,i[3]/100).setAlpha(i[4]/100)},"#HEX":function(t){var i=/^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(i[1],16)/255,parseInt(i[2],16)/255,parseInt(i[3],16)/255)},"#HEX3":function(t){var i=/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(String(i[1])+i[1],16)/255,parseInt(String(i[2])+i[2],16)/255,parseInt(String(i[3])+i[3],16)/255)},HEX:function(t){var i=/^([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(i[1],16)/255,parseInt(i[2],16)/255,parseInt(i[3],16)/255)},HEX3:function(t){var i=/^([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(String(i[1])+i[1],16)/255,parseInt(String(i[2])+i[2],16)/255,parseInt(String(i[3])+i[3],16)/255)},"#HEXA":function(t){var i=/^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(i[1],16)/255,parseInt(i[2],16)/255,parseInt(i[3],16)/255,parseInt(i[4],16)/255)},"#HEXA4":function(t){var i=/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(String(i[1])+i[1],16)/255,parseInt(String(i[2])+i[2],16)/255,parseInt(String(i[3])+i[3],16)/255,parseInt(String(i[4])+i[4],16)/255)},HEXA:function(t){var i=/^([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(i[1],16)/255,parseInt(i[2],16)/255,parseInt(i[3],16)/255,parseInt(i[4],16)/255)},HEXA4:function(t){var i=/^([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/.exec(t);if(i)return new n.colorpicker.Color(parseInt(String(i[1])+i[1],16)/255,parseInt(String(i[2])+i[2],16)/255,parseInt(String(i[3])+i[3],16)/255,parseInt(String(i[4])+i[4],16)/255)}};this.partslists={full:["header","map","bar","hex","hsv","rgb","alpha","lab","cmyk","preview","swatches","footer"],popup:["map","bar","hex","hsv","rgb","alpha","preview","footer"],draggable:["header","map","bar","hex","hsv","rgb","alpha","preview","footer"],inline:["map","bar","hex","hsv","rgb","alpha","preview"]};this.limits={websafe:function(n){n.limit(6)},nibble:function(n){n.limit(16)},binary:function(n){n.limit(2)},name:function(n,t){var i=t._getSwatch(t._closestName(n));n.setRGB(i.r,i.g,i.b)}};this.parts={header:function(t){var f=this,i=null,u=function(){var i=t.options.title||t._getRegional("title"),n='<span class="ui-dialog-title">'+i+"<\/span>";return!t.inline&&t.options.showCloseButton&&(n+='<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"><span class="ui-icon ui-icon-closethick">close<\/span><\/a>'),'<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">'+n+"<\/div>"},r=function(n){n.preventDefault();t.close(t.options.revert)};this.init=function(){var f,e;i=n(u()).prependTo(t.dialog);f=n(".ui-dialog-titlebar-close",i);t._hoverable(f);t._focusable(f);f.on("click",r);!t.inline&&t.options.draggable&&(e={handle:i},t.options.containment&&(e.containment=t.options.containment),t.dialog.draggable(e))};this.disable=function(t){n(".ui-dialog-titlebar-close",i)[t?"off":"on"]("click",r)}},map:function(t){var e=this,u=null,l,r,f,i={},o,h,s,c,a;o=function(e){if(t.opened){var c=i.p.offset(),l=e.pageX-c.left,a=e.pageY-c.top;if(l>=0&&l<r&&a>=0&&a<f){e.stopImmediatePropagation();e.preventDefault();u.off("mousedown",o).focus();n(document).on("mouseup",h);n(document).on("mousemove",s);s(e)}}};h=function(i){i.stopImmediatePropagation();i.preventDefault();n(document).off("mouseup",h);n(document).off("mousemove",s);u.on("mousedown",o);t._callback("stop")};s=function(n){if(n.stopImmediatePropagation(),n.preventDefault(),n.pageX!==e.x||n.pageY!==e.y){e.x=n.pageX;e.y=n.pageY;var s=i.p.offset(),u=n.pageX-s.left,o=n.pageY-s.top;u=Math.max(0,Math.min(u/r,1));o=Math.max(0,Math.min(o/f,1));switch(t.mode){case"h":t.color.setHSV(null,u,1-o);break;case"s":case"a":t.color.setHSV(u,null,1-o);break;case"v":t.color.setHSV(u,1-o,null);break;case"r":t.color.setRGB(null,1-o,u);break;case"g":t.color.setRGB(1-o,null,u);break;case"b":t.color.setRGB(u,1-o,null)}t._change(!1)}};c=function(n){var e={h:"s",s:"h",v:"h",r:"b",g:"b",b:"r",a:"h"},h={37:-1,39:1},o={h:"v",s:"v",v:"s",r:"g",g:"r",b:"g",a:"v"},c={38:1,40:-1},s={35:0,36:1},i,u;typeof h[n.which]!="undefined"?(u=t.color.getChannel(e[t.mode])*r,i=h[n.which],n.shiftKey?i*=10:(n.ctrlKey||n.metaKey)&&(i*=r),t.color.setChannel(e[t.mode],(u+i)/r),t._change(!1)):typeof c[n.which]!="undefined"?(u=t.color.getChannel(o[t.mode])*f,i=c[n.which],n.shiftKey?i*=10:(n.ctrlKey||n.metaKey)&&(i*=f),t.color.setChannel(o[t.mode],(u+i)/f),t._change(!1)):typeof s[n.which]!="undefined"&&(t.color.setChannel(e[t.mode],1-s[n.which]),t.color.setChannel(o[t.mode],s[n.which]),t._change(!1))};a=function(){return'<div class="ui-colorpicker-map ui-colorpicker-map-'+(t.options.part.map.size||256)+' ui-colorpicker-border" taonex="0"><span class="ui-colorpicker-map-layer-1">&nbsp;<\/span><span class="ui-colorpicker-map-layer-2">&nbsp;<\/span>'+(t.options.alpha?'<span class="ui-colorpicker-map-layer-alpha">&nbsp;<\/span>':"")+'<span class="ui-colorpicker-map-layer-pointer"><span class="ui-colorpicker-map-pointer"><\/span><\/span><\/div>'};this.init=function(){u=n(a()).appendTo(n(".ui-colorpicker-map-container",t.dialog));u.on("mousedown",o);u.on("keydown",c);i[1]=n(".ui-colorpicker-map-layer-1",u);i[2]=n(".ui-colorpicker-map-layer-2",u);i.a=n(".ui-colorpicker-map-layer-alpha",u);i.p=n(".ui-colorpicker-map-layer-pointer",u);r=i.p.width();f=i.p.height();l=n(".ui-colorpicker-map-pointer",u)};this.update=function(){var n=(t.options.part.map.size||256)*65/64;switch(t.mode){case"h":i[1].css({"background-position":"0 0",opacity:""}).show();i[2].hide();break;case"s":case"a":i[1].css({"background-position":"0 "+-n+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*2+"px",opacity:""}).show();break;case"v":u.css("background-color","black");i[1].css({"background-position":"0 "+-n*3+"px",opacity:""}).show();i[2].hide();break;case"r":i[1].css({"background-position":"0 "+-n*4+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*5+"px",opacity:""}).show();break;case"g":i[1].css({"background-position":"0 "+-n*6+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*7+"px",opacity:""}).show();break;case"b":i[1].css({"background-position":"0 "+-n*8+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*9+"px",opacity:""}).show()}e.repaint()};this.repaint=function(){var e=0,o=0,f,n;switch(t.mode){case"h":f=t.color.getHSV();e=f.s*r;o=(1-f.v)*r;u.css("background-color",t.color.copy().setHSV(null,1,1).toCSS());break;case"s":case"a":f=t.color.getHSV();e=f.h*r;o=(1-f.v)*r;i[2].css("opacity",1-f.s);break;case"v":f=t.color.getHSV();e=f.h*r;o=(1-f.s)*r;i[1].css("opacity",f.v);break;case"r":n=t.color.getRGB();e=n.b*r;o=(1-n.g)*r;i[2].css("opacity",n.r);break;case"g":n=t.color.getRGB();e=n.b*r;o=(1-n.r)*r;i[2].css("opacity",n.g);break;case"b":n=t.color.getRGB();e=n.r*r;o=(1-n.g)*r;i[2].css("opacity",n.b)}t.options.alpha&&i.a.css("opacity",1-t.color.getAlpha());l.css({left:e-7,top:o-7})};this.disable=function(n){u[n?"off":"on"]("mousedown",o);u[n?"off":"on"]("keydown",c)}},bar:function(t){var o=this,r=null,c,l,u,i={},f,s,e,h,a;f=function(o){if(t.opened){var h=i.p.offset(),c=o.pageX-h.left,a=o.pageY-h.top;if(c>=0&&c<l&&a>=0&&a<u){o.stopImmediatePropagation();o.preventDefault();r.off("mousedown",f).focus();n(document).on("mouseup",s);n(document).on("mousemove",e);e(o)}}};s=function(i){i.stopImmediatePropagation();i.preventDefault();n(document).off("mouseup",s);n(document).off("mousemove",e);r.on("mousedown",f);t._callback("stop")};e=function(n){if(n.stopImmediatePropagation(),n.preventDefault(),n.pageY!==o.y){o.y=n.pageY;var f=i.p.offset(),r=n.pageY-f.top;r=Math.max(0,Math.min(r/u,1));switch(t.mode){case"h":t.color.setHSV(1-r,null,null);break;case"s":t.color.setHSV(null,1-r,null);break;case"v":t.color.setHSV(null,null,1-r);break;case"r":t.color.setRGB(1-r,null,null);break;case"g":t.color.setRGB(null,1-r,null);break;case"b":t.color.setRGB(null,null,1-r);break;case"a":t.color.setAlpha(1-r)}t._change(!1)}};h=function(n){var i={38:1,40:-1,33:10,34:-10},r={35:0,36:1},f;typeof i[n.which]!="undefined"?(f=t.color.getChannel(t.mode)*u,i=i[n.which],n.shiftKey?i*=10:(n.ctrlKey||n.metaKey)&&(i*=u),t.color.setChannel(t.mode,(f+i)/u),t._change(!1)):typeof r[n.which]!="undefined"&&(t.color.setChannel(t.mode,r[n.which]),t._change(!1))};a=function(){var n='<div class="ui-colorpicker-bar ui-colorpicker-bar-'+(t.options.part.bar.size||256)+'  ui-colorpicker-border" taonex="0"><span class="ui-colorpicker-bar-layer-1">&nbsp;<\/span><span class="ui-colorpicker-bar-layer-2">&nbsp;<\/span><span class="ui-colorpicker-bar-layer-3">&nbsp;<\/span><span class="ui-colorpicker-bar-layer-4">&nbsp;<\/span>';return t.options.alpha&&(n+='<span class="ui-colorpicker-bar-layer-alpha">&nbsp;<\/span><span class="ui-colorpicker-bar-layer-alphabar">&nbsp;<\/span>'),n+'<span class="ui-colorpicker-bar-layer-pointer"><span class="ui-colorpicker-bar-pointer"><\/span><\/span><\/div>'};this.init=function(){r=n(a()).appendTo(n(".ui-colorpicker-bar-container",t.dialog));r.on("mousedown",f);r.on("keydown",h);i[1]=n(".ui-colorpicker-bar-layer-1",r);i[2]=n(".ui-colorpicker-bar-layer-2",r);i[3]=n(".ui-colorpicker-bar-layer-3",r);i[4]=n(".ui-colorpicker-bar-layer-4",r);i.a=n(".ui-colorpicker-bar-layer-alpha",r);i.ab=n(".ui-colorpicker-bar-layer-alphabar",r);i.p=n(".ui-colorpicker-bar-layer-pointer",r);l=i.p.width();u=i.p.height();c=n(".ui-colorpicker-bar-pointer",r)};this.update=function(){var n=(t.options.part.bar.size||256)*65/64;switch(t.mode){case"h":case"s":case"v":case"r":case"g":case"b":i.a.show();i.ab.hide();break;case"a":i.a.hide();i.ab.show()}switch(t.mode){case"h":i[1].css({"background-position":"0 0",opacity:""}).show();i[2].hide();i[3].hide();i[4].hide();break;case"s":i[1].css({"background-position":"0 "+-n+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*2+"px",opacity:""}).show();i[3].hide();i[4].hide();break;case"v":i[1].css({"background-position":"0 "+-n*2+"px",opacity:""}).show();i[2].hide();i[3].hide();i[4].hide();break;case"r":i[1].css({"background-position":"0 "+-n*6+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*5+"px",opacity:""}).show();i[3].css({"background-position":"0 "+-n*3+"px",opacity:""}).show();i[4].css({"background-position":"0 "+-n*4+"px",opacity:""}).show();break;case"g":i[1].css({"background-position":"0 "+-n*10+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*9+"px",opacity:""}).show();i[3].css({"background-position":"0 "+-n*7+"px",opacity:""}).show();i[4].css({"background-position":"0 "+-n*8+"px",opacity:""}).show();break;case"b":i[1].css({"background-position":"0 "+-n*14+"px",opacity:""}).show();i[2].css({"background-position":"0 "+-n*13+"px",opacity:""}).show();i[3].css({"background-position":"0 "+-n*11+"px",opacity:""}).show();i[4].css({"background-position":"0 "+-n*12+"px",opacity:""}).show();break;case"a":i[1].hide();i[2].hide();i[3].hide();i[4].hide()}o.repaint()};this.repaint=function(){var f=0,e,n;switch(t.mode){case"h":f=(1-t.color.getHSV().h)*u;break;case"s":e=t.color.getHSV();f=(1-e.s)*u;i[2].css("opacity",1-e.v);r.css("background-color",t.color.copy().setHSV(null,1,null).toCSS());break;case"v":f=(1-t.color.getHSV().v)*u;r.css("background-color",t.color.copy().setHSV(null,null,1).toCSS());break;case"r":n=t.color.getRGB();f=(1-n.r)*u;i[2].css("opacity",Math.max(0,n.b-n.g));i[3].css("opacity",Math.max(0,n.g-n.b));i[4].css("opacity",Math.min(n.b,n.g));break;case"g":n=t.color.getRGB();f=(1-n.g)*u;i[2].css("opacity",Math.max(0,n.b-n.r));i[3].css("opacity",Math.max(0,n.r-n.b));i[4].css("opacity",Math.min(n.r,n.b));break;case"b":n=t.color.getRGB();f=(1-n.b)*u;i[2].css("opacity",Math.max(0,n.r-n.g));i[3].css("opacity",Math.max(0,n.g-n.r));i[4].css("opacity",Math.min(n.r,n.g));break;case"a":f=(1-t.color.getAlpha())*u;r.css("background-color",t.color.copy().toCSS())}t.mode!=="a"&&i.a.css("opacity",1-t.color.getAlpha());c.css("top",f-3)};this.disable=function(n){r[n?"off":"on"]("mousedown",f);r[n?"off":"on"]("keydown",h)}},preview:function(t){var c=this,i=null,r,u,f,e,o,s,h=function(){t.color=t.currentColor.copy();t._change()};s=function(){return'<div class="ui-colorpicker-preview ui-colorpicker-border"><div class="ui-colorpicker-preview-initial"><div class="ui-colorpicker-preview-initial-alpha"><\/div><\/div><div class="ui-colorpicker-preview-current"><div class="ui-colorpicker-preview-current-alpha"><\/div><\/div><\/div>'};this.init=function(){i=n(s()).appendTo(n(".ui-colorpicker-preview-container",t.dialog));n(".ui-colorpicker-preview-initial",i).on("click",h);u=n(".ui-colorpicker-preview-initial",i);f=n(".ui-colorpicker-preview-initial-alpha",i);e=n(".ui-colorpicker-preview-current",i);o=n(".ui-colorpicker-preview-current-alpha",i);r=n(".ui-colorpicker-preview-initial-alpha, .ui-colorpicker-preview-current-alpha",i)};this.update=function(){r[t.options.alpha?"show":"hide"]();this.repaint()};this.repaint=function(){u.css("background-color",t.currentColor.set?t.currentColor.toCSS():"").attr("title",t.currentColor.set?t.currentColor.toCSS():"");f.css("opacity",1-t.currentColor.getAlpha());e.css("background-color",t.color.set?t.color.toCSS():"").attr("title",t.color.set?t.color.toCSS():"");o.css("opacity",1-t.color.getAlpha())};this.disable=function(t){n(".ui-colorpicker-preview-initial",i)[t?"off":"on"]("click",h)}},hsv:function(t){var f=this,r=null,i={},u;u=function(){var n="";return t.options.hsv&&(n+='<div class="ui-colorpicker-hsv-h"><input class="ui-colorpicker-mode" type="radio" value="h"/><label>'+t._getRegional("hsvH")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="360" size="10"/><span class="ui-colorpicker-unit">&deg;<\/span><\/div><div class="ui-colorpicker-hsv-s"><input class="ui-colorpicker-mode" type="radio" value="s"/><label>'+t._getRegional("hsvS")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100" size="10"/><span class="ui-colorpicker-unit">%<\/span><\/div><div class="ui-colorpicker-hsv-v"><input class="ui-colorpicker-mode" type="radio" value="v"/><label>'+t._getRegional("hsvV")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100" size="10"/><span class="ui-colorpicker-unit">%<\/span><\/div>'),'<div class="ui-colorpicker-hsv">'+n+"<\/div>"};this.init=function(){r=n(u()).appendTo(n(".ui-colorpicker-hsv-container",t.dialog));n(".ui-colorpicker-mode",r).click(function(){t.mode=n(this).val();t._updateAllParts()});i.h=n(".ui-colorpicker-hsv-h .ui-colorpicker-number",r);i.s=n(".ui-colorpicker-hsv-s .ui-colorpicker-number",r);i.v=n(".ui-colorpicker-hsv-v .ui-colorpicker-number",r);n(".ui-colorpicker-number",r).on("input change keyup",function(){t.color.setHSV(i.h.val()/360,i.s.val()/100,i.v.val()/100);t._change()})};this.repaint=function(){var n=t.color.getHSV();i.h.val(Math.round(n.h*360));i.s.val(Math.round(n.s*100));i.v.val(Math.round(n.v*100))};this.update=function(){n(".ui-colorpicker-mode",r).each(function(){var i=n(this);i.prop("checked",i.val()===t.mode)});this.repaint()};this.disable=function(t){n(":input",r).prop("disabled",t)}},rgb:function(t){var f=this,i=null,r={},u;u=function(){var n="";return t.options.rgb&&(n+='<div class="ui-colorpicker-rgb-r"><input class="ui-colorpicker-mode" type="radio" value="r"/><label>'+t._getRegional("rgbR")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="255"/><\/div><div class="ui-colorpicker-rgb-g"><input class="ui-colorpicker-mode" type="radio" value="g"/><label>'+t._getRegional("rgbG")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="255"/><\/div><div class="ui-colorpicker-rgb-b"><input class="ui-colorpicker-mode" type="radio" value="b"/><label>'+t._getRegional("rgbB")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="255"/><\/div>'),'<div class="ui-colorpicker-rgb">'+n+"<\/div>"};this.init=function(){i=n(u()).appendTo(n(".ui-colorpicker-rgb-container",t.dialog));n(".ui-colorpicker-mode",i).click(function(){t.mode=n(this).val();t._updateAllParts()});r.r=n(".ui-colorpicker-rgb-r .ui-colorpicker-number",i);r.g=n(".ui-colorpicker-rgb-g .ui-colorpicker-number",i);r.b=n(".ui-colorpicker-rgb-b .ui-colorpicker-number",i);n(".ui-colorpicker-number",i).on("input change keyup",function(){var u=n(".ui-colorpicker-rgb-r .ui-colorpicker-number",i).val();t.color.setRGB(r.r.val()/255,r.g.val()/255,r.b.val()/255);t._change()})};this.repaint=function(){var n=t.color.getRGB();r.r.val(Math.round(n.r*255));r.g.val(Math.round(n.g*255));r.b.val(Math.round(n.b*255))};this.update=function(){n(".ui-colorpicker-mode",i).each(function(){var i=n(this);i.prop("checked",i.val()===t.mode)});this.repaint()};this.disable=function(t){n(":input",i).prop("disabled",t)}},lab:function(t){var f=this,r=null,i={},u=function(){var n="";return t.options.hsv&&(n+='<div class="ui-colorpicker-lab-l"><label>'+t._getRegional("labL")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><\/div><div class="ui-colorpicker-lab-a"><label>'+t._getRegional("labA")+'<\/label><input class="ui-colorpicker-number" type="number" min="-128" max="127"/><\/div><div class="ui-colorpicker-lab-b"><label>'+t._getRegional("labB")+'<\/label><input class="ui-colorpicker-number" type="number" min="-128" max="127"/><\/div>'),'<div class="ui-colorpicker-lab">'+n+"<\/div>"};this.init=function(){r=n(u()).appendTo(n(".ui-colorpicker-lab-container",t.dialog));i.l=n(".ui-colorpicker-lab-l .ui-colorpicker-number",r);i.a=n(".ui-colorpicker-lab-a .ui-colorpicker-number",r);i.b=n(".ui-colorpicker-lab-b .ui-colorpicker-number",r);n(".ui-colorpicker-number",r).on("input change keyup",function(){t.color.setLAB(parseInt(i.l.val(),10)/100,(parseInt(i.a.val(),10)+128)/255,(parseInt(i.b.val(),10)+128)/255);t._change()})};this.repaint=function(){var n=t.color.getLAB();i.l.val(Math.round(n.l*100));i.a.val(Math.round(n.a*255)-128);i.b.val(Math.round(n.b*255)-128)};this.update=this.repaint;this.disable=function(t){n(":input",r).prop("disabled",t)}},cmyk:function(t){var f=this,r=null,i={},u=function(){var n="";return t.options.hsv&&(n+='<div class="ui-colorpicker-cmyk-c"><label>'+t._getRegional("cmykC")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%<\/span><\/div><div class="ui-colorpicker-cmyk-m"><label>'+t._getRegional("cmykM")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%<\/span><\/div><div class="ui-colorpicker-cmyk-y"><label>'+t._getRegional("cmykY")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%<\/span><\/div><div class="ui-colorpicker-cmyk-k"><label>'+t._getRegional("cmykK")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%<\/span><\/div>'),'<div class="ui-colorpicker-cmyk">'+n+"<\/div>"};this.init=function(){r=n(u()).appendTo(n(".ui-colorpicker-cmyk-container",t.dialog));i.c=n(".ui-colorpicker-cmyk-c .ui-colorpicker-number",r);i.m=n(".ui-colorpicker-cmyk-m .ui-colorpicker-number",r);i.y=n(".ui-colorpicker-cmyk-y .ui-colorpicker-number",r);i.k=n(".ui-colorpicker-cmyk-k .ui-colorpicker-number",r);n(".ui-colorpicker-number",r).on("input change keyup",function(){t.color.setCMYK(parseInt(i.c.val(),10)/100,parseInt(i.m.val(),10)/100,parseInt(i.y.val(),10)/100,parseInt(i.k.val(),10)/100);t._change()})};this.repaint=function(){var n=t.color.getCMYK();i.c.val(Math.round(n.c*100));i.m.val(Math.round(n.m*100));i.y.val(Math.round(n.y*100));i.k.val(Math.round(n.k*100))};this.update=this.repaint;this.disable=function(t){n(":input",r).prop("disabled",t)}},alpha:function(t){var f=this,i=null,r,u=function(){var n="";return t.options.alpha&&(n+='<div class="ui-colorpicker-a"><input class="ui-colorpicker-mode" name="mode" type="radio" value="a"/><label>'+t._getRegional("alphaA")+'<\/label><input class="ui-colorpicker-number" type="number" min="0" max="100"/><span class="ui-colorpicker-unit">%<\/span><\/div>'),'<div class="ui-colorpicker-alpha">'+n+"<\/div>"};this.init=function(){i=n(u()).appendTo(n(".ui-colorpicker-alpha-container",t.dialog));n(".ui-colorpicker-mode",i).click(function(){t.mode=n(this).val();t._updateAllParts()});r=n(".ui-colorpicker-a .ui-colorpicker-number",i);n(".ui-colorpicker-number",i).on("input change keyup",function(){t.color.setAlpha(r.val()/100);t._change()})};this.update=function(){n(".ui-colorpicker-mode",i).each(function(){n(this).prop("checked",n(this).val()===t.mode)});this.repaint()};this.repaint=function(){r.val(Math.round(t.color.getAlpha()*100))};this.disable=function(t){n(":input",i).prop("disabled",t)}},hex:function(r){var s=this,f=null,u={},e=function(t){var i,r;return(r=/^#?([a-fA-F0-9]{1,3})$/.exec(t),r)?(i=parseInt(r[1],16),new n.colorpicker.Color((i>>8&15)/15,(i>>4&15)/15,(i&15)/15)):(r=/^#?([a-fA-F0-9]{1,6})$/.exec(t),r)?(i=parseInt(r[1],16),new n.colorpicker.Color((i>>16&255)/255,(i>>8&255)/255,(i&255)/255)):new n.colorpicker.Color},o=function(){var n="";return r.options.alpha&&(n+='<input class="ui-colorpicker-hex-alpha" type="text" maxlength="2" size="2"/>'),n+='<input class="ui-colorpicker-hex-input" type="text" maxlength="6" size="6"/>','<div class="ui-colorpicker-hex"><label>#<\/label>'+n+"<\/div>"};this.init=function(){f=n(o()).appendTo(n(".ui-colorpicker-hex-container",r.dialog));u.color=n(".ui-colorpicker-hex-input",f);u.alpha=n(".ui-colorpicker-hex-alpha",f);u.color.on("keydown keyup",function(n){return n.ctrlKey||n.metaKey||t.isHex(n.which)||!t.isPrint(n.which)});u.color.on("change",function(){/[^a-fA-F0-9]/.test(u.color.val())&&u.color.val(u.color.val().replace(/[^a-fA-F0-9]/g,""))});u.color.on("change keyup",function(){r.color=e(u.color.val()).setAlpha(r.color.getAlpha());r._change()});u.alpha.on("keydown keyup",function(n){return n.ctrlKey||n.metaKey||t.isHex(n.which)||!t.isPrint(n.which)});u.alpha.on("change",function(){/[^a-fA-F0-9]/.test(u.alpha)&&u.alpha.val(u.alpha.val().replace(/[^a-fA-F0-9]/g,""))});u.alpha.on("change keyup",function(){r.color.setAlpha(parseInt(u.alpha.val(),16)/255);r._change()})};this.repaint=function(){u.color.is(":focus")||u.color.val(r.color.toHex(!0));u.alpha.is(":focus")||u.alpha.val(i(r.color.getAlpha()*255))};this.update=this.repaint;this.disable=function(t){n(":input",f).prop("disabled",t)}},swatches:function(t){var f=this,i=null,u=function(){var i="";return t._eachSwatch(function(t,r){var u=new n.colorpicker.Color(r.r,r.g,r.b),f=u.toCSS();i+='<div class="ui-colorpicker-swatch" style="background-color:'+f+'" title="'+t+'"><\/div>'}),'<div class="ui-colorpicker-swatches ui-colorpicker-border" style="width:'+t.options.swatchesWidth+'px">'+i+"<\/div>"},r=function(){t.color=t._parseColor(n(this).css("background-color"))||new n.colorpicker.Color;t._change()};this.init=function(){i=n(u());n(".ui-colorpicker-swatches-container",t.dialog).html(i);n(".ui-colorpicker-swatch",i).on("click",r)};this.disable=function(t){n(".ui-colorpicker-swatch",i)[t?"off":"on"]("click",r)}},footer:function(t){var e=this,i=null,r="ui-colorpicker-special-transparent-"+t.colorpicker_index,u="ui-colorpicker-special-none-"+t.colorpicker_index,f=function(){var n="";return(t.options.alpha||!t.inline&&t.options.showNoneButton)&&(n+='<div class="ui-colorpicker-buttonset">',t.options.alpha&&(n+='<input type="radio" name="ui-colorpicker-special" id="'+r+'" class="ui-colorpicker-special-transparent"/><label for="'+r+'">'+t._getRegional("transparent")+"<\/label>"),!t.inline&&t.options.showNoneButton&&(n+='<input type="radio" name="ui-colorpicker-special" id="'+u+'" class="ui-colorpicker-special-none"><label for="'+u+'">'+t._getRegional("none")+"<\/label>"),n+="<\/div>"),t.inline||(n+='<div class="ui-dialog-buttonset">',t.options.showCancelButton&&(n+='<button class="ui-colorpicker-cancel">'+t._getRegional("cancel")+"<\/button>"),n+='<button class="ui-colorpicker-ok">'+t._getRegional("ok")+"<\/button>",n+="<\/div>"),'<div class="ui-dialog-buttonpane ui-widget-content">'+n+"<\/div>"};this.init=function(){i=n(f()).appendTo(t.dialog);n(".ui-colorpicker-ok",i).button().click(function(){t.close()});n(".ui-colorpicker-cancel",i).button().click(function(){t.close(!0)});n(".ui-colorpicker-buttonset",i)[n.fn.controlgroup?"controlgroup":"buttonset"]();n(".ui-colorpicker-special-color",i).click(function(){t._change()});n("#"+u,i).click(function(){t.color.set=!1;t._change()});n("#"+r,i).click(function(){t.color.setAlpha(0);t._change()})};this.repaint=function(){n(".ui-colorpicker-special-none",i).prop("checked",!t.color.set).button("refresh");n(".ui-colorpicker-special-transparent",i).prop("checked",t.color.set&&t.color.getAlpha()===0).button("refresh");n(".ui-colorpicker-ok",i).button(t.changed?"enable":"disable")};this.update=function(){};this.disable=function(r){n(":input, :button",i).button(r?"disable":"enable");r||n(".ui-colorpicker-ok",i).button(t.changed?"enable":"disable")}}};this.Color=function(){var t={rgb:{r:0,g:0,b:0},hsv:{h:0,s:0,v:0},hsl:{h:0,s:0,l:0},lab:{l:0,a:0,b:0},cmyk:{c:0,m:0,y:0,k:1}},a=1,u=[.9504285,1,1.0889],r=arguments,i=function(n){return isNaN(n)||n===null?0:(typeof n=="string"&&(n=parseInt(n,10)),Math.max(0,Math.min(n,1)))},l=function(n){var n=Math.round(n),t="0123456789abcdef",i=n%16,r=(n-i)/16;return t.charAt(r)+t.charAt(i)},f=function(n){var t=n.r>.04045?Math.pow((n.r+.055)/1.055,2.4):n.r/12.92,i=n.g>.04045?Math.pow((n.g+.055)/1.055,2.4):n.g/12.92,r=n.b>.04045?Math.pow((n.b+.055)/1.055,2.4):n.b/12.92;return{x:t*.4124+i*.3576+r*.1805,y:t*.2126+i*.7152+r*.0722,z:t*.0193+i*.1192+r*.9505}},v=function(n){var t={r:n.x*3.2406+n.y*-1.5372+n.z*-.4986,g:n.x*-.9689+n.y*1.8758+n.z*.0415,b:n.x*.0557+n.y*-.204+n.z*1.057};return t.r=t.r>.0031308?1.055*Math.pow(t.r,1/2.4)-.055:12.92*t.r,t.g=t.g>.0031308?1.055*Math.pow(t.g,1/2.4)-.055:12.92*t.g,t.b=t.b>.0031308?1.055*Math.pow(t.b,1/2.4)-.055:12.92*t.b,t},e=function(n){var o=Math.min(n.r,n.g,n.b),i=Math.max(n.r,n.g,n.b),r=i-o,u,f,e,t={h:0,s:0,v:i};return r===0?(t.h=0,t.s=0):(t.s=r/i,u=((i-n.r)/6+r/2)/r,f=((i-n.g)/6+r/2)/r,e=((i-n.b)/6+r/2)/r,n.r===i?t.h=e-f:n.g===i?t.h=1/3+u-e:n.b===i&&(t.h=2/3+f-u),t.h<0?t.h+=1:t.h>1&&(t.h-=1)),t},y=function(n){var t={r:0,g:0,b:0},u,i,r,f,e;return n.s===0?t.r=t.g=t.b=n.v:(u=n.h===1?0:n.h*6,i=Math.floor(u),r=n.v*(1-n.s),f=n.v*(1-n.s*(u-i)),e=n.v*(1-n.s*(1-(u-i))),i===0?(t.r=n.v,t.g=e,t.b=r):i===1?(t.r=f,t.g=n.v,t.b=r):i===2?(t.r=r,t.g=n.v,t.b=e):i===3?(t.r=r,t.g=f,t.b=n.v):i===4?(t.r=e,t.g=r,t.b=n.v):(t.r=n.v,t.g=r,t.b=f)),t},o=function(n){var u=Math.min(n.r,n.g,n.b),i=Math.max(n.r,n.g,n.b),r=i-u,f,e,o,t={h:0,s:0,l:(i+u)/2};return r===0?(t.h=0,t.s=0):(t.s=t.l<.5?r/(i+u):r/(2-i-u),f=((i-n.r)/6+r/2)/r,e=((i-n.g)/6+r/2)/r,o=((i-n.b)/6+r/2)/r,n.r===i?t.h=o-e:n.g===i?t.h=1/3+f-o:n.b===i&&(t.h=2/3+e-f),t.h<0?t.h+=1:t.h>1&&(t.h-=1)),t},p=function(n){var i,t,r=function(n,t,i){return(i<0&&(i+=1),i>1&&(i-=1),6*i<1)?n+(t-n)*6*i:2*i<1?t:3*i<2?n+(t-n)*(2/3-i)*6:n};return n.s===0?{r:n.l,g:n.l,b:n.l}:(t=n.l<.5?n.l*(1+n.s):n.l+n.s-n.s*n.l,i=2*n.l-t,{r:r(i,t,n.h+1/3),g:r(i,t,n.h),b:r(i,t,n.h-1/3)})},s=function(n){var i=n.x/u[0],t=n.y/u[1],r=n.z/u[2];return i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,t=t>.008856?Math.pow(t,1/3):7.787*t+16/116,r=r>.008856?Math.pow(r,1/3):7.787*r+16/116,{l:(116*t-16)/100,a:(500*(i-t)+128)/255,b:(200*(t-r)+128)/255}},w=function(n){var i={l:n.l*100,a:n.a*255-128,b:n.b*255-128},t={x:0,y:(i.l+16)/116,z:0};return t.x=i.a/500+t.y,t.z=t.y-i.b/200,t.x=Math.pow(t.x,3)>.008856?Math.pow(t.x,3):(t.x-16/116)/7.787,t.y=Math.pow(t.y,3)>.008856?Math.pow(t.y,3):(t.y-16/116)/7.787,t.z=Math.pow(t.z,3)>.008856?Math.pow(t.z,3):(t.z-16/116)/7.787,t.x*=u[0],t.y*=u[1],t.z*=u[2],t},h=function(n){return{c:1-n.r,m:1-n.g,y:1-n.b}},b=function(n){return{r:1-n.c,g:1-n.m,b:1-n.y}},c=function(n){var t=1;return(n.c<t&&(t=n.c),n.m<t&&(t=n.m),n.y<t&&(t=n.y),t===1)?{c:0,m:0,y:0,k:1}:{c:(n.c-t)/(1-t),m:(n.m-t)/(1-t),y:(n.y-t)/(1-t),k:t}},k=function(n){return{c:n.c*(1-n.k)+n.k,m:n.m*(1-n.k)+n.k,y:n.y*(1-n.k)+n.k}};this.set=!1;this.setAlpha=function(n){return n!==null&&(a=i(n)),this.set=!0,this};this.getAlpha=function(){return a};this.setRGB=function(n,r,u){return t={rgb:this.getRGB()},n!==null&&(t.rgb.r=i(n)),r!==null&&(t.rgb.g=i(r)),u!==null&&(t.rgb.b=i(u)),this.set=!0,this};this.getChannel=function(n){switch(n){case"h":case"s":case"v":return this.getHSV()[n];case"r":case"g":case"b":return this.getRGB()[n];case"a":return this.getAlpha()}return null};this.setChannel=function(n,t){switch(n){case"h":return this.setHSV(t,null,null);case"s":return this.setHSV(null,t,null);case"v":return this.setHSV(null,null,t);case"r":return this.setRGB(t,null,null);case"g":return this.setRGB(null,t,null);case"b":return this.setRGB(null,null,t);case"a":return this.setAlpha(t)}return this};this.setHSV=function(n,r,u){return t={hsv:this.getHSV()},n!==null&&(t.hsv.h=i(n)),r!==null&&(t.hsv.s=i(r)),u!==null&&(t.hsv.v=i(u)),this.set=!0,this};this.setHSL=function(n,r,u){return t={hsl:this.getHSL()},n!==null&&(t.hsl.h=i(n)),r!==null&&(t.hsl.s=i(r)),u!==null&&(t.hsl.l=i(u)),this.set=!0,this};this.setLAB=function(n,r,u){return t={lab:this.getLAB()},n!==null&&(t.lab.l=i(n)),r!==null&&(t.lab.a=i(r)),u!==null&&(t.lab.b=i(u)),this.set=!0,this};this.setCMYK=function(n,r,u,f){return t={cmyk:this.getCMYK()},n!==null&&(t.cmyk.c=i(n)),r!==null&&(t.cmyk.m=i(r)),u!==null&&(t.cmyk.y=i(u)),f!==null&&(t.cmyk.k=i(f)),this.set=!0,this};this.getRGB=function(){return t.rgb||(t.rgb=t.lab?v(w(t.lab)):t.hsv?y(t.hsv):t.hsl?p(t.hsl):t.cmyk?b(k(t.cmyk)):{r:0,g:0,b:0},t.rgb.r=i(t.rgb.r),t.rgb.g=i(t.rgb.g),t.rgb.b=i(t.rgb.b)),n.extend({},t.rgb)};this.getHSV=function(){return t.hsv||(t.hsv=t.lab?e(this.getRGB()):t.rgb?e(t.rgb):t.hsl?e(this.getRGB()):t.cmyk?e(this.getRGB()):{h:0,s:0,v:0},t.hsv.h=i(t.hsv.h),t.hsv.s=i(t.hsv.s),t.hsv.v=i(t.hsv.v)),n.extend({},t.hsv)};this.getHSL=function(){return t.hsl||(t.hsl=t.rgb?o(t.rgb):t.hsv?o(this.getRGB()):t.cmyk?o(this.getRGB()):t.hsv?o(this.getRGB()):{h:0,s:0,l:0},t.hsl.h=i(t.hsl.h),t.hsl.s=i(t.hsl.s),t.hsl.l=i(t.hsl.l)),n.extend({},t.hsl)};this.getCMYK=function(){return t.cmyk||(t.cmyk=t.rgb?c(h(t.rgb)):t.hsv?c(h(this.getRGB())):t.hsl?c(h(this.getRGB())):t.lab?c(h(this.getRGB())):{c:0,m:0,y:0,k:1},t.cmyk.c=i(t.cmyk.c),t.cmyk.m=i(t.cmyk.m),t.cmyk.y=i(t.cmyk.y),t.cmyk.k=i(t.cmyk.k)),n.extend({},t.cmyk)};this.getLAB=function(){return t.lab||(t.lab=t.rgb?s(f(t.rgb)):t.hsv?s(f(this.getRGB())):t.hsl?s(f(this.getRGB())):t.cmyk?s(f(this.getRGB())):{l:0,a:0,b:0},t.lab.l=i(t.lab.l),t.lab.a=i(t.lab.a),t.lab.b=i(t.lab.b)),n.extend({},t.lab)};this.getChannels=function(){return{r:this.getRGB().r,g:this.getRGB().g,b:this.getRGB().b,a:this.getAlpha(),h:this.getHSV().h,s:this.getHSV().s,v:this.getHSV().v,c:this.getCMYK().c,m:this.getCMYK().m,y:this.getCMYK().y,k:this.getCMYK().k,L:this.getLAB().l,A:this.getLAB().a,B:this.getLAB().b}};this.getSpaces=function(){return n.extend(!0,{},t)};this.distance=function(n){var t="get"+"lab".toUpperCase(),i=this[t](),f=n[t](),r=0;for(var u in i)r+=Math.pow(i[u]-f[u],2);return r};this.equals=function(n){if(n){var t=this.getRGB(),i=n.getRGB();return this.set===n.set&&this.getAlpha()===n.getAlpha()&&t.r===i.r&&t.g===i.g&&t.b===i.b}return!1};this.limit=function(n){n-=1;var t=this.getRGB();this.setRGB(Math.round(t.r*n)/n,Math.round(t.g*n)/n,Math.round(t.b*n)/n)};this.toHex=function(){var n=this.getRGB();return l(n.r*255)+l(n.g*255)+l(n.b*255)};this.toCSS=function(){return"#"+this.toHex()};this.copy=function(){var t=new n.colorpicker.Color(this.getSpaces(),this.getAlpha());return t.set=this.set,t};r.length===2&&(t=r[0],this.setAlpha(r[1]===0?0:r[1]||1),this.set=!0);r.length>2&&(this.setRGB(r[0],r[1],r[2]),this.setAlpha(r[3]===0?0:r[3]||1),this.set=!0)}},n.widget("vanderlee.colorpicker",{options:{alpha:!1,altAlpha:!0,altField:"",altOnChange:!0,altProperties:"background-color",autoOpen:!1,buttonClass:null,buttonColorize:!1,buttonImage:"libs/colorpicker-master/images/ui-colorpicker.png",buttonImageOnly:!1,buttonText:null,cancelOnExit:!1,closeOnEscape:!0,closeOnOutside:!0,color:"#00FF00",colorFormat:"HEX",disabled:!1,draggable:!0,containment:null,duration:"fast",hideOn:"button",hsv:!0,inline:!0,inlineFrame:!0,layout:{map:[0,0,1,5],bar:[1,0,1,5],preview:[2,0,1,1],hsv:[2,1,1,1],rgb:[2,2,1,1],alpha:[2,3,1,1],hex:[2,4,1,1],lab:[3,1,1,1],cmyk:[3,2,1,2],swatches:[4,0,1,5]},limit:"",modal:!1,mode:"h",okOnEnter:!1,parts:"",part:{map:{size:256},bar:{size:256}},position:null,regional:"",revert:!1,rgb:!0,showAnim:"fadeIn",showCancelButton:!0,showNoneButton:!1,showCloseButton:!0,showOn:"focus",showOptions:{},swatches:null,swatchesWidth:84,title:null,cancel:null,close:null,init:null,ok:null,open:null,select:null,stop:null,ready:null},_create:function(){var t=this,i;if(t.colorpicker_index=r++,t.widgetEventPrefix="colorpicker",t.opened=!1,t.generated=!1,t.inline=!1,t.changed=!1,t.dialog=null,t.button=null,t.image=null,t.overlay=null,t.events={window_resize:null,document_keydown:null,document_click_html:null},t.mode=t.options.mode,t.element.is("input")||t.options.inline===!1){if(t._setColor(t.element.is("input")?t.element.val():t.options.color),t._callback("init"),/\bfocus|all|both\b/.test(t.options.showOn))t.element.on("focus",function(){t.open()});if(/\bfocus|all|both\b/.test(t.options.hideOn))t.element.on("focusout",function(){t.close()});if(/\bclick|all|both\b/.test(t.options.showOn))t.element.on("click",function(){t.opened&&/\bclick|all|both\b/.test(t.options.hideOn)?t.close():t.open()});if(/\bbutton|all|both\b/.test(t.options.showOn)&&(t.options.buttonImage!==""&&(i=t.options.buttonText||t._getRegional("button"),t.image=n("<img/>").attr({src:t.options.buttonImage,alt:i,title:i}),t.options.buttonClass&&t.image.attr("class",t.options.buttonClass),t._setImageBackground()),t.options.buttonImageOnly&&t.image?t.button=t.image:(t.button=n('<button type="button"><\/button>').html(t.image||t.options.buttonText).button(),t.image=t.image?n("img",t.button).first():null),t.button.insertAfter(t.element).click(function(){t.options.disabled||(t.opened&&/\bbutton|all|both\b/.test(t.options.hideOn)?t.close():t.open())})),/\balt|all|both\b/.test(t.options.showOn))n(t.options.altField).on("click",function(){t.opened&&/\balt|all|both\b/.test(t.options.hideOn)?t.close():t.open()});t.options.autoOpen&&t.open()}else t.inline=!0,t._generate(),t.opened=!0;return(t.element.is(":disabled")||t.options.disabled)&&t.disable(),t._callback("ready"),this},_setOption:function(t,i){switch(t){case"disabled":this[i?"disable":"enable"]();break;case"swatches":this.options.swatches=i;this.parts.swatches.init()}n.Widget.prototype._setOption.apply(this,arguments)},enable:function(){this.element&&this.element.prop("disabled",!1);this.button&&this.button.prop("disabled",!1);this.dialog&&this.dialog.removeClass("ui-colorpicker-disabled");this.options.disabled=!1;this.parts&&n.each(this.parts,function(n,t){t.disable&&t.disable(!1)})},disable:function(){this.element&&this.element.prop("disabled",!0);this.button&&this.button.prop("disabled",!0);this.dialog&&this.dialog.addClass("ui-colorpicker-disabled");this.options.disabled=!0;this.parts&&n.each(this.parts,function(n,t){t.disable&&t.disable(!0)})},_setImageBackground:function(){this.image&&this.options.buttonColorize&&this.image.css("background-color",this.color.set?this._formatColor("RGBA",this.color):"")},_setAltField:function(){if(this.options.altOnChange&&this.options.altField&&this.options.altProperties){for(var i,r=this.options.altProperties.split(","),t=0;t<=r.length;++t){i=n.trim(r[t]);switch(i){case"color":case"fill":case"stroke":case"background-color":case"backgroundColor":case"outline-color":case"border-color":n(this.options.altField).css(i,this.color.set?this.color.toCSS():"")}}this.options.altAlpha&&n(this.options.altField).css("opacity",this.color.set?this.color.getAlpha():"")}},_setColor:function(t){this.color=this._parseColor(t)||new n.colorpicker.Color;this.currentColor=this.color.copy();this._setImageBackground();this._setAltField()},setColor:function(n){this._setColor(n);this._change()},getColor:function(n){return this._formatColor(n||this.options.colorFormat,this.color)},_generateInline:function(){var t=this;n(t.element).html(t.options.inlineFrame?f:e);t.dialog=n(".ui-colorpicker",t.element)},_generatePopup:function(){var t=this;if(t.dialog=n(u).appendTo("body"),t.events.document_click_html===null)n(document).on("touchstart click","html",t.events.document_click_html=function(i){if(t.opened&&i.target!==t.element[0]&&!t.overlay){if(t.dialog.is(i.target)||t.dialog.has(i.target).length>0){t.element.blur();return}var r,u=n(i.target).parents();for(u.push(i.target),r=0;r<=u.length;++r){if(t.button!==null&&u[r]===t.button[0])return;if(/\balt|all|both\b/.test(t.options.showOn)&&n(t.options.altField).is(u[r]))return}t.options.closeOnOutside&&(t.options.cancelOnExit&&(t.color=t.currentColor.copy(),t._change()),t.close(t.options.revert))}});if(t.events.document_keydown===null)n(document).on("keydown",t.events.document_keydown=function(n){t.opened&&n.keyCode===27&&t.options.closeOnEscape&&t.close(t.options.revert);t.opened&&n.keyCode===13&&t.options.okOnEnter&&t.close()});t.element.keydown(function(n){n.keyCode===9&&t.close()}).keyup(function(){var n=t._parseColor(t.element.val());n&&!t.color.equals(n)&&(t.color=n,t._change())})},_generate:function(){var t=this,u,r,f,i;t._setColor(t.inline||!t.element.is("input")?t.options.color:t.element.val());t[t.inline?"_generateInline":"_generatePopup"]();u=typeof t.options.parts=="string"?n.colorpicker.partslists[t.options.parts]?n.colorpicker.partslists[t.options.parts]:n.colorpicker.partslists[t.inline?"inline":"popup"]:t.options.parts;t.parts={};n.each(u,function(i,r){n.colorpicker.parts[r]&&(t.parts[r]=new n.colorpicker.parts[r](t))});t.generated||(r=[],n.each(t.options.layout,function(n,i){t.parts[n]&&r.push({part:n,pos:i})}),f=n(o(r,function(n,t,r){return i=["ui-colorpicker-"+n.part+"-container"],t>0&&i.push("ui-colorpicker-padding-left"),r>0&&i.push("ui-colorpicker-padding-top"),'<td  class="'+i.join(" ")+'"'+(n.pos[2]>1?' colspan="'+n.pos[2]+'"':"")+(n.pos[3]>1?' rowspan="'+n.pos[3]+'"':"")+' valign="top"><\/td>'})).appendTo(t.dialog),t.options.inlineFrame&&f.addClass("ui-dialog-content ui-widget-content"),t._initAllParts(),t._updateAllParts(),t.generated=!0)},_effectGeneric:function(t,i,r,u,f){var e=this;n.effects&&n.effects[e.options.showAnim]?t[i](e.options.showAnim,e.options.showOptions,e.options.duration,f):(t[e.options.showAnim==="slideDown"?r:e.options.showAnim==="fadeIn"?u:i](e.options.showAnim?e.options.duration:null,f),!n.isFunction(f)||e.options.showAnim&&e.options.duration||f())},_effectShow:function(n,t){this._effectGeneric(n,"show","slideDown","fadeIn",t)},_effectHide:function(n,t){this._effectGeneric(n,"hide","slideUp","fadeOut",t)},open:function(){var t=this,i,u,r;t.opened||(t._generate(),u=t.element.is(":hidden")?n("<div/>").insertBefore(t.element):t.element,t.element.is(":hidden")&&u.remove(),i=0,n(t.element[0]).parents().each(function(){var t=n(this).css("z-index");if(typeof t!="number"&&typeof t!="string"||t===""||isNaN(t))n(this).siblings().each(function(){var t=n(this).css("z-index");typeof t!="number"&&typeof t!="string"||t===""||isNaN(t)||t>i&&(i=parseInt(t,10))});else if(t>i)return i=parseInt(t,10),!1}),i+=2,t.dialog.css("z-index",i),t.options.modal&&(t.overlay=n('<div class="ui-widget-overlay"><\/div>').appendTo("body").css("z-index",i-1),t.events.window_resize!==null&&n(window).off("resize",t.events.window_resize),t.events.window_resize=function(){t.overlay&&(t.overlay.width(n(document).width()),t.overlay.height(n(document).height()))},n(window).on("resize",t.events.window_resize),t.events.window_resize()),t._effectShow(this.dialog),t.options.position?(r=n.extend({},t.options.position),r.of==="element"&&(r.of=u)):r={my:"left top",at:"left bottom",of:u,collision:"flip"},t.dialog.position(r),t.opened=!0,t._callback("open"),n(function(){t._repaintAllParts()}))},close:function(t){var i=this;i.opened&&(t?(i.color=i.currentColor.copy(),i._change(),i._callback("cancel")):(i.currentColor=i.color.copy(),i._callback("ok")),i.changed=!1,i.overlay&&(n(window).off("resize",i.events.window_resize),i.overlay.remove()),i._effectHide(i.dialog,function(){i.dialog.remove();i.dialog=null;i.generated=!1;i.opened=!1;i._callback("close")}))},destroy:function(){var t=this;t.events.document_click_html!==null&&n(document).off("touchstart click","html",t.events.document_click_html);t.events.document_keydown!==null&&n(document).off("keydown",t.events.document_keydown);t.events.window_resize!==null&&n(window).off("resize",t.events.window_resize);this.element.off();this.overlay&&this.overlay.remove();this.dialog!==null&&this.dialog.remove();this.image!==null&&this.image.remove();this.button!==null&&this.button.remove()},_callback:function(n){var t=this,i,r;return t.color.set?(i={formatted:t._formatColor(t.options.colorFormat,t.color),colorPicker:t},i.hex=t.color.toHex(),i.css=t.color.toCSS(),i.a=t.color.getAlpha(),i.rgb=t.color.getRGB(),i.hsv=t.color.getHSV(),i.cmyk=t.color.getCMYK(),i.hsl=t.color.getHSL(),r=t.color.getLAB(),r.a=r.a*2-1,r.b=r.b*2-1,i.lab=r,t._trigger(n,null,i)):t._trigger(n,null,{formatted:"",colorPicker:t})},_initAllParts:function(){n.each(this.parts,function(n,t){t.init&&t.init()})},_updateAllParts:function(){n.each(this.parts,function(n,t){t.update&&t.update()})},_repaintAllParts:function(){n.each(this.parts,function(n,t){t.repaint&&t.repaint()})},_change:function(t){this.color.set&&this.options.limit&&n.colorpicker.limits[this.options.limit]&&n.colorpicker.limits[this.options.limit](this.color,this);this.changed=!this.color.equals(this.currentColor);this.inline||(this.color.set?this.color.equals(this._parseColor(this.element.val()))||this.element.val(this._formatColor(this.options.colorFormat,this.color)).change():this.element.val()!==""&&this.element.val("").change(),this._setImageBackground());this._setAltField();this.options.color=this.color.set?this.color.toCSS():"";this.opened&&this._repaintAllParts();this._callback("select");(typeof t=="undefined"?!1:!t)||this._callback("stop")},_hoverable:function(n){n.hover(function(){n.addClass("ui-state-hover")},function(){n.removeClass("ui-state-hover")})},_focusable:function(n){n.focus(function(){n.addClass("ui-state-focus")}).blur(function(){n.removeClass("ui-state-focus")})},_getRegional:function(t){return n.colorpicker.regional[this.options.regional][t]!==undefined?n.colorpicker.regional[this.options.regional][t]:n.colorpicker.regional[""][t]},_getSwatches:function(){return typeof this.options.swatches=="string"?n.colorpicker.swatches[this.options.swatches]:n.isPlainObject(this.options.swatches)?this.options.swatches:n.colorpicker.swatches.html},_eachSwatch:function(t){var i=this._getSwatches(),r;n.each(i,function(u,f){return r=n.isArray(i)?f.name:u,t(r,f)})},_getSwatch:function(n){var t=!1;return this._eachSwatch(function(i,r){if(i.toLowerCase()==n.toLowerCase())return t=r,!1}),t},_parseFormat:function(t,i){var y=this,a={x:function(){return"([0-9a-fA-F]{2})"},d:function(){return"([12]?[0-9]{1,2})"},f:function(){return"([0-9]*\\.?[0-9]*)"},p:function(){return"([0-9]*\\.?[0-9]*)"}},v={x:function(n){return parseInt(n,16)/255},d:function(n){return n/255},f:function(n){return n},p:function(n){return n*.01}},h={r:"setRGB",g:"setRGB",b:"setRGB",h:"setHSV",s:"setHSV",v:"setHSV",c:"setCMYK",m:"setCMYK",y:"setCMYK",k:"setCMYK",L:"setLAB",A:"setLAB",B:"setLAB"},c=[],l=[],r=null,u,f,e,o,s;return f=t.replace(/[()\\^$.|?*+[\]]/g,function(n){return"\\"+n}),f=f.replace(/\\?[argbhsvcmykLAB][xdfp]/g,function(n){if(n.match(/^\\/))return n.slice(1);var t=n.charAt(0),i=n.charAt(1);return c.push(t),l.push(v[i]),h[t]&&(r=h[t]),a[i]()}),r&&(e=i.match(new RegExp(f)),e&&(o=[],e.shift(),n.each({setRGB:["r","g","b"],setHSV:["h","s","v"],setCMYK:["c","m","y","k"],setLAB:["L","A","B"]}[r],function(t,i){s=n.inArray(i,c);o[t]=l[s](e[s])}),u=new n.colorpicker.Color,u[r].apply(u,o))),u},_parseColor:function(t){var r=this,i,u=n.isArray(r.options.colorFormat)?r.options.colorFormat:[r.options.colorFormat];return(n.each(u,function(u,f){return i=n.colorpicker.parsers[f]?n.colorpicker.parsers[f](t,r):r._parseFormat(f,t),i?!1:void 0}),i||n.each(n.colorpicker.parsers,function(n,u){return i=u(t,r),i?!1:void 0}),i)?i:!1},_exactName:function(t){var i=!1;return this._eachSwatch(function(r,u){if(t.equals(new n.colorpicker.Color(u.r,u.g,u.b)))return i=r,!1}),i},_closestName:function(t){var f=t.getRGB(),r=null,u=!1,i;return this._eachSwatch(function(f,e){if(i=t.distance(new n.colorpicker.Color(e.r,e.g,e.b)),i<r||r===null){if(u=f,i<=1e-20)return!1;r=i}}),u},_formatColor:function(t,r){var f=this,u=null,e={x:function(n){return i(n*255)},d:function(n){return Math.round(n*255)},f:function(n){return n},p:function(n){return n*100}},o=r.getChannels();return n.isArray(t)||(t=[t]),n.each(t,function(t,i){return n.colorpicker.writers[i]?(u=n.colorpicker.writers[i](r,f),u===!1):(u=i.replace(/\\?[argbhsvcmykLAB][xdfp]/g,function(n){return n.match(/^\\/)?n.slice(1):e[n.charAt(1)](o[n.charAt(0)])}),!1)}),u}}),n.vanderlee.colorpicker});var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(n){function f(n){var t=/^[0-1]+$/;return t.test(n)}function i(n){return/^[-+]?[0-9]+$/.test(n)}function e(n){return typeof n=="string"&&(n=n.replace(/\s+/g,"").replace(w2utils.settings.groupSymbol,"").replace(w2utils.settings.decimalSymbol,".")),(typeof n=="number"||typeof n=="string"&&n!=="")&&!isNaN(Number(n))}function o(n){var t=w2utils.settings,i=new RegExp("^"+(t.currencyPrefix?"\\"+t.currencyPrefix+"?":"")+"[-+]?"+(t.currencyPrefix?"\\"+t.currencyPrefix+"?":"")+"[0-9]*[\\"+t.decimalSymbol+"]?[0-9]+"+(t.currencySuffix?"\\"+t.currencySuffix+"?":"")+"$","i");return(typeof n=="string"&&(n=n.replace(new RegExp(t.groupSymbol,"g"),"")),typeof n=="object"||n==="")?!1:i.test(n)}function s(n){return/^[a-fA-F0-9]+$/.test(n)}function h(n){return/^[a-zA-Z0-9_-]+$/.test(n)}function c(n){return/^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(n)}function l(n,t,r){var h,f,e,o,c,a,l,u,s;if(!n)return!1;if(h="Invalid Date",t==null&&(t=w2utils.settings.dateFormat),typeof n.getUTCFullYear=="function")o=n.getUTCFullYear(),f=n.getUTCMonth()+1,e=n.getUTCDate();else if(parseInt(n)==n&&parseInt(n)>0)n=new Date(parseInt(n)),o=n.getUTCFullYear(),f=n.getUTCMonth()+1,e=n.getUTCDate();else{if(n=String(n),new RegExp("mon","ig").test(t))for(t=t.replace(/month/ig,"m").replace(/mon/ig,"m").replace(/dd/ig,"d").replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),n=n.replace(/[, ]/ig,"/").replace(/\/\//g,"/").toLowerCase(),c=0,a=w2utils.settings.fullmonths.length;c<a;c++)l=w2utils.settings.fullmonths[c],n=n.replace(new RegExp(l,"ig"),parseInt(c)+1).replace(new RegExp(l.substr(0,3),"ig"),parseInt(c)+1);u=n.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/");s=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase();s==="mm/dd/yyyy"&&(f=u[0],e=u[1],o=u[2]);s==="m/d/yyyy"&&(f=u[0],e=u[1],o=u[2]);s==="dd/mm/yyyy"&&(f=u[1],e=u[0],o=u[2]);s==="d/m/yyyy"&&(f=u[1],e=u[0],o=u[2]);s==="yyyy/dd/mm"&&(f=u[2],e=u[1],o=u[0]);s==="yyyy/d/m"&&(f=u[2],e=u[1],o=u[0]);s==="yyyy/mm/dd"&&(f=u[1],e=u[2],o=u[0]);s==="yyyy/m/d"&&(f=u[1],e=u[2],o=u[0]);s==="mm/dd/yy"&&(f=u[0],e=u[1],o=u[2]);s==="m/d/yy"&&(f=u[0],e=u[1],o=parseInt(u[2])+1900);s==="dd/mm/yy"&&(f=u[1],e=u[0],o=parseInt(u[2])+1900);s==="d/m/yy"&&(f=u[1],e=u[0],o=parseInt(u[2])+1900);s==="yy/dd/mm"&&(f=u[2],e=u[1],o=parseInt(u[0])+1900);s==="yy/d/m"&&(f=u[2],e=u[1],o=parseInt(u[0])+1900);s==="yy/mm/dd"&&(f=u[1],e=u[2],o=parseInt(u[0])+1900);s==="yy/m/d"&&(f=u[1],e=u[2],o=parseInt(u[0])+1900)}return i(o)?i(f)?i(e)?(o=+o,f=+f,e=+e,h=new Date(o,f-1,e),f==null)?!1:String(h)=="Invalid Date"?!1:h.getMonth()+1!==f||h.getDate()!==e||h.getFullYear()!==o?!1:r===!0?h:!0:!1:!1:!1}function a(t,i){var s,h,c,f;if(t==null)return!1;t=String(t);t=t.toUpperCase();h=t.indexOf("AM")>=0;c=t.indexOf("PM")>=0;f=c||h;s=f?12:24;t=t.replace("AM","").replace("PM","");t=n.trim(t);var r=t.split(":"),u=parseInt(r[0]||0),e=parseInt(r[1]||0),o=parseInt(r[2]||0);return(!f||r.length!==1)&&r.length!==2&&r.length!==3?!1:r[0]===""||u<0||u>s||!this.isInt(r[0])||r[0].length>2?!1:r.length>1&&(r[1]===""||e<0||e>59||!this.isInt(r[1])||r[1].length!==2)?!1:r.length>2&&(r[2]===""||o<0||o>59||!this.isInt(r[2])||r[2].length!==2)?!1:!f&&s===u&&(e!==0||o!==0)?!1:f&&r.length===1&&u===0?!1:i===!0?(c&&u!==12&&(u+=12),h&&u===12&&(u+=12),{hours:u,minutes:e,seconds:o}):!0}function v(n,t,i){var r,e,o,u,f;return t==null&&(t=w2utils.settings.datetimeFormat),r=t.split("|"),typeof n.getUTCFullYear=="function"?i!==!0?!0:n:parseInt(n)==n&&parseInt(n)>0?(n=new Date(parseInt(n)),i!==!0)?!0:n:(e=String(n).indexOf(" "),o=[n.substr(0,e),n.substr(e).trim()],r[0]=r[0].trim(),r[1]&&(r[1]=r[1].trim()),u=w2utils.isDate(o[0],r[0],!0),f=w2utils.isTime(o[1],!0),u!==!1&&f!==!1?i!==!0?!0:(u.setHours(f.hours),u.setMinutes(f.minutes),u.setSeconds(f.seconds),u):!1)}function y(n){var u;if(n===""||n==null||(u=typeof n.getUTCFullYear=="function"?n:parseInt(n)==n&&parseInt(n)>0?new Date(parseInt(n)):new Date(n),String(u)=="Invalid Date"))return"";var f=new Date,t=(f.getTime()-u.getTime())/1e3,i="",r="";return t<0?(i=0,r="sec"):t<60?(i=Math.floor(t),r="sec",t<0&&(i=0,r="sec")):t<3600?(i=Math.floor(t/60),r="min"):t<86400?(i=Math.floor(t/3600),r="hour"):t<2592e3?(i=Math.floor(t/86400),r="day"):t<31536e3?(i=Math.floor(t/259200)/10,r="month"):t<126144e3?(i=Math.floor(t/3153600)/10,r="year"):t>=126144e3&&(i=Math.floor(t/365.25/8640)/10,r="year"),i+" "+r+(i>1?"s":"")}function p(n){return n<1e3?"< 1 sec":n<6e4?Math.floor(n/1e3)+" secs":n<36e5?Math.floor(n/6e4)+" mins":n<864e5?Math.floor(n/36e4)/10+" hours":n<2628e6?Math.floor(n/864e4)/10+" days":n<31536e6?Math.floor(n/2628e5)/10+" months":Math.floor(n/31536e5)/10+" years"}function w(n){var t;if(n===""||n==null||typeof n=="object"&&!n.getMonth||(t=new Date(n),w2utils.isInt(n)&&(t=new Date(Number(n))),String(t)=="Invalid Date"))return"";var u=w2utils.settings.shortmonths,f=new Date,i=new Date;i.setTime(i.getTime()-864e5);var r=u[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),o=u[f.getMonth()]+" "+f.getDate()+", "+f.getFullYear(),s=u[i.getMonth()]+" "+i.getDate()+", "+i.getFullYear(),h=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),c=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),e=r;return r===o&&(e=h),r===s&&(e=w2utils.lang("Yesterday")),'<span title="'+r+" "+c+'">'+e+"<\/span>"}function b(n){if(!w2utils.isFloat(n)||n==="")return"";if(n=parseFloat(n),n===0)return 0;var t=parseInt(Math.floor(Math.log(n)/Math.log(1024)));return(Math.floor(n/Math.pow(1024,t)*10)/10).toFixed(t===0?0:1)+" "+(["Bt","KB","MB","GB","TB","PB","EB","ZB"][t]||"??")}function k(n,t,i){if(n==null||n===""||typeof n=="object")return"";var r={minimumFractionDigits:t,maximumFractionDigits:t,useGrouping:i};return(t==null||t<0)&&(r.minimumFractionDigits=0,r.maximumFractionDigits=20),parseFloat(n).toLocaleString(w2utils.settings.locale,r)}function d(n,t){var i;if((t||(t=this.settings.dateFormat),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),String(i)=="Invalid Date"))return"";var r=i.getFullYear(),f=i.getMonth(),u=i.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[f]).replace("mon",w2utils.settings.shortmonths[f]).replace(/yyyy/g,r).replace(/yyy/g,r).replace(/yy/g,r>2e3?100+parseInt(String(r).substr(2)):String(r).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+r).replace(/mm/g,(f+1<10?"0":"")+(f+1)).replace(/dd/g,(u<10?"0":"")+u).replace(/th/g,u==1?"st":"th").replace(/th/g,u==2?"nd":"th").replace(/th/g,u==3?"rd":"th").replace(/(^|[^a-z$])m/g,"$1"+(f+1)).replace(/(^|[^a-z$])d/g,"$1"+u)}function g(n,t){var h=w2utils.settings.shortmonths,c=w2utils.settings.fullmonths,i,o;if((t||(t=this.settings.timeFormat),n===""||n==null||typeof n=="object"&&!n.getMonth)||(i=new Date(n),w2utils.isInt(n)&&(i=new Date(Number(n))),w2utils.isTime(n)&&(o=w2utils.isTime(n,!0),i=new Date,i.setHours(o.hours),i.setMinutes(o.minutes)),String(i)=="Invalid Date"))return"";var s="am",r=i.getHours(),e=i.getHours(),u=i.getMinutes(),f=i.getSeconds();return u<10&&(u="0"+u),f<10&&(f="0"+f),(t.indexOf("am")!==-1||t.indexOf("pm")!==-1)&&(r>=12&&(s="pm"),r>12&&(r=r-12)),t.toLowerCase().replace("am",s).replace("pm",s).replace("hhh",r<10?"0"+r:r).replace("hh24",e<10?"0"+e:e).replace("h24",e).replace("hh",r).replace("mm",u).replace("mi",u).replace("ss",f).replace(/(^|[^a-z$])h/g,"$1"+r).replace(/(^|[^a-z$])m/g,"$1"+u).replace(/(^|[^a-z$])s/g,"$1"+f)}function nt(n,t){var i;return n===""||n==null||typeof n=="object"&&!n.getMonth?"":(typeof t!="string"?i=[this.settings.dateFormat,this.settings.timeFormat]:(i=t.split("|"),i[0]=i[0].trim(),i[1]=i[1].trim()),i[1]=="h12"&&(i[1]="h:m pm"),i[1]=="h24"&&(i[1]="h24:m"),this.formatDate(n,i[0])+" "+this.formatTime(n,i[1]))}function tt(t){var i;if(t==null)return t;switch(typeof t){case"string":t=String(t).replace(/(<([^>]+)>)/ig,"");break;case"object":if(Array.isArray(t))for(t=n.extend(!0,[],t),i=0;i<t.length;i++)t[i]=this.stripTags(t[i]);else{t=n.extend(!0,{},t);for(i in t)t[i]=this.stripTags(t[i])}}return t}function r(t){var i;if(t==null)return t;switch(typeof t){case"string":t=String(t).replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/"/g,"&quot;");break;case"object":if(Array.isArray(t))for(t=n.extend(!0,[],t),i=0;i<t.length;i++)t[i]=this.encodeTags(t[i]);else{t=n.extend(!0,{},t);for(i in t)t[i]=this.encodeTags(t[i])}}return t}function it(t){var i;if(t==null)return t;switch(typeof t){case"string":t=String(t).replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&quot;/g,'"').replace(/&amp;/g,"&");break;case"object":if(Array.isArray(t))for(t=n.extend(!0,[],t),i=0;i<t.length;i++)t[i]=this.decodeTags(t[i]);else{t=n.extend(!0,{},t);for(i in t)t[i]=this.decodeTags(t[i])}}return t}function rt(n){return n===""||n==null?"":String(n).replace(/([;&,\.\+\*\~'`:"\!\^#$%@\[\]\(\)=<>\|\/? {}\\])/g,"\\$1")}function ut(n){function l(n){var i,r,t;for(n=String(n).replace(/\r\n/g,"\n"),i="",r=0;r<n.length;r++)t=n.charCodeAt(r),t<128?i+=String.fromCharCode(t):t>127&&t<2048?(i+=String.fromCharCode(t>>6|192),i+=String.fromCharCode(t&63|128)):(i+=String.fromCharCode(t>>12|224),i+=String.fromCharCode(t>>6&63|128),i+=String.fromCharCode(t&63|128));return i}var e="",o,t,i,h,c,s,r,u=0,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=l(n);u<n.length;)o=n.charCodeAt(u++),t=n.charCodeAt(u++),i=n.charCodeAt(u++),h=o>>2,c=(o&3)<<4|t>>4,s=(t&15)<<2|i>>6,r=i&63,isNaN(t)?s=r=64:isNaN(i)&&(r=64),e=e+f.charAt(h)+f.charAt(c)+f.charAt(s)+f.charAt(r);return e}function ft(n){function l(n){for(var r="",t=0,i=0,u,f;t<n.length;)i=n.charCodeAt(t),i<128?(r+=String.fromCharCode(i),t++):i>191&&i<224?(u=n.charCodeAt(t+1),r+=String.fromCharCode((i&31)<<6|u&63),t+=2):(u=n.charCodeAt(t+1),f=n.charCodeAt(t+2),r+=String.fromCharCode((i&15)<<12|(u&63)<<6|f&63),t+=3);return r}var t="",o,s,h,c,f,r,e,i=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(n=n.replace(/[^A-Za-z0-9\+\/\=]/g,"");i<n.length;)c=u.indexOf(n.charAt(i++)),f=u.indexOf(n.charAt(i++)),r=u.indexOf(n.charAt(i++)),e=u.indexOf(n.charAt(i++)),o=c<<2|f>>4,s=(f&15)<<4|r>>2,h=(r&3)<<6|e,t=t+String.fromCharCode(o),r!==64&&(t=t+String.fromCharCode(s)),e!==64&&(t=t+String.fromCharCode(h));return l(t)}function et(n){function k(n){return y(l(f(n)))}function l(n){return b(o(v(n),n.length*8))}function y(n){var i,r,u,t;try{h}catch(f){h=0}for(i=h?"0123456789ABCDEF":"0123456789abcdef",r="",t=0;t<n.length;t++)u=n.charCodeAt(t),r+=i.charAt(u>>>4&15)+i.charAt(u&15);return r}function f(n){for(var i="",r=-1,t,u;++r<n.length;)t=n.charCodeAt(r),u=r+1<n.length?n.charCodeAt(r+1):0,55296<=t&&t<=56319&&56320<=u&&u<=57343&&(t=65536+((t&1023)<<10)+(u&1023),r++),t<=127?i+=String.fromCharCode(t):t<=2047?i+=String.fromCharCode(192|t>>>6&31,128|t&63):t<=65535?i+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|t&63):t<=2097151&&(i+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|t&63));return i}function v(n){for(var i=Array(n.length>>2),t=0;t<i.length;t++)i[t]=0;for(t=0;t<n.length*8;t+=8)i[t>>5]|=(n.charCodeAt(t/8)&255)<<t%32;return i}function b(n){for(var i="",t=0;t<n.length*32;t+=8)i+=String.fromCharCode(n[t>>5]>>>t%32&255);return i}function o(n,f){var l;n[f>>5]|=128<<f%32;n[(f+64>>>9<<4)+14]=f;var o=1732584193,s=-271733879,h=-1732584194,c=271733878;for(l=0;l<n.length;l+=16){var a=o,v=s,y=h,p=c;o=t(o,s,h,c,n[l+0],7,-680876936);c=t(c,o,s,h,n[l+1],12,-389564586);h=t(h,c,o,s,n[l+2],17,606105819);s=t(s,h,c,o,n[l+3],22,-1044525330);o=t(o,s,h,c,n[l+4],7,-176418897);c=t(c,o,s,h,n[l+5],12,1200080426);h=t(h,c,o,s,n[l+6],17,-1473231341);s=t(s,h,c,o,n[l+7],22,-45705983);o=t(o,s,h,c,n[l+8],7,1770035416);c=t(c,o,s,h,n[l+9],12,-1958414417);h=t(h,c,o,s,n[l+10],17,-42063);s=t(s,h,c,o,n[l+11],22,-1990404162);o=t(o,s,h,c,n[l+12],7,1804603682);c=t(c,o,s,h,n[l+13],12,-40341101);h=t(h,c,o,s,n[l+14],17,-1502002290);s=t(s,h,c,o,n[l+15],22,1236535329);o=i(o,s,h,c,n[l+1],5,-165796510);c=i(c,o,s,h,n[l+6],9,-1069501632);h=i(h,c,o,s,n[l+11],14,643717713);s=i(s,h,c,o,n[l+0],20,-373897302);o=i(o,s,h,c,n[l+5],5,-701558691);c=i(c,o,s,h,n[l+10],9,38016083);h=i(h,c,o,s,n[l+15],14,-660478335);s=i(s,h,c,o,n[l+4],20,-405537848);o=i(o,s,h,c,n[l+9],5,568446438);c=i(c,o,s,h,n[l+14],9,-1019803690);h=i(h,c,o,s,n[l+3],14,-187363961);s=i(s,h,c,o,n[l+8],20,1163531501);o=i(o,s,h,c,n[l+13],5,-1444681467);c=i(c,o,s,h,n[l+2],9,-51403784);h=i(h,c,o,s,n[l+7],14,1735328473);s=i(s,h,c,o,n[l+12],20,-1926607734);o=r(o,s,h,c,n[l+5],4,-378558);c=r(c,o,s,h,n[l+8],11,-2022574463);h=r(h,c,o,s,n[l+11],16,1839030562);s=r(s,h,c,o,n[l+14],23,-35309556);o=r(o,s,h,c,n[l+1],4,-1530992060);c=r(c,o,s,h,n[l+4],11,1272893353);h=r(h,c,o,s,n[l+7],16,-155497632);s=r(s,h,c,o,n[l+10],23,-1094730640);o=r(o,s,h,c,n[l+13],4,681279174);c=r(c,o,s,h,n[l+0],11,-358537222);h=r(h,c,o,s,n[l+3],16,-722521979);s=r(s,h,c,o,n[l+6],23,76029189);o=r(o,s,h,c,n[l+9],4,-640364487);c=r(c,o,s,h,n[l+12],11,-421815835);h=r(h,c,o,s,n[l+15],16,530742520);s=r(s,h,c,o,n[l+2],23,-995338651);o=u(o,s,h,c,n[l+0],6,-198630844);c=u(c,o,s,h,n[l+7],10,1126891415);h=u(h,c,o,s,n[l+14],15,-1416354905);s=u(s,h,c,o,n[l+5],21,-57434055);o=u(o,s,h,c,n[l+12],6,1700485571);c=u(c,o,s,h,n[l+3],10,-1894986606);h=u(h,c,o,s,n[l+10],15,-1051523);s=u(s,h,c,o,n[l+1],21,-2054922799);o=u(o,s,h,c,n[l+8],6,1873313359);c=u(c,o,s,h,n[l+15],10,-30611744);h=u(h,c,o,s,n[l+6],15,-1560198380);s=u(s,h,c,o,n[l+13],21,1309151649);o=u(o,s,h,c,n[l+4],6,-145523070);c=u(c,o,s,h,n[l+11],10,-1120210379);h=u(h,c,o,s,n[l+2],15,718787259);s=u(s,h,c,o,n[l+9],21,-343485551);o=e(o,a);s=e(s,v);h=e(h,y);c=e(c,p)}return Array(o,s,h,c)}function s(n,t,i,r,u,f){return e(d(e(e(t,n),e(r,f)),u),i)}function t(n,t,i,r,u,f,e){return s(t&i|~t&r,n,t,u,f,e)}function i(n,t,i,r,u,f,e){return s(t&r|i&~r,n,t,u,f,e)}function r(n,t,i,r,u,f,e){return s(t^i^r,n,t,u,f,e)}function u(n,t,i,r,u,f,e){return s(i^(t|~r),n,t,u,f,e)}function e(n,t){var i=(n&65535)+(t&65535),r=(n>>16)+(t>>16)+(i>>16);return r<<16|i&65535}function d(n,t){return n<<t|n>>>32-t}var h=0,c="";return k(n)}function ot(t,i,r,u){var e=n(t).width(),o=n(t).height(),f=.5;if(!t||!i){console.log("ERROR: Cannot do transition when one of the divs is null");return}t.parentNode.style.cssText+="perspective: 900px; overflow: hidden;";t.style.cssText+="; position: absolute; z-index: 1019; backface-visibility: hidden";i.style.cssText+="; position: absolute; z-index: 1020; backface-visibility: hidden";switch(r){case"slide-left":t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; transform: translate3d("+e+"px, 0, 0)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: translate3d(0, 0, 0)";t.style.cssText+="transition: "+f+"s; transform: translate3d(-"+e+"px, 0, 0)"},1);break;case"slide-right":t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; transform: translate3d(-"+e+"px, 0, 0)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: translate3d(0px, 0, 0)";t.style.cssText+="transition: "+f+"s; transform: translate3d("+e+"px, 0, 0)"},1);break;case"slide-down":t.style.cssText+="overflow: hidden; z-index: 1; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; z-index: 0; transform: translate3d(0, 0, 0)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: translate3d(0, 0, 0)";t.style.cssText+="transition: "+f+"s; transform: translate3d(0, "+o+"px, 0)"},1);break;case"slide-up":t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; transform: translate3d(0, "+o+"px, 0)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: translate3d(0, 0, 0)";t.style.cssText+="transition: "+f+"s; transform: translate3d(0, 0, 0)"},1);break;case"flip-left":t.style.cssText+="overflow: hidden; transform: rotateY(0deg)";i.style.cssText+="overflow: hidden; transform: rotateY(-180deg)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: rotateY(0deg)";t.style.cssText+="transition: "+f+"s; transform: rotateY(180deg)"},1);break;case"flip-right":t.style.cssText+="overflow: hidden; transform: rotateY(0deg)";i.style.cssText+="overflow: hidden; transform: rotateY(180deg)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: rotateY(0deg)";t.style.cssText+="transition: "+f+"s; transform: rotateY(-180deg)"},1);break;case"flip-down":t.style.cssText+="overflow: hidden; transform: rotateX(0deg)";i.style.cssText+="overflow: hidden; transform: rotateX(180deg)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: rotateX(0deg)";t.style.cssText+="transition: "+f+"s; transform: rotateX(-180deg)"},1);break;case"flip-up":t.style.cssText+="overflow: hidden; transform: rotateX(0deg)";i.style.cssText+="overflow: hidden; transform: rotateX(-180deg)";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: rotateX(0deg)";t.style.cssText+="transition: "+f+"s; transform: rotateX(180deg)"},1);break;case"pop-in":t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0); transform: scale(.8); opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; transform: scale(1); opacity: 1;";t.style.cssText+="transition: "+f+"s;"},1);break;case"pop-out":t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0); transform: scale(1); opacity: 1;";i.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0); opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; opacity: 1;";t.style.cssText+="transition: "+f+"s; transform: scale(1.7); opacity: 0;"},1);break;default:t.style.cssText+="overflow: hidden; transform: translate3d(0, 0, 0)";i.style.cssText+="overflow: hidden; translate3d(0, 0, 0); opacity: 0;";n(i).show();window.setTimeout(function(){i.style.cssText+="transition: "+f+"s; opacity: 1;";t.style.cssText+="transition: "+f+"s"},1)}setTimeout(function(){r==="slide-down"&&(n(t).css("z-index","1019"),n(i).css("z-index","1020"));i&&n(i).css({opacity:"1"}).css(w2utils.cssPrefix({transition:"",transform:""}));t&&n(t).css({opacity:"1"}).css(w2utils.cssPrefix({transition:"",transform:""}));typeof u=="function"&&u()},f*1e3)}function st(t,i,r){var u={},f,e;typeof i=="object"?u=i:(u.msg=i,u.spinner=r);u.msg||u.msg===0||(u.msg="");w2utils.unlock(t);n(t).prepend('<div class="w2ui-lock"><\/div><div class="w2ui-lock-msg"><\/div>');f=n(t).find(".w2ui-lock");e=n(t).find(".w2ui-lock-msg");u.msg||e.css({"background-color":"transparent",border:"0px"});u.spinner===!0&&(u.msg='<div class="w2ui-spinner" '+(u.msg?"":'style="width: 35px; height: 35px"')+"><\/div>"+u.msg);u.opacity!=null&&f.css("opacity",u.opacity);typeof f.fadeIn=="function"?(f.fadeIn(200),e.html(u.msg).fadeIn(200)):(f.show(),e.html(u.msg).show(0))}function ht(t,r){i(r)?(n(t).find(".w2ui-lock").fadeOut(r),setTimeout(function(){n(t).find(".w2ui-lock").remove();n(t).find(".w2ui-lock-msg").remove()},r)):(n(t).find(".w2ui-lock").remove(),n(t).find(".w2ui-lock-msg").remove())}function ct(t,i){function p(i,e){if(f==null&&(f=e.trigger({phase:"before",type:"open",target:"self"}),f.isCancelled===!0)){u.css("z-index",u.data("old-z-index"));n(t.box).find("#w2ui-message"+r).remove();return}var o=i.data("prev_focus");i.remove();o&&o.length>0?o.focus():a&&a.focus&&a.focus();u.css("z-index",u.data("old-z-index"));e.trigger(n.extend(f,{phase:"after"}))}var a=this,y,f,s,u,v,r,c,i,l;n().w2tag();i||(i={width:200,height:100});i.on==null&&n.extend(i,w2utils.event);i.width==null&&(i.width=200);i.height==null&&(i.height=100);var o=parseInt(n(t.box).width()),h=parseInt(n(t.box).height()),e=parseInt(n(t.box).find(t.title).css("height")||0);if(i.width>o&&(i.width=o-10),i.height>h-e&&(i.height=h-10-e),i.originalWidth=i.width,i.originalHeight=i.height,parseInt(i.width)<0&&(i.width=o+i.width),parseInt(i.width)<10&&(i.width=10),parseInt(i.height)<0&&(i.height=h+i.height-e),parseInt(i.height)<10&&(i.height=10),i.hideOnClick==null&&(i.hideOnClick=!1),s=n(t.box).data("options")||{},(i.width==null||i.width>s.width-10)&&(i.width=s.width-10),(i.height==null||i.height>s.height-e-5)&&(i.height=s.height-e-5),i.originalHeight<0&&(i.height=h+i.originalHeight-e),i.originalWidth<0&&(i.width=o+i.originalWidth*2),u=n(t.box).find(t.title),v=n(t.box).find(".w2ui-message.w2ui-closing"),n(t.box).find(".w2ui-message.w2ui-closing").length>0&&(clearTimeout(y),p(v,v.data("options")||{})),r=n(t.box).find(".w2ui-message").length,n.trim(i.html)===""&&n.trim(i.body)===""&&n.trim(i.buttons)===""){if(r===0)return;if(c=n(t.box).find("#w2ui-message"+(r-1)),i=c.data("options")||{},f=i.trigger({phase:"before",type:"close",target:"self"}),f.isCancelled===!0)return;c.css(w2utils.cssPrefix({transition:"0.15s",transform:"translateY(-"+i.height+"px)"})).addClass("w2ui-closing");r==1?this.unlock&&(t.param?this.unlock(t.param,150):this.unlock(150)):n(t.box).find("#w2ui-message"+(r-2)).css("z-index",1500);y=setTimeout(function(){p(c,i)},150)}else if((n.trim(i.body)!==""||n.trim(i.buttons)!=="")&&(i.html='<div class="w2ui-message-body">'+(i.body||"")+'<\/div><div class="w2ui-message-buttons">'+(i.buttons||"")+"<\/div>"),n(t.box).find(".w2ui-message").css("z-index",1390),u.data("old-z-index",u.css("z-index")),u.css("z-index",1501),n(t.box).find(t.body).before('<div id="w2ui-message'+r+'" onmousedown="event.stopPropagation();"    class="w2ui-message" style="display: none; z-index: 1500; '+(u.length===0?"top: 0px;":"top: "+w2utils.getSize(u,"height")+"px;")+(i.width!=null?"width: "+i.width+"px; left: "+(o-i.width)/2+"px;":"left: 10px; right: 10px;")+(i.height!=null?"height: "+i.height+"px;":"bottom: 6px;")+w2utils.cssPrefix("transition",".3s",!0)+'"'+(i.hideOnClick===!0?t.param?'onclick="'+t.path+".message('"+t.param+"');\"":'onclick="'+t.path+'.message();"':"")+"><\/div>"),n(t.box).find("#w2ui-message"+r).data("options",i).data("prev_focus",n(":focus")),l=n(t.box).find("#w2ui-message"+r).css("display"),n(t.box).find("#w2ui-message"+r).css(w2utils.cssPrefix({transform:l=="none"?"translateY(-"+i.height+"px)":"translateY(0px)"})),l=="none"){if(n(t.box).find("#w2ui-message"+r).show().html(i.html),i.box=n(t.box).find("#w2ui-message"+r),f=i.trigger({phase:"before",type:"open",target:"self"}),f.isCancelled===!0){u.css("z-index",u.data("old-z-index"));n(t.box).find("#w2ui-message"+r).remove();return}setTimeout(function(){n(t.box).find("#w2ui-message"+r).css(w2utils.cssPrefix({transform:l=="none"?"translateY(0px)":"translateY(-"+i.height+"px)"}))},1);r===0&&this.lock&&(t.param?this.lock(t.param):this.lock());setTimeout(function(){n(t.box).find("#w2ui-message"+r).css(w2utils.cssPrefix({transition:"0s"}));i.trigger(n.extend(f,{phase:"after"}))},350)}}function lt(t,i){var r=n(t),u={left:parseInt(r.css("border-left-width"))||0,right:parseInt(r.css("border-right-width"))||0,top:parseInt(r.css("border-top-width"))||0,bottom:parseInt(r.css("border-bottom-width"))||0},f={left:parseInt(r.css("margin-left"))||0,right:parseInt(r.css("margin-right"))||0,top:parseInt(r.css("margin-top"))||0,bottom:parseInt(r.css("margin-bottom"))||0},e={left:parseInt(r.css("padding-left"))||0,right:parseInt(r.css("padding-right"))||0,top:parseInt(r.css("padding-top"))||0,bottom:parseInt(r.css("padding-bottom"))||0};switch(i){case"top":return u.top+f.top+e.top;case"bottom":return u.bottom+f.bottom+e.bottom;case"left":return u.left+f.left+e.left;case"right":return u.right+f.right+e.right;case"width":return u.left+u.right+f.left+f.right+e.left+e.right+parseInt(r.width());case"height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom+parseInt(r.height());case"+width":return u.left+u.right+f.left+f.right+e.left+e.right;case"+height":return u.top+u.bottom+f.top+f.bottom+e.top+e.bottom}return 0}function at(t,i){var u,f='<div id="_tmp_width" style="position: absolute; top: -900px;'+(i||"")+'">'+r(t)+"<\/div>";return n("body").append(f),u=n("#_tmp_width").width(),n("#_tmp_width").remove(),u}function vt(n){var t=this.settings.phrases[n];return t==null?n:t}function yt(t){if(t||(t="en-us"),typeof t!="string"){w2utils.settings=n.extend(!0,w2utils.settings,t);return}t.length===5&&(t="locale/"+t+".json");w2utils.settings.phrases={};n.ajax({url:t,type:"GET",dataType:"JSON",async:!1,success:function(t){w2utils.settings=n.extend(!0,w2utils.settings,t)},error:function(){console.log("ERROR: Cannot load locale "+t)}})}function pt(){if(t.scrollBarSize)return t.scrollBarSize;return n("body").append('<div id="_scrollbar_width" style="position: absolute; top: -300px; width: 100px; height: 100px; overflow-y: scroll;">    <div style="height: 120px">1<\/div><\/div>'),t.scrollBarSize=100-n("#_scrollbar_width > div").width(),n("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(t.scrollBarSize=t.scrollBarSize/2),t.scrollBarSize}function wt(n,t){return!n||n.name==null?(console.log('ERROR: The parameter "name" is required but not supplied in $().'+t+"()."),!1):w2ui[n.name]!=null?(console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+n.name+")."),!1):w2utils.isAlphaNumeric(n.name)?!0:(console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '),!1)}function bt(t,i,r,u){n.isArray(i)||(i=[i]);for(var f=0;f<i.length;f++)if(i[f].id===t)return console.log('ERROR: The parameter "id='+t+'" is not unique within the current '+r+". (obj: "+u+")"),!1;return!0}function kt(n){var t=[],i=n.replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(n,i,r,u,f,e){return t.push({name:u,optional:!!e}),i=i||"",""+(e?"":i)+"(?:"+(e?i:"")+(r||"")+(f||r&&"([^/.]+?)"||"([^/]+?)")+")"+(e||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)");return{path:new RegExp("^"+i+"$","i"),keys:t}}function dt(t,i,r){var f={},e={},o="",u;n.isPlainObject(t)?(f=t,i===!0&&(r=!0)):f[t]=i;for(u in f)e[u]=f[u],e["-webkit-"+u]=f[u],e["-moz-"+u]=f[u].replace("-webkit-","-moz-"),e["-ms-"+u]=f[u].replace("-webkit-","-ms-"),e["-o-"+u]=f[u].replace("-webkit-","-o-");if(r===!0)for(u in e)o+=u+": "+e[u]+"; ";else o=e;return o}function gt(n){var u,f,s,e;if(n==null)return null;var i=0,r=n.ownerDocument||n.document,o=r.defaultView||r.parentWindow,t;return n.tagName&&n.tagName.toUpperCase()=="INPUT"&&n.selectionStart?i=n.selectionStart:o.getSelection?(t=o.getSelection(),t.rangeCount>0&&(u=t.getRangeAt(0),f=u.cloneRange(),f.selectNodeContents(n),f.setEnd(u.endContainer,u.endOffset),i=f.toString().length)):(t=r.selection)&&t.type!="Control"&&(s=t.createRange(),e=r.body.createTextRange(),e.moveToElementText(n),e.setEndPoint("EndToEnd",s),i=e.text.length),i}function ni(t,i,r){var o=document.createRange(),u,s=window.getSelection(),f,e;if(t!=null){for(f=0;f<t.childNodes.length;f++)if(e=n(t.childNodes[f]).text(),t.childNodes[f].tagName&&(e=n(t.childNodes[f]).html(),e=e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&nbsp;/g," ")),i<=e.length){u=t.childNodes[f];u.childNodes&&u.childNodes.length>0&&(u=u.childNodes[0]);u.childNodes&&u.childNodes.length>0&&(u=u.childNodes[0]);break}else i-=e.length;u!=null&&(i>u.length&&(i=u.length),o.setStart(u,i),r?o.setEnd(u,r):o.collapse(!0),s.removeAllRanges(),s.addRange(o))}}function u(){var n="w2ui_test";try{return localStorage.setItem(n,n),localStorage.removeItem(n),!0}catch(t){return!1}}var t={};return{version:"1.5.RC1",settings:{locale:"en-us",dateFormat:"m/d/yyyy",timeFormat:"hh:mi pm",datetimeFormat:"m/d/yyyy|hh:mi pm",currencyPrefix:"$",currencySuffix:"",currencyPrecision:2,groupSymbol:",",decimalSymbol:".",shortmonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],fullmonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortdays:["M","T","W","T","F","S","S"],fulldays:["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],weekStarts:"M",dataType:"HTTPJSON",phrases:{},dateStartYear:1950,dateEndYear:2020},isBin:f,isInt:i,isFloat:e,isMoney:o,isHex:s,isAlphaNumeric:h,isEmail:c,isDate:l,isTime:a,isDateTime:v,age:y,interval:p,date:w,formatSize:b,formatNumber:k,formatDate:d,formatTime:g,formatDateTime:nt,stripTags:tt,encodeTags:r,decodeTags:it,escapeId:rt,base64encode:ut,base64decode:ft,md5:et,transition:ot,lock:st,unlock:ht,message:ct,lang:vt,locale:yt,getSize:lt,getStrWidth:at,scrollBarSize:pt,checkName:wt,checkUniqueId:bt,parseRoute:kt,cssPrefix:dt,getCursorPosition:gt,setCursorPosition:ni,testLocalStorage:u,hasLocalStorage:u(),isIOS:navigator.userAgent.toLowerCase().indexOf("iphone")!=-1||navigator.userAgent.toLowerCase().indexOf("ipod")!=-1||navigator.userAgent.toLowerCase().indexOf("ipad")!=-1?!0:!1,isIE:navigator.userAgent.toLowerCase().indexOf("msie")!=-1||navigator.userAgent.toLowerCase().indexOf("trident")!=-1?!0:!1}}(jQuery);w2utils.formatters={number:function(n,t){return(parseInt(t)>20&&(t=20),parseInt(t)<0&&(t=0),n==null||n==="")?"":w2utils.formatNumber(parseFloat(n),t,!0)},float:function(n,t){return w2utils.formatters.number(n,t)},int:function(n){return w2utils.formatters.number(n,0)},money:function(n){if(n==null||n==="")return"";var t=w2utils.formatNumber(Number(n),w2utils.settings.currencyPrecision||2);return(w2utils.settings.currencyPrefix||"")+t+(w2utils.settings.currencySuffix||"")},currency:function(n,t){return w2utils.formatters.money(n,t)},percent:function(n,t){return n==null||n===""?"":w2utils.formatNumber(n,t||1)+"%"},size:function(n){return n==null||n===""?"":w2utils.formatSize(parseInt(n))},date:function(n,t){if(t===""&&(t=w2utils.settings.dateFormat),n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,t,!0);return i===!1&&(i=w2utils.isDate(n,t,!0)),'<span title="'+i+'">'+w2utils.formatDate(i,t)+"<\/span>"},datetime:function(n,t){if(t===""&&(t=w2utils.settings.datetimeFormat),n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,t,!0);return i===!1&&(i=w2utils.isDate(n,t,!0)),'<span title="'+i+'">'+w2utils.formatDateTime(i,t)+"<\/span>"},time:function(n,t){if(t===""&&(t=w2utils.settings.timeFormat),t==="h12"&&(t="hh:mi pm"),t==="h24"&&(t="h24:mi"),n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,t,!0);return i===!1&&(i=w2utils.isDate(n,t,!0)),'<span title="'+i+'">'+w2utils.formatTime(n,t)+"<\/span>"},timestamp:function(n,t){if(t===""&&(t=w2utils.settings.datetimeFormat),n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,t,!0);return i===!1&&(i=w2utils.isDate(n,t,!0)),i.toString?i.toString():""},gmt:function(n,t){if(t===""&&(t=w2utils.settings.datetimeFormat),n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,t,!0);return i===!1&&(i=w2utils.isDate(n,t,!0)),i.toUTCString?i.toUTCString():""},age:function(n,t){if(n==null||n===0||n==="")return"";var i=w2utils.isDateTime(n,null,!0);return i===!1&&(i=w2utils.isDate(n,null,!0)),'<span title="'+i+'">'+w2utils.age(n)+(t?" "+t:"")+"<\/span>"},interval:function(n,t){return n==null||n===0||n===""?"":w2utils.interval(n)+(t?" "+t:"")},toggle:function(n){return n?"Yes":""},password:function(n){for(var t="",i=0;i<n.length;i++)t+="*";return t}};w2utils.event={on:function(n,t){var r=jQuery,u,i;if(typeof n=="string"&&n.indexOf(".")!=-1&&(i=n.split("."),n=i[0],u=i[1]),typeof n=="string"&&n.indexOf(":")!=-1&&(i=n.split(":"),["complete","done"].indexOf(n[1])!=-1&&(n[1]="after"),n={type:i[0],execute:i[1]}),r.isPlainObject(n)||(n={type:n,scope:u}),n=r.extend({type:null,execute:"before",target:null,onComplete:null},n),!n.type){console.log("ERROR: You must specify event type when calling .on() method of "+this.name);return}if(!t){console.log("ERROR: You must specify event handler function when calling .on() method of "+this.name);return}r.isArray(this.handlers)||(this.handlers=[]);this.handlers.push({edata:n,handler:t})},off:function(n,t){var o=jQuery,u,r,e,f,s,i;if(typeof n=="string"&&n.indexOf(".")!=-1&&(r=n.split("."),n=r[0],u=r[1]),typeof n=="string"&&n.indexOf(":")!=-1&&(r=n.split(":"),["complete","done"].indexOf(n[1])!=-1&&(n[1]="after"),n={type:r[0],execute:r[1]}),o.isPlainObject(n)||(n={type:n}),n=o.extend({},{type:null,execute:"before",target:null,onComplete:null},n),!n.type&&!u){console.log("ERROR: You must specify event type when calling .off() method of "+this.name);return}for(t||(t=null),e=[],f=0,s=this.handlers.length;f<s;f++)i=this.handlers[f],(i.edata.type===n.type||n.type==="*"||i.edata.scope!=null&&n.type=="")&&(i.edata.target===n.target||n.target==null)&&(i.edata.execute===n.execute||n.execute==null)&&(i.handler===t||t==null||u!=null&&i.edata.scope==u)||e.push(i);this.handlers=e},trigger:function(n){var s=jQuery,n=s.extend({type:null,phase:"before",target:null,doneHandlers:[]},n,{isStopped:!1,isCancelled:!1,done:function(n){this.doneHandlers.push(n)},preventDefault:function(){this.isCancelled=!0},stopPropagation:function(){this.isStopped=!0}}),i,u,r,o,t,f,e;for(n.phase==="before"&&(n.onComplete=null),n.target==null&&(n.target=null),s.isArray(this.handlers)||(this.handlers=[]),o=this.handlers.length-1;o>=0;o--)if(t=this.handlers[o],(t.edata.type===n.type||t.edata.type==="*")&&(t.edata.target===n.target||t.edata.target==null)&&(t.edata.execute===n.phase||t.edata.execute==="*"||t.edata.phase==="*")&&(n=s.extend({},t.edata,n),i=[],r=new RegExp(/\((.*?)\)/).exec(t.handler),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?t.handler.call(this,n.target,n):t.handler.call(this,n),n.isStopped===!0||n.stop===!0))return n;if((f="on"+n.type.substr(0,1).toUpperCase()+n.type.substr(1),n.phase==="before"&&typeof this[f]=="function"&&(u=this[f],i=[],r=new RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0))||n.object!=null&&n.phase==="before"&&typeof n.object[f]=="function"&&(u=n.object[f],i=[],r=new RegExp(/\((.*?)\)/).exec(u),r&&(i=r[1].split(/\s*,\s*/)),i.length===2?u.call(this,n.target,n):u.call(this,n),n.isStopped===!0||n.stop===!0))return n;if(n.phase==="after")for(typeof n.onComplete=="function"&&n.onComplete.call(this,n),e=0;e<n.doneHandlers.length;e++)typeof n.doneHandlers[e]=="function"&&n.doneHandlers[e].call(this,n);return n}},function(n){n.fn.w2render=function(t){n(this).length>0&&(typeof t=="string"&&w2ui[t]&&w2ui[t].render(n(this)[0]),typeof t=="object"&&t.render(n(this)[0]))};n.fn.w2destroy=function(n){!n&&this.length>0&&(n=this.attr("name"));typeof n=="string"&&w2ui[n]&&w2ui[n].destroy();typeof n=="object"&&n.destroy()};n.fn.w2marker=function(){function i(n,t){while(t.innerHTML.indexOf('<span class="w2ui-marker">')!=-1)t.innerHTML=t.innerHTML.replace(/\<span class=\"w2ui\-marker\"\>((.|\n|\r)*)\<\/span\>/ig,"$1")}var t=Array.prototype.slice.call(arguments,0);return Array.isArray(t[0])&&(t=t[0]),t.length!==0&&t[0]?n(this).each(function(n,r){function o(n){return'<span class="w2ui-marker">'+n+"<\/span>"}var f,u,e;for(i(n,r),f=0;f<t.length;f++)u=t[f],typeof u!="string"&&(u=String(u)),u=u.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&amp;").replace(/</g,"&gt;").replace(/>/g,"&lt;"),e=new RegExp(u+"(?!([^<]+)?>)","gi"),r.innerHTML=r.innerHTML.replace(e,o)}):n(this).each(i)};n.fn.w2tag=function(t,i){if(arguments.length==1&&typeof t=="object"&&(i=t,i.html!=null&&(t=i.html)),i=n.extend({id:null,html:t,position:"right|top",align:"none",left:0,top:0,style:"",css:{},className:"",inputClass:"",onShow:null,onHide:null,hideOnKeyPress:!0,hideOnBlur:!1,hideOnClick:!1},i),i.name!=null&&i.id==null&&(i.id=i.name),i["class"]!==""&&i.inputClass===""&&(i.inputClass=i["class"]),n(this).length===0){n(".w2ui-tag").each(function(t,i){var r=n(i).data("options");r==null&&(r={});n(n(i).data("taged-el")).removeClass(r.inputClass).removeData("w2tag").removeData("checkIfMoved");clearInterval(n(i).data("timer"));n(i).remove()});return}return n(this).each(function(r,u){function e(){(f=n("#w2ui-tag-"+s),f.length<=0)||(clearInterval(f.data("timer")),f.remove(),n(document).off(".w2tag"),n(u).off(".w2tag",e).removeClass(i.inputClass).removeData("w2tag").removeData("checkIfMoved"),n(u).length>0&&(n(u)[0].style.cssText=h),typeof i.onHide=="function"&&i.onHide())}function o(t,r){var s=n(u).offset(),p,k,w,v;if(n(u).length===0||s.left===0&&s.top===0||f.find(".w2ui-tag-body").length===0){clearInterval(f.data("timer"));e();return}r||setTimeout(o,100);var l="w2ui-tag-right",h=parseInt(s.left+u.offsetWidth+(i.left?i.left:0)),c=parseInt(s.top+(i.top?i.top:0)),y=f.find(".w2ui-tag-body"),a=y[0].offsetWidth,b=y[0].offsetHeight;if(typeof i.position=="string"&&i.position.indexOf("|")!=-1&&(i.position=i.position.split("|")),i.position=="top")l="w2ui-tag-top",h=parseInt(s.left+(i.left?i.left:0))-14,c=parseInt(s.top+(i.top?i.top:0))-b-10;else if(i.position=="bottom")l="w2ui-tag-bottom",h=parseInt(s.left+(i.left?i.left:0))-14,c=parseInt(s.top+u.offsetHeight+(i.top?i.top:0))+10;else if(i.position=="left")l="w2ui-tag-left",h=parseInt(s.left+(i.left?i.left:0))-a-20,c=parseInt(s.top+(i.top?i.top:0));else if(Array.isArray(i.position)){for(p=window.innerWidth,k=window.innerHeight,w=0;w<i.position.length;w++)if(v=i.position[w],v=="right"){if(l="w2ui-tag-right",h=parseInt(s.left+u.offsetWidth+(i.left?i.left:0)),c=parseInt(s.top+(i.top?i.top:0)),h+a<=p)break}else if(v=="left"){if(l="w2ui-tag-left",h=parseInt(s.left+(i.left?i.left:0))-a-20,c=parseInt(s.top+(i.top?i.top:0)),h>=0)break}else if(v=="top"){if(l="w2ui-tag-top",h=parseInt(s.left+(i.left?i.left:0))-14,c=parseInt(s.top+(i.top?i.top:0))-b-10,h+a<=p&&c>=0)break}else if(v=="bottom"&&(l="w2ui-tag-bottom",h=parseInt(s.left+(i.left?i.left:0))-14,c=parseInt(s.top+u.offsetHeight+(i.top?i.top:0))+10,h+a<=p&&c+b<=k))break;y.data("posClass")!==l&&y.removeClass("w2ui-tag-right w2ui-tag-left w2ui-tag-top w2ui-tag-bottom").addClass(l).data("posClass",l)}return f.data("position")!==h+"x"+c&&t!==!0&&f.css(w2utils.cssPrefix({transition:r?"0s":".2s"})).css({left:h+"px",top:c+"px"}).data("position",h+"x"+c),{left:h,top:c,posClass:l}}var c=i.id?i.id:u.id,s=w2utils.escapeId(c),f=n("#w2ui-tag-"+s),h;if(t===""||t==null){f.css("opacity",0);clearInterval(f.data("timer"));f.remove();return}f.length!==0?(i=n.extend(f.data("options"),i),f.data("options",i),f.find(".w2ui-tag-body").attr("style",i.style).addClass(i.className).html(i.html),o(!0)):(h="",n(u).length>0&&(h=n(u)[0].style.cssText),n("body").append('<div onclick="event.stopPropagation()" style="display:none;" id="w2ui-tag-'+c+'"        class="w2ui-tag '+(n(u).parents(".w2ui-popup, .w2ui-overlay-popup, .w2ui-message").length>0?"w2ui-tag-popup":"")+'">   <div style="margin: -2px 0px 0px -2px; white-space: nowrap;">      <div class="w2ui-tag-body '+i.className+'" style="'+(i.style||"")+'">'+t+"<\/div>   <\/div><\/div>"),f=n("#w2ui-tag-"+s),n(u).data("w2tag",f.get(0)).data("checkIfMoved",o));setTimeout(function(){if(f.css("display","block"),n(u).offset()){var t=o(!0);if(t!=null){if(f.css({opacity:"1",left:t.left+"px",top:t.top+"px"}).data("options",i).data("taged-el",u).data("position",t.left+"x"+t.top).data("timer",setTimeout(o,100)).find(".w2ui-tag-body").addClass(t.posClass),n(u).css(i.css).off(".w2tag").addClass(i.inputClass),i.hideOnKeyPress)n(u).on("keypress.w2tag",e);if(i.hideOnBlur)n(u).on("blur.w2tag",e);if(i.hideOnClick)n(document).on("click.w2tag",e);typeof i.onShow=="function"&&i.onShow()}}},1)})};n.fn.w2overlay=function(t,i){function a(){var t=n("#w2ui-overlay"+r),i,f;t.data("element")===u[0]&&t.length!==0&&(i=n(u).offset()||{},f=i.left+"x"+i.top,t.data("position")!==f?s():setTimeout(a,250))}function s(t){var u,f;if(!t||t.button===0){if(u=n("#w2ui-overlay"+r),u.data("keepOpen")===!0){u.removeData("keepOpen");return}(typeof i.onHide=="function"&&(f=i.onHide()),f!==!1)&&(u.remove(),n(document).off("click",s),clearInterval(u.data("timer")))}}function l(){var o=n("#w2ui-overlay"+r),t=o.find(" > div"),nt=n("#w2ui-overlay"+r+" div.menu"),y,b,k,d,s,g;if(nt.css("overflow-y","hidden"),o.length>0){t.height("auto").width("auto");var w=!1,h=t.height(),f=t.width();i.width&&i.width<f&&(f=i.width);f<30&&(f=30);i.tmp.contentHeight&&(h=parseInt(i.tmp.contentHeight),t.height(h),setTimeout(function(){var n=t.find("div.menu");h>n.height()&&t.find("div.menu").css("overflow-y","hidden")},1),setTimeout(function(){var n=t.find("div.menu");n.css("overflow-y")!="auto"&&n.css("overflow-y","auto")},10));i.tmp.contentWidth&&i.align!="both"&&(f=parseInt(i.tmp.contentWidth),t.width(f),setTimeout(function(){f>t.find("div.menu > table").width()&&t.find("div.menu > table").css("overflow-x","hidden")},1),setTimeout(function(){t.find("div.menu > table").css("overflow-x","auto")},10));var a=i.left,v=i.width,c=i.tipLeft;switch(i.align){case"both":a=17;i.width===0&&(i.width=w2utils.getSize(n(u),"width"));i.maxWidth&&i.width>i.maxWidth&&(i.width=i.maxWidth);break;case"left":a=17;break;case"right":a=w2utils.getSize(n(u),"width")-f+10;c=f-40}v=f!==30||v?i.width?i.width:"auto":30;y=(f-17)/2;v!="auto"&&(y=(v-17)/2);y<25&&(a=25-y,c=Math.floor(y));i.contextMenu?(b=i.pageX+8,k=i.pageY-0,d=i.pageY):(s=u.offset()||{},b=(s.left>25?s.left:25)+a,k=s.top+w2utils.getSize(u,"height")+i.top+7,d=s.top);o.css({left:b+"px",top:k+"px","min-width":v,"min-height":i.height?i.height:"auto"});var s=t.offset()||{},e=window.innerHeight+n(document).scrollTop()-s.top-7,p=window.innerWidth+n(document).scrollLeft()-s.left-7;i.contextMenu&&(e=window.innerHeight+n(document).scrollTop()-i.pageY-15,p=window.innerWidth+n(document).scrollLeft()-i.pageX);e>-50&&e<210||i.openAbove===!0?(i.contextMenu?(e=i.pageY-7,g=5):(e=s.top-n(document).scrollTop()-7,g=24),i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),h>e&&(w=!0,t.height(e).width(f).css({"overflow-y":"auto"}),h=e),o.addClass("bottom-arrow"),o.css("top",d-h-g+i.top+"px"),o.find(">style").html("#w2ui-overlay"+r+":before { margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { margin-left: "+parseInt(c)+"px; }")):(i.maxHeight&&e>i.maxHeight&&(e=i.maxHeight),h>e&&(w=!0,t.height(e).width(f).css({"overflow-y":"auto"})),o.addClass("top-arrow"),o.find(">style").html("#w2ui-overlay"+r+":before { margin-left: "+parseInt(c)+"px; }#w2ui-overlay"+r+":after { margin-left: "+parseInt(c)+"px; }"));f=t.width();p=window.innerWidth+n(document).scrollLeft()-s.left-7;i.maxWidth&&p>i.maxWidth&&(p=i.maxWidth);f>p&&i.align!=="both"&&(i.align="right",setTimeout(function(){l()},1));(i.contextMenu||i.noTip)&&o.find(">style").html("#w2ui-overlay"+r+":before { display: none; }#w2ui-overlay"+r+":after { display: none; }");w&&i.align!="both"&&t.width(f+w2utils.scrollBarSize()+2)}nt.css("overflow-y","auto")}var u=this,r="",f,e,h,o,c;if(arguments.length==1&&(i=typeof t=="object"?t:{html:t}),arguments.length==2&&(i.html=t),n.isPlainObject(i)||(i={}),i=n.extend({},{name:null,html:"",align:"none",left:0,top:0,tipLeft:30,noTip:!1,selectable:!1,width:0,height:0,maxWidth:null,maxHeight:null,contextMenu:!1,pageX:null,pageY:null,originalEvent:null,style:"","class":"",overlayStyle:"",onShow:null,onHide:null,openAbove:!1,tmp:{}},i),i.name&&(r="-"+i.name),this.length===0||i.html===""||i.html==null)return n("#w2ui-overlay"+r).length>0?(f=n("#w2ui-overlay"+r)[0].hide,typeof f=="function"&&f()):n("#w2ui-overlay"+r).remove(),n(this);n("#w2ui-overlay"+r).length>0&&(f=n("#w2ui-overlay"+r)[0].hide,n(document).off(".w2overlayHide"),typeof f=="function"&&f());u.length>0&&(u[0].tagName==null||u[0].tagName.toUpperCase()=="BODY")&&(i.contextMenu=!0);i.contextMenu&&i.originalEvent&&(i.pageX=i.originalEvent.pageX,i.pageY=i.originalEvent.pageY);i.contextMenu&&(i.pageX==null||i.pageY==null)&&console.log("ERROR: to display menu at mouse location, pass options.pageX and options.pageY.");n("body").append('<div id="w2ui-overlay'+r+'" style="display: none; left: 0px; top: 0px; '+i.overlayStyle+'"        class="w2ui-reset w2ui-overlay '+(n(this).parents(".w2ui-popup, .w2ui-overlay-popup, .w2ui-message").length>0?"w2ui-overlay-popup":"")+'">    <style><\/style>    <div style="min-width: 100%; '+i.style+'" class="'+i["class"]+'"><\/div><\/div>');e=n("#w2ui-overlay"+r);h=e.find(" > div");h.html(i.html);o=h.css("background-color");o!=null&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent"&&e.css({"background-color":o,"border-color":o});c=n(u).offset()||{};e.data("element",u.length>0?u[0]:null).data("options",i).data("position",c.left+"x"+c.top).fadeIn("fast").on("click",function(n){n.target.tagName.toUpperCase()=="LABEL"&&n.stopPropagation()}).on("mousedown",function(t){n("#w2ui-overlay"+r).data("keepOpen",!0);["INPUT","TEXTAREA","SELECT"].indexOf(t.target.tagName.toUpperCase())!=-1||i.selectable||t.preventDefault()});return e[0].hide=s,e[0].resize=l,setTimeout(function(){l();n(document).off(".w2overlayHide").on("click.w2overlayHide",s);typeof i.onShow=="function"&&i.onShow()},10),a(),n(this)};n.fn.w2menu=function(t,i){function o(){setTimeout(function(){var t,u;if(n("#w2ui-overlay"+r+" tr.w2ui-selected").removeClass("w2ui-selected"),t=n("#w2ui-overlay"+r+" tr[index="+i.index+"]"),u=n("#w2ui-overlay"+r+" div.menu").scrollTop(),t.addClass("w2ui-selected"),i.tmp&&(i.tmp.contentHeight=n("#w2ui-overlay"+r+" table").height()+(i.search?50:10)),i.tmp&&(i.tmp.contentWidth=n("#w2ui-overlay"+r+" table").width()),n("#w2ui-overlay"+r).length>0&&n("#w2ui-overlay"+r)[0].resize(),t.length>0){var f=t[0].offsetTop-5,o=n("#w2ui-overlay"+r+" div.menu"),e=o.height();n("#w2ui-overlay"+r+" div.menu").scrollTop(u);(f<u||f+t.height()>u+e)&&n("#w2ui-overlay"+r+" div.menu").animate({scrollTop:f-(e-t.height()*2)/2},200,"linear")}},1)}function p(t){var v=this.value,y=t.keyCode,e=!1,h,f,a;switch(y){case 13:n("#w2ui-overlay"+r).remove();n.fn.w2menuClick(t,i.index);break;case 9:case 27:n("#w2ui-overlay"+r).remove();n.fn.w2menuClick(t,-1);break;case 38:for(i.index=w2utils.isInt(i.index)?parseInt(i.index):0,i.index--;i.index>0&&i.items[i.index].hidden;)i.index--;if(i.index===0&&i.items[i.index].hidden)while(i.items[i.index]&&i.items[i.index].hidden)i.index++;i.index<0&&(i.index=0);e=!0;break;case 40:for(i.index=w2utils.isInt(i.index)?parseInt(i.index):0,i.index++;i.index<i.items.length-1&&i.items[i.index].hidden;)i.index++;if(i.index===i.items.length-1&&i.items[i.index].hidden)while(i.items[i.index]&&i.items[i.index].hidden)i.index--;i.index>=i.items.length&&(i.index=i.items.length-1);e=!0}if(!e){for(h=0,f=0;f<i.items.length;f++){var u=i.items[f],c="",l="";["is","begins with"].indexOf(i.match)!==-1&&(c="^");["is","ends with"].indexOf(i.match)!==-1&&(l="$");try{a=new RegExp(c+v+l,"i");u.hidden=a.test(u.text)||u.text==="..."?!1:!0}catch(p){}s.type==="enum"&&n.inArray(u.id,ids)!==-1&&(u.hidden=!0);u.hidden!==!0&&h++}for(i.index=0;i.index<i.items.length-1&&i.items[i.index].hidden;)i.index++;h<=0&&(i.index=-1)}n(s).w2menu("refresh",i);o()}function y(){var t,n,e,u,c,s;if(i.spinner)return'<table class="w2ui-drop-menu"><tbody><tr><td style="padding: 5px 10px 10px 10px; text-align: center">    <div class="w2ui-spinner" style="width: 18px; height: 18px; position: relative; top: 5px;"><\/div>     <div style="display: inline-block; padding: 3px; color: #999;">'+w2utils.lang("Loading...")+"<\/div><\/td><\/tr><\/tbody><\/table>";var h=0,o='<table cellspacing="0" cellpadding="0" class="w2ui-drop-menu"><tbody>',f=null,r=null;for(t=0;t<i.items.length;t++)n=i.items[t],typeof n=="string"?n={id:n,text:n}:(n.text!=null&&n.id==null&&(n.id=n.text),n.text==null&&n.id!=null&&(n.text=n.id),n.caption!=null&&(n.text=n.caption),f=n.img,r=n.icon,f==null&&(f=null),r==null&&(r=null)),["radio","check"].indexOf(i.type)!=-1&&(r=n.checked===!0?"w2ui-icon-check":"w2ui-icon-empty"),n.hidden!==!0&&(e="",u=n.text,typeof i.render=="function"&&(u=i.render(n,i)),f&&(e='<td class="menu-icon"><div class="w2ui-tb-image w2ui-icon '+f+'"><\/div><\/td>'),r&&(e='<td class="menu-icon" align="center"><span class="w2ui-icon '+r+'"><\/span><\/td>'),u==null||u===""||/^-+$/.test(u)?o+='<tr><td colspan="3" style="padding: 6px; pointer-events: none"><div style="border-top: 1px solid silver;"><\/div><\/td><\/tr>':(c=h%2==0?"w2ui-item-even":"w2ui-item-odd",i.altRows!==!0&&(c=""),s=1,e===""&&s++,n.count==null&&n.hotkey==null&&s++,n.tooltip==null&&n.hint!=null&&(n.tooltip=n.hint),o+='<tr index="'+t+'" style="'+(n.style?n.style:"")+'" '+(n.tooltip?'title="'+w2utils.lang(n.tooltip)+'"':"")+'        class="'+c+" "+(i.index===t?"w2ui-selected":"")+" "+(n.disabled===!0?"w2ui-disabled":"")+'"        onmousedown="if ('+(n.disabled===!0?"true":"false")+") return;               jQuery.fn.w2menuDown(event, '"+t+'\');"        onclick="event.stopPropagation();                if ('+(n.disabled===!0?"true":"false")+") return;               jQuery.fn.w2menuClick(event, '"+t+"');\">"+e+'   <td class="menu-text" colspan="'+s+'">'+w2utils.lang(u)+'<\/td>   <td class="menu-count">'+(n.count!=null?"<span>"+n.count+"<\/span>":"")+(n.hotkey!=null?'<span class="hotkey">'+n.hotkey+"<\/span>":"")+"<\/td><\/tr>",h++)),i.items[t]=n;return h===0&&(o+='<tr><td style="padding: 13px; color: #999; text-align: center">'+i.msgNoItems+"<\/div><\/td><\/tr>"),o+"<\/tbody><\/table>"}var f,h,a,c,l,v;i&&typeof i.items=="function"&&(i.items=i.items());var s=this,r="";if(t==="refresh")n("#w2ui-overlay"+r).length>0?(i=n.extend(n.fn.w2menuOptions,i),f=n("#w2ui-overlay"+r+" div.menu").scrollTop(),n("#w2ui-overlay"+r+" div.menu").html(y()),n("#w2ui-overlay"+r+" div.menu").scrollTop(f),o()):n(this).w2menu(i);else if(t==="refresh-index"){var u=n("#w2ui-overlay"+r+" div.menu"),e=u.find("tr[index="+i.index+"]"),f=u.scrollTop();u.find("tr.w2ui-selected").removeClass("w2ui-selected");e.addClass("w2ui-selected");e.length>0&&(h=e[0].offsetTop-5,a=u.height(),u.scrollTop(f),(h<f||h+e.height()>f+a)&&u.animate({scrollTop:h-(a-e.height()*2)/2},200,"linear"));o()}else{if(arguments.length===1?i=t:i.items=t,typeof i!="object"&&(i={}),i=n.extend({},{type:"normal",index:null,items:[],render:null,msgNoItems:"No items",onSelect:null,tmp:{}},i),n.fn.w2menuOptions=i,i.name&&(r="-"+i.name),typeof i.select=="function"&&typeof i.onSelect!="function"&&(i.onSelect=i.select),typeof i.onRender=="function"&&typeof i.render!="function"&&(i.render=i.onRender),n.fn.w2menuClick=function(t,u){var e=!1,f;["radio","check"].indexOf(i.type)!=-1&&(t.shiftKey||t.metaKey||t.ctrlKey)&&(e=!0);typeof i.onSelect=="function"&&setTimeout(function(){i.onSelect({index:u,item:i.items[u],keepOpen:e,originalEvent:t})},10);f=n("#w2ui-overlay"+r);f.removeData("keepOpen");typeof f[0].hide!="function"||e||f[0].hide()},n.fn.w2menuDown=function(t,r){var f=n(t.target).parents("tr"),e=f.find(".w2ui-icon"),u;(i.type=="check"||i.type=="radio")&&(u=i.items[r],u.checked=!u.checked,u.checked?(i.type=="radio"&&e.parents("table").find(".w2ui-icon").removeClass("w2ui-icon-check").addClass("w2ui-icon-empty"),e.removeClass("w2ui-icon-empty").addClass("w2ui-icon-check")):i.type=="check"&&e.removeClass("w2ui-icon-check").addClass("w2ui-icon-empty"));f.parent().find("tr").removeClass("w2ui-selected");f.addClass("w2ui-selected")},c="",i.search)for(c+='<div style="position: absolute; top: 0px; height: 40px; left: 0px; right: 0px; border-bottom: 1px solid silver; background-color: #ECECEC; padding: 8px 5px;">    <div class="w2ui-icon icon-search" style="position: absolute; margin-top: 4px; margin-left: 6px; width: 11px; background-position: left !important;"><\/div>    <input id="menu-search" type="text" style="width: 100%; outline: none; padding-left: 20px;" onclick="event.stopPropagation();"/><\/div>',i.style+=";background-color: #ECECEC",i.index=0,l=0;l<i.items.length;l++)i.items[l].hidden=!1;return c+='<div class="menu" style="position: absolute; top: '+(i.search?40:0)+'px; bottom: 0px; width: 100%;">'+y()+"<\/div>",v=n(this).w2overlay(c,i),setTimeout(function(){n("#w2ui-overlay"+r+" #menu-search").on("keyup",p).on("keydown",function(n){n.keyCode===9&&(n.stopPropagation(),n.preventDefault())});if(i.search){if(["text","password"].indexOf(n(s)[0].type)!=-1||n(s)[0].tagName.toUpperCase()=="TEXTAREA")return;n("#w2ui-overlay"+r+" #menu-search").focus()}o()},200),o(),v}return};n.fn.w2color=function(t,i){function e(n){for(var f,t,o=n.color,e='<div class="w2ui-color" onmousedown="event.stopPropagation(); event.preventDefault()"><table cellspacing="5"><tbody>',i=0;i<r.length-1;i++){for(e+="<tr>",f=0;f<r[i].length;f++)e+='<td>    <div class="color '+(r[i][f]===""?"no-color":"")+'" style="background-color: #'+r[i][f]+';"        name="'+r[i][f]+'" index="'+i+":"+f+'">'+(n.color==r[i][f]?"&#149;":"&#160;")+"    <\/div><\/td>",n.color==r[i][f]&&(u=[i,f]);e+="<\/tr>";i<2&&(e+='<tr><td style="height: 8px" colspan="8"><\/td><\/tr>')}return t=r[r.length-1],e+='<tr><td style="height: 8px" colspan="8"><\/td><\/tr><tr>   <td colspan="4" style="text-align: left"><input placeholder="#FFF000" style="margin-left: 1px; width: 74px" maxlength="7"/><\/td>   <td><div class="color" style="background-color: #'+t[0]+';" name="'+t[0]+'" index="8:0">'+(n.color==t[0]?"&#149;":"&#160;")+'<\/div><\/td>   <td><div class="color" style="background-color: #'+t[1]+';" name="'+t[1]+'" index="8:0">'+(n.color==t[1]?"&#149;":"&#160;")+'<\/div><\/td>   <td><div class="color" style="background-color: #'+t[2]+';" name="'+t[2]+'" index="8:0">'+(n.color==t[2]?"&#149;":"&#160;")+'<\/div><\/td>   <td><div class="color" style="background-color: #'+t[3]+';" name="'+t[3]+'" index="8:0">'+(n.color==t[3]?"&#149;":"&#160;")+'<\/div><\/td><\/tr><tr><td style="height: 4px" colspan="8"><\/td><\/tr>',e+"<\/tbody><\/table><\/div>"}var o=this,f=n(this)[0],u=[-1,-1],r;n.fn.w2colorPalette==null&&(n.fn.w2colorPalette=[["000000","555555","888888","BBBBBB","DDDDDD","EEEEEE","F7F7F7","FFFFFF"],["FF011B","FF9838","FFFD59","01FD55","00FFFE","006CE7","9B24F4","FF21F5"],["FFEAEA","FCEFE1","FCF5E1","EBF7E7","E9F3F5","ECF4FC","EAE6F4","F5E7ED"],["F4CCCC","FCE5CD","FFF2CC","D9EAD3","D0E0E3","CFE2F3","D9D1E9","EAD1DC"],["EA9899","F9CB9C","FEE599","B6D7A8","A2C4C9","9FC5E8","B4A7D6","D5A6BD"],["E06666","F6B26B","FED966","93C47D","76A5AF","6FA8DC","8E7CC3","C27BA0"],["CC0814","E69138","F1C232","6AA84F","45818E","3D85C6","674EA7","A54D79"],["99050C","B45F17","BF901F","37761D","124F5C","0A5394","351C75","741B47"],["F2F2F2","F2F2F2","F2F2F2","F2F2F2","F2F2F2"]]);r=n.fn.w2colorPalette;typeof t=="string"&&(t={color:t,transparent:!0});t.transparent&&r[0][1]=="555555"&&(r[0].splice(1,1),r[0].push(""));t.transparent||r[0][1]=="555555"||(r[0].splice(1,0,"555555"),r[0].pop());t.color&&(t.color=String(t.color).toUpperCase());n("#w2ui-overlay").length===0?n(f).w2overlay(e(t),{onHide:function(){typeof i=="function"&&i(n(f).data("_color"));n(f).removeData("_color")}}):n("#w2ui-overlay .w2ui-color").parent().html(e(t));n("#w2ui-overlay .color").off(".w2color").on("mousedown.w2color",function(t){var i=n(t.originalEvent.target).attr("name");u=n(t.originalEvent.target).attr("index").split(":");n(f).data("_color",i)}).on("mouseup.w2color",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)});n("#w2ui-overlay input").off(".w2color").on("mousedown.w2color",function(t){n("#w2ui-overlay").data("keepOpen",!0);setTimeout(function(){n("#w2ui-overlay").data("keepOpen",!0)},10);t.stopPropagation()}).on("keyup.w2color",function(){this.value!==""&&this.value[0]!=="#"&&(this.value="#"+this.value)}).on("change.w2color",function(){var u=this.value;if(u.substr(0,1)=="#"&&(u=u.substr(1)),u.length!=6){n(this).w2tag("Invalid color.");return}n.fn.w2colorPalette[r.length-1].unshift(u.toUpperCase());n(f).w2color(t,i);setTimeout(function(){n("#w2ui-overlay input")[0].focus()},100)}).w2field("hex");f.nav=function(t){switch(t){case"up":u[0]--;break;case"down":u[0]++;break;case"right":u[1]++;break;case"left":u[1]--}return u[0]<0&&(u[0]=0),u[0]>r.length-2&&(u[0]=r.length-2),u[1]<0&&(u[1]=0),u[1]>r[0].length-1&&(u[1]=r[0].length-1),color=r[u[0]][u[1]],n(f).data("_color",color),color}}}(jQuery),function(n){var t=function(t){this.name=null;this.box=null;this.header="";this.url="";this.routeData={};this.columns=[];this.columnGroups=[];this.records=[];this.summary=[];this.searches=[];this.searchData=[];this.sortData=[];this.postData={};this.httpHeaders={};this.toolbar={};this.stateId=null;this.show={header:!1,toolbar:!1,footer:!1,columnHeaders:!0,lineNumbers:!1,expandColumn:!1,selectColumn:!1,emptyRecords:!0,toolbarReload:!1,toolbarColumns:!1,toolbarSearch:!0,toolbarInput:!0,toolbarAdd:!1,toolbarEdit:!1,toolbarDelete:!1,toolbarSave:!1,searchAll:!0,statusRange:!0,statusBuffered:!1,statusRecordID:!0,statusSelection:!0,statusResponse:!0,statusSort:!1,statusSearch:!1,recordTitles:!0,selectionBorder:!0,skipRecords:!0,saveRestoreState:!0};this.hasFocus=!1;this.autoLoad=!0;this.fixedBody=!0;this.recordHeight=24;this.lineNumberWidth=null;this.vs_start=150;this.vs_extra=15;this.keyboard=!0;this.selectType="row";this.multiSearch=!0;this.multiSelect=!0;this.multiSort=!0;this.reorderColumns=!1;this.reorderRows=!1;this.markSearch=!0;this.columnTooltip="normal";this.disableCVS=!1;this.textSearch="begins";this.total=0;this.limit=100;this.offset=0;this.style="";this.ranges=[];this.menu=[];this.method=null;this.recid=null;this.parser=null;this.last={field:"",caption:"",logic:"OR",search:"",searchIds:[],selection:{indexes:[],columns:{}},multi:!1,scrollTop:0,scrollLeft:0,colStart:0,colEnd:0,sortData:null,sortCount:0,xhr:null,range_start:null,range_end:null,sel_ind:null,sel_col:null,sel_type:null,edit_col:null,isSafari:/^((?!chrome|android).)*safari/i.test(navigator.userAgent)};n.extend(!0,this,w2obj.grid,t)};n.fn.w2grid=function(i){var r,e,c,f,h,w,b,o;if(n.isPlainObject(i)){if(!w2utils.checkName(i,"w2grid"))return;var l=i.columns,a=i.columnGroups,s=i.records,v=i.searches,y=i.searchData,p=i.sortData,k=i.postData,d=i.httpHeaders,g=i.toolbar,u=new t(i);if(n.extend(u,{postData:{},httpHeaders:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]}),u.onExpand!=null&&(u.show.expandColumn=!0),n.extend(!0,u.toolbar,g),l)for(r=0;r<l.length;r++)u.columns[r]=n.extend(!0,{},l[r]);if(a)for(r=0;r<a.length;r++)u.columnGroups[r]=n.extend(!0,{},a[r]);if(v)for(r=0;r<v.length;r++)u.searches[r]=n.extend(!0,{},v[r]);if(y)for(r=0;r<y.length;r++)u.searchData[r]=n.extend(!0,{},y[r]);if(p)for(r=0;r<p.length;r++)u.sortData[r]=n.extend(!0,{},p[r]);if(u.postData=n.extend(!0,{},k),u.httpHeaders=n.extend(!0,{},d),s)for(e=0;e<s.length;e++){if(s[e].recid==null&&s[e][u.recid]==null){console.log("ERROR: Cannot add records without recid. (obj: "+u.name+")");return}u.records[e]=n.extend(!0,{},s[e])}for(c=0;c<u.columns.length;c++)(f=u.columns[c],h=f.searchable,h!=null&&h!==!1&&u.getSearch(f.field)==null)&&(n.isPlainObject(h)?u.addSearch(n.extend({field:f.field,caption:f.caption,type:"text"},h)):(w=f.searchable,b="",f.searchable===!0&&(w="text",b='size="20"'),u.addSearch({field:f.field,caption:f.caption,type:w,attr:b})));return u.initToolbar(),n(this).length!==0&&u.render(n(this)[0]),w2ui[u.name]=u,u}return(o=w2ui[n(this).attr("name")],!o)?null:arguments.length>0?(o[i]&&o[i].apply(o,Array.prototype.slice.call(arguments,1)),this):o};t.prototype={msgDelete:"Are you sure you want to delete selected records?",msgNotJSON:"Returned data is not in valid JSON format.",msgAJAXerror:"AJAX error. See console for more details.",msgRefresh:"Refreshing...",msgNeedReload:"Your remote data source record count has changed, reloading from the first record.",msgEmpty:"",buttons:{reload:{type:"button",id:"w2ui-reload",icon:"w2ui-icon-reload",tooltip:"Reload data in the list"},columns:{type:"drop",id:"w2ui-column-on-off",icon:"w2ui-icon-columns",tooltip:"Show/hide columns",arrow:!1,html:""},search:{type:"html",id:"w2ui-search",html:"<div class=\"w2ui-icon icon-search-down w2ui-search-down\" onclick=\"var obj = w2ui[jQuery(this).parents('div.w2ui-grid').attr('name')]; obj.searchShowFields();\"><\/div>"},"search-go":{type:"drop",id:"w2ui-search-advanced",icon:"w2ui-icon-search",text:"Search",tooltip:"Open Search Fields"},add:{type:"button",id:"w2ui-add",text:"Add New",tooltip:"Add new record",icon:"w2ui-icon-plus"},edit:{type:"button",id:"w2ui-edit",text:"Edit",tooltip:"Edit selected record",icon:"w2ui-icon-pencil",disabled:!0},"delete":{type:"button",id:"w2ui-delete",text:"Delete",tooltip:"Delete selected records",icon:"w2ui-icon-cross",disabled:!0},save:{type:"button",id:"w2ui-save",text:"Save",tooltip:"Save changed records",icon:"w2ui-icon-check"}},operators:{text:["is","begins","contains","ends"],number:["is","between",{oper:"less",text:"less than"},{oper:"more",text:"more than"}],date:["is","between",{oper:"less",text:"before"},{oper:"more",text:"after"}],list:["is"],hex:["is","between"],color:["is","begins","contains","ends"],"enum":["in","not in"]},operatorsMap:{text:"text",int:"number",float:"number",money:"number",currency:"number",percent:"number",hex:"hex",alphanumeric:"text",color:"color",date:"date",time:"date",datetime:"date",list:"list",combo:"text","enum":"enum",file:"enum",select:"list",radio:"list",checkbox:"list",toggle:"list"},onAdd:null,onEdit:null,onRequest:null,onLoad:null,onDelete:null,onSave:null,onSelect:null,onUnselect:null,onClick:null,onDblClick:null,onContextMenu:null,onMenuClick:null,onColumnClick:null,onColumnDblClick:null,onColumnResize:null,onSort:null,onSearch:null,onSearchOpen:null,onChange:null,onRestore:null,onExpand:null,onCollapse:null,onError:null,onKeydown:null,onToolbar:null,onColumnOnOff:null,onCopy:null,onPaste:null,onSelectionExtend:null,onEditField:null,onRender:null,onRefresh:null,onReload:null,onResize:null,onDestroy:null,onStateSave:null,onStateRestore:null,onFocus:null,onBlur:null,onReorderRow:null,add:function(t,i){var u,f,r,e;for(n.isArray(t)||(t=[t]),u=0,f=0;f<t.length;f++){if(r=t[f],r.recid==null&&r[this.recid]==null){console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");continue}r.w2ui&&r.w2ui.summary===!0?i?this.summary.unshift(r):this.summary.push(r):i?this.records.unshift(r):this.records.push(r);u++}return(e=typeof this.url!="object"?this.url:this.url.get,!e)?(this.total=this.records.length,this.localSort(!1,!0),this.localSearch(),this.refreshBody(),this.resizeRecords(),u):(this.refresh(),u)},find:function(n,t){var e,o,r,u,i,f;n==null&&(n={});e=[];o=!1;for(i in n)String(i).indexOf(".")!=-1&&(o=!0);for(r=0;r<this.records.length;r++){u=!0;for(i in n)f=this.records[r][i],o&&String(i).indexOf(".")!=-1&&(f=this.parseField(this.records[r],i)),n[i]=="not-null"?(f==null||f==="")&&(u=!1):n[i]!=f&&(u=!1);u&&t!==!0&&e.push(this.records[r].recid);u&&t===!0&&e.push(r)}return e},set:function(t,i,r){var f,u,e;if(typeof t=="object"&&(r=i,i=t,t=null),t==null){for(f=0;f<this.records.length;f++)n.extend(!0,this.records[f],i);r!==!0&&this.refresh()}else{if(u=this.get(t,!0),u==null)return!1;e=this.records[u]&&this.records[u].recid==t?!1:!0;e?n.extend(!0,this.summary[u],i):n.extend(!0,this.records[u],i);r!==!0&&this.refreshRow(t,u)}return!0},get:function(t,i){var u,r;if(n.isArray(t)){for(u=[],r=0;r<this.records.length;r++)n.inArray(this.records[r].recid,t)!=-1&&(i===!0?u.push(r):u.push(this.records[r]));for(r=0;r<this.summary.length;r++)n.inArray(this.summary[r].recid,t)!=-1&&(i===!0?u.push(r):u.push(this.summary[r]));return u}for(r=0;r<this.records.length;r++)if(this.records[r].recid==t)return i===!0?r:this.records[r];for(r=0;r<this.summary.length;r++)if(this.summary[r].recid==t)return i===!0?r:this.summary[r];return null},remove:function(){for(var n,r,i=0,t=0;t<arguments.length;t++){for(n=this.records.length-1;n>=0;n--)this.records[n].recid==arguments[t]&&(this.records.splice(n,1),i++);for(n=this.summary.length-1;n>=0;n--)this.summary[n].recid==arguments[t]&&(this.summary.splice(n,1),i++)}return r=typeof this.url!="object"?this.url:this.url.get,r||(this.localSort(!1,!0),this.localSearch()),this.refresh(),i},addColumn:function(t,i){var e=0,r,u,f;for(arguments.length==1?(i=t,t=this.columns.length):(typeof t=="string"&&(t=this.getColumn(t,!0)),t==null&&(t=this.columns.length)),n.isArray(i)||(i=[i]),r=0;r<i.length;r++)this.columns.splice(t,0,i[r]),i[r].searchable&&(u=i[r].searchable,f="",i[r].searchable===!0&&(u="text",f='size="20"'),this.addSearch({field:i[r].field,caption:i[r].caption,type:u,attr:f})),t++,e++;return this.refresh(),e},removeColumn:function(){for(var n,i=0,t=0;t<arguments.length;t++)for(n=this.columns.length-1;n>=0;n--)this.columns[n].field==arguments[t]&&(this.columns[n].searchable&&this.removeSearch(arguments[t]),this.columns.splice(n,1),i++);return this.refresh(),i},getColumn:function(n,t){var r,i;if(arguments.length===0){for(r=[],i=0;i<this.columns.length;i++)r.push(this.columns[i].field);return r}for(i=0;i<this.columns.length;i++)if(this.columns[i].field==n)return t===!0?i:this.columns[i];return null},toggleColumn:function(){for(var n,t,r=0,i=0;i<arguments.length;i++)for(n=this.columns.length-1;n>=0;n--)t=this.columns[n],t.field==arguments[i]&&(t.hidden=!t.hidden,r++);return this.refreshBody(),this.resizeRecords(),r},showColumn:function(){for(var t,n,r=0,i=0;i<arguments.length;i++)for(t=this.columns.length-1;t>=0;t--)n=this.columns[t],n.gridMinWidth&&delete n.gridMinWidth,n.field==arguments[i]&&n.hidden!==!1&&(n.hidden=!1,r++);return this.refreshBody(),this.resizeRecords(),r},hideColumn:function(){for(var n,t,r=0,i=0;i<arguments.length;i++)for(n=this.columns.length-1;n>=0;n--)t=this.columns[n],t.field==arguments[i]&&t.hidden!==!0&&(t.hidden=!0,r++);return this.refreshBody(),this.resizeRecords(),r},addSearch:function(t,i){var u=0,r;for(arguments.length==1?(i=t,t=this.searches.length):(typeof t=="string"&&(t=this.getSearch(t,!0)),t==null&&(t=this.searches.length)),n.isArray(i)||(i=[i]),r=0;r<i.length;r++)this.searches.splice(t,0,i[r]),t++,u++;return this.searchClose(),u},removeSearch:function(){for(var n,i=0,t=0;t<arguments.length;t++)for(n=this.searches.length-1;n>=0;n--)this.searches[n].field==arguments[t]&&(this.searches.splice(n,1),i++);return this.searchClose(),i},getSearch:function(n,t){var r,i;if(arguments.length===0){for(r=[],i=0;i<this.searches.length;i++)r.push(this.searches[i].field);return r}for(i=0;i<this.searches.length;i++)if(this.searches[i].field==n)return t===!0?i:this.searches[i];return null},toggleSearch:function(){for(var n,i=0,t=0;t<arguments.length;t++)for(n=this.searches.length-1;n>=0;n--)this.searches[n].field==arguments[t]&&(this.searches[n].hidden=!this.searches[n].hidden,i++);return this.searchClose(),i},showSearch:function(){for(var n,i=0,t=0;t<arguments.length;t++)for(n=this.searches.length-1;n>=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!1&&(this.searches[n].hidden=!1,i++);return this.searchClose(),i},hideSearch:function(){for(var n,i=0,t=0;t<arguments.length;t++)for(n=this.searches.length-1;n>=0;n--)this.searches[n].field==arguments[t]&&this.searches[n].hidden!==!0&&(this.searches[n].hidden=!0,i++);return this.searchClose(),i},getSearchData:function(n){for(var t=0;t<this.searchData.length;t++)if(this.searchData[t].field==n)return this.searchData[t];return null},localSort:function(t,i){function l(){for(var n,t=0;t<r.records.length;t++)n=r.records[t],n.w2ui&&n.w2ui.parent_recid!=null&&(n.w2ui._path=o(n))}function a(){for(var t,n=0;n<r.records.length;n++)t=r.records[n],t.w2ui&&t.w2ui.parent_recid!=null&&(t.w2ui._path=null)}function v(n,t){var i,r,u,f;if((!n.w2ui||n.w2ui.parent_recid==null)&&(!t.w2ui||t.w2ui.parent_recid==null))return s(n,t);for(i=o(n),r=o(t),u=0;u<Math.min(i.length,r.length);u++)if(f=s(i[u],r[u]),f!==0)return f;return i.length>r.length?1:i.length<r.length?-1:(console.log("ERROR: two paths should not be equal."),0)}function o(n){if(!n.w2ui||n.w2ui.parent_recid==null)return[n];if(n.w2ui._path)return n.w2ui._path;var t=r.get(n.w2ui.parent_recid);return t?o(t).concat(n):(console.log("ERROR: no parent record: "+n.w2ui.parent_recid),[n])}function s(t,i){var u,f,e,o,c,s;if(t===i)return 0;for(u=0;u<r.sortData.length;u++)if(f=r.sortData[u].field,r.sortData[u].field_&&(f=r.sortData[u].field_),e=t[f],o=i[f],String(f).indexOf(".")!=-1&&(e=r.parseField(t,f),o=r.parseField(i,f)),c=r.getColumn(f),c&&c.editable!=null&&(n.isPlainObject(e)&&e.text&&(e=e.text),n.isPlainObject(o)&&o.text&&(o=o.text)),s=h(e,o,u,r.sortData[u].direction),s!==0)return s;return(s=h(t.recid,i.recid,-1,"asc"),s!==0)?s:0}function h(t,i,r,u){var f,e;return t===i?0:(t==null||t==="")&&i!=null&&i!==""?1:t!=null&&t!==""&&(i==null||i==="")?-1:(f=u=="asc"?1:-1,typeof t!=typeof i)?typeof t>typeof i?f:-f:t.constructor.name!=i.constructor.name?t.constructor.name>i.constructor.name?f:-f:(t&&typeof t=="object"&&(t=t.valueOf()),i&&typeof i=="object"&&(i=i.valueOf()),e={}.toString,t&&typeof t=="object"&&t.toString!=e&&(t=String(t)),i&&typeof i=="object"&&i.toString!=e&&(i=String(i)),typeof t=="string"&&(t=n.trim(t.toLowerCase())),typeof i=="string"&&(i=n.trim(i.toLowerCase())),t>i)?f:t<i?-f:0}var c=typeof this.url!="object"?this.url:this.url.get,e,r,f,u;if(c){console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");return}if(!n.isEmptyObject(this.sortData)){for(e=(new Date).getTime(),r=this,r.selectionSave(),r.prepareData(),i||r.reset(),f=0;f<this.sortData.length;f++){if(u=this.getColumn(this.sortData[f].field),!u)return;typeof u.render=="string"&&(["date","age"].indexOf(u.render.split(":")[0])!=-1&&(this.sortData[f].field_=u.field+"_"),["time"].indexOf(u.render.split(":")[0])!=-1&&(this.sortData[f].field_=u.field+"_"))}return l(),this.records.sort(function(n,t){return v(n,t)}),a(),r.selectionRestore(i),e=(new Date).getTime()-e,t!==!0&&r.show.statusSort&&setTimeout(function(){r.status(w2utils.lang("Sorting took")+" "+e/1e3+" "+w2utils.lang("sec"))},10),e}},localSearch:function(t){function h(t){for(var o,r,a,f,u,s,c,p,v,w,e=0,y=0;y<i.searchData.length;y++)if(o=i.searchData[y],r=i.getSearch(o.field),o!=null){r==null&&(r={field:o.field,type:o.type});a=i.parseField(t,r.field);f=a!==null&&a!==undefined&&(typeof a!="object"||a.toString!=l)?String(a).toLowerCase():"";o.value!=null&&(n.isArray(o.value)?(u=o.value[0],s=o.value[1]):u=String(o.value).toLowerCase());switch(o.operator){case"is":if(i.parseField(t,r.field)==o.value)e++;else if(r.type=="date"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDate(c,"yyyy-mm-dd"),u=w2utils.formatDate(w2utils.isDate(u,w2utils.settings.dateFormat,!0),"yyyy-mm-dd");f==u&&e++}else if(r.type=="time"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatTime(c,"hh24:mi"),u=w2utils.formatTime(u,"hh24:mi");f==u&&e++}else if(r.type=="datetime"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDateTime(c,"yyyy-mm-dd|hh24:mm:ss"),u=w2utils.formatDateTime(w2utils.isDateTime(u,w2utils.settings.datetimeFormat,!0),"yyyy-mm-dd|hh24:mm:ss");f==u&&e++}break;case"between":if(["int","float","money","currency","percent"].indexOf(r.type)!=-1)parseFloat(i.parseField(t,r.field))>=parseFloat(u)&&parseFloat(i.parseField(t,r.field))<=parseFloat(s)&&e++;else if(r.type=="date"){var f=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),u=w2utils.isDate(u,w2utils.settings.dateFormat,!0),s=w2utils.isDate(s,w2utils.settings.dateFormat,!0);s!=null&&(s=new Date(s.getTime()+864e5));f>=u&&f<s&&e++}else if(r.type=="time"){var f=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),u=w2utils.isTime(u,!0),s=w2utils.isTime(s,!0);u=(new Date).setHours(u.hours,u.minutes,u.seconds?u.seconds:0,0);s=(new Date).setHours(s.hours,s.minutes,s.seconds?s.seconds:0,0);f>=u&&f<s&&e++}else if(r.type=="datetime"){var f=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),u=w2utils.isDateTime(u,w2utils.settings.datetimeFormat,!0),s=w2utils.isDateTime(s,w2utils.settings.datetimeFormat,!0);s&&(s=new Date(s.getTime()+864e5));f>=u&&f<s&&e++}break;case"less":if(["int","float","money","currency","percent"].indexOf(r.type)!=-1)parseFloat(i.parseField(t,r.field))<=parseFloat(o.value)&&e++;else if(r.type=="date"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDate(c,"yyyy-mm-dd"),u=w2utils.formatDate(w2utils.isDate(u,w2utils.settings.dateFormat,!0),"yyyy-mm-dd");f<=u&&e++}else if(r.type=="time"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatTime(c,"hh24:mi"),u=w2utils.formatTime(u,"hh24:mi");f<=u&&e++}else if(r.type=="datetime"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDateTime(c,"yyyy-mm-dd|hh24:mm:ss"),u=w2utils.formatDateTime(w2utils.isDateTime(u,w2utils.settings.datetimeFormat,!0),"yyyy-mm-dd|hh24:mm:ss");f.length==u.length&&f<=u&&e++}break;case"more":if(["int","float","money","currency","percent"].indexOf(r.type)!=-1)parseFloat(i.parseField(t,r.field))>=parseFloat(o.value)&&e++;else if(r.type=="date"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDate(c,"yyyy-mm-dd"),u=w2utils.formatDate(w2utils.isDate(u,w2utils.settings.dateFormat,!0),"yyyy-mm-dd");f>=u&&e++}else if(r.type=="time"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatTime(c,"hh24:mi"),u=w2utils.formatTime(u,"hh24:mi");f>=u&&e++}else if(r.type=="datetime"){var c=i.parseField(t,r.field+"_")instanceof Date?i.parseField(t,r.field+"_"):i.parseField(t,r.field),f=w2utils.formatDateTime(c,"yyyy-mm-dd|hh24:mm:ss"),u=w2utils.formatDateTime(w2utils.isDateTime(u,w2utils.settings.datetimeFormat,!0),"yyyy-mm-dd|hh24:mm:ss");f.length==u.length&&f>=u&&e++}break;case"in":c=o.value;o.svalue&&(c=o.svalue);c.indexOf(w2utils.isFloat(f)?parseFloat(f):f)!==-1&&e++;c.indexOf(w2utils.isFloat(a)?parseFloat(a):a)!==-1&&e++;break;case"not in":c=o.value;o.svalue&&(c=o.svalue);c.indexOf(w2utils.isFloat(f)?parseFloat(f):f)==-1&&e++;c.indexOf(w2utils.isFloat(a)?parseFloat(a):a)==-1&&e++;break;case"begins":case"begins with":f.indexOf(u)===0&&e++;break;case"contains":f.indexOf(u)>=0&&e++;break;case"null":i.parseField(t,r.field)==null&&e++;break;case"not null":i.parseField(t,r.field)!=null&&e++;break;case"ends":case"ends with":p=f.lastIndexOf(u);p!==-1&&p==f.length-u.length&&e++}}if(i.last.logic=="OR"&&e!==0||i.last.logic=="AND"&&e==i.searchData.length)return!0;if(t.w2ui&&t.w2ui.children&&t.w2ui.expanded!==!0)for(v=0;v<t.w2ui.children.length;v++)if(w=t.w2ui.children[v],h(w))return!0;return!1}function c(t){var r,u;t!==undefined&&(o[t]||(o[t]=!0,r=i.get(t,!0),r!=null)&&n.inArray(r,i.last.searchIds)==-1&&(u=i.records[r],u&&u.w2ui&&c(u.w2ui.parent_recid),i.last.searchIds.push(r)))}var e=typeof this.url!="object"?this.url:this.url.get,r,u,s;if(e){console.log("ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.");return}var f=(new Date).getTime(),i=this,l={}.toString,o={};if(this.total=this.records.length,this.last.searchIds=[],this.prepareData(),this.searchData.length>0&&!e){for(this.total=0,r=0;r<this.records.length;r++)u=this.records[r],s=h(u),s&&(u&&u.w2ui&&c(u.w2ui.parent_recid),this.last.searchIds.push(r));this.total=this.last.searchIds.length}return f=(new Date).getTime()-f,t!==!0&&i.show.statusSearch&&setTimeout(function(){i.status(w2utils.lang("Search took")+" "+f/1e3+" "+w2utils.lang("sec"))},10),f},getRangeData:function(n,t){var o=this.get(n[0].recid,!0),h=this.get(n[1].recid,!0),s=n[0].column,c=n[1].column,i=[],r,f,u,e;if(s==c)for(r=o;r<=h;r++)f=this.records[r],e=f[this.columns[s].field]||null,t!==!0?i.push(e):i.push({data:e,column:s,index:r,record:f});else if(o==h)for(f=this.records[o],u=s;u<=c;u++)e=f[this.columns[u].field]||null,t!==!0?i.push(e):i.push({data:e,column:u,index:o,record:f});else for(r=o;r<=h;r++)for(f=this.records[r],i.push([]),u=s;u<=c;u++)e=f[this.columns[u].field],t!==!0?i[i.length-1].push(e):i[i.length-1].push({data:e,column:u,index:r,record:f});return i},addRange:function(t){var s=0,i,r,u,e,h,o,f;if(this.selectType=="row")return s;for(n.isArray(t)||(t=[t]),i=0;i<t.length;i++){if(typeof t[i]!="object"&&(t[i]={name:"selection"}),t[i].name=="selection"){if(this.show.selectionBorder===!1)continue;if(r=this.getSelection(),r.length===0){this.removeRange("selection");continue}else u=r[0],e=r[r.length-1]}else u=t[i].range[0],e=t[i].range[1];if(u){for(h={name:t[i].name,range:[{recid:u.recid,column:u.column},{recid:e.recid,column:e.column}],style:t[i].style||""},o=!1,f=0;f<this.ranges.length;f++)if(this.ranges[f].name==t[i].name){o=f;break}o!==!1?this.ranges[o]=h:this.ranges.push(h);s++}}return this.refreshRanges(),s},removeRange:function(){for(var i,t,u=0,r=0;r<arguments.length;r++)for(i=arguments[r],n("#grid_"+this.name+"_"+i).remove(),n("#grid_"+this.name+"_f"+i).remove(),t=this.ranges.length-1;t>=0;t--)this.ranges[t].name==i&&(this.ranges.splice(t,1),u++);return u},refreshRanges:function(){function ot(t){var i=f.getSelection();f.last.move={type:"expand",x:t.screenX,y:t.screenY,divX:0,divY:0,recid:i[0].recid,column:i[0].column,originalRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}],newRange:[{recid:i[0].recid,column:i[0].column},{recid:i[i.length-1].recid,column:i[i.length-1].column}]};n(document).off("mousemove",w).on("mousemove",w);n(document).off("mouseup",b).on("mouseup",b);t.preventDefault()}function w(t){var i=f.last.move,u,e,r,o;if(i&&i.type=="expand"&&(i.divX=t.screenX-i.x,i.divY=t.screenY-i.y,r=t.originalEvent.target,r.tagName.toUpperCase()!="TD"&&(r=n(r).parents("td")[0]),n(r).attr("col")!=null&&(e=parseInt(n(r).attr("col"))),r=n(r).parents("tr")[0],u=n(r).attr("recid"),i.newRange[1].recid!=u||i.newRange[1].column!=e)){if(o=n.extend({},i.newRange),i.newRange=[{recid:i.recid,column:i.column},{recid:u,column:e}],c=f.trigger(n.extend(c,{originalRange:i.originalRange,newRange:i.newRange})),c.isCancelled===!0){i.newRange=o;c.newRange=o;return}f.removeRange("grid-selection-expand");f.addRange({name:"grid-selection-expand",range:c.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"})}}function b(){f.removeRange("grid-selection-expand");delete f.last.move;n(document).off("mousemove",w);n(document).off("mouseup",b);f.trigger(n.extend(c,{phase:"after"}))}var v,r,l,a,c;if(this.ranges.length!==0){var f=this,rt=(new Date).getTime(),y=n("#grid_"+this.name+"_frecords"),p=n("#grid_"+this.name+"_records");for(v=0;v<this.ranges.length;v++){var u=this.ranges[v],t=u.range[0],i=u.range[1];t.index==null&&(t.index=this.get(t.recid,!0));i.index==null&&(i.index=this.get(i.recid,!0));var e=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.recid)+' td[col="'+t.column+'"]'),s=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(i.recid)+' td[col="'+i.column+'"]'),h=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t.recid)+' td[col="'+t.column+'"]'),o=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(i.recid)+' td[col="'+i.column+'"]'),k=i.column;t.column<this.last.colStart&&i.column>this.last.colStart&&(e=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.recid)+' td[col="start"]'));t.column<this.last.colEnd&&i.column>this.last.colEnd&&(k='"end"',s=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(i.recid)+' td[col="end"]'));var d=parseInt(n("#grid_"+this.name+"_rec_top").next().attr("index")),g=parseInt(n("#grid_"+this.name+"_rec_bottom").prev().attr("index")),nt=parseInt(n("#grid_"+this.name+"_frec_top").next().attr("index")),tt=parseInt(n("#grid_"+this.name+"_frec_bottom").prev().attr("index"));e.length===0&&t.index<d&&i.index>d&&(e=n("#grid_"+this.name+"_rec_top").next().find("td[col="+t.column+"]"));s.length===0&&i.index>g&&t.index<g&&(s=n("#grid_"+this.name+"_rec_bottom").prev().find("td[col="+k+"]"));h.length===0&&t.index<nt&&i.index>nt&&(h=n("#grid_"+this.name+"_frec_top").next().find("td[col="+t.column+"]"));o.length===0&&i.index>tt&&t.index<tt&&(o=n("#grid_"+this.name+"_frec_bottom").prev().find("td[col="+i.column+"]"));var ut=n(this.box).find("#grid_"+this.name+"_editable"),it=ut.find(".w2ui-input"),ft=it.attr("recid"),et=it.attr("column");(u.name!="selection"||u.range[0].recid!=ft||u.range[0].column!=et)&&(r=n("#grid_"+this.name+"_f"+u.name),h.length>0||o.length>0?(r.length===0?(y.append('<div id="grid_'+this.name+"_f"+u.name+'" class="w2ui-selection" style="'+u.style+'">'+(u.name=="selection"?'<div id="grid_'+this.name+'_resizer" class="w2ui-selection-resizer"><\/div>':"")+"<\/div>"),r=n("#grid_"+this.name+"_f"+u.name)):(r.attr("style",u.style),r.find(".w2ui-selection-resizer").show()),o.length===0&&(o=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(i.recid)+" td:last-child"),o.length===0&&(o=n("#grid_"+this.name+"_frec_bottom td:first-child")),r.css("border-right","0px"),r.find(".w2ui-selection-resizer").hide()),t.recid!=null&&i.recid!=null&&h.length>0&&o.length>0?(l=h.position().left-1+y.scrollLeft(),a=h.position().top-1+y.scrollTop(),r.show().css({left:(l>0?l:0)+"px",top:(a>0?a:0)+"px",width:o.position().left-h.position().left+o.width()+3+"px",height:o.position().top-h.position().top+o.height()+3+"px"})):r.hide()):r.hide(),r=n("#grid_"+this.name+"_"+u.name),e.length>0||s.length>0?(r.length===0?(p.append('<div id="grid_'+this.name+"_"+u.name+'" class="w2ui-selection" style="'+u.style+'">'+(u.name=="selection"?'<div id="grid_'+this.name+'_resizer" class="w2ui-selection-resizer"><\/div>':"")+"<\/div>"),r=n("#grid_"+this.name+"_"+u.name)):r.attr("style",u.style),e.length===0&&(e=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t.recid)+" td:first-child"),e.length===0&&(e=n("#grid_"+this.name+"_rec_top td:first-child"))),o.length!==0&&r.css("border-left","0px"),t.recid!=null&&i.recid!=null&&e.length>0&&s.length>0?(l=e.position().left-1+p.scrollLeft(),a=e.position().top-1+p.scrollTop(),r.show().css({left:(l>0?l:0)+"px",top:(a>0?a:0)+"px",width:s.position().left-e.position().left+s.width()+3+"px",height:s.position().top-e.position().top+s.height()+3+"px"})):r.hide()):r.hide())}n(this.box).find(".w2ui-selection-resizer").off("mousedown").on("mousedown",ot).off("dblclick").on("dblclick",function(t){var i=f.trigger({phase:"before",type:"resizerDblClick",target:f.name,originalEvent:t});i.isCancelled!==!0&&f.trigger(n.extend(i,{phase:"after"}))});return c={phase:"before",type:"selectionExtend",target:f.name,originalRange:null,newRange:null},(new Date).getTime()-rt}},select:function(){var h,b,f,r,c,l,a,t,i,u,e,v,s,y,p,k,d;if(arguments.length===0)return 0;var g=(new Date).getTime(),w=0,o=this.last.selection;if(this.multiSelect||this.selectNone(),h={phase:"before",type:"select",target:this.name},arguments.length==1?(h.multiple=!1,n.isPlainObject(arguments[0])?(h.recid=arguments[0].recid,h.column=arguments[0].column):h.recid=arguments[0]):(h.multiple=!0,h.recids=Array.prototype.slice.call(arguments,0)),b=this.trigger(h),b.isCancelled===!0)return 0;if(this.selectType=="row"){for(r=0;r<arguments.length;r++)if((t=typeof arguments[r]=="object"?arguments[r].recid:arguments[r],i=this.get(t,!0),i!=null)&&(u=null,e=null,(this.searchData.length!==0||i+1>=this.last.range_start&&i+1<=this.last.range_end)&&(u=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)),e=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t))),this.selectType=="row")){if(o.indexes.indexOf(i)!=-1)continue;o.indexes.push(i);u&&e&&(u.addClass("w2ui-selected").data("selected","yes").find(".w2ui-col-number").addClass("w2ui-row-selected"),e.addClass("w2ui-selected").data("selected","yes").find(".w2ui-col-number").addClass("w2ui-row-selected"),u.find(".w2ui-grid-select-check").prop("checked",!0));w++}}else{for(f={},r=0;r<arguments.length;r++)if(t=typeof arguments[r]=="object"?arguments[r].recid:arguments[r],c=typeof arguments[r]=="object"?arguments[r].column:null,f[t]=f[t]||[],n.isArray(c))f[t]=c;else if(w2utils.isInt(c))f[t].push(c);else for(l=0;l<this.columns.length;l++)this.columns[l].hidden||f[t].push(parseInt(l));a=[];for(t in f)if(i=this.get(t,!0),i!=null){for(u=null,e=null,i+1>=this.last.range_start&&i+1<=this.last.range_end&&(u=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)),e=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t))),v=o.columns[i]||[],o.indexes.indexOf(i)==-1&&o.indexes.push(i),s=0;s<f[t].length;s++)v.indexOf(f[t][s])==-1&&v.push(f[t][s]);for(v.sort(function(n,t){return n-t}),s=0;s<f[t].length;s++)y=f[t][s],a.indexOf(y)==-1&&a.push(y),u&&(u.find("#grid_"+this.name+"_data_"+i+"_"+y).addClass("w2ui-selected"),u.find(".w2ui-col-number").addClass("w2ui-row-selected"),u.data("selected","yes"),u.find(".w2ui-grid-select-check").prop("checked",!0)),e&&(e.find("#grid_"+this.name+"_data_"+i+"_"+y).addClass("w2ui-selected"),e.find(".w2ui-col-number").addClass("w2ui-row-selected"),e.data("selected","yes"),e.find(".w2ui-grid-select-check").prop("checked",!0)),w++;o.columns[i]=v}for(p=0;p<a.length;p++)n(this.box).find("#grid_"+this.name+"_column_"+a[p]+" .w2ui-col-header").addClass("w2ui-col-selected")}return o.indexes.sort(function(n,t){return n-t}),k=this.records.length>0&&o.indexes.length==this.records.length,d=o.indexes.length>0&&this.searchData.length!==0&&o.indexes.length==this.last.searchIds.length,k||d?n("#grid_"+this.name+"_check_all").prop("checked",!0):n("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),this.trigger(n.extend(b,{phase:"after"})),w},unselect:function(){for(var t,a,r,v,s,h,u,b,k,l=0,i=this.last.selection,e=0;e<arguments.length;e++)if(t=typeof arguments[e]=="object"?arguments[e].recid:arguments[e],a=this.get(t),a!=null){var o=this.get(a.recid,!0),f=n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)),c=n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t));if(this.selectType=="row"){if(i.indexes.indexOf(o)==-1)continue;if(h=this.trigger({phase:"before",type:"unselect",target:this.name,recid:t,index:o}),h.isCancelled===!0)continue;i.indexes.splice(i.indexes.indexOf(o),1);f.removeClass("w2ui-selected w2ui-inactive").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected");c.removeClass("w2ui-selected w2ui-inactive").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected");f.length!=0&&(f[0].style.cssText="height: "+this.recordHeight+"px; "+f.attr("custom_style"),c[0].style.cssText="height: "+this.recordHeight+"px; "+c.attr("custom_style"));f.find(".w2ui-grid-select-check").prop("checked",!1);l++}else{if(r=arguments[e].column,!w2utils.isInt(r)){for(v=[],u=0;u<this.columns.length;u++)this.columns[u].hidden||v.push({recid:t,column:u});return this.unselect.apply(this,v)}if(s=i.columns[o],!n.isArray(s)||s.indexOf(r)==-1)continue;if(h=this.trigger({phase:"before",type:"unselect",target:this.name,recid:t,column:r}),h.isCancelled===!0)continue;s.splice(s.indexOf(r),1);n("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)).find(" > td[col="+r+"]").removeClass("w2ui-selected w2ui-inactive");n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)).find(" > td[col="+r+"]").removeClass("w2ui-selected w2ui-inactive");var p=!1,w=!1,y=this.getSelection();for(u=0;u<y.length;u++)y[u].column==r&&(p=!0),y[u].recid==t&&(w=!0);p||n(this.box).find(".w2ui-grid-columns td[col="+r+"] .w2ui-col-header, .w2ui-grid-fcolumns td[col="+r+"] .w2ui-col-header").removeClass("w2ui-col-selected");w||n("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)).find(".w2ui-col-number").removeClass("w2ui-row-selected");l++;s.length===0&&(delete i.columns[o],i.indexes.splice(i.indexes.indexOf(o),1),f.removeData("selected"),f.find(".w2ui-grid-select-check").prop("checked",!1),c.removeData("selected"))}this.trigger(n.extend(h,{phase:"after"}))}return b=this.records.length>0&&i.indexes.length==this.records.length,k=i.indexes.length>0&&this.searchData.length!==0&&i.indexes.length==this.last.searchIds.length,b||k?n("#grid_"+this.name+"_check_all").prop("checked",!0):n("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),l},selectAll:function(){var o=(new Date).getTime(),r,f,t,i;if(this.multiSelect!==!1&&(r=this.trigger({phase:"before",type:"select",target:this.name,all:!0}),r.isCancelled!==!0)){var e=typeof this.url!="object"?this.url:this.url.get,i=this.last.selection,u=[];for(t=0;t<this.columns.length;t++)u.push(t);if(i.indexes=[],e||this.searchData.length===0)for(f=this.records.length,this.searchData.length==0||e||(f=this.last.searchIds.length),t=0;t<f;t++)i.indexes.push(t),this.selectType!="row"&&(i.columns[t]=u.slice());else for(t=0;t<this.last.searchIds.length;t++)i.indexes.push(this.last.searchIds[t]),this.selectType!="row"&&(i.columns[this.last.searchIds[t]]=u.slice());return this.selectType=="row"?(n(this.box).find(".w2ui-grid-records tr").not(".w2ui-empty-record").addClass("w2ui-selected").data("selected","yes").find(".w2ui-col-number").addClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-frecords tr").not(".w2ui-empty-record").addClass("w2ui-selected").data("selected","yes").find(".w2ui-col-number").addClass("w2ui-row-selected"),n(this.box).find("input.w2ui-grid-select-check").prop("checked",!0)):(n(this.box).find(".w2ui-grid-columns td .w2ui-col-header, .w2ui-grid-fcolumns td .w2ui-col-header").addClass("w2ui-col-selected"),n(this.box).find(".w2ui-grid-records tr .w2ui-col-number").addClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-records tr").not(".w2ui-empty-record").find(".w2ui-grid-data").not(".w2ui-col-select").addClass("w2ui-selected").data("selected","yes"),n(this.box).find(".w2ui-grid-frecords tr .w2ui-col-number").addClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-frecords tr").not(".w2ui-empty-record").find(".w2ui-grid-data").not(".w2ui-col-select").addClass("w2ui-selected").data("selected","yes"),n(this.box).find("input.w2ui-grid-select-check").prop("checked",!0)),i=this.getSelection(),i.length==1?this.toolbar.enable("w2ui-edit"):this.toolbar.disable("w2ui-edit"),i.length>=1?this.toolbar.enable("w2ui-delete"):this.toolbar.disable("w2ui-delete"),this.addRange("selection"),n("#grid_"+this.name+"_check_all").prop("checked",!0),this.trigger(n.extend(r,{phase:"after"})),(new Date).getTime()-o}},selectNone:function(){var r=(new Date).getTime(),i=this.trigger({phase:"before",type:"unselect",target:this.name,all:!0}),t;if(i.isCancelled!==!0)return t=this.last.selection,this.selectType=="row"?(n(this.box).find(".w2ui-grid-records tr.w2ui-selected").removeClass("w2ui-selected w2ui-inactive").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-frecords tr.w2ui-selected").removeClass("w2ui-selected w2ui-inactive").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected"),n(this.box).find("input.w2ui-grid-select-check").prop("checked",!1)):(n(this.box).find(".w2ui-grid-columns td .w2ui-col-header, .w2ui-grid-fcolumns td .w2ui-col-header").removeClass("w2ui-col-selected"),n(this.box).find(".w2ui-grid-records tr .w2ui-col-number").removeClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-frecords tr .w2ui-col-number").removeClass("w2ui-row-selected"),n(this.box).find(".w2ui-grid-data.w2ui-selected").removeClass("w2ui-selected w2ui-inactive").removeData("selected"),n(this.box).find("input.w2ui-grid-select-check").prop("checked",!1)),t.indexes=[],t.columns={},this.toolbar.disable("w2ui-edit","w2ui-delete"),this.removeRange("selection"),n("#grid_"+this.name+"_check_all").prop("checked",!1),this.trigger(n.extend(i,{phase:"after"})),(new Date).getTime()-r},getSelection:function(n){var r=[],i=this.last.selection,t,f,u;if(this.selectType=="row"){for(t=0;t<i.indexes.length;t++)this.records[i.indexes[t]]&&(n===!0?r.push(i.indexes[t]):r.push(this.records[i.indexes[t]].recid));return r}for(t=0;t<i.indexes.length;t++)if(f=i.columns[i.indexes[t]],this.records[i.indexes[t]])for(u=0;u<f.length;u++)r.push({recid:this.records[i.indexes[t]].recid,index:parseInt(i.indexes[t]),column:f[u]});return r},search:function(t,i){for(var it,rt,ut,p,ft,ht,h,v,u,y,c,r,o,g,lt=this,ct=typeof this.url!="object"?this.url:this.url.get,s=[],w=this.last.multi,b=this.last.logic,et=this.last.field,k=this.last.search,ot=!1,f=0;f<this.searches.length;f++)this.searches[f].hidden&&(s.push({field:this.searches[f].field,operator:this.searches[f].operator||"is",type:this.searches[f].type,value:this.searches[f].value||""}),ot=!0);if(arguments.length===0){for(k="",f=0;f<this.searches.length;f++){var r=this.searches[f],l=n("#grid_"+this.name+"_operator_"+f).val(),nt=n("#grid_"+this.name+"_field_"+f),st=n("#grid_"+this.name+"_field2_"+f),e=nt.val(),a=st.val(),d=null,tt=null;if(["int","float","money","currency","percent"].indexOf(r.type)!=-1&&(it=nt.data("w2field"),rt=st.data("w2field"),it&&(e=it.clean(e)),rt&&(a=rt.clean(a))),["list","enum"].indexOf(r.type)!=-1)if(e=nt.data("selected")||{},n.isArray(e)){for(d=[],o=0;o<e.length;o++)d.push(w2utils.isFloat(e[o].id)?parseFloat(e[o].id):String(e[o].id).toLowerCase()),delete e[o].hidden;n.isEmptyObject(e)&&(e="")}else tt=e.text||"",e=e.id||"";if(e!==""&&e!=null||a!=null&&a!==""){u={field:r.field,type:r.type,operator:l};l=="between"?n.extend(u,{value:[e,a]}):l=="in"&&typeof e=="string"?n.extend(u,{value:e.split(",")}):l=="not in"&&typeof e=="string"?n.extend(u,{value:e.split(",")}):n.extend(u,{value:e});d&&n.extend(u,{svalue:d});tt&&n.extend(u,{text:tt});try{r.type=="date"&&l=="between"&&(u.value[0]=e,u.value[1]=a);r.type=="date"&&l=="is"&&(u.value=e)}catch(at){}s.push(u)}}w=!0;b="AND"}if(typeof t=="string"&&(arguments.length==1&&(i=t,t="all"),et=t,k=i,w=!1,b=ot?"AND":"OR",i!=null))if(t.toLowerCase()=="all")if(this.searches.length>0){for(f=0;f<this.searches.length;f++)if(r=this.searches[f],(r.type=="text"||r.type=="alphanumeric"&&w2utils.isAlphaNumeric(i)||r.type=="int"&&w2utils.isInt(i)||r.type=="float"&&w2utils.isFloat(i)||r.type=="percent"&&w2utils.isFloat(i)||(r.type=="hex"||r.type=="color")&&w2utils.isHex(i)||r.type=="currency"&&w2utils.isMoney(i)||r.type=="money"&&w2utils.isMoney(i)||r.type=="date"&&w2utils.isDate(i)||r.type=="time"&&w2utils.isTime(i)||r.type=="datetime"&&w2utils.isDateTime(i)||r.type=="enum"&&w2utils.isAlphaNumeric(i)||r.type=="list"&&w2utils.isAlphaNumeric(i))&&(u={field:r.field,type:r.type,operator:r.operator!=null?r.operator:r.type=="text"?this.textSearch:"is",value:i},n.trim(i)!=""&&s.push(u)),["int","float","money","currency","percent"].indexOf(r.type)!=-1&&n.trim(String(i)).split("-").length==2&&(ut=n.trim(String(i)).split("-"),u={field:r.field,type:r.type,operator:r.operator!=null?r.operator:"between",value:[ut[0],ut[1]]},s.push(u)),["list","enum"].indexOf(r.type)!=-1){for(p=[],o=0;o<r.options.items;o++){u=r.options.items[o];try{ft=new RegExp(i,"i");ft.test(u)&&p.push(o);u.text&&ft.test(u.text)&&p.push(u.id)}catch(at){}}p.length>0&&(u={field:r.field,type:r.type,operator:r.operator!=null?r.operator:"in",value:p},s.push(u))}}else for(f=0;f<this.columns.length;f++)u={field:this.columns[f].field,type:"text",operator:this.textSearch,value:i},s.push(u);else if(ht=n("#grid_"+this.name+"_search_all"),r=this.getSearch(t),r==null&&(r={field:t,type:"text"}),r.field==t&&(this.last.caption=r.caption),i!==""){if(h=this.textSearch,v=i,["date","time","datetime"].indexOf(r.type)!=-1&&(h="is"),["list","enum"].indexOf(r.type)!=-1&&(h="is",u=ht.data("selected"),v=u&&!n.isEmptyObject(u)?u.id:""),r.type=="int"&&i!==""&&(h="is",String(i).indexOf("-")!=-1&&(u=i.split("-"),u.length==2&&(h="between",v=[parseInt(u[0]),parseInt(u[1])])),String(i).indexOf(",")!=-1))for(u=i.split(","),h="in",v=[],f=0;f<u.length;f++)v.push(u[f]);r.operator!=null&&(h=r.operator);u={field:r.field,type:r.type,operator:h,value:v};s.push(u)}if(n.isArray(t))for(y="AND",typeof i=="string"&&(y=i.toUpperCase(),y!="OR"&&y!="AND"&&(y="AND")),k="",w=!0,b=y,f=0;f<t.length;f++){if(c=t[f],r=this.getSearch(c.field),r==null&&(r={type:"text",operator:"begins"}),n.isArray(c.value))for(o=0;o<c.value.length;o++)typeof c.value[o]=="string"&&(c.value[o]=c.value[o].toLowerCase());s.push(n.extend(!0,{},r,c))}(g=this.trigger({phase:"before",type:"search",multi:arguments.length===0?!0:!1,target:this.name,searchData:s,searchField:t?t:"multi",searchValue:t?i:"multi"}),g.isCancelled!==!0)&&(this.searchData=g.searchData,this.last.field=et,this.last.search=k,this.last.multi=w,this.last.logic=b,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selection.indexes=[],this.last.selection.columns={},this.searchClose(),ct?(this.last.xhr_offset=0,this.reload()):(this.localSearch(),this.refresh()),this.trigger(n.extend(g,{phase:"after"})))},searchOpen:function(){if(this.box&&this.searches.length!==0){var t=this,i=this.trigger({phase:"before",type:"searchOpen",target:this.name});if(i.isCancelled===!0){setTimeout(function(){t.toolbar.uncheck("w2ui-search-advanced")},1);return}n("#tb_"+this.name+"_toolbar_item_w2ui-search-advanced").w2overlay({html:this.getSearchesHTML(),name:this.name+"-searchOverlay",left:-10,"class":"w2ui-grid-searches",onShow:function(){t.initSearches();n("#w2ui-overlay-"+t.name+"-searchOverlay .w2ui-grid-searches").data("grid-name",t.name);var r=n("#w2ui-overlay-"+this.name+"-searchOverlay .w2ui-grid-searches *[rel=search]");r.length>0&&r[0].focus();t.trigger(n.extend(i,{phase:"after"}))}})}},searchClose:function(){var t=this;this.box&&this.searches.length!==0&&(this.toolbar&&this.toolbar.uncheck("w2ui-search-advanced"),n().w2overlay({name:this.name+"-searchOverlay"}),n().w2overlay({name:this.name+"-searchOverlay"}))},searchReset:function(t){for(var u,i,f=[],e=!1,r=0;r<this.searches.length;r++)this.searches[r].hidden&&(f.push({field:this.searches[r].field,operator:this.searches[r].operator||"is",type:this.searches[r].type,value:this.searches[r].value||""}),e=!0);if(u=this.trigger({phase:"before",type:"search",reset:!0,target:this.name,searchData:f}),u.isCancelled!==!0){if(this.searchData=u.searchData,this.last.search="",this.last.logic=e?"AND":"OR",this.searches.length>0)if(this.multiSearch&&this.show.searchAll)this.last.field="all",this.last.caption=w2utils.lang("All Fields");else{for(i=0;i<this.searches.length&&(this.searches[i].hidden||this.searches[i].simple===!1);)i++;i>=this.searches.length?(this.last.field="",this.last.caption=""):(this.last.field=this.searches[i].field,this.last.caption=this.searches[i].caption)}this.last.multi=!1;this.last.xhr_offset=0;this.last.scrollTop=0;this.last.scrollLeft=0;this.last.selection.indexes=[];this.last.selection.columns={};this.searchClose();n("#grid_"+this.name+"_search_all").val("").removeData("selected");t||this.reload();this.trigger(n.extend(u,{phase:"after"}))}},searchShowFields:function(){for(var i,u=this,f=n("#grid_"+this.name+"_search_all"),r='<div class="w2ui-select-field"><table><tbody>',t=-1;t<this.searches.length;t++){if(i=this.searches[t],t==-1){if(!this.multiSearch||!this.show.searchAll)continue;i={field:"all",caption:w2utils.lang("All Fields")}}else if(this.searches[t].hidden===!0||this.searches[t].simple===!1)continue;r+="<tr "+(w2utils.isIOS?"onTouchStart":"onClick")+"=\"w2ui['"+this.name+"'].initAllField('"+i.field+"');      event.stopPropagation(); jQuery('#grid_"+this.name+"_search_all').w2overlay({ name: '"+this.name+'-searchFields\' });">   <td>       <span class="w2ui-column-check w2ui-icon-'+(i.field==this.last.field?"check":"empty")+'"><\/span>   <\/td>   <td>'+i.caption+"<\/td><\/tr>"}r+="<\/tbody><\/table><\/div>";setTimeout(function(){n(f).w2overlay({html:r,name:u.name+"-searchFields",left:-10})},1)},initAllField:function(t,i){var u=n("#grid_"+this.name+"_search_all"),r,f;if(t=="all")r={field:"all",caption:w2utils.lang("All Fields")},u.w2field("clear"),u.change();else{if(r=this.getSearch(t),r==null)return;f=r.type;["enum","select"].indexOf(f)!=-1&&(f="list");u.w2field(f,n.extend({},r.options,{suffix:"",autoFormat:!1,selected:i}));["list","enum","date","time","datetime"].indexOf(r.type)!=-1&&(this.last.search="",this.last.item="",u.val(""))}this.last.search!=""?(this.last.caption=r.caption,this.search(r.field,this.last.search)):(this.last.field=r.field,this.last.caption=r.caption);u.attr("placeholder",w2utils.lang(r.caption));n().w2overlay({name:this.name+"-searchFields"})},clear:function(n){this.total=0;this.records=[];this.summary=[];this.last.xhr_offset=0;this.reset(!0);n||this.refresh()},reset:function(t){this.last.scrollTop=0;this.last.scrollLeft=0;this.last.selection={indexes:[],columns:{}};this.last.range_start=null;this.last.range_end=null;n("#grid_"+this.name+"_records").prop("scrollTop",0);t||this.refresh()},skip:function(n,t){var i=typeof this.url!="object"?this.url:this.url.get;i?(this.offset=parseInt(n),this.offset>this.total&&(this.offset=this.total-this.limit),(this.offset<0||!w2utils.isInt(this.offset))&&(this.offset=0),this.clear(!0),this.reload(t)):console.log("ERROR: grid.skip() can only be called when you have remote data source.")},load:function(n,t){if(n==null){console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.');return}this.clear(!0);this.request("get",{},n,t)},reload:function(n){var t=this,i=typeof this.url!="object"?this.url:this.url.get;t.selectionSave();i?this.load(i,function(){t.selectionRestore();typeof n=="function"&&n()}):(this.reset(!0),this.localSearch(),this.selectionRestore(),typeof n=="function"&&n({status:"success"}))},request:function(t,i,r,u){var e,o,s,l,h,c,f;if(i==null&&(i={}),(r==""||r==null)&&(r=this.url),r!=""&&r!=null){if(e={},w2utils.isInt(this.offset)||(this.offset=0),w2utils.isInt(this.last.xhr_offset)||(this.last.xhr_offset=0),e.cmd=t,e.selected=this.getSelection(),e.limit=this.limit,e.offset=parseInt(this.offset)+parseInt(this.last.xhr_offset),e.search=this.searchData,e.searchLogic=this.last.logic,e.sort=this.sortData,this.searchData.length===0&&(delete e.search,delete e.searchLogic),this.sortData.length===0&&delete e.sort,n.extend(e,this.postData),n.extend(e,i),t=="get"){if(o=this.trigger({phase:"before",type:"request",target:this.name,url:r,postData:e,httpHeaders:this.httpHeaders}),o.isCancelled===!0){typeof u=="function"&&u({status:"error",message:"Request aborted."});return}}else o={url:r,postData:e,httpHeaders:this.httpHeaders};if(s=this,this.last.xhr_offset===0?s.lock(w2utils.lang(s.msgRefresh),!0):(l=n("#grid_"+this.name+"_rec_more, #grid_"+this.name+"_frec_more"),this.autoLoad===!0?l.show().find("td").html('<div><div style="width: 20px; height: 20px;" class="w2ui-spinner"><\/div><\/div>'):l.find("td").html("<div>"+w2utils.lang("Load")+" "+s.limit+" "+w2utils.lang("More")+"...<\/div>")),this.last.xhr)try{this.last.xhr.abort()}catch(a){}if(r=typeof o.url!="object"?o.url:o.url.get,e.cmd=="save"&&typeof o.url=="object"&&(r=o.url.save),e.cmd=="delete"&&typeof o.url=="object"&&(r=o.url.remove),!n.isEmptyObject(s.routeData)&&(h=w2utils.parseRoute(r),h.keys.length>0))for(c=0;c<h.keys.length;c++)s.routeData[h.keys[c].name]!=null&&(r=r.replace(new RegExp(":"+h.keys[c].name,"g"),s.routeData[h.keys[c].name]));f={type:"POST",url:r,data:o.postData,headers:o.httpHeaders,dataType:"text"};w2utils.settings.dataType=="HTTP"&&(f.data=typeof f.data=="object"?String(n.param(f.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"):f.data);w2utils.settings.dataType=="HTTPJSON"&&(f.data={request:JSON.stringify(f.data)});w2utils.settings.dataType=="RESTFULL"&&(f.type="GET",e.cmd=="save"&&(f.type="PUT"),e.cmd=="delete"&&(f.type="DELETE"),f.data=typeof f.data=="object"?String(n.param(f.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"):f.data);w2utils.settings.dataType=="RESTFULLJSON"&&(f.type="GET",e.cmd=="save"&&(f.type="PUT"),e.cmd=="delete"&&(f.type="DELETE"),f.data=JSON.stringify(f.data),f.contentType="application/json");w2utils.settings.dataType=="JSON"&&(f.type="POST",f.data=JSON.stringify(f.data),f.contentType="application/json");this.method&&(f.type=this.method);this.last.xhr_cmd=e.cmd;this.last.xhr_start=(new Date).getTime();this.last.xhr=n.ajax(f).done(function(n,i){s.requestComplete(i,t,u)}).fail(function(i,r,f){var h={status:r,error:f,rawResponseText:i.responseText},o=s.trigger({phase:"before",type:"error",error:h,xhr:i}),e;if(o.isCancelled!==!0){if(r!="abort"){try{e=n.parseJSON(i.responseText)}catch(c){}console.log("ERROR: Server communication failed.","\n   EXPECTED:",{status:"success",total:5,records:[{recid:1,field:"value"}]},"\n         OR:",{status:"error",message:"error message"},"\n   RECEIVED:",typeof e=="object"?e:i.responseText);s.requestComplete("error",t,u)}s.trigger(n.extend(o,{phase:"after"}))}});t=="get"&&this.trigger(n.extend(o,{phase:"after"}))}},requestComplete:function(t,i,r){var f=this,h,c,u,e,s,o,l;if(this.unlock(),setTimeout(function(){f.show.statusResponse&&f.status(w2utils.lang("Server Response")+" "+((new Date).getTime()-f.last.xhr_start)/1e3+" "+w2utils.lang("sec"))},10),this.last.pull_more=!1,this.last.pull_refresh=!0,h="load",this.last.xhr_cmd=="save"&&(h="save"),this.last.xhr_cmd=="delete"&&(h="delete"),c=this.trigger({phase:"before",target:this.name,type:h,xhr:this.last.xhr,status:t}),c.isCancelled===!0){typeof r=="function"&&r({status:"error",message:"Request aborted."});return}if(e=this.last.xhr.responseText,t!="error"){if(e!=null&&e!=""){if(typeof e=="object")u=e;else if(typeof f.parser=="function")u=f.parser(e),typeof u!="object"&&console.log("ERROR: Your parser did not return proper object");else try{eval("data = "+e)}catch(a){}if(u==null?u={status:"error",message:w2utils.lang(this.msgNotJSON),responseText:e}:Array.isArray(u)&&(u={status:"success",records:u}),f.recid&&u.records)for(s=0;s<u.records.length;s++)u.records[s].recid=u.records[s][f.recid];if(u.status=="error")f.error(u.message);else{if(i=="get"){if(u.total==null&&(u.total=-1),u.records.length==this.limit?this.last.xhr_hasMore=!0:(this.last.xhr_hasMore=!1,this.total=this.last.xhr_offset+u.records.length),this.last.xhr_offset===0)this.records=[],this.summary=[],w2utils.isInt(u.total)&&(this.total=parseInt(u.total));else if(u.total!=-1&&parseInt(u.total)!=parseInt(this.total)){this.message(w2utils.lang(this.msgNeedReload),function(){delete this.last.xhr_offset;this.reload()}.bind(this));return}if(u.records)for(o=0;o<u.records.length;o++)this.records.push(u.records[o]);if(u.summary)for(this.summary=[],o=0;o<u.summary.length;o++)this.summary.push(u.summary[o])}if(i=="delete"){this.reset();this.reload();return}}}}else u={status:"error",message:w2utils.lang(this.msgAJAXerror),responseText:e},f.error(w2utils.lang(this.msgAJAXerror));l=typeof this.url!="object"?this.url:this.url.get;l||(this.localSort(),this.localSearch());this.total=parseInt(this.total);this.last.xhr_offset===0?this.refresh():(this.scroll(),this.resize());typeof r=="function"&&r(u);this.trigger(n.extend(c,{phase:"after"}))},error:function(t){var r=this,i=this.trigger({target:this.name,type:"error",message:t,xhr:this.last.xhr});if(i.isCancelled===!0){typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."});return}this.message(t);this.trigger(n.extend(i,{phase:"after"}))},getChanges:function(){for(var t,r=[],i=0;i<this.records.length;i++)t=this.records[i],t.w2ui&&t.w2ui.changes!=null&&r.push(n.extend(!0,{recid:t.recid},t.w2ui.changes));return r},mergeChanges:function(){for(var r,n,i=this.getChanges(),t=0;t<i.length;t++){r=this.get(i[t].recid);for(n in i[t])if(n!="recid"){typeof i[t][n]=="object"&&(i[t][n]=i[t][n].text);try{n.indexOf(".")!=-1?eval("record['"+n.replace(/\./g,"']['")+"'] = changes[c][s]"):r[n]=i[t][n]}catch(u){console.log("ERROR: Cannot merge. ",u.message||"",u)}r.w2ui&&delete r.w2ui.changes}}this.refresh()},save:function(){var i=this,u=this.getChanges(),t=this.trigger({phase:"before",target:this.name,type:"save",changes:u}),r;t.isCancelled!==!0&&(r=typeof this.url!="object"?this.url:this.url.save,r?this.request("save",{changes:t.changes},null,function(r){r.status!=="error"&&i.mergeChanges();i.trigger(n.extend(t,{phase:"after"}))}):(this.mergeChanges(),this.trigger(n.extend(t,{phase:"after"}))))},editField:function(t,i,r,u){function w(){try{var r=this.tagName.toUpperCase()=="DIV"?n(this).text():this.value,t=n("#grid_"+f.name+"_editable"),u="font-family: "+n(this).css("font-family")+"; font-size: "+n(this).css("font-size")+"; white-space: pre;",i=w2utils.getStrWidth(r,u);i+20>t.width()&&t.width(i+20)}catch(e){}}var f=this,s=f.get(t,!0),e=f.getCellEditable(s,i),v,k,h,o,g,b,nt,y,p,d,l;if(e){var a=f.records[s],c=f.columns[i],tt=c.frozen===!0?"_f":"_";if(["enum","file"].indexOf(e.type)!=-1){console.log('ERROR: input types "enum" and "file" are not supported in inline editing.');return}if((v=f.trigger({phase:"before",type:"editField",target:f.name,recid:t,column:i,value:r,index:s,originalEvent:u}),v.isCancelled!==!0)&&(r=v.value,this.selectNone(),this.select({recid:t,column:i}),this.last.edit_col=i,["checkbox","check"].indexOf(e.type)==-1)){k=n("#grid_"+f.name+tt+"rec_"+w2utils.escapeId(t));h=k.find("[col="+i+"] > div");n(this.box).find("div.w2ui-edit-box").remove();this.selectType!="row"&&(n("#grid_"+this.name+tt+"selection").attr("id","grid_"+this.name+"_editable").removeClass("w2ui-selection").addClass("w2ui-edit-box").prepend('<div style="position: absolute; top: 0px; bottom: 0px; left: 0px; right: 0px;"><\/div>').find(".w2ui-selection-resizer").remove(),h=n("#grid_"+this.name+"_editable >div:first-child"));e.inTag==null&&(e.inTag="");e.outTag==null&&(e.outTag="");e.style==null&&(e.style="");e.items==null&&(e.items=[]);o=a.w2ui&&a.w2ui.changes&&a.w2ui.changes[c.field]!=null?w2utils.stripTags(a.w2ui.changes[c.field]):w2utils.stripTags(a[c.field]);o==null&&(o="");g=typeof o!="object"?o:"";v.old_value!=null&&(g=v.old_value);r!=null&&(o=r);b=c.style!=null?c.style+";":"";typeof c.render=="string"&&["number","int","float","money","percent","size"].indexOf(c.render.split(":")[0])!=-1&&(b+="text-align: right;");e.items.length>0&&!n.isPlainObject(e.items[0])&&(e.items=w2obj.field.prototype.normMenu(e.items));switch(e.type){case"select":for(nt="",y=0;y<e.items.length;y++)nt+='<option value="'+e.items[y].id+'"'+(e.items[y].id==o?' selected="selected"':"")+">"+e.items[y].text+"<\/option>";h.addClass("w2ui-editable").html('<select id="grid_'+f.name+"_edit_"+t+"_"+i+'" column="'+i+'" class="w2ui-input"    style="width: 100%; pointer-events: auto; padding: 0 0 0 3px; margin: 0px; border-left: 0; border-right: 0; border-radius: 0px;            outline: none; font-family: inherit;'+b+e.style+'"     field="'+c.field+'" recid="'+t+'"     '+e.inTag+">"+nt+"<\/select>"+e.outTag);setTimeout(function(){h.find("select").on("change",function(){delete f.last.move}).on("blur",function(t){n(this).data("keep-open")!=!0&&f.editChange.call(f,this,s,i,t)})},10);break;case"div":p=k.find("[col="+i+"] > div");d="font-family: "+p.css("font-family")+"; font-size: "+p.css("font-size")+";";h.addClass("w2ui-editable").html('<div id="grid_'+f.name+"_edit_"+t+"_"+i+'" class="w2ui-input"    contenteditable style="'+d+b+e.style+'" autocorrect="off" autocomplete="off" spellcheck="false"     field="'+c.field+'" recid="'+t+'" column="'+i+'" '+e.inTag+"><\/div>"+e.outTag);r==null&&h.find("div.w2ui-input").text(typeof o!="object"?o:"");l=h.find("div.w2ui-input").get(0);setTimeout(function(){var t=l;n(t).on("blur",function(r){n(this).data("keep-open")!=!0&&f.editChange.call(f,t,s,i,r)})},10);r!=null&&n(l).text(typeof o!="object"?o:"");break;default:p=k.find("[col="+i+"] > div");d="font-family: "+p.css("font-family")+"; font-size: "+p.css("font-size");h.addClass("w2ui-editable").html('<input id="grid_'+f.name+"_edit_"+t+"_"+i+'" autocorrect="off" autocomplete="off" spellcheck="false" type="text"     style="'+d+"; width: 100%; height: 100%; padding: 3px; border-color: transparent; outline: none; border-radius: 0;        pointer-events: auto; "+b+e.style+'"     field="'+c.field+'" recid="'+t+'" column="'+i+'" class="w2ui-input"'+e.inTag+"/>"+e.outTag);e.type=="number"&&(o=w2utils.formatNumber(o));e.type=="date"&&(o=w2utils.formatDate(w2utils.isDate(o,e.format,!0),e.format));r==null&&h.find("input").val(typeof o!="object"?o:"");l=h.find("input").get(0);n(l).w2field(e.type,n.extend(e,{selected:o}));setTimeout(function(){var t=l;if(e.type=="list"){t=n(n(l).data("w2field").helpers.focus).find("input");typeof o!="object"&&o!=""&&t.val(o).css({opacity:1}).prev().css({opacity:1});h.find("input").on("change",function(n){f.editChange.call(f,l,s,i,n)})}n(t).on("blur",function(t){n(this).data("keep-open")!=!0&&f.editChange.call(f,l,s,i,t)})},10);r!=null&&n(l).val(typeof o!="object"?o:"")}setTimeout(function(){h.find("input, select, div.w2ui-input").data("old_value",g).on("mousedown",function(n){n.stopPropagation()}).on("click",function(){e.type=="div"?w.call(h.find("div.w2ui-input")[0],null):w.call(h.find("input, select")[0],null)}).on("paste",function(n){var i=n.originalEvent,t;n.preventDefault();t=i.clipboardData.getData("text/plain");document.execCommand("insertHTML",!1,t)}).on("keydown",function(r){var u=this,o=u.tagName.toUpperCase()=="DIV"?n(u).text():n(u).val();switch(r.keyCode){case 8:e.type!="list"||n(l).data("w2field")||r.preventDefault();break;case 9:case 13:r.preventDefault();break;case 37:w2utils.getCursorPosition(u)===0&&r.preventDefault();break;case 39:w2utils.getCursorPosition(u)==o.length&&(w2utils.setCursorPosition(u,o.length),r.preventDefault())}setTimeout(function(){var h,e,y,l,p,v,o;switch(r.keyCode){case 9:if(h=t,e=r.shiftKey?f.prevCell(s,i,!0):f.nextCell(s,i,!0),e==null&&(y=r.shiftKey?f.prevRow(s,i):f.nextRow(s,i),y!=null&&y!=s))for(h=f.records[y].recid,l=0;l<f.columns.length;l++)if(p=f.getCellEditable(s,l),p!=null&&["checkbox","check"].indexOf(p.type)==-1&&(e=parseInt(l),!r.shiftKey))break;h===!1&&(h=t);e==null&&(e=i);u.blur();setTimeout(function(){f.selectType!="row"?(f.selectNone(),f.select({recid:h,column:e})):f.editField(h,e,null,r)},1);r.preventDefault&&r.preventDefault();break;case 13:u.blur();v=r.shiftKey?f.prevRow(s,i):f.nextRow(s,i);v!=null&&v!=s&&setTimeout(function(){f.selectType!="row"?(f.selectNone(),f.select({recid:f.records[v].recid,column:i})):f.editField(f.records[v].recid,i,null,r)},1);u.tagName.toUpperCase()=="DIV"&&r.preventDefault();break;case 27:o=f.parseField(a,c.field);a.w2ui&&a.w2ui.changes&&a.w2ui.changes[c.field]!=null&&(o=a.w2ui.changes[c.field]);n(u).data("old_value")!=null&&(o=n(u).data("old_value"));u.tagName.toUpperCase()=="DIV"?n(u).text(o!=null?o:""):u.value=o!=null?o:"";u.blur();setTimeout(function(){f.select({recid:t,column:i})},1)}w.call(u,r)},1)}).on("keyup",function(n){w.call(this,n)});setTimeout(function(){var t=h.find(".w2ui-input"),i=n(t).val().length;e.type=="div"&&(i=n(t).text().length);t.length>0&&(t.focus(),clearTimeout(f.last.kbd_timer),t[0].tagName!="SELECT"&&w2utils.setCursorPosition(t[0],i),t[0].resize=w,w.call(t[0],null))},50);f.trigger(n.extend(v,{phase:"after",input:h.find("input, select, div.w2ui-input")}))},5);return}}},editChange:function(t,i,r,u){var v=this,c,o,l;setTimeout(function(){var t=n(v.box).find("#grid_"+v.name+"_focus");t.is(":focus")||t.focus()},10);c=i<0;i=i<0?-i-1:i;var y=c?this.summary:this.records,f=y[i],s=this.columns[r],p=n("#grid_"+this.name+(s.frozen===!0?"_frec_":"_rec_")+w2utils.escapeId(f.recid)),e=t.tagName&&t.tagName.toUpperCase()=="DIV"?n(t).text():t.value,h=this.parseField(f,s.field),a=n(t).data("w2field");for(a&&(a.type=="list"&&(e=n(t).data("selected")),(n.isEmptyObject(e)||e==null)&&(e=""),n.isPlainObject(e)||(e=a.clean(e))),t.type=="checkbox"&&(f.w2ui&&f.w2ui.editable===!1&&(t.checked=!t.checked),e=t.checked),o={phase:"before",type:"change",target:this.name,input_id:t.id,recid:f.recid,index:i,column:r,originalEvent:u.originalEvent?u.originalEvent:u,value_new:e,value_previous:f.w2ui&&f.w2ui.changes&&f.w2ui.changes.hasOwnProperty(s.field)?f.w2ui.changes[s.field]:h,value_original:h},n(u.target).data("old_value")!=null&&(o.value_previous=n(u.target).data("old_value"));;){if(e=o.value_new,typeof e!="object"&&String(h)!=String(e)||typeof e=="object"&&e.id!=h&&(typeof h!="object"||h==null||e.id!=h.id)){if(o=this.trigger(n.extend(o,{type:"change",phase:"before"})),o.isCancelled!==!0){if(e!==o.value_new)continue;f.w2ui=f.w2ui||{};f.w2ui.changes=f.w2ui.changes||{};f.w2ui.changes[s.field]=o.value_new;this.trigger(n.extend(o,{phase:"after"}))}}else if(o=this.trigger(n.extend(o,{type:"restore",phase:"before"})),o.isCancelled!==!0){if(e!==o.value_new)continue;f.w2ui&&f.w2ui.changes&&delete f.w2ui.changes[s.field];f.w2ui&&n.isEmptyObject(f.w2ui.changes)&&delete f.w2ui.changes;this.trigger(n.extend(o,{phase:"after"}))}break}l=n(p).find("[col="+r+"]");c||(f.w2ui&&f.w2ui.changes&&f.w2ui.changes[s.field]!=null?l.addClass("w2ui-changed"):l.removeClass("w2ui-changed"),l.replaceWith(this.getCellHTML(i,r,c)));n(this.box).find("div.w2ui-edit-box").remove();this.show.toolbarSave&&(this.getChanges().length>0?this.toolbar.enable("w2ui-save"):this.toolbar.disable("w2ui-save"))},"delete":function(t){var c=(new Date).getTime(),u=this,f=this.trigger({phase:"before",target:this.name,type:"delete",force:t}),i,h,r;if(f.isCancelled!==!0&&(t=f.force,setTimeout(function(){n().w2tag()},20),i=this.getSelection(),i.length!==0)){if(this.msgDelete!=""&&!t){this.message({width:350,height:170,body:'<div class="w2ui-centered">'+w2utils.lang(u.msgDelete)+"<\/div>",buttons:'<button class="w2ui-btn w2ui-btn-red" onclick="w2ui[\''+this.name+"'].delete(true)\">"+w2utils.lang("Yes")+'<\/button><button class="w2ui-btn" onclick="w2ui[\''+this.name+"'].message()\">"+w2utils.lang("No")+"<\/button>",onOpen:function(){var t=n(this.box).find("input, textarea, select, button");t.off(".message").on("blur.message",function(n){t.index(n.target)+1===t.length&&(t.get(0).focus(),n.preventDefault())}).on("keydown.message",function(n){n.keyCode==27&&u.message()});setTimeout(function(){n(this.box).find(".w2ui-btn:last-child").focus();clearTimeout(u.last.kbd_timer)},25)}});return}if(this.message(),h=typeof this.url!="object"?this.url:this.url.remove,h)this.request("delete");else if(typeof i[0]!="object")this.selectNone(),this.remove.apply(this,i);else{for(r=0;r<i.length;r++){var e=this.columns[i[r].column].field,o=this.get(i[r].recid,!0),s=this.records[o];o!=null&&e!="recid"&&(this.records[o][e]="",s.w2ui&&s.w2ui.changes&&delete s.w2ui.changes[e])}this.update()}this.trigger(n.extend(f,{phase:"after"}))}},click:function(t,i){var g=(new Date).getTime(),r=null,e=this,nt,p,u,b,k,l,o,s,a,f,tt,h,v;if(this.last.cancelClick!=!0&&(!i||!i.altKey)){if(typeof t=="object"&&(r=t.column,t=t.recid),i==null&&(i={}),g-parseInt(this.last.click_time)<350&&this.last.click_recid==t&&i.type=="click"){this.dblClick(t,i);return}if(this.last.bubbleEl&&(n(this.last.bubbleEl).w2tag(),this.last.bubbleEl=null),this.last.click_time=g,nt=this.last.click_recid,this.last.click_recid=t,r==null&&i.target&&(f=i.target,f.tagName.toUpperCase()!="TD"&&(f=n(f).parents("td")[0]),n(f).attr("col")!=null&&(r=parseInt(n(f).attr("col")))),p=this.trigger({phase:"before",target:this.name,type:"click",recid:t,column:r,originalEvent:i}),p.isCancelled!==!0){e=this;u=this.getSelection();n("#grid_"+this.name+"_check_all").prop("checked",!1);var c=this.get(t,!0),rt=this.records[c],w=[];if(e.last.sel_ind=c,e.last.sel_col=r,e.last.sel_recid=t,e.last.sel_type="click",i.shiftKey&&u.length>0&&e.multiSelect){if(u[0].recid)for(o=this.get(u[0].recid,!0),s=this.get(t,!0),r>u[0].column?(b=u[0].column,k=r):(b=r,k=u[0].column),l=b;l<=k;l++)w.push(l);else o=this.get(nt,!0),s=this.get(t,!0);for(a=[],o>s&&(f=o,o=s,s=f),tt=typeof this.url!="object"?this.url:this.url.get,h=o;h<=s;h++)if(!(this.searchData.length>0)||tt||n.inArray(h,this.last.searchIds)!=-1)if(this.selectType=="row")a.push(this.records[h].recid);else for(v=0;v<w.length;v++)a.push({recid:this.records[h].recid,column:w[v]});this.select.apply(this,a)}else{var d=this.last.selection,y=d.indexes.indexOf(c)!=-1?!0:!1,it=!1;n(i.target).parents("td").hasClass("w2ui-col-select")&&(it=!0);(i.ctrlKey||i.shiftKey||i.metaKey||it)&&this.multiSelect||this.showSelectColumn?(this.selectType!="row"&&n.inArray(r,d.columns[c])==-1&&(y=!1),y===!0?this.unselect({recid:t,column:r}):this.select({recid:t,column:r})):(this.selectType!="row"&&n.inArray(r,d.columns[c])==-1&&(y=!1),u.length>300?this.selectNone():this.unselect.apply(this,u),y===!0&&u.length==1?this.unselect({recid:t,column:r}):this.select({recid:t,column:r}))}this.status();e.initResize();this.trigger(n.extend(p,{phase:"after"}))}}},columnClick:function(t,i){var r=this.trigger({phase:"before",type:"columnClick",target:this.name,field:t,originalEvent:i}),f,o,s,u;if(r.isCancelled!==!0){if(this.selectType=="row")f=this.getColumn(t),f&&f.sortable&&this.sort(t,null,i&&(i.ctrlKey||i.metaKey)?!0:!1),r.field=="line-number"&&(this.getSelection().length>=this.records.length?this.selectNone():this.selectAll());else if(r.field=="line-number")this.getSelection().length>=this.records.length?this.selectNone():this.selectAll();else{i.shiftKey||i.metaKey||i.ctrlKey||this.selectNone();var h=this.getSelection(),f=this.getColumn(r.field,!0),c=[],e=[];if(h.length!=0&&i.shiftKey)for(o=f,s=h[0].column,o>s&&(o=h[0].column,s=f),u=o;u<=s;u++)e.push(u);else e.push(f);if(r=this.trigger({phase:"before",type:"columnSelect",target:this.name,columns:e}),r.isCancelled!==!0){for(u=0;u<this.records.length;u++)c.push({recid:this.records[u].recid,column:e});this.select.apply(this,c)}this.trigger(n.extend(r,{phase:"after"}))}this.trigger(n.extend(r,{phase:"after"}))}},columnDblClick:function(t,i){var r=this.trigger({phase:"before",type:"columnDblClick",target:this.name,field:t,originalEvent:i});r.isCancelled!==!0&&this.trigger(n.extend(r,{phase:"after"}))},focus:function(t){var i=this,r=this.trigger({phase:"before",type:"focus",target:this.name,originalEvent:t});if(r.isCancelled===!0)return!1;this.hasFocus=!0;n(this.box).find(".w2ui-inactive").removeClass("w2ui-inactive");setTimeout(function(){var t=n(i.box).find("#grid_"+i.name+"_focus");t.is(":focus")||t.focus()},10);this.trigger(n.extend(r,{phase:"after"}))},blur:function(t){var i=this.trigger({phase:"before",type:"blur",target:this.name,originalEvent:t});if(i.isCancelled===!0)return!1;this.hasFocus=!1;n(this.box).find(".w2ui-selected").addClass("w2ui-inactive");n(this.box).find(".w2ui-selection").addClass("w2ui-inactive");this.trigger(n.extend(i,{phase:"after"}))},keydown:function(t){function nt(){var n=Math.floor(ot[0].scrollTop/i.recordHeight)+1;(!i.records[n]||n<2)&&(n=0);i.select({recid:i.records[n].recid,column:0})}function tt(){if(i.last.sel_type!="click")return!1;if(i.selectType!="row"){if(i.last.sel_type="key",r.length>1){for(var n=0;n<r.length;n++)if(r[n].recid==i.last.sel_recid&&r[n].column==i.last.sel_col){r.splice(n,1);break}return i.unselect.apply(i,r),!0}return!1}return(i.last.sel_type="key",r.length>1)?(r.splice(r.indexOf(i.records[i.last.sel_ind].recid),1),i.unselect.apply(i,r),!0):!1}var i=this,ut=typeof this.url!="object"?this.url:this.url.get,it,w,et,s,h,o,l,f,e;if(i.keyboard===!0&&(it=i.trigger({phase:"before",type:"keydown",target:i.name,originalEvent:t}),it.isCancelled!==!0)){if(n(this.box).find(">.w2ui-message").length>0){t.keyCode==27&&this.message();return}var p=!1,ot=n("#grid_"+i.name+"_records"),r=i.getSelection();r.length===0&&(p=!0);var a=r[0]||null,u=[],ft=r[r.length-1];if(typeof a=="object"&&a!=null){for(a=r[0].recid,u=[],w=0;;){if(!r[w]||r[w].recid!=a)break;u.push(r[w].column);w++}ft=r[r.length-1].recid}var c=i.get(a,!0),b=i.get(ft,!0),st=i.get(a),k=n("#grid_"+i.name+"_rec_"+(c!=null?w2utils.escapeId(i.records[c].recid):"none")),y=!1,rt=t.keyCode,v=t.shiftKey;switch(rt){case 8:case 46:(this.show.toolbarDelete||this.onDelete)&&i["delete"]();y=!0;t.stopPropagation();break;case 27:i.selectNone();y=!0;break;case 65:if(!t.metaKey&&!t.ctrlKey)break;i.selectAll();y=!0;break;case 13:if(this.selectType=="row"&&i.show.expandColumn===!0){if(k.length<=0)break;i.toggle(a,t);y=!0}else{for(o=0;o<this.columns.length;o++)if(et=this.getCellEditable(c,o),et){u.push(parseInt(o));break}this.selectType=="row"&&this.last.edit_col&&(u=[this.last.edit_col]);u.length>0&&(i.editField(a,u[0],null,t),y=!0)}break;case 37:if(p){nt();break}if(this.selectType=="row"){if(k.length<=0)break;f=this.records[c].w2ui||{};!f||f.parent_recid==null||Array.isArray(f.children)&&f.children.length!==0&&f.expanded?i.collapse(a,t):(i.unselect(a),i.collapse(f.parent_recid,t),i.select(f.parent_recid))}else if(s=i.prevCell(c,u[0]),v||s!=null||(this.selectNone(),s=0),s!=null)if(v&&i.multiSelect){if(tt())return;var f=[],d=[],g=[];if(u.indexOf(this.last.sel_col)===0&&u.length>1){for(e=0;e<r.length;e++)f.indexOf(r[e].recid)==-1&&f.push(r[e].recid),g.push({recid:r[e].recid,column:u[u.length-1]});i.unselect.apply(i,g);i.scrollIntoView(c,u[u.length-1],!0)}else{for(e=0;e<r.length;e++)f.indexOf(r[e].recid)==-1&&f.push(r[e].recid),d.push({recid:r[e].recid,column:s});i.select.apply(i,d);i.scrollIntoView(c,s,!0)}}else t.metaKey=!1,i.click({recid:a,column:s},t),i.scrollIntoView(c,s,!0);else if(!v)if(r.length>1)i.selectNone();else for(l=1;l<r.length;l++)i.unselect(r[l]);y=!0;break;case 39:if(p){nt();break}if(this.selectType=="row"){if(k.length<=0)break;i.expand(a,t)}else if(h=i.nextCell(c,u[u.length-1]),v||h!=null||(this.selectNone(),h=this.columns.length-1),h!=null)if(v&&rt==39&&i.multiSelect){if(tt())return;var f=[],d=[],g=[];if(u.indexOf(this.last.sel_col)==u.length-1&&u.length>1){for(e=0;e<r.length;e++)f.indexOf(r[e].recid)==-1&&f.push(r[e].recid),g.push({recid:r[e].recid,column:u[0]});i.unselect.apply(i,g);i.scrollIntoView(c,u[0],!0)}else{for(e=0;e<r.length;e++)f.indexOf(r[e].recid)==-1&&f.push(r[e].recid),d.push({recid:r[e].recid,column:h});i.select.apply(i,d);i.scrollIntoView(c,h,!0)}}else t.metaKey=!1,i.click({recid:a,column:h},t),i.scrollIntoView(c,h,!0);else if(!v)if(r.length>1)i.selectNone();else for(l=0;l<r.length-1;l++)i.unselect(r[l]);y=!0;break;case 38:if(p&&nt(),k.length<=0)break;if(s=i.prevRow(c,u[0]),v||s!=null||(s=this.searchData.length==0||ut?0:this.last.searchIds[0]),s!=null){if(v&&i.multiSelect){if(tt())return;if(i.selectType=="row")i.last.sel_ind>s&&i.last.sel_ind!=b?i.unselect(i.records[b].recid):i.select(i.records[s].recid);else if(i.last.sel_ind>s&&i.last.sel_ind!=b){for(s=b,f=[],o=0;o<u.length;o++)f.push({recid:i.records[s].recid,column:u[o]});i.unselect.apply(i,f)}else{for(f=[],o=0;o<u.length;o++)f.push({recid:i.records[s].recid,column:u[o]});i.select.apply(i,f)}}else r.length>300?this.selectNone():this.unselect.apply(this,r),i.click({recid:i.records[s].recid,column:u[0]},t);i.scrollIntoView(s);t.preventDefault&&t.preventDefault()}else if(!v)if(r.length>1)i.selectNone();else for(l=1;l<r.length;l++)i.unselect(r[l]);break;case 40:if(p&&nt(),k.length<=0)break;if(h=i.nextRow(b,u[0]),v||h!=null||(h=this.searchData.length==0||ut?this.records.length-1:this.last.searchIds[this.last.searchIds.length-1]),h!=null){if(v&&i.multiSelect){if(tt())return;if(i.selectType=="row")this.last.sel_ind<h&&this.last.sel_ind!=c?i.unselect(i.records[c].recid):i.select(i.records[h].recid);else if(this.last.sel_ind<h&&this.last.sel_ind!=c){for(h=c,f=[],o=0;o<u.length;o++)f.push({recid:i.records[h].recid,column:u[o]});i.unselect.apply(i,f)}else{for(f=[],o=0;o<u.length;o++)f.push({recid:i.records[h].recid,column:u[o]});i.select.apply(i,f)}}else r.length>300?this.selectNone():this.unselect.apply(this,r),i.click({recid:i.records[h].recid,column:u[0]},t);i.scrollIntoView(h);y=!0}else if(!v)if(r.length>1)i.selectNone();else for(l=0;l<r.length-1;l++)i.unselect(r[l]);break;case 17:case 91:if(p)break;i.last.isSafari&&(i.last.copy_event=i.copy(!1,t),n("#grid_"+i.name+"_focus").val(i.last.copy_event.text).select());break;case 67:(t.metaKey||t.ctrlKey)&&(i.last.isSafari?i.copy(i.last.copy_event,t):(i.last.copy_event=i.copy(!1,t),n("#grid_"+i.name+"_focus").val(i.last.copy_event.text).select(),i.copy(i.last.copy_event,t)));break;case 88:if(p)break;(t.ctrlKey||t.metaKey)&&(i.last.isSafari?i.copy(i.last.copy_event,t):(i.last.copy_event=i.copy(!1,t),n("#grid_"+i.name+"_focus").val(i.last.copy_event.text).select(),i.copy(i.last.copy_event,t)),setTimeout(function(){i["delete"](!0)},100))}for(f=[32,187,189,192,219,220,221,186,222,188,190,191],e=48;e<=111;e++)f.push(e);f.indexOf(rt)==-1||t.ctrlKey||t.metaKey||y||(u.length===0&&u.push(0),y=!1,setTimeout(function(){var r=n("#grid_"+i.name+"_focus"),f=r.val();r.val("");i.editField(a,u[0],f,t)},1));y&&t.preventDefault&&t.preventDefault();i.trigger(n.extend(it,{phase:"after"}))}},scrollIntoView:function(t,i,r){var v=this.records.length,f,u,o,s,y,l,a;if(this.searchData.length==0||this.url||(v=this.last.searchIds.length),v!==0){if(t==null){if(f=this.getSelection(),f.length===0)return;n.isPlainObject(f[0])?(t=f[0].index,i=f[0].column):t=this.get(f[0],!0)}if(u=n("#grid_"+this.name+"_records"),o=this.last.searchIds.length,o>0&&(t=this.last.searchIds.indexOf(t)),u.height()<this.recordHeight*(o>0?o:v)&&u.length>0&&(s=Math.floor(u[0].scrollTop/this.recordHeight),y=s+Math.floor(u.height()/this.recordHeight),t==s&&(r===!0?u.prop({scrollTop:u.scrollTop()-u.height()/1.3}):(u.stop(),u.animate({scrollTop:u.scrollTop()-u.height()/1.3},250,"linear"))),t==y&&(r===!0?u.prop({scrollTop:u.scrollTop()+u.height()/1.3}):(u.stop(),u.animate({scrollTop:u.scrollTop()+u.height()/1.3},250,"linear"))),(t<s||t>y)&&(r===!0?u.prop({scrollTop:(t-1)*this.recordHeight}):(u.stop(),u.animate({scrollTop:(t-1)*this.recordHeight},250,"linear")))),i!=null){var h=0,e=0,c=w2utils.scrollBarSize();for(l=0;l<=i;l++)(a=this.columns[l],a.frozen||a.hidden)||(h=e,e+=parseInt(a.sizeCalculated));u.width()<e-u.scrollLeft()?r===!0?u.prop({scrollLeft:h-c}):u.animate({scrollLeft:h-c},250,"linear"):h<u.scrollLeft()&&(r===!0?u.prop({scrollLeft:e-u.width()+c*2}):u.animate({scrollLeft:e-u.width()+c*2},250,"linear"))}}},dblClick:function(t,i){var r=null,u,s;typeof t=="object"&&(r=t.column,t=t.recid);i==null&&(i={});r==null&&i.target&&(u=i.target,u.tagName.toUpperCase()!="TD"&&(u=n(u).parents("td")[0]),r=parseInt(n(u).attr("col")));var f=this.get(t,!0),e=this.records[f],o=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:t,column:r,originalEvent:i});o.isCancelled!==!0&&(this.selectNone(),s=this.getCellEditable(f,r),s?this.editField(t,r,null,i):(this.select({recid:t,column:r}),(this.show.expandColumn||e.w2ui&&Array.isArray(e.w2ui.children))&&this.toggle(t)),this.trigger(n.extend(o,{phase:"after"})))},contextMenu:function(t,i,r){var u=this,f,o,s,e,h;if(u.last.userSelect!="text"){if(r==null&&(r={offsetX:0,offsetY:0,target:n("#grid_"+u.name+"_rec_"+t)[0]}),r.offsetX==null&&(r.offsetX=r.layerX-r.target.offsetLeft,r.offsetY=r.layerY-r.target.offsetTop),w2utils.isFloat(t)&&(t=parseFloat(t)),f=this.getSelection(),this.selectType=="row")f.indexOf(t)==-1&&u.click(t);else{for(o=n(r.target),o[0].tagName.toUpperCase()!="TD"&&(o=n(r.target).parents("td")),s=!1,i=o.attr("col"),e=0;e<f.length;e++)(f[e].recid==t||f[e].column==i)&&(s=!0);s||t==null||u.click({recid:t,column:i});s||i==null||u.columnClick(this.columns[i].field,r)}(h=u.trigger({phase:"before",type:"contextMenu",target:u.name,originalEvent:r,recid:t,column:i}),h.isCancelled!==!0)&&(u.menu.length>0&&n(u.box).find(r.target).w2menu(u.menu,{originalEvent:r,contextMenu:!0,onSelect:function(n){u.menuClick(t,parseInt(n.index),n.originalEvent)}}),r.preventDefault&&r.preventDefault(),u.trigger(n.extend(h,{phase:"after"})))}},menuClick:function(t,i,r){var u=this,f=u.trigger({phase:"before",type:"menuClick",target:u.name,originalEvent:r,recid:t,menuIndex:i,menuItem:u.menu[i]});f.isCancelled!==!0&&u.trigger(n.extend(f,{phase:"after"}))},toggle:function(n){var t=this.get(n);return t.w2ui=t.w2ui||{},t.w2ui.expanded===!0?this.collapse(n):this.expand(n)},expand:function(t){var l=this,s=this.get(t,!0),r=this.records[s],i,u,h,f;if(r.w2ui=r.w2ui||{},i=w2utils.escapeId(t),u=r.w2ui.children,Array.isArray(u)){if(r.w2ui.expanded===!0||u.length===0||(f=this.trigger({phase:"before",type:"expand",target:this.name,recid:t}),f.isCancelled===!0))return!1;r.w2ui.expanded=!0;u.forEach(function(n){n.w2ui=n.w2ui||{};n.w2ui.parent_recid=r.recid;n.w2ui.children==null&&(n.w2ui.children=[])});this.records.splice.apply(this.records,[s+1,0].concat(u));this.total+=u.length;h=typeof this.url!="object"?this.url:this.url.get;h||(this.localSort(!0,!0),this.searchData.length>0&&this.localSearch(!0));this.refresh();this.trigger(n.extend(f,{phase:"after"}))}else{if(n("#grid_"+this.name+"_rec_"+i+"_expanded_row").length>0||this.show.expandColumn!==!0||r.w2ui.expanded=="none")return!1;if(n("#grid_"+this.name+"_rec_"+i).after('<tr id="grid_'+this.name+"_rec_"+t+'_expanded_row" class="w2ui-expanded-row">    <td colspan="100" class="w2ui-expanded2">        <div id="grid_'+this.name+"_rec_"+t+'_expanded"><\/div>    <\/td>    <td class="w2ui-grid-data-last"><\/td><\/tr>'),n("#grid_"+this.name+"_frec_"+i).after('<tr id="grid_'+this.name+"_frec_"+t+'_expanded_row" class="w2ui-expanded-row">'+(this.show.lineNumbers?'<td class="w2ui-col-number"><\/td>':"")+'    <td class="w2ui-grid-data w2ui-expanded1" colspan="100">       <div id="grid_'+this.name+"_frec_"+t+'_expanded"><\/div>   <\/td><\/tr>'),f=this.trigger({phase:"before",type:"expand",target:this.name,recid:t,box_id:"grid_"+this.name+"_rec_"+t+"_expanded",fbox_id:"grid_"+this.name+"_frec_"+i+"_expanded"}),f.isCancelled===!0)return n("#grid_"+this.name+"_rec_"+i+"_expanded_row").remove(),n("#grid_"+this.name+"_frec_"+i+"_expanded_row").remove(),!1;var o=n(this.box).find("#grid_"+this.name+"_rec_"+t+"_expanded"),c=n(this.box).find("#grid_"+this.name+"_frec_"+t+"_expanded"),e=o.find("> div:first-child").height();o.height()<e&&o.css({height:e+"px"});c.height()<e&&c.css({height:e+"px"});n("#grid_"+this.name+"_rec_"+i).attr("expanded","yes").addClass("w2ui-expanded");n("#grid_"+this.name+"_frec_"+i).attr("expanded","yes").addClass("w2ui-expanded");n("#grid_"+this.name+"_cell_"+this.get(t,!0)+"_expand div").html("-");r.w2ui.expanded=!0;this.trigger(n.extend(f,{phase:"after"}));this.resizeRecords()}return!0},collapse:function(t){function v(n){var t,i;for(n.w2ui.expanded=!1,t=0;t<n.w2ui.children.length;t++)i=n.w2ui.children[t],i.w2ui.expanded&&v(i)}var r=this,c=this.get(t,!0),u=this.records[c],i,l,h,o,s,f,a,e;if(u.w2ui=u.w2ui||{},i=w2utils.escapeId(t),l=u.w2ui.children,Array.isArray(l)){if(u.w2ui.expanded!==!0||(e=this.trigger({phase:"before",type:"collapse",target:this.name,recid:t}),e.isCancelled===!0))return!1;for(v(u),h=[],o=u;o!=null;o=this.get(o.w2ui.parent_recid))h.push(o.w2ui.parent_recid);for(s=c+1,f=s;;){if(this.records.length<=f+1||this.records[f+1].w2ui==null||h.indexOf(this.records[f+1].w2ui.parent_recid)>=0)break;f++}this.records.splice(s,f-s+1);this.total-=f-s+1;a=typeof this.url!="object"?this.url:this.url.get;a||this.searchData.length>0&&this.localSearch(!0);this.refresh();r.trigger(n.extend(e,{phase:"after"}))}else{if(n("#grid_"+this.name+"_rec_"+i+"_expanded_row").length===0||this.show.expandColumn!==!0||(e=this.trigger({phase:"before",type:"collapse",target:this.name,recid:t,box_id:"grid_"+this.name+"_rec_"+i+"_expanded",fbox_id:"grid_"+this.name+"_frec_"+i+"_expanded"}),e.isCancelled===!0))return!1;n("#grid_"+this.name+"_rec_"+i).removeAttr("expanded").removeClass("w2ui-expanded");n("#grid_"+this.name+"_frec_"+i).removeAttr("expanded").removeClass("w2ui-expanded");n("#grid_"+this.name+"_cell_"+this.get(t,!0)+"_expand div").html("+");n("#grid_"+r.name+"_rec_"+i+"_expanded").css("height","0px");n("#grid_"+r.name+"_frec_"+i+"_expanded").css("height","0px");setTimeout(function(){n("#grid_"+r.name+"_rec_"+i+"_expanded_row").remove();n("#grid_"+r.name+"_frec_"+i+"_expanded_row").remove();u.w2ui.expanded=!1;r.trigger(n.extend(e,{phase:"after"}));r.resizeRecords()},300)}return!0},sort:function(t,i,r){var e=this.trigger({phase:"before",type:"sort",target:this.name,field:t,direction:i,multiField:r}),u,f,o;if(e.isCancelled!==!0){if(t!=null){for(u=this.sortData.length,f=0;f<this.sortData.length;f++)if(this.sortData[f].field==t){u=f;break}if(i==null)if(this.sortData[u]==null)i="asc";else switch(String(this.sortData[u].direction)){case"asc":i="desc";break;case"desc":i="asc";break;default:i="asc"}this.multiSort===!1&&(this.sortData=[],u=0);r!=!0&&(this.sortData=[],u=0);this.sortData[u]==null&&(this.sortData[u]={});this.sortData[u].field=t;this.sortData[u].direction=i}else this.sortData=[];o=typeof this.url!="object"?this.url:this.url.get;o?(this.trigger(n.extend(e,{phase:"after"})),this.last.xhr_offset=0,this.reload()):(this.localSort(!0,!0),this.searchData.length>0&&this.localSearch(!0),this.last.scrollTop=0,n("#grid_"+this.name+"_records").prop("scrollTop",0),this.trigger(n.extend(e,{phase:"after"})),this.refresh())}},copy:function(t,i){var u,r,c,y,e,l,f,o,s;if(n.isPlainObject(t))return this.trigger(n.extend(t,{phase:"after"})),t.text;if(u=this.getSelection(),u.length===0)return"";if(r="",typeof u[0]=="object"){var a=u[0].column,v=u[0].column,h=[];for(e=0;e<u.length;e++)u[e].column<a&&(a=u[e].column),u[e].column>v&&(v=u[e].column),h.indexOf(u[e].index)==-1&&h.push(u[e].index);for(h.sort(function(n,t){return n-t}),c=0;c<h.length;c++){for(l=h[c],f=a;f<=v;f++)(o=this.columns[f],o.hidden!==!0)&&(r+=w2utils.stripTags(this.getCellHTML(l,f))+"\t");r=r.substr(0,r.length-1)+"\n"}}else{for(f=0;f<this.columns.length;f++)(o=this.columns[f],o.hidden!==!0)&&(y=o.caption?o.caption:o.field,o.caption&&o.caption.length<3&&o.tooltip&&(y=o.tooltip),r+='"'+w2utils.stripTags(y)+'"\t');for(r=r.substr(0,r.length-1),r+="\n",e=0;e<u.length;e++){for(l=this.get(u[e],!0),f=0;f<this.columns.length;f++)(o=this.columns[f],o.hidden!==!0)&&(r+='"'+w2utils.stripTags(this.getCellHTML(l,f))+'"\t');r=r.substr(0,r.length-1)+"\n"}}return(r=r.substr(0,r.length-1),t==null)?(s=this.trigger({phase:"before",type:"copy",target:this.name,text:r,originalEvent:i}),s.isCancelled===!0)?"":(r=s.text,this.trigger(n.extend(s,{phase:"after"})),r):t===!1?(s=this.trigger({phase:"before",type:"copy",target:this.name,text:r,originalEvent:i}),s.isCancelled===!0)?"":(r=s.text,s):void 0},paste:function(t){var h=this.getSelection(),c=this.get(h[0].recid,!0),r=h[0].column,u=this.trigger({phase:"before",type:"paste",target:this.name,text:t,index:c,column:r}),l,t,f,o,y,s;if(u.isCancelled!==!0){if(t=u.text,this.selectType=="row"||h.length===0){console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected.");this.trigger(n.extend(u,{phase:"after"}));return}for(l=[],t=t.split("\n"),f=0;f<t.length;f++){var v=t[f].split("\t"),e=0,i=this.records[c],a=[];if(i!=null){for(o=0;o<v.length;o++)this.columns[r+e]&&(y=this.columns[r+e].field,i.w2ui=i.w2ui||{},i.w2ui.changes=i.w2ui.changes||{},i.w2ui.changes[y]=v[o],a.push(r+e),e++);for(s=0;s<a.length;s++)l.push({recid:i.recid,column:a[s]});c++}}this.selectNone();this.select.apply(this,l);this.refresh();this.trigger(n.extend(u,{phase:"after"}))}},resize:function(){var t=this,r=(new Date).getTime(),i;if(this.box&&n(this.box).attr("name")==this.name)return(n(this.box).find("> div.w2ui-grid-box").css("width",n(this.box).width()).css("height",n(this.box).height()),i=this.trigger({phase:"before",type:"resize",target:this.name}),i.isCancelled===!0)?void 0:(t.resizeBoxes(),t.resizeRecords(),t.toolbar&&t.toolbar.resize&&t.toolbar.resize(),this.trigger(n.extend(i,{phase:"after"})),(new Date).getTime()-r)},update:function(t){var s=(new Date).getTime(),i,e,f,o,u,r;if(this.box==null)return 0;if(t==null){for(u=this.last.range_start-1;u<=this.last.range_end-1;u++)if(!(u<0))for(i=this.records[u]||{},i.w2ui||(i.w2ui={}),r=0;r<this.columns.length;r++)e=n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(i.recid)),f=n(this.box).find("#grid_"+this.name+"_data_"+u+"_"+r),f.replaceWith(this.getCellHTML(u,r,!1)),f=n(this.box).find("#grid_"+this.name+"_data_"+u+"_"+r),i.w2ui.style==null||n.isEmptyObject(i.w2ui.style)?f.attr("style",""):(typeof i.w2ui.style=="string"&&e.attr("style",i.w2ui.style),n.isPlainObject(i.w2ui.style)&&typeof i.w2ui.style[r]=="string"&&f.attr("style",i.w2ui.style[r])),i.w2ui.class==null||n.isEmptyObject(i.w2ui.class)||(typeof i.w2ui.class=="string"&&e.addClass(i.w2ui.class),n.isPlainObject(i.w2ui.class)&&typeof i.w2ui.class[r]=="string"&&f.addClass(i.w2ui.class[r]))}else for(o=0;o<t.length;o++)if(u=t[o].index,r=t[o].column,!(u<0)){if(u==null||r==null){console.log("ERROR: Wrong argument for grid.update(cells), cells should be [{ index: X, column: Y }, ...]");continue}var i=this.records[u]||{},e=n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(i.recid)),f=n(this.box).find("#grid_"+this.name+"_data_"+u+"_"+r);i.w2ui||(i.w2ui={});f.replaceWith(this.getCellHTML(u,r,!1));f=n(this.box).find("#grid_"+this.name+"_data_"+u+"_"+r);i.w2ui.style==null||n.isEmptyObject(i.w2ui.style)?f.attr("style",""):(typeof i.w2ui.style=="string"&&e.attr("style",i.w2ui.style),n.isPlainObject(i.w2ui.style)&&typeof i.w2ui.style[r]=="string"&&f.attr("style",i.w2ui.style[r]));i.w2ui.class==null||n.isEmptyObject(i.w2ui.class)||(typeof i.w2ui.class=="string"&&e.addClass(i.w2ui.class),n.isPlainObject(i.w2ui.class)&&typeof i.w2ui.class[r]=="string"&&f.addClass(i.w2ui.class[r]))}return(new Date).getTime()-s},refreshCell:function(t,i){var f=this.get(t,!0),o=this.records[f]&&this.records[f].recid==t?!1:!0,u=this.getColumn(i,!0),r=o?this.summary[f]:this.records[f],s=this.columns[u],e=n(this.box).find("#grid_"+this.name+"_data_"+f+"_"+u);if(r==null)return!1;e.replaceWith(this.getCellHTML(f,u,o));e=n(this.box).find("#grid_"+this.name+"_data_"+f+"_"+u);r.w2ui&&r.w2ui.changes&&r.w2ui.changes[s.field]!=null?e.addClass("w2ui-changed"):e.removeClass("w2ui-changed");r.w2ui&&r.w2ui.style!=null&&!n.isEmptyObject(r.w2ui.style)?(typeof r.w2ui.style=="string"&&n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(r.recid)).attr("style",r.w2ui.style),n.isPlainObject(r.w2ui.style)&&typeof r.w2ui.style[u]=="string"&&e.attr("style",r.w2ui.style[u])):e.attr("style","");r.w2ui&&r.w2ui.class!=null&&!n.isEmptyObject(r.w2ui.class)&&(typeof r.w2ui.class=="string"&&n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(r.recid)).addClass(r.w2ui.class),n.isPlainObject(r.w2ui.class)&&typeof r.w2ui.class[u]=="string"&&e.addClass(r.w2ui.class[u]))},refreshRow:function(t,i){var u=n(this.box).find("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)),e=n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)),f,o,r;if(u.length>0){i==null&&(i=this.get(t,!0));var h=u.attr("line"),s=this.records[i]&&this.records[i].recid==t?!1:!0,c=typeof this.url!="object"?this.url:this.url.get;if(this.searchData.length>0&&!c)for(f=0;f<this.last.searchIds.length;f++)this.last.searchIds[f]==i&&(i=f);o=this.getRecordHTML(i,h,s);n(u).replaceWith(o[0]);n(e).replaceWith(o[1]);r=this.records[i].w2ui?this.records[i].w2ui.style:"";typeof r=="string"&&(u=n(this.box).find("#grid_"+this.name+"_frec_"+w2utils.escapeId(t)),e=n(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(t)),u.attr("custom_style",r),e.attr("custom_style",r),u.hasClass("w2ui-selected")&&(r=r.replace("background-color","none")),u[0].style.cssText="height: "+this.recordHeight+"px;"+r,e[0].style.cssText="height: "+this.recordHeight+"px;"+r);s&&this.resize()}},refresh:function(){var t=this,a=(new Date).getTime(),v=typeof this.url!="object"?this.url:this.url.get,s,u,r,f,e,h,l,o,i;if((this.total<=0&&!v&&this.searchData.length===0&&(this.total=this.records.length),this.toolbar.disable("w2ui-edit","w2ui-delete"),this.box)&&(s=this.trigger({phase:"before",target:this.name,type:"refresh"}),s.isCancelled!==!0)){if(this.show.header?n("#grid_"+this.name+"_header").html(this.header+"&#160;").show():n("#grid_"+this.name+"_header").hide(),this.show.toolbar){if((!this.toolbar||!this.toolbar.get("w2ui-column-on-off")||!this.toolbar.get("w2ui-column-on-off").checked)&&(n("#grid_"+this.name+"_toolbar").show(),typeof this.toolbar=="object"))for(i=this.toolbar.items,u=0;u<i.length;u++)i[u].id!="w2ui-search"&&i[u].type!="break"&&this.toolbar.refresh(i[u].id)}else n("#grid_"+this.name+"_toolbar").hide();for(this.searchClose(),r=n("#grid_"+t.name+"_search_all"),!this.multiSearch&&this.last.field=="all"&&this.searches.length>0&&(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption),f=0;f<this.searches.length;f++)this.searches[f].field==this.last.field&&(this.last.caption=this.searches[f].caption);this.last.multi?(r.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]"),r.w2field("clear")):r.attr("placeholder",w2utils.lang(this.last.caption));r.val()!=this.last.search&&(e=this.last.search,i=r.data("w2field"),i&&(e=i.format(e)),r.val(e));t.refreshBody();this.show.footer?n("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show():n("#grid_"+this.name+"_footer").hide();h=n("#grid_"+this.name+"_searchClear");h.hide();this.searchData.some(function(n){var i=t.getSearch(n.field);if(t.last.multi||i&&!i.hidden&&i.type!="list")return h.show(),!0});var c=this.last.selection,y=this.records.length>0&&c.indexes.length==this.records.length,p=c.indexes.length>0&&this.searchData.length!==0&&c.indexes.length==this.last.searchIds.length;for(y||p?n("#grid_"+this.name+"_check_all").prop("checked",!0):n("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),l=t.find({"w2ui.expanded":!0},!0),o=0;o<l.length;o++)i=t.records[l[o]].w2ui,i&&!Array.isArray(i.children)&&(i.expanded=!1);return t.markSearch&&setTimeout(function(){for(var r,f,i=[],u=0;u<t.searchData.length;u++)(r=t.searchData[u],f=t.getSearch(r.field),f&&!f.hidden)&&i.indexOf(r.value)==-1&&i.push(r.value);i.length>0&&n(t.box).find(".w2ui-grid-data > div").w2marker(i)},50),this.show.toolbarSave&&(this.getChanges().length>0?this.toolbar.enable("w2ui-save"):this.toolbar.disable("w2ui-save")),this.trigger(n.extend(s,{phase:"after"})),t.resize(),t.addRange("selection"),setTimeout(function(){t.resize();t.scroll()},1),t.reorderColumns&&!t.last.columnDrag?t.last.columnDrag=t.initColumnDrag():!t.reorderColumns&&t.last.columnDrag&&t.last.columnDrag.remove(),t.dragRow?t.initRowDrag():(n(t.box).find("tr").each(function(){n(this).removeAttr("draggable")}),n(t.box).off("dragstart","tr",function(n){n.preventDefault();n.stopPropagation()}),n(t.box).off("dragend","tr",function(n){n.preventDefault();n.stopPropagation()})),(new Date).getTime()-a}},refreshBody:function(){var i=this.find({"w2ui.summary":!0},!0),t,r;if(i.length>0){for(t=0;t<i.length;t++)this.summary.push(this.records[i[t]]);for(t=i.length-1;t>=0;t--)this.records.splice(i[t],1)}this.scroll();var u=this.getRecordsHTML(),f=this.getColumnsHTML(),e='<div id="grid_'+this.name+'_frecords" class="w2ui-grid-frecords" style="margin-bottom: '+(w2utils.scrollBarSize()-1)+'px;">'+u[0]+'<\/div><div id="grid_'+this.name+'_records" class="w2ui-grid-records" onscroll="w2ui[\''+this.name+"'].scroll(event);\">"+u[1]+'<\/div><div id="grid_'+this.name+'_scroll1" class="w2ui-grid-scroll1" style="height: '+w2utils.scrollBarSize()+'px"><\/div><div id="grid_'+this.name+'_fcolumns" class="w2ui-grid-fcolumns">    <table><tbody>'+f[0]+'<\/tbody><\/table><\/div><div id="grid_'+this.name+'_columns" class="w2ui-grid-columns">    <table><tbody>'+f[1]+"<\/tbody><\/table><\/div>";n("#grid_"+this.name+"_body").html(e);this.records.length===0&&this.msgEmpty?n("#grid_"+this.name+"_body").append('<div id="grid_'+this.name+'_empty_msg" class="w2ui-grid-empty-msg"><div>'+this.msgEmpty+"<\/div><\/div>"):n("#grid_"+this.name+"_empty_msg").length>0&&n("#grid_"+this.name+"_empty_msg").remove();this.summary.length>0?(r=this.getSummaryHTML(),n("#grid_"+this.name+"_fsummary").html(r[0]).show(),n("#grid_"+this.name+"_summary").html(r[1]).show()):(n("#grid_"+this.name+"_fsummary").hide(),n("#grid_"+this.name+"_summary").hide())},render:function(t){function v(t){var f,a,s,b,k,u,e,r,d,v;if(t.which==1&&(i.last.userSelect=="text"&&(delete i.last.userSelect,n(i.box).find(".w2ui-grid-body").css(w2utils.cssPrefix("user-select","none"))),i.selectType!="row"||!(n(t.target).parents().hasClass("w2ui-head")||n(t.target).hasClass("w2ui-head")))&&(!i.last.move||i.last.move.type!="expand")){if(t.altKey)n(i.box).find(".w2ui-grid-body").css(w2utils.cssPrefix("user-select","text")),i.selectNone(),i.last.move={type:"text-select"},i.last.userSelect="text";else if(i.multiSelect||i.reorderRows){for(var r=t.target,h={x:t.offsetX-10,y:t.offsetY-10},p=!1;r;){if(r.classList&&r.classList.contains("w2ui-grid"))break;r.tagName&&r.tagName.toUpperCase()=="TD"&&(p=!0);r.tagName&&r.tagName.toUpperCase()!="TR"&&p==!0&&(h.x+=r.offsetLeft,h.y+=r.offsetTop);r=r.parentNode}if(i.last.move={x:t.screenX,y:t.screenY,divX:0,divY:0,focusX:h.x,focusY:h.y,recid:n(t.target).parents("tr").attr("recid"),column:parseInt(t.target.tagName.toUpperCase()=="TD"?n(t.target).attr("col"):n(t.target).parents("td").attr("col")),type:"select",ghost:!1,start:!0},i.last.move.recid==null&&(i.last.move.type="select-column"),f=t.target,a=n(i.box).find("#grid_"+i.name+"_focus"),i.last.move){var w=i.last.move.focusX,y=i.last.move.focusY,o=n(f).parents("table").parent();(o.hasClass("w2ui-grid-records")||o.hasClass("w2ui-grid-frecords")||o.hasClass("w2ui-grid-columns")||o.hasClass("w2ui-grid-fcolumns")||o.hasClass("w2ui-grid-summary"))&&(w=i.last.move.focusX-n(i.box).find("#grid_"+i.name+"_records").scrollLeft(),y=i.last.move.focusY-n(i.box).find("#grid_"+i.name+"_records").scrollTop());(n(f).hasClass("w2ui-grid-footer")||n(f).parents("div.w2ui-grid-footer").length>0)&&(y=n(i.box).find("#grid_"+i.name+"_footer").position().top);a.css({left:w-10,top:y})}setTimeout(function(){["INPUT","TEXTAREA","SELECT"].indexOf(f.tagName.toUpperCase())!=-1?n(f).focus():a.is(":focus")||a.focus()},50)}i.reorderRows==!0&&(s=t.target,s.tagName.toUpperCase()!="TD"&&(s=n(s).parents("td")[0]),n(s).hasClass("w2ui-col-number")?(i.selectNone(),i.last.move.reorder=!0,b=n(i.box).find(".w2ui-even.w2ui-empty-record").css("background-color"),k=n(i.box).find(".w2ui-odd.w2ui-empty-record").css("background-color"),n(i.box).find(".w2ui-even td").not(".w2ui-col-number").css("background-color",b),n(i.box).find(".w2ui-odd td").not(".w2ui-col-number").css("background-color",k),u=i.last.move,u.ghost||(e=n("#grid_"+i.name+"_rec_"+u.recid),r=e.parents("table").find("tr:first-child").clone(),u.offsetY=t.offsetY,u.from=u.recid,u.pos=e.position(),u.ghost=n(e).clone(!0),u.ghost.removeAttr("id"),e.find("td").remove(),e.append('<td colspan="1000" style="height: '+i.recordHeight+'px; background-color: #eee; border-bottom: 1px dashed #aaa; border-top: 1px dashed #aaa;"><\/td>'),v=n(i.box).find(".w2ui-grid-records"),v.append('<table id="grid_'+i.name+'_ghost" style="position: absolute; z-index: 999999; opacity: 0.7; pointer-events: none;"><\/table>'),n("#grid_"+i.name+"_ghost").append(r).append(u.ghost)),d=n("#grid_"+i.name+"_ghost"),v=n(i.box).find(".w2ui-grid-records"),d.css({top:u.pos.top+v.scrollTop(),left:u.pos.left,"border-top":"1px solid #aaa","border-bottom":"1px solid #aaa"})):i.last.move.reorder=!1);n(document).on("mousemove",c);n(document).on("mouseup",l);t.stopPropagation()}}function c(t){var r=i.last.move,ft,it,rt,ut,s,y,l,p,tt,g,nt,c,w,a,v,b,d,u,k,h,e,o;if(r&&["select","select-column"].indexOf(r.type)!=-1&&(r.divX=t.screenX-r.x,r.divY=t.screenY-r.y,!(Math.abs(r.divX)<=1)||!(Math.abs(r.divY)<=1))){if(i.last.cancelClick=!0,i.reorderRows==!0&&i.last.move.reorder){u=n(t.target).parents("tr");y=u.attr("recid");y!=r.from&&(ft=n("#grid_"+i.name+"_rec_"+r.recid),it=n("#grid_"+i.name+"_rec_"+y),n(i.box).find(".tmp-ghost").css("border-top","0px"),it.addClass("tmp-ghost").css("border-top","2px solid #769EFC"),r.lastY=t.screenY,r.to=y);rt=n("#grid_"+i.name+"_ghost");ut=n(i.box).find(".w2ui-grid-records");rt.css({top:r.pos.top+r.divY+ut.scrollTop(),left:r.pos.left});return}if(r.start&&r.recid&&(i.selectNone(),r.start=!1),s=[],y=t.target.tagName.toUpperCase()=="TR"?n(t.target).attr("recid"):n(t.target).parents("tr").attr("recid"),y==null){if(i.selectType=="row")return;if(i.last.move&&i.last.move.type=="select")return;if(l=parseInt(n(t.target).parents("td").attr("col")),isNaN(l))i.removeRange("column-selection"),n(i.box).find(".w2ui-grid-columns .w2ui-col-header, .w2ui-grid-fcolumns .w2ui-col-header").removeClass("w2ui-col-selected"),n(i.box).find(".w2ui-col-number").removeClass("w2ui-row-selected"),delete r.colRange;else{for(p=l+"-"+l,r.column<l&&(p=r.column+"-"+l),r.column>l&&(p=l+"-"+r.column),tt=[],u=p.split("-"),g=parseInt(u[0]);g<=parseInt(u[1]);g++)tt.push(g);if(r.colRange!=p&&(f=i.trigger({phase:"before",type:"columnSelect",target:i.name,columns:tt,isCancelled:!1}),f.isCancelled!==!0)){for(r.colRange==null&&i.selectNone(),u=p.split("-"),n(i.box).find(".w2ui-grid-columns .w2ui-col-header, .w2ui-grid-fcolumns .w2ui-col-header").removeClass("w2ui-col-selected"),nt=parseInt(u[0]);nt<=parseInt(u[1]);nt++)n(i.box).find("#grid_"+i.name+"_column_"+nt+" .w2ui-col-header").addClass("w2ui-col-selected");n(i.box).find(".w2ui-col-number").not(".w2ui-head").addClass("w2ui-row-selected");r.colRange=p;i.removeRange("column-selection");i.addRange({name:"column-selection",range:[{recid:i.records[0].recid,column:u[0]},{recid:i.records[i.records.length-1].recid,column:u[1]}],style:"background-color: rgba(90, 145, 234, 0.1)"})}}}else{if(c=i.get(r.recid,!0),c==null||i.records[c]&&i.records[c].recid!=r.recid)return;if(w=i.get(y,!0),w==null)return;if(a=parseInt(r.column),v=parseInt(t.target.tagName.toUpperCase()=="TD"?n(t.target).attr("col"):n(t.target).parents("td").attr("col")),isNaN(a)&&isNaN(v)&&(a=0,v=i.columns.length-1),c>w&&(u=c,c=w,w=u),u="ind1:"+c+",ind2;"+w+",col1:"+a+",col2:"+v,r.range==u)return;for(r.range=u,b=c;b<=w;b++)if(!(i.last.searchIds.length>0)||i.last.searchIds.indexOf(b)!=-1)if(i.selectType!="row")for(a>v&&(u=a,a=v,v=u),u=[],d=a;d<=v;d++)i.columns[d].hidden||s.push({recid:i.records[b].recid,column:parseInt(d)});else s.push(i.records[b].recid);if(i.selectType!="row"){for(h=i.getSelection(),u=[],e=0;e<s.length;e++){for(k=!1,o=0;o<h.length;o++)s[e].recid==h[o].recid&&s[e].column==h[o].column&&(k=!0);k||u.push({recid:s[e].recid,column:s[e].column})}for(i.select.apply(i,u),u=[],o=0;o<h.length;o++){for(k=!1,e=0;e<s.length;e++)s[e].recid==h[o].recid&&s[e].column==h[o].column&&(k=!0);k||u.push({recid:h[o].recid,column:h[o].column})}i.unselect.apply(i,u)}else if(i.multiSelect){for(h=i.getSelection(),e=0;e<s.length;e++)h.indexOf(s[e])==-1&&i.select(s[e]);for(o=0;o<h.length;o++)s.indexOf(h[o])==-1&&i.unselect(h[o])}}}}function l(t){var r=i.last.move,u,a,e,v,o,y;if(setTimeout(function(){delete i.last.cancelClick},1),!n(t.target).parents().hasClass(".w2ui-head")&&!n(t.target).hasClass(".w2ui-head")){if(r&&["select","select-column"].indexOf(r.type)!=-1){if(r.colRange!=null&&f.isCancelled!==!0){for(u=r.colRange.split("-"),a=[],e=0;e<i.records.length;e++){for(v=[],o=parseInt(u[0]);o<=parseInt(u[1]);o++)v.push(o);a.push({recid:i.records[e].recid,column:v})}i.removeRange("column-selection");i.trigger(n.extend(f,{phase:"after"}));i.select.apply(i,a)}if(i.reorderRows==!0&&i.last.move.reorder){if(y=i.trigger({phase:"before",target:i.name,type:"reorderRow",recid:r.from,moveAfter:r.to}),y.isCancelled===!0){n("#grid_"+i.name+"_ghost").remove();i.refresh();return}var s=i.get(r.from,!0),h=i.get(r.to,!0),u=i.records[s];s!=null&&h!=null&&(i.records.splice(s,1),s>h?i.records.splice(h,0,u):i.records.splice(h-1,0,u));n("#grid_"+i.name+"_ghost").remove();i.refresh();i.trigger(n.extend(y,{phase:"after"}))}}delete i.last.move;n(document).off("mousemove",c);n(document).off("mouseup",l)}}var i=this,a=(new Date).getTime(),e,o,r,s,h,u,f;if((t!=null&&(n(this.box).find("#grid_"+this.name+"_body").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),this.box=t),this.box)&&(e=typeof this.url!="object"?this.url:this.url.get,o=this.trigger({phase:"before",target:this.name,type:"render",box:t}),o.isCancelled!==!0)){if(this.reset(!0),!this.last.field)if(this.multiSearch&&this.show.searchAll)this.last.field="all",this.last.caption=w2utils.lang("All Fields");else{for(r=0;r<this.searches.length&&(this.searches[r].hidden||this.searches[r].simple===!1);)r++;r>=this.searches.length?(this.last.field="",this.last.caption=""):(this.last.field=this.searches[r].field,this.last.caption=this.searches[r].caption)}for(n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html('<div class="w2ui-grid-box">    <div id="grid_'+this.name+'_header" class="w2ui-grid-header"><\/div>    <div id="grid_'+this.name+'_toolbar" class="w2ui-grid-toolbar"><\/div>    <div id="grid_'+this.name+'_body" class="w2ui-grid-body"><\/div>    <div id="grid_'+this.name+'_fsummary" class="w2ui-grid-body w2ui-grid-summary"><\/div>    <div id="grid_'+this.name+'_summary" class="w2ui-grid-body w2ui-grid-summary"><\/div>    <div id="grid_'+this.name+'_footer" class="w2ui-grid-footer"><\/div>    <textarea id="grid_'+this.name+'_focus" class="w2ui-grid-focus-input"><\/textarea><\/div>'),this.selectType!="row"&&n(this.box).addClass("w2ui-ss"),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.initToolbar(),this.toolbar!=null&&this.toolbar.render(n("#grid_"+this.name+"_toolbar")[0]),this.last.field&&this.last.field!="all"&&(s=this.searchData,setTimeout(function(){i.initAllField(i.last.field,s.length==1?s[0].value:null)},1)),n("#grid_"+this.name+"_footer").html(this.getFooterHTML()),this.last.state||(this.last.state=this.stateSave(!0)),this.stateRestore(),e&&this.refresh(),h=!1,u=0;u<this.searches.length;u++)if(this.searches[u].hidden){h=!0;break}h?(this.searchReset(!1),e||setTimeout(function(){i.searchReset()},1)):this.reload();n(this.box).find("#grid_"+this.name+"_focus").on("focus",function(){clearTimeout(i.last.kbd_timer);i.hasFocus||i.focus()}).on("blur",function(){clearTimeout(i.last.kbd_timer);i.last.kbd_timer=setTimeout(function(){i.hasFocus&&i.blur()},100)}).on("paste",function(){var n=this;setTimeout(function(){w2ui[i.name].paste(n.value);n.value=""},1)}).on("keydown",function(n){w2ui[i.name].keydown.call(w2ui[i.name],n)});n(this.box).on("mousedown",v);if(this.trigger(n.extend(o,{phase:"after"})),n(".w2ui-layout").length===0)n(window).off("resize.w2ui-"+this.name).on("resize.w2ui-"+this.name,function(){w2ui[i.name].resize()});return(new Date).getTime()-a}},destroy:function(){var t=this.trigger({phase:"before",target:this.name,type:"destroy"});t.isCancelled!==!0&&(n(window).off("resize.w2ui-"+this.name),typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),n(this.box).find("#grid_"+this.name+"_body").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})))},initColumnOnOff:function(){var n,i,t,u,r,f;if(this.show.toolbarColumns){for(n=this,i='<div class="w2ui-col-on-off"><table><tbody><tr id="grid_'+this.name+'_column_ln_check" onclick="w2ui[\''+n.name+'\'].columnOnOff(event, \'line-numbers\'); event.stopPropagation();">   <td style="width: 30px; text-align: center; padding-right: 3px; color: #888;">      <span class="w2ui-column-check w2ui-icon-'+(n.show.lineNumbers?"check":"empty")+'"><\/span>   <\/td>   <td onclick="jQuery(\'.w2ui-overlay\')[0].hide();">      <label>'+w2utils.lang("Line #")+"<\/label>   <\/td><\/tr>",t=0;t<this.columns.length;t++)(u=this.columns[t],r=this.columns[t].caption,u.hideable!==!1)&&(!r&&this.columns[t].tooltip&&(r=this.columns[t].tooltip),r||(r="- column "+(parseInt(t)+1)+" -"),i+='<tr id="grid_'+this.name+"_column_"+t+'_check"        onclick="w2ui[\''+n.name+"'].columnOnOff(event, '"+u.field+'\'); event.stopPropagation();">   <td style="width: 30px; text-align: center; padding-right: 3px; color: #888;">      <span class="w2ui-column-check w2ui-icon-'+(u.hidden?"empty":"check")+'"><\/span>   <\/td>   <td onclick="jQuery(\'.w2ui-overlay\')[0].hide();">       <label>'+w2utils.stripTags(r)+"<\/label>   <\/td><\/tr>");f=typeof this.url!="object"?this.url:this.url.get;(f&&n.show.skipRecords||n.show.saveRestoreState)&&(i+='<tr style="pointer-events: none"><td colspan="2"><div style="border-top: 1px solid #ddd;"><\/div><\/td><\/tr>');f&&n.show.skipRecords&&(i+='<tr><td colspan="2" style="padding: 0px">    <div style="cursor: pointer; padding: 2px 8px; cursor: default">'+w2utils.lang("Skip")+'        <input type="text" style="width: 60px" value="'+this.offset+'"             onkeydown="if ([48,49,50,51,52,53,54,55,56,57,58,13,8,46,37,39].indexOf(event.keyCode) == -1) { event.preventDefault() }"            onkeypress="if (event.keyCode == 13) {                w2ui[\''+n.name+"'].skip(this.value);                jQuery('.w2ui-overlay')[0].hide();             }\"/> "+w2utils.lang("Records")+"    <\/div><\/td><\/tr>");n.show.saveRestoreState&&(i+='<tr><td colspan="2" onclick="var obj = w2ui[\''+n.name+"']; obj.toolbar.uncheck('w2ui-column-on-off'); obj.stateSave();\">    <div style=\"cursor: pointer; padding: 4px 8px; cursor: default\">"+w2utils.lang("Save Grid State")+'<\/div><\/td><\/tr><tr><td colspan="2" onclick="var obj = w2ui[\''+n.name+"']; obj.toolbar.uncheck('w2ui-column-on-off'); obj.stateReset();\">    <div style=\"cursor: pointer; padding: 4px 8px; cursor: default\">"+w2utils.lang("Restore Default State")+"<\/div><\/td><\/tr>");i+="<\/tbody><\/table><\/div>";this.toolbar.get("w2ui-column-on-off").html=i}},initColumnDrag:function(){function r(){t.pressed=!1;clearTimeout(t.timeout)}function u(r){t.timeout&&clearTimeout(t.timeout);const u=this;t.pressed=!0;t.timeout=setTimeout(function(){var o,s;if(t.pressed){var h,c,a,l,v,y=["w2ui-col-number","w2ui-col-expand","w2ui-col-select"].concat(["w2ui-head-last"]);if(n(r.originalEvent.target).parents().hasClass("w2ui-head")){for(o=0,s=y.length;o<s;o++)if(n(r.originalEvent.target).parents().hasClass(y[o]))return;if(t.numberPreColumnsPresent=n(i.box).find(".w2ui-head.w2ui-col-number, .w2ui-head.w2ui-col-expand, .w2ui-head.w2ui-col-select").length,t.columnHead=l=n(r.originalEvent.target).parents(".w2ui-head"),v=parseInt(l.attr("col"),10),h=i.trigger({type:"columnDragStart",phase:"before",originalEvent:r,origColumnNumber:v,target:l[0]}),h.isCancelled===!0)return!1;c=t.columns=n(i.box).find(".w2ui-head:not(.w2ui-head-last)");n(document).on("mouseup",e);n(document).on("mousemove",f);for(t.originalPos=parseInt(n(r.originalEvent.target).parent(".w2ui-head").attr("col"),10),t.ghost=n(u).clone(!0),n(t.ghost).find('[col]:not([col="'+t.originalPos+'"]), .w2ui-toolbar, .w2ui-grid-header').remove(),n(t.ghost).find(".w2ui-col-number, .w2ui-col-expand, .w2ui-col-select").remove(),n(t.ghost).find(".w2ui-grid-body").css({top:0}),a=n(t.ghost).find('[col="'+t.originalPos+'"]'),n(document.body).append(t.ghost),n(t.ghost).css({width:0,height:0,margin:0,position:"fixed",zIndex:999999,opacity:0}).addClass(".w2ui-grid-ghost").animate({width:a.width(),height:n(i.box).find(".w2ui-grid-body:first").height(),left:r.pageX,top:r.pageY,opacity:.8},0),t.offsets=[],o=0,s=c.length;o<s;o++)t.offsets.push(n(c[o]).offset().left);i.trigger(n.extend(h,{phase:"after"}))}}},150)}function f(i){if(t.pressed){var r=i.originalEvent.pageX,u=i.originalEvent.pageY,f=t.offsets,e=n(".w2ui-head:not(.w2ui-head-last)").width();t.targetInt=Math.max(t.numberPreColumnsPresent,s(r,f,e));o(t.targetInt);h(r,u)}}function e(r){t.pressed=!1;var h,u,c,o,s,l=n(".w2ui-grid-ghost");if(h=i.trigger({type:"columnDragEnd",phase:"before",originalEvent:r,target:t.columnHead[0]}),h.isCancelled===!0)return!1;c=i.columns[t.originalPos];o=i.columns;s=n(t.columns[Math.min(t.lastInt,t.columns.length-1)]);u=t.lastInt<t.columns.length?parseInt(s.attr("col")):o.length;u!==t.originalPos+1&&u!==t.originalPos&&s&&s.length?(n(t.ghost).animate({top:n(i.box).offset().top,left:s.offset().left,width:0,height:0,opacity:.2},300,function(){n(this).remove();l.remove()}),o.splice(u,0,n.extend({},c)),o.splice(o.indexOf(c),1)):(n(t.ghost).remove(),l.remove());n(document).off("mouseup",e);n(document).off("mousemove",f);t.marker&&t.marker.remove();t={};i.refresh();i.trigger(n.extend(h,{phase:"after",targetColumnNumber:u-1}))}function o(i){t.marker||t.markerLeft||(t.marker=n('<div class="col-intersection-marker"><div class="top-marker"><\/div><div class="bottom-marker"><\/div><\/div>'),t.markerLeft=n('<div class="col-intersection-marker"><div class="top-marker"><\/div><div class="bottom-marker"><\/div><\/div>'));t.lastInt&&t.lastInt===i||(t.lastInt=i,t.marker.remove(),t.markerLeft.remove(),n(".w2ui-head").removeClass("w2ui-col-intersection"),i>=t.columns.length?(n(t.columns[t.columns.length-1]).children("div:last").append(t.marker.addClass("right").removeClass("left")),n(t.columns[t.columns.length-1]).addClass("w2ui-col-intersection")):i<=t.numberPreColumnsPresent?(n(t.columns[t.numberPreColumnsPresent]).prepend(t.marker.addClass("left").removeClass("right")).css({position:"relative"}),n(t.columns[t.numberPreColumnsPresent]).prev().addClass("w2ui-col-intersection")):(n(t.columns[i]).children("div:last").prepend(t.marker.addClass("left").removeClass("right")),n(t.columns[i]).prev().children("div:last").append(t.markerLeft.addClass("right").removeClass("left")).css({position:"relative"}),n(t.columns[i-1]).addClass("w2ui-col-intersection")))}function s(n,t,i){var r,u;if(n<=t[0])return 0;if(n>=t[t.length-1]+i)return t.length;for(r=0,u=t.length;r<u;r++){var o=t[r],f=t[r+1]||t[r]+i,e=(f-t[r])/2+t[r];if(n>o&&n<=e)return r;if(n>e&&n<=f)return r+1}return intersection}function h(i,r){n(t.ghost).css({left:i-10,top:r-10})}if(this.columnGroups&&this.columnGroups.length)throw"Draggable columns are not currently supported with column groups.";var i=this,t={};t.lastInt=null;t.pressed=!1;t.timeout=null;t.columnHead=null;n(i.box).on("mousedown",u);n(i.box).on("mouseup",r);return{remove:function(){n(i.box).off("mousedown",u);n(i.box).off("mouseup",r);n(i.box).find(".w2ui-head").removeAttr("draggable");i.last.columnDrag=!1}}},columnOnOff:function(t,i){var u=n(t.target).parents("tr").find(".w2ui-column-check"),s=this.trigger({phase:"before",target:this.name,type:"columnOnOff",field:i,originalEvent:t}),e,h,r,o,f;if(s.isCancelled!==!0){for(e=this,h=e.find({"w2ui.expanded":!0},!0),r=0;r<h.length;r++)o=this.records[r].w2ui,o&&!Array.isArray(o.children)&&(this.records[r].w2ui.expanded=!1);i=="line-numbers"?(this.show.lineNumbers=!this.show.lineNumbers,this.show.lineNumbers?u.addClass("w2ui-icon-check").removeClass("w2ui-icon-empty"):u.addClass("w2ui-icon-empty").removeClass("w2ui-icon-check"),this.refreshBody(),this.resizeRecords()):(f=this.getColumn(i),f.hidden?(u.addClass("w2ui-icon-check").removeClass("w2ui-icon-empty"),this.showColumn(f.field)):(u.addClass("w2ui-icon-empty").removeClass("w2ui-icon-check"),this.hideColumn(f.field)));t.shiftKey||t.metaKey||t.ctrlKey||setTimeout(function(){n().w2overlay({name:e.name+"_toolbar"})},150);this.trigger(n.extend(s,{phase:"after"}))}},scrollToColumn:function(n){var r,u,i,t,f;if(n!=null){for(r=0,u=!1,i=0;i<this.columns.length;i++){if(t=this.columns[i],t.field==n){u=!0;break}t.frozen||t.hidden||(f=parseInt(t.sizeCalculated?t.sizeCalculated:t.size),r+=f)}u&&(this.last.scrollLeft=r+1,this.scroll())}},initRowDrag:function(){function r(){t.pressed=!1;clearTimeout(t.timeout);n(t.ghost).length&&n(t.ghost).remove();t={}}function u(r){var u,f;if(t.timeout&&clearTimeout(t.timeout),t.pressed=!0,u=n(i.box).find("tr.w2ui-selected"),!(u.length>0)){if(f=r.target.tagName=="TR"?n(r.target).attr("recid"):n(r.target).parents("tr").attr("recid"),typeof f=="undefined")return;i.select(f)}t.selectedRows=u;r.originalEvent.dataTransfer.effectAllowed="copy";r.originalEvent.dataTransfer.setData("text",JSON.stringify({sourceGrid:i.name,recid:n(this).attr("recid")}))}var i=this,t={};t.lastInt=null;t.pressed=!1;t.timeout=null;n(i.box).find("tr").each(function(){typeof n(this).attr("id")!="undefined"&&(n(this).is(".w2ui-even")||n(this).is(".w2ui-odd"))&&n(this).attr("draggable","true")});n(i.box).on("dragstart","tr",u);n(i.box).on("dragend","tr",r)},initToolbar:function(){var t=this,i,u,r;if(this.toolbar.render==null){if(i=this.toolbar.items,this.toolbar.items=[],this.toolbar=n().w2toolbar(n.extend(!0,{},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.show.toolbarReload&&this.toolbar.items.push(n.extend(!0,{},this.buttons.reload)),this.show.toolbarColumns&&this.toolbar.items.push(n.extend(!0,{},this.buttons.columns)),(this.show.toolbarReload||this.show.toolbarColumns)&&this.toolbar.items.push({type:"break",id:"w2ui-break0"}),this.show.toolbarInput&&(u='<div class="w2ui-toolbar-search"><table cellpadding="0" cellspacing="0"><tbody><tr>    <td>'+this.buttons.search.html+'<\/td>    <td>        <input type="text" id="grid_'+this.name+'_search_all" class="w2ui-search-all" tabindex="-1"             placeholder="'+w2utils.lang(this.last.caption)+'" value="'+this.last.search+'"            onfocus="clearTimeout(w2ui[\''+this.name+'\'].last.kbd_timer);"            onkeydown="if (event.keyCode == 13 &amp;&amp; w2utils.isIE) this.onchange();"            onchange="                var grid = w2ui[\''+this.name+"'];                 var val = this.value;                 var sel = jQuery(this).data('selected');                var fld = jQuery(this).data('w2field');                 if (fld) val = fld.clean(val);                if (fld &amp;&amp; fld.type == 'list' &amp;&amp; sel &amp;&amp; typeof sel.id == 'undefined') {                   grid.searchReset();                } else {                   grid.search(grid.last.field, val);                }            \"/>    <\/td>    <td>        <div class=\"w2ui-search-clear\" id=\"grid_"+this.name+'_searchClear"               onclick="var obj = w2ui[\''+this.name+'\']; obj.searchReset();" style="display: none"        >&#160;&#160;<\/div>    <\/td><\/tr><\/tbody><\/table><\/div>',this.toolbar.items.push({type:"html",id:"w2ui-search",html:u})),this.show.toolbarSearch&&this.multiSearch&&this.searches.length>0&&this.toolbar.items.push(n.extend(!0,{},this.buttons["search-go"])),(this.show.toolbarSearch||this.show.toolbarInput)&&(this.show.toolbarAdd||this.show.toolbarEdit||this.show.toolbarDelete||this.show.toolbarSave)&&this.toolbar.items.push({type:"break",id:"w2ui-break1"}),this.show.toolbarAdd&&this.toolbar.items.push(n.extend(!0,{},this.buttons.add)),this.show.toolbarEdit&&this.toolbar.items.push(n.extend(!0,{},this.buttons.edit)),this.show.toolbarDelete&&this.toolbar.items.push(n.extend(!0,{},this.buttons["delete"])),this.show.toolbarSave&&((this.show.toolbarAdd||this.show.toolbarDelete||this.show.toolbarEdit)&&this.toolbar.items.push({type:"break",id:"w2ui-break2"}),this.toolbar.items.push(n.extend(!0,{},this.buttons.save))),i)for(r=0;r<i.length;r++)this.toolbar.items.push(i[r]);t=this;this.toolbar.on("click",function(i){var r=t.trigger({phase:"before",type:"toolbar",target:i.target,originalEvent:i}),u,f,e,h,o,s;if(r.isCancelled!==!0){u=i.target;switch(u){case"w2ui-reload":if(f=t.trigger({phase:"before",type:"reload",target:t.name}),f.isCancelled===!0)return!1;t.reload();t.trigger(n.extend(f,{phase:"after"}));break;case"w2ui-column-on-off":t.initColumnOnOff();t.initResize();t.resize();break;case"w2ui-search-advanced":if(e=this,h=this.get(u),h.checked)t.searchClose(),setTimeout(function(){e.uncheck(u)},1);else{t.searchOpen();i.originalEvent.stopPropagation();function r(){n("#w2ui-overlay-"+t.name+"-searchOverlay").data("keepOpen")!==!0&&(e.uncheck(u),n(document).off("click","body",r))}n(document).on("click","body",r)}break;case"w2ui-add":r=t.trigger({phase:"before",target:t.name,type:"add",recid:null});t.trigger(n.extend(r,{phase:"after"}));setTimeout(function(){n().w2tag()},20);break;case"w2ui-edit":o=t.getSelection();s=null;o.length==1&&(s=o[0]);r=t.trigger({phase:"before",target:t.name,type:"edit",recid:s});t.trigger(n.extend(r,{phase:"after"}));setTimeout(function(){n().w2tag()},20);break;case"w2ui-delete":t["delete"]();break;case"w2ui-save":t.save()}t.trigger(n.extend(r,{phase:"after"}))}})}},initResize:function(){var t=this;n(this.box).find(".w2ui-resizer").off("click").on("click",function(n){n.stopPropagation?n.stopPropagation():n.cancelBubble=!0;n.preventDefault&&n.preventDefault()}).off("mousedown").on("mousedown",function(i){var r,u,f,e;for(i||(i=window.event),t.resizing=!0,t.last.tmp={x:i.screenX,y:i.screenY,gx:i.screenX,gy:i.screenY,col:parseInt(n(this).attr("name"))},i.stopPropagation?i.stopPropagation():i.cancelBubble=!0,i.preventDefault&&i.preventDefault(),r=0;r<t.columns.length;r++)t.columns[r].hidden||(t.columns[r].sizeOriginal==null&&(t.columns[r].sizeOriginal=t.columns[r].size),t.columns[r].size=t.columns[r].sizeCalculated);u={phase:"before",type:"columnResize",target:t.name,column:t.last.tmp.col,field:t.columns[t.last.tmp.col].field};u=t.trigger(n.extend(u,{resizeBy:0,originalEvent:i}));f=function(i){if(t.resizing==!0){if(i||(i=window.event),u=t.trigger(n.extend(u,{resizeBy:i.screenX-t.last.tmp.gx,originalEvent:i})),u.isCancelled===!0){u.isCancelled=!1;return}t.last.tmp.x=i.screenX-t.last.tmp.x;t.last.tmp.y=i.screenY-t.last.tmp.y;t.columns[t.last.tmp.col].size=parseInt(t.columns[t.last.tmp.col].size)+t.last.tmp.x+"px";t.resizeRecords();t.scroll();t.last.tmp.x=i.screenX;t.last.tmp.y=i.screenY}};e=function(i){delete t.resizing;n(document).off("mousemove","body");n(document).off("mouseup","body");t.resizeRecords();t.scroll();t.trigger(n.extend(u,{phase:"after",originalEvent:i}))};n(document).on("mousemove","body",f);n(document).on("mouseup","body",e)}).each(function(t,i){var r=n(i).parent();n(i).css({height:"25px","margin-left":r.width()-3+"px"})})},resizeBoxes:function(){var i=n("#grid_"+this.name+"_header"),r=n("#grid_"+this.name+"_toolbar"),f=n("#grid_"+this.name+"_fsummary"),u=n("#grid_"+this.name+"_summary"),t=n("#grid_"+this.name+"_footer"),e=n("#grid_"+this.name+"_body");this.show.header&&i.css({top:"0px",left:"0px",right:"0px"});this.show.toolbar&&r.css({top:0+(this.show.header?w2utils.getSize(i,"height"):0)+"px",left:"0px",right:"0px"});this.summary.length>0&&(f.css({bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+"px"}),u.css({bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+"px",right:"0px"}));this.show.footer&&t.css({bottom:"0px",left:"0px",right:"0px"});e.css({top:0+(this.show.header?w2utils.getSize(i,"height"):0)+(this.show.toolbar?w2utils.getSize(r,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(t,"height"):0)+(this.summary.length>0?w2utils.getSize(u,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){function yt(t,i,r){var u="",o="",s="",f,e;for(u+='<tr class="'+(t%2?"w2ui-even":"w2ui-odd")+' w2ui-empty-record" style="height: '+i+'px">',o+='<tr class="'+(t%2?"w2ui-even":"w2ui-odd")+' w2ui-empty-record" style="height: '+i+'px">',r.show.lineNumbers&&(u+='<td class="w2ui-col-number"><\/td>'),r.show.selectColumn&&(u+='<td class="w2ui-grid-data w2ui-col-select"><\/td>'),r.show.expandColumn&&(u+='<td class="w2ui-grid-data w2ui-col-expand"><\/td>'),o+='<td class="w2ui-grid-data-spacer" col="start" style="border-right: 0"><\/td>',f=0;f<r.columns.length;f++)(e=r.columns[f],(e.hidden||f<r.last.colStart||f>r.last.colEnd)&&!e.frozen)||(s='<td class="w2ui-grid-data" '+(e.attr!=null?e.attr:"")+' col="'+f+'"><\/td>',e.frozen?u+=s:o+=s);u+='<td class="w2ui-grid-data-last"><\/td> <\/tr>';o+='<td class="w2ui-grid-data-last" col="end"><\/td> <\/tr>';n("#grid_"+r.name+"_frecords > table").append(u);n("#grid_"+r.name+"_records > table").append(o)}var t=this,at,p,it,vt,w,b,d,ft,o,i,e,r;n(this.box).find(".w2ui-empty-record").remove();var et=n(this.box),k=n(this.box).find("> div.w2ui-grid-box"),ot=n("#grid_"+this.name+"_header"),st=n("#grid_"+this.name+"_toolbar"),c=n("#grid_"+this.name+"_summary"),ht=n("#grid_"+this.name+"_fsummary"),ct=n("#grid_"+this.name+"_footer"),v=n("#grid_"+this.name+"_body"),f=n("#grid_"+this.name+"_columns"),nt=n("#grid_"+this.name+"_fcolumns"),u=n("#grid_"+this.name+"_records"),y=n("#grid_"+this.name+"_frecords"),tt=n("#grid_"+this.name+"_scroll1"),s=String(this.total).length*8+10;s<34&&(s=34);this.lineNumberWidth!=null&&(s=this.lineNumberWidth);var l=!1,a=!1,lt=0;for(r=0;r<t.columns.length;r++)t.columns[r].frozen||t.columns[r].hidden||(at=parseInt(t.columns[r].sizeCalculated?t.columns[r].sizeCalculated:t.columns[r].size),lt+=at);if(u.width()<lt&&(l=!0),v.height()-f.height()<n(u).find(">table").height()+(l?w2utils.scrollBarSize():0)&&(a=!0),this.fixedBody?(p=k.height()-(this.show.header?w2utils.getSize(ot,"height"):0)-(this.show.toolbar?w2utils.getSize(st,"height"):0)-(c.css("display")!="none"?w2utils.getSize(c,"height"):0)-(this.show.footer?w2utils.getSize(ct,"height"):0),v.css("height",p)):(p=w2utils.getSize(f,"height")+w2utils.getSize(n("#grid_"+t.name+"_records table"),"height")+(l?w2utils.scrollBarSize():0),t.height=p+w2utils.getSize(k,"+height")+(t.show.header?w2utils.getSize(ot,"height"):0)+(t.show.toolbar?w2utils.getSize(st,"height"):0)+(c.css("display")!="none"?w2utils.getSize(c,"height"):0)+(t.show.footer?w2utils.getSize(ct,"height"):0),k.css("height",t.height),v.css("height",p),et.css("height",w2utils.getSize(k,"height")+w2utils.getSize(et,"+height"))),it=this.records.length,vt=typeof this.url!="object"?this.url:this.url.get,this.searchData.length==0||vt||(it=this.last.searchIds.length),this.fixedBody||(a=!1),l||a?(f.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show(),u.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(f,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":l?"auto":"hidden","overflow-y":a?"auto":"hidden"})):(f.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide(),u.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(f,"height")+"px",overflow:"hidden"}),u.length>0&&(this.last.scrollTop=0,this.last.scrollLeft=0)),l?(y.css("margin-bottom",w2utils.scrollBarSize()),tt.show()):(y.css("margin-bottom",0),tt.hide()),y.css({overflow:"hidden",top:u.css("top")}),this.show.emptyRecords&&!a&&(w=Math.floor(u.height()/this.recordHeight)-1,b=0,u[0]&&(b=u[0].scrollHeight-w*this.recordHeight),b>=this.recordHeight&&(b-=this.recordHeight,w++),this.fixedBody)){for(d=it;d<w;d++)yt(d,this.recordHeight,this);yt(w,b,this)}if(v.length>0){var g=parseInt(v.width())-(a?w2utils.scrollBarSize():0)-(this.show.lineNumbers?s:0)-(this.show.selectColumn?26:0)-(this.show.expandColumn?26:0)-1,rt=g,h=0,ut=!1;for(r=0;r<this.columns.length;r++)i=this.columns[r],i.gridMinWidth>0&&(i.gridMinWidth>rt&&i.hidden!==!0&&(i.hidden=!0,ut=!0),i.gridMinWidth<rt&&i.hidden===!0&&(i.hidden=!1,ut=!0));if(ut===!0){this.refresh();return}for(r=0;r<this.columns.length;r++)(i=this.columns[r],i.hidden)||(String(i.size).substr(String(i.size).length-2).toLowerCase()=="px"?(g-=parseFloat(i.size),this.columns[r].sizeCalculated=i.size,this.columns[r].sizeType="px"):(h+=parseFloat(i.size),this.columns[r].sizeType="%",delete i.sizeCorrected));if(h!=100&&h>0)for(r=0;r<this.columns.length;r++)(i=this.columns[r],i.hidden)||i.sizeType=="%"&&(i.sizeCorrected=Math.round(parseFloat(i.size)*1e4/h)/100+"%");for(r=0;r<this.columns.length;r++)(i=this.columns[r],i.hidden)||i.sizeType=="%"&&(this.columns[r].sizeCalculated=this.columns[r].sizeCorrected!=null?Math.floor(g*parseFloat(i.sizeCorrected)/100)-1+"px":Math.floor(g*parseFloat(i.size)/100)-1+"px")}for(ft=0,r=0;r<this.columns.length;r++)(i=this.columns[r],i.hidden)||(i.min==null&&(i.min=20),parseInt(i.sizeCalculated)<parseInt(i.min)&&(i.sizeCalculated=i.min+"px"),parseInt(i.sizeCalculated)>parseInt(i.max)&&(i.sizeCalculated=i.max+"px"),ft+=parseInt(i.sizeCalculated));if(o=parseInt(rt)-parseInt(ft),o>0&&h>0)for(r=0;;){if(i=this.columns[r],i==null){r=0;continue}if(i.hidden||i.sizeType=="px"){r++;continue}if(i.sizeCalculated=parseInt(i.sizeCalculated)+1+"px",o--,o===0)break;r++}else o>0&&f.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();for(e=1,this.show.lineNumbers&&(e+=s),this.show.selectColumn&&(e+=26),this.show.expandColumn&&(e+=26),r=0;r<this.columns.length;r++)this.columns[r].hidden||this.columns[r].frozen&&(e+=parseInt(this.columns[r].sizeCalculated));nt.css("width",e);y.css("width",e);ht.css("width",e);tt.css("width",e);f.css("left",e);u.css("left",e);c.css("left",e);f.find("> table > tbody > tr:nth-child(1) td").add(nt.find("> table > tbody > tr:nth-child(1) td")).each(function(i,r){var e,f,u;if(n(r).hasClass("w2ui-col-number")&&n(r).css("width",s),e=n(r).attr("col"),e!=null){if(e=="start"){for(f=0,u=0;u<t.last.colStart;u++)!t.columns[u]||t.columns[u].frozen||t.columns[u].hidden||(f+=parseInt(t.columns[u].sizeCalculated));n(r).css("width",f+"px")}t.columns[e]&&n(r).css("width",t.columns[e].sizeCalculated)}if(n(r).hasClass("w2ui-head-last"))if(t.last.colEnd+1<t.columns.length){for(f=0,u=t.last.colEnd+1;u<t.columns.length;u++)!t.columns[u]||t.columns[u].frozen||t.columns[u].hidden||(f+=parseInt(t.columns[u].sizeCalculated));n(r).css("width",f+"px")}else n(r).css("width",w2utils.scrollBarSize()+(o>0&&h===0?o:0)+"px")});f.find("> table > tbody > tr").length==3&&f.find("> table > tbody > tr:nth-child(1) td").add(nt.find("> table > tbody > tr:nth-child(1) td")).html("").css({height:"0px",border:"0px",padding:"0px",margin:"0px"});u.find("> table > tbody > tr:nth-child(1) td").add(y.find("> table > tbody > tr:nth-child(1) td")).each(function(i,r){var e,f,u;if(n(r).hasClass("w2ui-col-number")&&n(r).css("width",s),e=n(r).attr("col"),e!=null){if(e=="start"){for(f=0,u=0;u<t.last.colStart;u++)!t.columns[u]||t.columns[u].frozen||t.columns[u].hidden||(f+=parseInt(t.columns[u].sizeCalculated));n(r).css("width",f+"px")}t.columns[e]&&n(r).css("width",t.columns[e].sizeCalculated)}if(n(r).hasClass("w2ui-grid-data-last")&&n(r).parents(".w2ui-grid-frecords").length===0)if(t.last.colEnd+1<t.columns.length){for(f=0,u=t.last.colEnd+1;u<t.columns.length;u++)!t.columns[u]||t.columns[u].frozen||t.columns[u].hidden||(f+=parseInt(t.columns[u].sizeCalculated));n(r).css("width",f+"px")}else n(r).css("width",(o>0&&h===0?o:0)+"px")});c.find("> table > tbody > tr:nth-child(1) td").add(ht.find("> table > tbody > tr:nth-child(1) td")).each(function(i,r){var f,e,u;if(n(r).hasClass("w2ui-col-number")&&n(r).css("width",s),f=n(r).attr("col"),f!=null){if(f=="start"){for(e=0,u=0;u<t.last.colStart;u++)!t.columns[u]||t.columns[u].frozen||t.columns[u].hidden||(e+=parseInt(t.columns[u].sizeCalculated));n(r).css("width",e+"px")}t.columns[f]&&n(r).css("width",t.columns[f].sizeCalculated)}n(r).hasClass("w2ui-grid-data-last")&&n(r).parents(".w2ui-grid-frecords").length===0&&n(r).css("width",w2utils.scrollBarSize()+(o>0&&h===0?o:0)+"px")});this.initResize();this.refreshRanges();(this.last.scrollTop||this.last.scrollLeft)&&u.length>0&&(f.prop("scrollLeft",this.last.scrollLeft),u.prop("scrollTop",this.last.scrollTop),u.prop("scrollLeft",this.last.scrollLeft))},getSearchesHTML:function(){function h(t,i){var s="",o=e.operators[e.operatorsMap[t]],f,r,u;for(i!=null&&(o=i),f=0;f<o.length;f++)r=o[f],u=r,Array.isArray(r)?(u=r[1],r=r[0],u==null&&(u=r)):n.isPlainObject(r)&&(u=r.text,r=r.oper),s+='<option value="'+r+'">'+w2utils.lang(u)+"<\/option>\n";return s}for(var t,f,s,r,e=this,u='<table cellspacing="0" onclick="event.stopPropagation()"><tbody>',o=!1,i=0;i<this.searches.length;i++)if(t=this.searches[i],t.type=String(t.type).toLowerCase(),!t.hidden){f="";o==!1&&(f='<button class="w2ui-btn close-btn" onclick="obj = w2ui[\''+this.name+"']; if (obj) obj.searchClose()\">X<\/button>",o=!0);t.inTag==null&&(t.inTag="");t.outTag==null&&(t.outTag="");t.style==null&&(t.style="");t.type==null&&(t.type="text");s='<select id="grid_'+this.name+"_operator_"+i+'" class="w2ui-input" onclick="event.stopPropagation();"   onchange="w2ui[\''+this.name+"'].initOperator(this, "+i+')">'+h(t.type,t.operators)+"<\/select>";u+='<tr>    <td class="close-btn">'+f+'<\/td>    <td class="caption">'+(t.caption||"")+'<\/td>    <td class="operator">'+s+'<\/td>    <td class="value">';switch(t.type){case"text":case"alphanumeric":case"hex":case"color":case"list":case"combo":case"enum":r="width: 250px;";["hex","color"].indexOf(t.type)!=-1&&(r="width: 90px;");u+='<input rel="search" type="text" id="grid_'+this.name+"_field_"+i+'" name="'+t.field+'"    class="w2ui-input" style="'+r+t.style+'" '+t.inTag+"/>";break;case"int":case"float":case"money":case"currency":case"percent":case"date":case"time":case"datetime":r="width: 90px";t.type=="datetime"&&(r="width: 140px;");u+='<input rel="search" type="text" class="w2ui-input" style="'+r+t.style+'" id="grid_'+this.name+"_field_"+i+'" name="'+t.field+'" '+t.inTag+'/><span id="grid_'+this.name+"_range_"+i+'" style="display: none">&#160;-&#160;&#160;<input rel="search" type="text" class="w2ui-input" style="'+r+t.style+'" id="grid_'+this.name+"_field2_"+i+'" name="'+t.field+'" '+t.inTag+"/><\/span>";break;case"select":u+='<select rel="search" class="w2ui-input" style="'+t.style+'" id="grid_'+this.name+"_field_"+i+'"  name="'+t.field+'" '+t.inTag+'  onclick="event.stopPropagation();"><\/select>'}u+=t.outTag+"    <\/td><\/tr>"}return u+('<tr>    <td colspan="4" class="actions">        <div>        <button class="w2ui-btn" onclick="obj = w2ui[\''+this.name+"']; if (obj) { obj.searchReset(); }\">"+w2utils.lang("Reset")+'<\/button>        <button class="w2ui-btn w2ui-btn-blue" onclick="obj = w2ui[\''+this.name+"']; if (obj) { obj.search(); }\">"+w2utils.lang("Search")+"<\/button>        <\/div>    <\/td><\/tr><\/tbody><\/table>")},initOperator:function(t,i){var u=this,f=u.searches[i],e=n("#grid_"+u.name+"_range_"+i),r=n("#grid_"+u.name+"_field_"+i),o=r.parent().find("span input");r.show();e.hide();switch(n(t).val()){case"between":e.show();o.w2field(f.type,f.options);break;case"not null":case"null":r.hide();r.val("1");r.change()}},initSearches:function(){for(var t,i,c,o,l,f,u,e,h,a,s=this,r=0;r<this.searches.length;r++){for(t=this.searches[r],i=this.getSearchData(t.field),t.type=String(t.type).toLowerCase(),c=s.operators[s.operatorsMap[t.type]],t.operators&&(c=t.operators),o=c[0],n.isPlainObject(o)&&(o=o.oper),typeof t.options!="object"&&(t.options={}),t.type=="text"&&(o="begins"),u=0;u<c.length;u++)if(l=c[u],n.isPlainObject(l)&&(l=l.oper),t.operator==l){o=t.operator;break}switch(t.type){case"text":case"alphanumeric":n("#grid_"+this.name+"_field_"+r).w2field(t.type,t.options);break;case"int":case"float":case"hex":case"color":case"money":case"currency":case"percent":case"date":case"time":case"datetime":n("#grid_"+this.name+"_field_"+r).w2field(t.type,t.options);n("#grid_"+this.name+"_field2_"+r).w2field(t.type,t.options);setTimeout(function(){n("#grid_"+s.name+"_field_"+r).keydown();n("#grid_"+s.name+"_field2_"+r).keydown()},1);break;case"list":case"combo":case"enum":f=t.options;t.type=="list"&&(f.selected={});t.type=="enum"&&(f.selected=[]);i&&(f.selected=i.value);n("#grid_"+this.name+"_field_"+r).w2field(t.type,n.extend({openOnFocus:!0},f));i&&i.text!=null&&n("#grid_"+this.name+"_field_"+r).data("selected",{id:i.value,text:i.text});break;case"select":for(f='<option value="">--<\/option>',u=0;u<t.options.items.length;u++)e=t.options.items[u],n.isPlainObject(t.options.items[u])?(h=e.id,a=e.text,h==null&&e.value!=null&&(h=e.value),a==null&&e.caption!=null&&(a=e.caption),h==null&&(h=""),f+='<option value="'+h+'">'+a+"<\/option>"):f+='<option value="'+e+'">'+e+"<\/option>";n("#grid_"+this.name+"_field_"+r).html(f)}i!=null?(i.type=="int"&&["in","not in"].indexOf(i.operator)!=-1&&n("#grid_"+this.name+"_field_"+r).w2field("clear").val(i.value),n("#grid_"+this.name+"_operator_"+r).val(i.operator).trigger("change"),n.isArray(i.value)?["in","not in"].indexOf(i.operator)!=-1?n("#grid_"+this.name+"_field_"+r).val(i.value).trigger("change"):(n("#grid_"+this.name+"_field_"+r).val(i.value[0]).trigger("change"),n("#grid_"+this.name+"_field2_"+r).val(i.value[1]).trigger("change")):i.value!=null&&n("#grid_"+this.name+"_field_"+r).val(i.value).trigger("change")):n("#grid_"+this.name+"_operator_"+r).val(o).trigger("change")}n("#w2ui-overlay-"+this.name+"-searchOverlay .w2ui-grid-searches *[rel=search]").on("keypress",function(t){t.keyCode==13&&(s.search(),n().w2overlay({name:s.name+"-searchOverlay"}))})},getColumnsHTML:function(){function s(){var u="<tr>",h="<tr>",f="",i,c,t,r,e,l,o,s,a;for(n.columnGroups[n.columnGroups.length-1].caption!=""&&n.columnGroups.push({caption:""}),n.show.lineNumbers&&(u+='<td class="w2ui-head w2ui-col-number">    <div style="height: '+(n.recordHeight+1)+'px">&#160;<\/div><\/td>'),n.show.selectColumn&&(u+='<td class="w2ui-head w2ui-col-select">    <div style="height: 25px">&#160;<\/div><\/td>'),n.show.expandColumn&&(u+='<td class="w2ui-head w2ui-col-expand">    <div style="height: 25px">&#160;<\/div><\/td>'),i=0,h+='<td id="grid_'+n.name+'_column_start" class="w2ui-head" col="start" style="border-right: 0"><\/td>',c=0;c<n.columnGroups.length;c++){for(t=n.columnGroups[c],r=n.columns[i],t.colspan!=null&&(t.span=t.colspan),(t.span==null||t.span!=parseInt(t.span))&&(t.span=1),e=0,l=i;l<i+t.span;l++)n.columns[l]&&!n.columns[l].hidden&&e++;if(c==n.columnGroups.length-1&&e++,!(e<=0))if(t.master===!0){for(o="",s=0;s<n.sortData.length;s++)n.sortData[s].field==r.field&&(new RegExp("asc","i").test(n.sortData[s].direction)&&(o="w2ui-sort-up"),new RegExp("desc","i").test(n.sortData[s].direction)&&(o="w2ui-sort-down"));a="";r.resizable!==!1&&(a='<div class="w2ui-resizer" name="'+i+'"><\/div>');f='<td id="grid_'+n.name+"_column_"+i+'" class="w2ui-head '+o+'" col="'+i+'"     rowspan="2" colspan="'+e+'"     oncontextmenu = "w2ui[\''+n.name+"'].contextMenu(null, "+i+', event);"    onclick="w2ui[\''+n.name+"'].columnClick('"+r.field+"', event);\"    ondblclick=\"w2ui['"+n.name+"'].columnDblClick('"+r.field+"', event);\">"+a+'    <div class="w2ui-col-group w2ui-col-header '+(o?"w2ui-col-sorted":"")+'">        <div class="'+o+'"><\/div>'+(r.caption?r.caption:"&#160;")+"    <\/div><\/td>";r&&r.frozen?u+=f:h+=f}else f='<td id="grid_'+n.name+"_column_"+i+'" class="w2ui-head" col="'+i+'"         colspan="'+e+'">    <div class="w2ui-col-group">'+(t.caption?t.caption:"&#160;")+"    <\/div><\/td>",r&&r.frozen?u+=f:h+=f;i+=t.span}return u+="<td><\/td><\/tr>",h+='<td id="grid_'+n.name+'_column_end" class="w2ui-head" col="end"><\/td><\/tr>',[u,h]}function u(t){var r="<tr>",u="<tr>",h,e,o,i,f,s;for(n.show.lineNumbers&&(r+='<td class="w2ui-head w2ui-col-number"        onclick="w2ui[\''+n.name+"'].columnClick('line-number', event);\"       ondblclick=\"w2ui['"+n.name+"'].columnDblClick('line-number', event);\">    <div>#<\/div><\/td>"),n.show.selectColumn&&(r+='<td class="w2ui-head w2ui-col-select"       onclick="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">    <div>        <input type="checkbox" id="grid_'+n.name+'_check_all" tabindex="-1"            style="'+(n.multiSelect==!1?"display: none;":"")+'"            onmousedown="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;"            onclick="var grid = w2ui[\''+n.name+"'];               if (this.checked) grid.selectAll(); else grid.selectNone();               if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;               clearTimeout(grid.last.kbd_timer); /* keep focus */            \"/>    <\/div><\/td>"),n.show.expandColumn&&(r+='<td class="w2ui-head w2ui-col-expand">    <div>&#160;<\/div><\/td>'),h=0,e=0,u+='<td id="grid_'+n.name+'_column_start" class="w2ui-head" col="start" style="border-right: 0"><\/td>',i=0;i<n.columns.length;i++)(f=n.columns[i],i==e&&(o=n.columnGroups[h++]||{},e=e+o.span),(i<n.last.colStart||i>n.last.colEnd)&&!f.frozen)||f.hidden||(o.master!==!0||t)&&(s=n.getColumnCellHTML(i),f&&f.frozen?r+=s:u+=s);return r+='<td class="w2ui-head w2ui-head-last"><div>&#160;<\/div><\/td>',u+='<td class="w2ui-head w2ui-head-last" col="end"><div>&#160;<\/div><\/td>',r+="<\/tr>",u+="<\/tr>",[r,u]}var n=this,t="",i="",r;if(this.show.columnHeaders)if(this.columnGroups.length>0){var f=u(!0),e=s(),o=u(!1);t=f[0]+e[0]+o[0];i=f[1]+e[1]+o[1]}else r=u(!0),t=r[0],i=r[1];return[t,i]},getColumnCellHTML:function(n){var i=this.columns[n],o,r,u,f,e,t;if(i==null)return"";for(o=this.reorderColumns&&(!this.columnGroups||!this.columnGroups.length)?" w2ui-reorder-cols-head ":"",r="",t=0;t<this.sortData.length;t++)this.sortData[t].field==i.field&&(new RegExp("asc","i").test(this.sortData[t].direction)&&(r="w2ui-sort-up"),new RegExp("desc","i").test(this.sortData[t].direction)&&(r="w2ui-sort-down"));u=this.last.selection.columns;f=!1;for(e in u)for(t=0;t<u[e].length;t++)u[e][t]==n&&(f=!0);return'<td id="grid_'+this.name+"_column_"+n+'" col="'+n+'" class="w2ui-head '+r+o+'" '+(this.columnTooltip=="normal"&&i.tooltip?'title="'+i.tooltip+'" ':"")+"    onmouseover = \"w2ui['"+this.name+"'].columnTooltipShow('"+n+"', event);\"    onmouseout  = \"w2ui['"+this.name+"'].columnTooltipHide('"+n+"', event);\"    oncontextmenu = \"w2ui['"+this.name+"'].contextMenu(null, "+n+', event);"    onclick="w2ui[\''+this.name+"'].columnClick('"+i.field+"', event);\"    ondblclick=\"w2ui['"+this.name+"'].columnDblClick('"+i.field+"', event);\">"+(i.resizable!==!1?'<div class="w2ui-resizer" name="'+n+'"><\/div>':"")+'    <div class="w2ui-col-header '+(r?"w2ui-col-sorted":"")+" "+(f?"w2ui-col-selected":"")+'">        <div class="'+r+'"><\/div>'+(i.caption?i.caption:"&#160;")+"    <\/div><\/td>"},columnTooltipShow:function(t){if(this.columnTooltip!="normal"){var i=n(this.box).find("#grid_"+this.name+"_column_"+t),r=this.columns[t],u=this.columnTooltip;i.prop("_mouse_over",!0);setTimeout(function(){i.prop("_mouse_over")===!0&&i.prop("_mouse_tooltip")!==!0&&(i.prop("_mouse_tooltip",!0),i.w2tag(r.tooltip,{position:u}))},1)}},columnTooltipHide:function(t){if(this.columnTooltip!="normal"){var i=n(this.box).find("#grid_"+this.name+"_column_"+t),r=this.columns[t];i.removeProp("_mouse_over");setTimeout(function(){i.prop("_mouse_over")!==!0&&i.prop("_mouse_tooltip")===!0&&(i.removeProp("_mouse_tooltip"),i.w2tag())},1)}},getRecordsHTML:function(){var i=this.records.length,s=typeof this.url!="object"?this.url:this.url.get,o,t,u;this.searchData.length==0||s||(i=this.last.searchIds.length);this.last.show_extra=i>this.vs_start?this.vs_extra:this.vs_start;o=n("#grid_"+this.name+"_records");t=Math.floor(o.height()/this.recordHeight)+this.last.show_extra+1;(!this.fixedBody||t>i)&&(t=i);var r=this.getRecordHTML(-1,0),f="<table><tbody>"+r[0],e="<table><tbody>"+r[1];for(f+='<tr id="grid_'+this.name+'_frec_top" line="top" style="height: 0px">    <td colspan="2000"><\/td><\/tr>',e+='<tr id="grid_'+this.name+'_rec_top" line="top" style="height: 0px">    <td colspan="2000"><\/td><\/tr>',u=0;u<t;u++)r=this.getRecordHTML(u,u+1),f+=r[0],e+=r[1];return f+='<tr id="grid_'+this.name+'_frec_bottom" line="bottom" style="height: '+(i-t)*this.recordHeight+'px">    <td colspan="2000" style="border: 0"><\/td><\/tr><tr id="grid_'+this.name+'_frec_more" style="display: none; visibility: hidden">    <td colspan="2000" class="w2ui-load-more"><\/td><\/tr><\/tbody><\/table>',e+='<tr id="grid_'+this.name+'_rec_bottom" line="bottom" style="height: '+(i-t)*this.recordHeight+'px">    <td colspan="2000" style="border: 0"><\/td><\/tr><tr id="grid_'+this.name+'_rec_more" style="display: none">    <td colspan="2000" class="w2ui-load-more"><\/td><\/tr><\/tbody><\/table>',this.last.range_start=0,this.last.range_end=t,[f,e]},getSummaryHTML:function(){var t;if(this.summary.length!==0){var n=this.getRecordHTML(-1,0),i="<table><tbody>"+n[0],r="<table><tbody>"+n[1];for(t=0;t<this.summary.length;t++)n=this.getRecordHTML(t,t+1,!0),i+=n[0],r+=n[1];return i+="<\/tbody><\/table>",r+="<\/tbody><\/table>",[i,r]}},scroll:function(t){function dt(){i.markSearch&&(clearTimeout(i.last.marker_timer),i.last.marker_timer=setTimeout(function(){for(var r,f,t=[],u=0;u<i.searchData.length;u++)(r=i.searchData[u],f=i.getSearch(r.field),f&&!f.hidden)&&t.indexOf(r.value)==-1&&t.push(r.value);t.length>0&&n(i.box).find(".w2ui-grid-data > div").w2marker(t)},50))}var ci=(new Date).getTime(),i=this,et=typeof this.url!="object"?this.url:this.url.get,e=n("#grid_"+this.name+"_records"),p=n("#grid_"+this.name+"_frecords"),ot,g,u,f,at,nt,tt,h,w,it,c,l,rt,wt,ut,ft,a,r,s,v,lt,d,bt,kt,y;if(t&&(ot=t.target.scrollTop,g=t.target.scrollLeft,i.last.scrollTop=ot,i.last.scrollLeft=g,n("#grid_"+i.name+"_columns")[0].scrollLeft=g,n("#grid_"+i.name+"_summary")[0].scrollLeft=g,p[0].scrollTop=ot),this.last.bubbleEl&&(n(this.last.bubbleEl).w2tag(),this.last.bubbleEl=null),u=null,f=null,i.disableCVS||i.columnGroups.length>0)u=0,f=i.columns.length-1;else{for(at=e.width(),nt=0,r=0;r<i.columns.length;r++)i.columns[r].frozen||i.columns[r].hidden||(tt=parseInt(i.columns[r].sizeCalculated?i.columns[r].sizeCalculated:i.columns[r].size),nt+tt+30>i.last.scrollLeft&&u==null&&(u=r),nt+tt-30>i.last.scrollLeft+at&&f==null&&(f=r),nt+=tt);f==null&&(f=i.columns.length-1)}if(u!=null&&(u<0&&(u=0),f<0&&(f=0),u==f&&(u>0?u--:f++),u!=i.last.colStart||f!=i.last.colEnd)){var o=n(i.box),gt=Math.abs(u-i.last.colStart),ni=Math.abs(f-i.last.colEnd);if(gt<5&&ni<5){var ti=o.find(".w2ui-grid-columns #grid_"+i.name+"_column_start"),ii=o.find(".w2ui-grid-columns .w2ui-head-last"),ri=o.find("#grid_"+i.name+"_records .w2ui-grid-data-spacer"),ui=o.find("#grid_"+i.name+"_records .w2ui-grid-data-last"),fi=o.find("#grid_"+i.name+"_summary .w2ui-grid-data-spacer"),ei=o.find("#grid_"+i.name+"_summary .w2ui-grid-data-last");if(u>i.last.colStart)for(r=i.last.colStart;r<u;r++)o.find("#grid_"+i.name+"_columns #grid_"+i.name+"_column_"+r).remove(),o.find("#grid_"+i.name+'_records td[col="'+r+'"]').remove(),o.find("#grid_"+i.name+'_summary td[col="'+r+'"]').remove();if(f<i.last.colEnd)for(r=i.last.colEnd;r>f;r--)o.find("#grid_"+i.name+"_columns #grid_"+i.name+"_column_"+r).remove(),o.find("#grid_"+i.name+'_records td[col="'+r+'"]').remove(),o.find("#grid_"+i.name+'_summary td[col="'+r+'"]').remove();if(u<i.last.colStart)for(r=i.last.colStart-1;r>=u;r--)i.columns[r]&&(i.columns[r].frozen||i.columns[r].hidden)||(ti.after(i.getColumnCellHTML(r)),ri.each(function(t,u){var f=n(u).parent().attr("index"),e='<td class="w2ui-grid-data" col="'+r+'" style="height: 0px"><\/td>';f!=null&&(e=i.getCellHTML(parseInt(f),r,!1));n(u).after(e)}),fi.each(function(t,u){var f=n(u).parent().attr("index"),e='<td class="w2ui-grid-data" col="'+r+'" style="height: 0px"><\/td>';f!=null&&(e=i.getCellHTML(parseInt(f),r,!0));n(u).after(e)}));if(f>i.last.colEnd)for(r=i.last.colEnd+1;r<=f;r++)i.columns[r]&&(i.columns[r].frozen||i.columns[r].hidden)||(ii.before(i.getColumnCellHTML(r)),ui.each(function(t,u){var f=n(u).parent().attr("index"),e='<td class="w2ui-grid-data" col="'+r+'" style="height: 0px"><\/td>';f!=null&&(e=i.getCellHTML(parseInt(f),r,!1));n(u).before(e)}),ei.each(function(t,u){var f=n(u).parent().attr("index"),e=i.getCellHTML(parseInt(f),r,!0);n(u).before(e)}));i.last.colStart=u;i.last.colEnd=f;i.resizeRecords()}else{i.last.colStart=u;i.last.colEnd=f;var oi=this.getColumnsHTML(),vt=this.getRecordsHTML(),yt=this.getSummaryHTML(),si=o.find("#grid_"+this.name+"_columns"),pt=o.find("#grid_"+this.name+"_records"),hi=o.find("#grid_"+this.name+"_frecords"),st=o.find("#grid_"+this.name+"_summary");si.find("tbody").html(oi[1]);hi.html(vt[0]);pt.prepend(vt[1]);yt!=null&&st.html(yt[1]);setTimeout(function(){pt.find("> table").not("table:first-child").remove();st[0]&&(st[0].scrollLeft=i.last.scrollLeft)},1);i.resizeRecords()}}if((h=this.records.length,this.searchData.length==0||et||(h=this.last.searchIds.length),h!==0&&e.length!==0&&e.height()!==0)&&(this.last.show_extra=h>this.vs_start?this.vs_extra:this.vs_start,!(e.height()<h*this.recordHeight)||e.css("overflow-y")!="hidden")&&(w=Math.round(e[0].scrollTop/this.recordHeight+1),it=w+(Math.round(e.height()/this.recordHeight)-1),w>h&&(w=h),it>=h-1&&(it=h),n("#grid_"+this.name+"_footer .w2ui-footer-right").html((i.show.statusRange?w2utils.formatNumber(this.offset+w)+"-"+w2utils.formatNumber(this.offset+it)+(this.total!=-1?" "+w2utils.lang("of")+" "+w2utils.formatNumber(this.total):""):"")+(et&&i.show.statusBuffered?" ("+w2utils.lang("buffered")+" "+w2utils.formatNumber(h)+(this.offset>0?", skip "+w2utils.formatNumber(this.offset):"")+")":"")),et||!(!this.fixedBody||this.total!=-1&&this.total<=this.vs_start))){c=Math.floor(e[0].scrollTop/this.recordHeight)-this.last.show_extra;l=c+Math.floor(e.height()/this.recordHeight)+this.last.show_extra*2+1;c<1&&(c=1);l>this.total&&this.total!=-1&&(l=this.total);var b=e.find("#grid_"+this.name+"_rec_top"),k=e.find("#grid_"+this.name+"_rec_bottom"),ht=p.find("#grid_"+this.name+"_frec_top"),ct=p.find("#grid_"+this.name+"_frec_bottom");if(String(b.next().prop("id")).indexOf("_expanded_row")!=-1&&(b.next().remove(),ht.next().remove()),this.total>l&&String(k.prev().prop("id")).indexOf("_expanded_row")!=-1&&(k.prev().remove(),ct.prev().remove()),rt=parseInt(b.next().attr("line")),wt=parseInt(k.prev().attr("line")),rt<c||rt==1||this.last.pull_refresh){if(l<=wt+this.last.show_extra-2&&l!=this.total)return;for(this.last.pull_refresh=!1;;){if(ut=p.find("#grid_"+this.name+"_frec_top").next(),s=e.find("#grid_"+this.name+"_rec_top").next(),s.attr("line")=="bottom")break;if(parseInt(s.attr("line"))<c)ut.remove(),s.remove();else break}for(ft=e.find("#grid_"+this.name+"_rec_bottom").prev(),a=ft.attr("line"),a=="top"&&(a=c),r=parseInt(a)+1;r<=l;r++)this.records[r-1]&&(s=this.records[r-1].w2ui,s&&!Array.isArray(s.children)&&(s.expanded=!1),v=this.getRecordHTML(r-1,r),k.before(v[1]),ct.before(v[0]));dt();setTimeout(function(){i.refreshRanges()},0)}else{if(c>=rt-this.last.show_extra+2&&c>1)return;for(;;){if(ut=p.find("#grid_"+this.name+"_frec_bottom").prev(),s=e.find("#grid_"+this.name+"_rec_bottom").prev(),s.attr("line")=="top")break;if(parseInt(s.attr("line"))>l)ut.remove(),s.remove();else break}for(ft=e.find("#grid_"+this.name+"_rec_top").next(),a=ft.attr("line"),a=="bottom"&&(a=l),r=parseInt(a)-1;r>=c;r--)this.records[r-1]&&(s=this.records[r-1].w2ui,s&&!Array.isArray(s.children)&&(s.expanded=!1),v=this.getRecordHTML(r-1,r),b.after(v[1]),ht.after(v[0]));dt();setTimeout(function(){i.refreshRanges()},0)}if(lt=(c-1)*i.recordHeight,d=(h-l)*i.recordHeight,d<0&&(d=0),b.css("height",lt+"px"),ht.css("height",lt+"px"),k.css("height",d+"px"),ct.css("height",d+"px"),i.last.range_start=c,i.last.range_end=l,bt=Math.floor(e[0].scrollTop/this.recordHeight),kt=bt+Math.floor(e.height()/this.recordHeight),kt+10>h&&this.last.pull_more!==!0&&(h<this.total-this.offset||this.total==-1&&this.last.xhr_hasMore))if(this.autoLoad===!0)this.last.pull_more=!0,this.last.xhr_offset+=this.limit,this.request("get");else{if(y=n("#grid_"+this.name+"_rec_more, #grid_"+this.name+"_frec_more"),y.css("display")=="none")y.show().on("click",function(){i.last.pull_more=!0;i.last.xhr_offset+=i.limit;i.request("get");n(this).find("td").html('<div><div style="width: 20px; height: 20px;" class="w2ui-spinner"><\/div><\/div>')});(y.find("td .w2ui-spinner").length>0||y.find("td").text().indexOf("Load")==-1)&&y.find("td").html("<div>"+w2utils.lang("Load")+" "+i.limit+" "+w2utils.lang("More")+"...<\/div>")}h>=this.total-this.offset&&this.total!=-1&&n("#grid_"+this.name+"_rec_more, #grid_"+this.name+"_frec_more").hide()}},getRecordHTML:function(n,t,i){var w="",u="",o="",tt=this.last.selection,r,nt,it,c,f,l,v,e,a,b,h,p,k,y,d,s,g;if(n==-1){for(u+='<tr line="0">',o+='<tr line="0">',this.show.lineNumbers&&(u+='<td class="w2ui-col-number" style="height: 0px;"><\/td>'),this.show.selectColumn&&(u+='<td class="w2ui-col-select" style="height: 0px;"><\/td>'),this.show.expandColumn&&(u+='<td class="w2ui-col-expand" style="height: 0px;"><\/td>'),o+='<td class="w2ui-grid-data w2ui-grid-data-spacer" col="start" style="height: 0px; width: 0px;"><\/td>',s=0;s<this.columns.length;s++)if(h=this.columns[s],w='<td class="w2ui-grid-data" col="'+s+'" style="height: 0px;"><\/td>',h.frozen&&!h.hidden)u+=w;else{if(h.hidden||s<this.last.colStart||s>this.last.colEnd)continue;o+=w}return u+='<td class="w2ui-grid-data-last" style="height: 0px"><\/td>',o+='<td class="w2ui-grid-data-last" col="end" style="height: 0px"><\/td>',u+="<\/tr>",o+="<\/tr>",[u,o]}if(nt=typeof this.url!="object"?this.url:this.url.get,i!==!0)if(this.searchData.length>0&&!nt){if(n>=this.last.searchIds.length)return"";n=this.last.searchIds[n];r=this.records[n]}else{if(n>=this.records.length)return"";r=this.records[n]}else{if(n>=this.summary.length)return"";r=this.summary[n]}if(!r)return"";for(r.recid==null&&this.recid!=null&&r[this.recid]!=null&&(r.recid=r[this.recid]),it=w2utils.escapeId(r.recid),c=!1,tt.indexes.indexOf(n)!=-1&&(c=!0),f=r.w2ui?r.w2ui.style:"",(f==null||typeof f!="string")&&(f=""),l=r.w2ui?r.w2ui.class:"",(l==null||typeof l!="string")&&(l=""),u+='<tr id="grid_'+this.name+"_frec_"+r.recid+'" recid="'+r.recid+'" line="'+t+'" index="'+n+'"  class="'+(t%2==0?"w2ui-even":"w2ui-odd")+" "+l+(c&&this.selectType=="row"?" w2ui-selected":"")+(r.w2ui&&r.w2ui.editable===!1?" w2ui-no-edit":"")+(r.w2ui&&r.w2ui.expanded===!0?" w2ui-expanded":"")+'" '+(i!==!0?w2utils.isIOS?"    onclick  = \"w2ui['"+this.name+"'].dblClick(jQuery(this).attr('recid'), event);\"":"    onclick  = \"w2ui['"+this.name+"'].click(jQuery(this).attr('recid'), event);\"    oncontextmenu = \"w2ui['"+this.name+"'].contextMenu(jQuery(this).attr('recid'), null, event);\"":"")+(this.selectType=="row"?" onmouseover=\"jQuery('#grid_"+this.name+"_rec_'+ w2utils.escapeId(jQuery(this).attr('recid'))).addClass('w2ui-record-hover')\" onmouseout =\"jQuery('#grid_"+this.name+"_rec_'+ w2utils.escapeId(jQuery(this).attr('recid'))).removeClass('w2ui-record-hover')\"":"")+' style="height: '+this.recordHeight+"px; "+(!c&&f!=""?f:f.replace("background-color","none"))+'" '+(f!=""?'custom_style="'+f+'"':"")+">",o+='<tr id="grid_'+this.name+"_rec_"+r.recid+'" recid="'+r.recid+'" line="'+t+'" index="'+n+'"  class="'+(t%2==0?"w2ui-even":"w2ui-odd")+" "+l+(c&&this.selectType=="row"?" w2ui-selected":"")+(r.w2ui&&r.w2ui.editable===!1?" w2ui-no-edit":"")+(r.w2ui&&r.w2ui.expanded===!0?" w2ui-expanded":"")+'" '+(i!==!0?w2utils.isIOS?"    onclick  = \"var obj = w2ui['"+this.name+"']; obj.dblClick(jQuery(this).attr('recid'), event);\"":"    onclick  = \"var obj = w2ui['"+this.name+"']; obj.click(jQuery(this).attr('recid'), event);\"    oncontextmenu = \"var obj = w2ui['"+this.name+"']; obj.contextMenu(jQuery(this).attr('recid'), null, event);\"":"")+(this.selectType=="row"?" onmouseover=\"jQuery('#grid_"+this.name+"_frec_' + w2utils.escapeId(jQuery(this).attr('recid'))).addClass('w2ui-record-hover')\" onmouseout =\"jQuery('#grid_"+this.name+"_frec_' + w2utils.escapeId(jQuery(this).attr('recid'))).removeClass('w2ui-record-hover')\"":"")+' style="height: '+this.recordHeight+"px; "+(!c&&f!=""?f:f.replace("background-color","none"))+'" '+(f!=""?'custom_style="'+f+'"':"")+">",this.show.lineNumbers&&(u+='<td id="grid_'+this.name+"_cell_"+n+"_number"+(i?"_s":"")+'"    class="w2ui-col-number '+(c?" w2ui-row-selected":"")+'"'+(this.reorderRows?' style="cursor: move"':"")+">"+(i!==!0?this.getLineHTML(t,r):"")+"<\/td>"),this.show.selectColumn&&(u+='<td id="grid_'+this.name+"_cell_"+n+"_select"+(i?"_s":"")+'" class="w2ui-grid-data w2ui-col-select">'+(i!==!0?'    <div>        <input class="w2ui-grid-select-check" type="checkbox" tabindex="-1" '+(c?'checked="checked"':"")+' style="pointer-events: none"/>    <\/div>':"")+"<\/td>"),this.show.expandColumn&&(v="",v=r.w2ui&&r.w2ui.expanded===!0?"-":"+",r.w2ui&&r.w2ui.expanded=="none"&&(v=""),r.w2ui&&r.w2ui.expanded=="spinner"&&(v='<div class="w2ui-spinner" style="width: 16px; margin: -2px 2px;"><\/div>'),u+='<td id="grid_'+this.name+"_cell_"+n+"_expand"+(i?"_s":"")+'" class="w2ui-grid-data w2ui-col-expand">'+(i!==!0?'    <div ondblclick="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;"             onclick="w2ui[\''+this.name+"'].toggle(jQuery(this).parents('tr').attr('recid'));                 if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;\">        "+v+" <\/div>":"")+"<\/td>"),o+='<td class="w2ui-grid-data-spacer" col="start" style="border-right: 0"><\/td>',e=0,a=0;;){if(b=1,h=this.columns[e],h==null)break;if(h.hidden){e++;a>0&&a--;continue}if(a>0){if(e++,this.columns[e]==null)break;r.w2ui.colspan[this.columns[e-1].field]=0;a--;continue}else r.w2ui&&(p=r.w2ui.colspan,k=this.columns[e].field,p&&p[k]===0&&delete p[k]);if((e<this.last.colStart||e>this.last.colEnd)&&!h.frozen){e++;continue}if(r.w2ui&&typeof r.w2ui.colspan=="object"&&(y=parseInt(r.w2ui.colspan[h.field])||null,y>1)){for(d=0,s=e;s<e+y;s++){if(s>=this.columns.length)break;this.columns[s].hidden&&d++}b=y-d;a=y-1}g=this.getCellHTML(n,e,i,b);h.frozen?u+=g:o+=g;e++}return u+='<td class="w2ui-grid-data-last"><\/td>',o+='<td class="w2ui-grid-data-last" col="end"><\/td>',u+="<\/tr>",o+="<\/tr>",[u,o]},getLineHTML:function(n){return"<div>"+n+"<\/div>"},getCellHTML:function(t,i,r,u){var f=this.columns[i],w,a,b,v,k,it,y,s,d;if(f==null)return"";var e=r!==!0?this.records[t]:this.summary[t],o=this.getCellValue(t,i,r),g=this.getCellEditable(t,i),c="max-height: "+parseInt(this.recordHeight)+"px;",rt=!r&&e&&e.w2ui&&e.w2ui.changes&&e.w2ui.changes[f.field]!=null,l="",p="",nt=this.last.selection,tt=!1,h="";if(nt.indexes.indexOf(t)!=-1&&(tt=!0),u==null&&(u=e&&e.w2ui&&e.w2ui.colspan&&e.w2ui.colspan[f.field]?e.w2ui.colspan[f.field]:1),i===0&&e&&e.w2ui&&Array.isArray(e.w2ui.children)){for(w=0,a=this.get(e.w2ui.parent_recid,!0);;)if(a!=null)if(w++,s=this.records[a].w2ui,s!=null&&s.parent_recid!=null)a=this.get(s.parent_recid,!0);else break;else break;if(e.w2ui.parent_recid)for(b=0;b<w;b++)h+='<span class="w2ui-show-children w2ui-icon-empty"><\/span>';h+='<span class="w2ui-show-children '+(e.w2ui.children.length>0?e.w2ui.expanded?"w2ui-icon-collapse":"w2ui-icon-expand":"w2ui-icon-empty")+'"  onclick="event.stopPropagation(); w2ui[\''+this.name+"'].toggle(jQuery(this).parents('tr').attr('recid'))\"><\/span>"}return f.info===!0&&(f.info={}),f.info!=null&&(f.info.icon||(f.info.icon="w2ui-icon-info"),h+='<span class="w2ui-info '+f.info.icon+'" style="'+(f.info.style||"")+'"  onclick="event.stopPropagation(); w2ui[\''+this.name+"'].showBubble("+t+", "+i+')"><\/span>'),f.render!=null?(typeof f.render=="function"&&(o=n.trim(f.render.call(this,e,t,i,o)),(o.length<4||o.substr(0,4).toLowerCase()!="<div")&&(o='<div style="'+c+'">'+h+String(o)+"<\/div>")),typeof f.render=="object"&&(o='<div style="'+c+'">'+h+(f.render[o]||"")+"<\/div>"),typeof f.render=="string"&&(v=f.render.toLowerCase().indexOf(":"),s=[],v==-1?(s[0]=f.render.toLowerCase(),s[1]=""):(s[0]=f.render.toLowerCase().substr(0,v),s[1]=f.render.toLowerCase().substr(v+1)),k=w2utils.formatters[s[0]],o='<div style="'+c+'">'+h+(typeof k=="function"?k(o,s[1]):"")+"<\/div>")):(g&&["checkbox","check"].indexOf(g.type)!=-1&&(it=r?-(t+1):t,c+="text-align: center;",o='<input tabindex="-1" type="checkbox" '+(o?'checked="checked"':"")+" onclick=\"    var obj = w2ui['"+this.name+"'];     obj.editChange.call(obj, this, "+it+", "+i+', event); "/>',h=""),this.show.recordTitles&&(y=w2utils.stripTags(String(o).replace(/"/g,"''")),f.title!=null&&(typeof f.title=="function"&&(y=f.title.call(this,e,t,i)),typeof f.title=="string"&&(y=f.title))),o='<div style="'+c+'" title="'+(y||"")+'">'+h+String(o)+"<\/div>"),o==null&&(o=""),typeof f.render=="string"&&(s=f.render.toLowerCase().split(":"),["number","int","float","money","currency","percent","size"].indexOf(s[0])!=-1&&(l+="text-align: right;")),e&&e.w2ui&&(typeof e.w2ui.style=="object"&&(typeof e.w2ui.style[i]=="string"&&(l+=e.w2ui.style[i]+";"),typeof e.w2ui.style[f.field]=="string"&&(l+=e.w2ui.style[f.field]+";")),typeof e.w2ui.class=="object"&&(typeof e.w2ui.class[i]=="string"&&(p+=e.w2ui.class[i]+" "),typeof e.w2ui.class[f.field]=="string"&&(p+=e.w2ui.class[f.field]+" "))),d=!1,tt&&n.inArray(i,nt.columns[t])!=-1&&(d=!0),'<td class="w2ui-grid-data'+(d?" w2ui-selected":"")+" "+p+(rt?" w2ui-changed":"")+'"    id="grid_'+this.name+"_data_"+t+"_"+i+'" col="'+i+'"    style="'+l+(f.style!=null?f.style:"")+'" '+(f.attr!=null?f.attr:"")+(u>1?'colspan="'+u+'"':"")+">"+o+"<\/td>"},showBubble:function(t,i){var o="",f=this.columns[i].info,l=this.records[t],v=n(this.box).find("#grid_"+this.name+"_data_"+t+"_"+i+" .w2ui-info"),s,c,a,h,r,e,u;if(this.last.bubbleEl&&n(this.last.bubbleEl).w2tag(),this.last.bubbleEl=v,f.fields==null)for(f.fields=[],c=0;c<this.columns.length;c++)e=this.columns[c],f.fields.push(e.field+(typeof e.render=="string"?":"+e.render:""));if(s=f.fields,typeof s=="function"&&(s=s(l,t,i)),typeof f.render=="function")o=f.render(l,t,i);else if(n.isArray(s)){for(o='<table cellpadding="0" cellspacing="0">',c=0;c<s.length;c++){if(r=String(s[c]).split(":"),r[0]==""||r[0]=="-"||r[0]=="--"||r[0]=="---"){o+='<tr><td colspan=2><div style="border-top: '+(r[0]==""?"0":"1")+'px solid #C1BEBE; margin: 6px 0px;"><\/div><\/td><\/tr>';continue}(e=this.getColumn(r[0]),e==null&&(e={field:r[0],caption:r[0]}),u=e?this.parseField(l,e.field):"",r.length>1&&(w2utils.formatters[r[1]]?u=w2utils.formatters[r[1]](u,r[2]||null):console.log('ERROR: w2utils.formatters["'+r[1]+'"] does not exists.')),f.showEmpty===!0||u!=null&&u!="")&&(f.maxLength!=null&&typeof u=="string"&&u.length>f.maxLength&&(u=u.substr(0,f.maxLength)+"..."),o+="<tr><td>"+e.caption+"<\/td><td>"+((u===0?"0":u)||"")+"<\/td><\/tr>")}o+="<\/table>"}else if(n.isPlainObject(s)){o='<table cellpadding="0" cellspacing="0">';for(a in s){if(h=s[a],h==""||h=="-"||h=="--"||h=="---"){o+='<tr><td colspan=2><div style="border-top: '+(h==""?"0":"1")+'px solid #C1BEBE; margin: 6px 0px;"><\/div><\/td><\/tr>';continue}(r=String(h).split(":"),e=this.getColumn(r[0]),e==null&&(e={field:r[0],caption:r[0]}),u=e?this.parseField(l,e.field):"",r.length>1&&(w2utils.formatters[r[1]]?u=w2utils.formatters[r[1]](u,r[2]||null):console.log('ERROR: w2utils.formatters["'+r[1]+'"] does not exists.')),typeof h=="function"&&(u=h(l,t,i)),f.showEmpty===!0||u!=null&&u!="")&&(f.maxLength!=null&&typeof u=="string"&&u.length>f.maxLength&&(u=u.substr(0,f.maxLength)+"..."),o+="<tr><td>"+a+"<\/td><td>"+(u||"")+"<\/td><\/tr>")}o+="<\/table>"}n(v).w2tag(n.extend({html:o,left:-4,position:"bottom|top",className:"w2ui-info-bubble",style:"",hideOnClick:!0},f.options||{}))},getCellEditable:function(n,t){var u=this.columns[t],r=this.records[n],i,f;return!r||!u?null:(i=r.w2ui?r.w2ui.editable:null,i===!1)?null:((i==null||i===!0)&&(i=u?u.editable:null,typeof i=="function"&&(f=this.getCellValue(n,t,!1),i=i.call(this,r,n,t,f))),i)},getCellValue:function(t,i,r){var e=this.columns[i],f=r!==!0?this.records[t]:this.summary[t],u=this.parseField(f,e.field);return f&&f.w2ui&&f.w2ui.changes&&f.w2ui.changes[e.field]!=null&&(u=f.w2ui.changes[e.field]),n.isPlainObject(u)&&e.editable&&(u.text!=null&&(u=u.text),u.id!=null&&(u=u.id)),u==null&&(u=""),u},getFooterHTML:function(){return'<div>    <div class="w2ui-footer-left"><\/div>    <div class="w2ui-footer-right"><\/div>    <div class="w2ui-footer-center"><\/div><\/div>'},status:function(t){var u,i,r;t!=null?n("#grid_"+this.name+"_footer").find(".w2ui-footer-left").html(t):(u="",i=this.getSelection(),i.length>0&&(this.show.statusSelection&&i.length>1&&(u=String(i.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")+" "+w2utils.lang("selected")),this.show.statusRecordID&&i.length==1&&(r=i[0],typeof r=="object"&&(r=r.recid+", "+w2utils.lang("Column")+": "+r.column),u=w2utils.lang("Record ID")+": "+r+" ")),n("#grid_"+this.name+"_footer .w2ui-footer-left").html(u),i.length==1?this.toolbar.enable("w2ui-edit"):this.toolbar.disable("w2ui-edit"),i.length>=1?this.toolbar.enable("w2ui-delete"):this.toolbar.disable("w2ui-delete"))},lock:function(){var t=this,i=Array.prototype.slice.call(arguments,0);i.unshift(this.box);setTimeout(function(){n(t.box).find("#grid_"+t.name+"_empty_msg").remove();w2utils.lock.apply(window,i)},10)},unlock:function(t){var i=this.box;setTimeout(function(){n(i).find(".w2ui-message").not(".w2ui-closing").length>0||w2utils.unlock(i,t)},25)},stateSave:function(t){var o=this,u,r,i,e,f;if(!w2utils.hasLocalStorage)return null;for(u={columns:[],show:n.extend({},this.show),last:{search:this.last.search,multi:this.last.multi,logic:this.last.logic,caption:this.last.caption,field:this.last.field,scrollTop:this.last.scrollTop,scrollLeft:this.last.scrollLeft},sortData:[],searchData:[]},i=0;i<this.columns.length;i++)r=this.columns[i],u.columns.push({field:r.field,hidden:r.hidden?!0:!1,frozen:r.frozen?!0:!1,size:r.size?r.size:null,sizeCalculated:r.sizeCalculated?r.sizeCalculated:null,sizeOriginal:r.sizeOriginal?r.sizeOriginal:null,sizeType:r.sizeType?r.sizeType:null});for(i=0;i<this.sortData.length;i++)u.sortData.push(n.extend({},this.sortData[i]));for(i=0;i<this.searchData.length;i++)u.searchData.push(n.extend({},this.searchData[i]));if(t!==!0){if(e=this.trigger({phase:"before",type:"stateSave",target:this.name,state:u}),e.isCancelled===!0){typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."});return}try{f=n.parseJSON(localStorage.w2ui||"{}");f||(f={});f.states||(f.states={});f.states[this.stateId||this.name]=u;localStorage.w2ui=JSON.stringify(f)}catch(s){return delete localStorage.w2ui,null}this.trigger(n.extend(e,{phase:"after"}))}return u},stateRestore:function(t){var u=this,h=typeof this.url!="object"?this.url:this.url.get,e,o,s,r,f,i;if(!t)try{if(!w2utils.hasLocalStorage)return!1;r=n.parseJSON(localStorage.w2ui||"{}");r||(r={});r.states||(r.states={});t=r.states[this.stateId||this.name]}catch(c){return delete localStorage.w2ui,null}if(e=this.trigger({phase:"before",type:"stateRestore",target:this.name,state:t}),e.isCancelled===!0){typeof callBack=="function"&&callBack({status:"error",message:"Request aborted."});return}if(n.isPlainObject(t)){for(n.extend(this.show,t.show),n.extend(this.last,t.last),o=this.last.scrollTop,s=this.last.scrollLeft,i=0;i<t.columns.length;i++)r=t.columns[i],f=this.getColumn(r.field,!0),f!==null&&(n.extend(this.columns[f],r),i!==f&&this.columns.splice(i,0,this.columns.splice(f,1)[0]));for(this.sortData.splice(0,this.sortData.length),i=0;i<t.sortData.length;i++)this.sortData.push(t.sortData[i]);for(this.searchData.splice(0,this.searchData.length),i=0;i<t.searchData.length;i++)this.searchData.push(t.searchData[i]);setTimeout(function(){h||(u.sortData.length>0&&u.localSort(),u.searchData.length>0&&u.localSearch());u.last.scrollTop=o;u.last.scrollLeft=s;u.refresh()},1)}return this.trigger(n.extend(e,{phase:"after"})),!0},stateReset:function(){var i=this,t;if(this.stateRestore(this.last.state),w2utils.hasLocalStorage)try{t=n.parseJSON(localStorage.w2ui||"{}");t.states&&t.states[this.stateId||this.name]&&delete t.states[this.stateId||this.name];localStorage.w2ui=JSON.stringify(t)}catch(r){return delete localStorage.w2ui,null}},parseField:function(n,t){var i="",u,r;try{for(i=n,u=String(t).split("."),r=0;r<u.length;r++)i=i[u[r]]}catch(f){i=""}return i},prepareData:function(){function r(n){for(var i,u,f,o,s,e=0;e<t.columns.length;e++)(i=t.columns[e],n[i.field]!=null&&typeof i.render=="string")&&(["number","int","float","money","currency","percent"].indexOf(i.render.split(":")[0])!=-1&&typeof n[i.field]!="number"&&(n[i.field]=parseFloat(n[i.field])),["date","age"].indexOf(i.render.split(":")[0])!=-1&&(n[i.field+"_"]||(f=n[i.field],w2utils.isInt(f)&&(f=parseInt(f)),n[i.field+"_"]=new Date(f))),["time"].indexOf(i.render)!=-1&&(w2utils.isTime(n[i.field])?(u=w2utils.isTime(n[i.field],!0),f=new Date,f.setHours(u.hours,u.minutes,u.seconds?u.seconds:0,0),n[i.field+"_"]||(n[i.field+"_"]=f)):(u=n[i.field],w2utils.isInt(u)&&(u=parseInt(u)),u=u!=null?new Date(u):new Date,f=new Date,f.setHours(u.getHours(),u.getMinutes(),u.getSeconds(),0),n[i.field+"_"]||(n[i.field+"_"]=f))));if(n.w2ui&&n.w2ui.children&&n.w2ui.expanded!==!0)for(o=0;o<n.w2ui.children.length;o++)s=n.w2ui.children[o],r(s)}for(var i,t=this,n=0;n<this.records.length;n++)i=this.records[n],r(i)},nextCell:function(n,t,i){var r=t+1,e;if(r>=this.columns.length)return null;var f=this.records[n].w2ui,s=this.columns[t],u=this.columns[r],o=f&&f.colspan&&!isNaN(f.colspan[u.field])?parseInt(f.colspan[u.field]):1;return u==null?null:u&&u.hidden||o===0?this.nextCell(n,r,i):i&&(e=this.getCellEditable(n,t),e==null||["checkbox","check"].indexOf(e.type)!=-1)?this.nextCell(n,r,i):r},prevCell:function(n,t,i){var r=t-1,e;if(r<0)return null;var f=this.records[n].w2ui,u=this.columns[r],o=f&&f.colspan&&!isNaN(f.colspan[u.field])?parseInt(f.colspan[u.field]):1;return u==null?null:u&&u.hidden||o===0?this.prevCell(n,r,i):i&&(e=this.getCellEditable(n,t),e==null||["checkbox","check"].indexOf(e.type)!=-1)?this.prevCell(n,r,i):r},nextRow:function(t,i){var r=this.last.searchIds,e=null;if(t+1<this.records.length&&r.length===0||r.length>0&&t<r[r.length-1]){if(t++,r.length>0)for(;;){if(n.inArray(t,r)!=-1||t>this.records.length)break;t++}var u=this.records[t].w2ui,f=this.columns[i],o=u&&u.colspan&&f!=null&&!isNaN(u.colspan[f.field])?parseInt(u.colspan[f.field]):1;e=o===0?this.nextRow(t,i):t}return e},prevRow:function(t,i){var r=this.last.searchIds,e=null;if(t>0&&r.length===0||r.length>0&&t>r[0]){if(t--,r.length>0)for(;;){if(n.inArray(t,r)!=-1||t<0)break;t--}var u=this.records[t].w2ui,f=this.columns[i],o=u&&u.colspan&&f!=null&&!isNaN(u.colspan[f.field])?parseInt(u.colspan[f.field]):1;e=o===0?this.prevRow(t,i):t}return e},selectionSave:function(){return this.last._selection=this.getSelection(),this.last._selection},selectionRestore:function(t){var e=(new Date).getTime(),r,f,u,i;for(this.last.selection={indexes:[],columns:{}},r=this.last.selection,f=this.last._selection,u=0;u<f.length;u++)n.isPlainObject(f[u])?(i=this.get(f[u].recid,!0),i!=null&&(r.indexes.indexOf(i)==-1&&r.indexes.push(i),r.columns[i]||(r.columns[i]=[]),r.columns[i].push(f[u].column))):(i=this.get(f[u],!0),i!=null&&r.indexes.push(i));return delete this.last._selection,t!==!0&&this.refresh(),(new Date).getTime()-e},message:function(t,i){typeof t=="string"&&(t={width:t.length<300?350:550,height:t.length<300?170:250,body:'<div class="w2ui-centered">'+t+"<\/div>",buttons:'<button class="w2ui-btn" onclick="w2ui[\''+this.name+"'].message()\">Ok<\/button>",onOpen:function(){setTimeout(function(){n(this.box).find(".w2ui-btn").focus()},25)},onClose:function(){typeof i=="function"&&i()}});w2utils.message.call(this,{box:this.box,path:"w2ui."+this.name,title:".w2ui-grid-header:visible",body:".w2ui-grid-box"},t)}};n.extend(t.prototype,w2utils.event);w2obj.grid=t}(jQuery),function(n){var i=function(t){this.box=null;this.name=null;this.panels=[];this.tmp={};this.padding=1;this.resizer=4;this.style="";n.extend(!0,this,w2obj.layout,t)},t=["top","left","main","preview","right","bottom"];n.fn.w2layout=function(r){function c(t,i,r){var u=t.get(i);return(u!=null&&r==null&&(r=u.tabs),u==null||r==null)?!1:(n.isArray(r)&&(r={tabs:r}),n().w2destroy(t.name+"_"+i+"_tabs"),u.tabs=n().w2tabs(n.extend({},r,{owner:t,name:t.name+"_"+i+"_tabs"})),u.show.tabs=!0,!0)}function l(t,i,r){var u=t.get(i);return(u!=null&&r==null&&(r=u.toolbar),u==null||r==null)?!1:(n.isArray(r)&&(r={items:r}),n().w2destroy(t.name+"_"+i+"_toolbar"),u.toolbar=n().w2toolbar(n.extend({},r,{owner:t,name:t.name+"_"+i+"_toolbar"})),u.show.toolbar=!0,!0)}var s,u,f,h,e,o;if(n.isPlainObject(r)){if(!w2utils.checkName(r,"w2layout"))return;for(s=r.panels||[],u=new i(r),n.extend(u,{handlers:[],panels:[]}),f=0,h=s.length;f<h;f++)u.panels[f]=n.extend(!0,{},i.prototype.panel,s[f]),(n.isPlainObject(u.panels[f].tabs)||n.isArray(u.panels[f].tabs))&&c(u,s[f].type),(n.isPlainObject(u.panels[f].toolbar)||n.isArray(u.panels[f].toolbar))&&l(u,s[f].type);for(e=0;e<t.length;e++)u.get(t[e])==null&&u.panels.push(n.extend(!0,{},i.prototype.panel,{type:t[e],hidden:t[e]!=="main",size:50}));return n(this).length>0&&u.render(n(this)[0]),w2ui[u.name]=u,u}return(o=w2ui[n(this).attr("name")],!o)?null:arguments.length>0?(o[r]&&o[r].apply(o,Array.prototype.slice.call(arguments,1)),this):o};i.prototype={onShow:null,onHide:null,onResizing:null,onResizerClick:null,onRender:null,onRefresh:null,onContent:null,onResize:null,onDestroy:null,panel:{type:null,title:"",size:100,minSize:20,maxSize:!1,hidden:!1,resizable:!1,overflow:"auto",style:"",content:"",tabs:null,toolbar:null,width:null,height:null,show:{toolbar:!1,tabs:!1},onRefresh:null,onShow:null,onHide:null},html:function(n,t,i){return this.content(n,t,i)},content:function(t,i,r){var e=this,u=this.get(t),h,o,f;if(t=="css")return n("#layout_"+e.name+"_panel_css").html("<style>"+i+"<\/style>"),!0;if(u==null)return!1;if(i==null)return u.content;if(h=this.trigger({phase:"before",type:"content",target:t,object:u,content:i,transition:r}),h.isCancelled!==!0){if(i instanceof jQuery)return console.log("ERROR: You can not pass jQuery object to w2layout.content() method"),!1;var s="#layout_"+this.name+"_panel_"+u.type,l=n(s+"> .w2ui-panel-content"),c=0;return l.length>0&&(n(s).scrollTop(0),c=n(l).position().top),u.content===""?(u.content=i,this.refresh(t)):(u.content=i,u.hidden||r!=null&&r!==""&&(o=n(s+"> .w2ui-panel-content"),o.after('<div class="w2ui-panel-content new-panel" style="'+o[0].style.cssText+'"><\/div>'),f=n(s+"> .w2ui-panel-content.new-panel"),o.css("top",c),f.css("top",c),typeof i=="object"?(i.box=f[0],i.render()):f.html(i),w2utils.transition(o[0],f[0],r,function(){o.remove();f.removeClass("new-panel");f.css("overflow",u.overflow);e.resize();window.navigator.userAgent.indexOf("MSIE")!=-1&&setTimeout(function(){e.resize()},100)})),this.refresh(t)),e.trigger(n.extend(h,{phase:"after"})),e.resize(),window.navigator.userAgent.indexOf("MSIE")!=-1&&setTimeout(function(){e.resize()},100),!0}},message:function(t,i){var f=this;typeof i=="string"&&(i={width:i.length<300?350:550,height:i.length<300?170:250,body:'<div class="w2ui-centered">'+i+"<\/div>",buttons:'<button class="w2ui-btn" onclick="w2ui[\''+this.name+"'].message('"+t+"')\">Ok<\/button>",onOpen:function(){setTimeout(function(){n(this.box).find(".w2ui-btn").focus()},25)}});var r=this.get(t),e=n("#layout_"+this.name+"_panel_"+r.type),o=e.css("overflow"),u;i&&(i.onClose&&(u=i.onClose),i.onClose=function(t){typeof u=="function"&&u(t);t.done(function(){n("#layout_"+f.name+"_panel_"+r.type).css("overflow",o)})});n("#layout_"+this.name+"_panel_"+r.type).css("overflow","hidden");w2utils.message.call(this,{box:n("#layout_"+this.name+"_panel_"+r.type),param:t,path:"w2ui."+this.name,title:".w2ui-panel-title:visible",body:".w2ui-panel-content"},i)},load:function(t,i,r,u){var f=this;return t=="css"?(n.get(i,function(n,i,r){f.content(t,r.responseText);u&&u()}),!0):this.get(t)!=null?(n.get(i,function(n,i,e){f.content(t,e.responseText,r);u&&u();f.resize();window.navigator.userAgent.indexOf("MSIE")!=-1&&setTimeout(function(){f.resize()},100)}),!0):!1},sizeTo:function(t,i,r){var u=this,f=u.get(t);return f==null?!1:(n(u.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",r!==!0?".2s":"0s")),setTimeout(function(){u.set(t,{size:i})},1),setTimeout(function(){n(u.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s"));u.resize()},500),!0)},show:function(t,i){var r=this,u=this.trigger({phase:"before",type:"show",target:t,object:this.get(t),immediate:i}),f;if(u.isCancelled!==!0)return(f=r.get(t),f==null)?!1:(f.hidden=!1,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"}),r.trigger(n.extend(u,{phase:"after"})),r.resize()):(n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),n(r.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",".2s")),setTimeout(function(){r.resize()},1),setTimeout(function(){n("#layout_"+r.name+"_panel_"+t).css({opacity:"1"})},250),setTimeout(function(){n(r.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s"));r.trigger(n.extend(u,{phase:"after"}));r.resize()},500)),!0)},hide:function(t,i){var r=this,u=this.trigger({phase:"before",type:"hide",target:t,object:this.get(t),immediate:i}),f;if(u.isCancelled!==!0)return(f=r.get(t),f==null)?!1:(f.hidden=!0,i===!0?(n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),r.trigger(n.extend(u,{phase:"after"})),r.resize()):(n(r.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",".2s")),n("#layout_"+r.name+"_panel_"+t).css({opacity:"0"}),setTimeout(function(){r.resize()},1),setTimeout(function(){n(r.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s"));r.trigger(n.extend(u,{phase:"after"}));r.resize()},500)),!0)},toggle:function(n,t){var i=this.get(n);return i==null?!1:i.hidden?this.show(n,t):this.hide(n,t)},set:function(t,i){var r=this.get(t,!0);return r==null?!1:(n.extend(this.panels[r],i),(i.content!=null||i.resizable!=null)&&this.refresh(t),this.resize(),!0)},get:function(n,t){for(var i=0;i<this.panels.length;i++)if(this.panels[i].type==n)return t===!0?i:this.panels[i];return null},el:function(t){var i=n("#layout_"+this.name+"_panel_"+t+"> .w2ui-panel-content");return i.length!=1?null:i[0]},hideToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!1,n("#layout_"+this.name+"_panel_"+t+"> .w2ui-panel-toolbar").hide(),this.resize())},showToolbar:function(t){var i=this.get(t);i&&(i.show.toolbar=!0,n("#layout_"+this.name+"_panel_"+t+"> .w2ui-panel-toolbar").show(),this.resize())},toggleToolbar:function(n){var t=this.get(n);t&&(t.show.toolbar?this.hideToolbar(n):this.showToolbar(n))},assignToolbar:function(t,i){var r,u;typeof i=="string"&&w2ui[i]!=null&&(i=w2ui[i]);r=this.get(t);r.toolbar=i;u=n(this.box).find(t+"> .w2ui-panel-toolbar");r.toolbar!=null?(u.find("[name="+r.toolbar.name+"]").length===0?u.w2render(r.toolbar):r.toolbar!=null&&r.toolbar.refresh(),this.showToolbar(t),this.refresh("main")):(u.html(""),this.hideToolbar(t))},hideTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!1,n("#layout_"+this.name+"_panel_"+t+"> .w2ui-panel-tabs").hide(),this.resize())},showTabs:function(t){var i=this.get(t);i&&(i.show.tabs=!0,n("#layout_"+this.name+"_panel_"+t+"> .w2ui-panel-tabs").show(),this.resize())},toggleTabs:function(n){var t=this.get(n);t&&(t.show.tabs?this.hideTabs(n):this.showTabs(n))},render:function(i){function h(){r.tmp.events={resize:function(){w2ui[r.name].resize()},resizeStart:c,mouseMove:a,mouseUp:l};n(window).on("resize",r.tmp.events.resize)}function c(i,u){var f,e;if(r.box){u||(u=window.event);n(document).off("mousemove",r.tmp.events.mouseMove).on("mousemove",r.tmp.events.mouseMove);n(document).off("mouseup",r.tmp.events.mouseUp).on("mouseup",r.tmp.events.mouseUp);for(r.tmp.resize={type:i,x:u.screenX,y:u.screenY,diff_x:0,diff_y:0,value:0},f=0;f<t.length;f++)e=n(r.el(t[f])).parent().find(".w2ui-lock"),e.length>0?e.attr("locked","previous"):r.lock(t[f],{opacity:0});(i=="left"||i=="right")&&(r.tmp.resize.value=parseInt(n("#layout_"+r.name+"_resizer_"+i)[0].style.left));(i=="top"||i=="preview"||i=="bottom")&&(r.tmp.resize.value=parseInt(n("#layout_"+r.name+"_resizer_"+i)[0].style.top))}}function l(i){var o,s;if(r.box&&(i||(i=window.event),n(document).off("mousemove",r.tmp.events.mouseMove),n(document).off("mouseup",r.tmp.events.mouseUp),r.tmp.resize!=null)){for(o=0;o<t.length;o++)s=n(r.el(t[o])).parent().find(".w2ui-lock"),s.attr("locked")=="previous"?s.removeAttr("locked"):r.unlock(t[o]);if(r.tmp.diff_x!==0||r.tmp.resize.diff_y!==0){var h=r.get("top"),c=r.get("bottom"),u=r.get(r.tmp.resize.type),a=parseInt(n(r.box).height()),v=parseInt(n(r.box).width()),l=String(u.size),f,e;switch(r.tmp.resize.type){case"top":f=parseInt(u.sizeCalculated)+r.tmp.resize.diff_y;e=0;break;case"bottom":f=parseInt(u.sizeCalculated)-r.tmp.resize.diff_y;e=0;break;case"preview":f=parseInt(u.sizeCalculated)-r.tmp.resize.diff_y;e=(h&&!h.hidden?h.sizeCalculated:0)+(c&&!c.hidden?c.sizeCalculated:0);break;case"left":f=parseInt(u.sizeCalculated)+r.tmp.resize.diff_x;e=0;break;case"right":f=parseInt(u.sizeCalculated)-r.tmp.resize.diff_x;e=0}u.size=l.substr(l.length-1)=="%"?Math.floor(f*100/(u.type=="left"||u.type=="right"?v:a-e)*100)/100+"%":String(u.size).substr(0,1)=="-"?parseInt(u.size)-u.sizeCalculated+f:f;r.resize()}n("#layout_"+r.name+"_resizer_"+r.tmp.resize.type).removeClass("active");delete r.tmp.resize}}function a(t){if(r.box&&(t||(t=window.event),r.tmp.resize!=null)){var i=r.get(r.tmp.resize.type),u=r.tmp.resize,h=r.trigger({phase:"before",type:"resizing",target:r.name,object:i,originalEvent:t,panel:u?u.type:"all",diff_x:u?u.diff_x:0,diff_y:u?u.diff_y:0});if(h.isCancelled!==!0){var s=n("#layout_"+r.name+"_resizer_"+u.type),e=t.screenX-u.x,o=t.screenY-u.y,f=r.get("main");s.hasClass("active")||s.addClass("active");switch(u.type){case"left":i.minSize-e>i.width&&(e=i.minSize-i.width);i.maxSize&&i.width+e>i.maxSize&&(e=i.maxSize-i.width);f.minSize+e>f.width&&(e=f.width-f.minSize);break;case"right":i.minSize+e>i.width&&(e=i.width-i.minSize);i.maxSize&&i.width-e>i.maxSize&&(e=i.width-i.maxSize);f.minSize-e>f.width&&(e=f.minSize-f.width);break;case"top":i.minSize-o>i.height&&(o=i.minSize-i.height);i.maxSize&&i.height+o>i.maxSize&&(o=i.maxSize-i.height);f.minSize+o>f.height&&(o=f.height-f.minSize);break;case"preview":case"bottom":i.minSize+o>i.height&&(o=i.height-i.minSize);i.maxSize&&i.height-o>i.maxSize&&(o=i.height-i.maxSize);f.minSize-o>f.height&&(o=f.minSize-f.height)}u.diff_x=e;u.diff_y=o;switch(u.type){case"top":case"preview":case"bottom":u.diff_x=0;s.length>0&&(s[0].style.top=u.value+u.diff_y+"px");break;case"left":case"right":u.diff_y=0;s.length>0&&(s[0].style.left=u.value+u.diff_x+"px")}r.trigger(n.extend(h,{phase:"after"}))}}}var r=this,o=(new Date).getTime(),f=r.trigger({phase:"before",type:"render",target:r.name,box:i}),u,s,e;if(f.isCancelled!==!0){if(i!=null&&(n(r.box).find("#layout_"+r.name+"_panel_main").length>0&&n(r.box).removeAttr("name").removeClass("w2ui-layout").html(""),r.box=i),!r.box)return!1;for(n(r.box).attr("name",r.name).addClass("w2ui-layout").html("<div><\/div>"),n(r.box).length>0&&(n(r.box)[0].style.cssText+=r.style),u=0;u<t.length;u++)s=r.get(t[u]),e='<div id="layout_'+r.name+"_panel_"+t[u]+'" class="w2ui-panel">    <div class="w2ui-panel-title"><\/div>    <div class="w2ui-panel-tabs"><\/div>    <div class="w2ui-panel-toolbar"><\/div>    <div class="w2ui-panel-content"><\/div><\/div><div id="layout_'+r.name+"_resizer_"+t[u]+'" class="w2ui-resizer"><\/div>',n(r.box).find(" > div").append(e);return n(r.box).find(" > div").append('<div id="layout_'+r.name+'_panel_css" style="position: absolute; top: 10000px;"><\/div>'),r.refresh(),r.trigger(n.extend(f,{phase:"after"})),setTimeout(function(){h();r.resize()},0),(new Date).getTime()-o}},refresh:function(t){var r=this,h,o,i,f,s,u,e;if(t==null&&(t=null),h=(new Date).getTime(),o=r.trigger({phase:"before",type:"refresh",target:t!=null?t:r.name,object:r.get(t)}),o.isCancelled!==!0){if(typeof t=="string"){if(i=r.get(t),i==null)return;f="#layout_"+r.name+"_panel_"+i.type;s="#layout_"+r.name+"_resizer_"+i.type;n(f).css({display:i.hidden?"none":"block"});i.resizable?n(s).show():n(s).hide();typeof i.content=="object"&&typeof i.content.render=="function"?(i.content.box=n(f+"> .w2ui-panel-content")[0],setTimeout(function(){n(f+"> .w2ui-panel-content").length>0&&(n(f+"> .w2ui-panel-content").removeClass().removeAttr("name").addClass("w2ui-panel-content").css("overflow",i.overflow)[0].style.cssText+=";"+i.style);i.content&&typeof i.content.render=="function"&&i.content.render()},1)):n(f+"> .w2ui-panel-content").length>0&&(n(f+"> .w2ui-panel-content").removeClass().removeAttr("name").addClass("w2ui-panel-content").html(i.content).css("overflow",i.overflow)[0].style.cssText+=";"+i.style);u=n(r.box).find(f+"> .w2ui-panel-tabs");i.show.tabs?u.find("[name="+i.tabs.name+"]").length===0&&i.tabs!=null?u.w2render(i.tabs):i.tabs.refresh():u.html("").removeClass("w2ui-tabs").hide();u=n(r.box).find(f+"> .w2ui-panel-toolbar");i.show.toolbar?u.find("[name="+i.toolbar.name+"]").length===0&&i.toolbar!=null?u.w2render(i.toolbar):i.toolbar.refresh():u.html("").removeClass("w2ui-toolbar").hide();u=n(r.box).find(f+"> .w2ui-panel-title");i.title?u.html(i.title).show():u.html("").hide()}else{if(n("#layout_"+r.name+"_panel_main").length===0){r.render();return}for(r.resize(),e=0;e<this.panels.length;e++)r.refresh(this.panels[e].type)}return r.trigger(n.extend(o,{phase:"after"})),(new Date).getTime()-h}},resize:function(){var v,w,nt,ft,rt,p;if(!this.box)return!1;var st=(new Date).getTime(),e=this.tmp.resize,et=this.trigger({phase:"before",type:"resize",target:this.name,panel:e?e.type:"all",diff_x:e?e.diff_x:0,diff_y:e?e.diff_y:0});if(et.isCancelled!==!0){this.padding<0&&(this.padding=0);v=parseInt(n(this.box).width());w=parseInt(n(this.box).height());n(this.box).find(" > div").css({width:v+"px",height:w+"px"});var h=this,ot=this.get("main"),y=this.get("preview"),o=this.get("left"),c=this.get("right"),s=this.get("top"),l=this.get("bottom"),ht=y!=null&&y.hidden!==!0?!0:!1,k=o!=null&&o.hidden!==!0?!0:!1,tt=c!=null&&c.hidden!==!0?!0:!1,d=s!=null&&s.hidden!==!0?!0:!1,it=l!=null&&l.hidden!==!0?!0:!1,f,u,i,r,a;for(nt=0;nt<t.length;nt++)t[nt]!=="main"&&(e=this.get(t[nt]),e)&&(ft=String(e.size||0),ft.substr(ft.length-1)=="%"?(rt=w,e.type=="preview"&&(rt=rt-(s&&!s.hidden?s.sizeCalculated:0)-(l&&!l.hidden?l.sizeCalculated:0)),e.sizeCalculated=parseInt((e.type=="left"||e.type=="right"?v:rt)*parseFloat(e.size)/100)):e.sizeCalculated=parseInt(e.size),e.sizeCalculated=Math.max(e.sizeCalculated,parseInt(e.minSize)));if(String(c.size).substr(0,1)=="-"&&(k&&o.size.substr(0,1)=="-"?console.log("ERROR: you cannot have both left panel.size and right panel.size be negative."):c.sizeCalculated=v-(k?o.sizeCalculated:0)+parseInt(c.size)),String(o.size).substr(0,1)=="-"&&(tt&&c.size.substr(0,1)=="-"?console.log("ERROR: you cannot have both left panel.size and right panel.size be negative."):o.sizeCalculated=v-(tt?c.sizeCalculated:0)+parseInt(o.size)),s!=null&&s.hidden!==!0){if(f=0,u=0,i=v,r=s.sizeCalculated,n("#layout_"+this.name+"_panel_top").css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}).show(),s.width=i,s.height=r,s.resizable){u=s.sizeCalculated-(this.padding===0?this.resizer:0);r=this.resizer>this.padding?this.resizer:this.padding;n("#layout_"+this.name+"_resizer_top").show().css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(t){var i=h.trigger({phase:"before",type:"resizerClick",target:"top",originalEvent:t});if(i.isCancelled!==!0)return w2ui[h.name].tmp.events.resizeStart("top",t),h.trigger(n.extend(i,{phase:"after"})),!1})}}else n("#layout_"+this.name+"_panel_top").hide(),n("#layout_"+this.name+"_resizer_top").hide();if(o!=null&&o.hidden!==!0){if(f=0,u=0+(d?s.sizeCalculated+this.padding:0),i=o.sizeCalculated,r=w-(d?s.sizeCalculated+this.padding:0)-(it?l.sizeCalculated+this.padding:0),a=n("#layout_"+this.name+"_panel_left"),window.navigator.userAgent.indexOf("MSIE")!=-1&&a.length>0&&a[0].clientHeight<a[0].scrollHeight&&(i+=17),a.css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}).show(),o.width=i,o.height=r,o.resizable){f=o.sizeCalculated-(this.padding===0?this.resizer:0);i=this.resizer>this.padding?this.resizer:this.padding;n("#layout_"+this.name+"_resizer_left").show().css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px",cursor:"ew-resize"}).off("mousedown").on("mousedown",function(t){var i=h.trigger({phase:"before",type:"resizerClick",target:"left",originalEvent:t});if(i.isCancelled!==!0)return w2ui[h.name].tmp.events.resizeStart("left",t),h.trigger(n.extend(i,{phase:"after"})),!1})}}else n("#layout_"+this.name+"_panel_left").hide(),n("#layout_"+this.name+"_resizer_left").hide();if(c!=null&&c.hidden!==!0){if(f=v-c.sizeCalculated,u=0+(d?s.sizeCalculated+this.padding:0),i=c.sizeCalculated,r=w-(d?s.sizeCalculated+this.padding:0)-(it?l.sizeCalculated+this.padding:0),n("#layout_"+this.name+"_panel_right").css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}).show(),c.width=i,c.height=r,c.resizable){f=f-this.padding;i=this.resizer>this.padding?this.resizer:this.padding;n("#layout_"+this.name+"_resizer_right").show().css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px",cursor:"ew-resize"}).off("mousedown").on("mousedown",function(t){var i=h.trigger({phase:"before",type:"resizerClick",target:"right",originalEvent:t});if(i.isCancelled!==!0)return w2ui[h.name].tmp.events.resizeStart("right",t),h.trigger(n.extend(i,{phase:"after"})),!1})}}else n("#layout_"+this.name+"_panel_right").hide(),n("#layout_"+this.name+"_resizer_right").hide();if(l!=null&&l.hidden!==!0){if(f=0,u=w-l.sizeCalculated,i=v,r=l.sizeCalculated,n("#layout_"+this.name+"_panel_bottom").css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}).show(),l.width=i,l.height=r,l.resizable){u=u-(this.padding===0?0:this.padding);r=this.resizer>this.padding?this.resizer:this.padding;n("#layout_"+this.name+"_resizer_bottom").show().css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(t){var i=h.trigger({phase:"before",type:"resizerClick",target:"bottom",originalEvent:t});if(i.isCancelled!==!0)return w2ui[h.name].tmp.events.resizeStart("bottom",t),h.trigger(n.extend(i,{phase:"after"})),!1})}}else n("#layout_"+this.name+"_panel_bottom").hide(),n("#layout_"+this.name+"_resizer_bottom").hide();if(f=0+(k?o.sizeCalculated+this.padding:0),u=0+(d?s.sizeCalculated+this.padding:0),i=v-(k?o.sizeCalculated+this.padding:0)-(tt?c.sizeCalculated+this.padding:0),r=w-(d?s.sizeCalculated+this.padding:0)-(it?l.sizeCalculated+this.padding:0)-(ht?y.sizeCalculated+this.padding:0),a=n("#layout_"+this.name+"_panel_main"),window.navigator.userAgent.indexOf("MSIE")!=-1&&a.length>0&&a[0].clientHeight<a[0].scrollHeight&&(i+=17),a.css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}),ot.width=i,ot.height=r,y!=null&&y.hidden!==!0){if(f=0+(k?o.sizeCalculated+this.padding:0),u=w-(it?l.sizeCalculated+this.padding:0)-y.sizeCalculated,i=v-(k?o.sizeCalculated+this.padding:0)-(tt?c.sizeCalculated+this.padding:0),r=y.sizeCalculated,a=n("#layout_"+this.name+"_panel_preview"),window.navigator.userAgent.indexOf("MSIE")!=-1&&a.length>0&&a[0].clientHeight<a[0].scrollHeight&&(i+=17),a.css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px"}).show(),y.width=i,y.height=r,y.resizable){u=u-(this.padding===0?0:this.padding);r=this.resizer>this.padding?this.resizer:this.padding;n("#layout_"+this.name+"_resizer_preview").show().css({display:"block",left:f+"px",top:u+"px",width:i+"px",height:r+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(t){var i=h.trigger({phase:"before",type:"resizerClick",target:"preview",originalEvent:t});if(i.isCancelled!==!0)return w2ui[h.name].tmp.events.resizeStart("preview",t),h.trigger(n.extend(i,{phase:"after"})),!1})}}else n("#layout_"+this.name+"_panel_preview").hide(),n("#layout_"+this.name+"_resizer_preview").hide();for(p=0;p<t.length;p++){var g=this.get(t[p]),ut="#layout_"+this.name+"_panel_"+t[p]+" > .w2ui-panel-",b=0;g&&(g.title&&(b+=w2utils.getSize(n(ut+"title").css({top:b+"px",display:"block"}),"height")),g.show.tabs&&(g.tabs!=null&&w2ui[this.name+"_"+t[p]+"_tabs"]&&w2ui[this.name+"_"+t[p]+"_tabs"].resize(),b+=w2utils.getSize(n(ut+"tabs").css({top:b+"px",display:"block"}),"height")),g.show.toolbar&&(g.toolbar!=null&&w2ui[this.name+"_"+t[p]+"_toolbar"]&&w2ui[this.name+"_"+t[p]+"_toolbar"].resize(),b+=w2utils.getSize(n(ut+"toolbar").css({top:b+"px",display:"block"}),"height")));n(ut+"content").css({display:"block"}).css({top:b+"px"})}return clearTimeout(this._resize_timer),this._resize_timer=setTimeout(function(){var t,i;for(t in w2ui)typeof w2ui[t].resize=="function"&&(w2ui[t].panels==null&&w2ui[t].resize(),i=n(w2ui[t].box).parents(".w2ui-layout"),i.length>0&&i.attr("name")==h.name&&w2ui[t].resize())},100),this.trigger(n.extend(et,{phase:"after"})),(new Date).getTime()-st}},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});if(t.isCancelled!==!0)return w2ui[this.name]==null?!1:(n(this.box).find("#layout_"+this.name+"_panel_main").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-layout").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})),this.tmp.events&&this.tmp.events.resize&&n(window).off("resize",this.tmp.events.resize),!0)},lock:function(n){if(t.indexOf(n)==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var i=Array.prototype.slice.call(arguments,0);i[0]="#layout_"+this.name+"_panel_"+n;w2utils.lock.apply(window,i)},unlock:function(n,i){if(t.indexOf(n)==-1){console.log("ERROR: First parameter needs to be the a valid panel name.");return}var r="#layout_"+this.name+"_panel_"+n;w2utils.unlock(r,i)}};n.extend(i.prototype,w2utils.event);w2obj.layout=i}(jQuery);w2popup={},function(n){n.fn.w2popup=function(t,i){var r,u;return t==null&&(i={},t="open"),n.isPlainObject(t)&&(i=t,t="open"),t=t.toLowerCase(),t==="load"&&typeof i=="string"&&(i=n.extend({url:i},arguments.length>2?arguments[2]:{})),t==="open"&&i.url!=null&&(t="load"),i=i||{},r={},n(this).length>0&&t=="open"&&(n(this).find("div[rel=title], div[rel=body], div[rel=buttons]").length>0?(n("#w2ui-popup").length>0&&(u=n("#w2ui-popup").data("options"),w2popup._prev={template:w2popup._template,title:u.title,body:u.body,buttons:u.buttons}),w2popup._template=this,n(this).find("div[rel=title]").length>0&&(r.title=n(this).find("div[rel=title]")),n(this).find("div[rel=body]").length>0&&(r.body=n(this).find("div[rel=body]"),r.style=n(this).find("div[rel=body]")[0].style.cssText),n(this).find("div[rel=buttons]").length>0&&(r.buttons=n(this).find("div[rel=buttons]"))):(r.title="&#160;",r.body=n(this).html()),parseInt(n(this).css("width"))!==0&&(r.width=parseInt(n(this).css("width"))),parseInt(n(this).css("height"))!==0&&(r.height=parseInt(n(this).css("height")))),w2popup[t](n.extend({},r,i))};w2popup={defaults:{title:"",body:"",buttons:"",style:"",color:"#000",opacity:.4,speed:.3,modal:!1,maximized:!1,keyboard:!0,width:500,height:300,showClose:!0,showMax:!1,transition:null},status:"closed",handlers:[],onOpen:null,onClose:null,onMax:null,onMin:null,onToggle:null,onKeydown:null,open:function(t){function w(t){t||(t=window.event);w2popup.status="moving";i.resizing=!0;i.isLocked=n("#w2ui-popup > .w2ui-lock").length==1?!0:!1;i.x=t.screenX;i.y=t.screenY;i.pos_x=n("#w2ui-popup").position().left;i.pos_y=n("#w2ui-popup").position().top;i.isLocked||w2popup.lock({opacity:0});n(document).on("mousemove",i.mvMove);n(document).on("mouseup",i.mvStop);if(t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault)t.preventDefault();else return!1}function b(t){i.resizing==!0&&(t||(t=window.event),i.div_x=t.screenX-i.x,i.div_y=t.screenY-i.y,n("#w2ui-popup").css(w2utils.cssPrefix({transition:"none",transform:"translate3d("+i.div_x+"px, "+i.div_y+"px, 0px)"})))}function k(t){i.resizing==!0&&(t||(t=window.event),w2popup.status="open",i.div_x=t.screenX-i.x,i.div_y=t.screenY-i.y,n("#w2ui-popup").css({left:i.pos_x+i.div_x+"px",top:i.pos_y+i.div_y+"px"}).css(w2utils.cssPrefix({transition:"none",transform:"translate3d(0px, 0px, 0px)"})),i.resizing=!1,n(document).off("mousemove",i.mvMove),n(document).off("mouseup",i.mvStop),i.isLocked||w2popup.unlock())}var u=this,f,t,e,o,y,p,c,h,l,s,r,v,a,i;if(w2popup.status=="closing"){setTimeout(function(){u.open.call(u,t)},100);return}if(f=n("#w2ui-popup").data("options"),t=n.extend({},this.defaults,f,{title:"",body:"",buttons:""},t,{maximized:!1}),setTimeout(function(){n("#w2ui-popup").data("options",t)},100),n("#w2ui-popup").length===0&&(w2popup.onMax=null,w2popup.onMin=null,w2popup.onToggle=null,w2popup.onOpen=null,w2popup.onClose=null,w2popup.onKeydown=null),t.onOpen&&(w2popup.onOpen=t.onOpen),t.onClose&&(w2popup.onClose=t.onClose),t.onMax&&(w2popup.onMax=t.onMax),t.onMin&&(w2popup.onMin=t.onMin),t.onToggle&&(w2popup.onToggle=t.onToggle),t.onKeydown&&(w2popup.onKeydown=t.onKeydown),t.width=parseInt(t.width),t.height=parseInt(t.height),window.innerHeight==undefined?(e=parseInt(document.documentElement.offsetWidth),o=parseInt(document.documentElement.offsetHeight),w2utils.engine==="IE7"&&(e+=21,o+=4)):(e=parseInt(window.innerWidth),o=parseInt(window.innerHeight)),e-10<t.width&&(t.width=e-10),o-10<t.height&&(t.height=o-10),y=(o-t.height)/2*.6,p=(e-t.width)/2,n("#w2ui-popup").length===0){if(s=this.trigger({phase:"before",type:"open",target:"popup",options:t,present:!1}),s.isCancelled===!0)return;w2popup.status="opening";w2popup.lockScreen(t);c="";t.showClose&&(c+='<div class="w2ui-popup-button w2ui-popup-close" onmousedown="event.stopPropagation()" onclick="w2popup.close()">Close<\/div>');t.showMax&&(c+='<div class="w2ui-popup-button w2ui-popup-max" onmousedown="event.stopPropagation()" onclick="w2popup.toggle()">Max<\/div>');l='<div id="w2ui-popup" class="w2ui-popup" style="opacity: 0; left: '+p+"px; top: "+y+"px;     width: "+parseInt(t.width)+"px; height: "+parseInt(t.height)+"px; "+w2utils.cssPrefix("transform","scale(0.8)",!0)+'"><\/div>';n("body").append(l);h=n("#w2ui-popup");h.find("div[rel=title], div[rel=body], div[rel=buttons]").length>0&&(i=h.find("div[rel=title]"),i.length>0&&(t.title=i.html(),i.remove()),i=h.find("div[rel=buttons]"),i.length>0&&(t.buttons=i.html(),i.remove()),i=h.find("div[rel=body]"),t.body=i.length>0?i.html():h.html());l='<div class="w2ui-popup-title" style="'+(t.title?"":"display: none")+'">'+c+'<\/div><div class="w2ui-box" style="'+(t.title?"":"top: 0px !important;")+(t.buttons?"":"bottom: 0px !important;")+'">    <div class="w2ui-popup-body w2ui-popup-no-title'+(t.buttons?"":" w2ui-popup-no-buttons")+'" style="'+t.style+'">    <\/div><\/div><div class="w2ui-popup-buttons" style="'+(t.buttons?"":"display: none")+'"><\/div><input class="w2ui-popup-hidden" style="position: absolute; top: -100px"/>';n("#w2ui-popup").html(l);t.title&&n("#w2ui-popup .w2ui-popup-title").append(t.title);t.buttons&&n("#w2ui-popup .w2ui-popup-buttons").append(t.buttons);t.body&&n("#w2ui-popup .w2ui-popup-body").append(t.body);setTimeout(function(){n("#w2ui-popup").css("opacity","1").css(w2utils.cssPrefix({transition:t.speed+"s opacity, "+t.speed+"s -webkit-transform",transform:"scale(1)"}));u.focus()},1);setTimeout(function(){n("#w2ui-popup").css(w2utils.cssPrefix("transform",""));w2popup.status="open";setTimeout(function(){u.trigger(n.extend(s,{phase:"after"}))},100)},t.speed*1e3)}else{if(w2popup._prev==null&&w2popup._template!=null&&u.restoreTemplate(),s=this.trigger({phase:"before",type:"open",target:"popup",options:t,present:!0}),s.isCancelled===!0)return;w2popup.status="opening";f!=null&&(f.maximized||f.width==t.width&&f.height==t.height||w2popup.resize(t.width,t.height),t.prevSize=t.width+"px:"+t.height+"px",t.maximized=f.maximized);r=n("#w2ui-popup .w2ui-box").clone();r.removeClass("w2ui-box").addClass("w2ui-box-temp").find(".w2ui-popup-body").empty().append(t.body);typeof t.body=="string"&&r.find("div[rel=title], div[rel=body], div[rel=buttons]").length>0&&(i=r.find("div[rel=title]"),i.length>0&&(t.title=i.html(),i.remove()),i=r.find("div[rel=buttons]"),i.length>0&&(t.buttons=i.html(),i.remove()),i=r.find("div[rel=body]"),t.body=i.length>0?i.html():r.html(),r.html(t.body));n("#w2ui-popup .w2ui-box").after(r);t.buttons?(n("#w2ui-popup .w2ui-popup-buttons").show().html("").append(t.buttons),n("#w2ui-popup .w2ui-popup-body").removeClass("w2ui-popup-no-buttons"),n("#w2ui-popup .w2ui-box, #w2ui-popup .w2ui-box-temp").css("bottom","")):(n("#w2ui-popup .w2ui-popup-buttons").hide().html(""),n("#w2ui-popup .w2ui-popup-body").addClass("w2ui-popup-no-buttons"),n("#w2ui-popup .w2ui-box, #w2ui-popup .w2ui-box-temp").css("bottom","0px"));t.title?(n("#w2ui-popup .w2ui-popup-title").show().html((t.showClose?'<div class="w2ui-popup-button w2ui-popup-close" onmousedown="event.stopPropagation()" onclick="w2popup.close()">Close<\/div>':"")+(t.showMax?'<div class="w2ui-popup-button w2ui-popup-max" onmousedown="event.stopPropagation()" onclick="w2popup.toggle()">Max<\/div>':"")).append(t.title),n("#w2ui-popup .w2ui-popup-body").removeClass("w2ui-popup-no-title"),n("#w2ui-popup .w2ui-box, #w2ui-popup .w2ui-box-temp").css("top","")):(n("#w2ui-popup .w2ui-popup-title").hide().html(""),n("#w2ui-popup .w2ui-popup-body").addClass("w2ui-popup-no-title"),n("#w2ui-popup .w2ui-box, #w2ui-popup .w2ui-box-temp").css("top","0px"));v=n("#w2ui-popup .w2ui-box")[0];a=n("#w2ui-popup .w2ui-box-temp")[0];w2utils.transition(v,a,t.transition,function(){u.restoreTemplate();n(v).remove();n(a).removeClass("w2ui-box-temp").addClass("w2ui-box");var i=n(a).find(".w2ui-popup-body");i.length==1&&(i[0].style.cssText=t.style);n("#w2ui-popup").data("prev-size",null);u.focus();w2popup.status="open";u.trigger(n.extend(s,{phase:"after"}))})}if(t._last_focus=n(":focus"),t.keyboard)n(document).on("keydown",this.keydown);i={resizing:!1,mvMove:b,mvStop:k};n("#w2ui-popup .w2ui-popup-title").on("mousedown",function(n){w2popup.get().maximized||w(n)});return this},keydown:function(t){var i=n("#w2ui-popup").data("options"),r;if((!i||i.keyboard)&&(r=w2popup.trigger({phase:"before",type:"keydown",target:"popup",options:i,originalEvent:t}),r.isCancelled!==!0)){switch(t.keyCode){case 27:t.preventDefault();n("#w2ui-popup .w2ui-message").length>0?w2popup.message():w2popup.close()}w2popup.trigger(n.extend(r,{phase:"after"}))}},close:function(t){var r=this,t=n.extend({},n("#w2ui-popup").data("options"),t),i;if(n("#w2ui-popup").length!==0&&this.status!="closed"){if(this.status=="opening"){setTimeout(function(){w2popup.close()},100);return}(i=this.trigger({phase:"before",type:"close",target:"popup",options:t}),i.isCancelled!==!0)&&(w2popup.status="closing",n("#w2ui-popup").css("opacity","0").css(w2utils.cssPrefix({transition:t.speed+"s opacity, "+t.speed+"s -webkit-transform",transform:"scale(0.9)"})),w2popup.unlockScreen(t),setTimeout(function(){r.restoreTemplate();n("#w2ui-popup").remove();w2popup.status="closed";t._last_focus.length>0&&t._last_focus.focus();r.trigger(n.extend(i,{phase:"after"}))},t.speed*1e3),t.keyboard&&n(document).off("keydown",this.keydown))}},toggle:function(){var r=this,t=n("#w2ui-popup").data("options"),i=this.trigger({phase:"before",type:"toggle",target:"popup",options:t});i.isCancelled!==!0&&(t.maximized===!0?w2popup.min():w2popup.max(),setTimeout(function(){r.trigger(n.extend(i,{phase:"after"}))},t.speed*1e3+50))},max:function(){var r=this,t=n("#w2ui-popup").data("options"),i;t.maximized!==!0&&(i=this.trigger({phase:"before",type:"max",target:"popup",options:t}),i.isCancelled!==!0)&&(w2popup.status="resizing",t.prevSize=n("#w2ui-popup").css("width")+":"+n("#w2ui-popup").css("height"),w2popup.resize(1e4,1e4,function(){w2popup.status="open";t.maximized=!0;r.trigger(n.extend(i,{phase:"after"}));n("#w2ui-popup .w2ui-grid, #w2ui-popup .w2ui-form, #w2ui-popup .w2ui-layout").each(function(){var t=n(this).attr("name");w2ui[t]&&w2ui[t].resize&&w2ui[t].resize()})}))},min:function(){var u=this,t=n("#w2ui-popup").data("options"),i,r;t.maximized===!0&&(i=t.prevSize.split(":"),r=this.trigger({phase:"before",type:"min",target:"popup",options:t}),r.isCancelled!==!0)&&(w2popup.status="resizing",w2popup.resize(parseInt(i[0]),parseInt(i[1]),function(){w2popup.status="open";t.maximized=!1;t.prevSize=null;u.trigger(n.extend(r,{phase:"after"}));n("#w2ui-popup .w2ui-grid, #w2ui-popup .w2ui-form, #w2ui-popup .w2ui-layout").each(function(){var t=n(this).attr("name");w2ui[t]&&w2ui[t].resize&&w2ui[t].resize()})}))},get:function(){return n("#w2ui-popup").data("options")},set:function(n){w2popup.open(n)},clear:function(){n("#w2ui-popup .w2ui-popup-title").html("");n("#w2ui-popup .w2ui-popup-body").html("");n("#w2ui-popup .w2ui-popup-buttons").html("")},reset:function(){w2popup.open(w2popup.defaults)},load:function(t){function e(i,r){if(delete t.url,n("body").append('<div id="w2ui-tmp" style="display: none">'+i+"<\/div>"),r!=null&&n("#w2ui-tmp #"+r).length>0?n("#w2ui-tmp #"+r).w2popup(t):n("#w2ui-tmp > div").w2popup(t),n("#w2ui-tmp > style").length>0){var u=n("<div>").append(n("#w2ui-tmp > style").clone()).html();n("#w2ui-popup #div-style").length===0&&n("#w2ui-popup").append('<div id="div-style" style="position: absolute; left: -100; width: 1px"><\/div>');n("#w2ui-popup #div-style").html(u)}n("#w2ui-tmp").remove()}var r;if(w2popup.status="loading",t.url==null){console.log("ERROR: The url parameter is empty.");return}var u=String(t.url).split("#"),i=u[0],f=u[1];t==null&&(t={});r=n("#w2ui-popup").data(i);r!=null?e(r,f):n.get(i,function(t,r,u){e(u.responseText,f);n("#w2ui-popup").data(i,u.responseText)})},message:function(t){var h=this,s,c,r,f,e,i,u,t,o;n().w2tag();t||(t={width:200,height:100});s=parseInt(n("#w2ui-popup").width());c=parseInt(n("#w2ui-popup").height());t.originalWidth=t.width;t.originalHeight=t.height;parseInt(t.width)<10&&(t.width=10);parseInt(t.height)<10&&(t.height=10);t.hideOnClick==null&&(t.hideOnClick=!1);r=n("#w2ui-popup").data("options")||{};f=parseInt(n("#w2ui-popup > .w2ui-popup-title").css("height"));(t.width==null||t.width>r.width-10)&&(t.width=r.width-10);(t.height==null||t.height>r.height-f-5)&&(t.height=r.height-f-5);t.originalHeight<0&&(t.height=c+t.originalHeight-f);t.originalWidth<0&&(t.width=s+t.originalWidth*2);e=n("#w2ui-popup .w2ui-popup-title");i=n("#w2ui-popup .w2ui-message").length;n.trim(t.html)===""&&n.trim(t.body)===""&&n.trim(t.buttons)===""?(u=n("#w2ui-popup #w2ui-message"+(i-1)),t=u.data("options")||{},u.css(w2utils.cssPrefix({transition:"0.15s",transform:"translateY(-"+t.height+"px)"})),i==1?w2popup.unlock(150):n("#w2ui-popup #w2ui-message"+(i-2)).css("z-index",1500),setTimeout(function(){var n=u.data("prev_focus");u.remove();n&&n.length>0?n.focus():h.focus();typeof t.onClose=="function"&&t.onClose()},150)):((n.trim(t.body)!==""||n.trim(t.buttons)!=="")&&(t.html='<div class="w2ui-message-body">'+t.body+'<\/div><div class="w2ui-message-buttons">'+t.buttons+"<\/div>"),n("#w2ui-popup .w2ui-message").css("z-index",1390),e.css("z-index",1501),n("#w2ui-popup .w2ui-box").before('<div id="w2ui-message'+i+'" class="w2ui-message" style="display: none; z-index: 1500; '+(e.length===0?"top: 0px;":"top: "+w2utils.getSize(e,"height")+"px;")+(t.width!=null?"width: "+t.width+"px; left: "+(s-t.width)/2+"px;":"left: 10px; right: 10px;")+(t.height!=null?"height: "+t.height+"px;":"bottom: 6px;")+w2utils.cssPrefix("transition",".3s",!0)+'"'+(t.hideOnClick===!0?'onclick="w2popup.message();"':"")+"><\/div>"),n("#w2ui-popup #w2ui-message"+i).data("options",t).data("prev_focus",n(":focus")),o=n("#w2ui-popup #w2ui-message"+i).css("display"),n("#w2ui-popup #w2ui-message"+i).css(w2utils.cssPrefix({transform:o=="none"?"translateY(-"+t.height+"px)":"translateY(0px)"})),o=="none"&&(n("#w2ui-popup #w2ui-message"+i).show().html(t.html),setTimeout(function(){n("#w2ui-popup #w2ui-message"+i).css(w2utils.cssPrefix({transform:o=="none"?"translateY(0px)":"translateY(-"+t.height+"px)"}))},1),i===0&&w2popup.lock(),setTimeout(function(){h.focus();n("#w2ui-popup #w2ui-message"+i).css(w2utils.cssPrefix({transition:"0s"}));typeof t.onOpen=="function"&&t.onOpen()},350)))},focus:function(){var i=null,u=n("#w2ui-popup"),f="input:visible, button:visible, select:visible, textarea:visible",e,r,t;n(u).find(f).off(".keep-focus");e=n("#w2ui-popup .w2ui-message").length-1;r=n("#w2ui-popup #w2ui-message"+e);r.length>0?(t=n(r[r.length-1]).find("button"),t.length>0&&t[0].focus(),i=r):u.length>0&&(t=u.find(".w2ui-popup-buttons button"),t.length>0&&t[0].focus(),i=u);n(i).find(f).on("blur.keep-focus",function(){setTimeout(function(){var t=n(":focus"),r;(t.length>0&&!n(i).find(f).is(t)||t.hasClass("w2ui-popup-hidden"))&&(r=n(i).find(f),r.length>0&&r[0].focus())},1)})},lock:function(){var t=Array.prototype.slice.call(arguments,0);t.unshift(n("#w2ui-popup"));w2utils.lock.apply(window,t)},unlock:function(t){w2utils.unlock(n("#w2ui-popup"),t)},lockScreen:function(t){if(n("#w2ui-lock").length>0)return!1;if(t==null&&(t=n("#w2ui-popup").data("options")),t==null&&(t={}),t=n.extend({},w2popup.defaults,t),n("body").append('<div id="w2ui-lock"     onmousewheel="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; if (event.preventDefault) event.preventDefault(); else return false;"    style="position: '+(w2utils.engine=="IE5"?"absolute":"fixed")+"; z-Index: 1199; left: 0px; top: 0px;            padding: 0px; margin: 0px; background-color: "+t.color+'; width: 100%; height: 100%; opacity: 0;"><\/div>'),setTimeout(function(){n("#w2ui-lock").css("opacity",t.opacity).css(w2utils.cssPrefix("transition",t.speed+"s opacity"))},1),t.modal==!0){n("#w2ui-lock").on("mousedown",function(){n("#w2ui-lock").css("opacity","0.6").css(w2utils.cssPrefix("transition",".1s"))});n("#w2ui-lock").on("mouseup",function(){setTimeout(function(){n("#w2ui-lock").css("opacity",t.opacity).css(w2utils.cssPrefix("transition",".1s"))},100)})}else n("#w2ui-lock").on("mousedown",function(){w2popup.close()});return!0},unlockScreen:function(t){return n("#w2ui-lock").length===0?!1:(t==null&&(t=n("#w2ui-popup").data("options")),t==null&&(t={}),t=n.extend({},w2popup.defaults,t),n("#w2ui-lock").css("opacity","0").css(w2utils.cssPrefix("transition",t.speed+"s opacity")),setTimeout(function(){n("#w2ui-lock").remove()},t.speed*1e3),!0)},resizeMessages:function(){var t=this,i=n("#w2ui-popup").data("options");n("#w2ui-popup .w2ui-message").each(function(){var t=n(this).data("options"),r=n("#w2ui-popup");parseInt(t.width)<10&&(t.width=10);parseInt(t.height)<10&&(t.height=10);var u=parseInt(r.find("> .w2ui-popup-title").css("height")),i=parseInt(r.width()),f=parseInt(r.height());t.width=t.originalWidth;t.width>i-10&&(t.width=i-10);t.height=t.originalHeight;t.height>f-u-5&&(t.height=f-u-5);t.originalHeight<0&&(t.height=f+t.originalHeight-u);t.originalWidth<0&&(t.width=i+t.originalWidth*2);n(this).css({left:(i-t.width)/2+"px",width:t.width+"px",height:t.height+"px"})})},resize:function(t,i,r){var o=this,u=n("#w2ui-popup").data("options"),f,e,s,h,c;t=parseInt(t);i=parseInt(i);window.innerHeight==undefined?(f=parseInt(document.documentElement.offsetWidth),e=parseInt(document.documentElement.offsetHeight),w2utils.engine==="IE7"&&(f+=21,e+=4)):(f=parseInt(window.innerWidth),e=parseInt(window.innerHeight));f-10<t&&(t=f-10);e-10<i&&(i=e-10);s=(e-i)/2*.6;h=(f-t)/2;n("#w2ui-popup").css(w2utils.cssPrefix({transition:u.speed+"s width, "+u.speed+"s height, "+u.speed+"s left, "+u.speed+"s top"})).css({top:s,left:h,width:t,height:i});c=setInterval(function(){o.resizeMessages()},10);setTimeout(function(){clearInterval(c);u.width=t;u.height=i;o.resizeMessages();typeof r=="function"&&r()},u.speed*1e3+50)},restoreTemplate:function(){var r=n("#w2ui-popup").data("options"),t;if(r!=null){var u=w2popup._template,f=r.title,i=r.body,e=r.buttons;if(w2popup._prev?(u=w2popup._prev.template,f=w2popup._prev.title,i=w2popup._prev.body,e=w2popup._prev.buttons,delete w2popup._prev):delete w2popup._template,u!=null){if(t=n(u),t.length===0)return;n(i).attr("rel")=="body"?(f&&t.append(f),i&&t.append(i),e&&t.append(e)):t.append(i)}}}};n.extend(w2popup,w2utils.event)}(jQuery);var w2alert=function(n,t,i){var r=jQuery;return t==null&&(t=w2utils.lang("Notification")),r("#w2ui-popup").length>0&&w2popup.status!="closing"?w2popup.message({width:400,height:170,body:'<div class="w2ui-centered w2ui-alert-msg" style="font-size: 13px;">'+n+"<\/div>",buttons:'<button onclick="w2popup.message();" class="w2ui-popup-btn w2ui-btn">'+w2utils.lang("Ok")+"<\/button>",onOpen:function(){r("#w2ui-popup .w2ui-message .w2ui-popup-btn").focus()},onClose:function(){typeof i=="function"&&i()}}):w2popup.open({width:450,height:220,showMax:!1,showClose:!1,title:t,body:'<div class="w2ui-centered w2ui-alert-msg" style="font-size: 13px;">'+n+"<\/div>",buttons:'<button onclick="w2popup.close();" class="w2ui-popup-btn w2ui-btn">'+w2utils.lang("Ok")+"<\/button>",onOpen:function(){setTimeout(function(){r("#w2ui-popup .w2ui-popup-btn").focus()},1)},onKeydown:function(){r("#w2ui-popup .w2ui-popup-btn").focus().addClass("clicked")},onClose:function(){typeof i=="function"&&i()}}),{ok:function(n){return i=n,this},done:function(n){return i=n,this}}},w2confirm=function(n,t,i){var u=jQuery,r={},f={msg:"",title:w2utils.lang("Confirmation"),width:u("#w2ui-popup").length>0?400:450,height:u("#w2ui-popup").length>0?170:220,yes_text:"Yes",yes_class:"",yes_style:"",yes_callBack:null,no_text:"No",no_class:"",no_style:"",no_callBack:null,callBack:null};return arguments.length==1&&typeof n=="object"?u.extend(r,f,n):typeof t=="function"?u.extend(r,f,{msg:n,callBack:t}):u.extend(r,f,{msg:n,title:t,callBack:i}),typeof r.btn_yes=="object"&&(r.yes_text=r.btn_yes.text||r.yes_text,r.yes_class=r.btn_yes["class"]||r.yes_class,r.yes_style=r.btn_yes.style||r.yes_style,r.yes_callBack=r.btn_yes.callBack||r.yes_callBack),typeof r.btn_no=="object"&&(r.no_text=r.btn_no.text||r.no_text,r.no_class=r.btn_no["class"]||r.no_class,r.no_style=r.btn_no.style||r.no_style,r.no_callBack=r.btn_no.callBack||r.no_callBack),u("#w2ui-popup").length>0&&w2popup.status!="closing"&&w2popup.get()?(r.width>w2popup.get().width&&(r.width=w2popup.get().width),r.height>w2popup.get().height-50&&(r.height=w2popup.get().height-50),w2popup.message({width:r.width,height:r.height,body:'<div class="w2ui-centered w2ui-confirm-msg" style="font-size: 13px;">'+r.msg+"<\/div>",buttons:'<button id="Yes" class="w2ui-popup-btn w2ui-btn '+r.yes_class+'" style="'+r.yes_style+'">'+w2utils.lang(r.yes_text)+'<\/button><button id="No" class="w2ui-popup-btn w2ui-btn '+r.no_class+'" style="'+r.no_style+'">'+w2utils.lang(r.no_text)+"<\/button>",onOpen:function(){u("#w2ui-popup .w2ui-message .w2ui-btn").on("click.w2confirm",function(n){w2popup._confirm_btn=n.target.id;w2popup.message()})},onClose:function(){u("#w2ui-popup .w2ui-message .w2ui-btn").off("click.w2confirm");setTimeout(function(){typeof r.callBack=="function"&&r.callBack(w2popup._confirm_btn);w2popup._confirm_btn=="Yes"&&typeof r.yes_callBack=="function"&&r.yes_callBack();w2popup._confirm_btn=="No"&&typeof r.no_callBack=="function"&&r.no_callBack()},300)}})):(w2utils.isInt(r.height)||(r.height=r.height+50),w2popup.open({width:r.width,height:r.height,title:r.title,modal:!0,showClose:!1,body:'<div class="w2ui-centered w2ui-confirm-msg" style="font-size: 13px;">'+r.msg+"<\/div>",buttons:'<button id="Yes" class="w2ui-popup-btn w2ui-btn '+r.yes_class+'" style="'+r.yes_style+'">'+w2utils.lang(r.yes_text)+'<\/button><button id="No" class="w2ui-popup-btn w2ui-btn '+r.no_class+'" style="'+r.no_style+'">'+w2utils.lang(r.no_text)+"<\/button>",onOpen:function(){setTimeout(function(){u("#w2ui-popup .w2ui-popup-btn").on("click",function(n){w2popup.close();typeof r.callBack=="function"&&r.callBack(n.target.id);n.target.id=="Yes"&&typeof r.yes_callBack=="function"&&r.yes_callBack();n.target.id=="No"&&typeof r.no_callBack=="function"&&r.no_callBack()});u("#w2ui-popup .w2ui-popup-btn#Yes").focus()},1)},onKeydown:function(n){if(u("#w2ui-popup .w2ui-message").length===0)switch(n.originalEvent.keyCode){case 13:u("#w2ui-popup .w2ui-popup-btn#Yes").focus().addClass("clicked");w2popup.close();break;case 27:u("#w2ui-popup .w2ui-popup-btn#No").focus().click();w2popup.close()}}})),{yes:function(n){return r.yes_callBack=n,this},no:function(n){return r.no_callBack=n,this}}},w2prompt=function(n,t,i){var u=jQuery,r={},f={label:"",value:"",attrs:"",title:w2utils.lang("Notification"),ok_text:w2utils.lang("Ok"),cancel_text:w2utils.lang("Cancel"),width:u("#w2ui-popup").length>0?400:450,height:u("#w2ui-popup").length>0?170:220,callBack:null};return arguments.length==1&&typeof n=="object"?u.extend(r,f,n):typeof t=="function"?u.extend(r,f,{label:n,callBack:t}):u.extend(r,f,{label:n,title:t,callBack:i}),u("#w2ui-popup").length>0&&w2popup.status!="closing"&&w2popup.get()?(r.width>w2popup.get().width&&(r.width=w2popup.get().width),r.height>w2popup.get().height-50&&(r.height=w2popup.get().height-50),w2popup.message({width:r.width,height:r.height,body:'<div class="w2ui-centered" style="font-size: 13px;">   <label style="margin-right: 10px;">'+r.label+':<\/label>   <input id="w2prompt" '+r.attrs+"><\/div>",buttons:'<button id="Ok" class="w2ui-popup-btn w2ui-btn">'+r.ok_text+'<\/button><button id="Cancel" class="w2ui-popup-btn w2ui-btn">'+r.cancel_text+"<\/button>",onOpen:function(){u("#w2prompt").val(r.value);u("#w2ui-popup .w2ui-message .w2ui-btn#Ok").on("click.w2prompt",function(){w2popup._prompt_value=u("#w2prompt").val();w2popup.message()});u("#w2ui-popup .w2ui-message .w2ui-btn#Cancel").on("click.w2prompt",function(){w2popup._prompt_value=null;w2popup.message()});setTimeout(function(){u("#w2prompt").focus()},100)},onClose:function(){u("#w2ui-popup .w2ui-message .w2ui-btn").off("click.w2prompt");setTimeout(function(){typeof r.callBack=="function"&&w2popup._prompt_value!=null&&r.callBack(w2popup._prompt_value)},300)}})):(w2utils.isInt(r.height)||(r.height=r.height+50),w2popup.open({width:r.width,height:r.height,title:r.title,modal:!0,showClose:!1,body:'<div class="w2ui-centered" style="font-size: 13px;"><label style="margin-right: 10px;">'+r.label+':<\/label><input id="w2prompt"><\/div>',buttons:'<button id="Ok" class="w2ui-popup-btn w2ui-btn">'+r.ok_text+'<\/button><button id="Cancel" class="w2ui-popup-btn w2ui-btn">'+r.cancel_text+"<\/button>",onOpen:function(){setTimeout(function(){u("#w2prompt").val(r.value);u("#w2prompt").w2field("text");u("#w2ui-popup .w2ui-popup-btn#Ok").on("click",function(){w2popup._prompt_value=u("#w2prompt").val();w2popup.close();typeof r.callBack=="function"&&r.callBack(w2popup._prompt_value)});u("#w2ui-popup .w2ui-popup-btn#Cancel").on("click",function(){w2popup._prompt_value=null;w2popup.close()});u("#w2ui-popup .w2ui-popup-btn#Ok");setTimeout(function(){u("#w2prompt").focus()},100)},1)},onKeydown:function(n){if(u("#w2ui-popup .w2ui-message").length===0)switch(n.originalEvent.keyCode){case 13:u("#w2ui-popup .w2ui-popup-btn#Ok").focus().addClass("clicked");w2popup.close();break;case 27:w2popup.close()}}})),{change:function(n){return u("#w2prompt").on("keyup",n).keyup(),this},ok:function(n){return r.callBack=n,this}}};(function(n){var t=function(t){this.box=null;this.name=null;this.active=null;this.flow="down";this.tooltip="top|left";this.tabs=[];this.routeData={};this.right="";this.style="";n.extend(this,{handlers:[]});n.extend(!0,this,w2obj.tabs,t)};n.fn.w2tabs=function(i){var e,r,f,u;if(n.isPlainObject(i)){if(!w2utils.checkName(i,"w2tabs"))return;for(e=i.tabs||[],r=new t(i),f=0;f<e.length;f++)r.tabs[f]=n.extend({},t.prototype.tab,e[f]);return n(this).length!==0&&r.render(n(this)[0]),w2ui[r.name]=r,r}return(u=w2ui[n(this).attr("name")],!u)?null:arguments.length>0?(u[i]&&u[i].apply(u,Array.prototype.slice.call(arguments,1)),this):u};t.prototype={onClick:null,onClose:null,onRender:null,onRefresh:null,onResize:null,onDestroy:null,tab:{id:null,text:null,route:null,hidden:!1,disabled:!1,closable:!1,tooltip:null,style:"",onClick:null,onRefresh:null,onClose:null},add:function(n){return this.insert(null,n)},insert:function(i,r){var u,f,e;for(n.isArray(r)||(r=[r]),u=0;u<r.length;u++){if(r[u].id==null){console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+this.name+")");return}if(!w2utils.checkUniqueId(r[u].id,this.tabs,"tabs",this.name))return;f=n.extend({},t.prototype.tab,r[u]);i==null?this.tabs.push(f):(e=this.get(i,!0),this.tabs=this.tabs.slice(0,e).concat([f],this.tabs.slice(e)));this.refresh(r[u].id);this.resize()}},remove:function(){for(var t,r=0,i=0;i<arguments.length;i++){if(t=this.get(arguments[i]),!t)return!1;r++;this.tabs.splice(this.get(t.id,!0),1);n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(t.id)).remove()}return this.resize(),r},select:function(n){return this.active==n||this.get(n)==null?!1:(this.active=n,this.refresh(),!0)},set:function(t,i){var r=this.get(t,!0);return r==null?!1:(n.extend(this.tabs[r],i),this.refresh(t),!0)},get:function(n,t){var u,r,i;if(arguments.length===0){for(u=[],r=0;r<this.tabs.length;r++)this.tabs[r].id!=null&&u.push(this.tabs[r].id);return u}for(i=0;i<this.tabs.length;i++)if(this.tabs[i].id==n)return t===!0?i:this.tabs[i];return null},show:function(){for(var n,r=this,u=0,t=[],i=0;i<arguments.length;i++)(n=this.get(arguments[i]),n&&n.hidden!==!1)&&(u++,n.hidden=!1,t.push(n.id));return setTimeout(function(){for(var n=0;n<t.length;n++)r.refresh(t[n]);r.resize()},15),u},hide:function(){for(var n,r=this,u=0,t=[],i=0;i<arguments.length;i++)(n=this.get(arguments[i]),n&&n.hidden!==!0)&&(u++,n.hidden=!0,t.push(n.id));return setTimeout(function(){for(var n=0;n<t.length;n++)r.refresh(t[n]);r.resize()},15),u},enable:function(){for(var n,u=this,r=0,t=[],i=0;i<arguments.length;i++)(n=this.get(arguments[i]),n&&n.disabled!==!1)&&(r++,n.disabled=!1,t.push(n.id));return setTimeout(function(){for(var n=0;n<t.length;n++)u.refresh(t[n])},15),r},disable:function(){for(var n,u=this,r=0,t=[],i=0;i<arguments.length;i++)(n=this.get(arguments[i]),n&&n.disabled!==!0)&&(r++,n.disabled=!0,t.push(n.id));return setTimeout(function(){for(var n=0;n<t.length;n++)u.refresh(t[n])},15),r},tooltipShow:function(t,i,r){if(this.tooltip!=null){var u=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(t)),e=this.get(t),o=this.tooltip,f=e.tooltip;typeof f=="function"&&(f=f.call(this,e));u.prop("_mouse_over",!0);setTimeout(function(){u.prop("_mouse_over")===!0&&u.prop("_mouse_tooltip")!==!0&&(u.prop("_mouse_tooltip",!0),u.w2tag(w2utils.lang(f),{position:o}));r==!0&&u.w2tag(w2utils.lang(f),{position:o})},1)}},tooltipHide:function(t){if(this.tooltip!=null){var i=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(t)),r=this.get(t);i.removeProp("_mouse_over");setTimeout(function(){i.prop("_mouse_over")!==!0&&i.prop("_mouse_tooltip")===!0&&(i.removeProp("_mouse_tooltip"),i.w2tag())},1)}},refresh:function(t){var l=(new Date).getTime(),o,f,i,r,u,s,h,e,c;if(this.flow=="up"?n(this.box).addClass("w2ui-tabs-up"):n(this.box).removeClass("w2ui-tabs-up"),o=this.trigger({phase:"before",type:"refresh",target:t!=null?t:this.name,object:this.get(t)}),o.isCancelled!==!0){if(t==null)for(f=0;f<this.tabs.length;f++)this.refresh(this.tabs[f].id);else{if(i=this.get(t),i==null)return!1;i.text==null&&i.caption!=null&&(i.text=i.caption);i.tooltip==null&&i.hint!=null&&(i.tooltip=i.hint);r=i.text;typeof r=="function"&&(r=r.call(this,i));r==null&&(r="");u=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id));s="";i.closable&&!i.disabled&&(s='<div class="w2ui-tab-close"     onmouseover = "w2ui[\''+this.name+"'].tooltipShow('"+i.id+"', event);\"    onmouseout  = \"w2ui['"+this.name+"'].tooltipHide('"+i.id+"', event);\"    onclick=\"w2ui['"+this.name+"'].animateClose('"+i.id+"', event);\"><\/div>");h=s+'    <div class="w2ui-tab'+(this.active===i.id?" active":"")+(i.closable?" closable":"")+(i["class"]?" "+i["class"]:"")+'" style="'+i.style+'"         onmouseover = "'+(i.disabled?"":"w2ui['"+this.name+"'].tooltipShow('"+i.id+"', event);")+'"        onmouseout  = "'+(i.disabled?"":"w2ui['"+this.name+"'].tooltipHide('"+i.id+"', event);")+'"        onclick="w2ui[\''+this.name+"'].click('"+i.id+"', event);\">"+w2utils.lang(r)+"<\/div>";u.length===0?(e="",i.hidden&&(e+="display: none;"),i.disabled&&(e+="opacity: 0.2;"),c='<td id="tabs_'+this.name+"_tab_"+i.id+'" style="'+e+'" valign="middle">'+h+"<\/td>",this.get(t,!0)!==this.tabs.length-1&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))+1].id)).before(c):n(this.box).find("#tabs_"+this.name+"_right").before(c)):(u.html(h),i.hidden?u.css("display","none"):u.css("display",""),i.disabled?u.css({opacity:"0.2"}):u.css({opacity:"1"}))}return n("#tabs_"+this.name+"_right").html(this.right),this.trigger(n.extend(o,{phase:"after"})),(new Date).getTime()-l}},render:function(t){var u=(new Date).getTime(),i=this.trigger({phase:"before",type:"render",target:this.name,box:t}),r;if(i.isCancelled!==!0)return(t!=null&&(n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),this.box=t),!this.box)?!1:(r='<div class="w2ui-scroll-wrapper" onmousedown="var el=w2ui[\''+this.name+'\']; if (el) el.resize();"><table cellspacing="0" cellpadding="1" width="100%"><tbody>    <tr><td width="100%" id="tabs_'+this.name+'_right" align="right">'+this.right+'<\/td><\/tr><\/tbody><\/table><\/div><div class="w2ui-scroll-left" onclick="var el=w2ui[\''+this.name+"']; if (el) el.scroll('left');\"><\/div><div class=\"w2ui-scroll-right\" onclick=\"var el=w2ui['"+this.name+"']; if (el) el.scroll('right');\"><\/div>",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-tabs").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.trigger(n.extend(i,{phase:"after"})),this.refresh(),this.resize(),(new Date).getTime()-u)},scroll:function(t){var o=n(this.box),s=this,r=o.find(".w2ui-scroll-wrapper"),e=r.scrollLeft(),u,f,i;switch(t){case"left":u=r.outerWidth();f=r.find(":first").outerWidth();i=e-u+50;i<=0&&(i=0);r.animate({scrollLeft:i},300);break;case"right":u=r.outerWidth();f=r.find(":first").outerWidth();i=e+u-50;i>=f-u&&(i=f-u);r.animate({scrollLeft:i},300)}setTimeout(function(){s.resize()},350)},resize:function(){var u=(new Date).getTime(),r=this.trigger({phase:"before",type:"resize",target:this.name}),i,t;if(r.isCancelled!==!0)return i=n(this.box),i.find(".w2ui-scroll-left, .w2ui-scroll-right").hide(),t=i.find(".w2ui-scroll-wrapper"),t.find(":first").outerWidth()>t.outerWidth()&&(t.scrollLeft()>0&&i.find(".w2ui-scroll-left").show(),t.scrollLeft()<t.find(":first").outerWidth()-t.outerWidth()&&i.find(".w2ui-scroll-right").show()),this.trigger(n.extend(r,{phase:"after"})),(new Date).getTime()-u},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});t.isCancelled!==!0&&(n(this.box).find("> table #tabs_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})))},click:function(t,i){var r=this.get(t),o,e,u,f;if(r==null||r.disabled)return!1;if(o=this.trigger({phase:"before",type:"click",target:t,tab:r,object:r,originalEvent:i}),o.isCancelled!==!0){if(n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.active)+" .w2ui-tab").removeClass("active"),this.active=r.id,typeof r.route=="string"){if(e=r.route!==""?String("/"+r.route).replace(/\/{2,}/g,"/"):"",u=w2utils.parseRoute(e),u.keys.length>0)for(f=0;f<u.keys.length;f++)this.routeData[u.keys[f].name]!=null&&(e=e.replace(new RegExp(":"+u.keys[f].name,"g"),this.routeData[u.keys[f].name]));setTimeout(function(){window.location.hash=e},1)}this.trigger(n.extend(o,{phase:"after"}));this.refresh(t)}},animateClose:function(t,i){var u=this.get(t),f,r;if(u==null||u.disabled)return!1;(f=this.trigger({phase:"before",type:"close",target:t,object:this.get(t),originalEvent:i}),f.isCancelled!==!0)&&(r=this,n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(u.id)).css(w2utils.cssPrefix("transition",".2s")).css("opacity","0"),setTimeout(function(){var t=n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).width();n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).html('<div style="width: '+t+"px; "+w2utils.cssPrefix("transition",".2s",!0)+'"><\/div>');setTimeout(function(){n(r.box).find("#tabs_"+r.name+"_tab_"+w2utils.escapeId(u.id)).find(":first-child").css({width:"0px"})},50)},200),setTimeout(function(){r.remove(t)},450),this.trigger(n.extend(f,{phase:"after"})),this.refresh())},animateInsert:function(t,i){var e,o,s,r,u,f;this.get(t)!=null&&n.isPlainObject(i)&&w2utils.checkUniqueId(i.id,this.tabs,"tabs",this.name)&&(e=n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id)),e.length===0)&&(i.text==null&&i.caption!=null&&(i.text=i.caption),o='<div id="_tmp_tabs" class="w2ui-reset w2ui-tabs" style="position: absolute; top: -1000px;"><table cellspacing="0" cellpadding="1" width="100%"><tbody><tr><td id="_tmp_simple_tab" style="" valign="middle">'+(i.closable?'<div class="w2ui-tab-close"><\/div>':"")+'    <div class="w2ui-tab '+(this.active===i.id?"active":"")+'">'+i.text+"<\/div><\/td><\/tr><\/tbody><\/table><\/div>",n("body").append(o),s='<div style="width: 1px; '+w2utils.cssPrefix("transition",".2s",!0)+'">&#160;<\/div>',r="",i.hidden&&(r+="display: none;"),i.disabled&&(r+="opacity: 0.2;"),u='<td id="tabs_'+this.name+"_tab_"+i.id+'" style="'+r+'" valign="middle">'+s+"<\/td>",this.get(t,!0)!==this.tabs.length&&n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).length>0?n(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(t,!0))].id)).before(u):n(this.box).find("#tabs_"+this.name+"_right").before(u),f=this,setTimeout(function(){var t=n("#_tmp_simple_tab").width();n("#_tmp_tabs").remove();n("#tabs_"+f.name+"_tab_"+w2utils.escapeId(i.id)+" > div").css("width",t+"px")},1),setTimeout(function(){f.insert(t,i)},200))}};n.extend(t.prototype,w2utils.event);w2obj.tabs=t})(jQuery),function(n){var t=function(t){this.box=null;this.name=null;this.routeData={};this.items=[];this.right="";this.tooltip="top|left";n.extend(!0,this,w2obj.toolbar,t)};n.fn.w2toolbar=function(i){var h,f,e,u,o,r,s;if(n.isPlainObject(i)){if(!w2utils.checkName(i,"w2toolbar"))return;for(h=i.items||[],f=new t(i),n.extend(f,{items:[],handlers:[]}),e=0;e<h.length;e++)if(f.items[e]=n.extend({},t.prototype.item,h[e]),f.items[e].type=="menu-check"){if(u=f.items[e],Array.isArray(u.selected)||(u.selected=[]),Array.isArray(u.items))for(o=0;o<u.items.length;o++)r=u.items[o],r.checked&&u.selected.indexOf(r.id)==-1&&u.selected.push(r.id),r.checked||u.selected.indexOf(r.id)==-1||(r.checked=!0),r.checked==null&&(r.checked=!1)}else if(f.items[e].type=="menu-radio"&&(u=f.items[e],Array.isArray(u.items)))for(o=0;o<u.items.length;o++)r=u.items[o],r.checked&&u.selected==null?u.selected=r.id:r.checked=!1,r.checked||u.selected!=r.id||(r.checked=!0),r.checked==null&&(r.checked=!1);return n(this).length!==0&&f.render(n(this)[0]),w2ui[f.name]=f,f}return(s=w2ui[n(this).attr("name")],!s)?null:arguments.length>0?(s[i]&&s[i].apply(s,Array.prototype.slice.call(arguments,1)),this):s};t.prototype={onClick:null,onRender:null,onRefresh:null,onResize:null,onDestroy:null,item:{id:null,type:"button",text:null,html:"",tooltip:null,count:null,hidden:!1,disabled:!1,checked:!1,img:null,icon:null,route:null,arrow:!0,style:null,color:null,transparent:null,group:null,items:null,selected:null,overlay:{},onClick:null,onRefresh:null},add:function(n){this.insert(null,n)},insert:function(i,r){var u,f,e;for(n.isArray(r)||(r=[r]),u=0;u<r.length;u++){if(r[u].type==null){console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.');return}if(n.inArray(String(r[u].type),["button","check","radio","drop","menu","menu-radio","menu-check","color","text-color","break","html","spacer"])==-1){console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] in w2toolbar.add() method.');return}if(r[u].id==null&&r[u].type!="break"&&r[u].type!="spacer"){console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.');return}if(!w2utils.checkUniqueId(r[u].id,this.items,"toolbar items",this.name))return;f=n.extend({},t.prototype.item,r[u]);i==null?this.items.push(f):(e=this.get(i,!0),this.items=this.items.slice(0,e).concat([f],this.items.slice(e)));this.refresh(f.id);this.resize()}},remove:function(){for(var i,r,u=0,t=0;t<arguments.length;t++)(i=this.get(arguments[t]),i&&String(arguments[t]).indexOf(":")==-1)&&(u++,n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(i.id)).remove(),r=this.get(i.id,!0),r!=null&&this.items.splice(r,1));return this.resize(),u},set:function(t,i){var r=this.get(t);return r==null?!1:(n.extend(r,i),this.refresh(String(t).split(":")[0]),!0)},get:function(n,t){var s,u,r,f,i,e,o;if(arguments.length===0){for(s=[],u=0;u<this.items.length;u++)this.items[u].id!=null&&s.push(this.items[u].id);return s}for(r=String(n).split(":"),f=0;f<this.items.length;f++)if(i=this.items[f],["menu","menu-radio","menu-check"].indexOf(i.type)!=-1&&r.length==2&&i.id==r[0]){for(e=0;e<i.items.length;e++)if(o=i.items[e],o.id==r[1]||o.id==null&&o.text==r[1])return t==!0?e:o}else if(i.id==r[0])return t==!0?f:i;return null},show:function(){for(var i,r=this,u=0,t=[],n=0;n<arguments.length;n++)(i=this.get(arguments[n]),i)&&(u++,i.hidden=!1,t.push(String(arguments[n]).split(":")[0]));return setTimeout(function(){for(var n=0;n<t.length;n++)r.refresh(t[n]);r.resize()},15),u},hide:function(){for(var r,i=this,u=0,n=[],t=0;t<arguments.length;t++)(r=this.get(arguments[t]),r)&&(u++,r.hidden=!0,n.push(String(arguments[t]).split(":")[0]));return setTimeout(function(){for(var t=0;t<n.length;t++)i.refresh(n[t]),i.tooltipHide(n[t]);i.resize()},15),u},enable:function(){for(var i,u=this,r=0,t=[],n=0;n<arguments.length;n++)(i=this.get(arguments[n]),i)&&(r++,i.disabled=!1,t.push(String(arguments[n]).split(":")[0]));return setTimeout(function(){for(var n=0;n<t.length;n++)u.refresh(t[n])},15),r},disable:function(){for(var i,r=this,u=0,n=[],t=0;t<arguments.length;t++)(i=this.get(arguments[t]),i)&&(u++,i.disabled=!0,n.push(String(arguments[t]).split(":")[0]));return setTimeout(function(){for(var t=0;t<n.length;t++)r.refresh(n[t]),r.tooltipHide(n[t])},15),u},check:function(){for(var i,u=this,r=0,t=[],n=0;n<arguments.length;n++)(i=this.get(arguments[n]),i&&String(arguments[n]).indexOf(":")==-1)&&(r++,i.checked=!0,t.push(String(arguments[n]).split(":")[0]));return setTimeout(function(){for(var n=0;n<t.length;n++)u.refresh(t[n])},15),r},uncheck:function(){for(var t,r=this,f=0,u=[],i=0;i<arguments.length;i++)(t=this.get(arguments[i]),t&&String(arguments[i]).indexOf(":")==-1)&&(["menu","menu-radio","menu-check","drop","color","text-color"].indexOf(t.type)!=-1&&t.checked&&setTimeout(function(){var i=n("#tb_"+r.name+"_item_"+w2utils.escapeId(t.id));i.w2overlay({name:r.name})},1),f++,t.checked=!1,u.push(String(arguments[i]).split(":")[0]));return setTimeout(function(){for(var n=0;n<u.length;n++)r.refresh(u[n])},15),f},click:function(t,i){var u=this,v=String(t).split(":"),r=this.get(v[0]),c,a,e,l,f,o,s,h;if(v.length>1){c=this.get(t);c&&!c.disabled&&u.menuClick({name:u.name,item:r,subItem:c,originalEvent:i});return}if(r&&!r.disabled){if(a=this.trigger({phase:"before",type:"click",target:t!=null?t:this.name,item:r,object:r,originalEvent:i}),a.isCancelled===!0)return;if(e="#tb_"+this.name+"_item_"+w2utils.escapeId(r.id)+" table.w2ui-button",n(e).removeClass("down"),r.type=="radio"){for(l=0;l<this.items.length;l++)(f=this.items[l],f!=null&&f.id!=r.id&&f.type==="radio")&&f.group==r.group&&f.checked&&(f.checked=!1,this.refresh(f.id));r.checked=!0;n(e).addClass("checked")}if(["menu","menu-radio","menu-check","drop","color","text-color"].indexOf(r.type)!=-1&&(u.tooltipHide(t),r.checked?setTimeout(function(){var t=n("#tb_"+u.name+"_item_"+w2utils.escapeId(r.id));t.w2overlay({name:u.name});r.checked=!1;u.refresh(r.id)},1):setTimeout(function(){function s(){r.checked=!1;n(e).removeClass("checked")}var f=n("#tb_"+u.name+"_item_"+w2utils.escapeId(r.id)),t,o;n.isPlainObject(r.overlay)||(r.overlay={});t=(f.width()-50)/2;t>19&&(t=19);r.type=="drop"&&f.w2overlay(r.html,n.extend({name:u.name,left:t,top:3},r.overlay,{onHide:function(){s()}}));["menu","menu-radio","menu-check"].indexOf(r.type)!=-1&&(o="normal",r.type=="menu-radio"&&(o="radio",r.items.forEach(function(n){n.checked=r.selected==n.id?!0:!1})),r.type=="menu-check"&&(o="check",r.items.forEach(function(t){t.checked=n.isArray(r.selected)&&r.selected.indexOf(t.id)!=-1?!0:!1})),f.w2menu(n.extend({name:u.name,items:r.items,left:t,top:3},r.overlay,{type:o,select:function(n){u.menuClick({name:u.name,item:r,subItem:n.item,originalEvent:n.originalEvent,keepOpen:n.keepOpen})},onHide:function(){s()}})));["color","text-color"].indexOf(r.type)!=-1&&(r.transparent==null&&(r.transparent=!0),n(f).w2color({color:r.color,transparent:r.transparent},function(n){n!=null&&u.colorClick({name:u.name,item:r,color:n,originalEvent:i.originalEvent});s()}))},1)),["check","menu","menu-radio","menu-check","drop","color","text-color"].indexOf(r.type)!=-1&&(r.checked=!r.checked,r.checked?n(e).addClass("checked"):n(e).removeClass("checked")),r.route){if(o=String("/"+r.route).replace(/\/{2,}/g,"/"),s=w2utils.parseRoute(o),s.keys.length>0)for(h=0;h<s.keys.length;h++)o=o.replace(new RegExp(":"+s.keys[h].name,"g"),this.routeData[s.keys[h].name]);setTimeout(function(){window.location.hash=o},1)}i&&["button","check","radio"].indexOf(r.type)!=-1&&this.tooltipShow(t,i,!0);this.trigger(n.extend(a,{phase:"after"}))}},scroll:function(t){var o=n(this.box),s=this,r=o.find(".w2ui-scroll-wrapper"),e=r.scrollLeft(),u,f,i;switch(t){case"left":u=r.outerWidth();f=r.find(":first").outerWidth();i=e-u+50;i<=0&&(i=0);r.animate({scrollLeft:i},300);break;case"right":u=r.outerWidth();f=r.find(":first").outerWidth();i=e+u-50;i>=f-u&&(i=f-u);r.animate({scrollLeft:i},300)}setTimeout(function(){s.resize()},350)},render:function(t){var e=(new Date).getTime(),f=this.trigger({phase:"before",type:"render",target:this.name,box:t}),r,u,i;if(f.isCancelled!==!0&&(t!=null&&(n(this.box).find("> table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),this.box=t),this.box)){for(r='<div class="w2ui-scroll-wrapper" onmousedown="var el=w2ui[\''+this.name+'\']; if (el) el.resize();"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr>',u=0;u<this.items.length;u++)(i=this.items[u],i!=null)&&(i.id==null&&(i.id="item_"+u),r+=i.type=="spacer"?'<td width="100%" id="tb_'+this.name+"_item_"+i.id+'" align="right"><\/td>':'<td id="tb_'+this.name+"_item_"+i.id+'" style="'+(i.hidden?"display: none":"")+'"     class="'+(i.disabled?"disabled":"")+'" valign="middle"><\/td>');return r+='<td width="100%" id="tb_'+this.name+'_right" align="right">'+this.right+"<\/td>",r+='<\/tr><\/tbody><\/table><\/div><div class="w2ui-scroll-left" onclick="var el=w2ui[\''+this.name+"']; if (el) el.scroll('left');\"><\/div><div class=\"w2ui-scroll-right\" onclick=\"var el=w2ui['"+this.name+"']; if (el) el.scroll('right');\"><\/div>",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-toolbar").html(r),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),this.refresh(),this.resize(),this.trigger(n.extend(f,{phase:"after"})),(new Date).getTime()-e}},refresh:function(t){var h=(new Date).getTime(),s=this.trigger({phase:"before",type:"refresh",target:t!=null?t:this.name,item:this.get(t)}),f,e,i,o,r,u;if(s.isCancelled!==!0){if(t==null){for(f=0;f<this.items.length;f++)e=this.items[f],e.id==null&&(e.id="item_"+f),this.refresh(e.id);return}return(i=this.get(t),i==null)?!1:typeof i.onRefresh=="function"&&(o=this.trigger({phase:"before",type:"refresh",target:t,item:i,object:i}),o.isCancelled===!0)?void 0:(r=n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(i.id)),u=this.getItemHTML(i),r.length===0?(u=i.type=="spacer"?'<td width="100%" id="tb_'+this.name+"_item_"+i.id+'" align="right"><\/td>':'<td id="tb_'+this.name+"_item_"+i.id+'" style="'+(i.hidden?"display: none":"")+'"     class="'+(i.disabled?"disabled":"")+'" valign="middle">'+u+"<\/td>",this.get(t,!0)==this.items.length-1?n(this.box).find("#tb_"+this.name+"_right").before(u):n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(this.items[parseInt(this.get(t,!0))+1].id)).before(u)):(["menu","menu-radio","menu-check","drop","color","text-color"].indexOf(i.type)!=-1&&i.checked==!1&&n("#w2ui-overlay-"+this.name).length>0&&n("#w2ui-overlay-"+this.name)[0].hide(),r.html(u),i.hidden?r.css("display","none"):r.css("display",""),i.disabled?r.addClass("disabled"):r.removeClass("disabled")),typeof i.onRefresh=="function"&&this.trigger(n.extend(o,{phase:"after"})),this.trigger(n.extend(s,{phase:"after"})),(new Date).getTime()-h)}},resize:function(){var u=(new Date).getTime(),r=this.trigger({phase:"before",type:"resize",target:this.name}),i,t;if(r.isCancelled!==!0)return i=n(this.box),i.find(".w2ui-scroll-left, .w2ui-scroll-right").hide(),t=i.find(".w2ui-scroll-wrapper"),t.find(":first").outerWidth()>t.outerWidth()&&(t.scrollLeft()>0&&i.find(".w2ui-scroll-left").show(),t.scrollLeft()<t.find(":first").outerWidth()-t.outerWidth()&&i.find(".w2ui-scroll-right").show()),this.trigger(n.extend(r,{phase:"after"})),(new Date).getTime()-u},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});t.isCancelled!==!0&&(n(this.box).find("> table #tb_"+this.name+"_right").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),n(this.box).html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})))},getItemHTML:function(n){var i="",r,t;if(n.caption!=null&&n.text==null&&(n.text=n.caption),n.text==null&&(n.text=""),n.tooltip==null&&n.hint!=null&&(n.tooltip=n.hint),n.tooltip==null&&(n.tooltip=""),r="<td>&#160;<\/td>",t=n.text,typeof t=="function"&&(t=t.call(this,n)),n.img&&(r='<td><div class="w2ui-tb-image w2ui-icon '+n.img+'"><\/div><\/td>'),n.icon&&(r='<td><div class="w2ui-tb-image"><span class="'+n.icon+'"><\/span><\/div><\/td>'),i==="")switch(n.type){case"color":case"text-color":typeof n.color=="string"&&n.color.substr(0,1)=="#"&&(n.color=n.color.substr(1));n.type=="color"&&(t='<div style="height: 12px; width: 12px; margin-top: 1px; border: 1px solid #8A8A8A; border-radius: 1px; box-shadow: 0px 0px 1px #fff;         background-color: #'+(n.color!=null?n.color:"fff")+'; float: left;"><\/div>'+(n.text?'<div style="margin-left: 17px;">'+w2utils.lang(n.text)+"<\/div>":""));n.type=="text-color"&&(t='<div style="color: #'+(n.color!=null?n.color:"444")+';">'+(n.text?w2utils.lang(n.text):"<b>Aa<\/b>")+"<\/div>");case"menu":case"menu-check":case"menu-radio":case"button":case"check":case"radio":case"drop":i+='<table cellpadding="0" cellspacing="0"        class="w2ui-button '+(n.checked?"checked":"")+'"        onclick     = "var el=w2ui[\''+this.name+"']; if (el) el.click('"+n.id+'\', event);"        onmouseover = "'+(n.disabled?"":"jQuery(this).addClass('over'); w2ui['"+this.name+"'].tooltipShow('"+n.id+"', event);")+'"       onmouseout  = "'+(n.disabled?"":"jQuery(this).removeClass('over').removeClass('down'); w2ui['"+this.name+"'].tooltipHide('"+n.id+"', event);")+'"       onmousedown = "'+(n.disabled?"":"jQuery(this).addClass('down');")+'"       onmouseup   = "'+(n.disabled?"":"jQuery(this).removeClass('down');")+'"><tbody><tr><td>  <table cellpadding="1" cellspacing="0"><tbody>  <tr>'+r+(t!==""?'<td class="w2ui-tb-caption" nowrap="nowrap" style="'+(n.style?n.style:"")+'">'+w2utils.lang(t)+"<\/td>":"")+(n.count!=null?'<td class="w2ui-tb-count" nowrap="nowrap"><span>'+n.count+"<\/span><\/td>":"")+(["menu","menu-radio","menu-check","drop","color","text-color"].indexOf(n.type)!=-1&&n.arrow!==!1?'<td class="w2ui-tb-down" nowrap="nowrap"><div><\/div><\/td>':"")+"  <\/tr><\/tbody><\/table><\/td><\/tr><\/tbody><\/table>";break;case"break":i+='<table cellpadding="0" cellspacing="0"><tbody><tr>    <td><div class="w2ui-break">&#160;<\/div><\/td><\/tr><\/tbody><\/table>';break;case"html":i+='<table cellpadding="0" cellspacing="0"><tbody><tr>    <td nowrap="nowrap">'+(typeof n.html=="function"?n.html.call(this,n):n.html)+"<\/td><\/tr><\/tbody><\/table>"}return"<div>"+i+"<\/div>"},tooltipShow:function(t,i,r){if(this.tooltip!=null){var u=n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(t)),e=this.get(t),o=this.tooltip,f=e.tooltip;typeof f=="function"&&(f=f.call(this,e));u.prop("_mouse_over",!0);setTimeout(function(){if(u.prop("_mouse_over")===!0&&u.prop("_mouse_tooltip")!==!0){if(u.prop("_mouse_tooltip",!0),["menu","menu-radio","menu-check","drop","color","text-color"].indexOf(e.type)!=-1&&e.checked==!0)return;u.w2tag(w2utils.lang(f),{position:o})}r==!0&&u.w2tag(w2utils.lang(f),{position:o})},1)}},tooltipHide:function(t){if(this.tooltip!=null){var i=n(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(t)),r=this.get(t);i.removeProp("_mouse_over");setTimeout(function(){i.prop("_mouse_over")!==!0&&i.prop("_mouse_tooltip")===!0&&(i.removeProp("_mouse_tooltip"),i.w2tag())},1)}},menuClick:function(t){var h=this,o,i,r,s,e,u,f;if(t.item&&!t.item.disabled){if(o=this.trigger({phase:"before",type:"click",target:t.item.id+":"+t.subItem.id,item:t.item,subItem:t.subItem,originalEvent:t.originalEvent}),o.isCancelled===!0)return;if(i=t.subItem,r=this.get(t.item.id),r.type=="menu-radio"&&(r.selected=i.id,t.item.items.forEach(function(n){n.checked=!1}),i.checked=!0),r.type=="menu-check"&&(n.isArray(r.selected)||(r.selected=[]),s=r.selected.indexOf(i.id),s==-1?(r.selected.push(i.id),i.checked=!0):(r.selected.splice(s,1),i.checked=!1)),typeof i.route=="string"){if(e=i.route!==""?String("/"+i.route).replace(/\/{2,}/g,"/"):"",u=w2utils.parseRoute(e),u.keys.length>0)for(f=0;f<u.keys.length;f++)h.routeData[u.keys[f].name]!=null&&(e=e.replace(new RegExp(":"+u.keys[f].name,"g"),this.routeData[u.keys[f].name]));setTimeout(function(){window.location.hash=e},1)}this.refresh(t.item.id);this.trigger(n.extend(o,{phase:"after"}))}},colorClick:function(t){var r=this,i;if(t.item&&!t.item.disabled){if(i=this.trigger({phase:"before",type:"click",target:t.item.id,item:t.item,color:t.color,originalEvent:t.originalEvent}),i.isCancelled===!0)return;t.item.color=t.color;r.refresh(t.item.id);this.trigger(n.extend(i,{phase:"after"}))}}};n.extend(t.prototype,w2utils.event);w2obj.toolbar=t}(jQuery),function(n){var t=function(t){this.name=null;this.box=null;this.sidebar=null;this.parent=null;this.nodes=[];this.menu=[];this.routeData={};this.selected=null;this.img=null;this.icon=null;this.style="";this.topHTML="";this.bottomHTML="";this.flatButton=!1;this.keyboard=!0;this.flat=!1;this.hasFocus=!1;n.extend(!0,this,w2obj.sidebar,t)};n.fn.w2sidebar=function(i){var f,r,u;return n.isPlainObject(i)?w2utils.checkName(i,"w2sidebar")?(f=i.nodes,r=new t(i),n.extend(r,{handlers:[],nodes:[]}),f!=null&&r.add(r,f),n(this).length!==0&&r.render(n(this)[0]),r.sidebar=r,w2ui[r.name]=r,r):void 0:(u=w2ui[n(this).attr("name")],!u)?null:arguments.length>0?(u[i]&&u[i].apply(u,Array.prototype.slice.call(arguments,1)),this):u};t.prototype={onClick:null,onDblClick:null,onContextMenu:null,onMenuClick:null,onExpand:null,onCollapse:null,onKeydown:null,onRender:null,onRefresh:null,onResize:null,onDestroy:null,onFocus:null,onBlur:null,onFlat:null,node:{id:null,text:"",count:null,img:null,icon:null,nodes:[],style:"",route:null,selected:!1,expanded:!1,hidden:!1,disabled:!1,group:!1,groupShowHide:!0,collapsible:!0,plus:!1,onClick:null,onDblClick:null,onContextMenu:null,onExpand:null,onCollapse:null,parent:null,sidebar:null},add:function(n,t){return arguments.length==1&&(t=arguments[0],n=this),typeof n=="string"&&(n=this.get(n)),this.insert(n,null,t)},insert:function(i,r,u){var o,s,e,f,c,h;if(arguments.length==2)if(u=arguments[1],r=arguments[0],r!=null){if(s=this.get(r),s==null)return n.isArray(u)||(u=[u]),o=u[0].caption!=null?u[0].caption:u[0].text,console.log('ERROR: Cannot insert node "'+o+'" because cannot find node "'+r+'" to insert before.'),null;i=this.get(r).parent}else i=this;for(typeof i=="string"&&(i=this.get(i)),n.isArray(u)||(u=[u]),h=0;h<u.length;h++){if(f=u[h],typeof f.id==null){o=f.caption!=null?f.caption:f.text;console.log('ERROR: Cannot insert node "'+o+'" because it has no id.');continue}if(this.get(this,f.id)!=null){o=f.caption!=null?f.caption:f.text;console.log("ERROR: Cannot insert node with id="+f.id+" (text: "+o+") because another node with the same id already exists.");continue}if(e=n.extend({},t.prototype.node,f),e.sidebar=this,e.parent=i,c=e.nodes||[],e.nodes=[],r==null)i.nodes.push(e);else{if(s=this.get(i,r,!0),s==null)return o=f.caption!=null?f.caption:f.text,console.log('ERROR: Cannot insert node "'+o+'" because cannot find node "'+r+'" to insert before.'),null;i.nodes.splice(s,0,e)}c.length>0&&this.insert(e,null,c)}return this.refresh(i.id),e},remove:function(){for(var i,r=0,n,t=0;t<arguments.length;t++)(n=this.get(arguments[t]),n!=null)&&(this.selected!=null&&this.selected===n.id&&(this.selected=null),i=this.get(n.parent,arguments[t],!0),i!=null)&&(n.parent.nodes[i].selected&&n.sidebar.unselect(n.id),n.parent.nodes.splice(i,1),r++);return r>0&&arguments.length==1?this.refresh(n.parent.id):this.refresh(),r},set:function(t,i,r){var u,f,e;if(arguments.length==2&&(r=i,i=t,t=this),typeof t=="string"&&(t=this.get(t)),t.nodes==null)return null;for(u=0;u<t.nodes.length;u++){if(t.nodes[u].id===i)return f=r.nodes,n.extend(t.nodes[u],r,{nodes:[]}),f!=null&&this.add(t.nodes[u],f),this.refresh(i),!0;if(e=this.set(t.nodes[u],i,r),e)return!0}return!1},get:function(n,t,i){var o,f,u,r,e;if(arguments.length===0){for(o=[],f=this.find({}),u=0;u<f.length;u++)f[u].id!=null&&o.push(f[u].id);return o}if((arguments.length==1||arguments.length==2&&t===!0)&&(i=t,t=n,n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return null;for(r=0;r<n.nodes.length;r++){if(n.nodes[r].id==t)return i===!0?r:n.nodes[r];if(e=this.get(n.nodes[r],t,i),e||e===0)return e}return null},find:function(n,t,i){var r,u,f;if(arguments.length==1&&(t=n,n=this),i||(i=[]),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return i;for(r=0;r<n.nodes.length;r++){u=!0;for(f in t)n.nodes[r][f]!=t[f]&&(u=!1);u&&i.push(n.nodes[r]);n.nodes[r].nodes.length>0&&(i=this.find(n.nodes[r],t,i))}return i},hide:function(){for(var t,i=0,n=0;n<arguments.length;n++)(t=this.get(arguments[n]),t!=null)&&(t.hidden=!0,i++);return arguments.length==1?this.refresh(arguments[0]):this.refresh(),i},show:function(){for(var t,i=0,n=0;n<arguments.length;n++)(t=this.get(arguments[n]),t!=null)&&(t.hidden=!1,i++);return arguments.length==1?this.refresh(arguments[0]):this.refresh(),i},disable:function(){for(var n,i=0,t=0;t<arguments.length;t++)(n=this.get(arguments[t]),n!=null)&&(n.disabled=!0,n.selected&&this.unselect(n.id),i++);return arguments.length==1?this.refresh(arguments[0]):this.refresh(),i},enable:function(){for(var t,i=0,n=0;n<arguments.length;n++)(t=this.get(arguments[n]),t!=null)&&(t.disabled=!1,i++);return arguments.length==1?this.refresh(arguments[0]):this.refresh(),i},select:function(t){var i=this.get(t);return i?this.selected==t&&i.selected?!1:(this.unselect(this.selected),n(this.box).find("#node_"+w2utils.escapeId(t)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),i.selected=!0,this.selected=t,!0):!1},unselect:function(t){arguments.length===0&&(t=this.selected);var i=this.get(t);return i?(i.selected=!1,n(this.box).find("#node_"+w2utils.escapeId(t)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),this.selected==t&&(this.selected=null),!0):!1},toggle:function(n){var t=this.get(n);if(t==null)return!1;if(t.plus){this.set(n,{plus:!1});this.expand(n);this.refresh(n);return}return t.nodes.length===0?!1:t.collapsible?this.get(n).expanded?this.collapse(n):this.expand(n):!1},collapse:function(t){var u=this,i=this.get(t),r=this.trigger({phase:"before",type:"collapse",target:t,object:i});if(r.isCancelled!==!0)return n(this.box).find("#node_"+w2utils.escapeId(t)+"_sub").slideUp(200),n(this.box).find("#node_"+w2utils.escapeId(t)+" .w2ui-node-dots:first-child").html('<div class="w2ui-expand">+<\/div>'),i.expanded=!1,this.trigger(n.extend(r,{phase:"after"})),setTimeout(function(){u.refresh(t)},200),!0},collapseAll:function(n){if(n==null&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return!1;for(var t=0;t<n.nodes.length;t++)n.nodes[t].expanded===!0&&(n.nodes[t].expanded=!1),n.nodes[t].nodes&&n.nodes[t].nodes.length>0&&this.collapseAll(n.nodes[t]);return this.refresh(n.id),!0},expand:function(t){var u=this,i=this.get(t),r=this.trigger({phase:"before",type:"expand",target:t,object:i});if(r.isCancelled!==!0)return n(this.box).find("#node_"+w2utils.escapeId(t)+"_sub").slideDown(200),n(this.box).find("#node_"+w2utils.escapeId(t)+" .w2ui-node-dots:first-child").html('<div class="w2ui-expand">-<\/div>'),i.expanded=!0,this.trigger(n.extend(r,{phase:"after"})),setTimeout(function(){u.refresh(t)},200),!0},expandAll:function(n){if(n==null&&(n=this),typeof n=="string"&&(n=this.get(n)),n.nodes==null)return!1;for(var t=0;t<n.nodes.length;t++)n.nodes[t].expanded===!1&&(n.nodes[t].expanded=!0),n.nodes[t].nodes&&n.nodes[t].nodes.length>0&&this.expandAll(n.nodes[t]);this.refresh(n.id)},expandParents:function(n){var t=this.get(n);return t==null?!1:(t.parent&&(t.parent.expanded||(t.parent.expanded=!0,this.refresh(t.parent.id)),this.expandParents(t.parent.id)),!0)},click:function(t,i){var r=this,u=this.get(t),e,f;u!=null&&(u.disabled||u.group||(n(r.box).find(".w2ui-node.w2ui-selected").each(function(t,i){var f=n(i).attr("id").replace("node_",""),u=r.get(f);u!=null&&(u.selected=!1);n(i).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected")}),e=n(r.box).find("#node_"+w2utils.escapeId(t)),f=n(r.box).find("#node_"+w2utils.escapeId(r.selected)),e.addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),setTimeout(function(){var c=r.trigger({phase:"before",type:"click",target:t,originalEvent:i,node:u,object:u}),h,o,s;if(c.isCancelled===!0){e.removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected");f.addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected");return}if(f!=null&&(f.selected=!1),r.get(t).selected=!0,r.selected=t,typeof u.route=="string"){if(h=u.route!==""?String("/"+u.route).replace(/\/{2,}/g,"/"):"",o=w2utils.parseRoute(h),o.keys.length>0)for(s=0;s<o.keys.length;s++)r.routeData[o.keys[s].name]!=null&&(h=h.replace(new RegExp(":"+o.keys[s].name,"g"),r.routeData[o.keys[s].name]));setTimeout(function(){window.location.hash=h},1)}r.trigger(n.extend(c,{phase:"after"}))},1)))},focus:function(t){var i=this,r=this.trigger({phase:"before",type:"focus",target:this.name,originalEvent:t});if(r.isCancelled===!0)return!1;this.hasFocus=!0;n(this.box).find(".w2ui-selected").removeClass("w2ui-inactive");setTimeout(function(){var t=n(i.box).find("#sidebar_"+i.name+"_focus");t.is(":focus")||t.focus()},10);this.trigger(n.extend(r,{phase:"after"}))},blur:function(t){var i=this.trigger({phase:"before",type:"blur",target:this.name,originalEvent:t});if(i.isCancelled===!0)return!1;this.hasFocus=!1;n(this.box).find(".w2ui-selected").addClass("w2ui-inactive");this.trigger(n.extend(i,{phase:"after"}))},keydown:function(t){function e(n,t){n==null||n.hidden||n.disabled||n.group||(i.click(n.id,t),setTimeout(function(){i.scrollIntoView()},50))}function s(n,t){for(n=t(n);n!=null&&(n.hidden||n.disabled);)if(n.group)break;else n=t(n);return n}function u(n,t){var f;if(n==null)return null;var e=n.parent,o=i.get(n.id,!0),r=null;return n.expanded&&n.nodes.length>0&&t!==!0?(f=n.nodes[0],r=f.hidden||f.disabled||f.group?u(f):f):r=e&&o+1<e.nodes.length?e.nodes[o+1]:u(e,!0),r!=null&&(r.hidden||r.disabled||r.group)&&(r=u(r)),r}function o(n){if(n==null)return null;var r=n.parent,u=i.get(n.id,!0),t=u>0?h(r.nodes[u-1]):r;return t!=null&&(t.hidden||t.disabled||t.group)&&(t=o(t)),t}function h(n){if(n.expanded&&n.nodes.length>0){var t=n.nodes[n.nodes.length-1];return t.hidden||t.disabled||t.group?o(t):h(t)}return n}var i=this,r=i.get(i.selected),f;i.keyboard===!0&&(r||(r=i.nodes[0]),f=i.trigger({phase:"before",type:"keydown",target:i.name,originalEvent:t}),f.isCancelled!==!0)&&((t.keyCode==13||t.keyCode==32)&&r.nodes.length>0&&i.toggle(i.selected),t.keyCode==37&&(r.nodes.length>0&&r.expanded?i.collapse(i.selected):(e(r.parent),r.parent.group||i.collapse(r.parent.id))),t.keyCode==39&&(r.nodes.length>0||r.plus)&&!r.expanded&&i.expand(i.selected),t.keyCode==38&&e(s(r,o)),t.keyCode==40&&e(s(r,u)),n.inArray(t.keyCode,[13,32,37,38,39,40])!=-1&&(t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation()),i.trigger(n.extend(f,{phase:"after"})))},scrollIntoView:function(t){var f;if(t==null&&(t=this.selected),f=this.get(t),f!=null){var i=n(this.box).find(".w2ui-sidebar-div"),r=n(this.box).find("#node_"+w2utils.escapeId(t)),u=r.offset().top-i.offset().top;(u+r.height()>i.height()||u<=0)&&i.animate({scrollTop:i.scrollTop()+u-i.height()/2+r.height()},250,"linear")}},dblClick:function(t,i){var u=this.get(t),r=this.trigger({phase:"before",type:"dblClick",target:t,originalEvent:i,object:u});r.isCancelled!==!0&&(this.toggle(t),this.trigger(n.extend(r,{phase:"after"})))},contextMenu:function(t,i){var r=this,f=r.get(t),u;(t!=r.selected&&r.click(t),u=r.trigger({phase:"before",type:"contextMenu",target:t,originalEvent:i,object:f,allowOnDisabled:!1}),u.isCancelled!==!0)&&(!f.disabled||u.allowOnDisabled)&&(r.menu.length>0&&n(r.box).find("#node_"+w2utils.escapeId(t)).w2menu({items:r.menu,contextMenu:!0,originalEvent:i,onSelect:function(n){r.menuClick(t,parseInt(n.index),n.originalEvent)}}),i.preventDefault&&i.preventDefault(),r.trigger(n.extend(u,{phase:"after"})))},menuClick:function(t,i,r){var u=this,f=u.trigger({phase:"before",type:"menuClick",target:t,originalEvent:r,menuIndex:i,menuItem:u.menu[i]});f.isCancelled!==!0&&u.trigger(n.extend(f,{phase:"after"}))},goFlat:function(){var t=this.trigger({phase:"before",type:"flat",goFlat:!this.flat});t.isCancelled!==!0&&(this.flat=!this.flat,this.refresh(),this.trigger(n.extend(t,{phase:"after"})))},render:function(t){var e=(new Date).getTime(),i=this,u=this.trigger({phase:"before",type:"render",target:this.name,box:t}),r,f;if(u.isCancelled!==!0&&(t!=null&&(n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),this.box=t),this.box)){n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-sidebar").html('<div><input id="sidebar_'+this.name+'_focus" style="position: absolute; top: 0; right: 0; width: 1px; z-index: -1; opacity: 0"/><div class="w2ui-sidebar-top"><\/div><div class="w2ui-sidebar-div"><\/div><div class="w2ui-sidebar-bottom"><\/div><\/div>');n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"});n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style);r="";this.flatButton==!0&&(r='<div class="w2ui-flat-'+(this.flat?"right":"left")+'" onclick="w2ui[\''+this.name+"'].goFlat()\"><\/div>");(this.topHTML!==""||r!=="")&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML+r),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px"));this.bottomHTML!==""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px"));n(this.box).find("#sidebar_"+this.name+"_focus").on("focus",function(n){clearTimeout(f);i.hasFocus||i.focus(n)}).on("blur",function(n){f=setTimeout(function(){i.hasFocus&&i.blur(n)},100)}).on("keydown",function(n){n.keyCode!=9&&w2ui[i.name].keydown.call(w2ui[i.name],n)});n(this.box).off("mousedown").on("mousedown",function(t){setTimeout(function(){var r,u;["INPUT","TEXTAREA","SELECT"].indexOf(t.target.tagName.toUpperCase())==-1&&(r=n(i.box).find("#sidebar_"+i.name+"_focus"),r.is(":focus")||(n(t.target).hasClass("w2ui-node")&&(u=n(t.target).position().top+n(i.box).find(".w2ui-sidebar-top").height()+t.offsetY,r.css({top:u+"px",left:"0px"})),r.focus()))},1)});return this.trigger(n.extend(u,{phase:"after"})),this.refresh(),(new Date).getTime()-e}},refresh:function(t){function a(n){var u="",e=n.img,f,t,r,o;for(e==null&&(e=this.img),f=n.icon,f==null&&(f=this.icon),t=n.parent,r=0;t&&t.parent!=null;)t.group&&r--,t=t.parent,r++;return n.caption!=null&&(n.text=n.caption),n.group?(u='<div class="w2ui-node-group w2ui-level-'+r+'" id="node_'+n.id+'"   onclick="w2ui[\''+i.name+"'].toggle('"+n.id+"')\"   oncontextmenu=\"w2ui['"+i.name+"'].contextMenu('"+n.id+"', event);\"   onmouseout=\"jQuery(this).find('span:nth-child(1)').css('color', 'transparent')\"    onmouseover=\"jQuery(this).find('span:nth-child(1)').css('color', 'inherit')\">"+(n.groupShowHide&&n.collapsible?"<span>"+(!n.hidden&&n.expanded?w2utils.lang("Hide"):w2utils.lang("Show"))+"<\/span>":"<span><\/span>")+(typeof n.text=="function"?n.text.call(i,n):"<span>"+n.text+"<\/span>")+'<\/div><div class="w2ui-node-sub" id="node_'+n.id+'_sub" style="'+n.style+";"+(!n.hidden&&n.expanded?"":"display: none;")+'"><\/div>',i.flat&&(u='<div class="w2ui-node-group" id="node_'+n.id+'"><span>&#160;<\/span><\/div><div id="node_'+n.id+'_sub" style="'+n.style+";"+(!n.hidden&&n.expanded?"":"display: none;")+'"><\/div>')):(n.selected&&!n.disabled&&(i.selected=n.id),t="",e&&(t='<div class="w2ui-node-image w2ui-icon '+e+(n.selected&&!n.disabled?" w2ui-icon-selected":"")+'"><\/div>'),f&&(t='<div class="w2ui-node-image"><span class="'+f+'"><\/span><\/div>'),o=n.text,typeof n.text=="function"&&(o=n.text.call(i,n)),u='<div class="w2ui-node w2ui-level-'+r+" "+(n.selected?"w2ui-selected":"")+" "+(n.disabled?"w2ui-disabled":"")+'" id="node_'+n.id+'" style="'+(n.hidden?"display: none;":"")+'"    ondblclick="w2ui[\''+i.name+"'].dblClick('"+n.id+"', event);\"    oncontextmenu=\"w2ui['"+i.name+"'].contextMenu('"+n.id+"', event);\"    onClick=\"w2ui['"+i.name+"'].click('"+n.id+'\', event); "><table cellpadding="0" cellspacing="0" style="margin-left:'+r*18+"px; padding-right:"+r*18+'px"><tbody><tr><td class="w2ui-node-dots" nowrap="nowrap" onclick="w2ui[\''+i.name+"'].toggle('"+n.id+'\');         if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">    <div class="w2ui-expand">'+(n.nodes.length>0?n.expanded?"-":"+":n.plus?"+":"")+'<\/div><\/td><td class="w2ui-node-data" nowrap="nowrap">'+t+(n.count||n.count===0?'<div class="w2ui-node-count">'+n.count+"<\/div>":"")+'<div class="w2ui-node-caption">'+o+'<\/div><\/td><\/tr><\/tbody><\/table><\/div><div class="w2ui-node-sub" id="node_'+n.id+'_sub" style="'+n.style+";"+(!n.hidden&&n.expanded?"":"display: none;")+'"><\/div>',i.flat&&(u='<div class="w2ui-node w2ui-level-'+r+" "+(n.selected?"w2ui-selected":"")+" "+(n.disabled?"w2ui-disabled":"")+'" id="node_'+n.id+'" style="'+(n.hidden?"display: none;":"")+"\"    onmouseover=\"jQuery(this).find('.w2ui-node-data').w2tag(w2utils.base64decode('"+w2utils.base64encode(o+(n.count||n.count===0?' - <span class="w2ui-node-count">'+n.count+"<\/span>":""))+"'),                { id: '"+n.id+"', position: 'left' })\"    onmouseout=\"jQuery(this).find('.w2ui-node-data').w2tag(null, { id: '"+n.id+"' })\"    ondblclick=\"w2ui['"+i.name+"'].dblClick('"+n.id+"', event);\"    oncontextmenu=\"w2ui['"+i.name+"'].contextMenu('"+n.id+"', event);\"    onClick=\"w2ui['"+i.name+"'].click('"+n.id+'\', event); "><div class="w2ui-node-data w2ui-node-flat">'+t+'<\/div><\/div><div class="w2ui-node-sub" id="node_'+n.id+'_sub" style="'+n.style+";"+(!n.hidden&&n.expanded?"":"display: none;")+'"><\/div>')),u}var v=(new Date).getTime(),l=this.trigger({phase:"before",type:"refresh",target:t!=null?t:this.name,fullRefresh:t!=null?!1:!0}),e,i,r,u,f,o,h,s,c;if(l.isCancelled!==!0){if(e="",this.flatButton==!0&&(e='<div class="w2ui-flat-'+(this.flat?"right":"left")+'" onclick="w2ui[\''+this.name+"'].goFlat()\"><\/div>"),(this.topHTML!==""||e!=="")&&(n(this.box).find(".w2ui-sidebar-top").html(this.topHTML+e),n(this.box).find(".w2ui-sidebar-div").css("top",n(this.box).find(".w2ui-sidebar-top").height()+"px")),this.bottomHTML!==""&&(n(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),n(this.box).find(".w2ui-sidebar-div").css("bottom",n(this.box).find(".w2ui-sidebar-bottom").height()+"px")),n(this.box).find("> div").removeClass("w2ui-sidebar-flat").addClass(this.flat?"w2ui-sidebar-flat":"").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),i=this,t==null)r=this,f=".w2ui-sidebar-div";else{if(r=this.get(t),r==null)return;f="#node_"+w2utils.escapeId(r.id)+"_sub"}for(r!==this&&(h="#node_"+w2utils.escapeId(r.id),o=a(r),n(this.box).find(h).before('<div id="sidebar_'+this.name+'_tmp"><\/div>'),n(this.box).find(h).remove(),n(this.box).find(f).remove(),n("#sidebar_"+this.name+"_tmp").before(o),n("#sidebar_"+this.name+"_tmp").remove()),n(this.box).find(f).html(""),s=0;s<r.nodes.length;s++)if(u=r.nodes[s],o=a(u),n(this.box).find(f).append(o),u.nodes.length!==0)this.refresh(u.id);else{if(c=this.trigger({phase:"before",type:"refresh",target:u.id}),c.isCancelled===!0)return;this.trigger(n.extend(c,{phase:"after"}))}return this.trigger(n.extend(l,{phase:"after"})),(new Date).getTime()-v}},resize:function(){var i=(new Date).getTime(),t=this.trigger({phase:"before",type:"resize",target:this.name});if(t.isCancelled!==!0)return n(this.box).css("overflow","hidden"),n(this.box).find("> div").css({width:n(this.box).width()+"px",height:n(this.box).height()+"px"}),this.trigger(n.extend(t,{phase:"after"})),(new Date).getTime()-i},destroy:function(){var t=this.trigger({phase:"before",type:"destroy",target:this.name});t.isCancelled!==!0&&(n(this.box).find("> div > div.w2ui-sidebar-div").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})))},lock:function(){var n=Array.prototype.slice.call(arguments,0);n.unshift(this.box);w2utils.lock.apply(window,n)},unlock:function(n){w2utils.unlock(this.box,n)}};n.extend(t.prototype,w2utils.event);w2obj.sidebar=t}(jQuery),function(n){var t=function(t){this.el=null;this.helpers={};this.type=t.type||"text";this.options=n.extend(!0,{},t);this.onSearch=t.onSearch||null;this.onRequest=t.onRequest||null;this.onLoad=t.onLoad||null;this.onError=t.onError||null;this.onClick=t.onClick||null;this.onAdd=t.onAdd||null;this.onNew=t.onNew||null;this.onRemove=t.onRemove||null;this.onMouseOver=t.onMouseOver||null;this.onMouseOut=t.onMouseOut||null;this.onIconClick=t.onIconClick||null;this.onScroll=t.onScroll||null;this.tmp={};delete this.options.type;delete this.options.onSearch;delete this.options.onRequest;delete this.options.onLoad;delete this.options.onError;delete this.options.onClick;delete this.options.onMouseOver;delete this.options.onMouseOut;delete this.options.onIconClick;delete this.options.onScroll;n.extend(!0,this,w2obj.field)};n.fn.w2field=function(i,r){var u;if(this.length===0){if(u=t.prototype,u[i])return u[i].apply(u,Array.prototype.slice.call(arguments,1))}else return arguments.length===0?n(this).data("w2field"):(typeof i=="string"&&typeof r=="object"&&(i=n.extend(!0,{},r,{type:i})),typeof i=="string"&&r==null&&(i={type:i}),i.type=String(i.type).toLowerCase(),this.each(function(r,u){var f=n(u).data("w2field");return f==null?(f=new t(i),n.extend(f,{handlers:[]}),u&&(f.el=n(u)[0]),f.init(),n(u).data("w2field",f),f):(f.clear(),i.type=="clear")?void 0:(f=new t(i),n.extend(f,{handlers:[]}),u&&(f.el=n(u)[0]),f.init(),n(u).data("w2field",f),f)}))};t.prototype={custom:{},addType:function(n,t){return n=String(n).toLowerCase(),this.custom[n]=t,!0},removeType:function(n){return(n=String(n).toLowerCase(),!this.custom[n])?!1:(delete this.custom[n],!0)},init:function(){var r=this,t=this.options,i,u,f;if(typeof this.custom[this.type]=="function"){this.custom[this.type].call(this,t);return}if(["INPUT","TEXTAREA"].indexOf(this.el.tagName.toUpperCase())==-1){console.log("ERROR: w2field could only be applied to INPUT or TEXTAREA.",this.el);return}switch(this.type){case"text":case"int":case"float":case"money":case"currency":case"percent":case"alphanumeric":case"bin":case"hex":i={min:null,max:null,step:1,autoFormat:!0,currencyPrefix:w2utils.settings.currencyPrefix,currencySuffix:w2utils.settings.currencySuffix,currencyPrecision:w2utils.settings.currencyPrecision,decimalSymbol:w2utils.settings.decimalSymbol,groupSymbol:w2utils.settings.groupSymbol,arrows:!1,keyboard:!0,precision:null,silent:!0,prefix:"",suffix:""};this.options=n.extend(!0,{},i,t);t=this.options;t.numberRE=new RegExp("["+t.groupSymbol+"]","g");t.moneyRE=new RegExp("["+t.currencyPrefix+t.currencySuffix+t.groupSymbol+"]","g");t.percentRE=new RegExp("["+t.groupSymbol+"%]","g");["text","alphanumeric","hex","bin"].indexOf(this.type)!=-1&&(t.arrows=!1,t.keyboard=!1);this.addPrefix();this.addSuffix();break;case"color":i={prefix:"#",suffix:'<div style="width: '+(parseInt(n(this.el).css("font-size"))||12)+'px">&#160;<\/div>',arrows:!1,keyboard:!1,transparent:!0};n.extend(t,i);this.addPrefix();this.addSuffix();n(this.el).attr("maxlength",6);n(this.el).val()!==""&&setTimeout(function(){r.change()},1);break;case"date":i={format:w2utils.settings.dateFormat,keyboard:!0,silent:!0,start:"",end:"",blocked:{},colored:{},blockWeekDays:null};this.options=n.extend(!0,{},i,t);t=this.options;n(this.el).attr("placeholder")==null&&n(this.el).attr("placeholder",t.format);break;case"time":i={format:w2utils.settings.timeFormat,keyboard:!0,silent:!0,start:"",end:"",noMinutes:!1};this.options=n.extend(!0,{},i,t);t=this.options;n(this.el).attr("placeholder")==null&&n(this.el).attr("placeholder",t.format);break;case"datetime":i={format:w2utils.settings.dateFormat+" | "+w2utils.settings.timeFormat,keyboard:!0,silent:!0,start:"",end:"",blocked:[],colored:{},placeholder:null,btn_now:!0,noMinutes:!1};this.options=n.extend(!0,{},i,t);t=this.options;n(this.el).attr("placeholder")==null&&n(this.el).attr("placeholder",t.placeholder||t.format);break;case"list":case"combo":if(i={items:[],selected:{},url:null,recId:null,recText:null,method:null,interval:350,postData:{},minLength:1,cacheMax:250,maxDropHeight:350,maxDropWidth:null,match:"begins",silent:!0,icon:null,iconStyle:"",onSearch:null,onRequest:null,onLoad:null,onError:null,onIconClick:null,renderDrop:null,compare:null,filter:!0,prefix:"",suffix:"",openOnFocus:!1,markSearch:!1},t.items=this.normMenu(t.items),this.type=="list"){if(i.openOnFocus=!0,n(this.el).addClass("w2ui-select"),!n.isPlainObject(t.selected)&&t.items)for(u=0;u<t.items.length;u++)if(f=t.items[u],f&&f.id==t.selected){t.selected=n.extend(!0,{},f);break}this.watchSize()}t=n.extend({},i,t,{align:"both",altRows:!0});this.options=t;n.isPlainObject(t.selected)||(t.selected={});n(this.el).data("selected",t.selected);t.url&&(t.items=[],this.request(0));this.type=="list"&&this.addFocus();this.addPrefix();this.addSuffix();setTimeout(function(){r.refresh()},10);n(this.el).attr("autocomplete","off");t.selected.text!=null&&n(this.el).val(t.selected.text);break;case"enum":i={items:[],selected:[],max:0,url:null,recId:null,recText:null,interval:350,method:null,postData:{},minLength:1,cacheMax:250,maxWidth:250,maxHeight:350,maxDropHeight:350,maxDropWidth:null,match:"contains",silent:!0,openOnFocus:!1,markSearch:!0,renderDrop:null,renderItem:null,compare:null,filter:!0,style:"",onSearch:null,onRequest:null,onLoad:null,onError:null,onClick:null,onAdd:null,onNew:null,onRemove:null,onMouseOver:null,onMouseOut:null,onScroll:null};t=n.extend({},i,t,{align:"both",suffix:"",altRows:!0});t.items=this.normMenu(t.items);t.selected=this.normMenu(t.selected);this.options=t;n.isArray(t.selected)||(t.selected=[]);n(this.el).data("selected",t.selected);t.url&&(t.items=[],this.request(0));this.addSuffix();this.addMulti();this.watchSize();break;case"file":i={selected:[],max:0,maxSize:0,maxFileSize:0,maxWidth:250,maxHeight:350,maxDropHeight:350,maxDropWidth:null,readContent:!0,silent:!0,renderItem:null,style:"",onClick:null,onAdd:null,onRemove:null,onMouseOver:null,onMouseOut:null};t=n.extend({},i,t,{align:"both",altRows:!0});this.options=t;n.isArray(t.selected)||(t.selected=[]);n(this.el).data("selected",t.selected);n(this.el).attr("placeholder")==null&&n(this.el).attr("placeholder",w2utils.lang("Attach files by dragging and dropping or Click to Select"));this.addMulti();this.watchSize()}this.tmp={onChange:function(n){r.change.call(r,n)},onClick:function(n){r.click.call(r,n)},onFocus:function(n){r.focus.call(r,n)},onBlur:function(n){r.blur.call(r,n)},onKeydown:function(n){r.keyDown.call(r,n)},onKeyup:function(n){r.keyUp.call(r,n)},onKeypress:function(n){r.keyPress.call(r,n)}};n(this.el).addClass("w2field w2ui-input").data("w2field",this).on("change.w2field",this.tmp.onChange).on("click.w2field",this.tmp.onClick).on("focus.w2field",this.tmp.onFocus).on("blur.w2field",this.tmp.onBlur).on("keydown.w2field",this.tmp.onKeydown).on("keyup.w2field",this.tmp.onKeyup).on("keypress.w2field",this.tmp.onKeypress).css(w2utils.cssPrefix("box-sizing","border-box"));this.change(n.Event("change"))},watchSize:function(){var t=this,i=n(t.el).data("tmp")||{};i.sizeTimer=setInterval(function(){n(t.el).parents("body").length>0?t.resize():clearInterval(i.sizeTimer)},200);n(t.el).data("tmp",i)},get:function(){return["list","enum","file"].indexOf(this.type)!=-1?n(this.el).data("selected"):n(this.el).val()},set:function(t,i){if(["list","enum","file"].indexOf(this.type)!=-1){if(this.type!="list"&&i)n(this.el).data("selected")==null&&n(this.el).data("selected",[]),n(this.el).data("selected").push(t),n(this.el).change();else{var r=this.type=="enum"?[t]:t;n(this.el).data("selected",r).change()}this.refresh()}else n(this.el).val(t)},setIndex:function(t,i){var r,u;return["list","enum"].indexOf(this.type)!=-1&&(r=this.options.items,r&&r[t])?(this.type!="list"&&i?(n(this.el).data("selected")==null&&n(this.el).data("selected",[]),n(this.el).data("selected").push(r[t]),n(this.el).change()):(u=this.type=="enum"?[r[t]]:r[t],n(this.el).data("selected",u).change()),this.refresh(),!0):!1},clear:function(){var u=this,r=this.options,t,i;if(["money","currency"].indexOf(this.type)!=-1&&n(this.el).val(n(this.el).val().replace(r.moneyRE,"")),this.type=="percent"&&n(this.el).val(n(this.el).val().replace(/%/g,"")),this.type=="color"&&n(this.el).removeAttr("maxlength"),this.type=="list"&&n(this.el).removeClass("w2ui-select"),this.type="clear",t=n(this.el).data("tmp"),this.tmp){t!=null&&(n(this.el).height("auto"),t&&t["old-padding-left"]&&n(this.el).css("padding-left",t["old-padding-left"]),t&&t["old-padding-right"]&&n(this.el).css("padding-right",t["old-padding-right"]),t&&t["old-background-color"]&&n(this.el).css("background-color",t["old-background-color"]),t&&t["old-border-color"]&&n(this.el).css("border-color",t["old-border-color"]),clearInterval(t.sizeTimer));n(this.el).val(this.clean(n(this.el).val())).removeClass("w2field").removeData().off(".w2field");for(i in this.helpers)n(this.helpers[i]).remove();this.helpers={}}},refresh:function(){var t=this,r=this.options,u=n(this.el).data("selected"),y=(new Date).getTime(),s,e,o,h,i,c,v,f,l,a;if(["list"].indexOf(this.type)!=-1&&(n(t.el).parent().css("white-space","nowrap"),t.helpers.prefix&&t.helpers.prefix.hide(),setTimeout(function(){if(t.helpers.focus){!n.isEmptyObject(u)&&r.icon?(r.prefix='<span class="w2ui-icon '+r.icon+'"style="cursor: pointer; font-size: 14px; display: inline-block; margin-top: -1px; color: #7F98AD;'+r.iconStyle+'"><\/span>',t.addPrefix()):(r.prefix="",t.addPrefix());var i=t.helpers.focus.find("input");n(i).val()===""?(n(i).css("text-indent","-9999em").prev().css("opacity",0),n(t.el).val(u&&u.text!=null?w2utils.lang(u.text):"")):(n(i).css("text-indent",0).prev().css("opacity",1),n(t.el).val(""),setTimeout(function(){t.helpers.prefix&&t.helpers.prefix.hide();var u="position: absolute; opacity: 0; margin: 4px 0px 0px 2px; background-position: left !important;";r.icon?(n(i).css("margin-left","17px"),n(t.helpers.focus).find(".icon-search").attr("style",u+"width: 11px !important; opacity: 1; display: block")):(n(i).css("margin-left","0px"),n(t.helpers.focus).find(".icon-search").attr("style",u+"width: 0px !important; opacity: 0; display: none"))},1));n(t.el).prop("readonly")||n(t.el).prop("disabled")?setTimeout(function(){n(t.helpers.prefix).css("opacity","0.6");n(t.helpers.suffix).css("opacity","0.6")},1):setTimeout(function(){n(t.helpers.prefix).css("opacity","1");n(t.helpers.suffix).css("opacity","1")},1)}},1)),["enum","file"].indexOf(this.type)!=-1){if(s="",u)for(e=0;e<u.length;e++)o=u[e],h="",h=typeof r.renderItem=="function"?r.renderItem(o,e,'<div class="w2ui-list-remove" title="'+w2utils.lang("Remove")+'" index="'+e+'">&#160;&#160;<\/div>'):'<div class="w2ui-list-remove" title="'+w2utils.lang("Remove")+'" index="'+e+'">&#160;&#160;<\/div>'+(t.type=="enum"?o.text:o.name+'<span class="file-size"> - '+w2utils.formatSize(o.size)+"<\/span>"),s+='<li index="'+e+'" style="max-width: '+parseInt(r.maxWidth)+"px; "+(o.style?o.style:"")+'">'+h+"<\/li>";i=t.helpers.multi;c=i.find("ul");i.attr("style",i.attr("style")+";"+r.style);n(t.el).css("z-index","-1");n(t.el).prop("readonly")||n(t.el).prop("disabled")?setTimeout(function(){i[0].scrollTop=0;i.addClass("w2ui-readonly").find("li").css("opacity","0.9").parent().find("li.nomouse").hide().find("input").prop("readonly",!0).parents("ul").find(".w2ui-list-remove").hide()},1):setTimeout(function(){i.removeClass("w2ui-readonly").find("li").css("opacity","1").parent().find("li.nomouse").show().find("input").prop("readonly",!1).parents("ul").find(".w2ui-list-remove").show()},1);i.find(".w2ui-enum-placeholder").remove();c.find("li").not("li.nomouse").remove();s!==""?c.prepend(s):n(t.el).attr("placeholder")!=null&&i.find("input").val()===""&&(v="padding-top: "+n(this.el).css("padding-top")+";padding-left: "+n(this.el).css("padding-left")+"; box-sizing: "+n(this.el).css("box-sizing")+"; line-height: "+n(this.el).css("line-height")+"; font-size: "+n(this.el).css("font-size")+"; font-family: "+n(this.el).css("font-family")+"; ",i.prepend('<div class="w2ui-enum-placeholder" style="'+v+'">'+n(t.el).attr("placeholder")+"<\/div>"));i.off("scroll.w2field").on("scroll.w2field",function(i){var r=t.trigger({phase:"before",type:"scroll",target:t.el,originalEvent:i});r.isCancelled!==!0&&t.trigger(n.extend(r,{phase:"after"}))}).find("li").data("mouse","out").on("click",function(i){var h=i.target.tagName.toUpperCase()=="LI"?i.target:n(i.target).parents("LI"),r=u[n(h).attr("index")],f,s,e,o;if(!n(h).hasClass("nomouse"))if(i.stopPropagation(),n(i.target).hasClass("w2ui-list-remove")){if(n(t.el).prop("readonly")||n(t.el).prop("disabled"))return;if(f=t.trigger({phase:"before",type:"remove",target:t.el,originalEvent:i.originalEvent,item:r}),f.isCancelled===!0)return;n().w2overlay();u.splice(n(i.target).attr("index"),1);n(t.el).trigger("change");n(i.target).parent().fadeOut("fast");setTimeout(function(){t.refresh();t.trigger(n.extend(f,{phase:"after"}))},300)}else{if(f=t.trigger({phase:"before",type:"click",target:t.el,originalEvent:i.originalEvent,item:r}),f.isCancelled===!0)return;t.type=="file"&&(s="",/image/i.test(r.type)&&(s='<div style="padding: 3px;">    <img src="'+(r.content?"data:"+r.type+";base64,"+r.content:"")+'" style="max-width: 300px;"         onload="var w = jQuery(this).width(); var h = jQuery(this).height();             if (w < 300 & h < 300) return;             if (w >= h && w > 300) jQuery(this).width(300);            if (w < h && h > 300) jQuery(this).height(300);"        onerror="this.style.display = \'none\'"    ><\/div>'),e='style="padding: 3px; text-align: right; color: #777;"',o='style="padding: 3px"',s+='<div style="padding: 8px;">    <table cellpadding="2"><tbody>    <tr><td '+e+">"+w2utils.lang("Name")+":<\/td><td "+o+">"+r.name+"<\/td><\/tr>    <tr><td "+e+">"+w2utils.lang("Size")+":<\/td><td "+o+">"+w2utils.formatSize(r.size)+"<\/td><\/tr>    <tr><td "+e+">"+w2utils.lang("Type")+":<\/td><td "+o+'>        <span style="width: 200px; display: block-inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap="nowrap";">'+r.type+"<\/span>    <\/td><\/tr>    <tr><td "+e+">"+w2utils.lang("Modified")+":<\/td><td "+o+">"+w2utils.date(r.modified)+"<\/td><\/tr>    <\/tbody><\/table><\/div>",n("#w2ui-overlay").remove(),n(h).w2overlay(s));t.trigger(n.extend(f,{phase:"after"}))}}).on("mouseover",function(i){var r=i.target.tagName.toUpperCase()=="LI"?i.target:n(i.target).parents("LI"),e,f;if(!n(r).hasClass("nomouse")){if(n(r).data("mouse")=="out"){if(e=u[n(i.target).attr("index")],f=t.trigger({phase:"before",type:"mouseOver",target:t.el,originalEvent:i.originalEvent,item:e}),f.isCancelled===!0)return;t.trigger(n.extend(f,{phase:"after"}))}n(r).data("mouse","over")}}).on("mouseout",function(i){var r=i.target.tagName.toUpperCase()=="LI"?i.target:n(i.target).parents("LI");n(r).hasClass("nomouse")||(n(r).data("mouse","leaving"),setTimeout(function(){if(n(r).data("mouse")=="leaving"){n(r).data("mouse","out");var e=u[n(i.target).attr("index")],f=t.trigger({phase:"before",type:"mouseOut",target:t.el,originalEvent:i.originalEvent,item:e});if(f.isCancelled===!0)return;t.trigger(n.extend(f,{phase:"after"}))}},0))});n(this.el).height("auto");f=n(i).find("> div.w2ui-multi-items").height()+w2utils.getSize(i,"+height")*2;f<26&&(f=26);f>r.maxHeight&&(f=r.maxHeight);i.length>0&&(i[0].scrollTop=1e3);l=w2utils.getSize(n(this.el),"height")-2;l>f&&(f=l);n(i).css({height:f+"px",overflow:f==r.maxHeight?"auto":"hidden"});f<r.maxHeight&&n(i).prop("scrollTop",0);n(this.el).css({height:f+2+"px"});t.type=="enum"&&(a=t.helpers.multi.find("input"),a.width((a.val().length+2)*8+"px"))}return(new Date).getTime()-y},reset:function(){var n=this.type;this.clear();this.type=n;this.init()},resize:function(){var t=this,i=n(t.el).width(),e=n(t.el).height(),f;if(t.tmp.current_width!=i||!(e>0)){var r=this.helpers.focus,u=this.helpers.multi,o=this.helpers.suffix,s=this.helpers.prefix;r&&r.width(n(t.el).width());u&&(f=w2utils.getSize(t.el,"width")-parseInt(n(t.el).css("margin-left"),10)-parseInt(n(t.el).css("margin-right"),10),n(u).width(f));o&&(t.options.suffix='<div class="arrow-down" style="margin-top: '+(parseInt(n(t.el).height())-6)/2+'px;"><\/div>',t.addSuffix());s&&t.addPrefix();t.tmp.current_width=i}},clean:function(t){if(typeof t=="number")return t;var i=this.options;return t=String(t).trim(),["int","float","money","currency","percent"].indexOf(this.type)!=-1&&(typeof t=="string"&&(i.autoFormat&&["money","currency"].indexOf(this.type)!=-1&&(t=String(t).replace(i.moneyRE,"")),i.autoFormat&&this.type=="percent"&&(t=String(t).replace(i.percentRE,"")),i.autoFormat&&["int","float"].indexOf(this.type)!=-1&&(t=String(t).replace(i.numberRE,"")),t=t.replace(/\s+/g,"").replace(w2utils.settings.groupSymbol,"").replace(w2utils.settings.decimalSymbol,".")),parseFloat(t)==t&&(i.min!=null&&t<i.min&&(t=i.min,n(this.el).val(i.min)),i.max!=null&&t>i.max&&(t=i.max,n(this.el).val(i.max))),t=t!==""&&w2utils.isFloat(t)?Number(t):""),t},format:function(n){var t=this.options;if(t.autoFormat&&n!=="")switch(this.type){case"money":case"currency":n=w2utils.formatNumber(n,t.currencyPrecision,t.groupSymbol);n!==""&&(n=t.currencyPrefix+n+t.currencySuffix);break;case"percent":n=w2utils.formatNumber(n,t.precision,t.groupSymbol);n!==""&&(n+="%");break;case"float":n=w2utils.formatNumber(n,t.precision,t.groupSymbol);break;case"int":n=w2utils.formatNumber(n,0,t.groupSymbol)}return n},change:function(t){var i=this,u=i.options,f,e,o,r;if(["int","float","money","currency","percent"].indexOf(this.type)!=-1&&(f=n(this.el).val(),e=this.format(this.clean(n(this.el).val())),f!==""&&f!=e))return n(this.el).val(e).change(),t.stopPropagation(),t.preventDefault(),!1;this.type=="color"&&(o="#"+n(this.el).val(),n(this.el).val().length!=6&&n(this.el).val().length!=3&&(o=""),n(this.el).next().find("div").css("background-color",o),n(i.el).is(":focus")&&this.updateOverlay());["list","enum","file"].indexOf(this.type)!=-1&&(i.refresh(),setTimeout(function(){i.refresh()},5));["date","time","datetime"].indexOf(this.type)!=-1&&(r=parseInt(i.el.value),w2utils.isInt(i.el.value)&&r>3e3&&(this.type=="time"&&n(i.el).val(w2utils.formatTime(new Date(r),u.format)).change(),this.type=="date"&&n(i.el).val(w2utils.formatDate(new Date(r),u.format)).change(),this.type=="datetime"&&n(i.el).val(w2utils.formatDateTime(new Date(r),u.format)).change()))},click:function(t){t.stopPropagation();["list","combo","enum"].indexOf(this.type)!=-1&&(n(this.el).is(":focus")||this.focus(t));["date","time","color","datetime"].indexOf(this.type)!=-1&&this.updateOverlay()},focus:function(){var t=this,i=this.options;if(["color","date","time","datetime"].indexOf(t.type)!==-1){if(n(t.el).prop("readonly")||n(t.el).prop("disabled"))return;n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();setTimeout(function(){t.updateOverlay()},150)}if(["list","combo","enum"].indexOf(t.type)!=-1){if(n(t.el).prop("readonly")||n(t.el).prop("disabled"))return;n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();t.resize();setTimeout(function(){if(t.type=="list"&&n(t.el).is(":focus")){n(t.helpers.focus).find("input").focus();return}t.search();setTimeout(function(){t.updateOverlay()},1)},1)}t.type=="file"&&n(t.helpers.multi).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"})},blur:function(){var t=this,i=t.options,r=n(t.el).val().trim();["color","date","time","list","combo","enum","datetime"].indexOf(t.type)!=-1&&n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();["int","float","money","currency","percent"].indexOf(t.type)!=-1&&(r===""||t.checkType(r)||(n(t.el).val("").change(),i.silent===!1&&(n(t.el).w2tag("Not a valid number"),setTimeout(function(){n(t.el).w2tag("")},3e3))));["date","time","datetime"].indexOf(t.type)!=-1&&(r===""||t.inRange(t.el.value)?t.type!="date"||r===""||w2utils.isDate(t.el.value,i.format)?t.type!="time"||r===""||w2utils.isTime(t.el.value)?t.type!="datetime"||r===""||w2utils.isDateTime(t.el.value,i.format)||(n(t.el).val("").removeData("selected").change(),i.silent===!1&&(n(t.el).w2tag("Not a valid date"),setTimeout(function(){n(t.el).w2tag("")},3e3))):(n(t.el).val("").removeData("selected").change(),i.silent===!1&&(n(t.el).w2tag("Not a valid time"),setTimeout(function(){n(t.el).w2tag("")},3e3))):(n(t.el).val("").removeData("selected").change(),i.silent===!1&&(n(t.el).w2tag("Not a valid date"),setTimeout(function(){n(t.el).w2tag("")},3e3))):(n(t.el).val("").removeData("selected").change(),i.silent===!1&&(n(t.el).w2tag("Not in range"),setTimeout(function(){n(t.el).w2tag("")},3e3))));t.type=="enum"&&n(t.helpers.multi).find("input").val("").width(20);t.type=="file"&&n(t.helpers.multi).css({outline:"none"})},keyPress:function(n){var t=this,r=t.options,i;if(["int","float","money","currency","percent","hex","bin","color","alphanumeric"].indexOf(t.type)!=-1){if(n.metaKey||n.ctrlKey||n.altKey||n.charCode!=n.keyCode&&n.keyCode>0)return;if(i=String.fromCharCode(n.charCode),!t.checkType(i,!0)&&n.keyCode!=13)return n.preventDefault(),n.stopPropagation?n.stopPropagation():n.cancelBubble=!0,!1}["date","time","datetime"].indexOf(t.type)!=-1&&n.keyCode!==9&&setTimeout(function(){t.updateOverlay()},1)},keyDown:function(t,i){var r=this,u=r.options,v=t.keyCode||i&&i.keyCode,g,f,c,y,d,o,l;if(["int","float","money","currency","percent"].indexOf(r.type)!=-1){if(!u.keyboard||n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;var h=!1,w=parseFloat(n(r.el).val().replace(u.moneyRE,""))||0,s=u.step;(t.ctrlKey||t.metaKey)&&(s=10);switch(v){case 38:if(t.shiftKey)break;n(r.el).val(w+s<=u.max||u.max==null?Number((w+s).toFixed(12)):u.max).change();h=!0;break;case 40:if(t.shiftKey)break;n(r.el).val(w-s>=u.min||u.min==null?Number((w-s).toFixed(12)):u.min).change();h=!0}h&&(t.preventDefault(),setTimeout(function(){r.el.setSelectionRange(r.el.value.length,r.el.value.length)},0))}if(r.type=="date"){if(!u.keyboard||n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;var h=!1,p=864e5,s=1;(t.ctrlKey||t.metaKey)&&(s=10);f=w2utils.isDate(n(r.el).val(),u.format,!0);f||(f=new Date,p=0);switch(v){case 38:if(t.shiftKey)break;c=w2utils.formatDate(f.getTime()+p,u.format);s==10&&(c=w2utils.formatDate(new Date(f.getFullYear(),f.getMonth()+1,f.getDate()),u.format));n(r.el).val(c).change();h=!0;break;case 40:if(t.shiftKey)break;c=w2utils.formatDate(f.getTime()-p,u.format);s==10&&(c=w2utils.formatDate(new Date(f.getFullYear(),f.getMonth()-1,f.getDate()),u.format));n(r.el).val(c).change();h=!0}h&&(t.preventDefault(),setTimeout(function(){r.el.setSelectionRange(r.el.value.length,r.el.value.length);r.updateOverlay()},0))}if(r.type=="time"){if(!u.keyboard||n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;var h=!1,s=t.ctrlKey||t.metaKey?60:1,w=n(r.el).val(),k=r.toMin(w)||r.toMin((new Date).getHours()+":"+((new Date).getMinutes()-1));switch(v){case 38:if(t.shiftKey)break;k+=s;h=!0;break;case 40:if(t.shiftKey)break;k-=s;h=!0}h&&(n(r.el).val(r.fromMin(k)).change(),t.preventDefault(),setTimeout(function(){r.el.setSelectionRange(r.el.value.length,r.el.value.length)},0))}if(r.type=="datetime"){if(!u.keyboard||n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;var h=!1,p=864e5,s=1;(t.ctrlKey||t.metaKey)&&(s=10);g=n(r.el).val();f=w2utils.isDateTime(g,this.options.format,!0);f||(f=new Date,p=0);switch(v){case 38:if(t.shiftKey)break;c=w2utils.formatDateTime(f.getTime()+p,u.format);s==10&&(c=w2utils.formatDateTime(new Date(f.getFullYear(),f.getMonth()+1,f.getDate()),u.format));n(r.el).val(c).change();h=!0;break;case 40:if(t.shiftKey)break;c=w2utils.formatDateTime(f.getTime()-p,u.format);s==10&&(c=w2utils.formatDateTime(new Date(f.getFullYear(),f.getMonth()-1,f.getDate()),u.format));n(r.el).val(c).change();h=!0}h&&(t.preventDefault(),setTimeout(function(){r.el.setSelectionRange(r.el.value.length,r.el.value.length);r.updateOverlay()},0))}if(r.type=="color"){if(n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;if(t.keyCode==86&&(t.ctrlKey||t.metaKey)&&(n(r.el).prop("maxlength",7),setTimeout(function(){var t=n(r).val();t.substr(0,1)=="#"&&(t=t.substr(1));w2utils.isHex(t)||(t="");n(r).val(t).prop("maxlength",6).change()},20)),(t.ctrlKey||t.metaKey)&&!t.shiftKey){y=null;d=null;switch(v){case 38:y="up";break;case 40:y="down";break;case 39:y="right";break;case 37:y="left"}r.el.nav&&y!=null&&(d=r.el.nav(y),n(r.el).val(d).change(),t.preventDefault())}}if(["list","combo","enum"].indexOf(r.type)!=-1){if(n(r.el).prop("readonly")||n(r.el).prop("disabled"))return;var a=n(r.el).data("selected"),e=n(r.el),b=!1;["list","enum"].indexOf(r.type)!=-1&&(r.type=="list"&&(e=n(r.helpers.focus).find("input")),r.type=="enum"&&(e=n(r.helpers.multi).find("input")),[37,38,39,40].indexOf(v)==-1&&setTimeout(function(){r.refresh()},1),t.keyCode==86&&(t.ctrlKey||t.metaKey)&&setTimeout(function(){r.refresh();r.search();r.request()},50));switch(v){case 27:r.type=="list"&&(e.val()!==""&&e.val(""),t.stopPropagation());break;case 13:if(n("#w2ui-overlay").length===0)break;if(o=u.items[u.index],r.type=="enum")if(o!=null){if(l=r.trigger({phase:"before",type:"add",target:r.el,originalEvent:t.originalEvent,item:o}),l.isCancelled===!0)return;o=l.item;a.length>=u.max&&u.max>0&&a.pop();delete o.hidden;delete r.tmp.force_open;a.push(o);n(r.el).change();e.val("").width(20);r.refresh();r.trigger(n.extend(l,{phase:"after"}))}else{if(o={id:e.val(),text:e.val()},l=r.trigger({phase:"before",type:"new",target:r.el,originalEvent:t.originalEvent,item:o}),l.isCancelled===!0)return;o=l.item;typeof r.onNew=="function"&&(a.length>=u.max&&u.max>0&&a.pop(),delete r.tmp.force_open,a.push(o),n(r.el).change(),e.val("").width(20),r.refresh());r.trigger(n.extend(l,{phase:"after"}))}else o&&n(r.el).data("selected",o).val(o.text).change(),n(r.el).val()===""&&n(r.el).data("selected")&&n(r.el).removeData("selected").val("").change(),r.type=="list"&&(e.val(""),r.refresh()),r.tmp.force_hide=!0;break;case 8:case 46:if(r.type=="enum"&&v==8&&e.val()===""&&a.length>0){if(o=a[a.length-1],l=r.trigger({phase:"before",type:"remove",target:r.el,originalEvent:t.originalEvent,item:o}),l.isCancelled===!0)return;a.pop();n(r.el).trigger("change");r.refresh();r.trigger(n.extend(l,{phase:"after"}))}r.type=="list"&&e.val()===""&&(n(r.el).data("selected",{}).change(),r.refresh());break;case 38:for(u.index=w2utils.isInt(u.index)?parseInt(u.index):0,u.index--;u.index>0&&u.items[u.index].hidden;)u.index--;if(u.index===0&&u.items[u.index].hidden)while(u.items[u.index]&&u.items[u.index].hidden)u.index++;b=!0;break;case 40:for(u.index=w2utils.isInt(u.index)?parseInt(u.index):-1,u.index++;u.index<u.items.length-1&&u.items[u.index].hidden;)u.index++;if(u.index==u.items.length-1&&u.items[u.index].hidden)while(u.items[u.index]&&u.items[u.index].hidden)u.index--;e.val()===""&&n("#w2ui-overlay").length===0?r.tmp.force_open=!0:b=!0}if(b){u.index<0&&(u.index=0);u.index>=u.items.length&&(u.index=u.items.length-1);r.updateOverlay(b);t.preventDefault();setTimeout(function(){var n;r.type=="enum"?(n=e.get(0),n.setSelectionRange(n.value.length,n.value.length)):r.type=="list"?(n=e.get(0),n.setSelectionRange(n.value.length,n.value.length)):r.el.setSelectionRange(r.el.value.length,r.el.value.length)},0);return}r.type=="enum"&&e.width((e.val().length+2)*8+"px")}},keyUp:function(t){var u=this,i,r;if(this.type=="color"&&t.keyCode==86&&(t.ctrlKey||t.metaKey)&&n(this).prop("maxlength",6),["list","combo","enum"].indexOf(this.type)!=-1){if(n(u.el).prop("readonly")||n(u.el).prop("disabled"))return;if([16,17,18,20,37,39,91].indexOf(t.keyCode)==-1){if(i=n(this.helpers.focus).find("input"),i.length===0&&(i=n(this.el)),r=this.trigger({phase:"before",type:"search",originalEvent:t,target:i,search:i.val()}),r.isCancelled===!0)return;this.tmp.force_hide||this.request();i.val().length==1&&this.refresh();(n("#w2ui-overlay").length===0||[38,40].indexOf(t.keyCode)==-1)&&this.search();this.trigger(n.extend(r,{phase:"after"}))}}},clearCache:function(){var n=this.options;n.items=[];this.tmp.xhr_loading=!1;this.tmp.xhr_search="";this.tmp.xhr_total=-1},request:function(t){var i=this,r=this.options,u=n(i.el).val()||"",f;if(r.url){if(i.type=="enum"&&(f=n(i.helpers.multi).find("input"),u=f.length===0?"":f.val()),i.type=="list"&&(f=n(i.helpers.focus).find("input"),u=f.length===0?"":f.val()),r.minLength!==0&&u.length<r.minLength){r.items=[];this.updateOverlay();return}t==null&&(t=r.interval);i.tmp.xhr_search==null&&(i.tmp.xhr_search="");i.tmp.xhr_total==null&&(i.tmp.xhr_total=-1);r.url&&n(i.el).prop("readonly")!==!0&&n(i.el).prop("disabled")!==!0&&(r.items.length===0&&i.tmp.xhr_total!==0||i.tmp.xhr_total==r.cacheMax&&u.length>i.tmp.xhr_search.length||u.length>=i.tmp.xhr_search.length&&u.substr(0,i.tmp.xhr_search.length)!=i.tmp.xhr_search||u.length<i.tmp.xhr_search.length)&&(i.tmp.xhr&&i.tmp.xhr.abort(),i.tmp.xhr_loading=!0,i.search(),clearTimeout(i.tmp.timeout),i.tmp.timeout=setTimeout(function(){var o=r.url,f={search:u,max:r.cacheMax},e,t;(n.extend(f,r.postData),e=i.trigger({phase:"before",type:"request",search:u,target:i.el,url:o,postData:f}),e.isCancelled!==!0)&&(o=e.url,f=e.postData,t={type:"GET",url:o,data:f,dataType:"JSON"},r.method&&(t.type=r.method),w2utils.settings.dataType=="JSON"&&(t.type="POST",t.data=JSON.stringify(t.data),t.contentType="application/json"),w2utils.settings.dataType=="HTTPJSON"&&(t.data={request:JSON.stringify(t.data)}),r.method!=null&&(t.type=r.method),i.tmp.xhr=n.ajax(t).done(function(t,e,o){var s=i.trigger({phase:"before",type:"load",target:i.el,search:f.search,data:t,xhr:o});if(s.isCancelled!==!0){if(t=s.data,typeof t=="string"&&(t=JSON.parse(t)),t.records==null&&t.items!=null&&(t.records=t.items,delete t.items),t.status!="success"||!Array.isArray(t.records)){console.log("ERROR: server did not return proper structure. It should return",{status:"success",records:[{id:1,text:"item"}]});return}t.records.length>r.cacheMax&&t.records.splice(r.cacheMax,1e5);r.recId==null&&r.recid!=null&&(r.recId=r.recid);(r.recId||r.recText)&&t.records.forEach(function(n){typeof r.recId=="string"&&(n.id=n[r.recId]);typeof r.recId=="function"&&(n.id=r.recId(n));typeof r.recText=="string"&&(n.text=n[r.recText]);typeof r.recText=="function"&&(n.text=r.recText(n))});i.tmp.xhr_loading=!1;i.tmp.xhr_search=u;i.tmp.xhr_total=t.records.length;r.items=i.normMenu(t.records);i.tmp.emptySet=u===""&&t.records.length===0?!0:!1;i.search();i.trigger(n.extend(s,{phase:"after"}))}}).fail(function(t,r,f){var s={status:r,error:f,rawResponseText:t.responseText},o=i.trigger({phase:"before",type:"error",target:i.el,search:u,error:s,xhr:t}),e;if(o.isCancelled!==!0){if(r!="abort"){try{e=n.parseJSON(t.responseText)}catch(h){}console.log("ERROR: Server communication failed.","\n   EXPECTED:",{status:"success",records:[{id:1,text:"item"}]},"\n         OR:",{status:"error",message:"error message"},"\n   RECEIVED:",typeof e=="object"?e:t.responseText)}i.clearCache();i.search();i.trigger(n.extend(o,{phase:"after"}))}}),i.trigger(n.extend(e,{phase:"after"})))},t))}},search:function(){var i=this,t=this.options,e=n(i.el).val(),o=i.el,h=[],u=n(i.el).data("selected"),f,c,s,r,l,a,v;if(i.type=="enum"){o=n(i.helpers.multi).find("input");e=o.val();for(f in u)u[f]&&h.push(u[f].id)}else if(i.type=="list"){o=n(i.helpers.focus).find("input");e=o.val();for(f in u)u[f]&&h.push(u[f].id)}if(i.tmp.xhr_loading!==!0){for(c=0,s=0;s<t.items.length;s++){if(r=t.items[s],t.compare!=null)typeof t.compare=="function"&&(r.hidden=t.compare.call(this,r,e)===!1?!0:!1);else{l="";a="";["is","begins"].indexOf(t.match)!=-1&&(l="^");["is","ends"].indexOf(t.match)!=-1&&(a="$");try{v=new RegExp(l+e+a,"i");r.hidden=v.test(r.text)||r.text=="..."?!1:!0}catch(y){}}t.filter===!1&&(r.hidden=!1);i.type=="enum"&&n.inArray(r.id,h)!=-1&&(r.hidden=!0);r.hidden!==!0&&(c++,delete r.hidden)}for(t.index=-1;t.items[t.index]&&t.items[t.index].hidden;)t.index++;c<=0&&(t.index=-1);t.spinner=!1;i.updateOverlay();setTimeout(function(){var i=n("#w2ui-overlay").html()||"";t.markSearch&&i.indexOf("$.fn.w2menuHandler")!=-1&&n("#w2ui-overlay").w2marker(e)},1)}else t.items.splice(0,t.cacheMax),t.spinner=!0,i.updateOverlay()},updateOverlay:function(t){var i=this,r=this.options,h,c,l,e,s,a,u,v,f;if(this.type=="color"){if(n(i.el).prop("readonly")||n(i.el).prop("disabled"))return;n(this.el).w2color({color:n(this.el).val(),transparent:r.transparent},function(t){t!=null&&n(i.el).val(t).change()})}if(this.type=="date"){if(n(i.el).prop("readonly")||n(i.el).prop("disabled"))return;n("#w2ui-overlay").length===0&&n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar" onclick="event.stopPropagation();"><\/div>',{css:{"background-color":"#f5f5f5"}});e=w2utils.isDate(n(i.el).val(),i.options.format,!0);e&&(c=e.getMonth()+1,l=e.getFullYear()),function o(t,r){n("#w2ui-overlay > div > div").html(i.getMonthHTML(t,r,n(i.el).val()));n("#w2ui-overlay .w2ui-calendar-title").on("mousedown",function(){if(n(this).next().hasClass("w2ui-calendar-jump"))n(this).next().remove();else{var t,r;n(this).after('<div class="w2ui-calendar-jump" style=""><\/div>');n(this).next().hide().html(i.getYearHTML()).fadeIn(200);setTimeout(function(){n("#w2ui-overlay .w2ui-calendar-jump").find(".w2ui-jump-month, .w2ui-jump-year").on("click",function(){n(this).hasClass("w2ui-jump-month")&&(n(this).parent().find(".w2ui-jump-month").removeClass("selected"),n(this).addClass("selected"),r=n(this).attr("name"));n(this).hasClass("w2ui-jump-year")&&(n(this).parent().find(".w2ui-jump-year").removeClass("selected"),n(this).addClass("selected"),t=n(this).attr("name"));t!=null&&r!=null&&(n("#w2ui-overlay .w2ui-calendar-jump").fadeOut(100),setTimeout(function(){o(parseInt(r)+1,t)},100))});n("#w2ui-overlay .w2ui-calendar-jump >:last-child").prop("scrollTop",2e3)},1)}});n("#w2ui-overlay .w2ui-date").on("mousedown",function(){var t=n(this).attr("date");n(i.el).val(t).change();n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"})}).on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)});n("#w2ui-overlay .previous").on("mousedown",function(){var n=i.options.current.split("/");n[0]=parseInt(n[0])-1;o(n[0],n[1])});n("#w2ui-overlay .next").on("mousedown",function(){var n=i.options.current.split("/");n[0]=parseInt(n[0])+1;o(n[0],n[1])})}(c,l)}if(this.type=="time"){if(n(i.el).prop("readonly")||n(i.el).prop("disabled"))return;n("#w2ui-overlay").length===0&&n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time" onclick="event.stopPropagation();"><\/div>',{css:{"background-color":"#fff"}});h=this.options.format=="h24";n("#w2ui-overlay > div").html(i.getHourHTML());n("#w2ui-overlay .w2ui-time").on("mousedown",function(){n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});var t=n(this).attr("hour");n(i.el).val((t>12&&!h?t-12:t)+":00"+(h?"":t<12?" am":" pm")).change()});if(this.options.noMinutes==null||this.options.noMinutes===!1)n("#w2ui-overlay .w2ui-time").on("mouseup",function(){var t=n(this).attr("hour");n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time"><\/div>',{css:{"background-color":"#fff"}});n("#w2ui-overlay > div").html(i.getMinHTML(t));n("#w2ui-overlay .w2ui-time").on("mousedown",function(){n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});var r=n(this).attr("min");n(i.el).val((t>12&&!h?t-12:t)+":"+(r<10?0:"")+r+(h?"":t<12?" am":" pm")).change()}).on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})});else n("#w2ui-overlay .w2ui-time").on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})}if(this.type=="datetime"){if(n(i.el).prop("readonly")||n(i.el).prop("disabled"))return;n("#w2ui-overlay .w2ui-time").length>0&&n("#w2ui-overlay")[0].hide();n("#w2ui-overlay").length===0&&n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar" onclick="event.stopPropagation();"><\/div>',{css:{"background-color":"#f5f5f5"}});e=w2utils.isDateTime(n(i.el).val(),i.options.format,!0);e&&(c=e.getMonth()+1,l=e.getFullYear());s=null,function o(t,u){n("#w2ui-overlay > div > div").html(i.getMonthHTML(t,u,n(i.el).val())+(r.btn_now?'<div class="w2ui-calendar-now now">'+w2utils.lang("Current Date & Time")+"<\/div>":""));n("#w2ui-overlay .w2ui-calendar-title").on("mousedown",function(){if(n(this).next().hasClass("w2ui-calendar-jump"))n(this).next().remove();else{var t,r;n(this).after('<div class="w2ui-calendar-jump" style=""><\/div>');n(this).next().hide().html(i.getYearHTML()).fadeIn(200);setTimeout(function(){n("#w2ui-overlay .w2ui-calendar-jump").find(".w2ui-jump-month, .w2ui-jump-year").on("click",function(){n(this).hasClass("w2ui-jump-month")&&(n(this).parent().find(".w2ui-jump-month").removeClass("selected"),n(this).addClass("selected"),r=n(this).attr("name"));n(this).hasClass("w2ui-jump-year")&&(n(this).parent().find(".w2ui-jump-year").removeClass("selected"),n(this).addClass("selected"),t=n(this).attr("name"));t!=null&&r!=null&&(n("#w2ui-overlay .w2ui-calendar-jump").fadeOut(100),setTimeout(function(){o(parseInt(r)+1,t)},100))});n("#w2ui-overlay .w2ui-calendar-jump >:last-child").prop("scrollTop",2e3)},1)}});n("#w2ui-overlay .w2ui-date").on("mousedown",function(){var t=n(this).attr("date");n(i.el).val(t).change();n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});s=new Date(n(this).attr("data-date"))}).on("mouseup",function(){var t,r,u;n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time"><\/div>',{css:{"background-color":"#fff"}});u=i.options.format=="h24";n("#w2ui-overlay > div").html(i.getHourHTML());n("#w2ui-overlay .w2ui-time").on("mousedown",function(){n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});t=n(this).attr("hour");s.setHours(t);var r=w2utils.formatDateTime(s,i.options.format);n(i.el).val(r).change()});if(i.options.noMinutes==null||i.options.noMinutes===!1)n("#w2ui-overlay .w2ui-time").on("mouseup",function(){var u=n(this).attr("hour");n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();n(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time"><\/div>',{css:{"background-color":"#fff"}});n("#w2ui-overlay > div").html(i.getMinHTML(u));n("#w2ui-overlay .w2ui-time").on("mousedown",function(){n(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});r=n(this).attr("min");s.setHours(t,r);var u=w2utils.formatDateTime(s,i.options.format);n(i.el).val(u).change()}).on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})});else n("#w2ui-overlay .w2ui-time").on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})});n("#w2ui-overlay .previous").on("mousedown",function(){var n=i.options.current.split("/");n[0]=parseInt(n[0])-1;o(n[0],n[1])});n("#w2ui-overlay .next").on("mousedown",function(){var n=i.options.current.split("/");n[0]=parseInt(n[0])+1;o(n[0],n[1])});n("#w2ui-overlay .now").on("mousedown",function(){var t=w2utils.formatDateTime(new Date,i.options.format);return n(i.el).val(t).change(),!1}).on("mouseup",function(){setTimeout(function(){n("#w2ui-overlay").length>0&&n("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})}(c,l)}if(["list","combo","enum"].indexOf(this.type)!=-1&&(a=this.el,u=this.el,this.type=="enum"&&(a=n(this.helpers.multi),u=n(a).find("input")),this.type=="list"&&(v=n(u).data("selected"),n.isPlainObject(v)&&!n.isEmptyObject(v)&&r.index==-1&&r.items.forEach(function(n,t){n.id==v.id&&(r.index=t)}),u=n(this.helpers.focus).find("input")),n(u).is(":focus"))){if(r.openOnFocus===!1&&n(u).val()===""&&i.tmp.force_open!==!0){n().w2overlay();return}if(i.tmp.force_hide){n().w2overlay();setTimeout(function(){delete i.tmp.force_hide},1);return}n(u).val()!==""&&delete i.tmp.force_open;f=w2utils.lang("No matches");r.url!=null&&n(u).val().length<r.minLength&&i.tmp.emptySet!==!0&&(f=r.minLength+" "+w2utils.lang("letters or more..."));r.url!=null&&n(u).val()===""&&i.tmp.emptySet!==!0&&(f=w2utils.lang("Type to search..."));r.url==null&&r.items.length===0&&(f=w2utils.lang("Empty list"));r.msgNoItems!=null&&(f=r.msgNoItems);f=="function"&&(f=f(r));n(a).w2menu(t?"refresh-index":"refresh",n.extend(!0,{},r,{search:!1,render:r.renderDrop,maxHeight:r.maxDropHeight,maxWidth:r.maxDropWidth,msgNoItems:f,onSelect:function(t){var u,f;if(i.type=="enum"){if(u=n(i.el).data("selected"),t.item){if(f=i.trigger({phase:"before",type:"add",target:i.el,originalEvent:t.originalEvent,item:t.item}),f.isCancelled===!0)return;u.length>=r.max&&r.max>0&&u.pop();delete t.item.hidden;u.push(t.item);n(i.el).data("selected",u).change();n(i.helpers.multi).find("input").val("").width(20);i.refresh();n("#w2ui-overlay").length>0&&n("#w2ui-overlay")[0].hide();i.trigger(n.extend(f,{phase:"after"}))}}else n(i.el).data("selected",t.item).val(t.item.text).change(),i.helpers.focus&&i.helpers.focus.find("input").val("")}}))}},inRange:function(t,i){var u=!1,p,f,r,s,c,l,e,h,o;if(this.type=="date"){if(f=w2utils.isDate(t,this.options.format,!0),f){if(this.options.start||this.options.end){var c=typeof this.options.start=="string"?this.options.start:n(this.options.start).val(),l=typeof this.options.end=="string"?this.options.end:n(this.options.end).val(),r=w2utils.isDate(c,this.options.format,!0),s=w2utils.isDate(l,this.options.format,!0),e=new Date(f);r||(r=e);s||(s=e);e>=r&&e<=s&&(u=!0)}else u=!0;if(this.options.blocked&&n.inArray(t,this.options.blocked)!=-1&&(u=!1),this.options.blockWeekDays!=null&&this.options.blockWeekDays!=undefined&&this.options.blockWeekDays.length!=undefined)for(p=this.options.blockWeekDays.length,h=0;h<p;h++)f.getDay()==this.options.blockWeekDays[h]&&(u=!1)}}else if(this.type=="time")if(this.options.start||this.options.end){var a=this.toMin(t),v=this.toMin(this.options.start),y=this.toMin(this.options.end);v||(v=a);y||(y=a);a>=v&&a<=y&&(u=!0)}else u=!0;else if(this.type=="datetime"&&(f=w2utils.isDateTime(t,this.options.format,!0),f&&(this.options.start||this.options.end?(typeof this.options.start=="object"&&this.options.start instanceof Date?r=this.options.start:(c=typeof this.options.start=="string"?this.options.start:n(this.options.start).val(),r=c.trim()!==""?w2utils.isDateTime(c,this.options.format,!0):""),typeof this.options.end=="object"&&this.options.end instanceof Date?s=this.options.end:(l=typeof this.options.end=="string"?this.options.end:n(this.options.end).val(),s=l.trim()!==""?w2utils.isDateTime(l,this.options.format,!0):""),e=f,r||(r=e),s||(s=e),i&&r instanceof Date&&(r.setHours(0),r.setMinutes(0),r.setSeconds(0)),e>=r&&e<=s&&(u=!0)):u=!0,u&&this.options.blocked)))for(h=0;h<this.options.blocked.length;h++)if(o=this.options.blocked[h],typeof o=="string"&&(o=w2utils.isDateTime(o,this.options.format,!0)),typeof o=="object"&&o instanceof Date&&o.getFullYear()==f.getFullYear()&&o.getMonth()==f.getMonth()&&o.getDate()==f.getDate()){u=!1;break}return u},checkType:function(n,t){var i=this;switch(i.type){case"int":return t&&["-",i.options.groupSymbol].indexOf(n)!=-1?!0:w2utils.isInt(n.replace(i.options.numberRE,""));case"percent":n=n.replace(/%/g,"");case"float":return t&&["-",w2utils.settings.decimalSymbol,i.options.groupSymbol].indexOf(n)!=-1?!0:w2utils.isFloat(n.replace(i.options.numberRE,""));case"money":case"currency":return t&&["-",i.options.decimalSymbol,i.options.groupSymbol,i.options.currencyPrefix,i.options.currencySuffix].indexOf(n)!=-1?!0:w2utils.isFloat(n.replace(i.options.moneyRE,""));case"bin":return w2utils.isBin(n);case"hex":case"color":return w2utils.isHex(n);case"alphanumeric":return w2utils.isAlphaNumeric(n)}return!0},addPrefix:function(){var t=this;setTimeout(function(){if(t.type!=="clear"){var i,r=n(t.el).data("tmp")||{};if(r["old-padding-left"]&&n(t.el).css("padding-left",r["old-padding-left"]),r["old-padding-left"]=n(t.el).css("padding-left"),n(t.el).data("tmp",r),t.helpers.prefix&&n(t.helpers.prefix).remove(),t.options.prefix!==""){n(t.el).before('<div class="w2ui-field-helper">'+t.options.prefix+"<\/div>");i=n(t.el).prev();i.css({color:n(t.el).css("color"),"font-family":n(t.el).css("font-family"),"font-size":n(t.el).css("font-size"),"padding-top":n(t.el).css("padding-top"),"padding-bottom":n(t.el).css("padding-bottom"),"padding-left":n(t.el).css("padding-left"),"padding-right":0,"margin-top":parseInt(n(t.el).css("margin-top"),10)+2+"px","margin-bottom":parseInt(n(t.el).css("margin-bottom"),10)+1+"px","margin-left":n(t.el).css("margin-left"),"margin-right":0}).on("click",function(){if(t.options.icon&&typeof t.onIconClick=="function"){var i=t.trigger({phase:"before",type:"iconClick",target:t.el,el:n(this).find("span.w2ui-icon")[0]});if(i.isCancelled===!0)return;t.trigger(n.extend(i,{phase:"after"}))}else t.type=="list"?n(t.helpers.focus).find("input").focus():n(t.el).focus()});n(t.el).css("padding-left",i.width()+parseInt(n(t.el).css("padding-left"),10)+"px");t.helpers.prefix=i}}},1)},addSuffix:function(){var t=this,i,r;setTimeout(function(){var u,f;if(t.type!=="clear"){if(u=n(t.el).data("tmp")||{},u["old-padding-right"]&&n(t.el).css("padding-right",u["old-padding-right"]),u["old-padding-right"]=n(t.el).css("padding-right"),n(t.el).data("tmp",u),r=parseInt(n(t.el).css("padding-right"),10),t.options.arrows){t.helpers.arrows&&n(t.helpers.arrows).remove();n(t.el).after('<div class="w2ui-field-helper" style="border: 1px solid transparent">&#160;    <div class="w2ui-field-up" type="up">        <div class="arrow-up" type="up"><\/div>    <\/div>    <div class="w2ui-field-down" type="down">        <div class="arrow-down" type="down"><\/div>    <\/div><\/div>');f=w2utils.getSize(t.el,"height");i=n(t.el).next();i.css({color:n(t.el).css("color"),"font-family":n(t.el).css("font-family"),"font-size":n(t.el).css("font-size"),height:n(t.el).height()+parseInt(n(t.el).css("padding-top"),10)+parseInt(n(t.el).css("padding-bottom"),10)+"px",padding:0,"margin-top":parseInt(n(t.el).css("margin-top"),10)+1+"px","margin-bottom":0,"border-left":"1px solid silver"}).css("margin-left","-"+(i.width()+parseInt(n(t.el).css("margin-right"),10)+12)+"px").on("mousedown",function(i){function f(){clearTimeout(r.data("_field_update_timer"));r.off("mouseup",f)}function u(r){n(t.el).focus();t.keyDown(n.Event("keydown"),{keyCode:n(i.target).attr("type")=="up"?38:40});r!==!1&&n("body").data("_field_update_timer",setTimeout(u,60))}var r=n("body");r.on("mouseup",f);r.data("_field_update_timer",setTimeout(u,700));u(!1)});r+=i.width()+12;n(t.el).css("padding-right",r+"px");t.helpers.arrows=i}if(t.options.suffix!==""){t.helpers.suffix&&n(t.helpers.suffix).remove();n(t.el).after('<div class="w2ui-field-helper">'+t.options.suffix+"<\/div>");i=n(t.el).next();i.css({color:n(t.el).css("color"),"font-family":n(t.el).css("font-family"),"font-size":n(t.el).css("font-size"),"padding-top":n(t.el).css("padding-top"),"padding-bottom":n(t.el).css("padding-bottom"),"padding-left":"3px","padding-right":n(t.el).css("padding-right"),"margin-top":parseInt(n(t.el).css("margin-top"),10)+2+"px","margin-bottom":parseInt(n(t.el).css("margin-bottom"),10)+1+"px"}).on("click",function(){t.type=="list"?n(t.helpers.focus).find("input").focus():n(t.el).focus()});i.css("margin-left","-"+(w2utils.getSize(i,"width")+parseInt(n(t.el).css("margin-right"),10)+2)+"px");r+=i.width()+3;n(t.el).css("padding-right",r+"px");t.helpers.suffix=i}}},1)},addFocus:function(){var t=this,o=this.options,f=0,u,i,e,r;n(t.helpers.focus).remove();i=n(t.el).attr("tabIndex");i&&i!=-1&&(t.el._tabIndex=i);t.el._tabIndex&&(i=t.el._tabIndex);i==null&&(i=-1);e='<div class="w2ui-field-helper">    <div class="w2ui-icon icon-search" style="opacity: 0; display: none"><\/div>    <input type="text" autocomplete="off" tabIndex="'+i+'"/><\/div>';n(t.el).attr("tabindex",-1).before(e);r=n(t.el).prev();t.helpers.focus=r;r.css({width:n(t.el).width(),"margin-top":n(t.el).css("margin-top"),"margin-left":parseInt(n(t.el).css("margin-left"))+parseInt(n(t.el).css("padding-left"))+"px","margin-bottom":n(t.el).css("margin-bottom"),"margin-right":n(t.el).css("margin-right")}).find("input").css({cursor:"default",width:"100%",outline:"none",opacity:1,margin:0,border:"1px solid transparent",padding:n(t.el).css("padding-top"),"padding-left":0,"margin-left":f>0?f+6:0,"background-color":"transparent"});r.find("input").on("click",function(i){n("#w2ui-overlay").length===0&&t.focus(i);i.stopPropagation()}).on("focus",function(i){u=n(t.el).attr("placeholder");n(t.el).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"});n(this).val("");n(t.el).triggerHandler("focus");i.stopPropagation?i.stopPropagation():i.cancelBubble=!0}).on("blur",function(i){n(t.el).css("outline","none");n(this).val("");t.refresh();n(t.el).triggerHandler("blur");i.stopPropagation?i.stopPropagation():i.cancelBubble=!0;u!=null&&n(t.el).attr("placeholder",u)}).on("keydown",function(i){var r=this;t.keyDown(i);setTimeout(function(){r.value===""?n(t.el).attr("placeholder",u):n(t.el).attr("placeholder","")},10)}).on("keyup",function(n){t.keyUp(n)}).on("keypress",function(n){t.keyPress(n)});r.on("click",function(){n(this).find("input").focus()});t.refresh()},addMulti:function(){var t=this,o=this.options,u,e,r,f,i;if(n(t.helpers.multi).remove(),u="",e="margin-top     : 0px; margin-bottom  : 0px; margin-left    : "+n(t.el).css("margin-left")+"; margin-right   : "+n(t.el).css("margin-right")+"; width          : "+(w2utils.getSize(t.el,"width")-parseInt(n(t.el).css("margin-left"),10)-parseInt(n(t.el).css("margin-right"),10))+"px;",t.type=="enum"&&(r=n(t.el).attr("tabIndex"),r&&r!=-1&&(t.el._tabIndex=r),t.el._tabIndex&&(r=t.el._tabIndex),r==null&&(r=-1),u='<div class="w2ui-field-helper w2ui-list" style="'+e+'; box-sizing: border-box">    <div style="padding: 0px; margin: 0px; display: inline-block" class="w2ui-multi-items">    <ul>        <li style="padding-left: 0px; padding-right: 0px" class="nomouse">            <input type="text" style="width: 20px; margin: -3px 0 0; padding: 2px 0; border-color: white" autocomplete="off"'+(n(t.el).prop("readonly")?' readonly="readonly"':"")+(n(t.el).prop("disabled")?' disabled="disabled"':"")+' tabindex="'+r+'"/>        <\/li>    <\/ul>    <\/div><\/div>'),t.type=="file"&&(u='<div class="w2ui-field-helper w2ui-list" style="'+e+'; box-sizing: border-box">   <div style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px;">       <input class="file-input" type="file" style="width: 100%; height: 100%; opacity: 0;" name="attachment" multiple tabindex="-1"'+(n(t.el).prop("readonly")?' readonly="readonly"':"")+(n(t.el).prop("disabled")?' disabled="disabled"':"")+(n(t.el).attr("accept")?' accept="'+n(t.el).attr("accept")+'"':"")+'/>   <\/div>    <div style="position: absolute; padding: 0px; margin: 0px; display: inline-block" class="w2ui-multi-items">        <ul><li style="padding-left: 0px; padding-right: 0px" class="nomouse"><\/li><\/ul>    <\/div><\/div>'),f=n(t.el).data("tmp")||{},f["old-background-color"]=n(t.el).css("background-color"),f["old-border-color"]=n(t.el).css("border-color"),n(t.el).data("tmp",f),n(t.el).before(u).css({"background-color":"transparent","border-color":"transparent"}),i=n(t.el).prev(),t.helpers.multi=i,t.type=="enum"){n(t.el).attr("tabindex",-1);i.find("input").on("click",function(i){n("#w2ui-overlay").length===0&&t.focus(i);n(t.el).triggerHandler("click")}).on("focus",function(r){n(i).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"});n(t.el).triggerHandler("focus");r.stopPropagation?r.stopPropagation():r.cancelBubble=!0}).on("blur",function(r){n(i).css("outline","none");n(t.el).triggerHandler("blur");r.stopPropagation?r.stopPropagation():r.cancelBubble=!0}).on("keyup",function(n){t.keyUp(n)}).on("keydown",function(n){t.keyDown(n)}).on("keypress",function(n){t.keyPress(n)});i.on("click",function(){n(this).find("input").focus()})}if(t.type=="file"){n(t.el).css("outline","none");i.on("click",function(r){(n(t.el).focus(),n(t.el).prop("readonly")||n(t.el).prop("disabled"))||(t.blur(r),t.resize(),setTimeout(function(){i.find("input").click()},10))}).on("dragenter",function(){n(t.el).prop("readonly")||n(t.el).prop("disabled")||n(i).addClass("w2ui-file-dragover")}).on("dragleave",function(r){if(!n(t.el).prop("readonly")&&!n(t.el).prop("disabled")){var u=n(r.target).parents(".w2ui-field-helper");u.length===0&&n(i).removeClass("w2ui-file-dragover")}}).on("drop",function(r){var f,u,e;if(!n(t.el).prop("readonly")&&!n(t.el).prop("disabled")){for(n(i).removeClass("w2ui-file-dragover"),f=r.originalEvent.dataTransfer.files,u=0,e=f.length;u<e;u++)t.addFile.call(t,f[u]);r.preventDefault();r.stopPropagation()}}).on("dragover",function(n){n.preventDefault();n.stopPropagation()});i.find("input").on("click",function(n){n.stopPropagation()}).on("change",function(){if(typeof this.files!="undefined")for(var n=0,i=this.files.length;n<i;n++)t.addFile.call(t,this.files[n])})}t.refresh()},addFile:function(t){var r=this,i=this.options,f=n(r.el).data("selected"),o={name:t.name,type:t.type,modified:t.lastModifiedDate,size:t.size,content:null,file:t},s=0,h=0,u,e,c,l;if(f)for(e=0;e<f.length;e++){if(f[e].name==t.name&&f[e].size==t.size)return;s+=f[e].size;h++}if(c=r.trigger({phase:"before",type:"add",target:r.el,file:o,total:h,totalSize:s}),c.isCancelled!==!0){if(i.maxFileSize!==0&&o.size>i.maxFileSize){u="Maximum file size is "+w2utils.formatSize(i.maxFileSize);i.silent===!1&&n(r.el).w2tag(u);console.log("ERROR: "+u);return}if(i.maxSize!==0&&s+o.size>i.maxSize){u="Maximum total size is "+w2utils.formatSize(i.maxSize);i.silent===!1&&n(r.el).w2tag(u);console.log("ERROR: "+u);return}if(i.max!==0&&h>=i.max){u="Maximum number of files is "+i.max;i.silent===!1&&n(r.el).w2tag(u);console.log("ERROR: "+u);return}f.push(o);typeof FileReader!="undefined"&&i.readContent===!0?(l=new FileReader,l.onload=function(){return function(t){var i=t.target.result,u=i.indexOf(",");o.content=i.substr(u+1);r.refresh();n(r.el).trigger("change");r.trigger(n.extend(c,{phase:"after"}))}}(),l.readAsDataURL(t)):(r.refresh(),n(r.el).trigger("change"))}},normMenu:function(t){var r,i;if(n.isArray(t)){for(i=0;i<t.length;i++)typeof t[i]=="string"?t[i]={id:t[i],text:t[i]}:(t[i].text!=null&&t[i].id==null&&(t[i].id=t[i].text),t[i].text==null&&t[i].id!=null&&(t[i].text=t[i].id),t[i].caption!=null&&(t[i].text=t[i].caption));return t}if(typeof t=="function")return this.normMenu(t());if(typeof t=="object"){r=[];for(i in t)r.push({id:i,text:t[i]});return r}},getMonthHTML:function(n,t,i){var f=new Date,rt=w2utils.settings.fullmonths,g=["31","28","31","30","31","30","31","31","30","31","30","31"],ut=f.getFullYear()+"/"+(Number(f.getMonth())+1)+"/"+f.getDate(),p=w2utils.settings.fulldays.slice(),v=w2utils.settings.shortdays.slice(),r,o,w,s,e,h,nt,u,b,d;for(w2utils.settings.weekStarts!="M"&&(p.unshift(p.pop()),v.unshift(v.pop())),r=this.options,r==null&&(r={}),t=w2utils.isInt(t)?parseInt(t):f.getFullYear(),n=w2utils.isInt(n)?parseInt(n):f.getMonth()+1,n>12&&(n-=12,t++),(n<1||n===0)&&(n+=12,t--),g[1]=t/4==Math.floor(t/4)?"29":"28",r.current=n+"/"+t,f=new Date(t,n-1,1),o=f.getDay(),w="",s=0;s<v.length;s++)w+='<td title="'+p[s]+'">'+v[s]+"<\/td>";for(e='<div class="w2ui-calendar-title title">    <div class="w2ui-calendar-previous previous"> <div><\/div> <\/div>    <div class="w2ui-calendar-next next"> <div><\/div> <\/div> '+rt[n-1]+", "+t+'<\/div><table class="w2ui-calendar-days" cellspacing="0"><tbody>    <tr class="w2ui-day-title">'+w+"<\/tr>    <tr>",h=1,w2utils.settings.weekStarts!="M"&&o++,this.type==="datetime"&&(nt=w2utils.isDateTime(i,r.format,!0),i=w2utils.formatDate(nt,w2utils.settings.dateFormat)),u=1;u<43;u++){if(o===0&&u==1){for(b=0;b<6;b++)e+='<td class="w2ui-day-empty">&#160;<\/td>';u+=6}else if(u<o||h>g[n-1]){e+='<td class="w2ui-day-empty">&#160;<\/td>';u%7==0&&(e+="<\/tr><tr>");continue}var c=t+"/"+n+"/"+h,k=new Date(c),y="";k.getDay()===6&&(y=" w2ui-saturday");k.getDay()===0&&(y=" w2ui-sunday");c==ut&&(y+=" w2ui-today");var ft=h,tt="",it="",l,a;this.type==="datetime"?(l=w2utils.formatDateTime(c,r.format),a=w2utils.formatDate(c,w2utils.settings.dateFormat)):(l=w2utils.formatDate(c,r.format),a=l);r.colored&&r.colored[a]!==undefined&&(d=r.colored[a].split(":"),it="background-color: "+d[0]+";",tt="color: "+d[1]+";");e+='<td class="'+(this.inRange(l,!0)?"w2ui-date "+(a==i?"w2ui-date-selected":""):"w2ui-blocked")+y+'"    style="'+tt+it+'" date="'+l+'" data-date="'+k+'">'+ft+"<\/td>";(u%7==0||o===0&&u==1)&&(e+="<\/tr><tr>");h++}return e+"<\/tr><\/tbody><\/table>"},getYearHTML:function(){for(var n,i=w2utils.settings.shortmonths,f=w2utils.settings.dateStartYear,e=w2utils.settings.dateEndYear,r="",u="",t=0;t<i.length;t++)r+='<div class="w2ui-jump-month" name="'+t+'">'+i[t]+"<\/div>";for(n=f;n<=e;n++)u+='<div class="w2ui-jump-year" name="'+n+'">'+n+"<\/div>";return"<div>"+r+"<\/div><div>"+u+"<\/div>"},getHourHTML:function(){var t=[],i=this.options,u,n,r,f,e,o,s;for(i==null&&(i={format:w2utils.settings.timeFormat}),u=i.format.indexOf("h24")>-1,n=0;n<24;n++)r=(n>=12&&!u?n-12:n)+":00"+(u?"":n<12?" am":" pm"),n!=12||u||(r="12:00 pm"),t[Math.floor(n/8)]||(t[Math.floor(n/8)]=""),f=this.fromMin(this.toMin(r)),e=this.fromMin(this.toMin(r)+59),this.type==="datetime"&&(o=w2utils.isDateTime(this.el.value,i.format,!0),s=i.format.split("|")[0].trim(),f=w2utils.formatDate(o,s)+" "+f,e=w2utils.formatDate(o,s)+" "+e),t[Math.floor(n/8)]+='<div class="'+(this.inRange(f)||this.inRange(e)?"w2ui-time ":"w2ui-blocked")+'" hour="'+n+'">'+r+"<\/div>";return'<div class="w2ui-calendar">   <div class="w2ui-calendar-title">'+w2utils.lang("Select Hour")+'<\/div>   <div class="w2ui-calendar-time"><table><tbody><tr>       <td>'+t[0]+"<\/td>       <td>"+t[1]+"<\/td>       <td>"+t[2]+"<\/td>   <\/tr><\/tbody><\/table><\/div><\/div>"},getMinHTML:function(n){var r,u,i,t,s,h;for(n==null&&(n=0),r=this.options,r==null&&(r={format:w2utils.settings.timeFormat}),u=r.format.indexOf("h24")>-1,i=[],t=0;t<60;t+=5){var o=(n>12&&!u?n-12:n)+":"+(t<10?0:"")+t+" "+(u?"":n<12?"am":"pm"),f=o,e=t<20?0:t<40?1:2;i[e]||(i[e]="");this.type==="datetime"&&(s=w2utils.isDateTime(this.el.value,r.format,!0),h=r.format.split("|")[0].trim(),f=w2utils.formatDate(s,h)+" "+f);i[e]+='<div class="'+(this.inRange(f)?"w2ui-time ":"w2ui-blocked")+'" min="'+t+'">'+o+"<\/div>"}return'<div class="w2ui-calendar">   <div class="w2ui-calendar-title">'+w2utils.lang("Select Minute")+'<\/div>   <div class="w2ui-calendar-time"><table><tbody><tr>       <td>'+i[0]+"<\/td>       <td>"+i[1]+"<\/td>       <td>"+i[2]+"<\/td>   <\/tr><\/tbody><\/table><\/div><\/div>"},toMin:function(n){if(typeof n!="string")return null;var t=n.split(":");if(t.length===2)t[0]=parseInt(t[0]),t[1]=parseInt(t[1]),n.indexOf("pm")!=-1&&t[0]!=12&&(t[0]+=12);else return null;return t[0]*60+t[1]},fromMin:function(n){n>=1440&&(n=n%1440);n<0&&(n=1440+n);var t=Math.floor(n/60),r=(n%60<10?"0":"")+n%60,i=this.options;return i==null&&(i={format:w2utils.settings.timeFormat}),i.format.indexOf("h24")!=-1?t+":"+r:(t<=12?t:t-12)+":"+r+" "+(t>=12?"pm":"am")}};n.extend(t.prototype,w2utils.event);w2obj.field=t}(jQuery),function(n){var t=function(t){this.name=null;this.header="";this.box=null;this.url="";this.routeData={};this.formURL="";this.formHTML="";this.page=0;this.recid=0;this.fields=[];this.actions={};this.record={};this.original={};this.postData={};this.httpHeaders={};this.method=null;this.toolbar={};this.tabs={};this.style="";this.focus=0;this.isGenerated=!1;this.last={xhr:null};n.extend(!0,this,w2obj.form,t)};n.fn.w2form=function(i){var l,o,f,u,e;if(n.isPlainObject(i)){if(e=this,!w2utils.checkName(i,"w2form"))return;var s=i.record,h=i.original,a=i.fields,v=i.toolbar,c=i.tabs,r=new t(i);if(n.extend(r,{record:{},original:{},fields:[],tabs:{},toolbar:{},handlers:[]}),n.isArray(c))for(n.extend(!0,r.tabs,{tabs:[]}),l=0;l<c.length;l++)o=c[l],typeof o=="object"?(r.tabs.tabs.push(o),o.active===!0&&(r.tabs.active=o.id)):r.tabs.tabs.push({id:o,caption:o});else n.extend(!0,r.tabs,c);if(n.extend(!0,r.toolbar,v),a)for(u=0;u<a.length;u++)f=n.extend(!0,{},a[u]),f.name==null&&f.field!=null&&(f.name=f.field),f.field==null&&f.name!=null&&(f.field=f.name),r.fields[u]=f;for(u in s)r.record[u]=n.isPlainObject(s[u])?n.extend(!0,{},s[u]):s[u];for(u in h)r.original[u]=n.isPlainObject(h[u])?n.extend(!0,{},h[u]):h[u];return e.length>0&&(r.box=e[0]),r.formURL!==""?n.get(r.formURL,function(t){r.formHTML=t;r.isGenerated=!0;(n(r.box).length!==0||t.length!==0)&&(n(r.box).html(t),r.render(r.box))}):r.formHTML!==""||(r.formHTML=n(this).length!==0&&n.trim(n(this).html())!==""?n(this).html():r.generateHTML()),w2ui[r.name]=r,r.formURL===""&&(String(r.formHTML).indexOf("w2ui-page")==-1&&(r.formHTML='<div class="w2ui-page page-0">'+r.formHTML+"<\/div>"),n(r.box).html(r.formHTML),r.isGenerated=!0,r.render(r.box)),r}return(e=w2ui[n(this).attr("name")],!e)?null:arguments.length>0?(e[i]&&e[i].apply(e,Array.prototype.slice.call(arguments,1)),this):e};t.prototype={onRequest:null,onLoad:null,onValidate:null,onSubmit:null,onProgress:null,onSave:null,onChange:null,onRender:null,onRefresh:null,onResize:null,onDestroy:null,onAction:null,onToolbar:null,onError:null,msgNotJSON:"Returned data is not in valid JSON format.",msgAJAXerror:"AJAX error. See console for more details.",msgRefresh:"Refreshing...",msgSaving:"Saving...",get:function(n,t){var u,r,i;if(arguments.length===0){for(u=[],r=0;r<this.fields.length;r++)this.fields[r].name!=null&&u.push(this.fields[r].name);return u}for(i=0;i<this.fields.length;i++)if(this.fields[i].name==n)return t===!0?i:this.fields[i];return null},set:function(t,i){for(var r=0;r<this.fields.length;r++)if(this.fields[r].name==t)return n.extend(this.fields[r],i),this.refresh(),!0;return!1},show:function(){for(var n,t=0,i=0;i<arguments.length;i++)n=this.get(arguments[i]),n&&n.hidden&&(n.hidden=!1,t++);return t>0&&this.refresh(),t},hide:function(){for(var n,t=0,i=0;i<arguments.length;i++)n=this.get(arguments[i]),n&&!n.hidden&&(n.hidden=!0,t++);return t>0&&this.refresh(),t},enable:function(){for(var n,t=0,i=0;i<arguments.length;i++)n=this.get(arguments[i]),n&&n.disabled&&(n.disabled=!1,t++);return t>0&&this.refresh(),t},disable:function(){for(var n,t=0,i=0;i<arguments.length;i++)n=this.get(arguments[i]),n&&!n.disabled&&(n.disabled=!0,t++);return t>0&&this.refresh(),t},reload:function(n){var t=typeof this.url!="object"?this.url:this.url.get;t&&this.recid!==0&&this.recid!=null?this.request(n):typeof n=="function"&&n()},clear:function(){this.recid=0;this.record={};n().w2tag();this.refresh()},error:function(t){var r=this,i=this.trigger({target:this.name,type:"error",message:t,xhr:this.last.xhr});if(i.isCancelled===!0){typeof callBack=="function"&&callBack();return}setTimeout(function(){r.message(t)},1);this.trigger(n.extend(i,{phase:"after"}))},message:function(t){typeof t=="string"&&(t={width:t.length<300?350:550,height:t.length<300?170:250,body:'<div class="w2ui-centered">'+t+"<\/div>",buttons:'<button class="w2ui-btn" onclick="w2ui[\''+this.name+"'].message()\">Ok<\/button>",onOpen:function(t){setTimeout(function(){n(t.box).find(".w2ui-btn").focus()},25)}});w2utils.message.call(this,{box:this.box,path:"w2ui."+this.name,title:".w2ui-form-header:visible",body:".w2ui-form-box"},t)},validate:function(t){var r,o,i,f,e,s,u;for(t==null&&(t=!0),n().w2tag(),r=[],o=0;o<this.fields.length;o++){i=this.fields[o];this.record[i.name]==null&&(this.record[i.name]="");switch(i.type){case"int":this.record[i.name]&&!w2utils.isInt(this.record[i.name])&&r.push({field:i,error:w2utils.lang("Not an integer")});break;case"float":this.record[i.name]&&!w2utils.isFloat(this.record[i.name])&&r.push({field:i,error:w2utils.lang("Not a float")});break;case"money":this.record[i.name]&&!w2utils.isMoney(this.record[i.name])&&r.push({field:i,error:w2utils.lang("Not in money format")});break;case"color":case"hex":this.record[i.name]&&!w2utils.isHex(this.record[i.name])&&r.push({field:i,error:w2utils.lang("Not a hex number")});break;case"email":this.record[i.name]&&!w2utils.isEmail(this.record[i.name])&&r.push({field:i,error:w2utils.lang("Not a valid email")});break;case"checkbox":this.record[i.name]=this.record[i.name]==!0?1:0;break;case"date":i.options.format||(i.options.format=w2utils.settings.dateFormat);this.record[i.name]&&!w2utils.isDate(this.record[i.name],i.options.format)&&r.push({field:i,error:w2utils.lang("Not a valid date")+": "+i.options.format})}f=this.record[i.name];i.required&&(f===""||n.isArray(f)&&f.length===0||n.isPlainObject(f)&&n.isEmptyObject(f))&&r.push({field:i,error:w2utils.lang("Required field")});i.equalto&&this.record[i.name]!=this.record[i.equalto]&&r.push({field:i,error:w2utils.lang("Field should be equal to ")+i.equalto})}if(e=this.trigger({phase:"before",target:this.name,type:"validate",errors:r}),e.isCancelled!==!0){if(t)for(s=0;s<e.errors.length;s++)(u=e.errors[s],u.field!=null)&&(u.field.type=="radio"?n(n(u.field.el).parents("div")[0]).w2tag(u.error,{"class":"w2ui-error"}):["enum","file"].indexOf(u.field.type)!=-1?function(t){setTimeout(function(){var i=n(t.field.el).data("w2field").helpers.multi;n(t.field.el).w2tag(t.error);n(i).addClass("w2ui-error")},1)}(u):n(u.field.el).w2tag(u.error,{"class":"w2ui-error"}),this.goto(r[0].field.page));return this.trigger(n.extend(e,{phase:"after"})),r}},getChanges:function(){var t=function(i,r,u){for(var f in i)typeof i[f]=="object"?(u[f]=t(i[f],r[f]||{},{}),(!u[f]||n.isEmptyObject(u[f]))&&delete u[f]):i[f]!=r[f]&&(u[f]=i[f]);return u};return t(this.record,this.original,{})},request:function(t,i){var u=this,e,f,o,s,h,r;if(typeof t=="function"&&(i=t,t=null),t==null&&(t={}),this.url&&(typeof this.url!="object"||this.url.get)){if(this.recid==null&&(this.recid=0),e={},e.cmd="get",e.recid=this.recid,e.name=this.name,n.extend(e,this.postData),n.extend(e,t),f=this.trigger({phase:"before",type:"request",target:this.name,url:this.url,postData:e,httpHeaders:this.httpHeaders}),f.isCancelled===!0){typeof i=="function"&&i({status:"error",message:"Request aborted."});return}if(this.record={},this.original={},this.lock(w2utils.lang(this.msgRefresh)),o=f.url,typeof f.url=="object"&&f.url.get&&(o=f.url.get),this.last.xhr)try{this.last.xhr.abort()}catch(c){}if(!n.isEmptyObject(u.routeData)&&(s=w2utils.parseRoute(o),s.keys.length>0))for(h=0;h<s.keys.length;h++)u.routeData[s.keys[h].name]!=null&&(o=o.replace(new RegExp(":"+s.keys[h].name,"g"),u.routeData[s.keys[h].name]));r={type:"POST",url:o,data:f.postData,headers:f.httpHeaders,dataType:"text"};switch(w2utils.settings.dataType){case"HTTP":r.data=String(n.param(r.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]");break;case"HTTPJSON":r.data={request:JSON.stringify(r.data)};break;case"RESTFULL":r.type="GET";r.data=String(n.param(r.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]");break;case"RESTFULLJSON":r.type="GET";r.data=JSON.stringify(r.data);r.contentType="application/json";break;case"JSON":r.type="POST";r.data=JSON.stringify(r.data);r.contentType="application/json"}this.method&&(r.type=this.method);this.last.xhr=n.ajax(r).done(function(t,r,f){var o,t,e;if(u.unlock(),o=u.trigger({phase:"before",target:u.name,type:"load",xhr:f}),o.isCancelled===!0){typeof i=="function"&&i({status:"error",message:"Request aborted."});return}if(e=u.last.xhr.responseText,r!="error"){if(e!=null&&e!==""){if(typeof e=="object")t=e;else try{eval("data = "+e)}catch(s){}t==null&&(t={status:"error",message:w2utils.lang(u.msgNotJSON),responseText:e});t.status=="error"?u.error(w2utils.lang(t.message)):(u.record=n.extend({},t.record),u.original=n.extend({},t.record))}}else u.error("AJAX Error "+f.status+": "+f.statusText),t={status:"error",message:w2utils.lang(u.msgAJAXerror),responseText:e};u.trigger(n.extend(o,{phase:"after"}));u.refresh();typeof i=="function"&&i(t)}).fail(function(t,i,r){var o={status:i,error:r,rawResponseText:t.responseText},e=u.trigger({phase:"before",type:"error",error:o,xhr:t}),f;if(e.isCancelled!==!0){if(i!="abort"){try{f=n.parseJSON(t.responseText)}catch(s){}console.log("ERROR: Server communication failed.","\n   EXPECTED:",{status:"success",items:[{id:1,text:"item"}]},"\n         OR:",{status:"error",message:"error message"},"\n   RECEIVED:",typeof f=="object"?f:t.responseText)}u.trigger(n.extend(e,{phase:"after"}))}});this.trigger(n.extend(f,{phase:"after"}))}},submit:function(n,t){return this.save(n,t)},save:function(t,i){var r=this,u;if(n(this.box).find(":focus").change(),typeof t=="function"&&(i=t,t=null),u=r.validate(!0),u.length===0){if(t==null&&(t={}),!r.url||typeof r.url=="object"&&!r.url.save){console.log("ERROR: Form cannot be saved because no url is defined.");return}r.lock(w2utils.lang(r.msgSaving)+' <span id="'+r.name+'_progress"><\/span>');setTimeout(function(){var e={},f,o,s,h,u;if(e.cmd="save",e.recid=r.recid,e.name=r.name,n.extend(e,r.postData),n.extend(e,t),r.fields.forEach(function(n){n.type=="file"&&Array.isArray(r.record[n.field])&&r.record[n.field].forEach(function(n){delete n.file})}),e.record=n.extend(!0,{},r.record),f=r.trigger({phase:"before",type:"submit",target:r.name,url:r.url,postData:e,httpHeaders:r.httpHeaders}),f.isCancelled!==!0){if(o=f.url,typeof f.url=="object"&&f.url.save&&(o=f.url.save),r.last.xhr)try{r.last.xhr.abort()}catch(c){}if(!n.isEmptyObject(r.routeData)&&(s=w2utils.parseRoute(o),s.keys.length>0))for(h=0;h<s.keys.length;h++)r.routeData[s.keys[h].name]!=null&&(o=o.replace(new RegExp(":"+s.keys[h].name,"g"),r.routeData[s.keys[h].name]));u={type:"POST",url:o,data:f.postData,headers:f.httpHeaders,dataType:"text",xhr:function(){var t=new window.XMLHttpRequest;return t.upload.addEventListener("progress",function(t){var i,u;if(t.lengthComputable){if(i=r.trigger({phase:"before",type:"progress",total:t.total,loaded:t.loaded,originalEvent:t}),i.isCancelled===!0)return;u=Math.round(t.loaded/t.total*100);n("#"+r.name+"_progress").text(""+u+"%");r.trigger(n.extend(i,{phase:"after"}))}},!1),t}};switch(w2utils.settings.dataType){case"HTTP":u.data=String(n.param(u.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]");break;case"HTTPJSON":u.data={request:JSON.stringify(u.data)};break;case"RESTFULL":r.recid!==0&&r.recid!=null&&(u.type="PUT");u.data=String(n.param(u.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]");break;case"RESTFULLJSON":r.recid!==0&&r.recid!=null&&(u.type="PUT");u.data=JSON.stringify(u.data);u.contentType="application/json";break;case"JSON":u.type="POST";u.data=JSON.stringify(u.data);u.contentType="application/json"}this.method&&(u.type=this.method);r.last.xhr=n.ajax(u).done(function(t,u,f){var o,t,e;if(r.unlock(),o=r.trigger({phase:"before",target:r.name,type:"save",xhr:f,status:u}),o.isCancelled!==!0){if(e=f.responseText,u!="error"){if(e!=null&&e!==""){if(typeof e=="object")t=e;else try{eval("data = "+e)}catch(s){}t==null&&(t={status:"error",message:w2utils.lang(r.msgNotJSON),responseText:e});t.status=="error"?r.error(w2utils.lang(t.message)):r.original=n.extend({},r.record)}}else r.error("AJAX Error "+f.status+": "+f.statusText),t={status:"error",message:w2utils.lang(r.msgAJAXerror),responseText:e};r.trigger(n.extend(o,{phase:"after"}));r.refresh();t.status=="success"&&typeof i=="function"&&i(t)}}).fail(function(t,i,u){var f={status:i,error:u,rawResponseText:t.responseText},e=r.trigger({phase:"before",type:"error",error:f,xhr:t});e.isCancelled!==!0&&(console.log("ERROR: server communication failed. The server should return",{status:"success"},"OR",{status:"error",message:"error message"},", instead the AJAX request produced this: ",f),r.trigger(n.extend(e,{phase:"after"})))});r.trigger(n.extend(f,{phase:"after"}))}},50)}},lock:function(){var n=Array.prototype.slice.call(arguments,0);n.unshift(this.box);setTimeout(function(){w2utils.lock.apply(window,n)},10)},unlock:function(n){var t=this.box;setTimeout(function(){w2utils.unlock(t,n)},25)},goto:function(t){this.page!==t&&(t!=null&&(this.page=t),n(this.box).data("auto-size")===!0&&n(this.box).height(0),this.refresh())},generateHTML:function(){for(var t,f,i,r,y,b,p,h,s,c,w,u=[],l="",a,v,e,o=0;o<this.fields.length;o++){e="";t=this.fields[o];t.html==null&&(t.html={});t.options==null&&(t.options={});t.html=n.extend(!0,{caption:"",span:6,attr:"",text:"",style:"",page:0,column:0},t.html);a==null&&(a=t.html.page);v==null&&(v=t.html.column);t.html.caption===""&&(t.html.caption=t.name);f='<input name="'+t.name+'" class="w2ui-input" type="text" '+t.html.attr+' tabindex="'+(o+1)+'"/>';switch(t.type){case"pass":case"password":f='<input name="'+t.name+'" class="w2ui-input" type = "password" '+t.html.attr+' tabindex="'+(o+1)+'"/>';break;case"checkbox":f='<input name="'+t.name+'" class="w2ui-input" type="checkbox" '+t.html.attr+' tabindex="'+(o+1)+'"/>';break;case"radio":for(f="",i=t.options.items?t.options.items:t.html.items,n.isArray(i)||(i=[]),i.length>0&&(i=w2obj.field.prototype.normMenu(i)),r=0;r<i.length;r++)f+='<label><input name="'+t.name+'" class="w2ui-input" type = "radio" '+t.html.attr+' value="'+i[r].id+'"/>&#160;'+i[r].text+"<\/label><br/>";break;case"select":for(f='<select name="'+t.name+'" class="w2ui-input" '+t.html.attr+' tabindex="'+(o+1)+'">',i=t.options.items?t.options.items:t.html.items,n.isArray(i)||(i=[]),i.length>0&&(i=w2obj.field.prototype.normMenu(i)),r=0;r<i.length;r++)f+='<option value="'+i[r].id+'">'+i[r].text+"<\/option>";f+="<\/select>";break;case"textarea":f='<textarea name="'+t.name+'" class="w2ui-input" '+t.html.attr+' tabindex="'+(o+1)+'"><\/textarea>';break;case"toggle":f='<input name="'+t.name+'" type="checkbox" '+t.html.attr+' class="w2ui-input w2ui-toggle" tabindex="'+(o+1)+'"/><div><div><\/div><\/div>';break;case"html":case"custom":case"empty":f=""}l!==""&&(a!=t.html.page||v!=t.html.column||t.html.group&&l!=t.html.group)&&(u[a][v]+="\n   <\/div>",l="");t.html.group&&l!=t.html.group&&(e+='\n   <div class="w2ui-group-title">'+t.html.group+'<\/div>\n   <div class="w2ui-group">',l=t.html.group);e+='\n      <div class="w2ui-field '+(t.html.span!=null?"w2ui-span"+t.html.span:"")+'" style="'+t.html.style+'">\n         <label>'+w2utils.lang(t.html.caption)+"<\/label>\n         <div>"+f+w2utils.lang(t.html.text)+"<\/div>\n      <\/div>";u[t.html.page]==null&&(u[t.html.page]=[]);u[t.html.page][t.html.column]==null&&(u[t.html.page][t.html.column]="");u[t.html.page][t.html.column]+=e;a=t.html.page;v=t.html.column}if(l!==""&&(u[a][v]+="\n   <\/div>"),this.tabs.tabs)for(r=0;r<this.tabs.tabs.length;r++)u[r]==null&&(u[r]=[]);if(y="",!n.isEmptyObject(this.actions)){b="";y+='\n<div class="w2ui-buttons">';for(p in this.actions)h=this.actions[p],s={caption:"",style:"","class":""},n.isPlainObject(h)?(h.caption&&(s.caption=h.caption),h.style&&(s.style=h.style),h["class"]&&(s["class"]=h["class"])):(s.caption=p,s["class"]=["save","update","create"].indexOf(p.toLowerCase())!=-1?"w2ui-btn-blue":""),y+='\n    <button name="'+p+'" class="w2ui-btn '+s["class"]+'" style="'+s.style+'">'+w2utils.lang(s.caption)+"<\/button>";y+="\n<\/div>"}for(e="",c=0;c<u.length;c++){for(e+='<div class="w2ui-page page-'+c+'" '+(c===0?"":'style="display: none;"')+'><div class="w2ui-column-container" style="display: flex;">',w=0;w<u[c].length;w++)e+='<div class="w2ui-column col-'+w+'">'+(u[c][w]||"")+"\n<\/div>";e+="\n<\/div><\/div>"}return e+y},action:function(t,i){var r=this.actions[t],u=r,f;(n.isPlainObject(r)&&r.onClick&&(u=r.onClick),f=this.trigger({phase:"before",target:t,type:"action",click:u,originalEvent:i}),f.isCancelled!==!0)&&(typeof u=="function"&&u.call(this,i),this.trigger(n.extend(f,{phase:"after"})))},resize:function(){function s(){h.width(n(t.box).width()).height(n(t.box).height());r.css("top",t.header!==""?w2utils.getSize(i,"height"):0);f.css("top",(t.header!==""?w2utils.getSize(i,"height"):0)+(typeof t.toolbar=="object"&&n.isArray(t.toolbar.items)&&t.toolbar.items.length>0?w2utils.getSize(r,"height"):0));e.css("top",(t.header!==""?w2utils.getSize(i,"height"):0)+(typeof t.toolbar=="object"&&n.isArray(t.toolbar.items)&&t.toolbar.items.length>0?w2utils.getSize(r,"height")+5:0)+(typeof t.tabs=="object"&&n.isArray(t.tabs.tabs)&&t.tabs.tabs.length>0?w2utils.getSize(f,"height")+5:0));e.css("bottom",u.length>0?w2utils.getSize(u,"height"):0)}var t=this,o=this.trigger({phase:"before",target:this.name,type:"resize"});if(o.isCancelled!==!0){var h=n(this.box).find("> div.w2ui-form-box"),i=n(this.box).find("> div .w2ui-form-header"),r=n(this.box).find("> div .w2ui-form-toolbar"),f=n(this.box).find("> div .w2ui-form-tabs"),e=n(this.box).find("> div .w2ui-page"),c=n(this.box).find("> div .w2ui-page.page-"+this.page),l=n(this.box).find("> div .w2ui-page.page-"+this.page+" > div"),u=n(this.box).find("> div .w2ui-buttons");s();(parseInt(n(this.box).height())===0||n(this.box).data("auto-size")===!0)&&(n(this.box).height((i.length>0?w2utils.getSize(i,"height"):0)+(typeof this.tabs=="object"&&n.isArray(this.tabs.tabs)&&this.tabs.tabs.length>0?w2utils.getSize(f,"height"):0)+(typeof this.toolbar=="object"&&n.isArray(this.toolbar.items)&&this.toolbar.items.length>0?w2utils.getSize(r,"height"):0)+(e.length>0?w2utils.getSize(l,"height")+w2utils.getSize(c,"+height")+12:0)+(u.length>0?w2utils.getSize(u,"height"):0)),n(this.box).data("auto-size",!0));s();this.toolbar&&this.toolbar.resize&&this.toolbar.resize();this.tabs&&this.tabs.resize&&this.tabs.resize();t.trigger(n.extend(o,{phase:"after"}))}},refresh:function(t){var y=(new Date).getTime(),u=this,l,s,c,e,t,i,v,a,r,h,o,f;if(this.box&&this.isGenerated&&n(this.box).html()!=null&&(l=this.trigger({phase:"before",target:this.name,type:"refresh",page:this.page,field:t}),l.isCancelled!==!0)){for(t!=null?(s=u.get(t,!0),c=s+1):(n(this.box).find("input, textarea, select").each(function(t,i){var o=n(i).attr("name")!=null?n(i).attr("name"):n(i).attr("id"),e=u.get(o),f,r;if(e&&(f=n(i).parents(".w2ui-page"),f.length>0))for(r=0;r<100;r++)if(f.hasClass("page-"+r)){e.page=r;break}}),n(this.box).find(".w2ui-page").hide(),n(this.box).find(".w2ui-page.page-"+this.page).show(),n(this.box).find(".w2ui-form-header").html(this.header),typeof this.tabs=="object"&&n.isArray(this.tabs.tabs)&&this.tabs.tabs.length>0?(n("#form_"+this.name+"_tabs").show(),this.tabs.active=this.tabs.tabs[this.page].id,this.tabs.refresh()):n("#form_"+this.name+"_tabs").hide(),typeof this.toolbar=="object"&&n.isArray(this.toolbar.items)&&this.toolbar.items.length>0?(n("#form_"+this.name+"_toolbar").show(),this.toolbar.refresh()):n("#form_"+this.name+"_toolbar").hide(),s=0,c=this.fields.length),e=s;e<c;e++){t=this.fields[e];t.name==null&&t.field!=null&&(t.name=t.field);t.field==null&&t.name!=null&&(t.field=t.name);t.$el=n(this.box).find('[name="'+String(t.name).replace(/\\/g,"\\\\")+'"]');t.el=t.$el[0];t.el==null&&console.log('ERROR: Cannot associate field "'+t.name+'" with html control. Make sure html control exists with the same name.');t.el&&(t.el.id=t.name);o=n(t).data("w2field");o&&o.clear();n(t.$el).off("change").on("change",function(){var r=this.value,s=u.record[this.name]!=null?u.record[this.name]:"",f=u.get(this.name),e,o,i,h,t,c;if(["list","enum","file"].indexOf(f.type)!=-1&&n(this).data("selected")){if(e=n(this).data("selected"),o=u.record[this.name],n.isArray(e))for(r=[],i=0;i<e.length;i++)r[i]=n.extend(!0,{},e[i]);if(n.isPlainObject(e)&&(r=n.extend(!0,{},e)),n.isArray(o))for(s=[],i=0;i<o.length;i++)s[i]=n.extend(!0,{},o[i]);n.isPlainObject(o)&&(s=n.extend(!0,{},o))}if(["toggle","checkbox"].indexOf(f.type)!=-1&&(r=n(this).prop("checked")?n(this).prop("value")=="on"?!0:n(this).prop("value"):!1),["int","float","percent","money","currency"].indexOf(f.type)!=-1&&(r=n(this).data("w2field").clean(r)),r!==s){if(h=u.trigger({phase:"before",target:this.name,type:"change",value_new:r,value_previous:s}),h.isCancelled===!0){n(this).val(u.record[this.name]);return}t=this.value;this.type=="select"&&(t=this.value);this.type=="checkbox"&&(t=this.checked?!0:!1);this.type=="radio"&&f.$el.each(function(n,i){i.checked&&(t=i.value)});["int","float","percent","money","currency","list","combo","enum","file","toggle"].indexOf(f.type)!=-1&&(t=r);["enum","file"].indexOf(f.type)!=-1&&t.length>0&&(c=n(f.el).data("w2field").helpers.multi,n(c).removeClass("w2ui-error"));(t===""||t==null||n.isArray(t)&&t.length===0||n.isPlainObject(t)&&n.isEmptyObject(t))&&(t=null);u.record[this.name]=t;u.trigger(n.extend(h,{phase:"after"}))}});t.required?n(t.el).parent().parent().addClass("w2ui-required"):n(t.el).parent().parent().removeClass("w2ui-required");t.disabled!=null&&(t.disabled?n(t.el).prop("readonly",!0):n(t.el).prop("readonly",!1));t.hidden?n(t.el).parent().parent().hide():n(t.el).parent().parent().show()}for(n(this.box).find("button, input[type=button]").each(function(t,i){n(i).off("click").on("click",function(n){var t=this.value;this.id&&(t=this.id);this.name&&(t=this.name);u.action(t,n)})}),e=s;e<c;e++)if(t=this.fields[e],i=this.record[t.name]!=null?this.record[t.name]:"",t.el){n(t.el).hasClass("w2ui-input")||n(t.el).addClass("w2ui-input");t.type=String(t.type).toLowerCase();t.options||(t.options={});switch(t.type){case"text":case"textarea":case"email":case"pass":case"password":t.el.value=i;break;case"int":case"float":case"money":case"currency":case"percent":t.el.value=i;n(t.el).w2field(n.extend({},t.options,{type:t.type}));break;case"hex":case"alphanumeric":case"color":case"date":case"time":t.el.value=i;n(t.el).w2field(n.extend({},t.options,{type:t.type}));break;case"toggle":w2utils.isFloat(i)&&(i=parseFloat(i));n(t.el).prop("checked",i?!0:!1);this.record[t.name]=i?i:!1;break;case"list":case"combo":if(t.type=="list"){for(v=n.isPlainObject(i)?i.id:n.isPlainObject(t.options.selected)?t.options.selected.id:i,t.options.items||(t.options.items=[]),r=t.options.items,n.isArray(r)&&r.length>0&&!n.isPlainObject(r[0])&&(t.options.items=w2obj.field.prototype.normMenu(r)),f=0;f<t.options.items.length;f++)if(a=t.options.items[f],a.id==v){i=n.extend(!0,{},a);u.record[t.name]=i;break}}else t.el.value=t.type!="combo"||n.isPlainObject(i)?n.isPlainObject(i)&&i.text!=null?i.text:"":i;n.isPlainObject(i)||(i={});n(t.el).w2field(n.extend({},t.options,{type:t.type,selected:i}));break;case"enum":case"file":n.isArray(i)||(i=[]);n(t.el).w2field(n.extend({},t.options,{type:t.type,selected:i}));break;case"select":if(r=t.options.items,r!=null&&r.length>0)for(r=w2obj.field.prototype.normMenu(r),n(t.el).html(""),h=0;h<r.length;h++)n(t.el).append('<option value="'+r[h].id+'">'+r[h].text+"<\/option");n(t.el).val(i);break;case"radio":n(t.$el).prop("checked",!1).each(function(t,r){n(r).val()==i&&n(r).prop("checked",!0)});break;case"checkbox":n(t.el).prop("checked",i?!0:!1);break;case"html":case"custom":case"empty":break;default:n(t.el).val(i);n(t.el).w2field(n.extend({},t.options,{type:t.type}))}}for(o=n(this.box).find(".w2ui-page"),f=0;f<o.length;f++)n(o[f]).find("> *").length>1&&n(o[f]).wrapInner("<div><\/div>");return this.trigger(n.extend(l,{phase:"after"})),this.resize(),(new Date).getTime()-y}},render:function(t){function e(){var t=n(i.box).find("div:not(.w2ui-field-helper) > input, select, textarea, div > label:nth-child(1) > :radio").not(".file-input");t.length>i.focus&&t[i.focus].focus()}var o=(new Date).getTime(),i=this,r,u,f;if((typeof t=="object"&&(n(this.box).find("#form_"+this.name+"_tabs").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),this.box=t),this.isGenerated)&&this.box&&(r=this.trigger({phase:"before",target:this.name,type:"render",box:t!=null?t:this.box}),r.isCancelled!==!0)){if(n.isEmptyObject(this.original)&&!n.isEmptyObject(this.record)&&(this.original=n.extend(!0,{},this.record)),u='<div class="w2ui-form-box">'+(this.header!==""?'<div class="w2ui-form-header">'+this.header+"<\/div>":"")+'    <div id="form_'+this.name+'_toolbar" class="w2ui-form-toolbar" style="display: none"><\/div>    <div id="form_'+this.name+'_tabs" class="w2ui-form-tabs" style="display: none"><\/div>'+this.formHTML+"<\/div>",n(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-form").html(u),n(this.box).length>0&&(n(this.box)[0].style.cssText+=this.style),typeof this.toolbar.render!="function"){this.toolbar=n().w2toolbar(n.extend({},this.toolbar,{name:this.name+"_toolbar",owner:this}));this.toolbar.on("click",function(t){var r=i.trigger({phase:"before",type:"toolbar",target:t.target,originalEvent:t});r.isCancelled!==!0&&i.trigger(n.extend(r,{phase:"after"}))})}if(typeof this.toolbar=="object"&&typeof this.toolbar.render=="function"&&this.toolbar.render(n("#form_"+this.name+"_toolbar")[0]),typeof this.tabs.render!="function"){this.tabs=n().w2tabs(n.extend({},this.tabs,{name:this.name+"_tabs",owner:this,active:this.tabs.active}));this.tabs.on("click",function(n){i.goto(this.get(n.target,!0))})}if(typeof this.tabs=="object"&&typeof this.tabs.render=="function"&&(this.tabs.render(n("#form_"+this.name+"_tabs")[0]),this.tabs.active&&this.tabs.click(this.tabs.active)),this.trigger(n.extend(r,{phase:"after"})),this.resize(),f=typeof this.url!="object"?this.url:this.url.get,f&&this.recid!==0&&this.recid!=null?this.request():this.refresh(),n(".w2ui-layout").length===0){this.tmp_resize=function(){w2ui[i.name].resize()};n(window).off("resize","body").on("resize","body",this.tmp_resize)}return this.focus>=0&&setTimeout(function(){n(i.box).find("input, select, textarea").length===0?setTimeout(e,500):e()},10),(new Date).getTime()-o}},destroy:function(){var t=this.trigger({phase:"before",target:this.name,type:"destroy"});t.isCancelled!==!0&&(typeof this.toolbar=="object"&&this.toolbar.destroy&&this.toolbar.destroy(),typeof this.tabs=="object"&&this.tabs.destroy&&this.tabs.destroy(),n(this.box).find("#form_"+this.name+"_tabs").length>0&&n(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),delete w2ui[this.name],this.trigger(n.extend(t,{phase:"after"})),n(window).off("resize","body"))}};n.extend(t.prototype,w2utils.event);w2obj.form=t}(jQuery);class Contextual{constructor(n){contextualCore.CloseMenu();this.position=n.isSticky!=null?n.isSticky:!1;this.menuControl=contextualCore.CreateEl(`<ul class='contextualJs contextualMenu'></ul>`);this.menuControl.style.width=n.width!=null?n.width:"200px";n.items.forEach(n=>{let t=new ContextualItem(n);this.menuControl.appendChild(t.element)});event!=undefined&&(event.stopPropagation(),document.body.appendChild(this.menuControl),contextualCore.PositionMenu(this.position,event,this.menuControl));document.onclick=function(n){n.target.classList.contains("contextualJs")||contextualCore.CloseMenu()}}add(n){this.menuControl.appendChild(n.element)}show(){event.stopPropagation();document.body.appendChild(this.menuControl);contextualCore.PositionMenu(this.position,event,this.menuControl)}hide(){event.stopPropagation();contextualCore.CloseMenu()}toggle(){event.stopPropagation();this.menuControl.parentElement!=document.body?(document.body.appendChild(this.menuControl),contextualCore.PositionMenu(this.position,event,this.menuControl)):contextualCore.CloseMenu()}}class ContextualItem{constructor(n){switch(n.type){case"seperator":this.seperator();break;case"custom":this.custom(n.markup);break;case"multi":this.multiButton(n.items);break;case"submenu":this.subMenu(n.label,n.items,n.icon!==undefined?n.icon:"",n.cssIcon!==undefined?n.cssIcon:"",n.enabled!==undefined?n.enabled:!0);break;case"hovermenu":this.hoverMenu(n.label,n.items,n.icon!==undefined?n.icon:"",n.cssIcon!==undefined?n.cssIcon:"",n.enabled!==undefined?n.enabled:!0);break;case"normal":default:this.button(n.label,n.onClick,n.shortcut!==undefined?n.shortcut:"",n.icon!==undefined?n.icon:"",n.cssIcon!==undefined?n.cssIcon:"",n.enabled!==undefined?n.enabled:!0)}}button(n,t,i="",r="",u="",f=true){this.element=contextualCore.CreateEl(`
              <li class='contextualJs contextualMenuItemOuter'>
                  <div class='contextualJs contextualMenuItem ${f==!0?"":"disabled"}'>
                      ${r!=""?`<img src='${r}' class='contextualJs contextualMenuItemIcon'/>`:`<div class='contextualJs contextualMenuItemIcon ${u!=""?u:""}'></div>`}
                      <span class='contextualJs contextualMenuItemTitle'>${n==undefined?"No label":n}</span>
                      <span class='contextualJs contextualMenuItemTip'>${i==""?"":i}</span>
                  </div>
              </li>`);f==!0&&this.element.addEventListener("click",()=>{event.stopPropagation(),t!==undefined&&t(),contextualCore.CloseMenu()},!1)}custom(n){this.element=contextualCore.CreateEl(`<li class='contextualJs contextualCustomEl'>${n}</li>`)}hoverMenu(n,t,i="",r="",u=true){this.element=contextualCore.CreateEl(`
              <li class='contextualJs contextualHoverMenuOuter'>
                  <div class='contextualJs contextualHoverMenuItem ${u==!0?"":"disabled"}'>
                      ${i!=""?`<img src='${i}' class='contextualJs contextualMenuItemIcon'/>`:`<div class='contextualJs contextualMenuItemIcon ${r!=""?r:""}'></div>`}
                      <span class='contextualJs contextualMenuItemTitle'>${n==undefined?"No label":n}</span>
                      <span class='contextualJs contextualMenuItemOverflow'>></span>
                  </div>
                  <ul class='contextualJs contextualHoverMenu'>
                  </ul>
              </li>
          `);let e=this.element.querySelector(".contextualHoverMenu"),f=this.element.querySelector(".contextualHoverMenuItem");t!==undefined&&t.forEach(n=>{let t=new ContextualItem(n);e.appendChild(t.element)});u==!0&&(f.addEventListener("mouseenter",()=>{}),f.addEventListener("mouseleave",()=>{}))}multiButton(n){this.element=contextualCore.CreateEl(`
              <li class='contextualJs contextualMultiItem'>
              </li>
          `);n.forEach(n=>{let t=new ContextualItem(n);this.element.appendChild(t.element)})}subMenu(n,t,i="",r="",u=true){this.element=contextualCore.CreateEl(`
              <li class='contextualJs contextualMenuItemOuter'>
                  <div class='contextualJs contextualMenuItem ${u==!0?"":"disabled"}'>
                      ${i!=""?`<img src='${i}' class='contextualJs contextualMenuItemIcon'/>`:`<div class='contextualJs contextualMenuItemIcon ${r!=""?r:""}'></div>`}
                      <span class='contextualJs contextualMenuItemTitle'>${n==undefined?"No label":n}</span>
                      <span class='contextualJs contextualMenuItemOverflow'>
                          <span class='contextualJs contextualMenuItemOverflowLine'></span>
                          <span class='contextualJs contextualMenuItemOverflowLine'></span>
                          <span class='contextualJs contextualMenuItemOverflowLine'></span>
                      </span>
                  </div>
                  <ul class='contextualJs contextualSubMenu contextualMenuHidden'>
                  </ul>
              </li>`);let f=this.element.querySelector(".contextualSubMenu"),e=this.element.querySelector(".contextualMenuItem");t!==undefined&&t.forEach(n=>{let t=new ContextualItem(n);f.appendChild(t.element)});u==!0&&e.addEventListener("click",()=>{e.classList.toggle("SubMenuActive"),f.classList.toggle("contextualMenuHidden")},!1)}seperator(){this.element=contextualCore.CreateEl(`<li class='contextualJs contextualMenuSeperator'><span></span></li>`)}}const contextualCore={PositionMenu:(n,t,i)=>{n?(i.style.left=t.target.offsetLeft+i.offsetWidth>=window.innerWidth?t.target.offsetLeft-i.offsetWidth+t.target.offsetWidth+"px":t.target.offsetLeft+"px",i.style.top=t.target.offsetTop+i.offsetHeight>=window.innerHeight?t.target.offsetTop-i.offsetHeight+"px":t.target.offsetHeight+t.target.offsetTop+"px"):(i.style.left=t.clientX+i.offsetWidth>=window.innerWidth?t.clientX-i.offsetWidth+"px":t.clientX+"px",i.style.top=t.clientY+i.offsetHeight>=window.innerHeight?t.clientY-i.offsetHeight+"px":t.clientY+"px")},CloseMenu:()=>{let n=document.querySelector(".contextualMenu:not(.contextualMenuHidden)");n!=null&&document.body.removeChild(n)},CreateEl:n=>{var t=document.createElement("div");return t.innerHTML=n,t.firstElementChild}};(function(n){n.fn.speedCurve=function(t){function y(){r.append('<div class="speedCurveRoot"><\/div><div class="speedCurveControls">Preloads:<input type="button" id="cmdSpeedRestore" value="Restore"><input type="button" id="cmdSpeedLinear" value="Linear"><input type="button" id="cmdSpeedExponentialEsu" value="Exponential ESU"><input type="button" id="cmdSpeedExponentialLenz" value="Exponential Lenz"><input type="checkbox" class="chkLabelShow" name="chkLabelShow"><label for="chkLabelShow" style="padding-bottom: 1px;"> Show Labels<\/label><div style="padding-top: 10px;">Speedstep (max): <select id="cmbSpeedMax"><\/select>&nbsp;&nbsp;Time (max): <select id="cmbSpeedTimeMax"><\/select><\/div><\/div>')}function p(){window.addEventListener("resize",function(){h(!1);f()});y();__chkLabelShow=r.find(".chkLabelShow");__speedCurveRoot=r.find(".speedCurveRoot");__speedCurveRoot.get(0).onmousedown=function(){o=!0};__speedCurveRoot.get(0).onmouseup=function(){o=!1}}function w(){r.css({width:i.width+"px",height:i.height+"px"});const v=r.find(".speedCurveRoot");__lineSpeed=n("<div>").css({width:i.width+"px"}).addClass("speedCurveLineSpeed");__lineSpeed.appendTo(__speedCurveRoot);__lineTime=n("<div>").css({height:i.height+"px"}).addClass("speedCurveLineTime");__lineTime.appendTo(__speedCurveRoot);const y=i.width/u.speedsteps;let t=n();for(let i=0;i<u.speedsteps;++i){const r=n("<div>").css({width:u.noobyWidth+"px",height:u.noobyHeight+"px"}).data("index",i).data("xsteps",y).addClass("nooby_"+i).addClass("nooby"),f=n("<div>").addClass("noobySpeedLbl").html("");f.appendTo(r);const e=n("<div>").addClass("noobyTimeLbl").html("");e.appendTo(r);t=t.add(r)}v.append(t);h();const s=r.find("select#cmbSpeedMax");for(let t=0;t<u.speedsteps;++t){const i=n("<option>",{value:t}).html(t);i.appendTo(s)}s.change(function(){const t=n(this).val();i.speedStepMaxDefault=parseInt(t);b(t);f()});s.val(i.speedStepMaxDefault);const c=r.find("select#cmbSpeedTimeMax");for(let t=0;t<u.speedsteps;++t)if(t===i.speedTimeMaxDefault){const i=n("<option>",{value:t,selected:""}).html(t+"s");i.appendTo(c)}else{const i=n("<option>",{value:t}).html(t+"s");i.appendTo(c)}c.change(function(){i.speedTimeMaxDefault=n(this).val();f()});__speedCurveRoot.mouseleave(function(){o=!1});__speedCurveRoot.mousemove(function(n){n.preventDefault();const t=nt(this,n);(__recentMouseMoveCoord=t,o!==!1)&&a(t)});__speedCurveRoot.click(function(){a(__recentMouseMoveCoord)});const p=r.find("#cmdSpeedRestore"),w=r.find("#cmdSpeedLinear"),d=r.find("#cmdSpeedExponentialEsu"),g=r.find("#cmdSpeedExponentialLenz");p.click(function(){l(i.preloadData)});w.click(function(){k()});d.click(function(){e(0)});g.click(function(){e(1)});__chkLabelShow.click(function(){f()});f();typeof i.preloadData=="string"?i.preloadData==="esu"?e(0):i.preloadData==="lenz"&&e(1):i.preloadData.length===0?e(0):l(i.preloadData)}function f(){const y=r.find(".speedCurveRoot"),t=i.speedStepMaxDefault,p=i.speedTimeMaxDefault,w=r.find(".speedCurveLineSpeed"),b=r.find(".speedCurveLineTime"),l=r.find(".nooby_"+t);let f=parseInt(l.css("top").replace("px",""));f<0&&(f=f*-1);const k=i.height-f;w.css({top:k});let o=parseInt(l.css("left").replace("px",""));o+=u.noobyWidth/2;o+=t*u.noobyWidth;b.css({left:o});const nt=y.get(0).getBoundingClientRect(),s=r.find(".nooby");let e=1;s.length>32&&(e=10);const d=r.find(".chkLabelShow"),a=d.is(":checked"),g=p/t/e;let h=0;for(let r=0;r<s.length;r++){const c=n(s[r]),o=c.find(".noobyTimeLbl"),f=c.find(".noobySpeedLbl");o.hide();f.hide();let l=h.toString();l=l.substr(0,3);o.html(l+"s");const y=c.parent().get(0).getBoundingClientRect(),p=c.get(0).getBoundingClientRect(),w=y.bottom-p.bottom,b=i.height/u.speedsteps,v=1/b*w;f.html(v);o.removeClass("timeHighlight");f.removeClass("speedHighlight");c.data("speed",v);c.data("timeStep",h);v>t?(o.hide(),f.hide()):r===t?(o.addClass("timeHighlight"),f.addClass("speedHighlight"),f.html(t),o.show(),f.show()):r%e==0&&(a==!0?o.show():o.hide(),a==!0?f.show():f.hide());for(let n=0;n<e;++n)h+=g}if(i.onChanged!=null&&c===!0)i.onChanged({data:v()})}function b(t){const i=r.find(".nooby"),u=parseInt(t);for(let t=0;t<i.length;++t){const r=n(i[t]);r.removeClass("noobyMax");t===u&&r.addClass("noobyMax")}}function l(n=[]){typeof n=="string"?i.preloadData==="esu"?e(0):i.preloadData==="lenz"&&e(1):typeof n!="undefined"&&n!=null&&n.length>0&&d(n)}function k(){const e=r.find(".nooby"),t=u.speedsteps,o=i.height/t;for(let i=0;i<t;++i){const t=n(e[i]),r=i*o;s(t,r)}f()}function d(t){const e=r.find(".nooby"),o=u.speedsteps,h=i.height/o,c=t.length;for(let i=0;i<c;++i){const r=h*t[i],u=n(e[i]);s(u,r)}f()}function e(t,e=[]){const a=r.find(".nooby"),h=u.speedsteps,c=u.deltaShow;let o=e;h===14?t===0?o=[0,2,9.573,17.536,26.306,36.309,47.98,61.759,78.091,97.423,120.208,146.9,177.956,213.836]:t===1&&(o=[0,2,7.786,15.905,26.266,38.822,53.543,70.402,89.382,110.465,133.639,158.889,186.206,215.579]):t===0?o=[0,2,5.763,9.573,13.48,17.536,21.794,26.306,31.127,36.309,41.909,47.98,54.578,61.759,69.578,78.091,87.353,97.423,108.356,120.208,133.037,146.9,161.854,177.956,195.264,213.836,233.728,255]:t===1&&(o=[0,2,4.591,7.786,11.562,15.905,20.809,26.266,32.272,38.822,45.914,53.543,61.706,70.402,79.628,89.382,99.662,110.465,121.792,133.639,146.005,158.889,172.29,186.206,200.636,215.579,231.034,247]);const l=o.length;for(let t=0,r=0;t<l-1;++t,r+=c){const f=o[t],e=o[t+1];let u=r+c;t===l-2&&(u=h);const v=u-r,y=e-f,p=y/v;for(let t=r,e=0;t<u;++t,++e){const r=f+p*e,u=n(a[t]),o=i.height/255*r;s(u,o)}}f()}function g(){return{top:i.height,left:0}}function s(n,t){if(!(t<0)&&!(t>i.height)){const r=u.noobyHeight;n.css({top:-t-r+"px"})}}function h(t=true){const i=g(),f=r.find(".nooby");for(let r=0;r<f.length;++r){const e=n(f[r]),s=e.data("xsteps"),o=i.left+parseInt(r*s)-r*u.noobyWidth;t===!0?e.css({top:i.top+"px",left:o+"px"}):e.css({left:o+"px"})}}function a(n){const o=i.width/u.speedsteps,e=tt(n.x,i.width,o);if(!(e<0)){const t=r.find(".nooby_"+e);if(typeof t!="undefined"&&t!=null&&t.length!==0){const h=n.y;s(t,h);f()}}}function nt(n,t){const r=t.pageX,u=t.pageY,i=n.getBoundingClientRect(),f=i.top,e=i.left,o=i.height;return{x:r-e,y:o-(u-f),topPage:r-e,leftPage:o-(u-f)}}function tt(n,t,i){if(n<0||n>t)return-1;let r=0;for(let u=0;u<t;u+=i){const t=u,f=t+i;if(n>=t&&n<f)return r;++r}return-1}function v(){const f=r.find("select#cmbSpeedMax"),e=r.find("select#cmbSpeedTimeMax"),o=parseInt(f.val()),s=parseInt(e.val()),t=r.find(".nooby");let u=[];for(let i=0;i<t.length;++i){const e=n(t[i]);let r=e.data("speed"),f=e.data("timeStep");r<0&&(r=0);f<0&&(f=0);const o={speed:r,timeStep:f};u.push(o)}return{objectId:i.objectId,maxSpeed:o,maxTime:s,steps:u}}var c=!1;this.refresh=function(){return h(!1),f(),this};this.getData=function(){return v()};var i=n.extend({objectId:-1,speedMode:"dcc28",width:750,height:200,speedTimeMaxDefault:5,speedStepMaxDefault:null,preloadData:[],onChanged:null},t),u={dcc14:{speedsteps:14,extraWidthForSteps:2,noobyWidth:4,noobyHeight:4,deltaShow:1},dcc28:{speedsteps:28,extraWidthForSteps:2,noobyWidth:4,noobyHeight:4,deltaShow:2},dcc128:{speedsteps:128,extraWidthForSteps:2,noobyWidth:4,noobyHeight:4,deltaShow:4},mm14:{speedsteps:14,extraWidthForSteps:2,noobyWidth:4,noobyHeight:4,deltaShow:1},mm27:{speedsteps:27,extraWidthForSteps:0,noobyWidth:4,noobyHeight:4,deltaShow:2},mm128:{speedsteps:128,extraWidthForSteps:2,noobyWidth:4,noobyHeight:4,deltaShow:5}}[i.speedMode],r=this,o=!1;return i.speedStepMaxDefault==null&&(i.speedStepMaxDefault=parseInt(u.speedsteps/2)),p(),w(),c=!0,this}})(jQuery),function(n){n.fn.videoStream=function(t){function v(){u.resizable({ghost:!1,stop:function(n,t){typeof i.moved!="undefined"&&i.moved!=null&&i.moved({url:r.get(0).src,x:t.position.left,y:t.position.top,w:t.size.width,h:t.size.height})}});u.draggable({stop:function(n,t){typeof i.moved!="undefined"&&i.moved!=null&&i.moved({url:r.get(0).src,x:t.position.left,y:t.position.top,w:parseInt(u.css("width").replace("px","")),h:parseInt(u.css("height").replace("px",""))})}});u.css({width:i.width+"px",height:i.height+"px"});r=n("<img>",{width:i.width,height:i.height,src:i.url});r.appendTo(u);f=n("<div>").addClass("lblDateTime");const t=(new Date).toLocaleString("de-DE");f.html(t);f.appendTo(u);typeof i.caption!="undefined"&&i.caption!=null&&i.caption.length>0&&(e=n("<div>").addClass("lblCaption"),e.html(i.caption),e.appendTo(u));h();c=!0}function a(){r.get(0).src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGsAAABvCAYAAADrLj4aAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAASdEVYdFNvZnR3YXJlAEdyZWVuc2hvdF5VCAUAAAszSURBVHhe7V1VjBU9FN5n7BF7wAkOCR5cQ4LzwqLBnQTXEJIFNhBCFnfdYEFeSHB3t+DBg7u79f+/+Tv/3p09nWnnzl1u7/RLvrDc7XS2/e60p+ecdpKYgTYwYmkEI5ZGMGJpBE+xPnz4wFavXs2aNGnCypUrxypWrGgYBStVqsTKly/PkpOT2ebNm3kvy8FVrI8fP7IWLVqwpKQkwxgwT548rFOnTuzXr1+8x90hFOvNmzescuXK5E0Mg2WjRo3Y79+/ec+LIRSrd+/eZMWGsWFqairveTFIsS5fvszy589PVmoYG9aoUYM9ffqUK0CDFGvhwoVkhYax5enTp7kCNEixUlJSyMoMY8slS5ZwBWiQYk2YMIGsDCxYsCAbM2YMS0tLM1Rkv379yD61OX36dK4ADWWx2rZty37+/MlLGqjg4cOH1hqL6lcwcLFatmzJfvz4wUsaqODBgwdGLF1gxNIIRiyNYMTSCEasbMC3b98sX+nXr1/5J/5gxIoRYGYjNNS5c2fWunVrKzzUpk0b6//p6ens7t27vKQ8jFgxwLRp01w7FURsavLkyUp9YcQKEIgrtW/fnmy3iI0bN7aGSRkYsQIC4kkNGzYk2+zFWrVqsU+fPvGaxDBiBYRRo0aR7ZUl5jIvGLECQBDxu1y5crG9e/fyGmkYsQKAlzdclh06dGB//vzhtWaFEStKvHr1ilWtWpVsqyqLFi1qCSKCEStKXL9+neXLl49sqx+eO3eO15wVRqwogc6l2umXR44c4TVnhRErSly4cIFsp18eO3aM15wVRqwocfPmTVasWDGyrX4I8UUwYkUJZB3XqVOHbKsqq1Wrxp4/f85rzgojVgAYO3Ys2VZV9u/fn9dIw4gVAO7fv+/aiTKERXnt2jVeIw0jVkBAYmvOnDnJNstw3LhxvCYxjFgBYsiQIWSbvdi3b19egzuMWAEDMSrZJwzlvOapSBixYgA4ZBEVFomGz+vWrct27drFr5CDEStGQNYxvPFz585lw4YNY+3atbOGu6lTp1prKZn4lRNGLI1gxNIIRiyNYMTSCEYsjZDwYl26dImdPHnSSrrUHQktFjKOkIiC+yIjFlFdnZGwYvXq1SvLvZHjcObMGV5CPySkWN27dyfvDSJm9OLFC15SLySUWEhf7tq1K3nfSCJlWcd9zQkjFvLFcSwOdU+KGCazAyNHjrTOrxowYAD7/Pkz/9QfEkIshNZr165N3s+NU6ZM4TUEDzy5OJkg8n5w3mKfll9oL9bbt29950Dkzp2bLV++nNcULM6ePfu/JRrJevXq+RZMa7FgKKDx1H1kWaJECXb06FFeY3CAd526H4gvF0YDVWgr1pMnT1iDBg3Ie6gSHYCOCBIIh1D3soltPt+/f+el5aClWPBK+N0LJaLfbzsF7NWSORQTbXDbiOCEdmIhcIfFLVV3tMSuxSDw8uVLVqZMGfIeTnbr1o1f5Q2txMIRbUFmv1KEqR0tkKVbvHhxsn6KPXv25Fe6QxuxkAOu0gF+CQsRaWXRAI5jqm439unTh18thhZiHT582LLaqPpiQZjc+/fv53dXx7x588h6vah9Ri46rWTJkmRdsSSGW7e9Um4YPnw4WacMBw8ezGvJirgWa9WqVX9FKJv169e3djaqonnz5mR9MsTx37NmzeI1ZUbcigXPAuUByG7C3yh7bjrw+vVrVqVKFbIuWWLexFDqRFyKtXjxYusPpq7/G5SZ/G3cvn07EIsV7V+0aBGv9T/EnVjz58+PK6Fszp49m/+F7sDygrreD9EPy5Yt4zXHmVhz5syJS6FA/F0rVqzgf6kYCxYsIK93I55EpB2ULVvW+hesUKECy5Ejh0V7SIwbsWbOnGlNrtQ18UIsH9z2/AIjRowgr7WJfVjNmjWzfIcbNmywLE6ckPbo0SNr1yOc0/gZn8Gttn79eusLgLkQYpUqVYqsF8wWsQYOHEiWjUfim43OFEFkCSKWBU/8lStXfJ87CD8i3uwjCgnFXCwsBKly8Ux0FhX1RWwNojjLbty4MaqgoxNwOO/YsYO1atUqk8UcU7FgZVFldCDl9MXQhbkGv4ezGVZtUJ58ETCUYq7DPWMmFpyX1O91IvISI4HoMD7H3qw7d+7wT2MPvDCmY8eObOnSpfwTGr7EkslA0oHOtdCWLVusV1GpAMMj5kB46hH+uXjxIrt165YVXH337h0vJYcvX77wn2goixWrWNTfIuaMAwcOWO3GKxNlAKtu27ZtlrDVq1e3jJbIiAKOZIX5jkg4TlzbuXOnJV60UBYrEYn3MMLK8wKeHnS+ny8sRIXVjGMc/MKI9S+9ApaPHz9mEydODOT0NBgw2GQOy1MVoRcLuYFuOH78OKtZsyZ5bTRERED1uPFQi4XhzG1Yglkdy6Ap3FSHDh3id/NGqMVat24db3FWYCEsex4GhkcYFEiyAWFwyF4L3+HBgwf5Xd0RWrHwkmzReeywDr0OOIZAeMcwRMWZTc+ePbPMeGRG4WnFXjIcy4B4mpdwsCS93vcIhFas3bt389Zmxr1796TiWaJoMAXkoMDn6BaMldnKFEqxsAmC8g0iogx/HXWNk0hXUJlvACzA3Z4yrwV5KMUSpapt375dKR6H4QtpayqA110UJsGTh6dQhNCJlTdvXssd5ASO9/Gz7QhDJlxMKkD0WDQkYrgUIXRiwUlLAU8VVR50CxiCsARV3UmDBg0i64KI58+f56UyI3RiTZo0ibcyM6gN5yC2JMHo8NqapLpvy+300NGjR/NSmRE6sajd/gjHwxqjytv5E/Cs4wmiytjEMOrlOY+EqJ9FBlCoxMJ8dePGDd7KDJw6dYosj/kIHnYbGJ68nLgq24AQUqGsQ6zxKMdyqMTCk0Ed5S3KaMKC1nkqAHyFXhssevTowUu7AyEZ0fBK7eYMlVilS5cmA4KYx6jyOEKcgoyHQ/bcXNGmPWp5ESqxYAlSc8HQoUPJ8m6nAaxcudLVIwHC4vOCKI8FYRQnQiUWjk6l/IH4nCo/Y8YMXoIGPBJugiGPEomvbkhNTSWvTUlJ4SUyQIqFglQFuhMeccq8Fn05qQ5zwisL2Znn4YTKU02KJVJbd8LAQNTXCXQMVV52Q4NogWsTgmHYpOA8GMXmmjVreIkMkGLt2bOHrEB3IqROpZjh5dFUeax3ZE+Z9jqKoUCBAv8n5tiAl130VrwTJ07wUhkgxYJJ6cxMTRTi+G8nVNc7IsBkd9YRSUSdYfrbQNCRmvNE/ktSLAAH0SOK6axIdyIg6ATMedGXE28DlwUWw167JrHQtn1/otRz0QZAoVjApk2bEk6w5ORk3rrMEO0jxtCpkj4Gd5OX9x4+QcTCRNlSor1krmIBqBSmbRBpWPFAJGAi9O7Evn37hIFBWY+EDVicXtOIKBqNfr569SqvKTM8xQLgcsHYvXXrVmvtgQR6XQnPgGjLjmgIgzVHDZ9uQMgEiZ1UfW50ixZLiRUWIEorerogWFpaGi8pBwQlVbJ3RYaFDSOWA25vA4dg48ePV8qmRdhf9mQdUazNhhHLgffv33vON/CUI+eQmvucwDkcbmcX2pQ5AsKIRQBpzUWKFCE7NZIIWMLLgV0iCGoiVxDEXuK1a9daGxFk5i2vt7DaMGIJgCBl4cKFyc4VEfOdqtVcqFAh6aWBEcsFyJIVuYOCINZjKq/tMGJ5AP47kbPVL+Figomu+nY7I5YEMPHDoAjCX4qnCTv1/cCIpQCY7Onp6axp06ZKcxPK4i0PMDpUsp+cMGL5AKLNsPqQpgZXHPLjcZIafH6ImeFnbJTv0qWLFX7BQlflZDYRjFgawYilEYxY2oCxfwDgrfnWu3dlhQAAAABJRU5ErkJggg=="}function y(){let n=new Image;n.onload=function(){if(typeof r!="undefined"&&r!=null){r.get(0).src=this.src;const n=r.parent().get(0).getBoundingClientRect();r.css({width:n.width+"px",height:n.height+"px"});const t=(new Date).toLocaleString("de-DE");f.html(t);f.show();e.show();h()}};n.onerror=function(){if(i.stopOnFailure===!0&&(s++,s>=i.stopAfterFailuresFps)){console.log("Refresh of Stream stopped: "+s+" >= "+i.stopAfterFailuresFps);clearTimeout(o);o=-1;a();return}typeof r!="undefined"&&r!=null&&(a(),f.hide(),e.hide(),h())};n.src=i.url+"?t="+Math.random()}function h(){clearTimeout(o);o=setTimeout(function(){y()},1e3/i.fps)}var c=!1,u=this,r=null,f=null,e=null,o=-1,s=0,i;const l=10;return(i=n.extend({width:320,height:240,fps:l,locale:"de-DE",caption:"",stopOnFailure:!1,stopAfterFailuresFps:2*l,moved:null},t),c===!0)?this:(v(),this)}}(jQuery);class Accessories{constructor(){console.log("**** construct Accessories");this.__installed=!1;this.__gridName="gridAccessories";this.__dialogName="dialogAccessories";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling();this.__recentlyHighlighted={};(typeof __toggleAccessoryTest=="undefined"||window.__toggleAccessoryTest==null)&&(window.__toggleAccessoryTest=function(n){window.__eventTrigger("startAccessoryTest",{cmd:"accessoryTest",addresses:JSON.parse(atob(n)),periods:10,pause:1e3})})}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"));w2ui[this.__gridName].refresh()}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}__removeAllHighlights(){const n=this,t=Object.keys(n.__recentlyHighlighted);$(t).each(function(){window.planField.highlightAccessory(this,!1)});n.__recentlyHighlighted={}}__renderTestFunctionality(n){const i=n.recid,r={addr1:n.addr1,addr2:n.addr2,port1:n.port1,port2:n.port2,inverse1:n.inverse1,inverse2:n.inverse2};let t=JSON.stringify(r);t=btoa(t);return'<div style="height: 100%; width: 100%; white-space: nowrap; text-align: center; padding-top: 3px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"><input type="button" value="Test" id="cmdAccessoryTest_'+i+'" onclick="window.__toggleAccessoryTest(\''+t+"')\"><\/span><\/div>"}install(n={}){const t=this,r=this.isShown();if(!r){(typeof n=="undefined"||typeof n.autoOpen=="undefined")&&(n==null&&(n={}),n.autoOpen=!1);const i=this.__windowGeometry.recent();if($("#"+this.__dialogName).dialog({height:i.height,width:i.width,left:i.left,top:i.top,closeOnEscape:!1,autoOpen:n.autoOpen,resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:n.target.clientWidth,height:n.target.clientHeight})},close:function(){t.__removeAllHighlights();const n=w2ui[t.__gridName];n.selectNone()}}),!w2ui[this.__gridName]){const i=$("#"+this.__gridName);i.w2grid({name:this.__gridName,header:"Accessories",show:{toolbar:!0,footer:!0,toolbarAdd:!1,toolbarDelete:!1,toolbarEdit:!1,toolbarSave:!1},textSearch:"contains",recid:"accessoryId",searches:[{field:"identifier",caption:"Identifier",type:"text"}],sortData:[{field:"identifier",direction:"asc"}],columns:[{field:"accessoryId",caption:"Accessory ID",size:"2%",sortable:!1,hidden:!0},{field:"identifier",caption:"Identifier",size:"7%",sortable:!0},{field:"type",caption:"Type",size:"10%",sortable:!0},{field:"state",caption:"State",size:"5%",sortable:!0},{field:"addr1",caption:"Address1",tooltip:"Address1",size:"5%",sortable:!0,hidden:!0,render:"int",editable:{type:"int",min:0,max:32756}},{field:"port1",caption:"Port1",tooltip:"Port1",size:"5%",sortable:!0,hidden:!0,render:"int",editable:{type:"int",min:0,max:32756}},{field:"inverse1",caption:"Inverse1",tooltip:"Inverse1",size:"5%",sortable:!1,hidden:!0,editable:{type:"checkbox",style:"text-align: center"}},{field:"addr2",caption:"Address2",tooltip:"Address2",size:"5%",sortable:!0,hidden:!0,render:"int",editable:{type:"int",min:0,max:32756}},{field:"port2",caption:"Port2",tooltip:"Port2",size:"5%",sortable:!0,hidden:!0,render:"int",editable:{type:"int",min:0,max:32756}},{field:"inverse2",caption:"Inverse2",tooltip:"Inverse2",size:"5%",sortable:!1,hidden:!0,editable:{type:"checkbox",style:"text-align: center"}},{field:"groupName",caption:"Group",tooltip:'In a group with the same name, only one accessory can be enabled (e.g. "green", "straight", "on").',size:"5%",sortable:!1,hidden:!1,editable:{type:"string"}},{field:"longTermSwitching",caption:"Test",tooltip:"Toggles long-term switching test, i.e. the accessory will be switched continously.",size:"5%",sortable:!1,hidden:!0,editable:!1,style:"text-align: center",render:t.__renderTestFunctionality}],records:[],onSelect:function(n){const e=n.recid,r=w2ui[t.__gridName],u=r.get(e);t.__removeAllHighlights();window.planField.highlightAccessory(u.identifier,!0);t.__recentlyHighlighted[u.identifier]=!0;const f=r.getSelection();let i;const o=f.length;for(i=0;i<o;++i){const u=f[i],n=r.get(u);window.planField.highlightAccessory(n.identifier,!0);t.__recentlyHighlighted[n.identifier]=!0}bringToFront(t.__dialogName)},onUnselect:function(n){const r=n.recid,u=w2ui[t.__gridName],i=u.get(r);typeof i!="undefined"&&i!=null&&(window.planField.highlightAccessory(i.identifier,!1),t.__recentlyHighlighted[i.identifier]=!1)}});const n=w2ui[this.__gridName].toolbar;n&&(n.insert("search",{type:"check",id:"itemAddressing",text:"Address/Port",img:"fas fa-sitemap",checked:!1,tooltip:function(){return"Toogles the columns to set-up the accessory addressing."},onClick:function(){const n=w2ui[t.__gridName];n.toggleColumn("addr1");n.toggleColumn("port1");n.toggleColumn("inverse1");n.toggleColumn("addr2");n.toggleColumn("port2");n.toggleColumn("inverse2");n.toggleColumn("longTermSwitching")}}),n.insert("search",{type:"button",id:"itemExecute",text:"Execute",img:"fas fa-exchange-alt",tooltip:function(){return"Switches the state of the current selected accessories."},onClick:function(){const i=w2ui[t.__gridName],r=i.getSelection();let n;const u=r.length;for(n=0;n<u;++n){const o=r[n],f=i.get(o),e=$("div.ctrlItemAccessory[id]");let u;const s=e.length;for(u=0;u<s;++u){const i=e[u];if(i){const n=$(i).data(constDataThemeItemObject);if(n!=null&&n.identifier===f.identifier){const i=n.coord;t.__trigger("accessoryExecute",{ctrlId:f.identifier,coord:i});break}}}}}}),n.add({type:"button",id:"cmdSave",text:"Save ",img:"fas fa-save",tooltip:function(){return"Applies all changes to the server."},onClick:function(){const n=w2ui[t.__gridName],i=n.getChanges(),r=i.length;for(let u=0;u<r;++u){const e=i[u],h=e.recid,f=n.get(h);let o=!1,s=!1;typeof e.inverse1!="undefined"&&e.inverse1!=null&&(o=e.inverse1!=f.inverse1);typeof e.inverse2!="undefined"&&e.inverse2!=null&&(s=e.inverse2!==f.inverse2);let r={Addr1:e.addr1,Port1:e.port1,Inverse1:e.inverse1,Addr2:e.addr2,Port2:e.port2,Inverse2:e.inverse2};(typeof r.Addr1=="undefined"||r.Addr1==null)&&(r.Addr1=f.addr1);(typeof r.Port1=="undefined"||r.Port1==null)&&(r.Port1=f.port1);(typeof r.Inverse1=="undefined"||r.Inverse1==null)&&(r.Inverse1=f.inverse1);(typeof r.Addr2=="undefined"||r.Addr2==null)&&(r.Addr2=f.addr2);(typeof r.Port2=="undefined"||r.Port2==null)&&(r.Port2=f.port2);(typeof r.Inverse2=="undefined"||r.Inverse2==null)&&(r.Inverse2=f.inverse2);o===!0&&(f.inverse1=e.inverse1,n.refreshCell(f,"inverse1"));s===!0&&(f.inverse2=e.inverse2,n.refreshCell(f,"inverse2"));window.planField.applyAddressToAccessory(f.identifier,r);r.identifier=f.identifier;f.groupName!==e.groupName&&(f.groupName=e.groupName,n.refreshCell(f,"groupName"),t.__trigger("setting",{mode:"accessory",cmd:"groupName",value:{identifier:f.identifier,name:f.groupName}}));t.__trigger("setting",{mode:"accessory",cmd:"address",value:r})}n.save()}}))}this.__installed=!0}}removeAccessory(n){if(typeof n!="undefined"&&n!=null){const r=this,i=w2ui[r.__gridName],t=i.find({identifier:n});if(t.length>0){let n;const r=t.length;for(n=0;n<r;++n){const r=t[n];i.remove(r)}}}}updateAccessories(n){const o=this,t=n.metamodel;if(typeof t!="undefined"&&t!=null){const r=t.planField,u=w2ui[o.__gridName];let i=[],f=0;const e=Object.keys(r),s=e.length;for(let n=0;n<s;++n){const p=e[n],o=r[p],w=o.editor.themeId;if(isSwitchOrAccessory(w)){const s=f;++f;const b=o.identifier,k=o.name,d=o.groupName;let h=-1,c=-1,l=!1,a=-1,v=-1,y=!1;const t=o.addresses;typeof t=="undefined"||t==null||(h=t.Addr1,c=t.Port1,l=t.Inverse1,a=t.Addr2,v=t.Port2,y=t.Inverse2);const g=u.find({accessoryId:s});g.length<=0&&i.push({accessoryId:s,identifier:b,type:k,groupName:d,state:"unknown",addr1:h,port1:c,inverse1:l,addr2:a,port2:v,inverse2:y})}}i.length>0&&u.add(i)}}updateStates(n){const u=this,t=n.ecosData.accessories;if(typeof t!="undefined"&&t!=null){const f=$("div.ctrlItemAccessory"),i=w2ui[u.__gridName],r=function(n){const i=t.length;for(let r=0;r<i;++r){const i=t[r];if(typeof i!="undefined"&&i!=null&&i.addr===n)return i.state}return"unknown"},e=t.length;for(let n=0;n<e;++n){const e=t[n];if(typeof e!="undefined"&&e!=null){const u=getAccByEcosAddr(f,e.addr);if(u!=null){const o=i.find({identifier:u.themeData.identifier});if(o.length>0){let n;const t=o.length;for(n=0;n<t;++n){const h=o[n],c=i.get(h);let e=null,t=null,s=null,f=null;if(u.ecosAddresses.length===2){let n="straight",o="turn";const a=u.themeData.editor.themeId;isDecoupler(a)||isButton(a)?(n="on",o="off"):isSignal(a)?(n="red",o="green"):isAccessory(a)&&(n="on",o="off");u.ecosAddresses[0].ecosAddrValid===!0&&(e=r(u.ecosAddresses[0].ecosAddr),e===0?t=n:e===1&&(t=o));u.ecosAddresses[1].ecosAddrValid===!0&&(s=r(u.ecosAddresses[1].ecosAddr),s===0?f=n:s===1&&(f=o));let l="unknown";t==null&&f==null||(t!=null&&f!=null?l=t+" / "+f:t==null?l=f:f==null&&(l=t));const v=c.state;v!==l&&(c.state=l,i.refreshCell(h,"state"))}}}}}}}}}class Blocks{constructor(){console.log("**** construct Blocks");this.__installed=!1;this.winLocomotives=null;this.gridLocomotives=null;this.__gridName="gridBlocks";this.__dialogName="dialogBlocks";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling();this.__fbsList=[]}__getFbsList(){return this.__fbsList}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"));w2ui[this.__gridName].refresh()}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}install(n={}){const t=this,r=this.isShown();if(!r&&!this.__installed){(typeof n=="undefined"||typeof n.autoOpen=="undefined")&&(n.autoOpen=!1);this.__expandedPreferences={};const i=this.__windowGeometry.recent();if($("#"+this.__dialogName).dialog({height:i.height,width:i.width,left:i.left,top:i.top,closeOnEscape:!1,autoOpen:n.autoOpen,resize:function(){t.__resizePreferences()},resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:n.target.clientWidth,height:n.target.clientHeight})},close:function(){const n=w2ui[t.__gridName];n.selectNone()}}),!w2ui[this.__gridName]){const n=$("#"+this.__gridName);n.w2grid({name:this.__gridName,header:"Blocks and Feedbacks",multiSelect:!1,show:{toolbar:!0,footer:!0,toolbarAdd:!1,toolbarDelete:!1,toolbarEdit:!1,toolbarSave:!1,multiSelect:!1},textSearch:"contains",searches:[{field:"blockId",caption:"Block",type:"text"}],sortData:[{field:"blockId",direction:"asc"}],columns:[{field:"recid",caption:"ID",sortable:!1,hidden:!0},{field:"blockId",caption:"Block",size:"25%",sortable:!0},{field:"fbEnter",caption:"Feedback Enter",size:"20%",sortable:!0,editable:{type:"list",items:t.__getFbsList(),filter:!1}},{field:"fbIn",caption:"Feedback In",size:"20%",sortable:!1,editable:{type:"list",items:t.__getFbsList(),filter:!1}}],records:[],onExpand:function(n){const r=w2ui[t.__gridName];for(let t=0;t<r.records.length;++t){const i=r.records[t];typeof i!="undefined"&&i!=null&&i.recid!==parseInt(n.recid)&&r.collapse(i.recid)}const u=r.get(n.recid),i=t.__getExpandedHtml(u);i.recid=n.recid;i.blockId=u.blockId;i.fbEnterItemId=u.fbEnter;i.fbInItemId=u.fbIn;$("#"+n.box_id).html(i.renderHtml);t.__expandedPreferences[n.recid]=!0;n.onComplete=function(){const r=$("#"+i.selectDeniedLocsId);if(typeof ecosData!="undefined"&&window.ecosData!=null){const n=window.ecosData.locomotives;for(let u=0;u<n.length;++u){const f=n[u],o=t.__isLocDenied(i.blockId,f.objectId),e=new Option(f.name,f.objectId,o,o);$(e).css({padding:"1px"});$(e).html(f.name);r.append(e)}}r.select2();r.on("select2:unselect",function(){t.__resizePreferences();t.__saveBlockSettings(i)});r.on("select2:select",function(){t.__resizePreferences();t.__saveBlockSettings(i)});const u=$("#"+i.selectBlockLocksId),f=t.__getBlockOfRecentData(i.blockId);if(typeof f!="undefined"&&f!=null){const e=f.AdditionalBlockLocks,r=$("div.ctrlItemBlock");let n=0,i=r.length,t=[];for(;n<i;++n){const i=r[n];if(typeof i!="undefined"&&i!=null){const u=i.getAttribute("id");u.length!==0&&t.push(u)}}const o=new Intl.Collator(undefined,{numeric:!0,sensitivity:"base"});for(t=t.sort(o.compare),i=t.length,n=0;n<i;++n){const i=t[n],f=e.includes(i),r=new Option(i,i,f,f);$(r).css({padding:"1px"});$(r).html(i);u.append(r)}}u.select2();u.on("select2:unselect",function(){t.__resizePreferences();t.__saveBlockAdditionalBlocks(i)});u.on("select2:select",function(){t.__resizePreferences();t.__saveBlockAdditionalBlocks(i)});const o=$("#"+i.fbEnterId),s=$("#"+i.fbInId);o.w2field("int");s.w2field("int");const h=i.checkboxIds;let e=[];for(let n=0;n<h.length;++n){const t=$("#"+h[n]);typeof t!="undefined"&&t!=null&&(t.w2field("checkbox"),e.push(t))}$("div#blockData_"+n.recid+" #"+i.selectDeniedLocsId+" + span").css({"margin-left":"10px"});$("div#blockData_"+n.recid+" #"+i.selectDeniedLocsId+" + span span.selection span.select2-selection").css({"border-radius":"3px",border:"1px solid #cacaca"});$("div#blockData_"+n.recid+" #"+i.selectBlockLocksId+" + span").css({"margin-left":"10px"});$("div#blockData_"+n.recid+" #"+i.selectBlockLocksId+" + span span.selection span.select2-selection").css({"border-radius":"3px",border:"1px solid #cacaca"});t.__loadRecentStatesFor(i.blockId,n.recid);o.change(function(){const n=getThemeJsonDataById(i.fbEnterItemId);n.addresses.Addr=parseInt($(this).val());setThemeJsonDataById(i.fbEnterItemId,n);t.__saveBlockSettings(i)});s.change(function(){const n=getThemeJsonDataById(i.fbInItemId);n.addresses.Addr=parseInt($(this).val());setThemeJsonDataById(i.fbInItemId,n);t.__saveBlockSettings(i)});for(let n=0;n<e.length;++n)e[n].change(function(){t.__saveBlockSettings(i)});t.__resizePreferences()}},onCollapse:function(n){t.__expandedPreferences[n.recid]=!1},onSelect:function(n){const i=w2ui[t.__gridName],r=i.get(n.recid);t.__addBlockFeedbackHiglight(r);const u=window.planField;u;bringToFront(t.__dialogName)},onUnselect:function(){t.__removeBlockFeedbackHiglight()},onChange:function(n){const r=w2ui[t.__gridName],i=r.get(n.recid),u=n.column;if(u===2||u===3){let f="null",e="null";u===2?(i.fbEnter=n.value_new.text,f=i.fbEnter):u===3&&(i.fbIn=n.value_new.text,e=i.fbIn);t.__saveBlockFbs(i.blockId,f,e);r.refreshCell(i.recid,"fbEnter");r.refreshCell(i.recid,"fbIn");r.save();setTimeout(function(){t.__addBlockFeedbackHiglight(i)},250)}}})}this.__installed=!0}}__resizePreferences(){const n=this.__expandedPreferences;$.each(n,function(n,t){if(t===!0)try{const t=$("div#blockData_"+n).get(0).getBoundingClientRect().height;$("div#grid_gridBlocks_frec_"+n+"_expanded").css({height:t+"px"})}catch(i){}})}__saveBlockFbs(n,t,i){this.__trigger("setting",{mode:"block",cmd:"blockDataFbs",value:{blockIdentifier:n,fbEnterId:t,fbInId:i}})}__saveBlockAdditionalBlocks(n){const t=$("#"+n.selectBlockLocksId).select2("data");this.__trigger("setting",{mode:"block",cmd:"blockDataBlockLocks",value:{blockIdentifier:n.blockId,additionalBlockLocks:t}})}__saveBlockSettings(n){const i=$("#"+n.selectDeniedLocsId).select2("data");let t={};if(n.checkboxIds==null)t=null;else{const i=n.checkboxIds;for(let n=0;n<i.length;++n){const r=$("#"+i[n]);if(typeof r!="undefined"&&r!=null){const u=$(r).attr("name"),f=$(r).is(":checked");t[u]=f}}}this.__trigger("setting",{mode:"block",cmd:"blockData",value:{blockIdentifier:n.blockId,fbEnter:{id:n.fbEnterItemId,ecosAddr:parseInt($("#"+n.fbEnterId).val())},fbIn:{id:n.fbInItemId,ecosAddr:parseInt($("#"+n.fbInId).val())},deniedLocomotives:i,checkboxSettings:t}})}__getBlockOfRecentData(n){for(let i=0;i<this.__recentFeedbacksData.length;++i){var t=this.__recentFeedbacksData[i];if(typeof t!="undefined"&&t!=null&&t.BlockId===n)return t}return null}__isLocDenied(n,t){const i=this.__getBlockOfRecentData(n);if(i!=null){var r=i.DeniedLocomotives;for(let n=0;n<r.length;++n){const i=r[n];if(typeof i!="undefined"&&i!=null&&parseInt(i.Id)===t)return!0}}return!1}__loadRecentStatesFor(n,t){const i=this.__getBlockOfRecentData(n);if(i!=null){const n=this.__getCtrlIdsForOptionsAndTypes(t);$("#"+n.chkIdWait).prop("checked",i.Settings.OptionWait);$("#"+n.chkIdDirection).prop("checked",i.Settings.OptionDirection);$("#"+n.chkIdMainline).prop("checked",i.Settings.OptionMainline);$("#"+n.chkIdBbt).prop("checked",i.Settings.OptionBbt);$("#"+n.chkIdOthers).prop("checked",i.Settings.TypeOthers);$("#"+n.chkIdLocal).prop("checked",i.Settings.TypeLocal);$("#"+n.chkIdIntercity).prop("checked",i.Settings.TypeIntercity);$("#"+n.chkIdFreight).prop("checked",i.Settings.TypeFreight);$("#"+n.chkIdShunting).prop("checked",i.Settings.TypeShunting);$("#"+n.chkIdRegional).prop("checked",i.Settings.TypeRegional);$("#"+n.chkIdBranchLine).prop("checked",i.Settings.TypeBranchLine);$("#"+n.chkIdBranchLineFreight).prop("checked",i.Settings.TypeBranchLineFreight)}}__getExpandedHtml(n){const u=this,i=n.recid,f="blockData_"+i,e="blockFbEnter_"+i,o="blockFbAddr_"+i,s="selectDeniedLocomotives_"+i,h="selectBlockLocks_"+i,y=getThemeJsonDataById(n.fbEnter),p=getThemeJsonDataById(n.fbIn);let t='<div id="'+f+'" style="padding: 5px; width: 100%; float: left;">',c=-1;try{c=y.addresses.Addr}catch(w){}let l=-1;try{l=p.addresses.Addr}catch(w){}t+='<div class="w2ui-field">';t+="<label>Feedback:<\/label>";t+='<div>Enter <input id="'+e+'" value="'+c+'" style="width: 75px;"> In <input id="'+o+'" value="'+l+'" style="width: 75px;"><\/div>';t+="<\/div>";t+='<div class="w2ui-field">';t+="<label>Denied Locs.:<\/label>";t+='<select name="selectDeniedLocomotives[]" id="'+s+'" multiple="multiple" style="width: 250px;">';t+="<\/select>";t+="<\/div>";t+='<div class="w2ui-field">';t+="<label>Additional Blocks:<\/label>";t+='<select name="selectBlockLocks[]" id="'+h+'" multiple="multiple" style="width: 250px;">';t+="<\/select>";t+="<\/div>";const a=u.__getCheckboxOptions("Options:",i),v=u.__getCheckboxTypes("Types:",i);t+=a.html;t+=v.html;t+="<\/div>";let r=[];return r=r.concat(a.checkboxIds),r=r.concat(v.checkboxIds),{renderId:f,fbEnterId:e,fbInId:o,selectDeniedLocsId:s,selectBlockLocksId:h,checkboxIds:r,renderHtml:t}}__getCtrlIdsForOptionsAndTypes(n){return{chkIdWait:"blockChkWait_"+n,chkIdDirection:"blockChkDirection_"+n,chkIdMainline:"blockChkMainline_"+n,chkIdBbt:"blockChkBbt_"+n,chkIdOthers:"blockChkTypeOthers_"+n,chkIdLocal:"blockChkTypeLocal_"+n,chkIdIntercity:"blockChkTypeIntercity_"+n,chkIdFreight:"blockChkTypeFreight_"+n,chkIdShunting:"blockChkTypeShunting_"+n,chkIdRegional:"blockChkTypeRegional_"+n,chkIdBranchLine:"blockChkTypeBranchLine_"+n,chkIdBranchLineFreight:"blockChkTypeBranchLineFreight_"+n}}__getCheckboxOptions(n,t){let i="";i+='<div class="w2ui-field">';i+="<label>"+n+"<\/label>";i+='<div style="padding-top: 7px;">';const u='style="word-wrap:break-word; font-weight: normal; margin-right: 10px;"',f='style="vertical-align: middle;"';var r=this.__getCtrlIdsForOptionsAndTypes(t);return i+="<label "+u+'><input name="OptionDirection" id="'+r.chkIdDirection+'" type="checkbox" '+f+"> Allow change direction <\/label>",i+="<label "+u+'><input name="OptionBbt" id="'+r.chkIdBbt+'" type="checkbox" '+f+"> Speed Curve <\/label>",i+="<\/div>",i+="<\/div>",{html:i,checkboxIds:[r.chkIdWait,r.chkIdDirection,r.chkIdMainline,r.chkIdBbt]}}__getCheckboxTypes(n,t){let r="";r+='<div class="w2ui-field">';r+="<label>"+n+"<\/label>";r+='<div style="padding-top: 7px;">';const u='style="word-wrap:break-word; font-weight: normal; margin-right: 10px;"',f='style="vertical-align: middle;"';var i=this.__getCtrlIdsForOptionsAndTypes(t);return r+="<label "+u+'><input name="TypeOthers" id="'+i.chkIdOthers+'" type="checkbox" '+f+"> Others <\/label>",r+="<label "+u+'><input name="TypeLocal" id="'+i.chkIdLocal+'" type="checkbox" '+f+"> Local <\/label>",r+="<label "+u+'><input name="TypeIntercity" id="'+i.chkIdIntercity+'" type="checkbox" '+f+"> Intercity <\/label>",r+="<label "+u+'><input name="TypeFreight" id="'+i.chkIdFreight+'" type="checkbox" '+f+"> Freight <\/label>",r+="<label "+u+'><input name="TypeShunting" id="'+i.chkIdShunting+'" type="checkbox" '+f+"> Shunting <\/label>",r+="<label "+u+'><input name="TypeRegional" id="'+i.chkIdRegional+'" type="checkbox" '+f+"> Regional <\/label>",r+="<label "+u+'><input name="TypeBranchLine" id="'+i.chkIdBranchLine+'" type="checkbox" '+f+"> Branch Line <\/label>",r+="<label "+u+'><input name="TypeBranchLineFreight" id="'+i.chkIdBranchLineFreight+'" type="checkbox" '+f+"> Branch Line (Freight) <\/label>",r+="<\/div>",r+="<\/div>",{html:r,checkboxIds:[i.chkIdOthers,i.chkIdLocal,i.chkIdIntercity,i.chkIdFreight,i.chkIdShunting,i.chkIdRegional,i.chkIdBranchLine,i.chkIdBranchLineFreight]}}__getCheckboxHtml(n,t,i,r=false){let f="";r===!0&&(f="checked");let u="";return u+='<div class="w2ui-field">',u+="<label>"+n+"<\/label>",u+='<div style="padding-top: 7px;"><input name="'+i+'" id="'+t+'" type="checkbox" '+f+"><\/div>",u+"<\/div>"}__addBlockFeedbackHiglight(n){const t=window.planField;if(t){toggleAllLocomotiveInformationOpacity(!1);var i=n.blockId,r=n.fbEnter,u=n.fbIn;const f=$("div.ctrlItemFeedback");f.each(function(){const n=$(this).attr("id");(n===r||n===u)&&$(this).addClass("highlightFeedback")});const e=$("div.ctrlItemBlock");e.each(function(){const n=$(this).attr("id");n===i&&($(this).addClass("highlightFeedbackBlock"),$(this).find("img").css({opacity:0}))})}}__removeBlockFeedbackHiglight(){const n=window.planField;if(n){toggleAllLocomotiveInformationOpacity(!0);const t=$("div.ctrlItemFeedback");t.each(function(){$(this).removeClass("highlightFeedback")});const i=$("div.ctrlItemBlock");i.each(function(){$(this).removeClass("highlightFeedbackBlock");$(this).find("img").css({opacity:1})})}}updateBlocks(n){const t=this,i=w2ui[t.__gridName];console.log(n)}updateFeedbacks(n){const u=this,f=w2ui[u.__gridName],i=n.data;u.__recentFeedbacksData=i;const r=[];let e=0,t;const o=i.length;for(t=0;t<o;++t){const n=i[t];if(typeof n!="undefined"&&n!=null){const u=f.find({blockId:n.BlockId});u.length===0&&(r.push({recid:e+1,blockId:n.BlockId,fbEnter:n.FbEnter,fbIn:n.FbIn}),++e)}}r.length>0&&f.add(r)}controlCreated(n){const t=this;try{const r=n.data(constDataThemeItemObject),u=isFeedback(r.editor.themeId);if(u===!1)return;const i=n.attr("id");t.__fbsList.includes(i)===!1&&t.__fbsList.push(i);const f=new Intl.Collator(undefined,{numeric:!0,sensitivity:"base"});t.__fbsList=t.__fbsList.sort(f.compare);t.__refreshFbCells()}catch(i){console.log(i)}}controlRemoved(n){const t=this,i=t.__fbsList.length;for(let r=0;r<i;r++)if(t.__fbsList[r]===n){t.__fbsList.splice(r,1);break}t.__refreshFbCells()}__refreshFbCells(){const n=this,t=w2ui[n.__gridName];t.columns[2].editable.items=n.__fbsList;t.columns[3].editable.items=n.__fbsList}clearGrid(){const n=this,t=w2ui[n.__gridName];n.__recentFeedbacksData=[];t.clear(!0);t.reset()}}class EcosHandler{constructor(){console.log("**** construct EcosHandler")}install(){}}class EditMenuBar{constructor(n={}){console.log("**** construct EditMenuBar");this.editMenu=$("#planField > div#planFieldItemEdit");this.cmdRotLeft=this.editMenu.find("div.rot-left");this.cmdRotRight=this.editMenu.find("div.rot-right");this.cmdRemove=this.editMenu.find("div.delete");this.cmdUngroup=this.editMenu.find("div.ungroup");this.options=n}rot(n,t,i=false){var e=getThemeJsonData(t),o=null,r=t.data(constDataThemeDimensionIndex),s,h,c;if(typeof r=="undefined"&&(r=0),s={w:1,h:1},h=1,typeof e.dimensions!="undefined"&&e.dimensions.length>0&&(s=e.dimensions[0],h=e.dimensions.length),s.w===1&&s.h===1?(o="center center",n===0?(++r,r>3&&(r=0)):n===1&&(--r,r<0&&(r=3))):(o="top left",n===0?r=r===1?0:1:n===1&&(r=r===0?1:0)),t.data(constDataThemeDimensionIndex,r),h>1){var u=null,f=null,l=r%4==0;i?l||(u=this.currentSelection.css("left"),f="calc( "+u+" + "+constItemWidth+"px)",this.currentSelection.css("left",f)):n>-1&&(l?(u=this.currentSelection.css("left"),f="calc( "+u+" - "+constItemWidth+"px)",this.currentSelection.css("left",f)):(u=this.currentSelection.css("left"),f="calc( "+u+" + "+constItemWidth+"px)",this.currentSelection.css("left",f)))}return c="rotate("+r*90+"deg)",this.currentSelection.css("transform-origin",o),this.currentSelection.css("transform",c),i||(this.updateEditMenuPositionAndEvents(t),h===1&&window.toolbox.rotate({themeId:e.id,themeDimIdx:r,transformOrigin:o,transform:c}),window.serverHandling.sendControl(this.currentSelection)),!0}setCurrentSelection(n){this.currentSelection=n;this.unbindMenuBar();const t=this;this.cmdRotLeft.click(function(n){n=n||window.event;n.preventDefault();n.stopPropagation();var i=t.rot(1,t.currentSelection);!i});this.cmdRotRight.click(function(n){n=n||window.event;n.preventDefault();n.stopPropagation();var i=t.rot(0,t.currentSelection);!i});this.cmdRemove.click(function(n){n=n||window.event;n.preventDefault();n.stopPropagation();t.hideEditMenu();var i=t.currentSelection.attr("id");t.currentSelection.remove();window.serverHandling.removeControl(i)});this.cmdUngroup.click(function(n){(n=n||window.event,n.preventDefault(),n.stopPropagation(),typeof planField!="undefined")&&window.planField.clearCtrlSelection()})}unbindMenuBar(){this.cmdRemove.unbind("click");this.cmdRotLeft.unbind("click");this.cmdRotRight.unbind("click")}updateEditMenuPositionAndEvents(n){var f;if(typeof n!="undefined"&&n!=null){const u=n.get(0),o=u.getBoundingClientRect().width,i=u.offsetLeft,r=u.offsetTop,s=i-constItemWidth/2,l=i+o+constItemWidth/2;f=$("div.ctrlItem[id]");const e=getCtrlOfPosition(s,r+10,f),h=getCtrlOfPosition(l,r+10,f);var a=parseInt(this.editMenu.width()),c=parseInt(this.editMenu.height()),t=!0;if(s<0?t=!1:e!=null&&h==null?t=!0:e==null&&h==null?t=!0:e==null&&(t=!1),t){const n=i-a-10,t=r-c/3;this.editMenu.css({left:n+"px",top:t+"px"})}else{const n=i+o+5,t=r-c/3;this.editMenu.css({left:n+"px",top:t+"px"})}}}hideEditMenu(){this.unbindMenuBar();this.editMenu.hide()}showEditMenu(){this.editMenu.show()}}const ErrorHandlerLevel={Info:1,Error:2};class ErrorHandler{constructor(){console.log("**** construct ErrorHandler");this.__overlay=$("div.overlay");this.__overlayText=$("div.overlay div.overlayText");this.setLevel(ErrorHandler.Info)}setLevel(n){typeof n=="undefined"&&(n=ErrorHandlerLevel.Info);let t="infoOverlay";switch(n){case ErrorHandlerLevel.Info:t="infoOverlay";break;case ErrorHandlerLevel.Error:t="errorOverlay"}this.__overlayText.removeClass("infoOverlay");this.__overlayText.removeClass("errorOverlay");this.__overlayText.addClass(t)}setText(n,t=false){const i=this.__overlay,r=this.__overlayText;i.is(":visible")?t&&r.html(n):(i.show(),r.html(n))}hide(){const n=this.__overlay,t=this.__overlayText;n.hide();t.html("")}}class Events{constructor(){this.__triggers={}}on(n,t){this.__triggers[n]||(this.__triggers[n]=[]);this.__triggers[n].push(t)}triggerHandler(n,t){if(this.__triggers[n])for(var i in this.__triggers[n])this.__triggers[n][i](t)}}class FeedbackVisualization{constructor(){console.log("**** construct FeedbackVisualization");this.__installed=!1;this.__dialogName="dialogFeedbackVisualization";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n,!1);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"));typeof this.__recentSensorData!="undefined"&&this.__recentSensorData!=null&&this.updateFeedbackSensors(this.__recentSensorData)}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}install(n={}){const t=this,r=this.isShown();if(!r&&!this.__installed){(typeof n=="undefined"||typeof n.autoOpen=="undefined")&&(n.autoOpen=!1);const i=this.__windowGeometry.recent();$("#"+this.__dialogName).dialog({left:i.left,top:i.top,resizable:!1,closeOnEscape:!1,autoOpen:n.autoOpen,resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:0,height:0})},close:function(){}});this.__installed=!0}}updateFeedbackSensors(n){const r=this;if(r.__recentSensorData=n,r.isShown()!==!1){let u=0,t;const e=n.length;for(t=0;t<e;++t){const i=n[t];r.__addPort(t,u,i.ports);u+=i.ports}let i;const o=n.length;for(i=0;i<o;++i){const t=n[i];if(typeof t!="undefined"&&t!=null){for(let n=15;n>=0;--n){const u="div#feedbackPort_"+i+"_"+n,r=$(u),f=1<<n;(t.stateOriginal&f)!=0?r.removeClass("feedbackStateGreen").addClass("feedbackStateRed"):r.removeClass("feedbackStateRed").addClass("feedbackStateGreen")}u+=t.ports}}const s=$("div.feedbackOuterWrapper");s.css({height:n.length*45+"px"});const f=$("#"+this.__dialogName);f.dialog("option","width",490);f.dialog("option","height",n.length*50+30)}}__addPort(n,t,i){const s=$("div.feedbackOuterWrapper"),o="feedbackPort_"+n,u=$("div#"+o);u!=="undefined"&&u!=null&&u.length>0&&u.remove();const r=$("<div>").attr("id",o).css({width:"470px"}).addClass("feedbackPort"),h=$("<div>").css({display:"block",float:"left","padding-top":"4px","padding-right":"5px"}).html("Port "+(n+1));r.append(h);for(let u=0;u<i;++u){const e="feedbackPort_"+n+"_"+(i-u-1),f=$("<div>").attr("id",e).attr("data-tipso-title","Port("+(n+1)+")  Index("+(i-u-1)+")  EcosAddr("+(t+(i-u-1))+")").addClass("feedbackStateRed");r.append(f);f.tipso({size:"tiny",speed:100,delay:250,useTitle:!0,width:"auto",background:"#333333",titleBackground:"#333333"})}s.append(r);let f="",e="";i===16?(f="440px",e="-20px"):i===8&&(f="233px",e="-20px");const c=$("<div>").css({position:"relative","font-size":"0.75em",left:f,top:e,width:"20px",height:"20px",overflow:"visible","text-align":"right"}).html(t),l=$("<div>").css({position:"relative","font-size":"0.75em",left:"50px",width:"20px",height:"20px",overflow:"visible"}).html(t+i-1);r.append(l);r.append(c)}}const constItemWidth=32,constItemHeight=32,constDataThemeDimensionIndex="theme-dimension-index",constDataThemeItemObject="theme-item-object",constDataThemeId="theme-id",constKeyEnter=13,constKeyEscape=27,constGitWebsite="https://github.com/cbries/railessentials",constGitWikiWebsite="https://github.com/cbries/railessentials/wiki/Table-of-Content",constGitUsedSwWebsite="https://github.com/cbries/railessentials#third-party-components-at-their-best",ListOfFunctionDescription={2:"Function",3:"Light",4:"Light_0",5:"Light_1",7:"Sound",8:"Music",9:"Announce",10:"Routing Speed",11:"abv",32:"Coupler",33:"Steam",34:"Panto",35:"Highbeam",36:"Bell",37:"Horn",38:"Whistle",39:"Door Sound",40:"Fan",42:"Shovel Work Sound",44:"Shift",260:"Interior Lighting",261:"Plate Light",263:"Brakesound",299:"Crane Raise Lower",555:"Hook Up Down",773:"Wheel Light",811:"Turn",1031:"Steam Blow",1033:"Radio Sound",1287:"Coupler Sound",1543:"Track Sound",1607:"Notch up",1608:"Notch down",2055:"Thunderer Whistle",3847:"Buffer Sound"};class LightAndPower{constructor(){console.log("**** construct LightAndPower");this.__rgbStripesIpAddr="ws://192.168.178.66:81";this.__powerPlugIpAddr="ws://192.168.178.62:81";this.__installed=!1;this.__ctrlIdMorning="rgbColorMorning";this.__ctrlIdNoon="rgbColorNoon";this.__ctrlIdAfternoon="rgbColorAfternoon";this.__ctrlIdNight="rgbColorNight";this.__dialogName="dialogLightAndPower";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__fieldNamePowerStates=this.__dialogName+"_powerStates";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n,!1);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"))}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}install(n={}){const t=this,e=this.isShown();if(!e&&!this.__installed){(typeof n=="undefined"||typeof n.autoOpen=="undefined")&&(n.autoOpen=!1);t.__c1DelayTimeout=0;t.__c2DelayTimeout=0;t.__c3DelayTimeout=0;t.__c4DelayTimeout=0;const r=[this.__ctrlIdMorning,this.__ctrlIdNoon,this.__ctrlIdAfternoon,this.__ctrlIdNight];let i;const o=r.length;for(i=0;i<o;++i){const n=$("#"+r[i]);n.colorpicker({stop:function(t,i){n.css({"background-color":i.css,color:i.css})}});var u=n.val();n.css({"background-color":"#"+u,color:"#"+u,"text-align":"left"});n.w2field("text")}$("#dialogLightAndPower input[type=eu-time]").w2field("time",{format:"h24"});const f=this.__windowGeometry.recent();$("#"+this.__dialogName).dialog({height:430,width:450,left:f.left,top:f.top,resizable:!1,closeOnEscape:!1,autoOpen:n.autoOpen,resize:function(){},resizeStop:function(n,t){console.log(t)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{})},close:function(){}});this.__applyRecentPowerSwitchStates(!0);this.__installed=!0}}__storePowerSwitchStates(){let n={in1:$("#powerChkIn1").is(":checked"),in2:$("#powerChkIn2").is(":checked"),in3:$("#powerChkIn3").is(":checked"),in4:$("#powerChkIn4").is(":checked")};$.localStorage.setItem(this.__fieldNamePowerStates,JSON.stringify(n))}__applyRecentPowerSwitchStates(n=false){const t=this,r=$("#powerChkIn1"),o=$("#powerChkIn1DelaySecs"),u=$("#powerChkIn2"),s=$("#powerChkIn2DelaySecs"),f=$("#powerChkIn3"),h=$("#powerChkIn3DelaySecs"),e=$("#powerChkIn4"),c=$("#powerChkIn4DelaySecs");n===!0&&(r.w2field("checkbox"),r.change(function(){t.__storePowerSwitchStates();t.__updatePowerDelayState(r,o);try{const n=$("#powerChkIn1DelaySpinner"),i=parseInt(o.val());r.is(":checked")?t.__c1DelayTimeout===0&&(n.show(),t.__c1DelayTimeout=setTimeout(function(){t.__sendPowerSwitch();clearTimeout(t.__c1DelayTimeout);t.__c1DelayTimeout=0;n.hide()},i*1e3)):(n.hide(),t.__sendPowerSwitch(),t.__c1DelayTimeout!==0&&(clearTimeout(t.__c1DelayTimeout),t.__c1DelayTimeout=0))}catch(n){}}),$("#powerChkIn1DelaySecs").w2field("int",{autoFormat:!0,min:0,max:30,silent:!1}),u.w2field("checkbox"),u.change(function(){t.__storePowerSwitchStates();t.__updatePowerDelayState(u,s);try{const n=$("#powerChkIn2DelaySpinner"),i=parseInt(s.val());u.is(":checked")?t.__c2DelayTimeout===0&&(n.show(),t.__c2DelayTimeout=setTimeout(function(){t.__sendPowerSwitch();clearTimeout(t.__c2DelayTimeout);t.__c2DelayTimeout=0;n.hide()},i*1e3)):(n.hide(),t.__sendPowerSwitch(),t.__c2DelayTimeout!==0&&(clearTimeout(t.__c2DelayTimeout),t.__c2DelayTimeout=0))}catch(n){}}),$("#powerChkIn2DelaySecs").w2field("int",{autoFormat:!0,min:0,max:30,silent:!1}),f.w2field("checkbox"),f.change(function(){t.__storePowerSwitchStates();t.__updatePowerDelayState(f,h);try{const n=$("#powerChkIn3DelaySpinner"),i=parseInt(h.val());f.is(":checked")?t.__c3DelayTimeout===0&&(n.show(),t.__c3DelayTimeout=setTimeout(function(){t.__sendPowerSwitch();clearTimeout(t.__c3DelayTimeout);t.__c3DelayTimeout=0;n.hide()},i*1e3)):(n.hide(),t.__sendPowerSwitch(),t.__c3DelayTimeout!==0&&(clearTimeout(t.__c3DelayTimeout),t.__c3DelayTimeout=0))}catch(n){}}),$("#powerChkIn3DelaySecs").w2field("int",{autoFormat:!0,min:0,max:30}),e.w2field("checkbox"),e.change(function(){t.__storePowerSwitchStates();t.__updatePowerDelayState(e,c);try{const n=$("#powerChkIn4DelaySpinner"),i=parseInt(c.val());e.is(":checked")?t.__c4DelayTimeout===0&&(n.show(),t.__c4DelayTimeout=setTimeout(function(){t.__sendPowerSwitch();clearTimeout(t.__c4DelayTimeout);t.__c4DelayTimeout=0;n.hide()},i*1e3)):(n.hide(),t.__sendPowerSwitch(),t.__c4DelayTimeout!==0&&(clearTimeout(t.__c4DelayTimeout),t.__c4DelayTimeout=0))}catch(n){}}),$("#powerChkIn4DelaySecs").w2field("int",{autoFormat:!0,min:0,max:30}),$("#rgbColorMorningRadio").w2field("radio"),$("#rgbColorNoonRadio").w2field("radio"),$("#rgbColorAfternoonRadio").w2field("radio"),$("#rgbColorNightRadio").w2field("radio"),$("#rgbColorMorningRadio").change(function(){t.__sendRgbStripe()}),$("#rgbColorNoonRadio").change(function(){t.__sendRgbStripe()}),$("#rgbColorAfternoonRadio").change(function(){t.__sendRgbStripe()}),$("#rgbColorNightRadio").change(function(){t.__sendRgbStripe()}));const l=$.localStorage.getItem(this.__fieldNamePowerStates);let i=JSON.parse(l);typeof i=="undefined"||i==null?i={in1:!1,in2:!1,in3:!1,in4:!1}:(r.prop("checked",i.in1),u.prop("checked",i.in2),f.prop("checked",i.in3),e.prop("checked",i.in3));t.__updatePowerDelayState(r,o);t.__updatePowerDelayState(u,s);t.__updatePowerDelayState(f,h);t.__updatePowerDelayState(e,c)}__updatePowerDelayState(n,t){const i=n.is(":checked");t.attr("disabled",i)}__sendRgbStripe(){const n=this,t=n.__getRgbStripesObject();n.__trigger("relayCommand",{mode:"websocket",target:this.__rgbStripesIpAddr,contentType:"application/json",data:t})}__getRgbStripesObject(){let n={r:255,g:255,b:255,w:1023};return $("#rgbColorMorningRadio").is(":checked")===!0?(n=hexToRgbA($("#rgbColorMorning").val()),n.w=200):$("#rgbColorNoonRadio").is(":checked")===!0?(n=hexToRgbA($("#rgbColorNoon").val()),n.w=1023):$("#rgbColorAfternoonRadio").is(":checked")===!0?(n=hexToRgbA($("#rgbColorAfternoon").val()),n.w=500):$("#rgbColorNightRadio").is(":checked")===!0&&(n=hexToRgbA($("#rgbColorNight").val()),n.w=100),n}__sendPowerSwitch(){const n=this,t={in1:$("#powerChkIn1").is(":checked"),in2:$("#powerChkIn2").is(":checked"),in3:$("#powerChkIn3").is(":checked"),in4:$("#powerChkIn4").is(":checked")};n.__trigger("relayCommand",{mode:"websocket",target:this.__powerPlugIpAddr,contentType:"application/json",data:t})}}const constLocomotiveControlBaseName="locomotiveCtrl_",constLocomotiveMinSpeed=0;class LocomotiveControl{constructor(){console.log("**** construct LocomotiveControl");this.__tplMain="./components/dialogLocomotiveControl/locomotiveControl.html";this.__baseDlgId=constLocomotiveControlBaseName;this.__dlgId=null;this.__dlgElement=null;this.__dlgIsClosed=!0;this.__windowGeometry=null;this.__locomotiveRecord=null;this.__speedTrigger=!0;this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}updateSpeedState(n){if(!this.__dlgIsClosed){const t=this.__dlgElement.find(".locomotiveSpeedometer");t&&(this.__speedTrigger=!1,t.slider("value",n.speedstep),this.__speedTrigger=!0,$(".locomotiveSpeedstepValue").html(n.speedstep))}}updateDirectionState(n){if(!this.__dlgIsClosed){const f=this,u=n.objectId,t=$("#locomotiveCtrl_"+u),i=t.find(".cmdLocBackward"),r=t.find(".cmdLocForward");i.css({color:"black"});r.css({color:"black"});n.direction===1?i.css({color:"green"}):n.direction===0&&r.css({color:"green"})}}updateFunctionStates(n){const r=n.objectId,u=n.nrOfFunctions,f=n.funcset,t=n.funcdesc;let i=0;for(let n=0;n<t.length;++n){const e=f[n],o=t[n];if(o.type!==0){const s="fncCommand_"+r+"_"+n,h=$("button."+s);if(this.__changeButtonStyle(h,e==="1"),++i,i>=u)break}}}__changeButtonStyle(n,t){t?n.css({"font-weight":"bold",color:"green"}):n.css({"font-weight":"bold",color:"red"})}open(n){const t=this;this.__locomotiveRecord=n;const r=this.__locomotiveRecord.name,s=this.__locomotiveRecord.speedstep,u=this.__locomotiveRecord.oid,h=this.__locomotiveRecord.noOfFunctions,c=this.__locomotiveRecord.funcset,l=this.__locomotiveRecord.funcdesc;this.__dlgId=this.__baseDlgId+u;this.__dlgSelector="#"+this.__dlgId;this.__windowGeometry=new WindowGeometryStorage(this.__dlgId);const v=$(this.__dlgSelector);if(v.length>0)return!1;this.__dlgIsClosed=!1;const y=$("div[id=tplLocomotiveControl]");let i=y.clone();this.__dlgElement=i;i.attr("id",this.__dlgId);i.attr("title",r);i.addClass("locomotiveControlMain");i.dialog({height:350,resizable:!1,autoOpen:!1,resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:n.target.clientWidth,height:n.target.clientHeight})},close:function(){i.remove();t.__trigger("dialogClosed",{instance:this})}});const p=i.find(".locomotiveSpeedometer");p.slider({orientation:"vertical",range:"min",min:constLocomotiveMinSpeed,max:t.__locomotiveRecord.speedstepMax,value:s,slide:function(n,t){$(".locomotiveSpeedstepValue").html(t.value)},stop:function(n,i){if(t.__speedTrigger){const r=t.__locomotiveRecord.oid;t.__trigger("speedChanged",{oid:r,speedstep:i.value})}}});$(".locomotiveSpeedstepValue").html(s);const a="img_"+this.__dlgId,f=i.find(".locomotiveImage");f.attr("id",a);f.attr("src","./images/noimage32x32.png");f.attr("alt",r);loadLocomotiveImageIntoHtml(a,r);const w=function(n){const i=$(n.currentTarget).data("function"),r=t.__locomotiveRecord.oid;t.__trigger("functionChanged",{oid:r,fncIdx:i,timestamp:Date.now()})},b=function(n){const i=$(n.currentTarget).data("speedstep"),r=t.__locomotiveRecord.oid;t.__trigger("speedChanged",{oid:r,speedstep:i,timestamp:Date.now()})},e={"font-size":"14px","font-weight":"bold",width:"50px",padding:"2px",margin:"2px"},k=i.find("button").not("button[data-function]");k.each(function(){$(this).button();$(this).data("speedstep")?($(this).css(e),$(this).click(b)):$(this).data("direction")&&($(this).css(e),$(this).css({width:"25px",display:"inline-block",margin:"-3px","margin-bottom":"2px"}),$(this).click(function(){const n=t.__locomotiveRecord.oid;t.__trigger("directionChanged",{oid:n,force:$(this).data("direction")})}))});const d=getArrayOfFunctions2(u,h,c,l),g=i.find("td.locomotiveCommandField");let o=0;for(let n=0;n<c.length;++n){const f=d[o],r=l[n];if(r.type!==0){const s="fncCommand_"+u+"_"+n;let t=$("<button>").text("F"+n);t.addClass("locomotiveCommand");t.addClass(s);t.data("function",n);let i=ListOfFunctionDescription[r.type];if((typeof i=="undefined"||i==null)&&(i="Function"),t.data("tipso-title",i),t.button(),t.css(e),this.__changeButtonStyle(t,f.state),t.click(w),t.appendTo(g),t.tipso({size:"tiny",speed:100,delay:250,useTitle:!0,width:"auto",background:"#333333",titleBackground:"#333333"}),++o,o>=h)break}}return i.dialog("open"),!0}}class Locomotives{constructor(){console.log("**** construct Locomotives");this.winLocomotives=null;this.gridLocomotives=null;this.__locomotiveImages={};this.__recentEcosData=null;this.__installed=!1;this.__gridName="gridLocomotives";this.__dialogName="dialogLocomotives";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"));this.updateLocomotives(this.__recentEcosData);w2ui[this.__gridName].refresh()}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}__handleLocomotiveFunctionToggle(){}__renderImage(n){const t="loadLocomotivesImage_"+n.oid;loadLocomotiveImageIntoHtml(t,n.name);return'<div style="height: 100%; width: 100%; white-space: nowrap; text-align: center; padding-top: 3px;"><span style="display: inline-block;height: 100%;vertical-align: middle;"><\/span><img id="'+t+'" style="height: 16px; width: 32px; margin: auto;" src="./images/noimage.png" /><\/div>'}__renderFunctions(n){const i=n.noOfFunctions;if(i==0)return"<b>&mdash;<\/b>";const r=window.getArrayOfFunctions(n);let t="";return $(r).each(function(){const n=this;let i=ListOfFunctionDescription[n.type];typeof i=="undefined"&&(i="Unknown");const r={oid:n.oid,fncIdx:n.idx,timestamp:Date.now()},u=window._htmlEntities(JSON.stringify(r)),f="fncCommand_"+n.oid+"_"+n.idx,e="onClick=\"window.__eventTrigger('functionChanged', '"+u+"');\"",o=n.state?"checked":"";t+='<input class="'+f+'" type="checkbox" '+o+" "+e+' title="'+i+'">'}),t}getLocomotiveRecord(n){if(n<=0||!w2ui[this.__gridName])return null;const i=w2ui[this.__gridName],t=i.find({oid:n});if(typeof t!="undefined"&&t!=null&&t.length>0){const n=t[0];return i.get(n)}return null}install(n={}){const t=this,u=this.isShown();if(!u){typeof n.autoOpen=="undefined"&&(n.autoOpen=!1);this.__gridRowDoubleBlickCount=0;this.__expandedPreferences={};const i=this.__windowGeometry.recent();if($("#"+this.__dialogName).dialog({height:i.height,width:i.width,left:i.left,top:i.top,closeOnEscape:!1,autoOpen:n.autoOpen,resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:n.target.clientWidth,height:n.target.clientHeight})}}),!w2ui[this.__gridName]){const n=$("#"+this.__gridName);n.w2grid({name:this.__gridName,header:"Locomotives",multiSelect:!1,show:{toolbar:!0,footer:!0,toolbarAdd:!1,toolbarDelete:!1,toolbarEdit:!1,toolbarSave:!1},dragRow:!0,textSearch:"contains",recid:"oid",searches:[{field:"name",caption:"Name",type:"text"}],sortData:[{field:"name",direction:"asc"}],columns:[{field:"oid",caption:'<div style="text-align: center; padding-left: 6px;"><i class="far fa-id-badge"><\/i><\/div>',style:"text-align: center",size:"5%",sortable:!0},{field:"locImage",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-camera-retro"><\/i><\/div>',size:"10%",style:"text-align: center",render:t.__renderImage},{field:"name",caption:"Name",size:"30%",sortable:!0,editable:{type:"text"}},{field:"protocol",caption:"Protocol",size:"10%",sortable:!0},{field:"addr",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-at"><\/i><\/div>',style:"text-align: center",size:"5%"},{field:"speed",caption:"Speed",size:"10%",hidden:!0},{field:"speedstep",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-tachometer-alt"><\/i><\/div>',style:"text-align: center",size:"5%",hidden:!1},{field:"speedstepMax",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-tachometer-alt"><\/i> (max)<\/div>',style:"text-align: center",size:"10%",hidden:!1},{field:"funcset",caption:"Functions",size:"15%",render:t.__renderFunctions},{field:"funcdesc",caption:"Func.-Desc.",hidden:!0},{field:"noOfFunctions",caption:"No. of Functions",hidden:!0},{field:"locked",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-unlock-alt"><\/i><\/div>',size:"5%",style:"text-align: center",editable:{type:"checkbox",style:"text-align: center"}},{field:"speedLevel1",caption:"Level1",size:"1%",hidden:!0},{field:"speedLevel2",caption:"Level2",size:"1%",hidden:!0},{field:"speedLevel3",caption:"Level3",size:"1%",hidden:!0},{field:"speedLevel4",caption:"Level4",size:"1%",hidden:!0},{field:"isCleaner",caption:'<div style="text-align: center; padding-left: 6px;"><i class="fas fa-bath"><\/i><\/div>',size:"5%",hidden:!1,style:"text-align: center",editable:{type:"checkbox",style:"text-align: center"}},],records:[],onExpand:function(n){if(t.__gridRowDoubleBlickCount!==0){--t.__gridRowDoubleBlickCount;n=n||window.event;n.preventDefault();n.stopPropagation();return}const r=w2ui[t.__gridName],u=r.get(n.recid),i=t.__getExpandedHtml(u);i.recid=n.recid;$("#"+n.box_id).html(i.renderHtml);t.__expandedPreferences[n.recid]=!0;n.onComplete=function(){const u=i.checkboxIds;let r=[];for(let n=0;n<u.length;++n){const t=$("#"+u[n]);typeof t!="undefined"&&t!=null&&(t.w2field("checkbox"),r.push(t))}const f=$("#"+i.blockCurrentId);f.w2field("list",{items:[]});$("div#locomotivesData_"+n.recid+" #"+i.selectId+" + span").css({"margin-left":"10px"});$("div#locomotivesData_"+n.recid+" #"+i.selectId+" + span span.selection span.select2-selection").css({"border-radius":"3px",border:"1px solid #cacaca"});t.__loadRecentStatesFor(n.recid);f.change(function(){t.__saveLocomotiveSettings(i)});for(let n=0;n<r.length;++n)r[n].change(function(){t.__saveLocomotiveSettings(i)});for(let n=0;n<i.speedLevel.length;++n){const r=i.speedLevel[n];if(typeof r!="undefined"&&r!=null){const u=$("#"+r);u.change(function(){const n=$(this).attr("id"),i=n.lastIndexOf("_"),r=n.substr(0,i),u=n.substr(i+1);t.__trigger("setting",{mode:"locomotive",cmd:"speedLevel",value:{oid:u,level:r,value:parseInt(this.value)}})})}}const e=$("#cmdSpeedCurveContainer_"+n.recid);e.w2field("button");e.click(function(){const i=n.recid;t.__showSpeedCurveDialog(i)});t.__resizePreferences()}},onCollapse:function(n){t.__expandedPreferences[n.recid]=!1},onDblClick:function(n){t.__gridRowDoubleBlickCount++;const i=w2ui[t.__gridName],r=n.column,u=i.columns[r];if(u.field==="name"){n.stopPropagation();return}const f=i.get(n.recid);t.__trigger("locomotiveDoubleClick",f)},onSelect:function(){bringToFront(t.__dialogName)}})}const r=w2ui[t.__gridName].toolbar;r&&r.add({type:"button",id:"cmdSave",text:"Save ",img:"fas fa-save",tooltip:function(){return"Applies all changes to the server."},onClick:function(){const n=w2ui[t.__gridName],i=n.getChanges();for(let r=0;r<i.length;++r){const f=i[r],c=f.recid,u=n.get(c),h=u.oid,e=f.name;typeof e!="undefined"&&e!=null&&(u.name=e,n.refreshCell(u,"name"),t.__trigger("setting",{mode:"locomotive",cmd:"rename",value:{oid:h,name:e}}));const o=f.locked;typeof o!="undefined"&&o!=null&&(u.locked=o,n.refreshCell(u,"locked"),t.__trigger("setting",{mode:"locomotive",cmd:"lock",value:{oid:h,locked:o}}));const s=f.isCleaner;typeof s!="undefined"&&s!=null&&(u.isCleaner=s,n.refreshCell(u,"isCleaner"),t.__trigger("setting",{mode:"locomotive",cmd:"cleaner",value:{oid:h,cleaner:s}}))}n.save()}});this.__installed=!0}}__getLocomotiveEcosData(n){const t=this;if(typeof t.__recentEcosData=="undefined"||t.__recentEcosData==null)return null;const i=parseInt(n);for(let n=0;n<t.__recentEcosData.length;++n){const r=t.__recentEcosData[n];if(r!=null&&r.objectId===i)return r}return null}__showSpeedCurveDialog(n){const t=this;w2ui.formSpeedCurve||$().w2form({name:"formSpeedCurve",style:"border: 0px; background-color: white;",formHTML:'<div class="w2ui-page page-0">    <div id="formSpeedCurveInstance" class="speedCurveDesign"><\/div><\/div><div class="w2ui-buttons">    <button class="w2ui-btn" name="cancel">Cancel<\/button>    <button class="w2ui-btn" name="save">Save<\/button><\/div>',fields:[],record:{},actions:{save:function(){const n=t.__speedCurveInstance.getData(),i=n.objectId;delete n.objectId;t.__saveLocomotiveSpeedCurve(i,n);w2popup.close()},cancel:function(){w2popup.close()}}});$().w2popup("open",{title:"SpeedCurve",body:'<div id="form" style="width: 100%; height: 100%;"><\/div>',style:"padding: 0px 0px 0px 0px; padding-left: 5px; background-color: white;",width:775,height:400,showMax:!1,onToggle:function(n){$(w2ui.foo.box).hide();n.onComplete=function(){$(w2ui.foo.box).show();w2ui.foo.resize()}},onOpen:function(i){i.onComplete=function(){$("#w2ui-popup #form").w2render("formSpeedCurve");const r=t.__getLocomotiveEcosData(n);let e="dcc128",u=55,f=15;r!=null&&(r.protocol==="DCC128"||r.protocol==="MM128"||r.protocol==="MFX"?(e="dcc128",u=55,f=15):r.protocol==="MMFKT"||r.protocol==="MM14"||r.protocol==="DCC14"?(e="dcc14",u=7,f=5):(r.protocol==="MM27"||r.protocol==="DCC28")&&(e="dcc28",u=7,f=5));const i=t.__getLocomotiveOfRecentData(n);let o="esu";if(i!=null&&i.SpeedCurve!=null){if(typeof i.SpeedCurve.steps!="undefined"&&i.SpeedCurve.steps!=null){o=[];for(let n=0;n<i.SpeedCurve.steps.length;++n)o.push(i.SpeedCurve.steps[n].speed)}typeof i.SpeedCurve.maxSpeed!="undefined"&&(u=i.SpeedCurve.maxSpeed);typeof i.SpeedCurve.maxTime!="undefined"&&(f=i.SpeedCurve.maxTime)}t.__speedCurveInstance=$("#w2ui-popup #formSpeedCurveInstance").speedCurve({objectId:n,speedMode:e,speedStepMaxDefault:u,speedTimeMaxDefault:f,height:220,preloadData:o});t.__speedCurveInstance.refresh()}}})}__resizePreferences(){const n=this.__expandedPreferences;$.each(n,function(n,t){if(t===!0)try{const t=$("div#locomotivesData_"+n).get(0).getBoundingClientRect().height;$("div#grid_gridLocomotives_frec_"+n+"_expanded").css({height:t+"px"})}catch(i){}})}__saveLocomotiveSpeedCurve(n,t){typeof t!="undefined"&&t!=null&&this.__trigger("setting",{mode:"locomotive",cmd:"speedCurve",value:{oid:n,data:t}})}__saveLocomotiveSettings(n){const t={},i=n.checkboxIds;for(let n=0;n<i.length;++n){const r=$("#"+i[n]);if(typeof r!="undefined"&&r!=null){const u=$(r).attr("name"),f=$(r).is(":checked");t[u]=f}}const r=n.recid;this.__trigger("setting",{mode:"locomotive",cmd:"locomotiveData",value:{oid:r,checkboxSettings:t}})}updateLocomotives2(n){const u=this,i=w2ui[u.__gridName],r=n.data;this.__recentLocomotivesData=r;for(let n in r)if(r.hasOwnProperty(n)){const f=parseInt(n),u=i.get(f);if(typeof u=="undefined"||u==null)continue;var t=r[f];if(typeof t=="undefined")continue;if(t==null)continue;u.locked!==t.IsLocked&&(u.locked=t.IsLocked,i.refreshCell(f,"locked"));u.isCleaner!==t.IsCleaner&&(u.isCleaner=t.IsCleaner,i.refreshCell(f,"isCleaner"));try{let n=0,r=0,e=0,o=0;typeof t.SpeedLevels!="undefined"&&t.SpeedLevels!=null&&(typeof t.SpeedLevels.speedLevel1!="undefined"&&t.SpeedLevels.speedLevel1!=null&&(n=t.SpeedLevels.speedLevel1),typeof t.SpeedLevels.speedLevel2!="undefined"&&t.SpeedLevels.speedLevel2!=null&&(r=t.SpeedLevels.speedLevel2),typeof t.SpeedLevels.speedLevel3!="undefined"&&t.SpeedLevels.speedLevel3!=null&&(e=t.SpeedLevels.speedLevel3),typeof t.SpeedLevels.speedLevel4!="undefined"&&t.SpeedLevels.speedLevel4!=null&&(o=t.SpeedLevels.speedLevel4));u.speedLevel1!==n&&(u.speedLevel1=n,i.refreshCell(f,"speedLevel1"));u.speedLevel2!==r&&(u.speedLevel2=r,i.refreshCell(f,"speedLevel2"));u.speedLevel3!==e&&(u.speedLevel3=e,i.refreshCell(f,"speedLevel3"));u.speedLevel4!==o&&(u.speedLevel4=o,i.refreshCell(f,"speedLevel4"))}catch(f){}}}updateLocomotives(n){const u=this;if(u.__recentEcosData=n,typeof n!="undefined"&&n!=null){const t=w2ui[u.__gridName];let r=[],i;const f=this.__recentEcosData.length;for(i=0;i<f;++i){const n=this.__recentEcosData[i];if(typeof n!="undefined"&&n!=null){const u=n.objectId,f=n.name,c=n.protocol,e=n.addr,l=n.speed,o=n.speedstep,a=n.speedstepMax,s=n.funcset,v=n.funcdesc,h=n.nrOfFunctions,y=t.find({oid:u});if(y.length<=0)r.push({oid:u,name:f,protocol:c,addr:e,speed:l,speedstep:o,speedstepMax:a,noOfFunctions:h,locked:!1,funcset:s,funcdesc:v});else{const i=t.get(u),c=function(){const n=constLocomotiveControlBaseName+u;return window.findLocomotivesDlg(n)},r=c();i.name!==f&&(i.name=f,t.refreshCell(u,"name"));i.addr!==e&&(i.addr=e,t.refreshCell(u,"addr"));i.speedstep!==o&&(i.speedstep=o,t.refreshCell(u,"speedstep"),r&&r.updateSpeedState(n));i.noOfFunctions!==h&&(i.noOfFunctions=h,t.refreshCell(u,"noOfFunctions"));i.funcset!==s&&(i.funcset=s,t.refreshCell(u,"funcset"),r&&r.updateFunctionStates(n));r&&r.updateDirectionState(n)}}}r.length>0&&t.add(r)}}__getCurrentSpeedLevelsOf(n,t){const o=this,i=o.__getLocomotiveOfRecentData(n);try{const n=i.SpeedLevels.speedLevel1,o=i.SpeedLevels.speedLevel2,s=i.SpeedLevels.speedLevel3,h=i.SpeedLevels.speedLevel4;var r=0,u=0,f=0,e=0;return r=typeof n!="undefined"&&n!=null?n.value:parseInt(t*.1),u=typeof o!="undefined"&&o!=null?o.value:parseInt(t*.3),f=typeof s!="undefined"&&s!=null?s.value:parseInt(t*.5),e=typeof h!="undefined"&&h!=null?h.value:parseInt(t*.6),{level1:parseInt(r),level2:parseInt(u),level3:parseInt(f),level4:parseInt(e)}}catch(s){return{level1:parseInt(t*.1),level2:parseInt(t*.3),level3:parseInt(t*.5),level4:parseInt(t*.6)}}}__getExpandedHtml(n){const e=this,i=n.oid,o="locomotivesData_"+i;let t='<div id="'+o+'" style="padding: 5px; width: 100%; float: left;">';const s=e.__getCheckboxOptions("Options:",i),h=e.__getCheckboxTypes("Types:",i);t+=s.html;t+=h.html;const f=e.__getCurrentSpeedLevelsOf(i,n.speedstepMax);let c="",l="",a="",v="";for(let t=0;t<n.speedstepMax;++t){let n="",i="",r="",u="";t===f.level1&&(n="selected");t===f.level2&&(i="selected");t===f.level3&&(r="selected");t===f.level4&&(u="selected");c+='<option value="'+t+'" '+n+">"+t+"<\/option>\n";l+='<option value="'+t+'" '+i+">"+t+"<\/option>\n";a+='<option value="'+t+'" '+r+">"+t+"<\/option>\n";v+='<option value="'+t+'" '+u+">"+t+"<\/option>\n"}const r=["speedLevel1_"+i,"speedLevel2_"+i,"speedLevel3_"+i,"speedLevel4_"+i];t+='<div class="w2ui-field">';t+='<label style="float: left;">Speed Levels:<\/label>';t+='<div style="padding: 2px; margin-top: 3px; margin-left: 5px;">';t+=' &nbsp; Level1: <select style="height: 20px;" name="speedLevel1" id="'+r[0]+'">'+c+"<\/select>";t+=' Level2: <select style="height: 20px;" name="speedLevel2" id="'+r[1]+'">'+l+"<\/select>";t+=' Level3: <select style="height: 20px;" name="speedLevel3" id="'+r[2]+'">'+a+"<\/select>";t+=' Level4: <select style="height: 20px;" name="speedLevel4" id="'+r[3]+'">'+v+"<\/select>";t+="<\/div>";t+="<\/div>";t+='<div class="w2ui-field">';t+="<label>Speed Curve:<\/label>";t+='<input type="button" id="cmdSpeedCurveContainer_'+i+'" value="Modify" style="padding: 2px; margin-top: 3px; margin-left: 5px;">';t+="<\/div > ";t+="<\/div>";t+="<\/div>";let u=[];return u=u.concat(s.checkboxIds),u=u.concat(h.checkboxIds),{renderId:o,checkboxIds:u,speedLevel:r,renderHtml:t}}__getCtrlIdsForOptionsAndTypes(n){return{chkIdDirection:"locomotiveChkDirection_"+n,chkIdMainline:"locomotiveChkMainline_"+n,chkIdOthers:"locomotiveChkTypeOthers_"+n,chkIdLocal:"locomotiveChkTypeLocal_"+n,chkIdIntercity:"locomotiveChkTypeIntercity_"+n,chkIdFreight:"locomotiveChkTypeFreight_"+n,chkIdShunting:"locomotiveChkTypeShunting_"+n,chkIdRegional:"locomotiveChkTypeRegional_"+n,chkIdBranchLine:"locomotiveChkTypeBranchLine_"+n,chkIdBranchLineFreight:"locomotiveChkTypeBranchLineFreight_"+n}}__getCheckboxOptions(n,t){let i="";i+='<div class="w2ui-field">';i+="<label>"+n+"<\/label>";i+='<div style="padding-top: 7px;">';const r=this.__getCtrlIdsForOptionsAndTypes(t);return i+='<label style="word-wrap:break-word; font-weight: normal; margin-right: 10px;"><input name="OptionDirection" id="'+r.chkIdDirection+'" type="checkbox" style="vertical-align: middle;"> Allow change direction <\/label>',i+="<\/div>",i+="<\/div>",{html:i,checkboxIds:[r.chkIdDirection,r.chkIdMainline,]}}__getCheckboxTypes(n,t){let r="";r+='<div class="w2ui-field">';r+="<label>"+n+"<\/label>";r+='<div style="padding-top: 7px;">';const u='style="word-wrap:break-word; font-weight: normal; margin-right: 10px;"',f='style="vertical-align: middle;"',i=this.__getCtrlIdsForOptionsAndTypes(t);return r+="<label "+u+'><input name="TypeOthers" id="'+i.chkIdOthers+'" type="checkbox" '+f+"> Others <\/label>",r+="<label "+u+'><input name="TypeLocal" id="'+i.chkIdLocal+'" type="checkbox" '+f+"> Local <\/label>",r+="<label "+u+'><input name="TypeIntercity" id="'+i.chkIdIntercity+'" type="checkbox" '+f+"> Intercity <\/label>",r+="<label "+u+'><input name="TypeFreight" id="'+i.chkIdFreight+'" type="checkbox" '+f+"> Freight <\/label>",r+="<label "+u+'><input name="TypeShunting" id="'+i.chkIdShunting+'" type="checkbox" '+f+"> Shunting <\/label>",r+="<label "+u+'><input name="TypeRegional" id="'+i.chkIdRegional+'" type="checkbox" '+f+"> Regional <\/label>",r+="<label "+u+'><input name="TypeBranchLine" id="'+i.chkIdBranchLine+'" type="checkbox" '+f+"> Branch Line <\/label>",r+="<label "+u+'><input name="TypeBranchLineFreight" id="'+i.chkIdBranchLineFreight+'" type="checkbox" '+f+"> Branch Line (Freight) <\/label>",r+="<\/div>",r+="<\/div>",{html:r,checkboxIds:[i.chkIdOthers,i.chkIdLocal,i.chkIdIntercity,i.chkIdFreight,i.chkIdShunting,i.chkIdRegional,i.chkIdBranchLine,i.chkIdBranchLineFreight]}}__getLocomotiveOfRecentData(n){if(typeof this.__recentLocomotivesData=="undefined"||this.__recentLocomotivesData==null)return null;const t=this.__recentLocomotivesData[n];return typeof t=="undefined"||t==null?null:t}__loadRecentStatesFor(n){const i=this,t=this.__getLocomotiveOfRecentData(n);if(t!=null){const i=this.__getCtrlIdsForOptionsAndTypes(n);$("#"+i.chkIdDirection).prop("checked",t.Settings.OptionDirection);$("#"+i.chkIdMainline).prop("checked",t.Settings.OptionMainline);$("#"+i.chkIdOthers).prop("checked",t.Settings.TypeOthers);$("#"+i.chkIdLocal).prop("checked",t.Settings.TypeLocal);$("#"+i.chkIdIntercity).prop("checked",t.Settings.TypeIntercity);$("#"+i.chkIdFreight).prop("checked",t.Settings.TypeFreight);$("#"+i.chkIdShunting).prop("checked",t.Settings.TypeShunting);$("#"+i.chkIdRegional).prop("checked",t.Settings.TypeRegional);$("#"+i.chkIdBranchLine).prop("checked",t.Settings.TypeBranchLine);$("#"+i.chkIdBranchLineFreight).prop("checked",t.Settings.TypeBranchLineFreight)}this.updateOccInformation(this.__recentOcc)}updateBlockInformation(n){const t=this,r=w2ui[t.__gridName],i=n.data;this.__recentFeedbacksData=i}updateOccInformation(){const n=this}}class Occ{constructor(){console.log("**** construct Occ");this.__secondsToWaitAfterBlockReach=10;this.__divRootClass="locomotiveInfo";this.__divFromClass="locomotiveInfoFrom";this.__divFinalClass="locomotiveInfoFinal";this.__dataOidName="locoid";this.__divBlockedClass="isblocked";this.__borderPaddingLeft=0;this.__borderPaddingTop=0;this.__borderPaddingRight=4;this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}getLocomotiveInfo(n){const u=this,t=$("div."+this.__divRootClass);if(typeof t=="undefined"||t==null||t.length===0)return null;let i;const r=t.length;for(i=0;i<r;++i){const r=t[i];if(r!=null){const u=$(r).data(this.__dataOidName);if(typeof u!="undefined"&&u!=null&&u===n)return r}}return null}__generateLocomotiveInfoIdentifiers(n){const t=this;return{root:"locomotiveInfo"+n,rootFinal:"locomotiveInfoFinal"+n,image:"locomotiveInfoImage"+n,imageFinal:"locomotiveInfoImageFinal"+n}}__showErrorPopup(n,t,i=5,r=5){const u=$("#routePopUp");let f=parseInt(t.css("left").replace("px",""));f-=i;let e=parseInt(t.css("top").replace("px",""));e-=r;u.css({left:f+"px",top:e+"px","background-color":"rgba(255, 0, 0, 0.6)",position:"absolute","font-size":"10px","font-weight":"bold","border-radius":"5px",padding:"2px",color:"white"});u.addClass("noselect");u.html(n);u.fadeIn("fast");setTimeout(function(){u.fadeOut("slow")},2e3)}__createLocomotiveInfo(n){const t=this,f=t.__generateLocomotiveInfoIdentifiers(n.objectId);let i=$("<div>",{}).css({"z-index":50,position:"absolute",overflow:"hidden",height:"28px","max-height":"28px","line-height":"28px",display:"inline-block","vertical-align":"middle","font-weight":"bold",cursor:"pointer","text-align":"center"}).attr("id",f.root).data(this.__dataOidName,n.objectId);i.attr("unselectable","on");i.attr("onselectstart","return false;");i.attr("onmousedown","return false;");i.addClass(this.__divRootClass);i.addClass(this.__divFromClass);const h=$("<div>").css({position:"absolute",top:"0",left:"0"}).addClass("locInfoLabel").html(n.name);h.appendTo(i);let c=$("<i>").css({display:"none",position:"absolute",right:"1px",top:"18px",color:"red","font-size":"0.6rem"}).addClass("fas fa-lock").addClass("lockState");c.appendTo(i);let l=$("<i>").css({display:"none",position:"absolute",left:"1px",top:"18px",color:"red","font-size":"0.6rem"}).addClass("fas fa-hand-paper").addClass("isStoppedState");l.appendTo(i);let a=$("<i>").css({display:"none"}).addClass("fas fa-long-arrow-alt-right").addClass("enterSide");a.appendTo(i);let v=$("<div>").css({position:"absolute",right:"1px",bottom:"-10px",color:"black","font-size":"0.45rem","letter-spacing":"-1px"}).html("-.-").addClass("speedInfo");v.appendTo(i);let r=i.clone();r.attr("id",f.rootFinal);r.data(this.__dataOidName,n.objectId);r.removeClass(this.__divFromClass);r.addClass(this.__divFinalClass);const y=r.find("img");y.attr("id",f.imageFinal);r.dblclick(function(){t.__trigger("resetAssignment",{mode:"resetAssignment",submode:"final",oid:n.objectId})});r.on("contextmenu",function(i){i.preventDefault();new Contextual({isSticky:!1,items:[{cssIcon:"fas fa-broom",enabled:!0,label:"Remove Assignment",onClick:()=>{console.log("OID: "+n.objectId),t.__trigger("resetAssignment",{mode:"resetAssignment",submode:"final",oid:n.objectId})}}]})});let p=$("<div>").css({display:"none","text-align":"center",position:"absolute",left:"0px",top:"0px",color:"black","background-color":"lightgray","font-size":"1.0rem",width:i.css("width"),height:i.css("height")}).addClass("countdown").html('<i class="fas fa-history" style="padding-right: 5px;"><\/i><span class="countdown">...<\/span>');p.appendTo(i);i.draggable({opacity:.7,helper:"clone",start:function(){const n=t.__getPlanfieldClickControlOfPosition();n!==null&&(t.__dragStartBlockElement=n)},stop:function(){var u=!1;try{const i=t.__getPlanfieldClickControlOfPosition();if(typeof i=="undefined"||i===null)throw"resetAssignment";if(!i.hasClass("ctrlItemBlock"))throw"resetAssignment";if(i.hasClass(this.__divBlockedClass))throw"reset";const e=t.__dragStartBlockElement,l=e.attr("id"),a=i.attr("id");if(l===a)throw"reset";const f=getThemeJsonData(e),r=getThemeJsonData(i);if(!isBlock(r.editor.themeId))throw"reset";if(window.__autoModeState===!1){t.__showErrorPopup("AutoMode is disabled.",i,0,0);return}const o=f.identifier+"[+]",s=f.identifier+"[-]",h=r.identifier+"[+]",c=r.identifier+"[-]",v=o+"_"+h,y=o+"_"+c,p=s+"_"+h,w=s+"_"+c;let u=!1;for(let n=0;n<window.routes.length;++n){const i=window.routes[n],t=i.name;t===v?u=!0:t===y?u=!0:t===p?u=!0:t===w&&(u=!0)}u===!1?t.__showErrorPopup("Route from "+f.identifier+" to "+r.identifier+" does not exist.",i):t.__trigger("gotoBlock",{mode:"gotoBlock",oid:n.objectId,fromBlock:f.coord,toBlock:r.coord})}catch(f){f==="reset"?u=!0:f==="resetAssignment"&&(i.hide(),r.hide(),t.__trigger("resetAssignment",{mode:"resetAssignment",oid:n.objectId}))}finally{u;t.__dragStartBlockElement=null}}});const w=$("div[id=tplLocomotiveInfoCtrl]");var u=w.find("div.locInfoCtrl").clone();u.css({display:"none"});u.attr("id","locCtrl_"+n.objectId);u.find("#locSpeedPlus").click(function(){t.__trigger("speedChanged",{oid:n.objectId,speedstep:"++",timestamp:Date.now()})});u.find("#locSpeedMinus").click(function(){t.__trigger("speedChanged",{oid:n.objectId,speedstep:"--",timestamp:Date.now()})});u.find("#locSpeedStop").click(function(){t.__trigger("speedChanged",{oid:n.objectId,speedstep:"level0",timestamp:Date.now()})});u.find("#locOpenDialog").click(function(){const i=n.objectId;t.__trigger("openLocomotiveControl",{oid:i})});u.find("#locBackward").click(function(){t.__trigger("directionChanged",{oid:n.objectId,force:"backward"})});u.find("#locForward").click(function(){t.__trigger("directionChanged",{oid:n.objectId,force:"forward"})});const b=u.find(".locSpeedSteps").find("button").not("button[data-function]");b.each(function(){$(this).button();$(this).data("speedstep")&&$(this).click(function(i){const r=$(i.currentTarget).data("speedstep");t.__trigger("speedChanged",{oid:n.objectId,speedstep:r,timestamp:Date.now()})})});const o=function(n){(clearTimeout(t.__timeoutBeforeHide),t.__timeoutBeforeHide=0,t.__timeoutBeforeShow>0)||t.isLocomotiveControlHoverShown(this)||($(".locInfoCtrl").each(function(){$(this).hide()}),t.__timeoutBeforeShow=setTimeout(function(){t.showLocomotiveControlHover($(n))},250))},s=function(n){clearTimeout(t.__timeoutBeforeShow);t.__timeoutBeforeShow=0;t.__timeoutBeforeHide=setTimeout(function(){t.hideLocomotiveControlHover($(n))},250)};i.mouseover(function(){o(this)});i.mouseleave(function(){s(this)});r.mouseover(function(){o(this)});r.mouseleave(function(){s(this)});i.on("dblclick",function(n){n.preventDefault();const r=i.data("oid");t.__saveLocomotiveStart(r,!0)});i.on("contextmenu",function(n){n.preventDefault();const r=i.data("oid"),u=t.__getLocomotiveOfRecentData(r);let o="",s="";u.EnterBlockSide==="'+' Side"?o="fas fa-check":u.EnterBlockSide==="'-' Side"?s="fas fa-check":o="fas fa-check";let f="",e="";u.IsLocked===!0?(e="Unlock Locomotive",f="fas fa-lock",i.data("isLocked",!0)):u.IsLocked===!1?(e="Lock Locomotive",f="fas fa-lock-open",i.data("isLocked",!1)):(e="Unlock Locomotive",f="fas fa-lock",i.data("isLocked",!0));const h=i.data("isLocked");new Contextual({isSticky:!1,items:[{cssIcon:"fas fa-play",enabled:window.__autoModeState,label:"Start",onClick:()=>{t.__saveLocomotiveStart(r,!0)}},{cssIcon:"fas fa-stop",enabled:window.__autoModeState,label:"Finalize",onClick:()=>{t.__stopWaitCounter(r),t.__saveLocomotiveFinalize(r,!0)}},{type:"seperator"},{cssIcon:o,label:'Enter "+"',onClick:()=>{i.data("enterSide","Plus"),t.__saveLocomotiveEnterSide(r,"'+' Side")}},{cssIcon:s,label:'Enter "-"',onClick:()=>{i.data("enterSide","Minus"),t.__saveLocomotiveEnterSide(r,"'-' Side")}},{type:"seperator"},{cssIcon:f,label:e,onClick:()=>{i.data("isLocked",!h),t.__saveLocomotiveLock(r,!h)}}]})});const e=$("body");u.appendTo(e);i.appendTo(e);r.appendTo(e);t.__updateStateVisualization(n.objectId)}__stopWaitCounter(n){if(typeof n!="undefined"&&n!=null&&!(n<=0)){const t=$("#locomotiveInfo"+n+" div.countdown");t.hide()}}__updateTimeVisualization(n){if(typeof n!="undefined"&&n!=null){const s=this,f=parseInt(new Date(n.ReachedTime).getTime()/1e3),r=f+n.SecondsToWait;let i=parseInt(r-parseInt((new Date).getTime()/1e3));i<0&&(i=0);const e=i<=0,o=n.Oid,t=$("#locomotiveInfo"+o+" div.countdown");if(e===!0)t.hide();else{if(t.is(":visible"))return;t.show();const n=t.find("span.countdown");n.data("walltime",r);n.html(i+"s");var u=function(n){setTimeout(function(){const t=n.find("span.countdown"),i=parseInt(t.data("walltime"));if(i>=0){const i=parseInt(t.data("walltime"))-parseInt((new Date).getTime()/1e3);if(isNaN(i)||i<1){t.data("walltime",-1);n.hide();return}t.html(i+"s");u(n)}else{n.hide();return}},1e3)};u(t)}}}__getLocomotiveOfRecentData(n){if(typeof this.__recentLocomotivesData=="undefined"||this.__recentLocomotivesData==null)return null;const t=this.__recentLocomotivesData[n];return typeof t=="undefined"||t==null?null:t}__fncScaleLbl(n,t){try{const i=n.find("div.locInfoLabel");if(!i.is(":visible"))return;if(i.width()===0||i.height()===0)return;i.boxfit();const u=i.find("span");let r=u.css("font-size");r=parseInt(r.replace("px",""));u.css("font-size",parseInt(r*t)+"px");n.data("fontIsScaled",!0)}catch(i){}}__updateStateVisualization(n){const r=this,h=r.__generateLocomotiveInfoIdentifiers(n),t=$("#"+h.root);if(typeof t!="undefined"&&t!=null&&t.length!==0){const u=r.__getLocomotiveOfRecentData(n);if(u==null){r.__fncScaleLbl(t,.75);return}const o=t.find(".speedInfo"),s=r.__getEcosDataOfLoc(n);s==null?o.html("-.-"):o.html(s.speedstep+"|"+s.speedstepMax);const i=t.find(".enterSide");if(typeof i!="undefined"&&i!=null&&i.length>0){let n="";u.EnterBlockSide.includes("'+'")?n="plus":u.EnterBlockSide.includes("'-'")&&(n="minus");i.removeAttr("style");n==="plus"?(i.css({position:"absolute",right:"2px",top:"1px",color:"yellow","font-size":"0.7rem",transform:"scaleX(1)"}),i.show()):n==="minus"?(i.css({position:"absolute",left:"2px",top:"1px",color:"yellow","font-size":"0.7rem",transform:"scaleX(-1)"}),i.show()):i.hide()}const f=t.find(".lockState");typeof f!="undefined"&&f!=null&&f.length>0&&(u.IsLocked===!1?(o.show(),f.hide(),r.__fncScaleLbl(t,.7)):(o.hide(),f.show(),r.__fncScaleLbl(t,.7)));const e=t.find(".isStoppedState");typeof e!="undefined"&&e!=null&&e.length>0&&(u.IsStopped===!1?e.hide():e.show())}}__saveLocomotiveStart(n,t){this.__trigger("setting",{mode:"locomotive",cmd:"start",value:{oid:n,state:t}})}__saveLocomotiveFinalize(n,t){this.__trigger("setting",{mode:"locomotive",cmd:"finalize",value:{oid:n,state:t}})}__saveLocomotiveLock(n,t){this.__trigger("setting",{mode:"locomotive",cmd:"lock",value:{oid:n,locked:t}})}__saveLocomotiveEnterSide(n,t){this.__trigger("setting",{mode:"locomotive",cmd:"locomotiveData",value:{oid:n,checkboxSettings:null,blockEnterSide:t}})}isLocomotiveControlHoverShown(n){const t=$(n).data(this.__dataOidName),i=$("#locCtrl_"+t);return i.is(":visible")}showLocomotiveControlHover(n){const r=this,e=$(n).data(this.__dataOidName),t=$("#locCtrl_"+e);t.show();const u=n.get(0),o=u.offsetLeft,s=u.offsetTop,h=n.get(0).getBoundingClientRect().height,f=t.get(0).getBoundingClientRect(),c=f.height,l=f.width,a=parseInt(c-h)/2;let i=s-a;i<0&&(i=5);t.css({"z-index":150,top:i+"px",left:o-l+1+"px"});t.mousemove(function(){clearTimeout(r.__timeoutBeforeHide);r.__timeoutBeforeHide=0});t.mouseleave(function(){setTimeout(function(){t.hide()},125)})}hideLocomotiveControlHover(n){const t=$(n).data(this.__dataOidName),i=$("#locCtrl_"+t);i.hide()}loadLocomotives(n){const t=this;t.__recentLocomotives=n;for(let i=0;i<n.length;++i)if(n[i]!==null){const r=n[i],u=r.objectId,f=t.getLocomotiveInfo(u);f==null&&t.__createLocomotiveInfo(r)}}resetAssignment(){console.log("reset assignment")}__getBlock(n){const i=this,t=$("div.ctrlItemBlock");for(let i=0;i<t.length;++i){const r=t[i];if(typeof r!="undefined"&&r!=null){const u=getThemeJsonData($(r));if(typeof u!="undefined"&&u!=null&&u.identifier===n)return $(r)}}return null}__applyInfoToBlock(n,t,i){(typeof i=="undefined"||i==null)&&(i=null);const s=this;if(typeof t!="undefined"&&t!=null){const o=t.get(0).getBoundingClientRect(),h=o.width,c=o.top+this.__borderPaddingTop+"px",l=o.left+this.__borderPaddingLeft+"px";let f=0,e=0;h<=64?(f=2*constItemWidth-this.__borderPaddingRight+"px",e=2*constItemWidth-this.__borderPaddingRight+"px"):(f=4*constItemWidth-this.__borderPaddingRight+"px",e=4*constItemWidth-this.__borderPaddingRight+"px");n.css({top:c,left:l,width:f,"max-width":e,"text-align":"left"});let r=n.find("div.locInfoLabel");typeof r!="undefined"&&r!=null&&r.length>0&&(r.css("width",f),r.css("max-width",e),r.css("height",constItemHeight));let u=n.find("div.countdown");typeof u!="undefined"&&u!=null&&u.length>0&&(u.css("width",f),u.css("max-width",e),u.css("height",constItemHeight));i!=null&&(n.data("oid",i.Oid),s.__updateStateVisualization(i.Oid));t.addClass(s.__divBlockedClass)}}handleData(n){const i=this,r=n.data;var f=[];let t;const u=r.length;for(t=0;t<u;++t){const n=r[t];f.push(n.Oid)}const e=$("div.locomotiveInfo");for(u===0?e.each(function(){$(this).hide()}):e.each(function(){const n=$(this),t=n.data(this.__dataOidName);f.includes(t)||n.hide()}),t=0;t<u;++t){const n=r[t];if(typeof n!="undefined"&&n!=null){const h=i.__generateLocomotiveInfoIdentifiers(n.Oid),o=$("div#"+h.root),u=$("div#"+h.rootFinal),f=n.FromBlock,e=n.FinalBlock;if(typeof f=="undefined"||f==null||f.length===0)o.hide();else{const t=i.__getBlock(f);o.show();i.__applyInfoToBlock(o,t,n)}if(typeof e=="undefined"||e==null||e.length===0)u.hide();else{const n=i.__getBlock(e);u.show();i.__applyInfoToBlock(u,n);i.__fncScaleLbl(u,.9)}const s=n.FinalEntered;typeof s!="undefined"&&s!=null&&(s===!0?u.find("div.locInfoLabel").addClass("locomotiveInfoFinalEntering"):u.find("div.locInfoLabel").removeClass("locomotiveInfoFinalEntering"));i.__updateTimeVisualization(n)}}}updateOccWithLocomotiveData(n){const i=this,t=n.data;this.__recentLocomotivesData=t;for(let n in t)if(t.hasOwnProperty(n)){const t=parseInt(n);i.__updateStateVisualization(t)}}updateEcosDirection(n){const i=this;if(typeof n!="undefined"&&n!=null){let t=0;const r=n.length;for(;t<r;++t){const s=n[t],u=s.objectId,f=$("#locCtrl_"+u),e=f.find("#locBackward"),o=f.find("#locForward");e.css({color:"black"});o.css({color:"black"});const r=i.__getEcosDataOfLoc(u);if(r==null)return;r.direction===0?o.css({color:"green"}):r.direction===1&&e.css({color:"green"})}}}updateEcosSpeedInfo(n){const i=this;if(typeof n!="undefined"&&n!=null){let t=0;const r=n.length;for(;t<r;++t){const s=n[t],e=s.objectId,h=i.__generateLocomotiveInfoIdentifiers(e),u=$("#"+h.root);if(typeof u!="undefined"&&u!=null&&u.length!==0){const f=u.find(".speedInfo"),r=i.__getEcosDataOfLoc(e),o=f.html();if(r==null)o==="-.-"||f.html("-.-");else{const n=r.speedstep+"|"+r.speedstepMax;n===o||f.html(r.speedstep+"|"+r.speedstepMax)}}}}}__getEcosDataOfLoc(n){const r=this;if(typeof ecosData=="undefined"||window.ecosData==null||typeof window.ecosData.locomotives=="undefined"||window.ecosData.locomotives==null)return null;let t=0;const i=window.ecosData.locomotives.length;for(;t<i;++t){const i=window.ecosData.locomotives[t];if(typeof i!="undefined"&&i!=null&&i.objectId===n)return i}return null}__getPlanfieldClickControlOfPosition(){const n=window.planField.planfieldElement.get(0),t=event.clientX-n.offsetLeft,i=event.clientY-n.offsetTop,r=$("div.ctrlItem[id]");return getCtrlOfPosition(t,i,r)}}class Planfield{constructor(n={}){console.log("**** construct Planfield");this.planfieldElement=null;this.isEditMode=!1;typeof n.isEditMode!="undefined"&&(this.isEditMode=n.isEditMode);this.currentSelection=null;this.currentSelectionMoved=!1;this.currentSelectionMovedItem=null;this.options=n;this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}setEditMode(n){const e=this;this.isEditMode=n;this.clearCtrlSelection();n?this.planfieldElement.addClass("planFieldBackground"):this.planfieldElement.removeClass("planFieldBackground");let t;const u=window.textfieldElementInstances.length;for(t=0;t<u;++t)window.textfieldElementInstances[t].setEditMode(n);const r=$("div.ctrlItem");let i;const f=r.length;for(i=0;i<f;++i){const t=r[i];t!=null&&(n?this.initDragFor($(t)):this.removeDragFor($(t)))}}__updatePlanfieldGeometryPixel(n={}){typeof n.w=="undefined"&&(n.w=$(window).width());typeof n.h=="undefined"&&(n.h=$(window).height());this.__updatePlanfieldGeometry(parseInt(n.w/constItemWidth),parseInt(n.h/constItemHeight))}__updatePlanfieldGeometry(n,t){const i=$("div#planField");return i.css("width","calc("+n+" * "+constItemWidth+"px + 1px)"),i.css("height","calc("+t+" * "+constItemHeight+"px + 1px)"),i}isCtrlSelected(n){if(typeof n=="undefined"||n==null)return!1;n instanceof jQuery||(n=$(n));const t=n.find("img");return typeof t=="undefined"?!1:t==null?!1:t.hasClass("selected")}__getCtrl(n,t){const i=n.x,r=n.y,u=i*constItemWidth+constItemWidth/2,f=r*constItemHeight+constItemHeight/2,e=getCtrlOfPosition(u,f,t);return $(e)}clearRouteUserHighlight(){const t=this,n=$("div.ctrlItem");if(typeof n!="undefined"&&n!=null&&n.length!==0)for(let t=0;t<n.length;++t){const i=n[t];i!=null&&$(i).removeClass("highlightRoute")}}activateRouteUserHighlight(n){const r=this,u=$("div.ctrlItem");let t,i=n.tracks.length;for(t=0;t<i;++t){const i=r.__getCtrl(n.tracks[t],u);i.addClass("highlightRoute")}for(i=n.sensors.length,t=0;t<i;++t){const i=r.__getCtrl(n.sensors[t],u);i.addClass("highlightRoute")}for(i=n.signals.length,t=0;t<i;++t){const i=r.__getCtrl(n.signals[t],u);i.addClass("highlightRoute")}for(i=n.switches.length,t=0;t<i;++t){const i=r.__getCtrl(n.switches[t],u);i.addClass("highlightRoute")}}activateRouteVisualization(n){const t=[];Array.prototype.push.apply(t,n.tracks);Array.prototype.push.apply(t,n.sensors);Array.prototype.push.apply(t,n.signals);Array.prototype.push.apply(t,n.switches);const r=this,u=$("div.ctrlItem");let i;const f=t.length;for(i=0;i<f;++i){const e=t[i];if(e!=null){const o=r.__getCtrl(e,u),n=o.find("img");if(typeof n!="undefined"&&n!=null&&n.length!==0){let f=n.attr("src");f.includes("-route.png")||(f=f.replace(".png","-route.png"),n.attr("src",f))}}}}deativateRouteVisualization(n){const t=[];Array.prototype.push.apply(t,n.tracks);Array.prototype.push.apply(t,n.sensors);Array.prototype.push.apply(t,n.signals);Array.prototype.push.apply(t,n.switches);const r=this,u=$("div.ctrlItem");let i;const f=t.length;for(i=0;i<f;++i){const e=t[i];if(e!=null){const o=r.__getCtrl(e,u),n=o.find("img");if(typeof n!="undefined"&&n!=null&&n.length!==0){let f=n.attr("src");f.includes("-route.png")&&(f=f.replace("-route.png",".png"),n.attr("src",f))}}}}clearCtrlSelection(){const n=$("div.ctrlItem");if(typeof n!="undefined"&&n!=null&&n.length!==0){let t;const i=n.length;for(t=0;t<i;++t){const i=n[t];i!=null&&this.isCtrlSelected(i)&&this.unselectCtrl($(i))}}}unselectCtrl(n){if(typeof n!="undefined"&&n!=null){let t=n.find("img");(typeof t=="undefined"&&(t=null),t!=null)&&(t.removeClass("selected"),this.editMenubar.hideEditMenu(),this.currentSelection=null)}}selectCtrl(n,t={}){if(typeof n!="undefined"&&n!=null){this.clearCtrlSelection();const i=n.find("img");typeof i!="undefined"&&i!=null&&i.addClass("selected");this.currentSelection=n;typeof t.startEditMode=="undefined"&&(t.startEditMode=!0);t.startEditMode&&(this.editMenubar.setCurrentSelection(n),this.editMenubar.updateEditMenuPositionAndEvents(n),this.editMenubar.showEditMenu())}}generateUniqueItemIdentifier(n){const i=$("div.ctrlItem[id]").map(function(){return this.id}).get();let t="Item";n&&(n>=10&&n<=25?t="TK":n>=50&&n<=75?t="SW":n>=100&&n<=125?t="SE":n>=150&&n<=175?t="BK":n>=200&&n<=225&&(t="FB"));const r=i.length;for(let n=0;n<r;++n){const r=t+"_"+n;if(!i.includes(r))return r}return t+"_"+r}install(){const n=this;n.__firstRun=!0;window.ctrlClickSpinnerCounter=0;$(window).resize(function(){n.__updatePlanfieldGeometryPixel()});this.editMenubar=new EditMenuBar(this.options);this.__updatePlanfieldGeometryPixel();this.planfieldElement=$("div#planField");this.planfieldElement.click(function(t){if(n.currentSelectionMoved){t.preventDefault();t.stopPropagation();n.currentSelectionMoved=!1;return}const i=getCtrlOfEvent($(this),t,$("div.ctrlItem"));if(i!=null){const u=i.data(constDataThemeItemObject);if(typeof u!="undefined"&&u!==null&&u.clickable&&!n.isEditMode){const f=$("div.lds-facebookOriginal"),u=f.clone();u.removeClass("lds-facebookOriginal");u.addClass("lds-facebook");const e="lfd-facebookClickId"+window.ctrlClickSpinnerCounter;if(u.addClass(e),++window.ctrlClickSpinnerCounter,u.css({top:t.clientY-constItemHeight/2,left:t.clientX-constItemWidth/2}),u.insertAfter(f),!u.is(":visible")){u.show();const n=e;var r=$("div."+n);setTimeout(function(){r.hide();r.remove()},500)}n.__trigger("clicked",{ctrlId:i.attr("id"),coord:getElementCoord(n.planfieldElement,t)})}}else if(n.isEditMode){const i=window.toolbox;i.recentItem&&n.createControlWithEv(i.recentItem,t)}});this.planfieldElement.get(0).ondragover=t=>{n.isEditMode&&t.preventDefault()};this.planfieldElement.get(0).ondrop=t=>{this.isEditMode&&n.createControlOnDrop(t,{editMode:!0})};$(document).keyup(function(t){t.keyCode===27&&n.clearCtrlSelection()})}__initBlockDrop(n){if(typeof n!="undefined"&&n!==null){const r=this,i=n.find("img");let t;const u=i.length;for(t=0;t<u;++t)$(i[t]).droppable({accept:"div.locomotiveInfo"});n.get(0).ondragover=function(n){n.preventDefault()};n.get(0).ondrop=function(t){try{t.preventDefault();const f=t.dataTransfer.getData("text"),i=JSON.parse(f),e={mode:"assignToBlock",oid:i.recid,coord:getThemeJsonData(n).coord};r.__trigger("assignToBlock",e);const u=w2ui[i.sourceGrid];u.selectNone();u.unselect(i.recid)}catch(t){}}}}updateFeedbacks(n){const i=this,u=n.data.length,t=$("div.ctrlItemBlock");if((i.__recentFbEventsData=n.data,i.__removeAllDisabledFlags(t),u!==0)&&typeof t!="undefined"&&t!=null&&t.length!==0){let r=0;for(;r<u;++r){const u=n.data[r];if(typeof u!="undefined"&&u!=null)try{const n=u.Settings.BlockEnabled;if(typeof n=="undefined"||n==null||n===!0)continue;const r=i.__getBlockCtrlOf(u,t);if(r==null)continue;r.addClass("blockDisabledState")}catch(f){}}}}__getBlockCtrlOf(n,t){const i=n.BlockId;for(let i=0;i<t.length;++i){const r=$(t[i]),u=r.data(constDataThemeItemObject),f=u.identifier;if(n.BlockId.startsWith(f))return r}return null}__removeAllDisabledFlags(n){if(typeof n!="undefined"&&n!=null&&n.length!==0){let t=0;const i=n.length;for(;t<i;++t){const i=n[t];typeof i!="undefined"&&i!=null&&$(i).removeClass("blockDisabledState")}}}updateEcosFeedbacks(n){const t=this,f=n.length,e=$("div.ctrlItemFeedback"),i=[];let r=0;const u=t.__recentFeedbacksData;(typeof u=="undefined"||u==null)&&(t.__recentFeedbacksData=n);for(let u=0;u<f;++u){const f=n[u];if(typeof f!="undefined"&&f!=null&&(f!==t.__recentFeedbacksData[u]||t.__firstRun!==!1)){for(let n=15;n>=0;--n){const l=r+n+1,u=getFbByEcosAddr(e,l);if(typeof u!="undefined"&&u!==null){let o="";const a=1<<n;o=(f.stateOriginal&a)!=0?"-on":"-off";const s=u.planItem.find("img");if(s){const h=s.attr("src"),v=h.includes("-route"),y=getDirpathOf(h);let t=u.themeData.basename;t=t.replace("-on","");t=t.replace("-off","");v===!0&&(o+="-route");const c=y+t+o+".png";h!==c&&i.push({ctrl:s,src:c+"?r="+Math.random()})}}}r+=f.ports}}for(let n=0;n<i.length;++n)i[n].ctrl.attr("src",i[n].src);t.__firstRun=!1}updateEcosAccessories(n){var i,t;const f=this;let r=n.length,u=$("div.ctrlItemAccessory");for(i=0;i<r;++i){const e=n[i];if(typeof e!="undefined"&&e!=null&&e.hasChanged){const f=getAccByEcosAddr(u,e.addr);if(f!=null){let h=0;if(f.ecosAddresses[0].ecosAddrValid===!0&&h++,f.ecosAddresses[1].ecosAddrValid===!0&&h++,h!==0){const o=f.planItem.find("img");if(o){const l=o.attr("src"),c=getDirpathOf(l),s=f.themeData.editor.themeId;let r=f.themeData.basename;switch(h){case 1:{let n=!1;f.ecosAddresses[0].ecosAddrValid===!0?n=f.ecosAddresses[0].inverse:f.ecosAddresses[1].ecosAddrValid===!0&&(n=f.ecosAddresses[1].inverse);t=e.state===1;n===!0&&(t=!t);isDecoupler(s)?t===!1?r+="-on":t===!0&&(r+=""):isSignal(s)?(r=r.replace("-r",""),r=r.replace("-g",""),t===!1?r+="-r":t===!0&&(r+="-g")):isAccessory(s)?t===!1?r+="-on":t===!0&&(r+="-off"):isButton(s)?(r=r.replace("-on",""),r=r.replace("-off",""),t===!1?r+="-on":t===!0&&(r+="-off")):isSwitchOrAccessory(s)&&(t===!1||t===!0&&(r+="-t"));let i=o.attr("src"),u=!1,h=!1;u=i.includes("-occ");h=i.includes("-route");u?r+="-occ":h&&(r+="-route");r+=".png";o.get(0).src=c+r+"?t="+Math.random()}break;case 2:{const h=f.planItem,u=f.ecosAddresses,l=u[0].ecosAddr,a=u[1].ecosAddr,s=e.addr;let n=h.data("recentState");typeof n=="undefined"&&(n={},n[l]="straight",n[a]="straight");e.state===0?n[s]="straight":e.state===1&&(n[s]="turn");let t=n[l],i=n[a];const y=n;h.data("recentState",y);u[0].ecosAddr===s&&(u[0].inverse===!0&&(t==="turn"?t="straight":t==="straight"&&(t="turn")),n[s]=t);u[1].ecosAddr===s&&(u[1].inverse===!0&&(i==="turn"?i="straight":i==="straight"&&(i="turn")),n[s]=i);t==="straight"&&i==="straight"||(t==="turn"&&i==="turn"?r+="-t":t==="turn"&&i==="straight"?r+="-tl":t==="straight"&&i==="turn"&&(r+="-tr"));const v=o.attr("src"),p=v.includes("-occ"),w=v.includes("-route");p?r+="-occ":w&&(r+="-route");r+=".png";o.get(0).src=c+r+"?t="+Math.random()}}}}}}}}applyAddressToAccessory(n,t){if(typeof n!="undefined"&&n!=null&&typeof t!="undefined"&&t!=null){const i=$('div.ctrlItemAccessory[id="'+n+'"]');if(typeof i!="undefined"&&i!=null&&i.length!==0){const r=$(i[0]),u=r.data(constDataThemeItemObject);u.addresses=t;r.data(constDataThemeItemObject,u)}}}createControlOnDrop(n,t={}){const i=this;if(n.preventDefault(),n.dataTransfer){const i=n.dataTransfer.getData("text/plain"),r=JSON.parse(i);this.createControlWithEv(r,n,t)}}createControlWithEv(n,t,i={}){const u=this,r=getElementCoord(u.planfieldElement,t);if(n!=null&&typeof n.editor!="undefined"){const t=n.editor,i=parseInt(t.offsetX/constItemWidth),u=parseInt(t.offsetY/constItemHeight);r.x-=i;r.y-=u}this.createControl(n,r,i)}createControl(n,t,i={}){var s,y,h,f,r,c,l,e,w,g,a,nt;const u=this;let tt=$("div.ctrlItem[id]"),b=getCtrlOfCoord(t.x,t.y,tt);if((typeof b=="undefined"||b==null)&&n!=null){s=coord2pixel(t);typeof i.editMode=="undefined"&&(i.editMode=!0);y=JSON.stringify(n);y=window.btoa(y);h=n.dimensions;typeof h=="undefined"&&(h=[{w:1,h:1}]);const k=h[0].w*constItemWidth,d=h[0].h*constItemHeight;if(typeof n.editor=="undefined"&&(n.editor={}),typeof n.editor.themeDimIdx=="undefined"&&(n.editor.themeDimIdx=0),f="",typeof n.identifier!="undefined"&&this.__isInitialization?(f=n.identifier,f.length===0&&(f=this.generateUniqueItemIdentifier(n.editor.themeId))):f=this.generateUniqueItemIdentifier(n.editor.themeId),r=null,n.editor.themeId===1010){var p=null,v=null,o=null;n.editor.innerHtml&&(p=n.editor.innerHtml);n.editor.outerHtml&&(v=$(n.editor.outerHtml).css("font-size"));n.editor.size&&(o=n.editor.size);c=new TextfieldElement;c.install({fontSize:v,uniqueId:n.identifier});window.textfieldElementInstances.push(c);r=c.__element;r.addClass("ctrlItem");r.attr("draggable",!0);r.css({left:s.x+"px",top:s.y+"px",width:k+"px",height:d+"px","z-index":0});r.data(constDataThemeItemObject,n);r.data(constDataThemeDimensionIndex,n.editor.themeDimIdx);l=r.find(".elEditor");n.editor.innerHtml&&p!==null&&l.html(p);n.editor.outerHtml&&v!==null&&l.css("font-size",v);n.editor.size&&o!==null&&(l.css({width:o.width,height:o.height}),l.parent().css({width:o.width,height:o.height}));this.__isInitialization||c.setEditMode(!0)}else if(r=$("<div>").addClass("ctrlItem").attr("id",f).css({left:s.x+"px",top:s.y+"px",width:k+"px",height:d+"px"}),n.isMaintenance===!0&&r.addClass("accessoryMaintenance"),r.data(constDataThemeItemObject,n),r.data(constDataThemeDimensionIndex,n.editor.themeDimIdx),e=n.editor.themeId,isBlock(e)?r.addClass("ctrlItemBlock"):isSwitchOrAccessory(e)||isAccessory(e)||isSignal(e)||isDecoupler(e)?r.addClass("ctrlItemAccessory"):isFeedback(e)&&r.addClass("ctrlItemFeedback"),w="",w=n.active&&n.active.default?n.active.default+".png":n.basename+".png",g=$("<img>",{}).attr({src:"theme/"+window.settings.themeName+"/"+w}),g.appendTo(r),a=getLabelOffsetBy(n),a!==null){a.display="none";window.labelShown===!0&&(a.display="visible");let n=$("<div>",{}).css(a);n.addClass("elementLabel");let t=$("<div>",{}).html(f);t.addClass("elementLabelTxt");t.appendTo(n);n.appendTo(r)}if(r!==null){if(isBlock(n.editor.themeId)){this.__initBlockDrop(r);r.on("contextmenu",function(n){if((n.preventDefault(),typeof u.__recentFbEventsData!="undefined")&&u.__recentFbEventsData!=null){let t=!1;const i=r.attr("id");let f=0;const e=u.__recentFbEventsData.length;for(;f<e;++f){const n=u.__recentFbEventsData[f];if(typeof n!="undefined"&&n!=null&&n.BlockId.startsWith(i)){const r=n.Settings;if(typeof r!="undefined"&&r!=null){t=r.BlockEnabled===!0?!0:!1;break}}}new Contextual({isSticky:!1,items:[{cssIcon:"fas fa-lock",enabled:t,label:"Disable",onClick:()=>{u.__trigger("setting",{mode:"block",cmd:"blockState",value:{blockIdentifier:i,state:!1}})}},{cssIcon:"fas fa-unlock",enabled:!t,label:"Enable",onClick:()=>{u.__trigger("setting",{mode:"block",cmd:"blockState",value:{blockIdentifier:i,state:!0}})}}]})}})}if(isSwitchOrAccessory(n.editor.themeId))r.on("contextmenu",function(n){n.preventDefault();const t=r.data(constDataThemeItemObject);if(typeof t!="undefined"&&t!=null){let i=t.isMaintenance;(typeof i=="undefined"||i==null)&&(i=!1);let f="Enable Maintenance",e="fas fa-stethoscope";i===!0&&(f="Disable Maintenance",e="far fa-thumbs-up");new Contextual({isSticky:!1,items:[{cssIcon:e,enabled:!0,label:f,onClick:()=>{const n=!i;t.isMaintenance=n;r.data(constDataThemeItemObject,t);n===!0?r.addClass("accessoryMaintenance"):r.removeClass("accessoryMaintenance");u.__trigger("setting",{mode:"accessory",cmd:"maintenance",value:{identifier:t.identifier,state:n}})}}]})}});r.appendTo(this.planfieldElement);r.click(function(){const n=$(this).hasClass("elEditorRoot");n||u.isEditMode&&(u.currentSelectionMoved||(u.isCtrlSelected(r)?u.unselectCtrl(r):(u.clearCtrlSelection(),u.selectCtrl(r))))});r.mouseover(function(n){const i=$(this).data(constDataThemeItemObject);var t=i.coord;t||(t=getElementCoord(u.planfieldElement,n));const r=$(this).attr("id"),f=i.name+" ("+t.x+", "+t.y+") &mdash; "+r,e=$("#statusBar div.ctrlInfo");e.html(f)});r.mouseleave(function(){const n=$("#statusBar div.ctrlInfo");n.html("")});this.isEditMode&&this.initDragFor(r);i.editMode&&(nt=r.hasClass("elEditorRoot"),nt||this.selectCtrl(r));this.editMenubar.setCurrentSelection(r);this.editMenubar.rot(-1,r,this.__isInitialization);this.__trigger("controlCreated",{instance:r});this.__isInitialization||window.serverHandling.sendControl(r)}}}removeDragFor(n){if(n!==null){const t=n.get(0);t.ondragstart=null}}initDragFor(n){function f(n){if(t.isEditMode){n=n||window.event;n.preventDefault();n.stopPropagation();t.currentSelectionMoved=!1;t.currentSelectionMovedItem=null;const h=$(this).hasClass("elEditorRoot");if(h){const n=$(this);t.currentSelectionMoved=!0;t.currentSelectionMovedItem=n;t.selectCtrl(n,{startEditMode:!1})}else{const i=$(n.target).parent();t.currentSelectionMoved=!0;t.currentSelectionMovedItem=i;t.selectCtrl(i)}document.onmouseup=o;document.onmousemove=e;const r=getElementCoord(u,n),f=$(n.target).parent(),s={x:Math.floor(f.get(0).offsetLeft/constItemWidth),y:Math.floor(f.get(0).offsetTop/constItemHeight)};i={x:Math.floor(r.x-s.x),y:Math.floor(r.y-s.y)}}}function e(n){if(t.isEditMode){n=n||window.event;n.preventDefault();n.stopPropagation();const f=getElementCoord(u,n);var e=(f.y-i.y)*constItemHeight,o=(f.x-i.x)*constItemWidth;const s=t.currentSelection.hasClass("elEditorRoot");s&&(e=Math.floor(f.y*constItemHeight),o=Math.floor(f.x*constItemWidth));r.style.top=e+"px";r.style.left=o+"px";s||t.editMenubar.updateEditMenuPositionAndEvents(t.currentSelection)}}function o(){t.isEditMode&&(document.onmouseup=null,document.onmousemove=null,t.__isInitialization||(window.serverHandling.removeControl(t.currentSelectionMovedItem.attr("id")),window.serverHandling.sendControl(t.currentSelectionMovedItem)),t.currentSelectionMovedItem=null)}var r=n.get(0),u,i;r.ondragstart=f;u=n.parent();const t=this;i=null}highlightAccessory(n,t){const r=this,u=n,i=$("div.ctrlItem[id]");for(let r=0;r<i.length;++r){const u=i[r];if(u){const f=$(u).data(constDataThemeItemObject);if(f!=null&&f.identifier===n){t?$(u).addClass("highlightAccessory"):$(u).removeClass("highlightAccessory");return}}}}initFromServer(n){const t=n.planField;this.__isInitialization=!0;for(let n in t)if(t.hasOwnProperty(n)){const i=t[n];this.createControl(i,i.coord,{editMode:!1})}this.__isInitialization=!1}}class Routes{constructor(){console.log("**** construct Routes");this.__installed=!1;this.__gridName="gridRoutes";this.__dialogName="dialogRoutes";this.__storageNameGeometry=this.__dialogName+"_geometry";this.__windowGeometry=new WindowGeometryStorage(this.__dialogName);this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}show(){const n=$("#"+this.__dialogName);this.__windowGeometry.showWithGeometry(n);this.__installed?n.dialog("open"):(this.install({autoOpen:!0}),n.dialog("open"));w2ui[this.__gridName].refresh()}isShown(){try{return $("#"+this.__dialogName).dialog("isOpen")}catch(n){}return!1}__removeAllHighlights(){const n=window.planField;n&&n.clearRouteUserHighlight()}install(n={}){const t=this,r=this.isShown();if(!r){typeof n.autoOpen=="undefined"&&(n.autoOpen=!1);const i=this.__windowGeometry.recent();if($("#"+this.__dialogName).dialog({height:i.height,width:i.width,left:i.left,top:i.top,closeOnEscape:!1,autoOpen:n.autoOpen,resizeStop:function(n,i){t.__windowGeometry.save(i.position,i.size)},dragStop:function(n,i){t.__windowGeometry.save(i.position,{width:n.target.clientWidth,height:n.target.clientHeight})},close:function(){t.__removeAllHighlights();const n=w2ui[t.__gridName];n.selectNone()}}),!w2ui[this.__gridName]){const i=$("#"+this.__gridName);i.w2grid({name:this.__gridName,header:"Routes",multiSelect:!1,show:{toolbar:!0,footer:!0,toolbarAdd:!1,toolbarDelete:!1,toolbarEdit:!1,toolbarSave:!1,multiSelect:!1},textSearch:"contains",recid:"routeId",searches:[{field:"name",caption:"Name",type:"text"}],sortData:[{field:"routeId",direction:"asc"}],columns:[{field:"routeId",caption:"Route ID",sortable:!1,hidden:!0},{field:"native",caption:"Native",sortable:!0,hidden:!0},{field:"name",caption:"Name",size:"20%",sortable:!0},{field:"isDisabled",caption:"Disabled",size:"10%",style:"text-align: center",editable:{type:"checkbox",style:"text-align: center"}},{field:"switches",caption:"Switches",size:"10%",sortable:!1},{field:"sensors",caption:"Sensors",size:"10%",sortable:!1},{field:"signals",caption:"Signals",size:"10%",sortable:!1},{field:"tracks",caption:"Tracks",size:"10%",sortable:!1},],records:[],onSelect:function(n){const r=w2ui[t.__gridName],u=r.get(n.recid),i=window.planField;i&&(i.clearRouteUserHighlight(),i.activateRouteUserHighlight(u.native));bringToFront(t.__dialogName)},onUnselect:function(){t.__removeAllHighlights()}});const n=w2ui[t.__gridName].toolbar;n&&(n.insert("search",{type:"button",id:"itemCheckRoute",text:"Check",img:"fas fa-check",checked:!1,tooltip:function(){return"Simulates the route by changing any relevant accessory to let the trains reach its destination."},onClick:function(){const n=w2ui[t.__gridName],i=n.getSelection();for(let r=0;r<i.length;++r){const f=i[r],u=n.get(f);t.__trigger("checkRoute",{mode:"checkRoute",routeName:u.name,"native":u.native})}}}),n.add({type:"button",id:"cmdSave",text:"Save ",img:"fas fa-save",tooltip:function(){return"Applies all changes to the server."},onClick:function(){const n=w2ui[t.__gridName],i=n.getChanges();for(let r=0;r<i.length;++r){const e=i[r],o=e.recid,f=n.get(o),u=e.isDisabled;typeof u!="undefined"&&u!=null&&(f.isDisabled=u,n.refreshCell(f,"isDisabled"),t.__trigger("setting",{mode:"route",cmd:"disable",value:{routeName:f.name,disableState:u}}))}t.__cleanupChangedState()}}));this.__installed=!0}}}__cleanupChangedState(){const n=this;$("#"+this.__dialogName+" td.w2ui-grid-data").each(function(){$(this).removeClass("w2ui-changed")})}updateRoutes(n){const u=this;if(typeof n!="undefined"&&n!=null){const i=w2ui[u.__gridName],r=[];let t;const f=n.length;for(t=0;t<f;++t){const e=i.find({routeId:t}),u=n[t],o=u.name;let f=u.isDisabled;if((typeof f=="undefined"||f==null)&&(f=!1),e.length<=0)r.push({routeId:t,"native":u,name:o,isDisabled:f,switches:u.switches.length,sensors:u.sensors.length,signals:u.signals.length,tracks:u.tracks.length});else{const r=e[0],n=i.get(r);n.isDisabled!==f&&(n.isDisabled=f,i.refreshCell(t,"isDisabled"))}}r.length>0&&i.add(r)}}clearGrid(){const t=this;typeof routes!="undefined"&&window.routes!=null&&(window.routes=[]);const n=w2ui[t.__gridName];typeof n!="undefined"&&n!=null&&(n.clear(!0),n.reset())}}class ServerHandling{constructor(n={}){console.log("**** construct ServerHandling");this.__reconnectIntervalMsecs=5e3;this.__updateServerInformation(n);this.__planField=window.planField;this.__errorHandler=window.errorHandler;this.__checkConnectIntervalId=null;this.__initEventHandling()}__initEventHandling(){this.__events=new Events}on(n,t){this.__events.on(n,t)}__trigger(n,t){this.__events.triggerHandler(n,{sender:this,data:t})}__getReconnectCountdownMessage(n){return"Connection not established to "+this.wsUrl+". Try to reconnect in "+n+" seconds."}__updateServerInformation(n){n&&(n.wsAddr&&(this.wsAddr=n.wsAddr),n.wsPort&&(this.wsPort=n.wsPort))}__cleanupWebSocket(){(typeof self.__ws!="undefined"||self.__ws!=null)&&(this.__ws.onopen=function(){},this.__ws.onmessage=function(){},this.__ws.onerror=function(){},this.__ws.onclose=function(){},this.__ws.close())}__connect(){const n=this;this.__cleanupWebSocket();this.wsUrl="ws://"+this.wsAddr+":"+this.wsPort+"/";this.__ws=new WebSocket(this.wsUrl);this.__ws.onopen=function(){n.__handleOnOpen()};this.__ws.onmessage=function(t){n.__handleOnMessage(t)};this.__ws.onerror=function(t){n.__handleOnError(t)};this.__ws.onclose=function(){n.__handleOnClose()}}__startConnectHandlerInterval(){if(this.__checkConnectIntervalId==null){const n=this;var t=parseInt(this.__reconnectIntervalMsecs/1e3);this.__checkConnectIntervalId=setInterval(function(){t<=0?(console.log("Try to connect..."),n.__errorHandler.setLevel(ErrorHandlerLevel.Info),n.__errorHandler.setText("Try to connect...",!0),n.__stopConnectHandlerInterval(),n.__connect()):(n.__errorHandler.setLevel(ErrorHandlerLevel.Error),n.__errorHandler.setText(n.__getReconnectCountdownMessage(t),!0));--t},1e3)}}__stopConnectHandlerInterval(){if(this.__checkConnectIntervalId!=null){const n=this;clearInterval(this.__checkConnectIntervalId);this.__checkConnectIntervalId=null}}__handleOnOpen(){console.log("ServerHandling Connected to "+this.wsUrl);this.__stopConnectHandlerInterval();this.__errorHandler.hide()}__handleOnMessage(n){const t=JSON.parse(n.data);switch(t.command){case"debugMessages":this.__trigger("debugMessages",t.messages);break;case"initialization":this.__trigger("settingsDataReceived",t.settings);this.__trigger("themeDataReceived",t.themeData);this.__planField.initFromServer(t.metamodel);this.__trigger("dataReceived",t);break;case"update":this.__trigger("dataReceived",t);break;case"occ":this.__trigger("occReceived",t);break;case"locomotivesData":this.__trigger("locomotivesDataReceived",t);break;case"feedbacksData":this.__trigger("feedbacksDataReceived",t);break;case"autoMode":this.__trigger("autoModeReceived",t);break;case"result":this.__trigger("commandResultReceived",t)}}__handleOnError(){const n=this.__reconnectIntervalMsecs/1e3;this.__errorHandler.setLevel(ErrorHandlerLevel.Error);this.__errorHandler.setText(this.__getReconnectCountdownMessage(n));this.__cleanupWebSocket();this.__startConnectHandlerInterval()}__handleOnClose(){this.__errorHandler.setLevel(ErrorHandlerLevel.Error);this.__errorHandler.setText("Connection closed.");this.__cleanupWebSocket();this.__startConnectHandlerInterval()}establishConnection(n={}){const t=this;this.__errorHandler.setLevel(ErrorHandlerLevel.Info);this.__errorHandler.setText("Try to establish connection...");this.__updateServerInformation(n);this.__connect()}isConnected(){if(typeof this.__ws=="undefined"||this.__ws==null)return!1;var n=this.__ws.readyState;return n==1}__getCoordOf(n){const t=n.get(0).offsetLeft/constItemWidth,i=n.get(0).offsetTop/constItemHeight;return{x:t,y:i}}__getJsonData(n){return n.data(constDataThemeItemObject)}sendControl(n){var t,r,i,u;if(!this.isConnected())return!1;t={command:"update",itemData:this.__getJsonData(n)};t.itemData.identifier=n.attr("id");t.itemData.coord=this.__getCoordOf(n);t.itemData.editor.themeDimIdx=n.data(constDataThemeDimensionIndex);r=n.hasClass("elEditorRoot");r&&(i=n.find("div.elEditor"),t.itemData.editor.innerHtml=i.html(),t.itemData.editor.outerHtml=n.html(),t.itemData.editor.size={width:i.css("width"),height:i.css("height")});u=JSON.stringify(t);this.__ws.send(u)}removeControl(n){if(!this.isConnected())return!1;var t={command:"remove",itemId:n};this.__ws.send(JSON.stringify(t))}sendCommand(n){typeof n!="undefined"&&n!==null&&this.__ws.send(JSON.stringify(n))}}(function(n,t){var i=[];t.each(["localStorage","sessionStorage"],function(r,u){try{i[u]=u in n&&n[u]!==null}catch(f){i[u]=!1}t[u]={settings:{cookiePrefix:"ecosApp:"+u+":",cookieOptions:{path:"/ecosApp",domain:document.domain,expires:"localStorage"===u?{expires:365}:undefined}},getItem:function(r){return i[u]?n[u].getItem(r):t.cookie(this.settings.cookiePrefix+r)},setItem:function(r,f){return i[u]?n[u].setItem(r,f):t.cookie(this.settings.cookiePrefix+r,f,this.settings.cookieOptions)},removeItem:function(r){if(i[u])return n[u].removeItem(r);var f=t.extend(this.settings.cookieOptions,{expires:-1});return t.cookie(this.settings.cookiePrefix+r,null,f)},clear:function(){if(i[u])return n[u].clear();var r=new RegExp("^"+this.settings.cookiePrefix,""),f=t.extend(this.settings.cookieOptions,{expires:-1});document.cookie&&document.cookie!==""&&t.each(document.cookie.split(";"),function(n,i){r.test(i=t.trim(i))&&t.cookie(i.substr(0,i.indexOf("=")),null,f)})}}})})(window,jQuery);class TextfieldElement{constructor(){console.log("**** construct TextfieldElement");window.__currentTextEditorElement=null;this.__tbId="textfieldElementToolbar";this.__uniqueId=null;this.__element=null;this.__initialText="TEXT";this.__initialFontSize="14px"}setEditMode(n){n?this.__element.resizable("enable"):(this.__element.attr("contenteditable",!1),this.__element.resizable("disable"))}install(n={}){typeof n.fontSize!="undefined"&&(this.__initialFontSize=n.fontSize);this.__uniqueId=typeof n.uniqueId!="undefined"?n.uniqueId:null;this.__initEditorToolbar();var i=$(".tplElEditorRoot"),t=i.clone();t.removeClass("tplElEditorRoot");t.addClass("elEditorRoot");this.__element=t;this.__uniqueId==null&&(this.__uniqueId=window.planField.generateUniqueItemIdentifier());t.attr("id",this.__uniqueId);t.show();this.__element.resizable({grid:constItemWidth});this.__initEditorForTextElements();this.__alignToolbarToEditor(t);this.setEditMode(!1)}__initEditorToolbar(){const n=this;this.__selectedSizeIdx="idSize14";switch(this.__initialFontSize){case"10px":this.__selectedSizeIdx="idSize10";break;case"11px":this.__selectedSizeIdx="idSize11";break;case"12px":this.__selectedSizeIdx="idSize12";break;case"13px":this.__selectedSizeIdx="idSize13";break;case"14px":this.__selectedSizeIdx="idSize14";break;case"15px":this.__selectedSizeIdx="idSize15";break;case"16px":this.__selectedSizeIdx="idSize16"}(typeof __editorToolboxInitialized=="undefined"&&(window.__editorToolboxInitialized=!1),window.__editorToolboxInitialized)||(window.__editorToolboxInitialized=!0,$("#"+this.__tbId).w2toolbar({name:"toolbarFont",style:"position: absolute; display: none;",items:[{id:"cmdRemove",type:"button",icon:"fas fa-trash-alt"},{type:"break"},{id:"cmdBold",type:"button",icon:"fas fa-bold"},{id:"cmdItalic",type:"button",icon:"fas fa-italic"},{id:"cmdUnderline",type:"button",icon:"fas fa-underline"},{type:"menu-radio",id:"fontSize",text:function(n){var t=this.get("fontSize:"+n.selected);return t.text},selected:n.__selectedSizeIdx,items:[{id:"idSize10",text:"10px"},{id:"idSize11",text:"11px"},{id:"idSize12",text:"12px"},{id:"idSize13",text:"13px"},{id:"idSize14",text:"14px"},{id:"idSize15",text:"15px"},{id:"idSize16",text:"16px"}]},{id:"cmdBackgroundColor",type:"color"},{id:"cmdTextColor",type:"text-color",transparent:!1}],onClick:function(t){var r,i,u;if(t.color!=null)t.done(function(){if(window.__currentTextEditorElement!=null)switch(t.item.type){case"color":document.execCommand("hilitecolor",!1,t.item.color);break;case"text-color":document.execCommand("foreColor",!1,t.item.color)}});else if(t.object!==null&&typeof t.object!="undefined")switch(t.object.id){case"cmdRemove":i=window.__currentTextEditorElement;i.off("DOMSubtreeModified");i.find(".elEditor").off("DOMSubtreeModified");$("#"+n.__tbId).hide();r=i.attr("id");window.serverHandling.removeControl(r);i.remove();removeTextfieldFromGlobalList(r);break;case"cmdBold":document.execCommand("bold",!1,null);break;case"cmdItalic":document.execCommand("italic",!1,null);break;case"cmdUnderline":document.execCommand("underline",!1,null)}else t.item!==null&&typeof t.item!="undefined"&&(i=window.__currentTextEditorElement,u=w2ui.toolbarFont.get(t.target).text,i.find(".elEditor").css({"font-size":u}),window.serverHandling.sendControl(i))}}))}__initEditorForTextElements(){var i;const n=this;this.setEditMode(window.planField.isEditMode);var t=this.__element,r=function(n){var t,r,i;if(typeof n.target!="undefined"&&n.target!==null){if(t=n.currentTarget,t&&$(t).hasClass("elEditorRoot")){window.serverHandling.sendControl($(t));return}r=$(n.target);i=r.parent(".elEditorRoot");i&&window.serverHandling.sendControl(i)}},u=function(n,t){if(t)n.on("DOMSubtreeModified",r);else n.off("DOMSubtreeModified",r)};t.dblclick(function(){if(window.planField.isEditMode){n.__element.attr("contenteditable",!0);$(this).focus();u($(this),!0);var t=$("#"+n.__tbId);t.show();n.__alignToolbarToEditor(n.__element);window.__currentTextEditorElement=$(this);w2ui.toolbarFont.refresh();$("#"+n.__tbId).find(".w2ui-scroll-right").css("display","none");$("#tb_toolbarFont_right").css("display","none")}});t.keydown(function(t){if(!t.shiftKey&&(t.keyCode===constKeyEnter||t.keyCode===constKeyEscape)){t.stopPropagation();t.preventDefault();$("#"+n.__tbId).hide();var i=$(".elEditorRoot");i.each(function(){$(this).blur();u($(this).find(".elEditor"),!1);$(this).attr("contenteditable",!1)})}});t.resize(function(){var i=$(this).width(),r=$(this).height(),t;n.__element.find(".elEditor").css({width:i+"px",height:r+"px"});t=window.__currentTextEditorElement;t||(t=n.__element);window.serverHandling.sendControl(t)});i=t.find(".elEditor");i.css({"font-size":this.__initialFontSize});i.html(this.__initialText)}__alignToolbarToEditor(n){var r;if(n){var i=n.get(0).getBoundingClientRect(),u=i.left,f=i.top,e=$("#"+this.__tbId).get(0).getBoundingClientRect(),o=e.height,s=w2ui.toolbarFont.items.length,h=s*constItemWidth+2+"px",t=f-o-5;t<0&&(t=0);r=$("#"+this.__tbId);r.css({"z-index":999,left:u-constItemWidth-5+"px",top:t+"px",width:h,border:"1px solid rgba(0,0,0,0.2)"})}}}class Toolbox{constructor(){toolbox;console.log("**** construct Toolbox");this.__toolbox=$("#toolbox");this.recentItem=null}rotate(n){const t=$("div.toolboxItem").filterByData("theme-id",n.themeId);if(typeof t!="undefined"&&t!=null){const i=t.find("img");if(typeof i!="undefined"&&i!=null){t.data(constDataThemeDimensionIndex,n.themeDimIdx);i.css({"transform-origin":n.transformOrigin,transform:n.transform});const r=this.getJsonDataOfItem(t);t.data(constDataThemeItemObject,r);this.recentItem=r}}}getJsonDataOfItem(n){const t=n.data(constDataThemeItemObject);return typeof t.editor=="undefined"&&(t.editor={}),t.editor.themeId=n.data("theme-id"),t.editor.themeDimIdx=n.data(constDataThemeDimensionIndex),t}showToolbox(){this.__toolbox.show()}hideToolbox(){this.__toolbox.hide()}__collapseCategory(n){n.data("railway-collapsed","");n.parent().find("div.toolboxItem").each(function(){$(this).hide()});const t=n.find("img");t.attr("src","images/expand.png")}__expandCategory(n){n.removeData("railway-collapsed");n.parent().find("div.toolboxItem").each(function(){$(this).show()});const t=n.find("img");t.attr("src","images/collapse.png")}install(){function i(t){const r=$(t.target),i=n.getJsonDataOfItem(r);i.editor.offsetX=t.offsetX;i.editor.offsetY=t.offsetY;r.data(constDataThemeItemObject,i);const u=JSON.stringify(i);t.dataTransfer.setData("text/plain",u);n.recentItem=i}const n=this;themeObject.forEach(t=>{var u=$("<div>",{}).css({}).addClass("toolboxHead").appendTo(this.__toolbox),i=$("<div>",{text:t.category}).addClass("toolboxTitle"),f,r;i.click(function(){var t=i.data("railway-collapsed");t=typeof t=="undefined"&&t==null?!1:!0;t?n.__expandCategory(i):n.__collapseCategory(i)});f=$("<img>",{width:"16px",height:"16px",float:"right"});f.appendTo(i);i.appendTo(u);r=$("<div>").appendTo(u);r.addClass("toolboxContainer");t.objects.forEach(n=>{if(n.id!=-1){if(typeof n.visible!="undefined"&&n.visible===!1)return;const t=$("<div>",{html:""}).addClass("toolboxItem").attr({draggable:"true"});t.data(constDataThemeId,n.id);t.data(constDataThemeItemObject,n);t.appendTo(r);let i="";i=n.active&&n.active.default?n.active.default+".png":n.basename+".png";const u=$("<img>",{}).addClass("imgWithTooltip").attr({"data-tipso-title":n.name,draggable:"false",src:"theme/"+window.settings.themeName+"/"+i});u.appendTo(t)}});t.category==="Signal"||t.category==="Block"?this.__collapseCategory(i):this.__expandCategory(i)});const t=$("div.toolboxItem");for(let n=0;n<t.length;++n){const r=t[n];r.ondragstart=i}$(".imgWithTooltip").tipso({size:"tiny",speed:100,delay:500,useTitle:!0,width:"auto",background:"#333333",titleBackground:"#333333"});this.__toolbox.resizable({minWidth:125,autoHide:!0})}}_htmlEntities=function(n){return String(n).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};window.__cachedLocomotiveImages={};class WindowGeometryStorage{constructor(n,t={left:100,top:100,width:450,height:500}){this.__fieldName=n;this.__defaultGeometry=t}save(n,t){const r=this;var i={left:n.left,top:n.top,width:t.width,height:t.height};$.localStorage.setItem(this.__fieldName,JSON.stringify(i))}recent(){var n;const t=this;return(n=$.localStorage.getItem(this.__fieldName),typeof n=="undefined"||n==null)?this.__defaultGeometry:JSON.parse(n)}showWithGeometry(n,t=true){var i=this.recent();t===!0&&(n.dialog("option","height",i.height),n.dialog("option","width",i.width));n.dialog("option","position",{my:"left top",at:"left+"+i.left+" top+"+i.top,of:window})}}window.__trainEvents||(window.__trainEvents=new Events,window.__eventOn=function(n,t){this.__trainEvents.on(n,t)},window.__eventTrigger=function(n,t){this.__trainEvents.triggerHandler(n,{sender:this,data:t})});window.occ=null;window.blocks=null;window.ecosData=null;window.serverHandling=null;window.editState=!1;window.routesDlg=null;window.accessoriesDlg=null;window.locomotivesDlg=null;window.locomotiveCtrlDlgs=[];window.textfieldElementInstances=[];window.planField=null;window.toolbox=null;window.errorHandler=null;window.labelShown=!1;window.findLocomotivesDlg=function(n){var r,t,i;if(!n)return null;for(r=window.locomotiveCtrlDlgs.length,t=0;t<r;++t)if((i=window.locomotiveCtrlDlgs[t],i)&&i.__dlgId===n)return i;return null};$(document).ready(function(){function n(n){return typeof n=="undefined"||n==null?!1:(window.planField.updateEcosAccessories(window.ecosData.accessories),typeof accessoriesDlg=="undefined"||window.accessoriesDlg==null)?!1:(n.result===!0&&(window.accessoriesDlg.removeAccessory(n.identifier),window.blocksDlg.controlRemoved(n.identifier)),!0)}window.__autoModeState=!1;addJqueryExtensions();initDebugConsole();$("#statusBar div.autoMode").tipso({size:"tiny",speed:100,delay:250,useTitle:!0,background:"#333333",titleBackground:"#333333"});$("#statusBar div.logging").tipso({size:"tiny",speed:100,delay:250,useTitle:!0,background:"#333333",titleBackground:"#333333"});window.__ecosbaseChanged=!1;window.__locomotivesChanged=!1;window.__accessoriesChanged=!1;window.__feedbacksChanged=!1;window.errorHandler=new ErrorHandler;window.toolbox=new Toolbox;window.dialogLightAndPower=new LightAndPower;window.dialogLightAndPower.install();window.dialogLightAndPower.on("relayCommand",function(n){const t=n.data;t.mode==="websocket"?relayWebsocketCommand(t):console.log("TODO unknown relay mode: "+t.mode)});window.dialogS88=new FeedbackVisualization;window.dialogS88.install();window.blocksDlg=new Blocks;window.blocksDlg.install();window.blocksDlg.on("setting",function(n){changeSetting(n.data)});window.occ=new Occ;window.occ.on("gotoBlock",function(n){gotoBlock(n.data)});window.occ.on("resetAssignment",function(n){resetAssignment(n.data)});window.occ.on("speedChanged",function(n){changeLocomotive("speedstep",n.data)});window.occ.on("directionChanged",function(n){changeLocomotive("direction",n.data)});window.occ.on("openLocomotiveControl",function(n){const t=n.data.oid;openLocomotiveControlDialogByOid(t)});window.occ.on("setting",function(n){changeSetting(n.data)});window.accessoriesDlg=new Accessories;window.accessoriesDlg.install();window.accessoriesDlg.on("accessoryExecute",function(n){accessoryExecute(n.data)});window.accessoriesDlg.on("setting",function(n){changeSetting(n.data)});window.__eventOn("startAccessoryTest",function(n){accessoryTest(n.data)});window.routesDlg=new Routes;window.routesDlg.install();window.routesDlg.on("checkRoute",function(n){checkRoute(n.data)});window.routesDlg.on("setting",function(n){changeSetting(n.data)});window.locomotivesDlg=new Locomotives;window.locomotivesDlg.install();window.locomotivesDlg.on("locomotiveDoubleClick",function(n){const t=n.data;openLocomotiveControlDialog(t)});window.locomotivesDlg.on("setting",function(n){changeSetting(n.data)});window.__eventOn("functionChanged",function(n){var t=JSON.parse(n.data);changeLocomotive("function",t)});window.planField=new Planfield({isEditMode:!1});window.planField.install();window.planField.on("controlCreated",function(n){const t=n.data.instance;typeof blocksDlg!="undefined"&&window.blocksDlg!=null&&window.blocksDlg.controlCreated(t)});window.planField.on("clicked",function(n){itemClicked(n.data)});window.planField.on("assignToBlock",function(n){assignLocomotiveToBlock(n.data)});window.planField.on("setting",function(n){changeSetting(n.data)});window.serverHandling=new ServerHandling({wsAddr:"localhost",wsPort:45099});window.serverHandling.establishConnection();window.serverHandling.on("occReceived",function(n){window.occ.handleData(n.data);window.locomotivesDlg.updateOccInformation(n.data)});window.serverHandling.on("locomotivesDataReceived",function(n){window.locomotivesDlg.updateLocomotives2(n.data);window.occ.updateOccWithLocomotiveData(n.data)});window.serverHandling.on("feedbacksDataReceived",function(n){window.blocksDlg.updateFeedbacks(n.data);window.planField.updateFeedbacks(n.data);window.locomotivesDlg.updateBlockInformation(n.data)});window.serverHandling.on("settingsDataReceived",function(n){window.settings=n.data});window.serverHandling.on("themeDataReceived",function(n){window.themeObject=n.data;window.toolbox.install()});window.serverHandling.on("debugMessages",function(n){window.addDebugMessages(n.data)});window.serverHandling.on("commandResultReceived",function(t){const i=t.data;if(typeof i=="undefined"||i==null)return!1;const r=i.command,u=i.result;if(typeof r=="undefined"||r==null||typeof u=="undefined"||u==null)return!1;switch(r){case"result":return n(u)}return!1});window.serverHandling.on("dataReceived",function(n){var t,r,i;if(window.ecosData=n.data.ecosData,typeof ecosData!="undefined"&&window.ecosData!=null){if(window.__ecosbaseChanged=window.ecosData.ecosbaseChanged,window.__locomotivesChanged=window.ecosData.locomotivesChanged,window.__accessoriesChanged=window.ecosData.accessoriesChanged,window.__feedbacksChanged=window.ecosData.feedbacksChanged,window.__ecosbaseChanged===!0&&(t=window.ecosData.ecosbase[0],typeof t!="undefined"&&t!=null)){r=$("#statusBar div.ecosPowerStatus");t.status==="GO"?(r.removeClass("offline"),r.addClass("online")):(r.removeClass("online"),r.addClass("offline"));var u=$("#statusBar div.ecosInformation"),f=t.name,e=t.protocolVersion,o=t.applicationVersion,s=t.hardwareVersion,h="<b>"+f+"<\/b> (SW: "+o+", HW: "+s+", Protocol: "+e+")";u.html(h)}window.__locomotivesChanged===!0&&(i=window.ecosData.locomotives,typeof i!="undefined"&&(window.locomotivesDlg.updateLocomotives(i),window.locomotivesDlg.updateLocomotives2(i),window.occ.updateEcosDirection(i),window.occ.updateEcosSpeedInfo(i)))}typeof n.data.routes!="undefined"&&n.data.routes!=null&&(window.routes=n.data.routes,typeof routes=="undefined"||window.routes==null||window.routesDlg.updateRoutes(window.routes));window.accessoriesDlg&&window.accessoriesDlg.updateAccessories(n.data);typeof ecosData!="undefined"&&window.ecosData!==null&&(window.__accessoriesChanged===!0&&window.planField.updateEcosAccessories(window.ecosData.accessories),window.__feedbacksChanged===!0&&(window.planField.updateEcosFeedbacks(window.ecosData.feedbacks),window.dialogS88.updateFeedbackSensors(window.ecosData.feedbacks)),window.accessoriesDlg&&window.accessoriesDlg.updateStates(n.data),typeof window.ecosData.locomotives!="undefined"&&window.ecosData.locomotives!=null&&window.__locomotivesChanged===!0&&window.occ.loadLocomotives(window.ecosData.locomotives))});window.serverHandling.on("autoModeReceived",function(n){const t=n.data;if(typeof t=="undefined"||t==null)return!1;const i=t.command;if(typeof i=="undefined"||i==null)return!1;const r=t.data.command;switch(r){case"ghost":{const n=t.data.state;if(typeof n=="undefined"||n==null)break;const i=function(){const n=$("div.ctrlItemFeedback[id]"),t=n.length;for(let i=0;i<t;++i)$(n[i]).removeClass("ghost")},r=function(){$(".overlayGhost").hide();$(".overlayGhostText").hide()},u=function(n){$(".overlayGhost").show();$(".overlayGhostText").html(n);$(".overlayGhostText").show()};if(typeof n.found=="undefined"||n.found==null||n.found===!1)i(),r();else{i();const r=$("div.ctrlItemFeedback[id]"),t=n.fbs;for(let n=0;n<t.length;++n){const i=t[n];if(typeof i!="undefined"&&i!=null){const u=i.coord,f=getCtrlOfCoord(u.x,u.y,r);f.addClass("ghost")}}t.length>0&&u("Ghost train detected!")}}break;case"state":{let n=t.data.state;if(typeof n=="undefined"||n==null)break;let i=t.data.state.stopping;if((typeof i=="undefined"||i==null)&&(i=!1),i===!0){n.message.length===0&&(n.message="AutoMode is stopping...");$(".overlayAutoMode").show();$(".overlayAutoModeText").html(n.message);$(".overlayAutoModeText").show();break}$(".overlayAutoMode").hide();$(".overlayAutoModeText").hide();let r=t.data.state.started;(typeof r=="undefined"||r==null)&&(r=!1);reinitAutoMode(r)}break;case"routeShow":{const n=t.data.routeNames;if(typeof n=="undefined"||n==null)return!1;let i;const r=n.length;for(i=0;i<r;++i)if(n[i]!=null){const t=n[i],r=getRouteByName(t);if(r==null){console.log("Route does not exist: "+t);continue}window.planField.activateRouteVisualization(r)}}break;case"routeReset":{const n=t.data.routeNames;if(typeof n=="undefined"||n==null)return!1;let i;const r=n.length;for(i=0;i<r;++i)if(n[i]!=null){const t=n[i],r=getRouteByName(t);if(r==null){console.log("Route does not exist: "+t);continue}window.planField.deativateRouteVisualization(r)}}}});loadSideBar();loadWebcams();initWebcamsState();initLabelState()});loadSideBar=function(){function n(n,t=true,i=null){(typeof __autoModeState=="undefined"||window.__autoModeState==null)&&(window.__autoModeState=!1);let r;r=n===!0&&window.__autoModeState===!1?"Do you like to start AutoMode?":"Stop AutoMode?";w2confirm(r,"AutoMode").yes(function(){const n=window.serverHandling;typeof n!="undefined"&&n!=null&&(window.__autoModeState===!0?(window.planField.clearRouteUserHighlight(),t===!0&&n.sendCommand({command:"autoMode",timestamp:Date.now(),cmddata:{state:!1}}),$("#statusBar div.autoMode").removeClass("fa-spin"),window.__autoModeState=!1):window.__autoModeState===!1&&(t===!0&&n.sendCommand({command:"autoMode",timestamp:Date.now(),cmddata:{state:!0}}),$("#statusBar div.autoMode").addClass("fa-spin"),window.__autoModeState=!0),i!=null&&i(window.__autoModeState))}).no(function(){})}function t(){w2confirm("Do you like to initialize all Switches, Accessories, Signals, and more to a well known state?","Initialize").yes(function(){const n=window.serverHandling;typeof n!="undefined"&&n!=null&&n.sendCommand({command:"initializeSystem",timestamp:Date.now(),cmddata:{}})}).no(function(){})}function i(){w2confirm("Do you like to analyze all routes?<br><br>Current disabled states will be kept, new routes will be added, vanished routes will be removed.","Analyze Routes").yes(function(){const n=window.serverHandling;typeof n!="undefined"&&n!=null&&(window.routesDlg.clearGrid(),window.blocksDlg.clearGrid(),n.sendCommand({command:"analyzeRoutes",timestamp:Date.now(),cmddata:{}}))}).no(function(){})}function r(){w2confirm("Do you like to shutdown your model railway?","Shutdown").yes(function(){const n=window.serverHandling;typeof n!="undefined"&&n!=null&&n.sendCommand({command:"shutdownSystem",timestamp:Date.now(),cmddata:{}})}).no(function(){})}function u(){w2popup.open({title:"TODO / TBD",body:'<div class="w2ui-centered">Must be implemented.<\/div>'})}$("#sidebar").w2sidebar({name:"sidebar",flatButton:!0,nodes:[{id:"level-1",text:"Control",img:"icon-folder",expanded:!0,group:!0,groupShowHide:!1,nodes:[{id:"cmdOpenLocomotives",text:"Locomotives",icon:"fa fa-train"},{id:"cmdAccessories",text:"Accessories",icon:"fas fa-magic"},{id:"cmdLight",text:"Light",icon:"fas fa-lightbulb"},{id:"cmdInitialize",text:"Initialize",icon:"fas fa-tasks"},{id:"cmdAutomatic",text:"Automatic (off)",icon:"fas fa-robot fa-red"}]},{id:"level-2",text:"Administration",img:"icon-folder",expanded:!0,group:!0,groupShowHide:!0,nodes:[{id:"cmdToggleLabels",text:"Labels (off)",icon:"fas fa-tags"},{id:"cmdEditPlan",text:"Layout",icon:"fa fa-edit"},{id:"cmdOpenBlocksAndFeedbacks",text:"Blocks/S88/Signals",icon:"fas fa-traffic-light"},{id:"cmdOpenS88",text:"S88 Viewer",icon:"fas fa-radiation-alt"},{id:"cmdOpenRoutes",text:"Routes",icon:"fa fa-route"},{id:"cmdAnalyzeRoutes",text:"Analyze Routes",icon:"fas fa-diagnoses"},{id:"cmdToggleWebcams",text:"Webcams (on)",icon:"fas fa-video"},{id:"cmdWorldClock",text:"Worldclock",icon:"fas fa-history",hidden:!0}]},{id:"levelEcos",text:"ECoS",img:"icon-folder",expanded:!0,group:!0,groupShowHide:!1,nodes:[{id:"cmdPower",text:"Power",icon:"fas fa-power-off"},{id:"cmdStop",text:"Stop Trains",icon:"fas fa-stop-circle"},{id:"cmdShutdown",text:"Shutdown",icon:"fas fa-times-circle"},{id:"cmdChangeWorkspace",text:"Workspace",icon:"fas fa-code-branch"}]},{id:"level-3",text:"Help",img:"icon-folder",group:!0,groupShowHide:!0,nodes:[{id:"cmdHelp",text:"Help",icon:"fas fa-question-circle"},{id:"cmdAbout",text:"About",icon:"fas fa-address-card"},{id:"cmdReport",text:"Report",icon:"far fa-newspaper"}]}],onFlat:function(n){$("#sidebar").css("width",n.goFlat?"35px":"200px");realignDebugConsole()},onClick:function(f){var e=f.target,o;if(e==="cmdOpenLocomotives")locomotivesDlg.show(),w2ui.sidebar.unselect("cmdOpenLocomotives");else if(e==="cmdOpenBlocksAndFeedbacks")window.blocksDlg.show(),w2ui.sidebar.unselect("cmdOpenBlocksAndFeedbacks");else if(e==="cmdOpenRoutes")routesDlg.show(),w2ui.sidebar.unselect("cmdOpenRoutes");else if(e==="cmdAccessories")accessoriesDlg.show(),w2ui.sidebar.unselect("cmdAccessories");else if(e==="cmdOpenS88")window.dialogS88.show(),w2ui.sidebar.unselect("cmdOpenS88");else if(e==="cmdEditPlan")o=function(n){toggleAllLocomotiveInformation(n)},window.editState?(window.editState=!1,window.planField.setEditMode(!1),o(!0),window.toolbox.hideToolbox()):(window.editState=!0,window.planField.setEditMode(!0),o(!1),window.toolbox.showToolbox()),w2ui.sidebar.unselect("cmdEditPlan");else if(e==="cmdToggleLabels")toggleLabelOnOff(f.node,"Labels","cmdToggleLabels",function(n){toggleAllLabelInformation(n);window.labelShown=n}),w2ui.sidebar.unselect("cmdToggleLabels");else if(e==="cmdToggleWebcams")toggleLabelOnOff(f.node,"Webcams","cmdToggleWebcams",function(n){toggleAllWebcamsVisibility(n)}),w2ui.sidebar.unselect("cmdToggleWebcams");else if(e==="cmdLight")window.dialogLightAndPower.show(),w2ui.sidebar.unselect("cmdLight");else if(e==="cmdWorldClock")u(),w2ui.sidebar.unselect("cmdWorldClock");else if(e==="cmdPower")changeSetting({mode:"ecos",cmd:"power"}),w2ui.sidebar.unselect("cmdPower");else if(e==="cmdStop")changeSetting({mode:"ecos",cmd:"stop"}),w2ui.sidebar.unselect("cmdStop");else if(e==="cmdAutomatic"){const t=f.node.text,i=t.includes("off");n(i,!0,function(n){toggleLabelOnOff(f.node,"Automatic","cmdAutomatic",null,n)});w2ui.sidebar.unselect("cmdAutomatic")}else e==="cmdInitialize"?(t(f.node),w2ui.sidebar.unselect("cmdInitialize")):e==="cmdAnalyzeRoutes"?(i(f.node),w2ui.sidebar.unselect("cmdAnalyzeRoutes")):e==="cmdShutdown"?(r(f.node),w2ui.sidebar.unselect("cmdShutdown")):e==="cmdChangeWorkspace"?(handleWorkspace(f.node),w2ui.sidebar.unselect("cmdChangeWorkspace")):e==="cmdHelp"?(window.open(constGitWikiWebsite,"_blank"),w2ui.sidebar.unselect("cmdHelp")):e==="cmdAbout"?(w2popup.open({title:"About",body:'<div class="w2ui-centered"><div style="font-weight: bold;">&copy; Dr. Christian Benjamin Ries<\/div><br><table style="text-align: center; margin: auto;"><tr><td>Contact:<\/td><td style="text-align: left;">rail@christianbenjaminries.de<\/td><\/tr><tr><td>License:<\/td><td style="text-align: left;">MIT<\/td><\/tr><tr><td>Sourcecode:<\/td><td style="text-align: left;"><a href="'+constGitWebsite+'" target="_blank">'+constGitWebsite+'<\/a><\/td><\/tr><tr><td>Website:<\/td><td style="text-align: left;"><a href="http://www.railessentials.net" target="_blank">www.railessentials.net<\/a><\/td><\/tr><tr><td>Used libraries:<\/td><td style="text-align: left;"><a href="'+constGitUsedSwWebsite+'" target="_blank">Link to \'Third-Party Components at Their Best\'<\/a><\/td><\/tr><\/table><\/div>'}),w2ui.sidebar.unselect("cmdAbout")):e==="cmdReport"&&window.open("/report.html","_blank").focus()}})};