	
	// call with 
	//   fieldName : name of field to be validated
	//   validate : type of validation number, text
	//   extras : an object with extra items e.g. max, min
	function doAjax(loginRequired, fieldName, validate, extras)	{

		// I need to trap select boxes here so I can get the proper selected index value

		if (validate == 'option')		{
			// Getting a vale from a select box
			workingValue = $('#'+ fieldName).val();
		}	else if (validate == 'check')		{
			// find out if it's checked - value always returns the value even when not checked
			workingValue = $('#'+ fieldName+':checked').val();
			if (workingValue == undefined)	{	workingValue = 0;	}
		}	else	{
			// normal text field
			workingValue = escape(String($('#'+ fieldName).val()));
		}

		$.getJSON(
			'ajaxValidate.asp', 
			{
				value : workingValue,
				val : validate,
				errorID : extras.errorID,
				required : extras.required,
				maxlength : extras.maxLength,
				minlength : extras.minLength,
				fieldName : extras.fieldName,
				loginRequired : loginRequired
			},
			
			function(data)
			{
				// Turn our Json string back to Javascript
				//resultSet = Json.evaluate(data);
				resultSet = data

				if (resultSet.valid == '1') 	{	valid = true }	else	{ valid = false	};
				message = resultSet.mes;

				if (valid)		{
					$('#' + fieldName).css('border-color', '#09FF3D');
					//$('label_' + fieldName).setStyle('color', '#09FF3D');			// Changes the label colour - overkill
					$('#mes_' + fieldName).css('color', '#09FF3D');
					$('#' + fieldName).css('border-width', '2px;');
					//icon = "<img src='img/good.gif' alt='OK'/>";
				}	else	{

					if (loginRequired)		{
						if (message == "Session Timeout")	{
							alert('Your session has expired due to inactivity. Please login again');
							document.location.href = 'login.asp';
						}
					}

					$('#' + fieldName).css('border-color', 'red');
					//$('label_' + fieldName).setStyle('color', 'red');				// Changes the label colour - overkill
					$('#mes_' + fieldName).css('color', 'red');
					$('#' + fieldName).css('border-width', '2px;');
					//icon = "<img src='img/bad.gif' alt='Error'/>";
				}

				//$('#mes_' + fieldName).html(icon + " " + message);
				$('#mes_' + fieldName).html(message);
				
			}
		);
	}


	// Switch off the ajax styles
	function resetStyle(fieldName)	{
		$('#mes_' + fieldName).html('');
		$(fieldName).css('border-color', 'black;');
		$(fieldName).css('border-width', '1px;');
		//$('label_' + fieldName).setStyle('color', 'black');
	}


	// need to check if one box is ticked to see if others need validated
	function isThisFieldRequired(fieldToCheck, valueToLookFor)	{
		if ($(fieldToCheck).checked == valueToLookFor)	{
			return '1';
		}	else	{
			return '0';
		}
	}


	// like above but with option box
	function isThisFieldRequiredOpt(fieldToCheck, valueToLookFor)	{
		if ($(fieldToCheck).value == valueToLookFor)	{
			return '1';
		}	else	{
			return '0';
		}
	}

