$(document).ready(function () {
    // PREVENT ASP.NET FORM FROM SUBMITTING
    $('#aspnetForm').bind('submit', function (e) {
        e.preventDefault();
    });
    $('#form1').bind('submit', function (e) {
        e.preventDefault();
    });

    // GLOBAL SEARCH
    $('#search').bind('keypress', function (e) {
        if (e.keyCode == 13) {
            var query = ($('#search').val() + '').trim();
            if (query) window.location.href = '/search.aspx?terms=' + query;
        }
    });

    // RENDER PROTECTED EMAIL LINKS
    // EXAMPLES:
    // <a class="email_link" href="#" link_to="hello(#)hello.com">click here to email hello(#)hello.com</a>
    var links = $('a.email_link');
    links.each(function (index, link) {
        $(link).attr('href', 'mailto:' + $(link).attr('link_to').replace('(#)', '@'));
        var link_content = $(link).html().replace('(#)', '@');
        if (link_content != $(link).html()) $(link).html(link_content);
    });

});
