function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

MM_preloadImages('images/bouton_voirreponses_f2.gif','images/bouton_deplier_f2.gif','images/bouton_recherche_f2.gif','images/bouton_ecrire_f2.gif','images/classer_messages_desc_f2.gif','images/classer_messages_asc_f2.gif','images/classer_auteur_desc_f2.gif','images/classer_auteur_asc_f2.gif','images/classer_date_desc_f2.gif','images/classer_date_asc_f2.gif');



/*
validation rules
at least, but no more that one @
at least one dot after the @
no more than one consecutive dot
no illegal characters (whitespace,semicolon, less than,
greater than, apostrophe, exclaimation,m ampersand etc...) - please check.
*/

function checkEmail(email)
{
    // check that there is actually something there
    if (email == "")
    {
        return "";
    }

    // check for bad characters
    var bad_chars = " \/:,<'&";
    for (i = 0; i < bad_chars.length; i++)
    {
        if (email.indexOf(bad_chars.charAt(i)) != -1)
        {
            return "";
        }
    }

    // check that there is at least one '@' and that it's
    // not the first character of the email address
    var at_index = email.indexOf("@", 1);
    if (at_index == -1)
    {
        return "";
    }

    // now check that there are no more '@' characters after
    // the one we've found
    if (email.indexOf("@", at_index + 1) != -1)
    {
        return "";
    }

    // check that there is at least one '.' after the '@'
    var dot_index = email.indexOf(".", at_index + 1);
    if (dot_index == -1)
    {
        return "";
    }

    // now look for any consecutive '.' chars and replace
    // them with single ones... also replace '>' or ';'
    // with '.'
    // we'll do this all in one pass... makes the code
    // simpler even though it's unlikely that we'll end
    // up with consecutive ';' or '>' characters

    if ((email.indexOf("..", at_index + 1) != -1) ||
        (email.indexOf(";", at_index + 1) != -1) ||
        (email.indexOf(">", at_index + 1) != -1))
    {
        var replace_chars = ".;>";
        var new_email = email.substring(0, at_index + 1);
        for (i = at_index + 1; i < email.length; i++)
        {
            if (replace_chars.indexOf(email.charAt(i)) != -1)
            {
                new_email += ".";
                while ((replace_chars.indexOf(email.charAt(i + 1)) != -1) &&
                       (i < email.length))
                {
                    i++;
                }
            }
            else
            {
                new_email += email.charAt(i);
            }
        }
        email = new_email;
    }

    // now check that there is something before the dot which 
    // follows the '@' and at least 2 characters following the
    // last dot
    // first find the index of the first dot again, since it 
    // might have changed in the removal of duplicate dots, etc
    dot_index = email.indexOf(".", at_index + 1);
    if (dot_index == at_index + 1)
    {
        return "";
    }
    dot_index = email.lastIndexOf(".");
    if (dot_index > email.length - 3)
    {
        return "";
    }

    return email;
}
