﻿/* ALICO COMMENT POST */


$(document).ready(function(){
	
	//$("#ajax_comment_form").load("http://www.milligazete.com.tr/haber/comment_form");
	
})

function post_form(process)
{
	text_load  = "lütfen bekleyiniz";
	text_erorr = "isleminiz gecersiz bir hata yürüttü";
	text_ok    = "islemeniz başarı ile tamamlandı";
	
	$("#report").bind("ajaxSend", function(){
        $("#report").html(text_load);
		$("#report").removeClass().addClass("load");
		$(this).show();
	}).bind("ajaxComplete", function(){
			$("#report").unbind();
	});
	
	var options={
		url:process,
		success:function(data)
		{
			//alert(data);
			
			
			var response=data.split("$");
			
			if(response[0]==1)
            {
				$(".scode_box").css("display","none");
				$("#report").removeClass().addClass("ok");
				$("#report").html(response[1]);
				$("#report").show()
			}
			else
			{
				
				
				if(response[2]=="logbox")
				{	
					$("#cform").css("display","none");
					$("#clogin").css("display","block");
				}
				
				if(response[2]=="rcode")
				{	
					$(".scode_box").css("display","block");
				}
				
				$("#report").removeClass().addClass("err");
				$("#report").html(response[1]);
				$("#report").show()
				
			}
		}
    };

    jQuery("#post").ajaxSubmit(options);
    return false;
}




/* yorum formu submit ediliyor */
function submit_comment(form_id)
{

	/* önce ajax loading göster */
	//$("#report").attr("class","loading").text("yorumunuz kaydediliyor");
		
	/* form verisini hazırla */
	var post = $("#"+form_id).serialize();	
	

	$.post("/haber/form_comment", post, function(data){
		
		json = eval('(' + data + ')');
		
		alert(json);
		
		/* gelen mesajı göster */
		
		
		/* eğer olumlu bir mesaj geliyorsa formu kapat */
		if(json.status=="scode")
		{
			tb_show("Deneme","/captcha/?height=184&width=325&modal=true");
			//$("#comment_submit").attr("disabled","disabled");
		}else if(json.status=="err"){
			$("#report").attr("class", json.status).text(json.message);
		}else if(json.status=="ok"){
			$("#report").attr("class", json.status).text(json.message);
		}
	})	

	return false;	
}




function scode_validate(element){

	var scode = $(element).prev().val();	
	
	//alert(scode);
	
	$.post("/haber/scode_validate", {scode:scode}, function(data){
	
		json = eval('('+data+')');
		
		/* doğru kod girildiyse */	
		if(json.status=="ok"){
		
			$("#scode_form").css("display","none");
			
			$("#scode_ok").css("display","block");
			//$("#comment_submit").remove();

			$("#report").text(json.message);
			
			
			tb_remove();
		
		/* kod hatalı */
		}else{
		
			$("#msg").text(json.message).attr("class", json.classname);
		}
		
		
	})

}

/* olumlu oy */
function t_up(comment_id, element)
{
	/* eğer disable aldıysa birşey yapma */
	if($(".rate_"+comment_id).hasClass("disabled")) return false;
	
	var post = "comment_id="+comment_id;
	$.post("/haber/t_up", post, function(data){
	
		
		$(element).addClass("check");
		$(".rate_"+comment_id).addClass("disabled");
		
		
		var json = eval('('+data+')');	
		$("#comment_rating_"+comment_id).text(json.rate);
		//$("#comment_rating_bar_"+comment_id).text(json.rate);
		
		//$("#comment_rating_"+comment_id).parent().children("a, strong").remove();
		//$("#comment_rating_"+comment_id).parent().children("a, strong").remove();
	})
	
	return false;
}

/* olumsuz oy */
function t_down(comment_id, element)
{
	
	/* eğer disable aldıysa birşey yapma */
	if($(".rate_"+comment_id).hasClass("disabled")) return false;
	
	var post = "comment_id="+comment_id;
	$.post("/haber/t_down", post, function(data){

		
		
		$(element).addClass("check");
		
		$(".rate_"+comment_id).addClass("disabled");
		
		
		var json = eval('('+data+')');	

		$("#comment_rating_"+comment_id).text(json.rate);
		/*
		$("#comment_rating_bar_"+comment_id).css("width", (json.rate / 10) * 50);
		$("#comment_rating_"+comment_id).parent().children("a, strong").remove();
		*/
	})

	return false;
}

function jump_comment_page(element, url, max)
{
	var page 		= Number($(element).prev().val());

	if(page>max) page = max;
	if(page<0)   page = 1;
	
	

	var location	= url+"/C"+page;

	
	window.location = location;
}

