﻿
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);
	}
}

//<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()
{
	
}

dcs.post.setInterfaceValue=function(strName,strValue,strMode)
{
	dcs.form.setValue(strName,strValue,strMode);
}




/*
########################################
########################################
*/
dcs.editor=new Object();
dcs.editor.tools=new Object();

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);
	}
}


/*
########################################
########################################
*/
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);
}

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);
}

