﻿/* Inscription */
var imgOk = "./imgs/insc_ok.gif";
var imgPOk = "./imgs/insc_pok.gif";
$(document).ready(function(){
	$("#formulaire .vNom").keyup(function() {
		var expr = /^([a-zA-Z ])+(-){0,1}([a-zA-Z ]){0,}$/;
		if ( expr.exec($(this).val()) ) 
			$(this).next("img").attr("src",imgOk);
		else 
			$(this).next("img").attr("src",imgPOk);
	});
	$("#formulaire .vNum").keyup(function() {
		var expr = /^(00|\+)[0-9]{10,}$/;
		if ( expr.exec($(this).val()) ) 
			$(this).next("img").attr("src",imgOk);
		else 
			$(this).next("img").attr("src",imgPOk);
	});
	$("#formulaire .vMail").keyup(function() {
		var expr = /^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$/;
		if ( expr.exec($(this).val()) ) 
			$(this).next("img").attr("src",imgOk);
		else 
			$(this).next("img").attr("src",imgPOk);
	});
	$("#ijeu1").change(function () {
		$("#fog").hide('slow');
		$("#fow").hide('slow');
	});
	$("#ijeu2").change(function () {
		$("#fow").hide('slow');
		$("#fog").show('slow');
	});
	$("#ijeu3").change(function () {
		$("#fog").hide('slow');
		$("#fow").show('slow');
	});
	$("#inscform").submit(function() {
		var inscok = true;
		var nexpr = /^([a-zA-Z ])+(-){0,1}([a-zA-Z ]){0,}$/;
		var texpr = /^(00|\+)[0-9]{10,}$/;
		var mexpr = /^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$/;
		if ( ! nexpr.exec($("#inom").val()) ) { inscok = false;  }
		if ( ! nexpr.exec($("#ipnom").val()) ) { inscok = false; }
		if ( ! nexpr.exec($("#ipay").val()) ) { inscok = false; }
		if ( ! texpr.exec($("#itel").val()) ) { inscok = false; }
		if ( ! mexpr.exec($("#imail").val()) ) { inscok = false; }
		if ( $('input[name=ijeu]:radio:checked').attr('value') == 1 )  {
			if ( $('input[name=ifogpoule]:radio:checked').attr('value') == null ) {
				inscok = false;
				alert("Please select a fog pool");
			}
		} 
		else if ( $('input[name=ijeu]:radio:checked').attr('value') == 2 ) { 
			if ( $('input[name=ifowpoule]:radio:checked').attr('value') == null ) {
				inscok = false;
				alert("Please select a fow pool");
			}
		}
		if ( $('#recaptcha_response_field').val().length == 0 ) {
			inscok = false;
			alert("Please fill the Capcha");
		}
		return inscok;
	});
});
