	
	validationRunning = false;

//*********************************************************************************************************
//	Function: makeValidationCall()
//				Compile the fields, submit them to the validator
//*********************************************************************************************************
	function makeValidationCall( form_name )
	{
	//---------------------------------------------------------------------------------------------------------
	//	Do not resubmit if a validation is pending
	//---------------------------------------------------------------------------------------------------------
		if (validationRunning)
		{
			return;
		}
		
		validationRunning = true;

	//---------------------------------------------------------------------------------------------------------
	//	Reset the display of previous error reports
	//---------------------------------------------------------------------------------------------------------
		clearFieldErrors( form_name );
		
	//---------------------------------------------------------------------------------------------------------
	//	Make sure the form exists
	//---------------------------------------------------------------------------------------------------------
		formObj = document.forms[form_name];
		
		if (!formObj)
		{
			validationDone();
		}

	//---------------------------------------------------------------------------------------------------------
	//	Get the form parameters as a string
	//---------------------------------------------------------------------------------------------------------
		postParms = compileAllFieldValues( formObj );

		if (!postParms)
		{
			validationDone();
		}

	//---------------------------------------------------------------------------------------------------------
	//	Submit the validation request via an ajax call
	//---------------------------------------------------------------------------------------------------------
		postURL = '/formsmgr/validate.php';
		
		var xmlhttp =  initHTTPObject();
		xmlhttp.open('POST', postURL, true );
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", postParms.length);
		xmlhttp.setRequestHeader("Connection", "close");
		
		xmlhttp.onreadystatechange = function() 
		{ 
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ) 
			{ 
				processValidationResponse( form_name, xmlhttp.responseText ) 
			}
		};

		xmlhttp.send(postParms);
	}

//*********************************************************************************************************
//
//	Function: processValidationResponse()
//				Response handler for makeValidationCall()
//*********************************************************************************************************
	function processValidationResponse( form_name, response )
	{
		validationRunning = false;

	//---------------------------------------------------------------------------------------------------------
	//	Init
	//---------------------------------------------------------------------------------------------------------
		found_errors = new Array();
		form_name	 = form_name.toString();

	//---------------------------------------------------------------------------------------------------------
	//	Was a response returned from the validator?
	//---------------------------------------------------------------------------------------------------------
		if (!response)
		{
			//	No, submit the form
			submitForm(form_name);
			return;
		}
		
	//---------------------------------------------------------------------------------------------------------
	//	Turn the response into a js array
	//---------------------------------------------------------------------------------------------------------
		eval( response );
		
	//---------------------------------------------------------------------------------------------------------
	//	Were errors returned?
	//---------------------------------------------------------------------------------------------------------
		if (!found_errors[0])
		{
			//	No, submit the form
			submitForm(form_name);
			return;
		}

	//---------------------------------------------------------------------------------------------------------
	//	Loop through the errors
	//---------------------------------------------------------------------------------------------------------
		for (i=0; i<=(found_errors.length-1); i++)
		{
			errornumber  = i+1;
			errormessage = found_errors[i][0];
			fieldname	 = found_errors[i][1];
			fieldid		 = found_errors[i][2];
			showError( form_name, errornumber, errormessage, fieldname, fieldid );
		}
	
	//---------------------------------------------------------------------------------------------------------
	//	Focus on the top of the form
	//---------------------------------------------------------------------------------------------------------
		window.location = '#' + form_name + 'top';

	//---------------------------------------------------------------------------------------------------------
	//	All done
	//---------------------------------------------------------------------------------------------------------
		validationDone();
	}	
	
//*********************************************************************************************************
//
//	Function: showError()
//				
//*********************************************************************************************************
	function showError( form_name, errornumber, errormessage, fieldname, fieldid )
	{
	//---------------------------------------------------------------------------------------------------------
	//	Get the error placeholders
	//---------------------------------------------------------------------------------------------------------
		fieldErrorContainer = document.getElementById( 'fielderror-' + fieldid );
		mainErrorsContainer = document.getElementById( 'formerrors' + form_name );
		fieldBlockContainer = document.getElementById( 'fieldblock-' + fieldid );

	//---------------------------------------------------------------------------------------------------------
	//	Is there a placeholder specifically for this field's error?
	//---------------------------------------------------------------------------------------------------------
		if (fieldErrorContainer)
		{
			fieldErrorContainer.innerHTML = errormessage;
		}
		
	//---------------------------------------------------------------------------------------------------------
	//	Is there a master placeholder for all the errors?
	//---------------------------------------------------------------------------------------------------------
		else if (mainErrorsContainer)
		{
			if (fieldname)
			{
				msg = '<a href="javascript:document.forms[\'' + form_name + '\'][\'fields[' + fieldname + ']\'].focus()">' + errormessage + '</a><br>';
			}

			else
			{
				msg = errormessage + '<br>';
			}

			divContents						= mainErrorsContainer.innerHTML;
			mainErrorsContainer.innerHTML	= divContents + msg;
		}

	//---------------------------------------------------------------------------------------------------------
	//	Otherwise, just alert the error
	//---------------------------------------------------------------------------------------------------------
		else 
		{
			alert( errormessage );
		}

	//---------------------------------------------------------------------------------------------------------
	//	If the field ws specified and it has a wrapper div, change its class
	//---------------------------------------------------------------------------------------------------------
		if (fieldBlockContainer)
		{
			fieldBlockContainer.className = 'fieldblock-error';
		}
	}
	
//*********************************************************************************************************
//
//	Function: submitForm()
//				
//*********************************************************************************************************
	function submitForm( formname )
	{
	//---------------------------------------------------------------------------------------------------------
	//	Make sure the form exists
	//---------------------------------------------------------------------------------------------------------
		formObj = document.forms[formname];

	//---------------------------------------------------------------------------------------------------------
	//	Submit the form
	//---------------------------------------------------------------------------------------------------------
		if (formObj)
		{
			setTimeout( "formObj.submit();", 1 );
			return;
		}

	//---------------------------------------------------------------------------------------------------------
	//	All done
	//---------------------------------------------------------------------------------------------------------
		validationDone();
	}

//*********************************************************************************************************
//
//	Function: validationDone()
//	
//*********************************************************************************************************
	function validationDone()
	{
		validationRunning = false;
	}

//*********************************************************************************************************
//
//	Function: clearFieldErrors()
//	
//*********************************************************************************************************
	function clearFieldErrors( formname )
	{
	//---------------------------------------------------------------------------------------------------------
	//	Clear the main error container
	//---------------------------------------------------------------------------------------------------------
		mainErrorsContainer = document.getElementById( 'formerrors' + formname );
		
		if (mainErrorsContainer)
		{
			mainErrorsContainer.innerHTML = '';
		}
	
	//---------------------------------------------------------------------------------------------------------
	//	Get all the elements of the form
	//---------------------------------------------------------------------------------------------------------
		fielderrorElements	= getElementsByClass( 'fielderror' );
		fieldblockElements	= getElementsByClass( 'fieldblock-error' );

	//---------------------------------------------------------------------------------------------------------
	//	Clear the field errors
	//---------------------------------------------------------------------------------------------------------
		if (fielderrorElements)
		{
			for(i=0; i<fielderrorElements.length; i++)
			{
				fielderrorElements[i].innerHTML = '';
			}
		}

	//---------------------------------------------------------------------------------------------------------
	//	Clear the fieldblock styling
	//---------------------------------------------------------------------------------------------------------
		if (fieldblockElements)
		{
			for(i=0; i<fieldblockElements.length; i++)
			{
				fieldblockElements[i].className = 'fieldblock';
			}
		}
	}
	
//*********************************************************************************************************
//
//	Function: compileAllFieldValues()
//	Return all the name/value pairs of a form, to be sent via HTTP POST
//
//*********************************************************************************************************
	function compileAllFieldValues( form )
	{
		valuestring = '';
		
	//---------------------------------------------------------------------------------------------------------
	//	Look at all the form fields
	//---------------------------------------------------------------------------------------------------------
		for (var e = 0; e < form.elements.length; e++) 
		{
		//---------------------------------------------------------------------------------------------------------
		//	Reset the values
		//---------------------------------------------------------------------------------------------------------
			var el    = form.elements[e];
			var name  = '';
			var value = '';

		//---------------------------------------------------------------------------------------------------------
		//	Parse a radio button
		//---------------------------------------------------------------------------------------------------------
			if (el.type == 'radio') 
			{
				if (el.checked)
				{
					name  = el.name;
					value = el.value;
				}
			}
		
		//---------------------------------------------------------------------------------------------------------
		//	Parse a checkbox
		//---------------------------------------------------------------------------------------------------------
			else if (el.type == 'checkbox') 
			{
				name  = el.name;
				value = el.checked;
			}
		
		//---------------------------------------------------------------------------------------------------------
		//	Parse al other fields
		//---------------------------------------------------------------------------------------------------------
			else
			{ 
				name  = el.name;
				value = el.value;
			}
		
		//---------------------------------------------------------------------------------------------------------
		//	Record the value
		//---------------------------------------------------------------------------------------------------------
			valuestring += escape( name ) + '=' + escape( value ) + '&';	
		}
		
		return valuestring;
	}
	
//*********************************************************************************************************
//
//	Function: initHTTPObject()
//	Initialize a new HTTP object
//
//*********************************************************************************************************
	function initHTTPObject() 
	{
		var xmlhttp;
		
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}

		if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch (e) {
				xmlhttp = false;
			}
		}

		return xmlhttp;
	}
	
//*********************************************************************************************************
//
//	Function: getElementsByClass()
//	Gets an array of elements by their class name
//
//*********************************************************************************************************
	function getElementsByClass(searchClass,node,tag) 
	{
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}