/** RSH must be initialized after the page is finished loading. */
window.onload = initialize;

function initialize() {
  // initialize RSH
  dhtmlHistory.initialize();
  
  // add ourselves as a listener for history
  // change events
  dhtmlHistory.addListener(handleHistoryChange);
  
  // determine our current location so we can
  // initialize ourselves at startup
  var initialLocation = dhtmlHistory.getCurrentLocation();
  
  // if no location specified, use the default

  if (initialLocation == 'view:success') {
	Application.newForm('getSuccessPage');
	}
  if (initialLocation == '') {
  	Application.newForm('getEmpty');
	}	
}

/** A function that is called whenever the user
    presses the back or forward buttons. This
    function will be passed the newLocation,
    as well as any history data we associated
    with the location. */
function handleHistoryChange(newLocation, historyData) {
  // use the history data to update our UI
  updateUI(newLocation, historyData);                           
}

/** A simple method that updates our user
    interface using the new location. */
function updateUI(newLocation, historyData) {
	var output = document.getElementById("ApplicationFormBody");
	// simply display the location and the
	// data
	var historyMessage;
	
	if (newLocation == 'view:form' || newLocation == '' ) {
		if (historyData != null) Application.params = historyData.message;
		Application.newForm('history');
	}
	
	if (newLocation == 'view:validate') {
		if (historyData != null) Application.params = historyData.message;
		Application.newForm('history');
	}
	
	if (newLocation == 'view:submit')	{
		if (historyData != null) historyMessage = historyData.message;
		output.innerHTML = historyMessage;
	}
	
	if (newLocation == 'view:success')	{
		historyMessage = Application.newForm('getSuccessPage');
		output.innerHTML = historyMessage;
	}
	
	if (newLocation == 'view:change') {
		if (historyData != null) Application.params = historyData.message;
		Application.changeDetailsForm('history');
	}
}

