(function(n){function f(){return n("<div/>")}var u=Math.abs,i=Math.max,r=Math.min,t=Math.round;n.imgAreaSelect=function(e,o){function kt(n){return n+rt.left-ct.left}function dt(n){return n+rt.top-ct.top}function st(n){return n-rt.left+ct.left}function ht(n){return n-rt.top+ct.top}function ui(n){return n.pageX-ct.left}function fi(n){return n.pageY-ct.top}function ot(n){var i=n||ni,r=n||ti;return{x1:t(s.x1*i),y1:t(s.y1*r),x2:t(s.x2*i),y2:t(s.y2*r),width:t(s.x2*i)-t(s.x1*i),height:t(s.y2*r)-t(s.y1*r)}}function ir(n,i,r,u,f){var e=f||ni,o=f||ti;s={x1:t(n/e||0),y1:t(i/o||0),x2:t(r/e||0),y2:t(u/o||0)};s.width=s.x2-s.x1;s.height=s.y2-s.y1}function vt(){si&&g.width()&&(rt={left:t(g.offset().left),top:t(g.offset().top)},nt=g.innerWidth(),d=g.innerHeight(),rt.top+=g.outerHeight()-d>>1,rt.left+=g.outerWidth()-nt>>1,ii=t(o.minWidth/ni)||0,ri=t(o.minHeight/ti)||0,di=t(r(o.maxWidth/ni||16777216,nt)),gi=t(r(o.maxHeight/ti||16777216,d)),n().jquery!="1.3.2"||ci!="fixed"||nr.getBoundingClientRect||(rt.top+=i(document.body.scrollTop,nr.scrollTop),rt.left+=i(document.body.scrollLeft,nr.scrollLeft)),ct=/absolute|relative/.test(wt.css("position"))?{left:t(wt.offset().left)-wt.scrollLeft(),top:t(wt.offset().top)-wt.scrollTop()}:ci=="fixed"?{left:n(document).scrollLeft(),top:n(document).scrollTop()}:{left:0,top:0},w=kt(0),b=dt(0),(s.x2>nt||s.y2>d)&&yi())}function vi(t){if(li){v.css({left:kt(s.x1),top:dt(s.y1)}).add(pt).width(et=s.width).height(at=s.height);pt.add(k).add(p).css({left:0,top:0});k.width(i(et-k.outerWidth()+k.innerWidth(),0)).height(i(at-k.outerHeight()+k.innerHeight(),0));n(y[0]).css({left:w,top:b,width:s.x1,height:d});n(y[1]).css({left:w+s.x1,top:b,width:et,height:s.y1});n(y[2]).css({left:w+s.x2,top:b,width:nt-s.x2,height:d});n(y[3]).css({left:w+s.x1,top:b+s.y2,width:et,height:d-s.y2});et-=p.outerWidth();at-=p.outerHeight();switch(p.length){case 8:n(p[4]).css({left:et>>1});n(p[5]).css({left:et,top:at>>1});n(p[6]).css({left:et>>1,top:at});n(p[7]).css({top:at>>1});case 4:p.slice(1,3).css({left:et});p.slice(2,4).css({top:at})}t!==!1&&(n.imgAreaSelect.onKeyPress!=pr&&n(document).unbind(n.imgAreaSelect.keyPress,n.imgAreaSelect.onKeyPress),o.keys&&n(document)[n.imgAreaSelect.keyPress](n.imgAreaSelect.onKeyPress=pr));gt&&k.outerWidth()-k.innerWidth()==2&&(k.css("margin",0),setTimeout(function(){k.css("margin","auto")},0))}}function rr(n){vt();vi(n);h=kt(s.x1);c=dt(s.y1);l=kt(s.x2);a=dt(s.y2)}function ur(n,t){o.fadeSpeed?n.fadeOut(o.fadeSpeed,t):n.hide()}function yt(n){var t=st(ui(n))-s.x1,i=ht(fi(n))-s.y1;if(!tr){vt();tr=!0;v.one("mouseout",function(){tr=!1})}tt="";o.resizable&&(i<=o.resizeMargin?tt="n":i>=s.height-o.resizeMargin&&(tt="s"),t<=o.resizeMargin?tt+="w":t>=s.width-o.resizeMargin&&(tt+="e"));v.css("cursor",tt?tt+"-resize":o.movable?"move":"");hi&&hi.toggle()}function hr(){n("body").css("cursor","");(o.autoHide||s.width*s.height==0)&&ur(v.add(y),function(){n(this).hide()});n(document).unbind("mousemove",fr);v.mousemove(yt);o.onSelectEnd(e,ot())}function cr(t){if(t.which!=1)return!1;if(vt(),tt){n("body").css("cursor",tt+"-resize");h=kt(s[/w/.test(tt)?"x2":"x1"]);c=dt(s[/n/.test(tt)?"y2":"y1"]);n(document).mousemove(fr).one("mouseup",hr);v.unbind("mousemove",yt)}else if(o.movable){bi=w+s.x1-ui(t);ki=b+s.y1-fi(t);v.unbind("mousemove",yt);n(document).mousemove(lr).one("mouseup",function(){o.onSelectEnd(e,ot());n(document).unbind("mousemove",lr);v.mousemove(yt)})}else g.mousedown(t);return!1}function ei(n){ft&&(n?(l=i(w,r(w+nt,h+u(a-c)*ft*(l>h||-1))),a=t(i(b,r(b+d,c+u(l-h)/ft*(a>c||-1)))),l=t(l)):(a=i(b,r(b+d,c+u(l-h)/ft*(a>c||-1))),l=t(i(w,r(w+nt,h+u(a-c)*ft*(l>h||-1)))),a=t(a)))}function yi(){h=r(h,w+nt);c=r(c,b+d);u(l-h)<ii&&(l=h-ii*(l<h||-1),l<w?h=w+ii:l>w+nt&&(h=w+nt-ii));u(a-c)<ri&&(a=c-ri*(a<c||-1),a<b?c=b+ri:a>b+d&&(c=b+d-ri));l=i(w,r(l,w+nt));a=i(b,r(a,b+d));ei(u(l-h)<u(a-c)*ft);u(l-h)>di&&(l=h-di*(l<h||-1),ei());u(a-c)>gi&&(a=c-gi*(a<c||-1),ei(!0));s={x1:st(r(h,l)),x2:st(i(h,l)),y1:ht(r(c,a)),y2:ht(i(c,a)),width:u(l-h),height:u(a-c)};vi();o.onSelectChange(e,ot())}function fr(n){return l=/w|e|^$/.test(tt)||ft?ui(n):kt(s.x2),a=/n|s|^$/.test(tt)||ft?fi(n):dt(s.y2),yi(),!1}function oi(t,i){l=(h=t)+s.width;a=(c=i)+s.height;n.extend(s,{x1:st(h),y1:ht(c),x2:st(l),y2:ht(a)});vi();o.onSelectChange(e,ot())}function lr(n){return h=i(w,r(bi+ui(n),w+nt-s.width)),c=i(b,r(ki+fi(n),b+d-s.height)),oi(h,c),n.preventDefault(),!1}function er(){n(document).unbind("mousemove",er);vt();l=h;a=c;yi();tt="";y.is(":visible")||v.add(y).hide().fadeIn(o.fadeSpeed||0);li=!0;n(document).unbind("mouseup",pi).mousemove(fr).one("mouseup",hr);v.unbind("mousemove",yt);o.onSelectStart(e,ot())}function pi(){if(n(document).unbind("mousemove",er).unbind("mouseup",pi),ur(v.add(y)),ir(st(h),ht(c),st(h),ht(c)),!(this instanceof n.imgAreaSelect)){o.onSelectChange(e,ot());o.onSelectEnd(e,ot())}}function ar(t){return t.which!=1||y.is(":animated")?!1:(vt(),bi=h=ui(t),ki=c=fi(t),n(document).mousemove(er).mouseup(pi),!1)}function vr(){rr(!1)}function yr(){si=!0;or(o=n.extend({classPrefix:"imgareaselect",movable:!0,parent:"body",resizable:!0,resizeMargin:10,onInit:function(){},onSelectStart:function(){},onSelectChange:function(){},onSelectEnd:function(){}},o));v.add(y).css({visibility:""});o.show&&(li=!0,vt(),vi(),v.add(y).hide().fadeIn(o.fadeSpeed||0));setTimeout(function(){o.onInit(e,ot())},0)}function wi(n,t){for(var i in t)o[i]!==undefined&&n.css(t[i],o[i])}function or(t){if(t.parent&&(wt=n(t.parent)).append(v.add(y)),n.extend(o,t),vt(),t.handles!=null){for(p.remove(),p=n([]),bt=t.handles?t.handles=="corners"?4:8:0;bt--;)p=p.add(f());p.addClass(o.classPrefix+"-handle").css({position:"absolute",fontSize:0,zIndex:ut+1||1});!parseInt(p.css("width"))>=0&&p.width(5).height(5);(it=o.borderWidth)&&p.css({borderWidth:it,borderStyle:"solid"});wi(p,{borderColor1:"border-color",borderColor2:"background-color",borderOpacity:"opacity"})}for(ni=o.imageWidth/nt||1,ti=o.imageHeight/d||1,t.x1!=null&&(ir(t.x1,t.y1,t.x2,t.y2),t.show=!t.hide),t.keys&&(o.keys=n.extend({shift:1,ctrl:"resize"},t.keys)),y.addClass(o.classPrefix+"-outer"),pt.addClass(o.classPrefix+"-selection"),bt=0;bt++<4;)n(k[bt-1]).addClass(o.classPrefix+"-border"+bt);wi(pt,{selectionColor:"background-color",selectionOpacity:"opacity"});wi(k,{borderOpacity:"opacity",borderWidth:"border-width"});wi(y,{outerColor:"background-color",outerOpacity:"opacity"});(it=o.borderColor1)&&n(k[0]).css({borderStyle:"solid",borderColor:it});(it=o.borderColor2)&&n(k[1]).css({borderStyle:"dashed",borderColor:it});v.append(pt.add(k).add(hi)).append(p);gt&&((it=(y.css("filter")||"").match(/opacity=(\d+)/))&&y.css("opacity",it[1]/100),(it=(k.css("filter")||"").match(/opacity=(\d+)/))&&k.css("opacity",it[1]/100));t.hide?ur(v.add(y)):t.show&&si&&(li=!0,v.add(y).fadeIn(o.fadeSpeed||0),rr());ft=(sr=(o.aspectRatio||"").split(/:/))[0]/sr[1];g.add(y).unbind("mousedown",ar);o.disable||o.enable===!1?(v.unbind("mousemove",yt).unbind("mousedown",cr),n(window).unbind("resize",vr)):((o.enable||o.disable===!1)&&((o.resizable||o.movable)&&v.mousemove(yt).mousedown(cr),n(window).resize(vr)),o.persistent||g.add(y).mousedown(ar));o.enable=o.disable=undefined}var g=n(e),si,v=f(),pt=f(),k=f().add(f()).add(f()).add(f()),y=f().add(f()).add(f()).add(f()),p=n([]),hi,w,b,rt={left:0,top:0},nt,d,wt,ct={left:0,top:0},ut=0,ci="absolute",bi,ki,ni,ti,tt,ii,ri,di,gi,ft,li,h,c,l,a,s={x1:0,y1:0,x2:0,y2:0,width:0,height:0},nr=document.documentElement,ai=navigator.userAgent,lt,sr,bt,it,et,at,tr,pr=function(n){var t=o.keys,u,f,e=n.keyCode;if(u=!isNaN(t.alt)&&(n.altKey||n.originalEvent.altKey)?t.alt:!isNaN(t.ctrl)&&n.ctrlKey?t.ctrl:!isNaN(t.shift)&&n.shiftKey?t.shift:isNaN(t.arrows)?10:t.arrows,t.arrows=="resize"||t.shift=="resize"&&n.shiftKey||t.ctrl=="resize"&&n.ctrlKey||t.alt=="resize"&&(n.altKey||n.originalEvent.altKey)){switch(e){case 37:u=-u;case 39:f=i(h,l);h=r(h,l);l=i(f+u,h);ei();break;case 38:u=-u;case 40:f=i(c,a);c=r(c,a);a=i(f+u,c);ei(!0);break;default:return}yi()}else{h=r(h,l);c=r(c,a);switch(e){case 37:oi(i(h-u,w),c);break;case 38:oi(h,i(c-u,b));break;case 39:oi(h+r(u,nt-st(l)),c);break;case 40:oi(h,c+r(u,d-ht(a)));break;default:return}}return!1};this.remove=function(){or({disable:!0});v.add(y).remove()};this.getOptions=function(){return o};this.setOptions=or;this.getSelection=ot;this.setSelection=ir;this.cancelSelection=pi;this.update=rr;var gt=(/msie ([\w.]+)/i.exec(ai)||[])[1],wr=/opera/i.test(ai),br=/webkit/i.test(ai)&&!/chrome/i.test(ai);for(lt=g;lt.length;)ut=i(ut,isNaN(lt.css("z-index"))?ut:lt.css("z-index")),lt.css("position")=="fixed"&&(ci="fixed"),lt=lt.parent(":not(body)");ut=o.zIndex||ut;gt&&g.attr("unselectable","on");n.imgAreaSelect.keyPress=gt||br?"keydown":"keypress";wr&&(hi=f().css({width:"100%",height:"100%",position:"absolute",zIndex:ut+2||2}));v.add(y).css({visibility:"hidden",position:ci,overflow:"hidden",zIndex:ut||"0"});v.css({zIndex:ut+2||2});pt.add(k).css({position:"absolute",fontSize:0});e.complete||e.readyState=="complete"||!g.is("img")?yr():g.one("load",yr);!si&&gt&&gt>=7&&(e.src=e.src)};n.fn.imgAreaSelect=function(t){return(t=t||{},this.each(function(){n(this).data("imgAreaSelect")?t.remove?(n(this).data("imgAreaSelect").remove(),n(this).removeData("imgAreaSelect")):n(this).data("imgAreaSelect").setOptions(t):t.remove||(t.enable===undefined&&t.disable===undefined&&(t.enable=!0),n(this).data("imgAreaSelect",new n.imgAreaSelect(this,t)))}),t.instance)?n(this).data("imgAreaSelect"):this}})(jQuery),function(n){n.imageCanvasCropper=function(t,i){function v(){u=new Image;u.onload=y;u.src=h.result}function y(){r.width=u.width;r.height=u.height;var t=r.getContext("2d");t.drawImage(u,0,0);n(r).imgAreaSelect({handles:!0,onSelectEnd:function(t,i){if(i.width&&i.height){var f=u.width/n(r).width(),e=i.x1*f,o=i.y1*f,s=i.width*f,h=i.height*f;a(e,o,s,h,i.width,i.height)}}});i.constrainCropper&&n(r).imgAreaSelect({aspectRatio:i.width+":"+i.height});a(0,0,u.width,u.height,u.width,u.height)}function a(t,r,e,o,s,h){var c=f.getContext("2d");c.clearRect(0,0,i.width,i.height);i.drawBackground&&(c.fillStyle=i.backgroundColor,c.fillRect(0,0,i.width,i.height));var v=0,y=0,l=i.width,a=i.height;i.width/i.height>s/h?(l=s/(h/i.height),v=Math.floor((i.width-l)/2)):i.width/i.height<s/h&&(a=h/(s/i.width),y=Math.floor((i.height-a)/2));c.drawImage(u,t,r,e,o,v,y,l,a);i.hiddenInput&&n(i.hiddenInput).val(f.toDataURL())}function p(t){n.extend(i,t)}var c,o,r,s,f,e,l,h,u;if(typeof FileReader!="function"){console.log("jQuery imageCanvasCropper fatal error: FileReader not supported in your browser!");return}c=n(t);o=document.createElement("label");o.textContent=i.cropperHeading!==undefined?i.cropperHeading:"Draw a rectangle to crop";r=document.createElement("canvas");r.className="cropper-interface";s=document.createElement("label");s.textContent=i.resultHeading!==undefined?i.resultHeading:"Resulting crop:";f=document.createElement("canvas");f.className="cropper-result";f.width=i.width;f.height=i.height;e=document.createElement("div");i.startHidden===!0&&(e.style.display="none");c.after(e);n(e).append(o,r,s,f);c.change(function(){n(e).is(":hidden")&&n(e).slideDown();n(r).imgAreaSelect({remove:!0});l=this.files[0];h=new FileReader;h.onload=v;h.readAsDataURL(l)});this.destroy=function(){n(r).imgAreaSelect({remove:!0});n(o).remove();n(r).remove();n(s).remove();n(f).remove()};this.getOptions=function(){return i};this.setOptions=p};n.fn.imageCanvasCropper=function(t){return(t=t||{},this.each(function(){n(this).data("imageCanvasCropper")?t.remove?(n(this).data("imageCanvasCropper").destroy(),n(this).removeData("imageCanvasCropper")):n(this).data("imageCanvasCropper").setOptions(t):t.remove||(t.enable===undefined&&t.disable===undefined&&(t.enable=!0),n(this).data("imageCanvasCropper",new n.imageCanvasCropper(this,t)))}),t.instance)?n(this).data("imageCanvasCropper"):this}}(jQuery),function(n,t){function i(n){n.imageCanvasCropper({width:300,height:55,cropperHeading:"Draw a rectangle to crop the signature.",drawBackground:!0,backgroundColor:"#FFF",hiddenInput:n.siblings('input[type="hidden"]').first(),startHidden:!0})}function r(n){n.imageCanvasCropper({remove:!0})}t('input[type="file"].signature-fileupload').each(function(){i(t(this))});t(document).on("dynamicCollectionAdded","li",function(n){i(t(n.target).find('input[type="file"].signature-fileupload'))});t(document).on("dynamicCollectionDeleted","li",function(n){r(t(n.target).find('input[type="file"].signature-fileupload'))})}(window,jQuery)