// JavaScript Document
// JavaScript Document
function IsEmailValid(checkThisEmail)
{
    var myEMailIsValid = true;
    var myAtSymbolAt = checkThisEmail.indexOf("@");
    var myLastDotAt = checkThisEmail.lastIndexOf(".");
    var mySpaceAt = checkThisEmail.indexOf(" ");
    var myLength = checkThisEmail.length;
    
    
    // at least one @ must be present and not before position 2
    // @yellow.com : NOT valid
    // x@yellow.com : VALID
    
    if (myAtSymbolAt < 1 )
	{myEMailIsValid = false}
    
    
    // at least one . (dot) afer the @ is required
    // x@yellow : NOT valid
    // x.y@yellow : NOT valid
    // x@yellow.org : VALID
    
    if (myLastDotAt < myAtSymbolAt)
	{myEMailIsValid = false}
    
    // at least two characters [com, uk, fr, ...] must occur after the last . (dot)
    // x.y@yellow. : NOT valid
    // x.y@yellow.a : NOT valid
    // x.y@yellow.ca : VALID
    
    if (myLength - myLastDotAt <= 2)
	{myEMailIsValid = false}
    
    
    // no empty space " " is permitted (one may trim the email)
    // x.y@yell ow.com : NOT valid
    
    if (mySpaceAt != -1)
	{myEMailIsValid = false}
    
    
    if (myEMailIsValid == false)
	{
	    var msg = "Votre email "+checkThisEmail+" n'est pas valide !"; 
	    alert(msg);
	}
    return myEMailIsValid;
}

function IsTitleValid(t)
{
    len = t.length;
    if (len >= 4) return true;
    var msg = "Le titre est trop court"; 
    alert(msg);
    return false;
}
function IsDescValid(t)
{
    len = t.length;
    if (len >= 5) return true;
    var msg = "Le message est trop court..."; 
    alert(msg);
    return false;
}
function IsNomValid(t)
{
    len = t.length;
    if (len >= 5) return true;
    var msg = "Le nom est trop court..."; 
    alert(msg);
    return false;
}

function efface_msg(name)
{
	document.forms[name].msg.value = '';
	return true;
}
function envoie_msg(name)
{
	var ok = false;
	
	// verif de l email
    ok = IsEmailValid(document.forms[name].email.value);
    if (ok == false) return(1);
	// verif du nom
    ok = IsNomValid(document.forms[name].nom.value);
	if (ok == false) return(2);
	// verif du titre
    ok = IsTitleValid(document.forms[name].sujet.value);
    if (ok == false) return(3); 
    // verif de la description
    ok = IsDescValid(document.forms[name].msg.value);
    if (ok == false) return(4);
  
	document.forms[name].submit();
	return 0;
}