var pageactu=1;
var nbpages=20;
var ordre="nom";
var sens="asc";
var terme="";

$(document).ready(function(){	
	ini();
	$("#form_search_ecole").submit(search_ecole);
	$("#to_search").autocomplete(tab_noms_ecoles, {"selectFirst":false});
	$("#to_search").result(function(event, data, formatted){
		search_ecole();
	});
	terme=$("#to_search").val();

});

function ini(){
	$(".lienpage").click(function(){
		change_page(this);
		return false;
	});

	$(".tri").change(function(){
		change_nbpages(this);
	});
	
	$(".suiv, .prev").click(function(){
		prev_next(this);
	});
	
	$("#liste_ecoles th a").click(function(){ change_ordre(this); return false; });
}

function search_ecole(){
	terme=$("#to_search").val();
	ini_post();
	return false;
}

function change_ordre(a){
	ordre=$(a).attr("id").split("order_");
	ordre=ordre[1];
	if($(a).find("img").length>0){
		if($(a).find("img").eq(0).hasClass("ico-down")) sens="asc";
		else sens="desc";
	}
	else {
		if(ordre=="remuneration_moyenne" || ordre=="insertion") sens="desc";
		else sens="asc";
	}
	ini_post();
}

function change_page(a){
	pageactu=$(a).html();
	ini_post();
};

function prev_next(a){
	if($(a).attr("href")!=pageactu) pageactu=$(a).attr("href");
	if(parseInt(pageactu)!=pageactu) {
		pageactu=pageactu.split("/");
		pageactu=pageactu[pageactu.length-1];
	}
	ini_post();
};


function change_nbpages(slc){
	nbpages=$(slc).val();
	ini_post();
};
		

function ini_post(){
		$.post(LIEN_ROOT+"includes/front/ajaxed/ecole_ajax.php", {nbpages:nbpages,pageactu:pageactu, ordre:ordre, sens:sens, terme: terme, posted:1 },function (data){
			$("#contener").fadeOut("fast",function(){
				$("#contener").html(data).fadeIn("fast");
				ini();
			});
		});
};

