$(document).ready(function() {

	// affichage layer tous les sites
	
	$('.showAZlayer').click(function(){
			$("#az_layer").toggle("slow");		
			return false;
	});
	
	$('.mon_parrain').click(function(){
			$(".parrainage").toggle("slow");		
			$(".parrainageV").toggle("slow");		
			return false;
	});
	
	$('.deconnexion').click(function(){
	 	$.get("/includes/php/deconnexion.php",
	 		{ idc: "0"},
	 		function(data){
	 			if(data == "OK") { 
	 				window.location.reload();
	 			}
	 		}
	 	);
	});
	
	
	$('#modif_email_compte').click(function(){
			$(".modif_email_compte_masqued").toggle("slow");		
			return false;
	})
	
	$('#modif_mdp_compte').click(function(){
			$(".modif_mdp_compte_masqued").toggle("slow");		
			return false;
	})
	
	
	$('#add_favorites').click(function() {
	
		var marchand = $("#add_favorites").attr("title");
	
		
	
			$.get("/includes/php/addfavorite.php",
	 				{ marchand:marchand},
				 function(data){
	 				if(data == "OK") { 
						// ok
					$("#marchand_partage .favoris").html('<a href="#" id="del_favorites" title="'+marchand+'">Retirer de mes sites favoris</a>')							
					return false;		
						
		 			} else {
		 				// nok deja pris
		 			return false;	
								
 					}
 				});
 						
		
	});
	
	$('#del_favorites').click(function() {
	
		var marchand = $("#del_favorites").attr("title");
	
		
	
			$.get("/includes/php/delfavorite.php",
	 				{ marchand:marchand},
				 function(data){
	 				if(data == "OK") { 
						// ok
					$("#marchand_partage .favoris").html('<a href="#" id="add_favorites" title="'+marchand+'">Ajouter à mes sites préférés</a>')							
					return false;		
						
		 			} else {
		 				// nok deja pris
		 			return false;	
								
 					}
 				});
 						
		
	});
	
	
	$(".cm_C_c_t").each(function(i){
       this.id = "#" + this.id;
    });
           
    
	$(".cm_C_c_t").not(":first").hide();
           
    $("#cm_nav_marchand #cm_nav_H .CR a").click(function() {
     	var idClient = $(this).attr("href");
     		$(".cm_C_c_t").hide();               
	     	$("div[id='" + idClient + "']").fadeIn();
			 $("#cm_nav_H a").removeClass('active');
			 $(this).addClass('active');                            
    return false;
     });
    
    $("#cm_nav_marchand #cm_nav_H .AVIS a").click(function() {
     	var idClient = $(this).attr("href");
     		$(".cm_C_c_t").hide();               
	     	$("div[id='" + idClient + "']").fadeIn();
			 $("#cm_nav_H a").removeClass('active');
			 $(this).addClass('active');                            
    return false;
     });
    
    $("#cm_nav_marchand #cm_nav_H .REL a").click(function() {
     	       
     		var marchand = $(this).attr("name");
     		$.get("/includes/php/Get_rel_info.php",
	 			{idm:marchand},
				 function(data){
				 
				 	var idClient = $(this).attr("href");
		     		$(".cm_C_c_t").hide();        
				 
				 	$("div[id='#content_REL']").html(data);							
	 				$("div[id='#content_REL']").fadeIn();
					$("#cm_nav_H a").removeClass('active');
					$("#cm_nav_marchand #cm_nav_H .REL a").addClass('active'); 
	 			
	 			}
     		);
     		
	     	                           
    return false;
     });
 
     
     


	// stars //
	
/*
.nostar {background-position:0 0}
.onestar {background-position:0 -16px}
.twostar {background-position:0 -32px}
.threestar {background-position:0 -48px}
.fourstar {background-position:0 -64px}
.fivestar	
	
*/
	$("#1").click(function() {
		$(".rating").removeClass('nostar onestar twostar threestar fourstar fivestar').addClass('onestar');
		$("#note_avis").val('1');
		return false;
	});

	$("#2").click(function() {
		$(".rating").removeClass('nostar onestar twostar threestar fourstar fivestar').addClass('twostar');
		$("#note_avis").val('2');
		return false;		
	});
	
	$("#3").click(function() {
		$(".rating").removeClass('nostar onestar twostar threestar fourstar fivestar').addClass('threestar');
		$("#note_avis").val('3');
		return false;		
	});
	
	$("#4").click(function() {
		$(".rating").removeClass('nostar onestar twostar threestar fourstar fivestar').addClass('fourstar');
		$("#note_avis").val('4');
		return false;		
	});

	$("#5").click(function() {
		$(".rating").removeClass('nostar onestar twostar threestar fourstar fivestar').addClass('fivestar');
		$("#note_avis").val('5');
		return false;		
	});				
	
	
	// faq //
	
	$("dd").hide();
		$("dt").css("cursor", "pointer");
		$("dt").click(function() {
			if($(this).next().is(":visible") == false) {
				$("dd").slideUp();
				$(this).next().slideDown();
			}
		});
		
		
	$(".content_form1").hide();	
	$(".content_form2").hide();	
	$(".content_form3").hide();		
	
	
	$(".contact_form1").click(function() {
		
		$(".content_form1").slideDown();
		$(".content_form2").slideUp();	
		$(".content_form3").slideUp()
		
		return false;			
	
	});
	
	
	$(".contact_form2").click(function() {
		
		$(".content_form2").slideDown();
		$(".content_form1").slideUp();	
		$(".content_form3").slideUp()
		
		return false;			
	
	});
	
	$(".contact_form3").click(function() {
		
		$(".content_form3").slideDown();
		$(".content_form2").slideUp();	
		$(".content_form1").slideUp()
		
		return false;			
	
	});
	
	$('.checked_all').click(function(){
			
			$("form#selection_email INPUT[@name=email_liste][type='checkbox']").attr('checked', true);
			return false;
	});
	
	$('.unchecked_all').click(function(){
			
			$("form#selection_email INPUT[@name=email_liste][type='checkbox']").attr('checked', false);
			return false;
	});
	
	// affichage felicitation
	
	var activationACT = $('#activationACT').text();
	

	if(activationACT == 1) {
		var activation = $('#activationCON').text();
    	$.nyroModalManual({
	     
	     	url: '/merci.php',
	      	closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="fermer"><img src="/img/close.gif" /></a>',
			cssOpt: { 
				wrapper: {
					overflow: 'hidden'
				}
			}
	      
    	});
	    return false;
	};
	
	


	$('a.nyroModal').nyroModal({
			width: '1060px',			
			cssOpt: { 
				wrapper: {
					overflow: 'auto',
					height : '330px',
					width : '954px'
				},				
				content: {
					width : '954px'
				},				
				nyroModalWrapper: {
					width : '954px'
				}
			}
			});
			
			
/*
.wrapper {
	height:330px;
	overflow:auto;
	width:954px;
}

#nyroModalContent {
	width: 954px;
}

#nyroModalWrapper {
	width: 954px;
}
*/			

	
	$(".pseudo").focusout(function() {
		var val = this.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)');											
				    ckckall();		
					
					} 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('');
								    ckckall();		
								


		 					} else {
		 						// nok deja pris
								$(".v_pseudo").html('<img src="/img/form_nok.png" alt="Pseudo déja utilisé" />')
								$(".er_pseudo").html('(Pseudo existant)');								
								    ckckall();		
		 					
		 					}
	 				}
	 	);
					}
			} 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)');								
								    ckckall();		
			
			}	
		} 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)');								
								    ckckall();		
		
		}
	});
	
	$(".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)');
								    ckckall();		
					
					} 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('');
								    ckckall();		

								
		 					} 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é)');
								    ckckall();		
								
		 					
		 					}
	 				}
	 				);
					}
	
		} else {
		//nok
					$(".v_email").html('<img src="/img/form_nok.png" alt="Email non valide" />')
					$(".er_email").html('(Format incorrect)');
								    ckckall();		
					

		}
	});


	$(".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('');
							    ckckall();		

							
		 				} 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)');
								    ckckall();		
							
							
	 					}
	 				}
	 	);
					
			} 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)');
								    ckckall();		
			
			
			}	
		} 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)');
								    ckckall();		
			
		
		}
	});

	$(".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('');
				    ckckall();		

				
				} else {
				// nok deja pris
						
				
				$(".v_capchta").html('<img src="/img/form_nok.png" alt="Votre code ne correspond pas" />');
				$(".er_capchta").html('(code incorrect)');				
				ckckall();
				}
			}
	 		);
			
	});
	
	$("#cgu").click(function() {
				    ckckall();		

	});

	
	$("#form_O1_O1_email").focusout(function() {
		var val = this.value;
		$("#message_email_erreur").hide();
		$("#autre_erreur").hide();
		var str ;
		var user = $(".h_info_user p span").text()
		$("#message_email_erreur").html(' ');
		$("#autre_erreur").html(' ');

		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
					str = $("#autre_erreur").text();
					$("#autre_erreur").html(str + '<p>Votre nouvel email n\'est pas valide</p>');
					} else {
					
						var valINIT = $("#form_O1_O1_email").value;
						//alert(valINIT);
						if (val == valINIT) {
							// ok 
						} else {
						$.get("/includes/php/checkformVal.php",
	 						{ cck: "email", value: val,user:user},
				 		function(data){
	 						if(data == "OK") { 
		 					} else {
		 						// nok deja pris
		 						str = $("#autre_erreur").text();
								$("#autre_erreur").html(str + '<p>Votre nouvel email existe déjà</p>');
		 					
		 					}
	 					}
		 				);
	 					}
					}
	
		} else {
		//nok
			str = $("#autre_erreur").text();
			$("#autre_erreur").html(str + '<p>Votre nouvel email n\'est pas valide</p>');
		}
		
		$.get("/includes/php/checkformVal.php",
	 		{ cck: "email_modif", user:user},
			function(data){
	 			if(data == "OK") { 
				// ok
				
				} else {
				// nok pas de mot de passe
					str = $("#message_email_erreur").text();
					$("#message_email_erreur").html(str + '<p>Vous devez renseigner votre mot de passe pour modifier votre email</p>');				
				}
	 		}
	 	);
			//alert(erreur);
			$("#message_email_erreur").show("fast");
			$("#autre_erreur").show("fast");

	
				
	});
	
	
	$("#form_O1_O1_pwd_email").focusout(function() {
		$("#message_email_erreur").hide();
		$("#message_pwd_erreur").hide();
		$("#autre_erreur").hide();
		var val = this.value;
		var user = $(".h_info_user p span").text()
		$.get("/includes/php/checkformVal.php",
	 		{ cck: "pws", value:val, user:user},
			function(data){
	 			if(data == "OK") { 
					$("#message_email_erreur").html('');
					$("#message_pwd_erreur").html('');
				} else {
				// nok mot de passe invalide
					$("#message_email_erreur").html('<p>Votre mot de passe n\'est pas valide</p>');
					$("#message_pwd_erreur").html('');
				}
	 		}
	 	);		
	
	$("#message_email_erreur").show();
	$("#message_pwd_erreur").show();	
	$("#autre_erreur").show();
	});
	
	
	$("#form_O1_O1_pwdN_old").focusout(function() {
		$("#message_email_erreur").hide();
		$("#message_pwd_erreur").hide();
		$("#autre_erreur").hide();
		var val = this.value;
		var user = $(".h_info_user p span").text()
		$.get("/includes/php/checkformVal.php",
	 		{ cck: "pws", value:val, user:user},
			function(data){
	 			if(data == "OK") { 
					$("#message_email_erreur").html('');
					$("#message_pwd_erreur").html('');
				} else {
				// nok mot de passe invalide
					$("#message_email_erreur").html('<p>Votre mot de passe n\'est pas valide</p>');
					$("#message_pwd_erreur").html('');
				}
	 		}
	 	);		
	
	$("#message_email_erreur").show();
	$("#message_pwd_erreur").show();	
	$("#autre_erreur").show();
	});

	$("#form_O1_O1_pwdN").focusout(function() {
		$("#message_pwd_erreur").hide();
		var val = this.value;
		var user = $(".h_info_user p span").text()
		$.get("/includes/php/checkformVal.php",
	 		{ cck: "pws_verif", user:user},
			function(data){
	 			if(data == "OK") { 
					$("#message_pwd_erreur").html('');
				} else {
				// nok mot de passe invalide
					$("#message_pwd_erreur").html('<p>Vous devez renseigner votre ancien mot de passe pour modifier votre mot de passe</p>');
				}
	 		}
	 	);		
	
	$("#message_pwd_erreur").show();
	});
	
	
	

});


// show CR

function show(get,idm,userW) {

	
	$.get("/includes/php/showCR.php",
  		{ idc: get, idm: idm, userw:userW },
  	function(data){
    	$("#cr_"+get).html('<div class="code_affiche"><p>'+data+'</p></div><div class="logo_marchand"><img src="http://www.wajestic.com/redirection/logo_marchand.jpg?idm='+idm+'&userw='+userW+'" /></div>');
  	}
  	
 
);	


}

