//~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var oPopup = window.createPopup();
var editDefault=0;
var borderShown = "no";

	function isTextSelected() {
//			if (foo.document.selection.type == "Text") {
			if (document.selection.type == "Text") {
				return true;
			} else {
				return false;
			}
	}

	function doFormat(oFormat) {
		oDiv.focus();
//		if (isAllowed() && isTextSelected())
		if (isAllowed())
		{
//			foo.document.execCommand('formatBlock',false,oFormat);
			document.execCommand('formatBlock',false,oFormat);
		}
	}

	function showColor(oBox,oColor) {
		oBox.innerHTML = oColor.style.backgroundColor.toUpperCase();
		oBox.style.backgroundColor = oColor.style.backgroundColor;
	}

	function doColor(oColor) {
		myCommand = 'ForeColor';

		if (colorType == 2) {
			myCommand = 'BackColor';
		}

		if (isAllowed())
		{
//			foo.document.execCommand(myCommand,false,oColor.innerHTML);
			document.execCommand(myCommand,false,oColor.innerHTML);
		}
		oPopup.hide();
	}

	function toggleBorders() {
//		var allForms = oDiv.document.body.getElementsByTagName("FORM");
//		var allInputs = oDiv.document.body.getElementsByTagName("INPUT");
//		var allTables = oDiv.document.body.getElementsByTagName("TABLE");
//		var allLinks = oDiv.document.body.getElementsByTagName("A");

		var allForms = document.all.oDiv.getElementsByTagName("FORM");
		var allInputs = document.all.oDiv.getElementsByTagName("INPUT");
		var allTables = document.all.oDiv.getElementsByTagName("TABLE");
		var allLinks = document.all.oDiv.getElementsByTagName("A");
		
		if (borderShown == "no") {
			toggle = "off";
		} else {
			toggle = "on";
		}

		// Do forms
		for (a=0; a < allForms.length; a++) {
			if (toggle == "off") {
				allForms[a].style.border = "1px dotted #FF0000";
			} else {
				allForms[a].removeAttribute("style");
			}
		}

		// Do hidden fields
		for (b=0; b < allInputs.length; b++) {
			if (toggle == "off") {
				if (allInputs[b].type.toUpperCase() == "HIDDEN") {
					allInputs[b].style.border = "1px dashed #000000";
					allInputs[b].style.width = "15px";
					allInputs[b].style.height = "15px";
					allInputs[b].style.backgroundColor = "#FDADAD";
					allInputs[b].style.color = "#FDADAD";
				}
			} else {
				if (allInputs[b].type.toUpperCase() == "HIDDEN")
					allInputs[b].removeAttribute("style");
			}
		}


		// Do tables
		for (i=0; i < allTables.length; i++) {
				if (toggle == "off") {
					allTables[i].style.border = "1px dotted #BFBFBF";
				} else {
					allTables[i].removeAttribute("style");
				}
				allRows = allTables[i].rows;
				for (y=0; y < allRows.length; y++) {
				 	allCellsInRow = allRows[y].cells;
						for (x=0; x < allCellsInRow.length; x++) {
							if (toggle == "off") {
								allCellsInRow[x].style.border = "1px dotted #BFBFBF";
							} else {
								allCellsInRow[x].removeAttribute("style");
							}
						}
				}
		}

		// Do anchors
		for (a=0; a < allLinks.length; a++) {
			if (toggle == "off") {
				if (allLinks[a].href.toUpperCase() == "") {
					allLinks[a].style.border = "1px dashed #000000";
					allLinks[a].style.width = "20px";
					allLinks[a].style.height = "16px";
					allLinks[a].style.backgroundColor = "#FFFFCC";
					allLinks[a].style.color = "#FFFFCC";			
				}
			} else {
				allLinks[a].removeAttribute("style");
			}
		}

		// Do Editable Content
		if (editDefault == 1)
		{
//			allElem =  oDiv.document.getElementsByName("webedit");
			allElem =  oDiv.getElementsByName("webedit");
			for (a=0; a < allElem.length; a++) {
				if (toggle == "off") {
					allElem[a].style.backgroundColor = "#FFF4FF";
				} else {
					allElem[a].removeAttribute("style");
				}
			}
		}

		if (toggle == "off") {
//			button_down(tBorders);
			borderShown = "yes";
		} else {
//			button_out(tBorders);
			borderShown = "no";
		}

//		foo.document.body.innerHTML = foo.document.body.innerHTML;
//		scrollUp();
//		showStatus();
	}


	function button_over(eButton){
		if (eButton.style.borderBottom != "buttonhighlight 1px solid")
		{
		eButton.style.borderBottom = "buttonshadow solid 1px";
		eButton.style.borderLeft = "buttonhighlight solid 1px";
		eButton.style.borderRight = "buttonshadow solid 1px";
		eButton.style.borderTop = "buttonhighlight solid 1px";
		}
	}
				
	function button_out2(eButton){
		if (eButton.style.borderBottom != "buttonhighlight 1px solid")
		{
		eButton.style.borderColor = "threedface";
		}
	}

	function button_out(eButton){
		eButton.style.borderColor = "threedface";
	}

	function char_out(eButton){
		eButton.style.borderColor = "#666666";
	}

	function button_down(eButton){
		eButton.style.borderBottom = "buttonhighlight solid 1px";
		eButton.style.borderLeft = "buttonshadow solid 1px";
		eButton.style.borderRight = "buttonhighlight solid 1px";
		eButton.style.borderTop = "buttonshadow solid 1px";
	}

	function button_up(eButton){
		eButton.style.borderBottom = "buttonshadow solid 1px";
		eButton.style.borderLeft = "buttonhighlight solid 1px";
		eButton.style.borderRight = "buttonshadow solid 1px";
		eButton.style.borderTop = "buttonhighlight solid 1px";
		eButton = null; 
	}


	function isAllowed() {
		var sel;
		var obj;
		if (editDefault != 1) {
			return true;
		} else {
//			sel = foo.document.selection;
			sel = document.selection;
			
			if (sel.type != "Control")
			{
				obj = sel.createRange().parentElement();
			} else {
				obj = sel.createRange()(0);
			}
			
			if (obj.isContentEditable) {
				return true;
			} else {
				return false;
			}
			
		}
	}


	function ShowInsertTable() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2;
		var topPos = (screen.availHeight-400) / 2;
 		inserttableWin = window.open('/editor/instable.htm','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);

		}
	}

	function contextHilite(menu){
	    menu.runtimeStyle.backgroundColor = "Highlight";
	    if (menu.state){
	        menu.runtimeStyle.color = "GrayText";
	    } else {
	        menu.runtimeStyle.color = "HighlightText";
	    }
	}

	function contextDelite(menu){
	    menu.runtimeStyle.backgroundColor = "";
	    menu.runtimeStyle.color = "";
	}

	function isImageSelected() {
//		if (foo.document.selection.type == "Control") {

		if (document.selection.type == "Control") {
//			var oControlRange = foo.document.selection.createRange();
			var oControlRange = document.selection.createRange();

			if (oControlRange(0).tagName.toUpperCase() == "IMG") {
//				selectedImage = foo.document.selection.createRange()(0);
				selectedImage = document.selection.createRange()(0);

				return true;
			}	
		}
	}

	function isTableSelected() {
//		if (foo.document.selection.type == "Control") {

		if (document.selection.type == "Control") {
//			var oControlRange = foo.document.selection.createRange();
			var oControlRange = document.selection.createRange();

			if (oControlRange(0).tagName.toUpperCase() == "TABLE") {
//				selectedTable = foo.document.selection.createRange()(0);
				selectedTable = document.selection.createRange()(0);

				return true;
			}	
		}
	} // End Function


	function isCursorInTableCell() {
		if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement();

                          while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                          {
                            if (elem.id == 'oDiv')
                              return false;

                            elem = elem.parentElement;
                            if (elem == null)
                              break;
                          }

				if (elem) {
					selectedTD = elem;
					selectedTR = selectedTD.parentElement;
					selectedTBODY =  selectedTR.parentElement;
					selectedTable = selectedTBODY.parentElement;
					return true;
				}
		}
	} // End function


	function ModifyTable() {
		if (isAllowed())
		{

		if (isTableSelected() || isCursorInTableCell()) {
			var leftPos = (screen.availWidth-500) / 2;
			var topPos = (screen.availHeight-400) / 2;
	 		modifytableWin = window.open('/editor/mtproperty.htm','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

	function ModifyCell() {
		if (isAllowed())
		{

		if (isCursorInTableCell()) {
			var leftPos = (screen.availWidth-500) / 2;
			var topPos = (screen.availHeight-400) / 2;
	 		modifytableWin = window.open('/editor/mtcell.htm','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

	function InsertRowAbove() {
		if (isCursorInTableCell()){
			var numCols = 0;

			allCells = selectedTR.cells;
			for (var i=0;i<allCells.length;i++) {
			 	numCols = numCols + allCells[i].getAttribute('colSpan');
			}

			var newTR = selectedTable.insertRow(selectedTR.rowIndex);
	
			for (i = 0; i < numCols; i++) {
			 	newTD = newTR.insertCell();
				newTD.innerHTML = "&nbsp;";

				if (borderShown == "yes") {
					newTD.style.border = "1px dotted #BFBFBF";
				}
			}
		}	
		
	} // End function

	function InsertRowBelow() {

		if (isCursorInTableCell()){
		
			var numCols = 0;

			allCells = selectedTR.cells;
			for (var i=0;i<allCells.length;i++) {
			 	numCols = numCols + allCells[i].getAttribute('colSpan');
			}

			var newTR = selectedTable.insertRow(selectedTR.rowIndex+1);

			for (i = 0; i < numCols; i++) {
			 	newTD = newTR.insertCell();
				newTD.innerHTML = "&nbsp;";

				if (borderShown == "yes") {
					newTD.style.border = "1px dotted #BFBFBF";
				}
			}
		}

	} // End function

	function IncreaseColspan() {
		if (isCursorInTableCell()) {

			var colSpanTD = selectedTD.getAttribute('colSpan');
			allCells = selectedTR.cells;

			if (selectedTD.cellIndex + 1 != selectedTR.cells.length) {
				var addColspan = allCells[selectedTD.cellIndex+1].getAttribute('colSpan');
				selectedTD.colSpan = colSpanTD + addColspan;
				selectedTR.deleteCell(selectedTD.cellIndex+1);
			}	
		}

	} // End function

	function IncreaseRowspan() {
		if (isCursorInTableCell()) {

			var rowSpanTD = selectedTD.getAttribute('rowSpan');
			allRows = selectedTable.rows;
			if (selectedTR.rowIndex +1 != allRows.length) {

				var allCellsInNextRow = allRows[selectedTR.rowIndex+selectedTD.rowSpan].cells;
				var addRowSpan = allCellsInNextRow[selectedTD.cellIndex].getAttribute('rowSpan');
				var moveTo = selectedTD.rowSpan;

				if (!addRowSpan) addRowSpan = 1;

				selectedTD.rowSpan = selectedTD.rowSpan + addRowSpan;
				allRows[selectedTR.rowIndex + moveTo].deleteCell(selectedTD.cellIndex);
			}
		}

	} // End function

	function DecreaseColspan() {

		if (isCursorInTableCell()) {
			if (selectedTD.colSpan != 1) {
				selectedTR.insertCell(selectedTD.cellIndex+1);
				selectedTD.colSpan = selectedTD.colSpan - 1;
			}
		}

	} // End function

	function DeleteRow() {
		if (isCursorInTableCell()) {
			selectedTable.deleteRow(selectedTR.rowIndex);
		}
	}

	function DeleteCol() {
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex);
			allRows = selectedTable.rows;
			for (var i=0;i<allRows.length;i++) {
				endOfRow = allRows[i].cells.length - 1;
				position = endOfRow - moveFromEnd;
				if (position < 0) {
					position = 0;
				} // End If
				

				allCellsInRow = allRows[i].cells;
				
				if (allCellsInRow[position].colSpan > 1) {
					allCellsInRow[position].colSpan = allCellsInRow[position].colSpan - 1;
				} else { 
					allRows[i].deleteCell(position);
				}

			} // End For	

        	} // End If

	} // End Function

	function InsertColAfter() {
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex);
			allRows = selectedTable.rows;
			for (i=0;i<allRows.length;i++) {
			rowCount = allRows[i].cells.length - 1;
			position = rowCount - moveFromEnd;
			if (position < 0) {
				position = 0;
			}
				newCell = allRows[i].insertCell(position+1);
				newCell.innerHTML = "&nbsp;";

				if (borderShown == "yes") {
					newCell.style.border = "1px dotted #BFBFBF";
				}
			}	
        	}
	} // End Function


	function InsertColBefore() {
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex);
			allRows = selectedTable.rows;
			for (i=0;i<allRows.length;i++) {
				rowCount = allRows[i].cells.length - 1;
				position = rowCount - moveFromEnd;
				if (position < 0) {
					position = 0;
				}
				newCell = allRows[i].insertCell(position);
				newCell.innerHTML = "&nbsp;";

				if (borderShown == "yes") {
					newCell.style.border = "1px dotted #BFBFBF";
				}
			}	
        	}
	}

	function showMenu(menu, width, height)
	{
	oDiv.focus();    
	var lefter = event.clientX;
	var leftoff = event.offsetX;
	var topper = event.clientY;
	var topoff = event.offsetY;
	var moveMe = 0;
	var oPopBody = oPopup.document.body;

	if (menu == "saveMenu" || menu == "previewMenu")
	{
		moveMe = 22;
	}

	if (menu == "colorMenu") {
		colorType = "0"
	}

	if (menu == "colorMenu2") {
		colorType = "2";
		menu = "colorMenu";
	}

	if (menu == "formMenu")
	{
		if (isCursorInForm()) {
			document.getElementById("modifyForm1").disabled = false;
		} else {
			document.getElementById("modifyForm1").disabled = true;
		}
	}

	if (menu == "tableMenu")
	{
	
		if (isCursorInTableCell() || isTableSelected()) {
			document.getElementById("modifyTable").disabled = false;
		} else {
			document.getElementById("modifyTable").disabled = true;
		}

		if (isCursorInTableCell())
		{
			document.getElementById("modifyCell").disabled = false;
			document.getElementById("rowAbove").disabled = false;
			document.getElementById("rowBelow").disabled = false;
			document.getElementById("deleteRow").disabled = false;
			document.getElementById("colAfter").disabled = false;
			document.getElementById("colBefore").disabled = false;
			document.getElementById("deleteCol").disabled = false;
			document.getElementById("increaseSpan").disabled = false;
			document.getElementById("decreaseSpan").disabled = false;
		} else {
			document.getElementById("modifyCell").disabled = true;
			document.getElementById("rowAbove").disabled = true;
			document.getElementById("rowBelow").disabled = true;
			document.getElementById("deleteRow").disabled = true;
			document.getElementById("colAfter").disabled = true;
			document.getElementById("colBefore").disabled = true;
			document.getElementById("deleteCol").disabled = true;
			document.getElementById("increaseSpan").disabled = true;
			document.getElementById("decreaseSpan").disabled = true;
		}
	}

	var HTMLContent = eval(menu).innerHTML;
	oPopBody.innerHTML = HTMLContent;
	oPopup.show(lefter - leftoff - 2 - moveMe, topper - topoff + 22, width, height, document.body);

	return false;
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//sInitColor is a global variable. It holds the value of the selected color in the color dialog box when it displays
var sInitColor = null;
//sPersistValue holds the value of the saved innerHTML 
var sPersistValue

function inshref()  //
{
	var leftPos = (screen.availWidth-500) / 2;
	var topPos = (screen.availHeight-400) / 2;
	oDiv.focus();
	var s=oDiv.document.selection.createRange();

if (isImageSelected()) 
{

	obj = selectedImage.parentElement;

	if (obj.tagName=='A') 
	{

		var rWin = window.open('/editor/adhref.php?vx=1&url='+obj.href,'','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);

	} else
	{
 		var rWin = window.open('/editor/adhref.php?vx=2','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);

	}
	
} else
{
	obj = s.parentElement();
	while ((obj!=null) && (obj.tagName!='P') && (obj.tagName!='H1') && (obj.tagName!='H2') && (obj.tagName!='H3') && (obj.tagName!='H4') && (obj.tagName!='H5') && (obj.tagName!='H6'))
	{
		
		if(obj.tagName=='DIV'){break;}
		if(obj.tagName=='A'){break;}
		obj = obj.parentElement;
	}

	if (obj.tagName=='A') 
	{
		var rWin = window.open('/editor/adhref.php?vx=3&url='+obj.href,'','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
	} else
	{
		//if (!s.boundingWidth)
		//{
		//	s.expand("word");
		//	s.select();
		//}
		if (s.boundingWidth)
		{

			var re=/\<\/a\>/ig;
			var n = s.htmlText.search(re);
			if (n!=-1)
			{
				re=/\<a href/ig;
				n = s.htmlText.search(re);
			}
			if (n==-1)
			{
				var rWin = window.open('/editor/adhref.php?vx=4','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			} else
			{
				alert('Выделенная область содержит ссылку');
			}

		} else
		{
			alert('Выделите область для ссылки!');
		}
	}
			
	
}
}

function rehref()  //
{
	if (document.anchors.length)
	{
		if (isImageSelected())
		{
			obj = selectedImage.parentElement;
			if (obj.tagName=='A') 
			{
				eval('var re = /\<a name=.*?\><img.*?\<\\/a\>/ig;'); 
				var n = obj.outerHTML.search(re);
				if (n>=0)
				{
					obj.outerHTML='';
				}
			}
		}

	} else
	{
		alert("У Вас нет брошеных якорей");	
	}
}


function adhref()  //
{
	var t=prompt("Введите имя якоря","");
	if (t)
	{
		var stop=0;
		for (var x=0;x<document.anchors.length;x++)
		{
			if (t==document.anchors[x].name) {stop=1;alert("Якорь с таким именем уже существует!");break;}	
		}
		if (stop==0)
		{
			oDiv.focus();
			var s=oDiv.document.selection.createRange();
			s.pasteHTML("<a name=\""+t+"\"><img src=\"\\editor/UI_adhref.gif\"></a>");
		}
	}
}


function tkiller()  //
{
	if(confirm("Внимание, разметка может быть нарушена. Продолжаем?"))
	{
		if(z==1)rotate();

		document.form4.objcontent.value=oDiv.innerText;

		document.all.form4.submit();

//		if(z==3)rotate();
	}
}

function doInit(){
	//ensure that all document elements except the content editable DIV are unselectable
 	for (i=0; i<document.all.length; i++)
    {
    	document.all(i).unselectable = "on";
    }

    oDiv.unselectable = "off";
//    window.resizeTo(639,470);

	//clear any text in the Document window and set the focus
//	oDiv.innerHTML="<?print addslashes($out) ?>";
	oDiv.focus();
}

//This function works for all of the command identifiers used in this page
function callFormatting(sFormatString){
//alert(sFormatString);
	document.execCommand(sFormatString);
}

//callColorDlg uses the dialog helper object's ChooseColorDlg method to open the color dialog box, then changes the font or back color of the selected text
function callColorDlg(sColorType){

if (sInitColor == null) 
	//display color dialog box
	var sColor = dlgHelper.ChooseColorDlg();
else
	var sColor = dlgHelper.ChooseColorDlg(sInitColor);
	//change decimal to hex
	sColor = sColor.toString(16);
	//add extra zeroes if hex number is less than 6 digits
if (sColor.length < 6) {
  	var sTempString = "000000".substring(0,6-sColor.length);
  	sColor = sTempString.concat(sColor);
}
	//change color of the selected text
	document.execCommand(sColorType, false, sColor);
	sInitColor = sColor;
	oDiv.focus();
}

var z=1;
//SaveDocument uses the common dialog box object to display the save as dialog, then writes a textstream object from the value of the div's innerHTML property
function SaveDocument(fr){

//for(elm in document.all.create_new)alert(elm+' '+eval('document.all.create_new.'+elm))

	oDiv.focus();

	if(z==1)rotate();

	fr.objContent.value=oDiv.innerText;

	if(z==3)rotate();

	oDiv.focus();

//	if(z==1){
//		sPersistValue=oDiv.innerHTML;
//		oDiv.innerText=oDiv.innerHTML;

//		callFormatting('SelectAll');
//		callFormatting('Copy');

//		oDiv.innerHTML=sPersistValue;
//	}
//	else {
//		callFormatting('SelectAll');
//		callFormatting('Copy');
//	}

//	window.close();
}

function ipic(){

		oDiv.focus();
		if (isAllowed())
		{

		if (isImageSelected()) {	 
			var leftPos = (screen.availWidth-500) / 2;
			var topPos = (screen.availHeight-400) / 2;
			imageWin = window.open('/editor/miproperty.htm','','width=500,height=430,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		} else {
			var arr=window.showModalDialog("/editor/insimage.php","","help:0;scroll:1;status:0;");
			if (arr != null)
			{
			    	var i='<img src="' + arr["ImgUrl"] + '" height="' + arr["ImgHeight"] + '" width="' + arr["ImgWidth"] + '" alt="' + arr["AltText"] + '" vspace="' + arr["VerSpace"] + '" hspace="' + arr["HorSpace"] +  '"align="' + arr["ImgAlign"] +'"border="' + arr["ImgBorder"]+ '">';
				//var i='<img src="/manager/picture.php?fid='+r[0]+'"'+r[1]+r[2]+'>';
				var s=oDiv.document.selection.createRange();
		   		s.pasteHTML(i);
			}

		}
		}

}

function ifile(){

		oDiv.focus();
		var arr=window.showModalDialog("/editor/insfile.php","","help:0;scroll:1;status:0;");
			if (arr != null)
			{
				if (!arr["FileName"]) {arr["FileName"]=arr["ImgUrl"];}
			    	var i='<a href="' + arr["ImgUrl"] + '" title="' + arr["AltText"] + '">'+arr["FileName"]+'</a>';
				var s=oDiv.document.selection.createRange();
		   		s.pasteHTML(i);
			}
}

function iico(){

	var r=window.showModalDialog("/admin/ipic.php","","help:0;scroll:1;status:0;");
	if(r)
	{
		ico.innerHTML='<img src="/picture.php?fid='+r[0]+'"'+r[1]+r[2]+'> сменить';
		form1.objIco.value=r[0];
	}

}
//???
function cico(){

		ico.innerHTML=' сменить';
		form1.objIco.value='';
}

function upbuttons()
{
	oDiv.focus();
		for (var ic=0;ic<document.images.length;ic++)
		{
			if (document.images.item(ic).id=="ic_pic_dis" || document.images.item(ic).id=="ic_pic_en")
			{
				button_over(document.images.item(ic));
				button_out(document.images.item(ic));
			}
		}
}

function Save(){

	oDiv.focus();
	window.returnValue=oDiv.innerHTML;
	window.close();

}

function rotate(){
	oDiv.focus();
	if (z==1)
	{
		document.all.formatDrop.disabled=true;
		for (var c=0;c<document.images.length;c++)
		{
			if (document.images.item(c).id=="ic_pic_dis") {document.images.item(c).disabled=true;document.images.item(c).style.filter="alpha(Opacity=20)";};
		}
		eval('var re = /\<a name=(.*?)\>(.*?)\<\\/a\>/ig;'); 
		oDiv.innerHTML=oDiv.innerHTML.replace(re,"<a name=\"$1\"></a>");
		oDiv.innerText=oDiv.innerHTML;
		z=3;
	}
	else
	{
		document.all.formatDrop.disabled=false;
		for (var c=0;c<document.images.length;c++)
		{
			if (document.images.item(c).id=="ic_pic_dis") {document.images.item(c).disabled=false;document.images.item(c).style.filter="alpha(Opacity=100)";};
		}
		oDiv.innerHTML=oDiv.innerText;
		eval('var re = /\<a name=(.*?)\>\<\\/a\>/ig;'); 
		oDiv.innerHTML=oDiv.innerHTML.replace(re,"<a name=\"$1\"><img src=\"\\editor/UI_adhref.gif\"></a>");
		z=1
	}
}

//NewDocument creates a new "document" by clearing the content of the div. If there is any new content in the div, the user is asked whether or not to save
function NewDocument(){
//  	var answer = checkForSave();
//   	if (answer) {var sCancel = SaveDocument();
//	 	if (sCancel) return;
//		oDiv.innerHTML="";}
//    if (answer==false)
        oDiv.innerHTML="";
	oDiv.focus();
}

//This function checks to see if the div has new text, then displays a modal dialog box if appropriate
function checkForSave()
{ 
	if ((oDiv.innerHTML!=sPersistValue)&&(oDiv.innerHTML !=""))
	 	var checkSave=showModalDialog('/editor/dcheckForSave.htm','','dialogHeight:125px;dialogWidth:250px;help:no;scroll:off;status:off;');
	else
	  	var checkSave=false;
  	return checkSave;
}

//this function is used to call other functions when the user clicks on a menu item. These are the same functions that are called by the toolbar buttons.
function CallMenuFunction(){
var menuChoice = event.result;
switch(menuChoice){
		case "new":
            NewDocument();
		    break;
		case "save":
			SaveDocument();
			break;
		case "cut":
			callFormatting('Cut');
			break;
        case "copy":
			callFormatting('Copy');
		    break;
        case "paste":
			callFormatting('Paste');
            break;
		case "bold":
			callFormatting('Bold');
            break;
		case "underline":
			callFormatting('Underline');
            break;
		case "italic":
			callFormatting('Italic');
            break;
		case "fontColor":
			callColorDlg('ForeColor');
            break;
		case "highlight":
			callColorDlg('BackColor');
            break;
		 case "about":
            break;
        default:
			break;
			}
}
