var bg="#eeeeee";//Specify bgcolor of calendar
var oldSel=new Array();var targetId="";
oldSel["dDate"]=""; oldSel["aDate"]="";
var flg = 0; var theInHTML = "" ;var fs=1;var currentDay = -1;
M = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
D = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
M1 = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function getBgn() 
{mo = pdy.getMonth();    // start month
 pyr = pdy.getFullYear();     // todays year
 theInHTML += '<TABLE bgcolor="#eeeeee" align="left" cellspacing="0" cellpadding="0" BORDER="0"><TR><TD VALIGN=TOP>';
 for (var lC = 0;lC < numMonths;lC++)
	{if (lC!=0)
		{mo++;}
	 pyr =((mo)>11?pyr+1:pyr);
	 mo = ((mo)>11?0:mo);
	 bgn = new Date(M[mo]+" 1,"+pyr); // assign to date
	 Calendar();           // build Month
	 if (lC == (numMonths - 1))
	 	{theInHTML += '</TD></TR><tr><td colspan="3" align="center" class="td9" style="padding-top:10px;" bgcolor="#eeeeee">Click a date to select it or <a href="JavaScript:doCloseCal()">here to close</a></td></tr></TABLE>';
		 document.getElementById("theCal").innerHTML =(theInHTML)
		} // Finish up
	 else //extra months
	 	{if (lC % 3 == 2)
			{theInHTML += '</td></tr></TABLE><br><TABLE BORDER=2><TR><TD VALIGN=TOP>'}
		 else
			{theInHTML += '</TD><TD VALIGN=TOP>';}
		}
	
	}
 }
function Calendar()
{dy = bgn.getDay();
yr = eval(pyr);
d = "312831303130313130313031";
if (yr / 4 == Math.floor(yr / 4)) 
	{d = d.substring(0, 2) + "29" + d.substring(4, d.length);}
pos = (mo * 2);
ld = eval(d.substring(pos, pos + 2));
theInHTML += '<TABLE BORDER="1" BGCOLOR="' + bg + '"><TR><TD ALIGN="CENTER" COLSPAN="7" class="td8" valign="top"><table align="center" cellpadding="0" cellspacing="0" width="100%"><tr><td width="13" valign="top"><img src="Images/calendarPrevious.gif" width="16" height="13" align="top" hspace="5" vspace="1" style="cursor:pointer;" onclick="doNextDate(-3)"></td><td class="td8">'+ M[mo] + ' ' + yr+ '</td><td width="13"><img src="Images/calendarNext.gif" width="16" height="13" align="top" hspace="5" vspace="1" style="cursor:pointer;" onclick="doNextDate(3)"></td></tr></table></td></TD></TR><TR><TR>';
for (var i = 0;i < 7;i ++)
	{theInHTML += '<TD ALIGN="CENTER" class="td7">' + D[i]+'</TD>';}
theInHTML += "</TR><TR>";
ctr = 0;//alert(dy);
for (var i = 0;i < 7; i++)
	{if (i < dy) 
		{theInHTML += '<TD ALIGN=CENTER style="border:none"><FONT SIZE=' + fs + '> </FONT></TD>';}
	 else 
		 {ctr++;currentDay++;
		  var theEventSelected=0;//theEventDate[currentDay];
		  if(theEventSelected>0 ){nString=' style="border:1px #ff0000 solid;"';}else{nString=''}
		  theInHTML += '<TD ALIGN="CENTER" onclick="doSetDate(' + ctr + ',' + mo + ',' + yr + ',this)" class="td6"'+nString+'>'+ ctr + '</TD>';
		 }
	}
theInHTML += "</TR><TR>";
while (ctr < ld) 
	{for (var i = 0;i < 7; i++)
		{ctr++;
			if (ctr > ld)
				{theInHTML += '<TD ALIGN=CENTER style="border:none;"> </TD>';}
			else 
				{currentDay++;var theEventSelected=0;//theEventDate[currentDay];
				 if(theEventSelected>0){nString=' style="border:1px #ff0000 solid;"';}else{nString=''}
				 theInHTML += '<TD ALIGN="CENTER" onclick="doSetDate(' + ctr + ',' + mo + ',' + yr + ',this)" class="td6"'+nString+'>'+ ctr + '</TD>';
				}
		 		
		}
	 theInHTML += "</TR><TR>";
	}
//currentDay--;alert(currentDay);
theInHTML += "</TR></TABLE>";

}
function doNextDate(n)
{var theCMonth = pdy.getMonth();var theCYear = pdy.getFullYear();
 theCMonth += n;
 theCMonth > 11 ? theCYear += 1 :theCYear += 0
 theCMonth > 11 ? theCMonth = 0 : theCMonth += 0
 theCMonth < 0 ? theCYear -= 1 :theCYear += 0
 theCMonth < 0 ? theCMonth = 11 : theCMonth += 0
 pdy = new Date(M[theCMonth]+" 1,"+theCYear);
 theInHTML = "";currentDay = -1;getBgn();
}
function doSetDate(dd,mm,yy,elem)
{if(oldSel[targetId] !=""){oldSel[targetId].style.border="none";}
 elem.style.border="1px #ff0000 solid";oldSel[targetId]=elem;
 document.getElementById(targetId).value=dd.toString(10)+" "+M[mm]+" "+yy.toString(10);
 doCloseCal();
}
function doCloseCal()
{document.getElementById("theCal").style.visibility="hidden";
document.getElementById("availabilityRight").style.opacity = 1.0;
document.getElementById("availabilityRight").style.filter ="alpha(opacity=100)";
document.getElementById("availabilityLeft").style.opacity = 1.0;
document.getElementById("availabilityLeft").style.filter ="alpha(opacity=100)";
document.getElementById("locationsD").style.visibility="visible";
document.getElementById("AType").style.visibility="visible";
}
