// wait for the DOM to be loaded
$(document).ready(function() {
	dateSetups();
	$("#policyType").change(showOptions);
	if (isExisting(document.qeForm.furthestDestination)) {
		$("#area").change(showOptions);	
	}
});

function dateSetups() {
	$('#startDate').datepicker({showOn:'none', minDate: 0});

	if (isExisting(document.qeForm.endDate)) {
		$('#endDate').datepicker({showOn:'none', minDate: 0});
	}

	if (isExisting(document.qeForm.bookingDate)) {
		$('#bookingDate').datepicker({showOn:'none', maxDate: 0});
	}
}
	
function showOptions() {
	options.success = tripTypeUpdate;
	document.qeForm.qeEvent.value = "getStep_1";
	document.qeForm.qeButtonNextStep.disabled=true;
	$('#qeForm').submit();
	document.qeForm.qeButtonNextStep.disabled=false;
	options.success = validateForm;
	document.qeForm.qeEvent.value = "validateForm";
}

function showActivities() {
	if (isExisting(document.qeForm.activitiesShow)) {
		if (document.qeForm.activitiesShow.checked) {
			$('#row_activitiesShow').hide();
			$('#activitiesHolder').show();
		}
	}
}

function tripTypeUpdate(responseText, statusText)  {
	loadingScreen("end");
	responseText = xmlTidy(responseText);
	$('#qeTripsFormContent').html(responseText);
	addCorners();
	dateSetups();
	// need to rebind
	$("#policyType").change(showOptions);
	if (isExisting(document.qeForm.furthestDestination)) {
		$("#area").change(showOptions);	
	}
	$('#qeForm').ajaxForm(options);
}

function corRedirect() {
	document.qeForm.qeEvent.value = "corRedirect";
	document.qeForm.qeButtonNextStep.disabled=true;
	$('#qeForm').submit();
}