$(document).ready( function () {
	
	$("input[name=paymentid]").click(
			function () {	
				$("#detail_echancier").css({ display: "none" });	
				//on recupere la valeur de l'input choisi
				/*var casecoche  = $("input[type=radio][checked]");
				var paymentid = casecoche.val();*/
				var id = $(this).attr("id");
				var paymentid = id.substring(9);
				var payment_method  = $("#payment_method");
				var form  = $("#checkout_form");
				
				form.attr("target", "");
				if(paymentid){
					$("#explication_paiement_cb").css({ display: "none" });	
					paymentid = parseInt(paymentid);
					var xhr_object = null; 
				     
					   if(window.XMLHttpRequest) // Firefox 
						      xhr_object = new XMLHttpRequest(); 
					   else if(window.ActiveXObject) // Internet Explorer 
						      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
					   else { // XMLHttpRequest non supporté par le navigateur 
						     // alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
						      return; 
						} 	 
						if (xhr_object == null) {
						   // alert("Votre navigateur ne supporte pas AJAX");
							return;   
						}
						
							  // Fonction à exécuter quand on aura une réponse du serveur
							  xhr_object.onreadystatechange = function() {
							    // on ne traite que si on a tout recu et que la réponse du serveur est OK
							    if (xhr_object.readyState == 4 && xhr_object.status == 200) {
							    	var paiement_configuration = xhr_object.responseText.split('|');
							    	if(paiement_configuration[0]){ 
										form.attr("target", paiement_configuration[0]);
									}
							    	if(paiement_configuration[1]){ 
							    		$("#explication_paiement_cb").css({ display: "inline" });
									}
							    	if(paiement_configuration[2]){ 
							    		payment_method.attr("value", paiement_configuration[2]);
									}
									

							    }
							  }
							// connexion au serveur:
							xhr_object.open("GET","paiement.php?mode="+paymentid,true);	
							
							
							// envoi de la requete :
							xhr_object.send(null);
									

				}
			});
});