// all validation and help functions for the add location form
jQuery(function(){
	// check name and city fields when both are not empty anymore
	NameCityCheck();	
});

// check name and city fields when both are not empty anymore
function NameCityCheck()
{
	// array with fields to check
	var formId = 3;
	var aFields = new Array('#gform_3 #input_3_1', '#gform_3 #input_3_11');

	// add event listeners to all fields
	for(var i=0; i < aFields.length; i++) {
		// on change
		$(aFields[i]).change(function(){		
			var checkFields = true;
			var sData = 'formId=' + formId;
			
			// get values for all fields
			for(var j=0; j < aFields.length; j++) {
				if($(aFields[j]).val() != '' && checkFields) {
					// add value to querystring for ajax call
					sData = sData + '&aFields[' + $(aFields[j]).attr("name") + ']=' + $(aFields[j]).val();
				} else {
					// empty value? don't continue
					checkFields = false;
				}
			}
			
			// make ajax call
			if(checkFields) {
				$.get("/control/namecitycheck.php", sData, function(r) {
					if(r != '') {
						$(aFields[0]).closest("form").find(".gform_footer").prepend(r);
					}
				});			
			}
		});
	}

}