$(document).ready(function () {
	$(".informdel .btn_delete").click(function(){
		$(".form-informDelete").remove();
		$('<div class="form-informDelete" >	<img src="forums/captchasecurityimages.php?_='+Math.random()+'"  hspace="1" border="0" id="img_security_code2" onclick="reloadImg(this)" style="cursor:pointer" /><br /><input type=text style="width:100px;" id="txt_security_code"/><br /><img src="images/txt/btn_send.png" alt="send" style="margin-left:6px;cursor:pointer" onclick="submitDelete('+ $(this).attr("rel") +',this)"/><img src="images/txt/btn_cancel.png" alt="cancel" style="vertical-align:top;cursor:pointer;margin-left:6px;" onclick="$(this).parent().remove()"/></div>')
			.insertBefore($(this).parent().parent().next());
	}).css({display:'none'});
	
	$(".comment-list dt").hover(
		function(){
			$(this).find(".btn_delete").show();
		},function(){
			$(this).find(".btn_delete").hide();
	});
	$(".comment-list dd").hover(
		function(){
			$(this).prev().find(".btn_delete").show();
		},function(){
			$(this).prev().find(".btn_delete").hide();
	});
});

function submitDelete($id,elm){
	var secur_code = $("#txt_security_code").val();
	var elm  =elm;
	var formInform = $(elm).parent();
	var btn_del = formInform.parent().find(".btn_delete");
	formInform.html("<img src='images/bg/ajax-loader.gif' />");
	 $.ajax({
		   type: "POST",
		   url: "postcomment.php",
		   data:"cmd=alert&security_code="+secur_code+"&id="+$id,
		   success:function(msg){
				if(msg == "admin"){
				//	alert("ลบแจ้งข้อมูลเรียบร้อยแล้ว");
					formInform.next().fadeOut(400,function(){
						formInform.next().remove();
						formInform.prev().remove();
						formInform.html( "ความคิดเห็นนี้ถูกลบไปแล้ว" );
						
					});
				}else if(msg == "ok"){
					formInform.html("ระบบแจ้งข้อมูลของท่านเรียบร้อยแล้ว");
					
				}else{
					alert(msg);
					formInform.remove();

				}
			},
		   error:function(){
			alert("ขออภัยระบบขัดข้อง โปรดรอสักครู่ หรือ ลองใหม่อีกครั้ง");
			
		   }
	});
}
function reloadImg(elm){
 mydate = new Date();
 url_img=elm.src.split("?")[0];
 elm.src=url_img+"?"+mydate.getTime();
}

function postComment($type,$id){

	$("#comment-post input,#comment-post img").hide();
	$(".img-loading").show();

		 $.ajax({
		   type: "POST",
		   url: "postcomment.php",
		   data:"cmd=post&type="+$type+"&id="+$id+"&comment="+$('#txt-comment').val(),
		   success:function(msg){
			if(msg == "ok"){
				window.location.href = window.location.href; 
			}else alert("ขออภัยระบบขัดข้อง โปรดรอสักครู่ หรือ ลองใหม่อีกครั้ง");
		   },
		   error:function(){
			alert("ขออภัยระบบขัดข้อง โปรดรอสักครู่ หรือ ลองใหม่อีกครั้ง");
		   }
		 });
	return false;
}
	

