Additional edit form field validation using ajax sync - how to use ajax async with a short delay to allow validation to complete first

Hi,
Ive added an additional field validation using the code below into a custom field file located in \custom\Extension\modules\ProjectTask\Ext\Vardefs.


$dictionary['ProjectTask']['fields']['project_task_department_c']['validation']= array (
    'type' => 'callback',
    'callback' => 'function (formname,nameIndex) {
		                var return_value = validateFields(formname,nameIndex); 
                    return return_value;
									 }', );

validateFields is a javascript function that sets up an ajax call to the db to check the selected relate field is within certain rules. any mismatch fields are returned and highlighted in the form using the suitecrm add_error_style function. I have got everything working ok with ajax set for a synchronous call.

Is it possible to make this happen with a friendlier asynchronous ajax call, with a delay (say 3 seconds) to allow the ajax to complete successfully? If the ajax call fails to complete in that time, a message should be displayed to say try again later.

I have tried many different ways of inserting a delay using a while loop after the ajax call is sent. the delay works, but completion of the ajax call appears to be blocked and ends up finishing after the above callback completes anyway. I have tried inserting the delay functionality in: the above callback function, within the validateFields javascript directly after the ajax call is made, and embedding another callback within the ajax script etc. but no luck.

Is the validation array above being handled in some magical way that is causing my problems ? Is a synchronous call the only option in this situation?

Thanks for your help with this.