function setCookie(name, value, expiredays, path, domain, secure) {
   if (expiredays) {
      var exdate=new Date();
      exdate.setDate(exdate.getDate()+expiredays);
      var expires = exdate.toGMTString();
   }
   document.cookie = name + "=" + escape(value) +
   ((expiredays) ? "; expires=" + expires : "") +
   ((path) ? "; path=" + path : "") +
   ((domain) ? "; domain=" + domain : "") +
   ((secure) ? "; secure" : "");
}
function getCookie(name) {
   var cookie = " " + document.cookie;
   var search = " " + name + "=";
   var setStr = null;
   var offset = 0;
   var end = 0;
   if (cookie.length > 0) {
      offset = cookie.indexOf(search);
      if (offset != -1) {
         offset += search.length;
         end = cookie.indexOf(";", offset)
         if (end == -1) {
            end = cookie.length;
         }
         setStr = unescape(cookie.substring(offset, end));
      }
   }
   return setStr;
}
function get_v(){
var user1 = getCookie('opros');
return user1;
}
$(document).ready(function() {
	if (get_v()=='yes1')
		$.post('/images/update_vote.php',{val1: 'none'}, function(data){
			$('#blok_oprosa').html(data);
		});
    $('.radiobutton').change(function() {
        if ($('.radiobutton:checked').size() > 4) {
			$(this).removeAttr('checked');
			alert('Максимум можно выбрать 4 варианта!');
        }
    });
	$('#vote').click(function(){		
		var user = getCookie('vote');
		if(user=='yes1') alert('Вы уже проголосовали!!!');
		else {
            var val1 = [];
            $('.radiobutton:checked').each(function() {
				val1.push($(this).val());
            });
            var val = ((val1 instanceof Array ) ? val1.join (',') : val1);
			$.post('/images/update_vote.php', {val: ''+val+''}, function(data) {
				$('#blok_oprosa').html(data);
				setCookie('opros', 'yes1', 365, '/');
			});
			$.post('/images/update_vote.php', {val1: 'none'}, function(data) {
				$('#blok_oprosa').html(data);
			});
		}
	});
});
