﻿var sections = new Array();
var filter = { type: "filter", value: "0", min: "0", max: "999999" };

function processFilter(pSections) {
    try {
        TL_Interaction('Seating Chart Clicked');
        var IMCookie = "IM_" + getPageName().toUpperCase();
        var sectionId = "";
        if (pSections.length > 0) {
            if (readCookie(IMCookie) != '' && readCookie(IMCookie) != null) {
                eraseCookie(IMCookie);
                var selectedSections = "'" + pSections.toString().replace(/,/g, "_''") + "_'";
                createCookie(IMCookie, selectedSections); //"'" + pSections.toString().replace(/,/g, "_''") + "_'");

                filterBySection(readCookie(IMCookie));
            }
            else {
                var selectedSections = "'" + pSections.toString().replace(/,/g, "_''") + "_'";
                createCookie(IMCookie, selectedSections); //"'" + pSections.toString().replace(/,/g, "_''") + "_'");
                filterBySection(readCookie(IMCookie));
            }
        }
        else {
            eraseCookie(IMCookie);
            filterBySection("");
        }
    }
    catch (ex) {
        var strParams = "strErrorMsg=" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=JS_Exception_processFilter&bIsHtmlMsg=true";
        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
}
function filterBySection(sectionNames) {
    try {
        var strSortDirection = "ASC";
        var strSortField = "Price";
        strSortField = returnObj("hidSortField").obj.value;
        strSortDirection = returnObj("hidSortDirection").obj.value;

        var strServiceURL = location.protocol + "//" + location.hostname + "/ws/tcws.asmx/GetTicketList";
        var nBrokerID = returnObj("hidBrokerId").obj.value;
        var nEventID = returnObj("hidEventId").obj.value;
        var nMinPrice = returnObj("ddMinPrice").obj.options[returnObj("ddMinPrice").obj.selectedIndex].value;
        var nMaxPrice = returnObj("ddMaxPrice").obj.options[returnObj("ddMaxPrice").obj.selectedIndex].value;
        var nQty = returnObj("TicketListings_ddFilterQty").obj.options[returnObj("TicketListings_ddFilterQty").obj.selectedIndex].value;
        var strFilter = returnObj("hidFilter").obj.value;
        var strFilterParking = returnObj("chkFilterParking").obj.checked.toString();
        var bTransform = "true";

        showHide("divTicketListingsLoading", "show");
        showHide("divTicketListings", "hide");
        showHide("divTicketListingsAjax", "hide");
        showHide("divTicketFilters", "hide");
        showHide("divTicketColumnHeaders", "hide");
        showHide("divTicketSummary", "hide");

        var strParams = "BrokerID=" + nBrokerID + "&EventID=" + nEventID + "&MinPrice=" + nMinPrice + "&MaxPrice=" + nMaxPrice + "&Qty=" + nQty + "&Sort=" + strSortField + " " + strSortDirection + "&Filter=" + strFilter + "&Transform=" + bTransform + "&SectionList=" + sectionNames + "&FilterParking=" + strFilterParking;
        ajaxPost(strParams, strServiceURL, "renderTickets");
    }
    catch (ex) {
        var strParams = "strErrorMsg=" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=JS_Exception_filterBySection&bIsHtmlMsg=true";
        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
}

function filterByFilters(pValue, pType) {
    try {
        switch (pType) {
            case 'Qty':
                filter.value = pValue;
                break;
            case 'Min':
                filter.min = pValue;
                break;
            case 'Max':
                filter.max = pValue == 0 ? 999999 : pValue;
                break;
        }
        try {
            $("#fvmap").fanvenues.filter(filter.min, filter.max);
        }
        catch (ex) {
        }
    }
    catch (ex) {
        //        var strParams = "strErrorMsg=" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=JS_Exception_filterByFilters&bIsHtmlMsg=true";
        //        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
}

function addSection(pSection) {
    var section = $("#fvmap").fanvenues.getOriginalSectionNamesFor(pSection.replace(/ /g,'-').toLowerCase());
    for (var i = 0; i < section.length; i++) {
        var j = jQuery.inArray(section[i], sections);
        if (j < 0) {
            sections.push(section[i]);
        }
    }
}
function removeSection(pSection) {
    var section = $("#fvmap").fanvenues.getOriginalSectionNamesFor(pSection.replace(/ /g, '-').toLowerCase());
    for (var i = 0; i < section.length; i++) {
        var j = jQuery.inArray(section[i], sections)
        if (j >= 0) {
            sections.splice(j, 1);
        }
    }
    //alert(pSection);
}
function breakSectionName(pSection) {
    var sectionName = jQuery.trim(pSection).split(' ');
    return sectionName[sectionName.length-1];
}

function reloadFlashMap() {
    try {
        var IMCookie = "IM_" + getPageName().toUpperCase();
        eraseCookie(IMCookie); 	 /* Start Fresh */
        filter = { type: "filter", value: "0", min: "0", max: "999999" };
        try {
            $("#resetMapButton").trigger("click");
            $("#fvmap").fanvenues.filter(filter.min, filter.max);
        }
        catch (ex) {
        }
    }
    catch (ex) {
        var strParams = "strErrorMsg=" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=JS_Exception_reloadFlashMap&bIsHtmlMsg=true";
        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
}

function fallBackToStatic() {
    try {
        $('#TicketListings_pnlInteractiveSeatingChart').html("");
        $('#map_3dView_tabs').html("");
        $("#divSeats").html("");
        $("#divSeats").html("<div id='divSeatingChartMask'><div id='divSeatingChartWrapper'><div id='divSeatingChart' onmousemove='panChart(event);' onmousedown='panChartStart(event);' onmouseup='panChartEnd();' ondrag='return false;'><div id='divSeatingCanvas'><img id='imgSeatingChart' onload='initSeatingChart();initSeatingCanvas();initSeatingScroll();' src='" + $('#hidStaticImagePath').val() + "' alt='' /></div></div><div id='divSeatingTools' class='divSeatingTools'><img src='/site-images/seatingchartnav/panUp.png' border='0' alt='Pan Up' class='imgSeatingTools' onclick='panSeatingChart(\"UP\");' /><br /><img src='/site-images/seatingchartnav/panLeft.png' border='0' alt='Pan Left' class='imgSeatingTools' onclick='panSeatingChart(\"LEFT\");' /><img src='/site-images/seatingchartnav/center.png' border='0' alt='Center Chart' class='imgSeatingTools' onclick='centerSeatingChart();' /><img src='/site-images/seatingchartnav/panRight.png' border='0' alt='Pan Right' class='imgSeatingTools' onclick='panSeatingChart(\"RIGHT\");' /><br /><img src='/site-images/seatingchartnav/panDown.png' border='0' alt='Pan Down' class='imgSeatingTools' onclick='panSeatingChart(\"DOWN\");' /><br /><img src='/site-images/global/spacer.gif' border='0' alt='' width='1px' height='5px' /><br /><img src='/site-images/seatingchartnav/zoomIn.png' border='0' alt='Zoom In' class='imgSeatingTools' onclick='zoomSeatingChart(\"IN\");' /><br /><img src='/site-images/seatingchartnav/zoomOut.png' border='0' alt='Zoom Out' class='imgSeatingTools' onclick='zoomSeatingChart(\"OUT\");' /><br /></div></div> </div>")

        var strParams = "strErrorMsg=FanvenuesMapFallback" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=FanvenuesMapFallback_JS_Exception_fallBackToStatic&bIsHtmlMsg=true";
        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
    catch (ex) {
        var strParams = "strErrorMsg=" + getDebugInfo() + getExceptionInfo(ex) + "&strSubject=JS_Exception_fallBackToStatic&bIsHtmlMsg=true";
        ajaxPost(strParams, location.protocol + "//" + location.hostname + "/ws/tcws.asmx/LogError", null);
    }
}
//function ISC_Exception(msg)
//{
//	try
//	{
//		var strInfo = "<b>ISC Error Message:</b> "+msg+"<br /><b>URL:</b> "+document.location.href+"<br /><hr />";
//		var strParams = "strErrorMsg="+strInfo.replace("&", "&#38;")+getDebugInfo().replace("&", "&#38;")+"&strSubject=JS_ISC-EXCEPTION&bIsHtmlMsg=true";
//		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
//   }
//   catch(ex){/*carry on*/}
//}

//function isc_notification(objType,task,sectionId,result)
//{
//	/* THIS FUNCTION OVERRIDE FIXES A DISPLAY QUIRK WITH IE6 */
//    switch (objType) 
//    {
//         case "Section":
//            switch (task)
//            {
//                case "Selected":
//                    if (returnObj("divDetailedIMapInstructionsWrapper").style.display=="")
//                    {
//                        showHideMapInstructions('hide');
//					}
//					break;
//			}
//			break;
//	}
//	isc_notification2(objType,task,sectionId,result);
//}

//function isc_notification2(objType,task,sectionId,result){
//    try
//        { 
//        switch (objType) 
//        {
//            case "Band":
//                switch (task) {
//                    case "Visible":
//                        // result = true / false
//                        break;
//                }
//                break;
//             case "Movie":
//                switch (task) {
//                    case "Stage":
//                        // result = <scale> Invalid, Set to <scale>
//                        break;
//                }
//             case "Section":
//                switch (task) {
//                    case "Highlight":
//                        /// result = highlighed / normal */
//                        break;
//                    case "Rollover":
//                        /* result = On / Off */
//                        break;
//                    case "Selected":
//                        /* result = true / false */
//                        TL_Interaction('Seating Chart Clicked');
//                        var IMCookie = "IM_" + getPageName().toUpperCase();
//                        if(readCookie(IMCookie)!='' && readCookie(IMCookie)!=null)//cookie exists - so append it
//                        {
//                           var old_cookie = readCookie(IMCookie);
//                           eraseCookie(IMCookie);
//                           if (old_cookie.indexOf("'" + sectionId + "_'") != -1)
//                           {   
//                               old_cookie = old_cookie.replace("'"+sectionId + "_'", ""); 
//                               createCookie(IMCookie, old_cookie)
//                               filterBySection(readCookie(IMCookie));   
//                           }
//                           else
//                           {
//                                createCookie(IMCookie, old_cookie+"'"+sectionId+"_'");
//                                filterBySection(readCookie(IMCookie));  
//                            }
//                        }
//                        else
//                        {  
//                            createCookie(IMCookie, "'"+sectionId+"_'");                             
//                            filterBySection(readCookie(IMCookie));  
//                        }
//                        break;
//                    case "Status":
//                        /* result = not found */
//                        break;
//                }
//                break;
//            case "SectionNames":
//                switch (task) {
//                    case "Visible":
//                        /* result = true / false */
//                        break;
//                }
//                break;
//            case "Venue":
//                switch (task) {
//                    case "Status":
//                        /* result = loaded, error loading venue <name>, Error <desc> */
//                        break;
//                }
//                break;
//        }
//}
//catch(ex)
//{
//    var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_isc_Notification&bIsHtmlMsg=true";  
//    ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);    
//}      
//}

// function  filterBySection(sectionNames)
// {
//    try
//    {
//        var strSortDirection = "ASC";
//        var strSortField = "Price";
//        strSortField=returnObj("hidSortField").obj.value;
//        strSortDirection=returnObj("hidSortDirection").obj.value;

//        var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetTicketList";
//        var nBrokerID = returnObj("hidBrokerId").obj.value;
//        var nEventID = returnObj("hidEventId").obj.value;
//        var nMinPrice = returnObj("ddMinPrice").obj.options[returnObj("ddMinPrice").obj.selectedIndex].value;
//        var nMaxPrice = returnObj("ddMaxPrice").obj.options[returnObj("ddMaxPrice").obj.selectedIndex].value;
//        var nQty = returnObj("ddFilterQty").obj.options[returnObj("ddFilterQty").obj.selectedIndex].value;
//        var strFilter = returnObj("hidFilter").obj.value;
//        var strFilterParking = returnObj("chkFilterParking").obj.checked.toString(); 
//        var bTransform = "true"; 

//        showHide("divTicketListingsLoading","show");
//        showHide("divTicketListings","hide");
//        showHide("divTicketListingsAjax","hide"); 
//        showHide("divTicketFilters","hide");
//        showHide("divTicketColumnHeaders","hide"); 
//        showHide("divTicketSummary","hide"); 

//        var strParams = "BrokerID="+nBrokerID+"&EventID="+nEventID+"&MinPrice="+nMinPrice+"&MaxPrice="+nMaxPrice+"&Qty="+nQty+"&Sort="+strSortField+" "+strSortDirection+"&Filter="+strFilter+"&Transform="+bTransform+"&SectionList="+sectionNames+"&FilterParking="+strFilterParking;
//        ajaxPost(strParams,strServiceURL,"renderTickets");	   
//    }
//    catch(ex)
//    {
//        var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_filterBySection&bIsHtmlMsg=true";  
//        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);    
//    }	    
// }

// function reloadFlashMap()
// {
//    try
//    {
//        var IMCookie = "IM_" + getPageName().toUpperCase();
//	    
//        eraseCookie(IMCookie); 	 /* Start Fresh */
//        
//        isc_clearSelected();
//     }
//    catch(ex)
//    {
//        var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_reloadFlashMap&bIsHtmlMsg=true";  
//        ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);    
//    }         

// }
//function showHideMapInstructions(method)
//{ 
//    if(method=="show")
//    { 
//        returnObj("divTicketListingsWrapper").style.display="none";
//        returnObj("divDetailedIMapInstructionsWrapper").style.display="";
//    }
//    else /*hide*/
//    {
//        returnObj("divDetailedIMapInstructionsWrapper").style.display="none";
//        returnObj("divTicketListingsWrapper").style.display="";
//    }
//}


////call from flex
//function onISCItemSelect(tickets) {
//    selectedSection = tickets.slice();
//    filterBySection(getSections(selectedSection));
//}
////call from flex
//function onISCItemDeselect(tickets, affected) {
//    selectedSection = tickets.slice();
//    filterBySection(getSections(selectedSection));
//}

//function getSections(ticketsList) {
//    var sections = "";
//    for (var i = 0; i < ticketsList.length; i++) {
//        sections += $("#s" + selectedSection[i]).text() + ","
//    }
//    return sections;
//}
