﻿   function DoClick() {Form1.Message.value='Text from include script.'}
   

   function browserIsIE()
   {
       return (navigator.appName=='Microsoft Internet Explorer');   
   }
      
   function ping()
   {
      alert('ping');
   }
   

function myImageUploadInsert2(editor)
{
  var imageFileName = null;
  var imageFileTitle = null;


  function postback(doc,popup_iframe)
  {
    if(doc != null) // Upload clicked
    {
      if(doc.getElementById("path").value != "")
      {
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     imageFileName = frm.contentWindow.imageFileName;
                     imageFileTitle = frm.contentWindow.imageFileTitle;

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert("error4: "+e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(imageFileName != null)
      {
        editor.focusEditor();
        editor.InsertHTML("<img src=\""+imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");
      }
    }
  }

  function init(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
        if(document.all)
        {
          popup_iframe.style.display = "none";
          doc.getElementById("path").click();
          popup_iframe.style.display = "";
          if(doc.getElementById("path").value == "")
            popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
    }
  }

  editor.customPopup("popup_image_upload","image-upload","../../EditorStuff/__cs_myImageUpload.aspx",postback,init, false, false);
}


function myDocumentUpload2(editor)
{
  var documentFileName = null;
  var documentFileTitle = null;

  function postback(doc,popup_iframe)
  {
  
    if (doc == null)
    {
         alert("postback - doc was  null");
    }
  
    if(doc != null) // Upload clicked
    {
      alert("postback - doc was not null");
      if(doc.getElementById("path").value != "")
      {
        alert("getElementById - doc was not null");
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     documentFileName = frm.contentWindow.documentFileName;
                     documentFileTitle = frm.contentWindow.documentFileTitle;

                     if(documentFileName == null)
                     {
                        alert("Msg1: "+ frm.contentWindow.documentSaved);
                     }

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert("Error1: "+e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(documentFileName != null)
      {
        editor.focusEditor();

        if(editor.TextSelected())
        {
           alert("(TextSelected) setting documentFileName to: "+documentFileName);
          editor.SurroundHTML("<a href=\""+documentFileName+"\" title=\""+documentFileTitle+"\" />","</a>");
        }
        else
        {
          var linkText = (documentFileTitle && documentFileTitle.length > 0)?documentFileTitle:"New document's link";
           alert("(Not TextSelected) setting documentFileName to: "+documentFileName);
          editor.InsertHTML("<a href=\""+documentFileName+"\" title=\""+documentFileTitle+"\" />"+linkText+"</a>");
        }
      }
    }
  }

  function initDoc(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
    }
    else
    {
         alert("initDoc - doc was  null");
    }
  }







  editor.customPopup("popup_document_upload","document-upload","EditorStuff/__cs_myDocumentUpload.aspx",postback,initDoc, false, false);
}


function myImageUploadInsert(editor)
{
  var imageFileName = null;
  var imageFileTitle = null;

  function postback(doc,popup_iframe)
  {
    if(doc != null) // Upload clicked
    {
      if(doc.getElementById("path").value != "")
      {
        var frm = doc.getElementById("fraExecute");

        function onLoad()
        {
          setTimeout(function()
                    {
                     if(frm.detachEvent)
                        frm.detachEvent("onload", onLoad);
                     else
                     if(frm.removeEventListener)
                        frm.removeEventListener("load", onLoad, true);

                     imageFileName = frm.contentWindow.imageFileName;
                     imageFileTitle = frm.contentWindow.imageFileTitle;

                     if(imageFileName == null)
                        alert(frm.contentWindow.imageSaved);

                     popup_iframe.contentWindow.document.getElementById("cancel").onclick();  // emulate Cancel pressed
                    },0);
        }

        if(frm.attachEvent)
           frm.attachEvent("onload", onLoad);
        else
        if(frm.addEventListener)
           frm.addEventListener("load", onLoad, true);

        try{doc.getElementById("frmFile").submit();}
        catch(e)
        {
          alert("Error2: "+e.message);

          if(frm.detachEvent)
             frm.detachEvent("onload", onLoad);
          else
          if(frm.removeEventListener)
             frm.removeEventListener("load", onLoad, true);

         popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
        return false;
      }
    }
    else  // Cancel clicked or emulated
    {
      if(imageFileName != null)
      {
        editor.focusEditor();
        editor.InsertHTML("<img src=\""+imageFileName+"\" alt=\""+imageFileTitle+"\" title=\""+imageFileTitle+"\" />");
      }
    }
  }

  function init(doc,popup_iframe)
  {
    if(doc != null)
    {
        doc.getElementById("title").value = "";
        if(document.all)
        {
          popup_iframe.style.display = "none";
          doc.getElementById("path").click();
          popup_iframe.style.display = "";
          if(doc.getElementById("path").value == "")
            popup_iframe.contentWindow.document.getElementById("cancel").onclick();
        }
    }
  }

  editor.customPopup("popup_image_upload","image-upload","EditorStuff/__cs_myImageUpload.aspx",postback,init, false, false);
}
var keyElement = null;
 
function onClientContentChanged(status){
if(!HTMLEditor.is_ie && keyElement != null && keyElement[1] == 'XXX') {
keyElement[1] = "v"; // Supposed that Ctrl-V was pressed
}
}
 
function controlV(editor){
editor.pasteWord();
if(!HTMLEditor.is_ie){ // IE has access to clipboard
if(keyElement == null){
if(editor._hotkeys.length > 0){ // try to find our hot key
var keysn = editor._hotkeys.length;
for(var i=0; i<keysn; i++){
var item = editor._hotkeys[i];
if(item[1] == "v" && !item[2] && !item[3] && item[4]){
keyElement = item;
break;
}
}
}
}
if(keyElement != null){
keyElement[1] = 'XXX'; // It is a trick to suppress temporary this hot key
}
}
}



function setStyleOfSelectedText(editor, command, selectObject)
{
  // changed  value in select
  if(command == 'change')
  {
    var value = selectObject.options.item(selectObject.selectedIndex).value;

    editor.AssignClassName(value);

    //oboutGetEditor(editorName).AssignClassName(className);

    /*if(value == "")
    {
       editor.removeAlignment();
       return;
    }
    editor.ExecCommand("formatblock", value);*/
  }
  else
  // request for toolbar button's state update
  if(command == 'state')
  {
    var value = editor.QueryCommand("formatblock");
    var index = 0;

    // is header up from the range start?
    if(/^h\d$/i.test(value))
    {
       for(var i=0; i< selectObject.options.length; i++)
       {
         // if we have such option in select - do it selected
         if(selectObject.options.item(i).value.toLowerCase() == value.toLowerCase())
         {
           index = i;
           break;
         }
       }
    }
    selectObject.selectedIndex = index;
  }
}


