﻿
var _MapSwfName = "SeatingChartSwf";
var _PanelNotFound = "pnlNotFound";
var _ArrSelections = new Array();
var _MapCreated = false;
var _MapFinishedLoading = false;

function notifyExternalOnLoad(status)
{
    _MapFinishedLoading = true;
}

// The selection object
function Selection()
{
    this.ID = 0;
    this.Seats = new Array();
    this.AreaID = 0;
    this.AreaName = "";
    this.SectionID = 0;
    this.SectionName = "";
    this.BlockID = 0;
    this.RowID = 0;
    this.RowName = "";
    this.TicketsID = "";
    this.Price = 0;
    this.EventID = 0;
    this.Notes = "";
    this.SeatsDisplay = "";
    this.Number = 0;
    this.Date = "";
}
Selection.prototype.ID = 0;
Selection.prototype.Seats = new Array();
Selection.prototype.AreaID = 0;
Selection.prototype.AreaName = 0;
Selection.prototype.SectionID = 0;
Selection.prototype.SectionName = "";
Selection.prototype.BlockID = 0;
Selection.prototype.RowID = 0;
Selection.prototype.RowName = "";
Selection.prototype.TicketsID = "";
Selection.prototype.Price = 0;
Selection.prototype.EventID = 0;
Selection.prototype.Notes = "";
Selection.prototype.SeatsDisplay = "";
Selection.prototype.Number = 0;
Selection.prototype.Date = "";

var strTicketAgentName;

// Locate the seats
function LocateSeats(chart, version)
{
	try
	{
        var theForm = document.forms[0];
        
        var area = theForm.selAreas.options[theForm.selAreas.selectedIndex].value;
        var row = theForm.txtRow.value;
        var lowSeat = theForm.txtLowSeat.value;
        var highSeat = theForm.txtHighSeat.value;

        if (!_MapFinishedLoading &&
            (row == "" && lowSeat == "" && area == "")
            )
        {
            alert("1. Get your tickets on " + strTicketAgentName + " window on the right hand side.\n2. Enter the section, row and seat numbers.\n3. Press 'Locate'.");
            return;
        }
        else if (row == "")
        {
            alert("Please enter the row");
            theForm.txtRow.focus();
            return;
        }
        else if (lowSeat == "")
        {
            alert("Please enter the seats");
            theForm.txtLowSeat.focus();
            return;
        }
        else if (area == "")
        {
            alert("Please choose the section");
            theForm.selAreas.focus();
            return;
        }
        
        if (!_MapCreated)
        {
            try
            {
                HideStepArrows();
            }
            catch(e)
            {
            }
            
            CreateMap();
        }

        try
        {
            DisplayElement("pnlMap", true);
            DisplayElement("pnlMapImage", false);
        }
        catch(e)
        {
        }

        FindSeats(chart, version, area, row, lowSeat, highSeat);
    }
    catch (e)
    {
        alert(e)
    }
    
    //return false;
}


function FindSeats(chart, version, area, row, lowSeat, highSeat)
{
    if (!_MapFinishedLoading) 
    {  
        window.setTimeout("FindSeats('" + chart + "','" + version + "','" + area + "','" + row + "','" + lowSeat + "','" + highSeat + "')",1000); 
        return;
    }
    
    BroadwayBox.WebServices.ChartService.FindSeats(chart, version, area, row, lowSeat, highSeat, FindSeatsCompleted);
}

function FindSeatsCompleted(results)
{
    //alert(results);
    if (typeof(results) != 'undefined')
    {
        try
        {
            try
            {
                ViewFullSize();
            }
            catch(e)
            {
            }

            if (results[0] == 0)
            {
                try
                {
                    DisplayNotFound();
                }
                catch(e)
                {
                }
            }
            else
            {
                try
                {
                    HideNotFound();
                }
                catch(e)
                {
                }
                
                var seatsArray = results[1].split(":");
                
                var seatData = seatsArray[0].split("-");
                
                var seatID = seatData[0];
                var rowID = seatData[1];
                var blockID = seatData[2];
                var sectionID = seatData[3];
                var areaID = seatData[4];
                
                var arrSeats = new Array();
                var strSeats = "";
                for (var i = 0 ; i < seatsArray.length ; i++)
                {
                    seatData = seatsArray[i].split("-");
                    if (seatData[0])
                    {
                        arrSeats.push(seatData[0]);
                    }
                }
                var oSelect = new Selection();
                oSelect.RowID = rowID;
                oSelect.BlockID = blockID;
                oSelect.SectionID = sectionID;
                oSelect.AreaID = areaID;
                oSelect.Seats = new Array(seatID.toString());
                oSelect.Number = _ArrSelections.length + 1;
                oSelect.Seats = arrSeats;
                
                _ArrSelections.push(oSelect);
                
                ShowSelection(oSelect);
                
                GetMovie(_MapSwfName).PlaySound();

//                for (var i = 0 ; i < seatsArray.length ; i++)
//                {
//                    var seatData = seatsArray[i].split("-");
//                    
//                    var seatID = seatData[0];
//                    var rowID = seatData[1];
//                    var blockID = seatData[2];
//                    var sectionID = seatData[3];
//                    var areaID = seatData[4];
//                    
//                    if (areaID != "" && sectionID != "" && blockID != "" && rowID != "" && seatID != "")
//                    {
//                        var oSelect = new Selection();
//                        oSelect.RowID = rowID;
//                        oSelect.BlockID = blockID;
//                        oSelect.SectionID = sectionID;
//                        oSelect.AreaID = areaID;
//                        oSelect.Seats = new Array(seatID.toString());
//                        oSelect.Number = _ArrSelections.length + 1;
//                        
//                        _ArrSelections.push(oSelect);
//                        
//                        ShowSelection(oSelect);
//                    }
//                }
            }
        }
        catch(e)
        {
            alert(e)
        }
    }
    
    try
    {
        AlignStepArrows();
    }
    catch(e)
    {
    }
}

function ShowSelection(oSelect)
{
    var arrSeats = oSelect.Seats;
    var strSeats = "";
    for (var i=0 ; i<arrSeats.length ; i++)
    {
        if (arrSeats[i])
        {
            strSeats += ":" + arrSeats[i].toString();
        }
    }
    strSeats = strSeats.substring(1,strSeats.length);

    GetMovie(_MapSwfName).AddSelection(oSelect.Number,
                                        "",
                                        "",
                                        "",
                                        "",
                                        oSelect.AreaID,
                                        oSelect.SectionID,
                                        oSelect.BlockID,
                                        oSelect.RowID,
                                        strSeats);
}

function DisplayNotFound()
{
    document.getElementById(_PanelNotFound).style.display = "block";
}

function HideNotFound()
{
    document.getElementById(_PanelNotFound).style.display = "none";
}

function ViewFullSize()
{
    var size = 600;
    SetSwfSize(_MapSwfName, size, size);
    document.getElementById("pnlZoomIn").style.display = "none";
    document.getElementById("pnlZoomOut").style.display = "block";
    self.resizeTo(size+56,1100);
    AlignStepArrows();
 }

function ViewSmallSize()
{
    var size = 300;
    SetSwfSize(_MapSwfName, size, size);
    document.getElementById("pnlZoomOut").style.display = "none";
    document.getElementById("pnlZoomIn").style.display = "block";
    self.resizeTo(size+56,1100);
    AlignStepArrows();
}
