var isOpenedPollWidgetTab1 = true;
var isOpenedPollWidgetTab2 = false;
function openPollWidgetTab(id, url){
	switch(id){
		case 1:
			$('#pollWidgetTab1').addClass('selected');
			$('#pollWidgetTab2').removeClass('selected');
			if(isOpenedPollWidgetTab1) return false;
			changePollWidgetTabAjax(id, url)
			break;
		case 2:
			if(isOpenedPollWidgetTab2) return false;
			$('#pollWidgetTab1').removeClass('selected');
			$('#pollWidgetTab2').addClass('selected');
			changePollWidgetTabAjax(id, url)
			break;
	}
	$('#poll').addClass('rightblock with_tabs loader');	 
}

function changePollWidgetTabAjax(id, url){
	 $.ajax({
	      url: url,
	      global: false,
	      type: "POST",	     
	      dataType: "html",
	      success: function(html){
		  	$('#ajax_poll').html(html);
		  	$('#poll').addClass('rightblock with_tabs');		  	
		  	switch(id){
				case 1:
					isOpenedPollWidgetTab1 = true;
					isOpenedPollWidgetTab2 = false;
					break;
				case 2:
					isOpenedPollWidgetTab1 = false;
					isOpenedPollWidgetTab2 = true;
					break;
			}
	      }
	   }
	);
}

function pollVote(url){
	$('#pollWidgetTab1').remove();
	$('#pollWidgetTab2').addClass('selected');
	$('#poll').addClass('rightblock with_tabs loader');
	var serializedForm = $('#pollForm').serialize();	
		  $.ajax({
		      url: url,
		      global: false,
		      type: "POST",
		      data: (serializedForm),
		      dataType: "html",
		      success: function(html){			  	
			  	$('#ajax_poll').html(html);
			  	$('#poll').addClass('rightblock with_tabs');
			  	isOpenedPollWidgetTab2 = true;
		      }
		   }
		);	
}