function pollLoader(container){
var loader = '
';
loader +='

';
loader +='
';
$j('#'+container).html(loader);
}
function getPollResults(poll_id){
pollLoader('poll_system');
$j.ajax({
url: getSiteRoot()+'/poll/fetch.php?action=post_result&id='+poll_id,
cache: false,
dataType: "html",
success: function(data){
$j('#poll_system').html(data);
}
});
}
function getPoll(poll_id){
pollLoader('poll_system');
$j.ajax({
url: getSiteRoot()+'/poll/fetch.php?action=showpoll&id='+poll_id,
cache: false,
dataType: "html",
success: function(data){
$j('#poll_system').html(data);
}
});
}
function isVoteCasted(){
var $jfields = $j('#poll_system').find('input[name="note"]:checked');
if (!$jfields.length){
alert('Please select an option to vote for!');
return false;
}else{
return true;
}
}
function casteVote(poll_id){
//Check if the vote has been casted
var option = document.getElementById("option").value;
var $jfields = $j('#poll_system').find('input[name="note"]:checked');
if (!$jfields.length){
alert('Please select an option to vote for!');
return false;
}
//End of checking if the vote has bee casted
pollLoader('poll_system');
$j.ajax({
url: getSiteRoot()+'/poll/fetch.php?action=post_result&id='+poll_id+'&option='+option,
cache: false,
dataType: "html",
success: function(data){
$j('#poll_system').html(data);
}
});
}
function begen(vote,color){
$j('#option').val(vote);
$j('#selected_color').val(color);
}
function getSiteRoot(){//Get the site toot url
return document.getElementById("siteroot").innerHTML;
}
function validatePollCommentsForm(){
if(document.getElementById("name").value == ""){
document.getElementById("error").innerHTML="Please enter your name!";
document.frm.name.focus();
return false;
}
if(!document.getElementById("email").value.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/)){
document.getElementById("error").innerHTML="Please enter your email!";
document.frm.email.focus();
return false;
}
if(document.getElementById("comment").value == ""){
document.getElementById("error").innerHTML="Please enter comment!!";
document.frm.comment.focus();
return false;
}
return true;
}
function savePollComments(){
if(validatePollCommentsForm() == false){
return false;
}
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var comment = document.getElementById("comment").value;
var pID = document.getElementById("pollID").value;
$j("#error").html('
');
$j.post(getSiteRoot()+"/poll/save-poll-comments.php", {name:name,email:email,comment:comment,pID:pID},function(data){
if(data = "SAVED"){
$j("#error").html('Thanks! Your comment will be posted shortly.');
document.getElementById("name").value = "";
document.getElementById("email").value = "";
document.getElementById("comment").value = "";
}else{
$j("#error").html('System error! Comments were not saved, please try again.');
}
});
}
function pollRate(comID,comments,rate_type){//This function rates the poll comments
$j("#"+comments).html('
');
$j.post(getSiteRoot()+"/poll/poll-rate.php", {comID:comID,rate_type:rate_type},function(data){
$j("#"+comments).html(data);
});
}
function getComments(pID,poll_comments_max_results,page,poll_comments_order){
if(poll_comments_order=='Sort By'){
return false;
}
$j("#comments").html('');
$j.post(getSiteRoot()+"/poll/get-comments.php", {pID:pID,poll_comments_max_results:poll_comments_max_results,page:page,poll_comments_order:poll_comments_order},function(data){
$j("#comments").html(data);
});
}