
var gNullable;

function populateDateControl(day, month, year, nullable){
	//populates the date dropdowns
	gNullable = nullable;



	//do pitch date
	var dtCurrentDate = addDays(new Date(),1);


	populateDaysControl(document.forms[0].elements[day],dtCurrentDate);
	
	populateMonthsControl(document.forms[0].elements[month],dtCurrentDate);
	
	populateYearsControl(document.forms[0].elements[year],dtCurrentDate);
	


}

function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function populateNightsControl(theControl,iSelectedNumNights){
	

	var iNumDays = 30;
	var i;

			theControl.options.length = iNumDays;
	

	for(i=seed;i<iNumDays;i++){
		theControl.options[i].text = i+1 + " nights";
		theControl.options[i].value = i+1;
		if (i % 2==1) theControl.options[i].className ='alt';
	}
	theControl.options.selectedIndex = iSelectedNumNights-1;	



}

function populateDaysControl(theControl,selectedDate){

	var iNumDays = 31;
	var i;


	if (gNullable == false) 
	{
		theControl.options.length = iNumDays;
		for(i=0;i<iNumDays;i++)
		{
			theControl.options[i].text = i+1;
			theControl.options[i].value = i+1;
			if (i % 2==1) theControl.options[i].className ='alt';
		}
		theControl.options.selectedIndex = selectedDate.getDate(selectedDate)-1;
	}
	else {
		theControl.options.length = iNumDays + 1;
		theControl.options[0].text = '-';
		theControl.options[0].value = '';
		for(i=1;i<iNumDays;i++)
		{
			theControl.options[i].text = i;
			theControl.options[i].value = i;
			if (i % 2==1) theControl.options[i].className ='alt';
		}
		theControl.options.selectedIndex = 0;
	}

	

}

function populateMonthsControl(theControl,selectedDate){
	var iNumMonths = 12;
	var i;

	if (gNullable == false) 
	{
			theControl.options.length = iNumMonths;
			for(i=0;i<iNumMonths;i++){
				theControl.options[i].text = getShortMonthFromNumber(i);
				theControl.options[i].value = i+1;
				if (i % 2==1) theControl.options[i].className ='alt';
			}
			theControl.options.selectedIndex = selectedDate.getMonth();
	} 
	else
	{
			theControl.options.length = iNumMonths + 1;
			theControl.options[0].text = '-';
			theControl.options[0].value = '';
			for(i=1;i<iNumMonths;i++){
				theControl.options[i].text = getShortMonthFromNumber(i - 1);
				theControl.options[i].value = i;
				if (i % 2==1) theControl.options[i].className ='alt';
			}
			theControl.options.selectedIndex = 0;
	}
}

function populateYearsControl(theControl,selectedDate){
	var iNumYears = 2;
	var i;


	if (gNullable == false) 
	{
		theControl.options.length = iNumYears;
		for(i=0;i<iNumYears;i++){
			
				theControl.options[i].text = selectedDate.getFullYear()+i;
				theControl.options[i].value = selectedDate.getFullYear()+i;
				if (i % 2==1) theControl.options[i].className ='alt';
			
		}
		theControl.options.selectedIndex = 0;
	} 
	else
	{
		theControl.options.length = iNumYears + 1;
		theControl.options[0].text = '-';
		theControl.options[0].value = '';
		for(i=1;i<iNumYears+1;i++){
			
				theControl.options[i].text = selectedDate.getFullYear()+i - 1;
				theControl.options[i].value = selectedDate.getFullYear()+i - 1;
				if (i % 2==1) theControl.options[i].className ='alt';
			
		}
		theControl.options.selectedIndex = 0;
	}
}

function getShortMonthFromNumber(iMonthNumber){
	switch(iMonthNumber){
		case 0:
			return "Jan";
			break;
		case 1:
			return "Feb";
			break;
		case 2:
			return "Mar";
			break;
		case 3:
			return "Apr";
			break;
		case 4:
			return "May";
			break;
		case 5:
			return "Jun";
			break;
		case 6:
			return "Jul";
			break;
		case 7:
			return "Aug";
			break;
		case 8:
			return "Sep";
			break;
		case 9:
			return "Oct";
			break;
		case 10:
			return "Nov";
			break;
		case 11:
			return "Dec";
			break;
	}
	return "Month out of range 0-11";
}