function AddVotoPoll(){
	var id= $("#id_poll").val();
	var id_poll= $("#id_poll").val();
	for(i=0; i< document.frmpoll.opcion_poll.length; i++){
		if (document.frmpoll.opcion_poll[i].checked) {
			var opcion= document.frmpoll.opcion_poll[i].value;
		}
	}
	if (!opcion) {
		$("#msgpoll").html('Ingrese una opcion').show(300);
		return false;
	}

	$("#msgpoll").hide(300);
	$("#btnpoll").fadeOut(300, function(){
	$("#msgpoll").html($("#preload").html()).fadeIn(300, function(){
	$("#frmpoll").ajaxSubmit({
		url: 'ajax_poll.php',
		type: 'POST',
		data: {id:id, opcion:opcion, add_voto_poll:true},
		dataType: 'json',
		error: function(){
			$("#msgpoll").html('Hubo un error intente nuevamente en unos minutos.');
			$("#btnpoll").show();			
		},
		success: function (m) {
			if (m.err){ 
				$("#msgpoll").html(m.msg).show(300);
				$("#btnpoll").html('<input type="button" onclick="return AddVotoPoll(); return false;" value="+ votar" class="textonuevo"/>').fadeIn(300);
			} else {
				GetResultPoll(m);
			}
		}
	 });	
	});
   });
}


function GetResultPoll(obj){
	var cnt= FormatPoll(obj);
	$("#div_poll").html(cnt);
	$("#msgpoll").html(obj.msg).show(300);
}

function FormatPoll(obj){
var str="";
str+='<table width="142" border="0" cellpadding="0" cellspacing="0" bgcolor="#6E7E95">';
str+='	<tr>';
str+='		<td height="1" bgcolor="#3A4A5A"></td>';
str+='	</tr>';
str+='	<tr>';
str+='		<td height="20"></td>';
str+='	</tr>';
str+='	<tr>';
str+='		<td>';
str+='	  		<table width="142" border="0" cellspacing="0" cellpadding="0">';
str+='        		<tr>';
str+='          			<td width="7"></td>';
str+='          			<td class="texto11blancobold">'+obj.poll.poll.title+'</td>';
str+='          			<td width="7"></td>';
str+='        		</tr>';
str+='      		</table>';
str+='		</td>';
str+='	</tr>';
		$.each(obj.poll.res, function(texto,txt) {
str+='	<tr>';
str+='		<td>';
str+='	  		<table width="142" border="0" cellspacing="0" cellpadding="0">';
str+='  				<tr>';
str+='    				<td width="20"><input type="radio" id="opcion_poll" name="opcion_poll" value="'+txt.id_rta+'"></td>';
str+='		    		<td class="texto11blanco">'+txt.texto+'</td>';
str+='	  			</tr>';
str+='			</table>';
str+='		</td>';
str+='	</tr>';
str+='	<tr>';
str+='		<td>';
str+='	  		<table width="142" border="0" cellspacing="0" cellpadding="0">';
str+='  				<tr>';
str+='				    <td height="20" width="20"></td>';
str+='				    <td height="20"><img src="images/enc.gif" width="'+(txt.porcentaje + 2)+'" height="5"></td>';
str+='				    <td height="20" width="7"></td>';
str+='				</tr>';
str+='				<tr>';
str+='				    <td width="20"></td>';
str+='				    <td align="right" class="texto11blanco">'+txt.porcentaje+'% ('+txt.votos+' votos)</td>';
str+='				    <td width="7"></td>';
str+='				</tr>';
str+='			</table>';
str+='		</td>';
str+='	</tr>';
str+='	<tr>';
str+='		<td height="20"></td>';
str+='	</tr>';
		});
str+='	<tr>';
str+='		<td height="20"></td>';
str+='	</tr>';
str+='	<tr>';
str+='		<td class="texto11blanco" align="center">Total de votos: '+obj.poll.poll.total_votos+'</td>';
str+='	</tr>';
str+='	<tr>';
str+='	  <td height="20"></td>';
str+='	</tr>';
str+='	<tr>';
str+='	  <td class="texto11blancobold" align="center"><div style="display:none;" id="msgpoll"></div></td>';
str+='  	</tr>';
str+='	<tr>';
str+='		<td height="10"></td>';
str+='	</tr>';
str+='	<input type="hidden" id="id_poll" name="id_poll" value="'+obj.poll.poll.id+'">';
str+='</table>';
return str;
}