// ====================================================
// prevIncr 
// ====================================================
function prevIncr (incr, unit, update) {

	backDate = new Date (_curDate);

        if (unit == _day)  backDate.setDate (backDate.getDate() - incr);
  	else if (unit == _month) backDate.setMonth (backDate.getMonth () - incr);
  	else backDate.setFullYear (backDate.getFullYear ()-incr);

	// update current date
        if (update && (backDate >= _start)) {

	    _curDate.setFullYear (backDate.getFullYear ());
	    _curDate.setMonth (backDate.getMonth ());
	    _curDate.setDate (backDate.getDate ());
	}

	return (backDate >= _start);
}


// ====================================================
// nextIncr 
// ====================================================
function nextIncr (incr, unit, update) {

	nextDate = new Date (_curDate);

        if (unit == _day) nextDate.setDate (nextDate.getDate() + incr);
	else if (unit == _month) nextDate.setMonth (nextDate.getMonth () + incr);
  	else nextDate.setFullYear (nextDate.getFullYear () + incr);

	// update current date
        if (update && (nextDate <= _end)) {

	    _curDate.setFullYear (nextDate.getFullYear ());
	    _curDate.setDate (nextDate.getDate ());
	    _curDate.setMonth (nextDate.getMonth ());
	}	

	return (nextDate <= _end);
}



// ====================================================
// update_date
// Mise a jour du champ date
// ====================================================
function update_date () {

   date1 = _curDate.getDate () + '-' + _labelMonthList [_curDate.getMonth ()].substring (0, 3) + "-" + _curDate.getFullYear ();

   document.DateSelection.Date_txt.value = date1;

}


// ====================================================
// get_image_name ()
// fonction calculant le nom d'une image / jour courant
// ====================================================

function get_image_name () {

   image_name = _curDate.getFullYear();
   image_name = image_name*100 + (_curDate.getMonth () + 1);
   image_name = image_name*100 + _curDate.getDate ();

   return (image_name);
}


// ====================================================
// update_images ()
// fonction de mise a jour d'une image
// ====================================================

function update_images (im_idx, var_idx) {
  if (var_idx == NADA) {
    im_url    = './images/image_nada.gif';
    info_url  = './images/info_nada.gif';
    title_url = './images/title_nada.gif';
  }
  else {
    im_url    = _small_image_root + '/' + _global_set + '/' + _datasets[var_idx][ID] + '/' + get_image_name() + '.png';
    info_url  = './images/info_nada.gif'; // pas d'info ici
    title_url = './images/' + _datasets[var_idx][ID] + '.png';

  }
  img_offsetnumber = 23;
  document.images [img_offsetnumber + im_idx*3].src   = im_url;
  document.images [img_offsetnumber + im_idx*3+1].src = info_url;
  document.images [img_offsetnumber + im_idx*3+2].src = title_url;
}

// ====================================================
// update_links ()
// fonction de mise a jour d'un lien
// ====================================================
function no_small_data (im_idx) {
  document.images[im_idx].src = "images/no_small_image.gif";
}

// ====================================================
// update_links ()
// fonction de mise a jour d'un lien
// ====================================================

function update_links (im_idx, var_idx) {

  if (var_idx == NADA) {
    info_url = "#";
    big_url  = "#";
  }
  else {
    info_url = _info_root + _datasets[var_idx][ID] + '.htm';
    big_url  = _big_image_root + '/' + _global_set + '/' + _datasets[var_idx][ID] + '/' + get_image_name() + '.png';
  }

  document.links [7 + im_idx*2].href   = big_url;
  //document.links [17 + im_idx*2+1].href = info_url;
}



// ====================================================
// update ()
// fonction de mise a jour generale du tableau d'images
// ====================================================

function update () {
  im_idx = 0;
  for (i = 0; i < _nbSets; ++i) {

    if ((_datasets [i][START] <= _curDate) &&
	(_datasets [i][END] >= _curDate)) {

      update_links (im_idx, i);
      update_images (im_idx, i);
      im_idx = im_idx + 1;
    }
  }
 

  update_date ();

  return true;

}



// ====================================================
// get_list ()
// fonction d'affichage de la liste des donnees
// ====================================================
function get_list () {

   for (i = 1; i < _nbSets; i++) {
     document.write ("<TR>");
     info_url =  _datasets [i][ID] + ".htm";
     document.write ("<TD bgcolor=#BFBFFF><A HREF=" + info_url + " onClick='info(" + (i - 1) + "); return false'><IMG SRC='images/icon_info.gif' BORDER=0></A></TD>");
     document.write ("<TD WIDTH=220 bgcolor=#BFBFFF><IMG SRC=images/" + _datasets [i][ID] + ".gif></TD>");
     date_start = _datasets [i][START].getDate () + ' ' + _labelMonthList [_datasets [i][START].getMonth ()].substring (0, 3) + " " + _datasets [i][START].getFullYear ();
     date_stop  = _datasets [i][END].getDate () + ' ' + _labelMonthList [_datasets [i][END].getMonth ()].substring (0, 3) + " " + _datasets [i][END].getFullYear ();
     document.write ("<TD WIDTH=100% bgcolor=#B1F1FC><STRONG>" + date_start + " - " + date_stop + "</STRONG></TD>");
     document.write ("</TR>");
   }
}

