﻿var l_PreviewSubmitID = "";

function OnClientPasteHtml(sender, args)
{
    var commandName = args.get_commandName();
    var value = args.get_value();

    if (commandName == "InsertTable")
    {
        var pos = value.toLowerCase().indexOf("<table>")
 
        if (pos>=0) {
            value = value.substring(0, pos) + "<TABLE BORDER='1'>" + value.substring(pos + 7);
            args.set_value(value);
        }
    }
}

function OnClientCommandExecuting(editor, args)
{
   var name = args.get_name();
   var val = args.get_value();
  
   if (name == "DynamicDropDown")
   {
       editor.pasteHtml(val);      
       //Cancel the further execution of the command as such a command does not exist in the editor command list
       args.set_cancel(true);

       if (l_PreviewSubmitID != "" && val == "[Property Template]") {
            $get('Has2ndTemplate').value = "Yes";
            $get(l_PreviewSubmitID).click();
       }
   }
   
   if (name == "ImageManager")
   {
        var key = $get("DocumentKey").value;
        
        if (key == "" || key == "-1")
        {
            alert("The document is not currently saved, please save the document before uploading any images.");
            args.set_cancel(true);
        }
   }

}


