function showhideVotesDiv() {
	if (document.getElementById("vote_details_div").style.display == "none") {
		document.getElementById("vote_details_div").style.display = "block";
	} else {
		document.getElementById("vote_details_div").style.display = "none";
	}
}

function addFavorites(id_document)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("addfavorite").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","/story/favorite/" + id_document,true);
	xmlHttp.send(null);
}

function vote(id_document, mark)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("votediv").innerHTML = "<td>" + xmlHttp.responseText + "</td>";
		}
	}
	xmlHttp.open("GET","/story/vote/" + id_document + "/" + mark,true);
	xmlHttp.send(null);
}

var commentblock_internal;
var per_page_internal;
var comments_internal;

function display_internal_comments(page) {
	total_text = "";
	for (i = (page * per_page_internal); (i < (per_page_internal + (page * per_page_internal))) &&  (i < comments_internal.length); i++) {
		total_text += commentblock_internal.replace("_USER_", comments_internal[i][0]).replace("_DATE_", comments_internal[i][1]).replace("_COMMENT_", comments_internal[i][2]);
	}
	
	links_text = "<center>";
	min = page - 4;
	if (min <= 0) { min = 0; } else { links_text += "... "; }
	max = min + 9;
	add_points = false;
	if (max > (comments_internal.length / per_page_internal) ) {
		max = Math.ceil(comments_internal.length  / per_page_internal);
		min = max - 9;
		if (min <= 0) { min = 0; }
	} else { add_points = true; }
	for (i = min; i < max; i++) {
		links_text += "<span class='nav_comments' onMouseOver='javascript:this.style.background=\"#AAAAAA\"' onMouseOut='javascript:this.style.background=\"\"' onClick='display_internal_comments(" + i + ")'>&nbsp;";
		if (i == page) { links_text += "<b>"; }
		links_text += (i + 1);
		if (i == page) { links_text += "</b>"; }
		links_text += "&nbsp;</span>";
	}
	if (add_points) {
		links_text += " ...";
	}
	links_text += "</center><br>";
	total_text = links_text + total_text + links_text + "<br>";
	if (document.getElementById) {
		document.getElementById("display_comments").innerHTML = total_text;
    } else if (document.all) {
    	document.all["display_comments"].innerHTML = total_text;
    }
}

function display_comments(commentblock, page, per_page, comments) {
	total_text = "";
	commentblock_internal = commentblock;
	per_page_internal = per_page;
	comments_internal = comments;
	display_internal_comments(page);
}

function report(id_document) {
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("report").innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET","/story/report/" + id_document + "/getform",true);
	xmlHttp.send(null);
}

function send_report(id_document) {
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("report").innerHTML = xmlHttp.responseText;
		}
	}
	var type = "";
	if (document.getElementById('report_type_1').checked) {
		type = document.getElementById('report_type_1').value;
	}
	if (document.getElementById('report_type_2').checked) {
		type = document.getElementById('report_type_2').value;
	}
	if (document.getElementById('report_type_3').checked) {
		type = document.getElementById('report_type_3').value;
	}
	var comment = document.getElementById('reportcomment').value;
	var email = document.getElementById('reportemail').value;
	var name = document.getElementById('reportname').value;
	if (comment != null && email != null || name != null) {
		var error = false;
		if (comment == 'Comment ...' || comment.length < 5) {
			error = true;
		}
		if (email == 'Your Email ...' || email.length < 5) {
			error = true;
		}
		if (name == 'Your name ...' || name.length < 5) {
			error = true;
		}
		if (!error) {
			xmlHttp.open("GET","/story/report/" + id_document + "/" + escape(comment) + "/" + escape(email) + "/" + escape(name) + "/" + escape(type), true);
			xmlHttp.send(null);
		}
	}
}
