
	/*----------------------------------------------------------------------------------------*/
	/* AJAX FUNCTIONS                                                                         */
	/*                                                                                        */
	/* functions makeRequest and alertContents are sourced from developer.mozilla.org         */
	/*----------------------------------------------------------------------------------------*/

	var http_request			= false;
	var ajax_result				= false;
	var supress_submit		= false;
	var timeout_ms				= 500;		// Milliseconds before another another ajax request/result test
	var delay_limit				= 40;			// Maximum number of times the ajax validation can be delayed
	var display_element;
	var parameters;
	
	// Used to display an animated busy indication if an ajax process is taking a while to process.
	// When a normal page loads the browser shows the busy/load status, but an ajax process does not
	// do this, so we use busyLayer to achieve a similar result.
	var busyLayer_id			= 'busyLayer';
	var busyLayer_width		= 140;
	var busyLayer_height	= 140;
	var busyLayer_active	= false;

	/*----------------------------------------------------------------------------------------*/
	function makeRequest ( url, parameters )
	/*----------------------------------------------------------------------------------------*/
	/* Make a HTTP request to the url with the provided parameters                            */
	/*----------------------------------------------------------------------------------------*/
	{
		http_request = false;
				
		if ( window.XMLHttpRequest )
		{ // Mozilla, Safari,...
			http_request = new XMLHttpRequest ( );
			if (http_request.overrideMimeType)
			{
				http_request.overrideMimeType ( 'text/xml' );
			}
		}
		else if ( window.ActiveXObject )
		{ // IE
			try
			{
				http_request = new ActiveXObject ( "Msxml2.XMLHTTP" );
			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject ( "Microsoft.XMLHTTP" );
				}
				catch (e) { }
			}
		}
		
		if ( !http_request )
		{
			alert ( 'Cannot create XMLHTTP instance' );
			
			return false;
		}
		
		http_request.onreadystatechange = alertContents;
		http_request.open( 'GET', url + parameters, true );
		http_request.send( null );
	}

	/*----------------------------------------------------------------------------------------*/
	function alertContents ( )
	/*----------------------------------------------------------------------------------------*/
	/* Process the ajax state change inserting the http request  result if succesful          */
	/*----------------------------------------------------------------------------------------*/
	{
		if ( http_request.readyState == 4 )
		{
			if ( http_request.status == 200 )
			{
				result = http_request.responseText;
				document.getElementById( display_element ).innerHTML = result;		
				ajax_result = true;

				return true;
			}
			else
			{
				alert ( 'There was a problem making an http_request for ajax to the server. If this continues please contact the Webmaster.' );
				ajax_result = false;
				
				return false;
			}
		}
	}
   
	/*----------------------------------------------------------------------------------------*/
	function get_ajax_content ( url, display_id, form_id, send_field )
	/*----------------------------------------------------------------------------------------*/
	/* Insert the output of page into the tage with the id of display_id. If only a single    */
	/* field of the form should be sent to the page this can be defined in send field         */
	/*----------------------------------------------------------------------------------------*/
	{
		display_element	= display_id;		// global value of which span to display results in
		ajax_result			= false;				// Clear the ajax request result
		parameters			= '';
		
		if ( send_field )
		{
			var inputNode	= document.getElementById ( send_field );
			parameters		= '?' + inputNode.name + '=' + inputNode.value;
		}
		else if ( form_id )
		{
			parameters	= '?' + get_form_fields ( form_id );
		}
		
		makeRequest ( url, parameters );
		
		return true;
	}	
	
	/*----------------------------------------------------------------------------------------*/
	function get_ajax_content_from_link ( url, display_id, form_id, send_field, refresh_id )
	/*----------------------------------------------------------------------------------------*/
	/* Insert the output of page into the tage with the id of display_id. If only a single    */
	/* field of the form should be sent to the page this can be defined in send field. The    */        
	/* function is different to get_ajax_content as it does not return a boolean result       */
	/* which will cause the link to fail. refresh_id allows for an animated refresh image to  */
	/* be used when the page content is being refreshed.                                      */
	/*----------------------------------------------------------------------------------------*/
	{
		display_element	= display_id;		// global value of which span to display results in
		ajax_result			= false;				// Clear the ajax request result
		parameters			= '';
		
		if ( send_field )
		{
			var inputNode	= document.getElementById ( send_field );
			parameters		= '?' + inputNode.name + '=' + inputNode.value;
		}
		else if ( form_id )
		{
			parameters	= '?' + get_form_fields ( form_id );
		}
		
		makeRequest ( url, parameters );	// No parameters on a direct request
	}
	
	/*----------------------------------------------------------------------------------------*/
	function link_with_form_data ( url, form_id )
	/*----------------------------------------------------------------------------------------*/
	/* Create a lint to a page with a query string generated from date in fomr form_id        */ 
	/*----------------------------------------------------------------------------------------*/
	{
		if ( form_id )
		{
			var parameters	= get_form_fields ( form_id );
			rxp_pattern 		= /\?/;

			if ( rxp_pattern.test ( url ) )
			{
				url = url + '&' + parameters;
			}
			else
			{
				url = url + '?' + parameters;
			}
		}
		
		location.href = url;
	}

	/*----------------------------------------------------------------------------------------*/
	function get_form_fields ( form_id )
	/*----------------------------------------------------------------------------------------*/
	/* Builds a query string from the input fields in the form                                */
	/*----------------------------------------------------------------------------------------*/
	{
		parameters	= '';
		arr_qs			= new Array ( );

		// Get the input nodes
		var inputNodeList			= document.getElementById ( form_id ).getElementsByTagName ( "INPUT" );
		var selectNodeList		= document.getElementById ( form_id ).getElementsByTagName ( "SELECT" );
		var textareaNodeList	= document.getElementById ( form_id ).getElementsByTagName ( "TEXTAREA" );
				
		// Iterate through the list
		for ( var i = 0; i < inputNodeList.length; i++ )
		{
			// Get an individual node
			var inputNode = inputNodeList.item ( i );

			if ( inputNode.disabled == false )
			{
				if ( inputNode.type.toLowerCase ( ) == "checkbox" || inputNode.type.toLowerCase ( ) == "radio" )
				{
					if ( inputNode.checked && inputNode.value != "" )
					{
						parameters += inputNode.name + "=" + inputNode.value + "&";
					// DEBUG alert ( inputNode.type.toLowerCase ( ) + ' 1:: ' + inputNode.name + ' / ' + inputNode.id + ' = ' + inputNode.value );
					}
				}
				else if ( inputNode.value != "" ) // type of text, hidden, password
				{
					parameters += inputNode.name + "=" + inputNode.value + "&";
					// DEBUG alert ( inputNode.type.toLowerCase ( ) + ' 2:: ' + inputNode.name + ' / ' + inputNode.id + ' = ' + inputNode.value );
				}
			}
			else if ( inputNode.disabled == false )
			{
				// DEBUG alert ( 'disabled ' + inputNode.type.toLowerCase ( ) + ' :: ' + inputNode.name + ' / ' + inputNode.id + ' = ' + inputNode.value );
			}
		}
		
		for ( var i = 0; i < selectNodeList.length; i++ )
		{
			// Get an individual node
			var selectNode	= selectNodeList.item ( i );
			// For cross-browser compatablity make sure the value and text is
			// set for any selects being used with ajax
			var str_value		=	selectNode.options[selectNode.selectedIndex].value;

			if ( selectNode.selectedIndex != -1 && selectNode.disabled == false && str_value != '')
			{
				parameters += selectNode.name + "=" + str_value + "&";
			// DEBUG alert ( 'select :: ' + selectNode.name + ' / ' + selectNode.id + ' = ' + str_value );
			}
			else if ( selectNode.disabled == true )
			{
				// DEBUG alert ( 'disabled select :: ' + selectNode.name + ' / ' + selectNode.id + ' = ' + str_value );
			}
		}
			
		for ( var i = 0; i < textareaNodeList.length; i++ )
		{
			// Get an individual node
			var textareaNode = textareaNodeList.item ( i );				

			if ( textareaNode.value != "" && textareaNode.disabled == false )
			{
				parameters += textareaNode.name + "=" + textareaNode.value + "&";
				// DEBUG alert ( 'textarea :: ' + textareaNode.name + ' / ' + textareaNode.id + ' = ' + textareaNode.value );
			}
			else if ( textareaNode.disabled == true )
			{
				// DEBUG alert ( 'disabled textarea :: ' + textareaNode.name + ' / ' + textareaNode.id + ' = ' + textareaNode.value );
			}
		}
			
		return parameters;
	}

	/*----------------------------------------------------------------------------------------*/
	function validate_form ( form_id, url, display_id )
	/*----------------------------------------------------------------------------------------*/
	/* Generic function that calls a PHP script to validation a form inserting any result     */
	/* (validation failure) into tag display_id. Successful validation will submit the form.  */
	/*----------------------------------------------------------------------------------------*/
	{
		supress_submit = false;

		get_ajax_content ( url, display_id, form_id );
		process_ajax_result ( form_id, display_id, 0 );

		return false;
	}

	/*----------------------------------------------------------------------------------------*/
	function process_ajax_result ( form_id, display_id, delay_count )
	/*----------------------------------------------------------------------------------------*/
	/* Check for completion of the ajax process until we have a result                        */
	/*----------------------------------------------------------------------------------------*/
	{
		// If the ajax process has not returned a result, fail the form
		// submission and and start the delayed validation result
		if ( ajax_result == false && delay_count < delay_limit )
		{
			// turn on the busy indication if we've been waiting more than a second
			if ( busyLayer_id && busyLayer_active == false && delay_count > 9 )
			{
				centrediv ( busyLayer_id, busyLayer_width, busyLayer_height );
			}

			delay_count++;
			setTimeout ( 'process_ajax_result ( "' + form_id + '", "' + display_id +'", ' + delay_count + ' ) ', timeout_ms );
		}
		else if ( delay_count == delay_limit )
		{
			// turn off the busy indication
			if ( busyLayer_id && busyLayer_active == true )
			{
				centrediv ( busyLayer_id, busyLayer_width, busyLayer_height );
			}

			alert ( 'There was a problem processing your form. This might result in you experiencing database problems. If this continues please contact the Webmaster.' );

			if ( supress_submit == false )
			{
				document.getElementById ( form_id ).submit ( );
			}
			else
			{
				process_secNav_form ( form_id );
			}
		}
		else
		{
			// turn off the busy indication
			if ( busyLayer_id && busyLayer_active == true )
			{
				centrediv ( busyLayer_id, busyLayer_width, busyLayer_height );
			}
			// if there's no content to the output element for the validation
			// result return true to allow the form submission
			if ( document.getElementById( display_id ).innerHTML == '' && supress_submit == false )
			{
				document.getElementById ( form_id ).submit ( );
			}
			else if ( document.getElementById( display_id ).innerHTML == '' && supress_submit == true )
			{
				process_secNav_form ( form_id );
			}
		}
	}

	/*----------------------------------------------------------------------------------------*/
	function validate_secNav_form ( form_id, url, display_id )
	/*----------------------------------------------------------------------------------------*/
	{
		supress_submit = true;
		
		get_ajax_content ( url, display_id, form_id );
		process_ajax_result ( form_id, display_id, 0 );

		return false;
	}

	/*----------------------------------------------------------------------------------------*/
	function process_secNav_form ( form_id, url, display_id )
	/*----------------------------------------------------------------------------------------*/
	{
		my_booking_glider.next ( );

		return false;
	}


	//---------------------------------------------------------------------------------// 
	function centrediv ( str_id, int_width, int_height ) 
	//---------------------------------------------------------------------------------// 
	// int_width  = width of div
	// int_height = height of div
	// str_id     = id of div (needs to have position:absolute appled to it)
	//---------------------------------------------------------------------------------// 
	{ 
		layer = document.getElementById ( str_id ); 
	
		// Find out where the div will be displayed 
		// Centre of display (doesn't work in IE6)
		if ( self.innerWidth )
		{
			LeftPosition	= ( self.innerWidth - int_width ) / 2; 
			TopPosition		= ( self.innerHeight - int_height ) / 2; 
		}
		else if ( document.documentElement && document.documentElement.clientWidth )
		// Centre of first screen worth of content in page
		{
			LeftPosition	= ( document.documentElement.clientWidth - int_width ) / 2; 
			TopPosition		= ( document.documentElement.clientHeight - int_height ) / 2; 
		} 
		else if ( document.body )
		// Center of page
		{ 
			LeftPosition	= ( document.body.clientWidth - int_width ) / 2; 
			TopPosition		= ( document.body.clientHeight - int_height ) / 2; 
		} 
	
		// Get Scroll offset 
		if ( document.body.scrollTop ) 
		{ 
			TopPosition = TopPosition + document.body.scrollTop;		// IE only 
		} 
		else if ( window.pageYOffset ) 
		{ 
			TopPosition = TopPosition + window.pageYOffset; 				// All the rest 
		} 
	
		// Locate the layer. Use pixels otherwise strict doctypes will fail 
		layer.style.top			= TopPosition + 'px'; 
		layer.style.left		= LeftPosition + 'px';
		
		// Change the display style and set a flag (which can be tested elsewhere)
		if ( busyLayer_active )
		{
			layer.style.display	= 'none';
			busyLayer_active		= false;
		}
		else
		{
			layer.style.display	= 'block';
			busyLayer_active		= true;
		}	
	} 

