// версия без дизайна для BBB
/*function poll() {};
poll.vote = function(element, essenceType, essenceId, mark){
  var url = W_AJAX + 'poll.php';
  $.post(url,
    {
      type: "application/x-www-form-urlencoded",
      essenceType: essenceType,
      essenceId:  essenceId,
      mark:  mark
    },
    function(responseText) {
      if (navigator.userAgent.indexOf ("Opera") != -1) var arrInfo = eval('(' + responseText + ')');
     else var arrInfo = JSON.parse(responseText);
      if(arrInfo['result'] == 'OK') {
        $(element).parent().find('p').removeClass('empty').html(arrInfo['average_mark']);
        var secondImg = $(element).parent().find("img[src!='" + $(element).attr('src') + "']");
        if($(secondImg).attr('src') == W_IMAGES + 'icons/up.gif')
         $(secondImg).attr('src',  W_IMAGES + 'icons/upGrey.gif');
        else
         $(secondImg).attr('src',  W_IMAGES + 'icons/downGrey.gif');
      }
      else
        alert(arrInfo['err_text']); 
    });
};*/

function poll() {};

poll.showResultMsg = function(txt, status) {
    if ($("#successPoll").length) $("#successPoll").remove();
    if (status <= 0) {
      txt = '<span class="red-text">' + txt + '</span>';
    }
  	var strEl = '<div class="pop-up" id="successPoll">' +
			        '<table class="pmain" cellspacing="0" cellpadding="0" border="0">' +
			          '<tr><td class="tl"/><td class="t"/><td class="tr"/></tr>' +
			          '<tr>' +
			            '<td class="l"/>' +
			            '<td class="body">' +
			              '<div class="content" style="display: block;">' +
			               txt + '</div>' +
			            '</td><td class="r"/>' +
			         '</tr>' +
			          '<tr><td class="bl"/><td class="b"/><td class="br"/></tr>' +
			        '</table>' +
			      '</div>';
  $(".poll_box").prepend(strEl);
  $("#successPoll").css("left", $(".poll_box").offset().left+100).fadeIn(1000);
  $("#successPoll").fadeOut(2000);
}

poll.vote = function(element, essenceType, essenceId, mark, idFolder){
  var url = W_AJAX + 'poll';
  $.post(url,
    {
      type: "application/x-www-form-urlencoded",
      essenceType: essenceType,
      essenceId:  essenceId,
      mark:  mark,
      idFolder: idFolder
    },
    function(responseText) {
      if (navigator.userAgent.indexOf ("Opera") != -1) var arrInfo = eval('(' + responseText + ')'); // 
     else var arrInfo = JSON.parse(responseText);
      if(arrInfo['result'] == 'OK') {
      		  var pBlock = $(element).parent().parent().parent();
	      		$(pBlock).html(arrInfo['markBlock']);
	      		poll.showResultMsg("Спасибо, Ваш голос учтён!", 1);
      } else poll.showResultMsg(arrInfo['err_text'], -1);
    });
};