//Init elements
$(document).ready(function() {
    submitMe();
});


function submitMe(){
    /* attach a submit handler to the form */
    $.each( $(".evoAjax"), function(){
        var obj = this;
        $(obj).find('form').submit(function(event) {

            /* stop form from submitting normally */
            event.preventDefault(); 
            $(obj).find('.loader').show().css('display','inline-block');
            var attributes = $(this).serializeArray();
        
            $.ajax({
                type: 'post',
                url: $(this).attr('action'),
                dataType: 'html',
                data: $.param(attributes) + '&evoajax=true',
                success: function(html){
                    $(obj).replaceWith(html);
                    $(obj).find('.loader').hide();
                    submitMe();
                }
            });
            return false;


        });
        
        
    });
    
    
}

// Fix oldies IE bug
if ($.browser.msie) {
    if ($.browser.version === "7.0" ||
        $.browser.version === "6.0") {
        $(".evoAjax button").live('click',function() {
            $(this).parents('form').submit();
        });
    }
}
