// vim: expandtab ts=8 sw=8
tinyMCEPopup.requireLangPack();


/**
 * Window args passed to the popup:
 *        (retrieve by tinyMCEPopup.getWindowArg('isIE');
 *
 * - plugin_url : url, // Plugin absolute URL
 * - listStyleType : listStyleType, // 'decimal', 'disc', etc.
 * - listNode : listNode, // the list dom element
 * - listStart : listStart, // 1, 2, 3
 * - classAttr : p.className, // html class attribute class
 * - isIE : isIE  // true / false
 */
function init() {
        tinyMCEPopup.resizeToInnerSize();

        var formObj = document.forms[0];
        var isIE = tinyMCEPopup.getWindowArg('isIE');
        var classAttr = tinyMCEPopup.getWindowArg('classAttr') || '';
        var listStyleType = tinyMCEPopup.getWindowArg('listStyleType');

        listSpecificInit();

        setListStyleType( listSpecificSwitch( formObj, listStyleType) );

        if (isIE) {
                document.getElementById("classAttrId").value = classAttr;
        } else {
                document.getElementById("classNameRow").style.display = "none";
                listSpecificNonIEInit();
        }
}


/**
 * Just copy a value from radio button to a hidden input.
 * This function is set as onclick event on radio controls.
 */
function setListStyleType(listStyleType) {
        document.forms[0].listStyleTypeId.value = listStyleType;
}


/**
 * This function is set as onclick event on the 'OK' button.
 */
function okayAction() {
        var formObj = document.forms[0];

        var listNode = tinyMCEPopup.getWindowArg('listNode');
        var classAttr = formObj.classAttr.value;
        var listStyleType = formObj.listStyleType.value;
        var isIE = tinyMCEPopup.getWindowArg('isIE');

        if (listNode) {
                tinyMCEPopup.execCommand('mceBeginUndoLevel');
                listNode.style.listStyleType = listStyleType;
                listNode.removeAttribute('mce_style'); // MAGIC! FIXME: wyjaśnij, po co jest mce_style

                listSpecificOkayAction( formObj, listNode );

                if (isIE) {
                        listNode.className = classAttr;
                }
                tinyMCEPopup.execCommand('mceEndUndoLevel');
        }
        tinyMCEPopup.close();
}


tinyMCEPopup.onInit.add(init);
