/*------------------------
BBS用JavaScript
------------------------*/

$(document).ready(function(){
	/*▼TEST
	--------------------*/
	$(".bbs_test").html("○ JavaScript is Runing!!");
	
	/*▼共通chk
	--------------------*/
	var flg = 0;//flg_CGI
	var error = 0;//flg_error
	$(".r_submit").removeAttr("disabled");
	
	/*▼JavaScript_error
	--------------------*/
	//error_comment
	$(".error_js").css("display","none");
	//Res_ClickBtn_show
	$(".bbs_open_resform").css("display","block");	
	
	/*▼親書き込み
	--------------------*/
	//New_submit
	$(".new_submit").click(function(){
		if(flg==0){
			if($(".n_n").val().length < 1){
				alert("[ 名前 ] を入力してくださ");
				return false;
			}else if($(".n_t").val().length < 1){
				alert("[ 件名 ] を入力してくださ");
				return false;
			}else if($(".n_b").val().length < 1){
				alert("[ 本文 ] を入力してくださ");
				return false;
			}else{
				if(window.confirm("返信書き込みしますか？")){
					SentCGI_New();
				}
			}
		}else{
			alert("処理実行中です");
		}
	});
	//New_from_sentCGI
	function SentCGI_New(oyaID){
		flg=1;
		$(".new_submit").attr("disabled", "disabled");
		$(".loading").css("display","inline");
		jQuery.post("cgi.php?s=oya", $("#first_box form").serialize(), function(data){
			flg = 0;
			$(".new_submit").removeAttr("disabled");
			$(".loading").css("display","none");
			if(data.flg == 1){
				$(".complate").css("display","inline");
				$(".complate").html("書き込み完了（2秒後にリロードします）");
				//$(".complate").html(data.msg);
				$.timer(2000, function(timer){
					$(".complate").fadeOut("slow",
						function(){
							window.location.reload();
						}
					);
					timer.stop();
				});
			}else{
				alert(data.msg);
			}
		},
		"json"//html,script,json,jsonp,text
		);
	}
	/*▼レス
	--------------------*/
	//Res_FromOpen
	$(".bbs_open_resform").click(function(){
		$(".dl_res").slideUp();
		$(".bbs_open_resform").slideDown();
		$(this).slideUp(
			"normal",
			function(){
				$(this).next().slideDown("normal");
			}
		);
		
	});
	//Res_submit
	$(".r_submit").click(function(){
		var oyaID = $(this).siblings(".oya").val();
		//alert(oyaID);
		if(flg==0){
			if($("#resf"+oyaID+" .r_n").val().length < 1){
				alert("[ 名前 ] を入力してくださ");
				return false;
			}else if($("#resf"+oyaID+" .r_b").val().length < 1){
				alert("[ 本文 ] を入力してくださ");
				return false;
			}else{
				if(window.confirm("返信書き込みしますか？")){
					SentCGI_res(oyaID);
				}
			}
		}else{
			alert("処理実行中です");
		}
	});
	//Res_from_sentCGI
	function SentCGI_res(oyaID){
		flg=1;
		$("#resf"+oyaID+" .r_submit").attr("disabled", "disabled");
		$("#resf"+oyaID+" .loading").css("display","inline");
		jQuery.post("cgi.php?s=res", $("#resf"+ oyaID+" form").serialize(), function(data){
			flg = 0;
			$("#resf"+oyaID+" .r_submit").removeAttr("disabled");
			$("#resf"+oyaID+" .loading").css("display","none");
			if(data.flg == 1){
				$("#resf"+oyaID+" .complate").css("display","inline");
				$("#resf"+oyaID+" .complate").html("返信書き込み完了（2秒後にリロードします）");
				$.timer(2000, function(timer){
					$("#resf"+oyaID+" .complate").fadeOut("slow",
						function(){
							window.location.reload();
						}
					);
					timer.stop();
				});
			}else{
				alert(data.msg);
			}
		},
		"json"//html,script,json,jsonp,text
		);
		//return false;
	}
	//$(".dl_res").css("display","block");
	
});































