function ShowAdvSearch() {
	var t = "S";
	var f = document.myDates;
	for (var i=0; i < f.qstab.length; i++) {
		if (f.qstab[i].checked) {
			t = f.qstab[i].value;
			break;
		}
	}

	var loadDatePicker = function() {
		if ($('#ButtonDatepickerA_Modal').length > 0) {
			//if ButtonDatepickerA_Modal was found, set hidden inputs

			//save the selected Arrival date value options to variables
			var moA = $("#myDates select[name=MonthA]").val();  //$("select[name=MonthA]").val();
			var dayA = $("#myDates select[name=DayA]").val();  //$("select[name=DayA]").val();
			var yrA = $("#myDates select[name=YearA]").val();  //$("select[name=YearA]").val();
			var ArrivalDT = moA + "/" + dayA + "/" + yrA;
			MakeDateSelection_Modal('A', ArrivalDT)
			$("#ButtonDatepickerA_Modal").attr("value", ArrivalDT);

			//save the selected Departure date value options to variables
			var moD = $("#myDates select[name=MonthD]").val(); //$("select[name=MonthD]").val();
			var dayD = $("#myDates select[name=DayD]").val();  //$("select[name=DayD]").val();
			var yrD = $("#myDates select[name=YearD]").val();  //$("select[name=YearD]").val();
			var DepartureDT = moD + "/" + dayD + "/" + yrD;
			MakeDateSelection_Modal('D', DepartureDT)
			$("#ButtonDatepickerD_Modal").attr("value", DepartureDT);
		}

		//attach the JQuery UI DatePicker widget to the hidden input ButtonDatePickerA_Modal
		$('#ButtonDatepickerA_Modal').datepicker({
			showOn: 'button',
			buttonImage: '/images/calendar_icon2.gif',
			buttonImageOnly: true,
			dateFormat: 'm/d/yy',
			maxDate: '+1y',
			minDate: new Date(),
			onSelect: function(dateText, inst) {
				//Datepicker just changed the value of our hidden input, select date value options for arrival date
				MakeDateSelection_Modal('A', $(this).val());

				//save selected arrival date to curDayA
				var curDayA = $("#myAdvSearch select[name=DayA]").val();

				//if curDayA = 30, use 30 as the new Departure day, else use the sum of curDayA + 1
				var newDateD = (curDayA == "30") ? newDateD = $("#myAdvSearch select[name=MonthA]").val() + "/30/" + $("#myAdvSearch select[name=YearA]").val() : newDateD = $("#myAdvSearch select[name=MonthA]").val() + "/" + (parseInt(curDayA) + 1) + "/" + $("#myAdvSearch select[name=YearA]").val();

				//set the hidden input value for departure date to the calculated month/day/year
				$("#ButtonDatepickerD_Modal").attr("value", newDateD);

				//select date value options for departure date using new calculated month/day/year
				MakeDateSelection_Modal('D', newDateD);
			}
		});

		//attach the JQuery UI DatePicker widget to the hidden input ButtonDatePickerD
		$('#ButtonDatepickerD_Modal').datepicker({
			showOn: 'button',
			buttonImage: '/images/calendar_icon2.gif',
			buttonImageOnly: true,
			dateFormat: 'm/d/yy',
			maxDate: '+1y',
			minDate: new Date(),
			onSelect: function(dateText, inst) { MakeDateSelection_Modal('D', $(this).val()); }
		});

		function MakeDateSelection_Modal(dateType, pickedDate) {

			//create array from the date sections of the pickedDate value
			var dateArray = pickedDate.split("/");

			//begin setting either the Arrival (dateType = A) or Departure (dateType = D) date select options
			$("#myAdvSearch select[name=Month" + dateType + "]").children("option").each(function() {

				//loop through each child, removing the selected attribute
				$(this).removeAttr("selected");

				//if the current Month value equals the month passed in pickedDate, set the selected attribute of the option
				if ($(this).attr("value") == dateArray[0])
					$(this).attr("selected", "selected");
			});

			$("#myAdvSearch select[name=Day" + dateType + "]").children("option").each(function() {

				//loop through each child, removing the selected attribute
				$(this).removeAttr("selected");

				//if the current Month value equals the month passed in pickedDate, set the selected attribute of the option
				if ($(this).attr("value") == dateArray[1])
					$(this).attr("selected", "selected");
			});

			$("#myAdvSearch select[name=Year" + dateType + "]").children("option").each(function() {

				//loop through each child, removing the selected attribute
				$(this).removeAttr("selected");

				//if the current Month value equals the month passed in pickedDate, set the selected attribute of the option
				if ($(this).attr("value") == dateArray[2])
					$(this).attr("selected", "selected");
			});
		}
	}
	
	switch (t) {
		case "S":
			$("#adv-search")
				.removeClass("adv-search-A")
				.removeClass("adv-search-H")
				.addClass("adv-search-S")
				.jqm({ ajax: "/ajax/ajax_get_advanced_search.asp?t=S&x=" + Math.random()
						 , ajaxText: "<div align=\"center\" style=\"position:relative;top:100px\"><img src=\"/images/ajax-loader3.gif\" alt=\"loading...\" width=\"50\" height=\"50\" /><br /><b>loading...</b></div>"
						 , onLoad: loadDatePicker
				})
				.jqmShow();
			break;
		case "A":
			$("#adv-search")
				.removeClass("adv-search-S")
				.removeClass("adv-search-H")
				.addClass("adv-search-A")
				.jqm({ajax: "/ajax/ajax_get_advanced_search.asp?t=A&x="+Math.random()
						 , ajaxText: "<div align=\"center\" style=\"position:relative;top:100px\"><img src=\"/images/ajax-loader3.gif\" alt=\"loading...\" width=\"50\" height=\"50\" /><br /><b>loading...</b></div>"
						 , onLoad: loadDatePicker
			    })
				.jqmShow();
			break;
		case "H":
		case "P":
			$("#adv-search")
				.removeClass("adv-search-S")
				.removeClass("adv-search-A")
				.addClass("adv-search-H")
				.jqm({ajax: "/ajax/ajax_get_advanced_search.asp?t=H&x="+Math.random()
						 , ajaxText: "<div align=\"center\" style=\"position:relative;top:100px\"><img src=\"/images/ajax-loader3.gif\" alt=\"loading...\" width=\"50\" height=\"50\" /><br /><b>loading...</b></div>"
						 , onLoad: loadDatePicker		 
			    })
				.jqmShow();
			break;
	}
}
function CheckForm08(f) {
	for (var i=0; i < f.qstab.length; i++) {
		if (f.qstab[i].checked) {
			f.tab.value = f.qstab[i].value;
			break;
		}
	}
	if (f.tab.value == "P") {
		f.action = "/vacation_packages.asp";
	} else {
		f.action = "/listings.asp";
	}
	f.submit();
}
function CheckForm(f) {
	if ((f.NumTravelers.value.length == 0) && (f.list.value == "Y")) {
		f.NumTravelers.focus();
		alert("Please enter the number of travelers.");
		return void(0);
	}
	f.submit();
}
function ShowDetails(t,id) {
	var f = document.myDates;
	f.tab.value = t;
	f.ID.value = id;
	if (f.list != null) {
		f.list.value = "N";
	}
	f.action = "/details.asp";
	f.submit();
}
function SyncDates(f) {
	var dA = new Date(f.MonthA.options[f.MonthA.selectedIndex].value+"/"+f.DayA.options[f.DayA.selectedIndex].value+"/"+f.YearA.options[f.YearA.selectedIndex].value);
	var dD = new Date();
	dD = dA;
	dD.setDate(dD.getDate() + 1);
	f.MonthD.selectedIndex = dD.getMonth();
	f.DayD.selectedIndex = dD.getDate()-1;
	f.YearD.selectedIndex = dD.getFullYear()-f.YearD.options[0].value;
}
function showCal(x) {
	var b;
	if (x==0) {
		if ((b=document.getElementById("cal1"))!=null) {
			b.style.display="none";
		}
		if ((b=document.getElementById("cal2"))!=null) {
			b.style.display="none";
		}
		if ((b=document.getElementById("cal3"))!=null) {
			b.style.display="none";
		}
		if ((b=document.getElementById("cal4"))!=null) {
			b.style.display="none";
		}
		return;
	}
	if (x==1) {
		if ((b=document.getElementById("cal2"))!=null) {
			b.style.display="none";
		}
	} else if (x==2) {
		if ((b=document.getElementById("cal1"))!=null) {
			b.style.display="none";
		}
	} else if (x==3) {
		if ((b=document.getElementById("cal4"))!=null) {
			b.style.display="none";
		}
	} else if (x==4) {
		if ((b=document.getElementById("cal3"))!=null) {
			b.style.display="none";
		}
	}
	if ((b=document.getElementById("cal"+x))!=null) {
		var f=null;
		if (x==1) {
			f=document.myDates;
			b.src="/calendar_iframe.asp?typ=A&dt="+f.MonthA[f.MonthA.selectedIndex].value+"/"+f.DayA[f.DayA.selectedIndex].value+"/"+f.YearA[f.YearA.selectedIndex].value+"&f="+f.name;
		} else if (x==2) {
			f=document.myDates;
			b.src="/calendar_iframe.asp?typ=D&dt="+f.MonthD[f.MonthD.selectedIndex].value+"/"+f.DayD[f.DayD.selectedIndex].value+"/"+f.YearD[f.YearD.selectedIndex].value+"&f="+f.name;
		} else if (x==3) {
			f=document.myAdvSearch;
			b.src="/calendar_iframe.asp?typ=A&dt="+f.MonthA[f.MonthA.selectedIndex].value+"/"+f.DayA[f.DayA.selectedIndex].value+"/"+f.YearA[f.YearA.selectedIndex].value+"&f="+f.name;
		} else if (x==4) {
			f=document.myAdvSearch;
			b.src="/calendar_iframe.asp?typ=D&dt="+f.MonthD[f.MonthD.selectedIndex].value+"/"+f.DayD[f.DayD.selectedIndex].value+"/"+f.YearD[f.YearD.selectedIndex].value+"&f="+f.name;
		}
		if (b.style.display=="") {
			b.style.display="none";
		} else {
			b.style.display="";
		}
	}
}
