// Check http://frans.lowter.us/calendar for new versions and changelogs
// Frenzie (http://frans.lowter.us, fl_dejonge@hotmail.com)

// version information
var current_version = '0.7.1 beta';
// start day of week, US = 0, EU = 1
var calStartDOW = 1;
// clockbutton, 0=off, 1=on (top), 2=on (bottom)
var theclock = 0;
// empty is default, to make something else default change to 'red', 'green' or whatever...
var style = 'default';
// language, I've used short three letter names for this
var lang = 'eng';
// more calendars, 0=three calendars, 1=five calendars, 2=one calendar
// JWR - cal_cnt is straight calendar count, 1-5
var cal_more = 0;
var cal_cnt = 3;
// settings, 0=force-off, 1=normal, 2=force-on
// This triggers a little style setting, if you use a stylesheet which doesn't display options
// the setting of 1 won't have an effect. The setting of 2 will force display of settings.
var settings = 1;
// advanced settings, 0=off, 1=on
var adv_set = '0';
// display weeks, 0=off, 1=on
var wk=1;
// ABBREVIATED MONTH NAMES
// months[] is used internally for (among other things) compatibility with 
// javascript Date.parse() methods.  You should only have to change it if 
// your language variable changes (read: never).
var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
// makes sure months have the right length...
var leapdays = new Array(31,29,31, 30,31,30, 31,31,30, 31,30,31); 
var yeardays = new Array(31,28,31, 30,31,30, 31,31,30, 31,30,31); 
// a global date object to speed things up a little, since 
// there are lots of places where we need today's date
var myDate = new Date();
// thisMonth and thisYear are used as static vars for 
// new_calendars() (for persistence between calls, which 
// involves reloading the document
var thisMonth = myDate.getMonth(); 
var thisYear  = myDate.getFullYear(); 
// Now, figure out the arguments the page was loaded with 
var URLargs = getURLArgs(true);
if (URLargs.cal_more) cal_more = URLargs.cal_more;
if (cal_more == 0) cal_cnt = 3;  // JWR - convert cal_more to cal_cnt
if (cal_more == 1) cal_cnt = 5;  
if (cal_more == 2) cal_cnt = 1;
if (URLargs.cal_cnt) cal_cnt = URLargs.cal_cnt;
if (URLargs.lang) lang = URLargs.lang;
if (URLargs.style) style = URLargs.style;
if (URLargs.settings) settings = URLargs.settings;
if (URLargs.adv_set) adv_set = URLargs.adv_set;
if (URLargs.wk) wk = URLargs.wk;
if (URLargs.clock) theclock = parseInt(URLargs.clock);
if (URLargs.year) thisYear = parseInt(URLargs.year);
if (URLargs.month) thisMonth = (parseInt(URLargs.month)%12);
if (URLargs.starton) calStartDOW = (parseInt(URLargs.starton)%7);
// STYLE SHEET SELECTION
// first things first, make sure the page is displayed nice
// if you add something, it's easier to do it alphabetically


if (style != '')
  document.write('<link rel="stylesheet" type="text/css" href="css/'+style+'.css"\/>');
else
  document.write('<link rel="stylesheet" type="text/css" href="css/default.css"\/>');
	
/*
if (style != '')
	document.getElementsByTagName('link')[0].href = 'css/'+style;
*/
// This is moved here for compatability with IE and Moz, which are @%@$#%@#$%!#%
// in their handling of javascript. Viva Opera!
// the css file selection dropdown
document.write('<script type="text/javascript" src="js/css.js"><\/script>');
// the language file selection dropdown
document.write('<script type="text/javascript" src="js/lang.js"><\/script>');
// MOVING HOLIDAYS VARIABLES
// Frenzie mod of BJ mod 04-05-03
// Modification of http://users.chariot.net.au/~gmarts/eastcalc.htm
// (C)opyright GM Arts 1997-1999
// Before we check what the language is we define
// the moving holiday variables
var eYear = 0;
// Easter Sunday
var esdDay = 0;
var esdMonth = 0;
// day after Easter Sunday
var emoDay = 0;
var emoMonth = 0;
// Easter Friday
var efrDay = 0;
var efrMonth = 0;
// Boze Cialo (Corpus Christi)
var bozDay = 0;
var bozMonth = 0;
// Ascencion Day Thursday
var athDay = 0;
var athMonth = 0;
// Whitsunday
var whsDay = 0;
var whsMonth = 0;
// day after Whitsunday
var whmDay = 0;
// Midsummer day
var mssDay = 0;
// All Saints' day
var ahdDay = 0;
var ahdMonth = 0;
// JWR - USA Holidays
// Martin Luther King Day (USA)
var mlkDay = 0;
// President's Day (USA)
var presDay = 0;
// Mother's Day (USA)
var momDay = 0;
// Memorial Day (USA)
var memDay = 0;
// Father's Day (USA)
var popDay = 0;
// Labor Day (USA)
var laborDay = 0;
// Columbus Day (USA)
var colmDay = 0;
// Thanksgiving Day (USA)
var thankDay = 0;
// IE and Moz compability
var close_window = 'Close window';
// LANGUAGE SELECTION
// calls the corresponding language file
if (lang != '')
  document.write('<script type="text/javascript" src="lang/'+lang+'.js"><\/script>');
else
  document.write('<script type="text/javascript" src="lang/eng.js"><\/script>');
// CLOCK scripts
if (theclock != 0) document.write('<script type="text/javascript" src="js/clock.js"><\/script>');
// MOVING HOLIDAY FUNCTIONS
// performs integer division of num/dvsr - eg IntDiv(9,4)=2
function IntDiv (num, dvsr) {
  var negate = false;
  var result = 0;

  if (dvsr == 0)
    return null;
  else {
    if (num * dvsr < 0 )
      negate = true;
    if (num < 0)
      num = -num;
    if (dvsr < 0)
      dvsr = -dvsr;
      result = ((num - (num % dvsr)) / dvsr);
    if (negate)
      return -result;
    else
      return result;
  }
}
// calculates easter for a lot of years
// the author of this script apperently never heard
// about logical variable names
function EasterWestern(eYear) {
  var g = 0;
  var c = 0;
  var h = 0;
  var i = 0;
  var j = 0;
  var p = 0;

  g = eYear % 19;
  c = IntDiv(eYear, 100);
  h = (c - IntDiv(c, 4) - IntDiv(8 * c + 13, 25) + 19 * g + 15) % 30;
  i = h - IntDiv(h, 28) * (1 - IntDiv(h, 28) * IntDiv(29, h + 1) 
      * IntDiv(21 - g, 11));
  j = (eYear + IntDiv(eYear, 4) + i + 2 - c + IntDiv(c, 4)) % 7;
  p = i - j + 28;

  esdDay = p;
  esdMonth = "Apr";
  if (p > 31)
    esdDay = p - 31;
  else
    esdMonth = "Mar";
  /* BJ mod 2003-05-04   Added more days than Easter Sunday */
  // day after Easter Sunday
  emoDay = p+1;
  emoMonth = "Apr";
  if (p > 30)
    emoDay = p - 30;
  else
    emoMonth = "Mar";
  // Easter Friday
  efrDay = p-2;
  efrMonth = "Apr";
  if (p > 33)
    efrDay = p - 33;
  else
    efrMonth = "Mar";
  // Ascension Day Thursday
  athDay = p + 39;
  if (athDay > 92) {
    athDay -= 92;
    athMonth = "Jun";
  }
  else if (athDay > 61) {
    athDay -= 61;
    athMonth = "May";
  }
  else {
    athDay -= 31;
    athMonth = "Apr";
  }
  // Whitsunday
  whsDay = p + 49;
  if (whsDay > 92) {
    whsDay -= 92;
    whsMonth = "Jun";
  }
  else if (whsDay > 61) {
    whsDay -= 61;
    whsMonth = "May";
  }
  else {
    whsDay -= 31;
    whsMonth = "Apr";
  }
  // day after Whitsunday
  whmDay = p + 50;
  if (whmDay > 92) {
    whmDay -= 92;
    whmMonth = "Jun";
  }
  else if (whmDay > 61) {
    whmDay -= 61;
    whmMonth = "May";
  }
  else {
    whmDay -= 31;
    whmMonth = "Apr";
  }
  // Boze Cialo (Corpus Christi)
  bozMonth = whmMonth;
  bozDay = whsDay + 11;
  if (bozDay > 31) {
    bozDay -= 31
    bozMonth = "Jun"
  }
}

var sURL = unescape(window.location.pathname);
function set_refresh(){setTimeout( "refresh()", 60*60*1000 );}
function refresh(){window.location.href = sURL;}

function isLeapYear( year ) {
  // is it leap year ? returns a boolean
  return ( (0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400))));
  // ie, if the year divides by 4, but not by 100 except when it divides by
  // 400, it is leap year
}
function canonicalDate(day, month, year) {
  // return the number of days since the Jan 0 2000 (ie, 1/1/2K returns 1, 31/12/1999 returns 0)
  // for days before Jan 1 2000, returns negative numbers
  var canonDate = 0;
  // if the function had no arguments, use today's date;
  var mday = myDate.getDate();
  var mday = myDate.getDate();
  var mmon = myDate.getMonth();
  var myr  = myDate.getFullYear();
  if( arguments.length > 0 ) mday = arguments[0];
  if( arguments.length > 1 ) mmon = arguments[1];
  if( arguments.length > 2 ) myr  = arguments[2];
  if(myr >= 2000) {
    canonDate += mday;
    while(mmon > 0)   { canonDate += isLeapYear(myr) ? leapdays[mmon]: yeardays[mmon]; mmon--; }
    while(myr > 2000) { canonDate += isLeapYear(myr) ? 366: 365; myr--; }
  }
  else {
    canonDate -= isLeapYear(myr) ? leapdays[mmon] - mday: yeardays[mmon] - mday;
    while(mmon < 11)  { mmon++; canonDate -= isLeapYear(myr) ? leapdays[mmon]: yeardays[mmon]; }
    while(myr < 1999) { myr++; canonDate -= isLeapYear(myr) ? 366: 365; }
  }
  return canonDate;
}
function dateDiff(firstDate, secondDate) {
  // returns the result in days of subtracting firstDate from secondDate. Result is negative if secondDate came before firstDate.
  var days = ( canonicalDate(secondDate.getDate(), secondDate.getMonth(), secondDate.getFullYear()) - canonicalDate(firstDate.getDate(), firstDate.getMonth(), firstDate.getFullYear()));
  return days;
}
function isHoliday(year,mon,mday) {
  // it the date on the list?
  // the format is a little sensitive, you
  // have to make sure that 'mon' is
  // something that Date.parse() can
  // understand
  setVarHolidays(year);
  var dStr = mday + " " + mon;
  
  if( holidays[dStr] || holidays[dStr + " " + year] ) {
    return true;
  }
  return false;
}
function isWeekend( year, mon, mday) {
  var mDate = new Date(mday + " " + mon + " " + year);
  return weekend_format( mDate );
}
function has_desc(year,mon,mday) {
  // is the date on the list
  // make sure the description will be there when clicked on
  var dStr = mday + " " + mon;
  if(holidays[dStr] || holidays[dStr + " " + year]) {
    return true;
  }
  return false;
}
function calculateDay (startDate, alteration) {
  // calculates a date
  newDate = new Date ( (new Date(startDate)).getTime() + (12*3600000)  + ( (24 * 36) * 100000 * alteration) );
  return newDate.getDate()+' '+months[(newDate.getMonth())];
}
function calculateWorkDays( startDate, endDate) {
  // called with 2 Date Objects as arguments.
  // calculates the number of workdays between two dates by adding up the
  // number of days and subtracting weekends and holidays.
  var myEndDate = canonicalDate(endDate.getDate(), endDate.getMonth(), endDate.getFullYear());
  var counter = 0;
  var mDay = startDate.getDate();
  var mMonth = startDate.getMonth();
  var mYear  = startDate.getFullYear();
  while  (canonicalDate(mDay, mMonth, mYear) <= myEndDate) {
    if(! ( isHoliday(mYear,months[mMonth],mDay) || isWeekend(mYear,months[mMonth],mDay)) ) {
      counter++;
    }
    // increment the date
    // are we at the end of a month ?
    var omDay = mDay;
    var omMonth = mMonth;

    var omYear = mYear;
    mDay = isLeapYear(mYear) ?
    ((mDay >= leapdays[mMonth]) ? 1 : mDay+1):
    ((mDay >= yeardays[mMonth]) ? 1 : mDay+1);
    // do we need to increment the month ?
    mMonth = (mDay == 1) ?  (mMonth +1) % 12: mMonth;
    // do we need to increment the year?
    mYear = ( (mDay == 1) && (mMonth == 0)) ? mYear + 1: mYear;
    // startDate = new Date(mDay, mMonth, mYear);
  }
  return counter;
}
function getWeek(year,month,day) {
  // Make sure weeks won't be displayed wrong for US week setting
  if (calStartDOW == 0) {
    day = day + 1;
  }
  month = month + 1;

  // source: http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
  a = Math.floor((14-month) / 12);
  y = year + 4800 - a;
  m = month + 12 * a - 3;
  // source: http://www.tondering.dk/claus/cal/node7.html#SECTION00780000000000000000
  J = day + Math.floor((153 * m + 2) / 5) + 365 * y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) - 32045;
  d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
  L = Math.floor(d4 / 1460);
  d1 = ((d4 - L) % 365) + L;
  week = Math.floor(d1/7) + 1;
  // align with other weeks for week=[1-9]
  if (week<10) week='&nbsp;'+week;
  return week;
}
// here we get the output of the calendar
function writeCalendar(target, myYear, myMonth, sday, eday) {
  // writes a calendar to target  for myMonth myYear.
  // sday and eday are optional values indicating the range of dates
  // to be set in bold.
  // get a new date for the first day of the month the user is looking at
  var calDate = new Date( myYear, myMonth, 1, 0,0,0,0 );
  // how many days are in the month ?
  var mDays = isLeapYear(myYear) ? leapdays[myMonth]: yeardays[myMonth];
  var i = 0;
  // what day of the week does the month start on?
  var wkDay = calDate.getDay();
  var date_class = '';
  // description normally is nothing
  var desc = '';
  var enddesc = '';
  // if the function was called with the sday and eday arguments, then the
  // caller wants a range of dates written in bold
  var useBold = arguments.length >= 5 ? true: false;
  // write the header for the calendar ( month and year )
  target.write('<table border="0" cellpadding="1" cellspacing="0" width="100%">\n');
  // set the class
  target.write('<tr class="head">');
  target.write('<td align="left"><a href="javascript:document.new_cal.previous.click();">&lt;&lt;</a><th colspan="'+((wk == 1)? '6' : '5')+'">'+longmonths[myMonth]+'&nbsp;&nbsp;&nbsp;'+myYear+'</th><td align="right"><a href="javascript:document.new_cal.next.click();">&gt;&gt;</a></td></tr>\n');
  // write the abbreviations for days of the week into the top line of the calendar
  target.write('<tr class="dow">');
  if(wk==1){target.write('<td class="week_head">'+week_ab+'</td>');}
  for(i=0; i< 7; i++) {
    target.write('<td align="center">' + dow[((i+calStartDOW)%7)] + '</td>');
  }
  target.write('</tr>\n');
  // start the first line with blank spaces until we get to the first day of the month
  target.write('<tr class="week">');
  if(wk==1){target.write('<td class="week_number">'+ getWeek(myYear,myMonth,calStartDOW) +'</td>');}
  for(i=0 ; i < ((7 - calStartDOW + wkDay)%7); i++) {
    target.write('<td> \ \ \ </td>');
  }
  // since javascript doesn't do modulus on negative numbers,
  // add 7 to anything that might be negative
  var cmdate = i - ((7 - calStartDOW + wkDay)%7);
  // write the weekdays
  for( i=i; cmdate < mDays ; i++) {
    // what is the date ?
    cmdate++;
		// no description by default
		var desc = '';
		var enddesc = '';
    // if we have reached the end of a week, start another one
    if( (0 == (i%7)) && (i!=0) ){
      target.write('</tr>\n<tr align="center" class="week">');
      if(wk==1){target.write('<td class="week_number">'+ getWeek(myYear,myMonth,cmdate) +'</td>');}
    }
    // if the date is a holiday or weekend, set it in color
    if( (isHoliday(calDate.getFullYear(),months[calDate.getMonth()],cmdate)) || (isWeekend(calDate.getFullYear(),months[calDate.getMonth()],cmdate)) ) {
      date_class = 'class="holiday"';
      // get that description there where it belongs
      if ((has_desc(calDate.getFullYear(),months[calDate.getMonth()],cmdate))) {
        var dStr = cmdate + " " + months[calDate.getMonth()];
				
        if ( (holidays[dStr] != true) && (holidays[dStr] != '') ) {
          var desc = '<a class="desc" onclick="javascript:popup_description(\'' + cmdate + '\',\'' + myMonth + '\',\'' + dStr + '\',\'' + myYear + '\');" title="'+ date_format(cmdate,longmonths[myMonth]) + ' - ' + holidays[dStr] + '">';
          var enddesc = '</a>';
        }
      }
    }
    else {
      var date_class = 'class="day"';
    }
    // set the days off in bold
    if( ( useBold )  && (cmdate >= sday) && (cmdate <= eday)) date_class = 'class="today"';
    target.write('<td ' + date_class + '>' + desc,cmdate,enddesc + '</td>');
  }
  while(0 != (i%7)) {
    target.write("<td>&nbsp;</td>"); i++;
  }
  target.write('</tr>');
  target.write('</table>');
}
function drawCalendar(ourTarget, ourYear, ourMonth, startDay, endDay) {
  // serves as a wrapper for writeCalendar()
  // if you want to do anything special, such as changing the colors,
  // or opening a special window, you can do it here before calling writeCalendar().
  // sday and eday are optional values indicating the range of dates
  // to be set in bold.
  // arguments:
  // ourTarget - document to write to
  // ourYear, ourMonth - integers, typically returned by Date.getMonth() and Date.getDate()
  // startDay, endDay  - optional start and end days for bolding
  var myMonth = myDate.getMonth();
  var myYear  = myDate.getFullYear();
  var target = document;
  // strictly speaking, all the arguments are optional.
  // if you only want this month's calendar, called drawCalendar() with no args.
  if(arguments.length >= 1) target = ourTarget;
  if(arguments.length >= 2) myYear = ourYear;
  if(arguments.length >= 3) myMonth = ourMonth;
  writeCalendar(target, myYear, myMonth, startDay, endDay);
}
// popups the version
function version() {
  alert('Version: ' + current_version);
}
// header and footer used with popupwindows
// to access it use
// <a href="javascript:popup_description(\'' + cmdate + '\',\'' + myMonth + '\',\'' + dStr + '\');">
var head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
'<html><head><title>';
var endhead = '</title><link rel=stylesheet type=text/css href=css/'+style+'.css></head><body id="popup"><p>';
var foot = '</p>[<a href=javascript:window.close()>'+close_window+'</a>]</p><br\/>&nbsp;<br\/>&nbsp;</body></html>';
// popups the description
function popup_description(cmdate,myMonth,dStr,year) {
  if (!holidays[dStr]) dStr = dStr + " " + year;
  var description = window.open('','description','width=300,height=100');
  description.document.write(head + date_format(cmdate,longmonths[myMonth]) + endhead
  + '<b>' + date_format(cmdate,longmonths[myMonth]) + '</b> - ' + holidays[dStr]
  + foot);
}
function getURLArgs(caseBool) {
  // gets the arguments the page was loaded with - that is,
  // everything after the first '?'
  // parameters:
  // caseBool - set to true or positive integer to force lowercase
  // for parameter values
  //
  // values are ALWAYS case sensitive
  var casefree = ( (true == caseBool) || (caseBool >= 1)) ? true: false;
  var args  = new Object();
  var query = location.search.substring(1);
  //  alert(query);
  var pairs = query.split("&");
  for(var i = 0; i< pairs.length; i++) {
    pairs[i]= unescape(pairs[i]);
    var pos=pairs[i].indexOf('=');
    if(-1 == pos) continue;
    var argname;
    if(true != casefree) { argname = pairs[i].substring(0,pos); }
    else { argname = pairs[i].substring(0,pos).toLowerCase(); }
    var value = pairs[i].substring(pos+1);
    args[argname] = value;
  }
  return args;
}
function new_calendars(myear, mmonth) {
//	document.write('<div id="content">');
	
  if (theclock == 1) clock();
  // puts three calendars on the page from which it was called. (last month, this month, next month)
  // Params
  //
  // when called with 2 arguments
  // myear  -  the year for the center calendar
  // mmonth -  the month for the center calendar
  var myMonth = thisMonth;
  var myYear  = thisYear;
  if(arguments.length == 2) myMonth = mmonth; myYear == myear;
  // sMonth and sYear are start month and year for displaying calendars
  // it's surprising how many coders don't use modular arithmetic to do date and time. Javascript doesn't understand negative numbers in
  // positive modulus, so we add 11 instead of subtracting 1.
  // start the calendar half the count back
  var sMonth = (myMonth - IntDiv(cal_cnt,2) + 12) % 12;
  var sYear    = (myMonth < sMonth)? myYear -1: myYear;
  var lastMonth = (myMonth + 11) % 12;
  var lmYear    = (myMonth == 0)? myYear -1: myYear;
  var nextMonth = (myMonth + 1)%12;
  var nmYear    = (myMonth == 11)? myYear + 1: myYear;

  document.write('<div id="calendar">');

  // cal2 is the myMonth calendar
  // more than 5 calendars uses only cal2 and cal4
  var lpStart = (cal_cnt < 6)? (2 - IntDiv(cal_cnt,2)):0;
  for(ii=lpStart; ii < (+lpStart + +cal_cnt); ii++) {
    if (cal_cnt > 5) {
      if (sMonth == myMonth)
        document.write('<div id="cal2" class="m' + (sMonth+1) + '">');
      else
        document.write('<div id="cal4" class="m' + (sMonth+1) + '">');
    }
    else
      switch (ii) {
      case 0: document.write('<div id="cal0" class="m' + (sMonth+1) + '">'); break;
      case 1: document.write('<div id="cal1" class="m' + (sMonth+1) + '">'); break;
      case 2: document.write('<div id="cal2" class="m' + (sMonth+1) + '">'); break;
      case 3: document.write('<div id="cal3" class="m' + (sMonth+1) + '">'); break;
      default: document.write('<div id="cal4" class="m' + (sMonth+1) + '">'); break;
      }

    var isThisMonth = (( sMonth == myDate.getMonth()) && (sYear==myDate.getFullYear()));
    drawCalendar(document, sYear, sMonth, (isThisMonth ? myDate.getDate():0), (isThisMonth ? myDate.getDate():0));
//    isThisMonth = ((myMonth == myDate.getMonth())&& (myYear==myDate.getFullYear()));
    sYear    = (sMonth == 11)? sYear +1: sYear;
    sMonth = (sMonth + 1) % 12;
    document.write('</div>');
  }
// JWR - end of rewrite

  document.write('</div>');

  // write the NEXT and PREVIOUS buttons
  // 
  // note that we create a form and use the document URL as the target,
  // with the METHOD of GET.
  // 
  // if we were writing the calendars into a separate window or frame, we wouldn't need to reload; we could just change the global values
  // for thisYear, thisMonth, and calStartDOW, and refresh that window by calling new_calendars() with that window as target.
  if (theclock == 2) clock();
  // here is determined wether the settings are displayed or not
  switch (settings) {
    case ('2'||2):
      var settings_display = ' style="display: block;"';
      break;
    case ('0'||0):
      var settings_display = ' style="display: none;"';
      break;
    default:
      var settings_display = '';
  }
  var docName = location.pathname;
  document.write('<div id="options"' + settings_display + '>');
  document.write('<form name="new_cal" method="get" action="' + docName + '">');
  document.write('<input type="hidden" name="month" value="' + myMonth + '"\/>'+
  '<input type="hidden" name="year" value="' + myYear + '"\/>'+
  '<input type="hidden" name="settings" value="' + settings + '"\/>'+
  '<input type="hidden" name="adv_set" value="' + adv_set + '"\/>'+
  '<input type="hidden" name="cal_cnt" value="' + cal_cnt + '"\/>'+
  '<input type="hidden" name="wk" value="' + wk + '"\/>');
  document.write('<div id="navigation">'+
/*  '<input class="button" id="previous" name="previous" type="button" value="<<" onclick="document.new_cal.month.value=\'' + lastMonth+  '\';document.new_cal.year.value=' + lmYear + ';submit();"\/>&nbsp;'+
  '<input class="button" id="at" type="button" value="@" onclick="document.location.href=document.location.href + \'&amp;month=' + myDate.getMonth() + '&amp;year=' + myDate.getFullYear() + ';\'"\/>&nbsp;'+
  '<input class="button" id="next" name="next" type="button" value=">>" onclick="document.new_cal.month.value=' + nextMonth + ';document.new_cal.year.value=' + nmYear + ';submit();"\/>'+*/
  '<input class="button" id="previous" name="previous" type="button" value="<<" onclick="document.new_cal.month.value=\'' + lastMonth +  '\';document.new_cal.year.value=' + lmYear + ';submit();"\/>&nbsp;'+
  '<input class="button" id="at" type="button" value="@" onclick="document.location.href=document.location.href + \'&amp;month=' + myDate.getMonth() + '&amp;year=' + myDate.getFullYear() + ';\'"\/>&nbsp;'+
  '<input class="button" id="next" name="next" type="button" value=">>" onclick="document.new_cal.month.value=' + nextMonth + ';document.new_cal.year.value=' + nmYear + ';submit();"\/>'+
  '</div>');
  document.write('<div id="more_options">'+
  '<div id="more_options_title">Options:</div>');
  document.write('<div id="more_options_us_eu">'+
  '<label>US<input type="radio" name="startOn" value="0"' + ((calStartDOW == 0)? ' checked="checked" ' : ' ') + ' onclick="document.new_cal.submit();"\/></label>&nbsp;'+
  '<label>EU<input type="radio" name="startOn" value="1"' + ((calStartDOW == 1)? ' checked="checked" ' : ' ') + ' onclick="document.new_cal.submit();"\/></label>'+
  '</div>');
  document.write(css_options);
  document.write(lang_options);
// JWR - should be able to condense this without wk==1, but doesn't work
//  var notwk = (wk+1)%2;
//  document.write('<div id="more_options_week">'+
//  '<label>Week off'+
//  '<input type="checkbox" name="wk" value=+notwk+' + ' onclick="document.new_cal.submit();"/></label>'+
//  '</div>');

//  document.write('<div id="more_options_week">'+
//  '<label>Week off'+
//  '<input type="checkbox" name="wk" value="0"' + ((wk == 0)? ' checked="checked" ' : ' ') + ' onclick="document.new_cal.submit();"/></label>'+
//  '</div>');

// JWR - fixes week being unchangeable in options
  if (wk == 1) {
    document.write('<div id="more_options_week">'+
    '<label>Week off'+
    '<input type="checkbox" name="wk" value="0"' + ' onclick="document.new_cal.submit();"/></label>'+
    '</div>');
  }
  else {
    document.write('<div id="more_options_week">'+
    '<label>Week on'+
    '<input type="checkbox" name="wk" value="1"' + ' onclick="document.new_cal.submit();"/></label>'+
    '</div>');
  }
  if (theclock != 0) {
    document.write('<div id="more_options_clock">Clock:'+
    '<label><input type="radio" name="clock" value="1"' + ((theclock == 1)? ' checked="checked" ' : ' ') + ' onclick="document.new_cal.submit();"/>top</label> '+
    '<label><input type="radio" name="clock" value="2"' + ((theclock == 2)? ' checked="checked" ' : ' ') + ' onclick="document.new_cal.submit();"/>bottom</label> '+
    '<label><input type="radio" name="clock" value="0" onclick="document.new_cal.submit();"/>off</label>'+
    '</div>');
  }
  else {
    document.write('<div id="more_options_clock"><label for="clock">Clock</label><input type="checkbox" name="clock" id="clock" value="1" onclick="document.new_cal.submit();"/></div>');
  }
  if (adv_set == 1) document.write('<div id="more_options_adv_set">'+
  '<input class="button" type="text" name="month" size="2" value="'+myMonth+'"\/>'+
  '<input class="button" type="text" name="year" size="4" value="'+myYear+'"\/></div>');

  document.write('</form>' +
  '</div>'+
//  '</div>'+
	'</div>');
}

// addEvent as created by John Resig, http://ejohn.org/projects/flexible-javascript-events/
function addEvent(obj, type, fn) {
	if ( obj.attachEvent ) {
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event);}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} else
		obj.addEventListener(type, fn, false);
}
function removeEvent(obj, type, fn) {
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	} else
		obj.removeEventListener(type, fn, false);
}

//addEvent(window, 'load', new_calendars);
addEvent(window, 'load', set_refresh);
addEvent(window, 'dblclick', version);