 $(document).ready(function() {
    $(".drag").draggable({ 
    	revert: "invalid"  	
    });
    $(".drop").droppable({
      over: function() { 
            $('#'+this.id).addClass(" active");
            
      },
      out: function() { 
            $('#'+this.id).removeClass(" active");
            
      },
     
      drop: function() { 
      		$('.drop').removeClass("dropped");
      		$('#'+this.id).addClass("dropped");
      		
      		var  reg=new  RegExp("[_]+", "g");
  			var  jeton=this.id.split(reg);
      		
    		$("#j_form_div").html('<input type="hidden" name="j" id = "j_form" value="'+jeton[1]+'" />');
    		
    		/*if (jeton[1] == "2E") {
	    		$("#j_form_message").html('Vous avez choisi de gagner 2 euros sur votre achat :');
    		} else {
    			$("#j_form_message").html('Vous avez choisi le n° '+jeton[1]+' pour être intégralement remboursé :');
    		}*/
    			$("#j_form_message").html('Le jeu de la roulette est terminé. Vous gagnez 2 euros sur vos achats.');
		   ckckall();		

      }
    });
  });



function clickjeton (jetonC) {
	$('.drop').removeClass("dropped")
	$('#'+jetonC).addClass("dropped");
      		
    var  reg=new  RegExp("[_]+", "g");
  	var  jeton=jetonC.split(reg);
      		
    $("#j_form_div").html('<input type="hidden" name="j" id = "j_form" value="'+jeton[1]+'" />');
    
    /*if (jeton[1] == "2E") {
	   	$("#j_form_message").html('Vous avez choisi de gagner 2 euros sur votre achat :');
    } else {
    	$("#j_form_message").html('Vous avez choisi le n° '+jeton[1]+' pour être intégralement remboursé :');
    }*/
    $("#j_form_message").html('Le jeu de la roulette est terminé. Vous gagnez 2 euros sur vos achats.');

    ckckall();		
    
}

function ckckall() {


	var erreur = 0;
	var val;
	
	// verif jeton
	
	var val = $("#j_form").attr('value');
	if(val.length > 0) {
	
	} else {
		erreur = 1
	}
	
	
	// verif pseudo
	
	var val = $(".form_ins_plateau .pseudo").attr('value');
			
		if(val.length > 2) {
			if(val.length < 21) {
				var verif = /^[0-9a-zA-Z]+$/;
					if (verif.exec(val) == null) {
					//nok
					//$(".v_pseudo").html('<img src="/img/form_nok.png" alt="Pseudo non valide" />')
					//$(".er_pseudo").html('(doit faire entre 3 et 20 caractères)');											
					erreur = 1;
					} else {
						$.get("/includes/php/checkformVal.php",
	 						{ cck: "pseudo", value: val},
				 		function(data){
	 						if(data == "OK") { 
								// ok
								//$(".v_pseudo").html('<img src="/img/form_ok.png" alt="Pseudo valide" />')
								//$(".er_pseudo").html('');	
															


		 					} else {
		 						// nok deja pris
								//$(".v_pseudo").html('<img src="/img/form_nok.png" alt="Pseudo déja utilisé" />')
								//$(".er_pseudo").html('(Pseudo existant)');
								erreur = 1;								
		 					
		 					}
	 				}
	 	);
					}
			} else {
			//nok
//			$(".v_pseudo").html('<img src="/img/form_nok.png" alt="Pseudo non valide" />')			
//			$(".er_pseudo").html('(doit faire entre 3 et 20 caractères)');								
			erreur = 1;
			}	
		} else {
		//nok
//		$(".v_pseudo").html('<img src="/img/form_nok.png" alt="Pseudo non valide" />')
//		$(".er_pseudo").html('(doit faire entre 3 et 20 caractères)');								
		erreur = 1;
		}
	
	var val = $(".form_ins_plateau .email").attr('value');
		if(val.length > 0) {
				var verif = /^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,4}$/;
					if (verif.exec(val) == null) {
					//nok
//					$(".v_email").html('<img src="/img/form_nok.png" alt="Email non valide" />')
//					$(".er_email").html('(Format incorrect)');
					erreur = 1;	
					} else {
						$.get("/includes/php/checkformVal.php",
	 						{ cck: "email", value: val},
				 		function(data){
	 						if(data == "OK") { 
								// ok
//								$(".v_email").html('<img src="/img/form_ok.png" alt="Email valide" />')
//								$(".er_email").html('');
								
		 					} else {
		 						// nok deja pris
//								$(".v_email").html('<img src="/img/form_nok.png" alt="Cet email existe déja" />')
//								$(".er_email").html('(email déjà utilisé)');
								erreur = 1;	
		 					
		 					}
	 				}
	 				);
					}
	
		} else {
		//nok
//					$(".v_email").html('<img src="/img/form_nok.png" alt="Email non valide" />')
//					$(".er_email").html('(Format incorrect)');
					erreur = 1;	

		}
		
		
	var val = $(".form_ins_plateau .mdp").attr('value');
		if(val.length > 5) {
			if(val.length < 21) {
				
					$.get("/includes/php/checkformVal.php",
	 					{ cck: "mdp", value: val},
					function(data){
	 					if(data == "OK") { 
							// ok
//							$(".v_mdp").html('<img src="/img/form_ok.png" alt="Mot de passe valide" />')
//							$(".er_mdp").html('');
							
		 				} else {
		 					// nok deja pris
//							$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')		
//							$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
							erreur = 1;	
							
	 					}
	 				}
	 	);
					
			} else {
			//nok
//			$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')			
//			$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
			erreur = 1;	
			
			}	
		} else {
		//nok
//		$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')
//			$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
			erreur = 1;	
		
		}
		
	var val = $(".form_ins_plateau .capchta").attr('value');
//	alert(val);
			$.get("/includes/php/checkformVal.php",
	 			{ cck: "capchta", value: val},
			function(data){
	 			//alert(data);
	 			if(data == "OK") { 
	 			
				// ok
//				$(".v_capchta").html('<img src="/img/form_ok.png" alt="Code valide" />');
//				$(".er_capchta").html('');
				
				} else {
				// nok deja pris
//				$(".v_capchta").html('<img src="/img/form_nok.png" alt="Votre code ne correspond pas" />');
//				$(".er_capchta").html('(code incorrect)');				
				erreur = 1;	
				}
			}
	 		);
	 		
	 		
	 var val = $("input:checked").length;
	 
	 if (val == 1) {
					

	} else {
	
		erreur = 1
	}
	
	//alert(erreur);
	
	if (erreur == 0) {

    $("#j_form_valid").html('<input type="submit" class="submit" value="" />');	
	
	
	}  else {
	
	 $("#j_form_valid").html('<div class="off"><img src="/img/strategie/bt_validerOFF.png" alt="Choisissez une strategie pour continuer" /></div>');
		
	}

}




/*


	$(".pseudo").focusout(function() {
		
	});
	
	$(".email").focusout(function() {
		var val = this.value;
		if(val.length > 0) {
				var verif = /^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,4}$/;
					if (verif.exec(val) == null) {
					//nok
					$(".v_email").html('<img src="/img/form_nok.png" alt="Email non valide" />')
					$(".er_email").html('(Format incorrect)');
					} else {
						$.get("/includes/php/checkformVal.php",
	 						{ cck: "email", value: val},
				 		function(data){
	 						if(data == "OK") { 
								// ok
								$(".v_email").html('<img src="/img/form_ok.png" alt="Email valide" />')
								$(".er_email").html('');
								
		 					} else {
		 						// nok deja pris
								$(".v_email").html('<img src="/img/form_nok.png" alt="Cet email existe déja" />')
								$(".er_email").html('(email déjà utilisé)');
		 					
		 					}
	 				}
	 				);
					}
	
		} else {
		//nok
					$(".v_email").html('<img src="/img/form_nok.png" alt="Email non valide" />')
					$(".er_email").html('(Format incorrect)');

		}
	});


	$(".confirm_email").focusout(function() {
		var val = this.value;
		if(val.length > 0) {
			$.get("/includes/php/checkformVal.php",
	 			{ cck: "email_verif", value: val},
			function(data){
	 			if(data == "OK") { 
				// ok
				$(".v_Vemail").html('<img src="/img/form_ok.png" alt="Email valide" />');
				} else {
				// nok deja pris
				$(".v_Vemail").html('<img src="/img/form_nok.png" alt="Votre email ne correspond pas" />');
				}
			}
	 		);
			
		} else {
		//nok
		$(".v_Vemail").html('<img src="/img/form_nok.png" alt="Champ vide" />')
		}
	});

	
	$(".mdp").focusout(function() {
		var val = this.value;
		if(val.length > 5) {
			if(val.length < 21) {
				
					$.get("/includes/php/checkformVal.php",
	 					{ cck: "mdp", value: val},
					function(data){
	 					if(data == "OK") { 
							// ok
							$(".v_mdp").html('<img src="/img/form_ok.png" alt="Mot de passe valide" />')
							$(".er_mdp").html('');
							
		 				} else {
		 					// nok deja pris
							$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')		
							$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
							
	 					}
	 				}
	 	);
					
			} else {
			//nok
			$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')			
			$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
			
			}	
		} else {
		//nok
		$(".v_mdp").html('<img src="/img/form_nok.png" alt="Mot de passe non valide" />')
			$(".er_mdp").html('(doit faire entre 6 et 20 caractères)');
		
		}
	});

	$(".confirm_mdp").focusout(function() {
		var val = this.value;
		if(val.length > 0) {
			$.get("/includes/php/checkformVal.php",
	 			{ cck: "mdp_verif", value: val},
			function(data){
	 			if(data == "OK") { 
				// ok
				$(".v_Vmdp").html('<img src="/img/form_ok.png" alt="Mot de passe valide" />');
				} else {
				// nok deja pris
				$(".v_Vmdp").html('<img src="/img/form_nok.png" alt="Votre Mot de passe ne correspond pas" />');
				}
			}
	 		);
			
		} else {
		//nok
		$(".v_Vmdp").html('<img src="/img/form_nok.png" alt="Champ vide" />')
		}
	});
	
	
	$(".parrain").focusout(function() {
		var val = this.value;
			
			$.get("/includes/php/checkformVal.php",
	 			{ cck: "parrain", value: val},
			function(data){
	 			if(data == "OK") { 
				// ok
				$(".v_parrain").html('<img src="/img/form_ok.png" alt="Votre parrain existe" />');
				$(".er_parrain").html('');
				
				} else {
				// nok deja pris
				$(".v_parrain").html('<img src="/img/form_nok.png" alt="Votre parrain n\'existe pas" />');
				$(".er_parrain").html('(Pseudo du parrain inconnu)');
				
				}
			}
	 		);
			
	});
	
	$(".capchta").focusout(function() {
			var val = this.value;
			
			$.get("/includes/php/checkformVal.php",
	 			{ cck: "capchta", value: val},
			function(data){
	 			if(data == "OK") { 
				// ok
				$(".v_capchta").html('<img src="/img/form_ok.png" alt="Code valide" />');
				$(".er_capchta").html('');
				
				} else {
				// nok deja pris
				$(".v_capchta").html('<img src="/img/form_nok.png" alt="Votre code ne correspond pas" />');
				$(".er_capchta").html('(code incorrect)');				
				}
			}
	 		);
			
	});

*/

