function VerifPseudo(pseudo)
{
	var regexp = /^[\w\_\9]+$/; 
	if (pseudo.length==0)
	{
		window.alert("Veuillez choisir un pseudo.");
		return false;
	}
	if (!regexp.test(pseudo))
	{
		window.alert("Pseudo incorrect.");
		return false;
	}
	return true;
}

function VerifMail(mail)
{
	valide1 = false;

	for(var j=1;j<(mail.length);j++){
		if(mail.charAt(j)=='@'){
			if(j<(mail.length-4)){
				for(var k=j;k<(mail.length-2);k++){
					if(mail.charAt(k)=='.') valide1=true;
				}
			}
		}
	}
	if(valide1==false) window.alert("Veuillez saisir une adresse email valide.");
	return valide1;
}



function VerifPassword(password, password2)
{
	if (password!=password2)
	{
		window.alert("Veuillez confirmer correctement votre mot de passe");
		return false;
	}
	else if (password.length<5)
	{
		window.alert("Veuillez saisir un mot de passe de plus de 5 carractères");
		return false;
	}
	else
		return true;
}



function call_ajax(methode, div)
{
   var xhr; 
    try { xhr = new XMLHttpRequest(); }                 
    catch(e) 
    {    
      xhr = new ActiveXObject('Microsoft.XMLHTTP');
    }
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if((xhr.status==200))
			  {
				  if (xhr.responseText.indexOf('#')>0)
				  {
					if (div==null)
						window.alert(xhr.responseText.substring(0,xhr.responseText.indexOf('#')));
					else
						document.getElementById(div).innerHTML=xhr.responseText.substring(0,xhr.responseText.indexOf('#')); 
					var y=document.createElement('span');
					y.innerHTML=xhr.responseText.substring(xhr.responseText.indexOf('#')+1, xhr.responseText.length);
					window.alert(y.innerHTML);
				  }
				  else
				  {
					if (div==null)
						window.alert(xhr.responseText);
					else
						document.getElementById(div).innerHTML=xhr.responseText; 
				  }
			  }
         }
    }; 
   xhr.open('GET', methode,  true); 
   xhr.send(null); 
}



function vote(id)
{
	call_ajax('/actions/vote.php?id='+id, 'votes_'+id);
}

function vote_blog(id)
{
	call_ajax('/actions/voteblog.php?id='+id, 'votes_blog_'+id);
}

function favoris_ajoute(id)
{
	call_ajax('/actions/favoris_ajoute.php?id='+id, 'favoris_'+id);
}

function ignore_ajoute(id)
{
	call_ajax('/actions/ignore_ajoute.php?id='+id, 'ignore_'+id);
}

function favoris_ajoute_cat(id)
{
	call_ajax('/actions/favoris_ajoute_cat.php?id='+id, 'favoris_cat'+id);
}

function favoris_enleve(id)
{
	call_ajax('/actions/favoris_enleve.php?id='+id, 'favoris_'+id);
}

function ignore_enleve(id)
{
	call_ajax('/actions/ignore_enleve.php?id='+id, 'ignore_'+id);
}

function favoris_enleve_cat(id)
{
	call_ajax('/actions/favoris_enleve_cat.php?id='+id, 'favoris_cat'+id);
}

function alerte_moderateur(id)
{
	call_ajax('/actions/moderation.php?id='+id, null);
}

function mot_de_passe_oublie(pseudo)
{
	if (pseudo.length>0)
	{
		call_ajax('/actions/mot_de_passe_oublie.php?pseudo='+pseudo, null)
	}
	else
	{
		window.alert('Veuillez saisir un pseudo valide pour que votre mot de passe vous soit restitué');
	}
}