/* =========================================================================

JavaScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT (TM)

NAME: PageTemplate.js

AUTHOR: Chris Smith , Anana Ltd
DATE  : 28/02/2005

COMMENT: Support for Espress Configurator Main Page Tempate page

============================================================================ */

var g_pageModified = false;

//***********************************************
// Call when page is dirty. Menu and link buttons
// should check IsPageModified() to see if OK
// to navigate away.
//***********************************************
function MarkPageModified()
{
	g_pageModified = true;
}

//***********************************************
// Check to see if page has been modified.
// First checks if apply button is enabled in case
// changes have been carried over from last page
//***********************************************
function IsPageModified()
{
	if (VAM_GetById("ButtonApplyContactPoint"))
		if (VAM_GetById("ButtonApplyContactPoint").disabled == false)
			return true;
	return g_pageModified;
}


//***********************************************
// Call when Log off button is pressed.
// Checks IsPageModified(). If set then warns
// user before allowing navigation.
//***********************************************
function OnLogout()
{
	if(IsPageModified())
	{
		// Allow navigation if press OK.
		return displayChangesMadeOkCancelBox();
	}
	
	return true;
}


//***********************************************
// Check and warns user before changes to passed
// URL.
//***********************************************
function OnChangeToNewPageWithWarning(newUrl)
{
	var bAllowNav = true;
	if(IsPageModified())
	{
		// Allow navigation if press OK.
		bAllowNav = displayChangesMadeOkCancelBox();
	}
		if(bAllowNav)
	{
		window.location = newUrl;
	}
}


//***********************************************
// Displays message box with OK & Cancel buttons
// with message about the fact that any changes
// will be lost.
// Returns true if OK is pressed.
// Displays message in the user's locale
// Depends on the hidden field being Form1.HiddenChangesLost
// TEMPSRL: Make more general and reusable?
//***********************************************
function displayChangesMadeOkCancelBox(msg)
{
	return displayOkCancelBox(document.Form1.HiddenChangesLost.value);
}

