/**
 * Include script for javascript application layer.
 * 
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @version 1.00, 11/09/2007
 * @access public
 */

//------------------------------------------------------------------------------
// PHASE I: INCLUDE ALL NECESSARY JAVASCRIPT FILES.
//------------------------------------------------------------------------------
document.write("<script src='/cms/jscripts/cms.event.js'></script>");
document.write("<script src='/cms/jscripts/cms.functions.js'></script>");
if ( document.all &&
	(	navigator.appVersion.indexOf("MSIE 5.") != -1 
		|| navigator.appVersion.indexOf("MSIE 6.") != -1
	)
) {
	document.write("<script src='/cms/jscripts/sarissa/sarissa.js''></script>");
} 
document.write("<script src='/inc/jscripts/FormHandler.js'></script>");
document.write("<script src='/inc/jscripts/googlemaps.js'></script>");
document.write("<script src='/inc/jscripts/planRoute.js'></script>");
document.write("<script src='/inc/jscripts/ChangeItem.js'></script>");
document.write("<script src='/inc/jscripts/ItemPop.js'></script>");
document.write("<script src='/inc/jscripts/ItemPop.brandwijn.js'></script>");
document.write("<script src='/inc/jscripts/FormDependencies.js'></script>");
document.write("<script src='/inc/jscripts/SearchFormHandler.js'></script>");
document.write("<script src='/inc/jscripts/OrderHandler.js'></script>");
document.write("<script src='/cms/jscripts/xmlhttp/XMLHttp.js'></script>");
document.write("<script src='/cms/jscripts/xmlhttp/XMLProcessor.js'></script>");
document.write("<script src='/cms/jscripts/xmlhttp/Data.js'></script>");

//------------------------------------------------------------------------------
// PHASE II: INITIALIZATION FUNCTION, CALLED ON DOCUMENT LOAD EVENT
//------------------------------------------------------------------------------

/**
 * Instance of ArtCollection object.
 * @var object artCollection
 * @access global
 */
var formHandler = null;

/**
 * Instance of PlanRoute object.
 * @var object planRoute
 * @access global
 */
var planRoute = false;


/**
 * Instance of Photoalbum object.
 * @var object changeImage
 * @access global
 */
var changeItem = false;

/**
 * Instance of XMLHttp object, used for XML HTTP data communication.
 * @var object xmlhttp
 * @access global
 */
var xmlhttp = null;

/**
 * Instance of XMLProcessor object, used for XML data processing.
 * @var object xmlprocessor
 * @access global
 */
var xmlprocessor = null;

/**
 * Data object takes care of collecting and sending data in AJAX communication.
 * @var object data
 * @access global
 */
var data = null; 

/**
 * The HTML page used to send AJAX requests to. Used in Data() object.
 * @var string actpage.
 * @access global
 */
var actpage = 'xmlrequest.html';

/**
 * Controller for the pushing an item into an pop up.
 */
var itemPop = null;

/**
 * Controller for the form dependencies (showon, etc)
 */
var formDependencies = null;

/**
 * Controller for the search form
 */
var searchFormHandler = null;

/**
 * Controller for the orderHandler script
 */
var orderHandler = null;

/**
 * Initialization function.
 *
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @param		boolean		refresh		should the nav-list be refreshed? default to true.
 * @return 	void
 * @access	public
 */
function init() {
	var inps,		// collection of input elements in this document.
			addedTo,// array to keep track of the forms the onsubmit has been added to
			i;			// iterator.
			
	xmlhttp = new XMLHttp();
	xmlhttp.init();
	
	xmlprocessor = new XMLProcessor();
	xmlprocessor.init(); 
	
	data = new Data();
	data.init();
	
	searchFormHandler = new SearchFormHandler;
	searchFormHandler.init();
	
	orderHandler = new OrderHandler;
	orderHandler.init();
	
	changeItem = new ChangeItem;
	changeItem.init();

	planRoute = new PlanRoute;
	planRoute.init();
	
	itemPop = new ItemPopBrandwijn;
	itemPop.init();
	
	formDependencies = new FormDependencies;
	formDependencies.init();

	inps = document.getElementsByAttribute('act', false, 'input');
	for ( it in inps ) {
		if ( document.getElementByAttribute('name', 'act', false, inps[it].form) ) {
			addEvent(inps[it], 'click', setAct);
		}
	}
	
	// if map div exists than call load function to show map
	if ( document.getElementById('map') ) {
		load();
	}
	
	if ( typeof(FormHandler) != 'undefined' ) {
		formHandler = new FormHandler;
		formHandler.init();
	}
	return true;
} // init()

/**
 * Onclick handler for inputs with attribute act
 * @param e
 * @return
 */
function setAct(e) {
	var eventSrc,
			form;
	e = e || window.event;
	eventSrc = getEventSrc(e); 
	if ( eventSrc.getAttribute('act') ) {
		document.getElementByAttribute('name', 'act', false, eventSrc.form).value = 
			eventSrc.getAttribute('act');
	}
} // setAct();



window.onload = init;
