function initQuickSearch(){
	//Set Up Date Pickers
	$jq("#eDate").datepicker({ 
		minDate: +8, showAnim: 'blind'
	});
	$jq("#sDate").datepicker({
		minDate: +7, 
		showAnim: 'blind',
		onSelect: function(dateText){
			$jq("#eDate").datepicker("option","minDate",dateText);
			if($jq("#sDate").datepicker("getDate") > $jq("#eDate").datepicker("getDate")){
				$jq("#eDate").datepicker("setDate",$jq("#sDate").datepicker("getDate"));
			}
		}
	});
 
	//Style/setup The Buttons
	$jq("#qcsSubBtn").click(function(){
		
		var formURL = $jq("#CS").attr("action");
		var CruiseLine = $jq("#Line").val();
		var Ship = $jq("#Ship").val();
		var Destinations = $jq("#Dest").val();
		var MinDuration = $jq("#minDur").val();
		var MaxDuration = $jq("#maxDur").val();
		var StartDate = $jq("#sDate").val();
		var EndDate = $jq("#eDate").val();
		
		if (CruiseLine != ""){
			formURL = formURL + "&CruiseLine=" + CruiseLine;
		}
		if(Ship != ""){
			formURL = formURL + "&Ship=" + Ship;
		}
		if(Destinations != ""){
			formURL = formURL + "&Destinations=" + Destinations;
		}
		if(MinDuration != ""){
			formURL = formURL + "&MinDuration=" + MinDuration;
		}
		if(MaxDuration != ""){
			formURL = formURL + "&MaxDuration=" + MaxDuration;
		}
		if(StartDate != ""){
			formURL = formURL + "&StartDate=" + StartDate;
		}
		if(EndDate != ""){
			formURL = formURL + "&EndDate=" + EndDate;
		}
		
		cslURL = "/QS/PHP/csl.php";
				
		cslURL = cslURL + "?vendorID=" + CruiseLine;
		cslURL = cslURL + "&shipID=" + Ship;
		cslURL = cslURL + "&destID=" + Destinations;
		cslURL = cslURL + "&minDays=" + MinDuration;
		cslURL = cslURL + "&maxDays=" + MaxDuration;
		cslURL = cslURL + "&startDate=" + StartDate;
		cslURL = cslURL + "&endDate=" + EndDate;
				
		//$jq.get(cslURL, {vendorID: CruiseLine, shipID: Ship, destID: Destinations, minDays: MinDuration, maxDays: MaxDuration, startDate: StartDate, endDate: EndDate}, document.location.href=formURL);
		
		$jq.ajax({
		type: "GET",
		url: cslURL,
		success: function(){
			document.location.href=formURL;
			}
		});
	});
	
	//Setup The Change Handler For The MinDuration Selector
	$jq("#minDur").change(function(){
		minSel = parseInt($jq("#minDur").val());
		maxSel = parseInt($jq("#maxDur").val());
		
		if (minSel <= maxSel){
			curSel = maxSel;
		}else{
			curSel = minSel + 1;
			if (curSel > 14){
				curSel = 9999;
			}
		}
		
		$jq("#maxDur").empty();
		$jq("#allMaxDurations").find("option").clone().appendTo("#maxDur");
		$jq("#maxDur").find("option").each(function(){
			if(parseInt($jq(this).attr("value")) < minSel){
				$jq(this).remove()
			}
			if(parseInt($jq(this).val()) == curSel){
				$jq(this).attr('selected', 'selected');
			}
		});
	});

	//Make AJAX Call for setup
	$jq.ajax({
		type: "GET",
		url: "/QS/PHP/CruiseSearchDriver.php?action=init",
		dataType: "xml",
		success: initSearch
	});
}

function initSearch(data){
	$jq(data).find('selects').each(function(){
		selectID = $jq(this).find("id").text();
		$jq(this).find("options").each(function(){
			sText = $jq(this).find("text").text();
			sValue = $jq(this).find("value").text();
			sExt = $jq(this).find("ext").text();
			$jq("#"+selectID).append("<option value='"+sValue+"' ext='"+sExt+"'>"+sText+"</option>");
		});
	});
	
	maxDate = $jq(data).find('maxDate').find('date').text();
	$jq("#sDate").datepicker("option","maxDate",maxDate);
	$jq("#eDate").datepicker("option","maxDate",maxDate);
	$jq("#sDate").datepicker("setDate","+90");
	$jq("#eDate").datepicker("setDate","+180");
	
	//Clone The Cruise Ship Selector Options
	$jq("#Ship").find("option").clone().appendTo("#allShips");
	
	//Setup Change Handler For Cruise Line Selector
	$jq("#Line").change(function(){
		clID = $jq("#Line").val();
		$jq("#Ship").empty();
		$jq("#allShips").find("option").clone().appendTo("#Ship");
		if(clID != ""){
			$jq("#Ship").find("option").each(function(){
				if($jq(this).attr("ext") != clID && $jq(this).attr("value") != ""){
					$jq(this).remove();
				}
			});
		}
	});
}

function checkDateFormat(dateString,format){
	var isValid = true;
	try{
		jQuery.datepicker.parseDate(format,dateString,null);
	}
	catch(error){
		isValid = false;
	}
	return isValid;
}

