function DoSort(columnName)
{
    ProgressMessage();
    gSort = true;
    gColumnName=columnName;
    if(gPrevSortColumnName == columnName)
    {
        if(gSortOrder == "Ascending" || gSortOrder == "")
        {
            gSortOrder = "Descending";
        }
        else if(gSortOrder == "Descending" )
        {
            gSortOrder = "Ascending";
        }
    }
    else
    {
        gSortOrder = "Ascending";
    }
    var priceRangeValues = "";
    var qty = "";
    if(gLeftPanelState != "Init")
    {
        priceRangeValues = GetFilterPriceRanges();
        qty = GetFilterQuantity();
    }

    if(gPriceLevelId != "" && gPriceLevelId != "null" && gLeftPanelState == "MapSelection" && gIsShowSavedTickets == false)
    {
        TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetSortedTicketDetails(performanceId, flashMapFileName, priceRangeValues, qty, "","", gPriceLevelId, gmode,gOpenNotesIds,gsavedTicketBlocks,columnName,gSortOrder,gIsShowSavedTickets,GetSortedTicketDetails_Callback);
    }
    else if(gSeatingAreaSection != "" && gSeatingAreaSection != "null" && gLeftPanelState == "MapSelection" && gIsShowSavedTickets == false)
    {
        TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetSortedTicketDetails(performanceId, flashMapFileName, priceRangeValues, qty, "",gSeatingAreaSection, "", gmode,gOpenNotesIds,gsavedTicketBlocks,columnName,gSortOrder,gIsShowSavedTickets,GetSortedTicketDetails_Callback);
    }
    else if(gIsShowSavedTickets == true)
    {
        TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetSortedTicketDetails(performanceId, flashMapFileName, priceRangeValues, qty, gsavedTicketBlocks,"", "", "",gOpenNotesIds,gsavedTicketBlocks,columnName,gSortOrder,gIsShowSavedTickets,GetSortedTicketDetails_Callback);
    }
    else
    {
        TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetSortedTicketDetails(performanceId, flashMapFileName, priceRangeValues, qty,"","","","",gOpenNotesIds,gsavedTicketBlocks,columnName,gSortOrder,gIsShowSavedTickets,GetSortedTicketDetails_Callback);
    }
    gPrevSortColumnName = columnName;
}

/**
* The method gets called on the go button click of the filter bar.It gets the tickets based on the price range
* and/or quantity selected
* @param bReturnToMap flag to determine whether the flash map is to be refreshed or not
*/
function GetTicketsByFilter(bReturnToMap)
{
    ProgressMessage();
    gColumnName = "Price";
    gSort = false;
    gSeatingAreaSection="";
    gRemovedSeatingAreaSection="";
    gPriceLevelId = "";
    gMode = "";
    gSortOrder = "";
    gLeftPanelState = "Filter";
    var priceRangeValues = "";
    var qty = "";
    if(bReturnToMap == true)
    {
        priceRangeValues = GetFilterPriceRanges();
        if(priceRangeValues == "")
            priceRangeValues = "VIEWALL";
        qty = GetFilterQuantity();
    }
    ShowProgress();
    hideSeatingContent();
    TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetTicketDetailsByFilters(performanceId, flashMapFileName, priceRangeValues, qty,gOpenNotesIds,gsavedTicketBlocks,GetTicketsByFilter_Callback);    
}


function GetStatus(gmd)
{
  try{
    if(gmd == 0 && isFlashPlayerAvailable == true)
    {     
        if(gLeftPanelState == "Init" && gSort==false && gIsShowSavedTickets == false && gIsRemoveSavedTickets==false)
        {
            gFlashFunctionStatus = "INITIALIZE";
            document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();//GetTicketListingInfo(gLeftPanelState);
            document.getElementById("TicketListingInfoDiv").style.display = '';
            
            InitializeBlock(gFlashSections);
            
            //window.setTimeout("InitializeBlock('" + gFlashSections + "')",4000);
        }
        else if(gLeftPanelState == "Filter" && gSort==false && gIsShowSavedTickets == false && gIsRemoveSavedTickets==false)
        {
            gFlashFunctionStatus = "REFRESH";
            document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();//GetTicketListingInfo(gLeftPanelState);
            document.getElementById("TicketListingInfoDiv").style.display = '';
             if(iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)  
            {
                document.getElementById("ToScrollMsgId").style.display = '';
            }
            else
            {
                document.getElementById("ToScrollMsgId").style.display = 'none';
            }
            refreshBlock(gFlashSections);
        }
        else if(gSort==false && gIsShowSavedTickets == true && gIsRemoveSavedTickets==false)
        {
            refreshBlock(gFlashSections);
            gFlashFunctionStatus = "SENDSAVEDTICKETS";
            sendSavedTickets(gsavedSeatingAreaSection);             
           iframeDoc.getElementById("LMTicketsInfo").innerHTML =  GetSavedTicketsInfo() + iframeDoc.getElementById("LMTicketsInfo").innerHTML ;
            
            document.getElementById("TicketListingInfoDiv").style.display = 'none';
            iframeDoc.getElementById("LMTicketsInfo").innerHTML
             if( iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)
            {
                document.getElementById("ToScrollMsgId").style.display = '';
            }
            else
            {
                document.getElementById("ToScrollMsgId").style.display = 'none';
            }
        }
        else if(gSort==false && gIsShowSavedTickets == true && gIsRemoveSavedTickets==true)
        {
            gFlashFunctionStatus = "REMOVESAVEDTICKET";
            removeSavedTicket(gRemovedSeatingAreaSection);
            document.getElementById("TicketListingInfoDiv").style.display = 'none';
            if( iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)            
            {
                document.getElementById("ToScrollMsgId").style.display = '';
            }
            else
            {
                document.getElementById("ToScrollMsgId").style.display = 'none';
            }
        }
        else if(gSort==true && gIsShowSavedTickets == true)
        {
            refreshBlock(gFlashSections);
            gFlashFunctionStatus = "SENDSAVEDTICKETS";
            sendSavedTickets(gsavedSeatingAreaSection);
             iframeDoc.getElementById("LMTicketsInfo").innerHTML =  GetSavedTicketsInfo() + iframeDoc.getElementById("LMTicketsInfo").innerHTML ;
            
            document.getElementById("TicketListingInfoDiv").style.display = 'none';
           
            if( iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)
            {
                document.getElementById("ToScrollMsgId").style.display = '';
            }
            else
            {
                document.getElementById("ToScrollMsgId").style.display = 'none';
            }
        }
        else if(gLeftPanelState == "MapSelection")
        {
             if( iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)
            {
                document.getElementById("ToScrollMsgId").style.display = '';
            }
            else
            {
                document.getElementById("ToScrollMsgId").style.display = 'none';
            }
            document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();
            document.getElementById("TicketListingInfoDiv").style.display = '';
        }
        else if(gSort == true)
        {
            document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();
            document.getElementById("TicketListingInfoDiv").style.display = '';
        }
        else
        {
            return;
        }
    }
     }catch(e){null}
}

function GetTicketListingInfo()
{
    var strTicketListingInfo = "";
         
    if(gLeftPanelState == "Init")
    {        
       if(gTicketCount>1)
        {
          strTicketListingInfo = "You are viewing "+gTicketCount+" tickets.";
        }
        else
        {                  
            strTicketListingInfo = "You are viewing "+gTicketCount+" ticket.";                   
        }
    }
    else
    {
        if(parseInt(gTotalTicketCount) == parseInt(gTicketCount))
        {                
            if(gTicketCount == 1)
                strTicketListingInfo = "You are viewing "+ gTicketCount+" ticket.";
            else
                strTicketListingInfo = "You are viewing "+ gTicketCount+" tickets.";                                    
        }
        else
        {              
             if(gTotalTicketCount == 1)
               strTicketListingInfo = "You are viewing "+ gTicketCount+" of " + gTotalTicketCount+" available ticket&nbsp;-&nbsp;(<a href='#' onclick='ReturnToMap(true);return false;' class='MapSubHeaderImageText'>View All</a>)";
             else
                strTicketListingInfo = "You are viewing "+ gTicketCount+" of " + gTotalTicketCount+" available tickets&nbsp;-&nbsp;(<a href='#' onclick='ReturnToMap(true);return false;' class='MapSubHeaderImageText'>View All</a>)";                
        } 
     }
     return strTicketListingInfo;
}

function GetHeader(sortStatus, sortColumn)
{
    var strTableHeader= "";//"<table cellpadding=0 cellspacing=0 width=430 border=0>";
    var sectionColumn ="<div id=\"LMtlsection\" class=\"HeaderColumn HeaderColumnLink\"  onclick=\"DoSort('Section'); return false;\">"+gSectionColumn;
    var rowColumn ="<div id=\"LMtlrow\" class='HeaderColumn HeaderColumnLink' onclick=\"DoSort('Row'); return false;\">"+gRowColumn+"";
    var costPerticketColumn ="<div id=\"LMtlprice\" class='HeaderColumn HeaderColumnLink' onclick=\"DoSort('Price'); return false;\">"+gPriceColumn+"";
    var quantityColumn ="<div id=\"LMtlqty\" class='HeaderColumn HeaderColumnLink' onclick=\"DoSort('Quantity'); return false;\">"+gQuantityColumn+"";
    var addToCartColumn ="<div id=\"LMtlcart\" class='HeaderColumn'>"+gAddToCartColumn+"</div>";
    if(sortColumn == "Section")
    {
        sectionColumn = sectionColumn + sortStatus + "</div>";
        rowColumn = rowColumn + "</div>";        
        costPerticketColumn=costPerticketColumn + "</div>";
        quantityColumn = quantityColumn  + "</div>";
    }
    if(sortColumn == "Row")
    {
        sectionColumn = sectionColumn + "</div>";
        rowColumn = rowColumn + sortStatus + "</div>";
        costPerticketColumn=costPerticketColumn + "</div>";
        quantityColumn = quantityColumn  + "</div>";
    }
    if(sortColumn == "Price")
    {
        sectionColumn = sectionColumn + "</div>";
        rowColumn = rowColumn + "</div>";
        costPerticketColumn = costPerticketColumn + sortStatus + "</div>";
        quantityColumn = quantityColumn  + "</div>";
    }
    if(sortColumn == "Quantity")
    {
        sectionColumn = sectionColumn + "</div>";
        rowColumn = rowColumn + "</div>";
        costPerticketColumn=costPerticketColumn + "</div>";
        quantityColumn = quantityColumn + sortStatus + "</div>";
    }
    strTableHeader =  strTableHeader +  sectionColumn + rowColumn + costPerticketColumn + quantityColumn + addToCartColumn;
    return strTableHeader;
}
/**
*
*/

function ShowFlashVersion(bShowFlashVersion)
{
    if(bShowFlashVersion == false)
    {
        //ShowNonFlashVersion
        document.getElementById("normalView").innerHTML = "<u>"+gswitchToNormalViewMessage+"</u>";

        document.getElementById("nonFlashVersionText").style.display = 'none';//<a href="#" class="helptxt" id='normalView' onclick="ShowFlashVersion(true);" visible="false"><%=switchToNormalViewMessage %></a>
        document.getElementById("normalViewdiv").style.display = '';

        document.getElementById("flashDiv").style.visibility = 'hidden';
        document.getElementById("divWaterMark").style.display = ''
        document.getElementById("nonLiveMapFlash").style.display = '';
        document.getElementById("nonLiveMapFlash").innerHTML = "<img width='498' height='678' id='livemapgif' src='"+flashMapPath.toUpperCase().replace(".SWF",".png")+"' />";
        document.getElementById("LiveMapsStep3").innerHTML = ''; 
    }
    else
    {
        document.getElementById("normalViewdiv").style.display = 'none';

        document.getElementById("flashDiv").style.visibility = 'visible';
        document.getElementById("divWaterMark").style.display = 'none'
        document.getElementById("nonLiveMapFlash").style.display = 'none';
        
        document.getElementById("nonFlashVersionText").style.display = '';
        document.getElementById("LiveMapsStep3").innerHTML = LiveMapsStep3Html();
    }
}

function onMapSelection(seatingAreaSection, priceLevelId, mode)
{
    var seatingArea = "";
    var section = "";
    var tickets = "";
    var ticketDetails = "";
    var multipleseatingAreaSection;
    gFlashFunctionStatus = "ONMAPSELECTION";
    gSeatingAreaSection = seatingAreaSection;
    gPriceLevelId = priceLevelId;
    gMode = mode;
    gLeftPanelState = "MapSelection";
    ProgressMessage();
    gtype = 'CLICKED';
    gmode = gMode;
    
    hideSeatingContent();
    
    iframeDoc.getElementById("LMTicketsInfo").scrollTop = 0
                   
    if(seatingAreaSection == "null")
    {
         ShowIFrameDiv(false)
         var noTicketsFound = "<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=100% colspan=6 align='left' valign='middle' bgcolor='#FFFFFF' ><span class='ItalicText'>Please select an area on the map</span>&nbsp;&nbsp;&nbsp;</td></tr></table>";
         document.getElementById("TicketInfo").innerHTML = noTicketsFound;
         
         gTicketCount = 0;
         gMinPrice = 0;
         gMaxPrice = 0;
         
         gTicketsAvailable = 0;
         document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();//GetTicketListingInfo(gLeftPanelState);
         document.getElementById("TicketListingInfoDiv").style.display = '';
         
         document.getElementById("ToScrollMsgId").style.display = 'none';        
    }
    else
    {
        var priceRangeValues = GetFilterPriceRanges();
        var qty = GetFilterQuantity();
        
        if(priceLevelId != "" && priceLevelId != "null")
        {
           TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetTicketDetailsByLevelSection(performanceId, flashMapFileName, priceRangeValues, qty, "", priceLevelId, mode,gOpenNotesIds,gsavedTicketBlocks,onMapSelection_CallBack);
        }
        else
        {
           TickCo.Web.AjaxWebServiceProxies.LiveMaps.GetTicketDetailsByLevelSection(performanceId, flashMapFileName, priceRangeValues, qty, seatingAreaSection, "", mode,gOpenNotesIds,gsavedTicketBlocks,onMapSelection_CallBack);
            if (mode == "STANDARD")
            {
                if (seatingAreaSection != String.Empty)
                {
                    var levelSectionblock = seatingAreaSection.split("_");
                    if (levelSectionblock.length >= 2)
                    {
                        var seatingArea = levelSectionblock[0];
                        showSeatingContent(seatingArea)
                    }
                }
            }            
        }
    }
}

function onMapSelection_CallBack(ticketDetails)
{
    
    if(ticketDetails.error == null)
    {
        gSortOrder = "";
        gSort=false;
        gColumnName = "Price";
        gIsShowSavedTickets=false;
        gIsRemoveSavedTickets=false;
        var domString = ticketDetails.DomString;
        gTicketListCount = ticketDetails.TicketListCount;
        gTicketCount = ticketDetails.TotalTicketCount;
        gMaxPrice = ticketDetails.MaxPrice;
        gMinPrice = ticketDetails.MinPrice;
        document.getElementById("LMticketlistheader").innerHTML =ticketDetails.HeaderString;
        showTickets(domString, "Price", true, true, "");
        if( iframeDoc.getElementById("LMTicketsInfo").scrollHeight > 580)
        {
            document.getElementById("ToScrollMsgId").style.display = '';
        }
        else
        {
            document.getElementById("ToScrollMsgId").style.display = 'none';
        }
         document.getElementById("TicketListingInfoDiv").innerHTML = GetTicketListingInfo();
         document.getElementById("TicketListingInfoDiv").style.display = '';
         
         if(gmode != "STANDARD")
         {
            if(ticketDetails.SelectedSeatingArea != null && ticketDetails.SelectedSeatingArea != "")
            showSeatingContent(ticketDetails.SelectedSeatingArea);
        }
    }
    else
        alert(ticketDetails.error);    
}


function  refreshBlock(liveMapControlSection)
{
    try{
    var flashMovie=LmFlashFrameWindow.getFlashMovieObject("FlashMap");
    if(flashMovie.handleCallback!=null)
    {
        flashMovie.handleCallback(liveMapControlSection,"REFRESH");
    }
    }catch(e){null}
}
function  returnToMap(sSeatingAreaSection)
{
    try{
    var flashMovie=LmFlashFrameWindow.getFlashMovieObject("FlashMap");
    if(flashMovie.handleCallback!=null)
    {
        flashMovie.handleCallback(sSeatingAreaSection,"RETURNTOMAP");
    }
    }catch(e){null}
}

function StopProgress()
{
    try{
          
    var flashMovie=LmFlashFrameWindow.getFlashMovieObject("FlashMap");
    if(flashMovie.handleCallback!=null)
    {
        flashMovie.handleCallback("","STOPPROGRESS");
    }
    }catch(e){null}
}
function ShowProgress()
{
    try{
    
    var flashMovie=LmFlashFrameWindow.getFlashMovieObject("FlashMap");
    if(flashMovie.handleCallback!=null)
    {
        flashMovie.handleCallback("","SHOWPROGRESS");
    }
    }catch(e){null}
}
