/**
 * init.js
 * Script to initialize the drop-in calendar on appropriate form elements
 * @author Luke Sneeringer
 * @author Copyright 2007, Live Oak Interactive
 */
var Cal = {
	init: function() {
		$$('.cal_select').each(function(e) {
			// get the base id
			var cal_id_arr = e.id.split('_');
			cal_id_arr.pop();
			var cal_id = cal_id_arr.join('_');
			
			new Insertion.Top(e, '<input name="' + cal_id + '" id="' + cal_id + '" value="' + $F(cal_id + '_formatted') + '" readonly="readonly" class="read-only" />');
			new Insertion.After($(cal_id), '<a href="' + window.location.pathname + '" id="' + cal_id + '_button"><img src="/includes/images/icons/calendar.png" alt="Calendar" /></a>');
			
			Calendar.setup({
				button: cal_id + '_button',
				ifFormat: '%B %e, %Y',
				inputField: cal_id,
				showOthers: true,
				range: Array(1902, 2037),
				weekNumbers  : false,
				singleClick: true,
				dateStatusFunc: Cal.public_status
			});

			Event.observe($(cal_id).form, 'submit', function(ev) {
				$(cal_id).disabled = false;
			});
		});
	}
};

addEvent(window, 'DOMContentLoaded', Cal.init);
