var scrawl=function(a){a&&this.initOptions(a)};(function(){var a=$G("J_brushBoard"),c=a.getContext("2d"),b=[],d=0;scrawl.prototype={isScrawl:false,brushWidth:-1,brushColor:"",initOptions:function(e){var f=this;f.originalState(e);f._buildToolbarColor(e.colorList);f._addBoardListener(e.saveNum);f._addOPerateListener(e.saveNum);f._addColorBarListener();f._addBrushBarListener();f._addEraserBarListener();f._addAddImgListener();f._addRemoveImgListenter();f._addScalePicListenter();f._addClearSelectionListenter();f._originalColorSelect(e.drawBrushColor);f._originalBrushSelect(e.drawBrushSize);f._clearSelection()},originalState:function(e){var f=this;f.brushWidth=e.drawBrushSize;f.brushColor=e.drawBrushColor;c.lineWidth=f.brushWidth;c.strokeStyle=f.brushColor;c.fillStyle="transparent";c.lineCap="round";c.fill()},_buildToolbarColor:function(j){var h=null,e=[];e.push("");for(var g=0,f;f=j[g++];){if((g-1)%5==0){if(g!=1){e.push("")}e.push("")}h="#"+f;e.push("")}e.push("
");$G("J_colorBar").innerHTML=e.join("")},_addBoardListener:function(n){var m=this,g=0,j=-1,h=-1,f=false,l=false,o=false,e=0,i,k="";g=parseInt(domUtils.getComputedStyle($G("J_wrap"),"margin-left"));b.push(c.getImageData(0,0,c.canvas.width,c.canvas.height));d+=1;domUtils.on(a,["mousedown","mousemove","mouseup","mouseout"],function(r){i=browser.webkit?r.which:e;switch(r.type){case"mousedown":e=1;k=1;f=true;o=false;l=false;m.isScrawl=true;j=r.clientX-g;h=r.clientY-g;c.beginPath();break;case"mousemove":if(!k&&i==0){return}if(!k&&i){j=r.clientX-g;h=r.clientY-g;c.beginPath();k=1}if(o||!f){return}var q=r.clientX-g,p=r.clientY-g;c.moveTo(j,h);c.lineTo(q,p);c.stroke();j=q;h=p;l=true;break;case"mouseup":e=0;if(!f){return}if(!l){c.arc(j,h,c.lineWidth,0,Math.PI*2,false);c.fillStyle=c.strokeStyle;c.fill()}c.closePath();m._saveOPerate(n);f=false;l=false;o=true;j=-1;h=-1;break;case"mouseout":k="";e=0;if(i==1){return}c.closePath();break}})},_addOPerateListener:function(f){var e=this;domUtils.on($G("J_previousStep"),"click",function(){if(d>1){d-=1;c.clearRect(0,0,c.canvas.width,c.canvas.height);c.putImageData(b[d-1],0,0)}});domUtils.on($G("J_nextStep"),"click",function(){if(d>0&&d")}h.innerHTML=d.join("");return h}var c=[[1,1,-1,-1],[0,1,0,-1],[0,1,1,-1],[1,0,-1,0],[0,0,1,0],[1,0,-1,1],[0,0,0,1],[0,0,1,1]];ScaleBoy.prototype={init:function(){b();var d=this,e=d.dom=a();d.scaleMousemove.fp=d;domUtils.on(e,"mousedown",function(g){var f=g.target||g.srcElement;d.start={x:g.clientX,y:g.clientY};if(f.className.indexOf("hand")!=-1){d.dir=f.className.replace("hand","")}domUtils.on(document.body,"mousemove",d.scaleMousemove);g.stopPropagation?g.stopPropagation():g.cancelBubble=true});domUtils.on(document.body,"mouseup",function(f){if(d.start){domUtils.un(document.body,"mousemove",d.scaleMousemove);if(d.moved){d.updateScaledElement({position:{x:e.style.left,y:e.style.top},size:{w:e.style.width,h:e.style.height}})}delete d.start;delete d.moved;delete d.dir}});return e},startScale:function(e){var d=this,f=d.dom;f.style.cssText="visibility:visible;top:"+e.style.top+";left:"+e.style.left+";width:"+e.offsetWidth+"px;height:"+e.offsetHeight+"px;";d.scalingElement=e},updateScaledElement:function(d){var f=this.scalingElement,g=d.position,e=d.size;if(g){typeof g.x!="undefined"&&(f.style.left=g.x);typeof g.y!="undefined"&&(f.style.top=g.y)}if(e){e.w&&(f.style.width=e.w);e.h&&(f.style.height=e.h)}},updateStyleByDir:function(d,h){var f=this,g=f.dom,e;c.def=[1,1,0,0];if(c[d][0]!=0){e=parseInt(g.style.left)+h.x;g.style.left=f._validScaledProp("left",e)+"px"}if(c[d][1]!=0){e=parseInt(g.style.top)+h.y;g.style.top=f._validScaledProp("top",e)+"px"}if(c[d][2]!=0){e=g.clientWidth+c[d][2]*h.x;g.style.width=f._validScaledProp("width",e)+"px"}if(c[d][3]!=0){e=g.clientHeight+c[d][3]*h.y;g.style.height=f._validScaledProp("height",e)+"px"}if(d==="def"){f.updateScaledElement({position:{x:g.style.left,y:g.style.top}})}},scaleMousemove:function(g){var f=arguments.callee.fp,i=f.start,d=f.dir||"def",h={x:g.clientX-i.x,y:g.clientY-i.y};f.updateStyleByDir(d,h);arguments.callee.fp.start={x:g.clientX,y:g.clientY};arguments.callee.fp.moved=1},_validScaledProp:function(g,f){var e=this.dom,d=$G("J_picBoard");f=isNaN(f)?0:f;switch(g){case"left":return f<0?0:(f+e.clientWidth)>d.clientWidth?d.clientWidth-e.clientWidth:f;case"top":return f<0?0:(f+e.clientHeight)>d.clientHeight?d.clientHeight-e.clientHeight:f;case"width":return f<=0?1:(f+e.offsetLeft)>d.clientWidth?d.clientWidth-e.offsetLeft:f;case"height":return f<=0?1:(f+e.offsetTop)>d.clientHeight?d.clientHeight-e.offsetTop:f}}}})();function ue_callback(b,d){var e=document,c=$G("J_picBoard"),a=e.createElement("img");function f(j,l,o,h){var g=0,n=0,k,i=j.width||o,m=j.height||h;if(i>l||m>l){if(i>=m){if(g=i-l){k=(g/i).toFixed(2);j.height=m-m*k;j.width=l}}else{if(n=m-l){k=(n/m).toFixed(2);j.width=i-i*k;j.height=l}}}}removeMaskLayer();if(d=="SUCCESS"){c.innerHTML="";a.onload=function(){f(this,300);c.appendChild(a);var g=new scrawl()};a.src=b}else{alert(d)}}function removeMaskLayer(){var a=$G("J_maskLayer");a.className="maskLayerNull";a.innerHTML="";dialog.buttons[0].setDisabled(false)}function addMaskLayer(a){var b=$G("J_maskLayer");dialog.buttons[0].setDisabled(true);b.className="maskLayer";b.innerHTML=a}function exec(scrawlObj){if(scrawlObj.isScrawl){addMaskLayer(lang.scrawlUpLoading);var base64=scrawlObj.getCanvasData();if(!!base64){var options={timeout:100000,onsuccess:function(xhr){if(!scrawlObj.isCancelScrawl){var responseObj;responseObj=eval("("+xhr.responseText+")");if(responseObj.state=="SUCCESS"){var imgObj={},url=editor.options.scrawlUrlPrefix+responseObj.url;imgObj.src=url;imgObj._src=url;imgObj.alt=responseObj.original||"";editor.execCommand("insertImage",imgObj);dialog.close()}else{alert(responseObj.state)}}},onerror:function(){alert(lang.imageError);dialog.close()}};options[editor.getOpt("scrawlFieldName")]=base64;var actionUrl=editor.getActionUrl(editor.getOpt("scrawlActionName")),params=utils.serializeParam(editor.queryCommandValue("serverparam"))||"",url=utils.formatUrl(actionUrl+(actionUrl.indexOf("?")==-1?"?":"&")+params);ajax.request(url,options)}}else{addMaskLayer(lang.noScarwl+"   ")}};