function goTo(address, timeout)
{
  if(timeout > 0)
  {
    window.setTimeout(function(){document.location.href = address;}, timeout);
  }
  else
  {
    document.location.href = address;
  }
}

function closeRankingLayer()
{
  $('#ranking-layer').hide();
  $('table.ranking tr td').css({background: ''});
}

function openRankingLayer(script, type, value, area)
{
  closeRankingLayer();
  var value_offset = $('#'+value).next().offset();

  $('#'+value+' > td').css({background: '#ffffff'});

  $('#ranking-layer').css({'top': value_offset.top+'px','left': value_offset.left+'px'});
  $('#rl-content').html('<img src="images/ajax-loader.gif">');
  $('#ranking-layer').fadeIn('slow');

  $.ajax({
    url: 'ajax/'+script,
    data: {type: type, value: value, area: area},
    type: 'POST',
    cache: false,
    async: true,
    success: function(data) {
      $('#rl-content').html(data);
    }
  });
}

function checkIKNr(iknr, url, msgid)
{
  $.ajax({
    url: 'ajax/request-check-iknr.php',
    data: {q: iknr},
    type: 'POST',
    cache: false,
    async: true,
    success: function(data) {
      if(data == "true")
      {
        goTo(url);
      }
      else
      {
        $('#'+msgid).dialog('open');
      }
    }
  });
}

function closeChartLayer()
{
  $('#chart-layer').hide();
  $('td:first-child').removeClass('highlight-left');
  $('td').removeClass('highlight');
  $('#chart-layer-connector').css({'display': 'none'});
}

function openChartLayer(type, abtid, bgColor, value)
{
  closeChartLayer();
  var value_offset = $('#'+value).offset();
  var value_first_offset = $('#'+abtid).offset();

  $('#'+value+' td:first-child').addClass('highlight-left');
  $('#'+value+' td').addClass('highlight');

  $('#chart-layer-connector').css({'top': (value_offset.top + 1)+'px', 'left': (value_offset.left + 595)+'px', 'background': bgColor, 'display': ''});

  //$('#chart-layer').css({'top': (value_first_offset.top + 26)+'px', 'left': (value_first_offset.left + 600)+'px', 'background': bgColor});
  $('#chart-layer').css({'top': (value_offset.top - 130)+'px', 'left': (value_offset.left + 600)+'px', 'background': bgColor});

  $('#cl-content').html('<img src="images/ajax-loader.gif">').css({'background': bgColor});
  $('#chart-layer').show();

  $.ajax({
    url: 'ajax/request-modul-bewertungen.php',
    data: {type: type, bgColor: bgColor, value: value},
    type: 'POST',
    cache: false,
    async: true,
    success: function(data) {
      $('#cl-content').html(data);
    }
  });
}

function popUp(url, p)
{
  popup = window.open(url, 'popup', 'width='+p.width+',height='+p.height+',status='+p.status+',location='+p.location+',scrollbars='+p.scrollbars+',resizable='+p.resizable+',menubar='+p.menubar+',toolbar='+p.toolbar+',top='+p.top+',left='+p.left);
  popup.focus();
}