﻿var bName, bVer;
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);





var BUTTON_IMAGE_PREFIX = "buttonImage";
	var BUTTON_DIV_PREFIX = "buttonDiv";
	var BUTTON_PAD1_PREFIX = "buttonPad1";
	var BUTTON_PAD2_PREFIX = "buttonPad2";
	var buttonid = 0;
	var buttonMap = new Object();

	function Button
	(
		caption,
		action,
		image
	)
	{
		this.caption = caption;
		this.action = action;
		this.image = "Images/"+image+".gif";
		this.Instantiate = ButtonInstantiate;
	}

	function ButtonInstantiate()
	{
		this.id = buttonid++;;
		buttonMap[this.id] = this;
		var html = "";
		html += '<div id="';
		html += BUTTON_DIV_PREFIX;
		html += this.id;
		html += '" class="bnn"';
		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 += '<img id="';
		html += BUTTON_PAD1_PREFIX;
		html += this.id;
		html += '" width=2 height=2>';
		html += '<img id="';
		html += BUTTON_IMAGE_PREFIX;
		html += this.id;
		html += '" src="';
		html += this.image;
		html += '" title="';
		html += this.caption;
		html += '" class="Image"';
		html += '>';
		html += '<img id="';
		html += BUTTON_PAD2_PREFIX;
		html += this.id;
		html += '" width=2 height=2>';
		html += '</div>';
		document.write(html);
	}

	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];
			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];
			ButtonReleaseButton(id);
		}
	}

	function ButtonOnMouseOut(element)
	{
		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
		var button = buttonMap[id];
		ButtonReleaseButton(id);
		document.all[BUTTON_DIV_PREFIX + id].className = "bnn";
		
	}

	function ButtonOnMouseOver(element)
	{

		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
	
		var button = buttonMap[id];


		ButtonReleaseButton(id);
		
		document.all[BUTTON_DIV_PREFIX + id].className = "bnmo";
	}

	function ButtonOnClick(element)
	{
		var id = element.id.substring(BUTTON_DIV_PREFIX.length, element.id.length);
		var button = buttonMap[id];
		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 = "bnp";
	}

	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 = "bnn";

	}


	function Editor()
	{
		this.instantiated = false;
		this.Instantiate = EditorInstantiate();
		this.GetText = EditorGetText;
		this.SetText = EditorSetText;
		this.GetHTML = EditorGetHTML;
		this.SetHTML = EditorSetHTML;
	}


    function CreateAndWriteHTML()
    {
var html = "";
		html += "<table class=menu_font cellpadding=0 cellspacing=0 border=0 width=445><tr>";
		html += "<td><img src=0.gif height=1><br>";
		html += "<table cellspacing=0 class=sort2  ><tr>";
		
		html += "<td>";
		html += "<scr"+"ipt>";

		html += "var b1 = new Button(";
		html += "\"Bold\",";
		html += "\"EditorOnBold()\",";
		html += "\"bold_kn\"";
		html += ");";
		html += "b1.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b2 = new Button(";
		html += "\"Italic\",";
		html += "\"EditorOnItalic()\",";
		html += "\"ital_kn\"";
		html += ");";
		html += "b2.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b3 = new Button(";
		html += "\"underline\",";
		html += "\"EditorOnUnderline()\",";
		html += "\"podch_kn\"";
		html += ");";
		html += "b3.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
			
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b6 = new Button(";
		html += "\"Align left\",";
		html += "\"EditorOnAlignLeft()\",";
		html += "\"al_lef\"";
		html += ");";
		html += "b6.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b7 = new Button(";
		html += "\"Center\",";
		html += "\"EditorOnCenter()\",";
		html += "\"al_cent\"";
		html += ");";
		html += "b7.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b8 = new Button(";
		html += "\"Align Right\",";
		html += "\"EditorOnAlignRight()\",";
		html += "\"al_rig\"";
		html += ");";
		html += "b8.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b9 = new Button(";
		html += "\"Justifry\",";
		html += "\"EditorOnAlignJustify()\",";
		html += "\"justify\"";
		html += ");";
		html += "b9.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b13 = new Button(";
		html += "\"Ordered List\",";
		html += "\"EditorOnOrderedList()\",";
		html += "\"orderedList\"";
		html += ");";
		html += "b13.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b13 = new Button(";
		html += "\"Unordered List\",";
		html += "\"EditorUnOrderedList()\",";
		html += "\"UnorderedList\"";
		html += ");";
		html += "b13.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		

		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b10 = new Button(";
		html += "\Decrease Intend\",";
		html += "\"EditorOnDecreaseIndent()\",";
		html += "\"vistup\"";
		html += ");";
		html += "b10.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b11 = new Button(";
		html += "\"Increase Intend\",";
		html += "\"EditorOnIncreaseIndent()\",";
		html += "\"otstup\"";
		html += ");";
		html += "b11.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b4 = new Button(";
		html += "\"Foreground Color\",";
		html += "\"EditorOnForegroundColor()\",";
		html += "\"color\"";
		html += ");";
		html += "b4.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b4 = new Button(";
		html += "\"Background Color\",";
		html += "\"EditorOnBackgroundColor()\",";
		html += "\"bgColor\"";
		html += ");";
		html += "b4.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";
		html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b12 = new Button(";
		html += "\"Hyperlink\",";
		html += "\"EditorOnCreateHyperlink()\",";
		html += "\"web\"";
		html += ");";
		html += "b12.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>"
				html += "<td>";
		html += "<scr"+"ipt>";
		html += "var b15 = new Button(";
		html += "\"Remove Formatting\",";
		html += "\"EditorOnRemoveFormat()\",";
		html += "\"remove\"";
		html += ");";
		html += "b15.Instantiate();";
		html += "</scr"+"ipt>";
		html += "</td>";

		html +="</tr></table></tr><tr><td>";
		html += "<table cellspacing=0 class=sort2><tr><td>";
		html += "<select onchange=\"EditorOnFont(this)\" class=tah70>";
		html += "<option class=\"Heading\">Font</option>";
		html += "<option value=\"Arial\">Arial</option>";
		html += "<option value=\"Arial Black\">Arial Black</option>";
		html += "<option value=\"Arial Narrow\">Arial Narrow</option>"
		html += "<option value=\"Comic Sans MS\">Comic Sans MS</option>";
		html += "<option value=\"Courier New\">Courier New</option>";
		html += "<option value=\"System\">System</option>";
		html += "<option value=\"Tahoma\">Tahoma</option>";
		html += "<option value=\"Times New Roman\">Times New Roman</option>";
		html += "<option value=\"Verdana\">Verdana</option>";
		html += "<option value=\"Wingdings\">Wingdings</option>";
        html += "</select>";
		html += "</td>";
		html += "<td>";
		html += "<select onchange=\"EditorOnSize(this)\" class=tah70>";
		html += "<option class=\"Heading\">Size</option>";
		html += "<option value=\"1\">1</option>";
		html += "<option value=\"2\">2</option>";
		html += "<option value=\"3\">3</option>";
		html += "<option value=\"4\">4</option>";
		html += "<option value=\"5\">5</option>";
		html += "<option value=\"6\">6</option>";
		html += "<option value=\"7\">7</option>";
		html += "</select>";
		html += "</td></tr></table></tr><tr>";
		html += "<td>";
		html += "</tr></table>";
		html += "<iframe id=\"htmledit\" width=\"445\" height=\"300\" class=wr_let>";
	
		html += "</iframe>";
		document.write(html);
    }

	function  EditorGetText()
	{
		return htmledit.document.body.innerText;
	}

	function  EditorSetText(text)
	{
		text = text.replace(/\n/g, "<br>");
		htmledit.document.body.innerHTML = text;
	}

	function  EditorGetHTML()
	{
		EditorCleanHTML();
		return htmledit.document.body.innerHTML;
	}

	function  EditorSetHTML(html)
	{
		htmledit.document.body.innerHTML = html;
	}
	function EditorUnOrderedList()
	{
		EditorFormat("InsertUnorderedList")
					
	}
	function 	EditorOnBackgroundColor()
	{
		var color = showModalDialog("SelectColor.aspx?backColor=true", " ", "font-family:Verdana;font-size:12;dialogWidth:28em;dialogHeight:21em");
		if (color) {
			EditorFormat("backcolor", color);
		}
		else {

			htmledit.focus();
		}
	}
	function EditorOnOrderedList()
	{
	EditorFormat("InsertOrderedList")	
	}
	function EditorOnBold()
	{
		EditorFormat("bold");
	}

	function EditorOnItalic()
	{
		EditorFormat("italic");
	}

	function EditorOnUnderline()
	{
		EditorFormat("underline");
	}

	function EditorOnForegroundColor()
	{
		var color = showModalDialog("SelectColor.aspx?textColor=true", " ", "font-family:Verdana;font-size:12;dialogWidth:28em;dialogHeight:21em");
		if (color) {
			EditorFormat("forecolor", color);
		}
		else {

			htmledit.focus();
		}
	}

	
	
	function EditorOnAlignLeft()
	{
		EditorFormat("justifyleft");
	}

	function EditorOnCenter()
	{
		EditorFormat("justifycenter");
	}

	function EditorOnAlignRight()
	{
		EditorFormat("justifyRight");
	}
	
	function EditorOnAlignJustify()
	{
		EditorFormat("justifyFull");
	}

	function EditorOnDecreaseIndent()
	{
		EditorFormat("outdent");
	}

	function EditorOnIncreaseIndent()
	{
		EditorFormat("indent");
	}
    function EditorOnRemoveFormat()
	{
		htmledit.document.execCommand('removeFormat');

	}

	function EditorOnCreateHyperlink()
	{
		var anchor = EditorGetElement("A", htmledit.document.selection.createRange().parentElement());
		var link = prompt("Prompt", anchor ? anchor.href : "http://");
		if (link && link != "http://") {
			if (htmledit.document.selection.type == "None") {
				var range = htmledit.document.selection.createRange();
				range.pasteHTML('<A HREF="' + link + '"></A>');
				range.select();
			}
			else {
				EditorFormat("CreateLink", link);
			}
		}
	}

	function EditorOnFont(select)
	{
		EditorFormat("fontname", select[select.selectedIndex].value);
		select.selectedIndex = 0;
	}

	function EditorOnSize(select)
	{
		EditorFormat("fontsize", select[select.selectedIndex].value);
		select.selectedIndex = 0;
	}

	function EditorFormat(what, opt)
	{
		htmledit.focus();
				if (opt == "removeFormat") {
			what = opt;
			opt = null;
		}
		if (opt == null) {
			htmledit.document.execCommand(what);
		}
		else {
			htmledit.document.execCommand(what, "", opt);
			
		}
	}

	function EditorCleanHTML()
	{
		var fonts = htmledit.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 EditorInstantiate(){
      //var sTaContent= "ctl00_cphMain_taContent"
        CreateAndWriteHTML()
        html = '';
        html += '<body class=wr_let style=""font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 8px; color: #333333; text-decoration: none"">';
        html += document.getElementById("ctl00_cphMain_taContent").value;
        htmledit.document.open()
        htmledit.document.write(html);
        htmledit.document.close();
        htmledit.document.designMode = "on";
        this.instantiated = true;
    }
    function RefreshBody(sTaContent) {
        document.getElementById(sTaContent).value = EditorGetHTML();
    }
