﻿var Editor={value:"",textarea:"",width:"730",height:"370",iframe:"",imgPath:"http://cache.soso.com/baike/i/",formateLayerUrl:"http://baike.soso.com/cache/FormatLayerNew.html",uploadPicUrl:"UploadPicBySelectNew.htm",editorInCss:"http://cache.soso.com/baike/css/editorIn_4.css",charHtmlUrl:"http://baike.soso.com/cache/CharNew.html",parseUrl:"/api/util/filter",loadingImg:"http://cache.soso.com/baike/i/imgLoading.gif",captureUploadUrl:"z/CaptureUploadPic",captureActiveX:null,editor_blankUrl:"http://baike.soso.com/cache/editor_blank.html",message:"\u6700\u591a\u8f93\u5165<b>30000</b>\u5b57",nodeTimer:null,formatTipsId:"formatTips",titleTipsId:"titleTips",pictureTipsId:"pictureTips",invalidNode:["A","SCRIPT","FORM","INPUT","FONT","IFRAME","STYLE","OBJECT","EMBED"],specialChar:"&nbsp;|&lt;|&gt;|&amp;",ieSelection:null,onBeforeClose:null,stopNodeChange:false,ie:Zhishi.Browser.isIE,fireFox:Zhishi.Browser.isFireFox,startTime:null,toolBar:{baike:[{type:"normal",label:"\u64a4\u9500",value:"Undo"},{type:"normal",label:"\u91cd\u505a",value:"Redo"},{type:"separator"},{type:"extend",label:"\u52a0\u7c97",value:"Bold"},{type:"extend",label:"\u659c\u4f53",value:"Italic"},{type:"separator"},{type:"normal",label:"\u6bb5\u843d\u6807\u9898",value:"Title",hasText:true},{type:"normal",label:"\u7279\u6b8a\u5b57\u7b26",value:"Char",hasText:true},{type:"normal",label:"\u63d2\u5165/\u4fee\u6539\u56fe\u7247",value:"Image",hasText:true},{type:"normal",label:"\u622a\u5c4f",value:"Capture",hasText:true,isIE:true},{type:"separator"},{type:"normal",label:"\u5e2e\u4f60\u81ea\u52a8\u68c0\u67e5\u683c\u5f0f\u95ee\u9898",value:"Formate",hasText2:true},{type:"normal",label:"\u5167\u90e8\u8bcd\u6761\u94fe\u63a5",value:"InnerLink",hasText:true}]},count:{b_undo:0,b_redo:0,b_bold:0,b_italic:0,b_title:0,b_char:0,b_char_suc:0,b_img:0,b_img_suc:0,b_format:0,b_add:0,b_plus:0,b_link:0,b_capture:0,b_capture_suc:0,k_z:0,k_y:0,k_b:0,k_i:0,k_v:0,k_c:0,k_x:0,right_click:0},keyMaps:{CTRL_B:1000+66,CTRL_I:1000+73,CTRL_U:1000+85,CTRL_L:1000+76,CTRL_K:1000+75,CTRL_Z:1000+90,CTRL_Y:1000+89,CTRL_V:1000+86,CTRL_X:1000+88,CTRL_C:1000+67},init:function(d,a){this.textarea=get(d);for(var b in a){Editor[b]=a[b]}this.createUI();if(!Zhishi.Browser.isIE){Zhishi.Event.attachEventListener(Editor.getWindow(),"load",Editor.initEvent.bind(this));Editor.Image.addEvent()}this.setToolTip(Editor.message);try{this.getDoc().execCommand("BackgroundImageCache",false,true);this.getDoc().execCommand("styleWithCSS",false,false);this.getDoc().execCommand("useCSS",false)}catch(c){}Editor.changeButtonState(["Redo","Undo"],"disable")},initEvent:function(a){Zhishi.Event.attachEventListener(a,"click",Editor.nodeChange_);Zhishi.Event.attachEventListener(a,"mouseup",Editor.nodeChange);Zhishi.Event.attachEventListener(a,"keyup",this.handleKeyUp);Zhishi.Event.attachEventListener(a,"keydown",this.handleKeyDown);Zhishi.Event.attachEventListener(a,"contextmenu",this.handleRightClick);var b=Editor.textarea.value;if(Editor.fireFox){b=b||"<br/>"}},setToolTip:function(b){if(b!=Editor.message){b='<span style="color:red;">'+b+"</span>"}if(!get("toolTip")){var a=document.createElement("span");a.innerHTML=b;a.id="toolTip";a.className="ed_toolTip";get("ed_stateBar").appendChild(a)}else{get("ed_stateBar").removeChild(get("toolTip"));var a=document.createElement("span");a.innerHTML=b;a.id="toolTip";a.className="ed_toolTip";get("ed_stateBar").appendChild(a)}},changeHeight:function(a){if(a=="+"){this.height=parseInt(this.height)+80;Editor.count.b_add++}else{if(this.height>280&&a=="-"){this.height=parseInt(this.height)-80;Editor.count.b_plus++}else{return}}$("ed_iframeContainer").style.height=(this.height-62)+"px";$("ed_container").style.height=this.height+"px";this.iframe.style.height=(this.height-62)+"px"},createUI:function(j){var n=this.toolBar.baike.length;var s='<table cellspacing="0" height="30"  class="ed_toolBar_table" cellpadding="0" border="0"><tbody><tr>';for(var k=0;k<n;k++){var e=this.toolBar.baike[k];if(e.type=="separator"){if(e.isIE&&!Editor.ie){continue}s+='<td class="divider"><img src="'+this.imgPath+'blank.gif" class="img" alt=""/></td>'}else{if(e.isIE&&!Editor.ie){continue}var r="";if(e.hasText){r="width:54px;"}if(e.hasText2){r="width:74px;"}var g="Editor."+e.value;var c=e.value;s+='<td unselectable="on"><div unselectable="on" onmouseover="'+g+'.handleMouseOver(this)" onmouseout="'+g+'.handleMouseOut(this)" onmousedown="'+g+'.handleMouseDown(this)" onmouseup="'+g+'.handleMouseUp(this)" onclick="'+g+'.handleClick(this)" id="Tool_'+e.value+'" title="'+e.label+'" class="ToolbarItem"><img src="'+this.imgPath+'blank.gif" alt="'+e.label+'" class="img '+c+'" style="'+r+'"/></div></td>'}}s+="</tr></tbody></table>";var m=document.createElement("div");m.className="ed_toolBar";m.id="ed_toolBarId";m.style.height="30px";m.style.width=this.width+"px";m.innerHTML=s;var f=document.createElement("div");f.id="ed_stateBar";f.style.height="30px";f.style.width=this.width+"px";var q='<span style="float:left;">';if(navigator.appVersion.indexOf("MSIE 6.")>=0){q='<span style="float:left;padding-top:7px;">'}f.innerHTML=q+'<span style="cursor:pointer;" onclick="Editor.changeHeight(\'+\');" title="\u6269\u5c55\u7f16\u8f91\u6846"><img src="'+this.imgPath+'add.gif"/>&nbsp;\u52a0\u5927</span>&nbsp;&nbsp;<span style="cursor:pointer;" onclick="Editor.changeHeight(\'-\');" title="\u6536\u7f29\u7f16\u8f91\u6846"><img src="'+this.imgPath+'plus.gif">&nbsp;\u51cf\u5c0f</span></span>';var h=document.createElement("iframe");h.id="ed_ifrm_id";h.className="ed_Iframe";h.setAttribute("frameBorder","0");h.setAttribute("border",0);h.setAttribute("width",(this.width-2)+"px");h.setAttribute("marginWidth","0");h.setAttribute("marginHeight","0");h.setAttribute("height",(this.height-62)+"px");var p=document.createElement("div");p.id="ed_iframeContainer";p.height=(this.height-62)+"px";p.width=this.width+"px";p.appendChild(h);var l=document.createElement("div");l.id="ed_container";l.style.height=this.height+"px";l.style.width=this.width+"px";l.appendChild(m);l.appendChild(p);l.appendChild(f);var a=this.textarea.value;if(Editor.fireFox){a=this.textarea.value||"<br/>"}this.textarea.parentNode.insertBefore(l,this.textarea.nextSibling);this.textarea.hide();if(Zhishi.Browser.isIE){h.src=Editor.editor_blankUrl;var b=setInterval(function(){if(h.contentWindow.access){clearInterval(b);h.contentWindow.document.body.contentEditable=true;h.contentWindow.document.body.onpaste=parent.Editor.handlePasteForIE;Editor.setValue(a);Editor.initEvent(h.contentWindow.document);Editor.Image.addEvent()}},100)}else{h.contentWindow.document.open();Editor.initEvent(h.contentWindow.document);h.contentWindow.document.write('<html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" href="'+Editor.editorInCss+'" type="text/css"/></head><body id="ed_body">'+a+"</body></html>");h.contentWindow.document.close();h.contentWindow.document.designMode="on"}this.iframe=h},handleKeyUp:function(b){b=window.event||b;var a=b.which||b.keyCode||b.charCode;switch(a){case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 8:case 46:Editor.nodeChange();break;default:break}},handleKeyDown:function(c){if(Editor.startTime==null){Editor.startTime=new Date()}c=window.event||c;var b=c.which||c.keyCode||c.charCode;var a=Editor.keyMaps;var d=0;if(c.ctrlKey||c.metaKey){d+=1000}else{if(c.shiftKey){d+=2000}}d+=b;switch(d){case a.CTRL_B:Editor.count.k_b++;Editor.prevent(c);Editor.Bold.execute(false);break;case a.CTRL_I:Editor.count.k_i++;Editor.prevent(c);Editor.Italic.execute();break;case a.CTRL_V:Editor.count.k_v++;if(Zhishi.Browser.isFirefox){setTimeout(Editor.Util.pasteTips,500)}if(Editor.ie){Editor.checkClipBorderHasImg(true)}break;case a.CTRL_C:Editor.count.k_c++;break;case a.CTRL_X:Editor.count.k_x++;break;case a.CTRL_Z:Editor.count.k_z++;break;case a.CTRL_Y:Editor.count.k_y++;break;default:break}Editor.nodeChange()},handlePasteForIE:function(){Editor.checkClipBorderHasImg(false);setTimeout(Editor.Util.pasteTips,500);return true},checkClipBorderHasImg:function(a){if(!Editor.Capture.isOnDoingPaste){Editor.Capture.isOnDoingPaste=true;if(Editor.captureActiveX==null){Editor.Capture.initCapture(false)}if(Editor.captureActiveX!=null&&Editor.captureActiveX.IsClipBoardImage){Editor.getIeRange();if(Editor.Capture.compareVersion(Editor.Capture.captureVersionForCtrlV,Editor.captureActiveX.Version)){Editor.captureActiveX.UploadClipBoardImg2(a)}else{Editor.captureActiveX.UploadClipBoardImg()}Editor.Capture.showProcess()}setTimeout(function(){Editor.Capture.isOnDoingPaste=false},100)}},handleRightClick:function(){if(Editor.captureActiveX==null){Editor.Capture.initCapture(false)}if(Editor.captureActiveX!=null){if(Editor.Capture.compareVersion(Editor.Capture.captureVersionForCtrlV,Editor.captureActiveX.Version)){Editor.captureActiveX.ContextMenuProcess()}}Editor.count.right_click++},prevent:function(a){a.returnValue=false;if(a.preventDefault){a.preventDefault()}return true},getCmdList:function(){var b=[],c=Editor.toolBar.baike;for(var a=0;a<c.length;a++){if(c[a].type=="extend"&&c[a].value!=null){b.push(c[a].value)}}return b},nodeChange:function(){if(!Editor.stopNodeChange){if(Editor.nodeTimer!=null){clearTimeout(Editor.nodeTimer)}Editor.nodeTimer=setTimeout(Editor.nodeChange_,100)}else{setTimeout(function(){Editor.stopNodeChange=false},100)}},isInnerLink:function(c){if(c.nodeName!="A"){return false}var b=c.className;var a=c.href;if(b==null||a==null){return false}return b=="ed_inner_link"},nodeChange_:function(){var e=Editor.getCmdList();var b=new Array();var c=Editor.getSelectedElement();for(var a=0;a<e.length;a++){if(Editor.getDoc().queryCommandState(e[a])){b.push(e[a])}}if(c){while(c.nodeName!="BODY"){if(c.nodeName=="H2"){b.push("Title");if(Editor.ie){b.shift()}break}else{if(Editor.isInnerLink(c)){b.push("InnerLink");break}else{c=c.parentNode}}}}e.push("Title");e.push("InnerLink");var d=["Undo","Redo"];for(var a=0;a<d.length;a++){if(Editor.getDoc().queryCommandEnabled(d[a])){Editor[d[a]]["enable"]()}else{Editor[d[a]]["disable"]()}}Editor.changeButtonState(e,"deactivate");Editor.changeButtonState(b,"activate")},changeButtonState:function(c,b){for(var a=0;a<c.length;a++){Editor[c[a]][b]()}},pasteHTML:function(a){if(!Editor.ie){Editor.getDoc().execCommand("insertHtml",false,a)}else{Editor.getDoc().selection.createRange().pasteHTML(a)}},getValue:function(){return this.getDoc().body.innerHTML},getContent:function(){return Editor.getDoc().body.innerHTML},setValue:function(a){if(Zhishi.Browser.isIE){var b=setInterval(function(){if(Editor.iframe.contentWindow.access){clearInterval(b);Editor.getDoc().body.innerHTML=a;Editor.Image.addEvent()}},100)}else{Editor.getDoc().body.innerHTML=a}},unFocus:function(){window.focus()},focus:function(){Editor.getWindow().focus()},getDoc:function(){return this.iframe.contentWindow.document},getWindow:function(){return this.iframe.contentWindow},getMySelection:function(){if(this.getWindow().getSelection){return this.getWindow().getSelection()}else{return this.getDoc().selection}},getRange:function(){var b=this.getMySelection();var a=null;if(b.getRangeAt){a=b.getRangeAt(0)}else{if(b.baseNode){a=this.getDoc().createRange();a.setStart(b.baseNode,b.baseOffset);a.setEnd(b.extentNode,b.extentOffset);if(a.collapsed){a.setStart(b.extentNode,b.extentOffset);a.setEnd(b.baseNode,b.baseOffset)}}else{a=b.createRange()}}return a},getText:function(){var a=this.getRange();return a?(Editor.ie?a.text:a.toString()):null},getSelectedElement:function(){var d=this.getDoc(),c=null,b=null,a=true,e=null;if(Editor.ie){b=this.getRange();if(b){e=b.item?b.item(0):b.parentElement()}}else{c=this.getMySelection();b=this.getRange();if(!c||!b){return null}if(Zhishi.Browser.isWebKit){if(b.startContainer){a=false;if(b.startContainer.nodeType==3){e=b.startContainer.parentNode}else{if(b.startContainer.nodeType==1){e=b.startContainer}else{a=true}}}}if(a){if(c.anchorNode&&(c.anchorNode.nodeType==3)){if(c.anchorNode.parentNode){e=c.anchorNode.parentNode}if(c.anchorNode.nextSibling!=c.focusNode.nextSibling){e=c.anchorNode.nextSibling}}if(!e){e=b.commonAncestorContainer;if(!b.collapsed){if(b.startContainer==b.endContainer){if(b.startOffset-b.endOffset<2){if(b.startContainer.hasChildNodes()){e=b.startContainer.childNodes[b.startOffset]}}}}}}}return e||this.getDoc().body},getIeRange:function(){if(Editor.ie){Editor.ieSelection=Editor.getDoc().selection.createRange()}},selectIeRange:function(){if(Editor.ie&&Editor.ieSelection){Editor.ieSelection.select();Editor.ieSelection=null}},closeFormatTips:function(){Editor.getIeRange();get(Editor.formatTipsId).style.display="none";Editor.selectIeRange();Editor.focus()},closeTitleTips:function(){Editor.getIeRange();get(Editor.titleTipsId).style.display="none";Editor.selectIeRange();Editor.focus()},closePictureTips:function(){Editor.getIeRange();get(Editor.pictureTipsId).style.display="none";Editor.selectIeRange();Editor.focus()},hasParagraphTitle:function(){var a=Editor.getDoc().getElementsByTagName("h2");if(a.length==0){return false}return true},hasAbstractPicture:function(){var a=Editor.getDoc().getElementById("topPic");if(!a){return false}return true},isEditingParagraph:function(){var a=document.getElementById("contentBefore");var b=document.getElementById("contentAfter");if(a){if(a.innerHTML.length!=0){return true}return false}else{return false}if(b){if(b.innerHTML.length!=0){return true}return false}else{return false}}};Editor.Util={getCountInfo:function(){var b="";var c=new Date();var a=(Date.parse(c)-Date.parse(Editor.startTime))/1000||0;for(var d in Editor.count){b+=d+":"+Editor.count[d]+","}return b+"time:"+a},resetCountInfo:function(){for(var a in Editor.count){Editor.count[a]=0}},pasteTips:function(){var b=false;for(var d=0;d<Editor.invalidNode.length;d++){var e=Editor.getDoc().getElementsByTagName(Editor.invalidNode[d]);if(e.length>0){b=true;break}}var f=Editor.getDoc().getElementsByTagName("IMG");for(var d=0;d<f.length;d++){if(f[d].src.indexOf(".soso.com")==-1&&f[d].src.indexOf("p/")!=0){b=true;break}}if(b){var c=get("Tool_Formate");var a=get(Editor.formatTipsId);a.style.left=c.getXY()[0]-20+"px";a.style.top=c.getXY()[1]-75+"px";a.style.position="absolute";a.style.display="block"}},showTitleTips:function(){var b=get("Tool_Title");var a=get(Editor.titleTipsId);a.style.left=b.getXY()[0]-20+"px";a.style.top=b.getXY()[1]-75+"px";a.style.position="absolute";a.style.display="block"},showPictureTips:function(){var b=get("Tool_Image");var a=get(Editor.pictureTipsId);a.style.left=b.getXY()[0]-20+"px";a.style.top=b.getXY()[1]-75+"px";a.style.position="absolute";a.style.display="block"},filterHtml:function(b){var a="";a=b.replace(/<br>/gi,"");a=a.replace(/&/gi,"&amp;");a=a.replace(/</gi,"&lt;");a=a.replace(/>/gi,"&gt;");return a}};Editor.BaseButton={disabled:false,command:"",execute:function(a){if(a==null){switch(this.command){case"Undo":Editor.count.b_undo++;break;case"Redo":Editor.count.b_redo++;break;case"Bold":Editor.count.b_bold++;break;case"Italic":Editor.count.b_italic++;break;default:break}}Editor.getDoc().execCommand(this.command,false,null)},afterExecute:function(){Editor.nodeChange_();Editor.focus();Editor.stopNodeChange=true},beforeExecute:function(){Editor.focus()},getButton:function(){return get("Tool_"+this.command)},addClass:function(a){this.getButton().addClassName(a)},removeClass:function(a){this.getButton().removeClassName(a)},hasClass:function(a){return this.getButton().hasClassName(a)},enable:function(){this.disabled=false;this.removeClass("ed_button_disabled")},disable:function(){this.disabled=true;this.removeClass("ed_button_mousedown");this.removeClass("ed_button_mouseover");this.addClass("ed_button_disabled")},activate:function(){this.addClass("ed_button_mousedown")},deactivate:function(){this.removeClass("ed_button_mousedown")},handleClick:function(){if(this.disabled){return}this.beforeExecute();this.execute();this.afterExecute()},handleMouseUp:function(){this.removeClass("ed_button_mousedown")},handleMouseDown:function(){if(this.disabled){return}this.addClass("ed_button_mousedown")},handleMouseOut:function(){this.removeClass("ed_button_mouseover")},handleMouseOver:function(){if(this.disabled){return}if(!this.hasClass("ed_button_mousedown")){this.addClass("ed_button_mouseover")}}};Editor.Undo={};Object.extend(Editor.Undo,Editor.BaseButton);Object.extend(Editor.Undo,{command:"Undo",afterExecute:function(){Editor.nodeChange_();Editor.focus()}});Editor.Redo={};Object.extend(Editor.Redo,Editor.BaseButton);Object.extend(Editor.Redo,{command:"Redo",afterExecute:function(){Editor.nodeChange_();Editor.focus()}});Editor.Bold={};Object.extend(Editor.Bold,Editor.BaseButton);Object.extend(Editor.Bold,{command:"Bold",handleMouseUp:function(){}});Editor.Italic={};Object.extend(Editor.Italic,Editor.BaseButton);Object.extend(Editor.Italic,{command:"Italic",handleMouseUp:function(){}});Editor.Title={};Object.extend(Editor.Title,Editor.BaseButton);Object.extend(Editor.Title,{command:"Title",execute:function(){var c=get(Editor.titleTipsId);if(c){c.style.display="none"}Editor.count.b_title++;var g=Editor.getSelectedElement().nodeName;if(g&&g=="H2"){Editor.getDoc().execCommand("formatblock",false,"<p>")}else{if(g!="IMG"){Editor.getDoc().execCommand("RemoveFormat",false,null);var e=Editor.getText();var b=Editor.getSelectedElement();if(Editor.fireFox&&b.innerHTML==""){b.parentNode.removeChild(b)}if(e==""){return}else{var d="<H2>"+Editor.Util.filterHtml(e)+"</H2>";if(Editor.ie){var a=Editor.getDoc().selection.createRange();Editor.getIeRange();if(a.htmlText.endsWith("<BR>")){a.moveEnd("character",-1)}if(a.moveEnd("character",1)>0){if(!a.htmlText.endsWith(">")){a.moveEnd("character",-1)}}if(a.moveStart("character",-1)<0){if(!a.htmlText.indexOf("<")>=0){a.moveStart("character",1)}}if(!a.htmlText.contains("<BR>")){Editor.selectIeRange();Editor.pasteHTML(d)}else{a.pasteHTML(d);a.collapse(false);a.select()}}else{var f=Editor.getSelectedElement();if(f.tagName=="BR"){Editor.getDoc().execCommand("formatblock",false,"<h2>")}else{Editor.pasteHTML(d)}}}}}}});Editor.InnerLink={};Object.extend(Editor.InnerLink,Editor.BaseButton);Object.extend(Editor.InnerLink,{command:"InnerLink",execute:function(){Editor.count.b_link++;var d=Editor.getSelectedElement();var g=Editor.getSelectedElement().nodeName;if(g&&g=="A"&&d.className=="ed_inner_link"){Editor.getDoc().execCommand("Unlink",false,null);if(Editor.fireFox){var c=Editor.getDoc().createTextNode(d.textContent);d.parentNode.replaceChild(c,d)}return}if(d&&(d.nodeName=="B"||d.nodeName=="STRONG"||d.nodeName=="EM"||d.nodeName=="I")){if(d.parentNode&&d.parentNode.nodeName=="A"&&d.parentNode.className=="ed_inner_link"){Editor.getDoc().execCommand("Unlink",false,null);return}}if(g!="IMG"&&g!="H2"){var f=Editor.getText();var b=Editor.getSelectedElement();if(Editor.fireFox&&b.innerHTML==""){b.parentNode.removeChild(b)}if(f==""||f.length>20){return}else{var e='<A target="_blank" class="ed_inner_link" href="#">'+Editor.Util.filterHtml(f)+"</A>";if(Editor.ie){var a=Editor.getDoc().selection.createRange();Editor.getIeRange();if(a.htmlText.endsWith("<BR>")){a.moveEnd("character",-1)}if(a.moveEnd("character",1)>0){if(!a.htmlText.endsWith(">")){a.moveEnd("character",-1)}}if(a.moveStart("character",-1)<0){if(!a.htmlText.indexOf("<")>=0){a.moveStart("character",1)}}if(!a.htmlText.contains("<BR>")){Editor.selectIeRange();Editor.pasteHTML(e)}else{a.pasteHTML(e);a.collapse(false);a.select()}}else{Editor.pasteHTML(e)}}}}});Editor.Char={};Object.extend(Editor.Char,Editor.BaseButton);Object.extend(Editor.Char,{command:"Char",charValue:"",clickCharWindow:false,charDialog:null,tdClick:function(){Editor.count.b_char_suc++;Editor.Char.clickCharWindow=true;Editor.selectIeRange();Editor.pasteHTML(Editor.Char.charValue.trim());Editor.Char.charDialog.close();Editor.focus()},execute:function(){Editor.count.b_char++;if(Editor.getSelectedElement().tagName=="IMG"){alert("\u56fe\u7247\u4e0d\u652f\u6301\u6b64\u64cd\u4f5c！");return}Editor.Char.clickCharWindow=false;Editor.Char.charDialog=new Zhishi.Dialog("\u63d2\u5165\u7279\u6b8a\u7b26\u53f7",390,400,true,Editor.charHtmlUrl);Editor.Char.charDialog.show();Editor.getIeRange();Editor.Char.charDialog.afterClose=function(){if(!Editor.Char.clickCharWindow){Editor.selectIeRange()}}}});Editor.Image={};Object.extend(Editor.Image,Editor.BaseButton);Object.extend(Editor.Image,{command:"Image",align:"top",title:"",uploadDialog:null,hasClick:false,currentImage:null,scaleImage:function(f,a,d,c){var e=1;var b=1;if(f>d||a>c){if(f>d){e=d/f}if(a>c){b=c/a}e=b=Math.min(e,b)}return e},scaleForWidth:function(d,a,c,b){return d*Editor.Image.scaleImage(d,a,c,b)},scaleForHeight:function(d,a,c,b){return a*Editor.Image.scaleImage(d,a,c,b)},showPreview:function(a,b,c,n){Editor.count.b_img_suc++;Editor.Image.hasClick=true;Editor.selectIeRange();if(Editor.ie){if(Editor.getSelectedElement().tagName=="IMG"){Editor.getDoc().execCommand("delete")}}if(b==null||b==""||b=="null"){b=a}var h="";var l=300;var m=300;var k=l;var p=m;var g=this.title;g="\u70b9\u51fb\u67e5\u770b\u5927\u56fe";if(this.align=="right"||this.align=="left"){if(c&&n){k=Editor.Image.scaleForWidth(c,n,l,m);p=Editor.Image.scaleForHeight(c,n,l,m)}h='<a target="_blank" title="'+g+'" href="'+b+'" class="ed_image_link"><img alt="\u56fe\u7247" class="ed_imgfloat_'+this.align+'"  title="'+this.title+'" src="'+a+'" width="'+k+'" height="'+p+'"></a>';var o=Editor.getSelectedElement();if(Editor.Image.currentImage!=null&&o.nodeName=="IMG"&&o.parentNode.nodeName=="A"){o.parentNode.href=b;o.parentNode.className="ed_image_link";o.parentNode.removeAttribute("id");o.className="ed_imgfloat_"+Editor.Image.align;o.removeAttribute("id");o.title=Editor.Image.title;o.src=a;o.width=k;o.height=p;o.focus()}else{Editor.pasteHTML(h)}Editor.Image.addEvent()}else{l=230;m=230;if(c&&n){k=Editor.Image.scaleForWidth(c,n,l,m);p=Editor.Image.scaleForHeight(c,n,l,m)}var j=Editor.getDoc();var e=j.getElementById("topPic");var i=null;if(e){i=e.parentNode}if(i&&i.id=="topPicLink"&&i.nodeName=="A"&&e){var o=Editor.getSelectedElement();if(o.nodeName=="IMG"&&(o.id==null||o.id!="topPic")){Editor.getDoc().execCommand("delete",false,null)}i.href=b;e.src=a;if(e.getAttribute("style")){e.removeAttribute("style")}if(e.getAttribute("height")){e.removeAttribute("height")}if(e.getAttribute("width")){e.removeAttribute("width")}e.title=this.title;e.width=k;e.height=p;e.focus()}else{if(e){e.parentNode.removeChild(e)}if(i){i.parentNode.removeChild(i)}h='<a target="_blank" id="topPicLink" title="'+g+'" href="'+b+'" class="ed_image_link"><img alt="\u56fe\u7247" class="ed_imgfloat_'+this.align+'"  id="topPic" title="'+this.title+'" src="'+a+'" width="'+k+'" height="'+p+'"></a>';var o=Editor.getSelectedElement();if(o.nodeName=="IMG"){Editor.getDoc().execCommand("delete",false,null)}Editor.setValue(h+Editor.getContent().replace(/hasdbevent="1"/gi,"").replace(/hasdbevent=1/gi,""));Editor.Image.addEvent();setTimeout(function(){Editor.getWindow().scrollTo(0,0)},50)}}this.title="";Editor.Image.uploadDialog.close();Editor.focus();var d=Editor.getDoc().selection;if(Editor.ie&&d&&d.type=="Control"){var f=Editor.getDoc().body.createTextRange();f.moveToElementText(Editor.getDoc().selection.createRange().item(0));f.collapse(false);f.select()}Editor.nodeChange_()},execute:function(){var a=get(Editor.pictureTipsId);if(a){a.style.display="none"}Editor.count.b_img++;Editor.Image.align="right";Editor.Image.title="";var b=Editor.getSelectedElement();if(b.nodeName=="IMG"){Editor.Image.currentImage=b}else{Editor.Image.currentImage=null}Editor.Image.uploadDialog=new Zhishi.Dialog('<DIV class="upload_img"></DIV><SPAN class="layer_title">\u4e0a\u4f20\u56fe\u7247</SPAN>',550,375,true,Editor.uploadPicUrl,{hasBottomHr:false,top:30});Editor.Image.uploadDialog.show();Editor.getIeRange();Editor.Image.uploadDialog.afterClose=function(){if(Editor.Image.hasClick){if(Editor.ieSelection!=null){Editor.selectIeRange()}}else{Editor.selectIeRange();Editor.focus()}}},addEvent:function(){var a=Editor.getDoc().getElementsByTagName("IMG");if(a==null){return}for(var b=0;b<a.length;b++){var c=a[b];if(c.getAttribute("hasdbevent")==null){Zhishi.Event.attachEventListener(c,"dblclick",Editor.Image.execute);c.setAttribute("hasdbevent","1")}}}});Editor.Formate={};Object.extend(Editor.Formate,Editor.BaseButton);Object.extend(Editor.Formate,{layerDialog:null,command:"Formate",execute:function(){Editor.count.b_format++;var a=Editor.getContent();Zhishi.Ajax.sendRequest("POST",Editor.parseUrl,{postdata:a,encode:false,onSuccess:function(b){Editor.setValue(b);Editor.Image.addEvent()}});get(Editor.formatTipsId).style.display="none";if((!Editor.hasParagraphTitle()||!Editor.hasAbstractPicture())&&!Editor.isEditingParagraph()){Editor.Formate.layerDialog=new Zhishi.Dialog("<SPAN class=layer_title>\u683c\u5f0f\u52a9\u624b</SPAN>",373,255,true,Editor.formateLayerUrl,{});Editor.Formate.layerDialog.show();Editor.Formate.layerDialog.afterClose=function(){Editor.Formate.afterLayerClosed();Editor.focus()}}},afterLayerClosed:function(){var b=Editor.hasParagraphTitle();var a=Editor.hasAbstractPicture();if(!b&&!a){Editor.Util.showTitleTips()}else{if(!b){Editor.Util.showTitleTips()}else{if(!a){Editor.Util.showPictureTips()}}}},handleLayerClose:function(){Editor.Formate.layerDialog.close()}});Editor.Capture={};Object.extend(Editor.Capture,Editor.BaseButton);Object.extend(Editor.Capture,{command:"Capture",processDialog:null,helpTipsDialog:null,systemClose:false,isOnDoingPaste:false,isCtrlVUploadPicForActiveX:false,isDoing:false,isUserStopUpload:false,xType:0,ieBarX:null,captureVersionForCtrlV:"3.1.14.11",captureVersion:"3.1.15.10",includeXToolbarVersion:"3.1.27.10",captureActiveSteupExe:"http://toolbar.soso.com/download/TencentSosoActiveXSetup3.EXE",captureActiveUpdateExe:"http://toolbar.soso.com/download/TencentSosoActiveXInstall3.EXE",captureToolbar:"http://toolbar.soso.com/download/QQToolbarInstallerForWenWenBaike3.exe",execute:function(){if(!Editor.Capture.isDoing){Editor.Capture.xType=0;if(Editor.Capture.initCapture(true)){Editor.getIeRange();Editor.Capture.systemClose=false;Editor.captureActiveX.DoCapture();Editor.Capture.isDoing=true;Editor.count.b_capture++}}},initCapture:function(a){if(Editor.Capture.checkHasCaptureX(false)){if(Editor.Capture.isNeedUpdate(a)){Editor.Capture.showHelpTips(8);return false}else{Editor.captureActiveX=Editor.Capture.getCaptureX();Editor.captureActiveX.URL=Editor.captureUploadUrl;Editor.captureActiveX.OnCaptureFinished=function(){Editor.focus();Editor.captureActiveX.StartUpload();Editor.Capture.showProcess()};Editor.captureActiveX.OnCaptureCanceled=function(){Editor.selectIeRange();Editor.focus();Editor.Capture.isDoing=false};Editor.captureActiveX.OnUploadFinished=function(b){Editor.Capture.hideProcess();Editor.selectIeRange();if(Editor.getSelectedElement().tagName=="IMG"){Editor.getDoc().execCommand("delete");Editor.focus()}if(b&&b.length>8){var d=b.substr(0,8)+"/";b="http://baike.soso.com/p/"+d+b}var c='<a target="_blank" title="\u70b9\u51fb\u67e5\u770b\u5927\u56fe" href="'+b+'" class="ed_image_link"><img class="ed_imgfloat_right" title="" src="'+b+'"></a>';Editor.pasteHTML(c);Editor.focus();Editor.Capture.isDoing=false;Editor.Image.addEvent()};Editor.captureActiveX.OnError=function(b,c){if(Editor.Capture.processDialog){Editor.Capture.processDialog.onClose=function(){return true};Editor.Capture.processDialog.close()}if(!Editor.Capture.isUserStopUpload){alert(b)}else{Editor.Capture.isUserStopUpload=false}Editor.selectIeRange();Editor.focus();Editor.Capture.isDoing=false};return true}}else{if(Editor.Capture.canRegFromToolbar(a)){return false}else{if(a){Editor.Capture.showHelpTips(1);return false}}}},getCaptureX:function(){if(Editor.captureActiveX){return Editor.captureActiveX}else{return new ActiveXObject("SosoBaike.ScreenCapture")}},getIEBarX:function(){if(Editor.Capture.ieBarX){return Editor.Capture.ieBarX}else{return new ActiveXObject("SosoIEBar.IEBarObj")}},showProcess:function(){Editor.Capture.processDialog=new Zhishi.Dialog("\u641c\u641c\u767e\u79d1",370,200,false,$("tips6").innerHTML);Editor.Capture.processDialog.onClose=function(){if(!Editor.Capture.systemClose){var a=confirm("\u56fe\u7247\u6b63\u5728\u4e0a\u4f20\u4e2d，\u60a8\u786e\u5b9a\u8981\u5173\u95ed\u6b64\u7a97\u53e3?");if(a&&Editor.captureActiveX){Editor.Capture.isUserStopUpload=true;Editor.captureActiveX.StopUpload()}return a}else{return true}};Editor.Capture.processDialog.show();Editor.Capture.processDialog.afterClose=function(){Editor.selectIeRange();Editor.focus();Editor.Capture.isDoing=false}},hideProcess:function(){if(Editor.Capture.processDialog!=null){Editor.Capture.systemClose=true;Editor.Capture.processDialog.close()}},isNeedUpdate:function(c){var b=false;if(c){var d=Zhishi.Cookie.getCookie("bk_isUpdateActiveX");if(d&&d=="0"){return false}Editor.captureActiveX=Editor.Capture.getCaptureX();var a=Editor.captureActiveX.Version;var e=Editor.Capture.captureVersion;if(a!=e){b=Editor.Capture.compareVersion(a,e)}}return b},compareVersion:function(f,c){var b=null;var a=false;if(f!=""&&c!=""){if(f==c){return true}else{b=f.split(".");var e=c.split(".");for(var d=0;d<e.length;d++){if(parseInt(e[d])>parseInt(b[d])){a=true;break}else{if(parseInt(e[d])<parseInt(b[d])){a=false;break}}}}}return a},checkHasCaptureX:function(c){var a=false;try{Editor.captureActiveX=Editor.Capture.getCaptureX();if(c){a=(Editor.Capture.compareVersion(Editor.Capture.captureVersion,Editor.captureActiveX.Version))?true:false}else{a=Editor.captureActiveX?true:false}}catch(b){}return a},checkHasToolbarX:function(){var a=false;try{Editor.Capture.ieBarX=Editor.Capture.getIEBarX();a=Editor.Capture.ieBarX?true:false}catch(b){}return a},showHelpTips:function(c){Editor.getIeRange();if(c==1){if(Editor.Capture.checkHasToolbarX()){c=7}else{$("tips1").getElementsByTagName("input")[0].checked="checked"}}else{if(c==2){var d=$("tips2").getElementsByTagName("a")[0];if(Editor.Capture.xType=="0"){d.href=Editor.Capture.captureToolbar}else{if(Editor.Capture.xType=="1"){d.href=Editor.Capture.captureActiveSteupExe}else{if(Editor.Capture.xType=="2"){d.href=Editor.Capture.captureActiveUpdateExe;if(document.location.href.indexOf(".sd")==-1){Zhishi.Cookie.setCookie("VisitedUrl",document.location,12)}}}}}}var b=$("tips"+c).innerHTML;Editor.Capture.helpTipsDialog=null;Editor.Capture.helpTipsDialog=new Zhishi.Dialog("\u5b89\u88c5\u63d0\u793a",370,220,false,b);Editor.Capture.helpTipsDialog.show();setTimeout(Zhishi.removeWindowCloseEvent,100)},selectType:function(a){Editor.Capture.xType=a},download:function(c){if(c){Editor.Capture.xType=c}this.hideTips();this.showHelpTips(2);var b=document.createElement("a");if(Editor.Capture.xType=="0"){b.href=Editor.Capture.captureToolbar}else{if(Editor.Capture.xType=="1"){b.href=Editor.Capture.captureActiveSteupExe}else{if(Editor.Capture.xType=="2"){b.href=Editor.Capture.captureActiveUpdateExe}}}document.body.appendChild(b);b.click()},hideTips:function(){Editor.Capture.helpTipsDialog.close();Editor.selectIeRange();Editor.focus()},startCheck:function(){Editor.Capture.hideTips();Editor.Capture.showHelpTips(3);setTimeout(function(){Editor.Capture.hideTips();if(Editor.Capture.checkHasCaptureX(true)){Editor.count.b_capture_suc++;Editor.Capture.showHelpTips(4)}else{Editor.Capture.showHelpTips(5)}},1000)},canRegFromToolbar:function(b){if(b&&Editor.Capture.checkHasToolbarX()){Editor.Capture.ieBarX=Editor.Capture.getIEBarX();var a=null;a=Editor.Capture.ieBarX.info("version","SosoIEBar.IEBarObj");if(Editor.Capture.compareVersion(Editor.Capture.includeXToolbarVersion,a)){if(confirm("\u60a8\u8fd8\u6ca1\u6709\u5b89\u88c5\u622a\u5c4f\u63a7\u4ef6，\u662f\u5426\u73b0\u5728\u5b89\u88c5？")){Editor.Capture.ieBarX.RegisterPrscrnAcitveX()}return true}}return false},cancelUpdate:function(){Zhishi.Cookie.setCookie("bk_isUpdateActiveX",0,7*24);Editor.Capture.hideTips()}});
