/**
* Core UI methods
* History
* Version		Date		By		Description
*----------------------------------------------------------------
* 1.1		03/29/2004		ml		Fixes to createWeekDaysList() and createMonthList() to get round IE bug in which
*									selected state was applied to the wrong object during array construction.
*									Rewrote all create*List methods as for...next loops for efficiency, file size and readability.
* 1.0		03/09/2004		ml		New (released with fixes 08/24/2004)
*/

/**
* Create and populate list box with the list of US states.  Current contents of list box will
* be cleared, and the list repopulated.  1st line is a blank.
* @param listObject - list to add to
* @param selectNewMexico if true will select New Mexico by default.
* @return void
*/
function createStatesList(listObject, selectNewMexico){
	var stateOptions = listObject.options;
	var shortCode = ["", "AL", "AK", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI","MN", "MS", "MO", "MT","NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"];
	var longDesc = ["", "Alabama", "Alaska", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Idaho", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan ",	"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",	"North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];
	var idx = 0;

	stateOptions.length = 0;
	
	for(idx = 0; idx < shortCode.length; idx++){
		stateOptions[stateOptions.length] = new Option(longDesc[idx], shortCode[idx], false, false);
	}
	
	if(selectNewMexico == true)
		listObject.selectedIndex = 30;
}

/**
* Populate a list object with the days of the week.  Current contents of list box will
* be cleared, and the list repopulated.  1st line is a blank.
* @param listObject - list to add
* @param shouldAbbreviate - if true, 1st 3 letters of each week are used in list.  Note that the
* value of the option is still set to the long version.  If shouldAbbreviate == false, then
* the long version is used as both text representation and value
* @param daySelected the index of the day to be selected initially.  Note that to select a day, it should
* be a number between 1 and 7.  To select blank as the default date, use 0.
* @param returnIndex - if true, the index of the selected item is returned (note that this will be between 0 and 7
* to include selection of blank line).  If false, the full text value is returned.
* @return void
*/
function createWeekDaysList(listObject, shouldAbbreviate, daySelected, returnIndex){
	var weekOptions = listObject.options;
	var dayArray =  ["", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	var dayIdx = 0;
	
	weekOptions.length = 0;
	
	for(dayIdx == 0; dayIdx < dayArray.length; dayIdx++){
		weekOptions[weekOptions.length] = new Option((shouldAbbreviate == true ? dayArray[dayIdx].substring(0, 3) : dayArray[dayIdx]), (returnIndex == true ? dayIdx : dayArray[dayIdx]), false, false);
	}
	
	weekOptions[daySelected].selected = true;
}

/**
* Populate a list object with the months of the year.  Current contents of list box will
* be cleared, and the list repopulated.  1st line is a blank.
* @param listObject - list to add
* @param shouldAbbreviate - if true, 1st 3 letters of each month are used in list.  Note that the
* value of the option is still set to the long version.  If shouldAbbreviate == false, then
* the long version is used as both text representation and value
* @param daySelected the index of the month to be selected initially.  Note that to select a month, it should
* be a number between 1 and 12.  To select blank as the default date, use 0.
* @param returnIndex - if true, the index of the selected item is returned (note that this will be between 0 and 12
* to include selection of blank line).  If false, the full text value is returned.
* @return void
*/
function createMonthList(listObject, shouldAbbreviate, monthSelected, returnIndex){
	var monthOptions = listObject.options;
	var monthArray = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var monthIdx = 0;

	monthOptions.length = 0;

	for(monthIdx = 0; monthIdx < monthArray.length; monthIdx++){
		state = monthIdx == monthSelected;
		monthOptions[monthOptions.length] = new Option((shouldAbbreviate == true ? monthArray[monthIdx].substring(0, 3) : monthArray[monthIdx]), returnIndex == true ? monthIdx : monthArray[monthIdx], false, false);
	}
	monthOptions[monthSelected].selected = true;
}