// JavaScript Document
//
// Written by Marc Lieberman

var now = new Date;
var curmonth = now.getMonth();
var curyear = now.getFullYear();
// initialize month and year
var month = curmonth;
var year = curyear;
var unAvailableYear=2010;
var unAvailableMonth=2;
var monName = new Array ("jan", "feb", "mar", "apr", "may", "jun", "july", "aug", "sept", "oct", "nov", "dec");

function loadCalendar(when)
{
	//comment out if condition once the calendar is made for current and next 6 month
	if(month >= unAvailableMonth && year >= unAvailableYear) {
		frames[0].location = "/counselor/calendar/" + "updateInProgress" + ".jsp";
		document.getElementById('previous').style.visibility = 'hidden';
		document.getElementById('next').style.visibility = 'hidden';
	} else {
		if (when=="now")  {
		  textyear = year + "";
		  shortyear = textyear.substr(2,2);
		  frames[0].location = "/counselor/calendar/" + monName[month] + shortyear + ".jsp";
		 }
		else if (when=="next") {
		  month = month + 1;
		  if (month == 12) {
		    month = 0;
			year = year + 1;
		  }
		  textyear = year + "";
		  shortyear = textyear.substr(2,2);
		  frames[0].location = "/counselor/calendar/" + monName[month] + shortyear + ".jsp"; 
		 }
		else if (when=="prev") {
		  month = month - 1;
		  if (month < 0) {
		    month = 11;
			year = year - 1;
		  }
		  textyear = year + "";
		  shortyear = textyear.substr(2,2);
		  frames[0].location = "/counselor/calendar/" + monName[month] + shortyear + ".jsp";
		 }
			
		setVisibility()
	}

}

function setVisibility() {
  // Only show "previous" button if user has moved forward from the current month/year
  if (month > curmonth || year > curyear) {
    document.getElementById('previous').style.visibility = 'visible';
  } else {
    document.getElementById('previous').style.visibility = 'hidden';
  }
  // Only show "next" button for max 5 months in the future
  maxmonth = curmonth + 5;
  maxyear = curyear;
  if (maxmonth >= 12) {
    maxmonth = maxmonth-12;
	maxyear = curyear + 1;
  }
  if (month>=maxmonth && year>=maxyear) {
      document.getElementById('next').style.visibility = 'hidden';
  } else {
    document.getElementById('next').style.visibility = 'visible';
  }
}

