//js pour le menu principale
function bullOv(id,linkIn){
	if (linkIn){
		$("#"+id).html('<img src="../media/buletOv.jpg" width="19" height="18"  class="imgBull" />');
	}else{
		$("#"+id).html('<img src="media/buletOv.jpg" width="19" height="18"  class="imgBull" />');
	}
	

}

function bullOut(id,linkIn){
	if (linkIn){
		$("#"+id).html('<img src="../media/bullet.jpg" width="19" height="18"  class="imgBull" />');
	}else{
		$("#"+id).html('<img src="media/bullet.jpg" width="19" height="18"  class="imgBull" />');
	}
	
	//$("#"+id).css( "backgroundImage", "url(media/CATALOGUE/btnOverBG.png)" )
	//$('#btnProduit')('<img src="media/menu/Produit_Over.jpg" name="fgh" width="118" height="57" border="0" id="fgh" />');
}
//fin fonction pour menu principale


//js pour le sous menu
function bullOvSous(id,linkIn){
	if (linkIn){
		$("#"+id).html('<img src="../media/SousBullOv.jpg" width="15" height="16" align="absmiddle" class="SousimgBull"/>');
	}else{
		$("#"+id).html('<img src="../media/SousBullOv.jpg" width="15" height="16" align="absmiddle" class="SousimgBull"/>');
	}
}

function bullOutSous(id,linkIn){
	if (linkIn){
		$("#"+id).html('<img src="../media/SousBull.jpg" width="15" height="16" align="absmiddle" class="SousimgBull"/>');
	}else{
		$("#"+id).html('<img src="../media/SousBull.jpg" width="15" height="16" align="absmiddle" class="SousimgBull"/>');
	}
	//$("#"+id).css( "backgroundImage", "url(media/CATALOGUE/btnOverBG.png)" )
	//$('#btnProduit')('<img src="media/menu/Produit_Over.jpg" name="fgh" width="118" height="57" border="0" id="fgh" />');
}
//fin fonction pour le sous menu

//fonction generateur de mesage bulltin wow
function showmessage(id){
	var msgAccueil, msgErr, msgEmailValid, msgGood, msgAlert
	msgAccueil = "Restez à l'affût des tendances de communication au Québec et à Montréal : inscrivez-vous au Bulletin WöW!"
	msgErr = "<span class='RedErr'>*Veuillez remplir tous les champs</span>"
	msgEmailValid = "<span class='RedErr'>*Veuillez indiquer une adresse électronique valide <br>(ex.: smith@msn.com).</span>" 
	msgGood = "<strong>vous êtes inscrit au Bulletin WOW.</strong>"
	msgBad = "<span class='RedErr'>Vous êtes déjà inscrit avec cette adresse courriel.<br> Pour le recevoir à une autre adresse veuillez modifier le champ courriel.</span>"
	//message general
	if(id == 1){
		msgAlert = msgAccueil
	}
	//message remplir tout les champs
	if(id == 2){
		msgAlert = msgErr
	}
	
	//message email invalide
	if(id == 3){
		msgAlert = msgEmailValid
	}
	//email est correct
	if(id == 4){
		msgAlert = msgGood
	}
	//email deja inscrite
	if(id == 5){
		msgAlert = msgBad
	}
	//retourne le msg demander 
	return msgAlert
}

	//global variable
	var isFirstKeyS
function msgErrRemove(){

	//voir si c'est le premier keystroke
	if(isFirstKeyS){
		$("#badFormWow").html("");
		$("#badFormWow").css("display","none")
		$("#FormWow").html(showmessage(1)).fadeIn("slow")
		$("#Email").css("borderColor","#5D6A72")
		isFirstKeyS = false;
	}
}

function valid(){
		var Prenom, Nom, Email
		var EmailFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

		Prenom = $("#Prenom").val()
		Nom = $("#Nom").val()
		Email = $("#Email").val()
		//alert(Prenom)
		//alert(Nom)
		//alert(Email)
		Prenom = Prenom.replace(/\;/g,"");
		Nom =  Nom.replace(/\;/g,"");
		
		//vlaider si le Email est présent
		if(Email ==""){
			//alert("Entrer le Email !")
			$("#Email").focus()
			$("#Email").css("borderColor","Red")
			//Email.style.borderColor = "Red"
			$("#FormWow").html("")
			$("#FormWow").css("display","none")
			$("#badFormWow").html(showmessage(2)).fadeIn("slow")
			
			//isFirstKeyS remetre le keypress a false pour changer
			//la couleur du textebox de rouge a gris
			isFirstKeyS = true;
			
		}
		if (Email != "") {
			// doit etre du bon forma 
			if(!(EmailFilter.test(Email))){
				//alert("Veuillez indiquer une adresse électronique valide pour votre entreprise \n(ex.: smith@msn.com).");
				$("#Email").focus()
				$("#Email").css("borderColor","Red")
				//alert("*Veuillez indiquer une adresse électronique valide \n(ex.: smith@msn.com).")
				$("#FormWow").html("")
				$("#FormWow").css("display","none")
				$("#badFormWow").html(showmessage(3)).fadeIn("slow")
				//isFirstKeyS remetre le keypress a false pour changer
				//la couleur du textebox de rouge a gris
				isFirstKeyS = true;
				
			}else{//------sinon email est valide! 
				/*variable ajax a envoyer et traiter*/
				fName = $("#Prenom").val()
				lName = $("#Nom").val()
				mail = $("#Email").val()
				fName =  fName.replace(/\;/g,"");
				lName =  lName.replace(/\;/g,"");
				mail =  mail.replace(/\;/g,"");
				//do some ajax
				$.ajax({
					type: "get",
					//a quelle page je submit le formulaire 
					url: "traitInfoLettre.asp",
					dataType: "html",
					data: "Prenom="+fName+"&Nom="+lName+"&Email="+mail+"",
					
					success: function(isGood){
					
						isGoodTab = isGood.split(";")
						
						isGood = parseInt(isGoodTab[0])
					//si isGood = true nous avions bien inscrit la personne dans la BD
						if(isGood){
							//affiche message comme quoi tout est correct
							$("#FormWow").html("")
							$("#FormWow").css("display","none")
							//$("#goodFormWow").html("vous êtes inscrit au Bulletin WOW.").fadeIn("slow")
							if(isGoodTab[1] == "null" || isGoodTab[2] == "null"){
								$("#FormWow").html(showmessage(4)).fadeIn("slow")
							}else{
								$("#FormWow").html("<strong>"+isGoodTab[1]+" "+isGoodTab[2]+"</strong><br>"+showmessage(4)).fadeIn("slow")
							}
							
							$("#Prenom").val("")
							$("#Nom").val("")
							$("#Email").val("")
							
							
							
						}else{
							$("#FormWow").html("")
							$("#FormWow").css("display","none")
							//$("#badFormWow").html("Error : vous êtes deja inscrit.").fadeIn("slow")
							$("#badFormWow").html(showmessage(5)).fadeIn("slow")
							$("#Email").focus()
							$("#Email").css("borderColor","Red")
							
							//isFirstKeyS remetre le keypress a false pour changer
							//la couleur du textebox de rouge a gris
							isFirstKeyS = true;
						}
					//
					
					
					}//callbck
				});//AJAX
				//alert("good to go!")
			}
		}
}

//gerer le enter key
$('#Email').keypress(function(event) {
								 //alert("hello kevin")
  if (event.keyCode == '13') {
     //event.preventDefault();
	 valid()
   }
});

//CHECK VOIR SI ENTER EST CALLER POUR FAIRE LE SUBMIT FORM :)
$(document).keypress(function(e) {
	 
	 valueInput = document.getElementById("Email").value
      switch(e.keyCode) { 
         // User pressed "enter"
         case 13:
            if(valueInput != '') {
               //window.location = currentUrl;
			   valid();
            }
         break;
      }
   });


function loadMsg(id){
	var id
	$("#FormWow").html(showmessage(id))
}

