﻿function fillMenu(sender, country, region, type) {

    startWaiting();

    $('#ctgr-name').empty();
    
    $('#ctgr-name').text($(sender).text());
    

    $.getJSON(
        '/DataAccess/HotelsService.svc/GetHotels?parameters={"Country": ' + country + ', "Region":' + region + ', "Type" : "' + type + '"}',
        function(result) { createMenu(result) }
    ); 
}

function createMenu(result) {

    $('#ntls-item-cnt').empty();

    $.each(result.d.Items, function(i, val) {
        $('#ntls-item-cnt').append('<div class="item-cnt"><a href="alert(' + val.ID + ')"><span>' + val.Name + '</span></a></div>');
    });

    if (result.d.CurrentPage != 1) {
        $('#prev-btn').bind('click', function() {  });
        $('#prev-btn').show();
    }
    else {
        $('#prev-btn').unbind('click');
        $('#prev-btn').hide();
    }

    if (result.d.CurrentPage == result.d.TotalPages) {
        $('#next-btn').hide();
    }
    else {
        $('#next-btn').show();
    }

    stopWaiting();
}

function startWaiting() {

    $('#items-cnt').hide();
    $('#items-waiting').show();

}

function stopWaiting() {

    $('#items-waiting').hide();
    $('#items-cnt').show();

}

