﻿function highlightTickets(e,bool)
{
	if(bool=="TRUE")
	{ 
		e.style.backgroundColor="#fff69d";
	}
	else
	{
		 e.style.backgroundColor="#ffffff";
	}  
}

function sortColumn(x)
{
 try
	{
	var strSort = "Up";
	if(returnObj("imgSortUp"+x).style.display!="none")
	{
		 strSort = "Down";
	}
	var strImgs = "S,R,Q,P".split(",");
	var n;
	var IMCookie = "IM_" + getPageName().toUpperCase();      
	for(n in strImgs)
	{
		returnObj("imgSortUp"+strImgs[n]).style.display="none";
		returnObj("imgSortDown"+strImgs[n]).style.display="none";
		returnObj("imgSortDown"+strImgs[n]+"x").style.display="inline";
	}
	returnObj("imgSortDown"+x+"x").style.display="none"; 
	returnObj("imgSort"+strSort+x).style.display="inline";
   
	returnObj("divTicketHeaderSection").style.background="url('/site-images/global/tl_column_bgX.png')";
	returnObj("divTicketHeaderRow").style.background="url('/site-images/global/tl_column_bgX.png')";
	returnObj("divTicketHeaderPrice").style.background="url('/site-images/global/tl_column_bgX.png')";
	returnObj("divTicketHeaderQty").style.background="url('/site-images/global/tl_column_bgX.png')";
	 
   
	var strSortField = "Price";
	switch(x)
	{
		case "S":
			strSortField = "Section";
			break;
		case "R":
			strSortField = "Row";
			break;
		case "Q":
			strSortField = "Qty";
			break;
		case "P":
			strSortField = "Price";
			break;
	}
	returnObj("divTicketHeader"+strSortField).style.backgroundImage="url('/site-images/global/tl_column_bg.png')";
	
	var strSortDirection = "ASC";
	if(strSort=="Down"){strSortDirection="DESC";}
   
	cmCreateConversionEventTag('Sort '+strSortField+' '+strSortDirection,'2','Ticket Listing Display');
	TL_Interaction('Sort '+strSortField+' '+strSortDirection);

	returnObj("hidSortField").obj.value=strSortField;
	returnObj("hidSortDirection").obj.value=strSortDirection;

	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 bTransform = "true"
	var strSections = readCookie(IMCookie); 
   var bFilterParking = returnObj("hidFilterParking").obj.value;

	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="+strSections+"&FilterParking="+bFilterParking;
	ajaxPost(strParams,strServiceURL,"renderTickets");
   }
   catch(ex)
   {
		var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_sortColumn [" + x + "]&bIsHtmlMsg=true";
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }
}

function renderTickets(xml)
{
	/*alert(xml);*/
	try
	{
		returnObj("divTicketListings").obj.innerHTML=xml;
		showHide("divTicketListingsAjax","hide");
		showHide("divTicketFilters","show");
		showHide("divTicketColumnHeaders","show");
		showHide("divTicketSummary","show");
		showHide("divTicketListingsLoading", "hide");
		showHide("divTicketListings", "show");

        /*fix for ajax return below (complete with ID stu stu stutter) */
		if ($('#threedee').hasClass('largeView')) {
		    $('#divTicketListings #divTicketListings').css('height', '668px');
		}
	}
   catch(ex)
   {
		var strException = getDebugInfo()+getExceptionInfo(ex)+"<textarea rows=\"10\" cols=\"100\">"+xml.toString()+"</textarea>";
		var strParams = "strErrorMsg="+strException+"&strSubject=JS_Exception_renderTickets&bIsHtmlMsg=true";  
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }    
}

function filterTickets(type)
{
	try
	{
		showHide("divTicketListingsLoading","show");
		showHide("divTicketListings","hide");
		showHide("divTicketListingsAjax","hide");
		showHide("divTicketFilters","hide");
		showHide("divTicketColumnHeaders","hide");
		showHide("divTicketSummary","hide"); 
	 
		var IMCookie = "IM_" + getPageName().toUpperCase();      
		var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/GetTicketList";
		var nBrokerID = returnObj("hidBrokerId").obj.value;
		var nEventID = returnObj("hidEventId").obj.value;
		var strSections = readCookie(IMCookie); 
		
		var nMinPrice = 0;
		var nMaxPrice = 0;
	   
		switch(type)
		{
			case "MIN":
				if(returnObj("ddMinPrice").obj.selectedIndex>returnObj("ddMaxPrice").obj.selectedIndex)
				{
					returnObj("ddMaxPrice").obj.selectedIndex=returnObj("ddMinPrice").obj.selectedIndex
				}
				break;
			case "MAX":
				if(returnObj("ddMinPrice").obj.selectedIndex>returnObj("ddMaxPrice").obj.selectedIndex)
				{
					returnObj("ddMinPrice").obj.selectedIndex=returnObj("ddMaxPrice").obj.selectedIndex
				}
				break;
		}
		
		nMinPrice = returnObj("ddMinPrice").obj.options[returnObj("ddMinPrice").obj.selectedIndex].value; 
		nMaxPrice = returnObj("ddMaxPrice").obj.options[returnObj("ddMaxPrice").obj.selectedIndex].value;

		var nQty = returnObj("TicketListings_ddFilterQty").obj.options[returnObj("TicketListings_ddFilterQty").obj.selectedIndex].value;
		var strSortField = returnObj("hidSortField").obj.value;
		var strSortDirection = returnObj("hidSortDirection").obj.value;
		var strFilter = returnObj("hidFilter").obj.value;
		var bTransform = "true";
		
		returnObj("hidFilterParking").obj.value = returnObj("chkFilterParking").obj.checked;
		var bFilterParking = returnObj("hidFilterParking").obj.value;
		
		cmCreateConversionEventTag('Filter '+type+(type=='QTY'?' '+nQty:''),'2','Ticket Listing Display');
		TL_Interaction('Filter '+type+(type=='QTY'?' '+nQty:''));

		var strParams = "BrokerID="+nBrokerID+"&EventID="+nEventID+"&MinPrice="+nMinPrice+"&MaxPrice="+nMaxPrice+"&Qty="+nQty+"&Sort="+strSortField+" "+strSortDirection+"&Filter="+strFilter+"&Transform="+bTransform+"&SectionList="+strSections+"&FilterParking="+bFilterParking;
		ajaxPost(strParams,strServiceURL,"renderTickets");
   }
   catch(ex)
   {
		var strException = getDebugInfo()+getExceptionInfo(ex);
		var strParams = "strErrorMsg="+strException+"&strSubject=JS_Exception_filterTickets [" + type + "]&bIsHtmlMsg=true";  
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }
}

function initSortColumn()
{
	try
	{
		var strSortD;
		if(returnObj("hidDefaultSortDirection").obj.value=="ASC")
		{
			strSortD="Up";
		}
		else
		{
			strSortD="Down";
		}
		var x = returnObj("hidDefaultSortField").obj.value.substring(0,1);
		returnObj("imgSort"+strSortD+x).style.display="inline";
		returnObj("imgSortDown"+x+"x").style.display="none";

		var strSortField = "Price";
		switch(x)
		{
			case "S":
				strSortField = "Section";
				break;
			case "R":
				strSortField = "Row";
				break;
			case "Q":
				strSortField = "Qty";
				break;
			case "P":
				strSortField = "Price";
				break;
		} 
		returnObj("divTicketHeader"+strSortField).style.backgroundImage="url('/site-images/global/tl_column_bg.png')";
   }
   catch(ex)
   {
		var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_initSortColumn&bIsHtmlMsg=true";  
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }
}

function resetListings()
{
	try
	{
	    var IMCookie = "IM_" + getPageName().toUpperCase();
		if (readCookie(IMCookie) || $("#fvmap") != null)
		{
			reloadFlashMap(); 
		}
		if (returnObj("divDetailedIMapInstructionsWrapper").style.display=="")
		{
			showHideMapInstructions('hide');                              
		}        
		returnObj("ddMinPrice").obj.selectedIndex=0;
		returnObj("ddMaxPrice").obj.selectedIndex=returnObj("ddMaxPrice").obj.options.length-1;
		returnObj("TicketListings_ddFilterQty").obj.selectedIndex = 0;
		sortColumn(returnObj("hidDefaultSortField").obj.value.substring(0,1));
   }
   catch(ex) {
		var strParams = "strErrorMsg="+getDebugInfo()+getExceptionInfo(ex)+"&strSubject=JS_Exception_resetListings&bIsHtmlMsg=true";  
		ajaxPost(strParams,location.protocol+"//"+location.hostname+"/ws/tcws.asmx/LogError", null);
   }        
}

function TicketSignup (emailID, email, brokerID, rttID)
{

	if(validateField(emailID,'show','divBlankEmail2','divBadEmail2', '') && validateEmail(emailID,'divBlankEmail2','divBadEmail2'))
	{
		args = new Array();
		for(n=0; n<arguments.length; n++)
		{
			args[n] = arguments[n];
		}

		var strParams = "RemoteIP="+readCookie("IPAddress")+"&Challenge="+returnObj("recaptcha_challenge_field").obj.value+"&Response="+returnObj("recaptcha_response_field").obj.value;
		var strServiceURL =  location.protocol+"//"+location.hostname+"/ws/tcws.asmx/ReCaptcha";
		ajaxPost(strParams,strServiceURL,"SignupForTix_ReCaptcha",args);
	}
}

function SignupForTix_ReCaptcha()
{
	xml = arguments[0];
	//txtEmail = arguments[1][0];
	strEmail = arguments[1][1];
	nBrokerID = arguments[1][2];
	nRTTID = arguments[1][3];
	
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		parser=new DOMParser();
		xmlDoc=parser.parseFromString(xml,"text/xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
	}
	else
	{
		alert("Your browser is having problems with our website!\n\nPlease call us to resolve this issue.");
		return;
	}

	Recaptcha.reload();

	switch(xmlDoc.getElementsByTagName("ReCaptcha")[0].getAttribute("StatusCode"))
	{
		case "0":

			SignupForTix(strEmail,nBrokerID,nRTTID);
			returnObj("divSuccess").style.display="";

			// reset the form
			bEmailSignupExpanded=false;
			returnObj("txtSignupAlerts").obj.value="";
			returnObj('divReCaptcha').style.display='none';
			returnObj('btnCancelEmailSignUp').style.display='none';
			Recaptcha.destroy();
			break;
		default:
			alert("The words entered into the verification box were incorrect!\n\nPlease try again or call 1-800-521-9616 to speak with a representative.");
			break;
	}
}

function SignupForTix(email, brokerID, rttID)
{
	var strParams = "strCB="+rttID+"&nBrokerID="+brokerID+"&EmailAddress="+email;
	var strServiceURL =  "http://"+location.hostname+"/ws/tcws.asmx/LogNewsLetter";
	ajaxPost(strParams,strServiceURL,"fnNada");
}

function iPhoneAlert()
{
	if((navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i))&&(readCookie("bIPhoneAlert")!="true"))
	{
		createCookie("bIPhoneAlert","true",0);
		showHideModalBG("show");
		showHide("divIPhoneAlertWindowWrapper","show");
		returnObj("divIPhoneAlertWindow").style.left=(returnObj("divMain").obj.offsetLeft+(returnObj("divMain").obj.offsetWidth/2))-(returnObj("divIPhoneAlertWindow").obj.offsetWidth/2)+"px";
		returnObj("aIPhoneAlertHeader").obj.focus(); /*ff,safari*/
	}
	else if(navigator.userAgent.match(/Android/i))
	{
		NoScrollTicketListings();
	}
}

function TL_Interaction(type)
{
	try
	{
		for(x = 1; x<4; x++)
		{
			var TLI = "TL_I_" + x;
			if(readCookie(TLI)=='' || readCookie(TLI)==null)
			{
				createCookie(TLI, type);
				cmCreateConversionEventTag(x+' - '+type,'2','Ticket Listing Interaction');
				x=99;
			}
		}
	}
	catch(ex){/*carry on*/}
}

function NoScrollTicketListings()
{
	returnObj("divTicketListingsWrapper").style.height="100%";
	returnObj("divTicketListings").style.height="100%";
}

$(document).ready(function () {
    /*bottom tabs*/

    var signupContent = $('#signup_content');
    var relatedContent = $('#related_content');

    signupContent.hide();

    $("#email_btn").click(function () {
        $('.tabs li').removeClass('selected_tab');
        $(this).addClass('selected_tab');
        relatedContent.hide();
        signupContent.fadeIn();
    });

    $("#related_btn").click(function () {
        $('.tabs li').removeClass('selected_tab');
        $(this).addClass('selected_tab');
        signupContent.hide();
        relatedContent.fadeIn();
    });

    /*add class so I can update styles for empty results*/
    if ($("#divNoResultsMsg").length > 0) {
        $('#divTicketListings').addClass('noResultsBox');

    }


    /*hide the event notes box when it's empty*/
    var eventNoteOuter = $("#eventNote_outer");

    if (eventNoteOuter.html() == 0) {
        eventNoteOuter.remove();
    }

    if ($("#eventNote_outer #divContentBlockWrapper").html() == 0) {
        eventNoteOuter.remove();
    }

    if ($("#eventNote_outer #TicketListings_pnlSeoContent").html() == 0) {
        eventNoteOuter.remove();
    }

    /*setup note functions*/
    var clickableNotesIcon = $("#divTicketListings .notes_icon");
    var notesContent = $("#divTicketListings .notes_content");

    $('.notes_content').hide();

    clickableNotesIcon.click(function () {
        $(this).hide();
        $(this).siblings().fadeIn();
    });

    clickableNotesIcon.live("click", function () {
        $(this).hide();
        $(this).siblings().fadeIn();
    });



    notesContent.click(function () {
        $(this).hide();
        $(this).siblings().fadeIn();
    });
    notesContent.live("click", function () {
        $(this).hide();
        $(this).siblings().fadeIn();
    });


    /*addding to solve IE7 abs. position issue*/
    notesContent.mouseleave(function () {
        $(this).hide();
        $(this).siblings().fadeIn();
    });
});

/*mock up & animated 3d view for fanvenues*/





function isViewSize() {
    if ($(window).height() < 760) {
        return true;
    }
    else {
        return false;
    }
}

$(document).ready(function () {
    var $enhancedPromo = $('#threedee');
    var $picInPic = $('#thumbnail');
    var $seatChart = $('#fvmap');
    var $mapViewTab = $('#map_3dView_tabs div');
    var $tixListing = $('#divTicketListings');
    var $tixListingWrapper = $('#divTicketListingsWrapper');
    var $iconKey = $('#icon_key');
    var $venueKey = $('#venue_key');
    var matrixDisclaimer = '<p class="small mapDisclaimer">All venue maps and seat views are approximate representations.</p>';
    var backToMap = '<a id="backToMap">Seating Chart</a>';


    /*using fanvenues*/
    if ($('#fvmap').length > 0) {
        $('#listing_inner').css('paddingBottom', '18px');
        $('#TicketListings_pnlInteractiveSeatingChart').addClass('seatViewOverflow');
        $('#divSeats').addClass('seatViewOverflow');
        $('#divBtnReset').css('marginTop', '-18px');
        $venueKey.append(matrixDisclaimer);
        /*using fanvenues + small screen*/
        if (isViewSize()) {
            $('#map_3dView_tabs').show();
            $(backToMap).appendTo('#divSeats');
            $('#backToMap').hide();
            $enhancedPromo.addClass('smallView');
            $enhancedPromo.hide();
            $picInPic.show();
            $('#listing_inner').css('height', '550px');

            //$iconKey.css('marginLeft', '0px');
            //$iconKey.css('top', '426px');
        }

        /*using fanvenues + big screen*/
        else {
            $('#map_3dView_tabs').hide();
            $tixListing.css('height', '668px');
            $tixListingWrapper.css('height', '840px');
            $enhancedPromo.addClass('largeView');
            $('#bazaarvoice_outer_wrapper_bg').addClass('ie_bv_largeviewFixer');
            $venueKey.addClass('ie_venueKey_largeviewFixer');
            $venueKey.css('top', '726px');
            $iconKey.css('top', '1026px');
            $enhancedPromo.html('<div id="viewLoader">Select a section on the map above to see the view from those seats.</div>');
            $enhancedPromo.show();
            $picInPic.hide();
        }
    }

    /*using ISC or static imgs*/
    else {
        $picInPic.remove();
        $enhancedPromo.remove();
        $('#map_3dView_tabs').remove();
        $('#listing_inner').css('height', '550px');
        $iconKey.show();
        $venueKey.append(matrixDisclaimer);
        $venueKey.css('margin-left', '480px');
        /*add check for static image*/
        if ($('#TicketListings_pnlTCSeatingChart').length > 0) {
            $('.key_type').addClass('hidden');
        }
    }

    /**handle tab clicks to jump between views*/
    $("#viewTab").click(function () {
        $mapViewTab.removeClass('selected_mapViewTab');
        $(this).addClass('selected_mapViewTab');
        $seatChart.hide();
        $enhancedPromo.fadeIn();
        $('#backToMap').show();
        $picInPic.hide();
    });

    $("#mapTab").click(function () {
        $mapViewTab.removeClass('selected_mapViewTab');
        $(this).addClass('selected_mapViewTab');
        $enhancedPromo.hide();
        $seatChart.fadeIn();
        $picInPic.fadeIn();
        $('#backToMap').hide();
    });

    $('#backToMap').live('click', function () {
        $("#mapTab").trigger('click');
    });



    /*add expand button to tix list for phones since they dont handle interior scrolls like they should*/
    if ((navigator.userAgent.match(/iPhone/i)) ||
   (navigator.userAgent.match(/Android/i)) ||
   (navigator.userAgent.match(/iPod/i)) ||
   (navigator.userAgent.match(/iPad/i))) {
        var tixExpandBtn = '<div id="tixExpandBtn">Expand</div>';
        if ($(window).height() < 800) {
            $('#divTicketColumnHeaders').append(tixExpandBtn);
        }
    }

    /*if there are zero related events, jump to email tab by default*/
    var $relatedContentItems = $('.related_content_items li');
    if ($relatedContentItems.length == 0) {
        $('#email_btn').trigger('click');
        $('#related_btn').hide();
    }
});


/*handle clicks of the expand button*/
$('#tixExpandBtn').live("click", function () {
    $(this).addClass('expandedTixList');
    $(this).text('minimize');
    $('#divTicketListings').animate({ height: '100%' });
    $('#divTicketListingsWrapper').animate({ height: '100%' });
    $('#listing_inner').animate({ height: '100%' });
    $('#listing_inner').css({ paddingBottom: '80px' });
});

$('.expandedTixList').live("click", function () {
    $(this).removeClass('expandedTixList');
    $(this).text('expand');
    $('#divTicketListings').animate({ height: '385px' });
    $('#divTicketListingsWrapper').animate({ height: '460px' });
    $('#listing_inner').animate({ height: '550px' });
    $('#listing_inner').css({ paddingBottom: '20px' });
});

