fullMonth = ["January","February","March","April","May","June","July","August","September","October","November","December"];
today = new Date();
curntDate = today;
setUp();

function setUp() {
	firstDate = new Date(curntDate.getFullYear(),curntDate.getMonth(),1);
	lastMonth = new Date(curntDate.getFullYear(),curntDate.getMonth()-1,1);
	nextMonth = new Date(curntDate.getFullYear(),curntDate.getMonth()+1,1);
	offSet   = firstDate.getDay() + 1;
	lastSlot = offSet + ((nextMonth - firstDate)/(3600*24*1000)) - 1;
	lastSlot = Math.round(lastSlot);
	calWeeks = Math.ceil(lastSlot/7);
	calDays  = calWeeks * 7;
	day = 1;
	
	tm = today.getMonth()+1;
	ty = today.getYear();
	if (ty<1900) {ty+=1900};
}

function goLast(boxMe,formMe) {
	curntDate = lastMonth;
	setUp();
	printCalendar(boxMe,formMe);
}

function goNext(boxMe,formMe) {
	curntDate = nextMonth;
	setUp();
	printCalendar(boxMe,formMe);
}

function printCalendar(boxMe,formMe) {
	setUp();
cM = curntDate.getMonth()+1;
cY = curntDate.getYear();
if (cY<1900) {cY+=1900};
eM = tm-1;
if (eM<1) {eM=12};
eY = ty+1;

pCal="";
pCal += "<table border=0 cellpadding=0 cellspacing=1>";

if ((cM==tm) && (cY==ty)) {
	pCal += "<tr><td class=mchead>&nbsp;</td>";
	}else{
	pCal += "<tr><td class=mchead><a href=javascript:goLast('"+boxMe+"','"+formMe+"')>&lt;</a></td>";
	}

pCal += "<td class=mchead colspan=5 align=center><nobr>" + fullMonth[curntDate.getMonth()] + " " + curntDate.getFullYear() +"</nobr></td>";

if ((cM==eM) && (cY==eY)) {
	pCal += "<td class=mchead>&nbsp;</td></tr>";
	}else{
	pCal += "<td class=mchead><a href=javascript:goNext('"+boxMe+"','"+formMe+"')>&gt;</a></td></tr>";
	}

pCal += "<tr ><td class=mcday>Sun</td><td class=mcday>Mon</td><td class=mcday>Tue</td><td class=mcday>Wed</td><td class=mcday>Thu</td><td class=mcday>Fri</td><td class=mcday>Sat</td></tr><tr align=center>";

	for (i=1; i<=calDays; i++) {
	if (i >= offSet && i <= lastSlot) {
		if (curntDate.getFullYear() > today.getFullYear() || (curntDate.getFullYear()==today.getFullYear() && curntDate.getMonth() > today.getMonth()) || (curntDate.getFullYear()==today.getFullYear() && curntDate.getMonth()==today.getMonth() && day >= today.getDate())){
			pCal += "<td class=mcdate><a href=javascript:return_date(" + day + ",'"+ formMe +"','"+boxMe+"')>" + day + "</a></td>";
		}else{
			pCal += "<td class=mnondate>" + day + "</td>";
		}
		day++;
	} else {
		pCal += "<td class=mnoday>&nbsp;</td>";
	}

	if (i%7 == 0) {
		pCal += "</tr>";
		}
	}
	
pCal += "</tr></table>";
document.getElementById(boxMe).innerHTML=pCal;

}


function return_date(z,formMe,boxMe) {
	
	// redo month and year selection
	newMY = ""+cM+","+cY;
	for(i=0; i<12; i++) {
		check = document.forms[formMe].arrivalMonthYear.options[i].value;
		if (check==newMY) {
			document.forms[formMe].arrivalMonthYear.selectedIndex = i;
		}
	}
	
	// redo dates
    maxDays = daysInMonth(cM,cY);
    document.forms[formMe].arrivalDate.length=0;
    for(i=1; i<=maxDays; i++) {
        document.forms[formMe].arrivalDate.options[i-1] = new Option(i,i);
    }
    
    // select right date
	document.forms[formMe].arrivalDate.selectedIndex = z-1;
	
	//close calendar
	openCal();
}


function openCal() {
	toggle = document.getElementById('mycal').style.display;

	if (toggle == "none" || toggle == null || toggle == "") {
		document.getElementById('mycal').style.display="inline";
	} else if (toggle == "inline") {
		document.getElementById('mycal').style.display="none";
	}
}









