function CalStartDateDialog(callback, startOn1st)
{
	IDM.Dialog.call(this);

	this.setTitle("Sélection de la date de début");
	this.setButtons([ IDM.Dialog.Button.OK, IDM.Dialog.Button.CANCEL ]);

	this.m_daySelect = null;
	this.m_monthSelect = null;
	this.m_yearSelect = null;

	this.m_callback = callback;
	this.m_startOn1st = startOn1st;
}

CalStartDateDialog.prototype = new IDM.Dialog();

CalStartDateDialog.prototype._constructInner = function(contElt, boxElt)
{
	var p = document.createElement("p");
	boxElt.appendChild(p);
	p.innerHTML = "Choisissez la date de début de votre calendrier.";

	p = document.createElement("p");
	boxElt.appendChild(p);

	var curDate = DateTime.now();
	curDate = new DateTime(1, 1, curDate.getYear() + 1);

	// Day selector
	if (!this.m_startOn1st)
	{
		var select = document.createElement("select");
		select.className = "select-control";

		p.appendChild(select);
		p.appendChild(document.createTextNode(" "));

		for (var i = 1 ; i != 32 ; ++i)
		{
			var sel = (curDate.getDay() == i);
			select.options[i - 1] = new Option("" + i, i, sel, sel);
		}

		this.m_daySelect = NodeRef.create(select);
	}

	// Month selector
	var select = document.createElement("select");
	select.className = "select-control";

	p.appendChild(select);
	p.appendChild(document.createTextNode(" "));

	for (var i = 1 ; i != 13 ; ++i)
	{
		var sel = (curDate.getMonth() == i);
		select.options[i - 1] = new Option(DateTime.getMonthName(i), i, sel, sel);
	}

	this.m_monthSelect = NodeRef.create(select);

	// Year selector
	select = document.createElement("select");
	select.className = "select-control";

	p.appendChild(select);
	p.appendChild(document.createTextNode(" "));

	for (var i = curDate.getYear() - 5 ; i != curDate.getYear() + 21 ; ++i)
	{
		var sel = (curDate.getYear() == i);
		select.options[select.options.length] = new Option("" + i, i, sel, sel);
	}


	this.m_yearSelect = NodeRef.create(select);
}

CalStartDateDialog.prototype._onClickedButton = function(btn)
{
	if (btn == IDM.Dialog.Button.OK)
	{
		var d = 1, m = 1, y = 2000;

		if (this.m_daySelect != null)
			d = parseInt(this.m_daySelect.getElement().value);

		m = parseInt(this.m_monthSelect.getElement().value);
		y = parseInt(this.m_yearSelect.getElement().value);

		var date = new DateTime(d, m, y);

		if (!date.isValid())
		{
			alert("Cette date n'est pas valide.");
			return false;
		}
		else if ((this.m_daySelect == null && date.setDay(DateTime.now().getDay()).isLowerThan(DateTime.now())) ||
				(this.m_daySelect != null && date.isLowerThan(DateTime.now())))
		{
			if (!confirm("La date de début est déjà passée.\nÊtes-vous sûr(e) de vouloir continuer ?"))
				return false;
		}

		this.m_callback(date.toInteger());

		this.close();

		return false;
	}

	return true;
}

