/**
 * $Id: calendar.js,v 1.2 2009/10/06 13:56:42 gdubourguet Exp $
 * @fileoverview Zapatec Calendar widget. Include this file in your HTML page.
 * Includes Zapatec Calendar modules: calendar-core.js, calendar-date-core.js, calendar-setup.js.
 *
 * <pre>
 * Copyright (c) 2004-2006 by Zapatec, Inc.
 * http://www.zapatec.com
 * 1700 MLK Way, Berkeley, California,
 * 94709, U.S.A.
 * All rights reserved.
 * </pre>
 */

/**
 * @private Get path to this script
 */
if (!window.Zapatec || (Zapatec && !Zapatec.include)) 
{
	alert("You need to include zapatec.js file!");
} 
else 
{
	// modif WD
	Zapatec.calendarPath = Zapatec.zapatecPath + '../'; //Zapatec.getPath("Zapatec.CalendarWidget");

	// Include required scripts
	Zapatec.Transport.include(Zapatec.calendarPath + 'src/calendar-core.js', "Zapatec.Calendar");
	Zapatec.Transport.include(Zapatec.calendarPath + 'src/calendar-date-core.js');
	Zapatec.Transport.include(Zapatec.calendarPath + 'src/calendar-setup.js');

	document.write('<style type="text/css">@import url(' + Zapatec.calendarPath + 'themes/default.css);</style>');
}

window.calendar = null;		/**< global object that remembers the calendar */

// initialize the preferences object;
// embed it in a try/catch so we don't have any surprises
try {
	Zapatec.Calendar.loadPrefs();
} catch(e) {};

Zapatec.Utils.addEvent(window, 'load', Zapatec.Utils.checkActivation);

/* ------------------ modif WD -------------------- */

// createCalendar
function createCalendar(id, statusHandler, buttonId)
{
	var update = function(cal) {
		if (cal.dateClicked) 
		{
			cal.inputField.value = cal.currentDate.print(cal.dateFormat);
			if (typeof cal.inputField.onchange == "function")
				cal.inputField.onchange(cal.inputField);
			cal.hide();
		}
	};

	var dateFmt = "%d-%m-%Y", 
		el = document.getElementById(id);

	cal = new Zapatec.Calendar(1, Date.parseDate(el.value, dateFmt), update, function(c) { c.hide(); });
	cal.id = id;
	cal.time24 = true;
	cal.helpButton = false;
	cal.disableDrag = true;
	cal.yearNav = false;
	cal.setDateFormat(dateFmt);
	cal.inputField = el;
	cal.update = update;
	cal.minYear = (new Date()).getFullYear();
	cal.maxYear = (new Date()).getFullYear() + 1;
	cal.create();
	cal.setDateStatusHandler(statusHandler);

	el.calendar = cal;
	el.readOnly = true;
	el.onclick = function() 
	{
		if (this.blur) this.blur();
		if (this.disabled || !this.calendar) return;
		if (this.value && (d = Date.parseDate(this.value, dateFmt))) this.calendar.setDate(d);
		this.calendar.showAtElement(this);
		return false;
	}
	
	if ((typeof buttonId != "undefined") && (btn = document.getElementById(buttonId)))
	{
		btn.onmouseover = function() { this.style.cursor = 'pointer'; };
		btn.onmouseout = function() { this.style.cursor = 'default'; }; 
		btn.onclick = function() { document.getElementById(id).onclick(); }
	}
	
	cal.setDate = function (d) { this._init(this.firstDayOfWeek, d, true); this.inputField.value = d.print(this.dateFormat); }
	cal.empty = function () { return (!this.date || !this.inputField.value.length); }
	return cal;
}
/* ------------------ /modif WD -------------------- */
