	function setVote(id, place)
	{
		jQuery.getJSON(
			handler_vote,
			{id: id, place: place, act: 1},
			onAjaxSuccess
		);
	}

	function unsetVote(place)
	{
		jQuery.getJSON(
			handler_vote,
			{place: place, act: 0},
			onAjaxSuccess
		);
	}
	
	function clearVotes(e)
	{
		e.preventDefault();
		jQuery.getJSON(
			handler_vote,
			{act: 2},
			onAjaxSuccess
		);
	}

	function saveVotes(e)
	{
		e.preventDefault();
		jQuery("#voteButtons input.vote").attr("disabled", "true");
		jQuery.getJSON(
			handler_vote,
			{act: 3},
			checkSaving
		);
	}

	function checkSaving(data)
	{
		if(data.status == "done")
		{
			window.location = data.location;
		}
		else
		{
			alert(data.message);
			jQuery("#voteButtons input.vote").removeAttr("disabled");
		}
	}
	
	function onAjaxSuccess(data)
	{
		switch (parseInt(data.result)){
			case 1: 
				if (data.clear_vt || (data.id == '0' && data.place == '0' && data.href == ""))
				{
					if (data.id == '0' && data.place == '0' && data.href == "")
					{
						data.clear_vt = "vt_"+0;
					}
					jQuery("th.rate a[id$=-"+(data.clear_vt.substr(3))+"]").html("");
					jQuery("p.rate a[id$=-"+(data.clear_vt.substr(3))+"]").html("");
					var clearInp = jQuery(jQuery("input#"+data.clear_vt));
					clearInp.prev().html("");
					var hinp = clearInp.next();
					hinp.html("");
					hinp.css("display","none");
					hinp.next().css("display","none");
					clearInp.val("");
					clearInp.show();
				}
				if (parseInt(data.id))
				{
					jQuery("th.rate a[id$=-"+data.place+"]").html("");
					jQuery("p.rate a[id$=-"+data.place+"]").html("");
					var setInp = jQuery(jQuery("input#vt_"+data.place));
					jQuery('a#'+data.id+"-"+(data.place)).html("<b></b>");
					setInp.hide();
					setInp.prev().html("<b></b>");
					var hinp = setInp.next();
					hinp.html(data.href);
					hinp.css("display","block");
					hinp.next().css("display","block");
				}
				break;
			case 2:
				jQuery("th.rate a").html("");
				var curInp = jQuery("#choice input:text").each(function()
				{
					var curInp = jQuery(this);
					curInp.prev().html("");
					var hinp = curInp.next();
					hinp.html("");
					hinp.css("display","none");
					hinp.next().css("display","none");
					curInp.val("");
					curInp.show();
				});
				break;
			default:
				// alert(0);
		}
	}
	
	function votingInit(handler_search, minchar)
	{
		jQuery(function() {
			jQuery(".vote_suggest").suggest(handler_search, { isVoting:true, minchars:minchar } );
		});

		jQuery("#choice a.del").click( 
			function () {
				unsetVote(jQuery(this).prev().prev().attr("id"));
			}
		 ); 

		jQuery("th.rate a").click( 
			function () {
				var re = new RegExp("([0-9]{1,})\-([0-4]{1})","im");
				var re2 = new RegExp("/djs/([0-9]{1,})","im");
				var tmp = jQuery(this).attr("id").match(re);
				setVote(tmp[1], tmp[2])
			}
		 ); 

		if(!jQuery("#voteButtons a.btn-vote").hasClass('sms-activate')) {
			jQuery("#voteButtons a.btn-vote").click(saveVotes);
		}
		jQuery("#voteButtons a.btn-clean").click(clearVotes);

	}
	