﻿/* ------------------------------------------------------------------------------------------------
Global
------------------------------------------------------------------------------------------------ */
$(function () {
    $("#changeOrder").change(function () {
        var url = $("#changeOrder").attr("title")
        var order = $("#changeOrder > option:selected").attr("value")

        if (order != "")
            window.location.href = url + "?order=" + order;
        else
            window.location.href = url;
    });
});

$(function () {
    $("#jumpToPage").change(function () {
        var url = $("#jumpToPage > option:selected").attr("value");

        if (url != -1)
            window.location.href = url;
    });
});

function setDropDown(dropdown, value) {
    $(dropdown).val(value);
}

function onBegin(message) {
    $("#loading").html('<p>' + message + '</p><p><img alt="" src="/content/images/layout/loading.gif" /></p>');
    $("#loading").dialog("open");
}

function onSuccess() {
    $("#loading").dialog("close");
    $("#loading").html("");
}

function onComplete(content) {
    if (content.Success == "true") {
        window.location.href = content.RedirectUrl;
    }
    else {
        $("#loading").dialog("close");
        $("#loading").html("");
        alert(content.Message);
    }
}

/* ------------------------------------------------------------------------------------------------
Shows - SideJumpToShow.cshtml
------------------------------------------------------------------------------------------------ */
$(function () {
    $("#jumpToShow").change(function () {
        var url = $("#jumpToShow > option:selected").attr("value");

        if (url != -1)
            window.location.href = url;
    });
});

/* ------------------------------------------------------------------------------------------------
Shows - FindTheatreTickets.cshtml
Shared - SideFindTheatreTickets.cshtml
------------------------------------------------------------------------------------------------ */
$(function () {
    $("#show").change(function () {
        $.getJSON("/Shows/GetAvailableDates?Id=" + $("#show > option:selected").attr("value"), function (data) {
            var items = "<option value='-1'>Select a date</option>";

            $.each(data, function (key, value) {
                items += "<option value='" + key + "'>" + value + "</option>";
            });

            $("#date").html(items);

            var Id = $("#show > option:selected").attr("value");
            var slug = $("#show > option:selected").attr("title")
            var action = "/" + Id + "/" + slug + "/find-tickets.html";

            $("#findTheatreTickets").attr("action", action);
        });
    });
});

$(function () {
    $("#findTheatreTickets").submit(function () {
        if ($("#show").val() == "-1") {
            alert("Please select a show")
            return false;
        }

        if ($("#date").val() == "-1") {
            alert("Please select a date")
            return false;
        }

        if ($("#qty").val() == "-1") {
            alert("Please select the no of tickets")
            return false;
        }

        return true;
    });
});

/* ------------------------------------------------------------------------------------------------
Shared - CheckTicketAvailability.cshtml
------------------------------------------------------------------------------------------------ */
$(function () {
    $("#checkTicketAvailability").submit(function () {
        if ($("#date2").val() == "-1") {
            alert("Please select a date")
            return false;
        }

        if ($("#date2").val() == "-1") {
            alert("Please select a date")
            return false;
        }

        if ($("#qty2").val() == "-1") {
            alert("Please select the no of tickets")
            return false;
        }

        return true;
    });
});

/* ------------------------------------------------------------------------------------------------
Venues - Index.cshtml
------------------------------------------------------------------------------------------------ */
function loadVenueMap(latitude, longitude, zoom) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2($("#map")[0]);
        var latlng = new google.maps.LatLng(latitude, longitude);
        var marker = new google.maps.Marker(latlng);

        map.removeControl(new GMapTypeControl());
        map.addControl(new GSmallZoomControl3D());
        map.setCenter(latlng, zoom);
        map.addOverlay(marker);
    }
}
