//função responsavel por disparar o evento de textchange do Radeditor e colocar o valor na variavel de sessão
function handleTabKey(editor, e) {
    // Defino o comportamento da tecla TAB para todos os browsers
    editor.removeShortCut("InsertTab");
    // Adaptado de: http://www.telerik.com/forums/radeditor-tab-key-focus-on-another-control-in-firefox-while-in-ie-it-inserts-whitespace
    if (e.keyCode == '9') {
        // Substitui o caracter tab, que varia entre os browsers, pelo comando IDENT/OUTDENT do editor

        // Verifica se a tecla shift está activa
        if (!e.shiftKey)
            // TAB
            //editor.fire("Indent");
            editor.pasteHtml("<span class='tab'>&nbsp;&nbsp;&nbsp;&nbsp;</span>");
        //else
            // SHIFT+TAB
            //editor.fire("Outdent");

        if (!document.all) {
            // Standard browser support
            e.preventDefault();
            e.preventBubble();
            e.stopPropagation();

        }
        else {
            // Deprecated browser support
            e.returnValue = false;
            e.cancelBubble = true;
        }
    }
}

function replaceMaginLeftWithTextIndent(element) {
    if (element.tagName.toLowerCase() == "p" && element.style.marginLeft != "") {
        element.style.textIndent = element.style.marginLeft;
        element.style.marginLeft = "";
    }

    return element
}

function replaceTextIndentWithMaginLeft(element) {
    if (element.tagName.toLowerCase() == "p" && element.style.textIndent != "") {
        element.style.marginLeft = element.style.textIndent;
        element.style.textIndent = "";
    }

    return element
}

function sanitizeHTML(initContent) {
    var cleanContent;

    //Perform necessary REGEX replacement to remove unsupported HTML tags
    //Supported Reporting HTML tags: FONT, STRONG, B, EM, I, U, A, OL, UL, LI, DIV, SPAN, P, BR, CENTER
    //HTML must be XHTML valid, too, but Editor already provides that filter

    //Following REGEX will remove all HTML tags EXCEPT those expliclitly listed
    cleanContent = initContent.replace(new RegExp("<(?!\/?(font|strong|b|em|(i(?!mg))|u|a|ol|ul|li|div|span|p|br|center)(?=>|\s?.*>))\/?.*?>", "ig"), "");
    // VS 2017-01-13: Retiramos também todos os atributos que não nos interessam
    cleanContent = cleanContent.replace(new RegExp("(margin.*?:)[^;].+?; ?", "ig"), "")
    return cleanContent;
}