var stuff={};function $(a){return document.getElementById(a)}stuff.removeAllChildren=function(a){if(a){while(a.firstChild){a.removeChild(a.firstChild)}}};function walkTheDOM(b,a){a(b);b=b.firstChild;while(b){walkTheDOM(b,a);b=b.nextSibling}}function purgeEventHandlers(a){walkTheDOM(a,function(b){for(var c in b){if(typeof b[c]==="function"){b[c]=null}}})}function stringStartsWith(c,b){if(c===null||c===undefined||b===null||b===undefined){return false}else{return b===c||b===c.slice(0,b.length)}}function stringEndsWith(c,b){if(c===null||c===undefined||b===null||b===undefined){return false}else{return b===c||b===c.slice(-b.length)}}function getImage(d,b,e,g,a,h){var c=new Image();c.src=d;if(b){c.className=b}if(e){c.alt=e}if(g){c.title=g}if(a){c.style.width=a}if(h){c.style.height=h}return c}stuff.arraysEqual=function(b,a){if(b===a){return true}if(!b||!a){return false}if(b.length!=a.length){return false}var c;for(c=0;c<b.length;c++){if(b[c]!=a[c]){return false}}return true};stuff.supplant=function(a,b){return b.replace(/\{([^{}]*)\}/g,function(d,c){var e=b[c];return typeof e==="string"?e:d})};stuff.getAge=(function(){var d=true,c=[31,28,31,30,31,30,31,31,30,31,30,31];function b(g){return g%4?28:g%400?g%100?29:28:29}function f(g){var i=g.getMonth(),h=g.getFullYear();if(i===0){i=11;h--}else{i--}if(i===1){return b(h)}else{return c[i]}}function e(g){var i=g.getMonth(),h=g.getFullYear();if(i===0){i=10;h--}else{if(i===1){i=11;h--}else{i-=2}}if(i===1){return b(h)}else{return c[i]}}function a(j,h,l){var n=[],o=h.getFullYear()-j.getFullYear(),i=h.getMonth()-j.getMonth(),r=h.getDate()-j.getDate(),p=h.getHours()-j.getHours(),m=h.getMinutes()-j.getMinutes(),q=h.getSeconds()-j.getSeconds(),g=0;function k(s,u,t,v){if(t===0||v>l){}else{if(t===1){s.push(String(t)+" "+u)}else{s.push(String(t)+" "+u+"s")}}}if(!l){l=7}if(q<0){q+=60;m--}if(m<0){m+=60;p--}if(p<0){p+=24;r--}if(r<0){r+=f(h);i--;if(r<0){r+=e(h);i--}}if(i<0){i+=12;o--}if(d){g=Math.floor(r/7);r=r%7}k(n,"year",o,1);k(n,"month",i,2);k(n,"week",g,3);k(n,"day",r,4);k(n,"hour",p,5);k(n,"minute",m,6);k(n,"second",q,7);if(n.length>1){n[n.length-1]="and "+n[n.length-1]}return n.join(", ")}return a})();stuff.getDuration=function(b){var a=new Date(),c=new Date(a.getTime()-b);return stuff.getAge(c,a)};stuff.arrayToMap=function(b,d){var c,e={};if(!b){return e}if(!d){d=0}for(c=b.length;d<c;d++){e[b[d]]=true}return e};stuff.hasClass=function(f,g){var a,e,d,b;if(f){a=f.className;if(a!==null&&a!==undefined&&a!==""){e=a.split(" ");for(d=0,b=e.length;d<b;d++){if(g===e[d]){return true}}}}return false};stuff.getClasses=function(b){var a;if(b){a=b.className;if(a!==null&&a!==undefined&&a!==""){return stuff.arrayToMap(a.split(" "))}}return{}};stuff.removeClass=function(f){var a,e=[],d,c,g=stuff.arrayToMap(arguments,1),b=[];if(f){a=f.className;if(a!==null&&a!==undefined&&a!==""){e=a.split(" ");for(d=0,c=e.length;d<c;d++){if(!g[e[d]]){b.push(e[d])}}}else{return}f.className=b.join(" ")}};stuff.addClass=function(e){var a,d=[],c,b,f;if(!e||arguments.length<=1){return}a=e.className;if(a!==null&&a!==undefined&&a!==""){d=a.split(" ")}else{d=[]}f=stuff.arrayToMap(d);for(c=1,b=arguments.length;c<b;c++){if(!f[arguments[c]]){d.push(arguments[c])}}e.className=d.join(" ")};stuff.merge=function(d,c){for(var e in c){if(c.hasOwnProperty(e)){d[e]=c[e]}}return d};stuff.trim=function(b){b=b.replace(/^\s+/,"");for(var a=b.length-1;a>=0;a--){if(/\S/.test(b.charAt(a))){b=b.substring(0,a+1);break}}return b};function Observable(){this.events={}}Observable.prototype.on=function(c,b,a){var e=this.events[c],d;if(!a){a=this}d=function(f){if(f){b.apply(a,f)}else{b.apply(a)}};if(!e){e=[d];this.events[c]=e}else{e.push(d)}};Observable.prototype.trigger=function(d,b){var e=this.events[d],c,a;if(e){for(c=0,a=e.length;c<a;c++){e[c](b)}}};function SmartTextField(a){var c=new Observable(),b=this;this.observable=c;this.textField=a;this.lastVal=this.getValue();a.onfocus=function(){stuff.removeClass(a,"textblur");stuff.addClass(a,"textfocus");c.trigger("focus")};a.onblur=function(){stuff.addClass(a,"textblur");stuff.removeClass(a,"textfocus");c.trigger("blur")};a.onkeydown=function(d){var f;d=d||event;f=d.keyCode||d.which;if(f===13){c.trigger("enter")}setTimeout(function(){b.synch()},0)};a.onchange=function(){setTimeout(function(){b.synch()},0)};stuff.addClass(a,"textblur");this.synch()}SmartTextField.prototype.synch=function(){var b=this.getValue(),a=b!==this.lastVal;this.lastVal=b;if(b.length===0){stuff.addClass(this.textField,"notext");if(a){this.observable.trigger("clear")}}else{stuff.removeClass(this.textField,"notext");if(a){this.observable.trigger("set",[b])}}};SmartTextField.prototype.getValue=function(){return stuff.trim(this.textField.value)};SmartTextField.prototype.on=function(c,b,a){this.observable.on(c,b,a)};SmartTextField.prototype.setValue=function(a){this.textField.value=stuff.trim(a);this.synch()};SmartTextField.prototype.clearValue=function(){this.textField.value="";this.synch()};stuff.getWinGeometry=(function(){if(typeof(window.innerWidth)==="number"){return function(){return{w:window.innerWidth,h:window.innerHeight,x:window.screenX,y:window.screenY}}}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){return function(){return{w:document.documentElement.clientWidth,h:document.documentElement.clientHeight,x:window.screenLeft,y:window.screenTop}}}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){return function(){return{w:document.body.clientWidth,h:document.body.clientHeight,x:window.screenLeft,y:window.screenTop}}}else{return function(){return{w:0,h:0,x:0,y:0}}}}}})();stuff.getAscendentProp=function(a,b){while(a){if((b in a.data)&&a.data[b]!==null&&a.data[b]!==undefined){return a.data[b]}a=a.parent}};stuff.getCrudFlags=function(a){var b={c:1===stuff.getAscendentProp(a,"IS_CREATE_ALLOWED"),r:1===stuff.getAscendentProp(a,"IS_READ_ALLOWED"),u:1===stuff.getAscendentProp(a,"IS_UPDATE_ALLOWED"),d:1===stuff.getAscendentProp(a,"IS_DELETE_ALLOWED"),s:1===stuff.getAscendentProp(a,"IS_STRUCTURAL_MODIFICATION_ALLOWED"),o:1===stuff.getAscendentProp(a,"IS_OPEN_BROWSE_ALLOWED")};return b};stuff.bubble=function(c,a){if(!a){c.cancelBubble=true;if(c.stopPropagation){c.stopPropagation()}}return a};
