﻿
dcs.post=new Object();


dcs.post.doInit=function()
{
	this.config=new Array();
	this.config["icon_total"]=9;
}
dcs.post.doInit();

dcs.post.getIcon=function(strinput,strvalue)
{
	if (strinput=="" || strinput==null) strinput="icon";
	var re="";
	for(var i=0;i<=this.config["icon_total"];i++)
	{
		if (i==0) re+="<img class=\"icon\" src=\""+dcs.config.getURL("common.smiley")+"icon/no.gif\">";
		else re+="<img class=\"icon\" src=\""+dcs.config.getURL("common.smiley")+"icon/"+i+".gif\">";
		re+="<input type=\"radio\" name=\""+strinput+"\" class=\"normal\" value=\""+i+"\"";
		if (strvalue==i) { re+=" checked"; }
		re+="> &nbsp;";
	}
	return re;
}

dcs.post.getColorBox=function(strinput,strcolor)
{
	var tmid="editor_color_"+strinput;
	if (strcolor=="" || strcolor==null) strcolor="000000";
	var re="";
	re+="<input id="+tmid+" type=\"text\" class=\"normal hand\" onClick=\"javascript:dcs.post.doColorChoose('"+strinput+"','"+tmid+"');\" style=\"width:18px; height:17px; background:#"+strcolor+" url('"+dcs.config.getURL("common.editor")+"images/ico_color_box.gif') no-repeat 0px 0px;\" readonly>";
	re+=" <a href=\"javascript:;\" onClick=\"javascript:dcs.post.doColorChoose('"+strinput+"','"+tmid+"');\">选取颜色</a>";
	return re;
}

dcs.post.doColorChoose=function(strinput,strid)
{
	var tmpcolor=window.showModalDialog(dcs.config.getURL("common.editor")+"dialog/win.color.html","s","dialogWidth=300px; dialogHeight=295px; status=0");
	if (tmpcolor && tmpcolor!="")
	{
		if (strid!="" && strid != null)
		{
			eval("document.all."+strid+".bgColor=tmpcolor;");	//window.document.all.item("bordercolor").bgColor=tmpcolor;
		}
		if (tmpcolor.length==7) { tmpcolor=tmpcolor.substr(1,tmpcolor.length); }
		dcs.form.setValue(strinput,tmpcolor);
	}
}

dcs.post.doTextareaResize=function(strRemark,strType,strSize)
{
	var tmpObject=strRemark;
	if (!isObject(tmpObject)) tmpObject=dcs.form.getElement(strRemark);
	var tmpSize=(strSize==null) ? 5 : strSize;
	var tmpRows=tmpSize;
	if (strType=="-") { tmpRows=-tmpSize; }
	if (parseInt(tmpObject.rows)+tmpRows>=tmpSize) { tmpObject.rows = parseInt(tmpObject.rows) + tmpRows; }
	//if (tmpRows>0) { tmpRows.width="90%"; }
}

//<input type=test name=tim value='2003-5-19' size=12 maxlength=10 readonly>
//<input type="button" class="btns" name="btn_select_tim" value="选择" onclick="javascript:dcs.post.getTimeChoose(tim);">
dcs.post.getTimeChoose=function(strInput,strtype)
{
	var tmpObject=dcs.form.getElement(strInput);
	if (strtype==null) strtype="";
	var tmpx=event.screenX-event.offsetX-14;
	var tmpy=event.screenY-event.offsetY-168;
	var tmpValue=window.showModalDialog(dcs.config.getURL("common.editor")+"dialog/win.time.html?time="+tmpObject.value+"&type="+strtype,"","dialogWidth:197px; dialogHeight:235px; dialogLeft:"+tmpx+"px; dialogTop:"+tmpy+"px; status:no; directories:yes;scrollbars:no;Resizable=no;");
	if( tmpValue!=null ) tmpObject.value=tmpValue;
}

dcs.post.doPreview=function(strName)
{
	var tmpRemark=dcs.editor.tools.getValue(strName);
	//alert(tmpRemark);
	tmpVar="";
	var tmpAry=tmpRemark.split("\r\n");
	for (var i=0;i<tmpAry.length;i++) { tmpVar+="\r\n_remark+=\""+dcs.common.toReplace(tmpAry[i],"\"","\\\"")+"\\r\\n\";"; }
	tmpContent="<html><head><meta http-equiv=\"Content-TYPE\" content=\"text/html; charset=utf-8\" /><script type=\"text/javascript\" language=\"Javascript\" src=\""+dcs.config.getURL("common")+"script/VDCS.js\" charset=\"utf-8\"></script></head><body>";
	tmpContent+="Jo"+"ek"+"oe "+" C"+"MS "+"4.0<br>Data Sending, Please Wait...";
	//tmpContent+="<div id=\"div-content\">"+tmpRemark+"</div>";
	tmpContent+="<form name=\"frm_data\" action=\""+dcs.config.getURL("common","preview")+"\" method=\"post\">";
	tmpContent+="<input type=\"hidden\" name=\"topic\" value=\"\">";
	tmpContent+="<input type=\"hidden\" name=\"username\" value=\"\">";
	tmpContent+="<input type=\"hidden\" name=\"sp_code\" value=\"\">";
	tmpContent+="<input type=\"hidden\" name=\"remark\" value=\"\">";
	//tmpContent+="<textarea name=\"remark\" value=\"\" cols=\"\" rows=\"\"></textarea>";
	//tmpContent+="<input type=\"submit\">";
	tmpContent+="</form>";
	tmpContent+="<script language=\"javascript\">";
	tmpContent+="var _remark='';"+tmpVar;
	tmpContent+="function doDataSubmit() {";
	tmpContent+="dcs.form.setValue('frm_data.remark',_remark);";	//$('div-content').innerHTML
	tmpContent+="dcs.form.doSubmit('frm_data');";
	tmpContent+="}";
	tmpContent+="window.setTimeout('doDataSubmit()',500);";
	tmpContent+="</script>";
	tmpContent+="</body></html>";
	dcs.pages.doOpenWins('about:blank','winpreview',600,400,'yes',tmpContent);
}

dcs.post.doTextareaKeyDown=function(strEvent)
{
	if (strEvent)
	{
		dcs.form.doQuickSubmit('frm_post',strEvent);
	}
}

dcs.post.setInterfaceValue=function(strName,strValue,strMode)
{
	dcs.form.setValue(strName,strValue,strMode);
}




/*
########################################
########################################
*/
dcs.editor=new Object();
dcs.editor.tools=new Object();
dcs.editor._Queues=new Array();

dcs.editor.addQueues=function(strInstanceName)
{
	var tmpI=this._Queues.length+1;
	this._Queues[tmpI]=new Array();
	this._Queues[tmpI]['instancename']=strInstanceName;
}

dcs.editor.getQueues=function(strI,strKey)
{
	if (isEmpty(strI)) strI=1;
	var re='';
	if (strI<=this._Queues.length) re=this._Queues[strI][strKey];
	return re;
}

dcs.editor.tools.getFrame=function(strInstanceName)
{
	var tmpName=strInstanceName+"___Frame";
	return document.frames ? document.frames[tmpName] : document.getElementById(tmpName).contentWindow;
}

dcs.editor.tools.setValue=function(strName,strValue,strMode)
{
	if (dcs.queues.isItem(strName))
	{
		var tmpFrame=dcs.editor.tools.getFrame(strName);
		if (tmpFrame) tmpFrame.dcs.editor.interface.setValue(strValue,strMode);
	}
}

dcs.editor.tools.getValue=function(strName)
{
	if (isEmpty(strName)) strName=dcs.editor.getQueues(1,'instancename');
	var tmpFrame=dcs.editor.tools.getFrame(strName);
	var re='';
	if (tmpFrame) re=tmpFrame.dcs.editor.getValue(strName);
	return re;
}



/*
########################################
########################################
*/
var VDCSeditor=function(strInstanceName,strMode,strToolbar)
{
	this.InstanceName	= strInstanceName;
	this.Mode		= strMode		|| "all";
	this.Toolbar		= strToolbar		|| "default";
	this.Width		= "100%";
	this.Height		= "300";
	this.Value		= "";
	this.BasePath		= dcs.config.getURL("common.editor");		//"editor/"
	this.CheckBrowser	= true;
	this.DisplayErrors	= true;
	this.Config		= new Object();
	//this.OnError		= null;  // function(source, errorNumber, errorDescription)
	dcs.queues.addItem(this.InstanceName);
	dcs.editor.addQueues(this.InstanceName);
}

VDCSeditor.prototype.setBasePath=function(strBasePath,strHeight) { if (!isEmpty(strBasePath)) this.BasePath=strBasePath; }
VDCSeditor.prototype.setToolbar=function(strToolbar) { if (!isEmpty(strToolbar)) this.Toolbar=strToolbar; }

VDCSeditor.prototype.setSize=function(strWidth,strHeight)
{
	if (!isEmpty(strWidth)) this.Width=strWidth;
	if (!isEmpty(strHeight)) this.Height=strHeight;
}
VDCSeditor.prototype.setValue=function(strValue) { if (!isEmpty(strValue)) this.Value=strValue; }


VDCSeditor.prototype.doReplaceTextarea=function()
{
	if (!this.CheckBrowser || this.isCompatibleBrowser())
	{
		var oTextarea=document.getElementsByName(this.InstanceName)[0];
		oTextarea.style.display="none";
		this.doInsertHtmlBefore(this.getConfigHtml(),oTextarea);
		this.doInsertHtmlBefore(this.getIFrameHtml(),oTextarea);
	}
}


VDCSeditor.prototype.doInsertHtmlBefore=function(strer,strElement)
{
	if (strElement.insertAdjacentHTML)	// IE
	{
		strElement.insertAdjacentHTML("beforeBegin",strer);
	}
	else					// Gecko
	{
		var oRange=document.createRange();
		oRange.setStartBefore(strElement);
		var oFragment=oRange.createContextualFragment(strer);
		strElement.parentNode.insertBefore(oFragment,strElement);
	}
}


VDCSeditor.prototype.getConfigHtml=function()
{
	var sConfig="";
	for (var o in this.Config)
	{
	if (sConfig.length > 0) sConfig += "&";
	sConfig += this.toHTMLEncode(o)+"="+this.toHTMLEncode(this.Config[o]);
	}
	return "<input type=\"hidden\" id=\""+this.InstanceName+"___Config\" value=\""+sConfig+"\">";
}

VDCSeditor.prototype.getIFrameHtml=function()
{
	var sLink=this.BasePath+"editor.html?mode="+this.Mode+"&toolbar="+this.Toolbar+"&instancename="+this.InstanceName+"";
	return "<iframe id=\""+this.InstanceName+"___Frame\" src=\""+sLink+"\" width=\""+this.Width+"\" height=\""+this.Height+"\" frameborder=\"no\" scrolling=\"no\"></iframe>";
}




//########################################
//########################################
VDCSeditor.prototype.isCompatibleBrowser=function()
{
	var tmpAgent=navigator.userAgent.toLowerCase();
	var re=false;
	if (tmpAgent.indexOf("msie")!=-1 && tmpAgent.indexOf("mac")==-1 && tmpAgent.indexOf("opera")==-1)	// Internet Explorer
	{
		var tmpBrowserVersion=navigator.appVersion.match(/MSIE (.\..)/)[1];
		re=(tmpBrowserVersion>=5.5);
	}
	else if (navigator.product=="Gecko" && navigator.productSub>=20030210)					// Gecko
	{
		re=true;
	}
	return re;
}


VDCSeditor.prototype.doThrowError=function(errorNumber,errorDescription)
{
	this.ErrorNumber		= errorNumber;
	this.ErrorDescription		= errorDescription;
	if (this.DisplayErrors)
	{
		document.write("<div style=\"COLOR:#ff0000\">");
		document.write("[ VDCSeditor Error "+this.ErrorNumber+": "+this.ErrorDescription+" ]");
		document.write("</div>");
	}
	if (typeof(this.OnError)=="function") this.OnError(this,errorNumber,errorDescription);
}


VDCSeditor.prototype.toHTMLEncode=function(strer)
{
	if (typeof(strer) != "string") strer=strer.toString();
	strer=strer.replace(/&/g, "&amp;");
	strer=strer.replace(/"/g, "&quot;");
	strer=strer.replace(/</g, "&lt;");
	strer=strer.replace(/>/g, "&gt;");
	strer=strer.replace(/'/g, "&#146;");
	return strer;
}




//########################################
//########################################
function setInterfaceValue(strName,strValue,strMode)
{
	dcs.post.setInterfaceValue(strName,strValue,strMode);
	var tmpName=strName;
	if (tmpName.indexOf(".")!=-1) tmpName=tmpName.substring(tmpName.indexOf(".")+1);
	dcs.editor.tools.setValue(tmpName,strValue,strMode);
}

