function base_form_valider()
{
	// checks nom field - cannot be empty
	if (document.frm.nom1.value == "")
	{
		alert("Nom obligatoire, s’il vous plait.");
		document.frm.nom1.focus();
		return false;
	}//if

	// checks prenom field - cannot be empty
	if (document.frm.prenom1.value == "")
	{
		alert("Prénom obligatoire, s’il vous plait.");
		document.frm.prenom1.focus();
		return false;
	}//if
	
	// checks telephone field - cannot be empty and must has more than ten characters
	if (document.frm.telephone1.value == "")
	{
		alert("Téléphone obligatoire, s’il vous plait.");
		document.frm.telephone1.focus();
		return false;
	}//if

	// checks telephone field - must has more than ten characters
	if (document.frm.telephone1.value.length < 10)
	{
		alert("Tapez 10 chiffres dans le champ télephone.");
		document.frm.telephone1.focus();
		return false;
	}//if
	
	// checks marques field - at less one marque is selected
	if(document.frm.marque1.value == "" && document.frm.marque2.value == ""
	   && document.frm.marque3.value == "" && document.frm.marque4.value == ""
	   && document.frm.marque5.value == "")
	{
		alert("Marques présentées obligatoire, s’il vous plait.");
		document.frm.marque1.focus();
		return false;
	}//if

	// checks email address
	var a = document.frm.email1.value;
	testm = false;
	if(a != "")
	{
		for (var j=1 ; j<(a.length) ; j++)
		{
			if (a.charAt(j)=='@')
			{
				if (j<(a.length-4))
				{
					for (var k=j ; k<(a.length-2) ; k++)
					{
						if (a.charAt(k)=='.') testm = true;
					}
				}
			}
		}//for

		if (testm==false)
		{
			alert("Votre adresse e-mail est incorrecte, s’il vous plait.");
			document.frm.email1.focus();
			return false;
		}//if
	}//if
	
	// checks login field - cannot be empty
	if (document.frm.identifiant.value == "")
	{
		alert("Identifiant obligatoire, s’il vous plait.");
		document.frm.identifiant.focus();
		return false;
	}//if
	
	if (document.frm.identifiant.value.indexOf("'") >= 0 
		|| document.frm.identifiant.value.indexOf("{") >= 0 
		|| document.frm.identifiant.value.indexOf("}") >= 0)
	{
		alert("Identifiant obligatoire, s’il vous plait.");
		document.frm.identifiant.focus();
		return false;
	}//if
	
	return true;
}

/**
* @desc This function is to validate if the form is filled in when login
*/
function register_form_valider()
{
	var mark = true;
	
	if(!base_form_valider()) 
	{
		mark = false;
	}
	else if (document.frm.motdepasse.value == "") // checks mot de passe field - cannot be empty
	{
		alert("Mot de passe obligatoire, s’il vous plait.");
		document.frm.motdepasse.focus();
		mark = false;
	}
	else if (document.frm.conf_motdepasse.value == "") // checks confirmation mot de passe filed
	{
		alert("Confirmation du mot de passe obligatoire, s’il vous plait.");
		document.frm.conf_motdepasse.focus();
		mark = false;
	}
	else if (document.frm.motdepasse.value != document.frm.conf_motdepasse.value) // checks if confirmation passe is equal to passe
	{
		alert("Les deux mots de passe doivent être identiques.");
		document.frm.conf_motdepasse.focus();
		mark = false;
	}//if
	
    if(mark)
	{
		document.frm.hidden_flag.value = "submit";  // if form is filled correctly, then sets a flag
		document.frm.submit();                      // submit form
	}

	return mark;
}//register_form_valider()

function update_register_form_valider()
{
	var mark = true;
	
	if(!base_form_valider())
	{
		mark = false;
	}
	else if (document.frm.motdepasse.value != "" || document.frm.conf_motdepasse.value != "")
	{
		// checks if confirmation passe is equal to passe
		if (document.frm.motdepasse.value != document.frm.conf_motdepasse.value)
		{
			alert("Les deux mots de passe doivent être identiques.");
			document.frm.conf_motdepasse.focus();
			mark = false;
		}//if
	}//if
	
    if(mark)
	{
		document.frm.hidden_flag.value = "submit";  // if form is filled correctly, then sets a flag
		document.frm.submit();                      // submit form
	}

	return mark;
}//update_register_form_valider()

function is_number(a_string) 
{
	tc = a_string.charAt(0);
	if (tc == "0" || tc == "1" || tc == "2" || tc == "3" ||	tc == "4" || tc == "5" 
		|| tc == "6" || tc == "7" || tc == "8" || tc == "9") 
	{
		return true;
	} 
	else 
	{
		return false;
   	}
}

function register_form_valider_for_admin()
{
	var mark = true;
	
	if (document.frm.nom_concession.value == "") // checks mot de passe field - cannot be empty
	{
		alert("Nom Concession obligatoire, s’il vous plait.");
		document.frm.nom_concession.focus();
		mark = false;
	}
	else if (document.frm.nom_groupe.value == "") // checks mot de passe field - cannot be empty
	{
		alert("Nom groupe obligatoire, s’il vous plait.");
		document.frm.nom_groupe.focus();
		mark = false;
	}
	else if (document.frm.emplacement.value == "") // checks mot de passe field - cannot be empty
	{
		alert("Emplacement obligatoire, s’il vous plait.");
		document.frm.emplacement.focus();
		mark = false;
	}
	else if (isNaN(document.frm.commission_defaut.value))
	{
		alert("Commission par défaut CD is not a number.");
		document.frm.commission_defaut.focus();
		mark = false;
	}else if (document.frm.contact1_email.value != "")
	{
		// checks email address
		var a = document.frm.contact1_email.value;
		testm = false;
		if(a != "")
		{
			for (var j=1 ; j<(a.length) ; j++)
			{
				if (a.charAt(j)=='@')
				{
					if (j<(a.length-4))
					{
						for (var k=j ; k<(a.length-2) ; k++)
						{
							if (a.charAt(k)=='.') testm = true;
						}
					}
				}
			}//for

			if (testm==false)
			{
				alert("Votre adresse e-mail est incorrecte, s’il vous plait.");
				document.frm.contact1_email.focus();
				mark = false;
			}//if
		}//if
	}else if (document.frm.contact2_email.value != "")
	{
		// checks email address
		var a = document.frm.contact2_email.value;
		testm = false;
		if(a != "")
		{
			for (var j=1 ; j<(a.length) ; j++)
			{
				if (a.charAt(j)=='@')
				{
					if (j<(a.length-4))
					{
						for (var k=j ; k<(a.length-2) ; k++)
						{
							if (a.charAt(k)=='.') testm = true;
						}
					}
				}
			}//for

			if (testm==false)
			{
				alert("Votre adresse e-mail est incorrecte, s’il vous plait.");
				document.frm.contact2_email.focus();
				mark = false;
			}//if
		}//if
	}else if (document.frm.contact3_email.value != "")
	{
		// checks email address
		var a = document.frm.contact3_email.value;
		testm = false;
		if(a != "")
		{
			for (var j=1 ; j<(a.length) ; j++)
			{
				if (a.charAt(j)=='@')
				{
					if (j<(a.length-4))
					{
						for (var k=j ; k<(a.length-2) ; k++)
						{
							if (a.charAt(k)=='.') testm = true;
						}
					}
				}
			}//for

			if (testm==false)
			{
				alert("Votre adresse e-mail est incorrecte, s’il vous plait.");
				document.frm.contact3_email.focus();
				mark = false;
			}//if
		}//if
	}else if (document.frm.telephone_standard.value != "" && document.frm.telephone_standard.value.length < 10)
	{
		// checks telephone field - cannot be empty and must has more than ten characters
		alert("Téléphone est incorrecte, s’il vous plait.");
		document.frm.telephone_standard.focus();
		mark = false;
	}else if (document.frm.contact1_telephone.value != "" && document.frm.contact1_telephone.value.length < 10)
	{
		// checks telephone field - cannot be empty and must has more than ten characters
		alert("Téléphone est incorrecte, s’il vous plait.");
		document.frm.contact1_telephone.focus();
		mark = false;
	}else if (document.frm.contact2_telephone.value != "" && document.frm.contact2_telephone.value.length < 10)
	{
		// checks telephone field - cannot be empty and must has more than ten characters
		alert("Téléphone est incorrecte, s’il vous plait.");
		document.frm.contact2_telephone.focus();
		mark = false;
	}else if (document.frm.contact3_telephone.value != "" && document.frm.contact3_telephone.value.length < 10)
	{
		// checks telephone field - cannot be empty and must has more than ten characters
		alert("Téléphone est incorrecte.");
		document.frm.contact3_telephone.focus();
		mark = false;
	}//if
	
    if(mark)
	{
		document.frm.hidden_flag.value = "submit";  // if form is filled correctly, then sets a flag
		document.frm.submit();                      // submit form
	}

	return mark;

}//update_register_form_valider()
