// JavaScript Document

function update_ss_categorie(){
	categorie = document.getElementById("categorie").value;
	new Ajax.Updater('ss_categorie', 'ss_categorie.inc.php', {asynchronous:true, postBody:"categorie="+categorie});
}

function choose_ss_categorie(){
	ss_categorie = document.getElementById("ss_categorie").value;
	new Ajax.Updater('ss_categorie', 'ss_categorie.inc.php', {asynchronous:true, postBody:"ss_categorie="+ss_categorie});
}

function choose(champ){
	champ_value = document.getElementById(champ).value;
	new Ajax.Updater('ss_categorie', 'ss_categorie.inc.php', {asynchronous:true, postBody:"" + champ + "=" + champ_value});
}

function choose_region(){
	region = document.getElementById("lieu").value;
	new Ajax.Updater('ss_categorie', 'ss_categorie.inc.php', {asynchronous:true, postBody:"region="+region});
}

function choose_duree(){
	duree = document.getElementById("duree").value;
	new Ajax.Updater('ss_categorie', 'ss_categorie.inc.php', {asynchronous:true, postBody:"duree="+duree});
}

function adv_search_hp(){
	new Ajax.Updater('adv_search_hp', 'adv_search_hp.php', {asynchronous:true, postBody:"search_type=adv"});
}

function simple_search_hp(){
	new Ajax.Updater('adv_search_hp', 'adv_search_hp.php', {asynchronous:true, postBody:"search_type=simple"});
}

function adv_search_left(){
	new Ajax.Updater('adv_search_left', 'adv_search_left.php', {asynchronous:true, postBody:"search_type=adv"});
}

function simple_search_left(){
	new Ajax.Updater('adv_search_left', 'adv_search_left.php', {asynchronous:true, postBody:"search_type=simple"});
}

function verif_selected_date_heure(){
	plage_heure_from = document.getElementById("plage_heure_from").value;
	plage_heure_to = document.getElementById("plage_heure_to").value;
	plage_date = document.getElementById("plage_date").value;
	new Ajax.Updater('selected_dates', 'selected_date.inc.php', {asynchronous:true, postBody:"plage_heure_from=" + plage_heure_from + "&plage_heure_to=" + plage_heure_to + "&plage_date=" + plage_date});
}

function remove_date(cle){
	new Ajax.Updater('selected_dates', 'selected_date.inc.php', {asynchronous:true, postBody:"action=remove&cle=" + cle});
}

function verif_selected_date_heure_contact_SP(){
	heure_from = document.getElementById("plage_heure_from").value;
	heure_to =  document.getElementById("plage_heure_to").value;
	ladate =  document.getElementById("plage_date").value;
	new Ajax.Updater('selected_dates', 'contact_SP_selected_date.php', {asynchronous:true, postBody:"plage_heure_from=" + heure_from + "&plage_heure_to=" + heure_to + "&plage_date=" + ladate});
}

function remove_date_contact_SP(cle){
	new Ajax.Updater('selected_dates', 'contact_SP_selected_date.php', {asynchronous:true, postBody:"action=remove&cle=" + cle});
}

function verif_nombre(champ) {
	var chiffres = new RegExp("[0-9\.]");
	var verif;
	var points = 0;
	var nb_dec = 0;
	var nb_dec_max = 2;

	for(x = 0; x < champ.value.length; x++){
		verif = chiffres.test(champ.value.charAt(x));
		if(champ.value.charAt(x) == ".") points++;
		if(points > 1) { verif = false; points = 1; } 
		if(points == 1 && verif)
			nb_dec ++;
		if(nb_dec > nb_dec_max + 1 ) verif = false;
		
		if(verif == false){
			if(champ.value.charAt(x) == ",") {
				champ.value = champ.value.substr(0,x) + "." + champ.value.substr(x+1,champ.value.length-x+1);
				x--;
			} else {
				champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1);
				x--;
			}
		}
	}
}

function verif_int(champ) {
	var chiffres = new RegExp("[0-9]");
	var verif;

	for(x = 0; x < champ.value.length; x++){
		verif = chiffres.test(champ.value.charAt(x));
		if(verif == false){	champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
	}
}

function show_hide_mdp_oubli(){
	if(document.getElementById("log_erreur"))
		document.getElementById("log_erreur").style.display = "none;"
	mdp_oubli_disp = document.getElementById("mdp_oubli").style.display;
	document.getElementById("mdp_oubli").style.display = (mdp_oubli_disp == "none") ? "block" : "none";
}

function mdp_oubli(){
	mdp_oubli_email = document.getElementById("mdp_oubli_email").value;
	new Ajax.Updater('mdp_oubli', 'mdp_oubli.php', {asynchronous:true, postBody:"mdp_oubli_email=" + mdp_oubli_email});
}

function reset_mdp_oubli(){
	new Ajax.Updater('mdp_oubli', 'mdp_oubli.php', {asynchronous:true, postBody:""});
}