/*  Copyright Mihai Bazon, 2002, 2003  |  http://dynarch.com/mishoo/
 * ---------------------------------------------------------------------------
 *
 * The DHTML Calendar
 *
 * Details and latest version at:
 * http://dynarch.com/mishoo/calendar.epl
 *
 * This script is distributed under the GNU Lesser General Public License.
 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
 *
 * This file defines helper functions for setting up the calendar.  They are
 * intended to help non-programmers get a working calendar on their site
 * quickly.  This script should not be seen as part of the calendar.  It just
 * shows you what one can do with the calendar, while in the same time
 * providing a quick and simple method for setting it up.  If you need
 * exhaustive customization of the calendar creation process feel free to
 * modify this code to suit your needs (this is recommended and much better
 * than modifying calendar.js itself).
 */Calendar.setup=function(a){function e(a){var b=a.params,c=a.dateClicked||b.electric;c&&b.inputField&&(b.inputField.value=a.date.print(b.ifFormat),typeof b.inputField.onchange=="function"&&b.inputField.onchange()),c&&b.displayArea&&(b.displayArea.innerHTML=a.date.print(b.daFormat)),c&&typeof b.onUpdate=="function"&&b.onUpdate(a),c&&b.flat&&(typeof b.flatCallback=="function"&&b.flatCallback(a)),c&&b.singleClick&&a.dateClicked&&a.callCloseHandler()}function b(b,c){typeof a[b]=="undefined"&&(a[b]=c)}b("inputField",null),b("displayArea",null),b("button",null),b("eventName","click"),b("ifFormat","%Y/%m/%d"),b("daFormat","%Y/%m/%d"),b("singleClick",!0),b("disableFunc",null),b("dateStatusFunc",a.disableFunc),b("dateText",null),b("firstDay",null),b("align","Br"),b("range",[1900,2999]),b("weekNumbers",!0),b("flat",null),b("flatCallback",null),b("onSelect",null),b("onClose",null),b("onUpdate",null),b("date",null),b("showsTime",!1),b("timeFormat","24"),b("electric",!0),b("step",5),b("position",null),b("cache",!1),b("showOthers",!1),b("multiple",null);var c=["inputField","displayArea","button"];for(var d in c)typeof a[c[d]]=="string"&&(a[c[d]]=document.getElementById(a[c[d]]));if(!(a.flat||a.multiple||a.inputField||a.displayArea||a.button)){alert("Calendar.setup:\n  Nothing to setup (no fields found).  Please check your code");return!1}if(a.flat!=null){typeof a.flat=="string"&&(a.flat=document.getElementById(a.flat));if(!a.flat){alert("Calendar.setup:\n  Flat specified but can't find parent.");return!1}var f=new Calendar(a.firstDay,a.date,a.onSelect||e);f.showsOtherMonths=a.showOthers,f.showsTime=a.showsTime,f.time24=a.timeFormat=="24",f.params=a,f.weekNumbers=a.weekNumbers,f.setRange(a.range[0],a.range[1]),f.setDateStatusHandler(a.dateStatusFunc),f.getDateText=a.dateText,a.ifFormat&&f.setDateFormat(a.ifFormat),a.inputField&&typeof a.inputField.value=="string"&&f.parseDate(a.inputField.value),f.create(a.flat),f.show();return!1}var g=a.button||a.displayArea||a.inputField;g["on"+a.eventName]=function(){var b=a.inputField||a.displayArea,c=a.inputField?a.ifFormat:a.daFormat,d=!1,f=window.calendar;b&&(a.date=Date.parseDate(b.value||b.innerHTML,c)),f&&a.cache?(a.date&&f.setDate(a.date),f.hide()):(window.calendar=f=new Calendar(a.firstDay,a.date,a.onSelect||e,a.onClose||function(a){a.hide()}),f.showsTime=a.showsTime,f.time24=a.timeFormat=="24",f.weekNumbers=a.weekNumbers,d=!0);if(a.multiple){f.multiple={};for(var g=a.multiple.length;--g>=0;){var h=a.multiple[g],i=h.print("%Y%m%d");f.multiple[i]=h}}f.showsOtherMonths=a.showOthers,f.yearStep=a.step,f.setRange(a.range[0],a.range[1]),f.params=a,f.setDateStatusHandler(a.dateStatusFunc),f.getDateText=a.dateText,f.setDateFormat(c),d&&f.create(),f.refresh(),a.position?f.showAt(a.position[0],a.position[1]):f.showAtElement(a.button||a.displayArea||a.inputField,a.align);return!1};return f}
