$(function() {
	$('#history').change(function() {
		$('#account').val($('#history').val());
	});

	$('#btnNext').click(function() {
		submitForm();
	});

	$('#btnConfirm').click(function() {
		$('#type').val('confirm');
		submitForm();
	});

	$('#btnBackInput').click(function() {
		$('#type').val('input');
		submitForm();
	});

	$('#btn2faSubmit').click(function() {
		$("#btn2faSubmit").attr("disabled", "disabled");
	});

	$('#btnComplete').click(function() {
		$("#btnComplete").attr("disabled", "disabled");
		$('#type').val('complete');
		submitForm();
	});

	$('#btnSave').click(function() {
		$('#type').val('save');
		$('#status').val('1');
		submitForm();
	});

	$('#btnRollBack').click(function() {
		$('#type').val('roll_back');
		$('#status').val('2');
		submitForm();
	});

	$('#btnList').click(function() {
		$('#type').val('list');
		submitForm();
	});

	$('#btnDelete').click(function() {
		deleteRequest();
	});

	$('#btnListApply').click(function() {
		location.href = 'request?type=apply'
	});
});

function goDetail(rId) {
	$('#type').val('detail');
	$('#r_id').val(rId);
	submitForm();
}

function getbtnSave(){
	$('#type').val('save');
	$('#status').val('1');
	submitForm();
}

function deleteRequest() {

	var rId		= $('#r_id').val();
	var status	= $('#status').val();
	var confMsg = '';

	// URLの取得
	var url = location.href;

	if(url.indexOf('/en/') > 0) {
		confMsg = 'Cancellation requests are irreversible and cannot be rescinded. Do you want to cancel this request?';
	} else if(url.indexOf('/ja/') > 0) {
		confMsg = '一旦削除した引落申請は、元に戻す事ができません。\nそれでも取消を行いますか？';
	} else if(url.indexOf('/sc/') > 0) {
		confMsg = '取消请求是不可逆转的，不能撤销。还要继续此取消请求吗？';
	} else if(url.indexOf('/tc/') > 0) {
		confMsg = '取消請求是不可逆轉的，不能撤銷。還要繼續此取消請求嗎？';
	} else if(url.indexOf('/id/') > 0) {
		confMsg = 'Permintaan pembatalan yang ireversibel dan tidak dapat dibatalkan. Apakah Anda ingin membatalkan permintaan ini?';
	}

	if(status != '0') {


		if(url.indexOf('/en/') > 0) {
			alert('Money Request is allowed to be cancelled only in the status of "applying".');
		} else if(url.indexOf('/ja/') > 0) {
			alert('引き落し申請の取り消しは、申請中でしかできません。');
		} else if(url.indexOf('/sc/') > 0) {
			alert('取消资金申请之能在“申请”状态才允许.');
		} else if(url.indexOf('/tc/') > 0) {
			alert(' 取消資金申請之能在“申請”狀態才允許.');
		} else if(url.indexOf('/id/') > 0) {
			alert('Permintaan uang diperbolehkan untuk dibatalkan hanya dalam status "Mengajukan".');
		}

		return false;

	} else if(confirm(confMsg)) {
		$('#type').val('delete');
		submitForm();
	}
}

function remove(rId) {
	$('#type').val('remove');
	$('#r_id').val(rId);

	submitForm();
}
