﻿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();
	}
}

function loadPopup()
{
    	// Show the overlay (disables rest of page)
	showOverlay();
	
	// Show dialogue and focus on newvalue
	$('dialogue').show();
	$('c2c_Phone').focus();
}

function loadCalling() 
{
    showOverlay();
    
    $('Calling').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()
{
	hideOverlay();
	
	// Hide dialogue
	$('dialogue').hide();
	
	// Clear dialogue
	$('c2c_Phone').value = '';
}

function closeCalling()
{
    hideOverlay();
    
    $('Calling').hide();
}

escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);
