var ieSelectionBookmark ;//记录IE的编辑光标
function insertEditor(mid,content,id,width,height){
	var sHTML = "";
	if(id==""||id==undefined)
	{
		id="wrEditor";
	}
	if(width==""||width==undefined)
	{
		width="416";
	}
	if(height==""||height==undefined)
	{
		height="258";
	}
	if(id=="wrEditor")
	{
		sHTML = '<iframe name="'+id+'" id="'+ id +'" width="'+ width +'" height="'+ height +'" src="content.htm" onbeforedeactivate="javascript:markIESelection(this)" onactivate="javascript:markIEReset(this)"></iframe>';
	}
	else
	{
		sHTML = '<iframe name="'+id+'" id="'+ id +'" width="'+ width +'" height="'+ height +'" src="content.htm" ></iframe>';
	}
	oe = document.getElementById(mid);
	oe.insertAdjacentHTML("beforeBegin",sHTML);
	var oEditor = document.getElementById(id);
	if (oEditor.attachEvent){
		oEditor.attachEvent("onload", function(e){
			var oe = e.target || window.event.srcElement;　
			oe.contentWindow.document.body.innerHTML = g_content;
			oe.contentWindow.document.designMode="On";
			//oe.focus();
		});
	} 
}

function getContent(id)
{
	if(id==""||id==undefined)
	{
		id="wrEditor";
	}
	return document.getElementById(id).contentWindow.document.body.innerHTML;
}

function setContent(Content,id)
{
	if(id==""||id==undefined)
	{
		id="wrEditor";
	}
	document.getElementById(id).contentWindow.document.body.innerHTML = Content;
}

function correctUrl(cont)
{
	var regExp;
	regExp = /<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi
	cont = cont.replace(regExp, "<a href=$2 target=\"_blank\"");
	regExp = /<a([^>]*)><\/a>/gi
	cont = cont.replace(regExp, "");
	return cont;
}

var ieSelectionBookmark ;
/**
* 记录IE的编辑光标
*/

function markIESelection(iframeid)
{ 
	if(iframeid.name=="wrEditor")
	{
		var contentWindow = document.getElementById("wrEditor").contentWindow;
		var range = contentWindow.document.selection.createRange();
		ieSelectionBookmark = range.getBookmark();
	}
}

/**
* 复位IE的编辑光标
*/
function markIEReset(iframeid)
{
	if(iframeid.name=="wrEditor")
	{
		if(ieSelectionBookmark){
		var contentWindow = document.getElementById("wrEditor").contentWindow;
		var range = contentWindow.document.body.createTextRange();
		range.moveToBookmark(ieSelectionBookmark);
		range.select();
		ieSelectionBookmark = null;
		}
	}
}