
document.observe('dom:loaded', function() {
	$$('.date_picker').each(function(s){
		load_date_picker(s.id);
	});
});

function load_date_picker(id){
// <![CDATA[    
	var key = id;
	var json = {};
	json[key] = "Y-ds-m-ds-d";
	datePickerController.createDatePicker({    
        formElements:json,
        statusFormat:"l-cc-sp-d-sp-F-sp-Y",
        fillGrid:true,
        constrainSelection:false,
  		callbackFunctions:{
			"dateset":[recalculate_payment_dates]
		}
	});
// ]]>
}

function recalculate_payment_dates(e){
	if (e.id=='start_date'){
		var start_date = new Date(e.date);
		$$("#schijven .date_picker").each(function(s){
			
			s.value = start_date.getFullYear() + "-"+(start_date.getMonth()+1)+'-'+start_date.getDate();
			start_date.add(3).months();
		}, this);
	}
}
