function readCookie(cookieName){
  a = document.cookie;
  res = '';
  while(a != ''){
    currentCookieName = a.substring(0,a.search('='));
    currentCookieValue = a.substring(a.search('=')+1,a.search(';'));
    if(currentCookieValue == '') {currentCookieValue = a.substring(a.search('=')+1,a.length);}
    if(cookieName == currentCookieName){res = currentCookieValue;}
    i = a.search(';')+1;
    if(i == 0){i = a.length}
    a = a.substring(i,a.length);
  }
  return res;
}
function writeCookie(n,v,e){
  var a = new Date();
  a = new Date(a.getTime() +e);
  document.cookie = n+'='+v+'; expires='+a.toGMTString()+';';
}
function updateJokeRating($rs){ updateRating($rs, 'rj');}
function updatePPSRating($rs){ updateRating($rs, 'rp');}
function updateRating($rs, $cookieName){
  $elemId = $rs.split(';')[0];
  $newAvg = $rs.split(';')[1];
  aV = document.getElementById('aV_' + $elemId);
  aV.innerHTML = parseInt(aV.innerHTML) + 1;
  avg = document.getElementById('avg_' + $elemId);
  avg.innerHTML = $newAvg;
  document.getElementById('rs_' + $elemId).style.visibility = 'hidden';
  writeCookie($cookieName, readCookie($cookieName) + ',' + $elemId, 1000*60*60*24*365);
}
function setupLinks() {$("div.navi").find("a").each(function() {var anchor = $(this);anchor.click(function() {try {
$("body").append('<div id="loader" class="load" title="Daten werden geladen"></div>');
$.ajax({
type: "GET",
url: anchor.attr("href"),
beforeSend: function(xhr) { xhr.setRequestHeader( "Content-type", "text/html; charset=utf-8" ); },
success: replaceElems
});
return false;}catch (e) { return true; }});});}
function replaceElems(data) {
$('#loader').remove();
var div = document.createElement("body");div.innerHTML = data;$("#main_content").replaceWith($(div).find("#main_content"));
setupLinks();}
function setupRss() { $("#rss > a").attr("href", "http://feedproxy.google.com/Witze-Zum-Ablachen-Der-Witze-rss-feed"); }
$(document).ready(function() { setupLinks();setupRss(); });