var dateFormat = "mm/dd/yyyy";
var textDateFormat = "(D, M dd yy)";
var stringFormats = new Array();
var USDate=true;
var g_startDay=0;

function createDatepicker(dep_id,arr_id,ow_id,dep_text_id,arr_text_id) {
// dep_id and arr_id parameters are obligatory, any other parameter is optional.
// ex.: createDatepicker("dep_cal","arr_cal","oneway","dep_text","arr_text");
	$("#"+dep_id+", #"+arr_id).datepicker({
		beforeShow:function(inp) {
			if(this.id!=arr_id || !$("#"+dep_id).val()) return {};
			/*	return an empty object if this is not the second calendar or if the first one has no value	*/	
			dMin = $.datepicker.parseDate(dateFormat.replace("yyyy", "yy"), $("#"+dep_id).val());
			/*	creating the left-limit date according to the current dateFormat	*/
			return {minDate:dMin};
		},
		onSelect: function(date, dpObject) {
			d = $(this).datepicker("getDate");
			if (dep_text_id && arr_text_id) {
				$(this.id==dep_id ? "#"+dep_text_id : "#"+arr_text_id).text($.datepicker.formatDate(textDateFormat, d));
				/*	(Th, Jan 15 2009)	*/
			}
			if(this.id==dep_id) {
			/*	if this is the first calendar	*/
				d2 = $.datepicker.parseDate(dateFormat.replace("yyyy", "yy"), $('#'+arr_id).val());
				if(d2 && d > d2) {
				/*	and first date is greater than the second one	*/
					d2.setTime(d.getTime()+60*60*24*5*1000);
	 				$("#"+arr_id).val($.datepicker.formatDate(dateFormat.replace("yyyy", "yy"), d2));
					/*	setting up the input value	*/
					if (arr_text_id) { $("#"+arr_text_id).html($.datepicker.formatDate(textDateFormat, d2)); }
							/*	setting up the span text	*/
				}
			}
		},
		onClose:function(A) {
			$("#submit_search").focus();
		}
	});
	if (ow_id) {
		$("#"+ow_id).click(function() {
			if(this.checked) {
				$("#"+arr_id).css("backgroundColor","#ddd").datepicker("disable");
			} else {
				$("#"+arr_id).css("backgroundColor","#fff").datepicker("enable");
			}
		});
	}
};

$(document).ready(function() {
	$.datepicker.setDefaults({
		showOn:"both",
		buttonImageOnly:true,
		buttonImage:"/datepicker/images/cal.gif",
		buttonText:"",
		hideIfNoPrevNext:true,
		highlightWeek:true,
		showStatus:true,
		prevText:'<span title="&lt; Prev">&nbsp;&nbsp;&nbsp;&nbsp;</span>',
		nextText:'<span title="Next &gt;">&nbsp;&nbsp;&nbsp;&nbsp;</span>',
		/*	prevText, nextText: images should be groupped with the main calendar background image	*/
		defaultDate:+7,
		minDate:0,
		maxDate:"2y",
		mandatory:true,
		changeFirstDay:false,
		changeMonth:false,
		changeYear:false,
		numberOfMonths:2,
		speed:"normal"
	});
	// createDatepicker("dep_cal","arr_cal","oneway","dep_text","arr_text");
});