var Save = new Object();

Save = {

	Submit: function(_JsonData) {

		if ( !confirm("よろしいですか？") ) return 0;

		// Form class from prototype.js
		var params = Form.serialize(_JsonData.form);
		var buttonValue = "";

		new Ajax.Request('ajaxMailProc.php', {

			asynchronous: true, // Run code anyway.
			//asynchronous: false, // Wait getting response.
			postBody: params + '&title=' + (_JsonData.title ? _JsonData.title : ""),

			onLoading:
				function() {
					// asynchronous: true, use this
					if ( _JsonData.button ) {
						buttonValue = _JsonData.button.value;
						_JsonData.button.value = "Please wait...";
						_JsonData.button.disabled = "disabled";
					}
				},

			onSuccess:
				function (_returnAjaxFunction) {

					var response = decodeURIComponent(_returnAjaxFunction.responseText);
					//alert(response);
					if ( parseInt(response) == 1 ) {

						alert("フォームを送信しました。ありがとうございます。");

						//document.location.reload();
						if ( _JsonData.thanks == true ) {
							document.location.href='page_request_thanks.php';
						}
						
						return 1;
					}
					else {

						alert("Error. Please check the form.");

						return 0;
					}

				},

			onComplete:
				function () {
					// Do nothing.
					if ( _JsonData.button ) {
						_JsonData.button.disabled = "";
						_JsonData.button.value = buttonValue;
					}
				},

			onFailure:
				function () {
					alert('Ajax object load failed. Check ajax module.');
				}

		}); // Ajax.Request

		// return SOME_VALUE;

	} // Submit method

} // Save class

