// view content methods

var selectedSection;
var selectedSectionText;
var innerAdHidden = false;
var gameChoiceHidden = true;
var sectionInfoHidden = true;
var GetSectionPricesURL = 'GetSectionPrices.aspx?date=20090831&session=day&xmltype=attribute';;

function playVideo() {
	$('viewflash').playVideo();
}

function pauseVideo() {
	$('viewflash').pauseVideo();
}

function gotoSection(n) {
	try
	{
		n = n.toLowerCase();
		if($('viewflash') != null)
		{		    
			$('viewflash').gotoSectionID(n);			                       
		}
	}
	catch(e)
	{
		//
	}
	return false;
}

function gotoSectionVideo(flashSectionId) 
{
	try
	{
		if($('viewflash') != null)
		{		
			$('viewflash').gotoSectionVideo(flashSectionId);
			document.getElementById('view_flashcontent').style.height = "470px";
		}
	}
	catch(e)
	{
	}
	return false;
}

function hideElement(idLoading,idFrame)
{
    if(document.getElementById(idLoading) != null && document.getElementById(idFrame) != null)
    {
        document.getElementById(idLoading).style.display = "none";
        document.getElementById(idFrame).height= "480px";
    }
    return;
}


function convertDateToYYYYMMDD(date)
{
     if(date == '' || date == undefined)
        date = '08/31/2009';
    var dateArray = date.split("/");
    
    var month = dateArray[0] + '';
    if(month.length <2)
        month = '0' + month;
    
    var day = dateArray[1] + '';
    if(day.length <2)
        day = '0' + day;
        
    return dateArray[2] + month + day;
}

function updateSectionMenu(sectionOnClick, sectionText)
{
    if(selectedSectionText) 
    {
		document.getElementById("mitem1").innerHTML = sectionText + '&#187;';
		document.getElementById("mitem1").style.display = "block";
		document.getElementById("mitem2").style.display = "block";
	}
	else 
	{
		document.getElementById("mitem1").style.display = "none";
		document.getElementById("mitem2").style.display = "none";
	}   
}

function saveHiddenInfo(date, session)
{
    var hidDate = 'ctl00_ContentPlaceHolder1_DynamicSectionInfo1_selectedDate';		
	var hidSession = 'ctl00_ContentPlaceHolder1_DynamicSectionInfo1_selectedSession';
	
	document.getElementById(hidDate).value = date;
	document.getElementById(hidSession).value = session;
}

function lnkDayClick(date, session, controlId, args)
{
    saveHiddenInfo(date, session);
    var yyyymmdd = convertDateToYYYYMMDD(date);
    GetSectionPricesURL = 'GetSectionPrices.aspx?date=' + yyyymmdd + '&session=' + session.toLowerCase() + '&xmltype=attribute';
        
    if(document.getElementById('view_seatinfo') != null && document.getElementById('view_seatinfo').style.display != "none")
    {
        sectionInfoHidden = false;
    }
    else
    {
        sectionInfoHidden = true;
    }
    
    gotoSection(GetSectionPricesURL);    
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(EffectsForDayClick);
    prm._doPostBack(controlId, args);
 }

function btnSessionClick(session, controlId)
{
    saveHiddenInfo($('ctl00_ContentPlaceHolder1_DynamicSectionInfo1_selectedDate').value, session);
    var yyyymmdd = convertDateToYYYYMMDD($('ctl00_ContentPlaceHolder1_DynamicSectionInfo1_selectedDate').value);
    
    if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null && document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice').style.display != "none")
    {
        gameChoiceHidden = false;
    }
    else
    {
        gameChoiceHidden = true;
    }
    
    if(document.getElementById('view_seatinfo') != null && document.getElementById('view_seatinfo').style.display != "none")
    {
        sectionInfoHidden = false;
    }
    else
    {
        sectionInfoHidden = true;
    }
    
    GetSectionPricesURL = 'GetSectionPrices.aspx?date=' + yyyymmdd + '&session=' + session.toLowerCase() + '&xmltype=attribute';
    gotoSection(GetSectionPricesURL);
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(EffectsForSessionClick);
    prm._doPostBack(controlId, '');
 }

function SetSeat(n)
{
	if( document.getElementById('DynamicSeatSelector1_idSeat') != null)
		document.getElementById('DynamicSeatSelector1_idSeat').value = n;
	
	if( document.getElementById('DynamicSectionInfo1_seatId') != null)
		document.getElementById('DynamicSectionInfo1_seatId').value = n;
}

function gotoMap(which) {
	
	document.getElementById('view_flashcontent').style.height = "630px";

	$('viewflash').ExternalConnection(which);
	
	if(which == 0) {
		$('flashtitle').innerHTML = 'Seating Chart - Arena Bowl';
	}
	
	if(which == 1) {
		$('flashtitle').innerHTML = 'Seating Chart - Floor Seating';
	}
	
	if($('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null && !gameChoiceHidden)
	{
		Element.show('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice');
	}
	
//	if(selectedSection) {
//		Element.show('menu1');
//		Element.show('menu2');
//		$('menu1').innerHTML = '<img src="Images/filmIcon.gif" align="bottom" /> Section ' + selectedSection + "&raquo;";
//		$('qmim1').innerHTML = '<img src="Images/filmIcon.gif" align="bottom" /> Section ' + selectedSection + "&raquo;";
//	} else {
//		Element.hide('menu1');
//		Element.hide('menu2');
//	}
	return false;
}

function gotoCenterCourt() {
	document.getElementById('view_flashcontent').style.height = "470px";
	$('viewflash').ExternalConnection(2);
	$('flashtitle').innerHTML = '360&deg; View';

	return false;
}

function gotoAmenities() {
	document.getElementById('view_flashcontent').style.height = "600px";
	$('viewflash').showAmenities();
	$('flashtitle').innerHTML = "Amenities";
	updateSectionMenu(selectedSection, selectedSectionText);

	return false;
}

function BlindUpCalendar(callback)
{
	if(gameChoiceHidden)
	{
		if(innerAdHidden)
		{
			BlindDownCalendar();
		}
		else
		{
			innerAdHidden = true;
			new Effect.BlindUp('innerad', {duration:0.5, afterFinish:callback});
		}
	}
	else
	{
		if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
		{
			new Effect.BlindUp('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5, afterFinish:callback});	
		}
		else
		{
		    callback();
		}
	}
}		  

function BlindDownCustomAddressAndGeneralDirections()
{
	if(document.getElementById("custom_address") != null)
	{
        new Effect.BlindDown('custom_address', {duration:0.5});
    }
    
    if(document.getElementById("dir_general") != null)
	{
        new Effect.BlindDown('dir_general', {duration:0.5});
    }
}

function BlindUpCustomParking()
{
	if(document.getElementById("custom_parking") != null)
	{
        new Effect.BlindUp('ctl00_ContentPlaceHolder1_DynamicDirections1_upParkingDetail', {duration:0.5});
        new Effect.BlindUp('custom_parking', {duration:0.5});
    }
}

function BlindDownCustomParking()
{
	if(document.getElementById("custom_parking") != null)
	{
        new Effect.BlindDown('ctl00_ContentPlaceHolder1_DynamicDirections1_upParkingDetail', {duration:0.5});
        new Effect.BlindDown('custom_parking', {duration:0.5});
    }
}
 
function BlindUpYourDirections(callback)
{
	if(document.getElementById("ctl00_ContentPlaceHolder1_DynamicDirections1_upYourDirections") != null)
	{
        new Effect.BlindUp('ctl00_ContentPlaceHolder1_DynamicDirections1_upYourDirections', {duration:0.5});
    }
}

function EffectsForDayClick()
{
    gameChoiceHidden = false;
	
    if(!innerAdHidden && document.getElementById('innerad') != null)
	{
	    innerAdHidden = true;
	    new Effect.BlindUp('innerad', {duration:0.5});
	}
	
	if(document.getElementById('sectionInfo') != null)
	{
//	    new Effect.BlindUp('sectionInfo', {duration:0.5});
	}
	
    if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
    {
	    new Effect.BlindDown('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5});
    }
    
//    if(document.getElementById('calendarmodule') != null)
//    {
//	    new Effect.BlindDown('calendarmodule', {duration:0.5});
//    }

    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(EffectsForDayClick);
}

function EffectsForSessionClick()
{
    if(innerAdHidden && !gameChoiceHidden && document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
    {
//        if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice').style.display != "none")
//	    {
	        new Effect.BlindDown('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5});
//	    }
    }
    
    if(!sectionInfoHidden && document.getElementById('view_seatinfo') != null)
	{
	    sectionInfoHidden = false;
        new Effect.BlindUp('view_seatinfo', {queue: {position:'front', scope: 'contentScope'} });
        new Effect.BlindDown('view_seatinfo', {queue: {position:'end', scope: 'contentScope'} });
	}
    
    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(EffectsForSessionClick);
}


function EffectsForSectionClick()
{
    if(!innerAdHidden && document.getElementById('innerad') != null)
	{
	    innerAdHidden = true;
	    new Effect.BlindUp('innerad', {duration:0.5});
	}
	
//	if(document.getElementById('calendarmodule') != null)
//    {
//	    new Effect.BlindDown('calendarmodule', {duration:0.5});
//    }
    
	if(document.getElementById('view_seatinfo') != null)
	{
	    sectionInfoHidden = false;
        new Effect.BlindUp('view_seatinfo', {queue: {position:'front', scope: 'contentScope'} });
        new Effect.BlindDown('view_seatinfo', {queue: {position:'end', scope: 'contentScope'} });
	}
	
//	if(document.getElementById('sectionInfo') != null)
//	{
//	    new Effect.BlindDown('sectionInfo', {duration:0.5});
//	}
	
    if(!gameChoiceHidden && document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
    {
        gameChoiceHidden = true;
	    new Effect.BlindUp('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5});
    }
    
	var ctrlSectionDescription = document.getElementById('ctl00_ContentPlaceHolder1_DynamicSectionInfo1_sectionDescription');
	if(ctrlSectionDescription != null)
	{
	    $('flashtitle').innerHTML = 'Seat View - ' + ctrlSectionDescription.value;
	    selectedSectionText = ctrlSectionDescription.value;
	}
	updateSectionMenu(selectedSection, selectedSectionText);
	
    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(EffectsForSectionClick);
}

function BlindDownCalendar()
{
	gameChoiceHidden = false;
	if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
	{
		new Effect.BlindDown('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5});
		closeSectionInfo();
		closeCalendar();
	}
}


function showInput(n) {
	if(n != "undefined" && n != null) 
	{		
		document.getElementById('view_flashcontent').style.height = "470px";
		selectedSection = n.toLowerCase();
		var ctrlName = 'ctl00_ContentPlaceHolder1_DynamicSectionInfo1_sectionId';		
				
		if(document.getElementById(ctrlName) != null)
		{
		    if(document.getElementById(ctrlName).value != selectedSection)
		    {
			    document.getElementById(ctrlName).value = selectedSection;
			    var panelId = "ctl00_ContentPlaceHolder1_DynamicSectionInfo1_upDynamicSectionInfo";
                
                var prm = Sys.WebForms.PageRequestManager.getInstance();
                prm.add_endRequest(EffectsForSectionClick);
                prm._doPostBack(panelId,'');
            }
            else
            {
                EffectsForSectionClick();
            }
        }
        else
        {
//			Element.show('menu1');
//			Element.show('menu2');
        }
		
		if(!gameChoiceHidden)
		{
			if(document.getElementById('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice') != null)
			{
				new Effect.BlindUp('ctl00_ContentPlaceHolder1_DynamicCalendar1_view_gamechoice', {duration:0.5});	
			}
		}
	}
}

function ShowDirections2()
{
   	Element.show('dir_ad1');
	Element.hide('custom_address');
}


function getSelectedSection() {
	if(selectedSection) {
		gotoSection(selectedSection);
	} else {
		gotoMap();	
	}
}

function openCalendar()
{
	new Effect.BlindDown('calendarmodule', {duration:0.5});
	Element.show('view_calendar_close');
	Element.hide('view_calendar_open');
}

function closeCalendar()
{
	new Effect.BlindUp('calendarmodule', {duration:0.5, afterFinish:nd});
	Element.hide('view_calendar_close');
	Element.show('view_calendar_open');
}

function openCalendarDetail()
{
	new Effect.BlindDown('calendarDetail', {duration:0.5});
	Element.show('view_calendardetail_close');
	Element.hide('view_calendardetail_open');
}

function closeCalendarDetail()
{
	new Effect.BlindUp('calendarDetail', {duration:0.5});
	Element.hide('view_calendardetail_close');
	Element.show('view_calendardetail_open');
}

function openSectionInfo()
{
	new Effect.BlindDown('sectionInfo', {duration:0.5});
	Element.show('view_section_close');
	Element.hide('view_section_open');
}

function closeSectionInfo()
{
	new Effect.BlindUp('sectionInfo', {duration:0.5});
	Element.hide('view_section_close');
	Element.show('view_section_open');
}

function PageQuery(q)
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}

	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	
	this.getValue = function(s) 
	{
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}

	this.getParameters = function() 
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}

	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key)
{
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}