
function calendar (dateStr) 
{
//  SET ARRAYS
var day_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var smonth_of_year = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

//  DECLARE AND INITIALIZE VARIABLES
// Remove Time (confused by 24 designation)
var Calendar = readDateStr(dataparam.caldate);  //current calendar date
var Data = readDateStr(dataparam.date); //data selected date
var startDate = new Date(2006,7,1,0,0,0,0);
//var startDate = new Date("June 1, 2003");
startDate.setUTCHours(0);
var endDate = new Date(2006,9,15,0,0,0,0);
//var endDate = new Date();

// Set local variables
var year = Calendar.getUTCFullYear();	    // Returns year
var month = Calendar.getUTCMonth();    // Returns month (0-11)
var today = Calendar.getUTCDate();    // Returns day (1-31)
var weekday = Calendar.getUTCDay();    // Returns day (1-31)

// Set forward and back links
var pre_month = new Date();
pre_month.setTime(Calendar.getTime());

if (month == 0) {
	pre_month.setUTCMonth(11);
	pre_month.setUTCFullYear(Calendar.getUTCFullYear() - 1);
} else {
	pre_month.setUTCMonth(Calendar.getUTCMonth() - 1);
}

var next_month = new Date();
next_month.setTime(Calendar.getTime());

if (month < 11) {
	next_month.setUTCMonth(Calendar.getUTCMonth() + 1);
} else {
	next_month.setUTCMonth(0);
	next_month.setUTCFullYear(Calendar.getUTCFullYear() + 1);
}

var DAYS_OF_WEEK = 7;    // "constant" for number of days in a week
var DAYS_OF_MONTH = 31;    // "constant" for number of days in a month
var cal;    // Used for printing

Calendar.setUTCDate(1);    // Start the calendar day at '1'
Calendar.setUTCMonth(month);    // Start the calendar month at now


/* VARIABLES FOR FORMATTING
NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
      tags to customize your caledanr's look. */

var TR_start = '<TR>';
var TR_end = '</TR>';
var highlight_start = '<TD WIDTH="30"><TABLE CELLSPACING=0 BORDER=1 BGCOLOR=DEDEFF BORDERCOLOR=CCCCCC><TR><TD WIDTH=20><B><CENTER>';
var highlight_end   = '</CENTER></TD></TR></TABLE></B>';
var TD_start = '<TD WIDTH="30"><CENTER>';
var TD_end = '</CENTER></TD>';

/* BEGIN CODE FOR CALENDAR
NOTE: You can format the 'BORDER', 'BGCOLOR', 'CELLPADDING', 'BORDERCOLOR'
tags to customize your calendar's look.*/

cal =  '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR=BBBBBB><TR><TD>';
cal += '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2>' + TR_start;
cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="#EFEFEF"><CENTER><B>';

//
// Add link to change calendar previous month
//

if ((pre_month.getUTCFullYear() > startDate.getUTCFullYear()) || (pre_month.getUTCMonth() >= startDate.getUTCMonth())) {
var pdate = writeDateStr(pre_month);
cal += '<a class="noline" href="javascript:changeCal(' + "'" + pdate +  "'" + ')">  &lt;</a>';
}


cal += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + month_of_year[month]  + '   ' + year + '&nbsp;&nbsp;&nbsp;'; 

//
// Add link to change calendar next month
//


if ((next_month.getUTCFullYear() < endDate.getUTCFullYear()) || (next_month.getUTCMonth() <= endDate.getUTCMonth())) {
    var ndate = writeDateStr(next_month);
    cal += '<a class="noline" href="javascript:changeCal(' + "'" + ndate + "'" + ')">&gt;</a> ';
}

cal += '</b>' + TD_end + TR_end;
cal += TR_start;

//   DO NOT EDIT BELOW THIS POINT  //

// LOOPS FOR EACH DAY OF WEEK
for(index=0; index < DAYS_OF_WEEK; index++)
{

// BOLD TODAY'S DAY OF WEEK
//if(weekday == index)
//cal += TD_start + '<B>' + day_of_week[index] + '</B>' + TD_end;

// PRINTS DAY
//else
cal += TD_start + day_of_week[index] + TD_end;
}

cal += TD_end + TR_end;
cal += TR_start;


// FILL IN BLANK GAPS UNTIL TODAY'S DAY
for(index=0; index < Calendar.getUTCDay(); index++)
cal += TD_start + '  ' + TD_end;

// LOOPS FOR EACH DAY IN CALENDAR
for(index=0; index < DAYS_OF_MONTH; index++)
{
if( Calendar.getUTCDate() > index )
{
  // RETURNS THE NEXT DAY TO PRINT
  week_day =Calendar.getUTCDay();

  // START NEW ROW FOR FIRST DAY OF WEEK
  if(week_day == 0)
  cal += TR_start;

  if(week_day != DAYS_OF_WEEK)
  {

  // SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
  var day  = Calendar.getUTCDate();

  // HIGHLIGHT TODAY'S DATE
	
if((Data.getUTCDate() == Calendar.getUTCDate()) && (Data.getUTCMonth() == Calendar.getUTCMonth()) && (Data.getUTCFullYear() == Calendar.getUTCFullYear())){
  cal += highlight_start + day + highlight_end + TD_end;
 

} else if ( (Calendar.getTime() <= endDate.getTime()) && (Calendar.getTime() >= startDate.getTime())) {
    var ddate = writeDateStr(Calendar);
  cal += TD_start + '<a href="javascript:changeDate('+ "'" + ddate +  "'" + ')">' + day + '</a>' + TD_end;
}

  // PRINTS DAY
  else
  cal += TD_start + day + TD_end;
  }

  // END ROW FOR LAST DAY OF WEEK
  if(week_day == DAYS_OF_WEEK)
  cal += TR_end;
  }

  // INCREMENTS UNTIL END OF THE MONTH
  Calendar.setUTCDate(Calendar.getUTCDate()+1);

}// end for loop

cal += '</TD></TR></TABLE></TABLE>';

//  PRINT CALENDAR
document.write(cal);


}

