var current_controleur = '';

function ajax_controleur(nom, type) {
	if(current_controleur == nom) {
		return false;
	}
	ajax_controleur_update_content(chargement);
	ajax_controleur_scrollto_content();
	var code = function(transport) {
		ajax_controleur_update_content(transport.responseText);
		current_controleur = nom;
		return false;
	}
	ajax_request('POST', 'main.php?ajax=controleur', 'ajaxctrlnom='+nom+'&type='+type, code, true);
}

function ajax_controleur_params(nom, params){
	if(current_controleur == nom) {
		return false;
	}
	ajax_controleur_update_content(chargement);
	ajax_controleur_scrollto_content();
	var code = function(transport) {
		ajax_controleur_update_content(transport.responseText);
		current_controleur = nom;
		return false;
	}
	var params_str = 'ajaxctrlnom='+nom+'&jparams='+params.toJSON();
	ajax_request('POST', 'main.php?ajax=controleur&ajaxtype=params', params_str, code, true);
}

function ajax_controleur_send_form(nom, type, form) {
	var code = function(transport) {
		ajax_controleur_update_content(transport.responseText);
		current_controleur = '';
		return false;
	}
	ajax_request('POST', 'main.php?ajax=controleur', 'ajaxctrlnom='+nom+'&type='+type+'&'+form2params(form), code, true);
	ajax_controleur_update_content(chargement);
}

function ajax_controleur_params_send_form(nom, form) {
	var code = function(transport) {
		ajax_controleur_update_content(transport.responseText);
		current_controleur = '';
		return false;
	}
	ajax_request('POST', 'main.php?ajax=controleur&ajaxtype=params', 'ajaxctrlnom='+nom+'&'+form2params(form), code, true);
	ajax_controleur_update_content(chargement);
}

function ajax_controleur_update_content(html) {
	$('controleur_content').innerHTML = html;
}

function ajax_controleur_cancel() {
	ajax_controleur_update_content('');
	current_controleur = '';
}

function ajax_controleur_scrollto_content() {
	var pos = Element.Methods.cumulativeOffset($('controleur_content'));
	window.scrollTo(0, pos[1] - $('controleur_content').offsetHeight);
}