
function checkBrowser() {
  this.ver = navigator.appVersion;
  this.dom = document.getElementById?1:0;
  this.ie4 = (document.all && !this.dom)?1:0;
  this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
  this.ns4 = (document.layers && !this.dom)?1:0;
  this.ns5 = (this.dom && parseInt(this.ver)>=5)?1:0;
  this.dyn = (this.ie4||this.ie5||this.ns4||this.ns5);
  return this;
}

function showHelp(topic, sub) {
  if (sub == undefined) sub = 0;
  if ((typeof(pophlp)=="object") && (typeof(pophlp.document)=="object")) pophlp.close();
  var url = ((sub==1)?"../":"./") + "help.php?id=" + topic;
  pophlp = window.open(url, "HELP", "width=400,height=400,scrollbars,resizable");
}

function showGraph(type, args) {
  if ((typeof(popgraph)=="object") && (typeof(popgraph.document)=="object")) popgraph.close();
  var url = "graph_" + type + ".php?curdate=" + args;
  popgraph = window.open(url, "GRAPHIQUE", "width=620,height=370,scrollbars,resizable");
}

function showAddress(ref) {
  if ((typeof(popadd)=="object") && (typeof(popadd.document)=="object")) popadd.close();
  var url = "address_part.php" + ((ref==1)?"?SELECT":"");
  popadd = window.open(url, "CONTACTS", "width=650,height=600,scrollbars,resizable,status=0");
}

function addAddress(adr) {
  var actual = document.frm.ADRESSE.value;
  if (actual != "") actual = actual + "; ";
  document.frm.ADRESSE.value = actual + adr;
}

function toggle(isChecked) {
  for (i=0; i<document.frm.elements.length; i++)
    document.frm.elements[i].checked = isChecked;
}

function genPwd(sub, field, ndeb, nfin) {
  if (field == undefined) field = "PASSWD";
  if (sub   == undefined) sub   = 0;
  if (ndeb  == undefined) ndeb  = 0;
  if (nfin  == undefined) nfin  = 0;
//if ((typeof(poppwd)=="object") && (typeof(poppwd.document)=="object")) poppwd.close();
  var url = ((sub==1)?"../":"./") + "gen_passwd.php?field=" + field + "&ndeb=" + ndeb + "&nfin=" + nfin;
  poppwd = window.open(url, "PASSWD", "width=10,height=10");
}

// -------------------------------------------------------------------------

  function getCalendar(year, month) {
    now = new Date();
    this_month = new Date(year, month, 1);
    next_month = new Date(year, month + 1, 1);
    prev_month = new Date(year, month, 0);
    month = this_month.getMonth();
    year  = this_month.getFullYear();

    months = new Array('janvier','février','mars','avril','mai','juin',
             'juillet','août','septembre','octobre','novembre','décembre');
         
    // Find out when this month starts and ends.         
    first_week_day = this_month.getDay() - 1; if (first_week_day < 0) first_week_day = 6;
    days_in_this_month = Math.floor((next_month.getTime() - this_month.getTime()) / (1000*60*60*24));
         
    calhtml = '<table border=0 width=175 height=160 cellpadding=0 cellspacing=0>';
    calhtml+= '<tr height=20>';
    calhtml+= '<td class="calcaz"><a href="javascript:showCal('+year+','+(month)+')" class="calcaz">&lt;</a></td>';
    calhtml+= '<td class="calcaz" colspan=5><a href="javascript:hideBox();">' + months[month] + ' ' + year + '</a></td>';
    calhtml+= '<td class="calcaz"><a href="javascript:showCal('+year+','+(month+2)+')" class="calcaz">&gt;</a></td>';
    calhtml+= '</tr>';
    calhtml+= '<tr height=20>';
    calhtml+= '<td class="calcaz" width=25>lu</td>';
    calhtml+= '<td class="calcaz" width=25>ma</td>';
    calhtml+= '<td class="calcaz" width=25>me</td>';
    calhtml+= '<td class="calcaz" width=25>je</td>';
    calhtml+= '<td class="calcaz" width=25>ve</td>';
    calhtml+= '<td class="calcaz" width=25>sa</td>';
    calhtml+= '<td class="calcaz" width=25>di</td>';
    calhtml+= '</tr>';
         
    // Fill the first week of the month with the appropriate number of blanks.       
    calhtml+= '<tr height=20>';
    for (week_day = 0; week_day < first_week_day; week_day++) {
      day_counter = prev_month.getDate() - first_week_day + week_day + 1;
      calhtml+= '<td class="calout"><a href="javascript:selectDate('+year+','+(month)+','+day_counter+')" class="calout">'+ day_counter +'</a></td>';   
    }

    week_day = first_week_day;
    for (day_counter = 1; day_counter <= days_in_this_month; day_counter++) {
      week_day %= 7;
      if ((week_day == 0) && (day_counter > 1)) calhtml+= '</tr><tr height=20>';
      if ((now.getFullYear()==year) && (now.getMonth()==month) && (now.getDate()==day_counter))
        calhtml+= '<td class="calnow"><a href="javascript:selectDate('+year+','+(month+1)+','+day_counter+')" class="calnow">' + day_counter + '</a></td>';
      else
        calhtml+= '<td class="calday"><a href="javascript:selectDate('+year+','+(month+1)+','+day_counter+')" class="calday">' + day_counter + '</a></td>';
      week_day++;
    }

    next_month_days = 42 - first_week_day - day_counter + 1;
    for (day_counter = 1; day_counter <= next_month_days; day_counter++) {
      week_day %= 7;
      if (week_day == 0) calhtml+= '</tr><tr height=20>';
      calhtml+= '<td class="calout"><a href="javascript:selectDate('+year+','+(month+2)+','+day_counter+')" class="calout">' + day_counter + '</a></td>';
      week_day++;
    }

    calhtml+= '</table>';
    return calhtml;
  }

  function hideBox() {
    var box = document.getElementById("calendar");
    box.style.visibility = "hidden";
    inputname = "";
  }
  
  function showBox(divMsg) {
    if ((navigator.userAgent.toLowerCase().indexOf("opera") == -1) &&
        (navigator.userAgent.toLowerCase().indexOf("khtml") == -1) &&
        (document.all)) {
      if (document.documentElement && document.documentElement.scrollTop) {
        var temp_y = document.documentElement.scrollTop;
        divMsg.style.top = temp_y+"px";
      } else if (document.body.scrollTop) {
        var temp_y = document.body.scrollTop;
        divMsg.style.top = temp_y+"px";
      }
    }
    divMsg.style.visibility = "visible";
    divMsg.style.zIndex = 1000;
  }

  function showCal(year, month) {
    now = new Date();
    if (year == null) year = now.getFullYear();
    if (month== null) month= now.getMonth()+1;
    var box = document.getElementById("calendar");
    box.innerHTML = getCalendar(year, month-1);
    showBox(box);
  }

  function launchCal(obj) {
    if (inputname != "") { hideBox(); return; }
    if (obj != null) inputname = obj;
    showCal();
  }

  function selectDate(year, month, day) {
    date = new Date(year, month, day);
    year  = date.getFullYear();
    month = date.getMonth();
    eval("document.frm."+inputname+".value='"+day+"/"+month+"/"+year+" 00:00';");
    hideBox();
  }

  var inputname = "";

// -------------------------------------------------------------------------

