var submitting = false;
function doSubmit() {
	if (submitting == true) {
		return;
	}
	var theButton = document.getElementById("submitButton");
	theButton.style.display = "none";
	var info = document.getElementById("submittingText");
	info.style.display = "block";

	var submitting="true";
	// submit the form
	document.getElementById("theForm").submit();
}

/**
 * Shows warning before taking action - used for delete.
 */
function doSubmitWarning(theFormId) {
	if (submitting == true) {
		return;
	}
	var doSubmit = confirm("Are you REALLY sure you want to delete this order?\n\nYou can NEVER get it back!");
	if (doSubmit == true) {
		var submitting="true";
		// submit the form
		document.getElementById(theFormId).submit();
	}
}



/**
 * Order form initialization.
 */
function initOrderForm() {
	var box = $("use_separate_shipping_address");
	if (box) {
		addEvent(box, "focus", toggleShippingAddress);
		addEvent(box, "click", toggleShippingAddress);
	}
	var box2 = $("use_personal_check");
	if (box2) {
		addEvent(box2, "focus", togglePersonalCheck);
		addEvent(box2, "click", togglePersonalCheck);
	}
	var box3 = $("use_order_instructions");
	if (box3) {
		addEvent(box3, "focus", toggleOrderInstructions);
		addEvent(box3, "click", toggleOrderInstructions);
	}
	var box4 = $("use_coupon_code");
	if (box4) {
		addEvent(box4, "focus", toggleCouponCode);
		addEvent(box4, "click", toggleCouponCode);
	}
}

Event.observe(window, 'load', initOrderForm, false);

/**
 * Toggles the display of shipping address
 */
function toggleShippingAddress(e) {
	var shipBlock = $("shipping_address");
	var box = $("use_separate_shipping_address");
	if (shipBlock != null && box != null) {
		if (box.checked == true) {
			shipBlock.style.display = "block";
		} else {
			shipBlock.style.display = "none";
		}
	}
}


/**
 * Toggles the display of order instructions
 */
function toggleOrderInstructions(e) {
	var instructionsBlock = $("order_instructions");
	var box = $("use_order_instructions");
	if (instructionsBlock != null && box != null) {
		if (box.checked == true) {
			instructionsBlock.style.display = "block";
		} else {
			instructionsBlock.style.display = "none";
		}
	}
}

/**
 * Toggles the display of personal check
 */
function togglePersonalCheck(e) {
	var checkBlock = $("personal_check");
	var creditBlock = $("credit_card");
	var box = $("use_personal_check");
	if (checkBlock != null && box != null) {
		if (box.checked == true) {
			checkBlock.style.display = "block";
			creditBlock.style.display = "none";
		} else {
			checkBlock.style.display = "none";
			creditBlock.style.display = "block";
		}
	}
}


/**
 * Toggles the display of order instructions
 */
function toggleCouponCode(e) {
	var couponBlock = $("coupon_code");
	var box = $("use_coupon_code");
	if (couponBlock != null && box != null) {
		if (box.checked == true) {
			couponBlock.style.display = "block";
		} else {
			couponBlock.style.display = "none";
		}
	}
}

