﻿function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var error_mail_invalide = "L'adresse email que vous avez entre est incorrecte, corrigez puis reessayez.";
		if (str.indexOf(at)==-1){
		   alert(error_mail_invalide);
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(error_mail_invalide);
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert(error_mail_invalide);
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert(error_mail_invalide);
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert(error_mail_invalide);
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert(error_mail_invalide);
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert(error_mail_invalide);
		    return false
		 }

 		 return true					
	}
	
function echeckSignup(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var error_mail_invalide = "L'adresse email que vous avez entre est incorrecte, corrigez puis reessayez.";
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}

function ValidateForm(){
	var emailID=document.fcdm_email.address
	var error = 0;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Merci d'insérer votre adresse email.")
		emailID.focus()
		error = 1;
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		error = 1;
	}
	if(error == 0) {
		$.fn.colorbox({width:"350px",height:"500px", inline:true, href:"#signup", overlayClose: false});
		document.fcdm_signup.address="";
		document.fcdm_signup.first_name="";
		document.fcdm_signup.last_name="";
		document.fcdm_signup.birthdate="";
		document.fcdm_signup.discipline="";
		document.fcdm_signup.address.value = emailID.value;
	}
}

function ValidateSignUp(){
	var emailID=document.fcdm_signup.address;
	var firstNameID=document.fcdm_signup.first_name;
	var lastNameID=document.fcdm_signup.last_name;
	var birthdateID=document.fcdm_signup.birthdate;
	var favouritePlayerID=document.fcdm_signup.favourite_player;
	var error = "";
	
	if ((emailID.value==null)||(emailID.value=="")){
		error += "Merci d'inscrire votre adresse email. \n";
	}
	if (echeckSignup(emailID.value)==false){
		error += "L'adresse email que vous avez entré est incorrecte, corrigez puis reessayez. \n";
	}
	
	if ((firstNameID.value==null)||(firstNameID.value=="")){
		error += "Merci d'insérer à nouveau votre nom. \n";
	}
	if ((lastNameID.value==null)||(lastNameID.value=="")){
		error += "Merci d'inscrire votre prénom. \n";
	}
	if ((birthdateID.value==null)||(birthdateID.value=="")){
		error += "Veuillez insérer votre date de naissance, merci. \n";
	}
	
	
	if (error != ""){
		alert(error);
		return false;
	} else {
		$.fn.colorbox.close();
		return true;
	}
}

function getReferer(form) {
	
	var path = document.location.href;
	form.referer.value = path;
}


$(function(){ 
	//$('input[title!=\'\']').hint();
});

$(document).ready(function(){
	/*$('#birthdate').datepicker({ // birthdate
		changeMonth: true,
		changeYear: true,
		yearRange: '1900:2010',
		dateFormat: 'dd-mm-yy'
	});

	$('.c').hide(); // hide all select's with class c
	$('#c20').show(); // show only select for france
	$('#countries').change( function () { 
		$('.c').hide();
		var country_name = $("#countries option:selected").text();
		var country_id = $("#countries option:selected").val();
		$("#"+country_id).show();
 	});
	*/
});
