/***********************************************/
/* FULFILLMENT.JS : FULFULLMENT MODULE         */
/* COPYRIGHT(C) 2009-2010 SPINNAKER360 PTE LTD */
/***********************************************/
/**** FULFILLMENT MAIN BRANCH ****/
function processFulfill(process, productID, attributes, postAction, change){
// processFulfill() : process fulfillment
// PARAM process : process to do
//	     productID : product ID (if any)
//	     attributes : related attributes (if any, products, fulfillment mode, payment mode, etc...)
//	     postAction : action to perform after fulfillment mode
//       change : [flag] change location OR payment mode

	// (A) PROCESS DATA
	var proceed = false, data, paymentMode, fulfill, mode, req;

	switch(process){
		// [PROCESS 0] : CHECK IF FULFILLMENT MODE IS CHOSEN
		case 0:
			data = { "action" : "process0" };
			req = new Request({
				url: 'ajax_fulfill.php', async: false,
				onSuccess: function(response){
					// (0.1) FULFILLMENT NOT CHOSEN
					if (response == "0"){ processFulfill(1, productID, attributes, postAction); }
					// (0.2) FULFILLMENT CHOSEN
					else { processPostAction(productID, attributes, postAction); }
				}
			}).post(data);
			break;

		// [PROCESS 1] : SHOW CC/CASH, PICKUP/DELIVER POPUP
		case 1:
			data = {
				"action" : "process1",
				"productID" : productID,
				"postAction" : postAction
			};
			if(attributes){
				$extend(data, { "attributes" : attributes });
			}
			proceed = true;
			break;

		// [PROCESS 2] : SET/CHANGE PAYMENT MODE
		case 2:
			data = {
				"action" : "process2",
				"productID" : productID,
				"postAction" : postAction
			};
			if(attributes){
				$extend(data, { "attributes" : attributes });
			}

			// CHANGE PAYMENT MODE
			if(change){
				$extend(data, { "mode" : attributes });
				$extend(data, { "change" : 1 });
			}
			// OR SET PAYMENT MODE
			else {
				fulfill = $('fulfillPickup').checked ? "pickup" : "deliver";
				if($('fulfillPayCC').checked){
					paymentMode = 'cc';
				} else if($('fulfillPayCash').checked){
					paymentMode = 'cash';
				} else {
					paymentMode = 'wt';
				}
				$extend(data, { "paymentMode" : paymentMode });
			}

			req = new Request({
				url: 'ajax_fulfill.php', async: false,
				onSuccess: function(response){
					// CHANGE PAYMENT MODE
					if(change){
						if(popup.open){ popup.hide(); }
						showCart(6);
					}
					// SET PAYMENT MODE
					else {
						if(fulfill == "pickup"){
							processFulfill(3, productID, attributes, postAction);
						} else {
							processFulfill(4, productID, attributes, postAction);
						}
					}
				}
			}).post(data);
			break;

		// [PROCESS 3] : PICKUP LOCATION & TIME POPUP
		case 3:
			data = {
				"action" : "process3",
				"productID" : productID,
				"postAction" : postAction
			};
			if(attributes){
				$extend(data, { "attributes" : attributes });
			}

			// CHANGE PICKUP LOCATION
			if(change){
				$extend(data, { "change" : 1 });
			}
			proceed = true;
			break;

		// [PROCESS 4] : DELIVERY LOCATION & TIME POPUP
		case 4:
			data = {
				"action" : "process4",
				"productID" : productID,
				"postAction" : postAction
			};
			if($defined(attributes)){
				$extend(data, { "attributes" : attributes });
			}
			if(change){
				$extend(data, { "change" : 1 });
			}
			proceed = true;
			break;

		// [PROCESS 5] : PROCESS SET FULFILLMENT LOCATION & TIME
		case 5:
			// [PROCESS 5A] CHECK FOR VALID TIME FIRST (SELECTED TIME SLOT HAS NOT EXPIRED)
			var pass = true;
			if($('validUnix')){
				data = {
					"action" : "checkFulfillValid",
					"validTill" : $('validUnix').value
				};
				req = new Request({
					url: 'ajax_fulfill.php', async: false,
					onRequest: function(){
						if($defined($('fulfillBack'))){ $('fulfillBack').disabled = true; }
						$('fulfillDone').disabled = true;
					},
					onSuccess: function(response){
						if(response=="0"){
							alert("Your selected time has expired!\nPlease select another time slot.");
							$('fulfillBack').disabled = false;
							$('fulfillDone').disabled = true;
							pass = false;
						}
					}
				}).post(data);
			}

			if(pass){
				// [PROCESS 5B] SET FULFILLMENT MODE
				// [PROCESS 5B.1] INTELLIGENCE GATHERING
				mode = $('fulfillMode').value;
				data = {
					"action" : "process5",
					"date" : $('selectedDate').value,
					"time" : $('selectedHr').value + ":" + $('selectedMin').value,
					"orderLimit" : $('fulfillOrderLimit').value,
					"mode" : mode
				};
				if($('validUnix')){
					data = $extend({ "valid" : $('validUnix').value }, data);
				}
				if(mode == "pickup"){
					data = $extend({ "location" : $('fulfillLocation').value }, data);
				} else {
					data = $extend({
						"fulfillDeliverType" : $('fulfillDeliverType').value,
						"location" : $('fulfillLocation').value,
						"fulfillUnit" : $('fulfillUnit').value,
						"fulfillDeliverStore" : $('deliverStore').value,
						"minOrder" : $('fulfillMinOrder').value,
						"deliveryCharge" : $('fulfillDeliverCharge').value,
						"freeDeliverZone" : $('fulfillFreeDeliver').value
					}, data);
				}
				// [WS][23 JUN 2011] NO WIRELESS CC FOR ON FOOT
				if($('noWT')){
					data = $extend({ "noWT" : 1 }, data);
				}
				// [PROCESS 5B.2] SEND TO INTELLIGENCE AGENCY
				req = new Request({
					url: 'ajax_fulfill.php', async: false,
					onRequest: function(){
						if($defined($('fulfillBack'))){ $('fulfillBack').disabled = true; }
						$('fulfillDone').disabled = true;
						$('fufillSaveStatus').set("html", "<img src='images/spinnerSmall.gif' alt=''/>");
					},
					onSuccess: function(response){
						// [PROCESS 5B.3] INTELLIGENCE AGENCY REPLY - CHEATERS ABOUND?
						if(response=="1"){
							// [PROCESS 5C] PRIME TIME BOMB
							if($defined($('validTimeStamp'))){
								timeBomb = Date.parse($('validTimeStamp').value);
								timeSync();
							} else {
								timeBomb = null;
								$('fulfillExpireWrapper').setStyle("display", "none");
								$('fulfillExpire').setStyle("display", "none");
							}
							// CONTINUE WITH POST ACTION
							processPostAction(productID, attributes, postAction);
						} else {
							if($defined($('fulfillBack'))){ $('fulfillBack').disabled = false; }
							$('fulfillDone').disabled = false;
							$('fufillSaveStatus').set("html", "<img src='images/cross.png' alt=''/> Error setting delivery time, please try another time slot.");
						}
					}
				}).post(data);
			}
			break;
	}

	// (B) DISPLAY POPUP
	if(proceed){
		popup.onShow = function(){ initToolTip(); };
		popup.setMode("ajax", "ajax_fulfill.php", data);
		popup.show();
	}
}

function processPostAction(productID, attributes, postAction) {
// processPostAction() : process post action (from fulfillment mode or hot item check)
// PARAM productID : product ID
//       attributes : product related attributes (if any)
//       postAction : action to perform after fulfillment mode

	var split, bread, build, selection;

	switch (postAction) {
		// Forward to "Show Cart"
		case "showCart":
			if(popup.open){ popup.hide(); }
			updateSneak();
			showCart(attributes);
			break;

		// Forward to "Redirect and show cart"
		case "redirectShowCart":
			location.href='menu.php?show=1';
			break;

		// Forward to "Use Previous Order"
		case "reorder":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			checkPreviousOrder(attributes);
			break;

		// Forward to "Customize Sub"
		case "sub":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			chooseSub(productID, attributes);
			break;

		/*
		// Forward to "Customize Breakfast Sub"
		case "breakfast":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			chooseBreakfast(productID);
			break;
		*/

		// Forward to "Customize Lunchbox"
		case "lunchbox":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			chooseLunchbox(productID, attributes);
			break;

		// Forward to "Customize Platter"
		case "platter":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			// Split [0] size [1] bread [2] build
			split = attributes.split('#');
			bread = split[1] != "0";
			build = split[2] != "0";
			choosePlatter(productID, parseInt(split[0], 10), bread, build);
			break;

		// Forward to "Customize Cookie Platter"
		case "cookiePlatter":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			chooseCookie(productID);
			break;

		// Forward to "Add Drink To Cart"
		case "drinks":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			var qtySplit = attributes.split('*');
			var option = qtySplit[0];
			var qty = qtySplit[1];
			addDrinkToCart(productID, option, qty);
			popup.hide();
			break;

		// Forward to "Add Snack To Cart"
		case "snack":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			var qtySplit = attributes.split('*');
			var option = qtySplit[0];
			var qty = qtySplit[1];
			addSnackToCart(productID, option, qty);
			popup.hide();
			break;

		// Forward to "Select Cookie"
		case "cookie":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			selectCookie(productID, '', attributes);
			break;

		// Forward to "Select Party Snacks"
		case "party":
			if($defined($('fulfillCat'))){
				updateProductCatalog($('fulfillCat').value);
			}
			selectParty(productID, '', attributes);
			break;
	}
}

/**** PICKUP BRANCH PROCESSES ****/
// [PROCESS 3A] SHOW DATE/TIME SELECTORS
function getStoreSelection(storeID){
// getStoreSelection() : show available date/time selections for store
// PARAM storeID : store ID

	$('fulfillDone').disabled = true;
	if(storeID){
		var data = {
			"action" : "storeSelection",
			"storeID" : storeID
		};

		var req = new Request({
			url: 'ajax_fulfill.php', async: false,
			onRequest: function(){
				$('fufillSaveStatus').set("html", "");
				$('fulfillStoreStatus').set("html", "<img src='images/spinnerSmall.gif' /> Retrieving store...");
			},
			onSuccess: function(response){
				$('fulfillStoreStatus').set("html", response);
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				if($('selectedDate')){
					var cal = new CalendarEightysix('selectedDateShow', {
						'format': '%d %b %Y',
						'minDate': (new Date()).format('%Y-%m-%d'), // today's date
						'maxDate': $('advanceOrderDateMax').value,
						'disallowUserInput': true,
						'pickFunction': changeDate
					});
					checkDate(storeID, $('selectedDate').value);
				}
			}
		}).post(data);
	} else {
		$('fulfillStoreStatus').set("html", "<div class='errorsign'>Please select a store.</div>");
	}
}

// [PROCESS 3B] CHECK SELECTED PICKUP DATE
function checkDate(storeID, date){
// checkDate() : check if selected date is open for pickups
// PARAM storeID : selected store ID
//       date : selected date

	// SET THE "NAME" OF THE SELECTED DATE
	var minDate = (new Date()).format('%Y-%m-%d'); // today's date
	var dateString = "";
	if(minDate==$('selectedDate').value){
		dateString = "(today)";
	} else {
		var mooDate = new Date();
		mooDate.parse($('selectedDate').value);
		dateString = "("+mooDate.format("%A")+")";
	}
	$('dateString').set("html", dateString);
	var data = {
		"action" : "checkPickupDate",
		"storeID" : storeID,
		"date" : date
	};
	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fufillSaveStatus').set("html", "");
			$('conflictstatusPre').set("html", "<img src='images/spinnerSmall.gif' /> Checking store status...");
			$('conflictstatusPost').set("html", "");
		},
		onSuccess: function(response){
			$('conflictstatusPre').set("html", response);
			if($('combatFit').value==1){
				getHourBounds(storeID, date);
			} else {
				$('fulfillDone').disabled = true;
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				$('selectedHr').set("html", "<option>--</option>");
				$('selectedMin').set("html", "<option>--</option>");
			}
		}
	}).post(data);
}

function changeDate(){
// changeDate() : handles date change in pickup fulfillment

	var dateStamp = new Date.parse($('selectedDateShow').value).format("%Y-%m-%d");
	$('selectedDate').value = dateStamp;
	checkDate($('fulfillLocation').value, $('selectedDate').value);
}

// [PROCESS 3C] GET SELECTABLE HOURS RANGE
function getHourBounds(storeID, date) {
// getHourBounds() : get selectable hours range for selected pickup store
// PARAM storeID : selected store ID
//       date : selected date

	var data = {
		action	: 'getHourBounds',
		storeID	: storeID,
		date	: date
	};

	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fufillSaveStatus').set("html", "");
			$('selectedHr').disabled = true;
			$('selectedMin').disabled = true;
			$('conflictstatusPost').set("html", "<img src='images/spinnerSmall.gif' /> Checking store status...");
		},
		onSuccess: function(response) {
			if(response=="NA"){
				$('fulfillDone').disabled = true;
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				$('selectedHr').set("html", "<option>--</option>");
				$('selectedMin').set("html", "<option>--</option>");
				$('conflictstatusPost').set("html", "<div class='errorsign'>Store is unable to handle orders for selected date.</div>");
			} else {
				$('selectedHr').set("html", response);
				$('selectedHr').disabled = false;
				getMinBounds(storeID, date, $('selectedHr').value);
			}
		}
	}).post(data);
}

// [PROCESS 3D] GET SELECTABLE MINS RANGE
function getMinBounds(storeID, date, hr) {
// getMinBounds() : get selectable min range for selected pickup store
// PARAM storeID : selected store ID
//       date : selected date
//       hr : selected hr

	var data = {
		action	: 'getMinBounds',
		storeID	: storeID,
		date	: date,
		hr		: hr
	};

	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fufillSaveStatus').set("html", "");
			$('selectedMin').disabled = true;
		},
		onSuccess: function(response){
			$('selectedMin').set("html", response);
			$('selectedMin').disabled = false;
			checkPickupTime();
		}
	}).post(data);
}

// [PROCESS 3E] CHECK SELECTED PICKUP DATE/TIME
function checkPickupTime(){
// checkPickupTime() : check if the selected date/time is available for pickup

	var data = {
		action	: 'checkPickupConflict',
		storeID	: $('fulfillLocation').value,
		date	: $('selectedDate').value,
		time	: $('selectedHr').value + ":" + $('selectedMin').value + ":00"
	};

	var req = new Request.JSON({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fufillSaveStatus').set("html", "");
			$('fulfillDone').disabled = true;
			$('conflictstatusPost').set("html", "<img src='images/spinnerSmall.gif' /> Checking store schedule");
		},
		onSuccess: function(result){
			$('conflictstatusPost').set("html", result.message);
			var toDisable = true;
			if(result.status == 'OK'){
				toDisable = $('fulfillCheck') ? true : false ;
			}
			$('fulfillDone').disabled = toDisable;
		}
	}).post(data);
}

/**** DELIVERY BRANCH PROCESSES ****/
function fulfillGetAddress(postcode){
// fulfillgetAddress() : get address for postal code; fulfillment mode specialized
// PARAM postcode : postal code

	if (postcode.length < 6 || isNaN(postcode)) {
		$('fulfill_address_status').set("html", "<img src='images/error.gif' /> Invalid postal code");
		$('fulfill_address').value = "";
	} else {
		var data = {
			action	: 'getAddr',
			pc		: postcode
		};
		var req = new Request({
			url: 'ajax_postcode.php', async: false,
			onRequest: function(){
				$('fulfill_address_status').set("html", "<img src='images/spinnerSmall.gif' /> Retrieving...");
			},
			onSuccess: function(response){
				if (response=="") {
					$('fulfill_address_status').set("html", "<img src='images/error.gif' /> Invalid postal code");
					$('fulfill_address').value = "";
				} else {
					$('fulfill_address_status').set("html", "<img src='images/ok.gif' />");
					$('fulfill_address').value = response;
				}
			}
		}).post(data);
	}
}

function setDeliveryAddress(mode){
// setDeliveryAddress() : set/check delivery address
// PARAM mode : [manual] entry or address [book]

	var proceed = false,
		fullAddress;

	if (mode == 'book'){
		$('fulfillDone').disabled = true;
		$('fulfillDeliverType').value = mode;
		$('fulfillAddressBook').getElements('option').each(function(item) {
			if (item.selected){
				// use title param for postcode, value for address book id and innerHTML for full address
				$('fulfillSelectedDeliver').set("html", item.innerHTML);
				$('fulfillLocation').value = item.value;
				$('fulfillUnit').value = "";
				$('bookPC').value = item.title;
				proceed = true;
			}
		});
	} else {
		if (!$chk($('fulfill_address').value) || $('fulfill_PC').value.length < 6) {
			$('fulfill_PC').addClass('inputErr');
			alert("Please enter a valid postal code.");
		} else {
			$('fulfill_PC').removeClass('inputErr');
			$('fulfillDone').disabled = true;
			fullAddress = $('fulfill_address').value + ($chk($('fulfill_unit').value) ? " " + $('fulfill_unit').value : "") + " Singapore " + $('fulfill_PC').value;
			$('fulfillSelectedDeliver').set("html", fullAddress);
			$('fulfillDeliverType').value = mode;
			$('fulfillLocation').value = $('fulfill_PC').value;
			$('fulfillUnit').value = $chk($('fulfill_unit').value) ? $('fulfill_unit').value : "";
			$('bookPC').value = "";
			proceed = true;
		}
	}

	if (proceed) { preDeliverCheck(); }
}

// [PROCESS 4A] PRE-DELIVERY CHECK (SHOW DATE/TIME SELECTOR, FILTER OFF AREAS NOT SERVICED)
function preDeliverCheck(){
// [Delivery fulfillment sub-function]
// preDeliverCheck() : pre-get hour & mins check

	var data = {
		action	: 'preDeliverCheck',
		pc		: $('fulfillDeliverType').value == "book" ? $('bookPC').value : $('fulfillLocation').value
	};

	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fufillSaveStatus').set("html", "");
			$('deliveryNotes').set("html", "<img src='images/spinnerSmall.gif' /> Checking stores..");
		},
		onSuccess: function(response){
			$('deliveryNotes').set("html", response);
			if($('selectedDate')){
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				var minDate = $defined($('sameDayDeliver'))
							? (new Date()).format('%Y-%m-%d') // today's date
							: (new Date()).increment().format('%Y-%m-%d'); // tomorrow's date
				var cal = new CalendarEightysix('selectedDateShow', {
					'format': '%d %b %Y',
					'defaultDate': minDate,
					'minDate': minDate,
					'maxDate': $('advanceOrderDateMax').value,
					'disallowUserInput': true,
					'pickFunction': checkDeliverDate
				});
				checkDeliverDate();
			}
		}
	}).post(data);
}

// [PROCESS 4B] CHECK FOR DELIVERY AVAILABILITY FOR THE SELECTED DAY
function checkDeliverDate(){
// checkDeliverDate() : check if selected delivery date is available

	// (0) CONVERT SELECTED DATE TO YYYY-MM-DD
	var dateStamp = new Date.parse($('selectedDateShow').value).format("%Y-%m-%d");
	$('selectedDate').value = dateStamp;

	// (1) SET SELECTED DATE AS STRING
	var todayDate = (new Date()).format('%Y-%m-%d'); // today's date
	var dateString = "";
	if(todayDate==$('selectedDate').value){
		dateString = "(Today)";
	} else {
		var mooDate = new Date();
		mooDate.parse($('selectedDate').value);
		dateString = "("+mooDate.format("%A")+")";
	}
	$('dateString').set("html", dateString);

	// (2) CHECK FOR DELIVERY AVAILABILITY FOR THE SELECTED DAY
	var data = {
		"action" : "checkDeliveryAvail",
		"date" : $('selectedDate').value,
		"pc" : $('fulfillDeliverType').value == "book" ? $('bookPC').value : $('fulfillLocation').value
	};
	if($('sameDayDeliver')){
		$extend(data, { "freeDeliver" : 1 });
	}

	var req = new Request.JSON({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function() {
			$('selectedHr').disabled = true;
			$('selectedMin').disabled = true;
			$('conflictStatus').set("html", "<img src='images/spinnerSmall.gif' /> Checking stores...");
			$('fufillSaveStatus').set("html", "");
		},
		onSuccess: function(response){
			if (response.checkpass == false){
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				$('selectedHr').set("html", "<option>--</option>");
				$('selectedMin').set("html", "<option>--</option>");
				$('conflictStatus').set("html", response.msg);
				$('fulfillDone').disabled = true;
			} else { getDHourBounds(); }
		}
	}).post(data);
}

// [PROCESS 4C] GET AVAILABLE HOUR SELECTIONS
function getDHourBounds(){
// getDHourBounds() : get selectable hours for delivery

	var data = {
		"action" : "getDHourBounds",
		"date" : $('selectedDate').value,
		"pc" : $('fulfillDeliverType').value == "book" ? $('bookPC').value : $('fulfillLocation').value
	};
	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function() {
			$('fufillSaveStatus').set("html", "");
		},
		onSuccess: function(response){
			if (response == "NA") {
				$('selectedHr').disabled = true;
				$('selectedMin').disabled = true;
				$('selectedHr').set("html", "<option>--</option>");
				$('selectedMin').set("html", "<option>--</option>");
				$('conflictStatus').set("html", "<div class='errorsign'>Sorry, we are unable to service deliveries on " + $('selectedDate').value + ". Please call " + $('hqTel').value + " for alternative arrangements.</div>");
				$('fulfillDone').disabled = true;
			} else {
				$('selectedHr').disabled = false;
				$('selectedHr').set("html", response);
				getDMinBounds();
			}
		}
	}).post(data);
}

// [PROCESS 4D] GET AVAILABLE MIN SELECTIONS
function getDMinBounds() {
// [Delivery fulfillment sub-function]
// getDMinBounds() : get selectable mins for delivery

	var data = {
		action	: 'getDMinBounds',
		date	: $('selectedDate').value,
		hr		: $('selectedHr').value,
		pc		: $('fulfillDeliverType').value == "book" ? $('bookPC').value : $('fulfillLocation').value
	};

	var req = new Request({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('selectedMin').disabled = true;
			$('fufillSaveStatus').set("html", "");
		},
		onSuccess: function(response){
			$('selectedMin').set("html", response);
			$('selectedMin').disabled = false;
			checkDeliverTime();
		}
	}).post(data);
}

// [PROCESS 4E] CHECK SELECTED DELIVER DATE/TIME
function checkDeliverTime(){
// checkDeliverTime() : check selected delivery time for conflicts

	var data = {
		action	: 'checkDeliverConflict',
		date	: $('selectedDate').value,
		time	: $('selectedHr').value + ":" + $('selectedMin').value + ":00",
		pc		: $('fulfillDeliverType').value == "book" ? $('bookPC').value : $('fulfillLocation').value
	};

	var req = new Request.JSON({
		url: 'ajax_fulfill.php', async: false,
		onRequest: function(){
			$('fulfillDone').disabled = true;
			$('conflictStatus').set("html", "<img src='images/spinnerSmall.gif' /> Checking store schedule");
			$('fufillSaveStatus').set("html", "");
		},
		onSuccess: function(result){
			$('conflictStatus').set("html", result.message);
			var toDisable = true;
			if(result.status == 'OK'){
				toDisable = $('fulfillCheck') ? true : false ;
			}
			$('fulfillDone').disabled = toDisable;
		}
	}).post(data);
}

/**** SHARED ****/
function fulfillAgree(agree){
// fulfillAgree() : enable "Done" button only if user agrees to fulfillment "terms"

	if(agree){ $('fulfillDone').disabled = false; }
	else{ $('fulfillDone').disabled = true; }
}
