var POLL={container:'#ecPoll_v3',url:'poll_v3/getPoll.php',delay:5000,load:function(id,prior){if(this.running){return;}
this.running=true;var _poll=this;$j.ajax({type:"post",url:_poll.url,data:"id="+id+"&prior="+prior,dataType:"xml",beforeSend:function(){$j('#pollSmallLoad').show();},success:function(data){$j(data).find('Poll').children().each(function(x){var node=$j(this);var answer_id=new Array();var answer=new Array();var num_votes=new Array();var link=new Array();var id_asked=node.find('id_asked').text();var poll_id=node.find('poll_id').text();if(id_asked==0){SUBMITPOLL.setCookie("ECV_C_3",poll_id,1);}
if(poll_id==SUBMITPOLL.getCookie("ECV_C_3")){$j('#pollNext').addClass('pollGrayedOut');$j('#pollNext').css('text-decoration','none');}else{$j('#pollNext').removeClass('pollGrayedOut');$j('#pollNext').css('text-decoration','');}
var question=node.find('question').text();var date=node.find('date').text();var active=node.find('active').text();var num_answers=node.find('num_answers').text();for(x=0;x<num_answers;x++){answer_id[x]=node.find('answer_id_'+x).text();answer[x]=node.find('answer_'+x).text();num_votes[x]=node.find('num_votes_'+x).text();link[x]=node.find('link_'+x).text();}
var total_votes=node.find('total_votes').text();_poll.display({'question':question,'id_asked':id_asked,'poll_id':poll_id,'date':date,'active':active,'num_answers':num_answers,'answer_id':answer_id,'answer':answer,'num_votes':num_votes,'link':link,'total_votes':total_votes});});},failure:function(){},complete:function(){$j('#pollLoading').hide();_poll.running=false;/*pageTracker._trackPageview("/frontpage/poll");*/$j('#pollSmallLoad').hide();}});},display:function(dataItem){if(dataItem.id_asked==0){POLL.pollShow("slide");}
$j('#pollQuestion').html(dataItem.question);$j('#pollResultQ').html(dataItem.question);$j('#poll_id').attr('value',dataItem.poll_id);$j('#poll_idR').attr('value',dataItem.poll_id);var totalVotes=parseInt(dataItem.total_votes);if(totalVotes==0)
totalVotes=1;var percent=new Array();for(y=1;y<=4;y++){$j('#pollAnswerId'+y).hide();$j('#pollAnswer'+y).hide();$j('#pollResult'+y).hide();$j('#pollResult'+y+'Bar').hide();$j('#pollPercent'+y).hide();}
for(x=0;x<dataItem.num_answers;x++){var y=x+1;if(dataItem.link[x].length>1){$j('#pollAnswer'+y).html("<a href='"+dataItem.link[x]+"' target='_blank'>"+dataItem.answer[x]+"</a>");$j('#pollResult'+y).html("<a href='"+dataItem.link[x]+"' target='_blank'>"+dataItem.answer[x]+"</a>");}else{$j('#pollAnswer'+y).html(dataItem.answer[x]);$j('#pollResult'+y).html(dataItem.answer[x]);}
$j('#pollPercent'+y).html(dataItem.num_votes[x]);$j('#pollAnswerId'+y).attr('value',dataItem.answer_id[x]);percent[y]=Math.round(parseInt($j('#pollPercent'+y).html())/totalVotes*100);$j('#pollPercent'+y).html(percent[y]+'%');$j('#pollResult'+y+'Bar').css('width',percent[y]);$j('#pollAnswerId'+y).show();$j('#pollAnswer'+y).show();$j('#pollResult'+y).show();$j('#pollResult'+y+'Bar').show();$j('#pollPercent'+y).show();}
var currentPoll=SUBMITPOLL.getCookie('ECV_C_3');if((SUBMITPOLL.checkCookie(currentPoll)==true)){POLL.pollHide("hide");}
if((dataItem.id_asked==0)&&(SUBMITPOLL.checkCookie(dataItem.poll_id)==false)){POLL.pollShow("hide");}},pollShow:function(how){if(how=="slide"){$j('#pollResults').hide();$j('#pollDisplay').show();$j('#pollVoteResults').html("Results");}else{$j('#pollResults').hide();$j('#pollDisplay').show();}
$j('#pollSubmitVote').show();$j('#pollPrior').hide();$j('input:radio').attr('checked',false);},pollHide:function(how){if(how=="slide"){$j('#pollDisplay').hide();$j('#pollResults').show();$j('#pollVoteResults').html("Current Vote");}else{$j('#pollDisplay').hide();$j('#pollResults').show();$j('#pollVoteResults').html("");$j('#pollVoteResults').css("cursor","auto");}
$j('#pollSubmitVote').hide();var currentPoll=SUBMITPOLL.getCookie('ECV_C_3');$j('#pollPrior').show();}}
var SUBMITPOLL={container:'#ecPoll_v3',url:'poll_v3/submitPoll.php',delay:5000,submit:function(){if(this.running){return;}
this.running=true;var _submitpoll=this;var form_data=$j('form').serialize();$j.ajax({type:"post",url:_submitpoll.url,data:form_data,dataType:"text",success:function(data){POLL.pollHide(data);_submitpoll.setCookie("ECV_P_3",data,1);},failure:function(){},complete:function(){_submitpoll.running=false;/*pageTracker._trackPageview("/frontpage/poll");*/var cookie=_submitpoll.getCookie("ECV_C_3");POLL.load(cookie,0);}});},setCookie:function(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+
((expiredays==null)?"":";expires="+exdate.toUTCString());},getCookie:function(c_name){if(document.cookie.length>0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}
return"";},checkCookie:function(poll_id){cookie=SUBMITPOLL.getCookie('ECV_P_3');if(cookie!=null&&cookie!=""){if(cookie==poll_id){return true;}else{return false;}}else{return false;}}}
function loadPoll()
{POLL.load(0,0);$j('#pollVoteResults').click(function(){var currentPoll=SUBMITPOLL.getCookie('ECV_C_3');if(SUBMITPOLL.checkCookie(currentPoll)==false){if($j('#pollDisplay').css('display')=='none'){POLL.load(0,0);}else{POLL.pollHide("slide");}}});$j('#pollSubmitVote').click(function(){var radioValue=$j('input:radio:checked').val();if((typeof(radioValue)!="undefined")&&(SUBMITPOLL.checkCookie($j('#poll_id').val())==false)){SUBMITPOLL.submit();}});$j('#pollPrev').click(function(){var poll_id=$j('#poll_id').val();if(poll_id!='10'){POLL.load(poll_id,-1);}});$j('#pollNext').click(function(){var poll_id=$j('#poll_id').val();if(poll_id!=SUBMITPOLL.getCookie("ECV_C_3")){POLL.load(poll_id,1);}});$j('#pollSubmitter').submit(function(){return false;});}
