function initQuotable() 
{
    $$('a').each(function(s) {
        if (s.getAttribute('rel') != 'quote') return;
        
        // Add onclick event handler to quote the message
        s.observe('click', function(event) {
             
            
           try {
                
                var container = event.findElement('div.post');
                //alert(container);
                var post = container.down('div.post-message');
                var author = container.down('div.author');
                var quote = post.cloneNode(true);
                var editor = FCKeditorAPI.GetInstance('data[Post][contents]');
                
                
                // Remove all existing block quotes from quoted post
                quote.select('blockquote[cite=*]').invoke('remove');
                
                // Get editor
                var editor = FCKeditorAPI.GetInstance('data[Post][contents]');
                if (typeof(editor) == 'undefined') {
                    return;
                } 
    
                // Build quote template
                var blockquote = '<blockquote cite="#{url}">';
                blockquote += '<div class="author">Quoting ';
                blockquote += '<a href="#{profile}" rel="profile">';
                blockquote += '#{author}';
                blockquote += '</a>';
                blockquote += ':</div>';
                blockquote += '<div class="quote">';
                blockquote += '#{quote}';
                blockquote += '</div>';
                blockquote += '</blockquote><p></p>';
                
                var template = new Template(blockquote);
                
                // Assign values to template
                var show = {
                    url:        location.href,
                    author:     author.innerHTML,
                    profile:    author.readAttribute('href'),
                    quote:      quote.innerHTML
                };
                
                // Insert quote and scroll to editor
                var quoted = template.evaluate(show);
                editor.InsertHtml(quoted);
                $("reply").scrollTo();
                editor.Focus();
                event.stop();
            } catch (e) {
                //alert('catch');
                //alert(e.description);
            } 
        });
    });
}

//Event.observe(window, 'load', function(event)
document.observe('dom:loaded', function(event)
{
    //Disable submit button after click
    
    initQuotable(); 
   /* $$('form').each(function(form) {
        form.observe('submit', function() {
            $$('input[type="submit"]').invoke('disable');
            $$('form').observe('submit', function(evt) { // once any form is submitted
                evt.stop(); // prevent any other form submission
            } );
        } );
    }); */ 
    

});