
Event.observe(window, 'load', function(event) {
    Tab.initialize_all();
    Tab.activate(Cookie.get('current_tab') || 'company');
});

var Tab = {
    all: function() {
        return ['company' , 'web_contact', 'notes', 'personal'];
    },
    initialize_all: function() {
        if (Cookie.get('current_tab') == undefined) {
            Cookie.set('current_tab', 'company');
        }
        $('content_tab_container').down('.tabs').update($('tabs').innerHTML);
        $('tabs').update('');
    },
    update_content: function(name) {
        var url = user_profile_link + '/' + name;
        var request = new Ajax.Request(url, {
            method: 'get',
            onSuccess: function(trans) {
                $('content_tab').update(trans.responseText);
            },
            onLoading: function(trans) {
                $('content_tab').update($('ajax_loading').innerHTML);
            }
        });           
    },
    activate: function(name) {
        Tab.update_content(name);
        Tab.highlight(name);
        Cookie.set('current_tab', name);
        Tab.all().without(name).each(function(tab) {
            Tab.deactivate(tab);
        });
    },
    highlight: function(name) {
        $(name + '_link').addClassName('active');
        $(name + '_link').removeClassName('inactive');
    },

    deactivate: function(name) {
        $(name + '_link').addClassName('inactive');
        $(name + '_link').removeClassName('active');
    }
}

var Note = {
    show_form: function(link) {
        $('add_note_form_container').show();
        $('add_note_form_container').setStyle({top: 5+'px', left: 5+'px'});
    },
    remove_form: function(link) {
        $('add_note_form_container').hide();
    },
    show_note: function(id) {
        $('note_' + id).show();
        $('note_' + id).setStyle({top: 5+'px', left: 5+'px', background: 'white', 'z-index': 100});
    },
    remove_note: function(id) {
        $('note_' + id).hide();
    }
}

