pol_loader_image='themes/default/images/loader_small.gif';

function pol_GetSelection(hash)
{
	var selection=new Array();
	var boxes=document.getElementsByTagName('input');
	for(var i=0;i<boxes.length;i++)
	{
		if((boxes[i].type=='radio' || boxes[i].type=='checkbox') && (boxes[i].id.indexOf('poll_'+hash)==0 && boxes[i].checked))
		{
			selection.push(boxes[i]);
		}
	}
	return selection;
}

function pol_SelectionPost(selection)
{
	var post=new Array();
	for(var i=0;i<selection.length;i++)
	{
		var temp=selection[i].id.split('_')[2];
		post.push('options[]='+temp);
	}
	return post.join('&');
}

function pol_Vote(hash,width,css_variant)
{
	var id='vote_btn_'+hash;

	var options=pol_SelectionPost(pol_GetSelection(hash));
	if(!options)
	{
		alert('Nu ai selectat nicio opţiune...');
		return;
	}
	
	ajax_CreateLoaderImage(document.getElementById(id), null, pol_loader_image);
		
	pajax(pol_Voted,'poller/poll.php', 'op=vote'+
							'&hash='+encodeURIComponent(hash)+
							'&elemid='+encodeURIComponent(id)+							
							'&width='+encodeURIComponent(width)+				
							'&css_variant='+encodeURIComponent(css_variant)+
							'&'+options
							);
}

function pol_Voted(server_response)
{
	response=ajax_ParseResponse(server_response);
	
	var container=document.getElementById(response['elemid']);
	
	container.innerHTML=response['data'];
}