function selectTheActivity(actId) {
	
	$("#actPricesDisplay").empty();
	$("#actPricesDisplay").append("Loading...");
	
	if(actId > 0) {
		$("#actPricesDisplay").load("/doAjax.php", { method: "getActivityPrices", activityId: actId} )
	}
	
};

var calculateActivtyTotal = function() {
	
	
	$("#bookTotalPrice").empty();
	$("#bookTotalPrice").append("Loading...");
	
	var actId = $("#activitySelect").val();
	var places = $("#bookPlaces").val();
	var discountPlaces = $("#bookDiscountPlaces").val();
	
	if(places == "") { places = 0; }
	if(discountPlaces == "") { discountPlaces = 0; }
	
	if(places <= 0 && discountPlaces == 0) {
		$("#bookTotalPrice").empty();
		$("#bookTotalPrice").append("A$0.00");
	} else {
		$("#bookTotalPrice").load("/doAjax.php", { 
													method: "bookingTotalPrice",
		                                            activityId: actId,
		                                            numPlaces: places,
		                                            numDiscount: discountPlaces
												 })
	}
};

var fillSubCategories = function() {
	
	$("#childId").removeOption(/./);
	var parentId =  $("#parentId").val();

	$("#childId").ajaxAddOption("/doAjax.php", {
	  "method" : "getSubCategories",
	  "parentId" : parentId 
	}, false );
};
var fillOperatorList = function() {
	
	$("#opId").removeOption(/./);
	var locId =  $("#locId").val();

	$("#opId").ajaxAddOption("/doAjax.php", {
	  "method" : "getOperatorList",
	  "locId" : locId 
	}, false );
};

var chooseCats = function() {
	
	$("#catIds").removeOption("0");
	
	$("#allCatIds").copyOptions("#catIds");
	
};

var removeCat = function() {
	
	$("#catIds option:selected").each(function() {
			$("#catIds").removeOption( $(this).val() );
	});
	
};

var getValidDays = function() {

	
		
		var actId = $("#activitySelect").val();	
		
		if(actId <=0) {
			$(".date_input").attr("disabled", "disabled");
			return false;
		}
		
		$(".date_input").removeAttr("disabled");
		$.get("/doAjax.php", { 
								method: "getValidDays",
	                            activityId: actId
							  }, function(data) {
							  	data = eval(data);
							  	  loadDateInput(data);
							  }
		);	
	
};

var loadDateInput = function(data) {

		
		$.extend(DateInput.DEFAULT_OPTS, {
		  valid_days: data,
		  /*stringToDate: function(string) {
		    var matches;
		    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
		      return new Date(matches[1], matches[2] - 1, matches[3]);
		    } else {
		      return null;
		    };
		  },
		
		  dateToString: function(date) {
		    var month = (date.getMonth() + 2).toString();
		    var dom = date.getDate().toString();
		    if (month.length == 1) month = "0" + month;
		    if (dom.length == 1) dom = "0" + dom;
		    return date.getFullYear() + "-" + month + "-" + dom;
		  }*/
		  stringToDate: function(string) {
		    var matches;
		    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
		      return new Date(matches[1], matches[2] - 1, matches[3]);
		    } else {
		      return null;
		    };
		  },
		
		  dateToString: function(date) {
		    var month = (date.getMonth() + 1).toString();
		    //var month = (date.getMonth()).toString();
		    var dom = date.getDate().toString();
		    if (month.length == 1) month = "0" + month;
		    if (dom.length == 1) dom = "0" + dom;
		    return date.getFullYear() + "-" + month + "-" + dom;
		  }
		});
		
		$(".date_input").date_input();
};

var getTimeslots = function() {
	
	$("#timeId").removeOption(/./);
	var activityId =  $("#activitySelect").val();
	
	if(activityId <=0) {
		$("#timeId").attr("disabled", "disabled");
		return false;
	}
	
	$("#timeId").removeAttr("disabled");

	$("#timeId").ajaxAddOption("/doAjax.php", {
	  "method" : "getTimeslots",
	  "actId" : activityId
	}, false );
};

var getAvailablePlaces = function() {
	
	var timeslotId = $("#timeId").val();
	var aDate = $(".date_input").val();
	
	if(timeslotId <= 0 || aDate == '') {
		$("#availablePlaces").empty();
		return false;
	}
	
	$.get("/doAjax.php", { 
							method: "getAvailablePlaces",
                            timeId: timeslotId,
                            theDate: aDate
						  }, function(data) {
						  	  $("#availablePlaces").empty();
						  	  $("#availablePlaces").append(data);
						  }
	);		
};