﻿function doClick(keyEvent) {
	if(keyEvent !=true && keyEvent != undefined && keyEvent.which != 1) {
		if(keyEvent.keyCode!=13) {
			return;
		}
	}
	gazouId =  document.writeform.id.value;
	name = document.writeform.name.value;
	msg = document.writeform.msg.value;
	inputCode = document.writeform.code.value;
	$("span#lineCommentResult").html("<img src='img/style/spinner.gif'>");
	if(msg == '') {
		$("span#lineCommentResult").html("<span class='errorText'>コメントが入力されていません。</span>");
		return;
	}
	
	if(name.length>15) {
		$("span#lineCommentResult").html("<span class='errorText'>名前が長すぎです。</span>");
		return;
	}
	
	if(msg.length>120) {
		$("span#lineCommentResult").html("<span class='errorText'>コメントが長すぎです。</span>");
		return;
	}
	
	code = Number( getImageId() ) - Number( gazouId ) + 135;
	if(code != inputCode) {
		$("span#lineCommentResult").html("<span class='errorText'>正しい認証コードを入力してください。</span>");
		return;
	}
	
	$.ajax({
		type: "POST",
		data: {
			action: 'write',
			gazouId: gazouId,
			comment: msg,
			name: name
		},
		url: "writeexec.php",
		success: function(msg)
		{
			if( msg == 'error' ) {
				$("span#lineCommentResult").html("<span class='errorText'>投稿に失敗しました。</span>");
				return
			}
			$("div#lineComment").html("<img src='img/style/spinner.gif'>");
			$("div#lineComment").load('writeexec.php', {action: 'view', gazouId: gazouId}).hide(0).fadeIn(500);
			$("span#lineCommentResult").html(msg+"<span class='successText'>投稿を完了しました。</span>");
			document.writeform.msg.value = "";
		}
	});
}
