var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var monthNameForCalc = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var dayNameShort= new Array('Sun', 'Mon','Tue','Wed','Thu','Fri','Sat');


rightnow = new Date();

function filterDropdown(passedDropdown, minSize, maxSize, singular, plural) {
  var s = '';
  for (i=minSize; i <=maxSize; i++) {
	if( i == 1 ){s=singular}else {s=plural;}
    passedDropdown.options[i - minSize] = new Option(i);
    passedDropdown.options[i - minSize].value = parseInt(i);
    passedDropdown.options[i - minSize].text = parseInt(i) + ' ' + s;
  }
}
function addOptionToDD(dropDownBox, optionText, optionValue) {
	dropDownBox[dropDownBox.length] = new Option(optionText, optionValue);
}

function populateDDforThisMonth(dropDownBox, bDayWeekFirst, iYear, iMonth, iDay) {

	var thisDate;
	var displayDay;
	
	//emptyDropDown('DepDay');
	dropDownBox.length = 0;
	for (counter=1; counter<=monthDays[parseInt(iMonth - 1)]; counter++) {
		thisDate = new Date(monthNameForCalc[parseInt(iMonth - 1)] + ' ' + counter + ', ' + iYear);
		if(bDayWeekFirst)
		{
			displayDay = dayNameShort[thisDate.getDay()] + ' ' + counter;
		}
		else
		{
			displayDay = counter + ' ' + dayNameShort[thisDate.getDay()];
		}
		addOptionToDD(dropDownBox, displayDay, counter);
	}
	
	//addOptionToDD('DepDay', ' ', 100);
	var newIndex = monthDays[parseInt(iMonth - 1)];
		
	if((iDay<=monthDays[parseInt(iMonth - 1)])&&(iDay>0)){
		newIndex = iDay - 1;
	}
	else
	{
		newIndex = monthDays[parseInt(iMonth - 1)] - 1;
	}
	dropDownBox.selectedIndex=newIndex;
}

function calcDayOfWeek(theMonthDropDown, theDayDropDown, bDayWeekFirst)
{
	var iYear = parseInt(theMonthDropDown.options[theMonthDropDown.selectedIndex].value.substring(3,7));
	var iMonth = theMonthDropDown.options[theMonthDropDown.selectedIndex].value.substring(0,2);
	var iDay = theDayDropDown.options[theDayDropDown.selectedIndex].value;
	monthDays[1] = ((iYear%4==0 && iYear%100!=0)||(iYear%400==0)) ? 29 : 28;
	populateDDforThisMonth(theDayDropDown, bDayWeekFirst, iYear, iMonth, iDay);
}
	


