﻿jQuery.noConflict();
jQuery(function() {
    jQuery("[id$='_ddlTime']").change(getLocation);
    jQuery('#ddlLocation').attr('disabled', true);
    jQuery('#ddlAge').attr('disabled', true);
});

function getLocation() {
    jQuery.ajax({
        type: "POST",
        url: "Services/ActivityFinder.asmx/GetLocation",
        data: "{timeSelected: '" + jQuery("[id$='_ddlTime']").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var locations = response;
            jQuery('#ddlLocation').attr('disabled', false).change(getAge).removeOption(/./).addOption('', 'Location');
            jQuery('#ddlAge').attr('disabled', true).removeOption(/./).addOption('', 'Age of child');

            for (var i = 0; i < locations.length; i++) {
                var val = locations[i];
                var text = locations[i];
                jQuery('#ddlLocation').addOption(val, text, false);
            }
        }
    });

}
function getAge() {
    jQuery.ajax({
        type: "POST",
        url: "Services/ActivityFinder.asmx/GetAge",
        data: "{timeSelected: '" + jQuery("[id$='_ddlTime']").val() + "', locationSelected: '" + jQuery('#ddlLocation').val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var ages = response;
            jQuery('#ddlAge').attr('disabled', false).removeOption(/./).addOption('', 'Age of child');

            for (var i = 0; i < ages.length; i++) {
                var val = ages[i];
                var text = ages[i];
                jQuery('#ddlAge').addOption(val, text, false);
            }
        }
    });
}
function goClick() {
    var timeSel = jQuery("[id$='_ddlTime']").val();
    var locationSel = jQuery('#ddlLocation').val();
    var ageSel = jQuery('#ddlAge').val();
    if (timeSel != 'Time available' && locationSel != 'Location' && ageSel != 'Age of child' && timeSel != '' && locationSel != '' && ageSel != '') {
        var urlString = 'find-activities.aspx?time=' + timeSel + '&location=' + locationSel + '&age=' + ageSel;
        location.href = urlString;
    }
    else {
        jQuery('#errorMsg').attr('style', 'visibility:true');
    }
}
