/**
 * Performs AJAX call to server and returns additional events for given category ID and country ISO. Returns filled
 * template.
 * @param category_id - ID of category
 */
function get_more_events(category_id) {
    $("#loader-" + category_id).show();
    $.ajax({
        type: "GET",
        url: "/events/get_more_events/"+ category_id,
        success: function(response) {
            $("#more-events-" + category_id).empty().append(response);
            $("#more-events-link-" + category_id).fadeOut();
            $("#loader-" + category_id).hide();
        }
    });
}

/**
 * Performs AJAX call to server and returns additional events for given category ID and country ISO. Returns filled
 * template.
 * @param category_id - ID of category
 * @param country_iso - country ISO
 */
function get_more_events_iso(category_id, country_iso) {
    $.ajax({
        type: "GET",
        url: "/events/get_more_events/"+ category_id + "/" + country_iso,
        success: function(response) {
            $("#more-events-" + category_id).empty().append(response);
            $("#more-events-link-" + category_id).fadeOut();
        }
    });
}

/**
 * Perform AJAX call to server and returns list of child categories for given parent category ID. Returns JSON object.
 * @param category_id - ID of parent category
 */
function get_child_categories(category_id) {
    $.ajax({
        type: "GET",
        dataType: "json",
        url: "/add_event/get_child_categories/" + category_id,
        success: function(response) {
            data = response.categories_data;

            if (data.length > 0) {
                // Child category available for parent category
                $("#div_secondary_category").show();

                $("#id_secondary_category").empty();
                $("#id_secondary_category").append("<option value=''>Select...</option>");
                for (var i = 0; i < data.length; i++) {
                    $("#id_secondary_category").append("<option value='" + data[i].id + "'>" + data[i].name + "</option>");
                }
            } else {
                // No child categories
                $("#id_secondary_category").empty();
                $("#div_secondary_category").hide();
            }
        }
    });
}


