$(document).ready(function() {
    $('a').each(function(id, element) {
        if ($(this).attr('id') != 'btnLogout' && $(this).attr('id') != 'btnLogin') {
            $(this).click(function(event) {
                event.preventDefault();
                $.ajax({
                    type: "GET",
                    url: $(this).attr('href'),
                    success: function(msg) {
                        $('#maincontent').empty();
                        $('#maincontent').html(msg);
                        $('#pageTitle').html($('#hdnPageTitle').html());
                    }
                });
            });
        }
    })
});

$(document).ready(function() {
    $('#news_latest .newsitem').each(function(id, element) {
        $(this).mouseover(function(event) {
            if (!$(this).hasClass('hovered')) {
                $(this).addClass('hovered');
            }
        }).mouseout(function(event) {
            if ($(this).hasClass('hovered')) {
                $(this).removeClass('hovered');
            }
        });
    })
});

$(document).ready(function() {
    $('#submit').hover(function() {
        $(this).addClass('hover')
    }, function() {
        $(this).removeClass('hover');
    });
});

function callAjax(url, data, divID, errorID) {
    if (url != '') {
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var data = msg.d;
                alert(data);
                $("#" + divID).empty();
                $("#" + divID).html(data);
            },
            error: function(xhr, desc, exceptionobj) {
            $("#" + divID).html(xhr.responseText);
            }
        });
    }
}

function login() {

    callAjax("login.aspx/Login", "{'username': '" + $('#username').val() + "','password': '" + $('#password').val() + "' }", "message");
}
