
function VerificationEmail(elm)
{
	if (elm.value.indexOf("@") != "-1" &&
    elm.value.indexOf(".") != "-1" &&
    elm.value != "")
    return true;

return false;
}



function inscription()
{
		var reg_login = /^[a-zA-Z0-9-_.]{3,20}$/;
		
		if(!(reg_login.test(document.selection.nom.value)))
		{
			document.selection.nom.focus();
			alert("Le login n\'est pas valide ! Vous ne devez utilisez ques les lettres, chiffres et le caractères _");
			return false;
		}
		if (document.selection.email.value.indexOf('@') == '-1' || document.selection.email.value.indexOf('.') == '-1')
		{ 
			alert('veuillez saisir un email valide'); 
			return false; 
		}
		if (document.selection.nom.value.charAt(0) == " " || document.selection.nom.value.length == 0)
		{
			alert('Vous devez donner un nom à votre personnage');
			return false;
		}
		if (document.selection.pwd.value.charAt(0) == " " || document.selection.pwd.value.length == 0)
		{
			alert('Vous devez définir un mot de passe.');
			return false;
		}
		
		if (document.selection.race.value == "")
		{
			alert('Vous devez choisir la race de votre personnage');
			return false;
		}
		
		var coiffure 	= document.getElementById('coiffure').style.backgroundImage;
		var peau 		= document.getElementById('peau').style.backgroundImage;
		var first 		= document.getElementById('first').style.backgroundImage;
		var second 		= document.getElementById('second').style.backgroundImage;
		
		var carac_pv 	= document.selection.carac_pv.value;
		var carac_pe 		= document.selection.carac_pe.value;
		var carac_agilite 		= document.selection.carac_agilite.value;
		var carac_sagesse 		= document.selection.carac_sagesse.value;
		var carac_defense 	= document.selection.carac_defense.value;
		var carac_degats 		= document.selection.carac_degats.value;
		
		coiffure 	= coiffure.split("/");
		peau 		= peau.split("/");
		first 		= first.split("/");
		second 		= second.split("/");
		coiffure 	= coiffure[5].substring(0, coiffure[5].length-1)
		peau 		= peau[5].substring(0, peau[5].length-1)
		first 		= first[5].substring(0, first[5].length-1)
		second 		= second[5].substring(0, second[5].length-1)
	
		http_inscription = createRequestObject();
		http_inscription.open('post', 'ajax/inscription.php', true);
		http_inscription.onreadystatechange = inscription_result;
		http_inscription.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_inscription.send('nom='+document.selection.nom.value+'&pwd='+document.selection.pwd.value+'&email='+document.selection.email.value+'&race='+document.selection.race.value+'&sexe='+document.selection.sexe.value+'&coiffure='+coiffure+'&peau='+peau+'&first='+first+'&second='+second+'&carac_pv='+carac_pv+'&carac_pe='+carac_pe+'&carac_sagesse='+carac_sagesse+'&carac_agilite='+carac_agilite+'&carac_defense='+carac_defense+'&carac_degats='+carac_degats);
}

function inscription_result()
{
    if(http_inscription.readyState == 4)
    {
        if(http_inscription.status == 200)
        {
						//alert(http_inscription.responseText);
						var tab_callback = new Array();
						tab_callback['ko'] = new Array();
						tab_callback['ok'] = new Array();
						tab_callback['ko'][0] = "Un joueur utilise deja cette adresse email.";
						tab_callback['ko'][1] = "Un personnage porte deja ce nom.";
						tab_callback['ko'][1] = "La limite maximale de joueurs est atteinte pour le moment. Vous ne pouvez donc pas vous inscrire.";
						tab_callback['ok'][0] = "Inscription reussie";
						
						var tab = http_inscription.responseText.split("#");
						debug_ajax(tab[0], http_inscription.responseText, "inscription_result");
						alert(tab_callback[tab[0]][tab[1]]);
						login(document.selection.email.value, document.selection.pwd.value, 'none');
        }
        else
        {
            alert(http_inscription.status);
        }
		}
}




