//<!--

/* escapeOverlay's construction is a bit hard to grasp. It is needed to be able to
stop the event listener. See the prototype API docs for more information:
http://www.prototypejs.org/api/event
*/
var escapeOverlay = {
	fx: function(e) 
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
		
		// If keypressed is escape and the new entry field is empty
		if(kC==Esc && ($F('newvalue') == '' || $F('newvalue') == null) )
			closeDialogue();
		else if(kC==Esc && window.confirm('Are you sure you wish to close the dialogue box?') )
			closeDialogue();
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup(popup)
{
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
	if ((browser == "Microsoft Internet Explorer") && (version < 7)) {
		if (popup == "cart_empty") {
			window.alert("Your shopping cart is currently empty. If you wish to purchase tickets, please browse to an event and add it to your cart using the 'Buy Tickets' option.");
		} else if (popup == "cart_conflict") {
			var choice = window.confirm("Currently, only events from a single venue can be added to your cart. You are attempting to add an event from a venue different than the current contents of your cart. If you continue, your current cart contents will be lost. Do you want to continue?");
			if (choice == true) {
				window.location = pageURL+'&clear=1';
			} else {
				return false;
			}
		} else if (popup == "seats_unavailable") {
			window.alert("We're sorry, but the seats that you have chosen are unavailable.  Please select new seats.");
		} else if (popup == "no_seats") {
			window.alert("You have not selected any seats.  Please select at least one seat for this event.");
		} else if (popup == "form_validate") {
			window.alert("Please correct the highlighted field.");
		}
	} else {
    	// Show the overlay (disables rest of page)
		showOverlay();
	
		// Show dialogue and focus on newvalue
		$(popup).show();
	}
}
 
// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	$('overlay').show();
	
	Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	$('overlay').hide();
	
	Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue(popup)
{
	hideOverlay();
	
	// Hide dialogue
	$(popup).hide();
}

/* Event handler for onKeyPress for the newvalue field. Enables the use of the ENTER (RETURN)
key when adding a new entry in the dialogue box */
function enterKey(event, field)
{
	// If the event key pressed was a return (code 13)
	if (event.which == 13 || event.keyCode == 13)
		addEntry(field.value);
}

// count is used to number the entries LI IDs
var count = 1;

// Adds an entry
function addEntry(message)
{
	// Close the dialogue
	closeDialogue();
	
	// If the value entered for the new entry is not empty
	if (message != '' && message != null)
	{		
		// Build a new LI, set its value and id and add it
		newLI= Builder.node('li', {id: count});
		newLI.innerHTML = message;
		count++;
		
		// Append the new LI to the entries UL
		$('entries').appendChild(newLI);
	}
}
//-->