﻿
function OnClientPasteHtml(sender, args) {
    var commandName = args.get_commandName();
    var value = args.get_value();

    if (commandName == "ImageManager") {
        //See if an img has an alt tag set      
        var div = document.createElement("DIV");

        //Do not use div.innerHTML as in IE this would cause the image's src or the link's href to be converted to absolute path.     
        //This is a severe IE quirk.     
        Telerik.Web.UI.Editor.Utils.setElementInnerHtml(div, value);

        //Now check if there is alt attribute      
        var img = div.firstChild;
        if (!img.alt || img.alt == "") {
            alert("Ingen alt-text är angiven. För att lägga till alt-text högerklicka på bilden och välj Properties.");
            var path = img.src;
            var lastSlash = path.lastIndexOf("/");
//            var imgName = img.src.substring(lastSlash + 1, path.length);
//            imgName = imgName.replace("å", "aring;").replace("ä", "auml;").replace("ö", "ouml;").replace("Å", "Aring;").replace("Ä", "Auml;").replace("Ö", "Ouml;");
//            img.setAttribute("alt", img.src.substring(lastSlash + 1, path.length));
//            args.set_value(div.innerHTML);
        }
    }
}

function OnClientLoad(editor, args) {
    editor.removeShortCut("InsertTab");
    var buttonsHolder = $get(editor.get_id() + "Top"); //get a reference to the top toolbar zone of the editor  
    var buttons = buttonsHolder.getElementsByTagName("A"); //get a reference to all A elements on the toolbar and disable the tabbing trough them  
    for (var i = 0; i < buttons.length; i++) {
        var a = buttons[i];
        a.tabIndex = -1;
        a.tabStop = false;
    }
    editor.get_contentAreaElement().tabIndex = "200";
}
function OnClientSubmit(sender, args) {
    
    var content = sender.get_html(false);
    if (content != null) {
        var newcontent = content.replace(/<A/g, "<A tabindex ='200'");
        sender.set_html(newcontent);
    
    }
   
    
   // var buttonsHolder = $get(editor.get_id() + "Top"); //get a reference to the top toolbar zone of the editor  
    //var buttons = buttonsHolder.getElementsByTagName("A"); //get a reference to all A elements on the toolbar and disable the tabbing trough them  
//    for (var i = 0; i < buttons.length; i++) {
//        var a = buttons[i];
//        a.tabIndex = -1;
//        a.tabStop = false;
//    }
//    editor.get_contentAreaElement().tabIndex = "200";
}

