/* canlendar2.js */

today=new Date();
paavl="";

function stick(day, month, year) {
	month++;
	if (month < 10)
		sDate = "0" + month + "/";
	else
		sDate = month + "/";
	if (day < 10)
		sDate = sDate + "0" + day + "/";
	else
		sDate = sDate + day + "/";
		
	sDate = sDate + year;
	window.thing.value = sDate
	window.thing.focus();
	window.thing.blur();
	calendarWindow.close();
}

function popCalendar(thing, graphics_url, cadate) {
	if (cadate == "") 
		return;
	window.thing	= thing;
	paavl			= cadate;
	calendarWindow	= window.open("", "calendarWindow", 'height=255,width=225')
	
	calendarWindow.graphics_url	= graphics_url;
	if (thing.value != "")
		today = new Date(thing.value);
	drawCalendar(today, graphics_url);
	calendarWindow.focus();
	return;
}

function nextDrawCalendar(month,year) {
	if (month==11) { 
		year++; 
		month=0;
	} else 
		month++;
		
	day = new Date(year, month, 1);
	drawCalendar(day, calendarWindow.graphics_url);
	return;
}

function backDrawCalendar(month,year) {
	if (month == 0) {
		year--; 
		month=11;
	} else
		month--;
		
  day = new Date(year, month, 1);
  drawCalendar(day, calendarWindow.graphics_url);
  return;
}

var daysInMonth = new Array(12);
daysInMonth[1]	=31;
daysInMonth[2]	= 28;
daysInMonth[3]	= 31;
daysInMonth[4]	= 30;
daysInMonth[5]	= 31;
daysInMonth[6]	= 30;
daysInMonth[7]	= 31;
daysInMonth[8]	= 31;
daysInMonth[9]	= 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;
 
function drawCalendar(day, graphics_url) {
	firstday=day.getDay();
	firstdate=day.getDate();

	while((firstdate%7) != 1) {
		firstdate--;
		firstday = (firstday % 7) - 1;
		if (firstday == -1)
			firstday=6;
	}
 
	calendarWindow.document.open();
	calendarWindow.document.write('<html><head><title>Calendar</title>');
	calendarWindow.document.write('<style>');
	calendarWindow.document.write('.stmt-b {FONT-WEIGHT: bold; FONT-SIZE: 13px; COLOR: blue; FONT-FAMILY: Arial}');
	calendarWindow.document.write('.stmt {FONT-SIZE: 12px; COLOR: blue; FONT-FAMILY: Arial}');
	calendarWindow.document.write('A:visited {color: blue;}');
	calendarWindow.document.write('A:hover {color: white;}');
	calendarWindow.document.write('</style>');
	calendarWindow.document.write('<SCRIPT LANGUAGE=javascript> ');
	calendarWindow.document.write('function TD_onMouseOver(o) ');
	calendarWindow.document.write('{	document.flip.oldBGColor.value=o.bgColor; o.bgColor = "#77aadd";} ');
	calendarWindow.document.write('function TD_onMouseOut(o) ');
	calendarWindow.document.write('{	o.bgColor = document.flip.oldBGColor.value;} ');
	calendarWindow.document.write('</SCRIPT>');
	calendarWindow.document.write('</head>');
	calendarWindow.document.write('<body bgcolor=#E3E9EC><form name=flip>');
	calendarWindow.document.write('<input type=hidden name=oldBGColor id=oldBGColor>'); 
	calendarWindow.document.write('<table border=0 width=100% cellpadding=0 cellspacing=0><tr bgcolor=#99ccff>');
	calendarWindow.document.write('<td align=left><a href="javascript: function back(){return 0;}" onclick="window.opener.backDrawCalendar('+day.getMonth()+','+day.getFullYear()+');"><img src="'+graphics_url+'prev.gif" border=0></a></td>\n');
	calendarWindow.document.write('<td align=center><select name=month style="font-family: arial; font-weight: bold; font-size: 12px;" onChange="window.opener.jump('+day.getFullYear()+')";><option value='+writeMonth(day.getMonth())+ '>'+writeMonth(day.getMonth())+'</option><option value="0">January<option value="1">February<option value="2">March<option value="3">April<option value="4">May<option value="5">June<option value="6">July<option value="7">August<option value="8">September<option value="9">October<option value="10">November<option value="11">December</select>');
	calendarWindow.document.write('<font style="font-family: arial; font-weight: bold; font-size: 12px;">&nbsp;&nbsp;' + day.getFullYear()+'</font></td>');
	calendarWindow.document.write('<td align=right><a href="javascript: function next(){return 0;}" onclick="window.opener.nextDrawCalendar('+day.getMonth()+','+day.getFullYear()+');"><img src="'+graphics_url+'next.gif" border=0></a></td>');
	calendarWindow.document.write('</table></form>'); 
	calendarWindow.document.write('<table border=1 CELLSPACING=1 CELLPADDING=1 align=center><tr><td><font class="stmt-b">Sun</font></td><td><font class="stmt-b">Mon</font></td><td><font class="stmt-b">Tue</font></td><td><font class="stmt-b">Wed</font></td><td><font class="stmt-b">Thu</font></td><td><font class="stmt-b">Fri</font></td><td><font class="stmt-b">Sat</font></td></tr>');
	calendarWindow.document.write('<tr>');
	currday=0;
	while (currday!=firstday) {
		calendarWindow.document.write('<td>&nbsp;</td>');
	    currday++;
	}

	var sDate;
	sDate = "";
  
	if (((day.getYear())%4) == 0)
		daysInMonth[2] = 29; 
	else 
		daysInMonth[2] = 28;

	for (days=1; days<=daysInMonth[day.getMonth()+1]; days++) {
	    if (!currday) 
			calendarWindow.document.write('</tr><tr>');
			
		mmm = day.getMonth() + 1;
		if (mmm < 10)
			sDate = "0" + mmm + "/";
		else
			sDate = mmm + "/";
		if (days < 10)
			sDate = sDate + "0" + days + "/";
		else
			sDate = sDate + days + "/";
	
		sDate = sDate + day.getFullYear();    

		if (paavl.search(sDate) > -1) {
			if (days == today.getDate() && today.getMonth() == day.getMonth())
				calendarWindow.document.write('<td align=center bgcolor=tan onmouseover="return TD_onMouseOver(this);" onmouseout="return TD_onMouseOut(this);">');
			else
				calendarWindow.document.write('<td align=center onmouseover="return TD_onMouseOver(this);" onmouseout="return TD_onMouseOut(this);">');
			
			calendarWindow.document.write('<a href="javascript:function cal(){window.close();}" onclick=window.opener.stick('+days+','+day.getMonth()+','+day.getFullYear()+')><font style="font-weight: bold; font-size: 13px; font-family: arial;">' + days + '</font></a></td>\n');
		} else {
			if (days==today.getDate() && today.getMonth()==day.getMonth())
				calendarWindow.document.write('<td align=center bgcolor=tan>');
			else
				calendarWindow.document.write('<td align=center>');
			calendarWindow.document.write('<font style="font-weight: bold; font-size: 13px; font-family: arial;">' + days + '</font></td>\n');
		}
		currday	= (currday + 1) % 7;
	}
	
	while (currday != 0) {
		calendarWindow.document.write('<td>&nbsp;</td>');
		currday	= (currday + 1) % 7;
	}
	calendarWindow.document.write('</tr>');	
	calendarWindow.document.write('</table>');

	calendarWindow.document.write('<p align=center><font style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Arial">Click on the date you would like to travel.</font>');
	calendarWindow.document.write('</body></html>');
	calendarWindow.graphics_url=graphics_url;
}

function writeMonth(m) {
  switch (m) {
    case 0: return "January";
    case 1: return "February";
    case 2: return "March";
    case 3: return "April";
    case 4: return "May";
    case 5: return "June";
    case 6: return "July";
    case 7: return "August";
    case 8: return "September";
    case 9: return "October";
    case 10: return "November";
    case 11: return "December";
  }
}

function jump(year) {

month=calendarWindow.document.flip.month.options[calendarWindow.document.flip.month.selectedIndex].value;
today= new Date;

day= new Date(year, month, 1);
drawCalendar(day, calendarWindow.graphics_url);
}

