tinyMCE.init({
    // General options
    language: "pl",
    file_browser_callback : "UrlChoser",

    mode : "exact",
    elements : "text",
    theme : "advanced",
    skin: "o2k7",
    plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,contactform,gmap,galery",

    // Theme options
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,|,sub,sup,|,undo,redo,|,link,unlink,anchor,image,|,charmap,iespell,media,nonbreaking",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|cleanup,help,code,|,contactform,gmap,galery",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    theme_advanced_resize_horizontal: false,
    cleanup_on_startup: true,
    relative_urls : true,
    document_base_url : base_url +'/',
    convert_urls : false,

    content_css : base_url + "/application/public/styles/style.css",

    verify_html : false, //żeby nie usuwał tagów przy formularzu kontaktowym

    // Replace values for the template plugin
    template_replace_values : {
        username : "Some User",
        staffid : "991234"
    }
});

$(document).ready( function() {
    $('#cms_btn_save').click( function() {
        SavePage();
     });
});
function SavePage()
{
    var cont_name = $('#controller_name').val();
    if(cont_name == '') {
        alert('Wpisz nazwę strony');
        return;
    }
    var reg = /^[a-z]+$/;
    if (!reg.test(cont_name)) {
        alert ('Nazwa strony zawiera niedozwolone znaki!');
        return;
    }

    $('#gwd_cms_edit').submit();

}

function UrlChoser (field_name, url, type, win) {
     tinyMCE.activeEditor.windowManager.open({
        file : base_url + '/browser/index/index/browser_type/' + type,
        title : 'Przegldarka zasobów',
        width : 553,  // Your dimensions may differ - toy around with them!
        height : 400,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous : "no"
    }, {
        window : win,
        input : field_name, mtype: type
    });
    return false;

}
