////////////////////////////////////////////////////////////////////////////////////////////
//This editor is written by one_puppy@yahoo.com. base on the following reference
//http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/ie55/EditRegions/default.asp
//http://www.mozilla.org/editor/midas-spec.html
//Button & image is print screen from MS Word & MS FrontPage
//Version: 0.5 beta
//Road map:
//0.5 Release
//	* Insert images
//	* Insert flash
//	* Insert music/movie
//	*
/////////////////////////////////////////////////////////////////////////////////////////////////////
//Global variables
//////////////////////////////////////////////////////////////////////////////////////////

var currentDialog;
var currentCommand;
var currentEditorName;
var currentRange;
var currentView;

//////////////////////////////////////////////////////////////////////////////////////////
//Initial editor variables
//////////////////////////////////////////////////////////////////////////////////////////

function RichTextEditor(editorName)
{
	
	this.name = editorName;
	//Text format control
	this.enableFormatBlock = true;
	this.enableFontName = true;
	this.enableFontSize = true;
	this.enableIncreaseFontSize = true;
	this.enableDecreaseFontSize = true;
	
	this.enableBold = true;
	this.enableItalic = true;
	this.enableUnderline = true;
	this.enableJustifyLeft = true;
	this.enableJustifyRight = true;
	this.enableJustifyCenter = true;
	this.enableJustifyFull = true;
	this.enableStrikethrough = true;
	
	this.enableSuperscript = true;
	this.enableSubscript = true;
	
	
	
	this.enableInsertHorizontalRule = true;
	this.enableInsertOrderedList = true;
	this.enableInsertUnorderedList = true;
	
	this.enableOutdent = true;
	this.enableIndent = true;
	this.enableForeColor = true;
	this.enableHighLightColor = true;
	this.enableInsertLink = true;
	this.enableInsertImage = true;
	this.enableInsertSpecialChars = true;
	this.enableInsertTable = true;
	this.enableSpellcheck = true;
	
	this.enableCut = true;
	this.enableCopy = true;
	this.enablePaste = true;
	this.enableUndo = true;
	this.enableRedo = true;
	this.enableRemoveFormat = true;
	this.enableUnlink = true;
	this.enableSwitchView = true;
	//Global control
	this.width = 440;
	this.height = 300;
	this.isRichText = true;
	this.value = "Welcome to my editor";
	this.NEW_LINE = "\r\n";
	this.imageFolder = "images/";
	this.editorFolder = "";
	this.comboClass = "textbox";
	this.buttonClass = "image";
	this.buttonClassOver = "image";
	this.isReadOnly = false;
	this.checkBrowser();
	
}
//////////////////////////////////////////////////////////////////////////////////////////
//Load editor control
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.loadControl = function()
{
	var strControlString = "";
	this.checkBrowser();
	if(!this.isRichText)
	{
		var iMaxLoop = 1000;
		var arrReplace = new Array("<br />","<br/>","#NEW_LINE#");
		for(i = 0; i < arrReplace.length;i++)
		{
			var iIndex = 0;
			while((this.value.toLowerCase().indexOf(arrReplace[i].toLowerCase()) >= 0) && (iIndex < iMaxLoop))
			{
				this.value = this.value.replace(arrReplace[i],"\r\n");
				this.value = this.value.replace(arrReplace[i].toLowerCase(),"\r\n");
				this.value = this.value.replace(arrReplace[i].toUpperCase(),"\r\n");
				iIndex++;
			}
		}
	
		this.value = this.value.replace("<br />","\r\n");
	}
	if((this.isRichText) && (this.isIE || this.isGecko))
	{
		
		strControlString = strControlString + "<table width=\"100%\" border=\"0\" style=\"width:" + this.width + "px;height:" + this.height + "px;\" cellspacing=\"0\" cellpadding=\"0\">" + this.NEW_LINE;
		strControlString = strControlString + " <tr>" + this.NEW_LINE;
		strControlString = strControlString + "  <td>" + this.NEW_LINE;
		strControlString = strControlString + "   <table width=\"100%\" id=\"tblButton" + this.name + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + this.NEW_LINE;
		strControlString = strControlString + "   	<tr>" + this.NEW_LINE;
		strControlString = strControlString + "    		<td>" + this.NEW_LINE;
		//Button Control
		strControlString = strControlString + "   			<table width=\"100%\" border=\"0\" background=\"" + this.imageFolder + "bar_background.gif\" cellspacing=\"0\" cellpadding=\"0\">" + this.NEW_LINE;
		strControlString = strControlString + "   				<tr>" + this.NEW_LINE;
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<img src=\"" + this.imageFolder + "begin_group.gif\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		if(this.enableFormatBlock)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<select class=\"" + this.comboClass + "\" id=\"cbFormatBlock" + this.name + "\" onchange=\"changeFormat('" + this.name + "',this,'formatblock');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"\">Style</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<p>\">Paragraph &lt;p&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h1>\">Heading 1 &lt;h1&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h2>\">Heading 2 &lt;h2&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h3>\">Heading 3 &lt;h3&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h4>\">Heading 4 &lt;h4&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h5>\">Heading 5 &lt;h5&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<h6>\">Heading 6 &lt;h6&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<address>\">Address &lt;ADDR&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"<pre>\">Formatted &lt;pre&gt;</option>" + this.NEW_LINE;
		strControlString = strControlString + "    						</select>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		if(this.enableFontName)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<select class=\"" + this.comboClass + "\" id=\"cbFontName" + this.name + "\" onchange=\"changeFormat('" + this.name + "',this,'fontname');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"\">Font</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Arial\">Arial</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Courier New\">Courier New</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Garamond\">Garamond</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Georgia\">Georgia</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Tahoma\">Tahoma</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Times New Roman\">Times</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"Verdana\">Verdana</option>" + this.NEW_LINE;
		strControlString = strControlString + "    						</select>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableFontSize)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<select class=\"" + this.comboClass + "\" id=\"cbFontName" + this.name + "\" onchange=\"changeFormat('" + this.name + "',this,'fontsize');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"\">Size</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"1\">1 (8 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"2\">2 (10 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"3\">3 (12 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"4\">4 (14 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"5\">5 (18 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"6\">6 (24 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    							<option value=\"7\">7 (36 pt)</option>" + this.NEW_LINE;
		strControlString = strControlString + "    						</select>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		if(this.enableBold)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Bold\" href=\"javascript:execCommand('" + this.name + "','bold','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "bold.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableItalic)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Italic\" href=\"javascript:execCommand('" + this.name + "','italic','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "italic.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableUnderline)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Underline\" href=\"javascript:execCommand('" + this.name + "','underline','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "underline.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableStrikethrough)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Superscript\" href=\"javascript:execCommand('" + this.name + "','strikethrough','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "strike_through.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<img src=\"" + this.imageFolder + "end_group.gif\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		
		strControlString = strControlString + "	   			 	</tr>" + this.NEW_LINE;
		strControlString = strControlString + "					</table>" + this.NEW_LINE;
		
		
		
		
		
		
		
		
		
		
		//Button Control
		strControlString = strControlString + "   			<table width=\"100%\" border=\"0\" background=\"" + this.imageFolder + "bar_background.gif\" cellspacing=\"0\" cellpadding=\"0\">" + this.NEW_LINE;
		strControlString = strControlString + "   				<tr>" + this.NEW_LINE;
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<img src=\"" + this.imageFolder + "begin_group.gif\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		
		
		if(this.enableJustifyLeft)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Align Left\" href=\"javascript:execCommand('" + this.name + "','justifyleft','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "justify_left.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		if(this.enableJustifyRight)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Align Right\" href=\"javascript:execCommand('" + this.name + "','justifyright','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "justify_right.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		
		if(this.enableJustifyCenter)
		{
		
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Align Center\" href=\"javascript:execCommand('" + this.name + "','justifycenter','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "justify_center.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		if(this.enableJustifyFull)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Align Justify\" href=\"javascript:execCommand('" + this.name + "','justifyfull','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "justify_full.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableInsertHorizontalRule)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Horizontal Rule\" href=\"javascript:execCommand('" + this.name + "','inserthorizontalrule','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "horizontal_rule.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableInsertOrderedList)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Numbering\" href=\"javascript:execCommand('" + this.name + "','insertorderedlist','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "ordered_list.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableInsertUnorderedList)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Bullets\" href=\"javascript:execCommand('" + this.name + "','insertunorderedlist','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "unordered_list.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableIndent)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Decrease Indent\" href=\"javascript:execCommand('" + this.name + "','outdent','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "outdent.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		if(this.enableOutdent)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Increase Indent\" href=\"javascript:execCommand('" + this.name + "','indent','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "indent.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		if(this.enableSubscript)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Subscript\" href=\"javascript:execCommand('" + this.name + "','subscript','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "sub_script.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		
		
		if(this.enableSuperscript)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Superscript\" href=\"javascript:execCommand('" + this.name + "','superscript','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img src=\"" + this.imageFolder + "super_script.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		
	
		if(this.enableForeColor)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Fore Color\" href=\"javascript:openColorWindow('" + this.name + "','forecolor','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img id=\"btnForeColor" + this.name + "\" src=\"" + this.imageFolder + "font_color.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
		
		if(this.enableHighLightColor)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"High Light\" href=\"javascript:openColorWindow('" + this.name + "','hightlight','');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img  id=\"btnHighLightColor" + this.name + "\" src=\"" + this.imageFolder + "high_light.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
	
		if(this.enableInsertLink)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Insert Hyperlink\" href=\"javascript:openWindow('" + this.name + "','insert_link.html','InsertLink','320','170');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img  id=\"btnInsertHyperlink" + this.name + "\" src=\"" + this.imageFolder + "link.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
	
		if(this.enableInsertTable)
		{
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<a title=\"Insert Table\" href=\"javascript:openWindow('" + this.name + "','insert_table.html','InsertTable','400','350');\">" + this.NEW_LINE;
		strControlString = strControlString + "    							<img  id=\"btnInsertHyperlink" + this.name + "\" src=\"" + this.imageFolder + "insert_table.gif\" border=\"0\" class=\"" + this.buttonClass + "\">" + this.NEW_LINE;
		strControlString = strControlString + "    						</a>" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		}
	
		
	
		
		strControlString = strControlString + "    					<td>" + this.NEW_LINE;
		strControlString = strControlString + "    						<img src=\"" + this.imageFolder + "end_group.gif\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
		strControlString = strControlString + "    					</td>" + this.NEW_LINE;
		
		strControlString = strControlString + "	   			 	</tr>" + this.NEW_LINE;
		strControlString = strControlString + "					</table>" + this.NEW_LINE;
		
		
		strControlString = strControlString + "    		</td>" + this.NEW_LINE;
		strControlString = strControlString + "	    </tr>" + this.NEW_LINE;
		
		strControlString = strControlString + "  </table>" + this.NEW_LINE;
		strControlString = strControlString + "  </td>" + this.NEW_LINE;
		strControlString = strControlString + " </tr>" + this.NEW_LINE;
		
		
		strControlString = strControlString + " <tr>" + this.NEW_LINE;
		strControlString = strControlString + "   <td>" + this.NEW_LINE;
		//Iframe box
		strControlString = strControlString + "    	<iframe id=\"i" + this.name + "\" name=\"i" + this.name + "\" width=\"" + this.width + "\" height=\"" + this.height + "\" src=\"blank.html\"></iframe>" + this.NEW_LINE;
		strControlString = strControlString + "    	<iframe id=\"iDialog" + this.name + "\" name=\"iDialog" + this.name + "\" width=\"200\" src=\"\" height=\"180\" src=\"blank.html\" scrolling=\"no\" style=\"visibility:hidden; position: absolute;\"></iframe>" + this.NEW_LINE;
		strControlString = strControlString + "			<input type=\"hidden\" name=\"" + this.name + "\" id=\"" + this.name + "\" value=\"" + this.value + "\">";
		
		//Global configuration value
		strControlString = strControlString + "			<input type=\"hidden\" name=\"imageFolder" + this.name + "\" id=\"imageFolder" + this.name + "\" value=\"" + this.imageFolder + "\">";
		strControlString = strControlString + "			<input type=\"hidden\" name=\"editorFolder" + this.name + "\" id=\"editorFolder" + this.name + "\" value=\"" + this.editorFolder + "\">";

		
		strControlString = strControlString + "   </td>" + this.NEW_LINE;
		strControlString = strControlString + " </tr>" + this.NEW_LINE;
		if(this.enableSwitchView)
		{
			strControlString = strControlString + " <tr>" + this.NEW_LINE;
			strControlString = strControlString + "   <td>" + this.NEW_LINE;
			//Switch view
			strControlString = strControlString + "   	<table width=\"1%\" border=\"0\" background=\"" + this.imageFolder + "bar_background.gif\" cellspacing=\"0\" cellpadding=\"0\">" + this.NEW_LINE;
			strControlString = strControlString + "   		<tr>" + this.NEW_LINE;
			strControlString = strControlString + "    			<td>" + this.NEW_LINE;
			strControlString = strControlString + "    				<a title=\"Design View\" href=\"javascript:switchView('" + this.name + "','design');\">" + this.NEW_LINE;
			strControlString = strControlString + "    					<img  id=\"btnDesignView" + this.name + "\" src=\"" + this.imageFolder + "design_select.gif\" border=\"0\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
			strControlString = strControlString + "    				</a>" + this.NEW_LINE;
			strControlString = strControlString + "    			</td>" + this.NEW_LINE;
			strControlString = strControlString + "    			<td>" + this.NEW_LINE;
			strControlString = strControlString + "    				<a title=\"Code View\" href=\"javascript:switchView('" + this.name + "','code');\">" + this.NEW_LINE;
			strControlString = strControlString + "    					<img  id=\"btnCodeView" + this.name + "\" src=\"" + this.imageFolder + "code.gif\" border=\"0\" style==\"margin:0px;padding:0px;\">" + this.NEW_LINE;
			strControlString = strControlString + "    				</a>" + this.NEW_LINE;
			strControlString = strControlString + "    			</td>" + this.NEW_LINE;
			strControlString = strControlString + "	   		</tr>" + this.NEW_LINE;
			strControlString = strControlString + "			</table>" + this.NEW_LINE;
			
			strControlString = strControlString + "    </td>" + this.NEW_LINE;
			strControlString = strControlString + "  </tr>" + this.NEW_LINE;
		}
		strControlString = strControlString + "</table>" + this.NEW_LINE;
		currentView = "design";
	}
	else
	{
		
		strControlString = strControlString + "<textarea name=\"" + this.name + "\" id=\"" + this.name + "\" style=\"width:" + this.width + "px;height:" + this.height + "px;\">" + this.value + "</textarea>";
		strControlString = strControlString + "<input type=\"hidden\" name=\"hIsTextArea" + this.name + "\" id=\"hIsTextArea" + this.name + "\" value=\"1\">";
		
	}
	//////alert(strControlString);
	document.write(strControlString);
	
	if(this.isRichText)
	{
		this.initialEditor();
	}
};

//////////////////////////////////////////////////////////////////////////////////////////
//Initial editor
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.initialEditor = function()
{
	var editorName = this.name;
	var objEditorDocument = this.getEditorDocument();
	var ControlValueFormatted = this.formatInitValue(this.value);
	
	document.getElementById(this.name).value = ControlValueFormatted;
	////alert(document.getElementById(this.name).value);
	if(this.isIE)
	{
		objEditorDocument.open();
		objEditorDocument.write(ControlValueFormatted);
		objEditorDocument.close();
		if(!this.isReadOnly)
		{
			objEditorDocument.designMode = "On";
		}
		
		var myEditor = this;
		var objEditor = this.getEditorObject()
		if(!this.isGecko)
		{
			objEditor.focus();
		}
		objEditorDocument.attachEvent("onkeyup",function (e){ myEditor.ieBlur(e);});
		//objEditorDocument.attachEvent("onblur",function (e){ myEditor.ieBlur(e);});
		objEditorDocument.attachEvent("onkeypress",function (e){ myEditor.ieKeyPress(e);});
		
	}
	if(this.isGecko)
	{
		objEditorDocument.open();
		objEditorDocument.write(ControlValueFormatted);
		objEditorDocument.close();
		if(!this.isReadOnly)
		{
			objEditorDocument.designMode = "On";
		}
		var myEditor = this;
		objEditorDocument.addEventListener("keypress", function (e){ myEditor.geckoKeyPress(e);}, true);
		objEditorDocument.addEventListener("blur", function (e){ myEditor.geckoBlur(e);}, true);
	}
}
/////////////////////////////////////////
//
/////////////////////////////////////////
RichTextEditor.prototype.formatInitValue = function(initValue)
{
	var strReturnValue = initValue;
	var iMaxLoop = 1000;
	

	var arrReplace = new Array("&lt;","&gt;","&quot;","&39;","&amp;","#NEW_LINE#");
	var arrNewReplace = new Array("<",">","\"","'","&","\r\n");
	for(i = 0; i < arrReplace.length;i++)
	{
		var iIndex = 0;
		while((strReturnValue.toLowerCase().indexOf(arrReplace[i].toLowerCase()) >= 0) && (iIndex < iMaxLoop))
		{
			strReturnValue = strReturnValue.replace(arrReplace[i],arrNewReplace[i]);
			strReturnValue = strReturnValue.replace(arrReplace[i].toLowerCase(),arrNewReplace[i]);
			strReturnValue = strReturnValue.replace(arrReplace[i].toUpperCase(),arrNewReplace[i]);
			iIndex++;
		}
	}
	var strRealReturnValue = ""; 
	//Format html to bound text to prevent unspecifed error
	strRealReturnValue = strRealReturnValue + "<html>";
	strRealReturnValue = strRealReturnValue + "<head>";
	strRealReturnValue = strRealReturnValue + "</head>";
	strRealReturnValue = strRealReturnValue + "<body>";
	strRealReturnValue = strRealReturnValue + strReturnValue;
	strRealReturnValue = strRealReturnValue + "</body>";
	strRealReturnValue = strRealReturnValue + "</html>";
	return strRealReturnValue;
};

/////////////////////////////////////////
//Get the editor object
/////////////////////////////////////////
RichTextEditor.prototype.getEditorName = function()
{
	var IFrameName = "i" + this.name;
	return IFrameName;
}
/////////////////////////////////////////
//Get the editor object
/////////////////////////////////////////
RichTextEditor.prototype.getEditorDocument = function()
{
	var objEditorDocument = this.getEditorObject().document;
	return objEditorDocument;
	
}
/////////////////////////////////////////
//Get the editor object
/////////////////////////////////////////
RichTextEditor.prototype.getEditorObject = function()
{

	var objEditor = this.getIFrameObject(this.getEditorName());
	return objEditor;
	
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.getIFrameObject = function(strIFrameName)
{
	var objEditor = frames[strIFrameName];
	if(this.isGecko)
	{
		objEditor = document.getElementById(strIFrameName).contentWindow;
	}
	return objEditor;
	
}
/////////////////////////////////////////
//Key press for gecko/firefox/
/////////////////////////////////////////
RichTextEditor.prototype.geckoKeyPress = function(evt)
{
	var editorName = evt.target.id;
	if (evt.ctrlKey) 
	{
		var key = String.fromCharCode(evt.charCode).toLowerCase();
		var command = "";
		switch (key) 
		{
			case "b": 
				command = "bold"; 
				break;
			case "i": 
				command = "italic"; 
				break;
			case "u": 
				command = "underline"; 
				break;
		};
		
		if (command != "") 
		{
			myEditor.execCommand(this.name,cmd, null);
			evt.preventDefault();
			evt.stopPropagation();
		}
 	}
	if(currentView == "code")
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerText);
	}
	else
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerHTML);
	}
	
	
}
/////////////////////////////////////////
//Key press for gecko/firefox/
/////////////////////////////////////////
RichTextEditor.prototype.geckoBlur = function(evt)
{
	document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerHTML);
}
//////////////////////////////////////////////////////////////////////////////////////
//Key press for ie
//////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.ieKeyPress = function(evt)
{
	var _ENTER = 13;
	
	//The following code is replace default tag <p> with <br />
	if (evt.keyCode == _ENTER)
	{
		var sel = this.getSelectionObject();
		if (sel.type == "Control") 
		{
			return;
		}
		var r = this.createRange(sel);
		if ((!this.CheckTag(r.parentElement(),'LI')) && (!this.CheckTag(r.parentElement(),'H'))) {
			r.pasteHTML('<br />');
			evt.cancelBubble = true; 
			evt.returnValue = false; 
			r.select();
			r.collapse(false);
		}
	}
	//////alert("Hello");
	document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerHTML);
	
};
//////////////////////////////////////////////////////////////////////////////////////
//Key press for ie
//////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.ieBlur = function(evt)
{
	
	if(currentView == "code")
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerText);
	}
	else
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerHTML);
	}
	//////alert(document.getElementById(this.name).value);
};
//////////////////////////////////////////////////////////////////////////////////////////
//Check Tag of selection selection
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.updateHTML = function()
{
	////alert("hello you 3" + this.getEditorDocument().body.innerHTML);
	if(currentView == "code")
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerText);
	}
	else
	{
		document.getElementById(this.name).value = formatHtml(this.getEditorDocument().body.innerHTML);
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
//Check Tag of selection selection
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.CheckTag = function(item,tagName)
{
	if (item.tagName.search(tagName)!=-1) 
	{
		return item;
	}
	if (item.tagName=='BODY') {
		return false;
	}
	item=item.parentElement;
	return this.CheckTag(item,tagName);
}
//////////////////////////////////////////////////////////////////////////////////////////
//Load editor control
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.checkBrowser = function()
{
	//Code check browser from http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html thanks mozilla
	
	var userAgent = navigator.userAgent.toLowerCase();
	this.isIE = ((userAgent.indexOf("msie") != -1) && (userAgent.indexOf("opera") == -1) && (userAgent.indexOf("webtv") == -1)); 
	this.isGecko = (userAgent.indexOf("gecko") != -1);
	this.isSafari = (userAgent.indexOf("safari") != -1);
	this.isKonqueror = (userAgent.indexOf("konqueror") != -1);
	this.isOpera = (userAgent.indexOf("opera") != -1);
	this.isWebTV = (userAgent.indexOf("webtv") != -1);
	//Check if this editor is enable to run or not
	var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);
	if(this.isIE)
	{
		var agt=navigator.userAgent.toLowerCase();
		var is_ie3  = (this.isIE && (is_major < 4));
	  var is_ie4  = (this.isIE && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	  var is_ie4up = (this.isIE && (is_major >= 4));
	  var is_ie5  = (this.isIE && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	  var is_ie5_5 = (this.isIE && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
		
		var isIE5_5up =(this.isIE && !is_ie3 && !is_ie4 && !is_ie5);
		if(!isIE5_5up)
		{
			this.isRichText = false;
		}
	}
	if(this.isGecko)
	{
		if(parseFloat(getFirefoxVersion()) < 1)
		{
			//////alert("No enable editor|" + parseFloat(getFirefoxVersion()));
			this.isRichText = false;
		}
	}
};

//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function getFirefoxVersion()
{
	var agt=navigator.userAgent.toLowerCase();
	var iLastIndex = agt.lastIndexOf("/");
	var ffVersion = "0";
	if(iLastIndex > 0)
	{
		ffVersion = agt.substring(iLastIndex + 1,agt.length);
	}
	
	return parseFloat(ffVersion);
}
/////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.setRange = function()
{
	//function to store range of current selection
	var objEditor = this.getEditorObject();
	if (this.isIE) 
	{
		
		var selection = objEditor.selection; 
		if (selection != null) 
		{
			currentRange = selection.createRange();
		}
	} 
	else 
	{
		if (this.isGecko) 
		{
			var selection = objEditor.getSelection();
			currentRange = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		}
	}
};
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.createRange = function(selection)
{
	//function to store range of current selection
	var newRange;
	if (selection != null) 
	{
		if (this.isIE) 
		{
			newRange = selection.createRange();
		} 
		else 
		{
			if (this.isGecko) 
			{
				newRange = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
			}
		}
	}
	return newRange;
};
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
RichTextEditor.prototype.getSelectionObject = function()
{
	var objEditor = this.getEditorObject();
	var selection = null;
	
	if(this.isIE)
	{
		 selection = objEditor.document.selection;
		 //////alert(selection);
	}
	if (this.isGecko) 
	{
		selection = objEditor.getSelection();
		//////alert(selection);
	}
	return selection;
};
//////////////////////////////////////////////////////////////////////////////////
//Swich to code view
//////////////////////////////////////////////////////////////////////////////////
function switchView(editorName,view)
{

	var myEditor = new RichTextEditor(editorName);
	var btnCodeViewID = "btnCodeView" + myEditor.name;
	var btnDesignViewID = "btnDesignView" + myEditor.name;
	
	var tblButton = document.getElementById("tblButton" + myEditor.name);
	var btnCodeViewButton = document.getElementById(btnCodeViewID);
	var btnDesignViewButton = document.getElementById(btnDesignViewID);
	var hCodeViewControl = document.getElementById(myEditor.name);
	var winDesignViewWindow = document.getElementById(myEditor.getEditorName());
	
	//////alert(myEditor.getEditorDocument().body.innerText);
	switch(view)
	{
		case "code":
			if(currentView != "code")
			{
				btnCodeViewButton.src = "" + getEditorHiddenValue(editorName,"imageFolder") + "code_select.gif";
				btnDesignViewButton.src = "" + getEditorHiddenValue(editorName,"imageFolder") + "design.gif";
				if(myEditor.isIE)
				{
					myEditor.getEditorDocument().body.innerText = myEditor.getEditorDocument().body.innerHTML;
				}
				else
				{
					var htmlSource = myEditor.getEditorDocument().createTextNode(myEditor.getEditorDocument().body.innerHTML);
					myEditor.getEditorDocument().body.innerHTML = "";
					myEditor.getEditorDocument().body.appendChild(htmlSource);
				}
				tblButton.style.visibility = "hidden";
				currentView = "code";
			}
			break;
		case "design":
			if(currentView != "design")
			{
				btnCodeViewButton.src = "" + getEditorHiddenValue(editorName,"imageFolder") + "code.gif";
				btnDesignViewButton.src = "" + getEditorHiddenValue(editorName,"imageFolder") + "design_select.gif";
				if(myEditor.isIE)
				{
					myEditor.getEditorDocument().body.innerHTML = myEditor.getEditorDocument().body.innerText;
				}
				else
				{
					var htmlSource = myEditor.getEditorDocument().body.ownerDocument.createRange();
					htmlSource.selectNodeContents(myEditor.getEditorDocument().body);
					myEditor.getEditorDocument().body.innerHTML = htmlSource.toString();
				}
				currentView = "design";
				tblButton.style.visibility = "visible";
			}
			break;
	}
}
//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////
function formatHtml(strValue)
{
	var strReturnValue = strValue;
	//Remove for msword format
	var arrReplace = new Array("<Xmp>","</Xmp>","&lt;Xmp&gt;","&lt;/Xmp&gt;","<!--[if !supportLists]-->","<!--[endif]-->","&lt;!--[if !supportLists]--&gt;","&lt;!--[endif]--&gt;","class=MsoNormal","class='MsoNormal'","class=\"MsoNormal\"","class=&quot;MsoNormal&quot;","MsoNormal","amp;");
	var iMaxLoop = 1000;
	
	for(i = 0; i < arrReplace.length;i++)
	{
		var iIndex = 0;
		while((strReturnValue.toLowerCase().indexOf(arrReplace[i].toLowerCase()) >= 0) && (iIndex < iMaxLoop))
		{
			strReturnValue = strReturnValue.replace(arrReplace[i],"");
			strReturnValue = strReturnValue.replace(arrReplace[i].toLowerCase(),"");
			strReturnValue = strReturnValue.replace(arrReplace[i].toUpperCase(),"");
			iIndex++;
		}
	}
	
	strReturnValue = strReturnValue.replace(/<style[^>]*>/,"");
	strReturnValue = strReturnValue.replace("</style>","");
	
	
	return strReturnValue;
}

//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////
function getEditorHiddenValue(editorName, fieldName)
{
	var strReturnValue = "";
	if(document.getElementById(fieldName + editorName) != null)
	{
		strReturnValue = document.getElementById(fieldName + editorName).value;
	}
	return strReturnValue;
}
//////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////


function setColor(color)
{
	//////alert(currentEditorName);
	/*
	var myEditor = new RichTextEditor(currentEditorName);
	
	var objEditor = myEditor.getEditorObject();
	var selection = myEditor.getSelectionObject();

	////alert(selection);
	if (selection != null) 
	{
		var newRange = myEditor.createRange(selection);
		newRange = currentRange;
		newRange.select();
		
	}
	*/
	if(currentCommand == "hightlight")
	{
		execCommand(currentEditorName,"backcolor","#" + color);
	}
	else
	{
		execCommand(currentEditorName,"forecolor","#" + color);
	}
	closeCurrentDialog();
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function changeFormat(editorName,target,command)
{
	if(target.selectedIndex > 0)
	{
		var option = target.options[target.selectedIndex].value;
		var myEditor = new RichTextEditor(editorName);
		var objEditorDocument = myEditor.getEditorDocument();
		objEditorDocument.execCommand(command,false,option);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function execCommand(editorName,command,option)
{
	var myEditor = new RichTextEditor(editorName);
	var objEditorDocument = myEditor.getEditorDocument();
	try
	{
		objEditorDocument.execCommand(command,false,option);
	}
	catch(exception)
	{
		
	}
	/*
	if(myEditor.isGecko)
	{
		////alert("hello you 1");
		setTimeout(function() 
		{
			////alert("hello you 2");
			myEditor.updateHTML();
		}, 100);	
	}
	else
	{
		myEditor.updateHTML();
	}
	*/
	myEditor.updateHTML();
}
/////////////////////////////////////////
//Get the editor object
/////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function openColorWindow(editorName,command,option)
{
	var ColorHtmlString = "";
	closeCurrentDialog();
	/*
	ColorHtmlString = ColorHtmlString + "<div id=\"Layer1\" style=\"position:absolute; width:200px; height:115px; z-index:1\">";
	ColorHtmlString = ColorHtmlString + " <p>sdgsgsd</p>";
	ColorHtmlString = ColorHtmlString + " <p>sgsgs</p>";
	ColorHtmlString = ColorHtmlString + "</div>";
	test.innerHTML = ColorHtmlString;
	//document.write(ColorHtmlString);
	*/
	
	var myEditor = new RichTextEditor(editorName);
	currentEditorName = myEditor.name;
	var strDialogName = "iDialog" + myEditor.name;
	////////alert(strDialogName);
	
	var objDialog = document.getElementById(strDialogName);
	
	oldRange = myEditor.setRange();
	var btnButtonID = "btnForeColor" + myEditor.name
	currentCommand = "forelight";
	if(command == "hightlight")
	{
		btnButtonID = "btnHighLightColor" + myEditor.name;
		currentCommand = "hightlight";
	}
	var buttonElement = document.getElementById(btnButtonID);
	
	var iLeftPos = getOffsetLeft(buttonElement);
	var iTopPos = getOffsetTop(buttonElement) + (buttonElement.offsetHeight + 4);
	objDialog.src = getEditorHiddenValue(editorName,"editorFolder") + "select_color.html";
	objDialog.style.left = (iLeftPos) + "px";
	objDialog.style.top = (iTopPos) + "px";
	
	objDialog.style.visibility = "visible";
	objDialog.style.width = "232";
	objDialog.style.height = "185";
	currentDialog = objDialog;
}

//////////////////////////////////////////////////////////////////////////////////
//Close the current active dialog if exist
//////////////////////////////////////////////////////////////////////////////////
function closeCurrentDialog()
{
	if(currentDialog != null)
	{
		currentDialog.style.visibility = "hidden";
	}
}
//////////////////////////////////////////////////////////////////////////////////
//Get Offset left of object
//////////////////////////////////////////////////////////////////////////////////
function getOffsetLeft(obj)
{
	var offsetParent = obj.offsetParent;
	var offsetLeft = obj.offsetLeft
	var iMaxParentLevel = 20;
	var i = 0;
	//Try to get container offset
	while((offsetParent != null) && (i < iMaxParentLevel))
	{
		offsetLeft = parseInt(offsetParent.offsetLeft,10) + parseInt(offsetLeft,10);
		offsetParent = offsetParent.offsetParent;
		i++;
	}
	return offsetLeft;
}
//////////////////////////////////////////////////////////////////////////////////
//Get Offset top of object
//////////////////////////////////////////////////////////////////////////////////
function getOffsetTop(obj)
{
	var offsetParent = obj.offsetParent;
	var offsetTop = obj.offsetTop
	var iMaxParentLevel = 20;
	var i = 0;
	//Try to get container offset
	while((offsetParent != null) && (i < iMaxParentLevel))
	{
		offsetTop = parseInt(offsetParent.offsetTop,10) + parseInt(offsetTop,10);
		offsetParent = offsetParent.offsetParent;
		i++;
	}
	return offsetTop;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////

function insertHTML(html) 
{
	//////alert(currentEditorName);
	var myEditor = new RichTextEditor(currentEditorName);
	var objEditor = myEditor.getEditorObject()
	objEditor.focus();
	if (myEditor.isIE) 
	{
		objEditor.document.selection.createRange().pasteHTML(html);
	} 
	else 
	{
		//////alert(currentEditorName + "--" + html);
		execCommand(currentEditorName,"inserthtml",html);
	}
}
//////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////
function formatUrl(strUrl)
{
	var tempUrl = strUrl.toLowerCase();
	if(tempUrl.indexOf("www.") >= 0)
	{
		//Check if it exist :// protocol
		if(tempUrl.indexOf("://") < 0)
		{
			strUrl = "http://" + strUrl;
		}
	}
	strUrl = strUrl.replace("dttxadmin/","");
	
	return strUrl;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function getCurrentEditor()
{
	
	var myEditor = new RichTextEditor(currentEditorName);
	return myEditor;
	
};
//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////
function openWindow(editorName,strUrl,Title,iWidth,iHeight)
{
	var width=iWidth-10;
	var height=iHeight-10;
	
	var iToolbarHeighEstimate = 100;
	//Align in center editor
	var myEditor = new RichTextEditor(editorName);
	currentEditorName = myEditor.name;
	/*
	var objEditorObject = document.getElementById(myEditor.getEditorName());
	var editorLeftOffset = getOffsetLeft(objEditorObject);
	var editorTopOffset = getOffsetTop(objEditorObject);
	//////alert(editorLeftOffset + " " + editorTopOffset);
	var LeftPosition = editorLeftOffset + (myEditor.width-width)/2;
	var TopPosition = editorTopOffset + (myEditor.height-height)/2 + iToolbarHeighEstimate;
	*/
	var LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	//////alert(editorLeftOffset + " " + editorTopOffset  + " " + LeftPosition  + " " + TopPosition );
	window.open(getEditorHiddenValue(editorName,"editorFolder") + strUrl,Title,'top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width='+width+',height='+height+'').focus();
}


//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////



