function repondre(destinataire)
{
   //ouverture du popup emission:
   document.form_chat.action = 'ichat_compose.php?transfer_file=0';
   document.form_chat.destinataire.value = destinataire;
   var name = 'compose'+ destinataire;
   document.form_chat.target=name;
   popup = window.open('',name,'width=450,height=200 toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,left=1,top=450');
   popup.focus();
   document.form_chat.submit();
}
function open_popup_imail(from,nom_popup)
{
   document.form_annu.from.value = from;
   document.form_annu.target=nom_popup;
   popup = window.open('',nom_popup,'width=350,height=425,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,left='+5+',top=1');
   popup.focus();
   document.form_annu.submit();
   id_message = document.getElementById("message");
   id_message.innerHTML = ""; //suppression de l'invitation message
}
function openwin(url,name,w,h)
{
    //verifier si c'est ie
    var popup = window.open(url,name,"width="+w+",height="+h+",toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,left=500,top=0");
    popup.focus();
}

var isIE= navigator.appName == "Microsoft Internet Explorer"; /* IE */
var isNS= navigator.appName == "Netscape"; /* Netscape, Mozilla Firefox */

function redimIframe(obj){
var the_height = 0;
var the_width = 0;
var i = 0;

var isIE= navigator.appName == "Microsoft Internet Explorer"; /* IE */
var isNS= navigator.appName == "Netscape"; /* Netscape, Mozilla Firefox */

with(document.getElementById(obj.id)){
 if (isIE){
  the_height = contentWindow.document.body.scrollHeight;
  the_height = the_height;
  style.height = the_height;
  the_width = contentWindow.document.body.scrollWidth;
  if(the_width == 0)
  the_width = 1;
  style.width = the_width;
  scrolling="no";
 }
 else if (isNS){
  the_height = contentDocument.body.offsetHeight;
  the_height = the_height + 10;
  style.height = the_height;
  the_width = contentDocument.body.scrollWidth;
  if(the_width == 0)
  the_width = 1;
  style.width = the_width;
  scrolling= "no";
 }
 else {
  style.height= "100%";
  scrolling= "auto";
 }
}
}

var nouveau_mess = '<Img Src="images/top_03.gif" Width=106 Height=42 Alt="Vous avez un nouveau message" border="0" >';
var xhr = null;
var time;
var l = 0;

function getXhr()
{
     if(window.XMLHttpRequest) // Firefox et autres
        xhr = new XMLHttpRequest();
     else if(window.ActiveXObject){ // Internet Explorer
           try {
                      xhr = new ActiveXObject("Msxml2.XMLHTTP");
                  } catch (e) {
                      xhr = new ActiveXObject("Microsoft.XMLHTTP");
                  }
        }
        else { // XMLHttpRequest non support? par le navigateur 
           alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
           xhr = false; 
        } 
}
      
      // Node cleaner
      function go(c){
        if(!c.data.replace(/\s/g,''))
          c.parentNode.removeChild(c);
      }

      function clean(d){
        var bal=d.getElementsByTagName('*');

        for(i=0;i<bal.length;i++) {
          a=bal[i].previousSibling;
          if(a && a.nodeType==3)
            go(a);
          b=bal[i].nextSibling;
          if(b && b.nodeType==3)
            go(b);
        }
        return d;
      } 

      /**
      * M?thode qui sera appel?e sur le click du bouton
      */
      function gophp(){
        getXhr();
        // On d?fini ce qu'on va faire quand on aura la r?ponse
        xhr.onreadystatechange = function(){
          // On ne fait quelque chose que si on a tout re?u et que le serveur est ok
              if(xhr.readyState == 4)
              {
                if(xhr.status == 200)
                {
                  reponse = clean(xhr.responseXML.documentElement);
                  if(reponse)
                  {
                      //Nombre d'element
                      var taille = reponse.childNodes.length;
                      if(taille >=1)
                      {
                          if(l == 900)
                          {
                               l = 0;
                          }
                          for(var i=0;i<taille;i++)
                          {
                              element = reponse.childNodes[i];
                              if(element.getElementsByTagName("logout")[0].firstChild)
                              {
                                  logout = element.getElementsByTagName("logout")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("from")[0].firstChild)
                              {
                                 from = element.getElementsByTagName("from")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("popup")[0].firstChild)
                              {
                                 nom_popup = element.getElementsByTagName("popup")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("to")[0].firstChild)
                              {
                                 to = element.getElementsByTagName("to")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("type")[0].firstChild)
                              {
                                 type = element.getElementsByTagName("type")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("fichier")[0].firstChild)
                              {
                                 fichier = element.getElementsByTagName("fichier")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("date")[0].firstChild)
                              {
                                 date = element.getElementsByTagName("date")[0].firstChild.nodeValue;
                              }
                              if(element.getElementsByTagName("message")[0].firstChild)
                              {
                                 message = element.getElementsByTagName("message")[0].firstChild.nodeValue;
                              }
                              if(logout == '1')
                              {
                                     window.parent.location='main.php';
                              }
                              else
                              {
                                  document.form_annu.from.value = from;
                                  document.form_annu.target= nom_popup;
                                  popup = window.open('',nom_popup,'width=350,height=425,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,status=0,left='+l+',top=1');
                                  if(!popup)
                                  {
                                     //proposer lien hypertext dans la cas de blockage des popups
                                     id_message = parent.document.getElementById("message");
                                     html = id_message.innerHTML;
                                     id_message.innerHTML = html+'<br>'+'<a class="nav3" href="javascript:open_popup_imail(\'_web_\',\''+nom_popup+'\')">'+nouveau_mess+'</a>';
                                  }
                                  else
                                  {
                                      if(popup.document.body)
                                      {
                                          if(popup.document.body.innerHTML == "")
                                          {
                                             document.form_annu.submit();
                                             l=l+300; 
                                          }
                                          else
                                          {
                                              //on reload la frame qui contient les messages...
                                              frame = popup.document.getElementById('CONTENU');
                                              //=> modification de la frame par javascript :
                                              if(type == 'E')
                                              {
                                                  couleur = "#000000";
                                                  nom = to;
                                              }
                                              else
                                              {
                                                  couleur = "#FF0000";
                                                  nom = from;
                                              }
                                              nom = 'metaphone';
                                             if(fichier == 1)
                                             {
					     	 var reg=new RegExp("[_FILE_]+", "g");
						 var tableau=message.split(reg);
						 var file_name = tableau[1];
						 message = '<a href="javascript:download(\''+message+'\');">'+file_name+'</a>';
                                              }
                                              html = '<table width="100%"><tbody><tr><td valign="top" width="3%" nowrap="nowrap" >'+date+', '+nom+' &gt;</td><td valign="top" align="left"><font color="'+couleur+'">'+message+'</font></td></tr></tbody></table>';
                                              if(frame.contentDocument)
                                              {
                                                  //mozilla - firefox
                                                  html_doc = frame.contentDocument;
                                              }
                                              else if(frame.contentWindow)
                                              {
                                                  // For IE5.5 and IE6
                                                  html_doc = frame.contentWindow.document;
                                              }
                                              else if(frame.document)
                                              {
                                                  // For IE5
                                                  html_doc = frame.document;
                                              }
                                              else
                                              {
                                                  frame.src = frame.src;
                                                  html_doc = 0;
                                              }
                                              if(html_doc)
                                              {
                                                  ligne = html_doc.getElementById('ligne');
                                                  inner_html = ligne.innerHTML;
                                                  ligne.innerHTML = html+inner_html;
                                                  ligne.display = "block";
                                                  popup.document.getElementById('tape').innerHTML='<table width="100%"><tr><td><font color="#0000FF">Attente de r&eacute;ponse de votre correspondant M&eacute;taphone</font></td></tr></table>';
                                              }
                                          }
                                      }
                                      else
                                      {
                                          document.form_annu.submit();
                                          l=l+300;
                                          popup.focus();
                                      }
                                  }
                              }
                          }
                      }
                  }
                }
              }
       }
       xhr.open("GET","ajax_ichat.php",true);
       xhr.send(null);
       time = setTimeout('gophp()',3000);
}
function afficheMasque(idBloc)
{
  bloc = document.getElementById(idBloc);
  if( bloc.style.display != "block" )
  {
       bloc.style.display = "block";
  }
  else
  {
     bloc.style.display = "none";
  }
  JSFX_FloatTopDiv();
}
var num_presentation = 0;
function change_presentation()
{
	if(num_presentation == 3)
		num_presentation = 0;

	elt_presentation = document.getElementById("presentation");
	elt_presentation.innerHTML=contenu_presentation[num_presentation];
	num_presentation++;
	setTimeout("change_presentation()",5000);
}
