	function setValues() {
		temp_id = 0;
		while (editorMap[temp_id] != null) {
			if (editorMap[temp_id] == null) exit;
			editorMap[temp_id].SetHTML(document.all.item(editorMap[temp_id].FieldName).value);
			eval(EDITOR_COMPOSITION_PREFIX + temp_id).document.body.onbeforepaste = new Function("EditorOnBeforePaste();");
			eval(EDITOR_COMPOSITION_PREFIX + temp_id).document.body.ondrop = new Function("EditorOnDrop(" + temp_id + ");");
			temp_id += 1;	
		}
	}
	var PasteSt = false;

// 1.Part
    function UtilBeginScript() { return String.fromCharCode(60, 115, 99, 114, 105, 112, 116, 62); }

    function UtilEndScript() { return String.fromCharCode(60, 47, 115, 99, 114, 105, 112, 116, 62);}

// 2.Part
	function IDGenerator(nextID)
	{
		this.nextID = nextID;
		this.GenerateID = IDGeneratorGenerateID;
	}

	function IDGeneratorGenerateID() { return this.nextID++; }


// 3.Part
	var BUTTON_IMAGEPATH = "fe/eimages"
	var BUTTON_IMAGE_PREFIX = "buttonImage";
	var BUTTON_DIV_PREFIX = "buttonDiv";
	var BUTTON_PAD1_PREFIX = "buttonPad1";
	var BUTTON_PAD2_PREFIX = "buttonPad2";
	var buttonMap = new Object();

	function Button (idGenerator, caption, action, image)
	{
		patt = /\(*\)/i
		this.container = action.substr(action.search(patt)-1,1);
		this.idGenerator = idGenerator;
		this.caption = caption;
		this.action = action;
		this.image = image;
		this.enabled = true;
		this.Instantiate = ButtonInstantiate;
		this.Enable = ButtonEnable;
	}

	function ButtonInstantiate()
	{
		this.id = this.idGenerator.GenerateID();
		buttonMap[this.container + 'X' + this.id] = this;
		var html = "";
		html += '<div id="';
		html += BUTTON_DIV_PREFIX;
		html += this.container + 'X';
		html += this.id;
		html += '" class="ButtonNormal"';
		html += ' onselectstart="ButtonOnSelectStart()"';
		html += ' ondragstart="ButtonOnDragStart()"';
		html += ' onmousedown="ButtonOnMouseDown(this)"';
		html += ' onmouseup="ButtonOnMouseUp(this)"';
		html += ' onmouseout="ButtonOnMouseOut(this)"';
		html += ' onmouseover="ButtonOnMouseOver(this)"';
		html += ' onclick="ButtonOnClick(this)"';
		html += ' ondblclick="ButtonOnDblClick(this)"';
		html += '>';
		html += '<table cellpadding=0 cellspacing=0 border=0><tr><td><img id="';
		html += BUTTON_PAD1_PREFIX;
		html += this.container + 'X';		
		html += this.id;
		html += '" width=2 height=2></td><td></td><td></td></tr><tr><td></td><td>';
		html += '<img id="';
		html += BUTTON_IMAGE_PREFIX;
		html += this.container + 'X';		
		html += this.id;
		html += '" src="';
		html += this.image;
		html += '" title="';
		html += this.caption;
		html += '" class="Image"';
		html += '>';
		html += '</td><td></td></tr><tr><td></td><td></td><td><img id="';
		html += BUTTON_PAD2_PREFIX;
		html += this.container + 'X';
		html += this.id;
		html += '" width=2 height=2></td></tr></table>';
		html += '</div>';
		document.write(html);
	}

	function ButtonEnable(enabled)
	{
		this.enabled = enabled;
		if (this.enabled)
		{
			document.all[BUTTON_DIV_PREFIX + this.container + 'X' + this.id].className = "ButtonNormal";
		}
		else
		{
			document.all[BUTTON_DIV_PREFIX + this.container + 'X' + this.id].className = "ButtonDisabled";
		}
	}

	function ButtonOnSelectStart() { window.event.returnValue = false; }

	function ButtonOnDragStart() { window.event.returnValue = false; }

	function ButtonOnMouseDown(element)
	{
		if (event.button == 1)
		{
			var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
			var button = buttonMap[id];
			if (button.enabled) ButtonPushButton(id);
		}
	}

	function ButtonOnMouseUp(element)
	{
		if (event.button == 1)
		{
			var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
			var button = buttonMap[id];
			if (button.enabled) ButtonReleaseButton(id);
		}
	}

	function ButtonOnMouseOut(element)
	{
		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled) ButtonReleaseButton(id);
	}

	function ButtonOnMouseOver(element)
	{
		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled) 
		{
			ButtonReleaseButton(id);
			document.all[BUTTON_DIV_PREFIX + id].className = "ButtonMouseOver";
		}
	}

	function ButtonOnClick(element)
	{
		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
		var button = buttonMap[id];
		if (button.enabled) eval(button.action);
	}

	function ButtonOnDblClick(element) { ButtonOnClick(element); }

	function ButtonPushButton(id)
	{
		document.all[BUTTON_PAD1_PREFIX + id].width = 3;
		document.all[BUTTON_PAD1_PREFIX + id].height = 3;
		document.all[BUTTON_PAD2_PREFIX + id].width = 1;
		document.all[BUTTON_PAD2_PREFIX + id].height = 1;
		document.all[BUTTON_DIV_PREFIX + id].className = "ButtonPressed";
	}

	function ButtonReleaseButton(id)
	{
		document.all[BUTTON_PAD1_PREFIX + id].width = 2;
		document.all[BUTTON_PAD1_PREFIX + id].height = 2;
		document.all[BUTTON_PAD2_PREFIX + id].width = 2;
		document.all[BUTTON_PAD2_PREFIX + id].height = 2;
		document.all[BUTTON_DIV_PREFIX + id].className = "ButtonNormal";
	}

// 5.Part
	var EDITOR_COMPOSITION_PREFIX = "editorComposition";
	var EDITOR_LIST_AND_INDENT_PREFIX = "editorListAndIndent";
	var EDITOR_TOP_TOOLBAR_PREFIX = "editorTopToolbar";
	var EDITOR_BOTTOM_TOOLBAR_PREFIX = "editorBottomToolbar";
	
	var editorMap = new Object();
	var editorIDGenerator = null;

	function Editor(idGenerator,idFieldName)
	{
		this.idGenerator = idGenerator;
		this.textMode = false;
		this.brief = false;
		this.instantiated = false;
		this.Instantiate = EditorInstantiate;
		this.GetText = EditorGetText;
		this.SetText = EditorSetText;
		this.GetHTML = EditorGetHTML;
		this.SetHTML = EditorSetHTML;
		this.GetBrief = EditorGetBrief;
		this.SetBrief = EditorSetBrief;
		this.Focus = EditorFocus;
		this.SetDomain = SetDomain;
		this.FieldName = idFieldName;
	}

	function EditorInstantiate()
	{
		if (this.instantiated) return;

		this.id = this.idGenerator.GenerateID();
		editorMap[this.id] = this;
		editorIDGenerator = this.idGenerator;

		var html = "";
		html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">";
		html += "<tr>";
		html += "<td id=\"" + EDITOR_TOP_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";

	// Hidden Area başlangıcı
		//html += "<div id=\"toolbar" + this.id + "\" style=\"display:none\">"
		html += "<div id=\"toolbar" + this.id + "\" style=\"display:block\">"
	
		//html += "</td>";
		//html += "</tr>";
		//html += "<tr>";
		//html += "<td id=\"" + EDITOR_BOTTOM_TOOLBAR_PREFIX + this.id + "\" class=\"Toolbar\">";

			html += "<table cellpaddin=\"0\" cellspacing=\"0\" border=\"0\">";
			html += "<tr>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var cutButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Cut\",";
				html += "\"EditorOnCut(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/cut.gif\"";
				html += ");";
				html += "cutButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var copyButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Copy\",";
				html += "\"EditorOnCopy(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/copy.gif\"";
				html += ");";
				html += "copyButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var pasteButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Paste\",";
				html += "\"EditorOnPaste(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/paste.gif\"";
				html += ");";
				html += "pasteButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += "<div class=\"Divider\"></div>";
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var boldButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Bold\",";
				html += "\"EditorOnBold(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/bold.gif\"";
				html += ");";
				html += "boldButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var italicButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Italic\",";
				html += "\"EditorOnItalic(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/italic.gif\"";
				html += ");";
				html += "italicButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var underlineButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Underline\",";
				html += "\"EditorOnUnderline(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/uline.gif\"";
				html += ");";
				html += "underlineButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += "<div class=\"Divider\"></div>";
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var alignLeftButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Align Left\",";
				html += "\"EditorOnAlignLeft(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/aleft.gif\"";
				html += ");";
				html += "alignLeftButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var centerButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Center\",";
				html += "\"EditorOnCenter(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/center.gif\"";
				html += ");";
				html += "centerButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var alignRightButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Align Right\",";
				html += "\"EditorOnAlignRight(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/aright.gif\"";
				html += ");";
				html += "alignRightButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var alignJustifyButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Align Justify\",";
				html += "\"EditorOnAlignJustify(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/afull.gif\"";
				html += ");";
				html += "alignJustifyButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";		

				html += "<td>";
				html += "<div class=\"Divider\"></div>";
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var InsertHorizontalRuleButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Çizgi Ekle\",";
				html += "\"EditorOnInsertHorizontalRule(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/line.gif\"";
				html += ");";
				html += "InsertHorizontalRuleButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var InsertTableButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Tablo Ekle\",";
				html += "\"EditorOnInsertTable(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/table.gif\"";
				html += ");";
				html += "InsertTableButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += "<div class=\"Divider\"></div>";
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var numberedListButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Numbered List\",";
				html += "\"EditorOnNumberedList(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/nlist.gif\"";
				html += ");";
				html += "numberedListButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var bullettedListButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Bulletted List\",";
				html += "\"EditorOnBullettedList(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/blist.gif\"";
				html += ");";
				html += "bullettedListButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += "<div class=\"Divider\"></div>";
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var decreaseIndentButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Decrease Indent\",";
				html += "\"EditorOnDecreaseIndent(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/ileft.gif\"";
				html += ");";
				html += "decreaseIndentButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

				html += "<td>";
				html += UtilBeginScript();
				html += "var increaseIndentButton = new Button(";
				html += "editorIDGenerator,";
				html += "\"Increase Indent\",";
				html += "\"EditorOnIncreaseIndent(" + this.id + ")\",";
				html += "\"" + BUTTON_IMAGEPATH + "/iright.gif\"";
				html += ");";
				html += "increaseIndentButton.Instantiate();";
				html += UtilEndScript();
				html += "</td>";

		html += "</tr>";
		html += "</table>";


	// Hidden Area sonu
		html += "</div>";
		html += "</td>";
		html += "</tr>";

		html += "<tr>";
		html += "<td>";
		html += "<iframe id=\"" + EDITOR_COMPOSITION_PREFIX + this.id + "\" width=\"100%\" height=\"190\" onblur=\"EditorOnBlur(" + this.id + ")\" onfocus=\"EditorOnFocus(" + this.id + ")\">";
		html += "</iframe>";
		html += "</td>";
		html += "</tr>";
		html += "</table>";

		document.write(html);

		html = '';
		html += '<html>';
		html += '<body style="font:10pt arial">';
		html += '</body>';
		html += '</html>';
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.open();
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.write(html);
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.close();
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.designMode = "on";
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.onclick = new Function("EditorOnClick(" + this.id + ")");
		
		
		editorIDGenerator = null;
		this.instantiated = true;
	}

	function  EditorGetText()
	{ return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText; }

	function  EditorSetText(text)
	{
		text = text.replace(/\n/g, "<br>");
		alert(text);
		eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = text;
	}

	function  EditorGetHTML()
	{
		if (this.textMode) {
			return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText;
		}
		return eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML;
	}

	function  EditorSetHTML(html)
	{
		if (this.textMode) {
			eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerText = html;
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + this.id).document.body.innerHTML = html;
		}
	}

	function EditorGetBrief() {return this.brief;}

	function EditorSetBrief(brief)
	{
		this.brief = brief;
		var display = this.brief ? "none" : "inline";
		if (this.instantiated) {
			eval(EDITOR_LIST_AND_INDENT_PREFIX + this.id).style.display = display;
		}
	}

	function EditorFocus(){eval(EDITOR_COMPOSITION_PREFIX + this.id).focus();}
	function EditorOnFocus(id){eval('toolbar' + id).style.display = "block";}
	function SetDomain(d){eval(EDITOR_COMPOSITION_PREFIX + this.id).document.domain = d;}
	function EditorOnCut(id){EditorFormat(id, "cut");}
	function EditorOnCopy(id){EditorFormat(id, "copy");}
	function EditorOnPaste(id) { EditorFormat(id, "paste");}
	function EditorOnBold(id){EditorFormat(id, "bold");}
	function EditorOnItalic(id){EditorFormat(id, "italic");}
	function EditorOnUnderline(id){EditorFormat(id, "underline");}
	function EditorOnAlignLeft(id){EditorFormat(id, "justifyleft");}
	function EditorOnCenter(id){EditorFormat(id, "justifycenter");}
	function EditorOnAlignRight(id){EditorFormat(id, "justifyright");}
	function EditorOnAlignJustify(id){EditorFormat(id, "justifyfull");}
	function EditorOnNumberedList(id){EditorFormat(id, "insertOrderedList");}
	function EditorOnBullettedList(id){EditorFormat(id, "insertUnorderedList");}
	function EditorOnDecreaseIndent(id){EditorFormat(id, "outdent");}
	function EditorOnIncreaseIndent(id){EditorFormat(id, "indent");}
	function EditorOnInsertTable(id)
	{
		if (!EditorValidateMode(id))  return;

		// table properties :
		// rows | cols | cellpassing | cellspacing | width | unit | border
		var tableprop = showModalDialog("editor/table.htm", "", "font-family:Verdana;font-size:12;dialogWidth:320px;dialogHeight:220px;scroll:no;status:no");
		if (tableprop) {
			var properties = tableprop.split('|');
			var sel = document.selection;
			if (sel!=null) {
			    var range = sel.createRange();
			    if (range!=null)
				tHTML = '<TABLE cellpadding=\"' + properties[2] + '\"';
				tHTML += ' cellspacing=\"' + properties[3] + '\"';
				tHTML += ' border=\"' + properties[6] + '\"';
				tHTML += ' width=\"' + properties[4] ;
				if (properties[5]='percent') {tHTML += '%\"';} else { tHTML += 'px\"'; }
				tHTML += '>';
				for(i=1;i<=properties[0];i++) {
					tHTML += '<tr>';
					for(j=1;j<=properties[1];j++) {
						tHTML += '<td></td>';
					}					
					tHTML += '</tr>';
				}				
				tHTML += '</TABLE>';
		        range.pasteHTML(tHTML);
			}
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		}	
	}
	
	function EditorOnInsertHorizontalRule(id)
	{
		EditorFormat(id, "inserthorizontalrule", "");
	}	

	function EditorOnClick(id)
	{
		// alert('click');
	}
	
	function EditorOnBeforePaste() {
		window.clipboardData.setData("Text", window.clipboardData.getData("Text"));
	}	

	function EditorOnDrop(id) {
		oldText = window.frames(EDITOR_COMPOSITION_PREFIX + id).event.dataTransfer.getData("Text");
		if (oldText == null) oldText = '';
		window.frames(EDITOR_COMPOSITION_PREFIX + id).event.returnValue = false;
		var sel = document.selection;
		if (sel!=null) {
			var range = sel.createRange();
			if (range!=null)
			range.pasteHTML(oldText);
		}		
	}		
	
	function EditorOnBlur(id)
	{
		curtoolbar = 'toolbar' + id;
		var curelem = document.activeElement;
		hide = true;
		while (curelem.parentElement) {
			var curelem = curelem.parentElement
			if(curelem.id == curtoolbar) hide=false;
		}
		//if(hide==true) eval(curtoolbar).style.display = "none";

		var editor = editorMap[id];
		document.all.item(editor.FieldName).value = editor.GetHTML();
	}
		
	function EditorValidateMode(id)
	{
		var editor = editorMap[id];
		if (!editor.textMode) return true;

		alert("Please uncheck the \"View HTML Source\" checkbox to use the toolbars.");
		eval(EDITOR_COMPOSITION_PREFIX + id).focus();
		return false;
	}

	function EditorFormat(id, what, opt)
	{
		if (!EditorValidateMode(id)) return;

		if (opt == "removeFormat") {
			what = opt;
			opt = null;
		}
		if (opt == null) {
			eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what);
		}
		else {
			eval(EDITOR_COMPOSITION_PREFIX + id).document.execCommand(what, "", opt);
		}
	}

	function EditorCleanHTML(id)
	{
		var fonts = eval(EDITOR_COMPOSITION_PREFIX + id).document.body.all.tags("FONT");
		for (var i = fonts.length - 1; i >= 0; i--) {
			var font = fonts[i];
			if (font.style.backgroundColor == "#ffffff") 
				font.outerHTML = font.innerHTML;
		}
	}

	function EditorGetElement(tagName, start)
	{
		while (start && start.tagName != tagName) 
			start = start.parentElement;
			
		return start;
	}
	function OpenLEditor(strlink,strname){
		try {
		window.open(strlink,strname,"height=360,width=630,scrollbars=yes,resizable=yes,status=no,menubar=no,toolbar=no,location=no");
		}catch (err) {alert(err.description);}
	}
