var monthDiff = 6;

function GenerateMonthTable(year, month, pagetype, displayid)
{
	//var dateObj = new Date();
	var dateObj = new Date(dateObject.substring(6,10),dateObject.substring(3,6)-1,dateObject.substring(0,2));
	
	var curr_date = dateObj.getDate();
	var curr_month = dateObj.getMonth()+1;
	
	var disp_cur_month = "";
	if(curr_month >= 10)
		disp_cur_month = "'" + curr_month + "'";
	else
		disp_cur_month = "'0" + curr_month + "'";

	var curr_year = dateObj.getFullYear();
	
	var nextyear = parseInt(year) + 1;
	
	var previousyear = year - 1;
	
	var previousyrdisplay = true;
	if (pagetype == 'Ear')
	{
		var prevEarningsYr = year-1;
		var todaydate = new Date(dateObject.substring(6,10),dateObject.substring(3,6)-1,dateObject.substring(0,2));
		var olddate = new Date(dateObject.substring(6,10),dateObject.substring(3,6)-1,dateObject.substring(0,2));	
		olddate.setMonth(todaydate.getMonth() - monthDiff);
		
		olddate.setDate(todaydate.getDate());
		var oldYr = olddate.getYear();
		
		if(oldYr <= prevEarningsYr)
		{
			previousyrdisplay = true;
		}
		else
		{
			previousyrdisplay = false;
		}
		
		
	}
	else if (pagetype == 'Int')
	{
		if (year <= curr_year - 2)
		{
			previousyrdisplay = false;
		}
	}
	else if (pagetype == 'Cal')
	{
		if (year <= curr_year - 2)
		{
			previousyrdisplay = false;
		}
	}

	var arrMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var tData = '<table width="619" border="0" cellspacing="0" cellpadding="0">';
	tData = tData + '<tr>';
	tData = tData + '<td class="hdr1gra" width="70" align="left">';
	
	if (!previousyrdisplay)
	{
		tData = tData +  '<span class="fontbold">&lt; Last year</span>';
	}
	else
	{
		if(previousyear == curr_year)
		{
			tData = tData + '<a href="javascript:openMonth(' + disp_cur_month + ',' + previousyear + ')"><span class="fontbold">&lt; Last year</span></a>';
		}
		else
		{
			tData = tData + '<a href="javascript:openMonth(' + 01 + ',' + previousyear + ')"><span class="fontbold">&lt; Last year</span></a>';
		}
	}
	tData = tData + '</td>';
	tData = tData + '<td class="hdr1gra" width="479">';
	tData = tData + '</span> | &nbsp;&nbsp;';
	var tmpcount;
	var tmpmonth = "'" + month + "'";
	for (icount=0; icount < arrMonth.length; icount++)
	{		
		jcount = icount + 1;
		if (jcount < 10)
		{
			tmpcount = "'0" + jcount + "'";			
		}
		else
			tmpcount = "'" + jcount + "'";
			
		
		if (tmpmonth == tmpcount)
		{
			tData = tData + '<span class="fontbold">&nbsp;&nbsp;' +  arrMonth[icount] + '&nbsp;&nbsp;</span> | ';
		}
		else
			tData = tData + '&nbsp;&nbsp;<a href="javascript:openMonth(' + tmpcount + ',' + year + ')">' + arrMonth[icount] + '</a>&nbsp;&nbsp; | ';
	}	
	tData = tData + '</td>';
	//tData = tData + '<td class="gratop2"><h2>&nbsp;' + year + '</h2></td>';
	tData = tData + '<td class="hdr1gra" width="70" align="left">';
	if (nextyear <= curr_year + 1)
	{
		if(nextyear == curr_year)
		{
			tData = tData +	'<a href="javascript:openMonth(' + disp_cur_month + ',' + nextyear + ')"><span class="fontbold">Next year &gt;</span></a>';
		}
		else
		{
			tData = tData +	'<a href="javascript:openMonth(' + 01 + ',' + nextyear + ')"><span class="fontbold">Next year &gt;</span></a>';
		}
	}
	else
	{
		tData = tData +	'<span class="fontbold">Next year &gt;</span>';
	}
	//tData = tData + '<br>';
	
	tData = tData + '</td><td class="hdr1gra" width="0">&nbsp;</td></tr></table>';
	document.write(tData);
}

function openMonth(month,year)
{
	curDate = dateObject.substring(0, 2);
	curMonth = dateObject.substring(3, 5);
	curYear = dateObject.substring(6, 10);

	for (i=0; i < montharr.length; i++)
	{
		if (montharr[i][0] == month && montharr[i][2] == year)
		{
			if(month == curMonth && year == curYear)
				linkName = "#"+curMonth+curDate;
			else
				linkName = "";

			location.href=montharr[i][1]+linkName;
		}
	}
}



