﻿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', 'display:block').attr('style', 'padding-top:3px');
        jQuery('#info').attr('style', 'display:none');
        jQuery('#errorEvents').attr('style', 'display:none');
    }
}

function goEventClick() {
   
    if ((jQuery("[id$='zipcode1']").val() != "City or postal Code") && (jQuery("[id$='_cityName']").val() != "")) {
        var date = jQuery("[id$='_eventListBox'] option:eq(0)").val();
        var cityOrPost = jQuery("[id$='zipcode1']").val();
        if (date != 'undefined' && date != null) {            
            date = date.substring(0, 10);
            location.href = 'event-calendar.aspx?startDate=' + date + '&endDate=&cityOrPost=' + cityOrPost;
        }
        else {
            location.href = 'event-calendar.aspx?startDate=&endDate=&cityOrPost=' + cityOrPost;            
        }        
    }
    else {
        jQuery('#errorEvents').attr('style', 'display:block').attr('style', 'padding-top:3px');
        jQuery('#info').attr('style', 'display:none');
        jQuery('#errorMsg').attr('style', 'display:none');
    }  
}

//Expand event details when user clicks on the list box
jQuery(document).ready(function() {
    jQuery("[id$='_eventListBox']").click(function() {        
        if (jQuery("[id$='_eventListBox']").val()) {            
            var date = jQuery("[id$='_eventListBox']").val();
            var index = parseInt(date.substring(11));
            var page = window.location.toString();
            if (page.indexOf("event-calendar.aspx") != -1) {                
                var divArray = jQuery(".popuplink");
                jQuery(divArray[index]).click();
                var displayed = jQuery(".act2morecont");
                jQuery.scrollTo(displayed[index], { speed: 2500 });
            }
        }
    });
});



function toggleCity() {
    if (document.getElementById('cityPostalcode').value == "City or postal code")
        document.getElementById('cityPostalcode').value = "";
}
function rePopulateCity() {
    if (document.getElementById('cityPostalcode').value == '')
        document.getElementById('cityPostalcode').value = "City or postal code";
}
