// CONSTRUCTOR for the CalendarPopup Object
function CalendarPopupDD() {
	
	
	
	var c;
	if (arguments.length>0) {
		c = new PopupWindow(arguments[0]);
		}
	else {
		c = new PopupWindow();
		c.setSize(150,175);
		}
	c.offsetX = -152;
	c.offsetY = 25;
	c.autoHide();
	// Calendar-specific properties
	c.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	c.monthAbbreviations = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	c.dayHeaders = new Array("S","M","T","W","T","F","S");
	c.returnFunction = "CP_DDReturnFunction";
	c.returnMonthFunction = "CP_tmpReturnMonthFunction";
	c.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
	c.returnYearFunction = "CP_tmpReturnYearFunction";
	c.weekStartDay = 0;
	c.isShowYearNavigation = false;
	c.displayType = "date";
	c.disabledWeekDays = new Object();
	c.disabledDatesExpression = "";
	c.yearSelectStartOffset = 2;
	c.currentDate = null;
	c.todayText="Close";
	c.cssPrefix="";
	c.isShowNavigationDropdowns=false;
	c.isShowYearNavigationInput=false;
	window.CP_calendarObject = null;
	window.CP_targetInput = null;
	window.CP_dateFormat = "MM/dd/yyyy";
	// Method mappings
	c.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
	c.setReturnFunction = CP_setReturnFunction;
	c.setReturnMonthFunction = CP_setReturnMonthFunction;
	c.setReturnQuarterFunction = CP_setReturnQuarterFunction;
	c.setReturnYearFunction = CP_setReturnYearFunction;
	c.setMonthNames = CP_setMonthNames;
	c.setMonthAbbreviations = CP_setMonthAbbreviations;
	c.setDayHeaders = CP_setDayHeaders;
	c.setWeekStartDay = CP_setWeekStartDay;
	c.setDisplayType = CP_setDisplayType;
	c.setDisabledWeekDays = CP_setDisabledWeekDays;
	c.addDisabledDates = CP_addDisabledDates;
	c.setYearSelectStartOffset = CP_setYearSelectStartOffset;
	c.setTodayText = CP_setTodayText;
	c.showYearNavigation = CP_showYearNavigation;
	c.showCalendar = CP_showCalendar;
	c.hideCalendar = CP_hideCalendar;
	c.getStyles = getCalendarStyles;
	c.refreshCalendar = CP_refreshCalendar;
	c.getCalendar = CP_getCalendar;
	c.select = CP_selectDD;
	c.setCssPrefix = CP_setCssPrefix;
	c.showNavigationDropdowns = CP_showNavigationDropdowns;
	c.showYearNavigationInput = CP_showYearNavigationInput;
	c.copyMonthNamesToWindow();
	// Return the object
	return c;
	}

// Simple method to interface popup calendar with a text-entry box
function CP_selectDD(inputobjn1,inputobjn2, linkname) {
    inputobj1 = document.getElementById(inputobjn1);
    inputobj2 = document.getElementById(inputobjn2);
	if (!window.getDateFromFormat) {
		alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
		return;
		}
	if (this.displayType!="date"&&this.displayType!="week-end") {
		alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
		return;
		}
	if (inputobj1.tagName!="SELECT" || inputobj2.tagName!="SELECT") { 
		alert("calendar.select: Input object passed is not a valid form input object (only SELECTs supported)"); 
		window.CP_targetInput=null;
		return;
		}
	if (inputobj1.disabled || inputobj2.disabled) { return; } // Can't use calendar input on disabled form input!
	window.CP_targetInput1 = inputobj1;
	window.CP_targetInput2 = inputobj2;
	window.CP_calendarObject = this;
	this.currentDate=null;
	var time=0;
	var ym = inputobj1.options[inputobj1.selectedIndex].value.split('-');
    this.currentDate = new Date(ym[0], ym[1]-1, inputobj2.options[inputobj2.selectedIndex].value);
	this.showCalendar(linkname);
}

function CP_DDReturnFunction(y,m,d)
{ 
	if (window.CP_targetInput1!=null&&window.CP_targetInput2!=null) 
	{
		var dt = new Date(y,m-1,d,0,0,0);
		var ym = y+'-'+(m<10?'0':'')+m;
        window.CP_targetInput1.selectedIndex = findOptionsIndex(window.CP_targetInput1, ym);
        window.CP_targetInput2.selectedIndex = findOptionsIndex(window.CP_targetInput2, d);
        //dateChanged(window.CP_targetInput1.form, window.CP_targetInput1.name)
        window.CP_targetInput1.onchange();

	}
	else 
	{
		alert('Use setReturnFunction() to define which function will get the clicked results!'); 
	}
}
	
function findOptionsIndex(select, val)
{
    for (i = 0; i < select.options.length; i++)
        if (select.options[i].value == val)
            return i;
    return select.selectedIndex;
}
