﻿$(document).ready(function() {
    var dropdown_data;

    var selectDateText = 'Choose Date';
    var selectRestText = 'Choose a Restaurant';
    var dropdown_xml = 'xml/dropdown_data.xml';


    $.get(dropdown_xml, function(data) {
        dropdown_data = data;
        var selDate = document.getElementById("ctl00_MainContent_hidDate");
        var dateList = $('#dates');
        $('Date', dropdown_data).each(function() {
            $('<option>').text($(this).attr('Name')).appendTo(dateList);
        });
    }, 'xml');

    $('#dates').change(function() {
        var val = $(this).val();
        var restaurantList = $('#restaurants').empty();
        var restaurantName;

        $('#restaurants').attr('disabled', true);
        if (val != '0') {
            $('#restaurants').attr('disabled', false);
        }
        $('<option>').val('0').text(selectRestText).appendTo(restaurantList);

        $('Date', dropdown_data).filter(function() {
            return val == $(this).attr('Name');
        }).find('Restaraunt').each(function() {
            $(this).find("Name").each(function() {
                restaurantName = $(this).text();
            });

            $(this).find("Name").each(function() {
                $('<option>').val(restaurantName).text(restaurantName).appendTo(restaurantList);
            });
        });
    });
});

// sets the Date and Restaurants for the HTML select statements
// from the XML
function setValues() {
        var date = $('#dates').val();
        var txtdate = document.getElementById("ctl00_MainContent_hidDate");
        txtdate.value = date;
       
        var rest = $('#restaurants').val();
        var txtrest = document.getElementById("ctl00_MainContent_hidRest");
        txtrest.value = rest;
};
