function doChallengeResponse(acrypter,resultat) {
	str = document.getElementById(acrypter).value;
	document.getElementById(resultat).value = MD5(str);
	document.getElementById(acrypter).value = "";
}

function jsServeur(params, php) {
	var xhr_object = null;
	if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return;
	}
	xhr_object.open("POST", php, true);
	xhr_object.onreadystatechange = function() {
		if (xhr_object.readyState == 4) {
			eval(xhr_object.responseText);
		}
	}
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	xhr_object.send(params);
}

var delai = 500;
var timerCP = null;
var timerNumClub = null;

function saisieCP(code, path) {
	var combo = document.getElementById("dataComboCP");
	if (timerCP) {
		clearTimeout(timerCP);
		timerCP = null;
	}
	//if (code.length == 5) {
		var params = "code="+code;
		//jsServeur(params, "dataComboCP.php");
		timerCP = setTimeout("jsServeur('"+params+"', '"+path+"dataComboCP.php');", delai);
	//} else combo.className = "dataCombo invisible";
}

function saisieNumClub(num, path) {
	var combo = document.getElementById("dataComboNumClub");
	if (timerNumClub) {
		clearTimeout(timerNumClub);
		timerNumClub = null;
	}
	
	if (num.length >= 1) {
		var params = "num="+parseInt(num,10);
		//jsServeur(params, "dataComboNumClub.php");
		timerNumClub = setTimeout("jsServeur('"+params+"', '"+path+"dataComboNumClub.php');", delai);
	} else combo.className = "dataCombo invisible";
}

function clickComboCP (commune, code) {
	var combo = document.getElementById("dataComboCP");
	document.getElementById('ville').value=commune;
	document.getElementById('cp').value=code;
	combo.className = "dataCombo invisible";
}

function clickComboNumClub (club, num) {
	var combo = document.getElementById("dataComboNumClub");
	document.getElementById('club').value=club;
	document.getElementById('numeroClubFFA').value=num;
	combo.className = "dataCombo invisible";
}

var timerBanque = null;

function saisieBanque(nom, path) {
	var combo = document.getElementById("dataComboBanque");
	if (timerBanque) {
		clearTimeout(timerBanque);
		timerBanque = null;
	}
	//if (code.length == 5) {
		var params = "nom="+nom;
		//jsServeur(params, "dataComboCP.php");
		timerBanque = setTimeout("jsServeur('"+params+"', '"+path+"dataComboBanque.php');", delai);
	//} else combo.className = "dataCombo invisible";
}

function clickComboBanque (nom) {
	var combo = document.getElementById("dataComboBanque");
	document.getElementById('nom_banque').value=nom;
	combo.className = "dataCombo invisible";
}

$(document).ready(function(){
	$("#licFFA").blur(function () {
		var params = "num="+$(this).val();
		jsServeur(params, path+"actionSaisieLicence.php");
	});
});
