/******************************************************************************
    Composant calendrier - jsCalendar
    Vincent Fiack - 07/08/2002

    Adapté de jsCalendar par
    Darren Neimke <darren@showusyourcode.com>
    http://www.flws.com.au/showusyourcode/codeLib/code/js_CalendarV3.asp
*******************************************************************************/
	
	
// -------------------------------------------
//        Classes d'aide
// -------------------------------------------
    
    
// visibilité
var Visibility = new Array()
Visibility.On = true ;
Visibility.Off = false ;
            
// navigateur
function Browser()
{
    // verification...
    if ( parseInt( navigator.appVersion.charAt(0) ) >= 4 )
    {
        this.isDOM = document.getElementById ? true : false ;
        this.isNav6 = (navigator.appName == "Netscape") ? true : false ;
        this.isNav4 = (navigator.appName == "Netscape" && !(this.isDOM)) ? true : false ;
        this.isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false ;
    }
}
var browser = new Browser();
        
        
// -------------------------------------------
//        Fonctions et variables globales
// -------------------------------------------

jsCalendarInstances = new Array();
    
// préparation du document qui va contenir le calendrier    
if(browser.isDOM)
{
    document.writeln('<style>');		
    document.writeln('#jsCalendar-container {');
    document.writeln('position : absolute;');
				
    if(browser.isIE)
    {
        document.writeln('width : 160px;');
        document.writeln('clip:rect(0px 160px 131px 0px);');
        document.writeln('height : 131px;');
    }
    else
    {
        document.writeln('width : 162px;');
        document.writeln('clip:rect(0px 162px 130px 0px);');
        document.writeln('height : 130px;');
    }
		
    document.writeln('visibility : hidden;');
    document.writeln('}');
    document.writeln('</style>')
    document.writeln('<div id="jsCalendar-container"></div>') ;
    document.writeln('<div id="jsCalendar-popup" style="z-index:+999;position:absolute;visibility:hidden;"></div>');

}

/**
 * Contourne le bug d'IE avec les select en cachant les éléments qui restent en
 * avant plan.
 *
 * @param element le type d'element a cacher
 */
function hideElement(element)
{
  if(browser.isIE)
  {
    for( i = 0; i < document.all.tags(element).length; i++ )
    {
      obj = document.all.tags(element)[i];
      if( !obj || !obj.offsetParent )
        continue;

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      objLeft = obj.offsetLeft;
      objTop = obj.offsetTop;
      objParent = obj.offsetParent;

      while( objParent.tagName.toUpperCase() != "BODY" )
      {
        objLeft += objParent.offsetLeft;
        objTop += objParent.offsetTop;
        objParent = objParent.offsetParent;
      }

      objHeight = obj.offsetHeight;
      objWidth = obj.offsetWidth;

      obj.style.display = "none";
    }
  }
}

/**
 * Contournement du bug d'IE avec les select
 * Réaffiche des élements précédements cachés
 *
 * @param element le type d'élement a cacher
 */
function showElement(element)
{
  if(browser.isIE)
  {
    for( i = 0; i < document.all.tags( element ).length; i++ )
    {
      obj = document.all.tags( element )[i];
      if( !obj || !obj.offsetParent )
        continue;

      obj.style.display = "block";
    }
  }
}

    
// -------------------------------------------
//        Définition du type jsCalendar
// -------------------------------------------

/**
 * Constructeur
 * @param calName le nom du calendrier. Ce doit être un chaine représentant la 
 *          variable dans laquelle le calendrier est stocké.
 * @param callback une fonction booleene qui sera appelée a chaque tentative de
 *          modification de la sélection
 */
function jsCalendar(calName, callback)
{
    jsCalendarInstances[jsCalendarInstances.length] = this;

    this.days = new Array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi') ;
    this.months = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre') ;
    this.monthsDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31) ;
    this.selection = new Array();

    this.name = calName;
        
    
    //aujourd'hui
    objDate = new Date() ;
    this.currentDay = objDate.getDate() ;
    this.currentMonth = objDate.getMonth() ; 
    this.currentYear = objDate.getFullYear();      
    
    //jour affiché
    this.year = this.currentYear ;
    this.month = this.currentMonth ;    
    this.day = this.currentDay;    
    
    this.callback = callback;
    this.isVisible = false ;
    this.hideSelectForIE = false;

        
    // entete du calendrier
    this.calTopOuter = '<center>'
        + '<form name="frmCalendar">'
        + '<table class="jsCalendar-header" cellpadding="1" cellspacing="0" border="0" width="160px">'
        + '<tr>'
        + '<td>'
        + '<table cellpadding="0" cellspacing="0" border="0">' ;
        
    // sélection de mois (+)
    this.calSelectorBarTop = '<tr class="jsCalendar-header">'
        + '<th class="jsCalendar-header" ;" align="left">'
        + '<a class="jsCalendar" href="javascript:void(0);" onClick="' + this.name + '.monthClick(-1) ;"><font class="jsCalendar-header">&lt;&lt;</font></a>'
        + '</th>'
        + '<th colspan="4" class="jsCalendar-header">'

    // sélection de mois (-) et Fermer (x)
    this.calSelectorBarBottom = '</th><th class="jsCalendar-header" align="right">'
        + '<a class="jsCalendar" href="javascript:void(0);" onClick="' + this.name + '.monthClick(1) ;"><font class="jsCalendar-header">&gt;&gt;</font></a>'
        + '</th><th class="jsCalendar-header" align="right">'
        + '<a class="jsCalendar" href="javascript:void(0);" onClick="' + this.name + '.hide() ;"><font class="jsCalendar-header">x</font></a>'
        + '</th>'
        + '</tr>' ;
        
        
    // titres des jours de la semaine
    this.calDayNameBar = '<tr class="jsCalendar-semaine">' ;
    for (var i=0; i < this.days.length; i++)
    {
        this.calDayNameBar += '<th class="jsCalendar-semaine" width="30px">' + this.days[i].substr(0,2) + '</th>' ; 
    }
    this.calDayNameBar += '</tr>' ;
        
        
    // lien du bas vers le jour courant
    this.calBottomOuter = '<tr class="jsCalendar-footer">'
        + '<th colspan="7" class="jsCalendar-footer">'
        + '<a class="jsCalendar" href="javascript: void(0) ;" onClick="' + this.name + '.selectToday() ;">'
        + '<font class="jsCalendar-footer">Aujourd\'hui</font></a>'
        + '</td></tr></table></form></center>' ;
            
    // initialisation du canvas
    this.initCanvass() ;
}


// -------------------------------------------
//        Méthodes publiques
// -------------------------------------------

/**
 * Positionne un flag indiquant au calendrier de cacher
 * les champs de type SELECT et APPLET qui risquent
 * de passer devant le calendrier sous IE.
 */
jsCalendar.prototype.ieSelectBug = function()
{
    this.hideSelectForIE = true;
}    

/**
 * Appelé par le developpeur pour afficher le calendrier
 * @param event l'evenement demandeur de l'affichage
 * @param dir la direction du calendrier (right ou left)
 */
jsCalendar.prototype.show = function(event, dir)
{
    //cache le calendrier s'il est deja visible
    if(this.isVisible == true)
    {
        this.setVisibility(Visibility.Off) ;	 
        return ;
    }
		
    this.setVisibility(Visibility.Off) ;
    if (browser.isIE)
    {
        var event = window.event ;
        if (dir == 'left')
            this.x = event.clientX - 180 ;
        else
            this.x = event.clientX + 22 ;

        this.y = event.clientY - 10 + document.body.scrollTop;
    }
    else if(browser.isNav6)
    {
        if (dir == 'left')
            this.x = event.pageX - 183 ;
        else
            this.x = event.pageX + 10 ;
        
        this.y = event.pageY - 5 ;    
    }
    else if (browser.isNav4)
    {
        if (dir == 'left')
            this.x = event.x - 162 ;
        else
            this.x = event.x + 10 ;

        this.y = event.y - 5 ;    
    }
        
    this.positionCanvass() ;
    if(this.hideSelectForIE && Browser.isIE)
    {
        hideElement('SELECT', document.getElementById(this.name));
        hideElement('APPLET', document.getElementById(this.name));
    }
    this.setVisibility(Visibility.On) ;
    this.writeString(this.buildString()) ;    
}

/**
 * Appelé par le developpeur pour afficher le calendrier
 * @param x
 * @param y
 * @param dir la direction du calendrier (right ou left)
 */
jsCalendar.prototype.showAbsolute = function(x, y, dir)
{
    //cache le calendrier s'il est deja visible
    if(this.isVisible == true)
    {
        this.setVisibility(Visibility.Off) ;	 
        return ;
    }
		
    this.setVisibility(Visibility.Off) ;
    this.x = x;
    this.y = y;
        
    this.positionCanvass() ;
    if(this.hideSelectForIE && Browser.isIE)
    {
        hideElement('SELECT', document.getElementById(this.name));
        hideElement('APPLET', document.getElementById(this.name));
    }
    this.setVisibility(Visibility.On) ;
    this.writeString(this.buildString()) ;    
}

    
/**
 * Cache le calendrier
 */
jsCalendar.prototype.hide = function()
{
    this.popdownMonth(-1);
    this.x = 0 ;
    this.y = 0 ;
    this.setVisibility(Visibility.Off) ;

    if(this.hideSelectForIE && Browser.isIE)
    {
        showElement('SELECT');
        showElement('APPLET');
    }   
}
    

/**
 * Inverse l'etat sélectionné d'un jour.
 * 
 * @param day le jour
 * @param month le mois
 * @param year l'année
 * @return true si le jour devient sélectionné, faux sinon
 */
jsCalendar.prototype.toggleSelection = function(day, month, year)
{
    if(this.isSelected(day, month, year))
    {
        this.removeSelection(day, month, year);
        return false;
    }
    else
    {
        this.addSelection(day, month, year);
        return true;
    }
}

/**
 * Sélectionne une date.
 * Si la date n'est pas déja sélectionnée, le callback est appelé pour
 * voir s'il est permis de sélectionner la date en question
 *
 * @param day le jour
 * @param month le mois
 * @param year l'année
 * @return true si la date devient sélectionnée, false sinon
 */
jsCalendar.prototype.addSelection = function(day, month, year)
{
    if(! this.isSelected(day, month, year))
    {
        if(this.callback(true, day, month, year))
        {
            date = new Array(day, month, year);
            this.selection[this.selection.length] = date;
            return true;
        }      
        return false;
    }
    return true;
}

/**
 * Désélectionne une date.
 * Appelle le callback pour vérifier s'il est permis de déselectionner la date
 *
 * @param day le jour
 * @param month le mois
 * @param year l'année
 * @return true si la date reste sélectionnée, false sinon
 */
jsCalendar.prototype.removeSelection = function(day, month, year)
{
    if(this.isSelected(day, month, year))
    {
        if(this.callback(false, day, month, year))
        {
            removed = false
            for(i=0;i<this.selection.length;i++)
            {
                if(this.selection[i][0] == day && this.selection[i][1] == month && this.selection[i][2] == year)
                    removed = true;
                if(removed)
                    this.selection[i] = this.selection[i + 1];                
            }
            this.selection.length=this.selection.length-1;
            return false;
        }
        return true;
    }
    return false;
}
   
/**
 * Appelé lors d'un clic sur un bouton de changement de mois.
 *
 * @param delta +1 ou -1 selon le bouton cliqué
 */
jsCalendar.prototype.monthClick = function(delta)
{
    if((this.month + delta) < 0)
    {
        this.month = 11 ;
        -- this.year ;
    }
    else if((this.month + delta) >= 12) 
    { 
        this.month = 0 ; 
        ++ this.year ; 
    }
    else
    {
        this.month = this.month + delta ;
    }
        
    this.writeString(this.buildString()) ;
}
   
 

/**
 * Sélectionne le jour courant et place le calendrier de manière a ce que le 
 * mois concerné soit visible.
 */    
jsCalendar.prototype.selectToday = function()
{
    var d = new Date();
    this.day = d.getDate();
    this.month = d.getMonth();
    this.year = d.getFullYear();
    this.addSelection(this.day, this.month, this.year);
    this.writeString(this.buildString()) ;
}

/**
 * Formatte une date au format JJ/MM/AAAA.
 *
 * @param day le jour
 * @param month le mois
 * @param year l'année
 * @return la date formattée
 */
jsCalendar.prototype.formatDate = function(day, month, year)
{
    var myday = (day > 9 ? '' + day : '0' + day);
    var mymonth = (month > 9 ? '' + month : '0' + month);
    return '' + myday + '/' + mymonth + '/' + year;
}

/**
 * Transforme une date au format JJ/MM/AAAA
 * en un tableau a 3 élements contenant le jour, le mois
 * et l'année
 *
 * @param date une date au format JJ/MM/AAAA
 * @return le tableau contenant la date
 */
jsCalendar.prototype.splitDate = function(date)
{
    day = date.substring(0, 2);
    month = date.substring(3, 5)-1 ;
    year = date.substring(6) ;
    return new Array(day, month, year);
}


/**
 * Vérifie si la date passée en parametre est sélectionnée
 *
 * @param d le jour du mois
 * @param m le numero de mois (0-11)
 * @param y l'année
 * @return true si la date est sélectionnée
 */
jsCalendar.prototype.isSelected = function(d, m, y)
{
    var selected = false;
    for(i=0;i<this.selection.length;i++)
    {
        if(this.selection[i][0] == d && this.selection[i][1] == m && this.selection[i][2] == y)
        {
            selected = true;
            break;
        }
    }
    return selected;
}
    

// -------------------------------------------
//        Méthodes privées
// -------------------------------------------
    

/**
 * Compte le nombre de jour d'un mois.
 * Si aucun parametre n'est fourni, le mois compté est celui du calendrier
 * Sinon, les parametres sont utilisés
 * 
 * @param y l'année
 * @param m le mois
 */    
jsCalendar.prototype.daysInMonth = function()
{
    var oride = (this.daysInMonth.arguments.length == 2) ; 
    var year = oride ? this.daysInMonth.arguments[0] : this.year ;
    var month = oride ? this.daysInMonth.arguments[1] : this.month ;
        
    if(month == 1 && this.isLeapYear(year))
        return (29) ;
    else
        return(this.monthsDays[month]) ;          
} 

/**
 * Appelé lors d'un clic sur un jour
 * Inverse la sélection de l'élement concerné
 *
 * @param le jour cliqué
 */
jsCalendar.prototype.dayClick = function(day)
{
    this.toggleSelection(day, this.month, this.year);
    this.writeString(this.buildString()) ;
}

/**
 * Appelé lors d'un clic sur un jour sur le mois précédent
 * Inverse la sélection de l'élement concerné et affiche la page de ce mois
 *
 * @param le jour cliqué
 */
jsCalendar.prototype.dayClickPreviousMonth = function(day)
{    
    if((this.month - 1) < 0) 
    { 
        newm = 11 ; 
        newy = this.year - 1 ; 
    }
    else
    {
        newm = this.month - 1 ;
        newy = this.year;
    }
    
    this.toggleSelection(day, newm, newy);
    this.writeString(this.buildString()) ;
}

/**
 * Appelé lors d'un clic sur un jour sur le mois suivant
 * Inverse la sélection de l'élement concerné et affiche la page de ce mois
 *
 * @param le jour cliqué
 */
jsCalendar.prototype.dayClickNextMonth = function(day)
{    
    if((this.month + 1) >= 12) 
    { 
        newm = 0 ; 
        newy = this.year + 1 ; 
    }
    else
    {
        newm = this.month + 1 ;
        newy = this.year;
    }
    
    this.toggleSelection(day, newm, newy);
    this.writeString(this.buildString()) ;
}
    

/**
 * Mets le canvas en place.
 * Appelé lors de l'initialisation pour créer l'objer DIV
 */
jsCalendar.prototype.initCanvass = function()
{
    if (browser.isNav4) 
        this.canvass = new Layer(200) ;
    else if (browser.isIE || browser.isDOM)
        this.canvass = browser.isDOM ? document.getElementById('jsCalendar-container') : document.all.jsCalendar-container ;
    
    this.setVisibility(Visibility.Off) ;
}


/**
 * Modifie la visibilité du calendrier.
 * Par défaut, inverse la visibilité courante.
 * Si un argument est passé, il doit etre dans l'énumération Visibility (On ou Off)
 */
jsCalendar.prototype.setVisibility = function()
{
    if(browser.isNav4)
    {
        if (this.setVisibility.arguments.length == 0)
        {
            this.canvass.visibility = this.isVisible ? 'show' : 'hide' ;
            this.isVisible = !(this.isVisible)
        }
        else
        {
            this.canvass.visibility = this.setVisibility.arguments[0] ? 'show' : 'hide' ;
            this.isVisible = this.setVisibility.arguments[0] ;
        }
    }
    else if (browser.isIE || browser.isDOM)
    {
        if (this.setVisibility.arguments.length == 0)
        {
            this.canvass.style.visibility = this.isVisible ? 'visible' : 'hidden' ;
            this.isVisible = !(this.isVisible)
        }
        else
        {
            this.canvass.style.visibility = this.setVisibility.arguments[0] ? 'visible' : 'hidden' ;
            this.isVisible = this.setVisibility.arguments[0] ;
        }
    } 
}
    
    
/**
 * Positionne le canvas sur la page
 */
jsCalendar.prototype.positionCanvass = function()
{
    if ( browser.isNav4 ) 
    { 
        this.canvass.left = this.x ;
        this.canvass.top = this.y ;
    }
    else if ( browser.isIE || browser.isDOM )
    {
        this.canvass.style.left = this.x ;
        this.canvass.style.top = this.y ;
    }       
}
    
    
/**
 * Créé la chaine HTML contenant le calendrier
 */
jsCalendar.prototype.buildString = function()
{
    // informations sur le mois courant
    var objDate = new Date( this.year, this.month, 1 ) ;
    var firstDayOfMonth = objDate.getDay() ;
    var lastDayOfMonth = this.daysInMonth() ;
    objDate = null ;
    var i = 0 ;
    var numCols = 0 ;
    var numRows = 0 ;
    var currentDay = 0 ;
    var endPadding = '&nbsp;&nbsp;' ;
               
    // informations sur le mois précédent
    var pM = 0 ;
    var pY = 0 ;
    if((this.month - 1) < 0)
    {
        pM = 11 ;
        pY = this.year - 1 ;
    }
    else
    { 
        pM = this.month-1 ;
        pY = this.year ;
    }
    var daysInPreviousMonth = this.daysInMonth(pY, pM) ;
    var startOfPreviousMonth = daysInPreviousMonth - (firstDayOfMonth-1)

    // informations sur le mois suivant
    var nM = 0 ;
    var nY = 0 ;
    if((this.month + 1) > 11)
    {
        nM = 0 ;
        nY = this.year + 1 ;
    }
    else
    { 
        nM = this.month + 1 ;
        nY = this.year ;
    }
        
    // début de construction du calendrier
    var tmpString = this.calTopOuter + this.calSelectorBarTop ;
        

    tmpString += '<font class="jsCalendar-headerDate"><a class="jsCalendar" href="javascript:void(0);" onclick="'
        + this.name + '.popupMonths(event)"><font class="jsCalendar-headerDate">' 
        + this.months[this.month] + '</font></a>'
        + ' <a class="jsCalendar" href="javascript:void(0);" onclick="' 
        + this.name + '.popupYears(event)"><font class="jsCalendar-headerDate">' 
        + this.year + '</font></a></font>'
        + this.calSelectorBarBottom
        + this.calDayNameBar ;
                
    // le coeur du calendrier
    tmpString += '<TR>' ;
    for(i = 0; i < firstDayOfMonth; i++)
    {
        if(this.isSelected(startOfPreviousMonth, pM, pY))
        {
           tmpString += '<td align="center" class="jsCalendar-jourAutreMoisSelection"> '
                + '<a class="jsCalendar" href="javascript: void(0);" '
                + 'onClick="' + this.name + '.dayClickPreviousMonth(' + startOfPreviousMonth + ') ;"> '
                + '<font class="jsCalendar-jourAutreMoisSelection">' + startOfPreviousMonth++ + '</font></a></td>' ;
        }
        else
        {
            tmpString += '<td align="center" class="jsCalendar-jourAutreMois"> '
                + '<a class="jsCalendar" href="javascript: void(0) ;" onClick="' 
                + this.name + '.dayClickPreviousMonth(' + startOfPreviousMonth
                + ') ;"><font class="jsCalendar-jourAutreMois">' + startOfPreviousMonth++ 
                + '</font></a></td>' ;
        }
        numCols++ ;
    }
       
    for(i = 1; i <= lastDayOfMonth; i++)
    {  
        if(this.isSelected(i,this.month,this.year))
        {
           tmpString += '<td align="center" class="jsCalendar-jourSelection"> '
                + '<a class="jsCalendar" href="javascript:void(0) ;" '
                + 'onClick="' + this.name + '.dayClick(' + i + ') ;">'
                + '<font class="jsCalendar-jourSelection">&nbsp;&nbsp;'  + i + '&nbsp;</font></a></td>' ;
        }
        else
        {
            tmpString += '<td align="center" class="jsCalendar-jour">'
                + ' <a class="jsCalendar" href="javascript: void(0) ;" onClick="' + this.name 
                + '.dayClick(' + i + ') ;"><font class="jsCalendar-jour">&nbsp;&nbsp;' + i 
                + '&nbsp;</font></a></td>' ;
        }
        
        numCols++ ;
        
        // changement de ligne toutes les 7 colonnes
        if (numCols % 7 == 0)
        {
            tmpString += '</TR><TR>' ;
            numRows++ ;
        }
    }
        
    var counterCols = numCols ;
    var j = 1 ;
    for(i = counterCols; i < 42; i++)
    {
        if(this.isSelected(j, nM, nY))
        {
           tmpString += '<td align="center" class="jsCalendar-jourAutreMoisSelection"> '
                + '<a class="jsCalendar" href="javascript: void(0);" '
                + 'onClick="' + this.name + '.dayClickNextMonth(' + j + ') ;"> '
                + '<font class="jsCalendar-jourAutreMoisSelection">' + j++ + '</font></a></td>' ;
        }
        else
        {
            tmpString += '<td align="center" class="jsCalendar-jourAutreMois"> '
                + '<a class="jsCalendar" href="javascript: void(0) ;" onClick="' 
                + this.name + '.dayClickNextMonth(' + j
                + ') ;"><font class="jsCalendar-jourAutreMois">' + j++ 
                + '</font></a></td>' ;
        }
        numCols++ ;
            
        // nouvelle ligne toutes les 7 colonnes
        if (numCols % 7 == 0)
        {
            tmpString += '</TR>' ;
            if(i < 42) tmpString += '<TR>' ;
        }
    }

    tmpString += this.calBottomOuter ;        
    return tmpString ;          
} 
    
    
/**
 * Ecrit la chaine dans le canvas
 * @param s la chaine a ecrire
 */
jsCalendar.prototype.writeString = function(s)
{
    this.popdownYear(-1);
    this.popdownMonth(-1);
    if(browser.isNav4)
    {
        alert("nav4");
        this.canvass.document.open() ;
        this.canvass.document.writeln(s) ;
        this.canvass.document.close() ;
    }
    else if (browser.isIE || browser.isDOM)
        this.canvass.innerHTML = s ;
} 
    

/**
 * Détermine si l'année sélectionnée est bisextile
 * @return true si l'année est bisextile, false sinon
 */
jsCalendar.prototype.isLeapYear = function()
{
    return(this.year % 4 == 0 && (this.year % 100 != 0 || this.year % 400 == 0));
}    

/**
 * Affiche la liste des mois pour sélection
 */
jsCalendar.prototype.popupMonths = function(event) 
{
    sHTML = ""
    for(i=0; i<12; i++) 
    {
        monthName = this.months[i];
        if(i == this.month)
            monthName = "<b>" + monthName + "</b>"
        sHTML += "<tr><td id='m" + i 
                + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' "
                + "onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' "
                + "onclick='" + this.name + ".popdownMonth(" + i + ");event.cancelBubble=true;'>&nbsp;" 
                + monthName + "&nbsp;</td></tr>"
    }

    document.getElementById("jsCalendar-popup").innerHTML = '<table width="70" '
        + 'style="font-family:arial; font-size:11px; border-width:1; border-style:solid; '
        + 'border-color:#a0a0a0;"bgcolor=#FFFFDD cellspacing=0 ' +
        + '>' + sHTML + '</table>'
    
    popup = null;
    if(browser.isDOM)
        popup = document.getElementById("jsCalendar-popup").style;
    else
        popup = document.jgetElementById("jsCalendar-popup");

    if (browser.isNav6)
    {
        popup.left = event.pageX;
        popup.top = event.pageY;
        popup.visibility = "visible";    
    }
    else
    {
        popup.left = event.x;
        popup.top = event.y + document.body.scrollTop;
        popup.visibility = "visible";
    }
    event.cancelBubble = true;
}

/**
 * Enleve la liste des mois et mets le calendrier a jour
 *
 * @param month le mois sélectionné
 */
jsCalendar.prototype.popdownMonth = function(month)	
{
    if(browser.isDOM)
        document.getElementById("jsCalendar-popup").style.visibility = "hidden";
    else
        document.getElementById("jsCalendar-popup").visibility = "hidden";

    if(month >= 0)
    {
        this.month = month;
        this.writeString(this.buildString());
    }    
}

/**
 * Affiche la liste des années pour sélection
 */
jsCalendar.prototype.popupYears = function(event) 
{
    sHTML = ""    
    for(i=this.year-5; i<this.year+5; i++) 
    {
        year = i
        if(i == this.year)
            year = "<b>" + year + "</b>"
        sHTML += "<tr><td id='m" + i 
                + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' "
                + "onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' "
                + "onclick='" + this.name + ".popdownYear(" + i + ");event.cancelBubble=true;'>&nbsp;" 
                + year + "&nbsp;</td></tr>"
    }

    document.getElementById("jsCalendar-popup").innerHTML = '<table width="70" '
        + 'style="font-family:arial; font-size:11px; border-width:1; border-style:solid; '
        + 'border-color:#a0a0a0;"bgcolor=#FFFFDD cellspacing=0 ' +
        + '>' + sHTML + '</table>'
    
    popup = null;
    if(browser.isDOM)
        popup = document.getElementById("jsCalendar-popup").style;
    else
        popup = document.getElementById("jsCalendar-popup");

    if (browser.isNav6)
    {
        popup.left = event.pageX;
        popup.top = event.pageY;
        popup.visibility = "visible";    
    }
    else
    {
        popup.left = event.x;
        popup.top = event.y + document.body.scrollTop;
        popup.visibility = "visible";
    }
    event.cancelBubble = true;
}

/**
 * Enleve la liste des années et mets le calendrier a jour
 *
 * @param year l'année sélectionnée
 */
jsCalendar.prototype.popdownYear = function(year)	
{
    if(browser.isDOM)
        document.getElementById("jsCalendar-popup").style.visibility = "hidden";
    else
        document.getElementById("jsCalendar-popup").visibility = "hidden";

    if(year >= 0)
    {
        this.year = year;
        this.writeString(this.buildString());
    }    
}

// -------------------------------------------
//        Divers
// -------------------------------------------

/**
 * Appelée lors d'un clic sur le document
 * Utile pour cacher le calendrier lorsqu'il devient inutile ou génant.
 *
 * @param e l'evenement
 */    
function handleDocumentClick(e)
{
    for(i=0;i<jsCalendarInstances.length;i++)
    {
        cal = jsCalendarInstances[i];

        if (browser.isIE) 
            e = window.event;

        if (browser.isNav6)
        {
            var bTest = (e.pageX > parseInt(cal.canvass.style.left) && e.pageX <  (parseInt(cal.canvass.style.left) + 162) && e.pageY < (parseInt(cal.canvass.style.top)+163) && e.pageY > parseInt(cal.canvass.style.top));
            if ((e.target.name != 'imgCalendar' && e.target.name != 'calSelMonth') && !(bTest))
                cal.hide() ; 
        }
	
        if (browser.isIE)
        {
            var bTest = (e.x > parseInt(cal.canvass.style.left) && e.x <  (parseInt(cal.canvass.style.left) + 160) && e.y < (parseInt(cal.canvass.style.top)+141) && e.y > parseInt(cal.canvass.style.top));
            if ((e.srcElement.name != 'imgCalendar' && e.srcElement.name != 'calSelMonth') && !(bTest))
                cal.hide(); 
        }
                    
        if (browser.isNav4) 
        cal.hide();           
    }
}

// mise en place du handler de clic
window.document.onclick = handleDocumentClick;

