
      window.onload=show_menu;
      var target = '';
      function show_menu(id) {
      var d = document.getElementById(id);
      	for (var i = 1; i<=6; i++) {
      		if (document.getElementById('menu'+i)) {document.getElementById('menu'+i).style.display='none';}
      	}
      if (d) {d.style.display='block';}
      }
      function get_content (dest,content,param)
      {
        if (content == 'portal_security.log_out')
        {
          logout();
        }
        else
        {
          if(window.XMLHttpRequest) { // FIREFOX
            xhr_object = new XMLHttpRequest();
          } else if(window.ActiveXObject) { // IE
              xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
          } else
              return(false) ;
          xhr_object.onreadystatechange = fetch;
          xhr_object.open("POST", content, true);
          xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
          xhr_object.setRequestHeader('Cache-Control', 'no-cache');
          xhr_object.send(param);
          target=document.getElementById(dest);
        }
      }
      function fetch() {
        if(xhr_object.readyState == 4)
        {
          var rt = xhr_object.responseText;
          target.innerHTML=rt;
          //target.innerHTML='';
          //inside = document.createElement('div');
          //inside.innerHTML = rt;
          //target.appendChild(inside);
        }
        else return(false);
      }
      function connect() {
        var login = document.getElementById('login').value;
        var pass = document.getElementById('pass').value;
        if(window.XMLHttpRequest) { // FIREFOX
          xhr_object = new XMLHttpRequest();
        } else if(window.ActiveXObject) { // IE
            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        } else
            return(false) ;
        xhr_object.open("POST", 'portal_security.connection', false);
        xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xhr_object.send('p_login='+login+'&p_pass='+pass);
        if(xhr_object.readyState == 4 && xhr_object.responseText=='')
        {
          get_content('PortletContainer','portal_display.portlet','p_light=0');
        }
        else
        {
          document.getElementById('ContentDiv').innerHTML=xhr_object.responseText;
        }
        //get_content('ContentDiv','portal_security.connection','p_login='+login+'&p_pass='+pass);
      }
      function logout() {
        if(window.XMLHttpRequest) { // FIREFOX
          xhr_object = new XMLHttpRequest();
        } else if(window.ActiveXObject) { // IE
            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        } else
            return(false) ;
        xhr_object.open("POST", 'portal_security.log_out', false);
        xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
        xhr_object.send(null);
        get_content('PortletContainer','portal_display.portlet','p_light=0');
      }
      //Affichage du tooltip des factures
      //on désactive la mise en cache parce qu'on utilise le tooltip dans plusieurs proc donc il faut rafraichir a chaque fois
      var tooltipContentTab = new Array();
      var tooltipDiv = false;
      var CurrentPage;
      var is_msie = (navigator.userAgent.indexOf('MSIE')>=0)?true:false;
      function tooltipContent(id,html) {
        this.id = id;
        this.html=html;
      }
      function pushContent(id,html)
      {
        tooltipContentTab[tooltipContentTab.length]=new tooltipContent(id,html);
      }
      function getContent (id,action) {
        if(window.XMLHttpRequest) { // FIREFOX
          xhr_object = new XMLHttpRequest();
        } else if(window.ActiveXObject) { // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        } else
          return(false) ;
        var dest = '/lure/'+action;
        xhr_object.open("POST", dest, false);
        xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr_object.send('p_id_invoice='+id);
        if(xhr_object.readyState == 4)
          return xhr_object.responseText;
      }
      function showTooltip(e,id,action) {
       if(!tooltipDiv)
       {
         tooltipDiv=document.createElement('div');
         tooltipDiv.id='tooltip';
         document.body.appendChild(tooltipDiv);
         if(is_msie)
         {
           iframe = document.createElement('iframe');
  	 	 		 iframe.frameborder='5';
  	 			 iframe.style.backgroundColor='#FFFFFF';
  				 iframe.src = '#';
  				 iframe.style.zIndex = 100;
  				 iframe.style.position = 'absolute';
  				 document.body.appendChild(iframe);
         }
       }
       if (CurrentPage != action)
       {
         tooltipContentTab = new Array();
         CurrentPage=action;
       }
       tooltipDiv.style.display='block';
       tooltipDiv.innerHTML=id;
		   if(is_msie) iframe.style.display='block';
       tooltipDiv.style.left= (is_msie) ? e.clientX+document.documentElement.scrollLeft+'px' : e.pageX+'px';
       tooltipDiv.style.top= (is_msie) ? e.clientY+document.documentElement.scrollTop+'px' : e.pageY+'px';
       for (var i=0;i<tooltipContentTab.length;i++)
       {
         if(tooltipContentTab[i].id == id)
           tooltipDiv.innerHTML=tooltipContentTab[i].html;
       }
       if(!isNaN(tooltipDiv.innerHTML))
       {
         var content = getContent(id,action);
         tooltipDiv.innerHTML=content;
         pushContent(id,content);
       }
       if(is_msie)
       {
         iframe.style.left= e.clientX+document.documentElement.scrollLeft+'px';
         iframe.style.top= e.clientY+document.documentElement.scrollTop+'px';
         iframe.style.width= tooltipDiv.clientWidth+'px';
         iframe.style.height= tooltipDiv.clientHeight+'px';
       }

      }

      function hideTooltip() {
       tooltipDiv.style.display='none';
		   if(is_msie) iframe.style.display='none';
       tooltipDiv.innerHTML=' ';
      }

      function check_pass() {
        var old=document.getElementById('old').value;
        if(window.XMLHttpRequest) { // FIREFOX
          xhr_object = new XMLHttpRequest();
        } else if(window.ActiveXObject) { // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        } else
          return(false) ;
        var dest = '/lure/portal.verify_pass';
        xhr_object.open("POST", dest, false);
        xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr_object.send('p_pass='+old);
        if(xhr_object.readyState == 4)
          if (xhr_object.responseText==0)
            alert('Le mot de passe actuel spécifié ne correspond pas.');
          else
          {
            var new1= document.getElementById('new1').value;
            var new2=document.getElementById('new2').value;
            if (new1=='' || new2=='')
              alert('Le nouveau mot de passe ne doit pas être vide.');
            else if (new1!=new2)
              alert('Le nouveau mot de passe et sa confirmation ne sont pas identique');
            else
              get_content('ContentDiv','portal.change_pass','p_old='+old+'&p_new='+new1);
          }
      }
      function get_pass_form () {
        var text = document.getElementById('textpass');
        text.innerHTML='Nouveau mot de passe pointage (4 caractères numériques)';
        input = document.createElement('input');
        input.setAttribute('class','frminput');
        input.setAttribute('className','frminput');
        input.setAttribute('id','pass');
        input.setAttribute('size','5');
        input.setAttribute('maxlength','4');
        document.getElementById('inputpass').appendChild(input);
        button = document.createElement('input');
        button.setAttribute('type','button');
        button.setAttribute('class','frminput');
        button.setAttribute('className','frminput');
        button.setAttribute('value','Valider');
        button.onclick= function () { change_child_pass(); }
        document.getElementById('gopass').appendChild(button);
      }
      function change_child_pass () {
        var pass = document.getElementById('pass').value;
        var child = document.getElementById('child').value;
        if (isNaN(pass))
          alert('Le mot de passe ne doit être composé que de chiffres');
        else if (pass=='')
          alert('Le mot de passe ne doit pas être vide');
        else if (pass.length!=4)
          alert('Le mot de passe doit être composé de quatre chiffres');
        else
        {
          if(window.XMLHttpRequest) { // FIREFOX
            xhr_object = new XMLHttpRequest();
          } else if(window.ActiveXObject) { // IE
            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
          } else
            return(false) ;
          var dest = '/lure/portal.change_child_pass';
          xhr_object.open("POST", dest, false);
          xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          xhr_object.send('p_pass='+pass+'&p_child='+child);
          if(xhr_object.responseText!=1)
            alert('Erreur !! Le mot de passe n\'a pas été modifié.');
          document.getElementById('textpass').innerHTML='<a href="javascript:get_pass_form();">Changer le mot de passe pointage</a>';
          document.getElementById('inputpass').innerHTML='&nbsp;';
          document.getElementById('gopass').innerHTML='&nbsp;';
        }
      }
      function update_mail (id,text) {
        var mail = document.getElementById(id).value;
        if (text.length!=mail.length)
          text = text.substr(0,text.length-1);
        regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
        if (!regexp.test(mail) && mail!=text)
          alert('Veuillez vérifier l\'adresse email.');
        else
          update_field(id,text,'update_mail');
      }
      function update_phone (id,text) {
        var phone = document.getElementById(id).value;
        phone = phone.replace(/[^\d]/g,'');
        document.getElementById(id).value=phone;
        if (isNaN(phone))
          alert('Veuillez vérifier le numéro de téléphone');
        else
          update_field(id,text,'update_phone');
      }
      function build_update (id,func) {
        var cell = document.getElementById(id);
        var text = cell.firstChild.nodeValue;
        if (text.charCodeAt(text.length-1)==160)
          text=text.substr(0,text.length-1);
        input = document.createElement('input');
        input.setAttribute('class','frminput');
        input.setAttribute('className','frminput');
        input.setAttribute('id','input'+id);
        input.setAttribute('value',text);
        button = document.createElement('input');
        button.setAttribute('type','button');
        button.setAttribute('class','frminput');
        button.setAttribute('className','frminput');
        button.setAttribute('value','Ok');
        button.onclick= function () { eval(func+'(\'input\'+id,text)') };
        cell.innerHTML='';
        cell.appendChild(input);
        cell.appendChild(button);
      }
      function update_field (id,old,func) {
        var val = document.getElementById(id).value;
        if (old.length!=val.length)
          old = old.substr(0,old.length-1);
        if (val==old)
        {
          cell = document.getElementById(id.substr(5));
          cell.innerHTML=old+'&nbsp;';
          link = document.createElement('a');
          link.setAttribute('href','javascript:build_update(\''+id.substr(5)+'\',\''+func+'\')');
          img = document.createElement('img');
          img.setAttribute('src','/images/edit.png');
          img.setAttribute('class','smallImg');
          img.setAttribute('className','smallImg');
          link.appendChild(img);
          cell.appendChild(link);
        }
        else
        {
          var val = document.getElementById(id).value;
          var parent = document.getElementById('parent'+id.replace(/[^\d]/g,'')).value;
          var field = id.substr(5,id.length-6);
          if(window.XMLHttpRequest) { // FIREFOX
            xhr_object = new XMLHttpRequest();
          } else if(window.ActiveXObject) { // IE
            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
          } else
            return(false) ;
          var dest = '/lure/portal.update_field';
          xhr_object.open("POST", dest, false);
          xhr_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          xhr_object.send('p_id='+parent+'&p_field='+field+'&p_value='+val);
          if (xhr_object.responseText!='1')
            alert('Erreur lors de la mise à jour. Veuillez contacter un administrateur.');
          else
          {
            cell = document.getElementById(id.substr(5));
            if (!isNaN(val))
            {
              val = break_phone(val);
            }
            cell.innerHTML=val+'&nbsp;';
            link = document.createElement('a');
            link.setAttribute('href','javascript:build_update(\''+id.substr(5)+'\',\''+func+'\')');
            img = document.createElement('img');
            img.setAttribute('src','/images/edit.png');
            img.setAttribute('class','smallImg');
            img.setAttribute('className','smallImg');
            link.appendChild(img);
            cell.appendChild(link);
          }
        }
      }
      function break_phone (phone) {
        var new_phone = '';
        for (i=0;i<phone.length;i++)
          if ((i+1)%2==0)
            new_phone = new_phone+phone.substr(i-1,2)+' ';
        return new_phone.substr(0,new_phone.length-1);
      }
      function paiement(url)
      {
        window.name="AgoraPortal";
        var button = document.getElementById('valid');
        button.onclick= function () { };
        button.style.cursor='default';
        if (navigator.appName=='Microsoft Internet Explorer')
          button.style.filter='alpha(opacity=50)';
        else
          button.style.opacity=.5;
        var win;
      	win=window.open(url,'SPPLUS','width=780,height=560,status=1');
      	win.focus();
      }
      var askEmailDiv=false;
      function ask_email (e,emission)
      {
        if (!askEmailDiv)
        {
          askEmailDiv=document.createElement('div');
          askEmailDiv.id='selectMail';
          askEmailDiv.setAttribute('class','selectMail');
          askEmailDiv.setAttribute('className','selectMail');
          askEmailDiv.style.width = '350px';
          askEmailDiv.style.height = '75px';
          document.body.appendChild(askEmailDiv);
          if(is_msie)
          {
            iframe = document.createElement('iframe');
            iframe.frameborder='5';
            iframe.style.backgroundColor='#FFFFFF';
            iframe.src = '#';
            iframe.style.zIndex = 100;
            iframe.style.position = 'absolute';
            document.body.appendChild(iframe);
          }
        }
        askEmailDiv.style.display='block';
        if(is_msie) iframe.style.display='block';
        askEmailDiv.style.left= (is_msie) ? e.clientX-350+document.documentElement.scrollLeft+'px' : e.pageX-350+'px';
        askEmailDiv.style.top= (is_msie) ? e.clientY+document.documentElement.scrollTop+'px' : e.pageY+'px';
        //askEmailDiv.style.left= e.clientX-350+'px';
        //askEmailDiv.style.top= e.clientY+'px';
        var content = get_content('selectMail','portal.get_mail_list','p_emission='+emission);
        askEmailDiv.innerHTML=content;
        if(is_msie)
        {
          iframe.style.left= e.clientX-350+document.documentElement.scrollLeft+'px';
          iframe.style.top= e.clientY+document.documentElement.scrollTop+'px';
          iframe.style.width= askEmailDiv.clientWidth+'px';
          iframe.style.height= askEmailDiv.clientHeight+'px';
        }
      }
      function closeSelectMail ()
      {
        document.getElementById('selectMail').style.display='none';
        if(is_msie) iframe.style.display='none';
        askEmailDiv.innerHTML=' ';
      }
      function chkSelectMail (emission)
      {
        var mail = document.getElementById('inpmail').value;
        var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
        if (!regexp.test(mail))
          alert('L\'adresse email n\'est pas valide.');
        else
        {
          get_content('ContentDiv','portal.confirm_payment','p_invoice='+emission+'&p_pbx_porteur='+mail);
          closeSelectMail();
        }
      }
      

