function delete_mission(mission_id) {
	var current = $('#mission_name_' + mission_id).text();
	var a = window.confirm("本当に " + current + " を削除してよろしいですか？");
	if(a) {
		$.post('/mission/' + mission_id + '/delete', { csrfmiddlewaretoken: csrf_token }, function(data){
			$('#mission_list_' + mission_id).remove();
		});
	}
}

function rename_mission(pk) {
	var current = $('#mission_name_' + pk).text();
	var pos = current.indexOf(' ', 0);
	if(pos >= 0) {
		current = current.substring(pos + 1);
	}
	var name = window.prompt("新しいミッション名", current);
	if(name) {
		$.post('/mission/' + pk + '/rename', { name: name, csrfmiddlewaretoken: csrf_token }, function(data){
			$('#mission_name_' + pk).text(data);
		});
	}

	var e = event || window.event;

	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;

	if (e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;

	return false;
}

function upload_archive(e) {
	var f = e.form;
	if(window.confirm("ファイルをアップロードしてミッションを作成しますか？")) {
		f.submit();
	} else {
		f.reset();
	}
}

function create_upload_mission() {
	$('#file').upload('/mission/upload', { csrfmiddlewaretoken: csrf_token }, function(data){
		alert(data);
	});

	return false;
}

function stopPropagation() {
	var e = event || window.event;

	/*
	if (e.preventDefault) e.preventDefault();
	else e.returnValue = false;
	*/

	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;

	return true;
}

$(window).load(function() {
	$('a').bind('click', stopPropagation);
	$('button').bind('click', stopPropagation);
	$('input').bind('click', stopPropagation);
	$('label').bind('click', stopPropagation);
	$('select').bind('click', stopPropagation);
});

