 //--------------------------------------------------------------------------------------- EDITOR FUNCTIONS ----------------------------
 function OnClientLoad(editor)
	{
	editor.AttachEventHandler ("RADEVENT_SEL_CHANGED", EditorSelectionChanged);
    editor.AttachEventHandler ("onkeydown", pagechanged); 
	editor.AttachEventHandler ("onkeyup", pagechanged); 
	ShowToolbar(editor,"minimal");
	}

function EditorSelectionChanged()
    {
    pagechanged();
   	//Display properties for the selected item (page, dataset find, dataset detail)
	if (document.getElementById("txteditid").value != "" && document.getElementById("diveditor").style.display=="")
        {
        PageItemClicked();
        }
    }

function pagechanged()
	{
	//only change the save status if the editor window is visible.
	if (document.getElementById("txteditid").value != "" && document.getElementById("diveditor").style.display=="" && document.getElementById("txtpagechanged").value != "true")
	    {
	    if (document.getElementById("NewEditorHTML").value != window.GetRadEditor("editor1").GetHtml())
	        {
            document.getElementById("txtpagechanged").value = "true";
            UpdateSaveColor()  
            }
        }
	}

function ShowToolbar(editor,toolbar)
    {
    if (toolbar == "full")
        {
        var disp="";
        editor.GetToolByName("Less").GetIcon().style.display="";   
        editor.GetToolByName("More").GetIcon().style.display="none";   
        }
    else
        {
        var disp="none";
        editor.GetToolByName("Less").GetIcon().style.display="none";   
        editor.GetToolByName("More").GetIcon().style.display="";   
        }    
        
        editor.GetToolByName("Print").GetIcon().style.display=disp;   
        editor.GetToolByName("SpellCheck").GetIcon().style.display =disp;   
        editor.GetToolByName("FindAndReplace").GetIcon().style.display =disp;   
        editor.GetToolByName("GlobalSearchAndReplace").GetIcon().style.display =disp;   
        editor.GetToolByName("Cut").GetIcon().style.display =disp;   
        editor.GetToolByName("Copy").GetIcon().style.display =disp;   
        editor.GetToolByName("Paste").GetIcon().style.display =disp;   
        editor.GetToolByName("PasteFromWord").GetIcon().style.display =disp;   
        editor.GetToolByName("PasteFromWordNoFontsNoSizes").GetIcon().style.display =disp;   
        editor.GetToolByName("PastePlainText").GetIcon().style.display =disp;   
        editor.GetToolByName("PasteAsHtml").GetIcon().style.display =disp;   
        editor.GetToolByName("Undo").GetIcon().style.display =disp;   
        editor.GetToolByName("Redo").GetIcon().style.display =disp;   
        editor.GetToolByName("LinkManager").GetIcon().style.display =disp;   
        editor.GetToolByName("Unlink").GetIcon().style.display =disp;   
        //editor.GetToolByName("InsertTable").GetIcon().style.display =disp;   
        //editor.GetToolByName("ImageManager").GetIcon().style.display =disp;   
        editor.GetToolByName("AbsolutePosition").GetIcon().style.display =disp;   
        editor.GetToolByName("FlashManager").GetIcon().style.display =disp;   
        editor.GetToolByName("MediaManager").GetIcon().style.display =disp;   
        editor.GetToolByName("DocumentManager").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertFormElement").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertSymbol").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertVariable").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertCondition").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertParagraph").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertHorizontalRule").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertDate").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertTime").GetIcon().style.display =disp; 
        //editor.GetToolByName("InsertPageObject").GetIcon().style.display ="none"; 
        editor.GetToolByName("StickyNote").GetIcon().style.display =disp;   
        editor.GetToolByName("FormatStripper").GetIcon().style.display =disp;   
        editor.GetToolByName("ToggleTableBorder").GetIcon().style.display =disp;   
        editor.GetToolByName("Indent").GetIcon().style.display =disp;   
        editor.GetToolByName("Outdent").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertOrderedList").GetIcon().style.display =disp;   
        editor.GetToolByName("InsertUnorderedList").GetIcon().style.display =disp;   
        editor.GetToolByName("Superscript").GetIcon().style.display =disp;   
        editor.GetToolByName("Subscript").GetIcon().style.display =disp;   
        editor.GetToolByName("StrikeThrough").GetIcon().style.display =disp;   
        editor.GetToolByName("ApplyClass").GetIcon().style.display =disp;   
        editor.GetToolByName("FormatBlock").GetIcon().style.display =disp;   
        //editor.GetToolByName("FontName").GetIcon().style.display =disp;   
        //editor.GetToolByName("FontSize").GetIcon().style.display =disp;   
        //editor.GetToolByName("Bold").GetIcon().style.display =disp;   
        editor.GetToolByName("Italic").GetIcon().style.display =disp;   
        //editor.GetToolByName("Underline").GetIcon().style.display =disp;   
        editor.GetToolByName("JustifyLeft").GetIcon().style.display =disp;   
        editor.GetToolByName("JustifyCenter").GetIcon().style.display =disp;   
        editor.GetToolByName("JustifyRight").GetIcon().style.display =disp;   
        editor.GetToolByName("JustifyFull").GetIcon().style.display =disp;   
        //editor.GetToolByName("ForeColor").GetIcon().style.display =disp;   
        editor.GetToolByName("BackColor").GetIcon().style.display =disp;   
        //If this is firefox then hide the sticky note icon. it doesn't work well in Firefox
        if (navigator.appName != "Microsoft Internet Explorer")
            {
            editor.GetToolByName("StickyNote").GetIcon().style.display ="none";   
            }
    }

   
    
function InsertCondition(commandName, editor)
	{
	
		var args = editor.GetDialogParameters(commandName);
		var argStr = "";
		for (var item in args)
		{
			argStr += "[" + item + "=" + args[item] + "] ";
		}

		//Get the name of the current project
		var projectname = GetProjectName();

		theEditor = editor;
		editor.ShowDialog(
			"../_engine/InsertCondition.aspx?projectname="+projectname
			, null
			, 290
			, 400
			, callBackFunctionPtr
			, null
			, "Insert Condition");
	};

function GlobalSearchAndReplace(editor)
    {
    if (document.getElementById("txtpagechanged").value == "true" && document.getElementById("txteditid").value != "")
        {
        alert("The page must be saved before using this function.");
        return;
        }
    
	//Get the name of the current project
	var projectname = GetProjectName();

	theEditor = editor;
	editor.ShowDialog(
		"../_engine/GlobalReplace.aspx?projectname="+projectname
		, null
		, 350
		, 250
		, GlobalSearchAndReplace_callback
		, null
		, "Global Search and Replace");
    }

function GlobalSearchAndReplace_callback(returnValue)
    {
	if (returnValue)
		{
			alert(returnValue);
			LoadPage_editor(TreeView1.SelectedNode.ID);
		}

    }

function InsertVariable(commandName, editor)
	{
		var args = editor.GetDialogParameters(commandName);
		var argStr = "";
		for (var item in args)
		{
			argStr += "[" + item + "=" + args[item] + "] ";
		}

		//Get the name of the current project
		var projectname = GetProjectName();

		theEditor = editor;
		editor.ShowDialog(
			"../_engine/InsertVariable.aspx?projectname="+projectname
			, null
			, 350
			, 250
			, callBackFunctionPtr
			, null
			, "Insert Variable");
	}

function callBackFunctionPtr(returnValue)
	{
		if (returnValue)
		{
			theEditor.PasteHtml(returnValue);
		}
	}

	function InsertStickyNote(editor)
		{
	
		//Get a unique id for the sticky note tag
		var sUniqueID="_note"+new Date().getTime()
        var sHTML = "<span tabindex='1' style='border-right:1px solid #676F7A; border-bottom:1px solid #676F7A;display:none; padding-right: 10px; padding-left: 10px; background-image:url(../_engine/images/stickynote_back.jpg); padding-bottom: 10px; width: 120px; height:20px; padding-top: 10px; '>"
        sHTML = sHTML + "<img src='../_engine/images/lightbulb.gif'>&nbsp;"
        sHTML = sHTML + "<font id='"+sUniqueID+"' tabindex='2'>&nbsp;</font></span>"
		editor.PasteHtml(sHTML);
		//Fire the absolutePosition command to ensure that the tag can be dragged.
		//set the focus to the text area inside the sticky note
		editor.ContentWindow.document.getElementById(sUniqueID).focus();
		}

function InsertPageObject(commandName, editor)
	{
	
		var args = editor.GetDialogParameters(commandName);
		var argStr = "";
		for (var item in args)
		{
			argStr += "[" + item + "=" + args[item] + "] ";
		}

		//Get the name of the current project
		var projectname = GetProjectName();

		theEditor = editor;
		editor.ShowDialog(
			"../_engine/InsertPageObject.aspx?projectname="+projectname
			, null
			, 350
			, 280
			, callBackFunctionPtr
			, null
			, "Insert Page Object");
	};

	
