/*
* jQuery Form Plugin
* version: 2.67 (12-MAR-2011)
* @requires jQuery v1.3.2 or later
*
* Examples and documentation at: http://malsup.com/jquery/form/
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*/
(function(b){b.fn.ajaxSubmit=function(w){if(!this.length){a("ajaxSubmit: skipping submit process - no element selected");return this}if(typeof w=="function"){w={success:w}}var j=this.attr("action");var d=(typeof j==="string")?b.trim(j):"";if(d){d=(d.match(/^([^#]+)/)||[])[1]}d=d||window.location.href||"";w=b.extend(true,{url:d,type:this[0].getAttribute("method")||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},w);var x={};this.trigger("form-pre-serialize",[this,w,x]);if(x.veto){a("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this}if(w.beforeSerialize&&w.beforeSerialize(this,w)===false){a("ajaxSubmit: submit aborted via beforeSerialize callback");return this}var f,s,p=this.formToArray(w.semantic);if(w.data){w.extraData=w.data;for(f in w.data){if(w.data[f] instanceof Array){for(var l in w.data[f]){p.push({name:f,value:w.data[f][l]})}}else{s=w.data[f];s=b.isFunction(s)?s():s;p.push({name:f,value:s})}}}if(w.beforeSubmit&&w.beforeSubmit(p,this,w)===false){a("ajaxSubmit: submit aborted via beforeSubmit callback");return this}this.trigger("form-submit-validate",[p,this,w,x]);if(x.veto){a("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this}var c=b.param(p);if(w.type.toUpperCase()=="GET"){w.url+=(w.url.indexOf("?")>=0?"&":"?")+c;w.data=null}else{w.data=c}var u=this,o=[];if(w.resetForm){o.push(function(){u.resetForm()})}if(w.clearForm){o.push(function(){u.clearForm()})}if(!w.dataType&&w.target){var t=w.success||function(){};o.push(function(n){var k=w.replaceTarget?"replaceWith":"html";b(w.target)[k](n).each(t,arguments)})}else{if(w.success){o.push(w.success)}}w.success=function(y,n,z){var v=w.context||w;for(var q=0,k=o.length;q<k;q++){o[q].apply(v,[y,n,z||u,u])}};var g=b("input:file",this).length>0;var e="multipart/form-data";var m=(u.attr("enctype")==e||u.attr("encoding")==e);if(w.iframe!==false&&(g||w.iframe||m)){if(w.closeKeepAlive){b.get(w.closeKeepAlive,r)}else{r()}}else{b.ajax(w)}this.trigger("form-submit-notify",[this,w]);return this;function r(){var v=u[0];if(b(":input[name=submit],:input[id=submit]",v).length){alert('Error: Form elements must not have name or id of "submit".');return}var D=b.extend(true,{},b.ajaxSettings,w);D.context=D.context||D;var G="jqFormIO"+(new Date().getTime()),B="_"+G;var y=b('<iframe id="'+G+'" name="'+G+'" src="'+D.iframeSrc+'" />');var C=y[0];y.css({position:"absolute",top:"-1000px",left:"-1000px"});var z={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){a("aborting upload...");var n="aborted";this.aborted=1;y.attr("src",D.iframeSrc);z.error=n;D.error&&D.error.call(D.context,z,"error",n);K&&b.event.trigger("ajaxError",[z,D,n]);D.complete&&D.complete.call(D.context,z,"error")}};var K=D.global;if(K&&!b.active++){b.event.trigger("ajaxStart")}if(K){b.event.trigger("ajaxSend",[z,D])}if(D.beforeSend&&D.beforeSend.call(D.context,z,D)===false){if(D.global){b.active--}return}if(z.aborted){return}var J=0;var A=v.clk;if(A){var H=A.name;if(H&&!A.disabled){D.extraData=D.extraData||{};D.extraData[H]=A.value;if(A.type=="image"){D.extraData[H+".x"]=v.clk_x;D.extraData[H+".y"]=v.clk_y}}}function I(){var Q=u.attr("target"),O=u.attr("action");v.setAttribute("target",G);if(v.getAttribute("method")!="POST"){v.setAttribute("method","POST")}if(v.getAttribute("action")!=D.url){v.setAttribute("action",D.url)}if(!D.skipEncodingOverride){u.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"})}if(D.timeout){setTimeout(function(){J=true;F()},D.timeout)}var P=[];try{if(D.extraData){for(var R in D.extraData){P.push(b('<input type="hidden" name="'+R+'" value="'+D.extraData[R]+'" />').appendTo(v)[0])}}y.appendTo("body");C.attachEvent?C.attachEvent("onload",F):C.addEventListener("load",F,false);v.submit()}finally{v.setAttribute("action",O);if(Q){v.setAttribute("target",Q)}else{u.removeAttr("target")}b(P).remove()}}if(D.forceSync){I()}else{setTimeout(I,10)}var M,N,L=50;function F(){if(z.aborted){return}var T=C.contentWindow?C.contentWindow.document:C.contentDocument?C.contentDocument:C.document;if(!T||T.location.href==D.iframeSrc){return}C.detachEvent?C.detachEvent("onload",F):C.removeEventListener("load",F,false);var P=true;try{if(J){throw"timeout"}var U=D.dataType=="xml"||T.XMLDocument||b.isXMLDoc(T);a("isXml="+U);if(!U&&window.opera&&(T.body==null||T.body.innerHTML=="")){if(--L){a("requeing onLoad callback, DOM not available");setTimeout(F,250);return}}z.responseText=T.body?T.body.innerHTML:T.documentElement?T.documentElement.innerHTML:null;z.responseXML=T.XMLDocument?T.XMLDocument:T;z.getResponseHeader=function(W){var V={"content-type":D.dataType};return V[W]};var S=/(json|script)/.test(D.dataType);if(S||D.textarea){var O=T.getElementsByTagName("textarea")[0];if(O){z.responseText=O.value}else{if(S){var R=T.getElementsByTagName("pre")[0];var n=T.getElementsByTagName("body")[0];if(R){z.responseText=R.textContent}else{if(n){z.responseText=n.innerHTML}}}}}else{if(D.dataType=="xml"&&!z.responseXML&&z.responseText!=null){z.responseXML=E(z.responseText)}}M=k(z,D.dataType,D)}catch(Q){a("error caught:",Q);P=false;z.error=Q;D.error&&D.error.call(D.context,z,"error",Q);K&&b.event.trigger("ajaxError",[z,D,Q])}if(z.aborted){a("upload aborted");P=false}if(P){D.success&&D.success.call(D.context,M,"success",z);K&&b.event.trigger("ajaxSuccess",[z,D])}K&&b.event.trigger("ajaxComplete",[z,D]);if(K&&!--b.active){b.event.trigger("ajaxStop")}D.complete&&D.complete.call(D.context,z,P?"success":"error");setTimeout(function(){y.removeData("form-plugin-onload");y.remove();z.responseXML=null},100)}var E=b.parseXML||function(n,O){if(window.ActiveXObject){O=new ActiveXObject("Microsoft.XMLDOM");O.async="false";O.loadXML(n)}else{O=(new DOMParser()).parseFromString(n,"text/xml")}return(O&&O.documentElement&&O.documentElement.nodeName!="parsererror")?O:null};var q=b.parseJSON||function(n){return window["eval"]("("+n+")")};var k=function(S,Q,P){var O=S.getResponseHeader("content-type")||"",n=Q==="xml"||!Q&&O.indexOf("xml")>=0,R=n?S.responseXML:S.responseText;if(n&&R.documentElement.nodeName==="parsererror"){b.error&&b.error("parsererror")}if(P&&P.dataFilter){R=P.dataFilter(R,Q)}if(typeof R==="string"){if(Q==="json"||!Q&&O.indexOf("json")>=0){R=q(R)}else{if(Q==="script"||!Q&&O.indexOf("javascript")>=0){b.globalEval(R)}}}return R}}};b.fn.ajaxForm=function(c){if(this.length===0){var d={s:this.selector,c:this.context};if(!b.isReady&&d.s){a("DOM not ready, queuing ajaxForm");b(function(){b(d.s,d.c).ajaxForm(c)});return this}a("terminating; zero elements found by selector"+(b.isReady?"":" (DOM not ready)"));return this}return this.ajaxFormUnbind().bind("submit.form-plugin",function(f){if(!f.isDefaultPrevented()){f.preventDefault();b(this).ajaxSubmit(c)}}).bind("click.form-plugin",function(l){var k=l.target;var g=b(k);if(!(g.is(":submit,input:image"))){var f=g.closest(":submit");if(f.length==0){return}k=f[0]}var j=this;j.clk=k;if(k.type=="image"){if(l.offsetX!=undefined){j.clk_x=l.offsetX;j.clk_y=l.offsetY}else{if(typeof b.fn.offset=="function"){var m=g.offset();j.clk_x=l.pageX-m.left;j.clk_y=l.pageY-m.top}else{j.clk_x=l.pageX-k.offsetLeft;j.clk_y=l.pageY-k.offsetTop}}}setTimeout(function(){j.clk=j.clk_x=j.clk_y=null},100)})};b.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};b.fn.formToArray=function(r){var q=[];if(this.length===0){return q}var d=this[0];var g=r?d.getElementsByTagName("*"):d.elements;if(!g){return q}var l,k,f,s,e,o,c;for(l=0,o=g.length;l<o;l++){e=g[l];f=e.name;if(!f){continue}if(r&&d.clk&&e.type=="image"){if(!e.disabled&&d.clk==e){q.push({name:f,value:b(e).val()});q.push({name:f+".x",value:d.clk_x},{name:f+".y",value:d.clk_y})}continue}s=b.fieldValue(e,true);if(s&&s.constructor==Array){for(k=0,c=s.length;k<c;k++){q.push({name:f,value:s[k]})}}else{if(s!==null&&typeof s!="undefined"){q.push({name:f,value:s})}}}if(!r&&d.clk){var m=b(d.clk),p=m[0];f=p.name;if(f&&!p.disabled&&p.type=="image"){q.push({name:f,value:m.val()});q.push({name:f+".x",value:d.clk_x},{name:f+".y",value:d.clk_y})}}return q};b.fn.formSerialize=function(c){return b.param(this.formToArray(c))};b.fn.fieldSerialize=function(d){var c=[];this.each(function(){var j=this.name;if(!j){return}var f=b.fieldValue(this,d);if(f&&f.constructor==Array){for(var g=0,e=f.length;g<e;g++){c.push({name:j,value:f[g]})}}else{if(f!==null&&typeof f!="undefined"){c.push({name:this.name,value:f})}}});return b.param(c)};b.fn.fieldValue=function(j){for(var g=[],e=0,c=this.length;e<c;e++){var f=this[e];var d=b.fieldValue(f,j);if(d===null||typeof d=="undefined"||(d.constructor==Array&&!d.length)){continue}d.constructor==Array?b.merge(g,d):g.push(d)}return g};b.fieldValue=function(c,k){var e=c.name,q=c.type,r=c.tagName.toLowerCase();if(k===undefined){k=true}if(k&&(!e||c.disabled||q=="reset"||q=="button"||(q=="checkbox"||q=="radio")&&!c.checked||(q=="submit"||q=="image")&&c.form&&c.form.clk!=c||r=="select"&&c.selectedIndex==-1)){return null}if(r=="select"){var l=c.selectedIndex;if(l<0){return null}var o=[],d=c.options;var g=(q=="select-one");var m=(g?l+1:d.length);for(var f=(g?l:0);f<m;f++){var j=d[f];if(j.selected){var p=j.value;if(!p){p=(j.attributes&&j.attributes.value&&!(j.attributes.value.specified))?j.text:j.value}if(g){return p}o.push(p)}}return o}return b(c).val()};b.fn.clearForm=function(){return this.each(function(){b("input,select,textarea",this).clearFields()})};b.fn.clearFields=b.fn.clearInputs=function(){return this.each(function(){var d=this.type,c=this.tagName.toLowerCase();if(d=="text"||d=="password"||c=="textarea"){this.value=""}else{if(d=="checkbox"||d=="radio"){this.checked=false}else{if(c=="select"){this.selectedIndex=-1}}}})};b.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset()}})};b.fn.enable=function(c){if(c===undefined){c=true}return this.each(function(){this.disabled=!c})};b.fn.selected=function(c){if(c===undefined){c=true}return this.each(function(){var d=this.type;if(d=="checkbox"||d=="radio"){this.checked=c}else{if(this.tagName.toLowerCase()=="option"){var e=b(this).parent("select");if(c&&e[0]&&e[0].type=="select-one"){e.find("option").selected(false)}this.selected=c}}})};function a(){if(b.fn.ajaxSubmit.debug){var c="[jquery.form] "+Array.prototype.join.call(arguments,"");if(window.console&&window.console.log){window.console.log(c)}else{if(window.opera&&window.opera.postError){window.opera.postError(c)}}}}})(jQuery);$.download=function(c,e,g,f){var a="";var b;var d;if(c&&e){if($("#iframeX")){$("#iframeX").remove()}b=$('<iframe src="[removed]false;" width="0" height="0" frameborder="0" name="iframeX" id="iframeX"></iframe>').appendTo("body").hide();if($.browser.msie){d=setInterval(function(){if(b&&b[0].readyState!="loading"){if(b[0].readyState=="complete"){f()}clearInterval(d)}},23)}else{b.load(function(){f()})}$.each(e,function(j,k){a+='<input type="hidden" name="'+j+'" value="'+k+'" />'});$('<form action="'+c+'" method='+(g||"post")+'" target="iframeX">'+a+"</form>").appendTo("body").submit().remove()}};(function(a){a.fn.splitter=function(b){b=b||{};return this.each(function(){var p;function k(u){if(c.outline){p=p||o.clone(false).insertAfter(g)}q.css("-webkit-user-select","none");o.addClass(c.activeClass);a('<div class="splitterMask"></div>').insertAfter(o);g._posSplit=g[0][c.pxSplit]-u[c.eventPos];a(document).bind("mousemove",m).bind("mouseup",s)}function m(u){var v=g._posSplit+u[c.eventPos];if(c.outline){v=Math.max(0,Math.min(v,d._DA-o._DA));o.css(c.origin,v)}else{n(v)}}function s(u){a("div.splitterMask").remove();o.removeClass(c.activeClass);var v=g._posSplit+u[c.eventPos];if(c.outline){p.remove();p=null;n(v)}q.css("-webkit-user-select","text");a(document).unbind("mousemove",m).unbind("mouseup",s)}function n(u){u=Math.max(g._min,d._DA-f._max,Math.min(u,g._max,d._DA-o._DA-f._min));o._DA=o[0][c.pxSplit];o.css(c.origin,u).css(c.fixed,d._DF);g.css(c.origin,0).css(c.split,u).css(c.fixed,d._DF);f.css(c.origin,u+o._DA).css(c.split,d._DA-o._DA-u).css(c.fixed,d._DF);if(!a.browser.msie){q.trigger("resize")}}function r(x,w){var v=0;for(var u=1;u<arguments.length;u++){v+=Math.max(parseInt(x.css(arguments[u]))||0,0)}return v}var l=(b.splitHorizontal?"h":b.splitVertical?"v":b.type)||"v";var c=a.extend({activeClass:"active",pxPerKey:8,tabIndex:0,accessKey:""},{v:{keyLeft:39,keyRight:37,cursor:"e-resize",splitbarClass:"vsplitbar",outlineClass:"voutline",type:"v",eventPos:"pageX",origin:"left",split:"width",pxSplit:"offsetWidth",side1:"Left",side2:"Right",fixed:"height",pxFixed:"offsetHeight",side3:"Top",side4:"Bottom"},h:{keyTop:40,keyBottom:38,cursor:"n-resize",splitbarClass:"hsplitbar",outlineClass:"houtline",type:"h",eventPos:"pageY",origin:"top",split:"height",pxSplit:"offsetHeight",side1:"Top",side2:"Bottom",fixed:"width",pxFixed:"offsetWidth",side3:"Left",side4:"Right"}}[l],b);var d=a(this).css({position:"relative"});var q=a(">*",d[0]).css({position:"absolute","z-index":"1","-moz-outline-style":"none"});var g=a(q[0]);var f=a(q[1]);var e=a('<a href="javascript:void(0)"></a>').attr({accessKey:c.accessKey,tabIndex:c.tabIndex,title:c.splitbarClass}).bind(a.browser.opera?"click":"focus",function(){this.focus();o.addClass(c.activeClass)}).bind("keydown",function(w){var v=w.which||w.keyCode;var u=v==c["key"+c.side1]?1:v==c["key"+c.side2]?-1:0;if(u){n(g[0][c.pxSplit]+u*c.pxPerKey,false)}}).bind("blur",function(){o.removeClass(c.activeClass)});var o=a(q[2]||"<div></div>").insertAfter(g).css("z-index","100").append(e).attr({"class":c.splitbarClass,unselectable:"on"}).css({position:"absolute","user-select":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none"}).bind("mousedown",k);if(/^(auto|default|)$/.test(o.css("cursor"))){o.css("cursor",c.cursor)}o._DA=o[0][c.pxSplit];d._PBF=a.boxModel?r(d,"border"+c.side3+"Width","border"+c.side4+"Width"):0;d._PBA=a.boxModel?r(d,"border"+c.side1+"Width","border"+c.side2+"Width"):0;g._pane=c.side1;f._pane=c.side2;a.each([g,f],function(){this._min=c["min"+this._pane]||r(this,"min-"+c.split);this._max=c["max"+this._pane]||r(this,"max-"+c.split)||9999;this._init=c["size"+this._pane]===true?parseInt(a.curCSS(this[0],c.split)):c["size"+this._pane]});var t=g._init;if(!isNaN(f._init)){t=d[0][c.pxSplit]-d._PBA-f._init-o._DA}if(c.cookie){if(!a.cookie){alert("jQuery.splitter(): jQuery cookie plugin required")}var j=parseInt(a.cookie(c.cookie));if(!isNaN(j)){t=j}a(window).bind("unload",function(){var u=String(o.css(c.origin));a.cookie(c.cookie,u,{expires:c.cookieExpires||365,path:c.cookiePath||document.location.pathname})})}if(isNaN(t)){t=Math.round((d[0][c.pxSplit]-d._PBA-o._DA)/2)}if(c.anchorToWindow){d._hadjust=r(d,"borderTopWidth","borderBottomWidth","marginBottom");d._hmin=Math.max(r(d,"minHeight"),20);a(window).bind("resize",function(){var v=d.offset().top;var u=a(window).height();d.css("height",Math.max(u-v-d._hadjust,d._hmin)+"px");if(!a.browser.msie){d.trigger("resize")}}).trigger("resize")}else{if(c.resizeToWidth&&!a.browser.msie){a(window).bind("resize",function(){d.trigger("resize")})}}d.bind("resize",function(v,u){if(v.target!=this){return}d._DF=d[0][c.pxFixed]-d._PBF;d._DA=d[0][c.pxSplit]-d._PBA;if(d._DF<=0||d._DA<=0){return}n(!isNaN(u)?u:(!(c.sizeRight||c.sizeBottom)?g[0][c.pxSplit]:d._DA-f[0][c.pxSplit]-o._DA))}).trigger("resize",[t])})}})(jQuery);(function(a){a.extend({add2cart:function(f,c,b,j){var d=a("#"+f);var e=a("#"+c);if(e.attr("id")){var g=a("#"+f+"_shadow");if(!g.attr("id")){a("body").prepend('<div id="'+d.attr("id")+'_shadow" style="display: none; background-color: '+b+'; border: solid 1px darkgray; position: static; top: 0px; z-index:100000">&nbsp;</div>');var g=a("#"+d.attr("id")+"_shadow")}g.width(d.css("width")).height(d.css("height")).css("top",d.offset().top).css("left",d.offset().left).css("opacity",0.5).show();g.css("position","absolute");g.animate({width:e.innerWidth(),height:e.innerHeight(),top:e.offset().top,left:e.offset().left},{duration:600}).animate({opacity:0},{duration:600,complete:j}).animate({opacity:0},200,function(){a(this).remove()})}}})})(jQuery);(function($){$.fn.extend({loadSQB:function(jsonstr){if(jsonstr!=""){var $tt=this[0];$("#sqlbuild_"+$tt.opts.reportid+" > p.sqlbuilderwhere > span.sqlwhere").remove();var j=eval("("+jsonstr+")");var wherediv=$("#9999_"+$tt.opts.reportid);for(var i=0;i<j.length;i++){if(j[i]!=null){wherediv[0].opts.onselect(j[i].columnslot,wherediv,{columnslot:j[i].columnslot,opslot:j[i].opslot,chainslot:j[i].chainslot,columnvalue:j[i].columnvalue})}}}}});var mouseX=0,mouseY=0;$().mousemove(function(e){mouseX=e.pageX;mouseY=e.pageY});$.fn.sqlsimplemenu=function(options){$.fn.sqlsimplemenu.defaults={menu:"kmenu",mtype:"menu",menuid:0,typefield:null,checkeditems:[],checkalltext:"Seleziona tutto",onselect:null,onselectclose:null,onselectablelist:null,oncheck:null,fields:[]};var opts=$.extend({},$.fn.sqlsimplemenu.defaults,options);function buildsimplemenu(){var mmenu="";if(opts.fields.length>0){for(var i=0;i<opts.fields.length;i++){if(opts.typefield==null||(opts.typefield!=null&&$.inArray(opts.typefield,opts.fields[i].ftype)!=-1)){mmenu=mmenu+'<li><a href="#'+opts.fields[i].id+'">'+opts.fields[i].name+"</a></li>"}}}return'<div id="'+opts.menu+'" class="sqlsimplemenu"><ul class="clickmenu">'+mmenu+"</ul></div>"}function buildselectboxmenu(){var mmenu="";if(opts.fields.length>0){for(var i=0;i<opts.fields.length;i++){mmenu=mmenu+'<li><input type="checkbox" '+($.inArray(opts.fields[i].id,opts.checkeditems)!=-1?" checked ":"")+'href="#'+(i+1)+'" id="'+opts.fields[i].id+'">'+opts.fields[i].name+"</li>"}}return'<div id="'+opts.menu+'" class="sqlsimplemenu"><ul class="clickmenu selectmenu">'+mmenu+"</ul></div>"}function buildtreeviewmenu(){return'<div id="'+opts.menu+'" class="wslink_tree sqlsimplemenu"></div>'}$("div.sqlbuild").click(function(e){var elemTarget=e.target||e.srcElement;if(!$(elemTarget).hasClass("expandNode")&&!$(elemTarget).hasClass("treecheckbox")&&!$(elemTarget).hasClass("treeNode")&&elemTarget.tagName.toLowerCase()!="li"){$("div.sqlsimplemenu").slideUp(200,function(){if(opts.onselectclose){opts.onselectclose($(this))}});e.stopPropagation();return false}});return this.each(function(){this.opts=opts;var sm=opts.mtype=="selectbox"?buildselectboxmenu():opts.mtype=="treeview"?buildtreeviewmenu():buildsimplemenu();$(document.body).after(sm);$("div#"+opts.menu).hide();$(this).click(function(e){var srcelement=$(this);e.stopPropagation();$("div.sqlsimplemenu").hide();if(!e.pageX){e.pageX=mouseX;e.pageY=mouseY}if(e.pageX==0&&$(this).attr("id")=="99"){var position=$("#99").offset();$("div#"+opts.menu).css({top:position.top-150,width:300,height:300,left:position.left-5,position:"absolute",overflow:"auto"}).slideToggle(200)}else{$("div#"+opts.menu).css({top:e.pageY+5,left:e.pageX+5,position:"absolute"}).slideToggle(200)}$("div#"+opts.menu).find("input[type=checkbox]").unbind("click").click(function(e){e.stopPropagation();if(opts.mtype=="selectbox"&&$(this).attr("href").substr(1)==0){$("div#"+opts.menu).find("input[type=checkbox]").attr("checked",$(this).attr("checked")?true:false)}else{$(this).attr("checked",$(this).attr("checked")?true:false)}var items=new Array();var k=0;$("div#"+opts.menu).find("input[type=checkbox]").each(function(){if(opts.mtype=="selectbox"&&$(this).attr("href").substr(1)!="0"){items[k]=($(this).attr("checked")?$(this).attr("id"):"");if($(this).attr("checked")){k++}}else{items[k]=($(this).attr("checked")?$(this).val():"");if($(this).attr("checked")){k++}}});if(k==0){items[0]=""}var items_str=items.join(",");if(items_str.substr(-1,1)==","){items_str=items_str.substr(0,items_str.length-1)}if(opts.onselect){if(opts.mtype=="selectbox"){opts.oncheck($(this).attr("href").substr(1),$(srcelement),$(this),items_str)}else{opts.oncheck($(this).val(),$(srcelement),$(this),items_str)}}});$("div#"+opts.menu).find("a").unbind("click").click(function(e){if(opts.mtype!="treeview"){var selitem=$(this);$("div#"+opts.menu).slideUp(200,function(){});if(opts.onselect){opts.onselect($(selitem).attr("href").substr(1),$(srcelement),null)}return false}});return false})})};$.fn.sqlquerybuilder=function(options){$.fn.sqlquerybuilder.defaults={reportid:0,counters:[0,0,0,0],sqldiv:null,presetlistdiv:null,reporthandler:null,datadiv:null,statusmsgdiv:null,whereinput:null,sortinput:null,groupinput:null,columninput:null,allinput:null,reportnameprompt:"Report name",reportnameinput:"type your report name here",columntitle:"Result columns ..",addnewcolumn:"[Click to a add new column]..",showcolumn:true,wheretitle:"Elenco filtri",addnewwhere:"Aggiungi un nuovo filtro",showwhere:true,sorttitle:"Sort columns by..",addnewsort:"[Click to a add new sort column]..",showsort:true,grouptitle:"Group columns by..",addnewgroup:"[Click to a add new group column]..",showgroup:true,deletetext:"",animate:true,onchange:null,onselectablelist:null,fields:[],joinrules:[],extrawhere:"",operators:[{id:0,name:"uguale",op:"%f='%s'",multipleval:false,ftype:["string","int","bool"]},{id:1,name:"diverso da",op:"%f!='%s'",multipleval:false,ftype:["string","int","bool"]},{id:2,name:"inizia con",op:"%f like '%s%'",multipleval:false,ftype:["string"]},{id:3,name:"non inizia con",op:"not(%f like '%s%')",multipleval:false,ftype:["string"]},{id:4,name:"contiene",op:"%f like '%%s%'",multipleval:false,ftype:["string"]},{id:5,name:"non contiene",op:"not(%f like '%%s%')",multipleval:false,ftype:["string"]},{id:6,name:"maggiore di",op:"%f>'%s'",multipleval:false,ftype:["string","int"]},{id:7,name:"maggiore o uguale",op:"%f>='%s'",multipleval:false,ftype:["string","int"]},{id:8,name:"minore di",op:"%f<'%s'",multipleval:false,ftype:["string","int"]},{id:9,name:"minore o uguale",op:"%f<='%s'",multipleval:false,ftype:["string","int"]},{id:10,name:"compreso",op:"%f between '%s1' and '%s2'",multipleval:true,info:"",ftype:["string","int"]},{id:11,name:"è in",op:"%f in (%s)",multipleval:false,selectablelist:true,info:"",ftype:["string","int","category","nation"]},{id:12,name:"non è in",op:"not(%f in (%s))",multipleval:false,selectablelist:true,info:"",ftype:["string","int","category","nation"]}],chain:[{id:0,name:" and ",op:" and "}],astagpre:'"',astagsuf:'"'};var opts=$.extend({},$.fn.sqlquerybuilder.defaults,options);var sqlwidget=$(this);var howmany=opts.amount;function addnewsqlwhere(){return"<label class='titlefilter'>"+opts.wheretitle+"</label><br/>"}function onchangeevent(type){if(opts.datadiv){var filter="";$("#sqlbuild_"+opts.reportid+" > p.sqlbuilderwhere > span.sqlwhere").each(function(){var col_slot=$(this).find("a.addnewsqlwhere").attr("href").substr(1);var op_slot=$(this).find("a.addnewsqlwhereoperator").attr("href").substr(1);var chain_slot=$(this).find("a.addnewsqlwherechain").attr("href").substr(1);var col_value=$(this).find("span.addnewsqlwherevalue").html();if((col_slot=="cat"&&col_value=="Categorie")||(col_slot=="naz"&&col_value=="Nazioni")){}else{var columndata='{columnslot:"'+col_slot+'",opslot:'+op_slot+",chainslot:"+chain_slot+',columnvalue:"'+col_value+'"},';filter=filter+columndata}});var data=filter!=""?"["+filter.substr(0,filter.length-1)+"]":"";opts.datadiv.val(data)}}return this.each(function(){this.opts=opts;var wheremarkup=addnewsqlwhere();var sqlbuildelement=$(this);$(this).html("<p class=sqlbuilderwhere>"+wheremarkup+'<a class="addnewsqlwhere newcondition" id="9999_'+opts.reportid+'" href="#">'+opts.addnewwhere+"</a></p>");$("[class*=addnewsqlwhere][id=9999_"+opts.reportid+"]").sqlsimplemenu({menu:"sqlmenulist_"+opts.reportid,fields:opts.fields,onselect:function(action,el,defval){var index=getIndex(action,true);var indexOperator=0;for(var i=0;i<opts.operators.length;i++){if($.inArray(opts.fields[index].ftype,opts.operators[i].ftype)!=-1){indexOperator=i;break}}var sqlline='<span class="sqlwhere" id="'+opts.counters[3]+"_"+opts.reportid+'"><a class="addnewsqlwheredelete" id="'+opts.counters[3]+"_"+opts.reportid+'" href="#'+opts.fields[index].id+'">'+opts.deletetext+'</a>&nbsp;<a class="addnewsqlwhere" id="'+opts.counters[3]+"_"+opts.reportid+'" href="#'+opts.fields[index].id+'">'+opts.fields[index].name+'</a>&nbsp;<a class="addnewsqlwhereoperator" id="'+opts.counters[3]+"_"+opts.reportid+'" href="#'+(defval?defval.opslot:opts.operators[indexOperator].id)+'">'+opts.operators[(defval?defval.opslot:indexOperator)].name+'</a>&nbsp;<span class="addnewsqlwherevalue" id="'+opts.counters[3]+"_"+opts.reportid+'" href="#0">'+(defval?defval.columnvalue:opts.fields[index].defaultval)+'</span>&nbsp;<a class="addnewsqlwherechain" id="'+opts.counters[3]+"_"+opts.reportid+'" href="#'+(defval?defval.chainslot:"0")+'">'+opts.chain[(defval?defval.chainslot:0)].name+"</a>&nbsp;</span>";var item=$(sqlline).hide();$("[class*=addnewsqlwhere][id=9999_"+opts.reportid+"]").before(item);if(opts.animate){$(item).animate({opacity:"show",height:"show"},150,"swing",function(){$(item).animate({height:"+=3px"},75,"swing",function(){$(item).animate({height:"-=3px"},50,"swing",function(){onchangeevent("new")})})})}else{$(item).show();onchangeevent("new")}$("span[class=addnewsqlwherevalue][id='"+opts.counters[3]+"_"+opts.reportid+"']").click(function(e){e.stopPropagation();var element=$(this);var operatorid=$("a[class=addnewsqlwhereoperator][id="+element.attr("id")+"]").attr("href").substr(1);var fieldid=$("a[class=addnewsqlwhere][id="+element.attr("id")+"]").attr("href").substr(1);var chainid=$("a[class=addnewsqlwherechain][id="+element.attr("id")+"]").attr("href").substr(1);var slotid=element.attr("id");if(element.hasClass("editing")||element.hasClass("disabled")){return}element.addClass("editing");var index=getIndex(fieldid,true);var oldhtml=$(this).html();hideHideble();if(opts.operators[operatorid].multipleval){$(this).html('<input type="text" class="editfield hideble" id=1> and <input type="text" class="editfield" id=2> <span class="sqlsyntaxhelp"></span>');$("#sqlbuild_"+opts.reportid).click(function(e){var elemTarget=e.target||e.srcElement;if($(elemTarget).attr("id")!="1"&&$(elemTarget).attr("id")!="2"){hideHideble()}});var vals=oldhtml.split("and");$("input[class*=editfield][id=1]").val(vals[0].replace(/^\s+|\s+$/g,""));$("input[class=editfield][id=2]").val(vals[1].replace(/^\s+|\s+$/g,""))}else{if(opts.fields[index].ftype=="bool"){$(this).html('<select class="editfield hideble" id=99><option value=0>falso</option><option value=1>vero</option></select>');$("#sqlbuild_"+opts.reportid).click(function(e){hideHideble()})}else{if(opts.fields[index].ftype=="category"||opts.fields[index].ftype=="nation"){$(this).html('<input type="text" class="editfield '+opts.fields[index].ftype+'" style="background:transparent;border:0px" id=99><span class="sqlsyntaxhelp"></span>')}else{$(this).html('<input type="text" class="editfield" id=99><span class="sqlsyntaxhelp"></span>')}}$(".editfield").val(oldhtml.replace(/^\s+|\s+$/g,""));if(opts.fields[index].ftype=="category"){if($("div#treeview"+slotid).length>0){$("div#treeview"+slotid).remove()}var editfield=$(this);$("input[class*=category][id=99]").sqlsimplemenu({menu:"treeview"+slotid,menuid:slotid,mtype:"treeview",oncheck:function(action,el,checkbox,checkitems){$(editfield).html(checkitems);onchangeevent("change")},onselect:function(action,el){$(editfield).htlm()}});$("#treeview"+slotid).wsTree({loadCall:"/Wizard/Site/Manipulation/loadStorePageBranch/",loadAllCall:"/Wizard/Site/Manipulation/loadStorePageTree/",loadChildrensCallWithType:true,checkboxes:true,checkboxesSingleSelection:false,acltypes:[],types:{store_page:{icon:"/Wizard/Web/common/img/common-store_root.png",color:"#e6f0fa",className:"store_page"}},afterbuild:function(){$("span#treeview"+slotid+"_node_0").find("input[type=checkbox]").hide();var checked=$("#99").val();if(checked!=null&&checked!=""){var farray=checked.split(",");for(h=0;h<farray.length;h++){$("span#treeview"+slotid+"_node_"+farray[h]).find("input[type=checkbox]").attr("checked",true)}}$("#99").click()}})}else{if(opts.fields[index].ftype=="nation"){if($("div#selectboxnation"+slotid).length>0){$("div#selectboxnation"+slotid).remove()}var nazioni=null;var nazioniChecked=$("#99").val().split(",");$.ajax({type:"POST",url:"/Wizard/GetNationList",data:null,async:false,dataType:"json",error:manageAsyncError,success:function(nation){nazioni=nation}});var editfield=$(this);$("input[class*=nation][id=99]").sqlsimplemenu({menu:"selectboxnation"+slotid,menuid:slotid,mtype:"selectbox",fields:nazioni,checkeditems:nazioniChecked,oncheck:function(action,el,checkbox,checkitems){$(editfield).html(checkitems);onchangeevent("change")},onselect:function(action,el){$(editfield).htlm()}});$("#99").click()}}}$(".sqlsyntaxhelp").html(opts.operators[operatorid].info);$(".editfield").blur(function(){closeEditField(this,element,false)});$(".editfield",element).keyup(function(event){if(event.which==13){closeEditField(this,element,false)}return true});$("input[class*=editfield][id="+(opts.operators[operatorid].multipleval?"1":"99")+"]").focus().select()});$("[class=addnewsqlwheredelete][id='"+opts.counters[3]+"_"+opts.reportid+"']").click(function(){var item=$("span[class=sqlwhere][id="+$(this).attr("id")+"]");if(opts.animate){$(item).animate({opacity:"hide",height:"hide"},150,"swing",function(){$(this).hide().remove();onchangeevent("change")})}else{$(item).hide().remove();onchangeevent("change")}});$("[class=addnewsqlwhere][id='"+opts.counters[3]+"_"+opts.reportid+"']").sqlsimplemenu({menu:"sqlmenulist_"+opts.counters[3]+"_"+opts.reportid,fields:opts.fields,onselect:function(action,el){var index=getIndex(action,true);$("[class=addnewsqlwhere][id="+$(el).attr("id")+"]").html(opts.fields[index].name).attr("href","#"+opts.fields[index].id);var operatore=$("[class=addnewsqlwhereoperator][id="+$(el).attr("id")+"]").html();var newoperatore=null;var opok=false;var mmenu="";if(opts.operators.length>0){for(var i=0;i<opts.operators.length;i++){if(opts.fields[index].ftype==null||(opts.fields[index].ftype!=null&&$.inArray(opts.fields[index].ftype,opts.operators[i].ftype)!=-1)){if(operatore==opts.operators[i].name){opok=true}mmenu=mmenu+'<li><a href="#'+opts.operators[i].id+'">'+opts.operators[i].name+"</a></li>";if(newoperatore==null){newoperatore=opts.operators[i].name}}}}var sm='<ul class="clickmenu">'+mmenu+"</ul>";$("div#operatorlist_"+$(el).attr("id")).html(sm);if(!opok){operatore=newoperatore;$("[class=addnewsqlwhereoperator][id="+$(el).attr("id")+"]").html(operatore)}var valore=$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html();if(valore!=null&&valore.indexOf(" and ")!=-1&&operatore!="compreso"){$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html(valore.replace(" and ",""))}onchangeevent("change")}});$("[class=addnewsqlwhereoperator][id='"+opts.counters[3]+"_"+opts.reportid+"']").sqlsimplemenu({menu:"operatorlist_"+opts.counters[3]+"_"+opts.reportid,fields:opts.operators,typefield:opts.fields[index].ftype,onselect:function(action,el){var index=getIndex(action,false);$("[class=addnewsqlwhereoperator][id="+$(el).attr("id")+"]").html(opts.operators[index].name).attr("href","#"+opts.operators[index].id);var val=$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html();if(val!=null){var farray=val.split(",");if((!opts.operators[index].selectablelist||opts.operators[index].multipleval)&&farray.length>1){val=farray[0];$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html(val)}if(opts.operators[index].multipleval){if(val.indexOf(" and ")==-1){$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html(val+" and "+val)}}else{if(val.indexOf("and")!=-1){var vals=val.split("and");$("[class=addnewsqlwherevalue][id="+$(el).attr("id")+"]").html(vals[0])}}}onchangeevent("change")}});opts.counters[3]++}})});function getIndex(valore,field){var list=field?opts.fields:opts.operators;var index=-1;for(var i=0;i<list.length;i++){if(list[i].id==valore){index=i;break}}return index}function hideHideble(){$(".hideble").each(function(){var element=$(this).parent();closeEditField(this,element,true)})}function closeEditField(edit,element,chiusura){switch($(edit).attr("id")){case"99":element.html($(edit).val().replace(/^\s+|\s+$/g,""));break;case"1":if(chiusura){element.html($("input[class*=editfield][id=1]").val().replace(/^\s+|\s+$/g,"")+" and "+$("input[class=editfield][id=2]").val().replace(/^\s+|\s+$/g,""))}else{return}break;case"2":element.html($("input[class*=editfield][id=1]").val().replace(/^\s+|\s+$/g,"")+" and "+$("input[class=editfield][id=2]").val().replace(/^\s+|\s+$/g,""));break}element.removeClass("editing");$(".sqlsyntaxhelp").remove();onchangeevent("change")}}})(jQuery);(function(a){a.fn.limitkeypress=function(b){var c={rexp:/^[-+]?\d*\.?\d*$/,numberRexp:null,typeRexp:[{name:"quantity",rexp:/^[1-9]\d{0,3}$/},{name:"quantityWZero",rexp:/^[0-9]\d{0,3}$/},{name:"discountMexal",rexp:/^(-\d*[\.\,]?[0-9]?[0-9]?)$|^([0-9][0-9]?([\.\,][0-9]?[0-9]?)?)$|^(1[0][0-9])$|^([0-9][0-9]?([\.\,][0-9]?[0-9]?)?([\+][0-9]?[0-9]?([\.\,][0-9]?[0-9]?)?){0,8})$/},{name:"integer",rexp:/^[1-9]\d*$/},{name:"decimalW2dec",rexp:/^\d+(\,\d{0,2})?$/}]};var b=a.extend(c,b);return this.each(function(){var f;var g=null;if(b.numberRexp!=null){f=b.typeRexp[b.numberRexp].rexp;g=b.typeRexp[b.numberRexp].name}else{f=b.rexp}a(this).blur(function(){j(this)});a(this).keypress(function(o){if((o.which=="0"&&o.keyCode!="38"&&o.keyCode!="40")||o.which=="8"||o.which=="13"||o.ctrlKey||o.altKey){return}d(this);var n=String.fromCharCode(o.which),p=this.value.substring(0,e(this))+n+this.value.substring(l(this),this.value.length);if(!f.test(p)){o.preventDefault();return}return});a(this).keydown(function(o){if((o.which=="0"&&o.keyCode!="38"&&o.keyCode!="40")||o.which=="8"||o.which=="13"||o.ctrlKey||o.altKey){return}d(this);if(g!=null&&(g=="quantity"||g=="quantityWZero")){var n=1;if(g=="quantityWZero"){n=0}if(o.keyCode=="38"){m("up",this,n)}if(o.keyCode=="40"){m("down",this,n)}}return});function d(u){var v=e(u),n=l(u),p="",t="",q=[];for(i=0;i<u.value.length;i++){if(v>i){q[i]="beforeSelection"}else{if((v<=i)&&(n>i)){q[i]="inSelection"}}}for(i=0;i<u.value.length;i++){var s=i+1;t+=u.value.substring(i,s);if((!f.test(t))){var r=t.length-1;p=t.substring(0,r);t=p;if(q[i]=="beforeSelection"){v=v-1;n=n-1}else{if(q[i]=="inSelection"){n=n-1}}}}u.value=t;k(u,v,n)}function j(s){var n="",r="";for(i=0;i<s.value.length;i++){var q=i+1;r+=s.value.substring(i,q);if((!f.test(r))){var p=r.length-1;n=r.substring(0,p);r=n}}s.value=r}function e(p){if(p.createTextRange){var n=document.selection.createRange().duplicate();n.moveEnd("character",p.value.length);if(n.text==""){return p.value.length}return p.value.lastIndexOf(n.text)}else{return p.selectionStart}}function l(p){if(p.createTextRange){var n=document.selection.createRange().duplicate();n.moveStart("character",-p.value.length);return n.text.length}else{return p.selectionEnd}}function k(o,p,q){if(o.setSelectionRange){o.focus();o.setSelectionRange(p,q)}else{if(o.createTextRange){var n=o.createTextRange();n.collapse(true);n.moveEnd("character",q);n.moveStart("character",p);n.select()}}}function m(n,r,q){var p=r.value==""?0:parseInt(r.value);switch(n){case"up":p=p+1;if(p>9999){p=9999}r.value=p;break;case"down":p=p-1;if(p<1){p=q}r.value=p;break;default:break}}})}})(jQuery);$(function(){$.extend($.support,{touch:"ontouchend" in document});$.fn.addTouch=function(){if($.support.touch){this.each(function(a,b){b.addEventListener("touchstart",iPadTouchHandler,false);b.addEventListener("touchmove",iPadTouchHandler,false);b.addEventListener("touchend",iPadTouchHandler,false);b.addEventListener("touchcancel",iPadTouchHandler,false)})}}});var lastTap=null;var tapValid=false;var tapTimeout=null;function cancelTap(){tapValid=false}var rightClickPending=false;var rightClickEvent=null;var holdTimeout=null;var cancelMouseUp=false;function cancelHold(){if(rightClickPending){window.clearTimeout(holdTimeout);rightClickPending=false;rightClickEvent=null}}function startHold(a){if(rightClickPending){return}rightClickPending=true;rightClickEvent=(a.changedTouches)[0];holdTimeout=window.setTimeout("doRightClick();",800)}function doRightClick(){rightClickPending=false;var b=rightClickEvent,a=document.createEvent("MouseEvent");a.initMouseEvent("mouseup",true,true,window,1,b.screenX,b.screenY,b.clientX,b.clientY,false,false,false,false,0,null);b.target.dispatchEvent(a);a=document.createEvent("MouseEvent");a.initMouseEvent("mousedown",true,true,window,1,b.screenX,b.screenY,b.clientX,b.clientY,false,false,false,false,2,null);b.target.dispatchEvent(a);a=document.createEvent("MouseEvent");a.initMouseEvent("contextmenu",true,true,window,1,b.screenX+50,b.screenY+5,b.clientX+50,b.clientY+5,false,false,false,false,2,null);b.target.dispatchEvent(a);cancelMouseUp=true;rightClickEvent=null}function iPadTouchStart(c){var d=c.changedTouches,e=d[0],a="mouseover",b=document.createEvent("MouseEvent");b.initMouseEvent(a,true,true,window,1,e.screenX,e.screenY,e.clientX,e.clientY,false,false,false,false,0,null);e.target.dispatchEvent(b);a="mousedown";b=document.createEvent("MouseEvent");b.initMouseEvent(a,true,true,window,1,e.screenX,e.screenY,e.clientX,e.clientY,false,false,false,false,0,null);e.target.dispatchEvent(b);if(!tapValid){lastTap=e.target;tapValid=true;tapTimeout=window.setTimeout("cancelTap();",600);startHold(c)}else{window.clearTimeout(tapTimeout);if(e.target==lastTap){lastTap=null;tapValid=false;a="click";b=document.createEvent("MouseEvent");b.initMouseEvent(a,true,true,window,1,e.screenX,e.screenY,e.clientX,e.clientY,false,false,false,false,0,null);e.target.dispatchEvent(b);a="dblclick";b=document.createEvent("MouseEvent");b.initMouseEvent(a,true,true,window,1,e.screenX,e.screenY,e.clientX,e.clientY,false,false,false,false,0,null);e.target.dispatchEvent(b)}else{lastTap=e.target;tapValid=true;tapTimeout=window.setTimeout("cancelTap();",600);startHold(c)}}}function iPadTouchHandler(d){var b="",a=0;if(d.touches.length>1){return}switch(d.type){case"touchstart":if($(d.changedTouches[0].target).is("select")){return}iPadTouchStart(d);d.preventDefault();return false;break;case"touchmove":cancelHold();b="mousemove";d.preventDefault();break;case"touchend":if(cancelMouseUp){cancelMouseUp=false;d.preventDefault();return false}cancelHold();b="mouseup";break;default:return}var e=d.changedTouches,f=e[0],c=document.createEvent("MouseEvent");c.initMouseEvent(b,true,true,window,1,f.screenX,f.screenY,f.clientX,f.clientY,false,false,false,false,a,null);f.target.dispatchEvent(c);if(b=="mouseup"&&tapValid&&f.target==lastTap){c=document.createEvent("MouseEvent");c.initMouseEvent("click",true,true,window,1,f.screenX,f.screenY,f.clientX,f.clientY,false,false,false,false,a,null);f.target.dispatchEvent(c)}};
