// 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(){
		setupCalendar(this);
		if (this.value == '0000-00-00'){
			this.value = '';
		}
	});
});


function setupCalendar(whichInput){
		// CHECK THE DATE FORMAT
		$(whichInput).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 YYYY-MM-DD");
					this.focus();
				}
			}else{
				this.value=formatDate(rawDate,dateFormat);
			}			
		});
		
		// Call the JQuery Calendar
		$(whichInput).attachDatepicker({appendText: dateFormat.toLowerCase(),dateFormat:'yy-mm-dd',buttonImageOnly:true,showOn:'button',buttonImage:root+'fs_webkit/jquery/calendar/calendar.png'});
}
