var Application = {
    lastId: 0,
    currentSampleNb: 0,
    openedWindow:0,
    
    getNewId: function() {
        Application.lastId++;
        return "window_id_" + Application.lastId;
    },

    addTitle: function(title, id) {
        Application.currentSampleNb++;
        idButton = id + '_click_button';

        document.write("<h2>" + Application.currentSampleNb + ". " + title + " (<span class='title'  id='" + idButton + "' href='#' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" onclick=\"Application.evalCode('" + id + "', true)\">click here</span>)</h2>")
    },

    addShowButton: function(id) {
        idButton = id + '_show_button';
        document.write("<span class='title2' id='" + idButton + "' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" onclick=\"Application.showCode(this, '" + id + "')\">View source</span>")
    },

    addEditButton: function(id) {
        idButton = id + '_edit_button';
        html = "<p class='buttons'><span class='button' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" id='" + idButton + "' onclick=\"Application.editCode('" + id + "')\">Edit Source</span> </p>";
        document.write(html)
    },

    addViewThemeButton: function(theme, modal) {
        idButton = theme + '_theme_button';
        html = "<span class='title2' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" id='" + idButton + "' onclick=\"Application.openThemeWindow('" + theme + "')\">View a window</span>";
        document.write(html)
    },

    addViewThemeDialogButton: function(theme, modal) {
        idButton = theme + '_modal_theme_button';
        html = "<span class='title2' onmouseover=\"$('" + idButton + "').addClassName('selected')\" onmouseout=\"$('" + idButton + "').removeClassName('selected')\" id='" + idButton + "' onclick=\"Application.openThemeDialog('" + theme + "')\">Open a alert dialog</span>";
        document.write(html)
    },

    openLogin: function() {
        this.openThemeWindow(false, 'ajax/ajax.login.form.php' , "LOGIN", 400, 180, 'alphacube');
    },
    
    openSignup: function() {
        this.openThemeWindow(false, 'ajax/ajax.signup.form.php' , "CREAZA UN CONT NOU", 550, 290, 'alphacube');
    },

    myAccount: function() {
        this.openThemeWindow(false, 'ajax/ajax.signup.form.php?', "MY ACCOUNT", 400, 350, 'alphacube');
    },

    ResetPassword: function() {
        this.openThemeWindow(false, 'ajax/ajax.resetPassword.form.php' , "RESET PASSWORD", 400, 180, 'alphacube');
    },

    openAddWebSite: function(itemsMap, _f) {
        this.openThemeWindow(false, 'ajax/ajax.addWebSite.form.php?_f=' + _f + '&'+ this.buildURL(itemsMap, -1) , "ADD A WEB SITE", 400, 150, 'alphacube');
    },

    openThemeWindow: function(modal, url, title, width, height, theme) {

        if (!title || title == "") title = "DEFAULT TITLE";
        if (!width || width == 0) width = 400;
        if (!height || height == 0) height = 200;
        if (!theme) theme = "alphacube";
        var _id = Application.getNewId();
        Application.openedWindow = _id;
        
        var win = new Window(_id, {
            className: theme,
            width:width,
            height:height,
            title: title,
            resizable: false,
            maximizable: false,
            minimizable:false,
            destroyOnClose: true,
            draggable: false
        });
        
        // win.getContent().innerHTML = "";
        win.setURL(url);
        win.showCenter(modal);
    },

    openThemeDialog: function(theme, modal) {
        Dialog.alert("Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim ad minim veniam, quis nostrud exerc",
        {windowParameters: {className: theme, width:350}, okLabel: "close"});
    }
}
