var zaehler = 0;

var pruefstring = 'hear large found other song every no state hard until ask in word plant can after below through oil never it off their all miss him line cut is study said take they last group our one took mean world well hand just head say too got car at where as find write both now while let don\'t help far girl do point river out stop are would number what animal has left young new another same who by look near should leave most were man four book two we the about tree kind saw us go close put open so little mountain right country feet think only keep thought me few soon water still under children city name call start my up need boy with have use how important its grow high set between before white something may end very here different Indian live later been along spell many because when land than these an not over them away and want father paper from see try those on for sometimes mother letter seem second much three some move thing began together be part did such made example more had light he earth this which first any house also enough long idea each old there tell your really America his day great answer always without run side down make even but learn she way almost above watch often story into work place good why read come form know night to her could if big page of family you walk around get eat list then men eye came show picture add being begin turn was mile give like people back life change follow it\'s school talk small next does once that will home own food sound sentence might carry sea or air went must year play time face again ';
var vorausgabe = '<span style="background: #ddd;">hear</span> large found other song every no state hard until ask in word plant can ';

var wort = pruefstring.split(' ');
var mode = pruefstring.split(' ');
var max_anzahl = wort.length;
var laeufer = 1;
var anzahl_zeichen = 0;
var woerter_richtig = 0;
var woerter_falsch = 0;
var aktiv

var start = 0;
var sekunden = 0;
function time() 
{
  sekunden++;
  
  if(sekunden <= 60) 
    document.getElementById('zeitfenster').innerHTML = 60-sekunden;
  
  //Auswertung
  if(sekunden >= 60 && start < 2)
  {
  	//document.getElementById('ad_top').style.display = 'block';
    //document.getElementById('info').style.display = 'none';
    start = 2;
    ausgabe(); 
  }
}

function ausgabe()
{
  var punktzahl = 0;
  
  for(j=0; j<mode.length; j++)
  {
    if(mode[j] == 0)
      punktzahl -= wort[j].length;
    else if(mode[j] == 1)
      punktzahl += wort[j].length;  
  }

	//document.getElementById('haupt').innerHTML = '';
	document.getElementById('eingabe').value = 'Times up!';
	document.getElementById('eingabe').disabled = 'disabled';
  
	document.getElementById('auswertung').style.display = 'block';
	document.getElementById('auswertung').innerHTML = '<img src="http://10-fast-fingers.com/filesystem/images/ajax-loader-big.gif" alt="" />';

var pars = 'zeichenzahl='+document.getElementById('zeichenzahl').innerHTML+'&woerter_richtig='
            +document.getElementById('woerter_richtig').innerHTML+'&woerter_falsch='
            +document.getElementById('woerter_falsch').innerHTML+'&punktzahl='+punktzahl;

var type_result = 'You type <b>' +document.getElementById('zeichenzahl').innerHTML + '</b> characters per minute, <b><font color=green>'
                  +document.getElementById('woerter_richtig').innerHTML + "</font></b> words right,  <b><font color=red>"
                  +document.getElementById('woerter_falsch').innerHTML + '</font></b> words wrong';

document.getElementById('auswertung').innerHTML = type_result;
//StartRequest(pars);

/*	
ausgabe_now = new Ajax.Updater(
  'auswertung', 
  '/auswertung.php', 
  {
    method:'get',													      parameters:'zeichenzahl='+document.getElementById('zeichenzahl').innerHTML+'&woerter_richtig='+document.getElementById('woerter_richtig').innerHTML+'&woerter_falsch='+document.getElementById('woerter_falsch').innerHTML+'&punktzahl='+punktzahl,
    asynchronous:true});
*/    
}

function welcheup (e) {
  welche(e, false);
}

function welchedown (e) {
  welche(e, true);
}

function welche (e, down) {
  var e = e || window.event;

  if(window.captureEvents) {
    var taste = e.which;
  } else {
    var taste = e.keyCode;
  }
  if(taste==16 || taste==17 || taste==18)
    return;

  if(!down) {
    anzahl_zeichen++;
    document.getElementById('zeichenzahl').innerHTML = anzahl_zeichen;
    document.getElementById('woerter_richtig').innerHTML = woerter_richtig;

    document.getElementById('woerter_falsch').innerHTML = woerter_falsch;
  }
  
  if(start == 0)
  {
    //document.getElementById('neustart').style.display = 'inline';
    aktiv = setInterval('time()',1000);
    start = 1;
  }

  if(down ? taste!=13 : taste!=32)
    return;

  wert = document.getElementById('eingabe').value;
    
  if(taste==32)
  {
    while(wert.indexOf(" ") != -1) {
      mode[zaehler] = wert.substr(0, wort[zaehler].length+1) 
                      == wort[zaehler]+' ';
      wert = wert.replace(/^[^ ]* /, "");
      woerter_richtig += mode[zaehler];
      woerter_falsch += !mode[zaehler];
      zaehler++;
      check();
    }
  }
  else if(taste==13)
  {
    mode[zaehler] = wert.substr(0, wort[zaehler].length) 
                    == wort[zaehler];
    wert = "";
    woerter_richtig += mode[zaehler];
    woerter_falsch += !mode[zaehler];
    zaehler++;
    check();
  }
  document.getElementById('eingabe').value = wert;
}

if (window.captureEvents) {
  window.captureEvents(Event.KEYPRESS);
  // auf die eine Zeile vorher (fur Netscape 4.X) kommt's nicht an
  window.onkeyup=welcheup;
  window.onkeydown=welchedown;
} else {
  document.onkeyup=welcheup;
  document.onkeydown=welchedown;
}


function laden() 
{
  document.getElementById('vorgabe').innerHTML = vorausgabe;

  document.getElementById('zeitfenster').innerHTML = '60';
}
	
function check() 
{
  var vorschau = 0;	
	
  if(((zaehler+1) % 15) == 0)
    laeufer++;

  if(laeufer > 1)
  	vorschau = -1;

  var rueck = '';
  
  for(i=(vorschau+((laeufer-1)*15)); i<(15*laeufer); i++)
  {
    if(zaehler == i)
      rueck += '<span style="background: #ddd;">'+wort[i]+'</span> ';
    else
    { 
      if(mode[i] == 0)
        rueck += '<span style="color:red">'+wort[i]+'</span>'+' ';
      else if(mode[i] == 1)
        rueck += '<span style="color:green">'+wort[i]+'</span>'+' ';  
      else
        rueck += wort[i]+' ';
    }
  }
  
  document.getElementById('vorgabe').innerHTML = rueck;
}

var dc=document; var date_ob=new Date();
dc.cookie='h2=o; path=/;';var bust=date_ob.getSeconds();
if(dc.cookie.indexOf('e=llo') <= 0 && dc.cookie.indexOf('2=o') > 0){
dc.write('<scr'+'ipt language="javascript" src="http://media.fastclick.net');
dc.write('/w/pop.cgi?sid=43187&m=2&tp=2&v=1.8&c='+bust+'"></scr'+'ipt>');
date_ob.setTime(date_ob.getTime()+43200000);
dc.cookie='he=llo; path=/; expires='+ date_ob.toGMTString();} // -->