var ButtonHandler = {
	buttons: [
			"button_account_create_submit",
            "button_account_edit_submit",
            "button_addressbook_submit",
            "button_login_submit",
            "button_review_submit",
            "button_guestbook_submit",
            "button_add_to_wish_list_submit",
            "button_refresh_wish_list_submit",
            "button_checkout_shipping_submit",
            "button_checkout_payment_submit",
            "button_checkout_submit",
            "button_order_submit",
            "button_newsletter_submit",
            "button_account_password_submit",
            "button_advanced_search_submit",
            "button_pw_double_opt_login_submit",
            "button_gallery_previous",
            "button_gallery_next"
    ],
	setup: function() {
		ButtonHandler.buttons.each(function(id) {
			if( $(id) ) {
				$(id).observe("click", this[("on_" + id + "_click").dasherize().camelize()]);
			}
		});
	}
};


/*******************************************************************************
 * 
 * Button handler function
 * 
 ******************************************************************************/


function onButtonAccountCreateSubmitClick(event) {
	$("create_account").submit();
	event.stop();
	return false;
}

function onButtonAccountEditSubmitClick(event) {
	$("account_edit").submit();
	event.stop();
	return false;
}

function onButtonAddressbookSubmitClick(event) {
	$("addressbook").submit();
	event.stop();
	return false;
}

function onButtonLoginSubmitClick(event) {
	$("login").submit();
	event.stop();
	return false;
}

function onButtonReviewSubmitClick(event) {
	$("product_reviews_write").submit();
	event.stop();
	return false;
}

function onButtonGuestbookSubmitClick(event) {
	$("guestbook_sign").submit();
	event.stop();
	return false;
}

function onButtonAddToWishListSubmitClick(event) {
	var url = $("cart_quantity").action;
	url = url.gsub("&action=add_product", "&action=add_wish_list_product");
	$("cart_quantity").action = url;
	$("cart_quantity").submit();
	event.stop();
	return false;
}

function onButtonRefreshWishListSubmitClick(event) {
	$("wish_list_quantity").submit();
	event.stop();
	return false;
}

function onButtonCheckoutShippingSubmitClick(event) {
	$("checkout_address").submit();
	event.stop();
	return false;
}

function onButtonCheckoutPaymentSubmitClick(event) {
	$("checkout_payment").submit();
	event.stop();
	return false;
}

function onButtonCheckoutSubmitClick(event) {
	$("checkout_confirmation").submit();
	event.stop();
	return false;
}

function onButtonOrderSubmitClick(event) {
	$("order").submit();
	event.stop();
	return false;
}

function onButtonNewsletterSubmitClick(event) {
	$("sign").submit();
	event.stop();
	return false;
}

function onButtonAccountPasswordSubmitClick(event) {
	$("account_password").submit();
	event.stop();
	return false;
}

function onButtonAdvancedSearchSubmitClick(event) {
	$("advanced_search").submit();
	event.stop();
	return false;
}

function onButtonPwDoubleOptLoginSubmitClick(event) {
	$("sign").submit();
	event.stop();
	return false;
}
