/****************************************************************************
 Web Editor
 ------------------------
 author:	clakeboy
 version:	1.0 Alpha 9
 date:		2008-06-20 11:28:29
 ****************************************************************************/
//editor config
cfg["editor"] = {};
cfg["editor"]["color"] = {
	"line-color":"#729bd1",
	"line-color-2":"#bfcbdf",
	"black-color":"#dde1eb"
};

cfg["editor"]["icon"] = {
	"save":"-480px",
	"print":"-496px",
	"undo":"0",
	"redo":"-16px",
	"bold":"-32px",
	"italic":"-48px",
	"under":"-64px",
	"font-color":"-80px",
	"back-color":"-96px",
	"num-list":"-176px",
	"bull-list":"-160px",
	"de-indent":"-144px",
	"in-indent":"-128px",
	"left":"-192px",
	"center":"-208px",
	"right":"-224px",
	"remove":"-256px",
	"select":"-368px",
	"source":"-544px,icons_4.png",
	"image":"-672px,toolbar3.png",
	"downheight":"-688px,icons_4.png",
	"upheight":"-672px,icons_4.png",
	"pages":"-128px,icons_4.png",
	"page":"-64px,icons_4.png",
	"flash":"-16px,toolbar2.png",
	"media":"-64px,toolbar2.png",
	"hide":"-64px,icons_4.png",
	"quote":"0,toolbar2.png",
	"face":"-48px,toolbar2.png",
	"clearhtml":"-656px"
}

cfg["editor"]["colorbar1"] = new Array("#000000","#444444","#666666","#999999","#cccccc","#eeeeee","#f3f3f3","#ffffff");

cfg["editor"]["colorbar2"] = new Array("#ff0000","#ff9900","#ffff00","#00ff00","#00ffff","#0000ff","#9900ff","#ff00ff");

cfg["editor"]["colorbar3"] = new Array();
cfg["editor"]["colorbar3"].push("#f4cccc");
cfg["editor"]["colorbar3"].push("#fce5cd");
cfg["editor"]["colorbar3"].push("#fff2cc");
cfg["editor"]["colorbar3"].push("#d9ead3");
cfg["editor"]["colorbar3"].push("#d0e0e3");
cfg["editor"]["colorbar3"].push("#cfe2f3");
cfg["editor"]["colorbar3"].push("#d9d2e9");
cfg["editor"]["colorbar3"].push("#ead1dc");

cfg["editor"]["colorbar3"].push("#ea9999");
cfg["editor"]["colorbar3"].push("#f9cb9c");
cfg["editor"]["colorbar3"].push("#ffe599");
cfg["editor"]["colorbar3"].push("#b6d7a8");
cfg["editor"]["colorbar3"].push("#a2c4c9");
cfg["editor"]["colorbar3"].push("#9fc5e8");
cfg["editor"]["colorbar3"].push("#b4a7d6");
cfg["editor"]["colorbar3"].push("#d5a6bd");

cfg["editor"]["colorbar3"].push("#e06666");
cfg["editor"]["colorbar3"].push("#f6b26b");
cfg["editor"]["colorbar3"].push("#ffd966");
cfg["editor"]["colorbar3"].push("#93c47d");
cfg["editor"]["colorbar3"].push("#76a5af");
cfg["editor"]["colorbar3"].push("#6fa8dc");
cfg["editor"]["colorbar3"].push("#8e7cc3");
cfg["editor"]["colorbar3"].push("#c27ba0");

cfg["editor"]["colorbar3"].push("#cc0000");
cfg["editor"]["colorbar3"].push("#e69138");
cfg["editor"]["colorbar3"].push("#f1c232");
cfg["editor"]["colorbar3"].push("#6aa84f");
cfg["editor"]["colorbar3"].push("#45818e");
cfg["editor"]["colorbar3"].push("#3d85c6");
cfg["editor"]["colorbar3"].push("#674ea7");
cfg["editor"]["colorbar3"].push("#a64d79");

cfg["editor"]["colorbar3"].push("#990000");
cfg["editor"]["colorbar3"].push("#b45f06");
cfg["editor"]["colorbar3"].push("#bf9000");
cfg["editor"]["colorbar3"].push("#38761d");
cfg["editor"]["colorbar3"].push("#134f5c");
cfg["editor"]["colorbar3"].push("#0b5394");
cfg["editor"]["colorbar3"].push("#351c75");
cfg["editor"]["colorbar3"].push("#741b47");

cfg["editor"]["colorbar3"].push("#660000");
cfg["editor"]["colorbar3"].push("#783f04");
cfg["editor"]["colorbar3"].push("#7f6000");
cfg["editor"]["colorbar3"].push("#274e13");
cfg["editor"]["colorbar3"].push("#0c343d");
cfg["editor"]["colorbar3"].push("#073763");
cfg["editor"]["colorbar3"].push("#20124d");
cfg["editor"]["colorbar3"].push("#4c1130");
//************************
//toolbar button object
//************************
function toolbarButton(name,icon) {
	/* property */
	this.outString = null;
	this.type = "button";
	this.isCheck = arguments[2] ? arguments[2] : false;
	this._text = null;
	this.checked = false;
	this.isText = false;
	this._title = null;
	//object name
	this._name = name;
	if (icon.split(",")[1] == "text") {
		this._text = icon.split(",")[0];
		if (arguments[3] && arguments[3].indexOf(",") != -1){
			this._icon = "background-image:url(/images/soimages/"+arguments[3].split(",")[1]+");";
			this._icon += "background-position:"+arguments[3].split(",")[0]+" 50%;";
		} else {
			this._icon = "background-position:"+arguments[3]+" 50%;";
		}
		this.isText = true;
	} else {
		if (cfg["editor"]["icon"][icon].indexOf(",") != -1){
			this._icon = "background-image:url(/images/soimages/"+cfg["editor"]["icon"][icon].split(",")[1]+");";
			this._icon += "background-position:"+cfg["editor"]["icon"][icon].split(",")[0]+" 50%;";
		} else {
			this._icon = "background-position:"+cfg["editor"]["icon"][icon]+" 50%;";
		}
	}
	
	/* functions */
	this.init = function() {
		var initBorderColor = "";
		if (is_ie6) {
			initBorderColor = "style=\"border-color:#eeeeee;\"";
		}
		if (this.isText) {
			this.outString = "<div id=\"edit_"+this._name+"_main\" onmousedown=\"Editor.toolbar['"+this._name+"'].click();\" onfocus=\"Editor.editwin.focus();\" "+(this.isCheck?"ischeck='true'":"")+" stype=\""+this.type+"\" "+initBorderColor+" class=\"toolbar_icon_textfont\" UNSELECTABLE=\"on\">";
			this.outString += "<div id=\"edit_"+this._name+"_icon\" style=\""+this._icon+"\" UNSELECTABLE=\"on\">"+this._text+"</div>";
			this.outString += "</div>";
		} else {
			this.outString = "<div id=\"edit_"+this._name+"_main\" onmousedown=\"Editor.toolbar['"+this._name+"'].click();\" onfocus=\"Editor.editwin.focus();\" "+(this.isCheck?"ischeck='true'":"")+" stype=\""+this.type+"\" "+initBorderColor+" class=\"toolbar_icon\" UNSELECTABLE=\"on\">";
			this.outString += "<div id=\"edit_"+this._name+"_icon\" class=\"toolbar_icon_img\" style=\""+this._icon+"\" UNSELECTABLE=\"on\"></div>";
			this.outString += "</div>";
		}
		initBorderColor = null;
	};
	
	this.setIcon = function (icon) {
		$("edit_"+this._name+"_icon").style.backgroundPosition = cfg["editor"]["icon"][icon] + " 50%";
	};
	
	this.setMouseOver = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseover = evt_func;
	};
	
	this.setMouseOut = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseout = evt_func;
	};
	
	this.objectEvent = function(){return false;};

	this.setChecked = function () {
		if (this.isCheck) {
			if (typeof arguments[0] == "boolean") {
				this.checked = arguments[0];
			}
			$("edit_"+this._name+"_main").style.backgroundColor = this.checked ? "transparent" : cfg["editor"]["color"]["black-color"];
			$("edit_"+this._name+"_main").style.borderColor = this.checked ? (is_ie6 ? "#eeeeee" : "transparent") : cfg["editor"]["color"]["line-color"];
			this.checked = !this.checked;
		} else {
			$("edit_"+this._name+"_main").style.backgroundColor = cfg["editor"]["color"]["black-color"];
			$("edit_"+this._name+"_main").style.borderColor = cfg["editor"]["color"]["line-color"];
			$("edit_"+this._name+"_main").onmouseup = function () {
				this.onmouseup = null;
				this.style.backgroundColor = "transparent";
			};
		}
	};

	this.setTitle = function (text) {
		$("edit_"+this._name+"_main").title = text;
		this._title = text;
	};

	this.click = function () {
		this.setChecked();
		this.objectEvent(this.checked);
	};



	/* init exec function */
	this.init();
}
//************************
//toolbar CHKbutton object
//************************
function toolbarCHKButton(name,icon) {
	/* property */
	this.outString = null;
	this.type = "CHKbutton";
	this.isCheck = false;
	this.checked = false;
	this.selectColor = "transparent";
	this.items = arguments[2] ? arguments[2] : null;
	//object name
	this._name = name;
	if (cfg["editor"]["icon"][icon].indexOf(",") != -1){
		this._icon = "background-image:url(/images/soimages/"+cfg["editor"]["icon"][icon].split(",")[1]+");";
		this._icon += "background-position:"+cfg["editor"]["icon"][icon].split(",")[0]+" 50%;";
	} else {
		this._icon = "background-position:"+cfg["editor"]["icon"][icon]+" 50%;";
	}
	this._title = "";
	/* functions */
	this.init = function() {
		var initBorderColor = "";
		if (is_ie6) {
			initBorderColor = "style=\"border-color:#eeeeee;\"";
		}
		this.outString = "<div id=\"edit_"+this._name+"_main\" onclick=\"Editor.toolbar['"+this._name+"'].setChecked();\" stype=\""+this.type+"\" "+initBorderColor+" class=\"toolbar_iconlist\" UNSELECTABLE=\"on\">";
		this.outString += "<div class=\"toolbar_icon_main\" UNSELECTABLE=\"on\">";
		this.outString += "<div id=\"edit_"+this._name+"_icon\" style=\""+this._icon+"\" stype=\""+this.type+"\" class=\"toolbar_icon_font\" UNSELECTABLE=\"on\"></div>";
		this.outString += "<div id=\"edit_"+this._name+"_color\" stype=\""+this.type+"\" class=\"toolbar_icon_font_color\" UNSELECTABLE=\"on\"></div>";
		this.outString += "</div>";
		this.outString += "<div class=\"toolbar_down\" stype=\""+this.type+"\" UNSELECTABLE=\"on\"></div>";
		this.outString += "</div>";
		initBorderColor = null;
	};

	this.setSelectColor = function(color) {
		$("edit_"+this._name+"_color").style.backgroundColor = color;
		this.selectColor = color;
		this.objectEvent(color);
		if (this.items) {
			this.items.setCurrentValue(color);
			this.setChecked();
		}
	};
	
	this.setIcon = function (icon) {
		$("edit_"+this._name+"_icon").style.backgroundPosition = cfg["editor"]["icon"][icon] + " 50%";
	};
	
	this.setMouseOver = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseover = evt_func;
	};
	
	this.setMouseOut = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseout = evt_func;
	};
	
	this.objectEvent = function(){return false;};

	this.setChecked = function () {
		if (this.isCheck) {
			if (arguments[0]) {
				this.checked = arguments[0];
			}
			if (this.checked) {
				this.items.close();
			} else {
				this.items.setCurrentValue(this.selectColor);
				this.items.show(this);
			}
			$("edit_"+this._name+"_main").style.backgroundColor = this.checked ? "transparent" : cfg["editor"]["color"]["black-color"];
			$("edit_"+this._name+"_main").style.borderColor = this.checked ? (is_ie6 ? "#eeeeee" : "transparent") : cfg["editor"]["color"]["line-color"];
			this.checked = !this.checked;
		}
	};

	this.setTitle = function (text) {
		$("edit_"+this._name+"_main").title = text;
		this._title = text;
	};

	/* init exec function */
	this.init();
}

//************************
//toolbar select object
//************************
function toolbarSelect(name) {
	/* property */
	this.outString = null;
	this.type = "select";
	this.isCheck = true;
	this.checked = false;
	this._text = arguments[1] ? arguments[1] : "";
	this._width = arguments[2] ? arguments[2] : 90;
	this.items = new selectItem(name,this._width);
	this.currentSelect = null;
	//object name
	this._name = name;
	this._title = "";
	/* functions */
	this.init = function() {
		this.outString = "<div id=\"edit_"+this._name+"_main\" onclick=\"Editor.toolbar['"+this._name+"'].setChecked();\" stype=\""+this.type+"\" class=\"toolbar_iconlist\" style=\"width:"+this._width+"px;border-color:"+cfg["editor"]["color"]["line-color-2"]+";\" UNSELECTABLE=\"on\">";
		this.outString += "<div id=\"edit_"+this._name+"_text\" stype=\""+this.type+"\" class=\"toolbar_icon_text\" style=\"width:"+(this._width-20)+"px;\" UNSELECTABLE=\"on\">"+this._text+"</div>";
		this.outString += "<div stype=\""+this.type+"\" class=\"toolbar_down\" UNSELECTABLE=\"on\"></div>";
		this.outString += "</div>";
	};
	
	this.setText = function (text) {
		if (flagEX == "IE") {
			$("edit_"+this._name+"_text").innerText = text;
		} else {
			$("edit_"+this._name+"_text").textContent = text;
		}
		this._text = text;
	};
	
	this.setMouseOver = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseover = evt_func;
	};
	
	this.setMouseOut = function (evt_func) {
		$("edit_"+this._name+"_main").onmouseout = evt_func;
	};
	
	this.objectEvent = function(){return false;};

	this.setChecked = function () {
		if (this.isCheck){
			if (arguments[0]) {
				this.checked = arguments[0];
			}
			if (this.checked) {
				this.items.close();
			} else {
				var toolonce = null;
				for (toolonce in Editor.toolbar){
					if (Editor.toolbar[toolonce].type == "select" && Editor.toolbar[toolonce].checked) {
						Editor.toolbar[toolonce].setChecked(true);
					}
				}
				toolonce = null;
				this.items.show();
			}
			$("edit_"+this._name+"_main").style.backgroundColor = this.checked ? "transparent" : cfg["editor"]["color"]["black-color"];
			$("edit_"+this._name+"_main").style.borderColor = this.checked ? cfg["editor"]["color"]["line-color-2"] : cfg["editor"]["color"]["line-color"];
			this.checked = !this.checked;
		}
	};

	this.setTitle = function (text) {
		$("edit_"+this._name+"_main").title = text;
		this._title = text;
	};

	this.setCurrentText = function (text) {
		for (var i=0; i<this.items.length; i++) {
			if (this.items.list[i].innerHTML == text) {
				if (this.currentSelect) {
					this.currentSelect.style.backgroundPosition = "-20px center";
				}
				this.items.list[i].style.backgroundPosition = "left center";
				this.currentSelect = this.items.list[i];
				break;
			}
		}
	};

	this.setCurrentValue = function (text) {
		for (var i=0; i<this.items.length; i++) {
			if (this.items.list[i].getAttribute("value") == text) {
				if (this.currentSelect) {
					this.currentSelect.style.backgroundPosition = "-20px center";
				}
				this.items.list[i].style.backgroundPosition = "left center";
				this.currentSelect = this.items.list[i];
				break;
			}
		}
		this.objectEvent(text);
	};

	/* init exec function */
	this.init();
}
//****************************
//toolbar select->item object
//****************************
function selectItem(name) {
	/* property */
	this.length = 0;
	this.list = null;
	this.outString = "";
	this._name = name;
	this._width = arguments[1] ? arguments[1] : 100;

	/* functions */
	this.init = function () {
		this.outString = "<div id=\""+this._name+"_select\" class=\"item\" onselectstart=\"return false;\" UNSELECTABLE=\"on\">";
		this.outString += "<ul id=\""+this._name+"_select_note\">";
		this.outString += "</ul>";
		this.outString += "</div>";
	};

	this.add = function (mixd) {
		var itemonce,obj;
		var tempitem = $(this._name+"_select_note");
		for (itemonce in mixd) {
			obj = document.createElement("LI");
			obj.innerHTML = mixd[itemonce]["text"];
			obj.setAttribute("value",mixd[itemonce]["value"]);
			obj.setAttribute("parent",this._name);
			obj.unselectable = "on";
			if (mixd[itemonce]["font"]) {
				obj.style.fontFamily = mixd[itemonce]["font"];
			}
			obj.onmouseover = function () {
				this.style.backgroundColor = "#e0edfe";
			};
			obj.onmouseout = function () {
				this.style.backgroundColor = "transparent";
			};
			obj.onclick = function () {
				Editor.toolbar[this.getAttribute("parent")].setText(this.innerHTML);
				Editor.toolbar[this.getAttribute("parent")].setCurrentValue(this.getAttribute("value"));
			};
			tempitem.appendChild(obj);
			obj = null;
			this.length++;
		}
		this.list = tempitem.childNodes;
		tempitem = itemonce = name = base = null;
	};

	this.remove = function (num) {
		var tempitem = $(this._name+"_select_note");
		tempitem.removeChild(tempitem.childNode[num]);
		this.length--;
	};

	this.show = function () {
		var t = getElementXY($("edit_"+this._name+"_main"));
		if (flagEX == "IE") {
			t["top"] += 21;
			t["left"] += 1;
		} else {
			t["top"] += 22;
			t["left"] += 2;
		}
		$(this._name+"_select").style.top = t["top"] + "px";
		$(this._name+"_select").style.left = t["left"] + "px"
		$(this._name+"_select").style.visibility = "visible";
		t = null;
	};

	this.close = function () {
		$(this._name+"_select").style.visibility = "hidden";
	};

	this.init();
}

//************************
// colorbar object
//************************
function colorBar(name) {
	/* property */
	this._name = name;
	this.outString = null;
	this.currentSelect = null;
	this.currentParent = null;
	this.list = new Array();
	/* functions */

	this.init = function () {
		this.outString = "<div id=\"edit_"+this._name+"_colorbar\" class=\"color_bar\" onselectstart=\"return false;\" UNSELECTABLE=\"on\">";
		this.outString += "<div class=\"color_bar_pos\" UNSELECTABLE=\"on\">";
		this.outString += "<div id=\"edit_"+this._name+"_colorbar_color1\" class=\"color_bar_posline\" UNSELECTABLE=\"on\">";
		this.outString += "</div>";
		this.outString += "</div>";
		this.outString += "<div class=\"color_bar_pos\" UNSELECTABLE=\"on\">";
		this.outString += "<div id=\"edit_"+this._name+"_colorbar_color2\" class=\"color_bar_posline\" UNSELECTABLE=\"on\">";
		this.outString += "</div>";
		this.outString += "</div>";
		this.outString += "<div class=\"color_bar_pos\" UNSELECTABLE=\"on\">";
		this.outString += "<div id=\"edit_"+this._name+"_colorbar_color3\" class=\"color_bar_posline\" style=\"width:144px;height:108px;\" UNSELECTABLE=\"on\">";
		this.outString += "</div>";
		this.outString += "</div>";
		this.outString += "</div>";
	};

	this.add = function(mixd,bar) {
		var pos = $("edit_"+this._name+"_colorbar_"+bar);
		var obj,i = null
		for (i=0;i < mixd.length ;i++ ){
			obj = document.createElement("DIV");
			obj.setAttribute("value",mixd[i]);
			obj.style.backgroundColor = mixd[i];
			obj.style.borderColor = mixd[i];
			obj.onmouseover = this.mouseOver;
			obj.onmouseout = this.mouseOut;
			obj.unselectable = "on";
			obj.onclick = function() {
				Editor.toolbar[this.parentNode.getAttribute("parent")].setSelectColor(this.getAttribute("value"));
			};
			this.list.push(obj);
			pos.appendChild(obj);
			obj = null;
		}
		pos = obj = i = null;
	};

	this.setCurrentValue = function (text) {
		if (!text || text == "transparent") {
			if (this.currentSelect) {
				this.currentSelect.style.backgroundPosition = "20px 50%";
			}
			this.currentSelect = null;
		}
		for (var i=0;i < this.list.length ; i++){
			if (this.list[i].getAttribute("value") == text.toLowerCase()) {
				if (this.currentSelect) {
					this.currentSelect.style.backgroundPosition = "20px 50%";
				}
				this.list[i].style.backgroundPosition = "-368px 50%";
				this.currentSelect = this.list[i];
			}
		}
	};

	this.show = function (obj) {
		this.currentParent = obj;
		$("edit_"+this._name+"_colorbar_color1").setAttribute("parent",obj._name);
		$("edit_"+this._name+"_colorbar_color2").setAttribute("parent",obj._name);
		$("edit_"+this._name+"_colorbar_color3").setAttribute("parent",obj._name);
		var t = getElementXY($("edit_"+obj._name+"_main"));
		if (flagEX == "IE") {
			t["top"] += 21;
			t["left"] += 1;
		} else {
			t["top"] += 22;
			t["left"] += 2;
		}
		$("edit_"+this._name+"_colorbar").style.top = t["top"]  + "px";
		$("edit_"+this._name+"_colorbar").style.left = t["left"] + "px";
		$("edit_"+this._name+"_colorbar").style.visibility = "visible";
		t = null;
	};

	this.close = function () {
		$("edit_"+this._name+"_colorbar").style.visibility = "hidden";
	};

	this.mouseOver = function () {
		this.style.borderColor = "#fff";
	};

	this.mouseOut = function () {
		this.style.borderColor = this.style.backgroundColor;
	};
	
	/* object init */
	this.init();
}

//*********************************************************
// Editor main object
//*********************************************************
var Editor = {
	toolbar:{},
	upFileURI:null,
	currSelect:null,
	colorbar:null,
	editdoc:null,
	editwin:null,
	viewSource:false,
	currPage:1,
	docPages:1,
	isPages:true,
	init:function() {
		var selects = "";
		var content = "<div id=\"edit_main\" class=\"edit_main\" onselectstart=\"return false;\">";
		content += "<div id=\"edit_toolbar\" class=\"edit_tools\">";
		//init colorbar html
		Editor.colorbar = new colorBar("clake");
		selects = Editor.colorbar.outString;
		//init toolbar html
		var toolonce = null;
		for (toolonce in cfg["editor"]["toolbar"]){
			if (cfg["editor"]["toolbar"][toolonce]["type"] == "button") {
				Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["toolbar"][toolonce]["name"],cfg["editor"]["toolbar"][toolonce]["check"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar"][toolonce]["func"] ? cfg["editor"]["toolbar"][toolonce]["func"]:function(){return false;};
			} else if (cfg["editor"]["toolbar"][toolonce]["type"] == "textButton") {
				Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["toolbar"][toolonce]["text"],cfg["editor"]["toolbar"][toolonce]["check"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar"][toolonce]["func"] ? cfg["editor"]["toolbar"][toolonce]["func"]:function(){return false;};
			} else if (cfg["editor"]["toolbar"][toolonce]["type"] == "CHKbutton"){
				Editor.toolbar[toolonce] = new toolbarCHKButton(toolonce,cfg["editor"]["toolbar"][toolonce]["name"],Editor.colorbar);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar"][toolonce]["func"] ? cfg["editor"]["toolbar"][toolonce]["func"]:function(){return false;};
				Editor.toolbar[toolonce].isCheck = true;
			} else if (cfg["editor"]["toolbar"][toolonce]["type"] == "select") {
				Editor.toolbar[toolonce] = new toolbarSelect(toolonce,cfg["editor"]["toolbar"][toolonce]["text"],cfg["editor"]["toolbar"][toolonce]["width"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar"][toolonce]["func"] ? cfg["editor"]["toolbar"][toolonce]["func"]:function(){return false;};
				selects += Editor.toolbar[toolonce].items.outString;
			} else if (cfg["editor"]["toolbar"][toolonce]["type"] == "step") {
				Editor.toolbar[toolonce] = new function (){this.type="step";this.outString = "<div class=\"toolbar_step\"></div>";};
			}
			content += Editor.toolbar[toolonce].outString;
		}
		content += "</div>";
		if (typeof(cfg["editor"]["toolbar2"]) != "undefined") {
			content += "<div id=\"edit_toolbar2\" class=\"edit_tools\">";
			for (toolonce in cfg["editor"]["toolbar2"]){
				if (cfg["editor"]["toolbar2"][toolonce]["type"] == "button") {
					Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["toolbar2"][toolonce]["name"],cfg["editor"]["toolbar2"][toolonce]["check"]);
					Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar2"][toolonce]["func"] ? cfg["editor"]["toolbar2"][toolonce]["func"]:function(){return false;};
				} else if (cfg["editor"]["toolbar2"][toolonce]["type"] == "textButton") {
					Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["toolbar2"][toolonce]["text"],cfg["editor"]["toolbar2"][toolonce]["check"]);
					Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar2"][toolonce]["func"] ? cfg["editor"]["toolbar2"][toolonce]["func"]:function(){return false;};
				} else if (cfg["editor"]["toolbar2"][toolonce]["type"] == "CHKbutton"){
					Editor.toolbar[toolonce] = new toolbarCHKButton(toolonce,cfg["editor"]["toolbar2"][toolonce]["name"],Editor.colorbar);
					Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar2"][toolonce]["func"] ? cfg["editor"]["toolbar2"][toolonce]["func"]:function(){return false;};
					Editor.toolbar[toolonce].isCheck = true;
				} else if (cfg["editor"]["toolbar2"][toolonce]["type"] == "select") {
					Editor.toolbar[toolonce] = new toolbarSelect(toolonce,cfg["editor"]["toolbar2"][toolonce]["text"],cfg["editor"]["toolbar2"][toolonce]["width"]);
					Editor.toolbar[toolonce].objectEvent = cfg["editor"]["toolbar2"][toolonce]["func"] ? cfg["editor"]["toolbar2"][toolonce]["func"]:function(){return false;};
					selects += Editor.toolbar[toolonce].items.outString;
				} else if (cfg["editor"]["toolbar2"][toolonce]["type"] == "step") {
					Editor.toolbar[toolonce] = new function (){this.type="step";this.outString = "<div class=\"toolbar_step\"></div>";};
				}
				content += Editor.toolbar[toolonce].outString;
			}
			content += "</div>";
		}
		content += "<div id=\"edit_doc\" class=\"edit_doc\">";
		content += "<iframe id=\"edit_editor\" name=\"edit_editor\" width=\"100%\" height=\"100%\" frameborder=\"0\" scrolling=\"auto\"></iframe>";
		content += "</div>";
		content += "<div id=\"edit_pagebar\" class=\"edit_tools\">";
		for (toolonce in cfg["editor"]["pagebar"]){
			if (cfg["editor"]["pagebar"][toolonce]["type"] == "button") {
				Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["pagebar"][toolonce]["name"],cfg["editor"]["pagebar"][toolonce]["check"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["pagebar"][toolonce]["func"] ? cfg["editor"]["pagebar"][toolonce]["func"]:function(){return false;};
			} else if (cfg["editor"]["pagebar"][toolonce]["type"] == "textButton") {
				Editor.toolbar[toolonce] = new toolbarButton(toolonce,cfg["editor"]["pagebar"][toolonce]["text"],cfg["editor"]["pagebar"][toolonce]["check"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["pagebar"][toolonce]["func"] ? cfg["editor"]["pagebar"][toolonce]["func"]:function(){return false;};
			} else if (cfg["editor"]["pagebar"][toolonce]["type"] == "CHKbutton"){
				Editor.toolbar[toolonce] = new toolbarCHKButton(toolonce,cfg["editor"]["pagebar"][toolonce]["name"],Editor.colorbar);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["pagebar"][toolonce]["func"] ? cfg["editor"]["pagebar"][toolonce]["func"]:function(){return false;};
				Editor.toolbar[toolonce].isCheck = true;
			} else if (cfg["editor"]["pagebar"][toolonce]["type"] == "select") {
				Editor.toolbar[toolonce] = new toolbarSelect(toolonce,cfg["editor"]["pagebar"][toolonce]["text"],cfg["editor"]["pagebar"][toolonce]["width"]);
				Editor.toolbar[toolonce].objectEvent = cfg["editor"]["pagebar"][toolonce]["func"] ? cfg["editor"]["pagebar"][toolonce]["func"]:function(){return false;};
				selects += Editor.toolbar[toolonce].items.outString;
			} else if (cfg["editor"]["pagebar"][toolonce]["type"] == "step") {
				Editor.toolbar[toolonce] = new function (){this.type="step";this.outString = "<div class=\"toolbar_step\"></div>";};
			}
			content += Editor.toolbar[toolonce].outString;
		}
		content += "</div>";
		content += "</div>";
		$("edit_parent").innerHTML += content;
		$("edit_parent").innerHTML += selects;
		content = toolonce = null;

		Editor.initEditdoc();
		Editor.initToolbarEvent();
	},
	initToolbarEvent:function() {
		var toolonce = null;
		for (toolonce in cfg["editor"]["toolbar"]){
			if (Editor.toolbar[toolonce].type == "step") continue;
			Editor.toolbar[toolonce].setMouseOver(Editor.evtMouseOver);
			Editor.toolbar[toolonce].setMouseOut(Editor.evtMouseOut);
			Editor.toolbar[toolonce].setTitle(cfg["editor"]["toolbar"][toolonce]["title"]);
			if (Editor.toolbar[toolonce].type == "select") {
				Editor.toolbar[toolonce].items.add(cfg["editor"]["toolbar"][toolonce]["items"]);
			}
		}
		for (toolonce in cfg["editor"]["pagebar"]){
			if (Editor.toolbar[toolonce].type == "step") continue;
			Editor.toolbar[toolonce].setMouseOver(Editor.evtMouseOver);
			Editor.toolbar[toolonce].setMouseOut(Editor.evtMouseOut);
			Editor.toolbar[toolonce].setTitle(cfg["editor"]["pagebar"][toolonce]["title"]);
			if (Editor.toolbar[toolonce].type == "select") {
				Editor.toolbar[toolonce].items.add(cfg["editor"]["pagebar"][toolonce]["items"]);
			}
		}
		if (typeof(cfg["editor"]["toolbar2"])) {
			for (toolonce in cfg["editor"]["toolbar2"]){
				if (Editor.toolbar[toolonce].type == "step") continue;
				Editor.toolbar[toolonce].setMouseOver(Editor.evtMouseOver);
				Editor.toolbar[toolonce].setMouseOut(Editor.evtMouseOut);
				Editor.toolbar[toolonce].setTitle(cfg["editor"]["toolbar2"][toolonce]["title"]);
				if (Editor.toolbar[toolonce].type == "select") {
					Editor.toolbar[toolonce].items.add(cfg["editor"]["toolbar2"][toolonce]["items"]);
				}
			}
		}
		
		Editor.colorbar.add(cfg["editor"]["colorbar1"],"color1");
		Editor.colorbar.add(cfg["editor"]["colorbar2"],"color2");
		Editor.colorbar.add(cfg["editor"]["colorbar3"],"color3");
		toolonce = null;
		if (flagEX == "IE") {
			document.attachEvent("onclick",Editor.hideMenus);
		} else {
			document.addEventListener("click",Editor.hideMenus,false);
		}
	},
	initEditdoc:function(){
		if (flagEX == "IE") {
			document.onreadystatechange = function(){
				var state = this.readyState;
            	if (state == "complete") {
					this.onreadystatechange = null;
					var toolbarheight = Editor.getToolbarHeight();
					$("edit_doc").style.height = ($("edit_main").clientHeight - toolbarheight) + "px";
					Editor.editdoc.body.innerHTML = $("edit_content_1").value;
					toolbarheight = null;
				}
			};
		} else {
			var toolbarheight = Editor.getToolbarHeight();
			$("edit_doc").style.height = ($("edit_main").clientHeight - toolbarheight) + "px";
			toolbarheight = null;
		}
		Editor.editwin = $("edit_editor").contentWindow;
		Editor.editdoc = Editor.editwin.document;
		Editor.editdoc.open('text/html', 'replace');
		Editor.editdoc.writeln('<style type="text/css">@import url("/css/socontent.css");</style>');
		Editor.editdoc.writeln("<body onload=\"this.focus();\"><br/></body>");
		Editor.editdoc.close();
		Editor.editdoc.designMode = "on";
		if (flagEX == "IE") {
			Editor.editdoc.attachEvent("onclick",Editor.hideMenus);
			Editor.editdoc.attachEvent("onmouseup",Editor.queryFormat);
		} else {
			//Editor.editdoc.execCommand("useCSS",false, true)
			Editor.editdoc.addEventListener("click",Editor.hideMenus,false);
			Editor.editdoc.addEventListener("mouseup",Editor.queryFormat,false);
		}
		Editor.initDocPages();
	},
	initDocPages:function() {
		if (!Editor.isPages) {
			if (flagEX != "IE") {
				Editor.editdoc.body.innerHTML = $("edit_content_1").value;	
			}
			return;
		}
		var contents = $N("content[]");
		var i,dfg;
		for (i=0;i<contents.length;i++) {
			Editor.toolbar["page_"+(i+1)] = new toolbarButton("page_"+(i+1),(i+1)+"#,text",true);
			eval("Editor.toolbar[\"page_"+(i+1)+"\"].objectEvent = function(){Editor.setCurrentPage("+(i+1)+");};");
			dfg = document.createElement("SPAN");
			dfg.innerHTML = Editor.toolbar["page_"+(i+1)].outString;
			$("edit_pagebar").appendChild(dfg);
			Editor.toolbar["page_"+(i+1)].setTitle("跳转到第"+(i+1)+"页");
			Editor.toolbar["page_"+(i+1)].setMouseOver(Editor.evtMouseOver);
			Editor.toolbar["page_"+(i+1)].setMouseOut(Editor.evtMouseOut);
			dfg = null;
		}
		Editor.docPages = contents.length;
		Editor.toolbar["page_1"].setChecked(false);
		if (flagEX != "IE") {
			Editor.editdoc.body.innerHTML = $("edit_content_1").value;
		}
		i = contents = dfg = null;
	},
	resetDocSize:function() {
		var toolbarheight = Editor.getToolbarHeight();
		$("edit_main").style.height = "100%";
		$("edit_doc").style.height = ($("edit_main").clientHeight - toolbarheight) + "px";
	},
	setCurrentPage:function(page) {
		if (Editor.viewSource) {
			alert("源代码模式不能执行操作!");
			return;
		}
		if (page == Editor.currPage) {
			Editor.toolbar["page_"+page].setChecked(false);
			return;
		}
		Editor.toolbar["page_"+Editor.currPage].setChecked(true);
		Editor.toolbar["page_"+page].setChecked(false);
		$("edit_content_"+Editor.currPage).value = Editor.editdoc.body.innerHTML;
		Editor.currPage = page;
		Editor.editdoc.body.innerHTML = $("edit_content_"+page).value;
		Editor.checkFocus();
	},
	addDocPage:function() {
		if (Editor.viewSource) {
			alert("源代码模式不能执行操作!");
			return;
		}
		Editor.docPages++;
		Editor.toolbar["page_"+Editor.docPages] = new toolbarButton("page_"+Editor.docPages,Editor.docPages+"#,text",true);
		eval("Editor.toolbar[\"page_"+Editor.docPages+"\"].objectEvent = function(){Editor.setCurrentPage("+Editor.docPages+");};");
		var dfg = document.createElement("SPAN");
		dfg.innerHTML = Editor.toolbar["page_"+Editor.docPages].outString;
		$("edit_pagebar").appendChild(dfg);
		Editor.toolbar["page_"+Editor.docPages].setTitle("跳转到第"+Editor.docPages+"页");
		Editor.toolbar["page_"+Editor.docPages].setMouseOver(Editor.evtMouseOver);
		Editor.toolbar["page_"+Editor.docPages].setMouseOut(Editor.evtMouseOut);
		var tmpcontent = document.createElement("TEXTAREA");
		tmpcontent.setAttribute("id","edit_content_"+Editor.docPages);
		tmpcontent.setAttribute("name","content[]");
		tmpcontent.style.display = "none";
		$("edit_doc").appendChild(tmpcontent);
		Editor.setCurrentPage(Editor.docPages);
		tmpcontent = dfg = null;
	},
	execFormat:function(cmd,arg) {
		Editor.checkFocus();
		if (Editor.viewSource) {
			alert("源代码模式不能执行操作!");
			return;
		}
		if (cmd == "FontSize") {
			Editor.execFormatFontSize(arg);
			return;
		} else if (cmd == "BackColor"){
			cmd = flagEX == "IE" ? cmd : "hiliteColor";
		}
		var userflag = typeof arguments[2] == "boolean" ? arguments[2] : false;
		Editor.editdoc.execCommand(cmd,userflag,arg);
		userflag = null;
		Editor.queryFormat();
		Editor.checkFocus();
	},
	execFormatFontSize:function(arg) {
		var content = null;
		if (flagEX == "IE") {
			content = Editor.editdoc.selection.createRange();
			var htmltext = content.htmlText;
			var reg = /<font[^>]*>/ig;
			var reg1 = /<\/font>/ig;
			htmltext = htmltext.replace(reg,"");
			htmltext = htmltext.replace(reg1,"");
			content.pasteHTML("<font style='font-size:"+arg+";'>"+htmltext+"</font>");
			content = reg = reg1 = htmltext = null
		} else {
			content = Editor.editwin.getSelection().getRangeAt(0);
			var font = document.createElement("FONT");
			font.style.fontSize = arg + "px";
			font.appendChild(content.cloneContents());
			var reg = /<font[^>]*>/ig;
			var reg1 = /<\/font>/ig;
			font.innerHTML = font.innerHTML.replace(reg,"");
			font.innerHTML = font.innerHTML.replace(reg1,"");
			content.deleteContents();
			content.collapse(true);
			content.insertNode(font);
			content.detach();
			font = content = reg = null;
			//getobjparm(content);
		}
	},
	queryFormat:function() {
		var toolonce = null;
		for (toolonce in Editor.toolbar) {
			Editor.setCurrentFormatButton(toolonce);
		}
	},
	setCurrentFormatButton:function(flag) {
		var sCmd = null;
		if (flag == "fontfamily"){
			sCmd = Editor.editdoc.queryCommandValue("FontName");
			if (sCmd == "" && flagEX != "IE" && window.getComputedStyle) {
				sCmd = Editor.editdoc.body.style.fontFamily;
			}
			sCmd = sCmd.indexOf(',') > 0 ? sCmd.substr(0, sCmd.indexOf(',')) : sCmd;
			var i = null;
			for (i =0;i<Editor.toolbar[flag].items.length;i++) {
				if (Editor.toolbar[flag].items.list[i].getAttribute("value").toLowerCase() == sCmd.toLowerCase()) {
					Editor.toolbar[flag].setCurrentText(Editor.toolbar[flag].items.list[i].innerHTML);
					Editor.toolbar[flag].setText(Editor.toolbar[flag].items.list[i].innerHTML);
					break;
				}
			}
			if (i == Editor.toolbar[flag].items.length) {
				Editor.toolbar[flag].setCurrentText("Sans Serif");
				Editor.toolbar[flag].setText("Sans Serif");
			}
			i = null;
		} else if (flag == "fontsize") {
			sCmd = Editor.editdoc.queryCommandValue("FontSize");
		} else if (flag == "bold") {
			sCmd = Editor.editdoc.queryCommandState("Bold");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "italic") {
			sCmd = Editor.editdoc.queryCommandState("Italic");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "under") {
			sCmd = Editor.editdoc.queryCommandState("Underline");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "fontcolor") {
			sCmd = Editor.editdoc.queryCommandValue("ForeColor");
			var color = rgbToColor(sCmd);
			$("edit_"+Editor.toolbar[flag]._name+"_color").style.backgroundColor = color;
			Editor.toolbar[flag].selectColor = color;
			Editor.toolbar[flag].items.setCurrentValue(color);
			var color = null;
		} else if (flag == "backcolor") {
			var cmd = flagEX == "IE" ? "BackColor" : "hiliteColor";
			sCmd = Editor.editdoc.queryCommandValue(cmd);
			var color = rgbToColor(sCmd);
			$("edit_"+Editor.toolbar[flag]._name+"_color").style.backgroundColor = color;
			Editor.toolbar[flag].selectColor = color;
			Editor.toolbar[flag].items.setCurrentValue(color);
			var color = null;
		} else if (flag == "numlist") {
			sCmd = Editor.editdoc.queryCommandState("InsertOrderedList");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "bulllist") {
			sCmd = Editor.editdoc.queryCommandState("InsertUnorderedList");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "left") {
			sCmd = Editor.editdoc.queryCommandState("JustifyLeft");
			if (sCmd === false && !Editor.toolbar["center"].checked && !Editor.toolbar["right"].checked && flagEX == "IE") {
				sCmd = true;
			}
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "center") {
			sCmd = Editor.editdoc.queryCommandState("JustifyCenter");
			Editor.toolbar[flag].setChecked(!sCmd);
		} else if (flag == "right") {
			sCmd = Editor.editdoc.queryCommandState("JustifyRight");
			Editor.toolbar[flag].setChecked(!sCmd);
		}
		sCmd = null;
	},
	textToHtml:function() {
		if (flagEX == "IE") {
			Editor.editdoc.body.innerHTML = Editor.editdoc.body.innerText;
		} else {
			var html = Editor.editdoc.createRange();
			html.selectNodeContents(Editor.editdoc.body);
			Editor.editdoc.body.innerHTML = html.toString();
			html = null;
		}
		Editor.viewSource = false;
	},
	htmlToText:function() {
		if (flagEX == "IE") {
			Editor.editdoc.body.innerText = Editor.editdoc.body.innerHTML;
		} else {
			var html = document.createTextNode(Editor.editdoc.body.innerHTML);
			Editor.editdoc.body.innerHTML = "";
			Editor.editdoc.body.appendChild(html);
			html = null;
		}
		Editor.viewSource = true;
	},
	openImageWindow:function() {
		showBlackBack(true);
		Editor.initUploadImage();
		var bod = document.documentElement ? document.documentElement : document.body;
		$("insertimage").style.top = (bod.scrollTop+bod.clientHeight/2-200) + "px";
		$("insertimage").style.left = (bod.clientWidth/2-$("insertimage").clientWidth/2) + "px";
		bod = null;
		$("imageurl").value = "http://";
		$("insertimage").style.visibility = "visible";
		Editor.checkFocus();
		if (flagEX == "IE") {
			Editor.currSelect = Editor.editdoc.selection.createRange();
		}
	},
	closeImageWindow:function() {
		showBlackBack(false);
		$("insertimage").style.visibility = "hidden";
	},
	insertImage:function() {
		Editor.checkFocus();
		var reg = /^http:\/\/(.+)\.gif|jpg|png|bmp|jpe|jpeg$/ig;
		if ($("imageurl").value.match(reg)) {
			if (flagEX == "IE") {
				Editor.currSelect.pasteHTML("<img src='"+$("imageurl").value+"'>");
				Editor.currSelect = null;
			} else {
				Editor.execFormat("InsertImage",$("imageurl").value);
			}
			Editor.closeImageWindow();
		} else {
			alert("不是正确的图片连接地址,请重新输入");
			$("imageurl").focus();
		}
	},
	initUploadImage:function() {
		$("doneupimg").disabled = false;
		var updoc = $("edit_upimg").contentWindow.document;
		updoc.open();
		updoc.writeln('<body style="margin:0;overflow:hidden;font-size:14px;">');
		updoc.writeln('<form id="up_image" name="up_image" method="post" action="'+Editor.upFileURI+'" enctype="multipart/form-data">');
		updoc.writeln('<input type="file" name="upimg" style="width:90%;">');
		updoc.writeln('<input type="hidden" name="action" value="upimage">');
		updoc.writeln('</body>');
		updoc.close();
		updoc = null;
	},
	uploadFileImage:function() {
		$("doneupimg").disabled = true;
		$("edit_upimg").contentWindow.document.forms["up_image"].submit();
	},
	openLinkWindow:function() {
		showBlackBack(true);
		$("linknormal").checked = true;
		$("istarget").checked = false;
		$("linkurl").value = "";
		$("linktitle").value = "";
		$("linktext").value = "";
		var bod = document.documentElement ? document.documentElement : document.body;
		$("insertlink").style.top = (bod.scrollTop+bod.clientHeight/2-200) + "px";
		$("insertlink").style.left = (bod.clientWidth/2-$("insertlink").clientWidth/2) + "px";
		$("insertlink").style.visibility = "visible";
		Editor.checkFocus();
		if (flagEX == "IE") {
			Editor.currSelect = Editor.editdoc.selection.createRange();
			var reg = /href=\"(.+?)\"/i;
			var selecthtml = Editor.currSelect.htmlText;
			var ss = selecthtml.match(reg);
			if (ss != null) {
				$("linkurl").value = ss[1];
			}
			reg = /title=(\S+)/i; 
			ss = selecthtml.match(reg);
			if (ss != null) {
				$("linktitle").value = ss[1];
			}
			reg = /target=(\S+?)/i; 
			ss = selecthtml.match(reg);
			if (ss != null) {
				$("istarget").checked = true;
			} else {
				$("istarget").checked = false;
			}
			$("linktext").value = Editor.currSelect.text;
			ss = reg = selecthtml = null;
		} else {
			Editor.currSelect = Editor.editwin.getSelection().getRangeAt(0);
			$("linktext").value = Editor.currSelect.toString();
			var text = Editor.currSelect.cloneContents();
			var rang = document.createElement("SPAN");
			rang.appendChild(text);
			var selecthtml = rang.innerHTML;
			var reg = /href=\"(.+?)\"/i;
			var ss = selecthtml.match(reg);
			if (ss != null) {
				$("linkurl").value = ss[1];
			}
			
			reg = /title=\"(.+?)\"/i; 
			ss = selecthtml.match(reg);
			if (ss != null) {
				$("linktitle").value = ss[1];
			}
			reg = /target=\"(.+?)\"/i; 
			ss = selecthtml.match(reg);
			if (ss != null) {
				$("istarget").checked = true;
			} else {
				$("istarget").checked = false;
			}
			
			text = rang = selecthtml = reg = ss = null;
		}
	},
	closeLinkWindow:function() {
		showBlackBack(false);
		$("insertlink").style.visibility = "hidden";
	},
	insertLink:function() {
		Editor.checkFocus();
		var linkurl = $("linkurl").value;
		if ($("linkmail").checked) {
			linkurl = "mailto:"+linkurl;
		}
		if (flagEX == "IE") {
			if ($("istarget").checked) {
				linkurl = "<a href=\""+linkurl+"\" target=\"_blank\" title=\""+$("linktitle").value+"\">"+$("linktext").value+"</a>";
			} else {
				linkurl = "<a href='"+linkurl+"' title='"+$("linktitle").value+"'>"+$("linktext").value+"</a>";
			}
			Editor.currSelect.pasteHTML(linkurl);
			Editor.currSelect = null;
		} else {
			var obj = document.createElement("A");
			obj.href = linkurl;
			if ($("istarget").checked) {
				obj.target = "_blank";
			}
			obj.title = $("linktitle").value;
			obj.innerHTML = $("linktext").value;
			Editor.currSelect.deleteContents();
			Editor.currSelect.collapse(true);
			Editor.currSelect.insertNode(obj);
			Editor.currSelect.detach();
			obj = null;
		}
		Editor.closeLinkWindow();
	},
	openFlashWindow:function() {
		showBlackBack(true);
		$("flashurl").value = "";
		$("flashwidth").value = "";
		$("flashheight").value = "";
		var bod = document.documentElement ? document.documentElement : document.body;
		$("insertFlash").style.top = (bod.scrollTop+bod.clientHeight/2-200) + "px";
		$("insertFlash").style.left = (bod.clientWidth/2-$("insertFlash").clientWidth/2) + "px";
		$("insertFlash").style.visibility = "visible";
		Editor.checkFocus();
		if (flagEX == "IE") {
			Editor.currSelect = Editor.editdoc.selection.createRange();
		} else {
			Editor.currSelect = Editor.editwin.getSelection().getRangeAt(0);
		}
	},
	closeFlashWindow:function() {
		showBlackBack(false);
		$("insertFlash").style.visibility = "hidden";
	},
	insertFlash:function() {
		var reg = /[^0-9]+/ig;
		var url = $("flashurl").value;
		var width = $("flashwidth").value;
		var height = $("flashheight").value;
		if (url.trim() == "") {
			alert("FLASH URL 地址不能为空!");
			$("flashurl").focus();
		} else if (width.match(reg) || height.match(reg)){
			alert("FLASH 宽或高不是数字");
		} else {
			if (width.trim() == "" || height.trim() == "") {
				var code = '[flash]'+url+'[/flash]';
			} else {
				var code = '[flash='+width+','+height+']'+url+'[/flash]';
			}
			Editor.insertCode(code,Editor.currSelect);
			Editor.closeFlashWindow();
		}
		url = reg = width = height = null;
		
	},
	openMediaWindow:function() {
		showBlackBack(true);
		$("mediaurl").value = "";
		$("mediawidth").value = "";
		$("mediaheight").value = "";
		var bod = document.documentElement ? document.documentElement : document.body;
		$("insertmedia").style.top = (bod.scrollTop+bod.clientHeight/2-200) + "px";
		$("insertmedia").style.left = (bod.clientWidth/2-$("insertmedia").clientWidth/2) + "px";
		$("insertmedia").style.visibility = "visible";
		Editor.checkFocus();
		if (flagEX == "IE") {
			Editor.currSelect = Editor.editdoc.selection.createRange();
		} else {
			Editor.currSelect = Editor.editwin.getSelection().getRangeAt(0);
		}
	},
	closeMediaWindow:function() {
		showBlackBack(false);
		$("insertmedia").style.visibility = "hidden";
	},
	insertMedia:function() {
		var reg = /[^0-9]/ig;
		var url = $("mediaurl").value;
		var width = $("mediawidth").value;
		var height = $("mediaheight").value;
		var auto = $("mediaauto").checked?1:0;
		if (url.trim() == "") {
			alert("媒体地址不能为空!");
			$("mediaurl").focus();
		} else if (width.match(reg) || height.match(reg)){
			alert("FLASH 宽或高不是数字");
		} else {
			var code = '';
			width = width.trim() == ""?"400":width.trim();
			height = height.trim() == ""?"300":height.trim();
			if ($("mediamp3").checked) {
				code = '[media=mp3,'+width+','+height+','+auto+']';
			} else if ($("mediawma").checked) {
				code = '[media=wma,'+width+','+height+','+auto+']';
			} else if ($("mediawmv").checked) {
				code = '[media=wmv,'+width+','+height+','+auto+']';
			} else if ($("mediarm").checked) {
				code = '[media=rm,'+width+','+height+','+auto+']';
			} else if ($("mediamov").checked) {
				code = '[media=mov,'+width+','+height+','+auto+']';
			}
			code += url + '[/media]';
			Editor.insertCode(code,Editor.currSelect);
			Editor.closeMediaWindow();
		}
		url = reg = width = height = auto = null;
	},
	openFaceWindow:function() {
		showBlackBack(true);
		var bod = document.documentElement ? document.documentElement : document.body;
		$("insertface").style.top = (bod.scrollTop+bod.clientHeight/2-200) + "px";
		$("insertface").style.left = (bod.clientWidth/2-$("insertface").clientWidth/2) + "px";
		$("insertface").style.visibility = "visible";
		Editor.checkFocus();
		if (flagEX == "IE") {
			Editor.currSelect = Editor.editdoc.selection.createRange();
		} else {
			Editor.currSelect = Editor.editwin.getSelection().getRangeAt(0);
		}
	},
	closeFaceWindow:function() {
		showBlackBack(false);
		$("insertface").style.visibility = "hidden";
	},
	insertFace:function(faceid) {
		Editor.execFormat("InsertImage",faceid);
		Editor.closeFaceWindow();
	},
	addEditorHeight:function() {
		$("edit_parent").style.height = (parseInt($("edit_parent").style.height) + 50) + "px";
		$("edit_doc").style.height = (parseInt($("edit_doc").style.height) + 50) + "px";
	},
	deleteEditorHeight:function() {
		if (parseInt($("edit_parent").style.height) > 400) {
			$("edit_parent").style.height = (parseInt($("edit_parent").style.height) - 50) + "px";
			$("edit_doc").style.height = (parseInt($("edit_doc").style.height) - 50) + "px";
		}
	},
	evtMouseOver:function() {
		if (this.getAttribute("stype") == "select" && this.style.backgroundColor != "transparent" && this.style.backgroundColor) {

		} else {
			var toolonce = null;
			for (toolonce in Editor.toolbar){
				if (Editor.toolbar[toolonce].type == "select" && Editor.toolbar[toolonce].checked && this.id != "edit_"+Editor.toolbar[toolonce]._name+"_main") {
					Editor.toolbar[toolonce].setChecked(true);
				}
			}
		}
		if (!(this.getAttribute("stype") == "CHKbutton" && this.style.backgroundColor != "transparent" && this.style.backgroundColor) && Editor.colorbar.currentParent) {
			Editor.colorbar.currentParent.setChecked(true);
		}
		toolonce = evt = null;
		this.style.borderColor = cfg["editor"]["color"]["line-color"];
	},
	evtMouseOut:function() {
		if (this.getAttribute("stype") == "button" || this.getAttribute("stype") == "CHKbutton"){
			if (this.style.backgroundColor == "transparent" || !this.style.backgroundColor) {
				if (is_ie6) {
					this.style.borderColor = "#eeeeee";
				} else {
					this.style.borderColor = "transparent";
				}
			} else {
				this.style.borderColor = cfg["editor"]["color"]["line-color-2"];
			}
			if (this.getAttribute("stype") == "button" && !this.getAttribute("ischeck")) {
				if (is_ie6) {
					this.style.borderColor = "#eeeeee";
				} else {
					this.style.borderColor = "transparent";
				}
				this.style.backgroundColor = "transparent";
			}
		} else {
			this.style.borderColor = cfg["editor"]["color"]["line-color-2"];
		}
	},
	hideMenus:function() {
		var evt = arguments[0] ? arguments[0] : window.event;
		if (!evt) return;
		if (flagEX == "IE"){
			if (evt.srcElement.getAttribute("stype") == "select" || evt.srcElement.getAttribute("stype") == "CHKbutton") return;
		} else {
			if (evt.target.getAttribute("stype") == "select" || evt.target.getAttribute("stype") == "CHKbutton") return;
		}
		var toolonce = null;
		for (toolonce in Editor.toolbar){
			if (Editor.toolbar[toolonce].type == "select" && Editor.toolbar[toolonce].checked) {
				Editor.toolbar[toolonce].setChecked(true);
			}
		}

		if (Editor.colorbar.currentParent) {
			Editor.colorbar.currentParent.setChecked(true);
		}
		toolonce = evt = null;
	},
	checkFocus:function() {
		if (!Editor.editwin.hasfocus) {
			Editor.editwin.focus();
		}
	},
	editDone:function() {
		$('edit_content_'+Editor.currPage).value = Editor.editdoc.body.innerHTML;
	},
	getToolbarHeight:function() {
		var toolbarheight = 0;
		if (typeof(cfg["editor"]["toolbar2"]) != "undefined") {
			toolbarheight += 30;
		}
		if (typeof(cfg["editor"]["toolbar"]) != "undefined") {
			toolbarheight += 30;
		}
		if (typeof(cfg["editor"]["pagebar"]) != "undefined") {
			toolbarheight += 30;
		}
		return toolbarheight;
	},
	getSelectionCode:function() {
		if(flagEX == "IE") {
			var range = Editor.editdoc.selection.createRange();
			if(range.htmlText && range.text) {
				return range.htmlText;
			} else {
				var htmltext = '';
				for(var i = 0; i < range.length; i++) {
					htmltext += range.item(i).outerHTML;
				}
				return htmltext;
			}
		} else {
			selection = Editor.editwin.getSelection();
			range = selection ? selection.getRangeAt(0) : editdoc.createRange();
			return Editor.readNodes(range.cloneContents(), false);
		}
	},
	readNodes:function(root, toptag) { // read firefox DocumentFragment html content
		var html = "";
		var moz_check = /_moz/i;
	
		switch(root.nodeType) {
			case Node.ELEMENT_NODE:
			case Node.DOCUMENT_FRAGMENT_NODE:
				var closed;
				if(toptag) {
					closed = !root.hasChildNodes();
					html = '<' + root.tagName.toLowerCase();
					var attr = root.attributes;
					for(var i = 0; i < attr.length; ++i) {
						var a = attr.item(i);
						if(!a.specified || a.name.match(moz_check) || a.value.match(moz_check)) {
							continue;
						}
						html += " " + a.name.toLowerCase() + '="' + a.value + '"';
					}
					html += closed ? " />" : ">";
				}
				for(var i = root.firstChild; i; i = i.nextSibling) {
					html += Editor.readNodes(i, true);
				}
				if(toptag && !closed) {
					html += "</" + root.tagName.toLowerCase() + ">";
				}
				break;
	
			case Node.TEXT_NODE:
				html = root.data;
				break;
		}
		return html;
	},
	insertNodeAtSelection:function(insertNode) {
		var sel = Editor.editwin.getSelection();
	
		var range = sel.getRangeAt(0);
	
		sel.removeAllRanges();
	
		range.deleteContents();
	
		var container = range.startContainer;
		var pos = range.startOffset;
	
		// make a new range for the new selection
		range=document.createRange();

		if (container.nodeType==3 && insertNode.nodeType==3) {
	
			// if we insert text in a textnode, do optimized insertion
			container.insertData(pos, insertNode.nodeValue);
	
			// put cursor after inserted text
			range.setEnd(container, pos+insertNode.length);
			range.setStart(container, pos+insertNode.length);
	
		} else {
	
			var afterNode;
			if (container.nodeType==3) {
				var textNode = container;
				container = textNode.parentNode;
				var text = textNode.nodeValue;
				// text before the split
				var textBefore = text.substr(0,pos);
				// text after the split
				var textAfter = text.substr(pos);
				
				var beforeNode = document.createTextNode(textBefore);
				afterNode = document.createTextNode(textAfter);
	
				// insert the 3 new nodes before the old one
				container.insertBefore(beforeNode, textNode);
				container.insertBefore(insertNode, textNode);
				container.insertBefore(afterNode, textNode);
				// remove the old node
				container.removeChild(textNode);
				textNode = text = textBefore = textAfter = beforeNode = null;
			} else {
				afterNode = container.childNodes[pos];
				container.insertBefore(insertNode, afterNode);
			}
	
			range.setEnd(afterNode, 0);
			range.setStart(afterNode, 0);
			afterNode = null;
		}
	
		sel.addRange(range);
		sel = range = container = pos = null;
	},
	insertCode:function(code) {
		var content = null;
		if (flagEX == "IE") {
			content = arguments[1]?arguments[1]:Editor.editdoc.selection.createRange();
			content.pasteHTML(code);
			content = null
		} else {
			//Editor.execFormat("insertHTML",code);
			var fragment = document.createDocumentFragment();
			var holder = document.createElement('span');
			holder.innerHTML = code;
			while(holder.firstChild) {
				fragment.appendChild(holder.firstChild);
			}
			Editor.checkFocus();
			Editor.insertNodeAtSelection(fragment);
			fragment = holder = null;
		}
	},
	insertHideCode:function() {
		Editor.checkFocus();
		var content = Editor.getSelectionCode();
		Editor.insertCode("[hide]"+content+"[/hide]");
		content = null;
	},
	insertQuoteCode:function() {
		Editor.checkFocus();
		var content = Editor.getSelectionCode();
		Editor.insertCode("[quote]"+content+"[/quote]");
		content = null;
	},
	emptyContent:function() {
		if (confirm("是否清除现在编辑的所有内容?")) {
			Editor.editdoc.body.innerHTML = "";
		}
	},
	checkConentLength:function() {
		var content = Editor.editdoc.body.innerHTML;
		var size = 0;
	},
	clearContentHtml:function() {
		if (confirm("是否清除所有HTML代码?")) {
			var scriptreg = /<script[^>]*?>[\S\s]*?<\/script>/ig;
			var stylereg = /<style[^>]*?>[\S\s]*?<\/style>/ig;
			var imgreg = /<img([^>]*?)>/ig;
			var htmlreg = /<[^>]*?>/ig;
			var brreg = /<br[\/]?>/ig;
			var preg = /<p[^>]*?>/ig;
			var endpreg = /<\/p>/ig;
			var content = Editor.editdoc.body.innerHTML;
			content = content.replace(brreg,"[br]");
			content = content.replace(preg,"[p]");
			content = content.replace(endpreg,"[/p]");
			content = content.replace(imgreg,function($0,$1){return "[img"+$1+"]";});
			content = content.replace(scriptreg,"");
			content = content.replace(stylereg,"");
			content = content.replace(htmlreg,"");
			content = content.replace(/\[br\]/ig,"<br/>");
			content = content.replace(/\[p\]/ig,"<p>");
			content = content.replace(/\[\/p\]/ig,"</p>");
			content = content.replace(/\[img([^\]]*?)\]/ig,function($0,$1){return "<img"+$1+">";});
			content = content.replace(/　/ig,"");
			content = content.replace(/&nbsp;/ig,"");
			Editor.editdoc.body.innerHTML = content;
			scriptreg = stylereg = htmlreg = brreg = preg = endpreg = content = null;
		}
	}
};
