//防止按回车键重复发文
function update() {
	document.frmAnnounce.submit_1.disabled=false;
	document.frmAnnounce.submit_2.disabled=false;
}
function change_button(){
var secs = 3;
	document.frmAnnounce.submit_1.disabled=true;
	document.frmAnnounce.submit_2.disabled=true;
	window.setTimeout("update()", secs * 1000);
}
function InitImageWidth(Imgobj){
var max=screen.width-274;
var w=Imgobj.width;
if(w==0){
var img=new Image();
img.src=Imgobj.src;
w=img.width;
}
if(w>max){Imgobj.width=max;}
}
function ChangeFace(type,faceNum){

var face1=$("face1");
var face2=$("face2");
var face3=$("face3");
var face4=$("face4");
var face5=$("face5");
if(face1 && face1.style.display=="block")
{
	if(face1)face1.style.display="none";
	if(face2)face2.style.display="block"
	if(face3)face3.style.display="none";
	if(face4)face4.style.display="none";
	if(face5)face5.style.display="none";
}else if(face2 && face2.style.display=="block")
{
	if(face1)face1.style.display="none";
	if(face2)face2.style.display="none"
	if(face3)face3.style.display="block";
	if(face4)face4.style.display="none";
	if(face5)face5.style.display="none";
}
else if(face3 && face3.style.display=="block")
{
	if(face1)face1.style.display="none";
	if(face2)face2.style.display="none"
	if(face3)face3.style.display="none";
	if(face4)face4.style.display="block";
	if(face5)face5.style.display="none";
}
else if(face4 && face4.style.display=="block")
{
	if(face1)face1.style.display="none";
	if(face2)face2.style.display="none"
	if(face3)face3.style.display="none";
	if(face4)face4.style.display="none";
	if(face5)face5.style.display="block";
}
else if(face5 && face5.style.display=="block")
{
	if(face1)face1.style.display="block";
	if(face2)face2.style.display="none"
	if(face3)face3.style.display="none";
	if(face4)face4.style.display="none";
	if(face5)face5.style.display="none";
}
/*
    var currentFace=1;
    for(i = 1; i <= faceNum; i++) 
    {
        if($("face"+faceNum).style.display=="block")
        {
            currentFace=i;
            break;
        }
    }
    for(j = 1; j <= faceNum; j++) 
    {
        $("face"+j).style.display="none";
    }
    if(type==0)//往前
    {
        if(currentFace==1)
        {
            $("face"+faceNum).style.display="block";
        }
        else
        {
            var PreFace=currentFace-1;
            $("face"+PreFace).style.display="block";
        }
    }
    else if(type==1)//往后
    {
        if(currentFace==faceNum)
        {
            $("face1").style.display="block";
        }
        else
        {
             var NextFace=currentFace+1;
            $("face"+NextFace).style.display="block";
        }
    }
    */
}
function reply(announceid, topic) {
    if (announceid == 0) {
        var m_announceid = document.getElementById("HTML_speak_subject");
        if (m_announceid != null) {
            m_announceid.value = "Re: " + topic;
            $("btn_upimg").focus();
        }
    } else {
        var m_announceid = document.getElementById("announceid");
        if (null != m_announceid) {
            m_announceid.value = announceid;
        }
        var m_topic = document.getElementById("topic");
        if (null != m_topic) {
            m_topic.value = topic;
            $("btn_upimg").focus();
        }
        var hehe = document.getElementById("HTML_speak_subject");
        if (hehe != null) {
            hehe.value = "Re: " + topic;
              $("btn_upimg").focus();
        }
    }
}
function SpeakCheck(Anonymous){
if(Anonymous){if($("html_guest_username").value==""){alert("请填昵称！");return false;}}
change_button();
if(document.frmAnnounce.subject.value == "发言主题(必填，限150字)"){
alert("请填写发言主题");
document.frmAnnounce.subject.focus();
return false;
}
if(document.frmAnnounce.subject.value.length < 1){
alert("还是写上主题吧！");
document.frmAnnounce.subject.focus();
return false;
}
if(document.frmAnnounce.subject.value.length > 180){
alert("您的主题太长了！");
document.frmAnnounce.subject.focus();
return false;
}
return CheckContent();
}
function CheckContent(){
if(editor){
editor.data();
var t=editor.value();
if(t.length>150000){
alert("内容请控制在150000字以内！");
editor.focus();
return false;
}
editor.data();
return true;
}
return false;
}
function face(facenum){
var face='http://img2.soufunimg.com/homebbs/image_jiatx/face/em';
var speak =$('speak');
if(editor&&editor.checked){
EditorImg(face+facenum+'.gif');
}else if(speak){
var ToAdd = '[Face' + facenum + ']';
speak.value += ToAdd;
speak.focus();
}
}
function quote(url,announceid,title,username,userid,dtime){
var she = $('HTML_speak_subject');
var sm =new StrMaker();
var speak =$('speak');
if(editor&&editor.checked){
	var hehe = $('HTML_body'+announceid);
	sm.add('引用：<a href=');
	blog();
	sm.add(' target=_blank>',username,'</a> 在',dtime,'写道：<a href="',url,'">原帖</a><br /> ');
	sm.add(hehe.innerHTML);
	Editorquote(sm.str());
}else if(speak){
	var hehe = $('HTML_quotebody'+announceid);
	sm.add('[QUOTE]引用：[URL=');
	blog();
	sm.add(']',username,'[/URL] 在',dtime,'写道：【[URL=',url,']原帖[/URL]】\n',hehe.value,'[/QUOTE]');
	speak.value=sm.str();
	speak.focus();
}
$('announceid').value = announceid;
if(she){she.value = "Re: " + title;}
function blog(){
sm.add("http://blog.soufun.com/blog_")
if(userid>0){sm.add(userid);}else{sm.add(username);}
sm.add(".htm");
}
return false;
}
function cimage(url){
var speak =$('speak');
if(editor&&editor.checked){
EditorImg(url);
}else if(speak){
speak.value += "[IMG]"+url+"[/IMG]\r";
speak.focus();
}
}
function CAddtag(tagText,i){
var text=tag();
var speak =$('speak');
if(editor&&editor.checked){
	InsertHtml(text,true);
}else if(speak){
	speak.value+=text;
	speak.focus();
}
function tag(){
var t='(图';
if(i){t+=i;}
return t+':'+tagText+')';
}
}
function CAddtagWithNewline(tagText,i){
var text=tag();
var speak =$('speak');
if(editor&&editor.checked){
	InsertHtml(text,true);
}else if(speak){
	speak.value+=text;
	speak.focus();
}
function tag(){
var t='(图';
if(i){t+=i;}
return t+':'+tagText+')\r';
}
}
function showchange(obj,fun){
var index=obj.selectedIndex;
var value=obj.options[index].value;
if(index>0){fun(value);obj.selectedIndex=0;}
}
function $(ID){return document.getElementById(ID);}
function _(name){return window.frames[name];}
function $$(iframe,ID){return iframe.getElementById(ID);}
function iframedoc(browser,name){
	if(browser>1)
	{
	//debugger;
		var v_editoriframe=document.getElementById(name+'Iframe');
		if(v_editoriframe.contentDocument){return v_editoriframe.contentDocument;} 
		else if (v_editoriframe.contentWindow){return v_editoriframe.contentWindow.document;}
		else if (v_editoriframe.document){return v_editoriframe.document;}

		//return document.getElementById(name+'Iframe').contentWindow.document;
	}
	else{return _(name+'Iframe').document;}
}
function StrMaker(){
this.arr = new Array();
this.str = function(){return this.arr.join('');}
this.add = function(){this.arr.push.apply(this.arr, arguments);}
this.size = function(w,h){if(w>0){this.add(' width="',w,'"');if(h>0){this.add(' height="',h,'"');}}}
this.csssize = function(w,h){if(w>0){this.add('width:',w,'px;');if(h>0){this.add('height:',h,'px;');}}}
this.iframe = function(name,w,h){	
	this.add('<iframe name="',name,'" id="',name,'" frameborder="0" style="');
	this.csssize(w,h);
	this.add('padding:0;margin:0;border:0;"></iframe>');
}
}
function CheckFileType(type,file){
if(file.match(/http:\/\/.{3,}/)){
var fileName=GetName("/");
var Ext=GetExt(fileName);
	switch(type){
	case 'image':return image();
	case 'flash':return flash();
	case 'REAL':return media();
	case 'MEDIA':return media();
	default:return true;
	}
} else{
alert(Editor.MSG['INPUT_URL']);
return false;
}
return false;

function image(){
if(Ext!='gif'&&Ext!='jpg'&&Ext!='png'&&Ext!='bmp'){alert(Editor.MSG['INVALID_IMAGE']);}else{return true;}
}
function flash(){
if(Ext!='swf'){alert(Editor.MSG['INVALID_FLASH']);}else{return true;}
}
function media(){
if(type=='REAL'){
	if(Ext!='rm'&&Ext!='rmvb'){alert(Editor.MSG['INVALID_REAL']);}else{return true;}
}else{
	if (Ext!='mp3'&&Ext!='wav'&&Ext!='wma'&&Ext!='wmv'&&Ext!='mid'&&Ext!='avi'&&Ext!='mpg'&&Ext!='asf'){alert(Editor.MSG['INVALID_MEDIA']);}else{return true;}
}
}
function GetExt(){
var temp = fileName.split(".");
var len = temp.length;
var Ext = temp[len-1].toLowerCase();
return Ext;
}
function GetName(separator){
var temp = file.split(separator);
var len = temp.length;
var Name = temp[len-1];
return Name;
}
}
function HtmlToXhtml(str){
str = str.replace(/<br.*?>/gi, "<br />");
str = str.replace(/(<hr\s+[^>]*[^\/])(>)/gi, "$1 />");
str = str.replace(/(<img\s+[^>]*[^\/])(>)/gi, "$1 />");
str = str.replace(/(<\w+)(.*?>)/gi,function ($0,$1,$2){return($1.toLowerCase()+ConvertAttribute($2));});
str = str.replace(/(<\/\w+>)/gi,function ($0,$1){return($1.toLowerCase());});
return str;
}
function ConvertAttribute(str){
var re = new RegExp("(\\son[a-z]+=)[\"']?[^>]*?[^\\\\\>][\"']?([\\s>])","ig");
return str.replace(re, function ($0,$1,$2){return($1.toLowerCase() + "\"\"" + $2);});
}
function ClearScriptTag(str){
return str.replace(/<\/?(script.*?)>/gi, "[$1]");
}
function Htmlentities(str)
{
	str = str.replace(/&/g,'&amp;');
	str = str.replace(/</g,'&lt;');
	str = str.replace(/>/g,'&gt;');
	str = str.replace(/"/g,'&quot;');
	return str;
}
function GetPos(id,type,begin){
var offset=0,pos=top,tmp = '';
if(type=='Left'){pos=left;}
if(begin>0){offset=begin;}
var obj = document.getElementById(id);
while (eval("obj" + tmp).tagName != "BODY") {
	tmp += ".offsetParent";
	offset += pos(eval("obj" + tmp));
}
return offset;

function left(obj){
return obj.offsetLeft;
}
function top(obj){
return obj.offsetTop;
}
}
function DisableMenu(){
var menu=$('menuDiv');
menu.innerHTML = '';
menu.style.display = 'none';
}
function GetMenuCommonStyle(){
var border = '#AAAAAA';
var sm = new StrMaker();
sm.add('position:absolute;top:1px;left:1px;color:');
sm.add(Editor.COLOR['MENU'], ';background-color:', Editor.BG['MENU']);
sm.add(';border:solid 1px ', border, ';z-index:1;display:none;');
sm.add(';z-index:1;display:none;');
return sm.str();
}
function GetCommonMenu(cmd, content){
var sm = new StrMaker();
sm.add('<div id="POPUP_', cmd, '" style="', GetMenuCommonStyle(), '">');
sm.add(content, '</div>');
return sm.str();
}
function PopupMenu(cmd){
switch (cmd){
case 'fontname':return font(Editor.FONTNAME);
case 'fontsize':return font(Editor.FONTSIZE);
case 'TEXTCOLOR':return color();
case 'SPECIALCHAR':return special();		
case 'IMAGE':return iframe(300);
case 'FLASH':return iframe(330);
case 'MEDIA':return iframe(330);
case 'REAL':return iframe(330);
case 'LINK':return iframe(60);
case 'QUOTE':return iframe(85);
default:return '';
}

function font(menu){
var fun=sizestr,sm = new StrMaker();
if(cmd!='fontsize'){fun=namestr;}
sm.add('<div id="POPUP_', cmd, '" style="', GetMenuCommonStyle(), '">');
for (i = 0; i < menu.length; i++) {
	sm.add('<div style="');
	fun(menu[i]);
	sm.add('padding:2px;cursor:pointer;" ');
	sm.add('onclick="ExecValue(\'',cmd,'\', \'',menu[i][0],'\');" '); 
	sm.add('onmouseover="this.style.backgroundColor=\'',Editor.COLOR['SELECTED'],'\';" ');
	sm.add('onmouseout="this.style.backgroundColor=\'',Editor.BG['MENU']+'\';">'); 
	sm.add(menu[i][1],'</div>');
}
sm.add('</div>');
return sm.str();
function namestr(obj){style('font-family',obj[0],160);}
function sizestr(obj){style('font-size',obj[1],120);}
function style(name,value,width){sm.add(name,':',value,';',width,'px;');}
}
function color(){
var table=Editor.COLORTABLE;
var sm = new StrMaker();
sm.add('<div id="POPUP_', cmd, '" style="width:160px;padding:2px;');
sm.add(GetMenuCommonStyle(), '">');
sm.add('<table cellpadding="0" cellspacing="2" border="0">');
for (i = 0; i < table.length; i++){
	if (i%10==0){if(i>0){sm.add('</tr><tr>');}else{sm.add('<tr>');}}
	sm.add('<td style="width:12px;height:12px;border:1px solid #AAAAAA;font-size:1px;cursor:pointer;background-color:');
	sm.add(table[i], ';" onmouseover="this.style.borderColor=\'#000000\';"');
	sm.add(' onmouseout="this.style.borderColor=\'#AAAAAA\';" '); 
	sm.add(' onclick="ExecValue(\'ForeColor\', \'');
	sm.add(table[i], '\');">&nbsp;</td>');
}
sm.add('</tr></table>');
sm.add('</div>');
return sm.str();
}
function special(){
var chars = Array(
	'§','№','☆','★','○','●','◎','◇','◆','□','℃','‰','■','△','▲','※',
	'→','←','↑','↓','〓','¤','°','＃','＆','＠','＼','︿','＿','￣','―','α',
	'β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ',
	'σ','τ','υ','φ','χ','ψ','ω','≈','≡','≠','＝','≤','≥','＜','＞','≮',
	'≯','∷','±','＋','－','×','÷','／','∫','∮','∝','∞','∧','∨','∑','∏',
	'∪','∩','∈','∵','∴','⊥','∥','∠','⌒','⊙','≌','∽','〖','〗',
	'【','】','（','）','［','］'
);
var sm = new StrMaker();
sm.add('<table id="POPUP_',cmd,'" cellpadding="0" cellspacing="2" style="',GetMenuCommonStyle(),'">');
for (i = 0; i < chars.length; i++) {
	if (i%10==0){if(i>0){sm.add('</tr><tr>');}else{sm.add('<tr>');}}
	sm.add('<td style="padding:2px;border:1px solid #AAAAAA;cursor:pointer;" '); 
	sm.add('onclick="ExecValue(\'special\', \'',chars[i],'\');" ');
	sm.add('onmouseover="this.style.borderColor=\'#000000\';" ');
	sm.add('onmouseout="this.style.borderColor=\'#AAAAAA\';">',chars[i],'</td>');
}
sm.add('</tr></table>');
return sm.str();
}
function iframe(height){
var sm = new StrMaker();
sm.add('<div id="POPUP_',cmd,'" style="width:250px;',GetMenuCommonStyle(),'">');
sm.iframe(cmd+'Iframe',250,height);
sm.add('</div>');
return sm.str();
}
}
function ImgTest(url,width,height){
var img=new Image();
img.src=url;
var rate,w=img.width,h=img.height;
w=w?w:width;h=h?h:height;
rate=w/h;
if(height&&width<w&&h>height){
var rate0=width/height;
	if(rate>rate0){w=width;h=parseInt(w/rate);}
	else{h=height;w=parseInt(h*rate);}
}
else if(w>width){w=width;h=parseInt(w/rate);}
else if(h>height){h=height;w=parseInt(height*rate);}
img.width = w;
img.height = h;
return img;
}
function EditorImage(view){
var url = iframedoc(Editor.BROWSER,'IMAGE').getElementById('imgLink').value;
if (CheckFileType('image',url)==false){return false;}
if(view){
	var imgtmp = ImgTest(url,230,230);
	var imgObj = iframedoc(Editor.BROWSER,'IMAGE').createElement("IMG");
	imgObj.src = url;
	if(imgtmp.width){imgObj.width=imgtmp.width;}
	if(imgtmp.height){imgObj.height=imgtmp.height;}
	var el = iframedoc(Editor.BROWSER,'IMAGE').getElementById('imgPreview');
	if(el.hasChildNodes()){el.removeChild(el.childNodes[0]);}
	el.appendChild(imgObj);
} else{EditorImg(url);}
}
function EditorImg(url){
//var imgtmp = ImgTest(url);c
var sm = new StrMaker();
sm.add('<img src="',url,'"');
//if(imgtmp.width>560){sm.add(' onload="InitImageWidth(this);"');}
sm.add(' onload="InitImageWidth(this);"');
sm.add(' />');
InsertHtml(sm.str(),true);
}
function EditorFlash(view){
var doc=iframedoc(Editor.BROWSER,'FLASH');
var url = doc.getElementById('flashLink').value;
if (CheckFileType('flash',url)){
if(view){
	var el = doc.getElementById('flashPreview');
	el.innerHTML = tag(230,230);
} else{
	var width = doc.getElementById('flashWidth').value;
	var height = doc.getElementById('flashHeight').value;
	if (width.match(/^\d+$/) == null) {
		alert(Editor.MSG['INVALID_WIDTH']);
		return false;
	}
	if (height.match(/^\d+$/) == null) {
		alert(Editor.MSG['INVALID_HEIGHT']);
		return false;
	}
	InsertHtml(tag(width,height),true);
}
}

function tag(w,h){
var sm = new StrMaker();
sm.add('<embed src="', url);
sm.add('" type="application/x-shockwave-flash"');
sm.size(w,h);
sm.add(' quality="high" />');
return sm.str();
}
}
function EditorQuote(){Editorquote(iframedoc(Editor.BROWSER,'QUOTE').getElementById('quotetext').value);}
function Editorquote(text){
if(text.length>0){InsertHtml(tag(text),true);}

function tag(){
return '<TABLE CLASS=quote><TR><TD><TABLE CLASS=quote_txt><TR><TD>'+text+'</TD></TR></TABLE></TD></TR></TABLE>';
}
}
function EditorMedia(cmd,view){
var doc;
if(cmd == 'REAL'){doc = iframedoc(Editor.BROWSER,'REAL');}
else{doc = iframedoc(Editor.BROWSER,'MEDIA');}
var url = doc.getElementById(cmd+'link').value;
if(CheckFileType(cmd,url)){
if(view){
	doc.getElementById(cmd+'preview').innerHTML = tag(230,230);
} else{
	var width = doc.getElementById(cmd+'Width').value;
	var height = doc.getElementById(cmd+'Height').value;
	if (width.match(/^\d+$/) == null) {
		alert(Editor.MSG['INVALID_WIDTH']);
		return false;
	}
	if (height.match(/^\d+$/) == null) {
		alert(Editor.MSG['INVALID_HEIGHT']);
		return false;
	}
	InsertHtml(tag(width,height),true);
}
}

function tag(w,h){
var sm = new StrMaker();
sm.add('<embed src="', url);
sm.add('" type="');
if(cmd=="ED_REAL"){sm.add("audio/x-pn-realaudio-plugin");}
else{sm.add("video/x-ms-asf-plugin");}
sm.add('"');
sm.size(w,h);
sm.add(' loop="true"');
sm.add(' autostart="true" />');
return sm.str();
}
}
function EditorLink(){
	var url = iframedoc(Editor.BROWSER,'LINK').getElementById('hyperLink').value;
	if (url.match(/http:\/\/.{3,}/) == null) {
		alert(Editor.MSG['INPUT_URL']);
		return false;
	}
    if(Editor.BROWSER<3) {
	Editor.Win.focus();
	Select();
		if (Editor.SELECTION.type.toLowerCase() == 'control') {
			var el = document.createElement("a");
			el.href = url;
			Editor.RANGE.item(0).applyElement(el);
			DisableMenu();
		} else if (Editor.SELECTION.type.toLowerCase() == 'text') {
			ExecValue('CreateLink', url);
		}
	}else {
		ExecValue('CreateLink', url);
    }	
}

function AddFlashNew(url,detailurls){
	var width=480;
	var height=400;
	var sm = new StrMaker();
	sm.add('<br />');
	sm.add('<embed src="', url);
	sm.add('" type="application/x-shockwave-flash"');
	sm.size(width,height);
	sm.add(' quality="high" />');
	sm.add('<div>');
	sm.add('<a href="');
	sm.add(detailurls);
	sm.add('" target=_blank><img src="http://img1.soufun.com/video/v1.gif" border="0"></a>&nbsp;<a href="http://youku.soufun.com/video/" target=_blank><img src="http://img1.soufun.com/video/v2.gif" border="0"></a>');
	sm.add('</div>')
	InsertHtml(sm.str(),true);
}

function AddFlash(url,detailurls){
	var speak =$('speak');
	if(editor&&editor.checked){
		AddFlashNew(url,detailurls);
	}else if(speak){
		speak.value+='\n[flash=480,400]' + url + '[/flash]';
		speak.focus();
	}
}

function Select(flag){
if(Editor.BROWSER<3){
if(!Editor.RANGE||flag){Selection();};
try{
Editor.RANGE.select();
}catch(err){}
}
}
function Selection(){
try{
if (Editor.BROWSER<3){
	var doc=iframedoc(Editor.BROWSER,'Editor');
	var selection=doc.selection;
	Editor.DOC=doc;
	Editor.SELECTION = selection;
	Editor.RANGE = selection.createRange();
} else {
	Editor.SELECTION = document.getElementById("EditorIframe").contentWindow.getSelection();
	Editor.RANGE = Editor.SELECTION.getRangeAt(0);
}
}catch(err){}
}
function InsertHtml(html,flag){
Editor.Win.focus();
Select(flag);
if(Editor.BROWSER<3) {
	if(Editor.SELECTION.type.toLowerCase() == 'control') {Editor.RANGE.item(0).outerHTML = html;}
	else{Editor.RANGE.pasteHTML(html);}
}else{
	Editor.DOC.execCommand('inserthtml', false, html);
}
DisableMenu();
}
function ExecMenu(cmd){
Editor.Win.focus();
Selection();
DisableMenu();
var top = GetTop(cmd);
var left = GetLeft(cmd);
var str = PopupMenu(cmd);
if(cmd=='QUOTE'){left-= 200;}
var menu=$('menuDiv');	
menu.style.display = 'none';
menu.innerHTML = str;
var popup=$('POPUP_'+cmd);
popup.style.top =  top + 'px';
popup.style.left = left + 'px';
popup.style.display = 'block';
menu.style.display = 'block';

function GetTop(id){return GetPos(id,'Top',28);}
function GetLeft(id){return GetPos(id,'Left',2);}
}

function ExecForm(cmd){
ExecMenu(cmd);
var html;
var doc=iframedoc(Editor.BROWSER,cmd);
	switch (cmd){		
	case 'IMAGE':html=image();break;
	case 'FLASH':html=flash();break;
	case 'MEDIA':html=media();break;
	case 'REAL':html=media();break;
	case 'LINK':html=Link();break;
	case 'QUOTE':html=quote();break;
	default:return;
	}
WriteFullHtml(doc,html);
Editor.Win.focus();
doc.getElementById(cmd+'submitButton').focus();

function image(){
var sm = new StrMaker();
sm.add('<div align="center">');
sm.add('<input type="hidden" name="fileName" id="fileName" value="" />');
sm.add('<table cellpadding="0" cellspacing="0" style="width:100%;">');
sm.add('<tr><td>');
sm.add('<table border="0" style="margin-bottom:3px;"><tr><td id="imgPreview" style="width:240px;height:240px;border:1px solid #AAAAAA;background-color:#FFFFFF;" align="center" valign="middle" colspan="2">&nbsp;</td></tr>');
sm.add('<tr><td style="width:50px;padding-left:5px;">');
sm.add('URL');
sm.add('</td><td style="width:200px;padding-bottom:3px;">');
sm.add('<input type="text" id="imgLink" value="http://" maxlength="255" style="width:95%;border:1px solid #555555;" />');
sm.add('</td>');
sm.add('</tr></table>');
sm.add('</td></tr><tr><td style="margin:5px;padding-bottom:5px;" align="center">');
sm.add('<input type="button" name="button" value="',Editor.MSG['PREVIEW'],'" onclick="parent.EditorImage(\'view\');" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /> ');
sm.add('<input type="button" name="button" id="',cmd,'submitButton" value="',Editor.MSG['CONFIRM'],'" onclick="parent.EditorImage();" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /> ');
sm.add('<input type="button" name="button" value="',Editor.MSG['CANCEL'],'" onclick="parent.DisableMenu();" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /></td></tr>');
sm.add('</table></div>');
return sm.str();
}
function flash(){
var sm = new StrMaker();
sm.add('<table cellpadding="0" cellspacing="0" style="width:100%;">'); 
sm.add('<tr><td colspan="2"><table border="0"><tr><td id="flashPreview" style="width:240px;height:240px;border:1px solid #AAAAAA;background-color:#FFFFFF;" align="center" valign="middle">&nbsp;</td></tr></table></td></tr>');  	
sm.add('<tr><td style="width:40px;padding:5px;">URL</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" id="flashLink" value="http://" style="width:190px;border:1px solid #555555;" /></td></tr>');
sm.add('<tr><td colspan="2" align="center">');
sm.add('<table cellpadding="0" cellspacing="0" style="width:80%;">');
sm.add('<tr><td style="width:40px;padding:5px;">',Editor.MSG['WIDTH'],'</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" name="flashWidth" id="flashWidth" value="480" maxlength="3" style="width:40px;border:1px solid #555555;" /></td>');
sm.add('<td style="width:40px;padding:5px;">',Editor.MSG['HEIGHT'],'</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" name="flashHeight" id="flashHeight" value="360" maxlength="3" style="width:40px;border:1px solid #555555;" /></td></tr>');
sm.add('</table>');
sm.add('</td></tr>');
sm.add('<tr><td colspan="2" style="margin:5px;padding-bottom:5px;" align="center">');
sm.add('<input type="button" name="button" value="',Editor.MSG['PREVIEW'],'" onclick="parent.EditorFlash(\'view\');" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /> ');
sm.add('<input type="submit" name="button" id="',cmd,'submitButton" value="',Editor.MSG['CONFIRM'],'" onclick="parent.EditorFlash();" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /> ');
sm.add('<input type="button" name="button" value="',Editor.MSG['CANCEL'],'" onclick="parent.DisableMenu();" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /></td></tr>');
sm.add('</table>');
return sm.str();
}
function media(){
var sm = new StrMaker();
sm.add('<table cellpadding="0" cellspacing="0" style="width:100%;">');
sm.add('<tr><td colspan="2"><table border="0"><tr><td id="', cmd);
sm.add('preview" style="width:240px;height:240px;border:1px solid #AAAAAA;');
sm.add('background-color:#FFFFFF;" align="center" valign="middle">&nbsp;</td></tr></table></td></tr>');	
sm.add('<tr><td style="width:40px;padding:5px;">URL</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" id="');
sm.add(cmd, 'link" value="http://" style="width:190px;border:1px solid #555555;" /></td></tr>');
sm.add('<tr><td colspan="2" align="center">');
sm.add('<table cellpadding="0" cellspacing="0" style="width:80%;">');
sm.add('<tr><td style="width:40px;padding:5px;">',Editor.MSG['WIDTH'],'</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" name="',cmd,'Width" id="',cmd,'Width" value="480" maxlength="3" style="width:40px;border:1px solid #555555;" /></td>');
sm.add('<td style="width:40px;padding:5px;">',Editor.MSG['HEIGHT'],'</td>');
sm.add('<td style="width:210px;padding-bottom:5px;"><input type="text" name="',cmd,'Height" id="',cmd,'Height" value="360" maxlength="3" style="width:40px;border:1px solid #555555;" /></td></tr>');
sm.add('</table>');
sm.add('</td></tr>');
sm.add('<tr><td colspan="2" style="margin:5px;padding-bottom:5px;" align="center">');
sm.add('<input type="button" name="button" value="', Editor.MSG['LISTENING']);
sm.add('" onclick="parent.EditorMedia(\'', cmd,'\',\'view\');"');
sm.add(' style="border:1px solid #555555;background-color:', Editor.COLOR['BUTTON'], ';" /> ');
sm.add('<input type="submit" name="button" id="', cmd, 'submitButton" value="');
sm.add(Editor.MSG['CONFIRM'], '" onclick="parent.EditorMedia(\'');
sm.add(cmd, '\');" style="border:1px solid #555555;background-color:');
sm.add(Editor.COLOR['BUTTON'], ';" /> ');
sm.add('<input type="button" name="button" value="');
sm.add(Editor.MSG['CANCEL'], '" onclick="parent.DisableMenu();"');
sm.add('style="border:1px solid #555555;background-color:', Editor.COLOR['BUTTON'], ';" />');
sm.add('</td></tr></table>');
return sm.str();
}
function Link(){
var sm = new StrMaker();
sm.add('<table cellpadding="0" cellspacing="0" style="width:100%;">');
sm.add('<tr><td style="width:50px;padding:5px;">URL</td>');
sm.add('<td style="width:200px;padding-top:5px;padding-bottom:5px;"><input type="text" id="hyperLink" value="http://" style="width:190px;border:1px solid #555555;background-color:#FFFFFF;"></td>');
sm.add('<tr><td colspan="2" style="padding-bottom:5px;" align="center">');
sm.add('<input type="submit" name="button" id="',cmd,'submitButton" value="',Editor.MSG['CONFIRM'],'" onclick="parent.EditorLink();" style="border:1px solid #555555;background-color:'+Editor.COLOR['BUTTON']+';" /> ');
sm.add('<input type="button" name="button" value="',Editor.MSG['CANCEL'],'" onclick="parent.DisableMenu();" style="border:1px solid #555555;background-color:',Editor.COLOR['BUTTON'],';" /></td></tr>');
sm.add('</table>');
return sm.str();
}
function quote(){
var sm = new StrMaker();
sm.add('<table>');
sm.add('<tr><td><textarea style="width:240px;height:50px;" id="quotetext" name="quotetext">请输入引用文字，完成后点击"确定引用"</textarea>');
sm.add('</td></tr>');
sm.add('<tr><td align="center">');
sm.add('<input type="submit" name="button" id="', cmd, 'submitButton" value="');
sm.add(Editor.MSG['CONFIRM'], '" onclick="parent.EditorQuote();"');
sm.add(' style="border:1px solid #555555;background-color:');
sm.add(Editor.COLOR['BUTTON'], ';" /> ');
sm.add('<input type="button" name="button" value="');
sm.add(Editor.MSG['CANCEL'], '" onclick="parent.DisableMenu();"');
sm.add('style="border:1px solid #555555;background-color:', Editor.COLOR['BUTTON'], ';" />');
sm.add('</td></tr>');
sm.add('</table>');
return sm.str();
}
}
function ExecValue(cmd, value){
if(cmd=='special'){
InsertHtml(value);
} else{
Editor.Win.focus();
Select();
Editor.DOC.execCommand(cmd, false, value);
DisableMenu();
}
}
function ExecText(cmd){
Editor.Win.focus();
Editor.DOC.execCommand(cmd, false, null);
DisableMenu();
}
function ExecRemove(){ExecText('removeformat');}
function WriteFullHtml(doc,str){
var sm=new StrMaker();
sm.add('<html>');
sm.add('<head>');
sm.add('<style type="text/css">');
sm.add('.quote{border-style:dashed;border-width:1px; width:94%;margin-left:18px;}');
sm.add('.quote_txt{ width:100%; margin:0px; padding-left:20px;border:none; font-size:13px; }');
sm.add('</style>');
sm.add('</head>');
sm.add('<body>');
sm.add(str);
sm.add('</body>');
sm.add('</html>');
doc.open();
doc.write(sm.str());
doc.close();
doc.body.style.margin = 0;
doc.body.scroll = 'no';
}
function Editorshow(flag){if(editor){editor.show(flag);};return false;}
function Editorhidden(flag){if(editor){editor.hidden(flag);}return false;}
function Editor(Name,div,flag){
	var skin="http://img2.soufunimg.com/homebbs/editor/";
	var content=flag?getvalue(Name):'';
	this.editor=null;
	this.editor0=null;
	this.checked=false;
	this.EditorDiv=$(div);
	this.hiddenName=Name;
	this.html=EditorStr(530,300);	
	this.html0=OldEditor();
	Editor.BROWSER = browser();
	this.EditorDiv.innerHTML='';
	this.show = function(flag){
		if(Editor.BROWSER<1){this.hidden();return;}
		this.checked=true;		
		if(this.editor0){this.editor0.style.display='none';}
		if(this.editor){this.editor.style.display='block';return;}		
		var editorstr=this.html;
		if(flag){editorstr+=change(1);}
		this.editor=document.createElement("div");		
		this.editor.innerHTML=editorstr;
		this.EditorDiv.appendChild(this.editor);
		var doc=iframedoc(Editor.BROWSER,'Editor');
		WriteFullHtml(doc,content);
		doc.designMode='on';
		try{
			var editorbody=null;
			var v_editoriframe=document.getElementById('EditorIframe');
			if(v_editoriframe.contentDocument){editorbody= v_editoriframe.contentDocument.body;} 
			else if (v_editoriframe.contentWindow){editorbody= v_editoriframe.contentWindow.document;}
			else if (v_editoriframe.document){editorbody= v_editoriframe.document.body;}
			editorbody.onclick=DisableMenu;		
		}
		catch(e){};
		Editor.DOC=doc;
		Editor.Win=_("EditorIframe");
		Editor.Win.InitImageWidth=InitImageWidth;
	}
	this.hidden = function(flag){
		this.checked=false;		
		if(this.editor){this.editor.style.display='none';}
		if(this.editor0){this.editor0.style.display='block';return;}
		this.editor0=document.createElement("div");	
		var editorstr=this.html0;
		if(flag){editorstr+=change();}
		this.editor0.innerHTML=editorstr;
		this.EditorDiv.appendChild(this.editor0);
	}
	this.value = function(){
	if(this.checked)
	{
		var str="";//Editor.DOC.body.innerHTML;
		var v_editoriframe=document.getElementById('EditorIframe');
		if(v_editoriframe.contentDocument){str= v_editoriframe.contentDocument.body.innerHTML;} 
		else if (v_editoriframe.contentWindow){str= v_editoriframe.contentWindow.document.body.innerHTML;}
		else if (v_editoriframe.document){str= v_editoriframe.document.body.innerHTML;}
		return str;
	}
	else{return getvalue('speak');}	
	}
	this.data = function(){
	if(this.checked){
	var re=/<\/?tbody>/g;
	//debugger;
	var str="";//Editor.DOC.body.innerHTML;
	var v_editoriframe=document.getElementById('EditorIframe');
	if(v_editoriframe.contentDocument){str= v_editoriframe.contentDocument.body.innerHTML;} 
	else if (v_editoriframe.contentWindow){str= v_editoriframe.contentWindow.document.body.innerHTML;}
	else if (v_editoriframe.document){str= v_editoriframe.document.body.innerHTML;}
		
	str=str.replace(re,'');
	setvalue(this.hiddenName,str);
	setvalue('speak','');
	}
	}
	this.focus = function(){if(this.checked){Editor.Win.focus();}else{$('speak').focus();}}

function change(flag){
var fun='show',mode0='旧',mode1='新',sm = new StrMaker();
if(flag){fun='hidden';mode0='新';mode1='旧';}
sm.add('<table width="532px"  style="border:1px solid #AAAAAA;border-top:0px;background-color:rgb(240, 240, 240);">');
sm.add('<tr>');
sm.add('<td width="10"></td>');
sm.add('<td width="300"/>当前使用模式：',mode0,'版编辑器</td>');
sm.add('<td width="100" height="30px;"><a href="#" onclick="return Editor',fun,'(1);"> <img width="21" height="20" align="absmiddle"  border=0  src="http://img2.soufunimg.com/bbs/image/bbs/post/mode.design.gif"/>使用',mode1,'版</a></td>');
sm.add('<td width="10"/></td>');
sm.add('</tr>');
sm.add('</table>');
return sm.str();
}	
function getvalue(name){
var node=$(name);
if(node){return node.value;}else{return '';}
}
function setvalue(name,str){
var node=$(name);
if(node){node.value=str;}
}
function EditorStr(width,height){
var sm = new StrMaker();
sm.add('<div style="');
sm.csssize(width,0);
sm.add('border:1px solid #DDDDDD;background-color:',Editor.BG['TOOLBAR'], '">');
sm.add(Toolbar());
sm.add('</div>');
sm.add('<div style="border:1px solid #DDDDDD;');
sm.csssize(width,0);
sm.add('border-top:0;">');
sm.iframe('EditorIframe',width-2,height);
sm.add('</div>');
sm.add('<div id="menuDiv"></div>');
return sm.str();
}
function Icon(obj){
var sm=new StrMaker();
sm.add('<img id="',obj[0],'" src="',skin,obj[1],'" alt="',obj[2]);
sm.add('" title="',obj[2]);
sm.add('" align="absmiddle" style="border:1px solid ',Editor.BG['TOOLBAR'],';cursor:pointer;height:20px;');
sm.add('" onclick="Exec',obj[3],'(\'',obj[0],'\');" ');
sm.add('>');
return sm.str();
}
function OldEditor(){
var bar = Array(
Array('button1','粗体','Cbold()'),
Array('button2','斜体','Citalic()'),
Array('button3','下划线','Cunder()'),
Array('button4','居中','Ccenter()'),
Array('button5','超级连接','Curl()'),
Array('button6','添加图片','Cimage5()'),
Array('swf','插入Flash','Cflash(\'speak\')'),
Array('mp','插入Windows Media','Cwmv(\'speak\')'),
Array('rm','插入Real Media','Crm(\'speak\')'),
Array('csound','插入MP3','Cmp3(\'speak\')')
);
var font=Editor.FONTNAME;
var color=Editor.COLORTABLE;
var sm = new StrMaker();
for (var i=0;i<bar.length;i++){sm.add('<IMG onclick="',bar[i][2],'" alt="',bar[i][1],'" src="',skin,bar[i][0],'.gif" />');}
sm.add('<select id="font" name="font" style="WIDTH: 100px" onchange="showchange(this,showfont)">');
for (var i=0;i<font.length;i++){sm.add('<option value="',font[i][0],'">',font[i][1],'</option>');}
sm.add('</select>');
sm.add('<select id="size" name="size" onchange="showchange(this,showsize)">');
for (var i=1;i<5;i++){
	sm.add('<option value="',i,'"');
	if(i==3){sm.add('  selected="selected"');}
	sm.add('>',i,'</option>');
}
sm.add('</select>');
sm.add('<select id="select" name="select" onchange="showchange(this,showcolor)">');
for (var i=0;i<color.length;i++){sm.add('<option style="COLOR:',color[i],'; BACKGROUND-COLOR:',color[i],'" value="',color[i],'">',color[i],'</option>');}
sm.add('</select>');
sm.add('<IMG onclick="Cquote2()" alt="引用" src="',skin,'button7.gif" /><br />');
sm.add('<TEXTAREA id="speak"  tabIndex="2" name="speak" rows="10" wrap="PHYSICAL"  style ="width:530px;" title="您可以使用Ctrl+Enter直接提交贴子" onkeydown="CtrlEnt()"></TEXTAREA>');
return sm.str();
}
function Toolbar(){
var bar = Array(
Array('bold','bold.gif','粗体','Text'),					
Array('italic','italic.gif','斜体','Text'),
Array('underline','underline.gif','下划线','Text'),
Array('justifyleft','justifyleft.gif','左对齐','Text'),
Array('justifycenter','justifycenter.gif','居中','Text'),
Array('justifyright','justifyright.gif','右对齐','Text'),
Array('LINK','link.gif','创建超级链接','Form'),
Array('IMAGE','image.gif','插入图片文件 支持类型:gif,jpg,png,bmp','Form'),
Array('FLASH','flash.gif','插入Flash文件 支持类型:swf','Form'),
Array('MEDIA','media.gif','插入Windows Media Player文件\n支持类型:mp3,wav,wma,wmv,mid,avi,mpg,asf','Form'),
Array('REAL','real.gif','插入Real Player文件 支持类型:rm,rmvb','Form'),
Array('SPECIALCHAR','specialchar.gif','特殊字符','Menu'),
Array('REMOVE','removeformat.gif','删除格式','Remove'),	
Array('fontname','font.gif','字体','Menu'),
Array('fontsize','fontsize.gif','文字大小','Menu'),
Array('TEXTCOLOR','textcolor.gif','文字颜色','Menu'),
Array('QUOTE','QUOTE.gif','引用','Form')
);
var sm = new StrMaker();
sm.add('<table cellpadding="0" cellspacing="0" border="0" height="26"><tr>');
for (var i=0;i<bar.length;i++){sm.add('<td style="padding:2px;">',Icon(bar[i]),'</td>');}
sm.add('</tr></table>');
return sm.str();
}
function browser(){
var b=0,v=0,agent=navigator.userAgent.toLowerCase();
var temp = agent.split('/');
var l=temp.length;
if(l){v=parseInt(temp[l-1]);}
if(agent.indexOf("msie") > -1) {
	var re = new RegExp("msie\\s?([\\d\\.]+)","ig");	
	var arr = re.exec(agent);
	v = parseInt(RegExp.$1);
	if(v>=6){b=2;}
	else if(v>=5){b=1;}
}
else if(agent.indexOf("firefox") > -1){b = 3;}
else if(agent.indexOf("netscape") > -1){if(v>=7){b = 3;}}
else if(agent.indexOf("gecko") > -1){b = 3;}
else if(agent.indexOf("opera") > -1){if(v>=9){b = 3;}}
return b;
}
}
Editor.COLORTABLE=Array(
	"#000000","#2F4F4F","#708090","#778899","#4682B4","#FF00FF","#FFFFFF","#F5F5F5","#DCDCDC","#FFFAFA",
	"#D3D3D3","#C0C0C0","#A9A9A9","#808080","#696969","#FF0000","#FFFF00","#00FF00","#00FFFF","#0000FF",
	"#4169E1","#6495ED","#B0C4DE","#7B68EE","#6A5ACD","#483D8B","#191970","#000080","#00008B","#0000CD",
	"#1E90FF","#00BFFF","#87CEFA","#87CEEB","#ADD8E6","#B0E0E6","#F0FFFF","#E0FFFF","#AFEEEE","#00CED1",
	"#5F9EA0","#48D1CC","#00FFFF","#40E0D0","#20B2AA","#008B8B","#008080","#7FFFD4","#66CDAA","#8FBC8F",
	"#3CB371","#2E8B57","#006400","#008000","#228B22","#32CD32","#00FF00","#7FFF00","#7CFC00","#ADFF2F",
	"#98FB98","#90EE90","#00FF7F","#00FA9A","#556B2F","#6B8E23","#808000","#BDB76B","#B8860B","#DAA520",
	"#FFD700","#F0E68C","#EEE8AA","#FFEBCD","#FFE4B5","#F5DEB3","#FFDEAD","#DEB887","#D2B48C","#BC8F8F",
	"#A0522D","#8B4513","#D2691E","#CD853F","#F4A460","#8B0000","#800000","#A52A2A","#B22222","#CD5C5C",
	"#F08080","#FA8072","#E9967A","#FFA07A","#FF7F50","#FF6347","#FF8C00","#FFA500","#FF4500","#DC143C",
	"#FF0000","#FF1493","#FF00FF","#FF69B4","#FFB6C1","#FFC0CB","#DB7093","#C71585","#800080","#8B008B",
	"#9370DB","#8A2BE2","#4B0082","#9400D3","#9932CC","#BA55D3","#DA70D6","#EE82EE","#DDA0DD","#D8BFD8",
	"#E6E6FA","#F8F8FF","#F0F8FF","#F5FFFA","#F0FFF0","#FAFAD2","#FFFACD","#FFF8DC","#FFFFE0","#FFFFF0",
	"#FFFAF0","#FAF0E6","#FDF5E6","#FAEBD7","#FFE4C4","#FFDAB9","#FFEFD5","#FFF5EE","#FFF0F5","#FFE4E1"
);
Editor.COLOR={MENU:'#222222',SELECTED:'#CCCCCC',BUTTON:'#AAAAAA'};
Editor.BG={MENU:'#EFEFEF',TOOLBAR:'#EFEFEF'};
Editor.MSG={
	INPUT_URL		: "请输入正确的URL地址。",
	SELECT_IMAGE	: "请选择图片。",
	INVALID_IMAGE	: "只能选择GIF,JPG,PNG,BMP格式的图片，请重新选择。",
	INVALID_FLASH	: "只能选择SWF格式的文件，请重新选择。",
	INVALID_MEDIA	: "只能选择MP3,WAV,WMA,WMV,MID,AVI,MPG,ASF格式的文件，请重新选择。",
	INVALID_REAL	: "只能选择RM,RMVB格式的文件，请重新选择。",
	INVALID_WIDTH	: "宽度不是数字，请重新输入。",
	INVALID_HEIGHT	: "高度不是数字，请重新输入。",
	INVALID_BORDER	: "边框不是数字，请重新输入。",
	INVALID_HSPACE	: "横隔不是数字，请重新输入。",
	INVALID_VSPACE	: "竖隔不是数字，请重新输入。",
	INPUT_CONTENT	: "请输入内容",
	WIDTH			: "宽",
	HEIGHT			: "高",
	CONFIRM			: "确定",
	CANCEL			: "取消",
	PREVIEW			: "预览",
	LISTENING		: "试听"
};
Editor.FONTNAME = Array(
	Array('SimSun', '宋体'), 
	Array('SimHei', '黑体'), 
	Array('FangSong_GB2312', '仿宋体'), 
	Array('KaiTi_GB2312', '楷体'), 
	Array('NSimSun', '新宋体'), 
	Array('Arial', 'Arial'), 
	Array('Arial Black', 'Arial Black'), 
	Array('Times New Roman', 'Times New Roman'), 
	Array('Courier New', 'Courier New'), 
	Array('Tahoma', 'Tahoma'), 
	Array('Verdana', 'Verdana'), 
	Array('GulimChe', 'GulimChe'), 
	Array('MS Gothic', 'MS Gothic') 
);
Editor.FONTSIZE = Array(
	Array(1,'8pt'), 
	Array(2,'10pt'), 
	Array(3,'12pt'), 
	Array(4,'14pt'), 
	Array(5,'18pt')
);
Editor.Win=null;
Editor.DOC=null;
Editor.SELECTION=null;
Editor.RANGE=null;
Editor.BROWSER=0;
Editor.MenuStyle=null;

