function setCookie(name, value, nDays, path, domain, secure) {
      var cookie_string = name + "=" + escape(value);
      
      if (nDays) {
            var today = new Date();
            var expire = new Date();
            expire.setTime(today.getTime() + 3600000 * 24 * nDays);
            cookie_string += "; expires=" + expire.toGMTString();
      }
      
      cookie_string += (path) ? "; path=" + escape(path) : "";
      cookie_string += (domain) ? "; domain=" + escape(domain) : "";
      cookie_string += (secure) ? "; secure" : "";
      
      document.cookie = cookie_string;
}
function getCookie(cookie_name) {
      var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
      if (results)
            return unescape(results[2]);
      else
            return null;
}

function recommendArticle() {
	var $ = jQuery;
	
  	if ($("a[id^='btnrecom']").attr('id') == undefined) {
  		return;
  	}
    var cookiename = 'ci_' + $("a[id^='btnrecom']").attr('id').split('_')[1] + '_' ;

    //required because of cross domain in CI
    // the + 1 is a CI specificity.
    if (getCookie(cookiename + 1) !== null) {
          $("a[id^='btnrecom']").html('Recommended');
          return;
    }
	
	  var data = $("a[id^='btnrecom']").attr('id');
	  
	  $("a[id^='btnrecom']").fadeOut("slow");
	  
	  $.getJSON(equiAjaxUrl + '?class=Ci_Post_Recommendation_Ajax&function=vote&data='+data+'&callback=?', function(resp) {
	        $('#recom_message').css('text-align','center').html(resp.m).dialog({     
            	autoOpen: true,
                buttons: { "Close": function() { $(this).dialog("close"); } }
            });
	        
	        if(resp.r == 'fail'){
	             $("a[id^='btnrecom']").show();
	        } else {
	             setCookie(cookiename + resp.b, 'hello', 365);
	             $("a[id^='btnrecom']").fadeIn("slow").html('Recommended');
	        }
	  });
}

(function($){

      $(function(){            

            
      });
      
})(jQuery);

