// calendar.js file 
        var addExtraWeekBefore = true; //do we want to display the week before the start of this month?
         var addExtraWeekAfter = false; //do we want to display the week after the end of this month?
         var thisMonth = true; //we're starting in the current month so set to true
         var futureMonth = false; //we're not in the future so set this to false
				
				/*COMMENTED OUT SO WE COULD CHANGE COLOURS LOCALLY FOR EACH SITE*/
         /*var standardColour = '#EEEEEE'; // Colour of the cell when not highlighted (same as standard class)
         var selectColour = '#F9FFF8';   // Selected days colour (same as lastseven class)
         var todayColour = '#AA1122';    // Today's highlighted colour (ame as currentday class)
         var selectedToday = '#AA5522';  // Today's highlighted colour when selected (same as currentdayselected class)*/
         
         var isMouseDown = false; //flag to check when the user clicks on a day
         var clickedDay = 0;
         var todayPos = 0;
         
         /*the month value is set externally when a user selects either a future or past month
         i.e when the url would be for example http://www.silicon.fr/actualite/semaine?month=3
         on initial startup month paramater is NaN*/
         var month = parseInt(getRequestParameter('month'));
         
         var days = new Array();
         
         var maxage = getRequestParameter('maxage')==null?7:parseInt(getRequestParameter('maxage'));
         var minage = getRequestParameter('minage')==null?0:parseInt(getRequestParameter('minage'));

         var dateFrom = new Date();
         var dateTo = new Date();
         dateFrom.setTime(new Date().getTime() - maxage*24*60*60*1000); //dateFrom is the date 7 days ago
         dateTo.setTime(new Date().getTime() - minage*24*60*60*1000); //dateTo is todays date
         
         var daysBefore = 0;
         var daysAfter = 0;
            
         if(addExtraWeekBefore) {
            daysBefore = 7; //this will display an extra week before the start of the current month
         }
            
         if(addExtraWeekAfter) {
            daysAfter = 7; //this will display an extra week after the end of the current month
         }
         
         var today = new Date();
         var date = new Date();
         //if month value has already been set then set the date object accordingly
         if(month || month == '0') {
            date.setMonth(parseInt(month));
            //Check 31st
            if(date.getDate()!=today.getDate()) {
               date.setMonth(parseInt(month), today.getDate()-1);
            }
            //If we come back to Feb but current day is over 28
            if(month==1 && today.getDate()>28) {
               date.setMonth(parseInt(month), 28);
            }
         //otherwise use todays date
         } else {
            month = date.getMonth();
         }
         if(date.getMonth()!=today.getMonth()) thisMonth = false;
         if(date.getMonth()>today.getMonth() && date.getYear()>=today.getYear()) futureMonth = true;
				
				 /*monthsAgo = how many months away from todays month has the user navigated to
				 ie if todays month is May and user navigates backwards to March, monthsAgo = 2
				 values will be negative if the user navigates forward */
         var monthsAgo =  (today.getYear()-date.getYear())*12 + (today.getMonth() - date.getMonth());
         // Figure out how many days ago was the same day of month
         var daysAgo = 0;
         for(var i=0;i<monthsAgo;i++) {
             var prevMonth = new Date();
             prevMonth.setMonth(prevMonth.getMonth()-i,1);
             prevMonth.setDate(prevMonth.getDate()-1);
             daysAgo += prevMonth.getDate();
         }
          
         var dayOfWeek = date.getDay();
         var dateOfMonth = date.getDate();


         /*Prepare the days array to display the calendar*/
         var firstDay = new Date(); //the first day of the month
         firstDay.setTime(new Date().getTime() - daysAgo*24*60*60*1000);
         if(month>-1) {
            firstDay.setMonth(month, 1);
         } else {
            firstDay.setDate(1);
         }

         /*What day of week is the first day of the month
         .getDay() returns integer representing day of the week
         ie if Sunday is the first day of the week, a value of 2 represents Tuesday
         added with daysBefore to ascertain where in final string of days the month will start*/
         var firstDayOfMonth = daysBefore+firstDay.getDay();
				
         var lastDay = new Date(); //the last day of the month
         lastDay.setTime(new Date().getTime() - daysAgo*24*60*60*1000);
         if(month>-1) { lastDay.setMonth(month, 1); }
         lastDay.setMonth(lastDay.getMonth()+1, 1);
         lastDay.setDate(lastDay.getDate()-1);

         var lastDateOfMonth = lastDay.getDate(); //essentially how many days in the current month
         var lastDayOfMonth = lastDay.getDay(); //the day of the week the last day of the month falls on
         
         //variables for previous month of which only the last week is displayed (if 'daysBefore' = 7)
         var lastMonth = new Date();
         lastMonth.setTime(new Date().getTime() - daysAgo*24*60*60*1000);
         lastMonth.setDate(1);
         if(month>-1) { lastMonth.setMonth(month,1); }
         lastMonth.setDate(lastMonth.getDate()-1);
         var lastDateOfLastMonth = lastMonth.getDate();

         //Fill up the days table with previous month days
         for(var i=lastDateOfLastMonth-firstDayOfMonth+1;i<=lastDateOfLastMonth;i++) {
             days.push(i);
         }

         //Fill up the days table with current month days
         for(var i=1;i<=lastDateOfMonth;i++) {
             days.push(i);
         }
         
         //Add the first week of the next month on demand
         if(addExtraWeekAfter) {
            for(var i=1;i<=(6-lastDayOfMonth+7);i++) {
                days.push(i);
            }
         }

         todayPos = firstDayOfMonth+dateOfMonth-1;
          
         var posMaxage = daysAgo+todayPos-maxage;
         var posMinage = daysAgo+todayPos-minage;

         /*Get request parameters from location.search*/
         function getRequestParameter (parameterName) {
           var queryString = document.location.search;
           var parameterName = parameterName + "=";
           if(queryString.length > 0 ) {
              begin = queryString.indexOf(parameterName);
              // If the parameter name is not found, skip it, otherwise return the value
              if(begin!=-1) {
                 // Add the length to the beginning
                 begin += parameterName.length;
                 // Multiple parameters are separated by &
                 end = queryString.indexOf ( "&" , begin );
                 if(end==-1) {
                    end = queryString.length
                 }
                 return unescape(queryString.substring(begin, end));
               }
           return null;
           }
         } 
         
         //called on mouseDown event
         function startDragging(i) {
					// 2 conditionals so that its not possible to drag and select days in the future
           if(!futureMonth) {
              if(i<=todayPos || !thisMonth) {
                 isMouseDown = true;
                 clickedDay = parseInt(i);
               	
               	//change the color selected days
                 for(var k=0;k<50;k++) {
                     var el = document.getElementById('day_'+k+'');
                     if(el) {
                        if(k==todayPos && thisMonth) {
                           el.style.background = todayColour;
                        } else {
                           el.style.background = standardColour;
                        }
                     }
                 }
               
                 var el = document.getElementById('day_'+i+'');
                 
                 if(i==todayPos && thisMonth) {
                    el.style.background = selectedToday;
                 } else {
                    el.style.background = selectColour;
                 }
                 
                 maxage = parseInt(todayPos) - parseInt(i);
                 if(!thisMonth) {
                    maxage = maxage+daysAgo;
                 }
                 document.getElementById('go').href = cal_url + '?maxage='+maxage+'&minage='+minage+'&month='+month+'';
              }
            }
         }
         
         //called on mouseUp event
         function stopDragging(i) {
           isMouseDown = false;
           minage = parseInt(todayPos) - parseInt(i);
           if(!thisMonth) {
              minage = minage+daysAgo;
           }
           
           if(minage>maxage) {
              var tmp = maxage;
              maxage = minage;
              minage = tmp;
           }
           
           document.getElementById('go').href = cal_url + '?maxage='+maxage+'&minage='+minage+'&month='+month+'';
         }
         
         //called on mouseOver. 'high' short for 'highlight' i guess
         function high(i) {
           
           if(!futureMonth) {
              if(isMouseDown) {
                 for(var k=0;k<50;k++) {
                     var el = document.getElementById('day_'+k+'');
                     if(el) {
                        if(k==todayPos && thisMonth) {
                           el.style.background = todayColour;
                        } else {
                           el.style.background = standardColour;
                        }
                     }
                 }

                 if(i>clickedDay && (i<=todayPos || !thisMonth)) {
                    for(var j=clickedDay;j<=i;j++) {
                        var el = document.getElementById('day_'+j+'');
                        if(j==todayPos && thisMonth) {
                           el.style.background = selectedToday;
                        } else {
                           el.style.background = selectColour;
                        }
                    }
                 } else {
                    for(var j=clickedDay;j>=i;j--) {
                        var el = document.getElementById('day_'+j+'');
                        if(j==todayPos && thisMonth) {
                           el.style.background = selectedToday;
                        } else {
                           el.style.background = selectColour;
                        }
                    }
                 }
              }
           }

         }
      
         function displayCalendar() {
            
            document.write('<table align="center" width="190" class="main" border="0" cellpadding="2" cellspacing="0">');
            document.write('  <tr>');
            document.write('    <td colspan="8" align="center"> <b><a href="?month='+(parseInt(month)-1)+'"><<</a> '+eurosite_months[date.getMonth()]+' '+date.getFullYear()+' <a href="?month='+(parseInt(month)+1)+'">>></a> </b> </td>');
            document.write('  </tr>');
            document.write('  <tr>');
            //document.write('    <td>&nbsp;</td>'); // If we highlight the whole week
            for(var i=0;i<7;i++) {
                document.write('  <td style="font-size:9px;">'+eurosite_daysOfWeek[i]+'</td>');
            }
            document.write('  </tr>');
            document.write('  <tr>');
            //document.write('    <td><a href="#">></a></td>');
            for(var i=0;i<days.length;i++) {
            
                if(i>=posMaxage && i<posMinage) {
                   document.write('    <td class="cell" id="cell_'+i+'"> <button class="lastseven" id="day_'+i+'" type="button" onfocus="this.blur();" onmousedown="startDragging(\''+i+'\');" onmouseup="stopDragging(\''+i+'\');" onmouseover="high(\''+i+'\')">'+days[i]+'</button></td>');
                } else if(i==posMinage && posMinage!=todayPos) {
                   document.write('    <td class="cell" id="cell_'+i+'"> <button class="lastseven" id="day_'+i+'" type="button" onfocus="this.blur();" onmousedown="startDragging(\''+i+'\');" onmouseup="stopDragging(\''+i+'\');" onmouseover="high(\''+i+'\')">'+days[i]+'</button></td>');
                } else if(i==posMinage && posMinage==todayPos) {
                   document.write('    <td class="cell" id="cell_'+i+'"> <button class="currentdayselected" id="day_'+i+'" type="button" onfocus="this.blur();" onmousedown="startDragging(\''+i+'\');" onmouseup="stopDragging(\''+i+'\');" onmouseover="high(\''+i+'\')">'+days[i]+'</button></td>');
                } else if(i==todayPos && thisMonth) {
                   document.write('    <td class="cell" id="cell_'+i+'"> <button class="currentday" id="day_'+i+'" type="button" onfocus="this.blur();" onmousedown="startDragging(\''+i+'\');" onmouseup="stopDragging(\''+i+'\');" onmouseover="high(\''+i+'\')">'+days[i]+'</button></td>');
                } else {
                   document.write('    <td class="cell" id="cell_'+i+'"> <button class="standard" id="day_'+i+'" type="button" onfocus="this.blur();" onmousedown="startDragging(\''+i+'\');" onmouseup="stopDragging(\''+i+'\');" onmouseover="high(\''+i+'\')">'+days[i]+'</button></td>');
                }
                if(i%7==6 && i<days.length-1) {
                   document.write(' </tr> <tr>');
                   //document.write(' <td><a href="#">></a></td>'); // TODO highlight whole week
                }            
            }
            document.write('  </tr>');
            document.write('  <tr>');
            document.write('    <td colspan="8" align="center" height="5"><b><a id="go" href="' + cal_url + '?maxage='+maxage+'&minage='+minage+'&month='+month+'">'+eurosite_submitLabel+'</a></b></td>');
            document.write('  </tr>');
            document.write('</table>');
         }
// calendar_days.js file
// ---------------------
var standardColour = '#99BBDD'; // Colour of the cell when not highlighted (same as standard class)
var selectColour = '#FCAE5A';   // Selected days colour (same as lastseven class)
var todayColour = '#DDE5EE';    // Today's highlighted colour (ame as currentday class)
var selectedToday = '#FCAE5A';  // Today's highlighted colour when selected (same as currentdayselected class)

var eurosite_monthsShort = new Array('Jan','F&#233;v','Mar','Avr','Mai','Juin','Juil','Aou','Sep','Oct','Nov','D&#233;c');
var eurosite_months = new Array('Janvier','F&#233;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&#251;t','Septembre','Octobre','Novembre','D&#233;cembre');
var eurosite_daysOfWeek = new Array('Dim','Lun','Mar','Mer','Jeu','Ven','Sam');
var eurosite_submitLabel = 'Valider';
var cal_url = '/actualite/infojour'
// search.js file
// --------------

//this function is called when the user clicks on the search results
//tabs, to invoke the required zone specific search
function changeZone(zoneName) {
  var form = document.forms['standardSearch'];
  form.elements['zone'].value = '1';
  form.elements['zone'].value = zoneName;
  form.submit();
}

// this function updates the page value, so results can be
// displayed accordingly
function changePage(pageValue, zone) {
  var form = document.forms['standardSearch'];
  form.elements['page'].value = pageValue;
  form.elements['zone'].value = zone;
  form.submit(); 
}
