addevent = function(onwas, func){
  if(window.addEventListener) return window.addEventListener(onwas, func, false);
  else if(window.attachEvent) return window.attachEvent("on" + onwas, func);
  else if(document.getElementById) return window.onwas = func;
}

autofeld = function(){
  var feldtempvalue;
  $('profillink').observe('focus', function(){ feldtempvalue = this.value; this.value = ''; });
  $('profillink').observe('blur', function(){ if(this.value == '') this.value = feldtempvalue; });
}

allesistaus = function(){
 // $('formwithallin').enable();
  $('statusresults').className = 'hoeraufdichzudrehen';
}

getstats = function(){
  $('statusresults').className = '';
  $('results').show();
  
  if($('profillink').value == '' || $('profillink').value == 'www.schuelervz.net/Profile/...'){
    $('statusresults').innerHTML = 'Bitte gebe den Link zu deinem sch&uuml;lerVZ Profil ein!<br />(<a href="javascript:void(0);" onclick="Effect.toggle(\'profillinkhowto\', \'slide\');">wo finde ich den denn?!</a>)';
    allesistaus();
    return false;
  }
  
  if($('profillink').value.substr(0, 7) == 'http://') $('profillink').value = $('profillink').value.substr(7);
  
  if($('profillink').value.substr(0, 27) != 'www.schuelervz.net/Profile/' && $('profillink').value.substr(0, 24) != 'www.studivz.net/Profile/'){
    $('statusresults').innerHTML = 'Der eingegebene Link f&auml;ngt nicht mit "www.schuelervz.net/Profile/" oder "www.studivz.net/Profile/" an!';
    allesistaus();
    return false;
  }
  
  $('statusresults').innerHTML = 'Initialisierung..';
  
  new Ajax.Request('/getstats.php', {
    method: 'post',
    parameters: $('formwithall').serialize(true),
    onLoading: function(){
      // $('formwithallin').disable();
    },
    onFailure: function(){
      $('statusresults').innerHTML = 'Etwas ist fehlgeschlagen, bitte versuche es sp&auml;ter erneut und/oder <a href="http://forum.svzcommunity.net/">melde es</a>.';
      allesistaus();
    }
  });
  
  return false;
}

weiterwennzuviel = function(sid){
  // $('formwithallin').disable();
  $('statusresults').className = '';
  $('statusresults').innerHTML = 'Okay.. einen Moment!';
  new Ajax.Request('/getstats.php?sid='+sid, {
    method: 'post',
    parameters: {
      send: 'send',
      schritt: 3
    },
  });
}

captchasend = function(){
  $('statusresults').innerHTML = 'Okay.. einen Moment!';
  new Ajax.Request('/getstats.php', {
    method: 'post',
    parameters: $('captchaform').serialize(true)
  });
}

recaptcha = function(sid){
  $('statusresults').innerHTML = 'Okay.. einen Moment!';
  new Ajax.Request('/getstats.php?sid='+sid, {
    method: 'post',
    parameters: { schritt: 'captcha', send: 'send' }
  });
}

updatestatcounter = function(){
  new Ajax.PeriodicalUpdater('statcounter', '/getcounter.php', {
    method: 'get',
    frequency: 5,
    decay: 2
  });
}

loadcurrentserverid = function(){
  new Ajax.Updater('serverid', '/getcurrserver.php', {
    method: 'get'
  });
}

getcached = function(sid){
  $('statusresults').innerHTML = 'Okay.. einen Moment!';
  new Ajax.Request('/getstats.php?sid='+sid, {
    method: 'post',
    parameters: { getcached: 'true', send: 'send' }
  });
}

// dummes reines html, naja.. get dann halt via js..
initget = function(){
  HTTP_GET_VARS = new Array();
  strGET = document.location.search.substr(1, document.location.search.length);
  if(strGET!=''){
    gArr=strGET.split('&');
    for(i=0;i<gArr.length;++i){
      v='';vArr=gArr[i].split('=');
      if(vArr.length>1){v=vArr[1];}
      HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
    }
  }
}

getprofidbyget = function(){
  profilbyget = HTTP_GET_VARS['profil'];
  submitbyget = HTTP_GET_VARS['submitit'];
  if(profilbyget && profilbyget != ''){
    if(profilbyget.substr(0, 34) != 'http://www.schuelervz.net/Profile/') 
      $('profillink').value = 'http://www.schuelervz.net/Profile/'+profilbyget;
    else $('profillink').value = profilbyget;
  }
}

getnews = function(){
  new Ajax.Updater('newscont', '/news.php', {
    method: 'get'
  });
}

addevent('load', function(){
  autofeld();
  initget();
  
  getprofidbyget();
  updatestatcounter();
  loadcurrentserverid();
  getnews();
  
  $('results').hide();
  $('nojs').hide();
  $('text').show(); 
  $('navi').show();
});