// Vérification de l'enregistrement

function Ajax_Register() 
{
	
	// recuperation des champs du formulaire
	var firstname = $('#firstname').val();
	var gender = $('[name=gender]:checked').val();
	var emailaddress = $('#emailaddress').val();
	var country = $('#country option:selected').attr('id');
	var lastname = $('#lastname').val();
	var month = $('#month option:selected').attr('id');
	var day = $('#day option:selected').attr('id');
	var year = $('#year option:selected').attr('id');
	var sex = "";//$('#year option:selected').attr('id');
	var language = $('#language option:selected').attr('id');
	var username = $('#username').val();
	var password = $('#password').val();
	var passwordconfirmation = $('#passwordconfirmation').val();
//	var tos = $('#tos:checkbox').val();
	var tos = document.getElementById('tos').checked;
	var captcha = $('#captcha').val();
	var subscription = $('[name=subscription]:checked').attr('value');

	$.ajax
	({
		type: 'POST',
		url: "/ajax/Register.php",		
		data: "firstname="+firstname+"&emailaddress="+emailaddress+"&gender="+gender+"&country="+country+"&lastname="+lastname+"&month="+month+"&day="+day+"&year="+year+"&language="+language+"&username="+username+"&password="+password+"&passwordconfirmation="+passwordconfirmation+"&tos="+tos+"&captcha="+captcha+"&subscription="+subscription,
		
		dataType: 'json',

		success: function (reponse) 
		{
			$("#personnal ul li").remove();
			$("#account ul li").remove();
			$("#last ul li").remove();
			
			if (reponse.sessionTest == "false")
			{
				document.location.href = "";
			}
			else if (reponse.state=="success")
			{
				// if subscribed offer is free testing
				if (reponse.subscriptionId >= 1000 && reponse.subscriptionId < 2000)
				{
					// return confirmation
					// cache le formulaire
					$("#personnal").hide();
					$("#account").hide();
					$("#last").hide();
					// renome le titre de la page
					$("#title").html(reponse.confirmTitle);
					// affiche le message de confirmation
					$("#confirm").html(reponse.confirmMessage);
					// modification du DOM
					$("#header").attr('class','in');
					// changement du menu
					UI_Navigation_AccountTabs_Show();
					// changement de l'identification (affichage déconnexion)
					$('div.navigation > div.identification > div.feedback').html(reponse.identificationMessage);
					UI_Identification_UserFeedback('success');
					// affiche le jeu
		     		// $("div#game").show();
					// haut de page
					document.location.href="#";
				}
				else
				{
					// send to paypal => validate specific form
					$("form#paypalForm input[name='custom']").val(reponse.custom);
					$('form#paypalForm input[name=item_name]').val(reponse.itemName);
					$('form#paypalForm input[name=amount]').val(reponse.amount);
					$('form#paypalForm input[name=quantity]').val(reponse.quantity);
					$('form#paypalForm input[name=return]').val(reponse.returnSuccess);
					$('form#paypalForm input[name=cancel_return]').val(reponse.returnCancel);
					$('form#paypalForm input[name=notify_url]').val(reponse.notifyUrl);
//					$('form#paypalForm input[name=country]').val(reponse.country);
					$('form#paypalForm input[name=first_name]').val(reponse.firstName);
					$('form#paypalForm input[name=last_name]').val(reponse.lastName);
//					$('form#paypalForm input[name=lc]').val(reponse.lc);
										
					$('form#paypalForm').submit();
				}				
			}
			else
			{
				// PERSONNAL
				
				if (reponse.alertFirstname!="")
				{
					var TalertFirstname = reponse.alertFirstname.split('[#]');
					
					$('#personnal ul').append('<li class="'+TalertFirstname[1]+'">'+TalertFirstname[0]+'</li>');
				}
				
				if (reponse.alertLastname!="")
				{
					var TalertLastname = reponse.alertLastname.split('[#]');
					
					$('#personnal ul').append('<li class="'+TalertLastname[1]+'">'+TalertLastname[0]+'</li>');
				}
				
				if (reponse.alertGender!="")
				{
					var TalertGender = reponse.alertGender.split('[#]');
					
					$('#personnal ul').append('<li class="'+TalertGender[1]+'">'+TalertGender[0]+'</li>');
				}
				
				if (reponse.alertMail!="")
				{
					var TalertMail = reponse.alertMail.split('[#]');
					
					$('#personnal ul').append('<li class="'+TalertMail[1]+'">'+TalertMail[0]+'</li>');
				}
				
				if (reponse.alertBirthDate!="")
				{
					var TalertBirthDate = reponse.alertBirthDate.split('[#]');
					
					$('#personnal ul').append('<li class="'+TalertBirthDate[1]+'">'+TalertBirthDate[0]+'</li>');
				}
				
				// ACCOUNT
				
				if (reponse.alertUsername!="")
				{
					var TalertUsername = reponse.alertUsername.split('[#]');
					
					$('#account ul').append('<li class="'+TalertUsername[1]+'">'+TalertUsername[0]+'</li>');
				}
				
				if (reponse.alertPassword!="")
				{
					var TalertPassword = reponse.alertPassword.split('[#]');
					
					$('#account ul').append('<li class="'+TalertPassword[1]+'">'+TalertPassword[0]+'</li>');
				}
				
				if (reponse.alertPasswordConfirm!="")
				{
					var TalertPasswordConfirm = reponse.alertPasswordConfirm.split('[#]');
					
					$('#account ul').append('<li class="'+TalertPasswordConfirm[1]+'">'+TalertPasswordConfirm[0]+'</li>');
				}
				
				if (reponse.alertPasswordValid!="")
				{
					var TalertPasswordValid = reponse.alertPasswordValid.split('[#]');
					
					$('#account ul').append('<li class="'+TalertPasswordValid[1]+'">'+TalertPasswordValid[0]+'</li>');
				}
				
				// LAST
				
				if (reponse.alertTos!="")
				{
					var TalertTos = reponse.alertTos.split('[#]');
					
					$('#last ul').append('<li class="'+TalertTos[1]+'">'+TalertTos[0]+'</li>');
				}
				
				if (reponse.alertCode!="")
				{
					var TalertCode = reponse.alertCode.split('[#]');

					$('#last ul').append('<li class="'+TalertCode[1]+'">'+TalertCode[0]+'</li>');
				}
				
				if (reponse.alertSubscription!="")
				{
					var TalertSubscription = reponse.alertSubscription.split('[#]');

					$('#last ul').append('<li class="'+TalertSubscription[1]+'">'+TalertSubscription[0]+'</li>');
				}
				
			}
		},

		error: function () {
			// alert('error');
		}

	});// End Ajax

}

