/**
Tilo 31.01.2007

Provider:
- EF-Suche
- Google-Suche
- Geonames-Suche
- Wikipedia-Suche

Im Provider wird gespeichert:
- Status
~ 0: Dienst nicht verwendet
~ 1: Suchanfrage gestartet
~ 2: Suchanfrage fertig
- Daten
~ Array mit GlobalPlace-Objecten

*/


Provider = function(type, status)
{
	// public
	this.type = type;
	this.status = status;
	this.xmlHttpRequest = null;
	this.xmlHttpRequest2 = null;
	this.data = null;

	// private
	var test = null;
}


/**
* The generic Ajax request
*/
Provider.prototype.sendRequest = function(serverFile, callback, parameter) 
{
	this.xmlHttpRequest = createRequest();

	logm("provider.js - sendRequest: " + serverFile + "; " + callback.toString().substring(0,35) + "; " + parameter.substring(0,92));

	this.xmlHttpRequest.open( "POST", "ajax/" + serverFile, true );
	this.xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	// The callback function
	this.xmlHttpRequest.onreadystatechange = callback;

	// Send query
	this.xmlHttpRequest.send(parameter);
}


Provider.prototype.sendRequest2 = function(serverFile, callback, parameter) 
{
	this.xmlHttpRequest2 = createRequest();

	logm("provider.js - sendRequest: " + serverFile + "; " + callback.toString().substring(0,35) + "; " + parameter.substring(0,92));

	this.xmlHttpRequest2.open( "POST", "ajax/" + serverFile, true );
	this.xmlHttpRequest2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	// The callback function
	this.xmlHttpRequest2.onreadystatechange = callback;

	// Send query
	this.xmlHttpRequest2.send(parameter);
}


Provider.prototype.lookupEarthfavesByCoordinates = function(coordinates, umkreissuche, callback) 
{
	this.sendRequest2("lookupEarthfaves.php", callback, 'coordinates=' + coordinates + '&umkreissuche=' + umkreissuche);
}


Provider.prototype.lookupGeoplaces = function(anzahl, name, address, fclass, fcode, callback) 
{
	if (name == global.search1) {
		name = '';
	}
	if (address == global.search2)
	address = '';

	// Leerzeichen durch "%20" ersetzen
	name = name.replace(/ /g, "%20");
	address = address.replace(/ /g, "%20");

	var wo = name;
	if (wo != "" && address != "") {
		wo += "+";
	}
	wo += address;
	this.sendRequest("lookupGeonames.php", callback, 'anzahl=' + anzahl + '&wo=' + encodeURIComponent(wo) + '&fcode=' + fcode + '&fclass=' + fclass);
//	this.sendRequest("lookupGeoPlaces.php", callback, 'anzahl=' + anzahl + '&wo=' + encodeURIComponent(wo) + '&fcode=' + fcode + '&fclass=' + fclass);
}