var newwindow = '';
function popup(url) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=600,width=800,scrollbars=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
Event.observe(window, 'load', function(){ 
	var forms = $$('form.poll');
	forms.each(function(x){
		var action = x.readAttribute('action');
		var pollname = x.urlname.value;

		var url = x.getElementsBySelector('a.view-results')[0].readAttribute('href');
		x.observe('submit',function(e) {
			var option = x.optionvalue;
			var optionvalue='';
			for (i=0;i<option.length;i++) {
				if (option[i].checked) {
					optionvalue = option[i].value;
				}
			}
            
            if(action.indexOf("?") > -1) {
                action =  x.readAttribute('action'); 
            }
            
			action = action + "?urlname=" + pollname + "&optionvalue=" + optionvalue;
			popup(action);
			Event.stop(e);
		});
		x.getElementsBySelector('a.view-results')[0].observe('click',function(e) {
			popup(url);
			Event.stop(e);
		});
	});
});