var objBody = document.getElementsByTagName("body").item(0);
subHidePointer();
var intSynopsisLength = 230;
var intClientX;
var intClientY;
var strSelectedVenueCode = strGetQueryVariable("cid");
var strSelectedSession = strGetQueryVariable("sid");
var strSelectedSubRegionCode = strGetQueryVariable("srid");
var strSelectedEventCode = strGetQueryVariable("eid");
var strSelectedDateCode = strGetQueryVariable("did");
var strSelectedShowTime = "";
var curTotal = 0;
var curDisplayTotal = 0;
var arrShowTimes = new Array();
var arrShowInfo = new Array();
var arrEventInfo = new Array();
var arrVenueInfo = new Array();
var arrShowPrices;
var arrTotal = new Array();
arrTotal[0] = 0;
arrTotal[1] = 0;
arrTotal[2] = 0;
arrTotal[3] = 0;
arrTotal[4] = 0;
var arrTimeRange = new Array();
arrTimeRange[0] = new Array(0, 1200, 'Y');
arrTimeRange[1] = new Array(1200, 1700, 'Y');
arrTimeRange[2] = new Array(1700, 2100, 'Y');
arrTimeRange[3] = new Array(2100, 2400, 'Y');
var arrPriceRange = new Array();
arrPriceRange[0] = new Array(0, 99, 'Y');
arrPriceRange[1] = new Array(100, 250, 'Y');
arrPriceRange[2] = new Array(251, 2000, 'Y');
var intVenueCounter = -1;
var intScheduleCounter = -1;
var strEventType = strGetQueryVariable("strEventType") != "" ? strGetQueryVariable("strEventType") : "MT";
var intSelectedPrice = 0;
var intFromTime = 0;
var intToTime = 2400;
var curMinPrice = 0;
var curMaxPrice = 2000;
var blnDisplaySchedule = true;
var blnTimeCheck = false;
var blnPriceCheck = false;
var blnFetchHomeDataOnly = false;
var strApplyOffer = strGetQueryVariable("strOffer");
var blnShowSeatLayout = true;
var intScrollDown = 0;
var intScrollTop = 0;
var blnSessionClosed = true;
subFillHeader();
subFillFooter();
var intsecScheduleHeight = 0;
var tktQty = 0;
subOnWindowScroll();
subSelectTabs(strEventType);

function subOnWindowScroll()
{
    window.onscroll = function() { subSlideOrderSummary(); }
}

function subSlideOrderSummary()
{
    var objsecSchedule = document.getElementById("secSchedule");
    if(objsecSchedule)
    {
        var objsecSummary = document.getElementById("tblSummary");
        var objtdPointer = document.getElementById("tdPointer");
        var intsecSummaryHeight = objsecSummary.clientHeight;
        if(intsecScheduleHeight == 0)
        {
            intsecScheduleHeight = objsecSchedule.clientHeight;
        }
        
        if(intsecSummaryHeight == 0)
        {
            intsecSummaryHeight = objsecSummary.childNodes[1].clientHeight;
        }
        var objtrSummarySpacer = document.getElementById("trSummarySpacer");
        var intScroll = 0;
        if(document.body.scrollTop > 0)
        {
            intScroll = document.body.scrollTop;
        }
        else
        {
            intScroll = document.documentElement.scrollTop;
        }
        
        if(intsecSummaryHeight + intScroll < intsecScheduleHeight)
        {
            objtrSummarySpacer.style.height = intScroll + "px";
            objtdPointer.style.paddingTop = 70 + intScroll + "px";
        }
    }
}

function subSetTimeRange(objCheckBox, intPosition)
{
    try
    {
        var strSubRegionCode = strSelectedSubRegionCode;
        var strEventCode = strSelectedEventCode;
        var strVenueCode = strSelectedVenueCode;
        var strShowDate = strSelectedDateCode;
        var strSearchCriteria = strGetCookie("strSearchCriteria", "");
        var strChecked = objCheckBox.checked == true ? "Y" : "N";
        blnTimeCheck = false;
        var strEval = "arrTimeRange[" + intPosition + "][2] = '" + strChecked + "';";

        eval(strEval);
        
        for(var intCount = 0; intCount <=3; intCount++)
        {
            if(arrTimeRange[intCount][2] == "Y")
            {
                blnTimeCheck = true;
                break;
            }
        }
        
        subCreateDisplaySchedule(strSubRegionCode, strVenueCode, strEventCode, strShowDate, strSearchCriteria);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subSetTimeRange()", e);
    }
}

function blnCheckTimeRange(intTime)
{
    try
    {
        if(blnTimeCheck == false)
        {
            return true;
        }
        for(var intCount = 0; intCount <=3; intCount++)
        {
            if(arrTimeRange[intCount][2] == "Y")
            {
                if((parseInt(intTime) >= arrTimeRange[intCount][0]) && (parseInt(intTime) <= arrTimeRange[intCount][1]))
                {
                    return true;
                }
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "blnCheckTimeRange(" + intTime + ")", e);
    }
    return false;
}

function subSetPriceRange(objCheckBox, intPosition)
{ 
    try
    {
        var strSubRegionCode = strSelectedSubRegionCode;
        var strEventCode = strSelectedEventCode;
        var strVenueCode = strSelectedVenueCode;
        var strShowDate = strSelectedDateCode;
        var strSearchCriteria = strGetCookie("strSearchCriteria", "");
        var strChecked = objCheckBox.checked == true ? "Y" : "N";
        blnPriceCheck = false;
        
        var strEval = "arrPriceRange[" + intPosition + "][2] = '" + strChecked + "';";

        eval(strEval);
        
        
        
        for(var intCount = 0; intCount <=2; intCount++)
        {
            if(arrPriceRange[intCount][2] == "Y")
            {
                blnPriceCheck = true;
                break;
            }
        }
        
        subCreateDisplaySchedule(strSubRegionCode, strVenueCode, strEventCode, strShowDate, strSearchCriteria);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "blnCheckTimeRange(" + intTime + ")", e);
    }
}

function blnCheckPriceRange(curMinPrice, curMaxPrice)
{
    try
    {
        if(blnPriceCheck == false)
        {
            return true;
        }
        for(var intCount = 0; intCount <=2; intCount++)
        {
            if(arrPriceRange[intCount][2] == "Y")
            {
                if((parseFloat(curMinPrice) >= arrPriceRange[intCount][0]) && (parseFloat(curMinPrice) <= arrPriceRange[intCount][1]))
                {
                    return true;
                }
                else if((parseFloat(curMaxPrice) >= arrPriceRange[intCount][0]) && (parseFloat(curMaxPrice) <= arrPriceRange[intCount][1]))
                {
                    return true;
                }
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "blnCheckTimeRange(" + intTime + ")", e);
    }
    return false;
}

function subStartScheduleDisplay()
{
    try
    {
        switch(strGetCookie("strSearchCriteria", ""))
        {
            case "EVENT":
                subFetchVenues(strSelectedSubRegionCode);
                break;
            case "VENUE":
                subFetchEvents(strEventType);
                break;
            default:
                break;
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subStartScheduleDisplay()", e);
    }
}

function subFillDisplayHeaders()
{   
    try
    {
        var objtblSummary = document.getElementById("tblSummary");
        var objTDTitle = document.getElementById("tdTitle");
        var objTDLocation = document.getElementById("tdLocation");
        var objTDShowDate = document.getElementById("tdShowDate");
        var objTDSummaryLocation = document.getElementById("spnSummaryLocation");
        var objTDSummaryShowDate = document.getElementById("spnSummaryDate");
        var objtdSummaryImage = document.getElementById("tdSummaryImage");
        var objtdInfo = document.getElementById("tdInfo");
        objtblSummary.style.display = "inline";
        objtdSummaryImage.innerHTML = "";
        
        if(strGetCookie("strSearchCriteria", "") == "EVENT")
        {
            objTDTitle.innerHTML = arrEventInfo[0][3];
            objtdSummaryImage.appendChild(objCreateMovieImage(arrEventInfo[0][5], arrEventInfo[0][5], true));
            objtdInfo.innerHTML = "<span class=\"cssFontB\">" + arrEventInfo[0][3] + "</span><br/>" + arrEventInfo[0][6].substring(0, intSynopsisLength) + "...";
        }
        else if(strGetCookie("strSearchCriteria", "") == "VENUE")
        {
            objTDTitle.innerHTML = arrVenueInfo[0][1];
            objtdSummaryImage.appendChild(objCreateVenueImage(arrVenueInfo[0][3]));
            objtdInfo.innerHTML = "";
        }
        objTDLocation.innerHTML = strGetCookie("srn", "");
        objTDSummaryLocation.innerHTML = strGetCookie("srn", "");
        if(strGetCookie("strDisplayDate", "") == "")
        {
            blnSetCookie("strDisplayDate", unescape(strGetQueryVariable("strDate")), false);
        }
        objTDShowDate.innerHTML = strGetCookie("strDisplayDate", "");
        objTDSummaryShowDate.innerHTML = strGetCookie("strDisplayDate", "");
        intsecScheduleHeight = 0;       
        var objtdPointer = document.getElementById("tdPointer");
        var objtrSummarySpacer = document.getElementById("trSummarySpacer");
        objtrSummarySpacer.style.height = "1px";
        objtdPointer.style.paddingTop = "70px";
        
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFillDisplayHeaders()", e);
    }
}

function subFetchVenues(strSubRegionCode)
{
    try
    {
        var strEventCode = strSelectedEventCode;
        var strVenueCode = strSelectedVenueCode;
        var strShowDate = strSelectedDateCode;
        var strSearchCriteria = strGetCookie("strSearchCriteria", "");
        subGetDataAndExecute("VENUES_" + strEventType + "_" + strSubRegionCode, strIBURL + "Data/GetVenues_" + strEventType + "_" + strSubRegionCode + ".js?" + strTimeStamp(), "subFetchShowTimes('" + strSubRegionCode + "', '" + strVenueCode + "', '" + strEventCode + "', '" + strShowDate + "', '" + strSearchCriteria + "');", false);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFetchVenues('" + strSubRegionCode + "')", e);
    }
}

function subFetchEvents(strGetEventType)
{
    try
    {
        var strSubRegionCode = strSelectedSubRegionCode;
        var strEventCode = strSelectedEventCode;
        var strVenueCode = strSelectedVenueCode;
        var strShowDate = strSelectedDateCode;
        var strSearchCriteria = strGetCookie("strSearchCriteria", "");
        subGetDataAndExecute("EVENTS_" + strGetEventType, strIBURL + "Data/GetEvents_" + strGetEventType + ".js?" + strTimeStamp(), "subFetchShowTimes('" + strSubRegionCode + "', '" + strVenueCode + "', '" + strEventCode + "', '" + strShowDate + "', '" + strSearchCriteria + "');", false);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFetchEvents('" + strGetEventType + "')", e);
    }
}

function subFetchShowTimes(strSubRegionCode,strVenueCode, strEventCode, strShowDate, strSearchCriteria)
{
    try
    {
        arrShowTimes = new Array();
        switch(strSearchCriteria)
        {
            case "VENUE":
                subGetDataAndExecute("SHOWTIMES", strIBURL + "Data/GetShowTimesByVenue_" + strVenueCode + "_" + strShowDate + ".js?" + strTimeStamp(), "subCreateDisplaySchedule('" + strSubRegionCode + "', '" + strVenueCode + "', '" + strEventCode + "','" + strShowDate + "', '" + strSearchCriteria + "');", true);
                break;
            case "EVENT":
                subGetDataAndExecute("SHOWTIMES", strIBURL + "Data/GetShowTimesByEvent_" + strEventCode + "_" + strSubRegionCode + "_" + strShowDate + ".js?" + strTimeStamp(), "subCreateDisplaySchedule('" + strSubRegionCode + "', '" + strVenueCode + "', '" + strEventCode + "','" + strShowDate + "', '" + strSearchCriteria + "');", true);
                break;
            default :
                break;
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFetchShowTimes('" + strSubRegionCode + "', '" + strVenueCode + "', '" + strEventCode + "', '" + strShowDate + "', '" + strSearchCriteria + "')", e);
    }
}

function subFetchEventInfo(strEventCode)
{
    try
    {
        arrEventInfo = new Array();
        subGetDataAndExecute("EVENTINFO", strDataURL + "strCommand=GETEVENTINFO&strEventCode=" + strEventCode, "subFillDisplayHeaders();", true);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFetchEventInfo('" + strEventCode + "')", e);
    }
}

function subFetchVenueInfo(strVenueCode)
{
    try
    {
        arrVenueInfo = new Array();
        subGetDataAndExecute("VENUEINFO", strDataURL + "strCommand=GETVENUEINFO&strVenueCode=" + strVenueCode, "subFillDisplayHeaders();", true);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFetchVenueInfo('" + strVenueCode + "')", e);
    }
}

function subCreateDisplaySchedule(strSubRegionCode,strVenueCode, strEventCode, strShowDate, strSearchCriteria)
{
    subHideCallOut("tblClass");
    var intShowsPerLine = 6;
    var objTable = document.createElement("table");
    var objTBody = document.createElement("tbody");
    var blnAddTrName = true;
    var objTRSeparator;
    
    objTable.style.width = "100%";
    objTable.setAttribute("cellPadding","2");
    objTable.setAttribute("cellSpacing","0");
    objTable.setAttribute("border","0");
    objTable.className = "cssScheduleTable";

    try 
    {
        if(strSearchCriteria == "EVENT")
        {
            var strPrevVenueCode = "";
            var strPrevVenueName = "";
            for(var intCount = 0; intCount < arrShowTimes.length; intCount++)
            {
                if(arrShowTimes[intCount][1] == strSubRegionCode && arrShowTimes[intCount][2] == strEventCode && arrShowTimes[intCount][3] == strShowDate)
                {
                    if(strPrevVenueCode != arrShowTimes[intCount][0])
                    {
                        if(strPrevVenueCode != "")
                        {
                            blnAddTrName = true;
                        }
                        
                        objTRSeparator = document.createElement("tr");
                        var objTDSeparator = document.createElement("td");
                        var objImgSeparator = document.createElement("img");
                        objImgSeparator.src = strImageUrl + "page2_r23_c4.gif";
                        objImgSeparator.style.width = "500px";
                        objTDSeparator.style.height = "5px";
                        objTDSeparator.colSpan = "20";
                        objTDSeparator.style.textAlign = "left";
                        objTDSeparator.style.backgroundImage = "url('Common/Images/dotted_line.gif')";
                        objTDSeparator.style.backgroundRepeat = "repeat-x";
                        objTDSeparator.style.backgroundPosition = "center";
                        objTDSeparator.style.height = "12px";
                        objTRSeparator.appendChild(objTDSeparator);

                        var objTRName = document.createElement("tr");
                        var objTD = document.createElement("td");
                        objTD.style.textAlign = "left";
                        objTD.colSpan = "20";
                        strPrevVenueName = strGetVenueName(arrShowTimes[intCount][0], 0);
                        strPrevVenueCode = arrShowTimes[intCount][0];
                        var intRowSpan = Math.ceil(intGetRowSpanByVenue(strPrevVenueCode) / intShowsPerLine);
                        var intTotalShows = Math.ceil(arrShowTimes.length / intShowsPerLine) * intShowsPerLine;
                        
                        objTD.innerHTML = strPrevVenueName;
                        objTD.className = "cssScheduleHeader";
                        objTRName.appendChild(objTD);
                        
                        var objTR = document.createElement("tr");
                        var objTD = document.createElement("td");
                        objTR.style.height = "20px";
                        objTD.innerHTML = "Choose Show:";
                        objTD.className = "cssFontB";
                        objTD.style.verticalAlign = "top";
                        objTD.rowSpan = intRowSpan;
                        objTD.style.width = "20%";
                        objTD.style.textAlign = "left";
                        objTR.appendChild(objTD);
                        
                        for(var intShowCount = 0; intShowCount <= intTotalShows; intShowCount++)
                        {                        
                            var intTDWidth = (80/intShowsPerLine);
                            var objTD = document.createElement("td");
                            
                            objTD.style.backgroundColor = "#FFFFFF";
                            objTD.style.width = "60px";
                            objTD.style.textAlign = "center";
                            if(intShowCount < arrShowTimes.length)
                            {
                                if(arrShowTimes[intShowCount][0] == strPrevVenueCode && arrShowTimes[intShowCount][1] == strSubRegionCode && arrShowTimes[intShowCount][2] == strEventCode && arrShowTimes[intShowCount][3] == strShowDate)
                                {
                                    var strInnerHTML = "";
                                    if(blnCheckPriceRange(arrShowTimes[intShowCount][9], arrShowTimes[intShowCount][10]) == false)
                                    {
                                        continue;
                                    }
                                    
                                    if(blnCheckTimeRange(arrShowTimes[intShowCount][5]) == false)
                                    {
                                        continue;
                                    }
                                    if(arrShowTimes[intShowCount][7] == 'Y')
                                    {
                                        if(arrShowTimes[intShowCount][8] == 'Y')
                                        {
                                            strInnerHTML = "<a class=\"cssScheduleShow\" onmouseover=\"javascript:subSetCursor(this, 'hand'); this.className='cssScheduleHrefEx' \" onmouseout=\"javascript:this.className='cssScheduleShow'\" onclick=\"javascript:subSelectShow(event, '" + arrShowTimes[intShowCount][0] + "', '" + arrShowTimes[intShowCount][4] + "', '" + arrShowTimes[intShowCount][2] + "', '" + arrShowTimes[intShowCount][6] + "');\">" + arrShowTimes[intShowCount][6] + "</a>";
                                        }
                                        else
                                        {
                                            strInnerHTML = "<a class=\"cssScheduleShow\" onmouseover=\"javascript:subSetCursor(this, 'hand');\" onclick=\"javascript://;\">" + arrShowTimes[intShowCount][6] + "</a>";
                                            
                                        }
                                    }
                                    else
                                    {
                                        strInnerHTML = "<a class=\"cssScheduleHrefRed\" onmouseover=\"javascript:subSetCursor(this, 'hand');\" onclick=\"javascript://;\">" + arrShowTimes[intShowCount][6] + "</a>";
                                    }
                                    
                                    objTD.innerHTML = strInnerHTML + "<span class=\"cssScheduleSpan\">&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
                                    
                                    
                                    objTR.appendChild(objTD);
                                    
                                }
                            }
                            else
                            {
                                objTD.innerHTML = "";
    
                            }
                            
                            
                            
                            if(objTR.childNodes.length == intShowsPerLine && objTR.firstChild.innerHTML != "Choose Show:")
                            {
                                if(blnAddTrName == true)
                                {
                                    objTBody.appendChild(objTRName);                                    
                                }
                                blnAddTrName = false;
                                objTBody.appendChild(objTR);
                                if(objTRSeparator != undefined)
                                {
                                    objTBody.appendChild(objTRSeparator);                                    
                                }
                                var objTR = document.createElement("tr");
                            }
                            if(objTR.childNodes.length == intShowsPerLine + 1 && objTR.firstChild.innerHTML == "Choose Show:")
                            {
                                if(blnAddTrName == true)
                                {
                                    objTBody.appendChild(objTRName);
                                }
                                blnAddTrName = false;
                                objTBody.appendChild(objTR);
                                if(objTRSeparator != undefined)
                                {
                                    objTBody.appendChild(objTRSeparator);                                    
                                }
                                var objTR = document.createElement("tr");
                            }
                        }
                    }
                              
                    if(objTR != undefined && objTR.childNodes.length > 1)  
                    {
                        if(objTR.firstChild.innerHTML == "Choose Show:")
                        {
                            for(var intCounter = objTR.childNodes.length;intCounter < intShowsPerLine + 1;intCounter++)
                            {
                                var intTDWidth = (80/intShowsPerLine);
                                var objTD = document.createElement("td");
                            
                                objTD.style.backgroundColor = "#FFFFFF";
                                objTD.style.width = "60px";
                                objTD.innerHTML = "";
                                objTR.appendChild(objTD);
                            }
                            
                            if(blnAddTrName == true)
                            {
                                objTBody.appendChild(objTRName);
                            }
                            blnAddTrName = false;
                            objTBody.appendChild(objTR);
                            if(objTRSeparator != undefined)
                            {
                                objTBody.appendChild(objTRSeparator);                                    
                            }
                            var objTR = document.createElement("tr");
                        }
                    }
                    
                    if(objTR != undefined && objTR.childNodes.length > 0)  
                    {
                        if(objTR.firstChild.innerHTML != "Choose Show:")
                        {
                            for(var intCounter = objTR.childNodes.length;intCounter < intShowsPerLine;intCounter++)
                            {
                                var intTDWidth = (80/intShowsPerLine);
                                var objTD = document.createElement("td");
                            
                                objTD.style.backgroundColor = "#FFFFFF";
                                objTD.style.width = "60px";
                                objTD.innerHTML = "";
                                objTR.appendChild(objTD);
                            }
                            if(blnAddTrName == true)
                            {
                                objTBody.appendChild(objTRName);
                            }
                            blnAddTrName = false;
                            objTBody.appendChild(objTR);
                            if(objTRSeparator != undefined)
                            {
                                objTBody.appendChild(objTRSeparator);                                    
                            }
                            var objTR = document.createElement("tr");
                        }
                    }
                }
            }
            
            objTable.appendChild(objTBody);
            var objsecSchedule = document.getElementById("secSchedule");
            objsecSchedule.innerHTML = "";
            objsecSchedule.appendChild(objTable);
            
            if(objTBody.childNodes.length == 0)
            {
                objsecSchedule.innerHTML = "Sorry!!! No results for the selected filters";
            }
            else
            {
                subFetchEventInfo(strEventCode);
            }
        }
        else if(strSearchCriteria == "VENUE")
        {
            var strPrevEventCode = "";
            var strPrevEventName = "";
            for(var intCount = 0; intCount < arrShowTimes.length; intCount++)
            {
                if(arrShowTimes[intCount][1] == strSubRegionCode && arrShowTimes[intCount][0] == strVenueCode && arrShowTimes[intCount][3] == strShowDate)
                {
                    if(strPrevEventCode != arrShowTimes[intCount][2] && blnIsEventInCategory(arrShowTimes[intCount][2], strEventType))
                    {

                            var objTRSeparator = document.createElement("tr");
                            var objTDSeparator = document.createElement("td");
                            var objImgSeparator = document.createElement("img");
                            objTDSeparator.style.height = "5px";
                            objTDSeparator.colSpan = "20";
                            objTDSeparator.style.textAlign = "left";
                            objTDSeparator.style.backgroundImage = "url('Common/Images/dotted_line.gif')";
                            objTDSeparator.style.backgroundRepeat = "repeat-x";
                            objTDSeparator.style.height = "15px";
                            objTRSeparator.appendChild(objTDSeparator);
                        
                        
                        blnAddTrName = true;
                        var objTRName = document.createElement("tr");
                        var objTD = document.createElement("td");
                        objTD.colSpan = "20";
                        objTD.style.textAlign = "left";
                        strPrevEventName = strGetEventName(arrShowTimes[intCount][2], 0);
                        strPrevEventCode = arrShowTimes[intCount][2];
                        var intRowSpan = Math.ceil(intGetRowSpanByEvent(strPrevEventCode) / intShowsPerLine);
                        var intTotalShows = Math.ceil(arrShowTimes.length / intShowsPerLine) * intShowsPerLine;
                        
                        objTD.innerHTML = strPrevEventName;
                        objTD.className = "cssScheduleHeader";
                        objTRName.appendChild(objTD);
                        
                        var objTR = document.createElement("tr");
                        var objTD = document.createElement("td");
                        objTR.style.height = "20px";
                        objTD.innerHTML = "Choose Show:";
                        objTD.className = "cssFontB";
                        objTD.style.verticalAlign = "top";
                        objTD.style.width = "20%";
                        objTD.rowSpan = intRowSpan;
                        objTD.style.textAlign = "left";
                        objTR.appendChild(objTD);
                        
                        for(var intShowCount = 0; intShowCount <= intTotalShows; intShowCount++)
                        {                        
                            var intTDWidth = (100/intShowsPerLine);
                            var objTD = document.createElement("td");
                            
                            objTD.style.backgroundColor = "#FFFFFF";
                            objTD.style.width = "60px";
                            objTD.style.textAlign = "center";
                            if(intShowCount < arrShowTimes.length)
                            {
                                if(arrShowTimes[intShowCount][2] == strPrevEventCode && arrShowTimes[intShowCount][1] == strSubRegionCode && arrShowTimes[intShowCount][0] == strVenueCode && arrShowTimes[intShowCount][3] == strShowDate)
                                {
                                    var strInnerHTML = "";
                                                                        
                                    if(blnCheckPriceRange(arrShowTimes[intShowCount][9], arrShowTimes[intShowCount][10]) == false)
                                    {
                                        continue;
                                    }
                                    
                                    if(blnCheckTimeRange(arrShowTimes[intShowCount][5]) == false)
                                    {
                                        continue;
                                    }
                                    
                                    if(arrShowTimes[intShowCount][7] == 'Y')
                                    {
                                        if(arrShowTimes[intShowCount][8] == 'Y')
                                        {
                                            strInnerHTML = "<a class=\"cssScheduleShow\" onmouseover=\"javascript:subSetCursor(this, 'hand'); this.className='cssScheduleHrefEx' \" onmouseout=\"javascript:this.className='cssScheduleShow'\" onclick=\"javascript:subSelectShow(event, '" + arrShowTimes[intShowCount][0] + "', '" + arrShowTimes[intShowCount][4] + "', '" + arrShowTimes[intShowCount][2] + "', '" + arrShowTimes[intShowCount][6] + "');\">" + arrShowTimes[intShowCount][6] + "</a>";
                                        }
                                        else
                                        {
                                            strInnerHTML = "<a class=\"cssScheduleShow\" onmouseover=\"javascript:subSetCursor(this, 'hand');\" onclick=\"javascript://;\">" + arrShowTimes[intShowCount][6] + "</a>";
                                            
                                        }
                                    }
                                    else
                                    {
                                        strInnerHTML = "<a class=\"cssScheduleHrefRed\" onmouseover=\"javascript:subSetCursor(this, 'hand');\" onclick=\"javascript://;\">" + arrShowTimes[intShowCount][6] + "</a>";
                                    }
                                    objTD.innerHTML = strInnerHTML + "<span class=\"cssScheduleSpan\">&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
                                    
                                    objTR.appendChild(objTD);
                                }
                            }
                            else
                            {
                                objTD.innerHTML = "";
                            }
                            if(objTR.childNodes.length == intShowsPerLine && objTR.firstChild.innerHTML != "Choose Show:")
                            {                                
                                if(blnAddTrName == true)
                                {
                                    objTBody.appendChild(objTRName);
                                    
                                }
                                blnAddTrName = false;
                                objTBody.appendChild(objTR);
                                if(objTRSeparator != undefined)
                                {
                                    objTBody.appendChild(objTRSeparator);                                    
                                }
                                var objTR = document.createElement("tr");
                            }
                            if(objTR.childNodes.length == intShowsPerLine + 1 && objTR.firstChild.innerHTML == "Choose Show:")
                            {
                                if(blnAddTrName == true)
                                {
                                    objTBody.appendChild(objTRName);
                                    
                                }
                                blnAddTrName = false;
                                objTBody.appendChild(objTR);
                                if(objTRSeparator != undefined)
                                {
                                    objTBody.appendChild(objTRSeparator);                                    
                                }
                                var objTR = document.createElement("tr");
                            }
                        }
                    }
                    
                    if(objTR != undefined && objTR.childNodes.length > 1)  
                    {
                        if(objTR.firstChild.innerHTML == "Choose Show:")
                        {
                            for(var intCounter = objTR.childNodes.length;intCounter < intShowsPerLine + 1;intCounter++)
                            {
                                var intTDWidth = (80/intShowsPerLine);
                                var objTD = document.createElement("td");
                            
                                objTD.style.backgroundColor = "#FFFFFF";
                                objTD.style.width = "60px";
                                objTD.innerHTML = "";
                                objTR.appendChild(objTD);
                            }
                            
                            if(blnAddTrName == true)
                            {
                                objTBody.appendChild(objTRName);
                            }
                            blnAddTrName = false;
                            objTBody.appendChild(objTR);
                            if(objTRSeparator != undefined)
                            {
                                objTBody.appendChild(objTRSeparator);                                    
                            }
                            var objTR = document.createElement("tr");
                        }
                    }
                    
                    if(objTR != undefined && objTR.childNodes.length > 0)  
                    {
                        if(objTR.firstChild.innerHTML != "Choose Show:")
                        {
                            for(var intCounter = objTR.childNodes.length;intCounter < intShowsPerLine;intCounter++)
                            {
                                var intTDWidth = (80/intShowsPerLine);
                                var objTD = document.createElement("td");
                            
                                objTD.style.backgroundColor = "#FFFFFF";
                                objTD.style.width = "60px";
                                objTD.innerHTML = "";
                                objTR.appendChild(objTD);
                            }
                            if(blnAddTrName == true)
                            {
                                objTBody.appendChild(objTRName);
                            }
                            blnAddTrName = false;
                            objTBody.appendChild(objTR);
                            if(objTRSeparator != undefined)
                            {
                                objTBody.appendChild(objTRSeparator);                                    
                            }
                            var objTR = document.createElement("tr");
                        }
                    }
                }
            }
            
            objTable.appendChild(objTBody);
            var objsecSchedule = document.getElementById("secSchedule");
            objsecSchedule.innerHTML = "";
            objsecSchedule.appendChild(objTable);
            
            if(objTBody.childNodes.length == 0)
            {
                objsecSchedule.innerHTML = "Sorry!!! No results for the selected filters";
            }
            else
            {
                subFetchVenueInfo(strVenueCode);
            }
        }
    } catch(e) {
        alert(e.message);
        subDisplayError("BuyTicketsPageCode.js", "objCreateDisplaySchedule('" + strVenueCode + "','" + strEventCode + "','" + strShowDate + "')", e);
    }
}

function intGetRowSpanByVenue(strVenueCode)
{
    try
    {
        var intCount = 0;
    
        for(var intCounter = 0; intCounter < arrShowTimes.length; intCounter++)
        {
            if(arrShowTimes[intCounter][0] == strVenueCode)
            {
                if(blnCheckPriceRange(arrShowTimes[intCounter][9], arrShowTimes[intCounter][10]) == false)
                {
                    continue;
                }
                
                if(blnCheckTimeRange(arrShowTimes[intCounter][5]) == false)
                {
                    continue;
                }
                intCount++;
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "intGetRowSpanByVenue('" + strVenueCode + "')", e);
    }
    intCount = intCount == 0 ? 1 : intCount;
    return intCount;
}

function intGetRowSpanByEvent(strEventCode)
{
    try
    {
        var intCount = 0;
        
        for(var intCounter = 0; intCounter < arrShowTimes.length; intCounter++)
        {
            if(arrShowTimes[intCounter][2] == strEventCode)
            {
                if(blnCheckPriceRange(arrShowTimes[intCounter][9], arrShowTimes[intCounter][10]) == false)
                {
                    continue;
                }
                
                if(blnCheckTimeRange(arrShowTimes[intCounter][5]) == false)
                {
                    continue;
                }
                intCount++;
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "intGetRowSpanByEvent('" + strEventCode + "')", e);
    }
    
    intCount = intCount == 0 ? 1 : intCount;
    return intCount;
}

function subSelectShow(e, strVenueCode, strSessionId, strEventCode, strShowTime)
{
    try
    {        
        subDisplayShowTime(strShowTime);
        
        var objtblClass = document.getElementById("tblClass");
         
        if(window.event)
        {
            intClientX = window.event.clientX - 120;
            
            if(document.body.scrollTop > 0)
            {
                intClientY = window.event.clientY + document.body.scrollTop;
            }
            else
            {
                intClientY = window.event.clientY + document.documentElement.scrollTop + 2;
            }
        }
        else if(e)
        {
            intClientX = e.clientX - 120;
            if(document.body.scrollTop > 0)
            {
                intClientY = (e.clientY + document.body.scrollTop);
            }
            else
            {
                intClientY = (e.clientY + document.documentElement.scrollTop + 2);
            }
        }
        strSelectedEventCode = strEventCode;
        strSelectedVenueCode = strVenueCode;
        strSelectedSession = strSessionId;
        subGetDataAndExecute("SHOWINFO_" + strVenueCode + "_" + strSessionId, strDataURL + "strCommand=GETSHOWINFO&strVenueCode=" + strVenueCode + "&strSessionId=" + strSessionId, "subFilterShowInfo('" + strVenueCode + "', '" + strSessionId + "');", true);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subSelectShow(" + e + ", '" + strVenueCode + "', '" + strSessionCode + "')", e);
    }
}

function subDisplayShowTime(strSelectedShowTime)
{
    try
    {
        var objspnShowTime = document.getElementById("spnShowTime");
        if(objspnShowTime)
        {
            if(strSelectedShowTime != "")
            {
                objspnShowTime.innerHTML = "&nbsp;@ " + strSelectedShowTime;
            }
            else
            {
                objspnShowTime.innerHTML = "";
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subDisplayShowTime('" + strSelectedShowTime + "')", e);
    }  
}

function subFilterShowInfo(strVenueCode, strSessionId)
{
    try
    {
        arrShowPrices = new Array();
        var strEval = "";
        blnShowSeatLayout = true;
        
        for(var intCount = 0;intCount < arrShowInfo.length;intCount++)
        {
            if(arrShowInfo[intCount][0] == strVenueCode && arrShowInfo[intCount][1] == strSessionId)
            {
                if(arrShowInfo[intCount][9] == "N")
                {
                    blnShowSeatLayout = false;
                }
                strEval = "arrShowPrices[" + eval("arrShowPrices.length") + "] = new Array('" + arrShowInfo[intCount][2] + "', '" + arrShowInfo[intCount][3] + "', '" + arrShowInfo[intCount][4] + "', '" + arrShowInfo[intCount][5] + "', '" + arrShowInfo[intCount][6] + "', '" + arrShowInfo[intCount][7] + "', '" + arrShowInfo[intCount][8] + "');";
        
                eval(strEval);
            }
        }
    
        subDisplaySessionClass(strVenueCode);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subFilterShowInfo('" + strVenueCode + "', '" + strSessionId + "')", e);
    }
}

function subDisplaySessionClass(strVenueCode)
{
    try
    {
        var objtblClass = document.getElementById("tblClass");        
        var objDiv = document.getElementById("divTotal");        
        var objDivResults = document.getElementById("divResults");
        var intClientHeight = objtblClass.clientHeight == 0 ? 300 : objtblClass.clientHeight;
        if(objDivResults) { objDivResults.style.display = "none";}        
        if(objDiv) { objDiv.innerHTML = "";}
        
        curTotal = 0;
        arrTotal[0] = 0;
        arrTotal[1] = 0;
        arrTotal[2] = 0;
        arrTotal[3] = 0;
        arrTotal[4] = 0;
        
        for(var intCount = 0;intCount < 5;intCount++)
        {
            var objTR = document.getElementById("trClass" + (intCount + 1).toString());
            var objCmbQty = document.getElementById("cmbQty" + (intCount + 1).toString());
            
            objTR.style.display = "none";
            objCmbQty.value = "0";
        }
        
        for(var intCount = 0;intCount < arrShowPrices.length;intCount++)
        {
            var objTR = document.getElementById("trClass" + (intCount + 1).toString());
            var objtxtClass = document.getElementById("txtClass" + (intCount + 1).toString());
            var objCmbQty = document.getElementById("cmbQty" + (intCount + 1).toString());
            
            subAddToQtyCombo(objCmbQty, arrShowPrices[intCount][3], arrShowPrices[intCount][4]);
            
            if(strBrowserType == "ie")
            {
                objTR.style.display = "block";
            }
            else
            {
                objTR.style.display = "table-row";
            }
            objtxtClass.value = arrShowPrices[intCount][1];
        }
        
        if(blnSessionClosed == true)
        {
            subShowMessage(0, "Sorry, Bookings for the current show have been closed.", "ErrorBg3");
            return;
        }
        
        if(objtblClass)
        {
            objtblClass.style.left=intClientX + "px";
	        objtblClass.style.top=intClientY + "px";	        
	        objtblClass.style.display="block";
	        var objspnSeatNote = document.getElementById("spnSeatNote");
	        var objbtnClass = document.getElementById("btnClass");
	        objspnSeatNote.innerHTML = "";
	        if(blnShowSeatLayout == false)
	        {
	            objspnSeatNote.innerHTML = "Note : No Seat Layout available for this Show<br/><br/>";
	            objbtnClass.src = "Common/Images/bookmyshow.jpg";
            }
            else
            {
                objbtnClass.src = "Common/Images/ChooseSeats.jpg";
            }
            if(strVenueCode == "PTHV")
            {
                objspnSeatNote.innerHTML += "Note : A valid Id/Age proof is required for Senior Citizens & Students tickets at the venue,failing which entry would be denied.";
            }
	        if(intClientY + intClientHeight - screen.availHeight > -20)
	        {
	            window.scrollTo(0, (screen.availHeight + (intClientY + intClientHeight - screen.availHeight)))
            }
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subDisplaySessionClass()", e);
    }
}

function subDisplayTotal(objCmbQty)
{
    var intarrCount;
    var curClassTotal;
    var intQty;
    var curClassPrice;

    var objTdTotal = document.getElementById("divTotal");
    tktQty = parseInt(tktQty) + parseInt(objCmbQty.value);
    if (tktQty > 10) {
    	alert("Sorry. You cannot book more than 10 tickets in a single transaction.");
    	document.getElementById("chSeats").style.display = "none";
    	return;
    }
    else {
    	document.getElementById("chSeats").style.display = "";
    }

    try {   
		
        switch(objCmbQty.id)
        {
            case "cmbQty1" :
                intarrCount = 0;
                intQty = objCmbQty.value;
                curClassPrice = parseFloat(arrShowPrices[intarrCount][2]);
                curClassTotal = curClassPrice * intQty;
                
                arrTotal[0] = curClassTotal;
                break;
            case "cmbQty2" :
                intarrCount = 1;
                intQty = objCmbQty.value;
                curClassPrice = parseFloat(arrShowPrices[intarrCount][2]);    
                curClassTotal = curClassPrice * intQty;
                
                arrTotal[1] = curClassTotal;
                break;
            case "cmbQty3" :
                intarrCount = 2;
                intQty = objCmbQty.value;
                curClassPrice = parseFloat(arrShowPrices[intarrCount][2]);    
                curClassTotal = curClassPrice * intQty;
                
                arrTotal[2] = curClassTotal;
                break;
            case "cmbQty4" :
                intarrCount = 3;
                intQty = objCmbQty.value;
                curClassPrice = parseFloat(arrShowPrices[intarrCount][2]);    
                curClassTotal = curClassPrice * intQty;
                
                arrTotal[3] = curClassTotal;
                break;
            case "cmbQty5" :
                intarrCount = 4;
                intQty = objCmbQty.value;
                curClassPrice = parseFloat(arrShowPrices[intarrCount][2]);
                curClassTotal = curClassPrice * intQty;
                
                arrTotal[4] = curClassTotal;
                break;
        }    
        
        curTotal = parseFloat(arrTotal[0]) + parseFloat(arrTotal[1]) + parseFloat(arrTotal[2]) + parseFloat(arrTotal[3]) + parseFloat(arrTotal[4]);
        
        if(curTotal != 0)
        {
            curDisplayTotal = curTotal - Math.ceil((curTotal*10)/100);
            subUpdateTotal();
        }
        else
        {
            objTdTotal.innerHTML = "";
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCodeEx.js", "subDisplayTotal(" + objCmbQty + ")", e);
    }
    
}

function strFormatTotal(strData)
{
    if(strData.indexOf(".") > 0)
    {
        strData = strData.split(".")[0].toString() + "." + (strData.split(".")[1].toString() + "0").substring(0,2).toString();
    }
    else
    {
        strData += ".00";
    }
    
    return strData;
}


function subUpdateTotal()
{
    try
    {
        var objTdTotal = document.getElementById("divTotal");
        
        if(curDisplayTotal <= curTotal)
        {
            objTdTotal.innerHTML = '$ ' + strFormatTotal(curDisplayTotal.toString());
            curDisplayTotal += 5;
        }
        else
        {
            objTdTotal.innerHTML = '$ ' + strFormatTotal(curTotal.toString());
            clearTimeout(objTimeOut);
            return;
        }
        
        objTimeOut = setTimeout("subUpdateTotal()","5");
    } catch(e) {
        subDisplayError("BuyTicketsPageCodeEx.js", "subUpdateTotal()", e);
    }
}

function subInitBook()
{
    try
    {
        var intTotalQty = 0;
        var strClassData = "";
        var strClassAreaData = "";
        var arrClassData = new Array();
        
        for(var intCount = 0;intCount < arrShowPrices.length;intCount++)
        {
            var objCmbQty = document.getElementById("cmbQty" + (intCount + 1).toString());
            
            if(objCmbQty.value != "0")
            {
                
                if(strClassAreaData != "")
                {
                    strClassData += "|";
                    strClassAreaData += "|";
                }
                
                strClassAreaData += arrShowPrices[intCount][6] + "-" + objCmbQty.value;
                arrClassData.push(new Array(arrShowPrices[intCount][0], objCmbQty.value));
                intTotalQty += parseInt(objCmbQty.value);
            }
        }
        
        if(intTotalQty <= 0)
        {
            subShowError(0, "Please select the Class/Quantity of tickets");
        }
        
        blnSetCookie("strArea", strClassAreaData, false);
        blnSetCookie("intTQty", intTotalQty, false);
    
        if(curTotal > 0)
        {
            var strOfferDetails = "";
            if(strGetCookie("oc", "") != "")
            {
                strOfferDetails = "|OFFERCODE=" + strGetCookie("oc", "") + "|";
            }
            subInitTrans(strSelectedVenueCode, strSelectedSession, arrClassData, strOfferDetails, blnShowSeatLayout);
        }
    
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subInitBook()", e);
    }
}

function subAddToQtyCombo(objCombo, strAllowSales, intQuantity)
{
    try
    {
        for(var intChildCount = objCombo.childNodes.length - 1; intChildCount >= 0; intChildCount--)
        {
            var objChild = objCombo.childNodes[intChildCount];
            objCombo.removeChild(objChild);
        }
        
        if(strAllowSales == "Y")
        {
            blnSessionClosed = false;
            for(var intCount = 0; intCount <= intQuantity; intCount++)
            {
                var objOption = document.createElement("option");
                objOption.setAttribute("value", intCount);
                objOption.innerHTML = intCount.toString();
                objCombo.appendChild(objOption);
            }
        }
        else if(strAllowSales == "N")
        {
            blnSessionClosed = false;
            var objOption = document.createElement("option");
            objOption.setAttribute("value", "0");
            objOption.innerHTML = "SOLD";
            objCombo.appendChild(objOption);
        }
        else if(strAllowSales == "C")
        {
            var objOption = document.createElement("option");
            objOption.setAttribute("value", "0");
            objOption.innerHTML = "SOLD";
            objCombo.appendChild(objOption);
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subAddToQtyCombo('" + strAllowSales + "', " + intQuantity + ")", e);
    }
}

function subDisableSchedule()
{
    try
    {
        var objDivDisableSchedule = document.getElementById("divDisableSchedule");
        objDivDisableSchedule.style.display = "block";
        var objtblDisableSchedule = document.getElementById("tblDisableSchedule");
        var objsecSchedule = document.getElementById("secSchedule");
        var intTop = objsecSchedule.offsetTop;
        var intLeft = objsecSchedule.offsetLeft;
           
        intTop += objsecSchedule.offsetParent.offsetTop;
        intTop += objsecSchedule.offsetParent.offsetParent.offsetTop;
        intTop += objsecSchedule.offsetParent.offsetParent.offsetParent.offsetTop;
        intTop += objsecSchedule.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
        intLeft += objsecSchedule.offsetParent.offsetLeft;
        intLeft += objsecSchedule.offsetParent.offsetParent.offsetLeft;
        intLeft += objsecSchedule.offsetParent.offsetParent.offsetParent.offsetLeft;
        intLeft += objsecSchedule.offsetParent.offsetParent.offsetParent.offsetParent.offsetLeft;
       
        objDivDisableSchedule.style.left = intLeft + "px";
        objDivDisableSchedule.style.top = intTop + "px";
        objtblDisableSchedule.style.height = objsecSchedule.clientHeight.toString() + "px";
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subDisableSchedule()", e);
    }
}

function subEnableSchedule(strData)
{
    try
    {
        subDeleteBookingInfo();
        var objDivDisableSchedule = document.getElementById("divDisableSchedule");
        var objsecPaymentButtons = document.getElementById("secPaymentButtons");
        if(objDivDisableSchedule)
        {
            objDivDisableSchedule.style.display = "none";
        }
        if(objsecPaymentButtons)
        {
            objsecPaymentButtons.innerHTML = "";
        }
        subRefreshSummaryTable();
        subHidePointer();
        subDisplayShowTime("");
        if (window.toggleSelection) toggleSelection(false);
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subEnableSchedule('" + strData + "')", e);
    }
    
}

function subDisplayPointer()
{
    var objDivDisableSchedule = document.getElementById("tdPointer");
    objDivDisableSchedule.innerHTML = "<img style=\"position:absolute;float:none;\" src=\"Common/Images/arrow.gif\" alt=\"\" />" ;  
}

function subHidePointer()
{
    var objDivDisableSchedule = document.getElementById("tdPointer");
    if(objDivDisableSchedule)
    {
        objDivDisableSchedule.innerHTML = "";
    }
}

function subRefreshSummaryTable()
{
    try
    {
        var objtblSummary = document.getElementById("tblSummary");
        if(tblSummary)
        {
            var objtdInfo = document.getElementById("tdInfo");
            var objspnSeatInfo = document.getElementById("spnSeatInfo");
            var objtdSummaryTotal = document.getElementById("tdSummaryTotal");
            var objtdSummaryTotalEx = document.getElementById("tdSummaryTotalEx");
            var objspnSummaryTitleName = document.getElementById("spnSummaryTitleName");
            var objspnSummaryTitle = document.getElementById("spnSummaryTitle");
            var objspnSeatInfo = document.getElementById("spnSeatInfo");
            var objspnClass = document.getElementById("spnClass");
            var objtblSeatInfo = document.getElementById("tblSeatInfo");
            var objspnSeatData = document.getElementById("spnSeatData");
            
            objtblSummary.style.display = "block";
            objspnSeatInfo.innerHTML = "";
            objtdSummaryTotal.innerHTML = "";
            objtdSummaryTotalEx.innerHTML = "";
            objspnSummaryTitleName.innerHTML = "";
            objspnSummaryTitle.innerHTML = "";
            objtblSeatInfo.innerHTML = "";
            objspnClass.style.display = "none";
            objspnSeatData.innerHTML = "";
        }
    } catch(e) {
        subDisplayError("BuyTicketsPageCode.js", "subRefreshSummaryTable()", e);
    }
}

