function y2k(date)
  {
  return (date < 1000) ? date + 1900 : date;
  }

function leTemps()
  {
  var d = new Date();
  return Date.UTC(
    y2k(d.getYear()),
    d.getMonth(),
    d.getDate(),
    d.getHours(),
    d.getMinutes(),
    d.getSeconds(),
    d.getMilliseconds()
    )
  }


//***** Variables *****

var xhr = null ;
var annuaire_str = '<p> Dans cette partie, vous pouvez consulter les informations relatives aux différents membres du Club de l\'Etang-Salé.</p>';
annuaire_str += '<p> Pour avoir plus de détails, cliquez sur <img src="images/b.gif" />. </p>' ;
annuaire_str += '<p> N\'oubliez pas de vous identifier pour avoir accès à ces informations complémentaires. </p>';
var formation_str = '<p> Dans cette partie, vous pouvez vous imprégner de la philosophie Rotary, découvrir ou redécouvrir ce qui a fait du Rotary ce qu\'il est aujourd\'hui.</p>';
formation_str += '<p> Pour avoir plus de détails sur chaque catégorie, cliquez sur <img src="images/b.gif" />. </p>' ;
var liens_str = '<p> Dans cette partie, vous pouvez découvrir les autres sites relatifs au Rotary.</p>';
liens_str += '<p> Pour cela, il vous suffit de cliquer sur le titre du site auquel vous voulez accéder. </p>' ;
var photos_str = '<p> Dans cette partie, le Rotary est en couleurs. Vous pouvez accéder aux galeries d\'images des différents événements qui ont marqué la vie du Club.</p>';
photos_str += '<p> Pour voir les photos de chaque événement, cliquez sur <img src="images/b.gif" />. </p>' ;
var newsletter_str = '<p> Pour accéder aux bulletins hebdomadaires, veuillez cliquer sur la date correspondante du calendrier. </p>' ;
newsletter_str += '<p> Vous devez vous identifier pour pouvoir visualiser les bulletins. </p>' ;
var accueil_str = '<p><b>Chers Ami(e)s Rotarien(ne)s,</b></p><p>En mon nom et au nom de tout le comité 2006/2007 je vous souhaite une excellente année rotarienne !</p><p> "Ouvrir la Voie" est le thème de notre Président du RI, William Boyd, et';
accueil_str += ' je m’engage à faire mon possible, avec votre soutien, pour que notre club vive des moments riches en camaraderie mais aussi en actions. Car c’est en définitive autour de l’action rotarienne qu’un club se développe,';
accueil_str += ' s’épanouit, s’enrichit tout en solidifiant les liens d’amitié qui unissent ses membres. La participation de tous, tout autant que l’assiduité est le ciment du club.</p><p> Les priorités fixées pour cette année sont dans la';
accueil_str += ' continuité de l’action du RI : la gestion des ressources en eau, l’alphabétisation, la santé et la faim ainsi que la famille du Rotary. Notre club peut être fier des actions qu’il a déjà menées dans tous ces domaines,';
accueil_str += ' et je compte sur les idées et l’engagement de chacun pour en faire aboutir de nouvelles.</p><p> Que tout membre de notre club puisse en juillet 2007 se retourner, être satisfait et fier de sa participation, fier de son club';
accueil_str += ' et fier d’être rotarien, avec en prime une envie d’action décuplée pour l’année à venir: tel est mon objectif !</p><div id="sign"><p><br/>Catherine Gouyet <br />Présidente du RC Etang-Salé 2006/2007</p><img src="images/signature.jpg" /></div> ';
var commission_str = '<p>Veuillez choisir la commission concernée dans le menu de gauche pour obtenir plus de détails sur sa composition et ses actions.</p>';
//***** XMLHttpRequest relative functions *****

//1)login

function login(){
  new Ajax.Request('Controllers/Controller_Login.php',{
    postBody : $H({'login_username':$F('login_username_field'),'login_username_type':'string','login_password':$F('login_password_field'),'login_password_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var errors_list = docXML.getElementsByTagName('erreur');
      var errors = $A(errors_list) ;     
      errors.each(function(error) {
       $('login_error').innerHTML = error.getElementsByTagName('err_description').item(0).firstChild.data ;     
      });  
      if (errors.length == 0){
        $('login').innerHTML = '<div id="login_title"></div><a href="#" id="logout_button" onClick="logout()"></a>' ;
        menu(docXML.getElementsByTagName('page').item(0).firstChild.data) ;
      }
      toggleIndicator();
    }
  });
}

//****************************************************************************

//2)menu

function menu(name){
  switch(name){
    case 'element1':checking();break;
    case 'element2':commissions();break;
    case 'element3':educations();break;
    case 'element4':date=new Date();calendar((date.getMonth()+1),date.getFullYear());$('e').innerHTML = '<div class="header"><ul><li class="current"><a href="#">Bulletins Hebdomadaires</a></li><li ><a href="#" onClick="occasional()">Bulletins Occasionnels</a></li></ul></div><div class="blank">blank</div><div id="newsletter_content">'+newsletter_str+'</div>';break;
    case 'element5':photos();break;
    case 'element6':links();break;
    case 'element7':members();break;
    case 'element8':window.location = "http://www.rotary-reunion.com/forum" ;break;
    default : checking() ;
  }
}

//****************************************************************************

//3)members

function members(){
  new Ajax.Request('Controllers/Controller_Members.php',{
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var members_list = docXML.getElementsByTagName('member');
      var members = $A(members_list) ;
      $('e').innerHTML = "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"; 
      var j = 0;
      var session = docXML.getElementsByTagName('session').item(0).firstChild.data ;
      members.each(function(member) {
        var str = '<div class="content_part" id="content_part'+j+'">';
        str += '<div class="trombi" id="trombi'+j+'"><div class="trombi_photo"><div class="trombi_photo_left" id="trombi_photo_left'+j+'"></div><div class="trombi_photo_center"><div class="trombi_photo_top"></div>';
        str += '<div class="trombi_photo_content"><img src="'+member.getElementsByTagName('photo').item(0).firstChild.data+'" /></div><div class="trombi_photo_bottom" id="trombi_photo_bottom'+j+'"></div></div><div class="trombi_photo_right" id="trombi_photo_right'+j+'"></div></div>';
        str += '<div class="trombi_right"><div class="trombi_title">'+member.getElementsByTagName('role').item(0).firstChild.data+'</div><div class="trombi_content_zone"><div class="trombi_content" id="trombi_content'+j+'"><div class="con">'+member.getElementsByTagName('fullname').item(0).firstChild.data+' '+member.getElementsByTagName('surname').item(0).firstChild.data+'<br />'+member.getElementsByTagName('profession').item(0).firstChild.data+'</div></div>';
        str += '<div class="trombi_content_right"><div class="trombi_button_top"></div><a href="#" class="trombi_button" id="trombi_button'+j+'" onClick="showMore('+j+','+session+');return(false);" ></a><div class="trombi_button_bottom" id="trombi_button_bottom'+j+'"></div></div></div></div></div>' ;
        str += '</div><div class="more_member invisible" id="more_member-'+j+'"><div class="trombi_more" id="trombi_more'+j+'"><div class="trombi_more_content"><div class="trombi_more_content_left">numéro RI :<br />E-mail :<br />Tél. fixe :<br />Tél. portable :</div><div class="trombi_more_content_right">'+member.getElementsByTagName('numri').item(0).firstChild.data+'<br />'+member.getElementsByTagName('email').item(0).firstChild.data+'<br /> '+member.getElementsByTagName('telephone').item(0).firstChild.data+'<br />'+member.getElementsByTagName('mobile').item(0).firstChild.data+'</div></div></div></div>';
        str += '<div class="more_member2 invisible" id="more_member2-'+j+'"><div class="trombi_more2" id="trombi_more2'+j+'"><div class="trombi_more_content2">Vous devez vous identifier pour accéder à ces informations </div></div></div>';   
        new Insertion.Bottom('e',str);
        j++;      
      });    
      $('left_content').innerHTML = annuaire_str;
      toggleIndicator();
    }
  });
}

//****************************************************************************

//4)showMore  

function showMore(id,session){
  if (session == 0) {
    if (Element.hasClassName('more_member2-'+id,'invisible')){   
      Element.removeClassName('more_member2-'+id,'invisible') ; 
      Element.setStyle('trombi_photo_left'+id,{background : 'url(images/t3h.gif)'});
      Element.setStyle('trombi_photo_right'+id,{background : 'url(images/t8h.gif)'});
      Element.setStyle('trombi_content'+id,{background : 'url(images/t9h.gif)'}); 
      Element.setStyle('trombi_photo_bottom'+id,{background : 'url(images/t12h.gif)'});
      Element.setStyle('trombi_button_bottom'+id,{background : 'url(images/t13h.gif)'});
      Element.setStyle('trombi_button'+id,{background : 'url(images/t11h.gif)'});
    }
    else {  
      Element.addClassName('more_member2-'+id,'invisible') ; 
      Element.setStyle('trombi_photo_left'+id,{background : 'url(images/t3.gif)'});
      Element.setStyle('trombi_photo_right'+id,{background : 'url(images/t8.gif)'});
      Element.setStyle('trombi_content'+id,{background : 'url(images/t9.gif)'}); 
      Element.setStyle('trombi_photo_bottom'+id,{background : 'url(images/t12.gif)'});
      Element.setStyle('trombi_button_bottom'+id,{background : 'url(images/t13.gif)'});
      Element.setStyle('trombi_button'+id,{background : 'url(images/t11.gif)'});
    }
  }
  else {
    if (Element.hasClassName('more_member-'+id,'invisible')){ 
      Element.removeClassName('more_member-'+id,'invisible') ; 
      Element.setStyle('trombi_photo_left'+id,{background : 'url(images/t3h.gif)'});
      Element.setStyle('trombi_photo_right'+id,{background : 'url(images/t8h.gif)'});
      Element.setStyle('trombi_content'+id,{background : 'url(images/t9h.gif)'}); 
      Element.setStyle('trombi_photo_bottom'+id,{background : 'url(images/t12h.gif)'});
      Element.setStyle('trombi_button_bottom'+id,{background : 'url(images/t13h.gif)'});
      Element.setStyle('trombi_button'+id,{background : 'url(images/t11h.gif)'});
    }
    else {
      Element.addClassName('more_member-'+id,'invisible') ; 
      Element.setStyle('trombi_photo_left'+id,{background : 'url(images/t3.gif)'});
      Element.setStyle('trombi_photo_right'+id,{background : 'url(images/t8.gif)'});
      Element.setStyle('trombi_content'+id,{background : 'url(images/t9.gif)'}); 
      Element.setStyle('trombi_photo_bottom'+id,{background : 'url(images/t12.gif)'});
      Element.setStyle('trombi_button_bottom'+id,{background : 'url(images/t13.gif)'});
      Element.setStyle('trombi_button'+id,{background : 'url(images/t11.gif)'});
    }
  }
}

//****************************************************************************

//5)calendar

function calendar(month,year){
  new Ajax.Request('Controllers/Controller_Calendar.php',{
    postBody : $H({'calendar_month': month,'calendar_month_type':'string','calendar_year':year,'calendar_year_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      $('left_content').innerHTML ="";
      var docXML = xhr.responseXML ;
      var items = docXML.getElementsByTagName('week');
      var number = items.length ;
      var current_day = docXML.getElementsByTagName('currentday')[0].firstChild.data ; 
      var current_month = docXML.getElementsByTagName('currentmonth')[0].firstChild.data ; 
      var current_year = docXML.getElementsByTagName('currentyear')[0].firstChild.data ; 
      var string_table ='<div id="calendar_title"><a href="#" id="calendar_title_left" onClick="previous_calendar('+month+','+year+')"></a><div id="calendar_title_center">'+docXML.getElementsByTagName('title')[0].firstChild.data+'</div><a href="#" id="calendar_title_right" onClick="next_calendar('+month+','+year+')"></a></div>';
      string_table +='<div id="calendar_days"><div class="day_value">Lun</div><div class="day_value">Mar</div><div class="day_value">Mer</div><div class="day_value">Jeu</div><div class="day_value">Ven</div><div class="day_value">Sam</div><div class="day_value">Dim</div></div>';
      for ( var i = 0 ; i < number ; i++) {
         string_table += '<div class="calendar_week" id="calendar_week'+i+'">';
         for ( var j = 0 ; j < 7 ; j++) {
           if (docXML.getElementsByTagName('day')[i*7+j].firstChild) {
             if (j == 2) {
               if ((docXML.getElementsByTagName('day')[i*7+j].firstChild.data == current_day) && (month == current_month) && (year == current_year))
                 string_table += '<a href="#" id="current_day_wednesday" onClick="showNewsletter('+current_day+','+current_month+','+current_year+')">'+ docXML.getElementsByTagName('day')[i*7+j].firstChild.data+'</a>';
               else
                 string_table += '<a href="#" class="day_wednesday" onClick="showNewsletter('+docXML.getElementsByTagName('day')[i*7+j].firstChild.data+','+month+','+year+')">'+ docXML.getElementsByTagName('day')[i*7+j].firstChild.data+'</a>';
             }
             else {
               if ((docXML.getElementsByTagName('day')[i*7+j].firstChild.data == current_day) && (month == current_month) && (year == current_year))
                 string_table += '<div id="current_day">'+ docXML.getElementsByTagName('day')[i*7+j].firstChild.data+'</div>';
               else
                 string_table += '<div class="day">'+ docXML.getElementsByTagName('day')[i*7+j].firstChild.data+'</div>';
             }
           }
           else
             string_table += '<div class="day">'+' '+'</div>';
         }
         string_table += '</div>';
      }
      string_table += '<div id="calendar_bottom"></div><div id="calendar_field_left"><select id="month" onChange="calendar(document.getElementById(\'month\').value,document.getElementById(\'year\').value)">';
      var array = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
      for (var i = 1 ; i <13 ; i++ ) 
        (month == i) ? string_table += '<option value="'+i+'" selected="selected">'+array[i-1]+'</option>': string_table+='<option value="'+i+'">'+array[i-1]+'</option>';
      string_table += '</select></div>';
      string_table += '<div id="calendar_field_center"><select id="year" onChange="calendar(document.getElementById(\'month\').value,document.getElementById(\'year\').value)">';
      for (var i = 2006 ; i <2011 ; i++ ) 
        (year == i) ? string_table += '<option value="'+i+'" selected="selected">'+i+'</option>':string_table += '<option value="'+i+'">'+i+'</option>';
      string_table += '</select></div>';
      document.getElementById('left_content').innerHTML = string_table;  
      toggleIndicator();
    }
  });
}

//****************************************************************************

//6)previous_calendar

function previous_calendar(month,year){
  if (month == 1)
    calendar(12,year-1);
  else
    calendar(month-1,year);
}

//****************************************************************************

//7)next_calendar

function next_calendar(month,year){
  if (month == 12)
    calendar(1,year+1);
  else
    calendar(month+1,year);
}

//****************************************************************************

//8)showNewsletter

function showNewsletter(day,month,year){
  new Ajax.Request('Controllers/Controller_Newsletters.php',{
    postBody : $H({'day':day,'day_type':'string','month':month,'month_type':'string','year':year,'year_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
    var array = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
    var docXML = xhr.responseXML ; 
    var items = docXML.getElementsByTagName('erreur');
    var str='';   
    if (items.length != 0)
      str += docXML.getElementsByTagName('err_description').item(0).firstChild.data ;
    else {
      var content = docXML.getElementsByTagName('content').item(0).firstChild.data ;
      str += '<div id="newsletter_box"><p id="newsletter_title">Bulletin no'+docXML.getElementsByTagName('number').item(0).firstChild.data+'</p>';
      str += '<p> Réunion statutaire du mercredi '+day+' '+array[month-1]+' '+year+'<br />Présence : '+docXML.getElementsByTagName('presence').item(0).firstChild.data+'</p></div>';
      str += '<div id ="next">'+content+'</div><br />' ;
    }
    if (docXML.getElementsByTagName('user').item(0).firstChild.data != '0')
      $('newsletter_content').innerHTML = str ;
    else
      $('newsletter_content').innerHTML = '<p>Vous devez être identifié pour pouvoir visualiser ce bulletin</p>' ;   
      toggleIndicator();
    }
  });
}

//****************************************************************************

//9)educations

function educations(){
  new Ajax.Request('Controllers/Controller_Educations.php',{
    onLoading : toggleIndicator,  
    onComplete : function(xhr) {
    var docXML = xhr.responseXML ; 
    var educations_list = docXML.getElementsByTagName('education');
    var educations = $A(educations_list) ;
    var i = 0;
    $('e').innerHTML ='<div class="blank">blank</div>';   
    educations.each(function(education) {   
      new Insertion.Bottom('e','<div class="education_part"><div class="education_title"><a href="#" class="education_icon" id="education_icon'+i+'" onClick="showEducation('+i+');return(false);"></a><div class="education_space"></div><div class="education_title_content'+(i%2+1)+'">'+ (i+1) +' - '+education.getElementsByTagName('title').item(0).firstChild.data+'</div></div></div><div class="more_education_part invisible" id="more_education_part'+i+'"><div class="more_education">'+education.getElementsByTagName('content').item(0).firstChild.data+'</div></div>');
      i ++ ; 
    });
    new Insertion.Bottom('e','<br/>');
    $('left_content').innerHTML = formation_str;
    toggleIndicator();
    }
  });
}

//****************************************************************************

//10)showEducation

function showEducation(id){
  if (Element.hasClassName($('more_education_part'+id),'invisible')) {
    Element.removeClassName($('more_education_part'+id),'invisible') ; 
    $('education_icon'+id).style.background='url(images/b2.gif)';
  }
  else {
    Element.addClassName($('more_education_part'+id),'invisible') ; 
    $('education_icon'+id).style.background='url(images/b.gif)';
  }
}

//****************************************************************************

//11)links

function links(){
  new Ajax.Request('Controllers/Controller_Links.php',{
    onLoading : toggleIndicator,  
    onComplete : function(xhr) {
    var docXML = xhr.responseXML ; 
    var links_list = docXML.getElementsByTagName('link');
    var links = $A(links_list) ;
    var i = 0;
    $('e').innerHTML ='';  
    links.each(function(link) { 
      var str = '<div class="blank">blank</div><div class="link_part">';
      str += '<div class="link_title"><a class="link_title" href="'+link.getElementsByTagName('name').item(0).firstChild.data+'">'+link.getElementsByTagName('title').item(0).firstChild.data+'</a></div>';
      if (i%2 == 1)        
          str += '<div class="link_photo"><a class="pure" href="'+link.getElementsByTagName('name').item(0).firstChild.data+'"><img src='+link.getElementsByTagName('image').item(0).firstChild.data+' title="'+link.getElementsByTagName('title').item(0).firstChild.data+'"></img></a></div><div class="link_text">'+link.getElementsByTagName('description').item(0).firstChild.data+'</div>';   
      else         
          str += '<div class="link_text2">'+link.getElementsByTagName('description').item(0).firstChild.data+'</div><div class="link_photo"><a class="pure" href="'+link.getElementsByTagName('name').item(0).firstChild.data+'"><img src='+link.getElementsByTagName('image').item(0).firstChild.data+' title="'+link.getElementsByTagName('title').item(0).firstChild.data+'"></img></a></div>';
      str += '</div>';
      new Insertion.Bottom('e',str) ;
      i ++;
    });
    new Insertion.Bottom('e','<br />') ;
    $('left_content').innerHTML = liens_str;
    toggleIndicator();
    }
  });
}

//****************************************************************************

//12)photos

function photos(){
  new Ajax.Request('Controllers/Controller_Photos.php',{
    onLoading : toggleIndicator,    
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ; //Mise en place de la réponse XML
      var events = docXML.getElementsByTagName('event'); // Récupération des événements
      var number = events.length ; // Récupération du nombre d'événements
      $('e').innerHTML = '<div class="blank">blank</div><p id="last_event">DERNIER EVENEMENT : '+docXML.getElementsByTagName('title').item(0).firstChild.data+'</p>';
      var last_date = docXML.getElementsByTagName('date').item(0).firstChild.data ;
      var last_day = last_date.substring(8,10) ;
      var last_month = last_date.substring(5,7) ;
      var last_year = last_date.substring(0,4) ;
      new Insertion.Bottom('e','<p><b>'+last_day+'-'+last_month+'-'+last_year+' :</b> '+docXML.getElementsByTagName('description').item(0).firstChild.data+'</p>') ;
      var last_photos = events.item(0).getElementsByTagName('photo');
      var num = last_photos.length ;
      var val = Math.min(num,4) ;
      for (var i=0;i<val;i++)
        new Insertion.Bottom('e','<a class="photo'+(i%2+1)+'" href="'+events.item(0).getElementsByTagName('path').item(i).firstChild.data+'" rel="lightbox['+0+']" title="'+events.item(0).getElementsByTagName('name').item(i).firstChild.data+'"><img class="picture" src="'+events.item(0).getElementsByTagName('thumb_path').item(i).firstChild.data+'" /></a>') ;
      if (val == 4 && num != 4){
        var str = '<p><a href="#" class="education_icon" id="education_icon0" onClick="showEducation(0)"></a>&nbsp;&nbsp;Plus...</p><div class="more_education_part invisible" id="more_education_part0"><div class="more_education">' ;
        for ( var i=4;i<num;i++)
            str += '<a class="photo'+(i%2+1)+'" href="'+events.item(0).getElementsByTagName('path').item(i).firstChild.data+'" rel="lightbox['+0+']" title="'+events.item(0).getElementsByTagName('name').item(i).firstChild.data+'"><img class="picture" src="'+events.item(0).getElementsByTagName('thumb_path').item(i).firstChild.data+'" /></a>' ;
        new Insertion.Bottom('e',str+'</div></div>') ;
      }
      new Insertion.Bottom('e','<p id="last_events"> LES 10 EVENEMENTS LES PLUS RECENTS :</p><div class="blank">blank</div>') ;
      val = Math.floor((number-2)/10) ;
      var value = Math.min(11,number) ;
      for (var i=1;i<value;i++) {  
        var date = events.item(i).getElementsByTagName('date').item(0).firstChild.data ;
        var day = date.substring(8,10) ;
        var month = date.substring(5,7) ;
        var year = date.substring(0,4) ;
        var id = events.item(i).getElementsByTagName('id').item(0).firstChild.data ;
        new Insertion.Bottom('e','<div class="education_part"><div class="education_title"><a href="#" class="education_icon" id="education_icon'+i+'" onClick="showPhotos('+id+','+i+');return(false);"></a><div class="education_space"></div><div class="education_title_content'+((i+1)%2+1)+'">'+ i +' - '+events.item(i).getElementsByTagName('title').item(0).firstChild.data+'</div></div></div><div class="more_education_part invisible" id="more_education_part'+i+'"><div class="more_education"><p><b>'+day+'-'+month+'-'+year+' : </b>'+events.item(i).getElementsByTagName('description').item(0).firstChild.data+'</p><p id="pict_content'+i+'" class="pict_content"></p></div></div>') ;     
      }
      var str ='';
      for (var i=1;i<=val;i++) {    
          value = Math.min(10*(i+1)+1,number) ;
          var str = '<p><a href="#" id="photo_icon'+i+'" class="education_icon" onClick="showEvents('+i+');return(false);"></a>&nbsp;&nbsp;Plus...</p>' ; 
          for (var j=(10*i+1) ; j<value ;j++){
            var date = events.item(j).getElementsByTagName('date').item(0).firstChild.data ;
            var day = date.substring(8,10) ;
            var month = date.substring(5,7) ;
            var year = date.substring(0,4) ;
            var id = events.item(j).getElementsByTagName('id').item(0).firstChild.data ;
            string += '<div class="more_education_part invisible" id="more_photo_part'+i+'"><div class="more_education"><div class="education_part"><div class="education_title"><a href="#" class="education_icon" id="education_icon'+j+'" onClick="showPhotos('+id+','+j+');return(false);"></a><div class="education_space"></div><div class="education_title_content'+(j%2+1)+'">'+ j +' - '+events.item(j).getElementsByTagName('title').item(0).firstChild.data+'</div></div></div><div class="more_education_part invisible" id="more_education_part'+j+'"><div class="more_education"><p>'+day+'-'+month+'-'+year+' : '+events.item(j).getElementsByTagName('description').item(0).firstChild.data+'</p><p id="pict_content'+j+'" class="pict_content"></p></div></div></div></div>';
          }
         
      }
      
      new Insertion.Bottom('e',str+'<br />');
      $('left_content').innerHTML = photos_str ;
      initLightbox();
      toggleIndicator();
    }
  });
}

//****************************************************************************

//13)showPhotos

function showPhotos(id,i){
  new Ajax.Request('Controllers/Controller_Photos_For_Event.php',{
    postBody : $H({'id':id,'id_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,    
    onComplete : function(xhr) {
        var docXML = xhr.responseXML;
        var photos = docXML.getElementsByTagName('photo');
        var num = photos.length ;
        var str='';
        for ( var k=0;k<num;k++)
          str += '<a class="photo'+(k%2+1)+'" href="'+docXML.getElementsByTagName('path')[k].firstChild.data+'" rel="lightbox['+i+']" title="'+docXML.getElementsByTagName('name')[k].firstChild.data+'"><img class="picture" src="'+docXML.getElementsByTagName('thumb_path')[k].firstChild.data+'" /></a>' ;
        $('pict_content'+i).innerHTML = str ;
        showEducation(i);
        initLightbox();
        toggleIndicator();
    }
  });
}

//****************************************************************************

//14)showEvents

function showEvents(id){
  if (Element.hasClassName($('more_photo_part'+id),'invisible')) {
    Element.removeClassName($('more_photo_part'+id),'invisible') ; 
    $('photo_icon'+id).style.background='url(images/b2.gif)';
  }
  else {
    Element.addClassName($('more_photo_part'+id),'invisible') ; 
    $('photo_icon'+id).style.background='url(images/b.gif)';
  }
}

//****************************************************************************

//15)logout

function logout(){
  new Ajax.Request('Controllers/Controller_Logout.php',{
    onLoading : toggleIndicator,    
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var str = '<div id="login_top"><div id="login_left"></div><div id="login_center"><form name="login_form"><input id="login_username_field" type="text" size="20" name="login_username_name" />';
      str += '<input id="login_password_field" type="password" size="20" name="login_password_name" /></form></div><div id="login_right"></div></div><div id="login_bottom">';
      str += '<div id="login_error_zone"><div id="login_error"></div></div><a href="#" id="login_button" onClick ="login(document.login_form.login_username_name.value,document.login_form.login_password_name.value)"></a></div>';
      $('login').innerHTML = str ;
      menu(docXML.getElementsByTagName('page').item(0).firstChild.data) ; 
      toggleIndicator();
    }
  });
}

//****************************************************************************

//16)occasional

function occasional(){
  $('e').innerHTML = '<div class="header"><ul><li><a href="#" onClick="menu(\'element4\')">Bulletins Hebdomadaires</a></li><li class="current"><a href="#">Bulletins Occasionnels</a></li></ul></div><div class="blank">blank</div><div id="newsletter_content"><p>Choisissez une année pour obtenir les bulletins occasionnels parus en cette période.</p></div>';
  $('left_content').innerHTML = '';
  for (var i=2006;i<2014;i++)
    new Insertion.Bottom('left_content','<div class="commission_border'+(i%2+1)+'"><a class="commission" href="#" onClick="showCasuals('+i+')">Année '+i+'</a></div>') ;
}

//****************************************************************************
//17)showCasuals

function showCasuals(year){
  new Ajax.Request('Controllers/Controller_Casuals.php',{
    postBody : $H({'year':year,'year_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var casuals_list = docXML.getElementsByTagName('casual');
      var casuals = $A(casuals_list) ;
      var i = 0;  
      if (casuals_list.length == 0)
        var str = '<p>Il n\'y a pas de bulletins occasionnels pour cette année.</p>';
      else {
        var str = '<p> Voici les différents bulletins occasionnels valables pour cette année :</p>';
        casuals.each(function(casual) {   
          var date = casual.getElementsByTagName('date').item(0).firstChild.data ;
          var day = date.substring(8,10) ;
          var month = date.substring(5,7) ;
          var year = date.substring(0,4) ;
          str += '<div class="education_part"><div class="education_title"><a href="#" class="education_icon" id="education_icon'+i+'" onClick="showEducation('+i+');return(false);"></a><div class="education_space"></div><div class="education_title_content'+(i%2+1)+'">'+ day+'/'+month+'/'+year+' - '+casual.getElementsByTagName('title').item(0).firstChild.data+'</div></div></div><div class="more_education_part invisible" id="more_education_part'+i+'"><div class="more_education">'+casual.getElementsByTagName('content').item(0).firstChild.data+'</div></div>';
          i ++ ; 
        });
        str += '<br/>' ;
      }
      if (docXML.getElementsByTagName('user').item(0).firstChild.data != '0')
        $('newsletter_content').innerHTML = str ;
      else
        $('newsletter_content').innerHTML = '<p>Vous devez être identifié pour pouvoir visualiser ce bulletin</p>' ;  
      toggleIndicator(); 
    }
  });
}

//****************************************************************************

//17)commissions

function commissions(){
  new Ajax.Request('Controllers/Controller_Commissions.php',{
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var commissions_list = docXML.getElementsByTagName('commission');
      var commissions = $A(commissions_list) ;
      $('left_content').innerHTML = '';
      $('e').innerHTML = '<div class="blank">blank</div><div id="commission_content">'+commission_str+'</div>' ;
      var i = 0;
      commissions.each(function(commission) {
        var subcommissions = commission.getElementsByTagName('subcommission') ;
        var num = subcommissions.length ;
        var val = Math.min(num+1,5) ;
        var str ='<div class="invisible" id="subcommission'+i+'"><div class="header" id="onglets-'+i+'-0"><ul>' ;
        if (num > 1)
          str += '<li id="list'+i+'-'+1+'"><a href="#" onClick="altern(0,'+i+','+1+','+num+','+commission.getElementsByTagName('id').item(1).firstChild.data+')">'+commission.getElementsByTagName('name').item(1).firstChild.data+'</a></li>' ;
        for (var k = 2 ; k < val ; k++)
          str += '<li id="list'+i+'-'+k+'" ><a href="#" onClick="altern(0,'+i+','+k+','+num+','+commission.getElementsByTagName('id').item(k).firstChild.data+')">'+commission.getElementsByTagName('name').item(k).firstChild.data+'</a></li>' ;
        if (val == 5 && num != 4){
          str += '</ul></div><div class="header" id="onglets-'+i+'-1"><ul>' ;
          val = Math.min((num+1),8) ;
          for (var k = 5 ; k < val ; k++) 
            str += '<li id="list'+i+'-'+k+'" ><a href="#" onClick="altern(1,'+i+','+k+','+num+','+commission.getElementsByTagName('id').item(k).firstChild.data+')">'+commission.getElementsByTagName('name').item(k).firstChild.data+'</a></li>' ;
        }
        if (val == 8 && num != 7){
          str += '</ul></div><div class="header last" id="onglets-'+i+'-2"><ul>' ;
          for (var k = 8; k < (num+1) ; k++) 
            str += '<li id="list'+i+'-'+k+'"><a href="#" onClick="altern(2,'+i+','+k+','+num+','+commission.getElementsByTagName('id').item(k).firstChild.data+')">'+commission.getElementsByTagName('name').item(k).firstChild.data+'</a></li>' ;
        }
        new Insertion.Bottom('e',str+'</ul></div></div>') ; 
        new Insertion.Bottom('left_content','<div class="commission_border'+(i%2+1)+'"><a class="commission" href="#" onClick="subcommission('+i+','+num+')">'+commission.getElementsByTagName('name').item(0).firstChild.data+'</a></div>') ;       
        i++;   
      });
      new Insertion.Bottom('e','<div id="newsletter_content"></div>');
      toggleIndicator();
    }
  });
}

//****************************************************************************

//18)subcommission

function subcommission(id,num){
  for (var i=0 ; i<=num ; i++)
     Element.removeClassName('list'+id+'-'+i,'current') ;
  $('newsletter_content').innerHTML ='<div class="blank">blank</div><p>Veuillez choisir la sous-commission qui vous intéresse.</p>';
  Element.addClassName($('commission_content'),'invisible') ;
  for ( var i = 0 ; i < 5 ; i++) {
  if ( i == id)
    Element.removeClassName($('subcommission'+i),'invisible') ;  
  else
    Element.addClassName($('subcommission'+i),'invisible') ;
  }
}

//****************************************************************************

//16)altern

function altern(a,ul,li,num,id){
   for (var i=0 ; i<=num ; i++)
     Element.removeClassName('list'+ul+'-'+i,'current') ;
   Element.addClassName('list'+ul+'-'+li,'current') ;
   if (!Element.hasClassName($('onglets-'+ul+'-'+a),'last')){
    for (var i=0;i<3;i++)
      Element.removeClassName($('onglets-'+ul+'-'+i),'last');
    var st = $('onglets-'+ul+'-'+a).innerHTML ;
    Element.remove($('onglets-'+ul+'-'+a)) ;
    new Insertion.Bottom('subcommission'+ul,'<div class="header last" id="'+'onglets-'+ul+'-'+a+'">'+st+'</div>');  
   }
   new Ajax.Request('Controllers/Controller_Articles.php',{
    postBody : $H({'commission':id,'commission_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var articles = docXML.getElementsByTagName('article');
      var number = articles.length ;
      var str = '<div class="blank">blank</div>';
      if (number == 0)
        str += '<p>Il n\'y a pas encore d\'actions concernant cette commission.</p>';
      else {
        var val = Math.min(number,10)
        str += '<p> Voici les différentes actions relatives à cette commission :</p>';
        for (var i = 0 ; i < val ; i++) {
          var date = docXML.getElementsByTagName('date').item(i).firstChild.data ;
          var day = date.substring(8,10) ;
          var month = date.substring(5,7) ;
          var year = date.substring(0,4) ;
          str += '<div class="education_part"><div class="education_title"><a href="#" class="education_icon" id="education_icon'+i+'" onClick="showEducation('+i+');return(false);"></a><div class="education_space"></div><div class="education_title_content'+(i%2+1)+'">'+ day+'/'+month+'/'+year+' - '+docXML.getElementsByTagName('title').item(i).firstChild.data+'</div></div></div><div class="more_education_part invisible" id="more_education_part'+i+'"><div class="more_education"><p class="center"><a class="photo1" href="'+docXML.getElementsByTagName('photo1').item(i).firstChild.data+'" rel="lightbox['+i+']" title="'+docXML.getElementsByTagName('title').item(i).firstChild.data+'"><img class="picture" src="'+docXML.getElementsByTagName('photo1_th').item(i).firstChild.data+'" /></a><span class="blank">blk</span><a class="photo2" href="'+docXML.getElementsByTagName('photo2').item(i).firstChild.data+'" rel="lightbox['+i+']" title="'+docXML.getElementsByTagName('title').item(i).firstChild.data+'"><img class="picture" src="'+docXML.getElementsByTagName('photo2_th').item(i).firstChild.data+'" /></a></p>'+docXML.getElementsByTagName('content').item(i).firstChild.data+'</div></div>';
        }
        str += '<br/>' ;
      }
      $('newsletter_content').innerHTML = str ;
      initLightbox();
      toggleIndicator();
    }
  });
}

//****************************************************************************

//19)checking

function checking(){
  new Ajax.Request('Controllers/Controller_Checking.php',{
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var str = '' ;
      if (docXML.getElementsByTagName('checking').item(0).firstChild.data == 'no') {
        str += '<div id="login_top"><div id="login_left"></div><div id="login_center"><form name="login_form"><input id="login_username_field" type="text" size="20" name="login_username_name" />';
        str += '<input id="login_password_field" type="password" size="20" name="login_password_name" /></form></div><div id="login_right"></div></div><div id="login_bottom">';
        str += '<div id="login_error_zone"><div id="login_error"></div></div><a href="#" id="login_button" onClick ="login()"></a></div>';
      }
      else {
        str += '<div id="login_title"></div><a href="#" id="logout_button" onClick="logout()"></a>' ;
      }
      $('login').innerHTML = str ;
      $('window_lines').innerHTML = "";  
    }
  });
  new Ajax.Request('Controllers/Controller_News.php',{
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var news = docXML.getElementsByTagName('new');
      var number = news.length ;
      var val = Math.min(number,5) ;
      var last_date = news.item(0).getElementsByTagName('date').item(0).firstChild.data ;
      var last_day = last_date.substring(8,10) ;
      var last_month = last_date.substring(5,7) ;
      var last_year = last_date.substring(0,4) ;
      $('e').innerHTML = '<div id="last_news_content"><p class="last_news1"><b>'+last_day+'/'+last_month+'/'+last_year+'</b> - '+news.item(0).getElementsByTagName('title').item(0).firstChild.data+'</p><div id="last_news_text">'+news.item(0).getElementsByTagName('content').item(0).firstChild.data+'</div><div id="last_news_photo"><a class="photo3" href="'+news.item(0).getElementsByTagName('photo_r').item(0).firstChild.data+'" rel="lightbox" title="'+news.item(0).getElementsByTagName('title').item(0).firstChild.data+'"><img  src="'+news.item(0).getElementsByTagName('photo').item(0).firstChild.data+'" /></a></div></div>' ;
      for (var i = 1 ; i < val ; i ++){
        var date = news.item(i).getElementsByTagName('date').item(0).firstChild.data ;
        var day = date.substring(8,10) ;
        var month = date.substring(5,7) ;
        var year = date.substring(0,4) ;
        new Insertion.Bottom('e','<div class="news_content"><p class="last_news'+(i%2+1)+'"><b>'+day+'/'+month+'/'+year+'</b> - '+news.item(i).getElementsByTagName('title').item(0).firstChild.data+'</p><div class="news_photo"><a class="photo3" href="'+news.item(i).getElementsByTagName('photo_r').item(0).firstChild.data+'" rel="lightbox" title="'+news.item(i).getElementsByTagName('title').item(0).firstChild.data+'"><img  src="'+news.item(i).getElementsByTagName('photo_m').item(0).firstChild.data+'" /></a></div><div class="news_text">'+news.item(i).getElementsByTagName('content').item(0).firstChild.data+'</div></div>') ;
      }
      new Insertion.Bottom('e','<br/><br/><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />') ; 
      date = new Date();
      calendar2((date.getMonth()+1),date.getFullYear());
      initLightbox();
      toggleIndicator();
    }
  });
}

//****************************************************************************

//20)calendar2

function calendar2(month,year){
  new Ajax.Request('Controllers/Controller_Calendar2.php',{
    postBody : $H({'calendar_month': month,'calendar_month_type':'string','calendar_year':year,'calendar_year_type':'string'}).toQueryString(),  
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      $('left_content').innerHTML ="";
      var docXML = xhr.responseXML ;
      var weeks_list = docXML.getElementsByTagName('week');
      var weeks = $A(weeks_list) ;
      var current_day = docXML.getElementsByTagName('currentday').item(0).firstChild.data ; 
      var current_month = docXML.getElementsByTagName('currentmonth').item(0).firstChild.data ; 
      var current_year = docXML.getElementsByTagName('currentyear').item(0).firstChild.data ; 
      var str = '<div id="agenda_title">Agenda</div><br />' ;
      str +='<div id="calendar_title"><a href="#" id="calendar_title_left" onClick="previous_calendar2('+month+','+year+');return(false);"></a><div id="calendar_title_center">'+docXML.getElementsByTagName('title').item(0).firstChild.data+'</div><a href="#" id="calendar_title_right" onClick="next_calendar2('+month+','+year+');return(false);"></a></div>';
      str +='<div id="calendar_days"><div class="day_value">Lun</div><div class="day_value">Mar</div><div class="day_value">Mer</div><div class="day_value">Jeu</div><div class="day_value">Ven</div><div class="day_value">Sam</div><div class="day_value">Dim</div></div>';
      var i = 0 ;
      weeks.each(function(week) {
         str += '<div class="calendar_week" id="calendar_week'+i+'">';
         for ( var j = 0 ; j < 7 ; j++) {
           if (week.getElementsByTagName('day').item(j).firstChild) {
               if ((week.getElementsByTagName('day').item(j).firstChild.data == current_day) && (month == current_month) && (year == current_year))
                 str += '<div id="day'+week.getElementsByTagName('day').item(j).firstChild.data+'" class="current_day2">'+ week.getElementsByTagName('day').item(j).firstChild.data+'</div>';
               else
                 str += '<div id="day'+week.getElementsByTagName('day').item(j).firstChild.data+'" class="day">'+week.getElementsByTagName('day').item(j).firstChild.data+'</div>';
           isAgenda(week.getElementsByTagName('day').item(j).firstChild.data,month,year);
           }
           else
             str += '<div class="day">'+' '+'</div>';
         }
         str += '</div>';
      });
      str += '<div id="calendar_bottom"></div><div id="calendar_field_left"><select id="month" onChange="calendar2($(\'month\').value,$(\'year\').value)">';
      var array = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
      for (var i = 1 ; i <13 ; i++ ) 
        (month == i) ? str+= '<option value="'+i+'" selected="selected">'+array[i-1]+'</option>': str+='<option value="'+i+'">'+array[i-1]+'</option>';
      str += '</select></div>';
      str += '<div id="calendar_field_center"><select id="year" onChange="calendar2($(\'month\').value,$(\'year\').value)">';
      for (var i = 2006 ; i <2011 ; i++ ) 
        (year == i) ? str += '<option value="'+i+'" selected="selected">'+i+'</option>':str += '<option value="'+i+'">'+i+'</option>';
      str += '</select></div><div id="testa"><p>Veuillez cliquer sur un jour pour voir l\'agenda correspondant.</p></div>';
      $('left_content').innerHTML = str; 
      toggleIndicator();
    }
  });
}

//****************************************************************************

//21)previous_calendar2

function previous_calendar2(month,year){
  if (month == 1)
    calendar2(12,year-1);
  else
    calendar2(month-1,year);
}

//****************************************************************************

//22)next_calendar2

function next_calendar2(month,year){
  if (month == 12)
    calendar2(1,year+1);
  else
    calendar2(month+1,year);
}

//****************************************************************************

//23)showAgenda

function showAgenda(day,month,year){
  new Ajax.Request('Controllers/Controller_Agendas.php',{
    postBody : $H({'day':day,'day_type':'string','month': month,'month_type':'string','year':year,'year_type':'string'}).toQueryString(),
    onLoading : toggleIndicator,
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var agendas = docXML.getElementsByTagName('agenda');
      var number = agendas.length ;
      var val = Math.min(number,6);
      $('testa').innerHTML = '';
      for(var i=0;i<val;i++)
          new Insertion.Bottom('testa','<p class="agenda"><b>'+agendas.item(i).getElementsByTagName('time').item(0).firstChild.data.substring(0,5)+' </b><span class="black">'+agendas.item(i).getElementsByTagName('content').item(0).firstChild.data+'</span></p>') ;
      if (month < 10)
        month = '0'+month ;
      if (day < 10)
        day = '0'+day ;
      $('agenda_title').innerHTML = 'Agenda du '+day+'-'+month+'-'+year ;
       toggleIndicator();
    }
  });
}

//****************************************************************************

//24)isAgenda

function isAgenda(day,month,year){
  new Ajax.Request('Controllers/Controller_Agendas.php',{
    postBody : $H({'day':day,'day_type':'string','month': month,'month_type':'string','year':year,'year_type':'string'}).toQueryString(),
    onComplete : function(xhr) {
      var docXML = xhr.responseXML ;
      var agendas_list = docXML.getElementsByTagName('agenda'); 
      if (agendas_list.length != 0){
        $('day'+day).innerHTML = '<a href="#" class="day2" onClick="showAgenda('+day+','+month+','+year+');return(false);">'+day+'</a>';
        Element.addClassName($('day'+day),'day_agenda');
      }
    }
  });
}

//****************************************************************************

//25)toggleIndicator

function toggleIndicator(){
  Element.toggle('indicator');
}

