/*
Funktionen für die AJAX-Funktionalität
*/
var xmlHttp = null;		// das XMLHttpRequest-Objekt


// Ein XMLHttpRequest-Objekt erzeugen
function ErzeugeRequest()
{
	// Microsoft Internet Explorer verwendet ActiveXObject
	if (window.ActiveXObject)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml12.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) 
			{
				alert ("Kann für den IE kein XMLHttp-Objekt erzeugen")	
			}
		}
	}
	// Alle übrigen Browser verwenden XMLHttpRequest
	else if (window.XMLHttpRequest)
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) 
		{
				alert ("Kann kein XMLHttp-Objekt erzeugen")	
		}
	}
	return xmlHttp;	
}


function AnfrageAktiv(xmlHttp) 
{
	return (xmlHttp.readyState > 0 && xmlHttp.readyState < 4);
}


function SendeRequest (wert)
{
	// Anfrage starten
	if (xmlHttp)
	{
		if (AnfrageAktiv(xmlHttp) && (browser == "Netscape" || browser == "Opera"))
		{
//			this.log ("Abort previous request (status: " + this.xmlHttp.readyState + ")", this.log_level.INFO);
			// If you take an xmlhttp object that's busy sending and receiving
			// and tell it to send another request, it simply stops doing whatever it does
			// and sends out the new request.
			// Except in Mozilla !! Therefore abort the current request and create a new one.
			// But abort() sometimes generates another error (an empty response)
			// Because abort() only stops the client (not the server computation) it seems ok
			// to do not abort the current request
			// xmlHttp.abort();
			// delete xmlHttp;
			ErzeugeRequest();
//			this.log ("New request object created (because of Mozilla/Opera bug)", this.log_level.INFO);
		}

		try
		{
			// Open url of PHP script which process this query and send header
			xmlHttp.open( "POST", site.PHP_URL + "/favoriten.php", true );
//			xmlHttp.open( "POST", cms.PHP_URL + "/favoriten.php", true );
			xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );

			// The callback function
			xmlHttp.onreadystatechange = RequestOk;

//			isAbort = false;
		}
		catch (e)
		{
//			this.log ("Error while preparing request " + e, this.log_level.FATAL);
		}
		try
		{
			// Send query
//			alert("pfad=" + cms.Klassen_Pfad + "&applikation=" + site.Id + "&wert=" + wert);
			this.xmlHttp.send("pfad=" + cms.Klassen_Pfad + "&applikation=" + site.Id + "&wert=" + wert);
		}
		catch (e)
		{
			alert ("Error while sending request: " + e);
//			alert ("Error while sending request: " + e, this.log_level.FATAL);
		}
	}
	else
	{
		alert ("No XMLHttpRequest object available in this method request");
//		alert ("No XMLHttpRequest object available in this method request", this.log_level.FATAL);
	}
}

	

function RequestOk ()
{
//	if (!abort)
	{	
		try
		{
			if (xmlHttp.readyState == 4)
			{
				// Alles in Ordnung, Antwort wurde empfangen
				if (xmlHttp.status == 200)
				{
					document.merker.src = site.Skins_URL + "merken1.jpg";
					eval (xmlHttp.responseText);
					zeige_favoriten_info (anzahl);
//					zeige_favoriten_info (xmlHttp.responseText);
				}
				else // Daten wurden nicht ordnungsgemäß oder unvollständig empfangen (z.B. wegen abort)
				{
					alert ("Daten wurden nicht ordnungsgemäß oder unvollständig empfangen (z.B. wegen abort): " + xmlHttp.status);
//					debug ("Daten wurden nicht ordnungsgemäß oder unvollständig empfangen (z.B. wegen abort): " + xmlHttp.status);
				}
			}
		}
		catch (e)
		{
			alert ("Ausnahmefehler beim Empfang von Daten (Status = "+xmlHttp.readyState+", Abbruch=" + abort + ")");
//			debug (xmlHttp.responseText);
		}
	}
}

// Erzeuge die beiden Request-Objekt
xmlHttp = ErzeugeRequest();

