text: /* w2ui 1.5.x (nightly) (c) http://w2ui.com, vitmalina@gmail.com */
  /* edited by mirza ramadhany 
  	add : 
  	show.selectColumn_All [variable show grid] 02 18 2015
  */
  var w2ui=w2ui||{},w2obj=w2obj||{},w2utils=function(){function e(e){var t=/^[-+]?[0-9]+$/;return t.test(e)}function t(e){return"string"==typeof e&&(e=e.replace(w2utils.settings.decimalSymbol,".")),("number"==typeof e||"string"==typeof e&&""!==e)&&!isNaN(Number(e))}function i(e){var t=w2utils.settings,i=new RegExp("^"+(t.currencyPrefix?"\\"+t.currencyPrefix+"?":"")+"[-+]?[0-9]*[\\"+t.decimalSymbol+"]?[0-9]+"+(t.currencySuffix?"\\"+t.currencySuffix+"?":"")+"$","i");return"string"==typeof e&&(e=e.replace(new RegExp(t.groupSymbol,"g"),"")),"object"==typeof e||""===e?!1:i.test(e)}function s(e){var t=/^[a-fA-F0-9]+$/;return t.test(e)}function n(e){var t=/^[a-zA-Z0-9_-]+$/;return t.test(e)}function r(e){var t=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;return t.test(e)}function a(t,i,s){if(!t)return!1;var n,r,a,o="Invalid Date";if(null==i&&(i=w2utils.settings.date_format),"function"==typeof t.getUTCFullYear&&"function"==typeof t.getUTCMonth&&"function"==typeof t.getUTCDate)a=t.getUTCFullYear(),n=t.getUTCMonth(),r=t.getUTCDate();else if("function"==typeof t.getFullYear&&"function"==typeof t.getMonth&&"function"==typeof t.getDate)a=t.getFullYear(),n=t.getMonth(),r=t.getDate();else{if(t=String(t),new RegExp("mon","ig").test(i)){i=i.replace(/month/gi,"m").replace(/mon/gi,"m").replace(/dd/gi,"d").replace(/[, ]/gi,"/").replace(/\/\//g,"/").toLowerCase(),t=t.replace(/[, ]/gi,"/").replace(/\/\//g,"/").toLowerCase();for(var l=0,d=w2utils.settings.fullmonths.length;d>l;l++){var h=w2utils.settings.fullmonths[l];t=t.replace(new RegExp(h,"ig"),parseInt(l)+1).replace(new RegExp(h.substr(0,3),"ig"),parseInt(l)+1)}}var u=t.replace(/-/g,"/").replace(/\./g,"/").toLowerCase().split("/"),c=i.replace(/-/g,"/").replace(/\./g,"/").toLowerCase();"mm/dd/yyyy"===c&&(n=u[0],r=u[1],a=u[2]),"m/d/yyyy"===c&&(n=u[0],r=u[1],a=u[2]),"dd/mm/yyyy"===c&&(n=u[1],r=u[0],a=u[2]),"d/m/yyyy"===c&&(n=u[1],r=u[0],a=u[2]),"yyyy/dd/mm"===c&&(n=u[2],r=u[1],a=u[0]),"yyyy/d/m"===c&&(n=u[2],r=u[1],a=u[0]),"yyyy/mm/dd"===c&&(n=u[1],r=u[2],a=u[0]),"yyyy/m/d"===c&&(n=u[1],r=u[2],a=u[0]),"mm/dd/yy"===c&&(n=u[0],r=u[1],a=u[2]),"m/d/yy"===c&&(n=u[0],r=u[1],a=parseInt(u[2])+1900),"dd/mm/yy"===c&&(n=u[1],r=u[0],a=parseInt(u[2])+1900),"d/m/yy"===c&&(n=u[1],r=u[0],a=parseInt(u[2])+1900),"yy/dd/mm"===c&&(n=u[2],r=u[1],a=parseInt(u[0])+1900),"yy/d/m"===c&&(n=u[2],r=u[1],a=parseInt(u[0])+1900),"yy/mm/dd"===c&&(n=u[1],r=u[2],a=parseInt(u[0])+1900),"yy/m/d"===c&&(n=u[1],r=u[2],a=parseInt(u[0])+1900)}return e(a)&&e(n)&&e(r)?(a=+a,n=+n,r=+r,o=new Date(a,n-1,r),null==n?!1:"Invalid Date"==String(o)?!1:o.getMonth()+1!==n||o.getDate()!==r||o.getFullYear()!==a?!1:s===!0?o:!0):!1}function o(e,t){if(null==e)return!1;var i,s;e=String(e),e=e.toUpperCase(),s=e.indexOf("PM")>=0;var n=s||e.indexOf("AM")>=0;i=n?12:24,e=e.replace("AM","").replace("PM",""),e=$.trim(e);var r=e.split(":"),a=parseInt(r[0]||0),o=parseInt(r[1]||0);return n&&1===r.length||2===r.length?""===r[0]||0>a||a>i||!this.isInt(r[0])||r[0].length>2?!1:2===r.length&&(""===r[1]||0>o||o>59||!this.isInt(r[1])||2!==r[1].length)?!1:n||i!==a||0===o?n&&1===r.length&&0===a?!1:t===!0?(s&&(a+=12),{hours:a,minutes:o}):!0:!1:!1}function l(e){if(""===e||null==e||"object"==typeof e&&!e.getMonth)return"";var t=new Date(e);if(w2utils.isInt(e)&&(t=new Date(Number(e))),"Invalid Date"==String(t))return"";var i=new Date,s=(i.getTime()-t.getTime())/1e3,n="",r="";return 0>s?(n='<span style="color: #aaa">0 sec</span>',r=""):60>s?(n=Math.floor(s),r="sec",0>s&&(n=0,r="sec")):3600>s?(n=Math.floor(s/60),r="min"):86400>s?(n=Math.floor(s/60/60),r="hour"):2592e3>s?(n=Math.floor(s/24/60/60),r="day"):31536e3>s?(n=Math.floor(s/30/24/60/60*10)/10,r="month"):126144e3>s?(n=Math.floor(s/365/24/60/60*10)/10,r="year"):s>=126144e3&&(n=Math.floor(s/365.25/24/60/60*10)/10,r="year"),n+" "+r+(n>1?"s":"")}function d(e){if(""===e||null==e||"object"==typeof e&&!e.getMonth)return"";var t=new Date(e);if(w2utils.isInt(e)&&(t=new Date(Number(e))),"Invalid Date"==String(t))return"";var i=w2utils.settings.shortmonths,s=new Date,n=new Date;n.setTime(n.getTime()-864e5);var r=i[t.getMonth()]+" "+t.getDate()+", "+t.getFullYear(),a=i[s.getMonth()]+" "+s.getDate()+", "+s.getFullYear(),o=i[n.getMonth()]+" "+n.getDate()+", "+n.getFullYear(),l=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+" "+(t.getHours()>=12?"pm":"am"),d=t.getHours()-(t.getHours()>12?12:0)+":"+(t.getMinutes()<10?"0":"")+t.getMinutes()+":"+(t.getSeconds()<10?"0":"")+t.getSeconds()+" "+(t.getHours()>=12?"pm":"am"),h=r;return r===a&&(h=l),r===o&&(h=w2utils.lang("Yesterday")),'<span title="'+r+" "+d+'">'+h+"</span>"}function h(e){if(!w2utils.isFloat(e)||""===e)return"";if(e=parseFloat(e),0===e)return 0;var t=["Bt","KB","MB","GB","TB"],i=parseInt(Math.floor(Math.log(e)/Math.log(1024)));return(Math.floor(e/Math.pow(1024,i)*10)/10).toFixed(0===i?0:1)+" "+t[i]}function u(e,t,i){var s="";return null==t&&(t=w2utils.settings.groupSymbol||","),null==i&&(i=w2utils.settings.decimalSymbol||"."),(w2utils.isFloat(e)||w2utils.isInt(e)||w2utils.isMoney(e))&&(R=String(e).split("."),s=String(R[0]).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+t),null!=R[1]&&(s+=i+R[1])),s}function c(e,t){if(t||(t=this.settings.date_format),""===e||null==e||"object"==typeof e&&!e.getMonth)return"";var i=new Date(e);if(w2utils.isInt(e)&&(i=new Date(Number(e))),"Invalid Date"==String(i))return"";var s=i.getFullYear(),n=i.getMonth(),r=i.getDate();return t.toLowerCase().replace("month",w2utils.settings.fullmonths[n]).replace("mon",w2utils.settings.shortmonths[n]).replace(/yyyy/g,s).replace(/yyy/g,s).replace(/yy/g,s>2e3?100+parseInt(String(s).substr(2)):String(s).substr(2)).replace(/(^|[^a-z$])y/g,"$1"+s).replace(/mm/g,(10>n+1?"0":"")+(n+1)).replace(/dd/g,(10>r?"0":"")+r).replace(/th/g,1==r?"st":"th").replace(/th/g,2==r?"nd":"th").replace(/th/g,3==r?"rd":"th").replace(/(^|[^a-z$])m/g,"$1"+(n+1)).replace(/(^|[^a-z$])d/g,"$1"+r)}function p(e,t){w2utils.settings.shortmonths,w2utils.settings.fullmonths;if(t||(t=this.settings.time_format),""===e||null==e||"object"==typeof e&&!e.getMonth)return"";var i=new Date(e);if(w2utils.isInt(e)&&(i=new Date(Number(e))),w2utils.isTime(e)){var s=w2utils.isTime(e,!0);i=new Date,i.setHours(s.hours),i.setMinutes(s.minutes)}if("Invalid Date"==String(i))return"";var n="am",r=i.getHours(),a=i.getHours(),o=i.getMinutes(),l=i.getSeconds();return 10>o&&(o="0"+o),10>l&&(l="0"+l),(-1!==t.indexOf("am")||-1!==t.indexOf("pm"))&&(r>=12&&(n="pm"),r>12&&(r-=12)),t.toLowerCase().replace("am",n).replace("pm",n).replace("hhh",10>r?"0"+r:r).replace("hh24",10>a?"0"+a:a).replace("h24",a).replace("hh",r).replace("mm",o).replace("mi",o).replace("ss",l).replace(/(^|[^a-z$])h/g,"$1"+r).replace(/(^|[^a-z$])m/g,"$1"+o).replace(/(^|[^a-z$])s/g,"$1"+l)}function f(e,t){var i;return""===e||null==e||"object"==typeof e&&!e.getMonth?"":(i="string"!=typeof t?[this.settings.date_format,this.settings.time_format]:t.split("|"),this.formatDate(e,i[0])+" "+this.formatTime(e,i[1]))}function g(e){if(null===e)return e;switch(typeof e){case"number":break;case"string":e=$.trim(String(e).replace(/(<([^>]+)>)/gi,""));break;case"object":for(var t in e)e[t]=this.stripTags(e[t])}return e}function m(e){if(null===e)return e;switch(typeof e){case"number":break;case"string":e=String(e).replace(/&/g,"&").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/"/g,"&quot;");break;case"object":for(var t in e)e[t]=this.encodeTags(e[t])}return e}function v(e){return""===e||null==e?"":String(e).replace(/([;&,\.\+\*\~'`:"\!\^#$%@\[\]\(\)=<>\|\/? {}\\])/g,"\\$1")}function w(e){function t(e){e=String(e).replace(/\r\n/g,"\n");for(var t="",i=0;i<e.length;i++){var s=e.charCodeAt(i);128>s?t+=String.fromCharCode(s):s>127&&2048>s?(t+=String.fromCharCode(s>>6|192),t+=String.fromCharCode(63&s|128)):(t+=String.fromCharCode(s>>12|224),t+=String.fromCharCode(s>>6&63|128),t+=String.fromCharCode(63&s|128))}return t}var i,s,n,r,a,o,l,d="",h=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(e=t(e);h<e.length;)i=e.charCodeAt(h++),s=e.charCodeAt(h++),n=e.charCodeAt(h++),r=i>>2,a=(3&i)<<4|s>>4,o=(15&s)<<2|n>>6,l=63&n,isNaN(s)?o=l=64:isNaN(n)&&(l=64),d=d+u.charAt(r)+u.charAt(a)+u.charAt(o)+u.charAt(l);return d}function y(e){function t(e){for(var t,i,s="",n=0,r=0;n<e.length;)r=e.charCodeAt(n),128>r?(s+=String.fromCharCode(r),n++):r>191&&224>r?(t=e.charCodeAt(n+1),s+=String.fromCharCode((31&r)<<6|63&t),n+=2):(t=e.charCodeAt(n+1),i=e.charCodeAt(n+2),s+=String.fromCharCode((15&r)<<12|(63&t)<<6|63&i),n+=3);return s}var i,s,n,r,a,o,l,d="",h=0,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");h<e.length;)r=u.indexOf(e.charAt(h++)),a=u.indexOf(e.charAt(h++)),o=u.indexOf(e.charAt(h++)),l=u.indexOf(e.charAt(h++)),i=r<<2|a>>4,s=(15&a)<<4|o>>2,n=(3&o)<<6|l,d+=String.fromCharCode(i),64!==o&&(d+=String.fromCharCode(s)),64!==l&&(d+=String.fromCharCode(n));return d=t(d)}function b(e,t,i,s){function n(e,t,i){var s=!!window.webkitURL;return s||"undefined"==typeof i||(t=i),";"+e+": "+t+"; -webkit-"+e+": "+t+"; -moz-"+e+": "+t+"; -ms-"+e+": "+t+"; -o-"+e+": "+t+";"}var r=$(e).width(),a=$(e).height(),o=.5;if(!e||!t)return void console.log("ERROR: Cannot do transition when one of the divs is null");switch(e.parentNode.style.cssText+=n("perspective","700px")+"; overflow: hidden;",e.style.cssText+="; position: absolute; z-index: 1019; "+n("backface-visibility","hidden"),t.style.cssText+="; position: absolute; z-index: 1020; "+n("backface-visibility","hidden"),i){case"slide-left":e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; "+n("transform","translate3d("+r+"px, 0, 0)","translate("+r+"px, 0)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+";"+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),e.style.cssText+=n("transition",o+"s")+";"+n("transform","translate3d(-"+r+"px, 0, 0)","translate(-"+r+"px, 0)")},1);break;case"slide-right":e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; "+n("transform","translate3d(-"+r+"px, 0, 0)","translate(-"+r+"px, 0)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d(0px, 0, 0)","translate(0px, 0)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d("+r+"px, 0, 0)","translate("+r+"px, 0)")},1);break;case"slide-down":e.style.cssText+="overflow: hidden; z-index: 1; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; z-index: 0; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d(0, "+a+"px, 0)","translate(0, "+a+"px)")},1);break;case"slide-up":e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, "+a+"px, 0)","translate(0, "+a+"px)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)")},1);break;case"flip-left":e.style.cssText+="overflow: hidden; "+n("transform","rotateY(0deg)"),t.style.cssText+="overflow: hidden; "+n("transform","rotateY(-180deg)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateY(0deg)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateY(180deg)")},1);break;case"flip-right":e.style.cssText+="overflow: hidden; "+n("transform","rotateY(0deg)"),t.style.cssText+="overflow: hidden; "+n("transform","rotateY(180deg)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateY(0deg)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateY(-180deg)")},1);break;case"flip-down":e.style.cssText+="overflow: hidden; "+n("transform","rotateX(0deg)"),t.style.cssText+="overflow: hidden; "+n("transform","rotateX(180deg)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateX(0deg)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateX(-180deg)")},1);break;case"flip-up":e.style.cssText+="overflow: hidden; "+n("transform","rotateX(0deg)"),t.style.cssText+="overflow: hidden; "+n("transform","rotateX(-180deg)"),$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateX(0deg)"),e.style.cssText+=n("transition",o+"s")+"; "+n("transform","rotateX(180deg)")},1);break;case"pop-in":e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+n("transform","scale(.8)")+"; opacity: 0;",$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; "+n("transform","scale(1)")+"; opacity: 1;",e.style.cssText+=n("transition",o+"s")+";"},1);break;case"pop-out":e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; "+n("transform","scale(1)")+"; opacity: 1;",t.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; opacity: 1;",e.style.cssText+=n("transition",o+"s")+"; "+n("transform","scale(1.7)")+"; opacity: 0;"},1);break;default:e.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)"),t.style.cssText+="overflow: hidden; "+n("transform","translate3d(0, 0, 0)","translate(0, 0)")+"; opacity: 0;",$(t).show(),window.setTimeout(function(){t.style.cssText+=n("transition",o+"s")+"; opacity: 1;",e.style.cssText+=n("transition",o+"s")},1)}setTimeout(function(){"slide-down"===i&&($(e).css("z-index","1019"),$(t).css("z-index","1020")),t&&$(t).css({opacity:"1"}).css(w2utils.cssPrefix({transition:"",transform:"","backface-visibility":""})),e&&($(e).css({opacity:"1"}).css(w2utils.cssPrefix({transition:"",transform:"","backface-visibility":""})),e.parentNode&&$(e.parentNode).css(w2utils.cssPrefix("perspective",""))),"function"==typeof s&&s()},1e3*o)}function x(e,t,i){var s={};"object"==typeof t?s=t:(s.msg=t,s.spinner=i),s.msg||0===s.msg||(s.msg=""),w2utils.unlock(e),$(e).prepend('<div class="w2ui-lock"></div><div class="w2ui-lock-msg"></div>');var n=$(e).find(".w2ui-lock"),r=$(e).find(".w2ui-lock-msg");s.msg||r.css({"background-color":"transparent",border:"0px"}),s.spinner===!0&&(s.msg='<div class="w2ui-spinner" '+(s.msg?"":'style="width: 35px; height: 35px"')+"></div>"+s.msg),null!=s.opacity&&n.css("opacity",s.opacity),"function"==typeof n.fadeIn?(n.fadeIn(200),r.html(s.msg).fadeIn(200)):(n.show(),r.html(s.msg).show(0)),$().w2tag()}function _(t,i){e(i)?($(t).find(".w2ui-lock").fadeOut(i),setTimeout(function(){$(t).find(".w2ui-lock").remove(),$(t).find(".w2ui-lock-msg").remove()},i)):($(t).find(".w2ui-lock").remove(),$(t).find(".w2ui-lock-msg").remove())}function k(e,t){var i=$(e),s={left:parseInt(i.css("border-left-width"))||0,right:parseInt(i.css("border-right-width"))||0,top:parseInt(i.css("border-top-width"))||0,bottom:parseInt(i.css("border-bottom-width"))||0},n={left:parseInt(i.css("margin-left"))||0,right:parseInt(i.css("margin-right"))||0,top:parseInt(i.css("margin-top"))||0,bottom:parseInt(i.css("margin-bottom"))||0},r={left:parseInt(i.css("padding-left"))||0,right:parseInt(i.css("padding-right"))||0,top:parseInt(i.css("padding-top"))||0,bottom:parseInt(i.css("padding-bottom"))||0};switch(t){case"top":return s.top+n.top+r.top;case"bottom":return s.bottom+n.bottom+r.bottom;case"left":return s.left+n.left+r.left;case"right":return s.right+n.right+r.right;case"width":return s.left+s.right+n.left+n.right+r.left+r.right+parseInt(i.width());case"height":return s.top+s.bottom+n.top+n.bottom+r.top+r.bottom+parseInt(i.height());case"+width":return s.left+s.right+n.left+n.right+r.left+r.right;case"+height":return s.top+s.bottom+n.top+n.bottom+r.top+r.bottom}return 0}function C(e){var t=this.settings.phrases[e];return null==t?e:t}function T(e){e||(e="en-us"),5===e.length&&(e="locale/"+e+".json"),w2utils.settings.phrases={},$.ajax({url:e,type:"GET",dataType:"JSON",async:!1,cache:!1,success:function(e){w2utils.settings=$.extend(!0,w2utils.settings,e);var t=w2obj.grid.prototype;for(var i in t.buttons)t.buttons[i].caption=w2utils.lang(t.buttons[i].caption),t.buttons[i].hint=w2utils.lang(t.buttons[i].hint);t.msgDelete=w2utils.lang(t.msgDelete),t.msgNotJSON=w2utils.lang(t.msgNotJSON),t.msgRefresh=w2utils.lang(t.msgRefresh)},error:function(){console.log("ERROR: Cannot load locale "+e)}})}function S(){if(R.scrollBarSize)return R.scrollBarSize;var e='<div id="_scrollbar_width" style="position: absolute; top: -300px; width: 100px; height: 100px; overflow-y: scroll;">    <div style="height: 120px">1</div></div>';return $("body").append(e),R.scrollBarSize=100-$("#_scrollbar_width > div").width(),$("#_scrollbar_width").remove(),String(navigator.userAgent).indexOf("MSIE")>=0&&(R.scrollBarSize=R.scrollBarSize/2),R.scrollBarSize}function z(e,t){return e&&"undefined"!=typeof e.name?"undefined"!=typeof w2ui[e.name]?(console.log('ERROR: The parameter "name" is not unique. There are other objects already created with the same name (obj: '+e.name+")."),!1):w2utils.isAlphaNumeric(e.name)?!0:(console.log('ERROR: The parameter "name" has to be alpha-numeric (a-z, 0-9, dash and underscore). '),!1):(console.log('ERROR: The parameter "name" is required but not supplied in $().'+t+"()."),!1)}function D(e,t,i,s){$.isArray(t)||(t=[t]);for(var n=0;n<t.length;n++)if(t[n].id===e)return console.log('ERROR: The parameter "id='+e+'" is not unique within the current '+i+". (obj: "+s+")"),!1;return!0}function O(e){var t=[],i=e.replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(e,i,s,n,r,a){return t.push({name:n,optional:!!a}),i=i||"",""+(a?"":i)+"(?:"+(a?i:"")+(s||"")+(r||s&&"([^/.]+?)"||"([^/]+?)")+")"+(a||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)");return{path:new RegExp("^"+i+"$","i"),keys:t}}function I(e,t,i){var s={},n={},r="";$.isPlainObject(e)?(s=e,t===!0&&(i=!0)):s[e]=t;for(var a in s)n[a]=s[a],n["-webkit-"+a]=s[a],n["-moz-"+a]=s[a].replace("-webkit-","-moz-"),n["-ms-"+a]=s[a].replace("-webkit-","-ms-"),n["-o-"+a]=s[a].replace("-webkit-","-o-");if(i===!0)for(var a in n)r+=a+": "+n[a]+"; ";else r=n;return r}var R={},j={version:"1.5.x",settings:{locale:"en-us",date_format:"m/d/yyyy",date_display:"Mon d, yyyy",time_format:"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:"HTTP",phrases:{}},isInt:e,isFloat:t,isMoney:i,isHex:s,isAlphaNumeric:n,isEmail:r,isDate:a,isTime:o,age:l,date:d,formatSize:h,formatNumber:u,formatDate:c,formatTime:p,formatDateTime:f,stripTags:g,encodeTags:m,escapeId:v,base64encode:w,base64decode:y,transition:b,lock:x,unlock:_,lang:C,locale:T,getSize:k,scrollBarSize:S,checkName:z,checkUniqueId:D,parseRoute:O,cssPrefix:I,isIOS:-1!=navigator.userAgent.toLowerCase().indexOf("iphone")||-1!=navigator.userAgent.toLowerCase().indexOf("ipod")||-1!=navigator.userAgent.toLowerCase().indexOf("ipad")?!0:!1,isIE:-1!=navigator.userAgent.toLowerCase().indexOf("msie")||-1!=navigator.userAgent.toLowerCase().indexOf("trident")?!0:!1};return j}();w2utils.event={on:function(e,t){return $.isPlainObject(e)||(e={type:e}),e=$.extend({type:null,execute:"before",target:null,onComplete:null},e),e.type?t?($.isArray(this.handlers)||(this.handlers=[]),void this.handlers.push({event:e,handler:t})):void console.log("ERROR: You must specify event handler function when calling .on() method of "+this.name):void console.log("ERROR: You must specify event type when calling .on() method of "+this.name)},off:function(e,t){if($.isPlainObject(e)||(e={type:e}),e=$.extend({},{type:null,execute:"before",target:null,onComplete:null},e),!e.type)return void console.log("ERROR: You must specify event type when calling .off() method of "+this.name);t||(t=null);for(var i=[],s=0,n=this.handlers.length;n>s;s++){var r=this.handlers[s];(r.event.type!==e.type&&"*"!==e.type||r.event.target!==e.target&&null!==e.target||r.handler!==t&&null!==t)&&i.push(r)}this.handlers=i},trigger:function(e){var e=$.extend({type:null,phase:"before",target:null},e,{isStopped:!1,isCancelled:!1,preventDefault:function(){this.isCancelled=!0},stopPropagation:function(){this.isStopped=!0}});"before"===e.phase&&(e.onComplete=null);var t,i,s;null==e.target&&(e.target=null),$.isArray(this.handlers)||(this.handlers=[]);for(var n=this.handlers.length-1;n>=0;n--){var r=this.handlers[n];if(!(r.event.type!==e.type&&"*"!==r.event.type||r.event.target!==e.target&&null!==r.event.target||r.event.execute!==e.phase&&"*"!==r.event.execute&&"*"!==r.event.phase)&&(e=$.extend({},r.event,e),t=[],s=new RegExp(/\((.*?)\)/).exec(r.handler),s&&(t=s[1].split(/\s*,\s*/)),2===t.length?r.handler.call(this,e.target,e):r.handler.call(this,e),e.isStopped===!0||e.stop===!0))return e}var a="on"+e.type.substr(0,1).toUpperCase()+e.type.substr(1);return"before"===e.phase&&"function"==typeof this[a]&&(i=this[a],t=[],s=new RegExp(/\((.*?)\)/).exec(i),s&&(t=s[1].split(/\s*,\s*/)),2===t.length?i.call(this,e.target,e):i.call(this,e),e.isStopped===!0||e.stop===!0)?e:null!=e.object&&"before"===e.phase&&"function"==typeof e.object[a]&&(i=e.object[a],t=[],s=new RegExp(/\((.*?)\)/).exec(i),s&&(t=s[1].split(/\s*,\s*/)),2===t.length?i.call(this,e.target,e):i.call(this,e),e.isStopped===!0||e.stop===!0)?e:("after"===e.phase&&"function"==typeof e.onComplete&&e.onComplete.call(this,e),e)}},w2utils.keyboard=function(e){function t(){$(document).on("keydown",i),$(document).on("mousedown",s)}function i(e){var t=e.target.tagName;-1===$.inArray(t,["INPUT","SELECT","TEXTAREA"])&&"true"!==$(e.target).prop("contenteditable")&&a&&w2ui[a]&&"function"==typeof w2ui[a].keydown&&w2ui[a].keydown.call(w2ui[a],e)}function s(e){var t=(e.target.tagName,$(e.target).parents(".w2ui-grid, .w2ui-sidebar, .w2ui-popup"));if(t.length>0){var i=t.attr("name"),s=w2ui[i];if(i!=a){if(r(e)===!1)return;if(n(i,e)===!1)return}s&&s.keyboard&&(a=i)}else r(e)}function n(e,t){if(null==e)return a;var i=w2ui[e];return i&&i.focus&&i.focus.call(i,t)===!1?!1:(a=e,!0)}function r(e){return null!=a&&w2ui[a].blur&&w2ui[a].blur.call(w2ui[a],e)===!1?!1:(a=null,!0)}var a=null;return e.active=n,e.clear=r,t(),e}({}),function(){$.fn.w2render=function(e){$(this).length>0&&("string"==typeof e&&w2ui[e]&&w2ui[e].render($(this)[0]),"object"==typeof e&&e.render($(this)[0]))},$.fn.w2destroy=function(e){!e&&this.length>0&&(e=this.attr("name")),"string"==typeof e&&w2ui[e]&&w2ui[e].destroy(),"object"==typeof e&&e.destroy()},$.fn.w2marker=function(){var e=Array.prototype.slice.call(arguments,0);return $(this).each(0!=e.length&&e[0]?function(t,i){function s(e){return'<span class="w2ui-marker">'+e+"</span>"}i.innerHTML=i.innerHTML.replace(/\<span class=\"w2ui\-marker\"\>(.*)\<\/span\>/gi,"$1");for(var n=0;n<e.length;n++){var r=e[n];"string"!=typeof r&&(r=String(r)),r=r.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&").replace(/&/g,"&").replace(/</g,"&gt;").replace(/>/g,"&lt;");var a=new RegExp(r+"(?!([^<]+)?>)","gi");i.innerHTML=i.innerHTML.replace(a,s)}}:function(e,t){t.innerHTML=t.innerHTML.replace(/\<span class=\"w2ui\-marker\"\>(.*)\<\/span\>/gi,"$1")})},$.fn.w2tag=function(e,t){return $.isPlainObject(t)||(t={}),$.isPlainObject(t.css)||(t.css={}),"undefined"==typeof t["class"]&&(t["class"]=""),0===$(this).length?void $(".w2ui-tag").each(function(e,t){var i=$(t).data("options");null==i&&(i={}),$($(t).data("taged-el")).removeClass(i["class"]),clearInterval($(t).data("timer")),$(t).remove()}):$(this).each(function(i,s){function n(){$tag=$("#w2ui-tag-"+a),$tag.length<=0||(clearInterval($tag.data("timer")),$tag.remove(),$(s).off("keypress",n).removeClass(t["class"]),$(s).length>0&&($(s)[0].style.cssText=l),"function"==typeof t.onHide&&t.onHide())}var r=t.id?t.id:s.id,a=w2utils.escapeId(r);if(""===e||null==e)$("#w2ui-tag-"+a).css("opacity",0),clearInterval($("#w2ui-tag-"+a).data("timer")),$("#w2ui-tag-"+a).remove();else{clearInterval($("#w2ui-tag-"+a).data("timer")),$("#w2ui-tag-"+a).remove(),$("body").append('<div id="w2ui-tag-'+r+'" class="w2ui-tag '+($(s).parents(".w2ui-popup").length>0?"w2ui-tag-popup":"")+'" style=""></div>');var o=setInterval(function(){return 0===$(s).length||0===$(s).offset().left&&0===$(s).offset().top?(clearInterval($("#w2ui-tag-"+a).data("timer")),void n()):void($("#w2ui-tag-"+a).data("position")!==$(s).offset().left+s.offsetWidth+"x"+$(s).offset().top&&$("#w2ui-tag-"+a).css(w2utils.cssPrefix({transition:".2s"})).css({left:$(s).offset().left+s.offsetWidth+(t.left?t.left:0)+"px",top:$(s).offset().top+(t.top?t.top:0)+"px"}).data("position",$(s).offset().left+s.offsetWidth+"x"+$(s).offset().top))},100);setTimeout(function(){$(s).offset()&&($("#w2ui-tag-"+a).css({opacity:"1",left:$(s).offset().left+s.offsetWidth+(t.left?t.left:0)+"px",top:$(s).offset().top+(t.top?t.top:0)+"px"}).html('<div style="margin-top: -2px 0px 0px -2px; white-space: nowrap;"> <div class="w2ui-tag-body">'+e+"</div> </div>").data("text",e).data("taged-el",s).data("options",t).data("position",$(s).offset().left+s.offsetWidth+"x"+$(s).offset().top).data("timer",o),$(s).off("keypress",n).on("keypress",n).off("change",n).on("change",n).css(t.css).addClass(t["class"]),"function"==typeof t.onShow&&t.onShow())},1);var l="";$(s).length>0&&(l=$(s)[0].style.cssText)}})},$.fn.w2overlay=function(e,t){function i(){var e=$("#w2ui-overlay"+a);if(e.data("element")===r[0]&&0!==e.length){var t=$(r).offset().left+"x"+$(r).offset().top;e.data("position")!==t?s():setTimeout(i,250)}}function s(){var e=$("#w2ui-overlay"+a);if(e.data("keepOpen")===!0)return void e.removeData("keepOpen");var i;"function"==typeof t.onHide&&(i=t.onHide()),i!==!1&&(e.remove(),$(document).off("click",s),clearInterval(e.data("timer")))}function n(){var e=$("#w2ui-overlay"+a),i=e.find(" > div");if(e.length>0){i.height("auto").width("auto");var s=!1,o=!1,l=i.height(),d=i.width();switch(t.width&&t.width<d&&(d=t.width),30>d&&(d=30),t.tmp.contentHeight&&(l=parseInt(t.tmp.contentHeight),i.height(l),setTimeout(function(){l>i.find("div.menu > table").height()&&i.find("div.menu").css("overflow-y","hidden")},1),setTimeout(function(){i.find("div.menu").css("overflow-y","auto")},10)),t.tmp.contentWidth&&(d=parseInt(t.tmp.contentWidth),i.width(d),setTimeout(function(){d>i.find("div.menu > table").width()&&i.find("div.menu").css("overflow-x","hidden")},1),setTimeout(function(){i.find("div.menu").css("overflow-x","auto")},10)),t.align){case"both":t.left=17,0===t.width&&(t.width=w2utils.getSize($(r),"width"));break;case"left":t.left=17;break;case"right":t.tipLeft=d-45,t.left=w2utils.getSize($(r),"width")-d+10}var h=(d-17)/2,u=t.left,c=t.width,p=t.tipLeft;c=30!==d||c?t.width?t.width:"auto":30,25>h&&(u=25-h,p=Math.floor(h)),e.css({top:r.offset().top+w2utils.getSize(r,"height")+t.top+7+"px",left:(r.offset().left>25?r.offset().left:25)+u+"px","min-width":c,"min-height":t.height?t.height:"auto"});var f=window.innerHeight+$(document).scrollTop()-i.offset().top-7,g=window.innerWidth+$(document).scrollLeft()-i.offset().left-7;f>-50&&210>f||t.openAbove===!0?(f=i.offset().top-$(document).scrollTop()-7,t.maxHeight&&f>t.maxHeight&&(f=t.maxHeight),l>f&&(o=!0,i.height(f).width(d).css({"overflow-y":"auto"}),l=f),e.css("top",$(r).offset().top-l-24+t.top+"px"),e.find(">style").html("#w2ui-overlay"+a+":before { display: none; margin-left: "+parseInt(p)+"px; }#w2ui-overlay"+a+":after { display: block; margin-left: "+parseInt(p)+"px; }")):(t.maxHeight&&f>t.maxHeight&&(f=t.maxHeight),l>f&&(o=!0,i.height(f).width(d).css({"overflow-y":"auto"})),e.find(">style").html("#w2ui-overlay"+a+":before { display: block; margin-left: "+parseInt(p)+"px; }#w2ui-overlay"+a+":after { display: none; margin-left: "+parseInt(p)+"px; }")),d=i.width(),g=window.innerWidth+$(document).scrollLeft()-i.offset().left-7,t.maxWidth&&g>t.maxWidth&&(g=t.maxWidth),d>g&&"both"!==t.align&&(t.align="right",setTimeout(function(){n()},1)),o&&s&&i.width(d+w2utils.scrollBarSize()+2)}}var r=this,a="",o={name:null,html:"",align:"none",left:0,top:0,tipLeft:30,width:0,height:0,maxWidth:null,maxHeight:null,style:"","class":"",onShow:null,onHide:null,openAbove:!1,tmp:{}};1==arguments.length&&(t="object"==typeof e?e:{html:e}),2==arguments.length&&(t.html=e),$.isPlainObject(t)||(t={}),t=$.extend({},o,t),t.name&&(a="-"+t.name);var l;if(0===this.length||""===t.html||null==t.html)return $("#w2ui-overlay"+a).length>0?(l=$("#w2ui-overlay"+a)[0].hide,"function"==typeof l&&l()):$("#w2ui-overlay"+a).remove(),$(this);$("#w2ui-overlay"+a).length>0&&(l=$("#w2ui-overlay"+a)[0].hide,$(document).off("click",l),"function"==typeof l&&l()),$("body").append('<div id="w2ui-overlay'+a+'" style="display: none"        class="w2ui-reset w2ui-overlay '+($(this).parents(".w2ui-popup, .w2ui-overlay-popup").length>0?"w2ui-overlay-popup":"")+'">    <style></style>    <div style="'+t.style+'" class="'+t["class"]+'"></div></div>');var d=$("#w2ui-overlay"+a),h=d.find(" > div");h.html(t.html);var u=h.css("background-color");return null!=u&&"rgba(0, 0, 0, 0)"!==u&&"transparent"!==u&&d.css("background-color",u),d.data("element",r.length>0?r[0]:null).data("options",t).data("position",$(r).offset().left+"x"+$(r).offset().top).fadeIn("fast").on("click",function(e){"LABEL"==e.target.tagName&&e.stopPropagation()}).on("mousedown",function(e){$("#w2ui-overlay"+a).data("keepOpen",!0),-1==["INPUT","TEXTAREA","SELECT"].indexOf(e.target.tagName)&&e.preventDefault()}),d[0].hide=s,d[0].resize=n,n(),setTimeout(function(){n(),$(document).off("click",s).on("click",s),"function"==typeof t.onShow&&t.onShow()},10),i(),$(this)},$.fn.w2menu=function(e,t){function i(){setTimeout(function(){$("#w2ui-overlay"+o+" tr.w2ui-selected").removeClass("w2ui-selected");var e=$("#w2ui-overlay"+o+" tr[index="+t.index+"]"),i=$("#w2ui-overlay"+o+" div.menu").scrollTop();if(e.addClass("w2ui-selected"),t.tmp&&(t.tmp.contentHeight=$("#w2ui-overlay"+o+" table").height()+(t.search?50:10)),t.tmp&&(t.tmp.contentWidth=$("#w2ui-overlay"+o+" table").width()),$("#w2ui-overlay"+o).length>0&&$("#w2ui-overlay"+o)[0].resize(),e.length>0){var s=e[0].offsetTop-5,n=$("#w2ui-overlay"+o+" div.menu"),r=n.height();$("#w2ui-overlay"+o+" div.menu").scrollTop(i),(i>s||s+e.height()>i+r)&&$("#w2ui-overlay"+o+" div.menu").animate({scrollTop:s-(r-2*e.height())/2},200,"linear")}},1)}function s(e){var s=this.value,n=e.keyCode,r=!1;switch(n){case 13:$("#w2ui-overlay"+o).remove(),$.fn.w2menuHandler(e,t.index);break;case 9:case 27:$("#w2ui-overlay"+o).remove(),$.fn.w2menuHandler(e,-1);break;case 38:for(t.index=w2utils.isInt(t.index)?parseInt(t.index):0,t.index--;t.index>0&&t.items[t.index].hidden;)t.index--;if(0===t.index&&t.items[t.index].hidden)for(;t.items[t.index]&&t.items[t.index].hidden;)t.index++;t.index<0&&(t.index=0),r=!0;break;case 40:for(t.index=w2utils.isInt(t.index)?parseInt(t.index):0,t.index++;t.index<t.items.length-1&&t.items[t.index].hidden;)t.index++;if(t.index===t.items.length-1&&t.items[t.index].hidden)for(;t.items[t.index]&&t.items[t.index].hidden;)t.index--;t.index>=t.items.length&&(t.index=t.items.length-1),r=!0
  }if(!r){for(var l=0,d=0;d<t.items.length;d++){var h=t.items[d],u="",c="";-1!==["is","begins with"].indexOf(t.match)&&(u="^"),-1!==["is","ends with"].indexOf(t.match)&&(c="$");try{var p=new RegExp(u+s+c,"i");h.hidden=p.test(h.text)||"..."===h.text?!1:!0}catch(f){}"enum"===a.type&&-1!==$.inArray(h.id,ids)&&(h.hidden=!0),h.hidden!==!0&&l++}for(t.index=0;t.index<t.items.length-1&&t.items[t.index].hidden;)t.index++;0>=l&&(t.index=-1)}$(a).w2menu("refresh",t),i()}function n(){if(t.spinner)return'<table class="w2ui-drop-menu"><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></table>";for(var e=0,i='<table cellspacing="0" cellpadding="0" class="w2ui-drop-menu">',s=null,n=null,r=0;r<t.items.length;r++){var a=t.items[r];if("string"==typeof a?a={id:a,text:a}:(null!=a.text&&null==a.id&&(a.id=a.text),null==a.text&&null!=a.id&&(a.text=a.id),null!=a.caption&&(a.text=a.caption),s=a.img,n=a.icon,null==s&&(s=null),null==n&&(n=null)),a.hidden!==!0){var l="",d=a.text;if("function"==typeof t.render&&(d=t.render(a,t)),s&&(l='<td class="menu-icon"><div class="w2ui-tb-image w2ui-icon '+s+'"></div></td>'),n&&(l='<td class="menu-icon" align="center"><span class="w2ui-icon '+n+'"></span></td>'),"undefined"==typeof d||""===d||/^-+$/.test(d))i+='<tr><td colspan="2" style="padding: 6px; pointer-events: none"><div style="border-top: 1px solid silver;"></div></td></tr>';else{var h=e%2===0?"w2ui-item-even":"w2ui-item-odd";t.altRows!==!0&&(h="");var u=1;""==l&&u++,null==a.count&&u++,i+='<tr index="'+r+'" style="'+(a.style?a.style:"")+'" '+(a.hint?'title="'+a.hint+'"':"")+'        class="'+h+" "+(t.index===r?"w2ui-selected":"")+" "+(a.disabled===!0?"w2ui-disabled":"")+"\"        onmousedown=\"$(this).parent().find('tr').removeClass('w2ui-selected'); $(this).addClass('w2ui-selected');\"        onclick=\"event.stopPropagation();                if ("+(a.disabled===!0?"true":"false")+") return;               $('#w2ui-overlay"+o+"').remove();                $.fn.w2menuHandler(event, '"+r+"');\">"+l+'   <td class="menu-text" colspan="'+u+'">'+d+'</td>   <td class="menu-count">'+(null!=a.count?"<span>"+a.count+"</span>":"")+"</td></tr>",e++}}t.items[r]=a}return 0===e&&(i+='<tr><td style="padding: 13px; color: #999; text-align: center">'+t.msgNoItems+"</div></td></tr>"),i+="</table>"}var r={index:null,items:[],render:null,msgNoItems:"No items",onSelect:null,tmp:{}},a=this,o="";if("refresh"!==e){if("refresh-index"===e){var l=$("#w2ui-overlay"+o+" div.menu"),d=l.find("tr[index="+t.index+"]"),h=l.scrollTop();if(l.find("tr.w2ui-selected").removeClass("w2ui-selected"),d.addClass("w2ui-selected"),d.length>0){var u=d[0].offsetTop-5,c=l.height();l.scrollTop(h),(h>u||u+d.height()>h+c)&&l.animate({scrollTop:u-(c-2*d.height())/2},200,"linear")}return}1===arguments.length?t=e:t.items=e,"object"!=typeof t&&(t={}),t=$.extend({},r,t),$.fn.w2menuOptions=t,t.name&&(o="-"+t.name),"function"==typeof t.select&&"function"!=typeof t.onSelect&&(t.onSelect=t.select),"function"==typeof t.onRender&&"function"!=typeof t.render&&(t.render=t.onRender),$.fn.w2menuHandler=function(e,i){"function"==typeof t.onSelect&&setTimeout(function(){t.onSelect({index:i,item:t.items[i],originalEvent:e})},10)};var p="";if(t.search){p+='<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>',t.style+=";background-color: #ECECEC",t.index=0;for(var f=0;f<t.items.length;f++)t.items[f].hidden=!1}p+='<div class="menu" style="position: absolute; top: '+(t.search?40:0)+'px; bottom: 0px; width: 100%; overflow: auto;">'+n()+"</div>";var g=$(this).w2overlay(p,t);return setTimeout(function(){if($("#w2ui-overlay"+o+" #menu-search").on("keyup",s).on("keydown",function(e){9===e.keyCode&&(e.stopPropagation(),e.preventDefault())}),t.search){if(-1!=["text","password"].indexOf($(a)[0].type)||"texarea"==$(a)[0].tagName)return;$("#w2ui-overlay"+o+" #menu-search").focus()}},200),i(),g}if($("#w2ui-overlay"+o).length>0){t=$.extend($.fn.w2menuOptions,t);var h=$("#w2ui-overlay"+o+" div.menu").scrollTop();$("#w2ui-overlay"+o+" div.menu").html(n()),$("#w2ui-overlay"+o+" div.menu").scrollTop(h),setTimeout(function(){i()},1)}else $(this).w2menu(t)}}(),function(){var w2grid=function(e){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.toolbar={},this.show={header:!1,toolbar:!1,footer:!1,columnHeaders:!0,lineNumbers:!1,expandColumn:!1,selectColumn:!1,selectColumn_All:!0,emptyRecords:!0,toolbarReload:!0,toolbarColumns:!0,toolbarSearch:!0,toolbarAdd:!1,toolbarEdit:!1,toolbarDelete:!1,toolbarSave:!1,statusRange:!0,statusBuffered:!1,statusRecordID:!0,statusSelection:!0,statusResponse:!0,statusSort:!0,statusSearch:!0,recordTitles:!0,selectionBorder:!0,skipRecords:!0},this.autoLoad=!0,this.fixedBody=!0,this.recordHeight=24,this.vs_start=300,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.total=0,this.limit=100,this.offset=0,this.style="",this.ranges=[],this.menu=[],this.method=null,this.recid=null,this.parser=null,this.onAdd=null,this.onEdit=null,this.onRequest=null,this.onLoad=null,this.onDelete=null,this.onDeleted=null,this.onSubmit=null,this.onSave=null,this.onSelect=null,this.onUnselect=null,this.onClick=null,this.onDblClick=null,this.onContextMenu=null,this.onMenuClick=null,this.onColumnClick=null,this.onColumnResize=null,this.onSort=null,this.onSearch=null,this.onChange=null,this.onRestore=null,this.onExpand=null,this.onCollapse=null,this.onError=null,this.onKeydown=null,this.onToolbar=null,this.onColumnOnOff=null,this.onCopy=null,this.onPaste=null,this.onSelectionExtend=null,this.onEditField=null,this.onRender=null,this.onRefresh=null,this.onReload=null,this.onResize=null,this.onDestroy=null,this.onStateSave=null,this.onStateRestore=null,this.onFocus=null,this.onBlur=null,this.last={field:"all",caption:w2utils.lang("All Fields"),logic:"OR",search:"",searchIds:[],selection:{indexes:[],columns:{}},multi:!1,scrollTop:0,scrollLeft: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},$.extend(!0,this,w2obj.grid,e)};$.fn.w2grid=function(e){if($.isPlainObject(e)){if(!w2utils.checkName(e,"w2grid"))return;var t=e.columns,i=e.columnGroups,s=e.records,n=e.searches,r=e.searchData,a=e.sortData,o=e.postData,l=e.toolbar,d=new w2grid(e);if($.extend(d,{postData:{},records:[],columns:[],searches:[],toolbar:{},sortData:[],searchData:[],handlers:[]}),null!=d.onExpand&&(d.show.expandColumn=!0),$.extend(!0,d.toolbar,l),t)for(var h=0;h<t.length;h++)d.columns[h]=$.extend(!0,{},t[h]);if(i)for(var h=0;h<i.length;h++)d.columnGroups[h]=$.extend(!0,{},i[h]);if(n)for(var h=0;h<n.length;h++)d.searches[h]=$.extend(!0,{},n[h]);if(r)for(var h=0;h<r.length;h++)d.searchData[h]=$.extend(!0,{},r[h]);if(a)for(var h=0;h<a.length;h++)d.sortData[h]=$.extend(!0,{},a[h]);if(d.postData=$.extend(!0,{},o),s)for(var u=0;u<s.length;u++){if(null==s[u].recid||"undefined"==typeof s[u].recid)return void console.log("ERROR: Cannot add records without recid. (obj: "+d.name+")");d.records[u]=$.extend(!0,{},s[u])}for(var c in d.columns){var p=d.columns[c];if("undefined"!=typeof p.searchable&&null==d.getSearch(p.field)){var f=p.searchable,g="";p.searchable===!0&&(f="text",g='size="20"'),d.addSearch({field:p.field,caption:p.caption,type:f,attr:g})}}return d.initToolbar(),0!==$(this).length&&d.render($(this)[0]),w2ui[d.name]=d,d}var m=w2ui[$(this).attr("name")];return m?arguments.length>0?(m[e]&&m[e].apply(m,Array.prototype.slice.call(arguments,1)),this):m:null},w2grid.prototype={msgDelete:w2utils.lang("Are you sure you want to delete selected records?"),msgNotJSON:w2utils.lang("Returned data is not in valid JSON format."),msgAJAXerror:w2utils.lang("AJAX error. See console for more details."),msgRefresh:w2utils.lang("Refreshing..."),msgNeedReload:w2utils.lang("Your remove data source record count has changed, reloading from the first record."),buttons:{reload:{type:"button",id:"w2ui-reload",icon:"w2ui-icon-reload",hint:w2utils.lang("Reload data in the list")},columns:{type:"drop",id:"w2ui-column-on-off",icon:"w2ui-icon-columns",hint:w2utils.lang("Show/hide columns"),arrow:!1,html:""},search:{type:"html",id:"w2ui-search",html:'<div class="w2ui-icon icon-search-down w2ui-search-down" title="'+w2utils.lang("Select Search Field")+"\" onclick=\"var obj = w2ui[$(this).parents('div.w2ui-grid').attr('name')]; obj.searchShowFields();\"></div>"},"search-go":{type:"drop",id:"w2ui-search-advanced",icon:"w2ui-icon-search",caption:w2utils.lang("Search"),hint:w2utils.lang("Open Search Fields")},add:{type:"button",id:"w2ui-add",caption:w2utils.lang("Add New"),hint:w2utils.lang("Add new record"),icon:"w2ui-icon-plus"},edit:{type:"button",id:"w2ui-edit",caption:w2utils.lang("Edit"),hint:w2utils.lang("Edit selected record"),icon:"w2ui-icon-pencil",disabled:!0},"delete":{type:"button",id:"w2ui-delete",caption:w2utils.lang("Delete"),hint:w2utils.lang("Delete selected records"),icon:"w2ui-icon-cross",disabled:!0},save:{type:"button",id:"w2ui-save",caption:w2utils.lang("Save"),hint:w2utils.lang("Save changed records"),icon:"w2ui-icon-check"}},add:function(e){$.isArray(e)||(e=[e]);var t=0;for(var i in e)this.recid&&"undefined"==typeof e[i].recid&&(e[i].recid=e[i][this.recid]),null!=e[i].recid&&"undefined"!=typeof e[i].recid?(this.records.push(e[i]),t++):console.log("ERROR: Cannot add record without recid. (obj: "+this.name+")");var s="object"!=typeof this.url?this.url:this.url.get;return s||(this.total=this.records.length,this.localSort(),this.localSearch()),this.refresh(),t},find:function(e,t){("undefined"==typeof e||null==e)&&(e={});var i=[],s=!1;for(var n in e)-1!=String(n).indexOf(".")&&(s=!0);for(var r=0;r<this.records.length;r++){var a=!0;for(var n in e){var o=this.records[r][n];s&&-1!=String(n).indexOf(".")&&(o=this.parseField(this.records[r],n)),e[n]!=o&&(a=!1)}a&&t!==!0&&i.push(this.records[r].recid),a&&t===!0&&i.push(r)}return i},set:function(e,t,i){if("object"==typeof e&&(i=t,t=e,e=null),null==e){for(var s in this.records)$.extend(!0,this.records[s],t);i!==!0&&this.refresh()}else{var n=this.get(e,!0);if(null==n)return!1;var r=this.records[n]&&this.records[n].recid==e?!1:!0;r?$.extend(!0,this.summary[n],t):$.extend(!0,this.records[n],t),i!==!0&&this.refreshRow(e)}return!0},get:function(e,t){for(var i=0;i<this.records.length;i++)if(this.records[i].recid==e)return t===!0?i:this.records[i];for(var i=0;i<this.summary.length;i++)if(this.summary[i].recid==e)return t===!0?i:this.summary[i];return null},remove:function(){for(var e=0,t=0;t<arguments.length;t++){for(var i=this.records.length-1;i>=0;i--)this.records[i].recid==arguments[t]&&(this.records.splice(i,1),e++);for(var i=this.summary.length-1;i>=0;i--)this.summary[i].recid==arguments[t]&&(this.summary.splice(i,1),e++)}var s="object"!=typeof this.url?this.url:this.url.get;return s||(this.localSort(),this.localSearch()),this.refresh(),e},addColumn:function(e,t){var i=0;1==arguments.length?(t=e,e=this.columns.length):("string"==typeof e&&(e=this.getColumn(e,!0)),null===e&&(e=this.columns.length)),$.isArray(t)||(t=[t]);for(var s in t){if(this.columns.splice(e,0,t[s]),t[s].searchable){var n=t[s].searchable,r="";t[s].searchable===!0&&(n="text",r='size="20"'),this.addSearch({field:t[s].field,caption:t[s].caption,type:n,attr:r})}e++,i++}return this.refresh(),i},removeColumn:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.columns.length-1;i>=0;i--)this.columns[i].field==arguments[t]&&(this.columns[i].searchable&&this.removeSearch(arguments[t]),this.columns.splice(i,1),e++);return this.refresh(),e},getColumn:function(e,t){for(var i=0;i<this.columns.length;i++)if(this.columns[i].field==e)return t===!0?i:this.columns[i];return null},toggleColumn:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.columns.length-1;i>=0;i--){var s=this.columns[i];s.field==arguments[t]&&(s.hidden=!s.hidden,e++)}return this.refresh(),e},showColumn:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.columns.length-1;i>=0;i--){var s=this.columns[i];s.gridMinWidth&&delete s.gridMinWidth,s.field==arguments[t]&&s.hidden!==!1&&(s.hidden=!1,e++)}return this.refresh(),e},hideColumn:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.columns.length-1;i>=0;i--){var s=this.columns[i];s.field==arguments[t]&&s.hidden!==!0&&(s.hidden=!0,e++)}return this.refresh(),e},addSearch:function(e,t){var i=0;1==arguments.length?(t=e,e=this.searches.length):("string"==typeof e&&(e=this.getSearch(e,!0)),null===e&&(e=this.searches.length)),$.isArray(t)||(t=[t]);for(var s in t)this.searches.splice(e,0,t[s]),e++,i++;return this.searchClose(),i},removeSearch:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.searches.length-1;i>=0;i--)this.searches[i].field==arguments[t]&&(this.searches.splice(i,1),e++);return this.searchClose(),e},getSearch:function(e,t){for(var i=0;i<this.searches.length;i++)if(this.searches[i].field==e)return t===!0?i:this.searches[i];return null},toggleSearch:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.searches.length-1;i>=0;i--)this.searches[i].field==arguments[t]&&(this.searches[i].hidden=!this.searches[i].hidden,e++);return this.searchClose(),e},showSearch:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.searches.length-1;i>=0;i--)this.searches[i].field==arguments[t]&&this.searches[i].hidden!==!1&&(this.searches[i].hidden=!1,e++);return this.searchClose(),e},hideSearch:function(){for(var e=0,t=0;t<arguments.length;t++)for(var i=this.searches.length-1;i>=0;i--)this.searches[i].field==arguments[t]&&this.searches[i].hidden!==!0&&(this.searches[i].hidden=!0,e++);return this.searchClose(),e},getSearchData:function(e){for(var t in this.searchData)if(this.searchData[t].field==e)return this.searchData[t];return null},localSort:function(e){var t="object"!=typeof this.url?this.url:this.url.get;if(t)return void console.log("ERROR: grid.localSort can only be used on local data source, grid.url should be empty.");if(!$.isEmptyObject(this.sortData)){var i=(new Date).getTime(),s=this;s.prepareData();for(var n in this.sortData){var r=this.getColumn(this.sortData[n].field);if(!r)return;"string"==typeof r.render&&(-1!=["date","age"].indexOf(r.render.split(":")[0])&&(this.sortData[n].field_=r.field+"_"),-1!=["time"].indexOf(r.render.split(":")[0])&&(this.sortData[n].field_=r.field+"_"))}return this.records.sort(function(e,t){var i=0;for(var n in s.sortData){var r=s.sortData[n].field;s.sortData[n].field_&&(r=s.sortData[n].field_);var a=e[r],o=t[r];if(-1!=String(r).indexOf(".")&&(a=s.parseField(e,r),o=s.parseField(t,r)),"string"==typeof a&&(a=$.trim(a.toLowerCase())),"string"==typeof o&&(o=$.trim(o.toLowerCase())),a>o&&(i="asc"==s.sortData[n].direction?1:-1),o>a&&(i="asc"==s.sortData[n].direction?-1:1),"object"!=typeof a&&"object"==typeof o&&(i=-1),"object"!=typeof o&&"object"==typeof a&&(i=1),null==a&&null!=o&&(i=1),null!=a&&null==o&&(i=-1),0!=i)break}return i}),i=(new Date).getTime()-i,e!==!0&&s.show.statusSort&&setTimeout(function(){s.status(w2utils.lang("Sorting took")+" "+i/1e3+" "+w2utils.lang("sec"))},10),i}},localSearch:function(e){var t="object"!=typeof this.url?this.url:this.url.get;if(t)return void console.log("ERROR: grid.localSearch can only be used on local data source, grid.url should be empty.");var i=(new Date).getTime(),s=this;if(this.total=this.records.length,this.last.searchIds=[],this.prepareData(),this.searchData.length>0&&!t){this.total=0;for(var n in this.records){var r=this.records[n],a=0;for(var o in this.searchData){var l=this.searchData[o],d=this.getSearch(l.field);if(null!=l){null==d&&(d={field:l.field,type:l.type});var h=String(s.parseField(r,d.field)).toLowerCase();if("undefined"!=typeof l.value)if($.isArray(l.value))var u=l.value[0],c=l.value[1];else var u=String(l.value).toLowerCase();switch(l.operator){case"is":if(r[d.field]==l.value&&a++,"date"==d.type){var p=r[d.field+"_"]instanceof Date?r[d.field+"_"]:r[d.field],h=w2utils.formatDate(p,"yyyy-mm-dd"),u=w2utils.formatDate(u,"yyyy-mm-dd");h==u&&a++}if("time"==d.type){var p=r[d.field+"_"]instanceof Date?r[d.field+"_"]:r[d.field],h=w2utils.formatTime(p,"h24:mi"),u=w2utils.formatTime(u,"h24:mi");h==u&&a++}break;case"between":if(-1!=["int","float","money","currency","percent"].indexOf(d.type)&&parseFloat(r[d.field])>=parseFloat(u)&&parseFloat(r[d.field])<=parseFloat(c)&&a++,"date"==d.type){var h=r[d.field+"_"]instanceof Date?r[d.field+"_"]:r[d.field],u=w2utils.isDate(u,w2utils.settings.date_format,!0),c=w2utils.isDate(c,w2utils.settings.date_format,!0);null!=c&&(c=new Date(c.getTime()+864e5)),h>=u&&c>h&&a++}if("time"==d.type){var h=r[d.field+"_"]instanceof Date?r[d.field+"_"]:r[d.field],u=w2utils.isTime(u,!0),c=w2utils.isTime(c,!0);u=(new Date).setHours(u.hours,u.minutes,u.seconds?u.seconds:0,0),c=(new Date).setHours(c.hours,c.minutes,c.seconds?c.seconds:0,0),h>=u&&c>h&&a++}break;case"in":var p=l.value;l.svalue&&(p=l.svalue),-1!==p.indexOf(w2utils.isFloat(h)?parseFloat(h):h)&&a++;break;case"not in":var p=l.value;l.svalue&&(p=l.svalue),-1==p.indexOf(w2utils.isFloat(h)?parseFloat(h):h)&&a++;break;case"begins":case"begins with":0==h.indexOf(u)&&a++;break;case"contains":h.indexOf(u)>=0&&a++;break;case"ends":case"ends with":h.indexOf(u)==h.length-u.length&&a++}}}("OR"==this.last.logic&&0!=a||"AND"==this.last.logic&&a==this.searchData.length)&&this.last.searchIds.push(parseInt(n))}this.total=this.last.searchIds.length}return i=(new Date).getTime()-i,e!==!0&&s.show.statusSearch&&setTimeout(function(){s.status(w2utils.lang("Search took")+" "+i/1e3+" "+w2utils.lang("sec"))},10),i},getRangeData:function(e,t){var i=this.get(e[0].recid,!0),s=this.get(e[1].recid,!0),n=e[0].column,r=e[1].column,a=[];if(n==r)for(var o=i;s>=o;o++){var l=this.records[o],d=l[this.columns[n].field]||null;a.push(t!==!0?d:{data:d,column:n,index:o,record:l})}else if(i==s)for(var l=this.records[i],h=n;r>=h;h++){var d=l[this.columns[h].field]||null;a.push(t!==!0?d:{data:d,column:h,index:i,record:l})}else for(var o=i;s>=o;o++){var l=this.records[o];a.push([]);for(var h=n;r>=h;h++){var d=l[this.columns[h].field];a[a.length-1].push(t!==!0?d:{data:d,column:h,index:o,record:l})}}return a},addRange:function(e){var t=0;if("row"==this.selectType)return t;$.isArray(e)||(e=[e]);for(var i in e){if("object"!=typeof e[i]&&(e[i]={name:"selection"}),"selection"==e[i].name){if(this.show.selectionBorder===!1)continue;var s=this.getSelection();if(0==s.length){this.removeRange(e[i].name);continue}{var n=s[0],r=s[s.length-1];$("#grid_"+this.name+"_rec_"+n.recid+" td[col="+n.column+"]"),$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]")}}else{var n=e[i].range[0],r=e[i].range[1];$("#grid_"+this.name+"_rec_"+n.recid+" td[col="+n.column+"]"),$("#grid_"+this.name+"_rec_"+r.recid+" td[col="+r.column+"]")}if(n){var a={name:e[i].name,range:[{recid:n.recid,column:n.column},{recid:r.recid,column:r.column}],style:e[i].style||""},o=!1;for(var l in this.ranges)if(this.ranges[l].name==e[i].name){o=i;break}o!==!1?this.ranges[o]=a:this.ranges.push(a),t++}}return this.refreshRanges(),t},removeRange:function(){for(var e=0,t=0;t<arguments.length;t++){var i=arguments[t];$("#grid_"+this.name+"_"+i).remove();for(var s=this.ranges.length-1;s>=0;s--)this.ranges[s].name==i&&(this.ranges.splice(s,1),e++)}return e},refreshRanges:function(){function e(e){var n=s.getSelection();s.last.move={type:"expand",x:e.screenX,y:e.screenY,divX:0,divY:0,recid:n[0].recid,column:n[0].column,originalRange:[{recid:n[0].recid,column:n[0].column},{recid:n[n.length-1].recid,column:n[n.length-1].column}],newRange:[{recid:n[0].recid,column:n[0].column},{recid:n[n.length-1].recid,column:n[n.length-1].column}]},$(document).off("mousemove",t).on("mousemove",t),$(document).off("mouseup",i).on("mouseup",i)}function t(e){var t=s.last.move;if(t&&"expand"==t.type){t.divX=e.screenX-t.x,t.divY=e.screenY-t.y;var i,n,r=e.originalEvent.target;if("TD"!=r.tagName&&(r=$(r).parents("td")[0]),"undefined"!=typeof $(r).attr("col")&&(n=parseInt($(r).attr("col"))),r=$(r).parents("tr")[0],i=$(r).attr("recid"),t.newRange[1].recid!=i||t.newRange[1].column!=n){var a=$.extend({},t.newRange);return t.newRange=[{recid:t.recid,column:t.column},{recid:i,column:n}],f=s.trigger($.extend(f,{originalRange:t.originalRange,newRange:t.newRange})),f.isCancelled===!0?(t.newRange=a,void(f.newRange=a)):(s.removeRange("grid-selection-expand"),void s.addRange({name:"grid-selection-expand",range:f.newRange,style:"background-color: rgba(100,100,100,0.1); border: 2px dotted rgba(100,100,100,0.5);"}))}}}function i(){s.removeRange("grid-selection-expand"),delete s.last.move,$(document).off("mousemove",t),$(document).off("mouseup",i),s.trigger($.extend(f,{phase:"after"}))}var s=this,n=(new Date).getTime(),r=$("#grid_"+this.name+"_records");for(var a in this.ranges){var o=this.ranges[a],l=o.range[0],d=o.range[1],h=$("#grid_"+this.name+"_rec_"+l.recid+" td[col="+l.column+"]"),u=$("#grid_"+this.name+"_rec_"+d.recid+" td[col="+d.column+"]"),c=$("#grid_"+this.name+"_rec_top").next().find("td.w2ui-selected"),p=$("#grid_"+this.name+"_rec_bottom").prev().find("td.w2ui-selected");0==$("#grid_"+this.name+"_"+o.name).length?r.append('<div id="grid_'+this.name+"_"+o.name+'" class="w2ui-selection" style="'+o.style+'">'+("selection"==o.name?'<div id="grid_'+this.name+'_resizer" class="w2ui-selection-resizer"></div>':"")+"</div>"):$("#grid_"+this.name+"_"+o.name).attr("style",o.style),(0==h.length&&0!=u.length||c.length>0)&&(h=$("#grid_"+this.name+"_rec_top").next().find("td[col="+l.column+"]")),(0==u.length&&0!=h.length||p.length>0)&&(u=$("#grid_"+this.name+"_rec_bottom").prev().find("td[col="+d.column+"]")),h.length>0&&u.length>0?$("#grid_"+this.name+"_"+o.name).show().css({left:h.position().left-1+r.scrollLeft()+"px",top:h.position().top-1+r.scrollTop()+"px",width:u.position().left-h.position().left+u.width()+3+"px",height:u.position().top-h.position().top+u.height()+3+"px"}):$("#grid_"+this.name+"_"+o.name).hide()}$(this.box).find("#grid_"+this.name+"_resizer").off("mousedown").on("mousedown",e);var f={phase:"before",type:"selectionExtend",target:s.name,originalRange:null,newRange:null};return(new Date).getTime()-n},select:function(){if(0==arguments.length)return 0;var e=((new Date).getTime(),0),t=this.last.selection;this.multiSelect||this.selectNone();var i={phase:"before",type:"select",target:this.name};1==arguments.length?(i.multiple=!1,$.isPlainObject(arguments[0])?(i.recid=arguments[0].recid,i.column=arguments[0].column):i.recid=arguments[0]):(i.multiple=!0,i.recids=Array.prototype.slice.call(arguments,0));var s=this.trigger(i);if(s.isCancelled===!0)return 0;if("row"==this.selectType)for(var n=0;n<arguments.length;n++){var r="object"==typeof arguments[n]?arguments[n].recid:arguments[n],a=this.get(r,!0);if(null!=a){var o=null;if((0!==this.searchData.length||a+1>=this.last.range_start&&a+1<=this.last.range_end)&&(o=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(r))),"row"==this.selectType){if(-1!=t.indexes.indexOf(a))continue;t.indexes.push(a),o&&(o.addClass("w2ui-selected").data("selected","yes").find(".w2ui-col-number").addClass("w2ui-row-selected"),o.find(".w2ui-grid-select-check").prop("checked",!0)),e++}}}else{for(var l={},n=0;n<arguments.length;n++){var r="object"==typeof arguments[n]?arguments[n].recid:arguments[n],d="object"==typeof arguments[n]?arguments[n].column:null;if(l[r]=l[r]||[],w2utils.isInt(d))l[r].push(d);else for(var h in this.columns)this.columns[h].hidden||l[r].push(parseInt(h))}var u=[];for(var r in l){var a=this.get(r,!0);if(null!=a){var o=null;a+1>=this.last.range_start&&a+1<=this.last.range_end&&(o=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(r)));var c=t.columns[a]||[];-1==t.indexes.indexOf(a)&&t.indexes.push(a);for(var p=0;p<l[r].length;p++)-1==c.indexOf(l[r][p])&&c.push(l[r][p]);c.sort(function(e,t){return e-t});for(var p=0;p<l[r].length;p++){var f=l[r][p];-1==u.indexOf(f)&&u.push(f),o&&(o.find("#grid_"+this.name+"_data_"+a+"_"+f).addClass("w2ui-selected"),o.find(".w2ui-col-number").addClass("w2ui-row-selected"),o.data("selected","yes"),o.find(".w2ui-grid-select-check").prop("checked",!0)),e++}t.columns[a]=c}}for(var h=0;h<u.length;h++)$(this.box).find("#grid_"+this.name+"_column_"+u[h]+" .w2ui-col-header").addClass("w2ui-col-selected")}return t.indexes.sort(function(e,t){return e-t}),t.indexes.length==this.records.length||0!==this.searchData.length&&t.indexes.length==this.last.searchIds.length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),this.trigger($.extend(s,{phase:"after"})),e},unselect:function(){for(var e=0,t=this.last.selection,i=0;i<arguments.length;i++){var s="object"==typeof arguments[i]?arguments[i].recid:arguments[i],n=this.get(s);if(null!=n){var r=this.get(n.recid,!0),a=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(s));if("row"==this.selectType){if(-1==t.indexes.indexOf(r))continue;var o=this.trigger({phase:"before",type:"unselect",target:this.name,recid:s,index:r});if(o.isCancelled===!0)continue;t.indexes.splice(t.indexes.indexOf(r),1),a.removeClass("w2ui-selected").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected"),0!=a.length&&(a[0].style.cssText="height: "+this.recordHeight+"px; "+a.attr("custom_style")),a.find(".w2ui-grid-select-check").prop("checked",!1),e++}else{var l=arguments[i].column;if(!w2utils.isInt(l)){var d=[];for(var h in this.columns)this.columns[h].hidden||d.push({recid:s,column:parseInt(h)});return this.unselect.apply(this,d)}var u=t.columns[r];if(!$.isArray(u)||-1==u.indexOf(l))continue;var o=this.trigger({phase:"before",type:"unselect",target:this.name,recid:s,column:l});if(o.isCancelled===!0)continue;u.splice(u.indexOf(l),1),$("#grid_"+this.name+"_rec_"+w2utils.escapeId(s)).find(" > td[col="+l+"]").removeClass("w2ui-selected");var c=!1,p=!1,f=this.getSelection();for(var g in f)f[g].column==l&&(c=!0),f[g].recid==s&&(p=!0);c||$(this.box).find(".w2ui-grid-columns td[col="+l+"] .w2ui-col-header").removeClass("w2ui-col-selected"),p||$("#grid_"+this.name+"_rec_"+w2utils.escapeId(s)).find(".w2ui-col-number").removeClass("w2ui-row-selected"),e++,0==u.length&&(delete t.columns[r],t.indexes.splice(t.indexes.indexOf(r),1),a.removeData("selected"),a.find(".w2ui-grid-select-check").prop("checked",!1))}this.trigger($.extend(o,{phase:"after"}))}}return t.indexes.length==this.records.length||0!==this.searchData.length&&t.indexes.length==this.last.searchIds.length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status(),this.addRange("selection"),e},selectAll:function(){var e=(new Date).getTime();if(this.multiSelect!==!1){var t=this.trigger({phase:"before",type:"select",target:this.name,all:!0});if(t.isCancelled!==!0){var i="object"!=typeof this.url?this.url:this.url.get,s=this.last.selection,n=[];for(var r in this.columns)n.push(parseInt(r));if(s.indexes=[],i||0===this.searchData.length){var a=this.records.length;0==this.searchData.length||this.url||(a=this.last.searchIds.length);for(var o=0;a>o;o++)s.indexes.push(o),"row"!=this.selectType&&(s.columns[o]=n.slice())}else for(var o=0;o<this.last.searchIds.length;o++)s.indexes.push(this.last.searchIds[o]),"row"!=this.selectType&&(s.columns[this.last.searchIds[o]]=n.slice());"row"==this.selectType?(console.log("fdddd"),$(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"),$(this.box).find("input.w2ui-grid-select-check").prop("checked",!0)):($(this.box).find(".w2ui-grid-columns td .w2ui-col-header").addClass("w2ui-col-selected"),$(this.box).find(".w2ui-grid-records tr .w2ui-col-number").addClass("w2ui-row-selected"),$(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"),$(this.box).find("input.w2ui-grid-select-check").prop("checked",!0));var s=this.getSelection();return 1==s.length?this.toolbar.enable("w2ui-edit"):this.toolbar.disable("w2ui-edit"),s.length>=1?this.toolbar.enable("w2ui-delete"):this.toolbar.disable("w2ui-delete"),this.addRange("selection"),$("#grid_"+this.name+"_check_all").prop("checked",!0),this.trigger($.extend(t,{phase:"after"})),(new Date).getTime()-e}}},selectNone:function(){var e=(new Date).getTime(),t=this.trigger({phase:"before",type:"unselect",target:this.name,all:!0});if(t.isCancelled!==!0){var i=this.last.selection;return"row"==this.selectType?($(this.box).find(".w2ui-grid-records tr.w2ui-selected").removeClass("w2ui-selected").removeData("selected").find(".w2ui-col-number").removeClass("w2ui-row-selected"),$(this.box).find("input.w2ui-grid-select-check").prop("checked",!1)):($(this.box).find(".w2ui-grid-columns td .w2ui-col-header").removeClass("w2ui-col-selected"),$(this.box).find(".w2ui-grid-records tr .w2ui-col-number").removeClass("w2ui-row-selected"),$(this.box).find(".w2ui-grid-data.w2ui-selected").removeClass("w2ui-selected").removeData("selected"),$(this.box).find("input.w2ui-grid-select-check").prop("checked",!1)),i.indexes=[],i.columns={},this.toolbar.disable("w2ui-edit","w2ui-delete"),this.removeRange("selection"),$("#grid_"+this.name+"_check_all").prop("checked",!1),this.trigger($.extend(t,{phase:"after"})),(new Date).getTime()-e}},getSelection:function(e){var t=[],i=this.last.selection;if("row"==this.selectType){for(var s in i.indexes)this.records[i.indexes[s]]&&t.push(e===!0?i.indexes[s]:this.records[i.indexes[s]].recid);return t}for(var s in i.indexes){var n=i.columns[i.indexes[s]];if(this.records[i.indexes[s]])for(var r in n)t.push({recid:this.records[i.indexes[s]].recid,index:parseInt(i.indexes[s]),column:n[r]})}return t},search:function(e,t){var i="object"!=typeof this.url?this.url:this.url.get,s=[],n=this.last.multi,r=this.last.logic,a=this.last.field,o=this.last.search;if(0==arguments.length){o="";for(var l in this.searches){var d=this.searches[l],h=$("#grid_"+this.name+"_operator_"+l).val(),u=$("#grid_"+this.name+"_field_"+l),c=$("#grid_"+this.name+"_field2_"+l),p=u.val(),f=c.val(),g=null;if(-1!=["int","float","money","currency","percent"].indexOf(d.type)){var m=u.data("w2field"),v=c.data("w2field");m&&(p=m.clean(p)),v&&(f=v.clean(f))}if(-1!=["list","enum"].indexOf(d.type)){if(p=u.data("selected")||{},$.isArray(p)){g=[];for(var w in p)g.push(w2utils.isFloat(p[w].id)?parseFloat(p[w].id):String(p[w].id).toLowerCase()),delete p[w].hidden}else p=p.id||"";$.isEmptyObject(p)&&(p="")}if(""!==p&&null!=p||"undefined"!=typeof f&&""!==f){var y={field:d.field,type:d.type,operator:h};"between"==h?$.extend(y,{value:[p,f]}):"in"==h&&"string"==typeof p?$.extend(y,{value:p.split(",")}):"not in"==h&&"string"==typeof p?$.extend(y,{value:p.split(",")}):$.extend(y,{value:p}),g&&$.extend(y,{svalue:g});try{"date"==d.type&&"between"==h&&(y.value[0]=p,y.value[1]=f),"date"==d.type&&"is"==h&&(y.value=p)}catch(b){}s.push(y)}}s.length>0&&!i?(n=!0,r="AND"):(n=!0,r="AND")}if("string"==typeof e&&(a=e,o=t,n=!1,r="OR","undefined"!=typeof t))if("all"==e.toLowerCase())if(this.searches.length>0)for(var l in this.searches){var d=this.searches[l];
  if("text"==d.type||"alphanumeric"==d.type&&w2utils.isAlphaNumeric(t)||"int"==d.type&&w2utils.isInt(t)||"float"==d.type&&w2utils.isFloat(t)||"percent"==d.type&&w2utils.isFloat(t)||"hex"==d.type&&w2utils.isHex(t)||"currency"==d.type&&w2utils.isMoney(t)||"money"==d.type&&w2utils.isMoney(t)||"date"==d.type&&w2utils.isDate(t)){var y={field:d.field,type:d.type,operator:"text"==d.type?"contains":"is",value:t};s.push(y)}if(-1!=["int","float","money","currency","percent"].indexOf(d.type)&&-1!=String(t).indexOf("-")){var x=String(t).split("-"),y={field:d.field,type:d.type,operator:"between",value:[x[0],x[1]]};s.push(y)}}else for(var _ in this.columns){var y={field:this.columns[_].field,type:"text",operator:"contains",value:t};s.push(y)}else{var k=$("#grid_"+this.name+"_search_all"),d=this.getSearch(e);if(null==d&&(d={field:e,type:"text"}),d.field==e&&(this.last.caption=d.caption),""!==t){var C="contains",T=t;if(-1!=["date","time"].indexOf(d.type)&&(C="is"),-1!=["list","enum"].indexOf(d.type)){C="is";var y=k.data("selected");T=y&&!$.isEmptyObject(y)?y.id:""}if("int"==d.type&&""!==t){if(C="is",-1!=String(t).indexOf("-")){var y=t.split("-");2==y.length&&(C="between",T=[parseInt(y[0]),parseInt(y[1])])}if(-1!=String(t).indexOf(",")){var y=t.split(",");C="in",T=[];for(var x in y)T.push(y[x])}}var y={field:d.field,type:d.type,operator:C,value:T};s.push(y)}}if($.isArray(e)){var S="AND";"string"==typeof t&&(S=t.toUpperCase(),"OR"!=S&&"AND"!=S&&(S="AND")),o="",n=!0,r=S;for(var z in e){var D=e[z],d=this.getSearch(D.field);if(null==d&&(d={type:"text",operator:"contains"}),$.isArray(D.value))for(var w in D.value)"string"==typeof D.value[w]&&(D.value[w]=D.value[w].toLowerCase());s.push($.extend(!0,{},d,D))}}var O=this.trigger({phase:"before",type:"search",target:this.name,searchData:s,searchField:e?e:"multi",searchValue:t?t:"multi"});O.isCancelled!==!0&&(this.searchData=O.searchData,this.last.field=a,this.last.search=o,this.last.multi=n,this.last.logic=r,this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selection.indexes=[],this.last.selection.columns={},this.searchClose(),this.set({expanded:!1},!0),i?(this.last.xhr_offset=0,this.reload()):(this.localSearch(),this.refresh()),this.trigger($.extend(O,{phase:"after"})))},searchOpen:function(){if(this.box&&0!=this.searches.length){var e=this;$("#tb_"+this.name+"_toolbar_item_w2ui-search-advanced").w2overlay(this.getSearchesHTML(),{name:"searches-"+this.name,left:-10,"class":"w2ui-grid-searches",onShow:function(){"OR"==e.last.logic&&(e.searchData=[]),e.initSearches(),$("#w2ui-overlay-searches-"+this.name+" .w2ui-grid-searches").data("grid-name",e.name);var t=$("#w2ui-overlay-searches-"+this.name+" .w2ui-grid-searches *[rel=search]");t.length>0&&t[0].focus()}})}},searchClose:function(){this.box&&0!=this.searches.length&&(this.toolbar&&this.toolbar.uncheck("w2ui-search-advanced"),$("#w2ui-overlay-searches-"+this.name+" .w2ui-grid-searches").length>0&&$().w2overlay("",{name:"searches-"+this.name}))},searchReset:function(e){var t=this.trigger({phase:"before",type:"search",target:this.name,searchData:[]});t.isCancelled!==!0&&(this.searchData=[],this.last.search="",this.last.logic="OR",this.last.multi&&(this.multiSearch?(this.last.field="all",this.last.caption=w2utils.lang("All Fields")):(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].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(),$("#grid_"+this.name+"_search_all").val(""),e||this.reload(),this.trigger($.extend(t,{phase:"after"})))},searchShowFields:function(){for(var e=$("#grid_"+this.name+"_search_all"),t='<div class="w2ui-select-field"><table>',i=-1;i<this.searches.length;i++){var s=this.searches[i];if(-1==i){if(!this.multiSearch)continue;s={field:"all",caption:w2utils.lang("All Fields")}}else if(this.searches[i].hidden===!0)continue;t+="<tr "+(w2utils.isIOS?"onTouchStart":"onClick")+"=\"w2ui['"+this.name+"'].initAllField('"+s.field+'\')">    <td><input type="radio" tabIndex="-1" '+(s.field==this.last.field?"checked":"")+"></td>    <td>"+s.caption+"</td></tr>"}t+="</table></div>",setTimeout(function(){$(e).w2overlay(t,{left:-10})},1)},initAllField:function(e,t){var i=$("#grid_"+this.name+"_search_all");if("all"==e){var s={field:"all",caption:w2utils.lang("All Fields")};i.w2field("clear"),i.change().focus()}else{var s=this.getSearch(e);if(null==s)return;var n=s.type;-1!=["enum","select"].indexOf(n)&&(n="list"),i.w2field(n,$.extend({},s.options,{suffix:"",autoFormat:!1,selected:t})),-1!=["list","enum","date","time"].indexOf(s.type)&&(this.last.search="",this.last.item="",i.val("")),setTimeout(function(){null!==t&&i.focus()},1)}""!=this.last.search?this.search(s.field,this.last.search):(this.last.field=s.field,this.last.caption=s.caption),i.attr("placeholder",s.caption),$().w2overlay()},clear:function(e){this.records=[],this.summary=[],this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selection.indexes=[],this.last.selection.columns={},this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,e||this.refresh()},reset:function(e){this.last.scrollTop=0,this.last.scrollLeft=0,this.last.selection.indexes=[],this.last.selection.columns={},this.last.range_start=null,this.last.range_end=null,this.last.xhr_offset=0,null!=this.last.sortData&&(this.sortData=this.last.sortData),this.set({expanded:!1},!0),e||this.refresh()},skip:function(e){var t="object"!=typeof this.url?this.url:this.url.get;t?(this.offset=parseInt(e),this.offset>this.total&&(this.offset=this.total-this.limit),(this.offset<0||!w2utils.isInt(this.offset))&&(this.offset=0),this.records=[],this.last.xhr_offset=0,this.last.pull_more=!0,this.last.scrollTop=0,this.last.scrollLeft=0,$("#grid_"+this.name+"_records").prop("scrollTop",0),this.reload()):console.log("ERROR: grid.skip() can only be called when you have remote data source.")},load:function(e,t){return"undefined"==typeof e?void console.log('ERROR: You need to provide url argument when calling .load() method of "'+this.name+'" object.'):void this.request("get-records",{},e,t)},reload:function(e){var t="object"!=typeof this.url?this.url:this.url.get;t?(this.clear(!0),this.request("get-records",{},null,e)):(this.last.scrollTop=0,this.last.scrollLeft=0,this.last.range_start=null,this.last.range_end=null,this.localSearch(),this.refresh(),"function"==typeof e&&e({status:"success"}))},request:function(e,t,i,s){if("undefined"==typeof t&&(t={}),("undefined"==typeof i||""==i||null==i)&&(i=this.url),""!=i&&null!=i){var n={};if(w2utils.isInt(this.offset)||(this.offset=0),w2utils.isInt(this.last.xhr_offset)||(this.last.xhr_offset=0),n.cmd=e,n.selected=this.getSelection(),n.limit=this.limit,n.offset=parseInt(this.offset)+this.last.xhr_offset,n.search=this.searchData,n.searchLogic=this.last.logic,n.sort=this.sortData,0==this.searchData.length&&(delete n.search,delete n.searchLogic),0==this.sortData.length&&delete n.sort,$.extend(n,this.postData),$.extend(n,t),"get-records"==e){var r=this.trigger({phase:"before",type:"request",target:this.name,url:i,postData:n});if(r.isCancelled===!0)return void("function"==typeof s&&s({status:"error",message:"Request aborted."}))}else var r={url:i,postData:n};var a=this;if(0==this.last.xhr_offset)this.lock(this.msgRefresh,!0);else{var o=$("#grid_"+this.name+"_rec_more");this.autoLoad===!0?o.show().find("td").html('<div><div style="width: 20px; height: 20px;" class="w2ui-spinner"></div></div>'):o.find("td").html("<div>"+w2utils.lang("Load")+" "+a.limit+" "+w2utils.lang("More")+"...</div>")}if(this.last.xhr)try{this.last.xhr.abort()}catch(l){}var i="object"!=typeof r.url?r.url:r.url.get;if("save-records"==n.cmd&&"object"==typeof r.url&&(i=r.url.save),"delete-records"==n.cmd&&"object"==typeof r.url&&(i=r.url.remove),!$.isEmptyObject(a.routeData)){var d=w2utils.parseRoute(i);if(d.keys.length>0)for(var h=0;h<d.keys.length;h++)null!=a.routeData[d.keys[h].name]&&(i=i.replace(new RegExp(":"+d.keys[h].name,"g"),a.routeData[d.keys[h].name]))}var u={type:"POST",url:i,data:r.postData,dataType:"text"};"HTTP"==w2utils.settings.dataType&&(u.data="object"==typeof u.data?String($.param(u.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"):u.data),"RESTFULL"==w2utils.settings.dataType&&(u.type="GET","save-records"==n.cmd&&(u.type="PUT"),"delete-records"==n.cmd&&(u.type="DELETE"),u.data="object"==typeof u.data?String($.param(u.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]"):u.data),"JSON"==w2utils.settings.dataType&&(u.type="POST",u.data=JSON.stringify(u.data),u.contentType="application/json"),this.method&&(u.type=this.method),this.last.xhr_cmd=n.cmd,this.last.xhr_start=(new Date).getTime(),this.last.xhr=$.ajax(u).done(function(t,i){a.requestComplete(i,e,s)}).fail(function(t,i,n){var r={status:i,error:n,rawResponseText:t.responseText},o=a.trigger({phase:"before",type:"error",error:r,xhr:t});if(o.isCancelled!==!0){if("abort"!=i){var l;try{l=$.parseJSON(t.responseText)}catch(d){}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:","object"==typeof l?l:t.responseText),a.requestComplete("error",e,s)}a.trigger($.extend(o,{phase:"after"}))}}),"get-records"==e&&this.trigger($.extend(r,{phase:"after"}))}},requestComplete:function(status,cmd,callBack){var obj=this;this.unlock(),setTimeout(function(){obj.show.statusResponse&&obj.status(w2utils.lang("Server Response")+" "+((new Date).getTime()-obj.last.xhr_start)/1e3+" "+w2utils.lang("sec"))},10),this.last.pull_more=!1,this.last.pull_refresh=!0;var event_name="load";"save-records"==this.last.xhr_cmd&&(event_name="save"),"delete-records"==this.last.xhr_cmd&&(event_name="deleted");var eventData=this.trigger({phase:"before",target:this.name,type:event_name,xhr:this.last.xhr,status:status});if(eventData.isCancelled===!0)return void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."}));var data,responseText=this.last.xhr.responseText;if("error"!=status){if("undefined"!=typeof responseText&&""!=responseText){if("object"==typeof responseText)data=responseText;else if("function"==typeof obj.parser)data=obj.parser(responseText),"object"!=typeof data&&console.log("ERROR: Your parser did not return proper object");else try{eval("data = "+responseText)}catch(e){}if(obj.recid)for(var r in data.records)data.records[r].recid=data.records[r][obj.recid];if("undefined"==typeof data&&(data={status:"error",message:this.msgNotJSON,responseText:responseText}),"error"==data.status)obj.error(data.message);else{if("get-records"==cmd)if(0==this.last.xhr_offset)this.records=[],this.summary=[],delete data.status,$.extend(!0,this,data);else{if(parseInt(data.total)!=parseInt(this.total))return w2alert(this.msgNeedReload),delete this.last.xhr_offset,void this.reload();var records=data.records;delete data.records,delete data.status,$.extend(!0,this,data);for(var r=0;r<records.length;r++)this.records.push(records[r])}if("delete-records"==cmd)return this.reset(),void this.reload()}}}else data={status:"error",message:this.msgAJAXerror,responseText:responseText},obj.error(this.msgAJAXerror);var url="object"!=typeof this.url?this.url:this.url.get;url||(this.localSort(),this.localSearch()),this.total=parseInt(this.total),this.trigger($.extend(eventData,{phase:"after"})),0==this.last.xhr_offset?this.refresh():this.scroll(),"function"==typeof callBack&&callBack(data)},error:function(e){var t=this.trigger({target:this.name,type:"error",message:e,xhr:this.last.xhr});return t.isCancelled===!0?void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."})):(w2alert(e,"Error"),void this.trigger($.extend(t,{phase:"after"})))},getChanges:function(){for(var e=[],t=0;t<this.records.length;t++){var i=this.records[t];"undefined"!=typeof i.changes&&e.push($.extend(!0,{recid:i.recid},i.changes))}return e},mergeChanges:function(){for(var changes=this.getChanges(),c=0;c<changes.length;c++){var record=this.get(changes[c].recid);for(var s in changes[c])if("recid"!=s){try{eval("record."+s+" = changes[c][s]")}catch(e){}delete record.changes}}this.refresh()},save:function(){var e=this,t=this.getChanges(),i=this.trigger({phase:"before",target:this.name,type:"submit",changes:t});if(i.isCancelled!==!0){var s="object"!=typeof this.url?this.url:this.url.save;s?this.request("save-records",{changes:i.changes},null,function(t){"error"!==t.status&&e.mergeChanges(),e.trigger($.extend(i,{phase:"after"}))}):(this.mergeChanges(),this.trigger($.extend(i,{phase:"after"})))}},editField:function(e,t,i,s){var n=this,r=n.get(e,!0),a=n.records[r],o=n.columns[t],l=o?o.editable:null;if(a&&o&&l&&a.editable!==!1){if(-1!=["enum","file"].indexOf(l.type))return void console.log('ERROR: input types "enum" and "file" are not supported in inline editing.');var d=n.trigger({phase:"before",type:"editField",target:n.name,recid:e,column:t,value:i,index:r,originalEvent:s});if(d.isCancelled!==!0&&(i=d.value,this.selectNone(),this.select({recid:e,column:t}),this.last.edit_col=t,-1==["checkbox","check"].indexOf(l.type))){var h=$("#grid_"+n.name+"_rec_"+w2utils.escapeId(e)),u=h.find("[col="+t+"] > div");"undefined"==typeof l.inTag&&(l.inTag=""),"undefined"==typeof l.outTag&&(l.outTag=""),"undefined"==typeof l.style&&(l.style=""),"undefined"==typeof l.items&&(l.items=[]);var c=w2utils.stripTags(a.changes&&"undefined"!=typeof a.changes[o.field]?a.changes[o.field]:a[o.field]);(null==c||"undefined"==typeof c)&&(c=""),"undefined"!=typeof i&&null!=i&&(c=i);var p="undefined"!=typeof o.style?o.style+";":"";if("string"==typeof o.render&&-1!=["number","int","float","money","percent"].indexOf(o.render.split(":")[0])&&(p+="text-align: right;"),l.items.length>0&&!$.isPlainObject(l.items[0])&&(l.items=w2obj.field.prototype.normMenu(l.items)),"select"==l.type){for(var f="",g=0;g<l.items.length;g++)f+='<option value="'+l.items[g].id+'" '+(l.items[g].id==c?"selected":"")+">"+l.items[g].text+"</option>";u.addClass("w2ui-editable").html('<select id="grid_'+n.name+"_edit_"+e+"_"+t+'" column="'+t+'"     style="width: 100%; '+p+l.style+'" field="'+o.field+'" recid="'+e+'"     '+l.inTag+">"+f+"</select>"+l.outTag),u.find("select").focus().on("change",function(){delete n.last.move}).on("blur",function(e){n.editChange.call(n,this,r,t,e)})}else{u.addClass("w2ui-editable").html('<input id="grid_'+n.name+"_edit_"+e+"_"+t+'"     type="text" style="font-family: inherit; font-size: inherit; outline: none; '+p+l.style+'" field="'+o.field+'" recid="'+e+'"     column="'+t+'" '+l.inTag+">"+l.outTag),"number"==typeof c&&(c=w2utils.formatNumber(c)),null==i&&u.find("input").val("object"!=typeof c?c:"");var m=u.find("input").get(0);$(m).w2field(l.type,$.extend(l,{selected:c})),setTimeout(function(){var e=m;"list"==l.type&&(e=$($(m).data("w2field").helpers.focus).find("input"),"object"!=typeof c&&""!=c&&e.val(c).css({opacity:1}).prev().css({opacity:1})),$(e).on("blur",function(e){n.editChange.call(n,m,r,t,e)})},10),null!=i&&$(m).val("object"!=typeof c?c:"")}setTimeout(function(){u.find("input, select").on("click",function(e){e.stopPropagation()}).on("keydown",function(i){var s=!1;switch(i.keyCode){case 9:s=!0;var l=e,d=i.shiftKey?n.prevCell(t,!0):n.nextCell(t,!0);if(null==d){var h=i.shiftKey?n.prevRow(r):n.nextRow(r);if(null!=h&&h!=r){l=n.records[h].recid;for(var u=0;u<n.columns.length;u++){var h=n.columns[u].editable;if("undefined"!=typeof h&&-1==["checkbox","check"].indexOf(h.type)&&(d=parseInt(u),!i.shiftKey))break}}}l===!1&&(l=e),null==d&&(d=t),this.blur(),setTimeout(function(){"row"!=n.selectType?(n.selectNone(),n.select({recid:l,column:d})):n.editField(l,d,null,i)},1);break;case 13:this.blur();var c=i.shiftKey?n.prevRow(r):n.nextRow(r);null!=c&&c!=r&&setTimeout(function(){"row"!=n.selectType?(n.selectNone(),n.select({recid:n.records[c].recid,column:t})):n.editField(n.records[c].recid,t,null,i)},100);break;case 38:if(!i.shiftKey)break;s=!0;var c=n.prevRow(r);c!=r&&(this.blur(),setTimeout(function(){"row"!=n.selectType?(n.selectNone(),n.select({recid:n.records[c].recid,column:t})):n.editField(n.records[c].recid,t,null,i)},1));break;case 40:if(!i.shiftKey)break;s=!0;var c=n.nextRow(r);null!=c&&c!=r&&(this.blur(),setTimeout(function(){"row"!=n.selectType?(n.selectNone(),n.select({recid:n.records[c].recid,column:t})):n.editField(n.records[c].recid,t,null,i)},1));break;case 27:var p=n.parseField(a,o.field);a.changes&&"undefined"!=typeof a.changes[o.field]&&(p=a.changes[o.field]),this.value="undefined"!=typeof p?p:"",this.blur(),setTimeout(function(){n.select({recid:e,column:t})},1)}s&&i.preventDefault&&i.preventDefault()});var s=u.find("input").focus();null!=i?s[0].setSelectionRange(s.val().length,s.val().length):s.select()},1),n.trigger($.extend(d,{phase:"after"}))}}},editChange:function(e,t,i){var s=0>t;t=0>t?-t-1:t;var n=s?this.summary:this.records,r=n[t],a=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(r.recid)),o=this.columns[i],l=e.value,d=this.parseField(r,o.field),h=$(e).data("w2field");h&&(l=h.clean(l),"list"==h.type&&""!=l&&(l=$(e).data("selected"))),"checkbox"==e.type&&(l=e.checked);for(var u={phase:"before",type:"change",target:this.name,input_id:e.id,recid:r.recid,index:t,column:i,value_new:l,value_previous:r.changes&&r.changes.hasOwnProperty(o.field)?r.changes[o.field]:d,value_original:d};;){if(l=u.value_new,"object"!=typeof l&&String(d)!=String(l)||"object"==typeof l&&("object"!=typeof d||null===d||l.id!=d.id)){if(u=this.trigger($.extend(u,{type:"change",phase:"before"})),u.isCancelled!==!0){if(l!==u.value_new)continue;r.changes=r.changes||{},r.changes[o.field]=u.value_new,this.trigger($.extend(u,{phase:"after"}))}}else if(u=this.trigger($.extend(u,{type:"restore",phase:"before"})),u.isCancelled!==!0){if(l!==u.value_new)continue;r.changes&&delete r.changes[o.field],$.isEmptyObject(r.changes)&&delete r.changes,this.trigger($.extend(u,{phase:"after"}))}break}var c=this.getCellHTML(t,i,s);s||(r.changes&&"undefined"!=typeof r.changes[o.field]?$(a).find("[col="+i+"]").addClass("w2ui-changed").html(c):$(a).find("[col="+i+"]").removeClass("w2ui-changed").html(c))},"delete":function(e){var t=((new Date).getTime(),this),i=this.trigger({phase:"before",target:this.name,type:"delete",force:e});if(i.isCancelled!==!0){e=i.force;var s=this.getSelection();if(0!=s.length){if(""!=this.msgDelete&&!e)return void w2confirm({title:w2utils.lang("Delete Confirmation"),msg:t.msgDelete,yes_class:"btn-red",callBack:function(e){"Yes"==e&&w2ui[t.name]["delete"](!0)}});var n="object"!=typeof this.url?this.url:this.url.remove;if(n)this.request("delete-records");else if(this.selectNone(),"object"!=typeof s[0])this.remove.apply(this,s);else{for(var r=0;r<s.length;r++){var a=this.columns[s[r].column].field,o=this.get(s[r].recid,!0),l=this.records[o];null!=o&&"recid"!=a&&(this.records[o][a]="",l.changes&&delete l.changes[a])}this.update()}this.trigger($.extend(i,{phase:"after"}))}}},click:function(e,t){var i=(new Date).getTime(),s=null;if(!(1==this.last.cancelClick||t&&t.altKey)){if("object"==typeof e&&(s=e.column,e=e.recid),"undefined"==typeof t&&(t={}),i-parseInt(this.last.click_time)<350&&"click"==t.type)return void this.dblClick(e,t);if(this.last.click_time=i,null==s&&t.target){var n=t.target;"TD"!=n.tagName&&(n=$(n).parents("td")[0]),"undefined"!=typeof $(n).attr("col")&&(s=parseInt($(n).attr("col")))}var r=this.trigger({phase:"before",target:this.name,type:"click",recid:e,column:s,originalEvent:t});if(r.isCancelled!==!0){var a=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(e)).parents("tr");if(a.length>0&&-1!=String(a.attr("id")).indexOf("expanded_row")){var o=a.parents(".w2ui-grid").attr("name");w2ui[o].selectNone(),a.parents(".w2ui-grid").find(".w2ui-expanded-row .w2ui-grid").each(function(e,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()})}$(this.box).find(".w2ui-expanded-row .w2ui-grid").each(function(e,t){var i=$(t).attr("name");w2ui[i]&&w2ui[i].selectNone()});var l=this,d=this.getSelection();$("#grid_"+this.name+"_check_all").prop("checked",!1);var h=this.get(e,!0),u=(this.records[h],[]);if(l.last.sel_ind=h,l.last.sel_col=s,l.last.sel_recid=e,l.last.sel_type="click",t.shiftKey&&d.length>0&&l.multiSelect){if(d[0].recid){var c=this.get(d[0].recid,!0),p=this.get(e,!0);if(s>d[0].column)var f=d[0].column,g=s;else var f=s,g=d[0].column;for(var m=f;g>=m;m++)u.push(m)}else var c=this.get(d[0],!0),p=this.get(e,!0);var v=[];if(c>p){var n=c;c=p,p=n}for(var w="object"!=typeof this.url?this.url:this.url.get,y=c;p>=y;y++)if(!(this.searchData.length>0)||w||-1!=$.inArray(y,this.last.searchIds))if("row"==this.selectType)v.push(this.records[y].recid);else for(var b=0;b<u.length;b++)v.push({recid:this.records[y].recid,column:u[b]});this.select.apply(this,v)}else{var x=this.last.selection,_=-1!=x.indexes.indexOf(h)?!0:!1;(t.ctrlKey||t.shiftKey||t.metaKey)&&this.multiSelect||this.showSelectColumn?("row"!=this.selectType&&-1==$.inArray(s,x.columns[h])&&(_=!1),_===!0?this.unselect({recid:e,column:s}):this.select({recid:e,column:s})):("row"!=this.selectType&&-1==$.inArray(s,x.columns[h])&&(_=!1),d.length>300?this.selectNone():this.unselect.apply(this,d),_===!0?this.unselect({recid:e,column:s}):this.select({recid:e,column:s}))}this.status(),l.initResize(),this.trigger($.extend(r,{phase:"after"}))}}},columnClick:function(e,t){var i=this.trigger({phase:"before",type:"columnClick",target:this.name,field:e,originalEvent:t});if(i.isCancelled!==!0){var s=this.getColumn(e);s&&s.sortable&&this.sort(e,null,t&&(t.ctrlKey||t.metaKey)?!0:!1),this.trigger($.extend(i,{phase:"after"}))}},focus:function(e){var t=this.trigger({phase:"before",type:"focus",target:this.name,originalEvent:e});return t.isCancelled===!0?!1:($(this.box).find(".w2ui-selected").removeClass("w2ui-inactive"),void this.trigger($.extend(t,{phase:"after"})))},blur:function(e){var t=this.trigger({phase:"before",type:"blur",target:this.name,originalEvent:e});return t.isCancelled===!0?!1:($(this.box).find(".w2ui-selected").addClass("w2ui-inactive"),void this.trigger($.extend(t,{phase:"after"})))},keydown:function(e){function t(){var e=Math.floor((o[0].scrollTop+o.height()/2.1)/n.recordHeight);n.records[e]||(e=0),n.select({recid:n.records[e].recid,column:0})}function i(){if("click"!=n.last.sel_type)return!1;if("row"!=n.selectType){if(n.last.sel_type="key",l.length>1){for(var e=0;e<l.length;e++)if(l[e].recid==n.last.sel_recid&&l[e].column==n.last.sel_col){l.splice(e,1);break}return n.unselect.apply(n,l),!0}return!1}return n.last.sel_type="key",l.length>1?(l.splice(l.indexOf(n.records[n.last.sel_ind].recid),1),n.unselect.apply(n,l),!0):!1}function s(){$("#_tmp_copy_data").remove(),$(document).off("keyup",s)}var n=this;if(n.keyboard===!0){var r=n.trigger({phase:"before",type:"keydown",target:n.name,originalEvent:e});if(r.isCancelled!==!0){var a=!1,o=$("#grid_"+n.name+"_records"),l=n.getSelection();0==l.length&&(a=!0);var d=l[0]||null,h=[],u=l[l.length-1];if("object"==typeof d&&null!=d){d=l[0].recid,h=[];for(var c=0;;){if(!l[c]||l[c].recid!=d)break;h.push(l[c].column),c++}u=l[l.length-1].recid}var p=n.get(d,!0),f=n.get(u,!0),g=n.get(d),m=$("#grid_"+n.name+"_rec_"+(null!==p?w2utils.escapeId(n.records[p].recid):"none")),v=!1,w=e.keyCode,y=e.shiftKey;switch(9==w&&(w=e.shiftKey?37:39,y=!1,v=!0),w){case 8:case 46:(this.show.toolbarDelete||this.onDelete)&&n["delete"](),v=!0,e.stopPropagation();break;case 27:n.selectNone(),l.length>0&&"object"==typeof l[0]&&n.select({recid:l[0].recid,column:l[0].column}),v=!0;break;case 65:if(!e.metaKey&&!e.ctrlKey)break;n.selectAll(),v=!0;break;case 70:if(!e.metaKey&&!e.ctrlKey)break;$("#grid_"+n.name+"_search_all").focus(),v=!0;break;case 13:if("row"==this.selectType&&n.show.expandColumn===!0){if(m.length<=0)break;n.toggle(d,e),v=!0}else{for(var b=0;b<this.columns.length;b++)if(this.columns[b].editable){h.push(parseInt(b));break}"row"==this.selectType&&this.last.edit_col&&(h=[this.last.edit_col]),h.length>0&&(n.editField(d,h[0],null,e),v=!0)}break;case 37:if(a)break;var x=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.records[p].recid)).parents("tr");if(x.length>0&&-1!=String(x.attr("id")).indexOf("expanded_row")){var d=x.prev().attr("recid"),_=x.parents(".w2ui-grid").attr("name");n.selectNone(),w2utils.keyboard.active(_,e),w2ui[_].set(d,{expanded:!1}),w2ui[_].collapse(d),w2ui[_].click(d),v=!0;break}if("row"==this.selectType){if(m.length<=0||g.expanded!==!0)break;n.set(d,{expanded:!1},!0),n.collapse(d,e)}else{var k=n.prevCell(h[0]);if(null!=k)if(y&&n.multiSelect){if(i())return;var C=[],T=[],S=[];if(0==h.indexOf(this.last.sel_col)&&h.length>1)for(var z=0;z<l.length;z++)-1==C.indexOf(l[z].recid)&&C.push(l[z].recid),S.push({recid:l[z].recid,column:h[h.length-1]});else for(var z=0;z<l.length;z++)-1==C.indexOf(l[z].recid)&&C.push(l[z].recid),T.push({recid:l[z].recid,column:k});n.unselect.apply(n,S),n.select.apply(n,T)}else e.shiftKey=!1,n.click({recid:d,column:k},e);else if(!y)if(l.length>1)n.selectNone();else for(var D=1;D<l.length;D++)n.unselect(l[D])}v=!0;break;case 39:if(a)break;if("row"==this.selectType){if(m.length<=0||g.expanded===!0||n.show.expandColumn!==!0)break;n.expand(d,e)}else{var O=n.nextCell(h[h.length-1]);if(null!==O)if(y&&39==w&&n.multiSelect){if(i())return;var C=[],T=[],S=[];if(h.indexOf(this.last.sel_col)==h.length-1&&h.length>1)for(var z=0;z<l.length;z++)-1==C.indexOf(l[z].recid)&&C.push(l[z].recid),S.push({recid:l[z].recid,column:h[0]});else for(var z=0;z<l.length;z++)-1==C.indexOf(l[z].recid)&&C.push(l[z].recid),T.push({recid:l[z].recid,column:O});n.unselect.apply(n,S),n.select.apply(n,T)}else n.click({recid:d,column:O},e);else if(!y)if(l.length>1)n.selectNone();else for(var D=0;D<l.length-1;D++)n.unselect(l[D])}v=!0;break;case 38:if(a&&t(),m.length<=0)break;var k=n.prevRow(p);if(null!=k){if(n.records[k].expanded){var I=$("#grid_"+n.name+"_rec_"+w2utils.escapeId(n.records[k].recid)+"_expanded_row").find(".w2ui-grid");if(I.length>0&&w2ui[I.attr("name")]){n.selectNone();var _=I.attr("name"),R=w2ui[_].records;w2utils.keyboard.active(_,e),w2ui[_].click(R[R.length-1].recid),v=!0;break}}if(y&&n.multiSelect){if(i())return;if("row"==n.selectType)n.last.sel_ind>k&&n.last.sel_ind!=f?n.unselect(n.records[f].recid):n.select(n.records[k].recid);else if(n.last.sel_ind>k&&n.last.sel_ind!=f){k=f;for(var C=[],b=0;b<h.length;b++)C.push({recid:n.records[k].recid,column:h[b]});n.unselect.apply(n,C)}else{for(var C=[],b=0;b<h.length;b++)C.push({recid:n.records[k].recid,column:h[b]});n.select.apply(n,C)}}else n.selectNone(),n.click({recid:n.records[k].recid,column:h[0]},e);n.scrollIntoView(k),e.preventDefault&&e.preventDefault()}else{if(!y)if(l.length>1)n.selectNone();else for(var D=1;D<l.length;D++)n.unselect(l[D]);var x=$("#grid_"+n.name+"_rec_"+w2utils.escapeId(n.records[p].recid)).parents("tr");if(x.length>0&&-1!=String(x.attr("id")).indexOf("expanded_row")){var d=x.prev().attr("recid"),_=x.parents(".w2ui-grid").attr("name");n.selectNone(),w2utils.keyboard.active(_,e),w2ui[_].click(d),v=!0;break}}break;case 40:if(a&&t(),m.length<=0)break;if(n.records[f].expanded){var I=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.records[f].recid)+"_expanded_row").find(".w2ui-grid");if(I.length>0&&w2ui[I.attr("name")]){n.selectNone();var _=I.attr("name"),R=w2ui[_].records;w2utils.keyboard.active(_,e),w2ui[_].click(R[0].recid),v=!0;break}}var O=n.nextRow(f);if(null!=O){if(y&&n.multiSelect){if(i())return;if("row"==n.selectType)this.last.sel_ind<O&&this.last.sel_ind!=p?n.unselect(n.records[p].recid):n.select(n.records[O].recid);else if(this.last.sel_ind<O&&this.last.sel_ind!=p){O=p;for(var C=[],b=0;b<h.length;b++)C.push({recid:n.records[O].recid,column:h[b]});n.unselect.apply(n,C)}else{for(var C=[],b=0;b<h.length;b++)C.push({recid:n.records[O].recid,column:h[b]});n.select.apply(n,C)}}else n.selectNone(),n.click({recid:n.records[O].recid,column:h[0]},e);n.scrollIntoView(O),v=!0}else{if(!y)if(l.length>1)n.selectNone();else for(var D=0;D<l.length-1;D++)n.unselect(l[D]);var x=$("#grid_"+this.name+"_rec_"+w2utils.escapeId(n.records[f].recid)).parents("tr");if(x.length>0&&-1!=String(x.attr("id")).indexOf("expanded_row")){var d=x.next().attr("recid"),_=x.parents(".w2ui-grid").attr("name");n.selectNone(),w2utils.keyboard.active(_,e),w2ui[_].click(d),v=!0;break}}break;case 17:case 91:if(a)break;var j=n.copy();$("body").append('<textarea id="_tmp_copy_data"    onpaste="var obj = this; setTimeout(function () { w2ui[\''+n.name+"'].paste(obj.value); }, 1);\"    onkeydown=\"w2ui['"+n.name+'\'].keydown(event)"   style="position: absolute; top: -100px; height: 1px; width: 1px">'+j+"</textarea>"),$("#_tmp_copy_data").focus().select(),$(document).on("keyup",s);break;case 88:if(a)break;(e.ctrlKey||e.metaKey)&&setTimeout(function(){n["delete"](!0)},100)}for(var C=[187,189,32],z=48;90>=z;z++)C.push(z);if(-1!=C.indexOf(w)&&!e.ctrlKey&&!e.metaKey&&!v){0==h.length&&h.push(0);var C=String.fromCharCode(w);187==w&&(C="="),189==w&&(C="-"),y||(C=C.toLowerCase()),n.editField(d,h[0],C,e),v=!0}v&&e.preventDefault&&e.preventDefault(),n.trigger($.extend(r,{phase:"after"}))}}},scrollIntoView:function(e){var t=this.records.length;if(0==this.searchData.length||this.url||(t=this.last.searchIds.length),"undefined"==typeof e){var i=this.getSelection();if(0==i.length)return;e=this.get(i[0],!0)}var s=$("#grid_"+this.name+"_records");if(0!=t){var n=this.last.searchIds.length;if(!(s.height()>this.recordHeight*(n>0?n:t))){n>0&&(e=this.last.searchIds.indexOf(e));var r=Math.floor(s[0].scrollTop/this.recordHeight),a=r+Math.floor(s.height()/this.recordHeight);e==r&&s.animate({scrollTop:s.scrollTop()-s.height()/1.3},250,"linear"),e==a&&s.animate({scrollTop:s.scrollTop()+s.height()/1.3},250,"linear"),(r>e||e>a)&&s.animate({scrollTop:(e-1)*this.recordHeight})}}},dblClick:function(e,t){var i=null;if("object"==typeof e&&(i=e.column,e=e.recid),"undefined"==typeof t&&(t={}),null==i&&t.target){var s=t.target;"TD"!=s.tagName&&(s=$(s).parents("td")[0]),i=parseInt($(s).attr("col"))}var n=this.trigger({phase:"before",target:this.name,type:"dblClick",recid:e,column:i,originalEvent:t});if(n.isCancelled!==!0){this.selectNone();var r=this.columns[i];r&&$.isPlainObject(r.editable)?this.editField(e,i,null,t):this.select({recid:e,column:i}),this.trigger($.extend(n,{phase:"after"}))}},contextMenu:function(e,t){var i=this;"text"!=i.last.userSelect&&("undefined"==typeof t&&(t={offsetX:0,offsetY:0,target:$("#grid_"+i.name+"_rec_"+e)[0]}),"undefined"==typeof t.offsetX&&(t.offsetX=t.layerX-t.target.offsetLeft,t.offsetY=t.layerY-t.target.offsetTop),w2utils.isFloat(e)&&(e=parseFloat(e)),-1==this.getSelection().indexOf(e)&&i.click(e),setTimeout(function(){var s=i.trigger({phase:"before",type:"contextMenu",target:i.name,originalEvent:t,recid:e});s.isCancelled!==!0&&(i.menu.length>0&&$(i.box).find(t.target).w2menu(i.menu,{left:t.offsetX,onSelect:function(t){i.menuClick(e,parseInt(t.index),t.originalEvent)}}),i.trigger($.extend(s,{phase:"after"})))},150),t.preventDefault&&t.preventDefault())},menuClick:function(e,t,i){var s=this,n=s.trigger({phase:"before",type:"menuClick",target:s.name,originalEvent:i,recid:e,menuIndex:t,menuItem:s.menu[t]});n.isCancelled!==!0&&s.trigger($.extend(n,{phase:"after"}))},toggle:function(e){var t=this.get(e);return t.expanded===!0?this.collapse(e):this.expand(e)},expand:function(e){function t(){var t=$("#grid_"+s.name+"_rec_"+n+"_expanded"),i=$("#grid_"+s.name+"_rec_"+n+"_expanded_row .w2ui-expanded1 > div");t.height()<5||(t.css("opacity",1),i.show().css("opacity",1),$("#grid_"+s.name+"_cell_"+s.get(e,!0)+"_expand div").html("-"))}var i=this.get(e),s=this,n=w2utils.escapeId(e);if($("#grid_"+this.name+"_rec_"+n+"_expanded_row").length>0)return!1;if("none"==i.expanded)return!1;var r=1+(this.show.selectColumn?1:0),a="";$("#grid_"+this.name+"_rec_"+n).after('<tr id="grid_'+this.name+"_rec_"+e+'_expanded_row" class="w2ui-expanded-row '+a+'">'+(this.show.lineNumbers?'<td class="w2ui-col-number"></td>':"")+'    <td class="w2ui-grid-data w2ui-expanded1" colspan="'+r+'"><div style="display: none"></div></td>    <td colspan="100" class="w2ui-expanded2">        <div id="grid_'+this.name+"_rec_"+e+'_expanded" style="opacity: 0"></div>    </td></tr>');
  var o=this.trigger({phase:"before",type:"expand",target:this.name,recid:e,box_id:"grid_"+this.name+"_rec_"+e+"_expanded",ready:t});return o.isCancelled===!0?void $("#grid_"+this.name+"_rec_"+n+"_expanded_row").remove():($("#grid_"+this.name+"_rec_"+n).attr("expanded","yes").addClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+n+"_expanded_row").show(),$("#grid_"+this.name+"_cell_"+this.get(e,!0)+"_expand div").html('<div class="w2ui-spinner" style="width: 16px; height: 16px; margin: -2px 2px;"></div>'),i.expanded=!0,setTimeout(t,300),this.trigger($.extend(o,{phase:"after"})),this.resizeRecords(),!0)},collapse:function(e){var t=this.get(e),i=this,s=w2utils.escapeId(e);if(0==$("#grid_"+this.name+"_rec_"+s+"_expanded_row").length)return!1;var n=this.trigger({phase:"before",type:"collapse",target:this.name,recid:e,box_id:"grid_"+this.name+"_rec_"+s+"_expanded"});return n.isCancelled!==!0?($("#grid_"+this.name+"_rec_"+s).removeAttr("expanded").removeClass("w2ui-expanded"),$("#grid_"+this.name+"_rec_"+s+"_expanded").css("opacity",0),$("#grid_"+this.name+"_cell_"+this.get(e,!0)+"_expand div").html("+"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+s+"_expanded").height("0px"),setTimeout(function(){$("#grid_"+i.name+"_rec_"+s+"_expanded_row").remove(),delete t.expanded,i.trigger($.extend(n,{phase:"after"})),i.resizeRecords()},300)},200),!0):void 0},sort:function(e,t,i){var s=this.trigger({phase:"before",type:"sort",target:this.name,field:e,direction:t,multiField:i});if(s.isCancelled!==!0){if("undefined"!=typeof e){for(var n=this.sortData.length,r=0;r<this.sortData.length;r++)if(this.sortData[r].field==e){n=r;break}if("undefined"==typeof t||null==t)if("undefined"==typeof this.sortData[n])t="asc";else switch(String(this.sortData[n].direction)){case"asc":t="desc";break;case"desc":t="asc";break;default:t="asc"}this.multiSort===!1&&(this.sortData=[],n=0),1!=i&&(this.sortData=[],n=0),"undefined"==typeof this.sortData[n]&&(this.sortData[n]={}),this.sortData[n].field=e,this.sortData[n].direction=t}else this.sortData=[];this.selectNone();var a="object"!=typeof this.url?this.url:this.url.get;a?(this.trigger($.extend(s,{phase:"after"})),this.last.xhr_offset=0,this.reload()):(this.localSort(),this.searchData.length>0&&this.localSearch(!0),this.trigger($.extend(s,{phase:"after"})),this.refresh())}},copy:function(){var e=this.getSelection();if(0==e.length)return"";var t="";if("object"==typeof e[0]){for(var i=e[0].column,s=e[0].column,n=[],r=0;r<e.length;r++)e[r].column<i&&(i=e[r].column),e[r].column>s&&(s=e[r].column),-1==n.indexOf(e[r].index)&&n.push(e[r].index);n.sort(function(e,t){return e-t});for(var a=0;a<n.length;a++){for(var o=n[a],l=i;s>=l;l++){var d=this.columns[l];d.hidden!==!0&&(t+=w2utils.stripTags(this.getCellHTML(o,l))+"	")}t=t.substr(0,t.length-1),t+="\n"}}else{for(var l=0;l<this.columns.length;l++){var d=this.columns[l];d.hidden!==!0&&(t+='"'+w2utils.stripTags(d.caption?d.caption:d.field)+'"	')}t=t.substr(0,t.length-1),t+="\n";for(var r=0;r<e.length;r++){for(var o=this.get(e[r],!0),l=0;l<this.columns.length;l++){var d=this.columns[l];d.hidden!==!0&&(t+='"'+w2utils.stripTags(this.getCellHTML(o,l))+'"	')}t=t.substr(0,t.length-1),t+="\n"}}t=t.substr(0,t.length-1);var h=this.trigger({phase:"before",type:"copy",target:this.name,text:t});return h.isCancelled===!0?"":(t=h.text,this.trigger($.extend(h,{phase:"after"})),t)},paste:function(e){var t=this.getSelection(),i=this.get(t[0].recid,!0),s=t[0].column,n=this.trigger({phase:"before",type:"paste",target:this.name,text:e,index:i,column:s});if(n.isCancelled!==!0){if(e=n.text,"row"==this.selectType||0==t.length)return console.log("ERROR: You can paste only if grid.selectType = 'cell' and when at least one cell selected."),void this.trigger($.extend(n,{phase:"after"}));for(var r=[],e=e.split("\n"),a=0;a<e.length;a++){for(var o=e[a].split("	"),l=0,d=this.records[i],h=[],u=0;u<o.length;u++)if(this.columns[s+l]){var c=this.columns[s+l].field;d.changes=d.changes||{},d.changes[c]=o[u],h.push(s+l),l++}for(var p=0;p<h.length;p++)r.push({recid:d.recid,column:h[p]});i++}this.selectNone(),this.select.apply(this,r),this.refresh(),this.trigger($.extend(n,{phase:"after"}))}},resize:function(){var e=this,t=(new Date).getTime();if(this.box&&$(this.box).attr("name")==this.name){$(this.box).find("> div").css("width",$(this.box).width()).css("height",$(this.box).height());var i=this.trigger({phase:"before",type:"resize",target:this.name});if(i.isCancelled!==!0)return e.resizeBoxes(),e.resizeRecords(),this.trigger($.extend(i,{phase:"after"})),(new Date).getTime()-t}},update:function(){var e=(new Date).getTime();if(null==this.box)return 0;for(var t=this.last.range_start-1;t<=this.last.range_end-1;t++)if(!(0>t))for(var i=this.records[t],s=0;s<this.columns.length;s++){var n=$(this.box).find("#grid_"+this.name+"_data_"+t+"_"+s);n.html(this.getCellHTML(t,s,!1)),null==i.style||$.isEmptyObject(i.style)?n.attr("style",""):("string"==typeof i.style&&$(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(i.recid)).attr("style",i.style),$.isPlainObject(i.style)&&"string"==typeof i.style[s]&&n.attr("style",i.style[s]))}return(new Date).getTime()-e},refreshCell:function(e,t){var i=this.get(e,!0),s=this.records[i]&&this.records[i].recid==e?!1:!0,n=this.getColumn(t,!0),r=s?this.summary[i]:this.records[i],a=this.columns[n],o=$(this.box).find("#grid_"+this.name+"_data_"+i+"_"+n);o.html(this.getCellHTML(i,n,s)),r.changes&&"undefined"!=typeof r.changes[a.field]?o.addClass("w2ui-changed"):o.removeClass("w2ui-changed"),null==r.style||$.isEmptyObject(r.style)?o.attr("style",""):("string"==typeof r.style&&$(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(r.recid)).attr("style",r.style),$.isPlainObject(r.style)&&"string"==typeof r.style[n]&&o.attr("style",r.style[n]))},refreshRow:function(e){var t=$(this.box).find("#grid_"+this.name+"_rec_"+w2utils.escapeId(e));if(0!=t.length){var i=this.get(e,!0),s=t.attr("line"),n=this.records[i]&&this.records[i].recid==e?!1:!0,r="object"!=typeof this.url?this.url:this.url.get;if(this.searchData.length>0&&!r)for(var a=0;a<this.last.searchIds.length;a++)this.last.searchIds[a]==i&&(i=a);$(t).replaceWith(this.getRecordHTML(i,s,n)),n&&this.resize()}},refresh:function(){var e=this,t=(new Date).getTime(),i="object"!=typeof this.url?this.url:this.url.get;if(this.total<=0&&!i&&0==this.searchData.length&&(this.total=this.records.length),this.toolbar.disable("w2ui-edit","w2ui-delete"),this.box){var s=this.trigger({phase:"before",target:this.name,type:"refresh"});if(s.isCancelled!==!0){if(this.show.header?$("#grid_"+this.name+"_header").html(this.header+"&nbsp;").show():$("#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);else if($("#grid_"+this.name+"_toolbar").show(),"object"==typeof this.toolbar)for(var n=this.toolbar.items,r=0;r<n.length;r++)"w2ui-search"!=n[r].id&&"break"!=n[r].type&&this.toolbar.refresh(n[r].id)}else $("#grid_"+this.name+"_toolbar").hide();this.searchClose();var a=$("#grid_"+e.name+"_search_all");!this.multiSearch&&"all"==this.last.field&&this.searches.length>0&&(this.last.field=this.searches[0].field,this.last.caption=this.searches[0].caption);for(var o=0;o<this.searches.length;o++)this.searches[o].field==this.last.field&&(this.last.caption=this.searches[o].caption);if(this.last.multi?a.attr("placeholder","["+w2utils.lang("Multiple Fields")+"]"):a.attr("placeholder",this.last.caption),a.val()!=this.last.search){var l=this.last.search,n=a.data("w2field");n&&(l=n.format(l)),a.val(l)}var n=this.find({summary:!0},!0);if(n.length>0){for(var r=0;r<n.length;r++)this.summary.push(this.records[n[r]]);for(var r=n.length-1;r>=0;r--)this.records.splice(n[r],1);this.total=this.total-n.length}var d="";d+='<div id="grid_'+this.name+'_records" class="w2ui-grid-records"    onscroll="var obj = w2ui[\''+this.name+"'];         obj.last.scrollTop  = this.scrollTop;         obj.last.scrollLeft = this.scrollLeft;         $('#grid_"+this.name+"_columns')[0].scrollLeft = this.scrollLeft;        $('#grid_"+this.name+"_summary')[0].scrollLeft = this.scrollLeft;        obj.scroll(event);\">"+this.getRecordsHTML()+'</div><div id="grid_'+this.name+'_columns" class="w2ui-grid-columns">    <table>'+this.getColumnsHTML()+"</table></div>",$("#grid_"+this.name+"_body").html(d),this.summary.length>0?$("#grid_"+this.name+"_summary").html(this.getSummaryHTML()).show():$("#grid_"+this.name+"_summary").hide(),this.show.footer?$("#grid_"+this.name+"_footer").html(this.getFooterHTML()).show():$("#grid_"+this.name+"_footer").hide(),this.searchData.length>0?$("#grid_"+this.name+"_searchClear").show():$("#grid_"+this.name+"_searchClear").hide();var h=this.last.selection;h.indexes.length==this.records.length||0!==this.searchData.length&&h.indexes.length==this.last.searchIds.length?$("#grid_"+this.name+"_check_all").prop("checked",!0):$("#grid_"+this.name+"_check_all").prop("checked",!1),this.status();for(var u=e.find({expanded:!0},!0),c=0;c<u.length;c++)e.records[u[c]].expanded=!1;return setTimeout(function(){var t=$.trim($("#grid_"+e.name+"_search_all").val());""!=t&&e.markSearch&&$(e.box).find(".w2ui-grid-data > div").w2marker(t)},50),this.trigger($.extend(s,{phase:"after"})),e.resize(),e.addRange("selection"),setTimeout(function(){e.resize(),e.scroll()},1),e.reorderColumns&&!e.last.columnDrag?e.last.columnDrag=e.initColumnDrag():!e.reorderColumns&&e.last.columnDrag&&e.last.columnDrag.remove(),(new Date).getTime()-t}}},render:function(e){function t(e){if(1==e.which&&("text"==n.last.userSelect&&(delete n.last.userSelect,$(n.box).find(".w2ui-grid-body").css(w2utils.cssPrefix("user-select","none")),$(this.box).on("selectstart",function(){return!1})),!($(e.target).parents().hasClass("w2ui-head")||$(e.target).hasClass("w2ui-head")||n.last.move&&"expand"==n.last.move.type))){if(e.altKey)$(n.box).off("selectstart"),$(n.box).find(".w2ui-grid-body").css(w2utils.cssPrefix("user-select","text")),n.selectNone(),n.last.move={type:"text-select"},n.last.userSelect="text";else{if(!n.multiSelect)return;n.last.move={x:e.screenX,y:e.screenY,divX:0,divY:0,recid:$(e.target).parents("tr").attr("recid"),column:"TD"==e.target.tagName?$(e.target).attr("col"):$(e.target).parents("td").attr("col"),type:"select",ghost:!1,start:!0}}$(document).on("mousemove",i),$(document).on("mouseup",s)}}function i(e){var t=n.last.move;if(t&&"select"==t.type&&(t.divX=e.screenX-t.x,t.divY=e.screenY-t.y,!(Math.abs(t.divX)<=1&&Math.abs(t.divY)<=1))){if(n.last.cancelClick=!0,1==n.reorderRows){if(!t.ghost){var i=$("#grid_"+n.name+"_rec_"+t.recid),s=i.parents("table").find("tr:first-child").clone();t.offsetY=e.offsetY,t.from=t.recid,t.pos=i.position(),t.ghost=$(i).clone(!0),t.ghost.removeAttr("id"),i.find("td:first-child").replaceWith('<td colspan="1000" style="height: '+n.recordHeight+'px; background-color: #ddd"></td>');var r=$(n.box).find(".w2ui-grid-records");r.append('<table id="grid_'+n.name+'_ghost" style="position: absolute; z-index: 999999; opacity: 0.8; border-bottom: 2px dashed #aaa; border-top: 2px dashed #aaa; pointer-events: none;"></table>'),$("#grid_"+n.name+"_ghost").append(s).append(t.ghost)}var a=$(e.target).parents("tr").attr("recid");if(a!=t.from){var o=$("#grid_"+n.name+"_rec_"+t.recid),l=$("#grid_"+n.name+"_rec_"+a);e.screenY-t.lastY<0?o.after(l):l.after(o),t.lastY=e.screenY,t.to=a}var d=$("#grid_"+n.name+"_ghost"),r=$(n.box).find(".w2ui-grid-records");return void d.css({top:t.pos.top+t.divY+r.scrollTop(),left:t.pos.left})}t.start&&t.recid&&(n.selectNone(),t.start=!1);var h=[],a="TR"==e.target.tagName?$(e.target).attr("recid"):$(e.target).parents("tr").attr("recid");if("undefined"!=typeof a){var u=n.get(t.recid,!0);if(null!==u){var c=n.get(a,!0);if(null!==c){var p=parseInt(t.column),f=parseInt("TD"==e.target.tagName?$(e.target).attr("col"):$(e.target).parents("td").attr("col"));if(u>c){var s=u;u=c,c=s}var s="ind1:"+u+",ind2;"+c+",col1:"+p+",col2:"+f;if(t.range!=s){t.range=s;for(var g=u;c>=g;g++)if(!(n.last.searchIds.length>0&&-1==n.last.searchIds.indexOf(g)))if("row"!=n.selectType){if(p>f){var s=p;p=f,f=s}for(var s=[],m=p;f>=m;m++)n.columns[m].hidden||h.push({recid:n.records[g].recid,column:parseInt(m)})}else h.push(n.records[g].recid);if("row"!=n.selectType){for(var v=n.getSelection(),s=[],w=0;w<h.length;w++){for(var y=!1,b=0;b<v.length;b++)h[w].recid==v[b].recid&&h[w].column==v[b].column&&(y=!0);y||s.push({recid:h[w].recid,column:h[w].column})}n.select.apply(n,s);for(var s=[],b=0;b<v.length;b++){for(var y=!1,w=0;w<h.length;w++)h[w].recid==v[b].recid&&h[w].column==v[b].column&&(y=!0);y||s.push({recid:v[b].recid,column:v[b].column})}n.unselect.apply(n,s)}else if(n.multiSelect){for(var v=n.getSelection(),w=0;w<h.length;w++)-1==v.indexOf(h[w])&&n.select(h[w]);for(var b=0;b<v.length;b++)-1==h.indexOf(v[b])&&n.unselect(v[b])}}}}}}}function s(e){var t=n.last.move;if(setTimeout(function(){delete n.last.cancelClick},1),!$(e.target).parents().hasClass(".w2ui-head")&&!$(e.target).hasClass(".w2ui-head")){if(t&&"select"==t.type&&1==n.reorderRows){var r=n.get(t.from,!0),a=n.records[r];n.records.splice(r,1);var o=n.get(t.to,!0);r>o?n.records.splice(o,0,a):n.records.splice(o+1,0,a),$("#grid_"+n.name+"_ghost").remove(),n.refresh()}delete n.last.move,$(document).off("mousemove",i),$(document).off("mouseup",s)}}var n=this,r=(new Date).getTime();if(null!=e&&($(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),this.box=e),this.box){null==this.last.sortData&&(this.last.sortData=this.sortData);var a=this.trigger({phase:"before",target:this.name,type:"render",box:e});if(a.isCancelled!==!0){if(this.reset(!0),$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-grid").html('<div>    <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+'_summary" class="w2ui-grid-body w2ui-grid-summary"></div>    <div id="grid_'+this.name+'_footer" class="w2ui-grid-footer"></div></div>'),"row"!=this.selectType&&$(this.box).addClass("w2ui-ss"),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.initToolbar(),null!=this.toolbar&&this.toolbar.render($("#grid_"+this.name+"_toolbar")[0]),this.last.field&&"all"!=this.last.field){var o=this.searchData;setTimeout(function(){n.initAllField(n.last.field,1==o.length?o[0].value:null)},1)}return $("#grid_"+this.name+"_footer").html(this.getFooterHTML()),this.last.state||(this.last.state=this.stateSave(!0)),this.stateRestore(),this.url&&this.refresh(),this.reload(),$(this.box).on("mousedown",t),$(this.box).on("selectstart",function(){return!1}),this.trigger($.extend(a,{phase:"after"})),0==$(".w2ui-layout").length&&(this.tmp_resize=function(){w2ui[n.name].resize()},$(window).off("resize",this.tmp_resize).on("resize",this.tmp_resize)),(new Date).getTime()-r}}},destroy:function(){var e=this.trigger({phase:"before",target:this.name,type:"destroy"});e.isCancelled!==!0&&(this.tmp_resize&&$(window).off("resize",this.tmp_resize),"object"==typeof this.toolbar&&this.toolbar.destroy&&this.toolbar.destroy(),$(this.box).find("#grid_"+this.name+"_body").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-grid").html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})))},initColumnOnOff:function(){if(this.show.toolbarColumns){for(var e=this,t='<div class="w2ui-col-on-off"><table><tr><td style="width: 30px">    <input id="grid_'+this.name+'_column_ln_check" type="checkbox" tabIndex="-1" '+(e.show.lineNumbers?"checked":"")+"        onclick=\"w2ui['"+e.name+"'].columnOnOff(this, event, 'line-numbers');\"></td><td onclick=\"w2ui['"+e.name+"'].columnOnOff(this, event, 'line-numbers'); $(document).click();\">    <label for=\"grid_"+this.name+'_column_ln_check">'+w2utils.lang("Line #")+"</label></td></tr>",i=0;i<this.columns.length;i++){var s=this.columns[i],n=this.columns[i].caption;s.hideable!==!1&&(!n&&this.columns[i].hint&&(n=this.columns[i].hint),n||(n="- column "+(parseInt(i)+1)+" -"),t+='<tr><td style="width: 30px">    <input id="grid_'+this.name+"_column_"+i+'_check" type="checkbox" tabIndex="-1" '+(s.hidden?"":"checked")+"        onclick=\"w2ui['"+e.name+"'].columnOnOff(this, event, '"+s.field+'\');"></td><td>    <label for="grid_'+this.name+"_column_"+i+'_check">'+n+"</label></td></tr>")}t+='<tr><td colspan="2"><div style="border-top: 1px solid #ddd;"></div></td></tr>';var r="object"!=typeof this.url?this.url:this.url.get;r&&e.show.skipRecords&&(t+='<tr><td colspan="2" style="padding: 0px">    <div style="cursor: pointer; padding: 2px 8px; cursor: default">'+w2utils.lang("Skip")+'        <input type="text" style="width: 45px" value="'+this.offset+'"             onkeypress="if (event.keyCode == 13) {                w2ui[\''+e.name+"'].skip(this.value);                $(document).click();             }\"> "+w2utils.lang("Records")+"    </div></td></tr>"),t+='<tr><td colspan="2" onclick="w2ui[\''+e.name+'\'].stateSave(); $(document).click();">    <div style="cursor: pointer; padding: 4px 8px; cursor: default">'+w2utils.lang("Save Grid State")+'</div></td></tr><tr><td colspan="2" onclick="w2ui[\''+e.name+'\'].stateReset(); $(document).click();">    <div style="cursor: pointer; padding: 4px 8px; cursor: default">'+w2utils.lang("Restore Default State")+"</div></td></tr>",t+="</table></div>",this.toolbar.get("w2ui-column-on-off").html=t}},initColumnDrag:function(){function e(){l.pressed=!1,clearTimeout(l.timeout)}function t(e){l.timeout&&clearTimeout(l.timeout);var t=this;l.pressed=!0,l.timeout=setTimeout(function(){if(l.pressed){var n,r,a,d,h,u=["w2ui-col-number","w2ui-col-expand","w2ui-col-select"],c=["w2ui-head-last"],p=u.concat(c),f=".w2ui-col-number, .w2ui-col-expand, .w2ui-col-select",g=".w2ui-head.w2ui-col-number, .w2ui-head.w2ui-col-expand, .w2ui-head.w2ui-col-select";if($(e.originalEvent.target).parents().hasClass("w2ui-head")){for(var m=0,v=p.length;v>m;m++)if($(e.originalEvent.target).parents().hasClass(p[m]))return;if(l.numberPreColumnsPresent=$(o.box).find(g).length,l.columnHead=d=$(e.originalEvent.target).parents(".w2ui-head"),h=parseInt(d.attr("col"),10),n=o.trigger({type:"columnDragStart",phase:"before",originalEvent:e,origColumnNumber:h,target:d[0]}),n.isCancelled===!0)return!1;r=l.columns=$(o.box).find(".w2ui-head:not(.w2ui-head-last)"),$(document).on("mouseup",s),$(document).on("mousemove",i),l.originalPos=parseInt($(e.originalEvent.target).parent(".w2ui-head").attr("col"),10),l.ghost=$(t).clone(!0),$(l.ghost).find('[col]:not([col="'+l.originalPos+'"]), .w2ui-toolbar, .w2ui-grid-header').remove(),$(l.ghost).find(f).remove(),$(l.ghost).find(".w2ui-grid-body").css({top:0}),a=$(l.ghost).find('[col="'+l.originalPos+'"]'),$(document.body).append(l.ghost),$(l.ghost).css({width:0,height:0,margin:0,position:"fixed",zIndex:999999,opacity:0}).addClass(".w2ui-grid-ghost").animate({width:a.width(),height:$(o.box).find(".w2ui-grid-body:first").height(),left:e.pageX,top:e.pageY,opacity:.8},0),l.offsets=[];for(var m=0,v=r.length;v>m;m++)l.offsets.push($(r[m]).offset().left);o.trigger($.extend(n,{phase:"after"}))}}},150)}function i(e){if(l.pressed){var t=e.originalEvent.pageX,i=e.originalEvent.pageY,s=l.offsets,o=$(".w2ui-head:not(.w2ui-head-last)").width();l.targetInt=Math.max(l.numberPreColumnsPresent,r(t,s,o)),n(l.targetInt),a(t,i)}}function s(e){l.pressed=!1;var t,n,r,a,d,h=$(".w2ui-grid-ghost");return t=o.trigger({type:"columnDragEnd",phase:"before",originalEvent:e,target:l.columnHead[0]}),t.isCancelled===!0?!1:(r=o.columns[l.originalPos],a=o.columns,d=$(l.columns[Math.min(l.lastInt,l.columns.length-1)]),n=l.lastInt<l.columns.length?parseInt(d.attr("col")):a.length,n!==l.originalPos+1&&n!==l.originalPos&&d&&d.length?($(l.ghost).animate({top:$(o.box).offset().top,left:d.offset().left,width:0,height:0,opacity:.2},300,function(){$(this).remove(),h.remove()}),a.splice(n,0,$.extend({},r)),a.splice(a.indexOf(r),1)):($(l.ghost).remove(),h.remove()),$(document).off("mouseup",s),$(document).off("mousemove",i),l.marker&&l.marker.remove(),l={},o.refresh(),void o.trigger($.extend(t,{phase:"after",targetColumnNumber:n-1})))}function n(e){l.marker||l.markerLeft||(l.marker=$('<div class="col-intersection-marker"><div class="top-marker"></div><div class="bottom-marker"></div></div>'),l.markerLeft=$('<div class="col-intersection-marker"><div class="top-marker"></div><div class="bottom-marker"></div></div>')),l.lastInt&&l.lastInt===e||(l.lastInt=e,l.marker.remove(),l.markerLeft.remove(),$(".w2ui-head").removeClass("w2ui-col-intersection"),e>=l.columns.length?($(l.columns[l.columns.length-1]).children("div:last").append(l.marker.addClass("right").removeClass("left")),$(l.columns[l.columns.length-1]).addClass("w2ui-col-intersection")):e<=l.numberPreColumnsPresent?($(l.columns[l.numberPreColumnsPresent]).prepend(l.marker.addClass("left").removeClass("right")).css({position:"relative"}),$(l.columns[l.numberPreColumnsPresent]).prev().addClass("w2ui-col-intersection")):($(l.columns[e]).children("div:last").prepend(l.marker.addClass("left").removeClass("right")),$(l.columns[e]).prev().children("div:last").append(l.markerLeft.addClass("right").removeClass("left")).css({position:"relative"}),$(l.columns[e-1]).addClass("w2ui-col-intersection")))}function r(e,t,i){if(e<=t[0])return 0;if(e>=t[t.length-1]+i)return t.length;for(var s=0,n=t.length;n>s;s++){var r=t[s],a=t[s+1]||t[s]+i,o=(a-t[s])/2+t[s];if(e>r&&o>=e)return s;if(e>o&&a>=e)return s+1}return intersection}function a(e,t){$(l.ghost).css({left:e-10,top:t-10})}if(this.columnGroups&&this.columnGroups.length)throw"Draggable columns are not currently supported with column groups.";var o=this,l={};return l.lastInt=null,l.pressed=!1,l.timeout=null,l.columnHead=null,$(o.box).on("mousedown",t),$(o.box).on("mouseup",e),{remove:function(){$(o.box).off("mousedown",t),$(o.box).off("mouseup",e),$(o.box).find(".w2ui-head").removeAttr("draggable"),o.last.columnDrag=!1}}},columnOnOff:function(e,t,i){var s=this.trigger({phase:"before",target:this.name,type:"columnOnOff",checkbox:e,field:i,originalEvent:t});if(s.isCancelled!==!0){for(var n=this,r=0;r<this.records.length;r++)this.records[r].expanded===!0&&(this.records[r].expanded=!1);var a=!0;if("line-numbers"==i)this.show.lineNumbers=!this.show.lineNumbers,this.refresh();else{var o=this.getColumn(i);o.hidden?($(e).prop("checked",!0),this.showColumn(o.field)):($(e).prop("checked",!1),this.hideColumn(o.field)),a=!1}a&&setTimeout(function(){$().w2overlay("",{name:"searches-"+this.name}),n.toolbar.uncheck("column-on-off")},100),this.trigger($.extend(s,{phase:"after"}))}},initToolbar:function(){if("undefined"==typeof this.toolbar.render){var e=this.toolbar.items;if(this.toolbar.items=[],this.toolbar=$().w2toolbar($.extend(!0,{},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.show.toolbarReload&&this.toolbar.items.push($.extend(!0,{},this.buttons.reload)),this.show.toolbarColumns&&this.toolbar.items.push($.extend(!0,{},this.buttons.columns)),(this.show.toolbarReload||this.show.toolbarColumn)&&this.toolbar.items.push({type:"break",id:"w2ui-break0"}),this.show.toolbarSearch){var t='<div class="w2ui-toolbar-search"><table cellpadding="0" cellspacing="0"><tr>    <td>'+this.buttons.search.html+'</td>    <td>        <input id="grid_'+this.name+'_search_all" class="w2ui-search-all"             placeholder="'+this.last.caption+'" value="'+this.last.search+'"            onkeydown="if (event.keyCode == 13 && w2utils.isIE) this.onchange();"            onchange="                var grid = w2ui[\''+this.name+"'];                 var val = this.value;                 var sel = $(this).data('selected');                var fld = $(this).data('w2field');                 if (fld) val = fld.clean(val);                if (fld && fld.type == 'list' && sel && typeof sel.id == 'undefined') {                   grid.searchReset();                } else {                   grid.search(grid.last.field, val);                }            \">    </td>    <td>        <div title=\""+w2utils.lang("Clear Search")+'" class="w2ui-search-clear" id="grid_'+this.name+'_searchClear"               onclick="var obj = w2ui[\''+this.name+"']; obj.searchReset();\"         >&nbsp;&nbsp;</div>    </td></tr></table></div>";this.toolbar.items.push({type:"html",id:"w2ui-search",html:t}),this.multiSearch&&this.searches.length>0&&this.toolbar.items.push($.extend(!0,{},this.buttons["search-go"]))}if(this.show.toolbarSearch&&(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($.extend(!0,{},this.buttons.add)),this.show.toolbarEdit&&this.toolbar.items.push($.extend(!0,{},this.buttons.edit)),this.show.toolbarDelete&&this.toolbar.items.push($.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($.extend(!0,{},this.buttons.save))),e)for(var i=0;i<e.length;i++)this.toolbar.items.push(e[i]);var s=this;this.toolbar.on("click",function(e){function t(){$("#w2ui-overlay-searches-"+s.name).data("keepOpen")!==!0&&(a.uncheck(n),$(document).off("click","body",t))}var i=s.trigger({phase:"before",type:"toolbar",target:e.target,originalEvent:e});if(i.isCancelled!==!0){var n=e.target;switch(n){case"w2ui-reload":var r=s.trigger({phase:"before",type:"reload",target:s.name});if(r.isCancelled===!0)return!1;s.reload(),s.trigger($.extend(r,{phase:"after"}));break;case"w2ui-column-on-off":s.initColumnOnOff(),s.initResize(),s.resize();break;case"w2ui-search-advanced":var a=this,o=this.get(n);o.checked?(s.searchClose(),setTimeout(function(){a.uncheck(n)},1)):(s.searchOpen(),e.originalEvent.stopPropagation(),$(document).on("click","body",t));break;case"w2ui-add":var i=s.trigger({phase:"before",target:s.name,type:"add",recid:null});s.trigger($.extend(i,{phase:"after"}));break;case"w2ui-edit":var l=s.getSelection(),d=null;1==l.length&&(d=l[0]);var i=s.trigger({phase:"before",target:s.name,type:"edit",recid:d});s.trigger($.extend(i,{phase:"after"}));break;case"w2ui-delete":s["delete"]();break;case"w2ui-save":s.save()}s.trigger($.extend(i,{phase:"after"}))}})}},initResize:function(){var e=this;$(this.box).find(".w2ui-resizer").off("click").on("click",function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,e.preventDefault&&e.preventDefault()}).off("mousedown").on("mousedown",function(t){t||(t=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),e.resizing=!0,e.last.tmp={x:t.screenX,y:t.screenY,gx:t.screenX,gy:t.screenY,col:parseInt($(this).attr("name"))},t.stopPropagation?t.stopPropagation():t.cancelBubble=!0,t.preventDefault&&t.preventDefault();for(var i=0;i<e.columns.length;i++)"undefined"==typeof e.columns[i].sizeOriginal&&(e.columns[i].sizeOriginal=e.columns[i].size),e.columns[i].size=e.columns[i].sizeCalculated;var s={phase:"before",type:"columnResize",target:e.name,column:e.last.tmp.col,field:e.columns[e.last.tmp.col].field};s=e.trigger($.extend(s,{resizeBy:0,originalEvent:t}));var n=function(t){if(1==e.resizing){if(t||(t=window.event),s=e.trigger($.extend(s,{resizeBy:t.screenX-e.last.tmp.gx,originalEvent:t})),s.isCancelled===!0)return void(s.isCancelled=!1);e.last.tmp.x=t.screenX-e.last.tmp.x,e.last.tmp.y=t.screenY-e.last.tmp.y,e.columns[e.last.tmp.col].size=parseInt(e.columns[e.last.tmp.col].size)+e.last.tmp.x+"px",e.resizeRecords(),e.last.tmp.x=t.screenX,e.last.tmp.y=t.screenY}},r=function(t){delete e.resizing,$(document).off("mousemove","body"),$(document).off("mouseup","body"),e.resizeRecords(),e.trigger($.extend(s,{phase:"after",originalEvent:t}))};$(document).on("mousemove","body",n),$(document).on("mouseup","body",r)}).each(function(e,t){var i=$(t).parent();$(t).css({height:"25px","margin-left":i.width()-3+"px"})})},resizeBoxes:function(){{var e=($(this.box).find("> div"),$("#grid_"+this.name+"_header")),t=$("#grid_"+this.name+"_toolbar"),i=$("#grid_"+this.name+"_summary"),s=$("#grid_"+this.name+"_footer"),n=$("#grid_"+this.name+"_body");$("#grid_"+this.name+"_columns"),$("#grid_"+this.name+"_records")}this.show.header&&e.css({top:"0px",left:"0px",right:"0px"}),this.show.toolbar&&t.css({top:0+(this.show.header?w2utils.getSize(e,"height"):0)+"px",left:"0px",right:"0px"}),this.show.footer&&s.css({bottom:"0px",left:"0px",right:"0px"}),this.summary.length>0&&i.css({bottom:0+(this.show.footer?w2utils.getSize(s,"height"):0)+"px",left:"0px",right:"0px"}),n.css({top:0+(this.show.header?w2utils.getSize(e,"height"):0)+(this.show.toolbar?w2utils.getSize(t,"height"):0)+"px",bottom:0+(this.show.footer?w2utils.getSize(s,"height"):0)+(this.summary.length>0?w2utils.getSize(i,"height"):0)+"px",left:"0px",right:"0px"})},resizeRecords:function(){var e=this;$(this.box).find(".w2ui-empty-record").remove();var t=$(this.box),i=$(this.box).find("> div"),s=$("#grid_"+this.name+"_header"),n=$("#grid_"+this.name+"_toolbar"),r=$("#grid_"+this.name+"_summary"),a=$("#grid_"+this.name+"_footer"),o=$("#grid_"+this.name+"_body"),l=$("#grid_"+this.name+"_columns"),d=$("#grid_"+this.name+"_records"),h=8*String(this.total).length+10;if(34>h&&(h=34),this.fixedBody){var u=i.height()-(this.show.header?w2utils.getSize(s,"height"):0)-(this.show.toolbar?w2utils.getSize(n,"height"):0)-("none"!=r.css("display")?w2utils.getSize(r,"height"):0)-(this.show.footer?w2utils.getSize(a,"height"):0);o.css("height",u)}else{var u=w2utils.getSize(l,"height")+w2utils.getSize($("#grid_"+e.name+"_records table"),"height");e.height=u+w2utils.getSize(i,"+height")+(e.show.header?w2utils.getSize(s,"height"):0)+(e.show.toolbar?w2utils.getSize(n,"height"):0)+("none"!=r.css("display")?w2utils.getSize(r,"height"):0)+(e.show.footer?w2utils.getSize(a,"height"):0),i.css("height",e.height),o.css("height",u),t.css("height",w2utils.getSize(i,"height")+w2utils.getSize(t,"+height"))}var c=this.records.length;0==this.searchData.length||this.url||(c=this.last.searchIds.length);var p=!1,f=!1;if(o.width()<$(d).find(">table").width()&&(p=!0),o.height()-l.height()<$(d).find(">table").height()+(p?w2utils.scrollBarSize():0)&&(f=!0),this.fixedBody||(f=!1,p=!1),p||f?(l.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show(),d.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(l,"height")+"px","-webkit-overflow-scrolling":"touch","overflow-x":p?"auto":"hidden","overflow-y":f?"auto":"hidden"})):(l.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").hide(),d.css({top:(this.columnGroups.length>0&&this.show.columns?1:0)+w2utils.getSize(l,"height")+"px",overflow:"hidden"}),d.length>0&&(this.last.scrollTop=0,this.last.scrollLeft=0)),this.show.emptyRecords&&!f){var g=Math.floor(d.height()/this.recordHeight)+1;if(this.fixedBody)for(var m=c;g>=m;m++){var v="";v+='<tr class="'+(m%2?"w2ui-even":"w2ui-odd")+' w2ui-empty-record" style="height: '+this.recordHeight+'px">',this.show.lineNumbers&&(v+='<td class="w2ui-col-number"></td>'),this.show.selectColumn&&(v+='<td class="w2ui-grid-data w2ui-col-select"></td>'),this.show.expandColumn&&(v+='<td class="w2ui-grid-data w2ui-col-expand"></td>');for(var w=0;this.columns.length>0;){var y=this.columns[w];if(y.hidden){if(w++,"undefined"==typeof this.columns[w])break}else if(v+='<td class="w2ui-grid-data" '+("undefined"!=typeof y.attr?y.attr:"")+' col="'+w+'"></td>',w++,"undefined"==typeof this.columns[w])break}v+='<td class="w2ui-grid-data-last"></td>',v+="</tr>",$("#grid_"+this.name+"_records > table").append(v)}}if(o.length>0){for(var b=parseInt(o.width())-(f?w2utils.scrollBarSize():0)-(this.show.lineNumbers?h:0)-(this.show.selectColumn?26:0)-(this.show.expandColumn?26:0),x=b,_=0,k=!1,C=0;C<this.columns.length;C++){var y=this.columns[C];
  y.gridMinWidth>0&&(y.gridMinWidth>x&&y.hidden!==!0&&(y.hidden=!0,k=!0),y.gridMinWidth<x&&y.hidden===!0&&(y.hidden=!1,k=!0))}if(k===!0)return void this.refresh();for(var C=0;C<this.columns.length;C++){var y=this.columns[C];y.hidden||("px"==String(y.size).substr(String(y.size).length-2).toLowerCase()?(b-=parseFloat(y.size),this.columns[C].sizeCalculated=y.size,this.columns[C].sizeType="px"):(_+=parseFloat(y.size),this.columns[C].sizeType="%",delete y.sizeCorrected))}if(100!=_&&_>0)for(var C=0;C<this.columns.length;C++){var y=this.columns[C];y.hidden||"%"==y.sizeType&&(y.sizeCorrected=Math.round(100*parseFloat(y.size)*100/_)/100+"%")}for(var C=0;C<this.columns.length;C++){var y=this.columns[C];y.hidden||"%"==y.sizeType&&(this.columns[C].sizeCalculated="undefined"!=typeof this.columns[C].sizeCorrected?Math.floor(b*parseFloat(y.sizeCorrected)/100)-1+"px":Math.floor(b*parseFloat(y.size)/100)-1+"px")}}for(var T=0,C=0;C<this.columns.length;C++){var y=this.columns[C];y.hidden||("undefined"==typeof y.min&&(y.min=20),parseInt(y.sizeCalculated)<parseInt(y.min)&&(y.sizeCalculated=y.min+"px"),parseInt(y.sizeCalculated)>parseInt(y.max)&&(y.sizeCalculated=y.max+"px"),T+=parseInt(y.sizeCalculated))}var S=parseInt(x)-parseInt(T);if(S>0&&_>0)for(var C=0;;){var y=this.columns[C];if("undefined"!=typeof y)if(y.hidden||"px"==y.sizeType)C++;else{if(y.sizeCalculated=parseInt(y.sizeCalculated)+1+"px",S--,0==S)break;C++}else C=0}else S>0&&l.find("> table > tbody > tr:nth-child(1) td.w2ui-head-last").css("width",w2utils.scrollBarSize()).show();l.find("> table > tbody > tr:nth-child(1) td").each(function(t,i){$(i).hasClass("w2ui-col-number")&&$(i).css("width",h);var s=$(i).attr("col");"undefined"!=typeof s&&e.columns[s]&&$(i).css("width",e.columns[s].sizeCalculated),$(i).hasClass("w2ui-head-last")&&$(i).css("width",w2utils.scrollBarSize()+(S>0&&0==_?S:0)+"px")}),3==l.find("> table > tbody > tr").length&&l.find("> table > tbody > tr:nth-child(1) td").html("").css({height:"0px",border:"0px",padding:"0px",margin:"0px"}),d.find("> table > tbody > tr:nth-child(1) td").each(function(t,i){$(i).hasClass("w2ui-col-number")&&$(i).css("width",h);var s=$(i).attr("col");"undefined"!=typeof s&&e.columns[s]&&$(i).css("width",e.columns[s].sizeCalculated),$(i).hasClass("w2ui-grid-data-last")&&$(i).css("width",(S>0&&0==_?S:0)+"px")}),r.find("> table > tbody > tr:nth-child(1) td").each(function(t,i){$(i).hasClass("w2ui-col-number")&&$(i).css("width",h);var s=$(i).attr("col");"undefined"!=typeof s&&e.columns[s]&&$(i).css("width",e.columns[s].sizeCalculated),$(i).hasClass("w2ui-grid-data-last")&&$(i).css("width",w2utils.scrollBarSize()+(S>0&&0==_?S:0)+"px")}),this.initResize(),this.refreshRanges(),(this.last.scrollTop||this.last.scrollLeft)&&d.length>0&&(l.prop("scrollLeft",this.last.scrollLeft),d.prop("scrollTop",this.last.scrollTop),d.prop("scrollLeft",this.last.scrollLeft))},getSearchesHTML:function(){for(var e='<table cellspacing="0">',t=!1,i=0;i<this.searches.length;i++){var s=this.searches[i];if(s.type=String(s.type).toLowerCase(),!s.hidden){var n="";if(0==t&&(n='<button class="w2ui-btn close-btn" onclick="obj = w2ui[\''+this.name+"']; if (obj) { obj.searchClose(); }\">X</button",t=!0),"undefined"==typeof s.inTag&&(s.inTag=""),"undefined"==typeof s.outTag&&(s.outTag=""),"undefined"==typeof s.type&&(s.type="text"),-1!=["text","alphanumeric","combo"].indexOf(s.type))var r='<select id="grid_'+this.name+"_operator_"+i+'" onclick="event.stopPropagation();">    <option value="is">'+w2utils.lang("is")+'</option>    <option value="begins">'+w2utils.lang("begins")+'</option>    <option value="contains">'+w2utils.lang("contains")+'</option>    <option value="ends">'+w2utils.lang("ends")+"</option></select>";if(-1!=["int","float","money","currency","percent","date","time"].indexOf(s.type))var r='<select id="grid_'+this.name+"_operator_"+i+'"         onchange="w2ui[\''+this.name+"'].initOperator(this, "+i+');" onclick="event.stopPropagation();">    <option value="is">'+w2utils.lang("is")+"</option>"+(-1!=["int"].indexOf(s.type)?'<option value="in">'+w2utils.lang("in")+"</option>":"")+(-1!=["int"].indexOf(s.type)?'<option value="not in">'+w2utils.lang("not in")+"</option>":"")+'<option value="between">'+w2utils.lang("between")+"</option></select>";if(-1!=["select","list","hex"].indexOf(s.type))var r='<select id="grid_'+this.name+"_operator_"+i+'" onclick="event.stopPropagation();">    <option value="is">'+w2utils.lang("is")+"</option></select>";if(-1!=["enum"].indexOf(s.type))var r='<select id="grid_'+this.name+"_operator_"+i+'" onclick="event.stopPropagation();">    <option value="in">'+w2utils.lang("in")+'</option>    <option value="not in">'+w2utils.lang("not in")+"</option></select>";switch(e+='<tr>    <td class="close-btn">'+n+'</td>    <td class="caption">'+s.caption+'</td>    <td class="operator">'+r+'</td>    <td class="value">',s.type){case"text":case"alphanumeric":case"hex":case"list":case"combo":case"enum":e+='<input rel="search" type="text" style="width: 300px;" id="grid_'+this.name+"_field_"+i+'" name="'+s.field+'" '+s.inTag+">";break;case"int":case"float":case"money":case"currency":case"percent":case"date":case"time":e+='<input rel="search" type="text" size="12" id="grid_'+this.name+"_field_"+i+'" name="'+s.field+'" '+s.inTag+'><span id="grid_'+this.name+"_range_"+i+'" style="display: none">&nbsp;-&nbsp;&nbsp;<input rel="search" type="text" style="width: 90px" id="grid_'+this.name+"_field2_"+i+'" name="'+s.field+'" '+s.inTag+"></span>";break;case"select":e+='<select rel="search" id="grid_'+this.name+"_field_"+i+'" name="'+s.field+'" '+s.inTag+'  onclick="event.stopPropagation();"></select>'}e+=s.outTag+"    </td></tr>"}}return e+='<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></table>"},initOperator:function(e,t){var i=this,s=i.searches[t],n=$("#grid_"+i.name+"_range_"+t),r=$("#grid_"+i.name+"_field_"+t),a=r.parent().find("span input");r.w2field("in"==$(e).val()||"not in"==$(e).val()?"clear":s.type),"between"==$(e).val()?(n.show(),a.w2field(s.type)):n.hide()},initSearches:function(){for(var e=this,t=0;t<this.searches.length;t++){var i=this.searches[t],s=this.getSearchData(i.field),n=null;switch(i.type=String(i.type).toLowerCase(),"object"!=typeof i.options&&(i.options={}),i.type){case"text":case"alphanumeric":n="begins",i.operator&&-1!=["is","begins","contains","ends"].indexOf(i.operator)&&(n=i.operator),-1!=["alphanumeric","hex"].indexOf(i.type)&&$("#grid_"+this.name+"_field_"+t).w2field(i.type,i.options);break;case"int":case"float":case"money":case"currency":case"percent":case"date":case"time":if(s&&"int"==s.type&&-1!=["in","not in"].indexOf(s.operator))break;n="is",i.operator&&-1!=["is","between"].indexOf(i.operator)&&(n=i.operator),$("#grid_"+this.name+"_field_"+t).w2field(i.type,i.options),$("#grid_"+this.name+"_field2_"+t).w2field(i.type,i.options),setTimeout(function(){$("#grid_"+e.name+"_field_"+t).keydown(),$("#grid_"+e.name+"_field2_"+t).keydown()},1);break;case"hex":n="is",i.operator&&-1!=["is","between"].indexOf(i.operator)&&(n=i.operator);break;case"list":case"combo":case"enum":"list"==i.type&&(n="is"),"combo"==i.type&&(n="begins",i.operator&&-1!=["is","begins","contains","ends"].indexOf(i.operator)&&(n=i.operator)),"enum"==i.type&&(n="in",i.operator&&-1!=["in","not in"].indexOf(i.operator)&&(n=i.operator));var r=i.options;"list"==i.type&&(r.selected={}),"enum"==i.type&&(r.selected=[]),s&&(r.selected=s.value),$("#grid_"+this.name+"_field_"+t).w2field(i.type,$.extend({openOnFocus:!0},r));break;case"select":n="is";for(var r='<option value="">--</option>',a=0;a<i.options.items;a++){var o=i.options.items[a];if($.isPlainObject(i.options.items[a])){var l=o.id,d=o.text;"undefined"==typeof l&&"undefined"!=typeof o.value&&(l=o.value),"undefined"==typeof d&&"undefined"!=typeof o.caption&&(d=o.caption),null==l&&(l=""),r+='<option value="'+l+'">'+d+"</option>"}else r+='<option value="'+o+'">'+o+"</option>"}$("#grid_"+this.name+"_field_"+t).html(r)}null!=s?("int"==s.type&&-1!=["in","not in"].indexOf(s.operator)&&$("#grid_"+this.name+"_field_"+t).w2field("clear").val(s.value),$("#grid_"+this.name+"_operator_"+t).val(s.operator).trigger("change"),$.isArray(s.value)?-1!=["in","not in"].indexOf(s.operator)?$("#grid_"+this.name+"_field_"+t).val(s.value).trigger("change"):($("#grid_"+this.name+"_field_"+t).val(s.value[0]).trigger("change"),$("#grid_"+this.name+"_field2_"+t).val(s.value[1]).trigger("change")):"udefined"!=typeof s.value&&$("#grid_"+this.name+"_field_"+t).val(s.value).trigger("change")):$("#grid_"+this.name+"_operator_"+t).val(n).trigger("change")}$("#w2ui-overlay-searches-"+this.name+" .w2ui-grid-searches *[rel=search]").on("keypress",function(t){13==t.keyCode&&(e.search(),$().w2overlay())})},getColumnsHTML:function(){function e(){var e="<tr>";""!=i.columnGroups[i.columnGroups.length-1].caption&&i.columnGroups.push({caption:""}),i.show.lineNumbers&&(e+='<td class="w2ui-head w2ui-col-number">    <div>&nbsp;</div></td>'),i.show.selectColumn&&(e+='<td class="w2ui-head w2ui-col-select">    <div>&nbsp;</div></td>'),i.show.expandColumn&&(e+='<td class="w2ui-head w2ui-col-expand">    <div>&nbsp;</div></td>');for(var t=0,s=0;s<i.columnGroups.length;s++){var n=i.columnGroups[s],r=i.columns[t];if(("undefined"==typeof n.span||n.span!=parseInt(n.span))&&(n.span=1),"undefined"!=typeof n.colspan&&(n.span=n.colspan),n.master===!0){for(var a="",o=0;o<i.sortData.length;o++)i.sortData[o].field==r.field&&(new RegExp("asc","i").test(i.sortData[o].direction)&&(a="w2ui-sort-up"),new RegExp("desc","i").test(i.sortData[o].direction)&&(a="w2ui-sort-down"));var l="";r.resizable!==!1&&(l='<div class="w2ui-resizer" name="'+t+'"></div>'),e+='<td id="grid_'+i.name+"_column_"+t+'" class="w2ui-head '+a+'" col="'+t+'" rowspan="2" colspan="'+(n.span+(s==i.columnGroups.length-1?1:0))+'"     onclick="w2ui[\''+i.name+"'].columnClick('"+r.field+"', event);\">"+l+'    <div class="w2ui-col-group w2ui-col-header '+(a?"w2ui-col-sorted":"")+'">        <div class="'+a+'"></div>'+(r.caption?r.caption:"&nbsp;")+"    </div></td>"}else e+='<td id="grid_'+i.name+"_column_"+t+'" class="w2ui-head" col="'+t+'"         colspan="'+(n.span+(s==i.columnGroups.length-1?1:0))+'">    <div class="w2ui-col-group">'+(n.caption?n.caption:"&nbsp;")+"    </div></td>";t+=n.span}return e+="</tr>"}function t(e){var t="<tr>",s=!i.reorderColumns||i.columnGroups&&i.columnGroups.length?"":" w2ui-reorder-cols-head ";i.show.lineNumbers&&(t+='<td class="w2ui-head w2ui-col-number" onclick="w2ui[\''+i.name+"'].columnClick('line-number', event);\">    <div>#</div></td>"),i.show.selectColumn&&i.show.selectColumn_All?t+='<td class="w2ui-head w2ui-col-select"         onclick="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">    <div>        <input type="checkbox" id="grid_'+i.name+'_check_all" tabIndex="-1"            style="'+(0==i.multiSelect?"display: none;":"")+'"            onclick="if (this.checked) w2ui[\''+i.name+"'].selectAll();                      else w2ui['"+i.name+"'].selectNone();                      if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;\">    </div></td>":i.show.selectColumn&&!i.show.selectColumn_All&&(t+='<td class="w2ui-head w2ui-col-select"         onclick="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">    &nbsp;</td>'),i.show.expandColumn&&(t+='<td class="w2ui-head w2ui-col-expand">    <div>&nbsp;</div></td>');for(var n=0,r=0,a=0;a<i.columns.length;a++){var o=i.columns[a],l={};if(a==r&&(r+="undefined"!=typeof i.columnGroups[n]?parseInt(i.columnGroups[n].span):0,n++),"undefined"!=typeof i.columnGroups[n-1])var l=i.columnGroups[n-1];if(!o.hidden){for(var d="",h=0;h<i.sortData.length;h++)i.sortData[h].field==o.field&&(new RegExp("asc","i").test(i.sortData[h].direction)&&(d="w2ui-sort-up"),new RegExp("desc","i").test(i.sortData[h].direction)&&(d="w2ui-sort-down"));if(l.master!==!0||e){var u="";o.resizable!==!1&&(u='<div class="w2ui-resizer" name="'+a+'"></div>'),t+='<td id="grid_'+i.name+"_column_"+a+'" col="'+a+'" class="w2ui-head '+d+s+'"     onclick="w2ui[\''+i.name+"'].columnClick('"+o.field+"', event);\">"+u+'    <div class="w2ui-col-header '+(d?"w2ui-col-sorted":"")+'">        <div class="'+d+'"></div>'+(o.caption?o.caption:"&nbsp;")+"    </div></td>"}}}return t+='<td class="w2ui-head w2ui-head-last"><div>&nbsp;</div></td>',t+="</tr>"}var i=this,s="";return this.show.columnHeaders&&(s=this.columnGroups.length>0?t(!0)+e()+t(!1):t(!0)),s},getRecordsHTML:function(){var e=this.records.length;0==this.searchData.length||this.url||(e=this.last.searchIds.length),this.last.show_extra=e>this.vs_start?this.vs_extra:this.vs_start;var t=$("#grid_"+this.name+"_records"),i=Math.floor(t.height()/this.recordHeight)+this.last.show_extra+1;(!this.fixedBody||i>e)&&(i=e);var s="<table>"+this.getRecordHTML(-1,0);s+='<tr id="grid_'+this.name+'_rec_top" line="top" style="height: 0px">    <td colspan="200"></td></tr>';for(var n=0;i>n;n++)s+=this.getRecordHTML(n,n+1);return s+='<tr id="grid_'+this.name+'_rec_bottom" line="bottom" style="height: '+(e-i)*this.recordHeight+'px">    <td colspan="200"></td></tr><tr id="grid_'+this.name+'_rec_more" style="display: none">    <td colspan="200" class="w2ui-load-more"></td></tr></table>',this.last.range_start=0,this.last.range_end=i,s},getSummaryHTML:function(){if(0!=this.summary.length){for(var e="<table>",t=0;t<this.summary.length;t++)e+=this.getRecordHTML(t,t+1,!0);return e+="</table>"}},scroll:function(){function e(){t.markSearch&&(clearTimeout(t.last.marker_timer),t.last.marker_timer=setTimeout(function(){for(var e=[],i=0;i<t.searchData.length;i++){var s=t.searchData[i];-1==$.inArray(s.value,e)&&e.push(s.value)}e.length>0&&$(t.box).find(".w2ui-grid-data > div").w2marker(e)},50))}var t=((new Date).getTime(),this),i=$("#grid_"+this.name+"_records"),s=this.records.length;if(0==this.searchData.length||this.url||(s=this.last.searchIds.length),0!=s&&0!=i.length&&0!=i.height()){if(this.last.show_extra=s>this.vs_start?this.vs_extra:this.vs_start,i.height()<s*this.recordHeight&&"hidden"==i.css("overflow-y"))return void(this.total>0&&this.refresh());var n=Math.round(i[0].scrollTop/this.recordHeight+1),r=n+(Math.round(i.height()/this.recordHeight)-1);n>s&&(n=s),r>=s-1&&(r=s);var a="object"!=typeof this.url?this.url:this.url.get;if($("#grid_"+this.name+"_footer .w2ui-footer-right").html((t.show.statusRange?w2utils.formatNumber(this.offset+n)+"-"+w2utils.formatNumber(this.offset+r)+" "+w2utils.lang("of")+" "+w2utils.formatNumber(this.total):"")+(a&&t.show.statusBuffered?" ("+w2utils.lang("buffered")+" "+w2utils.formatNumber(s)+(this.offset>0?", skip "+w2utils.formatNumber(this.offset):"")+")":"")),a||this.fixedBody&&!(this.total<=300)){var o=Math.floor(i[0].scrollTop/this.recordHeight)-this.last.show_extra,l=o+Math.floor(i.height()/this.recordHeight)+2*this.last.show_extra+1;1>o&&(o=1),l>this.total&&(l=this.total);var d=i.find("#grid_"+this.name+"_rec_top"),h=i.find("#grid_"+this.name+"_rec_bottom");-1!=String(d.next().prop("id")).indexOf("_expanded_row")&&d.next().remove(),this.total>l&&-1!=String(h.prev().prop("id")).indexOf("_expanded_row")&&h.prev().remove();var u=parseInt(d.next().attr("line")),c=parseInt(h.prev().attr("line"));if(o>u||1==u||this.last.pull_refresh){if(l<=c+this.last.show_extra-2&&l!=this.total)return;for(this.last.pull_refresh=!1;;){var p=i.find("#grid_"+this.name+"_rec_top").next();if("bottom"==p.attr("line"))break;if(!(parseInt(p.attr("line"))<o))break;p.remove()}var p=i.find("#grid_"+this.name+"_rec_bottom").prev(),f=p.attr("line");"top"==f&&(f=o);for(var g=parseInt(f)+1;l>=g;g++)this.records[g-1]&&(this.records[g-1].expanded===!0&&(this.records[g-1].expanded=!1),h.before(this.getRecordHTML(g-1,g)));e(),setTimeout(function(){t.refreshRanges()},0)}else{if(o>=u-this.last.show_extra+2&&o>1)return;for(;;){var p=i.find("#grid_"+this.name+"_rec_bottom").prev();if("top"==p.attr("line"))break;if(!(parseInt(p.attr("line"))>l))break;p.remove()}var p=i.find("#grid_"+this.name+"_rec_top").next(),f=p.attr("line");"bottom"==f&&(f=l);for(var g=parseInt(f)-1;g>=o;g--)this.records[g-1]&&(this.records[g-1].expanded===!0&&(this.records[g-1].expanded=!1),d.after(this.getRecordHTML(g-1,g)));e(),setTimeout(function(){t.refreshRanges()},0)}var m=(o-1)*t.recordHeight,v=(s-l)*t.recordHeight;0>v&&(v=0),d.css("height",m+"px"),h.css("height",v+"px"),t.last.range_start=o,t.last.range_end=l;var w=Math.floor(i[0].scrollTop/this.recordHeight),y=w+Math.floor(i.height()/this.recordHeight);if(y+10>s&&this.last.pull_more!==!0&&s<this.total-this.offset)if(this.autoLoad===!0)this.last.pull_more=!0,this.last.xhr_offset+=this.limit,this.request("get-records");else{var b=$("#grid_"+this.name+"_rec_more");"none"==b.css("display")&&b.show().on("click",function(){t.last.pull_more=!0,t.last.xhr_offset+=t.limit,t.request("get-records"),$(this).find("td").html('<div><div style="width: 20px; height: 20px;" class="w2ui-spinner"></div></div>')}),-1==b.find("td").text().indexOf("Load")&&b.find("td").html("<div>"+w2utils.lang("Load")+" "+t.limit+" "+w2utils.lang("More")+"...</div>")}s>=this.total-this.offset&&$("#grid_"+this.name+"_rec_more").hide()}}},getRecordHTML:function(e,t,i){var s,n="",r=this.last.selection;if(-1==e){n+='<tr line="0">',this.show.lineNumbers&&(n+='<td class="w2ui-col-number" style="height: 0px;"></td>'),this.show.selectColumn&&(n+='<td class="w2ui-col-select" style="height: 0px;"></td>'),this.show.expandColumn&&(n+='<td class="w2ui-col-expand" style="height: 0px;"></td>');for(var a=0;a<this.columns.length;a++)this.columns[a].hidden||(n+='<td class="w2ui-grid-data" col="'+a+'" style="height: 0px;"></td>');return n+='<td class="w2ui-grid-data-last" style="height: 0px;"></td>',n+="</tr>"}var o="object"!=typeof this.url?this.url:this.url.get;if(i!==!0)if(this.searchData.length>0&&!o){if(e>=this.last.searchIds.length)return"";e=this.last.searchIds[e],s=this.records[e]}else{if(e>=this.records.length)return"";s=this.records[e]}else{if(e>=this.summary.length)return"";s=this.summary[e]}if(!s)return"";var l=(w2utils.escapeId(s.recid),!1);if(-1!=r.indexes.indexOf(e)&&(l=!0),n+='<tr id="grid_'+this.name+"_rec_"+s.recid+'" recid="'+s.recid+'" line="'+t+'"  class="'+(t%2==0?"w2ui-even":"w2ui-odd")+(l&&"row"==this.selectType?" w2ui-selected":"")+(s.expanded===!0?" w2ui-expanded":"")+'" '+(i!==!0?w2utils.isIOS?"    onclick  = \"var obj = w2ui['"+this.name+"']; obj.dblClick('"+s.recid+"', event);\"":"    onclick  = \"var obj = w2ui['"+this.name+"']; obj.click('"+s.recid+"', event);\"    oncontextmenu = \"var obj = w2ui['"+this.name+"']; obj.contextMenu('"+s.recid+"', event);\"":"")+' style="height: '+this.recordHeight+"px; "+(l||"string"!=typeof s.style?"":s.style)+'" '+("string"==typeof s.style?'custom_style="'+s.style+'"':"")+">",this.show.lineNumbers&&(n+='<td id="grid_'+this.name+"_cell_"+e+"_number"+(i?"_s":"")+'"    class="w2ui-col-number '+(l?" w2ui-row-selected":"")+'">'+(i!==!0?"<div>"+t+"</div>":"")+"</td>"),this.show.selectColumn&&(n+='<td id="grid_'+this.name+"_cell_"+e+"_select"+(i?"_s":"")+'" class="w2ui-grid-data w2ui-col-select"         onclick="if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">'+(i!==!0?'    <div>        <input class="w2ui-grid-select-check" type="checkbox" tabIndex="-1"            '+(l?'checked="checked"':"")+"            onclick=\"var obj = w2ui['"+this.name+"'];                 if (!obj.multiSelect) { obj.selectNone(); }                if (this.checked) obj.select('"+s.recid+"'); else obj.unselect('"+s.recid+"');                 if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;\">    </div>":"")+"</td>"),this.show.expandColumn){var d="";d=s.expanded===!0?"-":"+","none"==s.expanded&&(d=""),"spinner"==s.expanded&&(d='<div class="w2ui-spinner" style="width: 16px; margin: -2px 2px;"></div>'),n+='<td id="grid_'+this.name+"_cell_"+e+"_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('"+s.recid+"', event);                 if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;\">        "+d+" </div>":"")+"</td>"}for(var h=0;;){var u=this.columns[h];if(u.hidden){if(h++,"undefined"==typeof this.columns[h])break}else{var c=!i&&s.changes&&"undefined"!=typeof s.changes[u.field],p=this.getCellHTML(e,h,i),f="";if("string"==typeof u.render){var g=u.render.toLowerCase().split(":");-1!=["number","int","float","money","currency","percent"].indexOf(g[0])&&(f+="text-align: right;")}"object"==typeof s.style&&("string"==typeof s.style[h]&&(f+=s.style[h]+";"),"string"==typeof s.style[u.field]&&(f+=s.style[u.field]+";"));var m=!1;if(l&&-1!=$.inArray(h,r.columns[e])&&(m=!0),n+='<td class="w2ui-grid-data'+(m?" w2ui-selected":"")+(c?" w2ui-changed":"")+'"     id="grid_'+this.name+"_data_"+e+"_"+h+'" col="'+h+'"     style="'+f+("undefined"!=typeof u.style?u.style:"")+'" '+("undefined"!=typeof u.attr?u.attr:"")+">"+p+"</td>",h++,"undefined"==typeof this.columns[h])break}}return n+='<td class="w2ui-grid-data-last"></td>',n+="</tr>"},getCellHTML:function(e,t,i){var s=this.columns[t],n=i!==!0?this.records[e]:this.summary[e],r=this.getCellValue(e,t,i),a=s.editable;if("undefined"!=typeof s.render){if("function"==typeof s.render&&(r=$.trim(s.render.call(this,n,e,t)),(r.length<4||"<div"!=r.substr(0,4).toLowerCase())&&(r="<div>"+r+"</div>")),"object"==typeof s.render&&(r="<div>"+(s.render[r]||"")+"</div>"),"string"==typeof s.render){var o=s.render.toLowerCase().indexOf(":"),l=[];-1==o?(l[0]=s.render.toLowerCase(),l[1]=""):(l[0]=s.render.toLowerCase().substr(0,o),l[1]=s.render.toLowerCase().substr(o+1));var d="",h="";-1!=["number","int","float","money","currency","percent"].indexOf(l[0])&&("undefined"!=typeof l[1]&&w2utils.isInt(l[1])||(l[1]=0),l[1]>20&&(l[1]=20),l[1]<0&&(l[1]=0),-1!=["money","currency"].indexOf(l[0])&&(l[1]=w2utils.settings.currencyPrecision,d=w2utils.settings.currencyPrefix,h=w2utils.settings.currencySuffix),"percent"==l[0]&&(h="%","0"!==l[1]&&(l[1]=1)),"int"==l[0]&&(l[1]=0),r="<div>"+(""!==r?d+w2utils.formatNumber(Number(r).toFixed(l[1]))+h:"")+"</div>"),"time"==l[0]&&(("undefined"==typeof l[1]||""==l[1])&&(l[1]=w2utils.settings.time_format),"h12"==l[1]&&(l[1]="hh:mi pm"),"h24"==l[1]&&(l[1]="h24:mi"),r="<div>"+d+w2utils.formatTime(r,l[1])+h+"</div>"),"date"==l[0]&&(("undefined"==typeof l[1]||""==l[1])&&(l[1]=w2utils.settings.date_display),r="<div>"+d+w2utils.formatDate(r,l[1])+h+"</div>"),"datetime"==l[0]&&(("undefined"==typeof l[1]||""==l[1])&&(l[1]=w2utils.settings.date_display+"|"+w2utils.settings.time_format),r="<div>"+d+w2utils.formatDateTime(r,l[1])+h+"</div>"),"age"==l[0]&&(r="<div>"+d+w2utils.age(r)+h+"</div>"),"toggle"==l[0]&&(r="<div>"+d+(r?"Yes":"")+h+"</div>")}}else{var u="";if(a&&-1!=["checkbox","check"].indexOf(a.type)){var c=i?-(e+1):e;u="text-align: center",r='<input type="checkbox" '+(r?"checked":"")+" onclick=\"    var obj = w2ui['"+this.name+"'];     obj.editChange.call(obj, this, "+c+", "+t+', event); ">'}if(this.show.recordTitles){var p=String(r).replace(/"/g,"''");"undefined"!=typeof s.title&&("function"==typeof s.title&&(p=s.title.call(this,n,e,t)),"string"==typeof s.title&&(p=s.title));var r='<div title="'+w2utils.stripTags(p)+'" style="'+u+'">'+r+"</div>"}else var r='<div style="'+u+'">'+r+"</div>"}return(null==r||"undefined"==typeof r)&&(r=""),r},getCellValue:function(e,t,i){var s=this.columns[t],n=i!==!0?this.records[e]:this.summary[e],r=this.parseField(n,s.field);return n.changes&&"undefined"!=typeof n.changes[s.field]&&(r=n.changes[s.field]),(null==r||"undefined"==typeof r)&&(r=""),r},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(e){if("undefined"!=typeof e)$("#grid_"+this.name+"_footer").find(".w2ui-footer-left").html(e);else{var t="",i=this.getSelection();if(i.length>0&&(this.show.statusSelection&&i.length>1&&(t=String(i.length).replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1,")+" "+w2utils.lang("selected")),this.show.statusRecordID&&1==i.length)){var s=i[0];"object"==typeof s&&(s=s.recid+", "+w2utils.lang("Column")+": "+s.column),t=w2utils.lang("Record ID")+": "+s+" "}$("#grid_"+this.name+"_footer .w2ui-footer-left").html(t),1==i.length?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 e=$(this.box).find("> div:first-child"),t=Array.prototype.slice.call(arguments,0);t.unshift(e),setTimeout(function(){w2utils.lock.apply(window,t)},10)},unlock:function(e){var t=this.box;setTimeout(function(){w2utils.unlock(t,e)},25)},stateSave:function(e){if(!localStorage)return null;for(var t={columns:[],show:$.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++){var s=this.columns[i];t.columns.push({field:s.field,hidden:s.hidden,size:s.size,sizeCalculated:s.sizeCalculated,sizeOriginal:s.sizeOriginal,sizeType:s.sizeType})}for(var i=0;i<this.sortData.length;i++)t.sortData.push($.extend({},this.sortData[i]));for(var i=0;i<this.searchData.length;i++)t.searchData.push($.extend({},this.searchData[i]));if(e!==!0){var n=this.trigger({phase:"before",type:"stateSave",target:this.name,state:t});if(n.isCancelled===!0)return void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."}));try{var r=$.parseJSON(localStorage.w2ui||"{}");r||(r={}),r.states||(r.states={}),r.states[this.name]=t,localStorage.w2ui=JSON.stringify(r)}catch(a){return delete localStorage.w2ui,null}this.trigger($.extend(n,{phase:"after"}))}return t},stateRestore:function(e){var t=this;if(!e)try{if(!localStorage)return!1;var i=$.parseJSON(localStorage.w2ui||"{}");i||(i={}),i.states||(i.states={}),e=i.states[this.name]}catch(s){return delete localStorage.w2ui,null}var n=this.trigger({phase:"before",type:"stateRestore",target:this.name,state:e});if(n.isCancelled===!0)return void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."}));if($.isPlainObject(e)){$.extend(this.show,e.show),$.extend(this.last,e.last);for(var r=this.last.scrollTop,a=this.last.scrollLeft,o=0;o<e.columns.length;o++){var i=e.columns[o],l=this.getColumn(i.field);l&&$.extend(l,i)}this.sortData.splice(0,this.sortData.length);for(var o=0;o<e.sortData.length;o++)this.sortData.push(e.sortData[o]);this.searchData.splice(0,this.searchData.length);for(var o=0;o<e.searchData.length;o++)this.searchData.push(e.searchData[o]);setTimeout(function(){("object"!=typeof t.url?t.url:t.url.get)||(t.sortData.length>0&&t.localSort(),t.searchData.length>0&&t.localSearch()),t.last.scrollTop=r,t.last.scrollLeft=a,t.refresh()},1)}return this.trigger($.extend(n,{phase:"after"})),!0},stateReset:function(){if(this.stateRestore(this.last.state),localStorage)try{var e=$.parseJSON(localStorage.w2ui||"{}");e.states&&e.states[this.name]&&delete e.states[this.name],localStorage.w2ui=JSON.stringify(e)}catch(t){return delete localStorage.w2ui,null}},parseField:function(e,t){var i="";try{i=e;for(var s=String(t).split("."),n=0;n<s.length;n++)i=i[s[n]]}catch(r){i=""}return i},prepareData:function(){for(var e=0;e<this.records.length;e++)for(var t=this.records[e],i=0;i<this.columns.length;i++){var s=this.columns[i];if(null!=t[s.field]&&"string"==typeof s.render){if(-1!=["number","int","float","money","currency","percent"].indexOf(s.render.split(":")[0])&&"number"!=typeof t[s.field]&&(t[s.field]=parseFloat(t[s.field])),-1!=["date","age"].indexOf(s.render.split(":")[0])&&!t[s.field+"_"]){var n=t[s.field];w2utils.isInt(n)&&(n=parseInt(n)),t[s.field+"_"]=new Date(n)}if(-1!=["time"].indexOf(s.render))if(w2utils.isTime(t[s.field])){var r=w2utils.isTime(t[s.field],!0),n=new Date;n.setHours(r.hours,r.minutes,r.seconds?r.seconds:0,0),t[s.field+"_"]||(t[s.field+"_"]=n)}else{var r=t[s.field];w2utils.isInt(r)&&(r=parseInt(r));var r=null!=r?new Date(r):new Date,n=new Date;n.setHours(r.getHours(),r.getMinutes(),r.getSeconds(),0),t[s.field+"_"]||(t[s.field+"_"]=n)}}}},nextCell:function(e,t){var i=e+1;if(this.columns.length==i)return null;if(t===!0){var s=this.columns[i].editable;if(this.columns[i].hidden||"undefined"==typeof s||s&&-1!=["checkbox","check"].indexOf(s.type))return this.nextCell(i,t)}return i},prevCell:function(e,t){var i=e-1;if(0>i)return null;if(t===!0){var s=this.columns[i].editable;if(this.columns[i].hidden||"undefined"==typeof s||s&&-1!=["checkbox","check"].indexOf(s.type))return this.prevCell(i,t)}return i},nextRow:function(e){if(e+1<this.records.length&&0==this.last.searchIds.length||this.last.searchIds.length>0&&e<this.last.searchIds[this.last.searchIds.length-1]){if(e++,this.last.searchIds.length>0)for(;;){if(-1!=$.inArray(e,this.last.searchIds)||e>this.records.length)break;e++}return e}return null},prevRow:function(e){if(e>0&&0==this.last.searchIds.length||this.last.searchIds.length>0&&e>this.last.searchIds[0]){if(e--,this.last.searchIds.length>0)for(;;){if(-1!=$.inArray(e,this.last.searchIds)||0>e)break;e--}return e}return null}},$.extend(w2grid.prototype,w2utils.event),w2obj.grid=w2grid}(),function(){var e=function(e){this.box=null,this.name=null,this.panels=[],this.tmp={},this.padding=1,this.resizer=4,this.style="",this.onShow=null,this.onHide=null,this.onResizing=null,this.onResizerClick=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,$.extend(!0,this,w2obj.layout,e)},t=["top","left","main","preview","right","bottom"];$.fn.w2layout=function(i){function s(e,t,i){var s=e.get(t);return null!==s&&"undefined"==typeof i&&(i=s.tabs),null===s||null===i?!1:($.isArray(i)&&(i={tabs:i}),$().w2destroy(e.name+"_"+t+"_tabs"),s.tabs=$().w2tabs($.extend({},i,{owner:e,name:e.name+"_"+t+"_tabs"})),s.show.tabs=!0,!0)}function n(e,t,i){var s=e.get(t);return null!==s&&"undefined"==typeof i&&(i=s.toolbar),null===s||null===i?!1:($.isArray(i)&&(i={items:i}),$().w2destroy(e.name+"_"+t+"_toolbar"),s.toolbar=$().w2toolbar($.extend({},i,{owner:e,name:e.name+"_"+t+"_toolbar"})),s.show.toolbar=!0,!0)}if($.isPlainObject(i)){if(!w2utils.checkName(i,"w2layout"))return;var r=i.panels||[],a=new e(i);$.extend(a,{handlers:[],panels:[]});for(var o=0,l=r.length;l>o;o++)a.panels[o]=$.extend(!0,{},e.prototype.panel,r[o]),($.isPlainObject(a.panels[o].tabs)||$.isArray(a.panels[o].tabs))&&s(a,r[o].type),($.isPlainObject(a.panels[o].toolbar)||$.isArray(a.panels[o].toolbar))&&n(a,r[o].type);for(var d=0;d<t.length;d++)null===a.get(t[d])&&a.panels.push($.extend(!0,{},e.prototype.panel,{type:t[d],hidden:"main"!==t[d],size:50}));return $(this).length>0&&a.render($(this)[0]),w2ui[a.name]=a,a}var h=w2ui[$(this).attr("name")];return h?arguments.length>0?(h[i]&&h[i].apply(h,Array.prototype.slice.call(arguments,1)),this):h:null},e.prototype={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(e,t,i){return this.content(e,t,i)},content:function(e,t,i){var s=this,n=this.get(e);if("css"==e)return $("#layout_"+s.name+"_panel_css").html("<style>"+t+"</style>"),!0;if(null===n)return!1;if("undefined"==typeof t||null===t)return n.content;if(t instanceof jQuery)return console.log("ERROR: You can not pass jQuery object to w2layout.content() method"),!1;
  var r="#layout_"+this.name+"_panel_"+n.type,a=$(r+"> .w2ui-panel-content"),o=0;if(a.length>0&&($(r).scrollTop(0),o=$(a).position().top),""===n.content)n.content=t,this.refresh(e);else{if(n.content=t,!n.hidden&&null!==i&&""!==i&&"undefined"!=typeof i){var l=$(r+"> .w2ui-panel-content");l.after('<div class="w2ui-panel-content new-panel" style="'+l[0].style.cssText+'"></div>');var d=$(r+"> .w2ui-panel-content.new-panel");l.css("top",o),d.css("top",o),"object"==typeof t?(t.box=d[0],t.render()):d.html(t),w2utils.transition(l[0],d[0],i,function(){l.remove(),d.removeClass("new-panel"),d.css("overflow",n.overflow),s.resize(),-1!=window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100)})}this.refresh(e)}return s.resize(),-1!=window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){s.resize()},100),!0},load:function(e,t,i,s){var n=this;return"css"==e?($.get(t,function(t,i,r){n.content(e,r.responseText),s&&s()}),!0):null!==this.get(e)?($.get(t,function(t,r,a){n.content(e,a.responseText,i),s&&s(),n.resize(),-1!=window.navigator.userAgent.indexOf("MSIE")&&setTimeout(function(){n.resize()},100)}),!0):!1},sizeTo:function(e,t){var i=this,s=i.get(e);return null===s?!1:($(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",".2s")),setTimeout(function(){i.set(e,{size:t})},1),setTimeout(function(){$(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s")),i.resize()},500),!0)},show:function(e,t){var i=this,s=this.trigger({phase:"before",type:"show",target:e,object:this.get(e),immediate:t});if(s.isCancelled!==!0){var n=i.get(e);return null===n?!1:(n.hidden=!1,t===!0?($("#layout_"+i.name+"_panel_"+e).css({opacity:"1"}),n.resizable&&$("#layout_"+i.name+"_resizer_"+e).show(),i.trigger($.extend(s,{phase:"after"})),i.resize()):(n.resizable&&$("#layout_"+i.name+"_resizer_"+e).show(),$("#layout_"+i.name+"_panel_"+e).css({opacity:"0"}),$(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",".2s")),setTimeout(function(){i.resize()},1),setTimeout(function(){$("#layout_"+i.name+"_panel_"+e).css({opacity:"1"})},250),setTimeout(function(){$(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s")),i.trigger($.extend(s,{phase:"after"})),i.resize()},500)),!0)}},hide:function(e,t){var i=this,s=this.trigger({phase:"before",type:"hide",target:e,object:this.get(e),immediate:t});if(s.isCancelled!==!0){var n=i.get(e);return null===n?!1:(n.hidden=!0,t===!0?($("#layout_"+i.name+"_panel_"+e).css({opacity:"0"}),$("#layout_"+i.name+"_resizer_"+e).hide(),i.trigger($.extend(s,{phase:"after"})),i.resize()):($("#layout_"+i.name+"_resizer_"+e).hide(),$(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition",".2s")),$("#layout_"+i.name+"_panel_"+e).css({opacity:"0"}),setTimeout(function(){i.resize()},1),setTimeout(function(){$(i.box).find(" > div > .w2ui-panel").css(w2utils.cssPrefix("transition","0s")),i.trigger($.extend(s,{phase:"after"})),i.resize()},500)),!0)}},toggle:function(e,t){var i=this.get(e);return null===i?!1:i.hidden?this.show(e,t):this.hide(e,t)},set:function(e,t){var i=this.get(e,!0);if(null===i)return!1;$.extend(this.panels[i],t),"undefined"!=typeof t.content&&this.refresh(e);var s=$("#layout_"+this.name+"_resizer_"+e);return t.resizable?s.show():s.hide(),this.resize(),!0},get:function(e,t){for(var i=0;i<this.panels.length;i++)if(this.panels[i].type==e)return t===!0?i:this.panels[i];return null},el:function(e){var t=$("#layout_"+this.name+"_panel_"+e+"> .w2ui-panel-content");return 1!=t.length?null:t[0]},hideToolbar:function(e){var t=this.get(e);t&&(t.show.toolbar=!1,$("#layout_"+this.name+"_panel_"+e+"> .w2ui-panel-toolbar").hide(),this.resize())},showToolbar:function(e){var t=this.get(e);t&&(t.show.toolbar=!0,$("#layout_"+this.name+"_panel_"+e+"> .w2ui-panel-toolbar").show(),this.resize())},toggleToolbar:function(e){var t=this.get(e);t&&(t.show.toolbar?this.hideToolbar(e):this.showToolbar(e))},hideTabs:function(e){var t=this.get(e);t&&(t.show.tabs=!1,$("#layout_"+this.name+"_panel_"+e+"> .w2ui-panel-tabs").hide(),this.resize())},showTabs:function(e){var t=this.get(e);t&&(t.show.tabs=!0,$("#layout_"+this.name+"_panel_"+e+"> .w2ui-panel-tabs").show(),this.resize())},toggleTabs:function(e){var t=this.get(e);t&&(t.show.tabs?this.hideTabs(e):this.showTabs(e))},render:function(e){function i(){a.tmp.events={resize:function(){w2ui[a.name].resize()},resizeStart:s,mouseMove:r,mouseUp:n},$(window).on("resize",a.tmp.events.resize)}function s(e,i){if(a.box){i||(i=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),$(document).off("mousemove",a.tmp.events.mouseMove).on("mousemove",a.tmp.events.mouseMove),$(document).off("mouseup",a.tmp.events.mouseUp).on("mouseup",a.tmp.events.mouseUp),a.tmp.resize={type:e,x:i.screenX,y:i.screenY,diff_x:0,diff_y:0,value:0};for(var s=0;s<t.length;s++){var n=$(a.el(t[s])).parent().find(".w2ui-lock");n.length>0?n.attr("locked","previous"):a.lock(t[s],{opacity:0})}("left"==e||"right"==e)&&(a.tmp.resize.value=parseInt($("#layout_"+a.name+"_resizer_"+e)[0].style.left)),("top"==e||"preview"==e||"bottom"==e)&&(a.tmp.resize.value=parseInt($("#layout_"+a.name+"_resizer_"+e)[0].style.top))}}function n(e){if(a.box&&(e||(e=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),$(document).off("mousemove",a.tmp.events.mouseMove),$(document).off("mouseup",a.tmp.events.mouseUp),"undefined"!=typeof a.tmp.resize)){for(var i=0;i<t.length;i++){var s=$(a.el(t[i])).parent().find(".w2ui-lock");"previous"==s.attr("locked")?s.removeAttr("locked"):a.unlock(t[i])}if(0!==a.tmp.diff_x||0!==a.tmp.resize.diff_y){var n,r,o=a.get("top"),l=a.get("bottom"),d=a.get(a.tmp.resize.type),h=parseInt($(a.box).height()),u=parseInt($(a.box).width()),c=String(d.size);switch(a.tmp.resize.type){case"top":n=parseInt(d.sizeCalculated)+a.tmp.resize.diff_y,r=0;break;case"bottom":n=parseInt(d.sizeCalculated)-a.tmp.resize.diff_y,r=0;break;case"preview":n=parseInt(d.sizeCalculated)-a.tmp.resize.diff_y,r=(o&&!o.hidden?o.sizeCalculated:0)+(l&&!l.hidden?l.sizeCalculated:0);break;case"left":n=parseInt(d.sizeCalculated)+a.tmp.resize.diff_x,r=0;break;case"right":n=parseInt(d.sizeCalculated)-a.tmp.resize.diff_x,r=0}d.size="%"==c.substr(c.length-1)?Math.floor(100*n/("left"==d.type||"right"==d.type?u:h-r)*100)/100+"%":n,a.resize()}$("#layout_"+a.name+"_resizer_"+a.tmp.resize.type).removeClass("active"),delete a.tmp.resize}}function r(e){if(a.box&&(e||(e=window.event),"undefined"!=typeof a.tmp.resize)){var t=a.get(a.tmp.resize.type),i=a.tmp.resize,s=a.trigger({phase:"before",type:"resizing",target:a.name,object:t,originalEvent:e,panel:i?i.type:"all",diff_x:i?i.diff_x:0,diff_y:i?i.diff_y:0});if(s.isCancelled!==!0){var n=$("#layout_"+a.name+"_resizer_"+i.type),r=e.screenX-i.x,o=e.screenY-i.y,l=a.get("main");switch(n.hasClass("active")||n.addClass("active"),i.type){case"left":t.minSize-r>t.width&&(r=t.minSize-t.width),t.maxSize&&t.width+r>t.maxSize&&(r=t.maxSize-t.width),l.minSize+r>l.width&&(r=l.width-l.minSize);break;case"right":t.minSize+r>t.width&&(r=t.width-t.minSize),t.maxSize&&t.width-r>t.maxSize&&(r=t.width-t.maxSize),l.minSize-r>l.width&&(r=l.minSize-l.width);break;case"top":t.minSize-o>t.height&&(o=t.minSize-t.height),t.maxSize&&t.height+o>t.maxSize&&(o=t.maxSize-t.height),l.minSize+o>l.height&&(o=l.height-l.minSize);break;case"preview":case"bottom":t.minSize+o>t.height&&(o=t.height-t.minSize),t.maxSize&&t.height-o>t.maxSize&&(o=t.height-t.maxSize),l.minSize-o>l.height&&(o=l.minSize-l.height)}switch(i.diff_x=r,i.diff_y=o,i.type){case"top":case"preview":case"bottom":i.diff_x=0,n.length>0&&(n[0].style.top=i.value+i.diff_y+"px");break;case"left":case"right":i.diff_y=0,n.length>0&&(n[0].style.left=i.value+i.diff_x+"px")}a.trigger($.extend(s,{phase:"after"}))}}}var a=this,o=(new Date).getTime(),l=a.trigger({phase:"before",type:"render",target:a.name,box:e});if(l.isCancelled!==!0){if("undefined"!=typeof e&&null!==e&&($(a.box).find("#layout_"+a.name+"_panel_main").length>0&&$(a.box).removeAttr("name").removeClass("w2ui-layout").html(""),a.box=e),!a.box)return!1;$(a.box).attr("name",a.name).addClass("w2ui-layout").html("<div></div>"),$(a.box).length>0&&($(a.box)[0].style.cssText+=a.style);for(var d=0;d<t.length;d++){var h=(a.get(t[d]),'<div id="layout_'+a.name+"_panel_"+t[d]+'" 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_'+a.name+"_resizer_"+t[d]+'" class="w2ui-resizer"></div>');$(a.box).find(" > div").append(h)}return $(a.box).find(" > div").append('<div id="layout_'+a.name+'_panel_css" style="position: absolute; top: 10000px;"></div'),a.refresh(),a.trigger($.extend(l,{phase:"after"})),setTimeout(function(){i(),a.resize()},0),(new Date).getTime()-o}},refresh:function(e){var t=this;"undefined"==typeof e&&(e=null);var i=(new Date).getTime(),s=t.trigger({phase:"before",type:"refresh",target:"undefined"!=typeof e?e:t.name,object:t.get(e)});if(s.isCancelled!==!0){if("string"==typeof e){var n=t.get(e);if(null===n)return;var r="#layout_"+t.name+"_panel_"+n.type,a="#layout_"+t.name+"_resizer_"+n.type;$(r).css({display:n.hidden?"none":"block"}),n.resizable?$(a).show():$(a).hide(),"object"==typeof n.content&&"function"==typeof n.content.render?(n.content.box=$(r+"> .w2ui-panel-content")[0],setTimeout(function(){$(r+"> .w2ui-panel-content").length>0&&($(r+"> .w2ui-panel-content").removeClass().removeAttr("name").addClass("w2ui-panel-content").css("overflow",n.overflow)[0].style.cssText+=";"+n.style),n.content.render()},1)):$(r+"> .w2ui-panel-content").length>0&&($(r+"> .w2ui-panel-content").removeClass().removeAttr("name").addClass("w2ui-panel-content").html(n.content).css("overflow",n.overflow)[0].style.cssText+=";"+n.style);var o=$(t.box).find(r+"> .w2ui-panel-tabs");n.show.tabs?0===o.find("[name="+n.tabs.name+"]").length&&null!==n.tabs?o.w2render(n.tabs):n.tabs.refresh():o.html("").removeClass("w2ui-tabs").hide(),o=$(t.box).find(r+"> .w2ui-panel-toolbar"),n.show.toolbar?0===o.find("[name="+n.toolbar.name+"]").length&&null!==n.toolbar?o.w2render(n.toolbar):n.toolbar.refresh():o.html("").removeClass("w2ui-toolbar").hide(),o=$(t.box).find(r+"> .w2ui-panel-title"),n.title?o.html(n.title).show():o.html("").hide()}else{if(0==$("#layout_"+t.name+"_panel_main").length)return void t.render();t.resize();for(var l=0;l<this.panels.length;l++)t.refresh(this.panels[l].type)}return t.trigger($.extend(s,{phase:"after"})),(new Date).getTime()-i}},resize:function(){if(!this.box)return!1;var e=(new Date).getTime(),i=this.tmp.resize,s=this.trigger({phase:"before",type:"resize",target:this.name,panel:i?i.type:"all",diff_x:i?i.diff_x:0,diff_y:i?i.diff_y:0});if(s.isCancelled!==!0){this.padding<0&&(this.padding=0);var n=parseInt($(this.box).width()),r=parseInt($(this.box).height());$(this.box).find(" > div").css({width:n+"px",height:r+"px"});for(var a,o,l,d,h,u=this,c=this.get("main"),p=this.get("preview"),f=this.get("left"),g=this.get("right"),m=this.get("top"),v=this.get("bottom"),w=null!==p&&p.hidden!==!0?!0:!1,y=null!==f&&f.hidden!==!0?!0:!1,b=null!==g&&g.hidden!==!0?!0:!1,x=null!==m&&m.hidden!==!0?!0:!1,_=null!==v&&v.hidden!==!0?!0:!1,k=0;k<t.length;k++)if("main"!==t[k]){var i=this.get(t[k]);if(i){var C=String(i.size||0);if("%"==C.substr(C.length-1)){var T=r;"preview"==i.type&&(T=T-(m&&!m.hidden?m.sizeCalculated:0)-(v&&!v.hidden?v.sizeCalculated:0)),i.sizeCalculated=parseInt(("left"==i.type||"right"==i.type?n:T)*parseFloat(i.size)/100)}else i.sizeCalculated=parseInt(i.size);i.sizeCalculated=Math.max(i.sizeCalculated,parseInt(i.minSize))}}null!==m&&m.hidden!==!0?(a=0,o=0,l=n,d=m.sizeCalculated,$("#layout_"+this.name+"_panel_top").css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}).show(),m.width=l,m.height=d,m.resizable&&(o=m.sizeCalculated-(0===this.padding?this.resizer:0),d=this.resizer>this.padding?this.resizer:this.padding,$("#layout_"+this.name+"_resizer_top").show().css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(e){var t=u.trigger({phase:"before",type:"resizerClick",target:"top",originalEvent:e});if(t.isCancelled!==!0)return w2ui[u.name].tmp.events.resizeStart("top",e),u.trigger($.extend(t,{phase:"after"})),!1}))):$("#layout_"+this.name+"_panel_top").hide(),null!==f&&f.hidden!==!0?(a=0,o=0+(x?m.sizeCalculated+this.padding:0),l=f.sizeCalculated,d=r-(x?m.sizeCalculated+this.padding:0)-(_?v.sizeCalculated+this.padding:0),h=$("#layout_"+this.name+"_panel_left"),-1!=window.navigator.userAgent.indexOf("MSIE")&&h.length>0&&h[0].clientHeight<h[0].scrollHeight&&(l+=17),h.css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}).show(),f.width=l,f.height=d,f.resizable&&(a=f.sizeCalculated-(0===this.padding?this.resizer:0),l=this.resizer>this.padding?this.resizer:this.padding,$("#layout_"+this.name+"_resizer_left").show().css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px",cursor:"ew-resize"}).off("mousedown").on("mousedown",function(e){var t=u.trigger({phase:"before",type:"resizerClick",target:"left",originalEvent:e});if(t.isCancelled!==!0)return w2ui[u.name].tmp.events.resizeStart("left",e),u.trigger($.extend(t,{phase:"after"})),!1}))):($("#layout_"+this.name+"_panel_left").hide(),$("#layout_"+this.name+"_resizer_left").hide()),null!==g&&g.hidden!==!0?(a=n-g.sizeCalculated,o=0+(x?m.sizeCalculated+this.padding:0),l=g.sizeCalculated,d=r-(x?m.sizeCalculated+this.padding:0)-(_?v.sizeCalculated+this.padding:0),$("#layout_"+this.name+"_panel_right").css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}).show(),g.width=l,g.height=d,g.resizable&&(a-=this.padding,l=this.resizer>this.padding?this.resizer:this.padding,$("#layout_"+this.name+"_resizer_right").show().css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px",cursor:"ew-resize"}).off("mousedown").on("mousedown",function(e){var t=u.trigger({phase:"before",type:"resizerClick",target:"right",originalEvent:e});if(t.isCancelled!==!0)return w2ui[u.name].tmp.events.resizeStart("right",e),u.trigger($.extend(t,{phase:"after"})),!1}))):$("#layout_"+this.name+"_panel_right").hide(),null!==v&&v.hidden!==!0?(a=0,o=r-v.sizeCalculated,l=n,d=v.sizeCalculated,$("#layout_"+this.name+"_panel_bottom").css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}).show(),v.width=l,v.height=d,v.resizable&&(o-=0===this.padding?0:this.padding,d=this.resizer>this.padding?this.resizer:this.padding,$("#layout_"+this.name+"_resizer_bottom").show().css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(e){var t=u.trigger({phase:"before",type:"resizerClick",target:"bottom",originalEvent:e});if(t.isCancelled!==!0)return w2ui[u.name].tmp.events.resizeStart("bottom",e),u.trigger($.extend(t,{phase:"after"})),!1}))):$("#layout_"+this.name+"_panel_bottom").hide(),a=0+(y?f.sizeCalculated+this.padding:0),o=0+(x?m.sizeCalculated+this.padding:0),l=n-(y?f.sizeCalculated+this.padding:0)-(b?g.sizeCalculated+this.padding:0),d=r-(x?m.sizeCalculated+this.padding:0)-(_?v.sizeCalculated+this.padding:0)-(w?p.sizeCalculated+this.padding:0),h=$("#layout_"+this.name+"_panel_main"),-1!=window.navigator.userAgent.indexOf("MSIE")&&h.length>0&&h[0].clientHeight<h[0].scrollHeight&&(l+=17),h.css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}),c.width=l,c.height=d,null!==p&&p.hidden!==!0?(a=0+(y?f.sizeCalculated+this.padding:0),o=r-(_?v.sizeCalculated+this.padding:0)-p.sizeCalculated,l=n-(y?f.sizeCalculated+this.padding:0)-(b?g.sizeCalculated+this.padding:0),d=p.sizeCalculated,h=$("#layout_"+this.name+"_panel_preview"),-1!=window.navigator.userAgent.indexOf("MSIE")&&h.length>0&&h[0].clientHeight<h[0].scrollHeight&&(l+=17),h.css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px"}).show(),p.width=l,p.height=d,p.resizable&&(o-=0===this.padding?0:this.padding,d=this.resizer>this.padding?this.resizer:this.padding,$("#layout_"+this.name+"_resizer_preview").show().css({display:"block",left:a+"px",top:o+"px",width:l+"px",height:d+"px",cursor:"ns-resize"}).off("mousedown").on("mousedown",function(e){var t=u.trigger({phase:"before",type:"resizerClick",target:"preview",originalEvent:e});if(t.isCancelled!==!0)return w2ui[u.name].tmp.events.resizeStart("preview",e),u.trigger($.extend(t,{phase:"after"})),!1}))):$("#layout_"+this.name+"_panel_preview").hide();for(var S=0;S<t.length;S++){var z=this.get(t[S]),D="#layout_"+this.name+"_panel_"+t[S]+" > .w2ui-panel-",O=0;z&&(z.title&&(O+=w2utils.getSize($(D+"title").css({top:O+"px",display:"block"}),"height")),z.show.tabs&&(null!==z.tabs&&w2ui[this.name+"_"+t[S]+"_tabs"]&&w2ui[this.name+"_"+t[S]+"_tabs"].resize(),O+=w2utils.getSize($(D+"tabs").css({top:O+"px",display:"block"}),"height")),z.show.toolbar&&(null!==z.toolbar&&w2ui[this.name+"_"+t[S]+"_toolbar"]&&w2ui[this.name+"_"+t[S]+"_toolbar"].resize(),O+=w2utils.getSize($(D+"toolbar").css({top:O+"px",display:"block"}),"height"))),$(D+"content").css({display:"block"}).css({top:O+"px"})}return clearTimeout(this._resize_timer),this._resize_timer=setTimeout(function(){for(var e in w2ui)if("function"==typeof w2ui[e].resize){"undefined"==w2ui[e].panels&&w2ui[e].resize();var t=$(w2ui[e].box).parents(".w2ui-layout");t.length>0&&t.attr("name")==u.name&&w2ui[e].resize()}},100),this.trigger($.extend(s,{phase:"after"})),(new Date).getTime()-e}},destroy:function(){var e=this.trigger({phase:"before",type:"destroy",target:this.name});if(e.isCancelled!==!0)return"undefined"==typeof w2ui[this.name]?!1:($(this.box).find("#layout_"+this.name+"_panel_main").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-layout").html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})),this.tmp.events&&this.tmp.events.resize&&$(window).off("resize",this.tmp.events.resize),!0)},lock:function(e){if(-1==t.indexOf(e))return void console.log("ERROR: First parameter needs to be the a valid panel name.");var i=Array.prototype.slice.call(arguments,0);i[0]="#layout_"+this.name+"_panel_"+e,w2utils.lock.apply(window,i)},unlock:function(e,i){if(-1==t.indexOf(e))return void console.log("ERROR: First parameter needs to be the a valid panel name.");var s="#layout_"+this.name+"_panel_"+e;w2utils.unlock(s,i)}},$.extend(e.prototype,w2utils.event),w2obj.layout=e}();var w2popup={};!function(){$.fn.w2popup=function(e,t){"undefined"==typeof e&&(t={},e="open"),$.isPlainObject(e)&&(t=e,e="open"),e=e.toLowerCase(),"load"===e&&"string"==typeof t&&(t=$.extend({url:t},arguments.length>2?arguments[2]:{})),"open"===e&&null!=t.url&&(e="load"),t=t||{};var i={};return $(this).length>0&&($(this).find("div[rel=title], div[rel=body], div[rel=buttons]").length>0?($(this).find("div[rel=title]").length>0&&(i.title=$(this).find("div[rel=title]").html()),$(this).find("div[rel=body]").length>0&&(i.body=$(this).find("div[rel=body]").html(),i.style=$(this).find("div[rel=body]")[0].style.cssText),$(this).find("div[rel=buttons]").length>0&&(i.buttons=$(this).find("div[rel=buttons]").html())):(i.title="&nbsp;",i.body=$(this).html()),0!=parseInt($(this).css("width"))&&(i.width=parseInt($(this).css("width"))),0!=parseInt($(this).css("height"))&&(i.height=parseInt($(this).css("height")))),w2popup[e]($.extend({},i,t))},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(e){function t(e){return e||(e=window.event),window.addEventListener||window.document.attachEvent("onselectstart",function(){return!1}),w2popup.status="moving",m.resizing=!0,m.isLocked=1==$("#w2ui-popup > .w2ui-lock").length?!0:!1,m.x=e.screenX,m.y=e.screenY,m.pos_x=$("#w2ui-popup").position().left,m.pos_y=$("#w2ui-popup").position().top,m.isLocked||w2popup.lock({opacity:0}),$(document).on("mousemove",m.mvMove),$(document).on("mouseup",m.mvStop),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,e.preventDefault?void e.preventDefault():!1}function i(e){1==m.resizing&&(e||(e=window.event),m.div_x=e.screenX-m.x,m.div_y=e.screenY-m.y,$("#w2ui-popup").css(w2utils.cssPrefix({transition:"none",transform:"translate3d("+m.div_x+"px, "+m.div_y+"px, 0px)"})))}function s(e){1==m.resizing&&(e||(e=window.event),w2popup.status="open",m.div_x=e.screenX-m.x,m.div_y=e.screenY-m.y,$("#w2ui-popup").css({left:m.pos_x+m.div_x+"px",top:m.pos_y+m.div_y+"px"}).css(w2utils.cssPrefix({transition:"none",transform:"translate3d(0px, 0px, 0px)"})),m.resizing=!1,$(document).off("mousemove",m.mvMove),$(document).off("mouseup",m.mvStop),m.isLocked||w2popup.unlock())}var n=this;if("closing"==w2popup.status)return void setTimeout(function(){n.open.call(n,e)},100);var r=$("#w2ui-popup").data("options"),e=$.extend({},this.defaults,r,{title:"",body:"",buttons:""},e,{maximized:!1});if(setTimeout(function(){$("#w2ui-popup").data("options",e)},100),0==$("#w2ui-popup").length&&(w2popup.handlers=[],w2popup.onMax=null,w2popup.onMin=null,w2popup.onToggle=null,w2popup.onOpen=null,w2popup.onClose=null,w2popup.onKeydown=null),e.onOpen&&(w2popup.onOpen=e.onOpen),e.onClose&&(w2popup.onClose=e.onClose),e.onMax&&(w2popup.onMax=e.onMax),e.onMin&&(w2popup.onMin=e.onMin),e.onToggle&&(w2popup.onToggle=e.onToggle),e.onKeydown&&(w2popup.onKeydown=e.onKeydown),void 0==window.innerHeight){var a=document.documentElement.offsetWidth,o=document.documentElement.offsetHeight;"IE7"===w2utils.engine&&(a+=21,o+=4)}else var a=window.innerWidth,o=window.innerHeight;parseInt(a)-10<parseInt(e.width)&&(e.width=parseInt(a)-10),parseInt(o)-10<parseInt(e.height)&&(e.height=parseInt(o)-10);var l=parseInt((parseInt(o)-parseInt(e.height))/2*.6),d=parseInt((parseInt(a)-parseInt(e.width))/2);if(0==$("#w2ui-popup").length){var h=this.trigger({phase:"before",type:"open",target:"popup",options:e,present:!1});if(h.isCancelled===!0)return;w2popup.status="opening",w2popup.lockScreen(e);var u="";e.showClose&&(u+='<div class="w2ui-msg-button w2ui-msg-close" onmousedown="event.stopPropagation()" onclick="w2popup.close()">Close</div>'),e.showMax&&(u+='<div class="w2ui-msg-button w2ui-msg-max" onmousedown="event.stopPropagation()" onclick="w2popup.toggle()">Max</div>');var c='<div id="w2ui-popup" class="w2ui-popup" style="opacity: 0; left: '+d+"px; top: "+l+"px;     width: "+parseInt(e.width)+"px; height: "+parseInt(e.height)+"px; "+w2utils.cssPrefix("transform","scale(0.8)",!0)+'">   <div class="w2ui-msg-title" style="'+(""==e.title?"display: none":"")+'">'+u+e.title+'</div>   <div class="w2ui-box1" style="'+(""==e.title?"top: 0px !important;":"")+(""==e.buttons?"bottom: 0px !important;":"")+'">       <div class="w2ui-msg-body'+(""!=!e.title?" w2ui-msg-no-title":"")+(""!=!e.buttons?" w2ui-msg-no-buttons":"")+'" style="'+e.style+'">'+e.body+'</div>   </div>   <div class="w2ui-box2" style="'+(""==e.title?"top: 0px !important;":"")+(""==e.buttons?"bottom: 0px !important;":"")+'">       <div class="w2ui-msg-body'+(""!=!e.title?" w2ui-msg-no-title":"")+(""!=!e.buttons?" w2ui-msg-no-buttons":"")+'" style="'+e.style+'"></div>       </div>   <div class="w2ui-msg-buttons" style="'+(""==e.buttons?"display: none":"")+'">'+e.buttons+"</div></div>";$("body").append(c),setTimeout(function(){$("#w2ui-popup .w2ui-box2").hide(),$("#w2ui-popup").css("opacity","1").css(w2utils.cssPrefix({transition:e.speed+"s opacity, "+e.speed+"s -webkit-transform",transform:"scale(1)"}))},1),setTimeout(function(){$("#w2ui-popup").css(w2utils.cssPrefix("transform","")),w2popup.status="open",setTimeout(function(){n.trigger($.extend(h,{phase:"after"}))},100)},1e3*e.speed)}else{var h=this.trigger({phase:"before",type:"open",target:"popup",options:e,present:!0});if(h.isCancelled===!0)return;w2popup.status="opening","undefined"!=typeof r&&(r.maximized||r.width==e.width&&r.height==e.height||w2popup.resize(e.width,e.height),e.prevSize=e.width+"px:"+e.height+"px",e.maximized=r.maximized);var p=$("#w2ui-popup .w2ui-box2 > .w2ui-msg-body").html(e.body);p.length>0&&(p[0].style.cssText=e.style),""!=e.buttons?($("#w2ui-popup .w2ui-msg-buttons").show().html(e.buttons),$("#w2ui-popup .w2ui-msg-body").removeClass("w2ui-msg-no-buttons"),$("#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2").css("bottom","")):($("#w2ui-popup .w2ui-msg-buttons").hide().html(""),$("#w2ui-popup .w2ui-msg-body").addClass("w2ui-msg-no-buttons"),$("#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2").css("bottom","0px")),""!=e.title?($("#w2ui-popup .w2ui-msg-title").show().html((e.showClose?'<div class="w2ui-msg-button w2ui-msg-close" onmousedown="event.stopPropagation()" onclick="w2popup.close()">Close</div>':"")+(e.showMax?'<div class="w2ui-msg-button w2ui-msg-max" onmousedown="event.stopPropagation()" onclick="w2popup.toggle()">Max</div>':"")+e.title),$("#w2ui-popup .w2ui-msg-body").removeClass("w2ui-msg-no-title"),$("#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2").css("top","")):($("#w2ui-popup .w2ui-msg-title").hide().html(""),$("#w2ui-popup .w2ui-msg-body").addClass("w2ui-msg-no-title"),$("#w2ui-popup .w2ui-box1, #w2ui-popup .w2ui-box2").css("top","0px"));var f=$("#w2ui-popup .w2ui-box1")[0],g=$("#w2ui-popup .w2ui-box2")[0];w2utils.transition(f,g,e.transition),g.className="w2ui-box1",f.className="w2ui-box2",$(g).addClass("w2ui-current-box"),$("#w2ui-popup").data("prev-size",null),setTimeout(function(){w2popup.status="open",n.trigger($.extend(h,{phase:"after"}))},100)}e._last_w2ui_name=w2utils.keyboard.active(),w2utils.keyboard.clear(),e.keyboard&&$(document).on("keydown",this.keydown);var m={resizing:!1,mvMove:i,mvStop:s};return $("#w2ui-popup .w2ui-msg-title").on("mousedown",function(e){w2popup.get().maximized||t(e)}),this},keydown:function(e){var t=$("#w2ui-popup").data("options");if(!t||t.keyboard){var i=w2popup.trigger({phase:"before",type:"keydown",target:"popup",options:t,originalEvent:e});if(i.isCancelled!==!0){switch(e.keyCode){case 27:e.preventDefault(),$("#w2ui-popup .w2ui-popup-message").length>0?w2popup.message():w2popup.close()}w2popup.trigger($.extend(i,{phase:"after"}))}}},close:function(e){var t=this,e=$.extend({},$("#w2ui-popup").data("options"),e);if(0!=$("#w2ui-popup").length){var i=this.trigger({phase:"before",type:"close",target:"popup",options:e});i.isCancelled!==!0&&(w2popup.status="closing",$("#w2ui-popup").css("opacity","0").css(w2utils.cssPrefix({transition:e.speed+"s opacity, "+e.speed+"s -webkit-transform",transform:"scale(0.9)"})),w2popup.unlockScreen(e),setTimeout(function(){$("#w2ui-popup").remove(),w2popup.status="closed",t.trigger($.extend(i,{phase:"after"}))},1e3*e.speed),w2utils.keyboard.active(e._last_w2ui_name,{}),e.keyboard&&$(document).off("keydown",this.keydown))}},toggle:function(){var e=this,t=$("#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(){e.trigger($.extend(i,{phase:"after"}))},1e3*t.speed+50))},max:function(){var e=this,t=$("#w2ui-popup").data("options");if(t.maximized!==!0){var i=this.trigger({phase:"before",type:"max",target:"popup",options:t});i.isCancelled!==!0&&(w2popup.status="resizing",t.prevSize=$("#w2ui-popup").css("width")+":"+$("#w2ui-popup").css("height"),w2popup.resize(1e4,1e4,function(){w2popup.status="open",t.maximized=!0,e.trigger($.extend(i,{phase:"after"})),$("#w2ui-popup .w2ui-grid, #w2ui-popup .w2ui-form, #w2ui-popup .w2ui-layout").each(function(){var e=$(this).attr("name");w2ui[e]&&w2ui[e].resize&&w2ui[e].resize()})}))}},min:function(){var e=this,t=$("#w2ui-popup").data("options");if(t.maximized===!0){var i=t.prevSize.split(":"),s=this.trigger({phase:"before",type:"min",target:"popup",options:t});s.isCancelled!==!0&&(w2popup.status="resizing",w2popup.resize(parseInt(i[0]),parseInt(i[1]),function(){w2popup.status="open",t.maximized=!1,t.prevSize=null,e.trigger($.extend(s,{phase:"after"})),$("#w2ui-popup .w2ui-grid, #w2ui-popup .w2ui-form, #w2ui-popup .w2ui-layout").each(function(){var e=$(this).attr("name");w2ui[e]&&w2ui[e].resize&&w2ui[e].resize()})}))}},get:function(){return $("#w2ui-popup").data("options")},set:function(e){w2popup.open(e)},clear:function(){$("#w2ui-popup .w2ui-msg-title").html(""),$("#w2ui-popup .w2ui-msg-body").html(""),$("#w2ui-popup .w2ui-msg-buttons").html("")},reset:function(){w2popup.open(w2popup.defaults)},load:function(e){function t(t,i){if(delete e.url,$("body").append('<div id="w2ui-tmp" style="display: none">'+t+"</div>"),"undefined"!=typeof i&&$("#w2ui-tmp #"+i).length>0?$("#w2ui-tmp #"+i).w2popup(e):$("#w2ui-tmp > div").w2popup(e),$("#w2ui-tmp > style").length>0){var s=$("<div>").append($("#w2ui-tmp > style").clone()).html();0==$("#w2ui-popup #div-style").length&&$("#w2ui-popup").append('<div id="div-style" style="position: absolute; left: -100; width: 1px"></div>'),$("#w2ui-popup #div-style").html(s)}$("#w2ui-tmp").remove()}if(w2popup.status="loading","undefined"==String(e.url))return void console.log("ERROR: The url parameter is empty.");var i=String(e.url).split("#"),s=i[0],n=i[1];"undefined"==String(e)&&(e={});var r=$("#w2ui-popup").data(s);"undefined"!=typeof r&&null!=r?t(r,n):$.get(s,function(e,i,r){t(r.responseText,n),$("#w2ui-popup").data(s,r.responseText)})},message:function(e){$().w2tag(),e||(e={width:200,height:100});var t=parseInt($("#w2ui-popup").width()),i=parseInt($("#w2ui-popup").height());e.originalWidth=e.width,e.originalHeight=e.height,parseInt(e.width)<10&&(e.width=10),parseInt(e.height)<10&&(e.height=10),"undefined"==typeof e.hideOnClick&&(e.hideOnClick=!1);var s=$("#w2ui-popup").data("options")||{},n=parseInt($("#w2ui-popup > .w2ui-msg-title").css("height"));("undefined"==typeof e.width||e.width>s.width-10)&&(e.width=s.width-10),("undefined"==typeof e.height||e.height>s.height-n-5)&&(e.height=s.height-n-5),e.originalHeight<0&&(e.height=i+e.originalHeight-n),e.originalWidth<0&&(e.width=t+2*e.originalWidth);var r=$("#w2ui-popup .w2ui-msg-title"),a=$("#w2ui-popup .w2ui-popup-message").length;if(""==$.trim(e.html)&&""==$.trim(e.body)&&""==$.trim(e.buttons)){var o=$("#w2ui-popup #w2ui-message"+(a-1)),e=o.data("options")||{};o.css(w2utils.cssPrefix({transition:"0.15s",transform:"translateY(-"+e.height+"px)"})),1==a?w2popup.unlock(150):$("#w2ui-popup #w2ui-message"+(a-2)).css("z-index",1500),setTimeout(function(){o.remove(),"function"==typeof e.onClose&&e.onClose()},150)}else{(""!=$.trim(e.body)||""!=$.trim(e.buttons))&&(e.html='<div class="w2ui-popup-message-body">'+e.body+'</div><div class="w2ui-popup-message-buttons">'+e.buttons+"</div>"),$("#w2ui-popup .w2ui-popup-message").css("z-index",1390),r.css("z-index",1501),$("#w2ui-popup .w2ui-box1").before('<div id="w2ui-message'+a+'" class="w2ui-popup-message" style="display: none; z-index: 1500; '+(0==r.length?"top: 0px;":"top: "+w2utils.getSize(r,"height")+"px;")+("undefined"!=typeof e.width?"width: "+e.width+"px; left: "+(t-e.width)/2+"px;":"left: 10px; right: 10px;")+("undefined"!=typeof e.height?"height: "+e.height+"px;":"bottom: 6px;")+w2utils.cssPrefix("transition",".3s",!0)+'"'+(e.hideOnClick===!0?'onclick="w2popup.message();"':"")+"></div>"),$("#w2ui-popup #w2ui-message"+a).data("options",e);var l=$("#w2ui-popup #w2ui-message"+a).css("display");$("#w2ui-popup #w2ui-message"+a).css(w2utils.cssPrefix({transform:"none"==l?"translateY(-"+e.height+"px)":"translateY(0px)"})),"none"==l&&($("#w2ui-popup #w2ui-message"+a).show().html(e.html),setTimeout(function(){$("#w2ui-popup #w2ui-message"+a).css(w2utils.cssPrefix({transform:"none"==l?"translateY(0px)":"translateY(-"+e.height+"px)"}))},1),0==a&&w2popup.lock(),setTimeout(function(){$("#w2ui-popup #w2ui-message"+a).css(w2utils.cssPrefix({transition:"0s"})),"function"==typeof e.onOpen&&e.onOpen()
  },350))}},lock:function(){var e=Array.prototype.slice.call(arguments,0);e.unshift($("#w2ui-popup")),w2utils.lock.apply(window,e)},unlock:function(e){w2utils.unlock($("#w2ui-popup"),e)},lockScreen:function(e){return $("#w2ui-lock").length>0?!1:("undefined"==typeof e&&(e=$("#w2ui-popup").data("options")),"undefined"==typeof e&&(e={}),e=$.extend({},w2popup.defaults,e),$("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: '+("IE5"==w2utils.engine?"absolute":"fixed")+"; z-Index: 1199; left: 0px; top: 0px;            padding: 0px; margin: 0px; background-color: "+e.color+'; width: 100%; height: 100%; opacity: 0;"></div>'),setTimeout(function(){$("#w2ui-lock").css("opacity",e.opacity).css(w2utils.cssPrefix("transition",e.speed+"s opacity"))},1),1==e.modal?($("#w2ui-lock").on("mousedown",function(){$("#w2ui-lock").css("opacity","0.6").css(w2utils.cssPrefix("transition",".1s"))}),$("#w2ui-lock").on("mouseup",function(){setTimeout(function(){$("#w2ui-lock").css("opacity",e.opacity).css(w2utils.cssPrefix("transition",".1s"))},100)})):$("#w2ui-lock").on("mousedown",function(){w2popup.close()}),!0)},unlockScreen:function(e){return 0==$("#w2ui-lock").length?!1:("undefined"==typeof e&&(e=$("#w2ui-popup").data("options")),"undefined"==typeof e&&(e={}),e=$.extend({},w2popup.defaults,e),$("#w2ui-lock").css("opacity","0").css(w2utils.cssPrefix("transition",e.speed+"s opacity")),setTimeout(function(){$("#w2ui-lock").remove()},1e3*e.speed),!0)},resizeMessages:function(){$("#w2ui-popup").data("options");$("#w2ui-popup .w2ui-popup-message").each(function(){var e=$(this).data("options"),t=$("#w2ui-popup");parseInt(e.width)<10&&(e.width=10),parseInt(e.height)<10&&(e.height=10);var i=parseInt(t.find("> .w2ui-msg-title").css("height")),s=parseInt(t.width()),n=parseInt(t.height());e.width=e.originalWidth,e.width>s-10&&(e.width=s-10),e.height=e.originalHeight,e.height>n-i-5&&(e.height=n-i-5),e.originalHeight<0&&(e.height=n+e.originalHeight-i),e.originalWidth<0&&(e.width=s+2*e.originalWidth),$(this).css({left:(s-e.width)/2+"px",width:e.width+"px",height:e.height+"px"})})},resize:function(e,t,i){var s=this,n=$("#w2ui-popup").data("options");e=parseInt(e),t=parseInt(t),$(window).width()-10<e&&(e=$(window).width()-10),$(window).height()-10<t&&(t=$(window).height()-10);var r=($(window).height()-t)/2*.8,a=($(window).width()-e)/2;$("#w2ui-popup").css(w2utils.cssPrefix({transition:n.speed+"s width, "+n.speed+"s height, "+n.speed+"s left, "+n.speed+"s top"})).css({top:r,left:a,width:e,height:t});var o=setInterval(function(){s.resizeMessages()},10);setTimeout(function(){clearInterval(o),n.width=e,n.height=t,s.resizeMessages(),"function"==typeof i&&i()},1e3*n.speed+50)}},$.extend(w2popup,w2utils.event)}();var w2alert=function(e,t,i){null==t&&(t=w2utils.lang("Notification")),$("#w2ui-popup").length>0&&"closing"!=w2popup.status?w2popup.message({width:400,height:170,body:'<div class="w2ui-centered" style="font-size: 13px;">'+e+"</div>",buttons:'<button onclick="w2popup.message();" class="w2ui-popup-btn w2ui-btn">'+w2utils.lang("Ok")+"</button>",onOpen:function(){$("#w2ui-popup .w2ui-popup-message .w2ui-popup-btn").focus()},onClose:function(){"function"==typeof i&&i()}}):w2popup.open({width:450,height:220,showMax:!1,showClose:!1,title:t,body:'<div class="w2ui-centered" style="font-size: 13px;">'+e+"</div>",buttons:'<button onclick="w2popup.close();" class="w2ui-popup-btn w2ui-btn">'+w2utils.lang("Ok")+"</button>",onOpen:function(){setTimeout(function(){$("#w2ui-popup .w2ui-popup-btn").focus()},1)},onKeydown:function(){$("#w2ui-popup .w2ui-popup-btn").focus().addClass("clicked")},onClose:function(){"function"==typeof i&&i()}})},w2confirm=function(e,t,i){var s={},n={msg:"",title:w2utils.lang("Confirmation"),width:$("#w2ui-popup").length>0?400:450,height:$("#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 1==arguments.length&&"object"==typeof e?$.extend(s,n,e):"function"==typeof t?$.extend(s,n,{msg:e,callBack:t}):$.extend(s,n,{msg:e,title:t,callBack:i}),"object"==typeof s.btn_yes&&(s.yes_text=s.btn_yes.text||s.yes_text,s.yes_class=s.btn_yes["class"]||s.yes_class,s.yes_style=s.btn_yes.style||s.yes_style,s.yes_callBack=s.btn_yes.callBack||s.yes_callBack),"object"==typeof s.btn_no&&(s.no_text=s.btn_no.text||s.no_text,s.no_class=s.btn_no["class"]||s.no_class,s.no_style=s.btn_no.style||s.no_style,s.no_callBack=s.btn_no.callBack||s.no_callBack),$("#w2ui-popup").length>0&&"closing"!=w2popup.status?(s.width>w2popup.get().width&&(s.width=w2popup.get().width),s.height>w2popup.get().height-50&&(s.height=w2popup.get().height-50),w2popup.message({width:s.width,height:s.height,body:'<div class="w2ui-centered" style="font-size: 13px;">'+s.msg+"</div>",buttons:'<button id="Yes" class="w2ui-popup-btn w2ui-btn '+s.yes_class+'" style="'+s.yes_style+'">'+w2utils.lang(s.yes_text)+'</button><button id="No" class="w2ui-popup-btn w2ui-btn '+s.no_class+'" style="'+s.no_style+'">'+w2utils.lang(s.no_text)+"</button>",onOpen:function(){$("#w2ui-popup .w2ui-popup-message .w2ui-btn").on("click",function(e){w2popup.message(),"function"==typeof s.callBack&&s.callBack(e.target.id),"Yes"==e.target.id&&"function"==typeof s.yes_callBack&&s.yes_callBack(),"No"==e.target.id&&"function"==typeof s.no_callBack&&s.no_callBack()})}})):(w2utils.isInt(s.height)||(s.height=s.height+50),w2popup.open({width:s.width,height:s.height,title:s.title,modal:!0,showClose:!1,body:'<div class="w2ui-centered" style="font-size: 13px;">'+s.msg+"</div>",buttons:'<button id="Yes" class="w2ui-popup-btn w2ui-btn '+s.yes_class+'" style="'+s.yes_style+'">'+w2utils.lang(s.yes_text)+'</button><button id="No" class="w2ui-popup-btn w2ui-btn '+s.no_class+'" style="'+s.no_style+'">'+w2utils.lang(s.no_text)+"</button>",onOpen:function(){setTimeout(function(){$("#w2ui-popup .w2ui-popup-btn").on("click",function(e){w2popup.close(),"function"==typeof s.callBack&&s.callBack(e.target.id),"Yes"==e.target.id&&"function"==typeof s.yes_callBack&&s.yes_callBack(),"No"==e.target.id&&"function"==typeof s.no_callBack&&s.no_callBack()}),$("#w2ui-popup .w2ui-popup-btn#No").focus()},1)},onKeydown:function(e){if(0==$("#w2ui-popup .w2ui-popup-message").length)switch(e.originalEvent.keyCode){case 13:$("#w2ui-popup .w2ui-popup-btn#Yes").focus().addClass("clicked"),w2popup.close();break;case 27:$("#w2ui-popup .w2ui-popup-btn#No").focus().click(),w2popup.close()}}})),{yes:function(e){return s.yes_callBack=e,this},no:function(e){return s.no_callBack=e,this}}};!function(){var e=function(e){this.box=null,this.name=null,this.active=null,this.flow="down",this.tabs=[],this.routeData={},this.right="",this.style="",this.onClick=null,this.onClose=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,$.extend(this,{handlers:[]}),$.extend(!0,this,w2obj.tabs,e)};$.fn.w2tabs=function(t){if($.isPlainObject(t)){if(!w2utils.checkName(t,"w2tabs"))return;for(var i=t.tabs||[],s=new e(t),n=0;n<i.length;n++)s.tabs[n]=$.extend({},e.prototype.tab,i[n]);return 0!==$(this).length&&s.render($(this)[0]),w2ui[s.name]=s,s}var r=w2ui[$(this).attr("name")];return r?arguments.length>0?(r[t]&&r[t].apply(r,Array.prototype.slice.call(arguments,1)),this):r:null},e.prototype={tab:{id:null,text:"",route:null,hidden:!1,disabled:!1,closable:!1,hint:"",style:"",onClick:null,onRefresh:null,onClose:null},add:function(e){return this.insert(null,e)},insert:function(t,i){$.isArray(i)||(i=[i]);for(var s=0;s<i.length;s++){if("undefined"==typeof i[s].id)return void console.log('ERROR: The parameter "id" is required but not supplied. (obj: '+this.name+")");if(!w2utils.checkUniqueId(i[s].id,this.tabs,"tabs",this.name))return;var n=$.extend({},e.prototype.tab,i[s]);if(null===t||"undefined"==typeof t)this.tabs.push(n);else{var r=this.get(t,!0);this.tabs=this.tabs.slice(0,r).concat([n],this.tabs.slice(r))}this.refresh(i[s].id)}},remove:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);if(!i)return!1;e++,this.tabs.splice(this.get(i.id,!0),1),$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id)).remove()}return e},select:function(e){return this.active==e||null===this.get(e)?!1:(this.active=e,this.refresh(),!0)},set:function(e,t){var i=this.get(e,!0);return null===i?!1:($.extend(this.tabs[i],t),this.refresh(e),!0)},get:function(e,t){if(0===arguments.length){for(var i=[],s=0;s<this.tabs.length;s++)null!=this.tabs[s].id&&i.push(this.tabs[s].id);return i}for(var n=0;n<this.tabs.length;n++)if(this.tabs[n].id==e)return t===!0?n:this.tabs[n];return null},show:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&n.hidden!==!1&&(t++,n.hidden=!1,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},hide:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&n.hidden!==!0&&(t++,n.hidden=!0,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},enable:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&n.disabled!==!1&&(t++,n.disabled=!1,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},disable:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&n.disabled!==!0&&(t++,n.disabled=!0,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},refresh:function(e){var t=(new Date).getTime();"up"==this.flow?$(this.box).addClass("w2ui-tabs-up"):$(this.box).removeClass("w2ui-tabs-up");var i=this.trigger({phase:"before",type:"refresh",target:"undefined"!=typeof e?e:this.name,object:this.get(e)});if(i.isCancelled!==!0){if("undefined"==typeof e)for(var s=0;s<this.tabs.length;s++)this.refresh(this.tabs[s].id);else{var n=this.get(e);if(null===n)return!1;"undefined"!=typeof n.caption&&(n.text=n.caption);var r=$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(n.id)),a=(n.closable?'<div class="w2ui-tab-close" onclick="w2ui[\''+this.name+"'].animateClose('"+n.id+"', event);\"></div>":"")+'    <div class="w2ui-tab'+(this.active===n.id?" active":"")+(n.closable?" closable":"")+'"         title="'+("undefined"!=typeof n.hint?n.hint:"")+'" style="'+n.style+'"         onclick="w2ui[\''+this.name+"'].click('"+n.id+"', event);\">"+n.text+"</div>";if(0===r.length){var o="";n.hidden&&(o+="display: none;"),n.disabled&&(o+="opacity: 0.2;");var l='<td id="tabs_'+this.name+"_tab_"+n.id+'" style="'+o+'" valign="middle">'+a+"</td>";this.get(e,!0)!==this.tabs.length-1&&$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(e,!0))+1].id)).length>0?$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(e,!0))+1].id)).before(l):$(this.box).find("#tabs_"+this.name+"_right").before(l)}else r.html(a),n.hidden?r.css("display","none"):r.css("display",""),r.css(n.disabled?{opacity:"0.2"}:{opacity:"1"})}return $("#tabs_"+this.name+"_right").html(this.right),this.trigger($.extend(i,{phase:"after"})),(new Date).getTime()-t}},render:function(e){var t=(new Date).getTime(),i=this.trigger({phase:"before",type:"render",target:this.name,box:e});if(i.isCancelled!==!0){if("undefined"!=typeof e&&null!==e&&($(this.box).find("> table #tabs_"+this.name+"_right").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),this.box=e),!this.box)return!1;var s='<table cellspacing="0" cellpadding="1" width="100%">    <tr><td width="100%" id="tabs_'+this.name+'_right" align="right">'+this.right+"</td></tr></table>";return $(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-tabs").html(s),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.trigger($.extend(i,{phase:"after"})),this.refresh(),(new Date).getTime()-t}},resize:function(){var e=(new Date).getTime(),t=this.trigger({phase:"before",type:"resize",target:this.name});return t.isCancelled!==!0?(this.trigger($.extend(t,{phase:"after"})),(new Date).getTime()-e):void 0},destroy:function(){var e=this.trigger({phase:"before",type:"destroy",target:this.name});e.isCancelled!==!0&&($(this.box).find("> table #tabs_"+this.name+"_right").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-tabs").html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})))},click:function(e,t){var i=this.get(e);if(null===i||i.disabled)return!1;var s=this.trigger({phase:"before",type:"click",target:e,tab:i,object:i,originalEvent:t});if(s.isCancelled!==!0){if($(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.active)+" .w2ui-tab").removeClass("active"),this.active=i.id,i.route){var n=String("/"+i.route).replace(/\/{2,}/g,"/"),r=w2utils.parseRoute(n);if(r.keys.length>0)for(var a=0;a<r.keys.length;a++)null!=this.routeData[r.keys[a].name]&&(n=n.replace(new RegExp(":"+r.keys[a].name,"g"),this.routeData[r.keys[a].name]));setTimeout(function(){window.location.hash=n},1)}this.trigger($.extend(s,{phase:"after"})),this.refresh(e)}},animateClose:function(e,t){var i=this.get(e);if(null===i||i.disabled)return!1;var s=this.trigger({phase:"before",type:"close",target:e,object:this.get(e),originalEvent:t});if(s.isCancelled!==!0){var n=this;$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(i.id)).css(w2utils.cssPrefix("transition",".2s")).css("opacity","0"),setTimeout(function(){var e=$(n.box).find("#tabs_"+n.name+"_tab_"+w2utils.escapeId(i.id)).width();$(n.box).find("#tabs_"+n.name+"_tab_"+w2utils.escapeId(i.id)).html('<div style="width: '+e+"px; "+w2utils.cssPrefix("transition",".2s",!0)+'"></div>'),setTimeout(function(){$(n.box).find("#tabs_"+n.name+"_tab_"+w2utils.escapeId(i.id)).find(":first-child").css({width:"0px"})},50)},200),setTimeout(function(){n.remove(e)},450),this.trigger($.extend(s,{phase:"after"})),this.refresh()}},animateInsert:function(e,t){if(null!==this.get(e)&&$.isPlainObject(t)&&w2utils.checkUniqueId(t.id,this.tabs,"tabs",this.name)){var i=$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(t.id));if(0===i.length){"undefined"!=typeof t.caption&&(t.text=t.caption);var s='<div id="_tmp_tabs" class="w2ui-reset w2ui-tabs" style="position: absolute; top: -1000px;"><table cellspacing="0" cellpadding="1" width="100%"><tr><td id="_tmp_simple_tab" style="" valign="middle">'+(t.closable?'<div class="w2ui-tab-close"></div>':"")+'    <div class="w2ui-tab '+(this.active===t.id?"active":"")+'">'+t.text+"</div></td></tr></table></div>";$("body").append(s);var n='<div style="width: 1px; '+w2utils.cssPrefix("transition",".2s",!0)+'">&nbsp;</div>',r="";t.hidden&&(r+="display: none;"),t.disabled&&(r+="opacity: 0.2;");var a='<td id="tabs_'+this.name+"_tab_"+t.id+'" style="'+r+'" valign="middle">'+n+"</td>";this.get(e,!0)!==this.tabs.length&&$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(e,!0))].id)).length>0?$(this.box).find("#tabs_"+this.name+"_tab_"+w2utils.escapeId(this.tabs[parseInt(this.get(e,!0))].id)).before(a):$(this.box).find("#tabs_"+this.name+"_right").before(a);var o=this;setTimeout(function(){var e=$("#_tmp_simple_tab").width();$("#_tmp_tabs").remove(),$("#tabs_"+o.name+"_tab_"+w2utils.escapeId(t.id)+" > div").css("width",e+"px")},1),setTimeout(function(){o.insert(e,t)},200)}}}},$.extend(e.prototype,w2utils.event),w2obj.tabs=e}(),function(){var e=function(e){this.box=null,this.name=null,this.routeData={},this.items=[],this.right="",this.onClick=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,$.extend(!0,this,w2obj.toolbar,e)};$.fn.w2toolbar=function(t){if($.isPlainObject(t)){if(!w2utils.checkName(t,"w2toolbar"))return;var i=t.items||[],s=new e(t);$.extend(s,{items:[],handlers:[]});for(var n=0;n<i.length;n++)s.items[n]=$.extend({},e.prototype.item,i[n]);return 0!==$(this).length&&s.render($(this)[0]),w2ui[s.name]=s,s}var r=w2ui[$(this).attr("name")];return r?arguments.length>0?(r[t]&&r[t].apply(r,Array.prototype.slice.call(arguments,1)),this):r:null},e.prototype={item:{id:null,type:"button",text:"",route:null,html:"",img:null,icon:null,count:null,hidden:!1,disabled:!1,checked:!1,arrow:!0,hint:"",group:null,items:null,overlay:{},onClick:null},add:function(e){this.insert(null,e)},insert:function(t,i){$.isArray(i)||(i=[i]);for(var s=0;s<i.length;s++){if("undefined"==typeof i[s].type)return void console.log('ERROR: The parameter "type" is required but not supplied in w2toolbar.add() method.');if(-1===$.inArray(String(i[s].type),["button","check","radio","drop","menu","break","html","spacer"]))return void console.log('ERROR: The parameter "type" should be one of the following [button, check, radio, drop, menu, break, html, spacer] in w2toolbar.add() method.');if("undefined"==typeof i[s].id)return void console.log('ERROR: The parameter "id" is required but not supplied in w2toolbar.add() method.');if(!w2utils.checkUniqueId(i[s].id,this.items,"toolbar items",this.name))return;var n=$.extend({},e.prototype.item,i[s]);if(null==t)this.items.push(n);else{var r=this.get(t,!0);this.items=this.items.slice(0,r).concat([n],this.items.slice(r))}this.refresh(n.id)}},remove:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);if(i){e++,$(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(i.id)).remove();var s=this.get(i.id,!0);null!=s&&this.items.splice(s,1)}}return e},set:function(e,t){var i=this.get(e,!0);return null===i?!1:($.extend(this.items[i],t),this.refresh(e),!0)},get:function(e,t){if(0===arguments.length){for(var i=[],s=0;s<this.items.length;s++)null!==this.items[s].id&&i.push(this.items[s].id);return i}for(var n=0;n<this.items.length;n++)if(this.items[n].id===e)return t===!0?n:this.items[n];return null},show:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&(t++,n.hidden=!1,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},hide:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&(t++,n.hidden=!0,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},enable:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]),r=arguments[s].split(":"),n=this.get(r[0]);if(n)if(t++,i.push(n.id),"menu"==n.type&&2==r.length)for(var a=0;a<n.items.length;a++){var o=n.items[a];(o.id==r[1]||null==o.id&&o.text==r[1])&&(o.disabled=!1)}else n.disabled=!1}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},disable:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=arguments[s].split(":"),r=this.get(n[0]);if(r)if(t++,i.push(r.id),"menu"==r.type&&2==n.length)for(var a=0;a<r.items.length;a++){var o=r.items[a];(o.id==n[1]||null==o.id&&o.text==n[1])&&(o.disabled=!0)}else r.disabled=!0}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},check:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&(t++,n.checked=!0,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},uncheck:function(){for(var e=this,t=0,i=[],s=0;s<arguments.length;s++){var n=this.get(arguments[s]);n&&(t++,n.checked=!1,i.push(n.id))}return setTimeout(function(){for(var t=0;t<i.length;t++)e.refresh(i[t])},15),t},render:function(e){var t=(new Date).getTime(),i=this.trigger({phase:"before",type:"render",target:this.name,box:e});if(i.isCancelled!==!0&&(null!=e&&($(this.box).find("> table #tb_"+this.name+"_right").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),this.box=e),this.box)){for(var s='<table cellspacing="0" cellpadding="0" width="100%"><tr>',n=0;n<this.items.length;n++){var r=this.items[n];null==r.id&&(r.id="item_"+n),null!==r&&(s+="spacer"===r.type?'<td width="100%" id="tb_'+this.name+"_item_"+r.id+'" align="right"></td>':'<td id="tb_'+this.name+"_item_"+r.id+'" style="'+(r.hidden?"display: none":"")+'"     class="'+(r.disabled?"disabled":"")+'" valign="middle">'+this.getItemHTML(r)+"</td>")}return s+='<td width="100%" id="tb_'+this.name+'_right" align="right">'+this.right+"</td>",s+="</tr></table>",$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-toolbar").html(s),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),this.trigger($.extend(i,{phase:"after"})),(new Date).getTime()-t}},refresh:function(e){var t=(new Date).getTime(),i=this.trigger({phase:"before",type:"refresh",target:"undefined"!=typeof e?e:this.name,item:this.get(e)});if(i.isCancelled!==!0){if(null==e)for(var s=0;s<this.items.length;s++){var n=this.items[s];null==n.id&&(n.id="item_"+s),this.refresh(n.id)}var r=this.get(e);if(null===r)return!1;var a=$(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(r.id)),o=this.getItemHTML(r);return 0===a.length?(o="spacer"===r.type?'<td width="100%" id="tb_'+this.name+"_item_"+r.id+'" align="right"></td>':'<td id="tb_'+this.name+"_item_"+r.id+'" style="'+(r.hidden?"display: none":"")+'"     class="'+(r.disabled?"disabled":"")+'" valign="middle">'+o+"</td>",this.get(e,!0)===this.items.length-1?$(this.box).find("#tb_"+this.name+"_right").before(o):$(this.box).find("#tb_"+this.name+"_item_"+w2utils.escapeId(this.items[parseInt(this.get(e,!0))+1].id)).before(o)):(a.html(o),r.hidden?a.css("display","none"):a.css("display",""),r.disabled?a.addClass("disabled"):a.removeClass("disabled")),this.trigger($.extend(i,{phase:"after"})),(new Date).getTime()-t}},resize:function(){var e=(new Date).getTime(),t=this.trigger({phase:"before",type:"resize",target:this.name});return t.isCancelled!==!0?(this.trigger($.extend(t,{phase:"after"})),(new Date).getTime()-e):void 0},destroy:function(){var e=this.trigger({phase:"before",type:"destroy",target:this.name});e.isCancelled!==!0&&($(this.box).find("> table #tb_"+this.name+"_right").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-toolbar").html(""),$(this.box).html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})))},getItemHTML:function(e){var t="";switch("undefined"!=typeof e.caption&&(e.text=e.caption),"undefined"==typeof e.hint&&(e.hint=""),"undefined"==typeof e.text&&(e.text=""),e.type){case"menu":case"button":case"check":case"radio":case"drop":var i="<td>&nbsp;</td>";e.img&&(i='<td><div class="w2ui-tb-image w2ui-icon '+e.img+'"></div></td>'),e.icon&&(i='<td><div class="w2ui-tb-image"><span class="'+e.icon+'"></span></div></td>'),t+='<table cellpadding="0" cellspacing="0" title="'+e.hint+'" class="w2ui-button '+(e.checked?"checked":"")+'"        onclick     = "var el=w2ui[\''+this.name+"']; if (el) el.click('"+e.id+'\', event);"        onmouseover = "'+(e.disabled?"":"$(this).addClass('over');")+'"       onmouseout  = "'+(e.disabled?"":"$(this).removeClass('over').removeClass('down');")+'"       onmousedown = "'+(e.disabled?"":"$(this).addClass('down');")+'"       onmouseup   = "'+(e.disabled?"":"$(this).removeClass('down');")+'"><tr><td>  <table cellpadding="1" cellspacing="0">  <tr>'+i+(""!==e.text?'<td class="w2ui-tb-caption" nowrap>'+e.text+"</td>":"")+(null!=e.count?'<td class="w2ui-tb-count" nowrap><span>'+e.count+"</span></td>":"")+("drop"!==e.type&&"menu"!==e.type||e.arrow===!1?"":'<td class="w2ui-tb-down" nowrap><div></div></td>')+"  </tr></table></td></tr></table>";break;case"break":t+='<table cellpadding="0" cellspacing="0"><tr>    <td><div class="w2ui-break">&nbsp;</div></td></tr></table>';break;case"html":t+='<table cellpadding="0" cellspacing="0"><tr>    <td nowrap>'+e.html+"</td></tr></table>"}var s="";return"function"==typeof e.onRender&&(s=e.onRender.call(this,e.id,t)),"function"==typeof this.onRender&&(s=this.onRender(e.id,t)),""!==s&&null!=s&&(t=s),t},menuClick:function(e){var t=this;if(e.item&&!e.item.disabled){var i=this.trigger({phase:"before",type:"click",target:e.item.id+":"+e.subItem.id,item:e.item,subItem:e.subItem,originalEvent:e.originalEvent});if(i.isCancelled===!0)return;var s=e.subItem;if(s.route){var n=String("/"+s.route).replace(/\/{2,}/g,"/"),r=w2utils.parseRoute(n);if(r.keys.length>0)for(var a=0;a<r.keys.length;a++)null!=t.routeData[r.keys[a].name]&&(n=n.replace(new RegExp(":"+r.keys[a].name,"g"),this.routeData[r.keys[a].name]));setTimeout(function(){window.location.hash=n},1)}this.trigger($.extend(i,{phase:"after"}))}},click:function(e,t){var i=this,s=this.get(e);if(s&&!s.disabled){var n=this.trigger({phase:"before",type:"click",target:"undefined"!=typeof e?e:this.name,item:s,object:s,originalEvent:t});if(n.isCancelled===!0)return;var r="#tb_"+this.name+"_item_"+w2utils.escapeId(s.id)+" table.w2ui-button";if($(r).removeClass("down"),"radio"===s.type){for(var a=0;a<this.items.length;a++){var o=this.items[a];null!=o&&o.id!==s.id&&"radio"===o.type&&o.group===s.group&&o.checked&&(o.checked=!1,this.refresh(o.id))}s.checked=!0,$(r).addClass("checked")}if(("drop"===s.type||"menu"===s.type)&&(s.checked?s.checked=!1:setTimeout(function(){function e(){s.checked=!1,$(r).removeClass("checked")}var t=$("#tb_"+i.name+"_item_"+w2utils.escapeId(s.id));$.isPlainObject(s.overlay)||(s.overlay={});var n=(t.width()-50)/2;n>19&&(n=19),"drop"===s.type&&t.w2overlay(s.html,$.extend({name:i.name,left:n,top:3},s.overlay,{onHide:function(){e()}})),"menu"===s.type&&t.w2menu(s.items,$.extend({left:n,top:3},s.overlay,{select:function(t){i.menuClick({name:i.name,item:s,subItem:t.item,originalEvent:t.originalEvent}),e()},onHide:function(){e()}}))},1)),("check"===s.type||"drop"===s.type||"menu"===s.type)&&(s.checked=!s.checked,s.checked?$(r).addClass("checked"):$(r).removeClass("checked")),s.route){var l=String("/"+s.route).replace(/\/{2,}/g,"/"),d=w2utils.parseRoute(l);if(d.keys.length>0)for(var h=0;h<d.keys.length;h++)l=l.replace(new RegExp(":"+d.keys[h].name,"g"),this.routeData[d.keys[h].name]);setTimeout(function(){window.location.hash=l},1)}this.trigger($.extend(n,{phase:"after"}))}}},$.extend(e.prototype,w2utils.event),w2obj.toolbar=e}(),function(){var e=function(e){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.keyboard=!0,this.flat=!1,this.onClick=null,this.onDblClick=null,this.onContextMenu=null,this.onMenuClick=null,this.onExpand=null,this.onCollapse=null,this.onKeydown=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,this.onFocus=null,this.onBlur=null,$.extend(!0,this,w2obj.sidebar,e)};$.fn.w2sidebar=function(t){if($.isPlainObject(t)){if(!w2utils.checkName(t,"w2sidebar"))return;var i=t.nodes,s=new e(t);return $.extend(s,{handlers:[],nodes:[]}),"undefined"!=typeof i&&s.add(s,i),0!==$(this).length&&s.render($(this)[0]),s.sidebar=s,w2ui[s.name]=s,s}var n=w2ui[$(this).attr("name")];return n?arguments.length>0?(n[t]&&n[t].apply(n,Array.prototype.slice.call(arguments,1)),this):n:null},e.prototype={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,plus:!1,onClick:null,onDblClick:null,onContextMenu:null,onExpand:null,onCollapse:null,parent:null,sidebar:null},add:function(e,t){return 1==arguments.length&&(t=arguments[0],e=this),"string"==typeof e&&(e=this.get(e)),this.insert(e,null,t)},insert:function(t,i,s){var n,r,a,o,l;if(2==arguments.length)if(s=arguments[1],i=arguments[0],null!=i){if(r=this.get(i),null===r)return $.isArray(s)||(s=[s]),n=null!=s[0].caption?s[0].caption:s[0].text,console.log('ERROR: Cannot insert node "'+n+'" because cannot find node "'+i+'" to insert before.'),null;t=this.get(i).parent}else t=this;"string"==typeof t&&(t=this.get(t)),$.isArray(s)||(s=[s]);for(var d=0;d<s.length;d++)if(o=s[d],null!=typeof o.id)if(null===this.get(this,o.id)){if(a=$.extend({},e.prototype.node,o),a.sidebar=this,a.parent=t,l=a.nodes||[],a.nodes=[],null===i)t.nodes.push(a);else{if(r=this.get(t,i,!0),null===r)return n=null!=o.caption?o.caption:o.text,console.log('ERROR: Cannot insert node "'+n+'" because cannot find node "'+i+'" to insert before.'),null;t.nodes.splice(r,0,a)}l.length>0&&this.insert(a,null,l)}else n=null!=o.caption?o.caption:o.text,console.log("ERROR: Cannot insert node with id="+o.id+" (text: "+n+") because another node with the same id already exists.");else n=null!=o.caption?o.caption:o.text,console.log('ERROR: Cannot insert node "'+n+'" because it has no id.');return this.refresh(t.id),a},remove:function(){for(var e,t=0,i=0;i<arguments.length;i++)if(e=this.get(arguments[i]),null!==e){null!==this.selected&&this.selected===e.id&&(this.selected=null);var s=this.get(e.parent,arguments[i],!0);null!==s&&(e.parent.nodes[s].selected&&e.sidebar.unselect(e.id),e.parent.nodes.splice(s,1),t++)}return t>0&&1==arguments.length?this.refresh(e.parent.id):this.refresh(),t},set:function(e,t,i){if(2==arguments.length&&(i=t,t=e,e=this),"string"==typeof e&&(e=this.get(e)),null==e.nodes)return null;for(var s=0;s<e.nodes.length;s++){if(e.nodes[s].id===t){var n=i.nodes;return $.extend(e.nodes[s],i,{nodes:[]}),null!=n&&this.add(e.nodes[s],n),this.refresh(t),!0}var r=this.set(e.nodes[s],t,i);if(r)return!0}return!1},get:function(e,t,i){if(0===arguments.length){for(var s=[],n=this.find({}),r=0;r<n.length;r++)null!=n[r].id&&s.push(n[r].id);return s}if((1==arguments.length||2==arguments.length&&t===!0)&&(i=t,t=e,e=this),"string"==typeof e&&(e=this.get(e)),null==e.nodes)return null;for(var a=0;a<e.nodes.length;a++){if(e.nodes[a].id==t)return i===!0?a:e.nodes[a];var o=this.get(e.nodes[a],t,i);if(o||0===o)return o}return null},find:function(e,t,i){if(1==arguments.length&&(t=e,e=this),i||(i=[]),"string"==typeof e&&(e=this.get(e)),null==e.nodes)return i;for(var s=0;s<e.nodes.length;s++){var n=!0;for(var r in t)e.nodes[s][r]!=t[r]&&(n=!1);n&&i.push(e.nodes[s]),e.nodes[s].nodes.length>0&&(i=this.find(e.nodes[s],t,i))}return i},hide:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);null!==i&&(i.hidden=!0,e++)}return 1==arguments.length?this.refresh(arguments[0]):this.refresh(),e},show:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);null!==i&&(i.hidden=!1,e++)}return 1==arguments.length?this.refresh(arguments[0]):this.refresh(),e},disable:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);null!==i&&(i.disabled=!0,i.selected&&this.unselect(i.id),e++)}return 1==arguments.length?this.refresh(arguments[0]):this.refresh(),e},enable:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);null!==i&&(i.disabled=!1,e++)}return 1==arguments.length?this.refresh(arguments[0]):this.refresh(),e},select:function(e){var t=this.get(e);return t?this.selected==e&&t.selected?!1:(this.unselect(this.selected),$(this.box).find("#node_"+w2utils.escapeId(e)).addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),t.selected=!0,this.selected=e,!0):!1},unselect:function(e){var t=this.get(e);return t?(t.selected=!1,$(this.box).find("#node_"+w2utils.escapeId(e)).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),this.selected==e&&(this.selected=null),!0):!1},toggle:function(e){var t=this.get(e);return null===t?!1:t.plus?(this.set(e,{plus:!1}),this.expand(e),void this.refresh(e)):0===t.nodes.length?!1:this.get(e).expanded?this.collapse(e):this.expand(e)},collapse:function(e){var t=this,i=this.get(e),s=this.trigger({phase:"before",type:"collapse",target:e,object:i});return s.isCancelled!==!0?($(this.box).find("#node_"+w2utils.escapeId(e)+"_sub").slideUp(200),$(this.box).find("#node_"+w2utils.escapeId(e)+" .w2ui-node-dots:first-child").html('<div class="w2ui-expand">+</div>'),i.expanded=!1,this.trigger($.extend(s,{phase:"after"})),setTimeout(function(){t.refresh(e)
  },200),!0):void 0},collapseAll:function(e){if("undefined"==typeof e&&(e=this),"string"==typeof e&&(e=this.get(e)),null==e.nodes)return!1;for(var t=0;t<e.nodes.length;t++)e.nodes[t].expanded===!0&&(e.nodes[t].expanded=!1),e.nodes[t].nodes&&e.nodes[t].nodes.length>0&&this.collapseAll(e.nodes[t]);return this.refresh(e.id),!0},expand:function(e){var t=this,i=this.get(e),s=this.trigger({phase:"before",type:"expand",target:e,object:i});return s.isCancelled!==!0?($(this.box).find("#node_"+w2utils.escapeId(e)+"_sub").slideDown(200),$(this.box).find("#node_"+w2utils.escapeId(e)+" .w2ui-node-dots:first-child").html('<div class="w2ui-expand">-</div>'),i.expanded=!0,this.trigger($.extend(s,{phase:"after"})),setTimeout(function(){t.refresh(e)},200),!0):void 0},expandAll:function(e){if("undefined"==typeof e&&(e=this),"string"==typeof e&&(e=this.get(e)),null==e.nodes)return!1;for(var t=0;t<e.nodes.length;t++)e.nodes[t].expanded===!1&&(e.nodes[t].expanded=!0),e.nodes[t].nodes&&e.nodes[t].nodes.length>0&&this.collapseAll(e.nodes[t]);this.refresh(e.id)},expandParents:function(e){var t=this.get(e);return null===t?!1:(t.parent&&(t.parent.expanded=!0,this.expandParents(t.parent.id)),this.refresh(e),!0)},click:function(e,t){var i=this,s=this.get(e);if(null!==s&&!s.disabled&&!s.group){$(i.box).find(".w2ui-node.w2ui-selected").each(function(e,t){var s=$(t).attr("id").replace("node_",""),n=i.get(s);null!=n&&(n.selected=!1),$(t).removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected")});var n=$(i.box).find("#node_"+w2utils.escapeId(e)),r=$(i.box).find("#node_"+w2utils.escapeId(i.selected));n.addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected"),setTimeout(function(){var a=i.trigger({phase:"before",type:"click",target:e,originalEvent:t,node:s,object:s});if(a.isCancelled===!0)return n.removeClass("w2ui-selected").find(".w2ui-icon").removeClass("w2ui-icon-selected"),void r.addClass("w2ui-selected").find(".w2ui-icon").addClass("w2ui-icon-selected");if(null!==r&&(r.selected=!1),i.get(e).selected=!0,i.selected=e,s.route){var o=String("/"+s.route).replace(/\/{2,}/g,"/"),l=w2utils.parseRoute(o);if(l.keys.length>0)for(var d=0;d<l.keys.length;d++)null!=i.routeData[l.keys[d].name]&&(o=o.replace(new RegExp(":"+l.keys[d].name,"g"),i.routeData[l.keys[d].name]));setTimeout(function(){window.location.hash=o},1)}i.trigger($.extend(a,{phase:"after"}))},1)}},focus:function(e){var t=this.trigger({phase:"before",type:"focus",target:this.name,originalEvent:e});return t.isCancelled===!0?!1:($(this.box).find(".w2ui-selected").removeClass("w2ui-inactive"),void this.trigger($.extend(t,{phase:"after"})))},blur:function(e){var t=this.trigger({phase:"before",type:"blur",target:this.name,originalEvent:e});return t.isCancelled===!0?!1:($(this.box).find(".w2ui-selected").addClass("w2ui-inactive"),void this.trigger($.extend(t,{phase:"after"})))},keydown:function(e){function t(e,t){null===e||e.hidden||e.disabled||e.group||(a.click(e.id,t),setTimeout(function(){a.scrollIntoView()},50))}function i(e,t){for(e=t(e);null!==e&&(e.hidden||e.disabled)&&!e.group;)e=t(e);return e}function s(e,t){if(null===e)return null;var i=e.parent,n=a.get(e.id,!0),r=null;if(e.expanded&&e.nodes.length>0&&t!==!0){var o=e.nodes[0];r=o.hidden||o.disabled||o.group?s(o):o}else r=i&&n+1<i.nodes.length?i.nodes[n+1]:s(i,!0);return null!==r&&(r.hidden||r.disabled||r.group)&&(r=s(r)),r}function n(e){if(null===e)return null;var t=e.parent,i=a.get(e.id,!0),s=i>0?r(t.nodes[i-1]):t;return null!==s&&(s.hidden||s.disabled||s.group)&&(s=n(s)),s}function r(e){if(e.expanded&&e.nodes.length>0){var t=e.nodes[e.nodes.length-1];return t.hidden||t.disabled||t.group?n(t):r(t)}return e}var a=this,o=a.get(a.selected);if(o&&a.keyboard===!0){var l=a.trigger({phase:"before",type:"keydown",target:a.name,originalEvent:e});l.isCancelled!==!0&&((13==e.keyCode||32==e.keyCode)&&o.nodes.length>0&&a.toggle(a.selected),37==e.keyCode&&(o.nodes.length>0&&o.expanded?a.collapse(a.selected):(t(o.parent),o.parent.group||a.collapse(o.parent.id))),39==e.keyCode&&(o.nodes.length>0||o.plus)&&!o.expanded&&a.expand(a.selected),38==e.keyCode&&t(i(o,n)),40==e.keyCode&&t(i(o,s)),-1!=$.inArray(e.keyCode,[13,32,37,38,39,40])&&(e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation()),a.trigger($.extend(l,{phase:"after"})))}},scrollIntoView:function(e){"undefined"==typeof e&&(e=this.selected);var t=this.get(e);if(null!==t){var i=$(this.box).find(".w2ui-sidebar-div"),s=$(this.box).find("#node_"+w2utils.escapeId(e)),n=s.offset().top-i.offset().top;n+s.height()>i.height()&&i.animate({scrollTop:i.scrollTop()+i.height()/1.3},250,"linear"),0>=n&&i.animate({scrollTop:i.scrollTop()-i.height()/1.3},250,"linear")}},dblClick:function(e,t){var i=this.get(e),s=this.trigger({phase:"before",type:"dblClick",target:e,originalEvent:t,object:i});s.isCancelled!==!0&&(this.toggle(e),this.trigger($.extend(s,{phase:"after"})))},contextMenu:function(e,t){var i=this,s=i.get(e);e!=i.selected&&i.click(e),setTimeout(function(){var n=i.trigger({phase:"before",type:"contextMenu",target:e,originalEvent:t,object:s});n.isCancelled!==!0&&(s.group||s.disabled||(i.menu.length>0&&$(i.box).find("#node_"+w2utils.escapeId(e)).w2menu(i.menu,{left:(t?t.offsetX||t.pageX:50)-25,onSelect:function(t){i.menuClick(e,parseInt(t.index),t.originalEvent)}}),i.trigger($.extend(n,{phase:"after"}))))},150)},menuClick:function(e,t,i){var s=this,n=s.trigger({phase:"before",type:"menuClick",target:e,originalEvent:i,menuIndex:t,menuItem:s.menu[t]});n.isCancelled!==!0&&s.trigger($.extend(n,{phase:"after"}))},render:function(e){var t=(new Date).getTime(),i=this.trigger({phase:"before",type:"render",target:this.name,box:e});return i.isCancelled!==!0&&("undefined"!=typeof e&&null!==e&&($(this.box).find("> div > div.w2ui-sidebar-div").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),this.box=e),this.box)?($(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-sidebar").html('<div><div class="w2ui-sidebar-top"></div><div class="w2ui-sidebar-div"></div><div class="w2ui-sidebar-bottom"></div></div>'),$(this.box).find("> div").css({width:$(this.box).width()+"px",height:$(this.box).height()+"px"}),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),""!==this.topHTML&&($(this.box).find(".w2ui-sidebar-top").html(this.topHTML),$(this.box).find(".w2ui-sidebar-div").css("top",$(this.box).find(".w2ui-sidebar-top").height()+"px")),""!==this.bottomHTML&&($(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),$(this.box).find(".w2ui-sidebar-div").css("bottom",$(this.box).find(".w2ui-sidebar-bottom").height()+"px")),this.trigger($.extend(i,{phase:"after"})),this.refresh(),(new Date).getTime()-t):void 0},refresh:function(e){function t(e){var t="",i=e.img;null===i&&(i=this.img);var s=e.icon;null===s&&(s=this.icon);for(var n=e.parent,r=0;n&&null!==n.parent;)n.group&&r--,n=n.parent,r++;return"undefined"!=typeof e.caption&&(e.text=e.caption),e.group?(t='<div class="w2ui-node-group" id="node_'+e.id+'"        onclick="w2ui[\''+o.name+"'].toggle('"+e.id+"')\"        onmouseout=\"$(this).find('span:nth-child(1)').css('color', 'transparent')\"         onmouseover=\"$(this).find('span:nth-child(1)').css('color', 'inherit')\">"+(e.groupShowHide?"<span>"+w2utils.lang(!e.hidden&&e.expanded?"Hide":"Show")+"</span>":"<span></span>")+"    <span>"+e.text+'</span></div><div class="w2ui-node-sub" id="node_'+e.id+'_sub" style="'+e.style+";"+(!e.hidden&&e.expanded?"":"display: none;")+'"></div>',o.flat&&(t='<div class="w2ui-node-group" id="node_'+e.id+'"><span>&nbsp;</span></div><div id="node_'+e.id+'_sub" style="'+e.style+";"+(!e.hidden&&e.expanded?"":"display: none;")+'"></div>')):(e.selected&&!e.disabled&&(o.selected=e.id),n="",i&&(n='<div class="w2ui-node-image w2ui-icon '+i+(e.selected&&!e.disabled?" w2ui-icon-selected":"")+'"></div>'),s&&(n='<div class="w2ui-node-image"><span class="'+s+'"></span></div>'),t='<div class="w2ui-node '+(e.selected?"w2ui-selected":"")+" "+(e.disabled?"w2ui-disabled":"")+'" id="node_'+e.id+'" style="'+(e.hidden?"display: none;":"")+'"    ondblclick="w2ui[\''+o.name+"'].dblClick('"+e.id+"', event);\"    oncontextmenu=\"w2ui['"+o.name+"'].contextMenu('"+e.id+"', event);         if (event.preventDefault) event.preventDefault();\"    onClick=\"w2ui['"+o.name+"'].click('"+e.id+'\', event); "><table cellpadding="0" cellspacing="0" style="margin-left:'+18*r+"px; padding-right:"+18*r+'px"><tr><td class="w2ui-node-dots" nowrap onclick="w2ui[\''+o.name+"'].toggle('"+e.id+'\');         if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;">    <div class="w2ui-expand">'+(e.nodes.length>0?e.expanded?"-":"+":e.plus?"+":"")+'</div></td><td class="w2ui-node-data" nowrap>'+n+(e.count||0===e.count?'<div class="w2ui-node-count">'+e.count+"</div>":"")+'<div class="w2ui-node-caption">'+e.text+'</div></td></tr></table></div><div class="w2ui-node-sub" id="node_'+e.id+'_sub" style="'+e.style+";"+(!e.hidden&&e.expanded?"":"display: none;")+'"></div>',o.flat&&(t='<div class="w2ui-node '+(e.selected?"w2ui-selected":"")+" "+(e.disabled?"w2ui-disabled":"")+'" id="node_'+e.id+'" style="'+(e.hidden?"display: none;":"")+"\"    onmouseover=\"$(this).find('.w2ui-node-data').w2tag(w2utils.base64decode('"+w2utils.base64encode(e.text+(e.count||0===e.count?' - <span class="w2ui-node-count">'+e.count+"</span>":""))+"'),                { id: '"+e.id+"', left: -5 })\"    onmouseout=\"$(this).find('.w2ui-node-data').w2tag(null, { id: '"+e.id+"' })\"    ondblclick=\"w2ui['"+o.name+"'].dblClick('"+e.id+"', event);\"    oncontextmenu=\"w2ui['"+o.name+"'].contextMenu('"+e.id+"', event);         if (event.preventDefault) event.preventDefault();\"    onClick=\"w2ui['"+o.name+"'].click('"+e.id+'\', event); "><div class="w2ui-node-data w2ui-node-flat">'+n+'</div></div><div class="w2ui-node-sub" id="node_'+e.id+'_sub" style="'+e.style+";"+(!e.hidden&&e.expanded?"":"display: none;")+'"></div>')),t}var i=(new Date).getTime(),s=this.trigger({phase:"before",type:"refresh",target:"undefined"!=typeof e?e:this.name});if(s.isCancelled!==!0){""!==this.topHTML&&($(this.box).find(".w2ui-sidebar-top").html(this.topHTML),$(this.box).find(".w2ui-sidebar-div").css("top",$(this.box).find(".w2ui-sidebar-top").height()+"px")),""!==this.bottomHTML&&($(this.box).find(".w2ui-sidebar-bottom").html(this.bottomHTML),$(this.box).find(".w2ui-sidebar-div").css("bottom",$(this.box).find(".w2ui-sidebar-bottom").height()+"px")),$(this.box).find("> div").css({width:$(this.box).width()+"px",height:$(this.box).height()+"px"});var n,r,a,o=this;if("undefined"==typeof e)n=this,a=".w2ui-sidebar-div";else{if(n=this.get(e),null===n)return;a="#node_"+w2utils.escapeId(n.id)+"_sub"}var l;if(n!==this){var d="#node_"+w2utils.escapeId(n.id);l=t(n),$(this.box).find(d).before('<div id="sidebar_'+this.name+'_tmp"></div>'),$(this.box).find(d).remove(),$(this.box).find(a).remove(),$("#sidebar_"+this.name+"_tmp").before(l),$("#sidebar_"+this.name+"_tmp").remove()}$(this.box).find(a).html("");for(var h=0;h<n.nodes.length;h++)r=n.nodes[h],l=t(r),$(this.box).find(a).append(l),0!==r.nodes.length&&this.refresh(r.id);return this.trigger($.extend(s,{phase:"after"})),(new Date).getTime()-i}},resize:function(){var e=(new Date).getTime(),t=this.trigger({phase:"before",type:"resize",target:this.name});return t.isCancelled!==!0?($(this.box).css("overflow","hidden"),$(this.box).find("> div").css({width:$(this.box).width()+"px",height:$(this.box).height()+"px"}),this.trigger($.extend(t,{phase:"after"})),(new Date).getTime()-e):void 0},destroy:function(){var e=this.trigger({phase:"before",type:"destroy",target:this.name});e.isCancelled!==!0&&($(this.box).find("> div > div.w2ui-sidebar-div").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-sidebar").html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})))},lock:function(){var e=$(this.box).find("> div:first-child"),t=Array.prototype.slice.call(arguments,0);t.unshift(e),w2utils.lock.apply(window,t)},unlock:function(e){w2utils.unlock(this.box,e)}},$.extend(e.prototype,w2utils.event),w2obj.sidebar=e}(),function(e){var t=function(t){this.el=null,this.helpers={},this.type=t.type||"text",this.options=e.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.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,e.extend(!0,this,w2obj.field)};e.fn.w2field=function(i,s){if(0!=this.length){if(0==arguments.length){var n=e(this).data("w2field");return n}return"string"==typeof i&&"object"==typeof s&&(i=e.extend(!0,{},s,{type:i})),"string"==typeof i&&"undefined"==typeof s&&(i={type:i}),i.type=String(i.type).toLowerCase(),this.each(function(s,n){var r=e(n).data("w2field");if("undefined"==typeof r){var r=new t(i);return e.extend(r,{handlers:[]}),n&&(r.el=e(n)[0]),r.init(),e(n).data("w2field",r),r}if(r.clear(),"clear"!=i.type){var r=new t(i);return e.extend(r,{handlers:[]}),n&&(r.el=e(n)[0]),r.init(),e(n).data("w2field",r),r}})}var r=t.prototype;return r[i]?r[i].apply(r,Array.prototype.slice.call(arguments,1)):void 0},t.prototype={custom:{},pallete:[["000000","444444","666666","999999","CCCCCC","EEEEEE","F3F3F3","FFFFFF"],["FF011B","FF9838","FFFD59","01FD55","00FFFE","0424F3","9B24F4","FF21F5"],["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"],["660205","783F0B","7F6011","274E12","0C343D","063762","20124D","4C1030"]],addType:function(e,t){return e=String(e).toLowerCase(),this.custom[e]=t,!0},removeType:function(e){return e=String(e).toLowerCase(),this.custom[e]?(delete this.custom[e],!0):!1},init:function(){var t,i=this,s=this.options;if("function"==typeof this.custom[this.type])return void this.custom[this.type].call(this,s);if(-1==["INPUT","TEXTAREA"].indexOf(this.el.tagName))return void console.log("ERROR: w2field could only be applied to INPUT or TEXTAREA.",this.el);switch(this.type){case"text":case"int":case"float":case"money":case"currency":case"percent":case"alphanumeric":case"hex":t={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=e.extend(!0,{},t,s),s=this.options,s.numberRE=new RegExp("["+s.groupSymbol+"]","g"),s.moneyRE=new RegExp("["+s.currencyPrefix+s.currencySuffix+s.groupSymbol+"]","g"),s.percentRE=new RegExp("["+s.groupSymbol+"%]","g"),-1!=["text","alphanumeric","hex"].indexOf(this.type)&&(s.arrows=!1,s.keyboard=!1),this.addPrefix(),this.addSuffix();break;case"color":t={prefix:"#",suffix:'<div style="width: '+(parseInt(e(this.el).css("font-size"))||12)+'px">&nbsp;</div>',arrows:!1,keyboard:!1},e.extend(s,t),this.addPrefix(),this.addSuffix(),e(this.el).attr("maxlength",6),""!=e(this.el).val()&&setTimeout(function(){i.change()},1);break;case"date":t={format:w2utils.settings.date_format,keyboard:!0,silent:!0,start:"",end:"",blocked:{},colored:{}},this.options=e.extend(!0,{},t,s),s=this.options,null==e(this.el).attr("placeholder")&&e(this.el).attr("placeholder",s.format);break;case"time":t={format:w2utils.settings.time_format,keyboard:!0,silent:!0,start:"",end:""},this.options=e.extend(!0,{},t,s),s=this.options,null==e(this.el).attr("placeholder")&&e(this.el).attr("placeholder",s.format);break;case"datetime":break;case"list":case"combo":if(t={items:[],selected:{},url:null,postData:{},minLength:1,cacheMax:250,maxDropHeight:350,match:"begins",silent:!0,icon:null,iconStyle:"",onSearch:null,onRequest:null,onLoad:null,onError:null,onIconClick:null,renderDrop:null,compare:null,prefix:"",suffix:"",openOnFocus:!1,markSearch:!1},s.items=this.normMenu(s.items),"list"==this.type){if(t.openOnFocus=!0,t.suffix='<div class="arrow-down" style="margin-top: '+(parseInt(e(this.el).height())-6)/2+'px;"></div>',e(this.el).addClass("w2ui-select"),!e.isPlainObject(s.selected)&&s.items)for(var n=0;n<s.items.length;n++){var r=s.items[n];if(r&&r.id==s.selected){s.selected=e.extend(!0,{},r);break}}this.watchSize()}s=e.extend({},t,s,{align:"both",altRows:!0}),this.options=s,e.isPlainObject(s.selected)||(s.selected={}),e(this.el).data("selected",s.selected),s.url&&this.request(0),"list"==this.type&&this.addFocus(),this.addPrefix(),this.addSuffix(),setTimeout(function(){i.refresh()},10),e(this.el).attr("autocomplete","off"),"undefined"!=typeof s.selected.text&&e(this.el).val(s.selected.text);break;case"enum":t={items:[],selected:[],max:0,url:null,postData:{},minLength:1,cacheMax:250,maxWidth:250,maxHeight:350,maxDropHeight:350,match:"contains",silent:!0,openOnFocus:!1,markSearch:!0,renderDrop:null,renderItem:null,compare:null,style:"",onSearch:null,onRequest:null,onLoad:null,onError:null,onClick:null,onAdd:null,onNew:null,onRemove:null,onMouseOver:null,onMouseOut:null},s=e.extend({},t,s,{align:"both",suffix:"",altRows:!0}),s.items=this.normMenu(s.items),s.selected=this.normMenu(s.selected),this.options=s,e.isArray(s.selected)||(s.selected=[]),e(this.el).data("selected",s.selected),s.url&&this.request(0),this.addSuffix(),this.addMulti(),this.watchSize();break;case"file":t={selected:[],max:0,maxSize:0,maxFileSize:0,maxWidth:250,maxHeight:350,maxDropHeight:350,silent:!0,renderItem:null,style:"",onClick:null,onAdd:null,onRemove:null,onMouseOver:null,onMouseOut:null},s=e.extend({},t,s,{align:"both",altRows:!0}),this.options=s,e.isArray(s.selected)||(s.selected=[]),e(this.el).data("selected",s.selected),null==e(this.el).attr("placeholder")&&e(this.el).attr("placeholder",w2utils.lang("Attach files by dragging and dropping or Click to Select")),this.addMulti(),this.watchSize()}this.tmp={onChange:function(e){i.change.call(i,e)},onClick:function(e){i.click.call(i,e)},onFocus:function(e){i.focus.call(i,e)},onBlur:function(e){i.blur.call(i,e)},onKeydown:function(e){i.keyDown.call(i,e)},onKeyup:function(e){i.keyUp.call(i,e)},onKeypress:function(e){i.keyPress.call(i,e)}},e(this.el).addClass("w2field").data("w2field",this).on("change",this.tmp.onChange).on("click",this.tmp.onClick).on("focus",this.tmp.onFocus).on("blur",this.tmp.onBlur).on("keydown",this.tmp.onKeydown).on("keyup",this.tmp.onKeyup).on("keypress",this.tmp.onKeypress).css(w2utils.cssPrefix("box-sizing","border-box")),this.change(e.Event("change"))},watchSize:function(){var t=this,i=e(t.el).data("tmp")||{};i.sizeTimer=setInterval(function(){e(t.el).parents("body").length>0?t.resize():clearInterval(i.sizeTimer)},200),e(t.el).data("tmp",i)},get:function(){var t;return t=-1!=["list","enum","file"].indexOf(this.type)?e(this.el).data("selected"):e(this.el).val()},set:function(t){-1!=["list","enum","file"].indexOf(this.type)?(e(this.el).data("selected",t).change(),this.refresh()):e(this.el).val(t)},setIndex:function(t){var i=this.options.items;return i&&i[t]?(e(this.el).data("selected",i[t]).change(),this.refresh(),!0):!1},clear:function(){var t=this.options;-1!=["money","currency"].indexOf(this.type)&&e(this.el).val(e(this.el).val().replace(t.moneyRE,"")),"percent"==this.type&&e(this.el).val(e(this.el).val().replace(/%/g,"")),"color"==this.type&&e(this.el).removeAttr("maxlength"),"list"==this.type&&e(this.el).removeClass("w2ui-select"),this.type="clear";var i=e(this.el).data("tmp");if(this.tmp){"undefined"!=typeof i&&(e(this.el).height("auto"),i&&i["old-padding-left"]&&e(this.el).css("padding-left",i["old-padding-left"]),i&&i["old-padding-right"]&&e(this.el).css("padding-right",i["old-padding-right"]),i&&i["old-background-color"]&&e(this.el).css("background-color",i["old-background-color"]),i&&i["old-border-color"]&&e(this.el).css("border-color",i["old-border-color"]),clearInterval(i.sizeTimer)),e(this.el).val(this.clean(e(this.el).val())).removeClass("w2field").removeData().off("change",this.tmp.onChange).off("click",this.tmp.onClick).off("focus",this.tmp.onFocus).off("blur",this.tmp.onBlur).off("keydown",this.tmp.onKeydown).off("keyup",this.tmp.onKeyup).off("keypress",this.tmp.onKeypress);for(var s in this.helpers)e(this.helpers[s]).remove();this.helpers={}}},refresh:function(){var t=this,i=this.options,s=e(this.el).data("selected"),n=(new Date).getTime();if(-1!=["list"].indexOf(this.type)&&(e(t.el).parent().css("white-space","nowrap"),t.helpers.prefix&&t.helpers.prefix.hide(),setTimeout(function(){if(t.helpers.focus){!e.isEmptyObject(s)&&i.icon?(i.prefix='<span class="w2ui-icon '+i.icon+'"style="cursor: pointer; font-size: 14px; display: inline-block; margin-top: -1px; color: #7F98AD;'+i.iconStyle+'"></span>',t.addPrefix()):(i.prefix="",t.addPrefix());var n=t.helpers.focus.find("input");""==e(n).val()?(e(n).css("opacity",0).prev().css("opacity",0),e(t.el).val(s&&null!=s.text?s.text:"")):(e(n).css("opacity",1).prev().css("opacity",1),e(t.el).val(""),setTimeout(function(){t.helpers.prefix&&t.helpers.prefix.hide();var s="position: absolute; opacity: 0; margin: 4px 0px 0px 2px; background-position: left !important;";i.icon?(e(n).css("margin-left","17px"),e(t.helpers.focus).find(".icon-search").attr("style",s+"width: 11px !important; opacity: 1")):(e(n).css("margin-left","0px"),e(t.helpers.focus).find(".icon-search").attr("style",s+"width: 0px !important; opacity: 0"))},1)),e(t.el).prop("readonly")||e(t.el).prop("disabled")?setTimeout(function(){e(t.helpers.prefix).css("opacity","0.6"),e(t.helpers.suffix).css("opacity","0.6")},1):setTimeout(function(){e(t.helpers.prefix).css("opacity","1"),e(t.helpers.suffix).css("opacity","1")},1)}},1)),-1!=["enum","file"].indexOf(this.type)){var r="";for(var a in s){var o=s[a],l="";l="function"==typeof i.renderItem?i.renderItem(o,a,'<div class="w2ui-list-remove" title="'+w2utils.lang("Remove")+'" index="'+a+'">&nbsp;&nbsp;</div>'):'<div class="w2ui-list-remove" title="'+w2utils.lang("Remove")+'" index="'+a+'">&nbsp;&nbsp;</div>'+("enum"==t.type?o.text:o.name+'<span class="file-size"> - '+w2utils.formatSize(o.size)+"</span>"),r+='<li index="'+a+'" style="max-width: '+parseInt(i.maxWidth)+"px; "+(o.style?o.style:"")+'">'+l+"</li>"}var d=t.helpers.multi,h=d.find("ul");if(d.attr("style",d.attr("style")+";"+i.style),e(t.el).prop("readonly")||e(t.el).prop("disabled")?(d.addClass("w2ui-readonly"),d.css("pointer-events","none").find("li").css("opacity","0.6"),e(t.helpers.multi).find("input").prop("readonly",!0)):(d.removeClass("w2ui-readonly"),d.css("pointer-events","auto").find("li").css("opacity","1"),e(t.helpers.multi).find("input").prop("readonly",!1)),d.find(".w2ui-enum-placeholder").remove(),h.find("li").not("li.nomouse").remove(),""!=r)h.prepend(r);else if(null!=e(t.el).attr("placeholder")){var u="padding-top: "+e(this.el).css("padding-top")+";padding-left: "+e(this.el).css("padding-left")+"; box-sizing: "+e(this.el).css("box-sizing")+"; line-height: "+e(this.el).css("line-height")+"; font-size: "+e(this.el).css("font-size")+"; font-family: "+e(this.el).css("font-family")+"; ";d.prepend('<div class="w2ui-enum-placeholder" style="'+u+'">'+e(t.el).attr("placeholder")+"</div>")}d.find("li").data("mouse","out").on("click",function(i){var n=s[e(i.target).attr("index")];if(!e(i.target).hasClass("nomouse")){i.stopPropagation();var r=t.trigger({phase:"before",type:"click",target:t.el,originalEvent:i.originalEvent,item:n});if(r.isCancelled!==!0){if(e(i.target).hasClass("w2ui-list-remove")){if(e(t.el).attr("readonly")||e(t.el).attr("disabled"))return;var r=t.trigger({phase:"before",type:"remove",target:t.el,originalEvent:i.originalEvent,item:n});if(r.isCancelled===!0)return;e().w2overlay(),s.splice(e(i.target).attr("index"),1),e(t.el).trigger("change"),e(i.target).parent().fadeOut("fast"),setTimeout(function(){t.refresh(),t.trigger(e.extend(r,{phase:"after"}))},300)}if("file"==t.type&&!e(i.target).hasClass("w2ui-list-remove")){var a="";/image/i.test(n.type)&&(a='<div style="padding: 3px;">    <img src="'+(n.content?"data:"+n.type+";base64,"+n.content:"")+'" style="max-width: 300px;"         onload="var w = $(this).width(); var h = $(this).height();             if (w < 300 & h < 300) return;             if (w >= h && w > 300) $(this).width(300);            if (w < h && h > 300) $(this).height(300);"        onerror="this.style.display = \'none\'"    ></div>');var o='style="padding: 3px; text-align: right; color: #777;"',l='style="padding: 3px"';a+='<div style="padding: 8px;">    <table cellpadding="2">    <tr><td '+o+">"+w2utils.lang("Name")+":</td><td "+l+">"+n.name+"</td></tr>    <tr><td "+o+">"+w2utils.lang("Size")+":</td><td "+l+">"+w2utils.formatSize(n.size)+"</td></tr>    <tr><td "+o+">"+w2utils.lang("Type")+":</td><td "+l+'>        <span style="width: 200px; display: block-inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">'+n.type+"</span>    </td></tr>    <tr><td "+o+">"+w2utils.lang("Modified")+":</td><td "+l+">"+w2utils.date(n.modified)+"</td></tr>    </table></div>",e("#w2ui-overlay").remove(),e(i.target).w2overlay(a)}t.trigger(e.extend(r,{phase:"after"}))}}}).on("mouseover",function(i){var n=i.target;if("LI"!=n.tagName&&(n=n.parentNode),!e(n).hasClass("nomouse")){if("out"==e(n).data("mouse")){var r=s[e(n).attr("index")],a=t.trigger({phase:"before",type:"mouseOver",target:t.el,originalEvent:i.originalEvent,item:r});if(a.isCancelled===!0)return;t.trigger(e.extend(a,{phase:"after"}))}e(n).data("mouse","over")}}).on("mouseout",function(i){var n=i.target;"LI"!=n.tagName&&(n=n.parentNode),e(n).hasClass("nomouse")||(e(n).data("mouse","leaving"),setTimeout(function(){if("leaving"==e(n).data("mouse")){e(n).data("mouse","out");var r=s[e(n).attr("index")],a=t.trigger({phase:"before",type:"f",target:t.el,originalEvent:i.originalEvent,item:r});if(a.isCancelled===!0)return;t.trigger(e.extend(a,{phase:"after"}))}},0))}),e(this.el).height("auto");var c=e(d).find("> div.w2ui-multi-items").height()+2*w2utils.getSize(d,"+height");26>c&&(c=26),c>i.maxHeight&&(c=i.maxHeight),d.length>0&&(d[0].scrollTop=1e3);var p=w2utils.getSize(e(this.el),"height")-2;p>c&&(c=p),e(d).css({height:c+"px",overflow:c==i.maxHeight?"auto":"hidden"}),c<i.maxHeight&&e(d).prop("scrollTop",0),e(this.el).css({height:c+2+"px"})}return(new Date).getTime()-n},reset:function(){var e=this.type;this.clear(),this.type=e,this.init()},resize:function(){var t=this,i=e(t.el).width(),s=e(t.el).height();if(!(t.tmp.current_width==i&&s>0)){var n=this.helpers.focus,r=this.helpers.multi,a=this.helpers.suffix,o=this.helpers.prefix;if(n&&n.width(e(t.el).width()),r){var l=w2utils.getSize(t.el,"width")-parseInt(e(t.el).css("margin-left"),10)-parseInt(e(t.el).css("margin-right"),10);e(r).width(l)}a&&(t.options.suffix='<div class="arrow-down" style="margin-top: '+(parseInt(e(t.el).height())-6)/2+'px;"></div>',t.addSuffix()),o&&t.addPrefix(),t.tmp.current_width=i}},clean:function(t){if("number"==typeof t)return t;var i=this.options;return t=String(t).trim(),-1!=["int","float","money","currency","percent"].indexOf(this.type)&&("string"==typeof t&&(i.autoFormat&&-1!=["money","currency"].indexOf(this.type)&&(t=String(t).replace(i.moneyRE,"")),i.autoFormat&&"percent"==this.type&&(t=String(t).replace(i.percentRE,"")),i.autoFormat&&-1!=["int","float"].indexOf(this.type)&&(t=String(t).replace(i.numberRE,"")),t=t.replace(i.decimalSymbol,".")),parseFloat(t)==t&&(null!==i.min&&t<i.min&&(t=i.min,e(this.el).val(i.min)),null!==i.max&&t>i.max&&(t=i.max,e(this.el).val(i.max))),t=""!==t&&w2utils.isFloat(t)?Number(t):""),t},format:function(e){var t=this.options;if(t.autoFormat&&""!=e)switch(this.type){case"money":case"currency":e=w2utils.formatNumber(Number(e).toFixed(t.currencyPrecision),t.groupSymbol),""!=e&&(e=t.currencyPrefix+e+t.currencySuffix);break;case"percent":e=w2utils.formatNumber(t.precision?Number(e).toFixed(t.precision):e,t.groupSymbol),""!=e&&(e+="%");break;case"float":e=w2utils.formatNumber(t.precision?Number(e).toFixed(t.precision):e,t.groupSymbol);break;case"int":e=w2utils.formatNumber(e,t.groupSymbol)}return e},change:function(t){var i=this,s=i.options;if(-1!=["int","float","money","currency","percent"].indexOf(this.type)){var n=e(this.el).val(),r=this.format(this.clean(e(this.el).val()));if(""!=n&&n!=r)return e(this.el).val(r).change(),t.stopPropagation(),t.preventDefault(),!1}if("color"==this.type){var a="#"+e(this.el).val();6!=e(this.el).val().length&&3!=e(this.el).val().length&&(a=""),e(this.el).next().find("div").css("background-color",a),e(i.el).is(":focus")&&this.updateOverlay()}if(-1!=["list","enum","file"].indexOf(this.type)&&(i.refresh(),setTimeout(function(){i.refresh()},5)),-1!=["date","time"].indexOf(this.type)){var o=parseInt(i.el.value);w2utils.isInt(i.el.value)&&o>3e3&&("time"==this.type&&e(i.el).val(w2utils.formatTime(new Date(o),s.format)).change(),"date"==this.type&&e(i.el).val(w2utils.formatDate(new Date(o),s.format)).change())}},click:function(t){t.stopPropagation(),-1!=["list","combo","enum"].indexOf(this.type)&&(e(this.el).is(":focus")||this.focus(t)),-1!=["date","time","color"].indexOf(this.type)&&this.updateOverlay()},focus:function(){{var t=this;this.options}if(-1!==["color","date","time"].indexOf(t.type)){if(e(t.el).attr("readonly")||e(t.el).attr("disabled"))return;e("#w2ui-overlay").length>0&&e("#w2ui-overlay")[0].hide(),setTimeout(function(){t.updateOverlay()},150)}if(-1!=["list","combo","enum"].indexOf(t.type)){if(e(t.el).attr("readonly")||e(t.el).attr("disabled"))return;e("#w2ui-overlay").length>0&&e("#w2ui-overlay")[0].hide(),t.resize(),setTimeout(function(){return"list"==t.type&&e(t.el).is(":focus")?void e(t.helpers.focus).find("input").focus():(t.search(),void setTimeout(function(){t.updateOverlay()},1))},1)}"file"==t.type&&e(t.helpers.multi).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"})},blur:function(){var t=this,i=t.options,s=e(t.el).val().trim();-1!=["color","date","time","list","combo","enum"].indexOf(t.type)&&e("#w2ui-overlay").length>0&&e("#w2ui-overlay")[0].hide(),-1!=["int","float","money","currency","percent"].indexOf(t.type)&&(""===s||t.checkType(s)||(e(t.el).val("").change(),i.silent===!1&&(e(t.el).w2tag("Not a valid number"),setTimeout(function(){e(t.el).w2tag("")},3e3)))),-1!=["date","time"].indexOf(t.type)&&(""===s||t.inRange(t.el.value)?("date"!=t.type||""===s||w2utils.isDate(t.el.value,i.format)||(e(t.el).val("").removeData("selected").change(),i.silent===!1&&(e(t.el).w2tag("Not a valid date"),setTimeout(function(){e(t.el).w2tag("")},3e3))),"time"!=t.type||""===s||w2utils.isTime(t.el.value)||(e(t.el).val("").removeData("selected").change(),i.silent===!1&&(e(t.el).w2tag("Not a valid time"),setTimeout(function(){e(t.el).w2tag("")},3e3)))):(e(t.el).val("").removeData("selected").change(),i.silent===!1&&(e(t.el).w2tag("Not in range"),setTimeout(function(){e(t.el).w2tag("")},3e3)))),"enum"==t.type&&e(t.helpers.multi).find("input").val("").width(20),"file"==t.type&&e(t.helpers.multi).css({outline:"none"})},keyPress:function(e){{var t=this;t.options}if(-1!=["int","float","money","currency","percent","hex","color","alphanumeric"].indexOf(t.type)){if(e.metaKey||e.ctrlKey||e.altKey||e.charCode!=e.keyCode&&e.keyCode>0)return;var i=String.fromCharCode(e.charCode);if(!t.checkType(i,!0)&&13!=e.keyCode)return e.preventDefault(),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,!1}-1!=["date","time"].indexOf(t.type)&&setTimeout(function(){t.updateOverlay()
  },1)},keyDown:function(t,i){var s=this,n=s.options,r=t.keyCode||i&&i.keyCode;if(-1!=["int","float","money","currency","percent"].indexOf(s.type)){if(!n.keyboard||e(s.el).attr("readonly"))return;var a=!1,o=parseFloat(e(s.el).val().replace(n.moneyRE,""))||0,l=n.step;switch((t.ctrlKey||t.metaKey)&&(l=10),r){case 38:if(t.shiftKey)break;e(s.el).val(o+l<=n.max||null===n.max?Number((o+l).toFixed(12)):n.max).change(),a=!0;break;case 40:if(t.shiftKey)break;e(s.el).val(o-l>=n.min||null===n.min?Number((o-l).toFixed(12)):n.min).change(),a=!0}a&&(t.preventDefault(),setTimeout(function(){s.el.setSelectionRange(s.el.value.length,s.el.value.length)},0))}if("date"==s.type){if(!n.keyboard||e(s.el).attr("readonly"))return;var a=!1,d=864e5,l=1;(t.ctrlKey||t.metaKey)&&(l=10);var h=w2utils.isDate(e(s.el).val(),n.format,!0);switch(h||(h=new Date,d=0),r){case 38:if(t.shiftKey)break;var u=w2utils.formatDate(h.getTime()+d,n.format);10==l&&(u=w2utils.formatDate(new Date(h.getFullYear(),h.getMonth()+1,h.getDate()),n.format)),e(s.el).val(u).change(),a=!0;break;case 40:if(t.shiftKey)break;var u=w2utils.formatDate(h.getTime()-d,n.format);10==l&&(u=w2utils.formatDate(new Date(h.getFullYear(),h.getMonth()-1,h.getDate()),n.format)),e(s.el).val(u).change(),a=!0}a&&(t.preventDefault(),setTimeout(function(){s.el.setSelectionRange(s.el.value.length,s.el.value.length),s.updateOverlay()},0))}if("time"==s.type){if(!n.keyboard||e(s.el).attr("readonly"))return;var a=!1,l=t.ctrlKey||t.metaKey?60:1,o=e(s.el).val(),c=s.toMin(o)||s.toMin((new Date).getHours()+":"+((new Date).getMinutes()-1));switch(r){case 38:if(t.shiftKey)break;c+=l,a=!0;break;case 40:if(t.shiftKey)break;c-=l,a=!0}a&&(e(s.el).val(s.fromMin(c)).change(),t.preventDefault(),setTimeout(function(){s.el.setSelectionRange(s.el.value.length,s.el.value.length)},0))}if("color"==s.type){if(e(s.el).attr("readonly"))return;if(86==t.keyCode&&(t.ctrlKey||t.metaKey)&&(e(s.el).prop("maxlength",7),setTimeout(function(){var t=e(s).val();"#"==t.substr(0,1)&&(t=t.substr(1)),w2utils.isHex(t)||(t=""),e(s).val(t).prop("maxlength",6).change()},20)),(t.ctrlKey||t.metaKey)&&!t.shiftKey){if("undefined"==typeof s.tmp.cind1)s.tmp.cind1=-1,s.tmp.cind2=-1;else{switch(r){case 38:s.tmp.cind1--;break;case 40:s.tmp.cind1++;break;case 39:s.tmp.cind2++;break;case 37:s.tmp.cind2--}s.tmp.cind1<0&&(s.tmp.cind1=0),s.tmp.cind1>this.pallete.length-1&&(s.tmp.cind1=this.pallete.length-1),s.tmp.cind2<0&&(s.tmp.cind2=0),s.tmp.cind2>this.pallete[0].length-1&&(s.tmp.cind2=this.pallete[0].length-1)}-1!=[37,38,39,40].indexOf(r)&&(e(s.el).val(this.pallete[s.tmp.cind1][s.tmp.cind2]).change(),t.preventDefault())}}if(-1!=["list","combo","enum"].indexOf(s.type)){if(e(s.el).attr("readonly"))return;var p=e(s.el).data("selected"),f=e(s.helpers.focus).find("input"),g=!1;switch("list"==s.type&&-1==[37,38,39,40].indexOf(r)&&s.refresh(),r){case 27:"list"==s.type&&(""!=e(f).val()&&e(f).val(""),t.stopPropagation());break;case 37:case 39:break;case 13:if(0==e("#w2ui-overlay").length)break;var m=n.items[n.index],v=e(s.helpers.multi).find("input");if("enum"==s.type)if(null!=m){var w=s.trigger({phase:"before",type:"add",target:s.el,originalEvent:t.originalEvent,item:m});if(w.isCancelled===!0)return;m=w.item,p.length>=n.max&&n.max>0&&p.pop(),delete m.hidden,delete s.tmp.force_open,p.push(m),e(s.el).change(),v.val("").width(20),s.refresh(),s.trigger(e.extend(w,{phase:"after"}))}else{m={id:v.val(),text:v.val()};var w=s.trigger({phase:"before",type:"new",target:s.el,originalEvent:t.originalEvent,item:m});if(w.isCancelled===!0)return;m=w.item,"function"==typeof s.onNew&&(p.length>=n.max&&n.max>0&&p.pop(),delete s.tmp.force_open,p.push(m),e(s.el).change(),v.val("").width(20),s.refresh()),s.trigger(e.extend(w,{phase:"after"}))}else m&&e(s.el).data("selected",m).val(m.text).change(),""==e(s.el).val()&&e(s.el).data("selected")&&e(s.el).removeData("selected").val("").change(),"list"==s.type&&(f.val(""),s.refresh()),s.tmp.force_hide=!0;break;case 8:case 46:if("enum"==s.type&&8==r&&""==e(s.helpers.multi).find("input").val()&&p.length>0){var m=p[p.length-1],w=s.trigger({phase:"before",type:"remove",target:s.el,originalEvent:t.originalEvent,item:m});if(w.isCancelled===!0)return;p.pop(),e(s.el).trigger("change"),s.refresh(),s.trigger(e.extend(w,{phase:"after"}))}"list"==s.type&&""==e(f).val()&&(e(s.el).data("selected",{}).change(),s.refresh());break;case 38:for(n.index=w2utils.isInt(n.index)?parseInt(n.index):0,n.index--;n.index>0&&n.items[n.index].hidden;)n.index--;if(0==n.index&&n.items[n.index].hidden)for(;n.items[n.index]&&n.items[n.index].hidden;)n.index++;g=!0;break;case 40:for(n.index=w2utils.isInt(n.index)?parseInt(n.index):-1,n.index++;n.index<n.items.length-1&&n.items[n.index].hidden;)n.index++;if(n.index==n.items.length-1&&n.items[n.index].hidden)for(;n.items[n.index]&&n.items[n.index].hidden;)n.index--;var y=s.el;-1!=["enum"].indexOf(s.type)&&(y=s.helpers.multi.find("input")),""==e(y).val()&&0==e("#w2ui-overlay").length?s.tmp.force_open=!0:g=!0}if(g)return n.index<0&&(n.index=0),n.index>=n.items.length&&(n.index=n.items.length-1),s.updateOverlay(g),t.preventDefault(),void setTimeout(function(){if("enum"==s.type){var e=s.helpers.multi.find("input").get(0);e.setSelectionRange(e.value.length,e.value.length)}else if("list"==s.type){var e=s.helpers.focus.find("input").get(0);e.setSelectionRange(e.value.length,e.value.length)}else s.el.setSelectionRange(s.el.value.length,s.el.value.length)},0);if("enum"==s.type){var y=s.helpers.multi.find("input"),b=y.val();y.width(8*(b.length+2)+"px")}-1==[16,17,18,20,37,39,91].indexOf(r)&&setTimeout(function(){s.tmp.force_hide||s.request(),s.search()},1)}},keyUp:function(t){"color"==this.type&&86==t.keyCode&&(t.ctrlKey||t.metaKey)&&e(this).prop("maxlength",6)},clearCache:function(){var e=this.options;e.items=[],this.tmp.xhr_loading=!1,this.tmp.xhr_search="",this.tmp.xhr_total=-1,this.search()},request:function(t){var i=this,s=this.options,n=e(i.el).val()||"";if(s.url){if("enum"==i.type){var r=e(i.helpers.multi).find("input");n=0==r.length?"":r.val()}if("list"==i.type){var r=e(i.helpers.focus).find("input");n=0==r.length?"":r.val()}if(0!=s.minLength&&n.length<s.minLength)return s.items=[],void this.updateOverlay();"undefined"==typeof t&&(t=350),"undefined"==typeof i.tmp.xhr_search&&(i.tmp.xhr_search=""),"undefined"==typeof i.tmp.xhr_total&&(i.tmp.xhr_total=-1),s.url&&1!=e(i.el).prop("readonly")&&(0===s.items.length&&0!==i.tmp.xhr_total||i.tmp.xhr_total==s.cacheMax&&n.length>i.tmp.xhr_search.length||n.length>=i.tmp.xhr_search.length&&n.substr(0,i.tmp.xhr_search.length)!=i.tmp.xhr_search||n.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 t=s.url,r={search:n,max:s.cacheMax};e.extend(r,s.postData);var a=i.trigger({phase:"before",type:"request",target:i.el,url:t,postData:r});if(a.isCancelled!==!0){t=a.url,r=a.postData;var o={type:"GET",url:t,data:r,dataType:"JSON"};"JSON"==w2utils.settings.dataType&&(o.type="POST",o.data=JSON.stringify(o.data),o.contentType="application/json"),i.tmp.xhr=e.ajax(o).done(function(t,a,o){var l=i.trigger({phase:"before",type:"load",target:i.el,search:r.search,data:t,xhr:o});if(l.isCancelled!==!0){if(t=l.data,"string"==typeof t&&(t=JSON.parse(t)),"success"!=t.status)return void console.log("ERROR: server did not return proper structure. It should return",{status:"success",items:[{id:1,text:"item"}]});t.items.length>s.cacheMax&&t.items.splice(s.cacheMax,1e5),i.tmp.xhr_loading=!1,i.tmp.xhr_search=n,i.tmp.xhr_total=t.items.length,s.items=i.normMenu(t.items),i.tmp.emptySet=""==n&&0==t.items.length?!0:!1,i.search(),i.trigger(e.extend(l,{phase:"after"}))}}).fail(function(t,s,r){var a={status:s,error:r,rawResponseText:t.responseText},o=i.trigger({phase:"before",type:"error",target:i.el,search:n,error:a,xhr:t});if(o.isCancelled!==!0){if("abort"!=s){var l;try{l=e.parseJSON(t.responseText)}catch(d){}console.log("ERROR: Server communication failed.","\n   EXPECTED:",{status:"success",items:[{id:1,text:"item"}]},"\n         OR:",{status:"error",message:"error message"},"\n   RECEIVED:","object"==typeof l?l:t.responseText)}i.clearCache(),i.trigger(e.extend(o,{phase:"after"}))}}),i.trigger(e.extend(a,{phase:"after"}))}},t))}},search:function(){var t=this,i=this.options,s=e(t.el).val(),n=t.el,r=[],a=e(t.el).data("selected");if("enum"==t.type){n=e(t.helpers.multi).find("input"),s=n.val();for(var o in a)a[o]&&r.push(a[o].id)}if("list"==t.type){n=e(t.helpers.focus).find("input"),s=n.val();for(var o in a)a[o]&&r.push(a[o].id)}var l=t.trigger({phase:"before",type:"search",target:n,search:s});if(l.isCancelled!==!0){if(t.tmp.xhr_loading!==!0){for(var d=0,h=0;h<i.items.length;h++){var u=i.items[h];if("function"==typeof i.compare)u.hidden=i.compare.call(this,u,s)===!1?!0:!1;else{var c="",p="";-1!=["is","begins"].indexOf(i.match)&&(c="^"),-1!=["is","ends"].indexOf(i.match)&&(p="$");try{var f=new RegExp(c+s+p,"i");u.hidden=f.test(u.text)||"..."==u.text?!1:!0}catch(g){}}"enum"==t.type&&-1!=e.inArray(u.id,r)&&(u.hidden=!0),u.hidden!==!0&&(d++,delete u.hidden)}for(i.index=0;i.items[i.index]&&i.items[i.index].hidden;)i.index++;0>=d&&(i.index=-1),i.spinner=!1,t.updateOverlay(),setTimeout(function(){var t=e("#w2ui-overlay").html()||"";i.markSearch&&-1!=t.indexOf("$.fn.w2menuHandler")&&e("#w2ui-overlay").w2marker(s)},1)}else i.items.splice(0,i.cacheMax),i.spinner=!0,t.updateOverlay();t.trigger(e.extend(l,{phase:"after"}))}},updateOverlay:function(t){var i=this,s=this.options;if("color"==this.type){if(e(i.el).attr("readonly"))return;0==e("#w2ui-overlay").length?e(i.el).w2overlay(i.getColorHTML()):e("#w2ui-overlay > div").html(i.getColorHTML()),e("#w2ui-overlay .color").on("mousedown",function(t){var s=e(t.originalEvent.target).attr("name"),n=e(t.originalEvent.target).attr("index").split(":");i.tmp.cind1=n[0],i.tmp.cind2=n[1],e(i.el).val(s).change(),e(this).html("&#149;")}).on("mouseup",function(){setTimeout(function(){e("#w2ui-overlay").length>0&&e("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})}if("date"==this.type){if(e(i.el).attr("readonly"))return;0==e("#w2ui-overlay").length&&e(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar" onclick="event.stopPropagation();"></div>',{css:{"background-color":"#f5f5f5"}});var n,r,a=w2utils.isDate(e(i.el).val(),i.options.format,!0);a&&(n=a.getMonth()+1,r=a.getFullYear()),function u(t,s){e("#w2ui-overlay > div > div").html(i.getMonthHTML(t,s)),e("#w2ui-overlay .w2ui-calendar-title").on("mousedown",function(){if(e(this).next().hasClass("w2ui-calendar-jump"))e(this).next().remove();else{var t,s;e(this).after('<div class="w2ui-calendar-jump" style=""></div>'),e(this).next().hide().html(i.getYearHTML()).fadeIn(200),setTimeout(function(){e("#w2ui-overlay .w2ui-calendar-jump").find(".w2ui-jump-month, .w2ui-jump-year").on("click",function(){e(this).hasClass("w2ui-jump-month")&&(e(this).parent().find(".w2ui-jump-month").removeClass("selected"),e(this).addClass("selected"),s=e(this).attr("name")),e(this).hasClass("w2ui-jump-year")&&(e(this).parent().find(".w2ui-jump-year").removeClass("selected"),e(this).addClass("selected"),t=e(this).attr("name")),null!=t&&null!=s&&(e("#w2ui-overlay .w2ui-calendar-jump").fadeOut(100),setTimeout(function(){u(parseInt(s)+1,t)},100))}),e("#w2ui-overlay .w2ui-calendar-jump >:last-child").prop("scrollTop",2e3)},1)}}),e("#w2ui-overlay .w2ui-date").on("mousedown",function(){var t=e(this).attr("date");e(i.el).val(t).change(),e(this).css({"background-color":"#B6D5FB","border-color":"#aaa"})}).on("mouseup",function(){setTimeout(function(){e("#w2ui-overlay").length>0&&e("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)}),e("#w2ui-overlay .previous").on("mousedown",function(){var e=i.options.current.split("/");e[0]=parseInt(e[0])-1,u(e[0],e[1])}),e("#w2ui-overlay .next").on("mousedown",function(){var e=i.options.current.split("/");e[0]=parseInt(e[0])+1,u(e[0],e[1])})}(n,r)}if("time"==this.type){if(e(i.el).attr("readonly"))return;0==e("#w2ui-overlay").length&&e(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time" onclick="event.stopPropagation();"></div>',{css:{"background-color":"#fff"}});var o="h24"==this.options.format;e("#w2ui-overlay > div").html(i.getHourHTML()),e("#w2ui-overlay .w2ui-time").on("mousedown",function(){e(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});var t=e(this).attr("hour");e(i.el).val((t>12&&!o?t-12:t)+":00"+(o?"":12>t?" am":" pm")).change()}).on("mouseup",function(){var t=e(this).attr("hour");e("#w2ui-overlay").length>0&&e("#w2ui-overlay")[0].hide(),e(i.el).w2overlay('<div class="w2ui-reset w2ui-calendar-time"></div>',{css:{"background-color":"#fff"}}),e("#w2ui-overlay > div").html(i.getMinHTML(t)),e("#w2ui-overlay .w2ui-time").on("mousedown",function(){e(this).css({"background-color":"#B6D5FB","border-color":"#aaa"});var s=e(this).attr("min");e(i.el).val((t>12&&!o?t-12:t)+":"+(10>s?0:"")+s+(o?"":12>t?" am":" pm")).change()}).on("mouseup",function(){setTimeout(function(){e("#w2ui-overlay").length>0&&e("#w2ui-overlay").removeData("keepOpen")[0].hide()},10)})})}if(-1!=["list","combo","enum"].indexOf(this.type)){var l=this.el,d=this.el;if("enum"==this.type&&(l=e(this.helpers.multi),d=e(l).find("input")),"list"==this.type&&(d=e(this.helpers.focus).find("input")),e(d).is(":focus")){if(s.openOnFocus===!1&&""==e(d).val()&&i.tmp.force_open!==!0)return void e().w2overlay();if(i.tmp.force_hide)return e().w2overlay(),void setTimeout(function(){delete i.tmp.force_hide},1);""!=e(d).val()&&delete i.tmp.force_open;var h=w2utils.lang("No matches");null!=s.url&&e(d).val().length<s.minLength&&i.tmp.emptySet!==!0&&(h=s.minLength+" "+w2utils.lang("letters or more...")),null!=s.url&&""==e(d).val()&&i.tmp.emptySet!==!0&&(h=w2utils.lang("Type to search....")),e(l).w2menu(t?"refresh-index":"refresh",e.extend(!0,{},s,{search:!1,render:s.renderDrop,maxHeight:s.maxDropHeight,msgNoItems:h,onSelect:function(t){if("enum"==i.type){var n=e(i.el).data("selected");if(t.item){var r=i.trigger({phase:"before",type:"add",target:i.el,originalEvent:t.originalEvent,item:t.item});if(r.isCancelled===!0)return;n.length>=s.max&&s.max>0&&n.pop(),delete t.item.hidden,n.push(t.item),e(i.el).data("selected",n).change(),e(i.helpers.multi).find("input").val("").width(20),i.refresh(),e("#w2ui-overlay").length>0&&e("#w2ui-overlay")[0].hide(),i.trigger(e.extend(r,{phase:"after"}))}}else e(i.el).data("selected",t.item).val(t.item.text).change(),i.helpers.focus&&i.helpers.focus.find("input").val("")}}))}}},inRange:function(t){var i=!1;if("date"==this.type){var s=w2utils.isDate(t,this.options.format,!0);if(s){if(this.options.start||this.options.end){var n="string"==typeof this.options.start?this.options.start:e(this.options.start).val(),r="string"==typeof this.options.end?this.options.end:e(this.options.end).val(),a=w2utils.isDate(n,this.options.format,!0),o=w2utils.isDate(r,this.options.format,!0),l=new Date(s);a||(a=l),o||(o=l),l>=a&&o>=l&&(i=!0)}else i=!0;this.options.blocked&&-1!=e.inArray(t,this.options.blocked)&&(i=!1)}}if("time"==this.type)if(this.options.start||this.options.end){var d=this.toMin(t),h=this.toMin(this.options.start),u=this.toMin(this.options.end);h||(h=d),u||(u=d),d>=h&&u>=d&&(i=!0)}else i=!0;return i},checkType:function(e,t){var i=this;switch(i.type){case"int":return t&&-1!=["-",i.options.groupSymbol].indexOf(e)?!0:w2utils.isInt(e.replace(i.options.numberRE,""));case"percent":e=e.replace(/%/g,"");case"float":return t&&-1!=["-",w2utils.settings.decimalSymbol,i.options.groupSymbol].indexOf(e)?!0:w2utils.isFloat(e.replace(i.options.numberRE,""));case"money":case"currency":return t&&-1!=["-",i.options.decimalSymbol,i.options.groupSymbol,i.options.currencyPrefix,i.options.currencySuffix].indexOf(e)?!0:w2utils.isFloat(e.replace(i.options.moneyRE,""));case"hex":case"color":return w2utils.isHex(e);case"alphanumeric":return w2utils.isAlphaNumeric(e)}return!0},addPrefix:function(){var t=this;setTimeout(function(){if("clear"!==t.type){var i,s=e(t.el).data("tmp")||{};s["old-padding-left"]&&e(t.el).css("padding-left",s["old-padding-left"]),s["old-padding-left"]=e(t.el).css("padding-left"),e(t.el).data("tmp",s),t.helpers.prefix&&e(t.helpers.prefix).remove(),""!==t.options.prefix&&(e(t.el).before('<div class="w2ui-field-helper">'+t.options.prefix+"</div>"),i=e(t.el).prev(),i.css({color:e(t.el).css("color"),"font-family":e(t.el).css("font-family"),"font-size":e(t.el).css("font-size"),"padding-top":e(t.el).css("padding-top"),"padding-bottom":e(t.el).css("padding-bottom"),"padding-left":e(t.el).css("padding-left"),"padding-right":0,"margin-top":parseInt(e(t.el).css("margin-top"),10)+2+"px","margin-bottom":parseInt(e(t.el).css("margin-bottom"),10)+1+"px","margin-left":e(t.el).css("margin-left"),"margin-right":0}).on("click",function(){if(t.options.icon&&"function"==typeof t.onIconClick){var i=t.trigger({phase:"before",type:"iconClick",target:t.el,el:e(this).find("span.w2ui-icon")[0]});if(i.isCancelled===!0)return;t.trigger(e.extend(i,{phase:"after"}))}else"list"==t.type?e(t.helpers.focus).find("input").focus():e(t.el).focus()}),e(t.el).css("padding-left",i.width()+parseInt(e(t.el).css("padding-left"),10)+"px"),t.helpers.prefix=i)}},1)},addSuffix:function(){var t,i,s=this;setTimeout(function(){if("clear"!==s.type){var n=e(s.el).data("tmp")||{};if(n["old-padding-right"]&&e(s.el).css("padding-right",n["old-padding-right"]),n["old-padding-right"]=e(s.el).css("padding-right"),e(s.el).data("tmp",n),i=parseInt(e(s.el).css("padding-right"),10),s.options.arrows){s.helpers.arrows&&e(s.helpers.arrows).remove(),e(s.el).after('<div class="w2ui-field-helper" style="border: 1px solid transparent">&nbsp;    <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>');{w2utils.getSize(s.el,"height")}t=e(s.el).next(),t.css({color:e(s.el).css("color"),"font-family":e(s.el).css("font-family"),"font-size":e(s.el).css("font-size"),height:e(s.el).height()+parseInt(e(s.el).css("padding-top"),10)+parseInt(e(s.el).css("padding-bottom"),10)+"px",padding:0,"margin-top":parseInt(e(s.el).css("margin-top"),10)+1+"px","margin-bottom":0,"border-left":"1px solid silver"}).css("margin-left","-"+(t.width()+parseInt(e(s.el).css("margin-right"),10)+12)+"px").on("mousedown",function(t){function i(){clearTimeout(r.data("_field_update_timer")),r.off("mouseup",i)}function n(i){e(s.el).focus(),s.keyDown(e.Event("keydown"),{keyCode:"up"==e(t.target).attr("type")?38:40}),i!==!1&&e("body").data("_field_update_timer",setTimeout(n,60))}var r=e("body");r.on("mouseup",i),r.data("_field_update_timer",setTimeout(n,700)),n(!1)}),i+=t.width()+12,e(s.el).css("padding-right",i+"px"),s.helpers.arrows=t}""!==s.options.suffix&&(s.helpers.suffix&&e(s.helpers.suffix).remove(),e(s.el).after('<div class="w2ui-field-helper">'+s.options.suffix+"</div>"),t=e(s.el).next(),t.css({color:e(s.el).css("color"),"font-family":e(s.el).css("font-family"),"font-size":e(s.el).css("font-size"),"padding-top":e(s.el).css("padding-top"),"padding-bottom":e(s.el).css("padding-bottom"),"padding-left":"3px","padding-right":e(s.el).css("padding-right"),"margin-top":parseInt(e(s.el).css("margin-top"),10)+2+"px","margin-bottom":parseInt(e(s.el).css("margin-bottom"),10)+1+"px"}).on("click",function(){"list"==s.type?e(s.helpers.focus).find("input").focus():e(s.el).focus()}),t.css("margin-left","-"+(w2utils.getSize(t,"width")+parseInt(e(s.el).css("margin-right"),10)+2)+"px"),i+=t.width()+3,e(s.el).css("padding-right",i+"px"),s.helpers.suffix=t)}},1)},addFocus:function(){var t,i=this,s=(this.options,0);e(i.helpers.focus).remove();var n='<div class="w2ui-field-helper">    <div class="w2ui-icon icon-search" style="opacity: 0"></div>    <input type="text" autocomplete="off"><div>';e(i.el).attr("tabindex",-1).before(n);var r=e(i.el).prev();i.helpers.focus=r,r.css({width:e(i.el).width(),"margin-top":e(i.el).css("margin-top"),"margin-left":parseInt(e(i.el).css("margin-left"))+parseInt(e(i.el).css("padding-left"))+"px","margin-bottom":e(i.el).css("margin-bottom"),"margin-right":e(i.el).css("margin-right")}).find("input").css({cursor:"default",width:"100%",outline:"none",opacity:1,margin:0,border:"1px solid transparent",padding:e(i.el).css("padding-top"),"padding-left":0,"margin-left":s>0?s+6:0,"background-color":"transparent"}),r.find("input").on("click",function(t){0==e("#w2ui-overlay").length&&i.focus(t),t.stopPropagation()}).on("focus",function(s){t=e(i.el).attr("placeholder"),e(i.el).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"}),e(this).val(""),e(i.el).triggerHandler("focus"),s.stopPropagation?s.stopPropagation():s.cancelBubble=!0}).on("blur",function(s){e(i.el).css("outline","none"),e(this).val(""),i.refresh(),e(i.el).triggerHandler("blur"),s.stopPropagation?s.stopPropagation():s.cancelBubble=!0,null!=t&&e(i.el).attr("placeholder",t)}).on("keydown",function(s){var n=this;i.keyDown(s),setTimeout(function(){""==n.value?e(i.el).attr("placeholder",t):e(i.el).attr("placeholder","")},10)}).on("keyup",function(e){i.keyUp(e)}).on("keypress",function(e){i.keyPress(e)}),r.on("click",function(){e(this).find("input").focus()}),i.refresh()},addMulti:function(){{var t=this;this.options}e(t.helpers.multi).remove();var i="",s="margin-top     : 0px; margin-bottom  : 0px; margin-left    : "+e(t.el).css("margin-left")+"; margin-right   : "+e(t.el).css("margin-right")+"; width          : "+(w2utils.getSize(t.el,"width")-parseInt(e(t.el).css("margin-left"),10)-parseInt(e(t.el).css("margin-right"),10))+"px;";"enum"==t.type&&(i='<div class="w2ui-field-helper w2ui-list" style="'+s+'; 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" autocomplete="off" '+(e(t.el).attr("readonly")?"readonly":"")+">        </li>    </ul>    </div></div>"),"file"==t.type&&(i='<div class="w2ui-field-helper w2ui-list" style="'+s+'; 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">   </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>');var n=e(t.el).data("tmp")||{};n["old-background-color"]=e(t.el).css("background-color"),n["old-border-color"]=e(t.el).css("border-color"),e(t.el).data("tmp",n),e(t.el).before(i).css({"background-color":"transparent","border-color":"transparent"});var r=e(t.el).prev();t.helpers.multi=r,"enum"==t.type&&(e(t.el).attr("tabindex",-1),r.find("input").on("click",function(i){0==e("#w2ui-overlay").length&&t.focus(i),e(t.el).triggerHandler("click")}).on("focus",function(i){e(r).css({outline:"auto 5px #7DB4F3","outline-offset":"-2px"}),e(t.el).triggerHandler("focus"),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0}).on("blur",function(i){e(r).css("outline","none"),e(t.el).triggerHandler("blur"),i.stopPropagation?i.stopPropagation():i.cancelBubble=!0}).on("keyup",function(e){t.keyUp(e)}).on("keydown",function(e){t.keyDown(e)}).on("keypress",function(e){r.find(".w2ui-enum-placeholder").remove(),t.keyPress(e)}),r.on("click",function(){e(this).find("input").focus()})),"file"==t.type&&(e(t.el).css("outline","none"),r.on("click",function(i){e(t.el).focus(),e(t.el).attr("readonly")||(t.blur(i),t.resize(),setTimeout(function(){r.find("input").click()},10))}).on("dragenter",function(){e(t.el).attr("readonly")||e(r).addClass("w2ui-file-dragover")}).on("dragleave",function(i){if(!e(t.el).attr("readonly")){var s=e(i.target).parents(".w2ui-field-helper");0==s.length&&e(r).removeClass("w2ui-file-dragover")}}).on("drop",function(i){if(!e(t.el).attr("readonly")){e(r).removeClass("w2ui-file-dragover");for(var s=i.originalEvent.dataTransfer.files,n=0,a=s.length;a>n;n++)t.addFile.call(t,s[n]);i.preventDefault(),i.stopPropagation()}}).on("dragover",function(e){e.preventDefault(),e.stopPropagation()}),r.find("input").on("click",function(e){e.stopPropagation()}).on("change",function(){if("undefined"!=typeof this.files)for(var e=0,i=this.files.length;i>e;e++)t.addFile.call(t,this.files[e])})),t.refresh()},addFile:function(t){var i,s=this,n=this.options,r=e(s.el).data("selected"),a={name:t.name,type:t.type,modified:t.lastModifiedDate,size:t.size,content:null,file:t},o=0,l=0;for(var d in r){if(r[d].name==t.name&&r[d].size==t.size)return;o+=r[d].size,l++}var h=s.trigger({phase:"before",type:"add",target:s.el,file:a,total:l,totalSize:o});if(h.isCancelled!==!0){if(0!==n.maxFileSize&&a.size>n.maxFileSize)return i="Maximum file size is "+w2utils.formatSize(n.maxFileSize),n.silent===!1&&e(s.el).w2tag(i),void console.log("ERROR: "+i);if(0!==n.maxSize&&o+a.size>n.maxSize)return i="Maximum total size is "+w2utils.formatSize(n.maxSize),n.silent===!1&&e(s.el).w2tag(i),void console.log("ERROR: "+i);if(0!==n.max&&l>=n.max)return i="Maximum number of files is "+n.max,n.silent===!1&&e(s.el).w2tag(i),void console.log("ERROR: "+i);if(r.push(a),"undefined"!=typeof FileReader){var u=new FileReader;u.onload=function(){return function(t){var i=t.target.result,n=i.indexOf(",");a.content=i.substr(n+1),s.refresh(),e(s.el).trigger("change"),s.trigger(e.extend(h,{phase:"after"}))}}(),u.readAsDataURL(t)}else s.refresh(),e(s.el).trigger("change")}},normMenu:function(t){if(e.isArray(t)){for(var i=0;i<t.length;i++)"string"==typeof t[i]?t[i]={id:t[i],text:t[i]}:("undefined"!=typeof t[i].text&&"undefined"==typeof t[i].id&&(t[i].id=t[i].text),"undefined"==typeof t[i].text&&"undefined"!=typeof t[i].id&&(t[i].text=t[i].id),"undefined"!=typeof t[i].caption&&(t[i].text=t[i].caption));return t}if("object"==typeof t){var s=[];for(var i in t)s.push({id:i,text:t[i]});return s}},getColorHTML:function(){for(var t='<div class="w2ui-color"><table cellspacing="5">',i=0;8>i;i++){t+="<tr>";for(var s=0;8>s;s++)t+='<td>    <div class="color" style="background-color: #'+this.pallete[i][s]+';" name="'+this.pallete[i][s]+'" index="'+i+":"+s+'">        '+(e(this.el).val()==this.pallete[i][s]?"&#149;":"&nbsp;")+"    </div></td>";t+="</tr>",2>i&&(t+='<tr><td style="height: 8px" colspan="8"></td></tr>')}return t+="</table></div>"},getMonthHTML:function(e,t){var i=new Date,s=w2utils.settings.fullmonths,n=["31","28","31","30","31","30","31","31","30","31","30","31"],r=i.getFullYear()+"/"+(Number(i.getMonth())+1)+"/"+i.getDate(),a=w2utils.settings.fulldays.slice(),o=w2utils.settings.shortdays.slice();"M"!=w2utils.settings.weekStarts&&(a.unshift(a.pop()),o.unshift(o.pop())),t=w2utils.isInt(t)?parseInt(t):i.getFullYear(),e=w2utils.isInt(e)?parseInt(e):i.getMonth()+1,e>12&&(e-=12,t++),(1>e||0===e)&&(e+=12,t--),n[1]=t/4==Math.floor(t/4)?"29":"28",this.options.current=e+"/"+t,i=new Date(t,e-1,1);for(var l=i.getDay(),d="",h=0;h<o.length;h++)d+='<td title="'+a[h]+'">'+o[h]+"</td>";var u='<div class="w2ui-calendar-title title">    <div class="w2ui-calendar-previous previous"> <div></div> </div>    <div class="w2ui-calendar-next next"> <div></div> </div> '+s[e-1]+", "+t+'</div><table class="w2ui-calendar-days" cellspacing="0">    <tr class="w2ui-day-title">'+d+"</tr>    <tr>",c=1;"M"!=w2utils.settings.weekStarts&&l++;for(var p=1;43>p;p++){if(0===l&&1==p){for(var f=0;6>f;f++)u+='<td class="w2ui-day-empty">&nbsp;</td>';p+=6}else if(l>p||c>n[e-1]){u+='<td class="w2ui-day-empty">&nbsp;</td>',p%7===0&&(u+="</tr><tr>");continue}var g=t+"/"+e+"/"+c,m=new Date(g),v="";6==m.getDay()&&(v=" w2ui-saturday"),0==m.getDay()&&(v=" w2ui-sunday"),g==r&&(v+=" w2ui-today");var w=c,y="",b="",x=w2utils.formatDate(g,this.options.format);if(this.options.colored&&void 0!==this.options.colored[x]){var $=this.options.colored[x].split(":");b="background-color: "+$[0]+";",y="color: "+$[1]+";"}u+='<td class="'+(this.inRange(x)?"w2ui-date ":"w2ui-blocked")+v+'" style="'+y+b+'" date="'+x+'">'+w+"</td>",(p%7===0||0===l&&1==p)&&(u+="</tr><tr>"),c++}return u+="</tr></table>"},getYearHTML:function(){for(var e=w2utils.settings.shortmonths,t="",i="",s=0;s<e.length;s++)t+='<div class="w2ui-jump-month" name="'+s+'">'+e[s]+"</div>";for(var n=1950;2020>=n;n++)i+='<div class="w2ui-jump-year" name="'+n+'">'+n+"</div>";return"<div>"+t+"</div><div>"+i+"</div>"},getHourHTML:function(){for(var e=[],t="h24"==this.options.format,i=0;24>i;i++){var s=(i>=12&&!t?i-12:i)+":00"+(t?"":12>i?" am":" pm");12!=i||t||(s="12:00 pm"),e[Math.floor(i/8)]||(e[Math.floor(i/8)]="");var n=this.fromMin(this.toMin(s)),r=this.fromMin(this.toMin(s)+59);e[Math.floor(i/8)]+='<div class="'+(this.inRange(n)||this.inRange(r)?"w2ui-time ":"w2ui-blocked")+'" hour="'+i+'">'+s+"</div>"}var a='<div class="w2ui-calendar-time"><table><tr>    <td>'+e[0]+"</td>    <td>"+e[1]+"</td>    <td>"+e[2]+"</td></tr></table></div>";return a},getMinHTML:function(e){"undefined"==typeof e&&(e=0);for(var t="h24"==this.options.format,i=[],s=0;60>s;s+=5){var n=(e>12&&!t?e-12:e)+":"+(10>s?0:"")+s+" "+(t?"":12>e?"am":"pm"),r=20>s?0:40>s?1:2;i[r]||(i[r]=""),i[r]+='<div class="'+(this.inRange(n)?"w2ui-time ":"w2ui-blocked")+'" min="'+s+'">'+n+"</div>"}var a='<div class="w2ui-calendar-time"><table><tr>    <td>'+i[0]+"</td>    <td>"+i[1]+"</td>    <td>"+i[2]+"</td></tr></table></div>";return a},toMin:function(e){if("string"!=typeof e)return null;var t=e.split(":");return 2!=t.length?null:(t[0]=parseInt(t[0]),t[1]=parseInt(t[1]),-1!=e.indexOf("pm")&&12!=t[0]&&(t[0]+=12),60*t[0]+t[1])},fromMin:function(e){var t="";e>=1440&&(e%=1440),0>e&&(e=1440+e);var i=Math.floor(e/60),s=(10>e%60?"0":"")+e%60;return t=-1!=this.options.format.indexOf("h24")?i+":"+s:(12>=i?i:i-12)+":"+s+" "+(i>=12?"pm":"am")}},e.extend(t.prototype,w2utils.event),w2obj.field=t}(jQuery),function(){var w2form=function(e){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.toolbar={},this.tabs={},this.style="",this.focus=0,this.msgNotJSON=w2utils.lang("Return data is not in JSON format."),this.msgAJAXerror=w2utils.lang("AJAX error. See console for more details."),this.msgRefresh=w2utils.lang("Refreshing..."),this.msgSaving=w2utils.lang("Saving..."),this.onRequest=null,this.onLoad=null,this.onValidate=null,this.onSubmit=null,this.onProgress=null,this.onSave=null,this.onChange=null,this.onRender=null,this.onRefresh=null,this.onResize=null,this.onDestroy=null,this.onAction=null,this.onToolbar=null,this.onError=null,this.isGenerated=!1,this.last={xhr:null},$.extend(!0,this,w2obj.form,e)};$.fn.w2form=function(e){if($.isPlainObject(e)){var t=this;if(!w2utils.checkName(e,"w2form"))return;var i=e.record,s=e.original,n=e.fields,r=e.toolbar,a=e.tabs,o=new w2form(e);if($.extend(o,{record:{},original:{},fields:[],tabs:{},toolbar:{},handlers:[]}),$.isArray(a)){$.extend(!0,o.tabs,{tabs:[]});for(var l=0;l<a.length;l++){var d=a[l];o.tabs.tabs.push("object"==typeof d?d:{id:d,caption:d})}}else $.extend(!0,o.tabs,a);if($.extend(!0,o.toolbar,r),n)for(var h=0;h<n.length;h++){var u=$.extend(!0,{},n[h]);"undefined"==typeof u.name&&"undefined"!=typeof u.field&&(u.name=u.field),"undefined"==typeof u.field&&"undefined"!=typeof u.name&&(u.field=u.name),o.fields[h]=u}for(var h in i)o.record[h]=$.isPlainObject(i[h])?$.extend(!0,{},i[h]):i[h];for(var h in s)o.original[h]=$.isPlainObject(s[h])?$.extend(!0,{},s[h]):s[h];return t.length>0&&(o.box=t[0]),""!=o.formURL?$.get(o.formURL,function(e){o.formHTML=e,o.isGenerated=!0,(0!=$(o.box).length||0!=e.length)&&($(o.box).html(e),o.render(o.box))}):""!=o.formHTML||(o.formHTML=0!=$(this).length&&""!=$.trim($(this).html())?$(this).html():o.generateHTML()),w2ui[o.name]=o,""==o.formURL&&(-1==String(o.formHTML).indexOf("w2ui-page")&&(o.formHTML='<div class="w2ui-page page-0">'+o.formHTML+"</div>"),$(o.box).html(o.formHTML),o.isGenerated=!0,o.render(o.box)),o
  }var t=w2ui[$(this).attr("name")];return t?arguments.length>0?(t[e]&&t[e].apply(t,Array.prototype.slice.call(arguments,1)),this):t:null},w2form.prototype={get:function(e,t){if(0===arguments.length){for(var i=[],s=0;s<this.fields.length;s++)null!=this.fields[s].name&&i.push(this.fields[s].name);return i}for(var n=0;n<this.fields.length;n++)if(this.fields[n].name==e)return t===!0?n:this.fields[n];return null},set:function(e,t){for(var i=0;i<this.fields.length;i++)if(this.fields[i].name==e)return $.extend(this.fields[i],t),this.refresh(),!0;return!1},show:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);i&&i.hidden&&(i.hidden=!1,e++)}return e>0&&this.refresh(),e},hide:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);i&&!i.hidden&&(i.hidden=!0,e++)}return e>0&&this.refresh(),e},enable:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);i&&i.disabled&&(i.disabled=!1,e++)}return e>0&&this.refresh(),e},disable:function(){for(var e=0,t=0;t<arguments.length;t++){var i=this.get(arguments[t]);i&&!i.disabled&&(i.disabled=!0,e++)}return e>0&&this.refresh(),e},reload:function(e){var t="object"!=typeof this.url?this.url:this.url.get;t&&0!=this.recid&&null!=this.recid?this.request(e):"function"==typeof e&&e()},clear:function(){this.recid=0,this.record={},$().w2tag(),this.refresh()},error:function(e){var t=this.trigger({target:this.name,type:"error",message:e,xhr:this.last.xhr});return t.isCancelled===!0?void("function"==typeof callBack&&callBack()):(setTimeout(function(){w2alert(e,"Error")},1),void this.trigger($.extend(t,{phase:"after"})))},validate:function(e){"undefined"==typeof e&&(e=!0),$().w2tag();for(var t=[],i=0;i<this.fields.length;i++){var s=this.fields[i];switch(null==this.record[s.name]&&(this.record[s.name]=""),s.type){case"int":this.record[s.name]&&!w2utils.isInt(this.record[s.name])&&t.push({field:s,error:w2utils.lang("Not an integer")});break;case"float":this.record[s.name]&&!w2utils.isFloat(this.record[s.name])&&t.push({field:s,error:w2utils.lang("Not a float")});break;case"money":this.record[s.name]&&!w2utils.isMoney(this.record[s.name])&&t.push({field:s,error:w2utils.lang("Not in money format")});break;case"color":case"hex":this.record[s.name]&&!w2utils.isHex(this.record[s.name])&&t.push({field:s,error:w2utils.lang("Not a hex number")});break;case"email":this.record[s.name]&&!w2utils.isEmail(this.record[s.name])&&t.push({field:s,error:w2utils.lang("Not a valid email")});break;case"checkbox":this.record[s.name]=1==this.record[s.name]?1:0;break;case"date":s.options.format||(s.options.format=w2utils.settings.date_format),this.record[s.name]&&!w2utils.isDate(this.record[s.name],s.options.format)&&t.push({field:s,error:w2utils.lang("Not a valid date")+": "+s.options.format});break;case"list":case"combo":break;case"enum":}var n=this.record[s.name];s.required&&(""===n||$.isArray(n)&&0==n.length||$.isPlainObject(n)&&$.isEmptyObject(n))&&t.push({field:s,error:w2utils.lang("Required field")}),s.equalto&&this.record[s.name]!=this.record[s.equalto]&&t.push({field:s,error:w2utils.lang("Field should be equal to ")+s.equalto})}var r=this.trigger({phase:"before",target:this.name,type:"validate",errors:t});if(r.isCancelled!==!0){if(e)for(var a in r.errors){var o=r.errors[a];"radio"==o.field.type?$($(o.field.el).parents("div")[0]).w2tag(o.error,{"class":"w2ui-error"}):-1!=["enum","file"].indexOf(o.field.type)?!function(e){setTimeout(function(){var t=$(e.field.el).data("w2field").helpers.multi;$(e.field.el).w2tag(e.error),$(t).addClass("w2ui-error")},1)}(o):$(o.field.el).w2tag(o.error,{"class":"w2ui-error"}),this["goto"](t[0].field.page)}return this.trigger($.extend(r,{phase:"after"})),t}},getChanges:function(){var e=function(t,i,s){for(var n in t)"object"==typeof t[n]?(s[n]=e(t[n],i[n]||{},{}),(!s[n]||$.isEmptyObject(s[n]))&&delete s[n]):t[n]!=i[n]&&(s[n]=t[n]);return s};return e(this.record,this.original,{})},request:function(postData,callBack){var obj=this;if("function"==typeof postData&&(callBack=postData,postData=null),("undefined"==typeof postData||null==postData)&&(postData={}),this.url&&("object"!=typeof this.url||this.url.get)){(null==this.recid||"undefined"==typeof this.recid)&&(this.recid=0);var params={};params.cmd="get-record",params.recid=this.recid,$.extend(params,this.postData),$.extend(params,postData);var eventData=this.trigger({phase:"before",type:"request",target:this.name,url:this.url,postData:params});if(eventData.isCancelled===!0)return void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."}));this.record={},this.original={},this.lock(this.msgRefresh);var url=eventData.url;if("object"==typeof eventData.url&&eventData.url.get&&(url=eventData.url.get),this.last.xhr)try{this.last.xhr.abort()}catch(e){}if(!$.isEmptyObject(obj.routeData)){var info=w2utils.parseRoute(url);if(info.keys.length>0)for(var k=0;k<info.keys.length;k++)null!=obj.routeData[info.keys[k].name]&&(url=url.replace(new RegExp(":"+info.keys[k].name,"g"),obj.routeData[info.keys[k].name]))}var ajaxOptions={type:"POST",url:url,data:eventData.postData,dataType:"text"};"HTTP"==w2utils.settings.dataType&&(ajaxOptions.data=String($.param(ajaxOptions.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]")),"RESTFULL"==w2utils.settings.dataType&&(ajaxOptions.type="GET",ajaxOptions.data=String($.param(ajaxOptions.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]")),"JSON"==w2utils.settings.dataType&&(ajaxOptions.type="POST",ajaxOptions.data=JSON.stringify(ajaxOptions.data),ajaxOptions.contentType="application/json"),this.last.xhr=$.ajax(ajaxOptions).done(function(data,status,xhr){obj.unlock();var eventData=obj.trigger({phase:"before",target:obj.name,type:"load",xhr:xhr});if(eventData.isCancelled===!0)return void("function"==typeof callBack&&callBack({status:"error",message:"Request aborted."}));var data,responseText=obj.last.xhr.responseText;if("error"!=status){if("undefined"!=typeof responseText&&""!=responseText){if("object"==typeof responseText)data=responseText;else try{eval("data = "+responseText)}catch(e){}"undefined"==typeof data&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),"error"==data.status?obj.error(data.message):(obj.record=$.extend({},data.record),obj.original=$.extend({},data.record))}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText),data={status:"error",message:obj.msgAJAXerror,responseText:responseText};obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),"function"==typeof callBack&&callBack(data)}).fail(function(e,t,i){var s={status:t,error:i,rawResponseText:e.responseText},n=obj.trigger({phase:"before",type:"error",error:s,xhr:e});if(n.isCancelled!==!0){if("abort"!=t){var r;try{r=$.parseJSON(e.responseText)}catch(a){}console.log("ERROR: Server communication failed.","\n   EXPECTED:",{status:"success",items:[{id:1,text:"item"}]},"\n         OR:",{status:"error",message:"error message"},"\n   RECEIVED:","object"==typeof r?r:e.responseText)}obj.trigger($.extend(n,{phase:"after"}))}}),this.trigger($.extend(eventData,{phase:"after"}))}},submit:function(e,t){return this.save(e,t)},save:function(postData,callBack){var obj=this;$(this.box).find(":focus").change(),"function"==typeof postData&&(callBack=postData,postData=null);var errors=obj.validate(!0);if(0===errors.length){if(("undefined"==typeof postData||null==postData)&&(postData={}),!obj.url||"object"==typeof obj.url&&!obj.url.save)return void console.log("ERROR: Form cannot be saved because no url is defined.");obj.lock(obj.msgSaving+' <span id="'+obj.name+'_progress"></span>'),setTimeout(function(){var params={};params.cmd="save-record",params.recid=obj.recid,$.extend(params,obj.postData),$.extend(params,postData),params.record=$.extend(!0,{},obj.record);var eventData=obj.trigger({phase:"before",type:"submit",target:obj.name,url:obj.url,postData:params});if(eventData.isCancelled!==!0){var url=eventData.url;if("object"==typeof eventData.url&&eventData.url.save&&(url=eventData.url.save),obj.last.xhr)try{obj.last.xhr.abort()}catch(e){}if(!$.isEmptyObject(obj.routeData)){var info=w2utils.parseRoute(url);if(info.keys.length>0)for(var k=0;k<info.keys.length;k++)null!=obj.routeData[info.keys[k].name]&&(url=url.replace(new RegExp(":"+info.keys[k].name,"g"),obj.routeData[info.keys[k].name]))}var ajaxOptions={type:"POST",url:url,data:eventData.postData,dataType:"text",xhr:function(){var e=new window.XMLHttpRequest;return e.upload.addEventListener("progress",function(e){if(e.lengthComputable){var t=obj.trigger({phase:"before",type:"progress",total:e.total,loaded:e.loaded,originalEvent:e});if(t.isCancelled===!0)return;var i=Math.round(e.loaded/e.total*100);$("#"+obj.name+"_progress").text(""+i+"%"),obj.trigger($.extend(t,{phase:"after"}))}},!1),e}};"HTTP"==w2utils.settings.dataType&&(ajaxOptions.data=String($.param(ajaxOptions.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]")),"RESTFULL"==w2utils.settings.dataType&&(0!=obj.recid&&null!=obj.recid&&(ajaxOptions.type="PUT"),ajaxOptions.data=String($.param(ajaxOptions.data,!1)).replace(/%5B/g,"[").replace(/%5D/g,"]")),"JSON"==w2utils.settings.dataType&&(ajaxOptions.type="POST",ajaxOptions.data=JSON.stringify(ajaxOptions.data),ajaxOptions.contentType="application/json"),obj.last.xhr=$.ajax(ajaxOptions).done(function(data,status,xhr){obj.unlock();var eventData=obj.trigger({phase:"before",target:obj.name,type:"save",xhr:xhr,status:status});if(eventData.isCancelled!==!0){var data,responseText=xhr.responseText;if("error"!=status){if("undefined"!=typeof responseText&&""!=responseText){if("object"==typeof responseText)data=responseText;else try{eval("data = "+responseText)}catch(e){}"undefined"==typeof data&&(data={status:"error",message:obj.msgNotJSON,responseText:responseText}),"error"==data.status?obj.error(data.message):obj.original=$.extend({},obj.record)}}else obj.error("AJAX Error "+xhr.status+": "+xhr.statusText),data={status:"error",message:obj.msgAJAXerror,responseText:responseText};obj.trigger($.extend(eventData,{phase:"after"})),obj.refresh(),"success"==data.status&&"function"==typeof callBack&&callBack(data)}}).fail(function(e,t,i){var s={status:t,error:i,rawResponseText:e.responseText},n=obj.trigger({phase:"before",type:"error",error:s,xhr:e});n.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: ",s),obj.trigger($.extend(n,{phase:"after"})))}),obj.trigger($.extend(eventData,{phase:"after"}))}},50)}},lock:function(){var e=$(this.box).find("> div:first-child"),t=Array.prototype.slice.call(arguments,0);t.unshift(e),w2utils.lock.apply(window,t)},unlock:function(e){var t=this;setTimeout(function(){w2utils.unlock(t.box,e)},25)},"goto":function(e){"undefined"!=typeof e&&(this.page=e),$(this.box).data("auto-size")===!0&&$(this.box).height(0),this.refresh()},generateHTML:function(){for(var e,t=[],i="",s=0;s<this.fields.length;s++){var n="",r=this.fields[s];"undefined"==typeof r.html&&(r.html={}),r.html=$.extend(!0,{caption:"",span:6,attr:"",text:"",style:"",page:0},r.html),"undefined"==typeof e&&(e=r.html.page),""==r.html.caption&&(r.html.caption=r.name);var a='<input name="'+r.name+'" type="text" '+r.html.attr+"/>";("pass"===r.type||"password"===r.type)&&(a='<input name="'+r.name+'" type = "password" '+r.html.attr+"/>"),"checkbox"==r.type&&(a='<input name="'+r.name+'" type="checkbox" '+r.html.attr+"/>"),"textarea"==r.type&&(a='<textarea name="'+r.name+'" '+r.html.attr+"></textarea>"),"toggle"==r.type&&(a='<input name="'+r.name+'" type="checkbox" '+r.html.attr+' class="w2ui-toggle"/><div><div></div></div>'),r.html.group&&(""!=i&&(n+="\n   </div>"),n+='\n   <div class="w2ui-group-title">'+r.html.group+'</div>\n   <div class="w2ui-group">',i=r.html.group),r.html.page!=e&&""!=i&&(t[t.length-1]+="\n   </div>",i=""),n+='\n      <div class="w2ui-field '+("undefined"!=typeof r.html.span?"w2ui-span"+r.html.span:"")+'" style="'+r.html.style+'">\n         <label>'+w2utils.lang(r.html.caption)+"</label>\n         <div>"+a+w2utils.lang(r.html.text)+"</div>\n      </div>","undefined"==typeof t[r.html.page]&&(t[r.html.page]=""),t[r.html.page]+=n,e=r.html.page}if(""!=i&&(t[t.length-1]+="\n   </div>"),this.tabs.tabs)for(var o=0;o<this.tabs.tabs.length;o++)"undefined"==typeof t[o]&&(t[o]="");for(var l=0;l<t.length;l++)t[l]='<div class="w2ui-page page-'+l+'">'+t[l]+"\n</div>";var d="";if(!$.isEmptyObject(this.actions)){d+='\n<div class="w2ui-buttons">';for(var h in this.actions){var u=this.actions[h],c={caption:"",style:"","class":""};$.isPlainObject(u)?(u.caption&&(c.caption=u.caption),u.style&&(c.style=u.style),u["class"]&&(c["class"]=u["class"])):(c.caption=h,c["class"]=-1!=["save","update","create"].indexOf(h.toLowerCase())?"w2ui-btn-green":""),d+='\n    <button name="'+h+'" class="w2ui-btn '+c["class"]+'" style="'+c.style+'">'+w2utils.lang(c.caption)+"</button>"}d+="\n</div>"}return t.join("")+d},action:function(e,t){var i=null,s=this.actions[e],i=s;$.isPlainObject(s)&&s.onClick&&(i=s.onClick);var n=this.trigger({phase:"before",target:e,type:"action",click:i,originalEvent:t});n.isCancelled!==!0&&("function"==typeof i&&i.call(this,t),this.trigger($.extend(n,{phase:"after"})))},resize:function(){function e(){s.width($(t.box).width()).height($(t.box).height()),r.css("top",""!=t.header?w2utils.getSize(n,"height"):0),a.css("top",(""!=t.header?w2utils.getSize(n,"height"):0)+("object"==typeof t.toolbar&&$.isArray(t.toolbar.items)&&t.toolbar.items.length>0?w2utils.getSize(r,"height"):0)),o.css("top",(""!=t.header?w2utils.getSize(n,"height"):0)+("object"==typeof t.toolbar&&$.isArray(t.toolbar.items)&&t.toolbar.items.length>0?w2utils.getSize(r,"height")+5:0)+("object"==typeof t.tabs&&$.isArray(t.tabs.tabs)&&t.tabs.tabs.length>0?w2utils.getSize(a,"height")+5:0)),o.css("bottom",h.length>0?w2utils.getSize(h,"height"):0)}var t=this,i=this.trigger({phase:"before",target:this.name,type:"resize"});if(i.isCancelled!==!0){var s=$(this.box).find("> div"),n=$(this.box).find("> div .w2ui-form-header"),r=$(this.box).find("> div .w2ui-form-toolbar"),a=$(this.box).find("> div .w2ui-form-tabs"),o=$(this.box).find("> div .w2ui-page"),l=$(this.box).find("> div .w2ui-page.page-"+this.page),d=$(this.box).find("> div .w2ui-page.page-"+this.page+" > div"),h=$(this.box).find("> div .w2ui-buttons");e(),(0==parseInt($(this.box).height())||$(this.box).data("auto-size")===!0)&&($(this.box).height((n.length>0?w2utils.getSize(n,"height"):0)+("object"==typeof this.tabs&&$.isArray(this.tabs.tabs)&&this.tabs.tabs.length>0?w2utils.getSize(a,"height"):0)+("object"==typeof this.toolbar&&$.isArray(this.toolbar.items)&&this.toolbar.items.length>0?w2utils.getSize(r,"height"):0)+(o.length>0?w2utils.getSize(d,"height")+w2utils.getSize(l,"+height")+12:0)+(h.length>0?w2utils.getSize(h,"height"):0)),$(this.box).data("auto-size",!0)),e(),t.trigger($.extend(i,{phase:"after"}))}},refresh:function(){var e=(new Date).getTime(),t=this;if(this.box&&this.isGenerated&&"undefined"!=typeof $(this.box).html()){$(this.box).find("input, textarea, select").each(function(e,i){var s=$(i).attr("undefined"!=typeof $(i).attr("name")?"name":"id"),n=t.get(s);if(n){var r=$(i).parents(".w2ui-page");if(r.length>0)for(var a=0;100>a;a++)if(r.hasClass("page-"+a)){n.page=a;break}}});var i=this.trigger({phase:"before",target:this.name,type:"refresh",page:this.page});if(i.isCancelled!==!0){$(this.box).find(".w2ui-page").hide(),$(this.box).find(".w2ui-page.page-"+this.page).show(),$(this.box).find(".w2ui-form-header").html(this.header),"object"==typeof this.tabs&&$.isArray(this.tabs.tabs)&&this.tabs.tabs.length>0?($("#form_"+this.name+"_tabs").show(),this.tabs.active=this.tabs.tabs[this.page].id,this.tabs.refresh()):$("#form_"+this.name+"_tabs").hide(),"object"==typeof this.toolbar&&$.isArray(this.toolbar.items)&&this.toolbar.items.length>0?($("#form_"+this.name+"_toolbar").show(),this.toolbar.refresh()):$("#form_"+this.name+"_toolbar").hide();for(var s=0;s<this.fields.length;s++){var n=this.fields[s];"undefined"==typeof n.name&&"undefined"!=typeof n.field&&(n.name=n.field),"undefined"==typeof n.field&&"undefined"!=typeof n.name&&(n.field=n.name),n.$el=$(this.box).find('[name="'+String(n.name).replace(/\\/g,"\\\\")+'"]'),n.el=n.$el[0],"undefined"==typeof n.el&&console.log('ERROR: Cannot associate field "'+n.name+'" with html control. Make sure html control exists with the same name.'),n.el&&(n.el.id=n.name);var r=$(n).data("w2field");r&&r.clear(),$(n.$el).off("change").on("change",function(){var e=this.value,i=t.record[this.name]?t.record[this.name]:"",s=t.get(this.name);if(-1!=["list","enum","file"].indexOf(s.type)&&$(this).data("selected")){var n=$(this).data("selected"),r=t.record[this.name];if($.isArray(n)){e=[];for(var a=0;a<n.length;a++)e[a]=$.extend(!0,{},n[a])}if($.isPlainObject(n)&&(e=$.extend(!0,{},n)),$.isArray(r)){i=[];for(var a=0;a<r.length;a++)i[a]=$.extend(!0,{},r[a])}$.isPlainObject(r)&&(i=$.extend(!0,{},r))}if("toggle"==s.type&&(e=$(this).prop("checked")?1:0),-1!=["int","float","percent","money","currency"].indexOf(s.type)&&(e=$(this).data("w2field").clean(e)),e!==i){var o=t.trigger({phase:"before",target:this.name,type:"change",value_new:e,value_previous:i});if(o.isCancelled===!0)return void $(this).val(t.record[this.name]);var l=this.value;if("select"==this.type&&(l=this.value),"checkbox"==this.type&&(l=this.checked?!0:!1),"radio"==this.type&&s.$el.each(function(e,t){t.checked&&(l=t.value)}),-1!=["int","float","percent","money","currency","list","combo","enum","file","toggle"].indexOf(s.type)&&(l=e),-1!=["enum","file"].indexOf(s.type)&&l.length>0){var d=$(s.el).data("w2field").helpers.multi;$(d).removeClass("w2ui-error")}(""==l||$.isArray(l)&&0==l.length||$.isPlainObject(l)&&$.isEmptyObject(l))&&(l=null),t.record[this.name]=l,t.trigger($.extend(o,{phase:"after"}))}}),n.required?$(n.el).parent().parent().addClass("w2ui-required"):$(n.el).parent().parent().removeClass("w2ui-required"),n.disabled?$(n.el).prop("readonly",!0):$(n.el).prop("readonly",!1),n.hidden?$(n.el).parent().parent().hide():$(n.el).parent().parent().show()}$(this.box).find("button, input[type=button]").each(function(e,i){$(i).off("click").on("click",function(e){var i=this.value;this.id&&(i=this.id),this.name&&(i=this.name),t.action(i,e)})});for(var s=0;s<this.fields.length;s++){var n=this.fields[s],a="undefined"!=typeof this.record[n.name]?this.record[n.name]:"";if(n.el)switch(n.type=String(n.type).toLowerCase(),n.options||(n.options={}),n.type){case"text":case"textarea":case"email":case"pass":case"password":n.el.value=a;break;case"int":case"float":case"money":case"currency":case"percent":n.el.value="number"==typeof a?w2utils.formatNumber(a,n.options.groupSymbol,n.options.decimalSymbol):a,$(n.el).w2field($.extend({},n.options,{type:n.type}));break;case"hex":case"alphanumeric":case"color":case"date":case"time":n.el.value=a,$(n.el).w2field($.extend({},n.options,{type:n.type}));break;case"toggle":w2utils.isFloat(a)&&(a=parseFloat(a)),$(n.el).prop("checked",a?!0:!1),this.record[n.name]=a?1:0;break;case"list":case"combo":if("list"==n.type){var o=$.isPlainObject(a)?a.id:a,l=n.options.items;$.isArray(l)&&l.length>0&&!$.isPlainObject(l[0])&&(n.options.items=w2obj.field.prototype.normMenu(l));for(var d=0;d<n.options.items.length;d++){var h=n.options.items[d];if(h.id==o){a=$.extend(!0,{},h),t.record[n.name]=a;break}}}else n.el.value="combo"!=n.type||$.isPlainObject(a)?$.isPlainObject(a)&&"undefined"!=typeof a.text?a.text:"":a;$.isPlainObject(a)||(a={}),$(n.el).w2field($.extend({},n.options,{type:n.type,selected:a}));break;case"enum":case"file":$.isArray(a)||(a=[]),$(n.el).w2field($.extend({},n.options,{type:n.type,selected:a}));break;case"select":var l=n.options.items;if("undefined"!=typeof l&&l.length>0){l=w2obj.field.prototype.normMenu(l),$(n.el).html("");for(var u=0;u<l.length;u++)$(n.el).append('<option value="'+l[u].id+'">'+l[u].text+"</option")}$(n.el).val(a);break;case"radio":$(n.$el).prop("checked",!1).each(function(e,t){$(t).val()==a&&$(t).prop("checked",!0)});break;case"checkbox":$(n.el).prop("checked",a?!0:!1);break;default:$(n.el).w2field($.extend({},n.options,{type:n.type}))}}for(var r=$(this.box).find(".w2ui-page"),d=0;d<r.length;d++)$(r[d]).find("> *").length>1&&$(r[d]).wrapInner("<div></div>");return this.trigger($.extend(i,{phase:"after"})),this.resize(),(new Date).getTime()-e}}},render:function(e){function t(){var e=$(s.box).find("input, select, textarea");e.length>s.focus&&e[s.focus].focus()}var i=(new Date).getTime(),s=this;if("object"==typeof e&&($(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),this.box=e),this.isGenerated&&this.box){var n=this.trigger({phase:"before",target:this.name,type:"render",box:"undefined"!=typeof e?e:this.box});if(n.isCancelled!==!0){$.isEmptyObject(this.original)&&!$.isEmptyObject(this.record)&&(this.original=$.extend(!0,{},this.record));var r="<div>"+(""!=this.header?'<div class="w2ui-form-header">'+this.header+"</div>":"")+'    <div id="form_'+this.name+'_toolbar" class="w2ui-form-toolbar"></div>    <div id="form_'+this.name+'_tabs" class="w2ui-form-tabs"></div>'+this.formHTML+"</div>";$(this.box).attr("name",this.name).addClass("w2ui-reset w2ui-form").html(r),$(this.box).length>0&&($(this.box)[0].style.cssText+=this.style),"function"!=typeof this.toolbar.render&&(this.toolbar=$().w2toolbar($.extend({},this.toolbar,{name:this.name+"_toolbar",owner:this})),this.toolbar.on("click",function(e){var t=s.trigger({phase:"before",type:"toolbar",target:e.target,originalEvent:e});t.isCancelled!==!0&&s.trigger($.extend(t,{phase:"after"}))})),"object"==typeof this.toolbar&&"function"==typeof this.toolbar.render&&this.toolbar.render($("#form_"+this.name+"_toolbar")[0]),"function"!=typeof this.tabs.render&&(this.tabs=$().w2tabs($.extend({},this.tabs,{name:this.name+"_tabs",owner:this})),this.tabs.on("click",function(e){s["goto"](this.get(e.target,!0))})),"object"==typeof this.tabs&&"function"==typeof this.tabs.render&&this.tabs.render($("#form_"+this.name+"_tabs")[0]),this.trigger($.extend(n,{phase:"after"})),this.resize();var a="object"!=typeof this.url?this.url:this.url.get;return a&&0!=this.recid&&null!=this.recid?this.request():this.refresh(),0==$(".w2ui-layout").length&&(this.tmp_resize=function(){w2ui[s.name].resize()},$(window).off("resize","body").on("resize","body",this.tmp_resize)),setTimeout(function(){s.resize(),s.refresh()},150),this.focus>=0&&setTimeout(t,500),(new Date).getTime()-i}}},destroy:function(){var e=this.trigger({phase:"before",target:this.name,type:"destroy"});e.isCancelled!==!0&&("object"==typeof this.toolbar&&this.toolbar.destroy&&this.toolbar.destroy(),"object"==typeof this.tabs&&this.tabs.destroy&&this.tabs.destroy(),$(this.box).find("#form_"+this.name+"_tabs").length>0&&$(this.box).removeAttr("name").removeClass("w2ui-reset w2ui-form").html(""),delete w2ui[this.name],this.trigger($.extend(e,{phase:"after"})),$(window).off("resize","body"))}},$.extend(w2form.prototype,w2utils.event),w2obj.form=w2form}();