Calendar.setup=function(g){function f(h,i){if(typeof g[h]=="undefined"){g[h]=i}}f("inputField",null);f("displayArea",null);f("button",null);f("eventName","click");f("ifFormat","%Y/%m/%d");f("daFormat","%Y/%m/%d");f("singleClick",true);f("disableFunc",null);f("dateStatusFunc",g.disableFunc);f("firstDay",0);f("align","Br");f("range",[1900,2999]);f("weekNumbers",true);f("flat",null);f("flatCallback",null);f("onSelect",null);f("onClose",null);f("onUpdate",null);f("date",null);f("showsTime",false);f("timeFormat","24");f("electric",true);f("step",2);f("position",null);f("cache",false);f("showOthers",false);var d=["inputField","displayArea","button"];for(var c in d){if(typeof g[d[c]]=="string"){g[d[c]]=document.getElementById(g[d[c]])}}if(!(g.flat||g.inputField||g.displayArea||g.button)){alert("Calendar.setup:\n  Nothing to setup (no fields found).  Please check your code");return false}function b(j){var i=j.params;var h=(j.dateClicked||i.electric);if(h&&i.flat){if(typeof i.flatCallback=="function"){i.flatCallback(j)}else{alert("No flatCallback given -- doing nothing.")}return false}if(h&&i.inputField){i.inputField.value=j.date.print(i.ifFormat);if(typeof i.inputField.onchange=="function"){i.inputField.onchange()}}if(h&&i.displayArea){i.displayArea.innerHTML=j.date.print(i.daFormat)}if(h&&i.singleClick&&j.dateClicked){j.callCloseHandler()}if(h&&typeof i.onUpdate=="function"){i.onUpdate(j)}}if(g.flat!=null){if(typeof g.flat=="string"){g.flat=document.getElementById(g.flat)}if(!g.flat){alert("Calendar.setup:\n  Flat specified but can't find parent.");return false}var e=new Calendar(g.firstDay,g.date,g.onSelect||b);e.showsTime=g.showsTime;e.time24=(g.timeFormat=="24");e.params=g;e.weekNumbers=g.weekNumbers;e.setRange(g.range[0],g.range[1]);e.setDateStatusHandler(g.dateStatusFunc);e.create(g.flat);e.show();return false}var a=g.button||g.displayArea||g.inputField;a["on"+g.eventName]=function(){var h=g.inputField||g.displayArea;var i=g.inputField?g.ifFormat:g.daFormat;var k=false;var j=window.calendar;if(!(j&&g.cache)){window.calendar=j=new Calendar(g.firstDay,g.date,g.onSelect||b,g.onClose||function(l){l.hide()});j.showsTime=g.showsTime;j.time24=(g.timeFormat=="24");j.weekNumbers=g.weekNumbers;k=true}else{if(g.date){j.setDate(g.date)}j.hide()}j.showsOtherMonths=g.showOthers;j.yearStep=g.step;j.setRange(g.range[0],g.range[1]);j.params=g;j.setDateStatusHandler(g.dateStatusFunc);j.setDateFormat(i);if(k){j.create()}j.parseDate(h.value||h.innerHTML);j.refresh();if(!g.position){j.showAtElement(g.button||g.displayArea||g.inputField,g.align)}else{j.showAt(g.position[0],g.position[1])}return false}};
