// JavaScript Document
function closeInfolettre(){
	$('infolettrePopup').setStyle("display", "none");
	hideCache();
}

function showInfolettreForm(){
	showCache();
	$("infolettrePopup").setStyle("display", "block");
}

function submitInscription(lang){
	if (lang == "FR"){
		var missValueMsg = "Svp, entrez votre ";
		var wrongEmailMsg = "Votre adresse courriel n'est pas valide.";
		var thanksMsg = "Merci, vous êtes maintenant enregistré.";
		var txtnom = "nom";
		var txtprenom = "prénom";
	}else{
		var missValueMsg = "Please fill your ";
		var wrongEmailMsg = "Your email address is not valid.";
		var thanksMsg = "Thank you, you are now registered.";
		var txtnom = "last name";
		var txtprenom = "first name";
	}
	var valid = true;
	
	if($("name_txt").getValue() == ""){
		alert(missValueMsg + txtnom);
		$("name_txt").focus();
		valid = false;
	}else
	if ($("fname_txt").getValue() == ""){
		alert(missValueMsg + txtprenom);
		$("fname_txt").focus();
		valid = false;
	}else
	if (!isValidEmail($("email_txt").getValue())){
		alert(wrongEmailMsg);
		$("email_txt").focus();
		valid = false;
	}
	
	if (valid){
		$("infolettreForm").send({
		onComplete: function() {
			$("formulaireInfolettre").empty();
			$("formulaireInfolettre").setHTML(thanksMsg);
		}
	});
	}
}

//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = String(strEmail);

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      return false;
    }else{ 
      return true;
	}
}