var poll_div_prefix = "poll_";
var poll_url_suffix = ".htm";
var site_domain = '.'+location.host.replace(/^www\./, "");
function poll_vote(poll_id, option_id) {
	$.ajax({
	  url: "/vote/result/"+poll_id+"/"+option_id+poll_url_suffix,
	  success: function(html){
	    $("."+poll_div_prefix+poll_id).replaceWith(html);
	  }
	});
	$.cookie('poll_' + poll_id, option_id, {expires: 7, domain: site_domain});
}
function poll_query(poll_id) {
	$(document).ready(function(){
		if($.cookie('poll_'+poll_id) > 0) {
			$.ajax({
			  url: "/vote/result/"+poll_id+poll_url_suffix,
			  success: function(html){
			    $("."+poll_div_prefix+poll_id).replaceWith(html);
			  }
			});
			// deleting cookie for testing only
			// $.cookie('poll_'+poll_id, null);
		} else {
		$.ajax({
		  url: "/vote/query/"+poll_id+poll_url_suffix,
		  success: function(html){
		    $("."+poll_div_prefix+poll_id).replaceWith(html);
		  }
		});
		}
	});
}
function poll_results(poll_id) {
	$.ajax({
	  url: "/vote/result/"+poll_id+poll_url_suffix,
	  success: function(html){
	    $("."+poll_div_prefix+poll_id).replaceWith(html);
	  }
	});
}