	
	var arrValid = [];
	var arrFields = [];
	var arrValues = [];
	
	function doAllAjax(){
		alert(arrValid);
		$.each($("input, select, textarea"), function(i,v) {
			var theTag = v.tagName;
			var theElement = $(v);
			var theValue = theElement.val();
			var fieldName = theElement.attr("name")
			//alert($(v).attr("name"));
			//if($(v).focus
		    if(!inArray(fieldName, arrValid)){
				if(!inArray(fieldName, arrFields)){
					arrFields.push(fieldName);
					arrValues.push(theValue);
				}

				//doAjax(fieldName, theValue);
			}
				   
		});
			
		// Now 
		$.getJSON(
			"/override/formsajax.asp?fields=" + String(arrFields) + "&values=" + String(arrValues),
			function(result)	{
				resultSet = eval(result);
				alert(resultSet.response);
			}
		)
		
	}
	
	
	// 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(fieldName, value, fbid)	{

		// I need to trap select boxes here so I can get the proper selected index value
		
		//if($('#'+fieldName).tagName == 'SELECT'){
			$('#pDebugOut').html($("#" + fieldName).val());
		//}
		//else{
		//		$('#pDebugOut').html('not dropdown');
		//}
		
		
		
		/*
		if ((validate == 'option') || (validate == 'DDNotDefault'))		{
			//workingValue = $("#" + fieldName)[$("#" + fieldName).selectedIndex].value;
			workingValue = $("#" + fieldName).val()
		}	else	{
			workingValue = escape(String($("#" + fieldName).val()))
		}
		*/
		// For radio buttons or checkboxes we need to ensure they're not still on a member of the group
		
		var nSplice;
		  
		$.getJSON(
			"/lib/formbuster_ajax.asp?tpl=" + strXmlTpl + "&field=" + fieldName + "&value=" + $("#" + fieldName).val().replace('&','%26') + "&FbId=" + fbid,
			function(result)	{
				// Turn our Json string back to Javascript
				resultSet = eval(result);
				//alert(resultSet.err);
				/*
				if (resultSet.valid == '1') 	{	valid = true }	else	{ valid = false	};
				message = resultSet.mes;
				*/
				if (resultSet.mes=='VALID')		{
					$('#' + fieldName).parent().css('border', 'none');
					$('#divErr_' + fieldName).fadeOut("slow");
					
					pushOneValue(fieldName);
				}	else	{
					//$('#' + fieldName).parent().css('border', '1px solid red');
					$('#mes_' + fieldName).html(resultSet.err);
					$('#' + fieldName).parent().css('border', 'none');
					$('#divErr_' + fieldName).fadeIn("slow");
									
					spliceByValue(fieldName);
				}

				// COULD BE USEFUL!
				//$('#pDebugOut').html(String(arrValid));
				
				
			}

		) 

	}


	function ajaxValidate(ele, strValidator, fbid){
		
		doAjax(ele.name, ele.value, fbid);
	}


	function resetErrorDivs()
	{
			
		$("div[id^='divErr']").fadeOut("slow");
		
	}


	// 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';
		}
	}
	
	
	
function spliceByValue(val, arr) {

    var idx = -1;
    for (i = 0; i < arrValid.length; i++) {
        if (arrValid[i].value == val) {
			alert(arrValid[i].value);
            idx = i;
        }
    }
	if(idx>-1)
    	arrValid.splice(idx, 1);
}

function pushOneValue(val) {

	var bPush = true;
	
    for (i = 0; i < arrValid.length; i++) {
        if (arrValid[i].value == val) {
            bPush = false;
        }
    }

	if(bPush)
    	arrValid.push(val);
}

function pushOneFieldname(val) {

	var bPush = true;
	
    for (i = 0; i < arrFields.length; i++) {
        if (arrFields[i].value == val) {
            bPush = false;
        }
    }

	if(bPush)
    	arrFields.push(val);
}


function inArray(what, where) {
    var a = false;
    for (var i = 0; i < where.length; i++) {
        if (what == where[i]) {
            a = true;
            break;
        }
    }
    return a;

}

/* ONLINE ENQUIRIES FUNCS */
function doEnqHelpAjax(fieldName)	{



		$.getJSON(
			"/override/enquiries_ajax.asp?fld=" + fieldName,
			function(result)	{
				// Turn our Json string back to Javascript
				resultSet = eval(result);
				
				//$('#divHelp_' + fieldName).css('display', 'block');
				$('#msgHelp_' + fieldName).html(resultSet.msg+$('#msgHelp_' + fieldName).html());
				$('#divHelp_' + fieldName).fadeIn("slow"); 
				
			}

		) 
	

}

