//var url_ajax = 'http://localhost:8080/ajax/'
var url_ajax = 'http://www.develway.pl/ajax/'

function verifyDelete(link, text) {
	var areYouSure = confirm(text);

	if (areYouSure == true) {
		window.location = link;
	} else {
		return false;
	}
}

function showInline(idBlock) {
	if (document.getElementById(idBlock)) {
		if (document.getElementById(idBlock).style.display == 'none') {
			$("#"+idBlock).css("display", "inline");
		} else {
			$("#"+idBlock).css("display", "none");
		}
	}	
}

function showOrHideBlock(idElement) {
	if (document.getElementById(idElement).style.display == 'none') {
		showBlock(idElement);
	} else {
		hideBlock(idElement);
	}
}

function showBlock(idElement) {
	$("#"+idElement).css('display', 'block');
}
 
function hideBlock(idElement) {
	$("#"+idElement).css('display', 'none');
}

function changeCommentText() {
	if (document.getElementById('commentForm').style.display == 'none') {
		$("#commentFormAddLink").empty();
		$("#commentFormAddLink").prepend("dodaj komentarz &raquo;");
	} else {
		$("#commentFormAddLink").empty();
		$("#commentFormAddLink").prepend("schowaj formularz dodawania komentarza &raquo;");
	}
}

function clearBox(idElement) {
	$("#"+idElement).empty();
}

$(document).ready(function(){
	$(".topLinksBlockUnactive").hover(
		function() {
			$(this).children("a").removeClass("topLinksBlockNonHoverLink")
			$(this).children("a").addClass("topLinksBlockHoverLink")
		},
		function() {
			$(this).children("a").removeClass("topLinksBlockHoverLink")
			$(this).children("a").addClass("topLinksBlockNonHoverLink")
		}
	);
});


/* AJAX */

function click_vote(news){
	$(".voteBlock .voteLink").empty();
	$(".voteBlock .voteLink").css('background-color', '#ffffff');
	$(".voteBlock .voteLink").prepend('<img src="/site_media/img/ajax-loader.gif" />');

	$.ajax({
		url: url_ajax + "vote/",
		dataType: "json",
		type: "POST",
		data: 'news=' + news,
		success: function(data) {
			$(".voteBlock .voteLink").empty();
			$(".voteBlock .voteAmount .votePoints").empty();
			$(".voteBury").empty();

			$.each(data, function(i, item) {
				$(".voteBlock .voteAmount .votePoints").prepend(item);
			});
		}
	});
}

function click_vote_on_list(news){
	$("#voteBlock" + news + " .voteLink").empty();
	$("#voteBlock" + news + " .voteLink").css('background-color', '#ffffff');
	$("#voteBlock" + news + " .voteLink").prepend('<img src="/site_media/img/ajax-loader.gif" />');

	$.ajax({
		url: url_ajax + "vote/",
		dataType: "json",
		type: "POST",
		data: 'news=' + news,
		success: function(data) {
			$("#voteBlock" + news + " .voteLink").empty();
			$("#voteBlock" + news + " .voteAmount .votePoints").empty();

			$.each(data, function(i, item) {
				$("#voteBlock" + news + " .voteAmount .votePoints").prepend(item);
			});
		}
	});
}

function click_vote_minus(news) {
	$.ajax({
		url: url_ajax + "vote_minus/",
		dataType: "json",
		type: "POST",
		data: 'news=' + news,
		success: function(data) {
			$(".voteBlock .voteLink").empty();
			$(".voteBlock .voteAmount .votePoints").empty();
			$(".voteBury").empty();

			$.each(data, function(i, item) {
				$(".voteBlock .voteAmount .votePoints").prepend(item);
			});
		}
	});
}

function go_to_url(link) {
	window.location = 'http://' + link;
}

