BlogComment = Class.create();
Object.extend(BlogComment.prototype, 
{
    initialize: function()
    {
    },
        
    submit: function(formObject)
    {
        this.hideErrors();
        
        /* Send the request */
        new Ajax.Request(
            '/ajax/Blogs/comment/', 
            {
                parameters:     Form.serialize(formObject),
                onSuccess:      this.submitSuccessHandler.bind(this),
                onFailure:      this.submitErrorHandler.bind(this),
                onException:    this.submitExceptionHandler.bind(this)
            }
        );
    },
        
    displayErrors: function(output)
    {
        Element.update($('error'), output);
    },
     
    hideErrors: function()
    {
    	Element.update($('error'), '');
    },
      
    submitSuccessHandler: function(request)
    {
        if(request.responseText == '1')
        {
            $('blogComment').reset();
            window.location.reload();
        }
        else
        {
            this.displayErrors(request.responseText);
        }
    },
        
    submitErrorHandler: function(request, json)
    {
        this.submitError('A javascript error occured. Please notify the webmaster at webmaster@fracturedatlas.org.');
    },
    
    submitExceptionHandler: function(request, exception)
    {
        this.submitError('A javascript exception occured. Please notify the webmaster at webmaster@fracturedatlas.org.');
    }
});

BlogRandomizer = Class.create();
Object.extend(BlogRandomizer.prototype, 
{
    initialize: function(container, blog)
    {
    	this.container = $(container);
        this.blog      = blog;
    },
    
    newPost: function()
    {
        new Ajax.Updater(this.container, '/ajax/Blogs/random_item/?blog='+this.blog);
    }
});

function bpbToggle(node, toggler)
{
    var section = $('bpb_'+node);
    
    if(section.style.display == 'none')
    {
        section.style.display = 'block';
        toggler.innerHTML = "&#9660;"; 
    }
    else
    {
        section.style.display = 'none';
        toggler.innerHTML = "&#9658;";
    }
}
