// CALENDAR LOADER
// THIS IS A BRIDGE BETWEEN THE CALENDAR AND OUR GENERIC CALENDAR CALLING SYSTEM

// TO IMPLEMENT A CALENDAR GIVE AN INPUT BOX A CLASS OF "fs_calendar"


dateFormat = 'yyyy-MM-dd';

$(document).ready(function(){
	$(".datepicker").each(function(){
		addDatePicker(this);
	});
});


function addDatePicker(to){
	var dateFormat1 = 'yy-mm-dd';
	var dateFormat2 = 'yyyy-MM-dd';

	$(to).blur(
		function(){
			// check the date format
			rawDate = parseDate(this.value);
			if(rawDate==null){
				if (this.value.length!=0){
					alert("Date string does not match any recognized formats. Try "+dateFormat2);
					this.focus();
				}
			}else{
				this.value=formatDate(rawDate,dateFormat2);
			}			
		}
	);
	// Call the JQuery Calendar
	$(to).datepicker(
		{ 
			constrainInput: true,
			showOn: 'button', 
			buttonImage: '/fs_webkit/jquery/calendar.ui/calendar.png', 
			buttonImageOnly: true,
			dateFormat: dateFormat1,
			changeMonth: true,
			changeYear: true
		}
	);
	//$(to).attachDatepicker({buttonImageOnly:true,showOn:'button',buttonImage:'images/calendar.png'});
}
