// JavaScript Document
//<!--

/* 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)
			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);

// loadOverlayPopup shows the overlay and dialogue box
function loadOverlayPopup(pc)
{
	var l_image = document.getElementById("popup_image");
	
	// Show the overlay (disables rest of page)
	showOverlay();
	
	//change popup image if necessary
	if (pc !== null)
	{
		//alert(pc);
		
		l_image.src = "http://www.wholesalechess.com/images/products/"+pc;
	}
	
	showDialogue();	
}

function loadShippingMethods()
{
	// Show the overlay (disables rest of page)
	showOverlay();
	
	showDialogue();	
}

function showDialogue()
{
	document.getElementById('dialogue').style.display = "";
}

// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	document.getElementById('overlay').style.display = "";
	
	if (navigator.appVersion.indexOf("MSIE") == -1)
		Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	document.getElementById('overlay').style.display = "none";
	
	if (navigator.appVersion.indexOf("MSIE") == -1)
		Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue()
{
	hideOverlay();
	
	// Hide dialogue
	document.getElementById('dialogue').style.display = "none";
}

// overlayCount is used to number the entries LI IDs
var overlayCount = 1;

// Adds an entry
function addOverlayEntry(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: overlayCount});
		newLI.innerHTML = message;
		overlayCount++;
		
		// Append the new LI to the entries UL
		document.getElementById('entries').appendChild(newLI);
	}
}
//-->
