// $Id: dscalendar.js,v 1.30.46.1 2009/02/12 14:55:52 mb Exp $

var widthNE   = 205;
var heightNE  = 130;

var widthIE   = 200;
var heightIE  = 130;
var deplIE    = 15;

function Browser()
{
  // Browser check.
  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.isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false ;
  }
}
var browser = new Browser();
var gCalendar ;
// constructor
function gfnCalInitialize()
{
  new DSCalendar(new Date()) ;
}
    
// Instantiate the calendar

 
if(browser.isIE4) // si IE4 le calendrier est un layer, si NE le calendrier s'affiche dans une fenetre
{
  document.writeln('<style>');
  document.writeln('.calContainer {');
  document.writeln('position : absolute;');
  document.writeln('width : 150 ;');
  document.writeln('height : 150 ;');
  document.writeln('z-index : 150 ;');
  document.writeln('visibility : hidden;');
  document.writeln('overflow-x : hidden;');
  document.writeln('overflow-y : hidden;');
  document.writeln('margin     : 0 0 0 0;');
  document.writeln('background-color : transparent;');
  document.writeln('}');
  document.writeln('</style>')
  document.writeln('<iframe id="frmCalendar" name="frameCalendar" class="calContainer" align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no"></iframe>');
}

function DSCalendar()
{
  this.widthS = 0;
  gCalendar = this ;
  this.MonthIndex=0;
  this.days = new Array('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samdedi','Dimanche') ;
  this.months = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Aout','Septembre','Octobre','Novembre','Decembre') ;
  this.monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31) ;
  this.windowWidth = document.body.clientWidth;
  this.scrollX     = document.body.scrollLeft;
  // Populate the current Day|Month|Year properties
  var objDate = new Date() ;
  this.currentDay = objDate.getDate() ;
  this.currentMonth = objDate.getMonth() ;
  var curYear = objDate.getYear() ;
  this.currentYear = (curYear < 1000) ? curYear + 1900 : curYear ;
  this.year = this.currentYear ;
  this.month = this.currentMonth ;
  this.isVisible = false ;
  // Pre-build the top shell
  this.calTopOuter = '<center>'
  + '<form name="fCalendar">'
  + '<table class="calTable">'
  + '<tr>'
  + '<td>'
  + '<table cellpadding="0" cellspacing="0" border="0">' ;
  // Pre-build the selector bar
  this.calSelectorBarTop = '';
  this.calSelectorBarBottom = '';

  // Pre-build the day names bar
  this.calDayNameBar = '<tr class="calHeadingBg">' ;
  for (var i=0; i < this.days.length; i++)
  {
    this.calDayNameBar += '<th class="calHeadingFont" width="30px">';
    this.calDayNameBar += this.days[i].substr(0,2) + '</th>' ;
  }
  this.calDayNameBar += '</tr>' ;
  // Pre-build the bottom shell
  this.calBottomOuter = '<tr class="calBottomBg" >'
  + '<th class="calBottomFont" colspan="7">'
  + '<a href="javascript: void(0) ;" onClick="';
  if(! browser.isIE4 )
  {
    this.calBottomOuter += 'window.opener.';
  }
  else
  {
    this.calBottomOuter += 'window.parent.';
  }
  this.calBottomOuter += 'gCalendar.MoveToCurrent() ;" class="calBottomFont">Date du jour</a>';
  this.calBottomOuter += '</th></tr></table></td></tr></table></form></center>' ;
  // Create the canvass that we will be displaying the calendar on
  this.initCanvass() ;
}
/*
Show is called when a user requests a calendar.  The show method
is passed 4 arguments; the event, the field day, the field month
and and optional dir value of 'right' or left'.  The default for the
fourth argument is 'right'
*/
DSCalendar.prototype.Show = function(event, dayfield, mthfield, form,dir, uri, dAff, css)
{
  //alert('dscalendar, css: ' + css)
  this.form = form;
  this.uri = uri;
  this.daff = dAff;
  this.windowWidth = document.body.clientWidth;
  this.scrollX = document.body.scrollLeft;
  if(this.isVisible == true)
  {
    this.setVisibility(false) ;
    return false;
  }
  this.setVisibility(false) ;
  if (browser.isIE4)
  {
    var event = window.event ;
    //Set the x pos of the calendar object
    this.x = event.clientX  + this.scrollX ;
    //Set the y pos of the calendar object
    this.y = event.clientY - 10 ;
  }
  else if(browser.isNav6)
  {
    this.x = event.pageX + 10 - this.scrollX;
    this.y = event.pageY - 5 ;
  }
  this.targetday = dayfield ;
  this.targetmth = mthfield ;
  this.currentDay = this.targetday.options[this.targetday.selectedIndex].value;
  mnt = this.targetmth.options[this.targetmth.selectedIndex].value;
  /* mnt est dans le format mmyyyy */
  if(mnt.length == 6)
  {
    tx = mnt.substring(0,2);
    mnt = tx;
  }
  var cDate = new Date();
  if(mnt <= 12)
  {
    this.month = mnt-1;
    this.currentMonth = mnt-1;
    this.currentYear = (cDate.getYear() < 1000) ? cDate.getYear()  + 1900 : cDate.getYear()  ;
    this.year = this.currentYear ;
  }
  else
  {
    this.month = mnt-13;
    this.currentMonth = mnt-13;
    this.currentYear = (cDate.getYear() < 1000) ? cDate.getYear()  + 1901 : cDate.getYear() + 1 ;
    this.year = this.currentYear ;
  }
  this.positionCanvass() ;
  this.setVisibility(true) ;
  this.css = css;
  this.writeString(this.buildString()) ;
  return false;
}
/*
Invoked by the user explicitly closing the calendar
*/
DSCalendar.prototype.Hide = function()
{
  this.x = 0 ;
  this.y = 0 ;
  if(! browser.isIE4 )
  {
    if(this.canvass != null)
    {
      if(!this.canvass.closed)
      {
        this.canvass.close();
      }
      this.canvass = null;
    }
  }
  this.setVisibility(false) ;
}
/*
Invoked by the user explicitly clicking a
day on the calendar face
*/
DSCalendar.prototype.DayClick = function(day)
{
  var sel = -1;
  this.targetday.selectedIndex = day-1;
  var cDate = new Date() ;
  var cYear = (cDate.getYear() < 1000) ? cDate.getYear() + 1900 : cDate.getYear() ;
  
  /* bug 19802 - modif. séléction combo pour les mois */
  /* if(this.year == cYear)
  {
    this.targetmth.selectedIndex = this.month - cDate.getMonth();
  }
  else
  {
    this.targetmth.selectedIndex = (12 - cDate.getMonth()) + this.month;
  }*/
  var tx = '' ;
  if(this.month+1 < 10)
  {
    tx = '0'+(this.month+1) + this.year;
  }
  else
  {
    tx = ''+(this.month+1) + this.year;
  }

  for(i=0;i<this.targetmth.options.length;i++)
  {
    if(this.targetmth.options[i].value == tx)
    {
      sel = i;
      break;
    }
  }

  if(sel == -1)
  {
    sel = 0;
  }
  this.targetmth.selectedIndex = sel;

  selectDay(this.daff,'MTH',this.targetday,this.targetmth,cYear,tx,this.targetday.value,this.form);

  this.setVisibility(false) ;
}
/*
Invoked by the user explicitly toggling the
Month by -1 or +1
*/
DSCalendar.prototype.MonthClick = function(n)
{
  var t = new Date();
  var tmpM = this.month + n;
  var tmpY = this.year;
  //var c = new Date(this.year, this.month, this.day);
  if(tmpM < 0)
  {
    tmpM = 11 ;
    -- tmpY ;
  }
  else if(tmpM >= 12)
  {
    tmpM = 0 ;
    ++ tmpY ;
  }
  var c = new Date(tmpY, tmpM, t.getDate());
  if((c.getYear()>t.getYear())||
    ((c.getYear()==t.getYear())&&(c.getMonth()>=t.getMonth())))
  {
    this.year = tmpY;
    this.month = tmpM;
  }
  else
  {
    return;
  }
  this.writeString(this.buildString()) ;
}
/*
Invoked by the user explicitly changing the
text in the year selector
*/
DSCalendar.prototype.YearChange = function(sel)
{
  this.year = sel.options[sel.selectedIndex].value ;
  var now = new Date();
  tmpY = (now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear() ;
  var obj = new Date(this.year, this.month, this.day);
  if(this.year<tmpY || ((this.year==tmpY) && (this.month < now.getMonth())))
  {
    this.year = tmpY;
    this.month = now.getMonth();
  }
  if(this.year>(tmpY+1) || ((this.year==(tmpY+1)) && (this.month > now.getMonth())))
  {
    this.year = (tmpY+1);
    this.month = now.getMonth();
  }  
  this.writeString(this.buildString()) ;
}
/*
Invoked by the user explicitly changing the
month dd selector
*/
DSCalendar.prototype.MonthOnChange = function(sel)
{
  var temp = sel.selectedIndex;
  var t = new Date();
  temp += this.MonthIndex;
  if(this.day == null)
  {
    this.day = t.getDay();
  }
  var p = new Date(this.year, temp, this.day);
  if((p.getYear() > t.getYear())
  || ((p.getYear() == t.getYear())&&(p.getMonth()>=t.getMonth())))
  {
    this.month = temp;
    this.writeString(this.buildString()) ;
  }
}
// Moves the Calendar to the current Month/Year
DSCalendar.prototype.MoveToCurrent = function()
{
  var objDate = new Date() ;
  this.month = objDate.getMonth() ;
  var curYear = objDate.getYear() ;
  this.year = (curYear < 1000) ? curYear + 1900 : curYear ;
  this.writeString(this.buildString()) ;
}

/*  **********************************************
Private methods
**********************************************/
// Set up the canvass
// Called on initialization of the Class to create the acutal DIV|LAYER Object
DSCalendar.prototype.initCanvass = function()
{
  if (browser.isIE4)
  {
    this.canvass = document.getElementById('frmCalendar'); 
  }
  this.setVisibility(false) ;
}
// overrideable - optional to pass in a Visibility enum
// signatureA =  setVisibility()      // defaults to opposite of current values
// signatureB =  setVisibility(true|false])
DSCalendar.prototype.setVisibility = function()
{
  if(browser.isNav4 || browser.isNav6)
  {
    var param = 'top='+this.y+',left='+this.x+',height='+heightNE+',width='+widthNE;
    param += ',fullscreen=0,channelmode=0,directories=0,resizable=0,titlebar=0,menubar=0,location=0,scrollbars=0,status=0';

    if (this.setVisibility.arguments.length == 0)
    {
      if(this.canvass == null)
      {
        this.canvass = window.open("","my_new_window",param);
      }
      else
      {
        this.canvass.close();
        this.canvass = null;
      }
    }
    else
    {
      if(this.setVisibility.arguments[0])
      {
        this.canvass = window.open("","my_new_window",param);
      }
      else
      {
        if(this.canvass != null && (!this.canvass.closed))
        {
          this.canvass.close();
        }
        this.canvass = null;
      }
      this.isVisible = this.setVisibility.arguments[0] ;
    }
  }
  else if (browser.isIE4)
  {
    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] ;
    }
  }
}   // setVisibility
// apply Positioning
DSCalendar.prototype.positionCanvass = function()
{
  if ( browser.isIE4 )
  {
    this.canvass.style.left = this.x ;
    this.canvass.style.top  = this.y ;
    var tmp = null;
    //var depl = this.noCols - 5;
    this.canvass.style.height = heightIE;
    this.canvass.style.width = widthIE;
    if(parseInt(this.canvass.style.left) + parseInt(this.canvass.style.width) > this.windowWidth + this.scrollX)
    {
      this.canvass.style.left = parseInt(this.canvass.style.left) 
                                - parseInt(this.canvass.style.width);
      this.x = parseInt(this.canvass.style.left);
    }
    if(parseInt(this.canvass.style.left) < 0)
    {
      this.canvass.style.left = 0;
      this.x = 0;
    }
  }
  else
  {
    if((this.y+heightNE)>screen.height)
    {
      this.y -= heightNE;
    }
    if(this.y < 0)
    {
      this.y = 0;
    }
    if((this.x+widthNE)>(this.windowWidth))
    {
      this.x -= (widthNE+20);
    }
    if(this.x < 0)
    {
      this.x = 0;
    }
    var param =  'top='+this.y+',left='+this.x+',height='+heightNE+',width='+widthNE;
    param += ',fullscreen=0,channelmode=0,directories=0,resizable=0,titlebar=0,menubar=0,location=0,scrollbars=0,status=0';
    this.canvass = window.open("","my_new_window",param);
  }
}   // positionCanvass
// builds/accumulates the string
DSCalendar.prototype.buildString = function()
{
  // Get the first and last Day numbers of the month being fetched
  var objDate = new Date( this.year, this.month, 1 ) ;
  var firstDayOfMonth = objDate.getDay()-1;
  if(firstDayOfMonth == -1)
  {
    firstDayOfMonth = 6;
  }
  var lastDayOfMonth = this.daysInMonth() ;
  var yearT = objDate.getYear();
  objDate = null ;
  var i = 0 ;
  var numCols = 0 ;
  var numRows = 0 ;
  var currentDay = 0 ;
  var endPadding = '&nbsp;&nbsp;' ;
  // Work out what month last month was
  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)
  // Start building the calendar body
  this.calSelectorBarBottom = '</th><th class="calSelectorBarFont" align="right">'
  + '<input class="calButton" type="button" name="nextMonth" value=" > " onClick="';
  if( !browser.isIE4 )
  {
    this.calSelectorBarBottom += 'window.opener.';
  }
  else
  {
    this.calSelectorBarBottom += 'window.parent.';
  }

  this.calSelectorBarBottom += 'gCalendar.MonthClick(1) ;"'
  if(this.lastMonth(objDate))
  {
    this.calSelectorBarBottom += ' disabled';
  }
  this.calSelectorBarBottom += '></th></tr>' ;

  this.calSelectorBarTop = '<tr class="calSelectorBarBg">'
  + '<th class="calSelectorBarFont" align="left">'
  + '<input class="calButton" type="button" name="previousMonth" value=" < " onClick="';
  if(! browser.isIE4 )
  {
    this.calSelectorBarTop += 'window.opener.';
  }
  else
  {
    this.calSelectorBarTop += 'window.parent.';
  }
  this.calSelectorBarTop += 'gCalendar.MonthClick(-1) ;"';
  if(this.firstMonth())
  {
    this.calSelectorBarTop += ' disabled';
  }
  this.calSelectorBarTop += '></th>'
  + '<th class="calSelectorBarFont" colspan="5">'
  + '<NOBR><select name="calSelMonth" class="calCombo" onChange="';
  if(! browser.isIE4 )
  {
    this.calSelectorBarTop += 'window.opener.';
  }
  else
  {
    this.calSelectorBarTop += 'window.parent.';
  }
  this.calSelectorBarTop += 'gCalendar.MonthOnChange(this);">';
  var tmp = new Date();
  if(yearT == tmp.getYear())
  {
    this.MonthIndex = tmp.getMonth();
  }
  else
  {
    this.MonthIndex = 0;
  }
  var tmpString = this.calTopOuter + this.calSelectorBarTop ;
  if(yearT < (tmp.getYear()+1))
  {
    for (var i=this.MonthIndex; i < this.months.length; i++)
    {
      tmpString += '<option value="' + i + '"' ;
      if (i == this.month)
      {
        tmpString += ' selected' ;
      }
      tmpString += '>' + this.months[i].substr(0,3) + '</option>' ;
    }
  }
  else
  {
    for (var i=0; i <= tmp.getMonth(); i++)
    {
      tmpString += '<option value="' + i + '"' ;
      if (i == this.month)
      {
        tmpString += ' selected' ;
      }
      tmpString += '>' + this.months[i].substr(0,3) + '</option>' ;
    }
  }
  tmpString += '</select><select name="calTxtYear" class="calCombo" onChange="';
  if(! browser.isIE4 )
  {
    tmpString += 'window.opener.';
  }
  else
  {
    tmpString += 'window.parent.';
  }
  tmpString += 'gCalendar.YearChange(this);">';
  var tmpC = (tmp.getYear() < 1000) ? tmp.getYear() + 1900 : tmp.getYear() ;
  for (var i=0; i <= 1; i++)
  {
    tmpString += '<option value="' + (tmpC+i) + '"' ;
    if ((tmpC+i) == this.year)
    {
      tmpString += ' selected' ;
    }
    tmpString += '>' + (tmpC+i) + '</option>' ;
  }
  tmpString += '</select></NOBR>' + this.calSelectorBarBottom + this.calDayNameBar ; 
  // Body of calendar goes here
  tmpString += '<TR>' ;
  this.noCols = 0;
  for(i = 0; i < firstDayOfMonth; i++)
  {
    tmpString += '<td class="calInvalidDateBg"><font class="calInvalidDateFont">' + startOfPreviousMonth++ + '</font></td>' ;
    numCols++ ;
  }
       
  for(i = 1; i <= lastDayOfMonth; i++)
  {
    if(this.isToday(i,this.month,this.year))
    {
      tmpString += '<td class="calTodayDateBg" id="test"><a href="javascript: void(0) ;" onClick="';
      if(! browser.isIE4 )
      {
        tmpString += 'window.opener.';
      }
      else
      {
        tmpString += 'window.parent.';
      }
      tmpString += 'gCalendar.DayClick(' + i + ') ;" class="calTodayDateFont">&nbsp;&nbsp;' + i + '&nbsp;</a></td>' ;
    }
    else if( this.isValable(i, this.month, this.year))
    {
      tmpString += '<td class="calWeekdayDateBg"><a href="javascript: void(0) ;" onClick="';
      if(! browser.isIE4 )
      {
        tmpString += 'window.opener.';
      }
      else
      {
        tmpString += 'window.parent.';
      }
      tmpString += 'gCalendar.DayClick(' + i + ') ;" class="calWeekdayDateFont">&nbsp;&nbsp;' + i + '&nbsp;</a></td>' ;
    }
    else
    {
      tmpString += '<td class="calInvalidDateBg"><font class="calInvalidDateFont">' + i + '</font></td>' ;
    }
    numCols++ ;
    /* Display new row after each 7 day block.  */
    if (numCols % 7 == 0)
    {
      tmpString += '</TR><TR>' ;
      this.noCols++;
      numRows++ ;
    }
  }
  var counterCols = numCols ;
  var j = 1 ;
  for(i = counterCols; ((i < 42)&&(numCols!=35)); i++)
  {
    // Call the method to create the cell contents
    tmpString += '<td class="calInvalidDateBg"><font class="calInvalidDateFont">' + j++ + '</font></td>' ;
    numCols++ ;
      
    /* Display new row after each 7 day block.  */
    if (numCols % 7 == 0)
    {
      tmpString += '</TR>' ;
      this.noCols ++;
      if(i < 42) tmpString += '<TR>' ;
    }
  }
  // End of BODY
  tmpString += this.calBottomOuter ;
  return tmpString ;    
}   // buildString    
// renders string to canvass
DSCalendar.prototype.writeString = function(s)
{
  if(browser.isNav4 || browser.isNav6)
  {
    this.canvass.document.open();
    if(this.uri === null)
    {
       this.uri = '';
    }
    var toWrite = '<html><head><title>Calendar</title><link rel="stylesheet" href="';
    //toWrite += (this.uri + '/css/dscalendar.css" type="text/css">');
    toWrite += (this.uri + this.css + '" type="text/css">');
    toWrite += '<script type="text/javascript" >function goodbye(){window.opener.gCalendar.Hide();}</script>';
    toWrite += '</head><body onUnLoad="goodbye();">';
    toWrite += s;
    toWrite += '</body></html>';
    //alert('toWrite: ' + toWrite)
    this.canvass.document.writeln(toWrite) ;
    this.canvass.document.close() ;
  }
  else if (browser.isIE4)
  {
    var toWrite = '<html><head><title>Calendar</title><link rel="stylesheet" href="';
    //toWrite += (this.uri + '/css/dscalendar.css" type="text/css">');
    toWrite += (this.uri + this.css + '" type="text/css">');
    toWrite += '</head><body class="calBody">';
    toWrite += s;
    toWrite += '</body></html>';
    var tmp = document.frames["frameCalendar"];
    tmp.document.open();
    tmp.document.write(toWrite);
    tmp.document.close();
    var depl = this.noCols - 5;
    this.canvass.style.height = heightIE + depl*deplIE;
    this.canvass.style.width = widthIE;
  }    
}   // writeString
// overrideable - optional to pass in yy/dd
// signatureA =  daysInMonth()      // defaults to this.year, this.month
// signatureB =  daysInMonth(y,m)
DSCalendar.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.monthDays[month]) ;  
}   // daysInMonth
// used to compare a date to TODAY.  Used to color today.
DSCalendar.prototype.isToday = function(d,m,y)
{
  var now = new Date() ;
  var date = new Date(y,m,d) ;
  if((date.getYear() == now.getYear()) && (date.getMonth() == now.getMonth())&& (date.getDate() == now.getDate()))
  {
    return true;
  }
  else
  {
    return false;
  }
}   // isToday

DSCalendar.prototype.isValable = function(d,m,y)
{
  var now = new Date() ;
  var date = new Date(y,m,d) ;
  if(now.getYear() == date.getYear())
  {
    if(now.getMonth()<date.getMonth())
    {
      return true;
    }
    if(now.getMonth()==date.getMonth())
    {
      if(now.getDate()<=date.getDate())
      {
        return  true;
      }
    }
  }
  if((now.getYear()+1) == date.getYear())
  {
    if(now.getMonth()>date.getMonth())
    {
      return true;
    }
    if(now.getMonth()==date.getMonth())
    {
      if(now.getDate()>date.getDate())
      {
        return  true;
      }
    }
  }
  return false;
}

// helper function
DSCalendar.prototype.isLeapYear = function()
{
  if (this.year % 4 == 0 && (this.year % 100 != 0 || this.year % 400 == 0))
    return(true) ; return(false) ;
}   // isLeapYear

DSCalendar.prototype.firstMonth = function()
{ 
  var p = new Date(this.year, this.month, 1 );
  var n = new Date();
  if(p.getTime() < n.getTime())
  {
    return true;
  }
  return false;
}

DSCalendar.prototype.lastMonth = function()
{ 
  var p = new Date(this.year, this.month, 1 );
  var n = new Date();
  if((p.getYear()== (n.getYear()+1)) && (p.getMonth() == n.getMonth()))
  {
    return true;
  }
  return false;
}
    
function handleDocumentClick(e)
{
  if (browser.isIE4) e = window.event;
  if (browser.isNav6)
  {
    //var bTest = (e.pageX > parseInt(gCalendar.canvass.style.left) && e.pageX <  (parseInt(gCalendar.canvass.style.left) + 162) && e.pageY < (parseInt(gCalendar.canvass.style.top)+163) && e.pageY > parseInt(gCalendar.canvass.style.top));
    if ((e.target.name != 'imgCalendar' && e.target.name != 'calSelMonth'))
    {
      if(gCalendar != null)
      {
        gCalendar.Hide() ;
      }
      else if( window.opener!= null)
      {
        if(window.opener.gCalendar != null)
        {
          window.opener.gCalendar.Hide() ;
        }
      }
    }
  }
  if (browser.isIE4)
  {
    // extra test to see if user clicked inside the calendar but not on a valid date, we don't want it to disappear in this case
    var bTest = (e.x > parseInt(gCalendar.canvass.style.left) && e.x <  (parseInt(gCalendar.canvass.style.left) + 160) && e.y < (parseInt(gCalendar.canvass.style.top)+141) && e.y > parseInt(gCalendar.canvass.style.top));
    if ((e.srcElement.name != 'imgCalendar' && e.srcElement.name != 'calSelMonth') && !(bTest))
    {
      gCalendar.Hide() ;
    }
  }
  if (browser.isNav4) gCalendar.Hide();
}
window.document.onclick=handleDocumentClick;
