﻿
function wodmailInit() {
    wodMailFormClose();

}

function wodMailFormClose() {
    $('#wodMailForm').hide();
}

function wodMailFormFadeOut() {
    $('#wodMailForm').fadeOut('slow');
}

function wodMailFormShow() {

    if (echeck($('.tbMailing').val()))
        $('.mailForm').fadeIn('fast');
}



function addWodMail() {

    var nom = ($('.tb_wodMailForm_nom').val() == '' || $('.tb_wodMailForm_nom').val() == undefined) ? '' : $('.tb_wodMailForm_nom').val();
    var sport = "0"
    var email = $('.tbMailing').val();
  
    $.ajax({
        type: "POST",
        url: "../WM/wodmail.aspx",
        data: "nom="+ nom +"&email="+ email +"&sport="+ sport +"",
        success: function (msg) {
        if(lg == 'fr')
            $('#bloc5').html('Merci, ' + nom + ' vous recevrez notre prochain envoi.');
         else
             $('#bloc5').html('Thank you,' + nom + 'You are now registred.');
         
        }
    });


}







/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		    alert("Courriel invalide")
		   return false
	}

	if (str == "moi@exemple.com")
	    return false

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Courriel invalide")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Courriel invalide")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		     alert("Courriel invalide")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		     alert("Courriel invalide")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		     alert("Courriel invalide")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		     alert("Courriel invalide")
		    return false
		 }

 		 return true					
	}

function Validemail(str){
	var emailID= str
	
	if ((emailID.value==null)||(emailID.value=="")){
	    alert("Courriel invalide")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

