function query_browser()
{
  var b = navigator.appName;
  var v = parseInt(navigator.appVersion);
  this.netscape = 0;
  this.gecko = 0;
  this.ns = 0;
  this.ie = 0;
  if (b == "Netscape" && v >= 4)
  {
    this.netscape = 1;
    if (v == 5)
      this.gecko = 1;
    if (v == 4)
      this.ns = 1;
  }
  if (b == "Microsoft Internet Explorer" && v >= 4)
    this.ie = 1;
}
agent = new query_browser();
var objects = new Array();
function dom_object(ob)
{
  this.css = ob;
  this.hide = hide_object;
  this.show = show_object;
  this.query_zindex = query_object_zindex;
  this.set_zindex = set_object_zindex;
  this.query_left = query_object_left;
  this.query_top = query_object_top;
  this.query_height = query_object_height;
  this.query_width = query_object_width;
  this.set_height = set_object_height;
  this.set_width = set_object_width;
  this.move = move_object;
  this.set_html = dom_set_object_html;
  this.set_bgcolor = set_object_bgcolor;
}
function ie_object(ob)
{
  this.css = ob;
  this.hide = hide_object;
  this.show = show_object;
  this.query_zindex = query_object_zindex;
  this.set_zindex = set_object_zindex;
  this.query_left = query_object_left;
  this.query_top = query_object_top;
  this.query_height = ie_query_object_height;
  this.query_width = ie_query_object_width;
  this.set_height = ie_set_object_height;
  this.set_width = ie_set_object_width;
  this.move = move_object;
  this.set_html = dom_set_object_html;
  this.set_bgcolor = set_object_bgcolor;
}
function ns_object(ob)
{
  this.css = ob;
  this.hide = ns_hide_object;
  this.show = ns_show_object;
  this.query_zindex = ns_query_object_zindex;
  this.set_zindex = ns_set_object_zindex;
  this.query_left = ns_query_object_left;
  this.query_top = ns_query_object_top;
  this.query_height = ns_query_object_height;
  this.query_width = ns_query_object_width;
  this.set_height = ns_set_object_height;
  this.set_width = ns_set_object_width;
  this.move = ns_move_object;
  this.set_html = ns_set_object_html;
  this.set_bgcolor = ns_set_object_bgcolor;
}
function create_ie_objects()
{
  objects = new Array();
  foo = document.all.tags("DIV");
  for (var nr = 0; nr < foo.length; nr++)
    if (foo[nr].id != "")
      objects[foo[nr].id] = new ie_object(foo[nr]);
}
function create_navigator_objects(layer_arr)
{
  for (var nr = 0; nr < layer_arr.layers.length; nr++)
    if (layer_arr.layers[nr].name != "")
    {
      objects[layer_arr.layers[nr].name] = new ns_object(layer_arr.layers[nr]);
      if (layer_arr.layers[nr].layers != null && layer_arr.layers[nr].layers.length > 0)
        create_navigator_objects(layer_arr.layers[nr]);
    }
}
function create_dom_objects()
{
  foo = document.getElementsByTagName("DIV");
  objects = new Array();
  for (var nr = 0; nr < foo.length; nr++)
    if (foo[nr].id != "")
      objects[foo[nr].id] = new dom_object(foo[nr]);
}
function create_objects()
{
  if (agent.ie)
  {
    create_ie_objects();
    return;
  }
  if (agent.ns)
  {
    objects = new Array();
    create_navigator_objects(document);
    return;
  }
  if (agent.gecko)
  {
    create_dom_objects();
    return;
  }
  alert("unsupported browser.");
}
var calX = 80;
var calY = 220;
var CurrentMonth = 0;
var dropYear = null;
var dropMonth = null;
var dropYearMonth = null;
var dropDay = null;
var dropYearMonthNext = null;
var dropDayNext = null;
var created_objects = false;
function create_objects_cal()
{
  if (!created_objects)
  {
    create_objects();
    created_objects = true;
  }
}
function draw_calendar(month)
{
  var table_top;
  var print_string;
  var tmpHtml = "";

  table_top = '<table cellpadding="0" cellspacing="0" border="0" class="calMain"><tr>\n';

  if (month > 0)
    tmpHtml = '<a href="javascript:move_month(-1);" class="calNextPrev">&lt;&lt;</a>';
  else
    tmpHtml = '&nbsp;';

  table_top += '<td class="calNextPrev">' + tmpHtml + '</td>\n';

  table_top += '<td colspan="5" class="calTextTitle">' + months[month] + '</td>\n';

  if (month < (monthMatrix.length-1))
    tmpHtml = '<a href="javascript:move_month(1);" class="calNextPrev">&gt;&gt;</a>';
  else
    tmpHtml = '&nbsp;';

  table_top += '<td class="calNextPrev">' + tmpHtml + '</td>\n';

  table_top += '</tr>\n';
  table_top += '<tr><td colspan="7" class="calSeparator"></td></tr>\n';
  table_top += '<tr>\n';
  for (dh=0;dh<dayHeaders.length;dh++)
    table_top += '<td class="calDaysChar">'+dayHeaders[dh]+'</td>';
  table_top += '</tr>\n';
  table_top += '<tr><td colspan="7" class="calSeparator"></td></tr>\n';

  print_string = '<tr>';

  thisMonth = monthMatrix[month];
  for (rw=0;rw<42;rw++)
  {
    if (rw!=0 && rw!=(thisMonth.length-1) && (rw%7==0))
      print_string += "</tr>\n<tr>";

    if (thisMonth[rw]!=0)
    {
      var clickDate = (monthDates[month]*100 + thisMonth[rw]);
      if (thisMonth[rw]>200)
        print_string += '<td class="calDayCur"><a class="calDayCur" href="javascript:handle_click('
                     + (clickDate-200) + ');">' + thisMonth[rw]%200 + '</a></td>';
      else if (thisMonth[rw]>100)
        print_string += '<td class="calDay">' + thisMonth[rw]%100 + '</td>';
      else
        print_string += '<td class="calDay"><a class="calDay" href="javascript:handle_click('
                     + clickDate + ');">' + thisMonth[rw] + '</a></td>';
    }
    else
      print_string += '<td class="calDay">&nbsp;</td>';
  }
  print_string += '</tr>\n';
  print_string += '<tr><td colspan="7" class="calBottom"><a class="calClose" href="javascript:hide_calendar();">close</a></td></tr>\n';
  print_string += '</table>\n';

  create_objects_cal();

  objects['startCalendar'].move(calX, calY);
  objects['startCalendar'].set_zindex(1);
  objects['startCalendar'].set_html(table_top + print_string);
  objects['startCalendar'].show();
}
function move_month(dir)
{
  if (dir==1) draw_calendar(++varCurrentMonth);
  else draw_calendar(--varCurrentMonth);
}
function handle_click(isoIn)
{
  isoIn = "" + isoIn;
  if (dropYear!=null) set_drop(dropYear, isoIn.substring(0,4) );
  if (dropMonth!=null) set_drop(dropMonth, isoIn.substring(4,6) );
  if (dropDay!=null) { dropDay.value = parseInt(isoIn.substring(6,8),10); }
  if (dropYearMonth!=null) set_drop(dropYearMonth, isoIn.substring(0,6) );
  if ( (dropYearMonthNext!=null) && (dropDayNext!=null) )
    handleSyncDates();
  hide_calendar();
}
function handleSyncDates()
{
  if (dropYearMonth[dropYearMonth.selectedIndex].value >
      dropYearMonthNext[dropYearMonthNext.selectedIndex].value)
  {
    set_drop(dropYearMonthNext, dropYearMonth[dropYearMonth.selectedIndex].value );
    dropDayNext.value = dropDay.value;
    set_drop_next_day();
    return;
  }
  if (dropYearMonth[dropYearMonth.selectedIndex].value ==
      dropYearMonthNext[dropYearMonthNext.selectedIndex].value)
  {
    var dd = dropDay.value;
    var ddN = dropDayNext.value;
    if (dd.length<2) { dd = '0' + dd; }
    if (ddN.length<2) { ddN = '0' + ddN; }
    if (dd > ddN)
    {
      dropDayNext.value = dropDay.value;
      set_drop_next_day();
    }
  }
}
function set_drop_next_day()
{
  var day = parseInt(dropDayNext.value);
  for(var i=0; i<monthDates.length; i++)
    if( monthDates[i] == dropYearMonthNext.value )
    {
      var mday = monthMatrix[i];
      var max = 0;
      for(var j=0; j<mday.length; j++)
        if(mday[j]>0 && mday[j]<32)
          max = mday[j];
      day = day + 1;
      if( day<max )
        dropDayNext.value = day;
      else if( i<monthDates.length-1 )
      {
        dropYearMonthNext.value = monthDates[i+1];
        dropDayNext.value = 1;
      }
      return;
    }
}

function set_drop(o,val)
{
  for (i=0;i<o.length;i++)
    if (o[i].value==val)
      o.selectedIndex = i;
}

function hide_calendar()
{
  dropYear = null;
  dropMonth = null;
  dropYearMonth = null;
  dropDay = null;
  dropYearMonthNext = null;
  dropDayNext = null;
  create_objects_cal();
  objects['startCalendar'].hide();
}
function open_cal(dropYearMonthObj, dropDayObj)
{
  dropYearMonth = dropYearMonthObj;
  dropDay = dropDayObj;
  dropYearMonthNext = null;
  dropDayNext = null;
  for (i=0;i<monthDates.length;i++)
    if (dropYearMonth[dropYearMonth.selectedIndex].value==monthDates[i])
      varCurrentMonth = i;
  draw_calendar(varCurrentMonth);
}
function open_cal(dropYearMonthObj, dropDayObj, dropYearMonthNextObj, dropDayNextObj)
{
  dropYearMonth = dropYearMonthObj;
  dropDay = dropDayObj;
  dropYearMonthNext = dropYearMonthNextObj;
  dropDayNext = dropDayNextObj;
  for (i=0;i<monthDates.length;i++)
    if (dropYearMonth[dropYearMonth.selectedIndex].value==monthDates[i])
      varCurrentMonth = i;
  draw_calendar(varCurrentMonth);
}
function ns_query_object_zindex()
{
  return this.css.zIndex;
}
function ns_set_object_zindex(arg)
{
  return this.css.zIndex = arg;
}
function query_object_zindex()
{
  return this.css.style.zIndex;
}
function set_object_zindex(arg)
{
  return this.css.style.zIndex = arg;
}
function ns_hide_object()
{
  this.css.visibility = "hide";
}
function ns_show_object()
{
  this.css.visibility = "show";
}
function hide_object()
{
  this.css.style.visibility = "hidden";
}
function show_object()
{
  this.css.style.visibility = "visible";
}
function ns_set_object_html(arg)
{
  this.css.document.write(arg);
  this.css.document.close();
}
function ns_set_object_bgcolor(arg)
{
  this.css.bgColor = arg;
}
function dom_set_object_html(arg)
{
  this.css.innerHTML = arg;
}
function ie_set_object_html(arg)
{
  this.css.innerHTML = arg;
}
function set_object_bgcolor(arg)
{
  this.css.style.background = arg;
}
function query_object_left()
{
  var nr;
  nr = parseInt(this.css.style.left, 10);
  return nr;
}
function query_object_top()
{
  var nr;
  nr = parseInt(this.css.style.top, 10);
  return nr;
}
function query_object_height()
{
  var nr;
  nr = parseInt(this.css.style.height, 10);
  return nr;
}
function query_object_width()
{
  var nr;
  nr = parseInt(this.css.style.width, 10);
  return nr;
}
function set_object_height(arg)
{
  this.css.style.height= arg + "px";
}
function set_object_width(arg)
{
  this.css.style.width = arg + "px";
}
function ns_query_object_left()
{
  this.css.style.left;
}
function ns_query_object_top()
{
  this.css.style.top;
}
function ns_query_object_height()
{
  return this.css.clip.height;
}
function ns_query_object_width()
{
  return this.css.clip.width;
}
function ns_set_object_height(arg)
{
  this.css.clip.height = arg;
}
function ns_set_object_width(arg)
{
  this.css.clip.width = arg;
}
function ie_query_object_height()
{
  return this.css.clientWidth;
}
function ie_query_object_width()
{
  return this.css.clientHeight;
}
function ie_set_object_height(arg)
{
  //this.css.clientHeight = arg + "px";
}
function ie_set_object_width(arg)
{
  //this.css.clientWidth = arg + "px";
}
function ns_move_object(x, y)
{
  this.css.moveTo(x, y);
}
function move_object(x, y)
{
  this.css.style.left = x+"px";
  this.css.style.top = y+"px";
}
function findPos(divName)
{
  if(bw.ns4)
  {
    x = document.layers.layerPoint.pageX;
    y = document.layers.layerPoint.pageY;
  }
  else
  {
    x=0; y=0;
    var el,temp;
    el = bw.ie4 ? document.all[divName] : document.getElementById(divName);
    if(el && el.offsetParent)
    {
      temp = el;
      while(temp.offsetParent)
      {
        temp=temp.offsetParent;
        x+=temp.offsetLeft;
        y+=temp.offsetTop;
      }
    }
    x+=el.offsetLeft;
    y+=el.offsetTop;
  }
  return [x,y];
}
function cm_bwcheck()
{
  this.ver = navigator.appVersion;
  this.agent = navigator.userAgent.toLowerCase();
  this.dom = document.getElementById?1:0;
  this.op5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera ;
  this.op6 = (this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera;
  this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6);
  this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);
  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6);
  this.ie4 = (this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6);
  this.ie = (this.ie4 || this.ie5 || this.ie6);
  this.mac = (this.agent.indexOf("mac")>-1);
  this.ns6 = (this.agent.indexOf("gecko")>-1 || window.sidebar);
  this.ns4 = (!this.dom && document.layers)?1:0;
  this.bw = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6);
  this.usedom = this.ns6;
  this.reuse = this.ie||this.usedom;
  this.px = this.dom&&!this.op5?"px":"";
  return this;
}
var bw=new cm_bwcheck();