function showRegWindow(oParams)
{
    if (!oParams) oParams = new Object();
    if (oParams.visible == undefined) oParams.visible = true;

    var wReg;

    if (wReg = document.getElementById("w-reg"))
    {
        if (!wReg.initialized)
        {
            wReg.initialized = true;
            wReg.visible = false;

            var wBackground = document.getElementById("w-reg-background");
            wBackground.style.opacity = ".8";
            wBackground.style.filter = "alpha(opacity=80)";

            if (window.addEventListener) {
                window.addEventListener("resize", resizeRegWindow, false);
            }
            else if (window.attachEvent) {
                window.attachEvent("onresize", resizeRegWindow);
            }
        }

        wReg.visible = oParams.visible;
        wReg.style.display = oParams.visible ? "block" : "none";

        resizeRegWindow();
    }
}

function resizeRegWindow(e)
{
    var wReg;

    if (wReg = document.getElementById("w-reg"))
    {
        if (wReg.visible)
        {
            wReg.style.width = String(document.documentElement.clientWidth) + "px";
            wReg.style.height = String(document.documentElement.clientHeight) + "px";
            wReg.style.top = window.pageYOffset != undefined ? String(window.pageYOffset) + "px" : document.documentElement.scrollTop + "px";
            wReg.style.left = window.pageXOffset != undefined ? String(window.pageXOffset) + "px" : document.documentElement.scrollLeft + "px";

            var wBackground = document.getElementById("w-reg-background");
            wBackground.style.width = wReg.style.width;
            wBackground.style.height = wReg.style.height;

            var wWindow = document.getElementById("w-reg-window");
            
            if (_window != undefined)
                wWindow = document.getElementById(_window);

            wWindow.style.left = String(Math.max((document.documentElement.clientWidth / 2) - (wWindow.offsetWidth / 2), 0)) + "px";
            wWindow.style.top = String(Math.max((document.documentElement.clientHeight / 2) - (wWindow.offsetHeight / 2), 0)) + "px";
        }
    }
}

var _assignedTicketURL;
var _friendlyName;
var _window = undefined;
var _performanceId;
var _id;
var _perfKey;

function displaySYOSModalById(assignedTicketLink, perfKey, ID, performanceID)
{
    _assignedTicketURL = assignedTicketLink;
    _perfKey = perfKey;
    _id = ID;
    _performanceId = performanceID;
    _window = "syos-reg-window";
    showLinkDivs(true);
    showRegWindow();
}

function loadSYOSInline(assignedTicketLink, eventId, performanceId, divName)
{
    _assignedTicketURL = assignedTicketLink;
    _id = eventId;
    _performanceId = performanceId;
    _window = "syos-reg-window";
    embedSYOSswf(divName);
}

function selectAssignedSeat()
{
    this.location.href = _assignedTicketURL;
}

function showLinkDivs(visible)
{
    var ticketSelectionsDiv = document.getElementById("ticketSelections");
    var modalWrapperDiv = document.getElementById("modalWrapper");
    var selectYourSeatContainer = document.getElementById("selectYourSeatContainer");

    if (visible == false) {
        ticketSelectionsDiv.style.display = 'none';
        selectYourSeatContainer.style.display = '';
        modalWrapperDiv.style.height = "630px";
        modalWrapperDiv.style.width = "961px";
    }
    else {
        ticketSelectionsDiv.style.display = '';
        selectYourSeatContainer.style.display = 'none';
        modalWrapperDiv.style.height = "706px";
        modalWrapperDiv.style.width = "961px";
    }
}

function selectSYOS(syosLink)
{
    this.location.href = syosLink + '?perfKey=' + _perfKey + '&perfId=' + _performanceId + '&eventId=' + _id;
}

function embedSYOSswf(divName)
{
	var configURL = "/aso/asoassets/swf/SYOS/configuration.xml?noCache=" + new Date().getTime();

    var flashVars =
        {
            eventID: _id,
            eventFriendlyName: _friendlyName,
            performanceId: _performanceId,
            configurationXMLUrl: configURL
        };

    var params =
        {
            allowfulllscreen: "true",
            allowscriptaccess: "always",
            wmode: "opaque"
        };

    swfobject.embedSWF("/aso/asoassets/swf/SYOS/SYOS.swf?noCache=" + "20101027", divName, "100%", "100%", "9", "/aso/assoassets/swf/expressInstall.swf", flashVars, params);
}

function thisMovie(movieName)
{
    return document[movieName];
}

function centerDialog()
{
    thisMovie("selectYourSeatContainer").centerDialog();
}

function externalRefreshRequested()
{
    thisMovie("selectYourSeatContainer").externalRefreshRequested();
}

function resizeSYOSContainer(data)
{
    document.getElementById("modalWrapper").style.width = data.sizeX + "px";
    document.getElementById("modalWrapper").style.height = data.sizeY + "px";
    resizeRegWindow();
    centerDialog();
}
