$(document).ready(function() {
    $('.btn').each(function() {
        var b = $(this);
        var tt = b.text() || b.val();
        if ($(':submit,:button',this)) {
            b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id);
            if (this.href) {
                b.attr('href', this.href);
            }
            if (this.tagName == 'INPUT') {
                b.click(function() {
                    f = findForm(this);
                    $(f).submit();
                });
            }
            $(this).remove();
        }
        b.text('').css({cursor:'pointer'}).prepend('<i></i>').append($('<span>').
        text(tt).append('<i></i><span></span>'));
    });
});

function findForm(f) {
    while(f.tagName != "FORM") {
        f = f.parentNode;
    }
    return f;
};


