<!--
/*
ein Script von massa :D
 _ __ ___   __ _ ___ ___  __ _ 
| '_ ` _ \ / _` / __/ __|/ _` |
| | | | | | (_| \__ \__ \ (_| |
|_| |_| |_|\__,_|___/___/\__,_|*/

//str_replace von php für javascript zugänglich machen
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

function sendRequest(id) {
	//aktuelles game für + - pfeil festlegen
	for(r=0; r<gameList.length; r++) {
		if(id==gameList[r]) g = r;
	}
	//game name anzeigen
	if(0 == id) {
		document.getElementById("gamelist_name").innerHTML = "&Uuml;bersicht";
	} else {
		document.getElementById("gamelist_name").innerHTML = gameListNames[g];
	}
	//request senden
	  try {
	  	  //unterscheiden zwischen IE und anderen browsern
	  	  req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e) {
			  //Kein AJAX Support
			   document.getElementById('latestmatches').innerHTML = 'AJAX wird von Ihrem Browser nicht unterst&uuml;tzt';
	  }
	  req.onreadystatechange = handleResp; //antwort verarbeiten
	 if('0'==id) {
		 req.open('get', 'ajax-latestmatches-content.php');
	 }else{
		 req.open('get', 'ajax-latestmatches-content.php?sp='+id);
	 }
	  req.send(null);
}

function handleResp() {
 /* 0 (nicht initialisiert)
  * 1 (lade)
  * 2 (geladen)
  * 3 (interaktiv)
  * 4 (vollständig)
  */
	  //es wird geladen
	  if (req.readyState != 4) {
			  document.getElementById('latestmatches').innerHTML = '<center><img src="images/loading.gif"><\/center>';
	  }
	  //wenn vollkommen geladen
	  if ((req.readyState == 4) && (req.status == 200)) {
	  		  var divtext;
			  divtext = str_replace('ä', '&auml;', req.responseText);
			  divtext = str_replace('ü', '&uuml;', divtext);
			  divtext = str_replace('ö', '&ouml;', divtext);
			  document.getElementById('latestmatches').innerHTML = divtext;
	  }
}

var g = 0;
function nextGame() {
	g++;
	if(g > (gameList.length-1)) g = 0;
	sendRequest(gameList[g]);
} 
function lastGame() {
	if(g == 0) {
		g = gameList.length-1;
	} else {
		g--;
	}
	sendRequest(gameList[g]);
}

sendRequest(0);
//nextGame();
//-->