// JavaScript Document


//Check form fields are non blank on admin page
function checkAdmin()
{
    if(document.Form_admin.password1.value == "")
    {
        alert("Veuillez saisir le nouveau mot de passe !")
        document.Form_admin.password1.focus();
        return false;
    }
    if(document.Form_admin.password2.value == "")
    {
        alert("Veuillez confirmer le nouveau mot de passe !")
        document.Form_admin.password2.focus();
        return false;
    }
    if(document.Form_admin.password2.value != document.Form_admin.password1.value)
    {
        alert("Veuillez reconfirmer le nouveau mot de passe !")
        document.Form_admin.password2.focus();
        return false;
    }
}


//Check form fields are non blank on Login page
function checkLogin()
{
    if(document.Form_login.login.value == "")
    {
        alert("Veuillez saisir votre login !")
        document.Form_login.login.focus();
        return false;
    }
    if(document.Form_login.password.value == "")
    {
        alert("Veuillez saisir votre mot de passe !")
        document.Form_login.password.focus();
        return false;
    }
}

//Check form fields are non blank on Forum page
function checkForum()
{
    if(document.form1.topic.value == "")
    {
        alert("Veuillez saisir le sujet !")
        document.form1.topic.focus();
        return false;
    }
}

//Check form fields are non blank on News (Modification) page
function checkModifNews()
{
    if(document.form1.revTitre.value == "")
    {
        alert("Veuillez saisir le titre !")
        document.form1.revTitre.focus();
        return false;
    }
}

//Check form fields are non blank on Add doc page
function checkAddDoc()
{
    if(document.ajout.bib_titre.value == "")
    {
        alert("Veuillez saisir le titre !")
        document.ajout.bib_titre.focus();
        return false;
    }
    if(document.ajout.bib_auteur.value == "")
    {
        alert("Veuillez saisir le nom d'auteur !")
        document.ajout.bib_auteur.focus();
        return false;
    }
    if(document.ajout.bib_editeur.value == "")
    {
        alert("Veuillez saisir l'édition !")
        document.ajout.bib_editeur.focus();
        return false;
    }
}

//Check form fields are non blank on Midification doc page
function checkModifDoc()
{
    if(document.modifDoc.bib_titre.value == "")
    {
        alert("Veuillez saisir le titre !")
        document.modifDoc.bib_titre.focus();
        return false;
    }
    if(document.modifDoc.bib_auteur.value == "")
    {
        alert("Veuillez saisir le nom d'auteur !")
        document.modifDoc.bib_auteur.focus();
        return false;
    }
    if(document.modifDoc.bib_editeur.value == "")
    {
        alert("Veuillez saisir l'édition !")
        document.modifDoc.bib_editeur.focus();
        return false;
    }
}

//Check form fields are non blank on News (Add) page
function checkAddNews()
{
    if(document.form2.rev_titre.value == "")
    {
        alert("Veuillez saisir le titre !")
        document.form2.rev_titre.focus();
        return false;
    }
}


//Check form fields are non blank on Profil page
function checkProfil()
{
    if(document.form_profil.pro_nom.value == "")
    {
        alert("Veuillez saisir votre nom !")
        document.form_profil.pro_nom.focus();
        return false;
    }
    if(document.form_profil.pro_prenom.value == "")
    {
        alert("Veuillez saisir votre prénom !")
        document.form_profil.pro_prenom.focus();
        return false;
    }
    if(document.form_profil.pro_email_pro.value == "")
    {
        alert("Veuillez saisir votre adresse email !")
        document.form_profil.pro_email_pro.focus();
        return false;
    }
    if(!(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(document.form_profil.pro_email_pro.value)))
    {
      alert("Merci de saisir une adresse e-mail correcte !")
      document.form_profil.pro_email_pro.focus();
      return false;
    }
    return true;
}

///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
function check_email(e) {
ok = "/1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
for(i=0; i < e.length ;i++){ if(ok.indexOf(e.charAt(i))<0){ return (false); } } 
      re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;

      re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

      if (!e.match(re) && e.match(re_two)) { return (-1); } 
}

//////////////////////////////////////////
//--- verifie si le champs est vide
//////////////////////////////////////////
function check_vide(valeur)
{
	var test="KO";
	for (i=0; i<valeur.length;i++)
	{
		if (valeur.charAt(i)!=" ")
		{
			test="OK";
		}
	}
	return test;
}

/////////////////////////////////////////////////////////////////
//--- vérifie si le champs est une valeur numérique sans virgule
/////////////////////////////////////////////////////////////////
function check_numeric(valeur)
{
	var test="OK";
	if(isNaN(valeur) || (Math.round(valeur)!=valeur))
	{
		test="KO";
	}
	return test;
}
