﻿var iNumSpecialNeedsSeats = 0;

function setSpecialNeeds(sNumSeats)
{
	iNumSpecialNeedsSeats = parseInt(sNumSeats);	
}

function FSCTGetCartPerformanceInfo( iPerfNo )
{
	var req = getreq();
	this.handler = function()
	{
		if (req.readyState == 4)
		{
			var result = JSON.parse(req.responseText);
			// alert(req.responseText);
			try
			{
				result = result.d;
				CartInfo = result;
			}
			catch (e)
			{
				CartInfo = null;
			}
			callSyosGetSeatsforZone = true;
			getPerformanceDetails(iPerfNo, true);
		}
	}

	req.open("POST", ( srvr + ORG_PATH + "handler.asmx/FSCTGetCartPerformanceInfo" ), true);
	req.setRequestHeader( CONTENT_TYPE, APP_JSON);
	req.onreadystatechange = this.handler;
	var sendObj = { perf_no: iPerfNo }; // 0 was currentZoneNumber -- always get all zones
	req.send(  JSON.serialize( sendObj) );
}



function displayPerformanceDetails(oPerfDetails)
{
	if ( oPerfDetails.Success )
	{
		currentPerformanceDetails = oPerfDetails;
		
		$('#performance_details_label').html("<span style='padding: 0 3px; background-color: #ddd'>Availability/Pricing: <b>" + oPerfDetails.Title + "</b> &ndash; " + oPerfDetails.Date + "</span>" );
		
		var quantitytable ="<table cellspacing='0' class='qtySelection' id='quantitytable'>";
		var pricetypetable = "<table cellspacing='0' class='pricetypeSelection' id='pricetypetable'><tr><th class='head'>Available Pricing</th></tr>";
		
		quantitytable += "<tr><th class='head'>Price</th><th class='head'>Quantity</th></tr>";
		
		if ( oPerfDetails.ZonePricingItems[0].Prices.length == 1 )
		{
			currentPriceTypeId =  oPerfDetails.ZonePricingItems[0].Prices[0].PriceTypeId;
			pricetypetable = "";
		}
		
		if ( oPerfDetails.ZonePricingItems.length == 1 )
		{
			currentZoneNumber = oPerfDetails.ZonePricingItems[0].ZoneNo;
		}
		
		for (var x=0; x < oPerfDetails.ZonePricingItems[0].Prices.length; x++ )
		{
			
			quantitytable += "<tr><th>" +  oPerfDetails.ZonePricingItems[0].Prices[x].PriceTypeName.replace(/FST /,"");
			quantitytable += "</th><td><select size='1' onchange='selectPriceTypeQuantity(" + oPerfDetails.ZonePricingItems[0].Prices[x].PriceTypeId + ",this.options[this.selectedIndex].value)'>";
			quantitytable += "<option value='0'>&nbsp;</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option>";
			quantitytable += "<option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option>";
			quantitytable += "</select></td>\r\n"
			
			if ( currentPriceTypeId == 0 )
			{
				pricetypetable += "<tr><td><input type='radio' name='currentPriceType' onclick='setCurrentPriceType(" + oPerfDetails.ZonePricingItems[0].Prices[x].PriceTypeId +  ")'>&nbsp;";
				pricetypetable += oPerfDetails.ZonePricingItems[0].Prices[x].PriceTypeName.replace(/FST /,"") + "</td></tr>"
			}
		}


		quantitytable += "</table>";
		// if ( pricetypetable.length > 0 )

		var floor_selection = "<table id='venue_section' cellspacing='0' style='display: inline; float:right;'><tr><th class='head'>Venue Section</th></tr><tr><td><input id='syos_map_id1' type='radio' onclick='change_view(1)' name='syos_map_selection' /> Main Floor</td></tr><tr><td><input id='syos_map_id2' type='radio' onclick='change_view(2)' name='syos_map_selection' /> Balcony</td></tr></table>";
		
		pricetypetable = "<div>" + floor_selection + pricetypetable + "</table>" + quantitytable + "</div>";
		
		var purchase_button = "<span class='action cancel' onclick='toggle_syosholder(\"hide\")' style='float: right;' title='Cancels all reserved seats for this performance'>Cancel these tickets</span>" 
		purchase_button += "<input type='button' disabled='true' id='btnPurchase' value='Confirm Tickets' style='display: block; margin-top: 6px;' onclick='doPurchaseTickets()'/>"
		
		var confirmationPanel = "<h3 style='margin: 6px 0;'>Your current seats for this performance</h3><div>";
		confirmationPanel += "<div id='currentLines'>" + clickOnDotsMessage + "</div>"; //"<div' id='currentLines'>"
		confirmationPanel += purchase_button;
		confirmationPanel += "</div>";
		
		$('#performance_details').html("<div id='tktSelection'>" + pricetypetable + confirmationPanel + "</div>");
		toggle_performance_details();
		// $("#tktSelection").accordion();
		if ( currentPerformanceCartItems && currentPerformanceCartItems.length > 0 )
		{
			for (var x=0; x < currentPerformanceCartItems.length; x++ )
				if ( currentPerformanceCartItems[x].PerformanceNumber == target_perf_no ) // currentSeatingInfo.perf_no
				{
					formatLines(currentPerformanceCartItems[x]);
					break;
				}
		}
		addShadow('performance_details_holder');

	}
}

// returns a formatted string of section & current price
function getZoneInfo(iZoneNo, iSectionNo, rowseat )
{
	for( var x=0; x < currentPerformanceDetails.ZonePricingItems.length; x++ )
		if ( currentPerformanceDetails.ZonePricingItems[x].ZoneNo == iZoneNo )
		{		
			var retval = "";
			
			for ( var y=0; y < currentSeatingInfo.SeatingInfo.Sections.length; y++ )
				if ( currentSeatingInfo.SeatingInfo.Sections[y].ID == iSectionNo )
				{
					retval = currentSeatingInfo.SeatingInfo.Sections[y].Description + " ";
				}
				
			if ( retval.length == 0 )
				retval = currentPerformanceDetails.ZonePricingItems[x].Description + " ";
			// if ( rowseat != null )
			//	retval += rowseat + ": ";
			for (var y = 0; y < currentPerformanceDetails.ZonePricingItems[x].Prices.length; y++ )
				if ( currentPriceTypeId == 0 || currentPriceTypeId == currentPerformanceDetails.ZonePricingItems[x].Prices[y].PriceTypeId )
				{
					retval += ( y == 0 ? " " : ", " ); 
					if ( currentPerformanceDetails.ZonePricingItems[x].Prices[y] )
					{
						retval += currentPerformanceDetails.ZonePricingItems[x].Prices[y].PriceString + " ";
						if ( currentPriceTypeId == currentPerformanceDetails.ZonePricingItems[x].Prices[y].PriceTypeId )
							retval += "[" + currentPerformanceDetails.ZonePricingItems[x].Prices[y].PriceTypeName + "]";
					}
				}
			return retval;
		}
	return "";
}

