var gjmode="1";var gjedit="1";var gjtemphtml=document.getElementById("gjbjq_temp_html");//var editgj=document.getElementById("gjbjq");
function gjinsertHTML(html){var bz=window.getSelection?"1":"0";if(bz=="1"){var r=window.getSelection().getRangeAt(0);var r2=r.createContextualFragment(html);r.deleteContents();r.insertNode(r2);}else{if (editgj.document.selection.type.toLowerCase() != "none"){editgj.document.selection.clear();}editgj.document.selection.createRange().pasteHTML(html);}}
function gjformat(lx,v){editgj.focus();if(gjedit!="1"){alert("需转换为设计状态后才能使用设计功能！");return;}
var w=window.getSelection?window.getSelection().toString():document.selection.createRange().text;if(w!=""){if(v){var v2=v.replace("<","</");if(lx=="FormatBlock"){gjinsertHTML(v+w+v2);}else if(lx=="fontname"){gjinsertHTML("<span style=\"font-family:"+v+";\">"+w+"</span>");}else if(lx=="fontsize"){gjinsertHTML("<span style=\"font-size:"+v+";\">"+w+"</span>");}
}else{if(lx=="bold"){gjinsertHTML("<b>"+w+"</b>");}else if(lx=="italic"){gjinsertHTML("<em>"+w+"</em>");}else if(lx=="underline"){gjinsertHTML("<u>"+w+"</u>");}else if(lx=="StrikeThrough"){gjinsertHTML("<s>"+w+"</s>");}else if(lx=="superscript"){gjinsertHTML("<sup>"+w+"</sup>");}else if(lx=="subscript"){gjinsertHTML("<sub>"+w+"</sub>");}else if(lx=="justifyleft"){gjinsertHTML("<p align=\"left\">"+w+"</p>");}else if(lx=="justifycenter"){gjinsertHTML("<p align=\"center\">"+w+"</p>");}else if(lx=="justifyright"){gjinsertHTML("<p align=\"right\">"+w+"</p>");}else if(lx=="justifyfull"){gjinsertHTML("<p align=\"justify\">"+w+"</p>");}else if(lx=="InsertHorizontalRule"){gjinsertHTML("<hr>");}}}else if(lx=="InsertHorizontalRule"){gjinsertHTML("<hr>");}}
function gjhtml(code){return code.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');}
function gjunhtml(code){return code.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');}
function gjtext(code){code=code.replace(/<\/?[^>]*>/g,"");code=code.replace(/[|]*\n/g,"\n");code=code.replace(/\n[\s||]*\r/g,"\n");return code;}
function gjsetHTML(html){if (gjmode=="2"){gjmode="2";gjedit="0";editgj.innerHTML=gjhtml(html);document.getElementById("set1").className="gjbton";document.getElementById("set2").className="gjbtof";document.getElementById("set3").className="gjbton";document.getElementById("set4").className="gjbton";}
else{gjmode="1";gjedit="1";editgj.innerHTML=html;document.getElementById("set1").className="gjbtof";document.getElementById("set2").className="gjbton";document.getElementById("set3").className="gjbton";document.getElementById("set4").className="gjbton";}}
function gjgetHTML(){var html;if((gjmode=="1")||(gjmode=="4")){html = editgj.innerHTML;}else{html = gjhtml(editgj.innerHTML);}return html;}
function gjnoword(w) {w = w.replace(/<\/?SPAN[^>]*>/gi, "" );w = w.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;w = w.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;w = w.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;w = w.replace(/<\\?\?xml[^>]*>/gi, "") ;w = w.replace(/<\/?\w+:[^>]*>/gi, "") ;w = w.replace(/&nbsp;/, " " );try{var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;w = w.replace( re, "<div$2</div>" ) ;}catch(e){}return w;}
function setMode(nmode){if (nmode=="1"){document.getElementById("set1").className="gjbtof";document.getElementById("set2").className="gjbton";document.getElementById("set3").className="gjbton";document.getElementById("set4").className="gjbton";}
else if (nmode=="2"){document.getElementById("set1").className="gjbton";document.getElementById("set2").className="gjbtof";document.getElementById("set3").className="gjbton";document.getElementById("set4").className="gjbton";}
else if (nmode=="3"){if(gjmode=="2"){}else{document.getElementById("set1").className="gjbton";document.getElementById("set2").className="gjbton";document.getElementById("set3").className="gjbtof";document.getElementById("set4").className="gjbton";}}
else if (nmode=="4"){document.getElementById("set1").className="gjbton";document.getElementById("set2").className="gjbton";document.getElementById("set3").className="gjbton";document.getElementById("set4").className="gjbtof";}
if (nmode==gjmode){return false;}
if (nmode=="3"){if (gjmode=="2"){alert("需转换为设计状态后才能使用文本功能！");return false;}if (gjmode=="1"||gjmode=="4"){if (!confirm("切换到文本模式会移除所有的HTML格式，您确认切换吗？")){return false;}}}
if (nmode=="1"){gjmode="1";gjedit="1";gjtemphtml=gjunhtml(editgj.innerHTML);editgj.innerHTML=gjtemphtml;editgj.contentEditable=true;}
else if (nmode=="2"){gjmode="2";gjedit="0";gjtemphtml=gjhtml(editgj.innerHTML);editgj.innerHTML=gjtemphtml;editgj.contentEditable=true;}
else if (nmode=="3"){gjmode="3";gjedit="0";gjtemphtml=gjtext(editgj.innerHTML);editgj.innerHTML=gjtemphtml;editgj.contentEditable=true;}
else if (nmode=="4"){gjmode="4";gjedit="0";gjtemphtml=gjunhtml(editgj.innerHTML);editgj.innerHTML=gjtemphtml;editgj.contentEditable=false;}
else if (nmode=="5"){if (gjmode=="2"){alert("需转换为设计状态后才能使用去除Word格式功能！");return false;}gjtemphtml=gjnoword(editgj.innerHTML);editgj.innerHTML=gjtemphtml;}}
var lb="0";var sp="0";
var URLParams = new Object() ;var aParams = document.location.search.substr(1).split('&') ;for (i=0 ; i < aParams.length ; i++){var aParam = aParams[i].split('=');URLParams[aParam[0]] = aParam[1];}
try{if(URLParams['id']){lb=URLParams['id'];}}catch(exp){} 
try{if(URLParams['sp']){sp=URLParams['sp'];}}catch(exp){} 
function show2(id){editgj.focus();
if(gjedit!="1"){alert("需转换为设计状态后才能使用设计功能！");return;}
id=id+"?id="+lb+"&sp="+sp;window.open(id,"upload","");}
function gjsize(size){for (var i=0; i<parent.frames.length; i++){if (parent.frames[i].document==self.document){var obj=parent.frames[i].frameElement;if(size=="1"){obj.height=775;editgj.style.height=window.getSelection?"700px":700;}else{obj.height=255;editgj.style.height=window.getSelection?"180px":180;}break;}}}
