document.write('<script src="editor/variables.js"><\/script>');
function editor(textareaObjectID) {
	try{
	 	if(neweditorWidth>0){
			editorWidth = neweditorWidth;
		}else
			editorWidth=tmpeditorWidth;
	}catch(e){
		editorWidth=tmpeditorWidth;
	}
	try{
		if(neweditorHeight>0){
			editorHeight = neweditorHeight;
		}else
			editorHeight=tmpeditorHeight;
	}catch(e){
		editorHeight=tmpeditorHeight;
	}
	document.getElementById(textareaObjectID).style.display = 'none'; 
 var n = textareaObjectID;
	viewTextModeDif[n]=0;
	editornsToolbarWidth = parseFloat(editorWidth) + 2;
 var nsMenuBegin="<table border=0 cellspacing=0 cellpadding=0 width=100%><tr height=54><td background='" +imgDirectory+ "menu_left.png' style='padding-left:11px;'></td><td background='" +imgDirectory+ "menu.png'>";
 var nsMenuEnd="</td><td background='" +imgDirectory+ "menu_right.png' style='padding-left:11px;'></td></tr><tr height=5><td background='" +imgDirectory+ "under_menu_left.png' width=11></td><td background='" +imgDirectory+ "under_menu.png'></td><td width=11 background='" +imgDirectory+ "under_menu_right.png'></td></tr></table>";
 var nsToolbar;
 nsToolbar = nsMenuBegin+'<table cellpadding="0" cellspacing="0" border="0" style="width:' + editornsToolbarWidth + 'px;border: 0px solid #666666; height: 26px; border-bottom: 0px; border-top: 0px;"><tr>';
 
	for (var i = 0; i <= buttonsArray.length;) { 
 if (buttonsArray[i]) {
	 var buttonObj = nsToolbarList[buttonsArray[i]];
		 var buttonID = buttonObj[0];
	 var buttonTitle = buttonObj[1];
 var buttonImage = buttonObj[2];
		 var buttonImageRollover = buttonObj[3];
			if (buttonsArray[i] == "seperator") {
		 		nsToolbar += '<td style="width: 12px;" align="center"><img src="' +buttonImage+ '" border=0 unselectable="on" width="2" height="18" hspace="0" unselectable="on"></td>';
			} else if (buttonsArray[i] == "viewSource"){
		 nsToolbar += '<td style="width: 36px;">';
				nsToolbar += '<span id="HTMLMode' + n + '"><img src="' +buttonImage+ '" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '"  onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' +buttonImageRollover+ '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' + buttonImage + '\';" unselectable="on" width="36" height="22"></span>';
				nsToolbar += '<span id="textMode' + n + '"><img src="' +imgDirectory+ 'text.png" border=0 unselectable="on" title="viewText" id="ViewText"  onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' +imgDirectory+ 'text_o.png\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' +imgDirectory+ 'text.png\';" unselectable="on" width="36" height="22"></span>';
	 nsToolbar += '</td>';
			} else {
		 nsToolbar += '<td style="width: 24px;"><img  width="24" height="22" src="' +buttonImage+ '" style="behavior: url(../styles/pngfix.htc);" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' + buttonImageRollover + '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' + buttonImage + '\';" unselectable="on"></td>';
	 }
 }
 i++;
 }

 	nsToolbar += '<td style="width: 90px;"><span style="display:none;" id="FontsSelectelect' + n + '"></span></td>';
	nsToolbar += '<td style="width: 60px;"><span style="display:none;" id="FontsSelectizes' + n + '"></span></td>';
 nsToolbar += '<td>&nbsp;</td></tr></table>'; 
 var nsToolbar2;
 nsToolbar2 = '<table cellpadding="0" cellspacing="0" border="0" style="width:' + editornsToolbarWidth + 'px;border: 0px solid #666666; height: 24px; border-bottom: 0px; border-top: 0px;"><tr>';
	
	nsToolbar2 += '<td style="width: 90px;"><span style="display:block;" id="ClassSelect' + n + '"></span></td>';

 for (var j = 0; j <= buttonsArray2.length;) {
 if (buttonsArray2[j]) {
	 var buttonObj = nsToolbarList[buttonsArray2[j]];
		 var buttonID = buttonObj[0];
	 var buttonTitle = buttonObj[1];
 var buttonImage = buttonObj[2];
		 var buttonImageRollover = buttonObj[3];
		 if (buttonsArray2[j] == "seperator") {
		 nsToolbar2 += '<td style="width: 12px;" align="center"><img src="' +buttonImage+ '" border=0 unselectable="on" width="2" height="18" hspace="0" unselectable="on"></td>';
			} else if (buttonsArray2[j] == "viewSource"){
		 nsToolbar2 += '<td style="width: 36px;">';
				nsToolbar2 += '<span id="HTMLMode' + n + '"><img src="' +buttonImage+ '" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '"  onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' +buttonImageRollover+ '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' + buttonImage + '\';" unselectable="on" width="36" height="22"></span>';
				nsToolbar2 += '<span id="textMode' + n + '"><img src="' +imgDirectory+ 'text.png" border=0 unselectable="on" title="viewText" id="ViewText"  onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' +imgDirectory+ 'text_o.png\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' +imgDirectory+ 'text.png\';" unselectable="on" width="36" height="22"></span>';
	 nsToolbar2 += '</td>';
			} else {
		 nsToolbar2 += '<td style="width: 24px;"><img src="' +buttonImage+ '" style="behavior: url(../styles/pngfix.htc);" border=0 unselectable="on" title="' +buttonTitle+ '" id="' +buttonID+ '" class="button" onClick="formatText(this.id,\'' + n + '\');" onmouseover="if(className==\'button\'){className=\'buttonOver\'} this.src=\'' +buttonImageRollover+ '\';" onmouseout="if(className==\'buttonOver\'){className=\'button\'} this.src=\'' + buttonImage + '\';" unselectable="on" width="24" height="22"></td>';
	 }
 }
 j++;
 }
 nsToolbar2 += '<td>&nbsp;</td></tr></table>'; 
	var iframe = '<table border=0 cellspacing=0 cellpadding=0><tr height=8><td background="' +imgDirectory+ 'iframe_top_left.png" width=11></td><td background="' +imgDirectory+ 'iframe_top.png"></td><td width=11 background="' +imgDirectory+ 'iframe_top_right.png"></td></tr><tr><td width=11 background="' +imgDirectory+ 'iframe_left.png"></td><td>'
 + '<table cellpadding="0" cellspacing="0" border="0" style="width:' + editorWidth + 'px; height:' + editorHeight + 'px;border:1px solid #ffffff;"><tr><td valign="top">\n'
 + '<iframe frameborder="0" id="editor' + n + '"></iframe>\n'
 + '</td></tr></table>'
 + '</td><td width=11 background="' +imgDirectory+ 'iframe_right.png"></td></tr><tr height=8><td width=11 background="' +imgDirectory+ 'iframe_bottom_left.png"></td><td background="' +imgDirectory+ 'iframe_bottom.png"></td><td width=11 background="' +imgDirectory+ 'iframe_bottom_right.png"></td></tr></table>';
 nsToolbar2 += nsMenuEnd;
 document.getElementById(n).insertAdjacentHTML("afterEnd", nsToolbar + nsToolbar2 + iframe);
	classSelection(n);
	fontSelection(n);
	sizeSelection(n); 
	classSelectHide(n);
 	fontsSelectHide(n);
	sizeSelectHide(n);
	document.getElementById("textMode" + n).style.display = 'none'; 
 document.getElementById("editor" + n).style.height = editorHeight + "px";
 document.getElementById("editor" + n).style.width = editorWidth + "px";
 var content = document.getElementById(n).value;
	var doc = document.getElementById("editor" + n).contentWindow.document;
	try{
		if(pageStyle){}
	}catch(e){
		pageStyle="";
	}
 doc.open();
 doc.write(pageStyle+content);
 doc.close();
 doc.body.contentEditable = true;
 doc.designMode = "on";
 var browserName = navigator.appName;
 if (browserName == "Microsoft Internet Explorer") {
 for (var idx=0; idx < document.forms.length; idx++) {
 document.forms[idx].attachEvent('onsubmit', function() { updateTextArea(n); });
 }
 } else {
 	for (var idx=0; idx < document.forms.length; idx++) {
 	document.forms[idx].addEventListener('submit',function OnSumbmit() { updateTextArea(n); }, true);
 }
 }
}
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
 HTMLElement.prototype.insertAdjacentElement = function
 (where,parsedNode)
	{
	 switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
 this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}
	HTMLElement.prototype.insertAdjacentHTML = function
 (where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}
	HTMLElement.prototype.insertAdjacentText = function
 (where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}
viewTextMode = 0;
function formatText(id, n, selected) {
 document.getElementById("editor" + n).contentWindow.focus();
	var formatIDs = new Array("FontsSelectize","FontName","Bold","Italic","Underline","Subscript","Superscript","Strikethrough","Justifyleft","Justifyright","Justifycenter","InsertUnorderedList","InsertOrderedList","Indent","Outdent","ForeColor","BackColor","InsertImage","InsertTable","CreateLink");
	for (var i = 0; i <= formatIDs.length;) {
		if (formatIDs[i] == id) {
			 var disabled_id = 1; 
		}
	 i++;
	}
	if (viewTextMode == 1 && disabled_id == 1) {
	 alert ("You are in HTML Mode. This feature has been disabled.");	
	} else {
	if(id == "className"){
		if(isIE){
			var workRange=document.getElementById("editor" + n).contentWindow.document.selection.createRange();
	 	 	xselection = workRange.text;
	 	 	workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 			var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 			xelement.outerHTML="<FONT class='"+selected+"'>"+xselection+"</FONT>";
		}else{
			var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT class='"+selected+"'>"+xselection+"</FONT>");
		}
	}else if (id == "FontsSelectize") {
	 	 document.getElementById("editor" + n).contentWindow.document.execCommand("FontSize", false, selected);
	 	/*if(isIE){
	 	 	var workRange=document.getElementById("editor" + n).contentWindow.document.selection.createRange();
	 	 	xselection = workRange.text;
 			var newHTML="";
 			//var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			fontsx=document.getElementById("editor" + n).contentWindow.document.getElementsByTagName('FONT');
 			lenf=fontsx.length;
 			var f=false;
	 		for(var i=0;i<lenf;i++){
	 			//alert(lenf);
	 			fontx=fontsx[i].innerHTML;
	 			zselection=xselection+"";
	 			fontx1=fontx.split(zselection);
		 		fontx2=zselection.split(fontx);
		 		if(fontx1.length>1){
	 				f=true;
		 			//alert("size out");
		 			if(fontsx[i].style.fontFamily){
		 				//alert(fontsx[i].style.fontFamily);
		 				//alert(zselection);
 						//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 						//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 						//xelement.outerHTML="<FONT style='font-family:"+fontsx[i].style.fontFamily+";font-size:"+selected+";'>"+zselection+"</FONT>";
		 				
		 				newHTML="<FONT style='font-family:"+fontsx[i].style.fontFamily+";font-size:"+selected+";'>"+zselection+"</FONT>";
		 			}else{
		 				//alert(zselection);
 						//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 						//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 						//xelement.outerHTML="<FONT style='font-size:"+selected+";'>"+zselection+"</FONT>";
 						
 						newHTML="<FONT style='font-size:"+selected+";'>"+zselection+"</FONT>";
 					}
		 		}else if(fontx2.length>1){
		 			f=true;
		 			//alert("size in");
		 			//alert(fontx);
		 			if(fontsx[i].style.fontFamily){
		 				ffamily=fontsx[i].style.fontFamily;
		 				zselection=zselection.replace(fontx,"<FONT style='font-family:"+ffamily+";font-size:"+selected+";'>"+fontx+"</FONT>");
		 			}
		 			//alert(zselection);
 					//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 					//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 					//xelement.outerHTML="<FONT style='font-size:"+selected+"'>"+zselection+"</FONT>";
 					
 					newHTML="<FONT style='font-size:"+selected+";'>"+zselection+"</FONT>";
		 		}
	 		}
	 		if(!f){
	 			//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 				//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 				//xelement.outerHTML="<FONT style='font-size:"+selected+";'>"+xselection+"</FONT>";
 				newHTML="<FONT style='font-size:"+selected+";'>"+xselection+"</FONT>";
 			}
 				workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 				var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 				xelement.outerHTML=newHTML;
 		}else{
 			//var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			//document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-size:"+selected+";'>"+xselection+"</FONT>");
 			
 			var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			fontsx=document.getElementById("editor" + n).contentWindow.document.getElementsByTagName('FONT');
 			var f=false;
	 		for(var i=0;i<fontsx.length;i++){
	 			fontx=fontsx[i].innerHTML;
	 			zselection=xselection+"";
	 			fontx1=fontx.split(zselection);
		 		fontx2=zselection.split(fontx);
		 		if(fontx1.length>1){
	 				f=true;
		 			//alert("size out");
		 			if(fontsx[i].style.fontFamily){
		 				//alert(fontsx[i].style.fontFamily);
		 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-family:"+fontsx[i].style.fontFamily+";font-size:"+selected+";'>"+zselection+"</FONT>");
		 			}else
		 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-size:"+selected+";'>"+zselection+"</FONT>");
		 		}else if(fontx2.length>1){
		 			f=true;
		 			//alert("size in");
		 			if(fontsx[i].style.fontFamily){
		 				ffamily=fontsx[i].style.fontFamily;
		 				zselection=zselection.replace(fontx,"<FONT style='font-family:"+ffamily+";font-size:"+selected+";'>"+fontx+"</FONT>");
		 			}
		 			document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-size:"+selected+"'>"+zselection+"</FONT>");
		 		}
	 		}
	 		if(!f)
 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-size:"+selected+";'>"+xselection+"</FONT>");
 		}*/
	 } else if (id == "FontName") {
	 	 document.getElementById("editor" + n).contentWindow.document.execCommand("FontName", false, selected);
	 	 /*if(isIE){
	 	 	var workRange=document.getElementById("editor" + n).contentWindow.document.selection.createRange();
	 	 	xselection = workRange.text;
 			var newHTML="";
 			//var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			fontsx=document.getElementById("editor" + n).contentWindow.document.getElementsByTagName('FONT');
 			lenf=fontsx.length;
 			var f=false;
	 		for(var i=0;i<lenf;i++){
	 			//alert(lenf);
	 			fontx=fontsx[i].innerHTML;
	 			zselection=xselection+"";
	 			fontx1=fontx.split(zselection);
		 		fontx2=zselection.split(fontx);
	 			if(fontx1.length>1){
	 				f=true;
		 			//alert("font out");
		 			if(fontsx[i].style.fontSize){
		 				//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 						//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 						//xelement.outerHTML="<FONT style='font-size:"+fontsx[i].style.fontSize+";font-family:"+selected+";'>"+zselection+"</FONT>";
 						
 						newHTML="<FONT style='font-size:"+fontsx[i].style.fontSize+";font-family:"+selected+";'>"+zselection+"</FONT>";
		 			}else{
		 				//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 						//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 						//xelement.outerHTML="<FONT style='font-family:"+selected+";'>"+zselection+"</FONT>";
 						
 						newHTML="<FONT style='font-family:"+selected+";'>"+zselection+"</FONT>";
		 			}
		 		}else if(fontx2.length>1){
		 			f=true;
		 			//alert("font in");
		 			if(fontsx[i].style.fontSize){
		 				fsize=fontsx[i].style.fontSize;
		 				zselection=zselection.replace(fontx,"<FONT style='font-size:"+fsize+";font-family:"+selected+";'>"+fontx+"</FONT>");
		 			}
		 			
		 			//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 					//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 					//xelement.outerHTML="<FONT style='font-family:"+selected+";'>"+zselection+"</FONT>";
 					
 					newHTML="<FONT style='font-family:"+selected+";'>"+xselection+"</FONT>";
		 		}
	 		}
	 		if(!f){
 				//workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 				//var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 				//xelement.outerHTML="<FONT style='font-family:"+selected+";'>"+xselection+"</FONT>";
 				
 				newHTML="<FONT style='font-family:"+selected+";'>"+zselection+"</FONT>";
 			}
 			workRange.execCommand("InsertInputHidden", false, "temporaryElement0");
 			var xelement = document.getElementById("editor" + n).contentWindow.document.getElementById("temporaryElement0");
 			xelement.outerHTML=newHTML;
 		}else{
 			var xselection=document.getElementById("editor" + n).contentWindow.getSelection();
 			fontsx=document.getElementById("editor" + n).contentWindow.document.getElementsByTagName('FONT');
 			var f=false;
	 		for(var i=0;i<fontsx.length;i++){
	 			fontx=fontsx[i].innerHTML;
	 			zselection=xselection+"";
	 			fontx1=fontx.split(zselection);
		 		fontx2=zselection.split(fontx);
	 			if(fontx1.length>1){
	 				f=true;
		 			//alert("font out");
		 			if(fontsx[i].style.fontSize)
		 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-size:"+fontsx[i].style.fontSize+";font-family:"+selected+";'>"+zselection+"</FONT>");
		 			else
		 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-family:"+selected+";'>"+zselection+"</FONT>");
		 		}else if(fontx2.length>1){
		 			f=true;
		 			//alert("font in");
		 			if(fontsx[i].style.fontSize){
		 				fsize=fontsx[i].style.fontSize;
		 				zselection=zselection.replace(fontx,"<FONT style='font-size:"+fsize+";font-family:"+selected+";'>"+fontx+"</FONT>");
		 			}
		 			document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-family:"+selected+"'>"+zselection+"</FONT>");
		 		}
	 		}
	 		if(!f)
 				document.getElementById("editor" + n).contentWindow.document.execCommand("inserthtml", false, "<FONT style='font-family:"+selected+";'>"+xselection+"</FONT>");
 			
 		}*/
	 } else if (id == 'ForeColor' || id == 'BackColor') {
 var w = screen.availWidth;
 var h = screen.availHeight;
 var popW = 315, popH = 230;
 var leftPos = (w-popW)/2, topPos = (h-popH)/2;
 var currentColor = parseRGB(document.getElementById("editor" + n).contentWindow.document.queryCommandValue(id));
	 window.open(dialogDirectory + 'select_color.html?color=' + currentColor + '&command=' + id + '&editor=' + n,'popup','location=0,status=0,scrollbars=0,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
 } else if (id == "InsertImage") {
 window.open(dialogDirectory + 'upload_image.php?editor=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=400,height=560');
	 } else if (id == "InsertTable") {
	 window.open(dialogDirectory + 'create_table.html?editor=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=400,height=360');
	 } else if (id == "CreateLink") {
	 window.open(dialogDirectory + 'insert_hyperlink.php?editor=' + n,'popup','location=0,status=0,scrollbars=0,resizable=0,width=320,height=600');
	 } else if (id == "ViewSource") {
	 viewSource(n);
	 }
		else if (id == "ViewText") {
	 viewText(n);
	 }
		else if (id == "Help") {
	 window.open(dialogDirectory + 'help.html','popup','location=0,status=0,scrollbars=0,resizable=0,width=700,height=500');
	 } else {
 document.getElementById("editor" + n).contentWindow.document.execCommand(id, false, null);
		}
 }
}
function insertHTML(html, n) {
 var browserName = navigator.appName;
	 	 
	if (browserName == "Microsoft Internet Explorer") {	 
	 document.getElementById('editor' + n).contentWindow.document.selection.createRange().pasteHTML(html); 
	} else {
	 var div = document.getElementById('editor' + n).contentWindow.document.createElement("div");
		div.innerHTML = html;
		var node = replaceSelectedWithNode(div, n);
	}
}
function replaceSelectedWithNode(insertNode, n) {
 var sel = document.getElementById('editor' + n).contentWindow.getSelection();
 var range = sel.getRangeAt(0);
 sel.removeAllRanges();
 range.deleteContents();
 var container = range.startContainer;
 var pos = range.startOffset;
 range=document.createRange();
 if (container.nodeType==3 && insertNode.nodeType==3) {
 container.insertData(pos, insertNode.nodeValue);
 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;
 var textBefore = text.substr(0,pos);
 var textAfter = text.substr(pos);
 var beforeNode = document.createTextNode(textBefore);
 afterNode = document.createTextNode(textAfter);
 container.insertBefore(afterNode, textNode);
 container.insertBefore(insertNode, afterNode);
 container.insertBefore(beforeNode, insertNode);
 container.removeChild(textNode);
 } else {
 afterNode = container.childNodes[pos];
 container.insertBefore(insertNode, afterNode);
 }
 range.setEnd(afterNode, 0);
 range.setStart(afterNode, 0);
 }
 sel.addRange(range);
}
function parseRGB(value) {
 var hex_string = "";
 for (var hexpair = 0; hexpair < 3; hexpair++) {
 var myByte = value & 0xFF;
 value >>= 8;
 var nybble2 = myByte & 0x0F;
 var nybble1 = (myByte >> 4) & 0x0F;
 hex_string += nybble1.toString(16);
 hex_string += nybble2.toString(16);
 }
 return hex_string.toUpperCase();
}
function classSelection(n) {
 var ClassSelectObj = nsToolbarList['selectclass'];
 var ClassSelection = ClassSelectObj[2];
 var ClassSelectOn = ClassSelectObj[3];
	var ClassSelectDropDown = new Array;
	ClassSelectDropDown[n] = '<table border="0" cellpadding="0" cellspacing="0" onmouseout="timedHideClassSelect(\'' + n + '\');" onmouseover="dontHideClassSelect(\''+n+'\');"><tr><td onMouseOver="document.getElementById(\'selectClass' + n + '\').src=\'' + ClassSelectOn + '\';" onMouseOut="document.getElementById(\'selectClass' + n + '\').src=\'' + ClassSelection + '\';"><img src="' + ClassSelection + '" id="selectClass' + n + '" width="85" height="22" onClick="showClassSelect(\'' + n + '\');" unselectable="on"><br>';
	ClassSelectDropDown[n] += '<span id="ClassSelectx' + n + '" class="dropdown" style="width: 145px;"  onmouseout="timedHideClassSelect(\''+n+'\');" onmouseover="dontHideClassSelect(\''+n+'\');">';
	for (var i = 0; i <= ClassSelect.length;) {
	 if (ClassSelect[i]) {
 ClassSelectDropDown[n] += '<button type="button" onClick="formatText(\'className\',\'' + n + '\',\'' + ClassSelect[i] + '\')\; classSelectHide(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 120px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left"><font class="' + ClassSelect[i] + '">' + ClassSelect[i] + '</font></td></tr></table></button><br>';	
 }	 
	 i++;
 }
	ClassSelectDropDown[n] += '</span></td></tr></table>';
	document.getElementById('ClassSelect' + n).insertAdjacentHTML("afterBegin", ClassSelectDropDown[n]);
}
function timedHideClassSelect(n){
	//alert("out");
	classSelectShown=true;
	setTimeout("hideClassSelect('"+n+"');",1500);
}
function hideClassSelect(n){
	//alert("hide");
	//alert(n);
	//alert(classSelectShown);
	if(classSelectShown)
		classSelectHide(n);
}
function dontHideClassSelect(n){
	//alert("in");
	classSelectShown=false;
}
function fontSelection(n) {
 var FontsSelectelectObj = nsToolbarList['selectfont'];
 var FontsSelectelect = FontsSelectelectObj[2];
 var FontsSelectelectOn = FontsSelectelectObj[3];
	FontsSelect.sort();
	var FontsSelectelectDropDown = new Array;
	FontsSelectelectDropDown[n] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td onMouseOver="document.getElementById(\'selectFont' + n + '\').src=\'' + FontsSelectelectOn + '\';" onMouseOut="document.getElementById(\'selectFont' + n + '\').src=\'' + FontsSelectelect + '\';"><img src="' + FontsSelectelect + '" id="selectFont' + n + '" width="85" height="22" onClick="showFontsSelect(\'' + n + '\');" unselectable="on"><br>';
	FontsSelectelectDropDown[n] += '<span id="FontsSelect' + n + '" class="dropdown" style="width: 145px;">';
	for (var i = 0; i <= FontsSelect.length;) {
	 if (FontsSelect[i]) {
 FontsSelectelectDropDown[n] += '<button type="button" onClick="formatText(\'FontName\',\'' + n + '\',\'' + FontsSelect[i] + '\')\; fontsSelectHide(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 120px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family:' + FontsSelect[i] + '; font-size: 12px;">' + FontsSelect[i] + '</td></tr></table></button><br>';	
 }	 
	 i++;
 }
	FontsSelectelectDropDown[n] += '</span></td></tr></table>';
	document.getElementById('FontsSelectelect' + n).insertAdjacentHTML("afterBegin", FontsSelectelectDropDown[n]);
}
function sizeSelection(n) {
 var FontsSelectizeObj = nsToolbarList['selectsize'];
 var FontsSelectize = FontsSelectizeObj[2];
 var FontsSelectizeOn = FontsSelectizeObj[3];
	FontsSelectizes.sort();
	var FontsSelectizesDropDown = new Array;
	FontsSelectizesDropDown[n] = '<table border="0" cellpadding="0" cellspacing="0" width=70><tr><td onMouseOver="document.getElementById(\'selectSize' + n + '\').src=\'' + FontsSelectizeOn + '\';" onMouseOut="document.getElementById(\'selectSize' + n + '\').src=\'' + FontsSelectize + '\';"><img src="' + FontsSelectize + '" id="selectSize' + n + '" width="60" height="22" onClick="showFontsSelectizes(\'' + n + '\');" unselectable="on"><br>';
 FontsSelectizesDropDown[n] += '<span id="Sizes' + n + '" class="dropdown" style="width: 85px;">';
	for (var i = 0; i <= FontsSelectizes.length;) {
	 if (FontsSelectizes[i]) {
 FontsSelectizesDropDown[n] += '<button type="button" onClick="formatText(\'FontsSelectize\',\'' + n + '\',\'' + FontsSelectizes[i] + '\')\;sizeSelectHide(\'' + n + '\');" onMouseOver="this.className=\'mouseOver\'" onMouseOut="this.className=\'mouseOut\'" class="mouseOut" style="width: 60px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td align="left" style="font-family: arial, verdana, helvetica;"><font style="font-size:' + FontsSelectizes[i] + 'mm;">' + FontsSelectizes[i] + '</font></td></tr></table></button><br>';	
 }	 
	 i++;
 }
	FontsSelectizesDropDown[n] += '</span></td></tr></table>';
	document.getElementById('FontsSelectizes' + n).insertAdjacentHTML("afterBegin", FontsSelectizesDropDown[n]);
}
function classSelectHide(n) {
 document.getElementById('ClassSelectx' + n).style.display = 'none'; 
}
function fontsSelectHide(n) {
 document.getElementById('FontsSelect' + n).style.display = 'none'; 
}
function sizeSelectHide(n) {
 document.getElementById('Sizes' + n).style.display = 'none'; 
}
function showClassSelect(n) { 
	//classSelectShown=true;
 if (document.getElementById('ClassSelectx' + n).style.display == 'block') {
 document.getElementById('ClassSelectx' + n).style.display = 'none';
	} else {
 document.getElementById('ClassSelectx' + n).style.display = 'block'; 
 document.getElementById('ClassSelectx' + n).style.position = 'absolute';
 }
}
function showFontsSelect(n) { 
 if (document.getElementById('FontsSelect' + n).style.display == 'block') {
 document.getElementById('FontsSelect' + n).style.display = 'none';
	} else {
 document.getElementById('FontsSelect' + n).style.display = 'block'; 
 document.getElementById('FontsSelect' + n).style.position = 'absolute';
 }
}
function showFontsSelectizes(n) { 
 if (document.getElementById('Sizes' + n).style.display == 'block') {
 document.getElementById('Sizes' + n).style.display = 'none';
	} else {
 document.getElementById('Sizes' + n).style.display = 'block'; 
 document.getElementById('Sizes' + n).style.position = 'absolute';
 }
}
function viewSource(n) {
 var getDocument = document.getElementById("editor" + n).contentWindow.document;
 var browserName = navigator.appName;
 if (browserName == "Microsoft Internet Explorer") {
 var iHTML = getDocument.body.innerHTML;
 	getDocument.body.innerText = iHTML;
	} else {
 var html = document.createTextNode(getDocument.body.innerHTML);
 getDocument.body.innerHTML = "";
 getDocument.body.appendChild(html);
	}
 document.getElementById('HTMLMode' + n).style.display = 'none'; 
	document.getElementById('textMode' + n).style.display = 'block';
	getDocument.body.style.FontsSelectize = "12px";
	getDocument.body.style.fontFamily = "Courier New"; 
 viewTextMode = 1;
 viewTextModeDif[n]=1;
}
function viewText(n) { 
 var getDocument = document.getElementById("editor" + n).contentWindow.document;
 var browserName = navigator.appName;
 if (browserName == "Microsoft Internet Explorer") {
 var iText = getDocument.body.innerText;
 getDocument.body.innerHTML = iText;
	} else {
 var html = getDocument.body.ownerDocument.createRange();
 html.selectNodeContents(getDocument.body);
 getDocument.body.innerHTML = html.toString();
	}
 document.getElementById('textMode' + n).style.display = 'none'; 
	document.getElementById('HTMLMode' + n).style.display = 'block';
 getDocument.body.style.FontsSelectize = "";
	getDocument.body.style.fontFamily = ""; 
	viewTextMode = 0;
	viewTextModeDif[n]=0;
}
function updateTextArea(n) {
	var browserName = navigator.appName;
	if (browserName == "Microsoft Internet Explorer") {
		document.getElementById(n).value = document.getElementById("editor" + n).contentWindow.document.body.innerHTML.replace( />\n/gi, ">");
	}else{
 		document.getElementById(n).value = document.getElementById("editor" + n).contentWindow.document.body.innerHTML.replace( /><br><\/td>/gi, "><div style='visibility: hidden; position: absolute;'><br></div></td>");
 }
}