$j=jQuery.noConflict(); var pollajaxurl='poll_ajax.php'; requestsInProgress=0; maxRequestsInProgress=1; function togglePoll(pollID, isClosed) { // One request at a time please if( requestsInProgress>=maxRequestsInProgress ) { alert(Language.Translate(2500115)); return false; } // Display var pollContainer = jQuery('#sePoll_'+pollID); if( isClosed ) { pollContainer.find('.sePollsClose').css("display", 'none'); pollContainer.find('.sePollsOpen').css("display", "block"); } else { pollContainer.find('.sePollsClose').css("display", 'block'); pollContainer.find('.sePollsOpen').css("display", "none"); } // Ajax var bind = this; var request = new Request.JSON({ 'method' : 'post', 'url' : pollajaxurl, 'data' : { 'task' : 'togglepoll', 'poll_id' : pollID, 'poll_closed' : (isClosed ? 1 : 0) }, 'onComplete': function(responseObject) { requestsInProgress--; if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" ) { if( !responseObject.message ) alert(Language.Translate(2500114)); else alert(responseObject.message); } else { } } }); requestsInProgress++; request.send(); } function deletePollConfirm(pollID) { // One request at a time please if( requestsInProgress>=maxRequestsInProgress ) { alert(bind.Base.Language.Translate(2500115)); return false; } // Display jQuery('#sePoll_'+pollID).remove(); // Ajax var bind = this; var request = new Request.JSON({ 'method' : 'post', 'url' : pollajaxurl, 'data' : { 'task' : 'deletepoll', 'poll_id' : pollID }, 'onComplete': function(responseObject) { bind.requestsInProgress--; if( !responseObject || $type(responseObject)!="object" || responseObject.result=="failure" ) { if( !responseObject.message ) alert(bind.Base.Language.Translate(2500114)); else alert(responseObject.message); } } }); this.requestsInProgress++; request.send(); // SHOW NEW MESSAGE if( $$('.sePollRow').length<1 ) $('pollnullmessage').style.display = 'block'; } function sendpollvote(value, id){ // 'this' is the hidden form element holding the current value // 'value' is the value selected // 'element' points to the link element that received the click. if( requestsInProgress>=maxRequestsInProgress ) { alert("Please wait until the previous operation is complete until starting another."); return false; } var request = new jQuery.ajax({ 'url' : pollajaxurl, 'method' : 'post', 'secure' : false, 'data' : { 'task' : 'votepoll', 'poll_id' : id, 'vote' : value }, dataType: 'json', success : function(responseObject) { requestsInProgress--; if( !responseObject || jQuery.type(responseObject)!="object" || responseObject.result=="failure" ) { if( !responseObject.message ) alert("There was an error processing your request."); else alert(responseObject.message); } else { generatepollresults(id, responseObject); pollViewMode(id); } } }); //request.send(); // To submit the form automatically: //this.form.submit(); // To submit the form via ajax: //$(this.form).ajaxSubmit(); } function getpolldata(id){ // 'this' is the hidden form element holding the current value // 'value' is the value selected // 'element' points to the link element that received the click. /*if( requestsInProgress>=maxRequestsInProgress ) { alert("Please wait until the previous operation is complete until starting another."); return false; }*/ var request = new jQuery.ajax({ 'method' : 'post', 'url' : pollajaxurl, 'data' : { 'task' : 'infopoll', 'poll_id' : id }, dataType: 'json', success: function(responseObject) { requestsInProgress--; if( !responseObject || jQuery.type(responseObject)!="object" || responseObject.result=="failure" ) { if( !responseObject.message ) alert("There was an error processing your request."); else alert(responseObject.message); } else { generatepollresults(id, responseObject); pollViewMode(id); } } }); //this.requestsInProgress++; //request.send(); // To submit the form automatically: //this.form.submit(); // To submit the form via ajax: //$(this.form).ajaxSubmit(); } function generatepollresults(pollID, pollDataObject){ var pollResultsContainer = $j('poll'+pollID+'_results'); pollResultsContainer.empty(); // Options //var bind = this; var isFirst = true; var pollResultIndex = 1; showstr='
'; $j.each(pollDataObject.poll_options, function(pollOptionIndex, pollOptionLabel) { //var pollResultTemplate = jQuery('#pollResultTemplate').getElement('.pollResult').clone(); var pollResultTemplate = jQuery('pollResultTemplate .pollResult').clone(); // Generate Stats var pollResultID = "poll" + pollID + "_bar" + pollOptionIndex; var pollResultClass = "poll_bar" + (pollResultIndex - (20 * Math.floor(pollResultIndex/20))).toString(); var width = 3; var percentage = 0; if(parseInt(function(){ return pollDataObject.poll_answers[pollOptionIndex]; })=="NaN"){thisVoteCount=0} else{thisVoteCount=function(){ return pollDataObject.poll_answers[pollOptionIndex]; }; thisVoteCount=thisVoteCount(); } width += Math.round((thisVoteCount / pollDataObject.poll_totalvotes) * 400); percentage += Math.round((thisVoteCount / pollDataObject.poll_totalvotes) * 100); // Apply to template if(thisVoteCount!=1){ var votesString = thisVoteCount+" votes";//'('+bind.Base.Language.TranslateFormatted(2500028, [thisVoteCount || '0'])+')'; } else{var votesString = thisVoteCount+" vote";} //$j('.pollResultLabel').addClass(pollResultClass); /*pollResultTemplate.getElement('.pollResultLabel').setProperty('html', pollOptionLabel); pollResultTemplate.getElement('.pollResultBar').addClass(pollResultClass); pollResultTemplate.getElement('.pollResultBar').setProperty('id', pollResultID); pollResultTemplate.getElement('.pollResultPercentage').setProperty('html', percentage+'%'); pollResultTemplate.getElement('.pollResultVotes').setProperty('html', votesString);*/ // Space them if( !isFirst ) { //(new Element('br')).inject(pollResultTemplate, 'top'); $j(pollResultTemplate).prepend("
"); //(new Element('br')).inject(pollResultTemplate, 'top'); } // Inject //pollResultTemplate.inject(pollResultsContainer); $j(pollResultTemplate).append(pollResultsContainer); pollResultIndex++; isFirst = false; var width = 3; var percentage = 0; if( pollDataObject.poll_answers[pollOptionIndex] ) width += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 400); if( pollDataObject.poll_answers[pollOptionIndex] ) percentage += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 100); // showstr+='
 
'+pollOptionLabel+'
'+percentage+'% ('+votesString+')
'; /*$j('.pollResult').each(function(){ $j(this).find('poll'+pollID+'_bar'+(pollResultIndex-1)).animate({ width:$j(this).attr('data-percent') },6000); alert("SSS"); }); */ //document.getElementById(pollResultID).style.width="100%"; // alert(document.getElementById('poll2130_results').innerHTML); }); showstr+='
'; document.getElementById('poll'+pollID+'_results').innerHTML=showstr; // Effects /*$j.each(pollDataObject.poll_options,function(pollOptionIndex, pollOptionLabel) { var pollResultElement = $j("#poll" + pollID + "_bar" + pollOptionIndex); //alert("fffff"); var width = 3; var percentage = 0; if( pollDataObject.poll_answers[pollOptionIndex] ) width += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 400); if( pollDataObject.poll_answers[pollOptionIndex] ) percentage += Math.round((pollDataObject.poll_answers[pollOptionIndex] / pollDataObject.poll_totalvotes) * 100); //document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.backgroundColor="red"; alert("poll" + pollID + "_bar" + pollOptionIndex); //jQuery("poll" + pollID + "_bar" + pollOptionIndex).style.display="block"; alert("AA"); //jQuery("#poll" + pollID + "_bar" + pollOptionIndex).style.display="block"; alert("AA"); //document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.width="100%"; alert("AA"); //document.getElementById("poll" + pollID + "_bar" + pollOptionIndex).style.height="300px"; /*jQuery(pollResultElement).animate({ left: 500, top: [500, 'easeOutBounce'] }, 1000);*/ //var pollEffect = new Fx.Tween(pollResultElement, {duration: 1000, transition: Fx.Transitions.Quad.easeOut}); // alert("aaa"); //pollEffect.start('width', 3, width); // }); } function showPollDelete(pollID) { var pollContainer = document.getElementById('sePoll_'+pollID); currentConfirmDeleteID = pollID; opendivmodal('confirmpolldelete'); } function pollViewMode(pollID) { document.getElementById('poll'+pollID+'_results').style.display = "block"; document.getElementById('poll'+pollID+'_results_actions').style.display = "block"; document.getElementById('poll'+pollID+'_vote').style.display = "none"; document.getElementById('poll'+pollID+'_vote_actions').style.display = "none"; } function pollVoteMode(pollID) { document.getElementById('poll'+pollID+'_results').style.display = "none"; document.getElementById('poll'+pollID+'_results_actions').style.display = "none"; document.getElementById('poll'+pollID+'_vote').style.display = "block"; document.getElementById('poll'+pollID+'_vote_actions').style.display = "block"; }