var clearedInputList = new Array();

function clearInputBox(elementID)
{
	var clearInput = true;

	for(var i = 0; i < clearedInputList.length; i ++)
	{
		if(clearedInputList[i] == elementID)
			clearInput = false;
	}

	if(clearInput)
	{
		document.getElementById(elementID).value = '';
		clearedInputList[clearedInputList.length] = elementID;
	}
}

function submitGalleryDatePickerForm()
{
	$('#date-picker-form').submit();

	return false;
}

function showEventPopup(eventID, position)
{
	$('#event_' + eventID).css('top', (position.top + 20));
	$('#event_' + eventID).css('left', (position.left + 30));
	$('#event_' + eventID).css('z-index', 20);

	$('#event_' + eventID).toggle();
}

function bindEventHoverLayers()
{
	$('a.event-link').each(function () {

		$(this).mouseover(function() { showEventPopup($(this).attr('id'), $(this).position()); return false; }).mouseout(function() { showEventPopup($(this).attr('id'), $(this).position()); return false; });
		$(this).css('z-index', 1);

		}
	);

	return false;
}

function showConfirmationBox(question, redirectURL)
{
	if(typeof document.body.style.maxHeight === "undefined")
	{
		//if IE 6
		$('body','html').css({height: '100%', width: '100%'});
		$('html').css('overflow', 'hidden');
	}
	
	$('body').append('<div id="confirmation-overlay"></div><div id="confirmation-window"></div>');

	$("#confirmation-overlay").click(hideConfirmationBox);

	$('#confirmation-overlay').addClass('confirmation-overlay-bg');

	var html = '<div class="confirmation-window-content">';
	html += '	<h2>Confirm</h2>';
	html += '	<p>' + question + '</p>';
	html += '	<div class="confirmation-button-block">';
	html += '		<a id="confirmation-ok-button">Yes</a>';
	html += '		<a id="confirmation-cancel-button">No</a>';
	html += '		<div class="break"></div>';
	html += '	</div>';
	html += '</div>';

	$('#confirmation-window').append(html);

	document.onkeydown = function(e){ 	

		if(e == null)
		{
			// ie
			keycode = event.keyCode;
		}
		else
		{
			// mozilla
			keycode = e.which;
		}

		if(keycode == 27)
		{
			// close
			hideConfirmationBox();
		}
	};

	$('#confirmation-cancel-button').click( function () { hideConfirmationBox(); return false; } );
	$('#confirmation-ok-button').click( function () { hideConfirmationBox(); window.location.href = redirectURL; } );

	$("#confirmation-window").css( { display:'block' } ); //for safari using css instead of show
}

function hideConfirmationBox()
{
	$("#confirmation-window").fadeOut("fast", function() { $('#confirmation-window,#confirmation-overlay').trigger("unload").unbind().remove(); } );
}

$(document).ready(
	function()
	{
		$('.box').focus( function () { $(this).addClass('box-focussed'); } ).blur( function (){ $(this).removeClass('box-focussed'); } );
		$('.halfbox').focus( function () { $(this).addClass('halfbox-focussed'); } ).blur( function (){ $(this).removeClass('halfbox-focussed'); } );
		$('.quarterbox').focus( function () { $(this).addClass('quarterbox-focussed'); } ).blur( function (){ $(this).removeClass('quarterbox-focussed'); } );
		$('.textinput').focus( function () { $(this).addClass('textinput-focussed'); } ).blur( function (){ $(this).removeClass('textinput-focussed'); } );

		// Put confirmations on all remove links....
		$('a.remove-link').click( function () { showConfirmationBox($(this).attr('title'), $(this).attr('href') ); return false; } );
	}
);

function bookingFormInit()
{
	if(!$('#booking_form_container').hasClass('showme'))
		$('#booking_form_container').hide();
	
	$('input[name="BookingContentObjectID"]').click( function () {

				$('label.booking-label').each( function () {

						$(this).removeClass('booking-label-hightlight');
					}
				);

				$(this).parent().addClass('booking-label-hightlight');

				if($(this).val() == 'other')
					$('#booking_form_container').slideDown();
				else
					$('#booking_form_container').hide();

			}
	);


	$('input[name="ticket_type"]').click( function () {

				$('label.ticket-label').each( function () {

						$(this).removeClass('ticket-label-hightlight');
					}
				);

				$(this).parent().addClass('ticket-label-hightlight');

			}

	);
}

function promoFormInit()
{
	$('input[name="PromoUserID"]').click( function () {

		$('label.ticket-label').each( function () {

				$(this).removeClass('ticket-label-hightlight');
			}
		);

		$(this).parent().addClass('ticket-label-hightlight');

	});
}