$(document).ready(function()
{
     // When 'more filter options' link is clicked
    $("#moreFilterOptionsLink").click(function()
    {
        // Extract image's source and get filename from it
        var imageSource = (this.src).split("/");
        var imageFilename = imageSource.pop();

        // If image's filename does not contain '+' (plus) then replace '-' (minus) with '+' (plus)
        if (0 > imageFilename.indexOf("+"))
        {
            imageFilename = imageFilename.replace("-", "+");
        }
        // If image's filename contains '+' (plus) then replace '+' (plus) with '-' (minus)
        else
        {
            imageFilename = imageFilename.replace("+", "-");
        }

        // Change image's source
        imageSource.push(imageFilename)
        this.src = imageSource.join("/");

        // Toggle display of 'more filter options' box
        $("#more_search").toggle();
    });

    // When country is changed then get its regions drop-down using AJAX request
    $("#JobCountryId").change(function()
    {
        $.get(baseUrl + "jobs/get_regions_for_country/" + this.options[this.selectedIndex].value, function(response)
        {
            $("#JobRegion").html(response);
            $('#JobAddForm').submit();
        });
    });

    $('#JobJobCategoryId, #JobTypeId, #JobStateId').change(function()
    {
        $('#JobAddForm').submit();
    });

    // Bind event for page
    bindPageEvents();
});

// Function used to bind event for page
function bindPageEvents()
{
    // When any pagination link is clicked
    $(".paginationLink").click(function()
    {
        // Send AJAX request to get page
        $.get(this.href, function(response)
        {
            $("#jobsList").html(response);
            bindPageEvents();
            window.scrollTo(0, 0);
        });

        // By default return false
        return false;
    });
}