

/************************************************************************
GLOBAL VARIABLES FOR FORMATTING FONTS AND TEXT
************************************************************************/
/***********************
COLORS
***********************/
var DATE_HIGHLIGHT_BACKGROUND		= '#DEDEFF';
var DATE_HIGHLIGHT_COLOR		= '#555555';
var DATE_HIGHLIGHT_BORDER_COLOR		= '#CCCCCC';
var DAY_OF_WEEK_COLOR			= '#555555'; 
var HIGHLIGHT_DAY_OF_WEEK		= '#555555';
var DATE_COLOR				= '#555555';
var MONTH_COLOR				= '#555555';
var YEAR_COLOR				= '#555555';
var MONTH_YEAR_BACKGROUND		= '#EEEEEE';
var CALENDAR_BORDER_COLOR		= '#CCCCCC';
var CALENDAR_BACKGROUND			= '#FFFFFF';

/***********************
FONTS
***********************/
var DATE_HIGHLIGHT_FONT			= 'Arial';
var DAY_OF_WEEK_FONT			= 'Arial';
var HIGHLIGHT_DAY_OF_WEEK_FONT		= 'Arial';
var DATE_FONT				= 'Arial';
var MONTH_FONT				= 'Arial';
var YEAR_FONT				= 'Arial';

/***********************
FONT SIZES
***********************/
var DATE_HIGHLIGHT_SIZE			= 1;
var DATE_HIGHLIGHT_BORDER_SIZE		= 1;
var DATE_SIZE				= 1;
var DAY_OF_WEEK_SIZE			= 1;
var HIGHLIGHT_DAY_OF_WEEK_SIZE		= 1;
var MONTH_SIZE				= 2;
var YEAR_SIZE				= 2;
var CALENDAR_BORDER_SIZE		= 1; 

/*******************************
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');

/********************************
DECLARE AND INITIALIZE VARIABLES
********************************/
var Calendar = new Date();

var year =  Calendar.getFullYear(); //Returns year
var month = Calendar.getMonth();	// Returns month (0-11)
var today = Calendar.getDate();		// Returns day (1-31)
var weekday = Calendar.getDay();	// Returns day (1-31)

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

var dueDate = '1/1/2015'; // set to date for testing 


// call this function to generate the calendar
// offset is in months from this month
function Render_Calander(offset)
{
	var tmpM = month + offset;
	if (tmpM >11) {
		tmpM -=12;
		if (tmpM == 0) year ++;
	} 
	//Calendar.setFullYear(2005);
	Calendar.setDate(1);			// Start the calendar day at '1'
	Calendar.setMonth(tmpM);		// Start the calendar month at value given

	var TR_start = '<TR>';
	var TR_end = '</TR>';
	var highlight_start = '<TD WIDTH="30"><TABLE CELLSPACING=0 BORDER="' + DATE_HIGHLIGHT_BORDER_SIZE + '" BGCOLOR="'+ DATE_HIGHLIGHT_BACKGROUND +'" BORDERCOLOR="' + DATE_HIGHLIGHT_BORDER_COLOR + '"><TR><TD WIDTH=20><B><CENTER>';
	var highlight_end   = '</CENTER></TD></TR></TABLE></B>';
	var TD_start = '<TD WIDTH="30" BACKGROUND="' + CALENDAR_BACKGROUND +'"><CENTER>';
	var TD_end = '</CENTER></TD>';

	/*************************************************************************
	BEGIN CODE FOR CALENDAR
	*************************************************************************/
	cal =  '<TABLE BORDER="' + CALENDAR_BORDER_SIZE + '" CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="' + CALENDAR_BORDER_COLOR + '" HEIGHT="100%"><TR><TD>';
	cal += '<TABLE BORDER="0" CELLSPACING=0 CELLPADDING=2 BGCOLOR="' + CALENDAR_BACKGROUND + '" HEIGHT="100%">' + TR_start;
	cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" BGCOLOR="' + MONTH_YEAR_BACKGROUND + '"><CENTER><B>';
	cal += '<FONT COLOR="' + MONTH_COLOR + '" FACE="'+ MONTH_FONT +'" SIZE="'+ MONTH_SIZE +'">' + month_of_year[tmpM]  + ' </FONT>&nbsp;&nbsp;' + '<FONT COLOR="' + YEAR_COLOR + '" FACE="'+ YEAR_FONT +'" SIZE="'+ YEAR_SIZE +'">' + year + '</B></FONT>' + 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++)
	{
		cal += TD_start + '<FONT COLOR="' + DAY_OF_WEEK_COLOR + '" FACE="'+ DAY_OF_WEEK_FONT +'" SIZE="'+ DAY_OF_WEEK_SIZE +'">' + day_of_week[index] + '</FONT>' + TD_end;
	}

	cal += TD_end + TR_end;
	cal += TR_start;

	// FILL IN BLANK GAPS UNTIL TODAY'S DAY
	for(index=0; index < Calendar.getDay(); index++)
	cal += TD_start + '&nbsp; ' + TD_end;

	// LOOPS FOR EACH DAY IN CALENDAR
	for(index=0; index < DAYS_OF_MONTH; index++)
	{
	if( Calendar.getDate() > index )
	{
		// RETURNS THE NEXT DAY TO PRINT
		week_day =Calendar.getDay();

		// 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.getDate();


		cal += "<TD STYLE='CURSOR:HAND;' ONCLICK='SetDueDate(&quot;" + Calendar + "&quot;);' WIDTH='30' BGCOLOR='" + DateClr(Calendar, dueDate) +"'><CENTER><FONT COLOR='" + DATE_COLOR + "' FACE='"+ DATE_FONT +"' SIZE='"+ DATE_SIZE +"'>" +  day + "</FONT></CENTER></TD>";        


		}

		// END ROW FOR LAST DAY OF WEEK	 
		if(week_day == DAYS_OF_WEEK)
			cal += TR_end;
	}

	// INCREMENTS UNTIL END OF THE MONTH
	Calendar.setDate(Calendar.getDate()+1);

	}// end for loop

	cal += '</TD></TR></TABLE></TABLE>';

	/*********************************
	PRINT CALENDAR
	********************************/

	return cal;
	//-->
}

function SetDueDate(dd){
	dueDate = dd;
	Calendar = new Date();
	year = 	Calendar.getFullYear(); //Returns year	

	document.getElementById("cal1").innerHTML = Render_Calander(0);
	document.getElementById("cal2").innerHTML = Render_Calander(1);
	document.getElementById("cal3").innerHTML = Render_Calander(2);
	document.getElementById("cal4").innerHTML = Render_Calander(3);
	document.getElementById("cal5").innerHTML = Render_Calander(4);
	document.getElementById("cal6").innerHTML = Render_Calander(5);
	document.getElementById("cal7").innerHTML = Render_Calander(6);
	document.getElementById("cal8").innerHTML = Render_Calander(7);
	document.getElementById("cal9").innerHTML = Render_Calander(8);

	if (dd != '1/1/2015'){
		//document.getElementById("header").innerText = "";
	document.getElementById("sc").style.visibility='visible';
	document.getElementById("header").style.visibility='hidden';
}
	
}

	
function DateClr(curDate, dueDate) {

    var BGClr = '#FFFFFF';
    var tmpN;
    var bufferA = Date.parse( dueDate );
    var bufferB = Date.parse( curDate );
    	
    var number = bufferA-bufferB ;
    
    // Get difference in days
    tmpN = number / 86400000 ;
	
	if (tmpN >= -1 & tmpN < 0){
		BGClr = '#9999FF';
	}
	else{
	
	    tmpN = parseInt(number / 86400000) ;
		tmpN += parseInt((number % 86400000)/43200001) ;
		// determin number of weeks
		tmpN = 39 - (parseInt(tmpN/7));
		//alert(dueDate + " , " + curDate);

		if (tmpN > 16 & tmpN< 23)
		{
			BGClr = '#C7E1EB'; // not so good time
		}
		else
		{
			if (tmpN > 22 & tmpN< 26)
			{
				BGClr = '#66FFFF'; // okay time
			}
			else
			{
				if (tmpN > 25 & tmpN< 29)
					BGClr = '#00bfff'; // best time
			}
			
		}
			if (tmpN > 28 & tmpN< 34)
		{
			BGClr = '#FFCCFF'; // another okay time
		}
		
	}
	return BGClr;
	
}
	