function viewRes(vote) {
	var width = 650;
	var height = 360;
	var x = parseInt(screen.width / 2.0) - (width / 2.0);
	var y = parseInt(screen.height / 2.0) - (height / 2.0);
	var win = window.open("/tpl/votes/result.html?theme="+vote, "Результат", "top=" + y + ",left=" + x + ",status=no, scrollbars=no,width=" + width + ",height=" + height + ",resizable=no");
	win.focus();	
}


function getVote(page) {
	$.post("/tpl/votes/show.html?page="+escape(page), function(data) {
		$('#voteDiv').html(data);
		$('#voteDiv').show();
		
		$("#voteFrm").ajaxForm ({ 
	        target:        null, 
	        beforeSubmit:  validVote,
	        success:       successVote,
	        url:           "/tpl/votes/click.html",
	        type:          'post' ,  
	        dataType:      'json'        
		});		
		
	});
}

function showVote(vote) {
	$.post("/tpl/votes/show.html?vote="+vote, function(data) {
		$('#voteDiv').html(data);
		$('#voteDiv').show();
	});
}


function successVote(data)  {
		$.cookie('__unique_vote__'+data.id, "1", {path:'/', expires: 1}); 
		showVote(data.id);
		$('#waiter').jqmHide();
}

function validVote(formData, jqForm) {
	var str = $("#voteFrm").formSerialize();
	if (/(answer)/.test(str)) {
		$('#voteBtn').attr("disabled", "disabled");
		$('#waiter').jqmShow().find('div.jqmdMSG').html('<br /><br />	<img src="/img/indicator.gif" /> &nbsp; Секунду...');
	}
    else  {
        alert('Ничего не выбрано'); 
        return false; 
    }
}
