function doAJAXSearch(ctrl, div, fields, links, width, columntitles, tab, classnames, onsuccess, alternateSuccess) {
	var oFormControls = getFormControls(ctrl);
	var sQueryString = "";
	for(var i = 0; i < oFormControls.length; i++) {
		if(oFormControls[i].name) {
			if(sQueryString != "") {
				sQueryString += "&";
			}
			sQueryString += oFormControls[i].name + "=" + oFormControls[i].value;
		}
	}
	
	sQueryString = removeAccents(sQueryString);

	(new ajaxObject(ACTION_URL + "doControllerAction", function(responseText) {
		var oJSON = JSON.parse(responseText).json;
		tab = $('tabText' + tab);
		if(tab) {
			if(tab.noresults) {
				tab.innerHTML = tab.noresults;
			} else {
				tab.noresults = tab.innerHTML;
			}
			tab.innerHTML += " (" + oJSON.length + ")";
		}
		
		if(window['submitNext'] != undefined && window['OfficesTabClicked'] == undefined) {
			submitNext();
		} else {
			window['OfficesTabClicked'] = undefined;
		}
		if(oJSON[0]) {
			if(alternateSuccess) {
				eval(alternateSuccess);
			} else {
				makeSearchResults(oJSON, div, fields, links, width, columntitles, classnames);
			}
		} else {
			if(CURRENT_LANGUAGE == 'en') {
				$(div).innerHTML = "<div style=\"padding-top: 20px;\">No result found." + (CURRENT_PAGE.indexOf("geomatics") == 0 ? " Have you tried the <a href=\"" + getPageURL("search", "?txtSearch=" + window['GlobalSearch']) + "\">exp.com's main search</a> ?" : "") + "</div>";
			} else {
				$(div).innerHTML = "<div style=\"padding-top: 20px;\">Aucune page trouvée." + (CURRENT_PAGE.indexOf("geomatics") == 0 ? " Avez-vous essayé la <a href=\"" + getPageURL("search", "?txtSearch=" + window['GlobalSearch']) + "\">recherche principale de exp.com</a> ?" : "") + "</div>";
			}
		}
	})).update(sQueryString, 'POST');
}

function makeSearchResults(JSONData, div, fields, links, width, columntitles, classnames) {
	div = $(div);
	div.innerHTML = "";
	var oTable = $c("table");
	oTable.className = "searchresults";
	oTable.id = "results" + div.id;
	var oTBody = $c("tbody");
	oTable.appendChild(oTBody);
	var oTR = $c("tr");
	oTR.className = "title";
	for(var i = 0; i < fields.length; i++) {
		var oTD = $c("td");
		oTD.innerHTML = columntitles[i];
		if(width[i] != null) {
			oTD.style.width = width[i] + "px";
		} else {
			oTable.style.width = "100%";
		}
		oTD.SortInfo = {table : oTable, column : i}
		oTD.onclick = orderRows;
		oTR.appendChild(oTD);
		oTBody.appendChild(oTR);
	}
	for(var i = 0; i < JSONData.length; i++) {
		oTR = $c("tr");
		for(var j = 0; j < fields.length; j++) {
			var oTD = $c("td");
			if(links[j]) {
				var oA = $c("a");
				oA.innerHTML = JSONData[i][fields[j]] == 'null' ? '' : JSONData[i][fields[j]];
				oA.href = getPageURL(JSONData[i][links[j].url], links[j].params ? JSONData[i][links[j].params] : undefined);
				oTD.appendChild(oA);
			} else {
				oTD.innerHTML = JSONData[i][fields[j]] == 'null' ? '' : JSONData[i][fields[j]];
			}
			if(width[j] != null) {
				oTD.style.width = width[j] + "px";
			}
			if(classnames && classnames[j] != null) {
				oTD.className = classnames[j];
			}
			oTD.style.verticalAlign = "top";
			oTR.appendChild(oTD);
		}
		if(i % 2 == 1) {
			oTR.className = "coloredrow";
		}
		oTBody.appendChild(oTR);
	}
	div.appendChild(oTable);
}
