var http_req;
var rated=false;
function email_to_author(link)
{
	window.open(link.href,'','width=550,height=580');
	return false;
}
function hide_all_uls()
{
	var divs=document.getElementById('article_archives_list').getElementsByTagName('div');
	for(i=0;divs.length>i;i++) {divs[i].style.display='none';divs[i].style.visibility='hidden';}
}
function show_archives_list(link)
{
	hide_all_uls();
	var active_list=link.href.split('?',2)[1].split('&',2)[1].split('=',2)[1];
	if(document.getElementById('article_archives_ul'+active_list)==null)
	{
		get_archive_list(link);
	}
	else
	{
		document.getElementById('article_archives_ul'+active_list).style.display='block';
		document.getElementById('article_archives_ul'+active_list).style.visibility='visible';
	}
	return false;
}
function get_archive_list(link)
{
	if(http_req==null) http_req=new Ajax();
	http_req.state_changing=archives_list;
	url_parts=link.href.split('?',2);
	http_req.send('libraries/article.php?http_request=1&author_id='+document.getElementById('author_id').value+'&'+url_parts[1]);
	return false;
}
function show_window(link,width,height)
{
	var wind=window.open(link.href,'','width='+width+',height='+height+',scrollbars=yes,resizable=yes');
	return false;
}
function archives_list()
{
	if(http_req.http_object.readyState==4)
	{
		if(http_req.http_object.status==200)
		{
			document.getElementById('article_archives_list').innerHTML+=http_req.http_object.responseText;
		}
	}
}
function rate(link)
{
	if(rated) return false;
	if(http_req==null) http_req=new Ajax();
	http_req.state_changing=rating;
	http_req.send(get_host_name()+'libraries/article.php?http_request=1&'+link.href.split('?',2)[1]);
	rated=true;
	return false;
}
function rating()
{
	if(http_req.http_object.readyState==4)
	{
		if(http_req.http_object.status==200)
		{
			document.getElementById('rating').innerHTML=http_req.http_object.responseText;
		}
	}
}

function write_comment()
{
	$("#loading").bind("ajaxSend", function(){
		$(this).fadeIn('slow');
	}).bind("ajaxComplete", function(){
		$(this).fadeOut('slow');
		$("#loading").unbind();
	});
	var isim=$("#comment_name").val();
	var eposta=$("#comment_email").val();
	var kod=$("#comment_scod").val();
	var yorum=$("#comment_text").val();
	var id=$("#article_id").val();
	$.post('article_request.php', { i:isim,e:eposta,k:kod,y:yorum,a:id,http:1 }, function (data)
	{
		var i=get_host_name()+'scode.php?id='+(new Date()).getTime();

		document.getElementById('scode_img').src=i;
		document.getElementById('comment_scod').value='';
		if(	document.getElementById('scode2'))
		{
		document.getElementById('scode2').src=i;
		document.getElementById('comment_scod2').value='';
		}
		eval(data);
		if(response.code=='0') var cla="errx"; else var cla="ok";
		$("#comment_response").html(response.message).attr('class',cla);

	});
}
function send_to_friend()
{
	$("#loading2").bind("ajaxSend", function(){
		$(this).fadeIn('slow');
	}).bind("ajaxComplete", function(){
		$(this).fadeOut('slow');
		$("#loading2").unbind();
	});
	var isim=$("#comment_name2").val();
	var ark_isim=$("#comment_name4").val();
	var eposta=$("#comment_email2").val();
	var ark_eposta=$("#comment_email3").val();
	var kod=$("#comment_scod2").val();
	var yorum=$("#comment_text2").val();
	var id=$("#article_id").val();
	var baslik=$("#title").html();

	if(isim.length>0 && ark_isim.length>0 && ark_eposta.length>0)
	{
	$.post('article_request.php', { i:isim,arki:ark_isim,epo:ark_eposta,e:eposta,k:kod,y:yorum,a:id,t:baslik,http:2 }, function (data)
	{
		var i=get_host_name()+'scode.php?id='+(new Date()).getTime();
		document.getElementById('scode2').src=i;
		document.getElementById('scode_img').src=i;
		document.getElementById('comment_scod2').value='';
		document.getElementById('comment_scod').value='';
		eval(data);
		if(response.code=='0') var cla="errx"; else var cla="ok";
		$("#send_response").html(response.message).attr('class',cla);
		$(".form_buttons").hide();
	});
	}
	else
	{

		data = "var response= { 'code':'0' , 'message':'Lütfen gerekli alanları doldurunuz' }";
		eval(data);
		if(response.code=='0') var cla="errx"; else var cla="ok";
		$("#send_response").html(response.message).attr('class',cla);
	}
return false;
}

function vote_comment(id,vote)
{

    $.post('article_request.php', { http:3,i:id,v:vote }, function (data)
	{
	   		eval(data);
            if(response.code==1)
            {
                $("#n_"+id).attr('width',response.no);
                $("#y_"+id).attr('width',response.yes);
                $("#rn_"+id).html('%'+Math.round(response.no));
                $("#ry_"+id).html('%'+Math.round(response.yes));
            }

	});

}
function sc()
{
	$("#af").fadeIn('slow');
//	$("#scode_img").attr("src","scode.php");
	document.getElementById('comment_text').focus();
}
function hc()
{
	$("#af").fadeOut('slow');
}
function se()
{
	$("#sf").fadeIn('slow');
	// $("#scode2").attr("src","scode.php");
		document.getElementById('comment_text2').focus();
}
function he()
{
	$("#sf").fadeOut('slow');
}