(function($) {
      
 
  // Define the hello button
  $.cleditor.buttons.emailLink = {
    name: "emailLink",
    image: "emailLink.png",
    title: "Inserisci un link ad una email",
    command: "inserthtml",
    popupName: "emailLink",
    popupClass: "cleditorPrompt",
    //Width: <input type='text' size='3' value='480' id='width' /><br /><br /> Height: <input type='text' size='3' id='height' value='385' />
    popupContent: "Inserire l'email (senza spazi):<br><input type='text' size='70' id='ybid' text=''><br /><br /><br /><input type='button' value='Inserisci' class='bottoneCLE'>",
    buttonClick: emailLinkClick
  };
      
 
 
  // Handle the hello button click event
  function emailLinkClick(e, data) {
      
   // Wire up the submit button click event
    $(data.popup).children(":button")
      .unbind("click")
      .bind("click", function(e) {
      
 
        // Get the editor
        var editor = data.editor;
        var ybId = $(data.popup).find("#ybid").val();
         
        // Check for selection before showing the link url popup
//        if (selectedText(editor) === "") {
//          $('body').append('<div id="email_message" style="position: fixed; top: 38%; left: 38%; width: 260px; height: 80px; border: 3px solid lightgray; background-color: #CCC;">Selezionare una parola per inserire il link.<br/><br/><input type="button" class="bottoneCLE" onclick="$(\'#youtube_message\').remove();" value="Ok"></input></div>');            
//         return false;
//        }

          // Wire up the submit button click event handler
//          $popup.children(":button")
//            .unbind(CLICK)
//            .bind(CLICK, function() {

              // Insert the image or link if a url was entered             
         var html = $.trim(ybId);
         html = html.replace('mailto: ','');
         html = html.replace('mailto:','');
         if ((html.indexOf('@') != -1))
         {
            html = html.replace('"','\"');
            editor.execCommand(data.command, "<a class=\"EstEditor\" href=mailto:" + html + ">"+html+"</a>", null, data.button);
         }
         else
         {
         $('body').append('<div id="messagePop" style="position: fixed; top: 38%; left: 38%; width: 260px; height: 80px; border: 3px solid lightgray; background-color: #CCC;">Inserire una mail corretta.<br/><br/><input type="button" class="bottoneCLE" onclick="$(\'#messagePop\').remove();" value="Ok"></input></div>');            
         }
             
             
         editor.hidePopups();
         editor.focus();
            //});
        });
    }
      
 
})(jQuery);

