//	alert
//
	var cp = new cpaint();
	cp.set_transfer_mode('get'); //post tai get. Opera ei tue POST-vaihtoehtoa
	resType = 'OBJECT'; // text/xml/object
	cp.set_response_type(resType);
	cp.set_debug(0); 			// 0=false/1=true/2=(full)
	phpFile = "dBaseConnector.php";

/* -------- funktio-lista -----------------

	function showPoiCat 
	function responseShowPoiCat 

	function selectPoiCategory          - ei enää käytössä
	function responseSelectPoiCategory  - ei enää käytössä

	function getPoiById (poiDbId, id2)
	function responseGetPoiById (result)

	function updateDbPoi 
	function responseUpdateDbPoi 

	function addDbPoi 
	function responseAddDbPoi

	function remDbPoi 
	function responseRemDbPoi 
*/

	// ------------- etsintä-funktio --------------

	function seachStringInDb (searchString, ftLanguage) {
		//alert('seachStringInDb sanalla: ' + searchString);
		var phpFunction = 'searchStringDB';
		var responseFunction = responseReachStringInDb;
		cp.call(phpFile, phpFunction, responseFunction, searchString, ftLanguage);
	}

	function responseReachStringInDb (result) {
		//alert('response');

		ftSearchResultPoiList = new Array(poiLkm);			


		var tulosteksti = 'Starts. ';
		//var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + debugText;
		var poiData = result.ajaxResponse[0].poiBody[0];
		//alert(poiData);
		var oldPoiLkm = 0;
		if(poiData.poiTitle != undefined) {
			var poiLkm = poiData.poiTitle.length;
			var uusia = poiLkm;
			//alert('Lukumaara ' + poiLkm);
			//

			for (i=0; i<poiLkm; i++) {
				var poiDbId = poiData.poiDbId[i].data;
				//alert('poiDbId' + poiDbId);
				var poiTitle = poiData.poiTitle[i].data;
				var poiInfo = poiData.poiInfo[i].data;
				//alert(poiInfo);
				var poiHref = poiData.poiUrl[i].data;
				var xCoord = poiData.xCoord[i].data;
				var yCoord = poiData.yCoord[i].data;
				var poiCat = poiData.cat[i].data;
				tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';
				
				//alert('poiCat: ' + poiCat + ' poiTitle: ' + poiTitle);
				//alert(tulosteksti);
				var idNum = i + oldPoiLkm;
				var poiId = 'Poi' + idNum;
				var xNew = xCoord - ftPoiXMove;
				var yNew = Math.round((yCoord - ftPoiYMove) * 0.707106);
				listElement = new Array(poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo);
				//alert(listElement);
				ftSearchResultPoiList[i + oldPoiLkm] = listElement;
				//createPOI (poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo);
			}
			//alert(ftPoiList);
			// seuraava debuggausta
			
			var ftpLen = ftSearchResultPoiList.length;
			var koestr = '';
			for (i=0; i<ftpLen; i++) {
				//var poiDbId = ftPoiList[i];
				//alert(poiDbId);
				var poi = ftSearchResultPoiList[i];
				poiTitle = poi[6];
				koestr = koestr + poiTitle + ' | ';
			}
			//alert(koestr);
			openSearchResultDiv(ftSearchResultPoiList);
			
		}
		else {
			alert('No search result');
		}

	} //function responseReachStringInDb

	// -----------------------------------------

	// yhteys tietokantaan
	function showPoiCat (cat) {
		//alert('showPoiCat alkaa. cat on: ' + cat);

		// laitetaan muistiin haettava categoria, jos emme saa vastausta
		ftAskedCat = cat;
		
		if(cat != 'none') {
			var phpFunction = 'showPoiCat';
			var responseFunction = responseShowPoiCat;
			cp.call(phpFile, phpFunction, responseFunction, cat, ftLanguage);
		}
		
		doLoadingDiv ();


	}
	
	// alussa 

	//
	function responseShowPoiCat (result) {
		//alert('responseShowPoiCat alkaa');
		//var category = document.getElementById('category').value;
		removeLoadingDiv ();
		//
		if (ftPoiList == null) {
			//alert('Poi LKM on: 0');
			var oldPoiLkm = 0;
		}
		else {
			//alert('Poi LKM on: ' + ftPoiList.length);
			var oldPoiLkm = ftPoiList.length;
		}

		var tulosteksti = 'Starts. ';
		//var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + debugText;
		var poiData = result.ajaxResponse[0].poiBody[0];
		//alert(poiData);
		if(poiData.poiTitle != undefined) {
			var poiLkm = poiData.poiTitle.length;
			var uusia = poiLkm;
			//alert('Lukumaara ' + poiLkm);
			//

			if (ftPoiList == null) {
				ftPoiList = new Array(poiLkm);			
			}

			for (i=0; i<poiLkm; i++) {
				var poiDbId = poiData.poiDbId[i].data;
				//alert('poiDbId' + poiDbId);
				var poiTitle = poiData.poiTitle[i].data;
				var poiInfo = poiData.poiInfo[i].data;
				//alert(poiInfo);
				var poiHref = poiData.poiUrl[i].data;
				var xCoord = poiData.xCoord[i].data;
				var yCoord = poiData.yCoord[i].data;
				var poiCat = poiData.cat[i].data;
				tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';
				//alert(tulosteksti);
				var idNum = i + oldPoiLkm;
				var poiId = 'Poi' + idNum;
				var xNew = xCoord - ftPoiXMove;
				var yNew = Math.round((yCoord - ftPoiYMove) * 0.707106);
				listElement = new Array(poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo);
				//alert(listElement);
				ftPoiList[i + oldPoiLkm] = listElement;
				createPOI (poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo);
			}
			//alert(ftPoiList);
			// seuraava debuggausta
			
			var ftpLen = ftPoiList.length;
			var koestr = '';
			for (i=0; i<ftpLen; i++) {
				//var poiDbId = ftPoiList[i];
				//alert(poiDbId);
				var poi = ftPoiList[i];
				poiTitle = poi[6];
				koestr = koestr + poiTitle + ' | ';
			}
			//alert(koestr);
			
			if(catWindowFlag == true) {
				document.getElementById(poiCat + 'Lkm').innerHTML = poiLkm;
				document.getElementById('totalLkm').innerHTML = 'Total ' + ftPoiList.length;
			}

			if(debugMode == true) {
				document.getElementById('testTextDiv').innerHTML = tulosteksti;
			}
		}
		else { // ei poiObjekteja tästä categoriasta
		
			poiCat = ftAskedCat;
			ftAskedCat = null;
			//alert('poiCat: ' + poiCat);
			poiLkm = 0;
			if (poiCat != null && catWindowFlag == true) {
				document.getElementById(poiCat + 'Lkm').innerHTML = poiLkm;
			}
		}
		
		//var yhteensa = ftPoiList.length;
		//alert('vanhoja: ' + oldPoiLkm + ', uusia: ' + uusia + ' , Yhteensä: ' + yhteensa);
		
		//else{
		//	alert('No POI-data found');
		//}
		//createPOIList(ftPoiList);
	} //function responseShowPoiCat


// ----------------------- Vanha yhteys ---------------------------------------
// --------- ei enää käytössä ---------
	// yhteys tietokantaan
	function selectPoiCategory () {
		alert('selectPoiCategory alkaa - EI PITÄIS ENÄÄ OLLA KÄYTÖSSÄ!!!');
		// poistetaan vanhat linkit
		if (document.getElementById("Poi0") != null) {
			removePOIList();
		}
		ftCategory = document.getElementById('category').value;
		if(ftCategory != 'none') {
			var phpFunction = 'selectPoiCategory';
			var responseFunction = responseSelectPoiCategory;
			cp.call(phpFile, phpFunction, responseFunction, ftCategory, ftLanguage);
		}
	}
	//
	function responseSelectPoiCategory (result) {
		//alert('responseSelectPoiCategory alkaa');
		// HUOM!! Seuraavan voisi palauttaa serverin kautta
		//var category = document.getElementById('category').value;
		//var perusData = result.ajaxResponse[0];
		var tulosteksti = 'Starts. ';
		//var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + debugText;
		var poiData = result.ajaxResponse[0].poiBody[0];
		//alert(poiData);
		if(poiData.poiTitle != undefined) {
			var poiLkm = poiData.poiTitle.length;
			//alert('Lukumaara ' + poiLkm);
			ftPoiList = new Array(poiLkm);
			for (i=0; i<poiLkm; i++) {
				var poiDbId = poiData.poiDbId[i].data;
				//alert(poiDbId);
				var poiTitle = poiData.poiTitle[i].data;
				var poiInfo = poiData.poiInfo[i].data;
				//alert(poiInfo);
				var poiHref = poiData.poiUrl[i].data;
				var xCoord = poiData.xCoord[i].data;
				var yCoord = poiData.yCoord[i].data;
				tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';
				var poiId = 'Poi' + i;
				var xNew = xCoord - ftPoiXMove;
				var yNew = Math.round((yCoord - ftPoiYMove) * 0.707106);
				listElement = new Array(poiId, poiDbId, ftCategory, xNew, yNew, poiHref, poiTitle, poiInfo);
				//alert(listElement);
				ftPoiList[i] = listElement;
				createPOI (poiId, poiDbId, ftCategory, xNew, yNew, poiHref, poiTitle, poiInfo);
			}
			// seuraava debuggausta
			/*
			var ftpLen = ftPoiList.length;
			for (i=0; i<ftpLen; i++) {
				var poiDbId = ftPoiList[i];
				alert(poiDbId);
			}
			*/
			if(debugMode == true) {
				document.getElementById('testTextDiv').innerHTML = tulosteksti;
			}
		}
		//else{
		//	alert('No POI-data found');
		//}
		//createPOIList(ftPoiList);
	} //function responseSelectPoiCategory

	// --------------------------------------------------------------------------------

	// yhteys tietokantaan
	function getPoiById (poiDbId, id2) {
		var phpFunction = 'getPoiById';
		var responseFunction = responseGetPoiById;
		cp.call(phpFile, phpFunction, responseFunction, poiDbId, id2);
	}

	function responseGetPoiById (result) {
		
		poiEditMode = 'edit'; 'edit'/'new'
		
		var tulosteksti = 'Starts. ';
		var poiData = result.ajaxResponse[0].poiBody[0];

		var poiLkm = poiData.poiTitle.length;
		//alert(poiLkm);
		
		var id2 = poiData.poiId[0].data;
		poiDbId = poiData.poiDbId[0].data;
		var poiTitle = poiData.poiTitle[0].data;
		var poiTitleFin = poiData.poiTitleFin[0].data;
		var poiInfo = poiData.poiInfo[0].data;
		var poiInfoFin = poiData.poiInfoFin[0].data;
		//alert(poiInfo);
		var poiHref = poiData.poiUrl[0].data;
		var poiHrefFin = poiData.poiUrlFin[0].data;
		var xCoord = poiData.xCoord[0].data;
		var yCoord = poiData.yCoord[0].data;
		tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';

		//var poiId = 'Poi' + i;

		// MUUNNOS MySQL->Ajax 	X=-255 Y=0
		//var xNew = xCoord - 255;
		var xNew = ftPoiDbScale * (xCoord - ftPoiXMove);
		var yNew = ftPoiDbScale * (Math.round((yCoord - ftPoiYMove) * 0.707106));


		//var yNew = yCoord * 0.707;
		//var yNew = Math.round(yCoord * 0.707106);  //0.7071067811865475244008443621052
		
		//alert(tulosteksti);
		if(debugMode == true) {
			document.getElementById('testTextDiv').innerHTML = tulosteksti;
		}
		//createPOIList(ftPoiList);

		//newEngTitleInput.setAttribute("id", "newEngTitleInput");
		if (poiInfo == "")poiInfo = ' ';
		if (poiInfoFin == "")poiInfoFin = ' ';
		
		if (ftLanguage == 'finnish') {
			document.getElementById('newStatusTitleDiv').innerHTML = 'Editoidaan Objektia Id: ' + poiDbId;
			document.getElementById('saveToDbaseButton').value = 'Päivitä tietokantaan';
		}
		else {
			document.getElementById('newStatusTitleDiv').innerHTML = 'Editing Object Id: ' + poiDbId;
			document.getElementById('saveToDbaseButton').value = 'Update to Dbase';
		}
		document.getElementById('newDisplayIdDiv').innerHTML = id2;
		document.getElementById('newEngTitleInput').value = umlToSkand(poiTitle);
		document.getElementById('newFinTitleInput').value = umlToSkand(poiTitleFin);
		document.getElementById('newEngDescrInput').value = umlToSkand(poiInfo);
		document.getElementById('newFinDescrInput').value = umlToSkand(poiInfoFin);
		document.getElementById('newEngUrlInput').value = poiHref;
		document.getElementById('newFinUrlInput').value = poiHrefFin;
		document.getElementById('newXInput').value = xNew;
		document.getElementById('newYInput').value = yNew;
	} //function responseGetPoiById

	// --------------------------------------------------------------------------------

	function updateDbPoiOLD (id2, poiDbId, ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord) {

		//alert('FF' + id2);
		var phpFunction = 'updateDbPoi';
		var responseFunction = responseUpdateDbPoi;
		//alert(poiInfoFin);
		cp.call(phpFile, phpFunction, responseFunction, id2, poiDbId, ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord);
	}

	function updateDbPoi (poiDbId, ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord) {
		var phpFunction = 'updateDbPoi';
		var responseFunction = responseUpdateDbPoi;
		//alert(poiInfoFin);
		cp.call(phpFile, phpFunction, responseFunction, poiDbId, ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord);
	}

	function responseUpdateDbPoi (result) {
		//
		var poiData = result.ajaxResponse[0].poiBody[0];
		var poiLkm = poiData.poiTitle.length;
		//alert(poiLkm);
//		poiId2 = poiData.id2[0].data;
//		poiId = 'Poi' + poiId2;

		poiDbId = poiData.poiDbId[0].data;
		ftCategory =  poiData.category[0].data;
		//alert(category);
		
		var poiTitle =    poiData.poiTitle[0].data;
		var poiTitleFin = poiData.poiTitleFin[0].data;
		var poiInfo =     poiData.poiInfo[0].data;
		var poiInfoFin =  poiData.poiInfoFin[0].data;
		//alert(poiInfo);
		var poiHref =     poiData.poiUrl[0].data;
		var poiHrefFin =  poiData.poiUrlFin[0].data;
		var xCoord =      poiData.xCoord[0].data;
		var yCoord =      poiData.yCoord[0].data;
		//alert(yCoord);
		
		var perusData = result.ajaxResponse[0];
		var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';

		//var poiId = 'Poi0'; //???????????????????

		// MUUNNOS MySQL->Ajax 	X=-255 Y=0
		var xNew = xCoord - ftPoiXMove;
		var yNew = Math.round((yCoord - ftPoiYMove) * 0.707106);
		//var xNew = xCoord - 255;
		//var yNew = Math.round(yCoord * 0.707106);  //0.7071067811865475244008443621052
		
		//alert('Removing object id:' + poiId);

//		ftMapDivElement.removeChild(document.getElementById(poiId));
//		createPOI (poiId, poiDbId, ftCategory, xNew, yNew, poiHref, poiTitle, poiInfo);
		
		alert(debugText);
		
		
		removePOIList(ftPoiList);
		ftPoiList = null;
		showPoiCat (ftCategory);

		

	} //function responseUpdatePoi

	function responseUpdateDbPoiOLD (result) {
		//
		var poiData = result.ajaxResponse[0].poiBody[0];
		var poiLkm = poiData.poiTitle.length;
		//alert(poiLkm);
		poiId2 = poiData.id2[0].data;
		poiId = 'Poi' + poiId2;

		poiDbId = poiData.poiDbId[0].data;
		ftCategory =  poiData.category[0].data;
		//alert(category);
		
		var poiTitle =    poiData.poiTitle[0].data;
		var poiTitleFin = poiData.poiTitleFin[0].data;
		var poiInfo =     poiData.poiInfo[0].data;
		var poiInfoFin =  poiData.poiInfoFin[0].data;
		//alert(poiInfo);
		var poiHref =     poiData.poiUrl[0].data;
		var poiHrefFin =  poiData.poiUrlFin[0].data;
		var xCoord =      poiData.xCoord[0].data;
		var yCoord =      poiData.yCoord[0].data;
		//alert(yCoord);
		
		var perusData = result.ajaxResponse[0];
		var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';

		//var poiId = 'Poi0'; //???????????????????

		// MUUNNOS MySQL->Ajax 	X=-255 Y=0
		var xNew = xCoord - ftPoiXMove;
		var yNew = Math.round((yCoord - ftPoiYMove) * 0.707106);
		//var xNew = xCoord - 255;
		//var yNew = Math.round(yCoord * 0.707106);  //0.7071067811865475244008443621052
		
		//alert('Removing object id:' + poiId);

		ftMapDivElement.removeChild(document.getElementById(poiId));
		createPOI (poiId, poiDbId, ftCategory, xNew, yNew, poiHref, poiTitle, poiInfo);
		
		alert(debugText);
		
		
		removePOIList(ftPoiList);
		ftPoiList = null;
		showPoiCat (ftCategory);

		

	} //function responseUpdatePoiOLD
	// --------------------------------------------------------------------------------

	function addDbPoi (ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord) {
		//alert('Adding new poi in cat:' + ftCategory);
		//alert(ftPoiList);
		var phpFunction = 'addDbPoi';
		var responseFunction = responseAddDbPoi;
		cp.call(phpFile, phpFunction, responseFunction, ftCategory, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xCoord, yCoord);
	}

	function responseAddDbPoi (result) {
		//
		//alert('res 0');
		var poiData   = result.ajaxResponse[0].poiBody[0];
		poiDbId       = poiData.poiDbId[0].data;
		var perusData = result.ajaxResponse[0];
		var debugText = perusData.debug[0].data;
		//tulosteksti = tulosteksti + poiTitle + '<br>' + poiInfo  + '<br>X-coord: '  + xCoord  + ' Y-coord: ' + yCoord + '<br> --------------<br>';
		if(ftPoiList != null) {
			var poiLkm = ftPoiList.length;
		}
		else {
			var poiLkm = 0;
			ftPoiList = new Array();
		}
		var poiId = 'Poi' + poiLkm;
		//ftCategory = document.getElementById('category').value;
		ftCategory = ftSelectedRadioCat;
		var poiTitle = document.getElementById('newEngTitleInput').value;
		var poiTitleFin = document.getElementById('newFinTitleInput').value;
		var poiInfo = document.getElementById('newEngDescrInput').value;
		var poiInfoFin = document.getElementById('newFinDescrInput').value;
		var poiHref = document.getElementById('newEngUrlInput').value;
		var poiHrefFin = document.getElementById('newFinUrlInput').value;
		var xCoord = document.getElementById('newXInput').value;
		var yCoord = document.getElementById('newYInput').value;
		// lisätään listaan
		listElement = new Array(poiId, poiDbId, ftCategory, xCoord, yCoord, poiHref, poiTitle, poiInfo);
		ftPoiList[poiLkm] = listElement;
		// luodaan uusi objekti näytölle
		createPOI (poiId, poiDbId, ftCategory, xCoord, yCoord, poiHref, poiTitle, poiInfo);
		alert(debugText + ', uusi dbid on:' + poiDbId);
		//
		removePOIList(ftPoiList);
		ftPoiList = null;
		showPoiCat (ftCategory);

		// nyt muutetaan edit-moodiin
		poiEditMode = 'edit'; 'edit'/'new'
		if (ftLanguage == 'finnish') {
			document.getElementById('newStatusTitleDiv').innerHTML = 'Editoidaan Objektia Id: ' + poiDbId;
			document.getElementById('saveToDbaseButton').value = 'Päivitä tietokantaan';
		}
		else {
			document.getElementById('newStatusTitleDiv').innerHTML = 'Editing Object Id: ' + poiDbId;
			document.getElementById('saveToDbaseButton').value = 'Update to Dbase';
		}



	} //function responseAddDbPoi

	// --------------------------------------------------------------------------------


	function remDbPoi (poiDbId) {

		//var phpFile = "dBaseConnector.php";
		var phpFunction = 'remDbPoi';
		var responseFunction = responseRemDbPoi;
		cp.call(phpFile, phpFunction, responseFunction, poiDbId);
	} // remDbPoi

	function responseRemDbPoi (result) {
		//
		//alert('res 0');
		//var poiData = result.ajaxResponse[0].poiBody[0];
		//poiDbId =         poiData.poiDbId[0].data;
		var perusData = result.ajaxResponse[0];
		var debugText = perusData.debug[0].data;
		alert(debugText);

//		ftCategory = document.getElementById('category').value;
//		selectPoiCategory (category);


		
	} //function remDbPoi

	// --------------------------------------------------------------------------------

