function validateAIIndexSearch() {
	var regex;
	var errorAlert = "";
	// get the form
	var ai_index = document.forms.ai_index_search.ai_index_input.value;
	
	// if the value is empty
	if (ai_index == "") errorAlert += "\n- please enter a valid AI INDEX"
	
	var pos1=ai_index.indexOf("/");
	var pos2=ai_index.indexOf("/",pos1+1);
	// if it hasn't found both "/"
	if ( pos1 <= 0 || pos2 <= 0 ) errorAlert += "\n- invalid AI INDEX format"

	var ai_class_subclass=ai_index.substring(0,pos1);
	regex=/^\s*\w{3}\s*\d{2}\d?\s*$/i;
	if (ai_class_subclass.search(regex)==-1) errorAlert += "\n- please enter a valid AI INDEX class, e.g. 'IOR 41' "
	
	var ai_document_no=ai_index.substring(pos1+1,pos2);
	regex=/^\s*\d{3}\s*$/i;
	if (ai_document_no.search(regex)==-1) errorAlert += "\n- please enter a valid AI INDEX document number"
	
	var ai_year=ai_index.substring(pos2+1);
	regex=/^\s*\d{4}\s*$/i;
	if (ai_year.search(regex)==-1) errorAlert += "\n- please enter a valid AI INDEX year"
	
	// if the year is not valid
	if ( errorAlert != "" ) {
		alert( "The AI Index you have entered is not valid:" + errorAlert + "\n\n e.g. MDE 14/066/2003" )
		return false;
	} else {
		// format document number and year before submitting
		if ( ai_year.length == 2 ) {
			if ( ai_year.search(/^0/) == -1 ) {  ai_year = "19" + ai_year } else { ai_year = "20" + ai_year }
		}
		// format document number and year before submitting
		if ( ai_document_no.length == 2 ) {
			ai_document_no = "0" + ai_document_no
		} else if ( ai_document_no.length == 1 ) {
			ai_document_no = "00" + ai_document_no
		}
		var clean_index = ai_class_subclass + ai_document_no + ai_year;
		document.forms.ai_index_search.ai_index.value = clean_index.replace(/\s/gi, "");
		return true;
	}
}
