function report(module, type, id)
{
  this.module = module;
  this.type = type;
  this.id = id;
  
  var that = this;
  
  this.overlay = document.getElementById('report_overlay');
  this.centerCont = document.getElementById('report_centercont');
  
  this.reportCallback = function(response)
  {
    that.overlay.style.display = 'none';
    that.centerCont.style.display = 'none';
    
    alert(response.text);
  }
  
  this.onCancel = function()
  {
    that.overlay.style.display = 'none';
    that.centerCont.style.display = 'none';
  }
  
  this.onSend = function()
  {
    var reason = document.getElementById('report_reason').value;
    
    if(reason.length < 15)
    {
      alert('Bitte gib mindestens 15 Zeichen an!');
      return false;
    }
    
    var request = new ajaxRequest({
      url:'lib/ajax/report.php',
      type:'POST',
      callback:that.reportCallback,
      data:{
        reason:reason,
        module:that.module,
        type:that.type,
        id:that.id
      }
    });
    request.startRequest();
  }
  
  if(this.overlay === null || this.centerCont === null)
  {
    this.overlay = document.createElement('div');
    this.overlay.style.position = 'fixed';
    this.overlay.style.width = '100%';
    this.overlay.style.height = '100%';
    this.overlay.id = 'report_overlay';
    this.overlay.style.backgroundColor = '#FFFFFF';
    transparency(this.overlay, 75);
    
    this.centerCont = document.createElement('div');
    this.centerCont.style.width = '100%';
    this.centerCont.style.height = '100%';
    this.centerCont.style.zIndex = '50000';
    this.centerCont.id = 'report_centercont';
    this.centerCont.style.position = 'absolute';
    
    var cont = document.createElement('div');
    cont.style.marginLeft = 'auto';
    cont.style.marginRight = 'auto';
    cont.style.borderWidth = '1px';
    cont.style.borderColor = '#999999';
    cont.style.borderStyle = 'solid';
    cont.style.backgroundColor = '#FFFFFF';
    cont.style.width = '400px';
    cont.innerHTML = '<div style="margin: 10px;"><textarea name="report_reason" id="report_reason" rows="5" style="width: 378px;"></textarea></div>';
    
    var contButtons = document.createElement('div');
    contButtons.style.textAlign = 'left';
    contButtons.style.marginRight = '10px';
    contButtons.style.marginLeft = '10px';
        
    var cancel = document.createElement('img');
    cancel.onclick = this.onCancel;
    cancel.src = 'img/icons/forum/cancel.gif';
    cancel.style.margin = '5px';
    contButtons.appendChild(cancel);
    
    var send = document.createElement('img');
    send.onclick = this.onSend;
    send.src = 'img/icons/forum/report.gif';
    send.style.margin = '5px';
    contButtons.appendChild(send);
    
    cont.appendChild(contButtons);
    this.centerCont.appendChild(cont);
    
    var body = document.getElementsByTagName('body')[0];
    body.insertBefore(this.centerCont, body.firstChild);
    body.insertBefore(this.overlay, body.firstChild);
    
    var top = typeof window.pageYOffset !== 'undefined' ? window.pageYOffset : (typeof document.documentElement.scrollTop  !== 'undefined' ? document.documentElement.scrollTop : document.body.scrollTop);
    
    cont.style.marginTop = top + ((screen.availHeight - cont.offsetHeight) / 2) + 'px'; 
  }
  else
  {
    that.overlay.style.display = 'block';
    that.centerCont.style.display = 'block';
    document.getElementById('report_reason').value = '';
  }
}

function doReport(module, type, id)
{
  r = new report(module,type,id);
  
  return false;
}
