/* seuraavissa funktioissa on eroja
	beginDrag     - erilainen event-käsittely, LISTAA EROT
	muut funtiot ovat tässä tiedostossa tai contactPoiServer.js-tiedostossa

function init()
function noSelect (element)
function ftAlert (string)
function doLoadingDiv ()
function removeLoadingDiv ()
function catList ()
function ft_classAttribute (obj, className)
function keyBoardMove(e)
function umlToSkand (tex)
function skandToUml (tex)
function panMap(dX,dY)
function calcInfo ()
function debugText (tex)
function mapSize(leveys, korkeus)
function drawCopyRight()
function zoomDivs (mScale)
function doZoom (mScale)
function doZoomPlus ()
function doZoomMinus ()
function createPOI (poiId, poiDbId, category, poiX, poiY, poiHref, poiTitle, poiInfo)
function createPOIList (ftPoiList)
function removePOIList () 
function updatePOIList () // poiObjektien liikuttelu
function createCP ()
function arrayMember (arr, member)
function arrayMones (arr, member)
function createCanvas ()
function calcMapCanvas ()
function doEditMode (eFlag)
function toggleCatRadioElement (catNum)
function doOpenCatRadioWindow ()
function drawCP ()
function clipMapDiv(element)
function addNewObject ()
function copyNewObject ()
function catchXYcoord ()
function saveToDbase ()
function removeFromDbase ()
function checkEngUrl()
function checkFinUrl()
function doLanguage ()
function getPoiIcon (catName)
function doSearch ()
function openSearchResultDiv (ftSearchResultPoiList)
function doCloseSearchResultDiv ()
function doShowOnMap (dbId, poiCat, xNew, yNew)
function doOpenCatWindow (eFlag)
function toggleCatElement (catNum)
function notShowPoiCat (catName)
function doCloseCatDiv ()
function copyLinkToClipBoard ()
function sendEmailF()
function doCloseEmail ()
function openFtWindow(osoite)
function startList()  // Tämä on menubaria varten ja vain ie:lle luulisin

*/


function init() {
	// ajetaan projekti kohtaiset tiedot conf-tiedostosta
	loadconf();
	//alert('Moi init.common');
	// ------------------------------
	
	catWindowFlag = false;
	editFlag = false;
	selLinksFlag = false;
	ftSelectedCatList = null;
	ftSelectedRadioCat = 'rakennus';
	ftPoiTemp = null;
	
	ftLoggedIn = false;
	ftUsername = '';
	poiEditMode = 'new'; 'edit'/'new'
	debugMode = false; // näytetäänkö testDiv'issä debuggaus tekstiä (testTextDiv)
	// alustetaan ftPoiList
	ftPoiList = null;
	ftHakuLkm = 15; //montako määräystä haetaan kerrallaan
	// UUSI lista, jossa eri katergorioista POI-objekteja
//	ftNewPoiList = null;
	ftDragtext = '';
	// koitetaan esilatausta IE:n bugin takia
	image1 = new Image();
	image1.src = "images/close.gif";
	
	// Tällä tarkistetaan tietyin välin DOM-puun orvot img-objektit
	// vielä käytössä, mutta jatkossa varmaankin tarpeeton
	virheLaskin = 0;

	// Nämä auttavat IE:n drag-ongelmaan, mutta estävät tekstin kopioinnin.
	// korjasin ongelman 2.9.2006 noSelect-funktiolla, joka
	// laitetaan jokaiselle img-objektille
	// tällöin kaikki muut osat voi valita
	// http://www.ditchnet.org/wp/2005/06/15/ajax-freakshow-drag-n-drop-events-2/
	// document.body.ondrag = function () { return false; };
	// document.body.onselectstart = function () { return false; };
	//testaaAika();
	//alert(aikaToPmaara('1174295780383'));
	catList();
} // init

/*
// replace callback support for safari.
(function(){
  var default_replace = String.prototype.replace;
  String.prototype.replace = function(search,replace){
	// replace is not function
	if(typeof replace != "function"){
		return default_replace.apply(this,arguments)
	}
	//alert('Moi');
	var str = "" + this;
	var callback = replace;
	// search string is not RegExp
	if(!(search instanceof RegExp)){
		var idx = str.indexOf(search);
		return (
			idx == -1 ? str :
			default_replace.apply(str,[search,callback(search, idx, str)])
		)
	}
	var reg = search;
	var result = [];
	var lastidx = reg.lastIndex;
	var re;
	while((re = reg.exec(str)) != null){
		var idx  = re.index;
		var args = re.concat(idx, str);
		result.push(
			str.slice(lastidx,idx),
			callback.apply(null,args).toString()
		);
		if(!reg.global){
			lastidx += RegExp.lastMatch.length;
			break
		}else{
			lastidx = reg.lastIndex;
		}
	}
	result.push(str.slice(lastidx));
	return result.join("")
  }
})();
*/


// tällämerkitään kaikki img-objektit ei valittaviksi, jotta niitä voisi dragatä
function noSelect (element) {
	element.ondrag = function () { return false; };
	element.onselectstart = function () { return false; };
}

function ftAlert (string) {
	if(ftDebugEcho == 1) {
		alert(string);
	}
}

// cookieta varten
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function aikaToPmaara(aikaStr) {
	var vanhaAika = parseInt(aikaStr);
	date2 = new Date(vanhaAika);
	//date2 = new Date(aika);
	//aikastring2 = date2.toString( );
	var vuosi = date2.getFullYear();
	var kk = 1 + date2.getMonth();
	if(kk < 10)
		kk = '0' + kk;
	var pva = date2.getDate();
	if(pva < 10)
		pva = '0' + pva;
	var tunti = date2.getHours();
	if(tunti < 10)
		tunti = '0' + tunti;
	var min = date2.getMinutes();
	if(min < 10)
		min = '0' + min;
	var aikaStr = pva + '.' + kk + '.' + vuosi + '_' + tunti + ':' + min;
	return aikaStr
}
function testaaAika() {
	ourDate = new Date();
	aika = ourDate.getTime();
	//aikastring=ourDate.toString();	
	//alert('aika on: ' + aika + '. Aikastring on:' + aikastring);
	//vanhaAika = 1168934224875;
	//vanhaAika = parseInt('1168934224875');
	//date2 = new Date(vanhaAika);
	//date2 = new Date(aika);

	//aikastring2 = date2.toString( );
/*	
	var vuosi = date2.getFullYear();
	var kk = 1 + date2.getMonth();
	var pva = date2.getDate();
	var tunti = date2.getHours();
	var min = date2.getMinutes();
*/
	var vuosi = ourDate.getFullYear();
	var kk = 1 + ourDate.getMonth();
	var pva = ourDate.getDate();
	var tunti = ourDate.getHours();
	var min = ourDate.getMinutes();
	//var locAika = date2.toLocaleString();
	var aikaStr = pva + '.' + kk + '.' + vuosi + ' ' + tunti + ':' + min;
	alert('aika on ' + aika + ' Päivämäärä: ' + aikaStr);
//	alert('aikastring2 on: ' + aikastring2 + ' Vuosi:' + vuosi + ' Locale:' + locAika);
// lisäsin 3 nollaa => meni eiliseen
//	date3 = new Date(1168845678000);
//	aikastring3 = date3.toString( );	
//	alert('aikastring2 on: ' + aikastring2 + 'aikastring3 on: ' + aikastring3);
}


// tällä kerrotaan käyttäjälle, että ladataan palvelimelta
function doLoadingDiv (message) {
	var loadingDiv = document.createElement("div");
	loadingDiv.setAttribute("id", "loadingDiv");
	loadingDiv.style.left= 200;
	loadingDiv.style.top = ftStatusDivHeight + ftUpperbannerHeight + 65; // vika 30
	loadingDiv.style.width = 180; // 200;
	loadingDiv.style.height = 50;
	loadingDiv.style.zIndex = 1600;
	if(message == '') {
		if(ftLanguage == 'finnish')
			loadingDiv.innerHTML = 'Ladataan tietokannasta...';
		else
			loadingDiv.innerHTML = 'Loading from dataBase...';
	}
	else {
		loadingDiv.innerHTML = message;
	}
	document.body.appendChild(loadingDiv);
}

// poistetaan "ladataan"-ilmoitus
function removeLoadingDiv () {
	var loadingDiv = document.getElementById("loadingDiv");
	document.body.removeChild(loadingDiv);
}


//
function catList () {
	var catLkm = ftCatNameList.length;
	ftCatList = new Array(catLkm);
	for (i=0; i<catLkm; i++) {
		var catName = ftCatNameList[i];
		var catPari = new Array(catName, false)
		ftCatList[i] = catPari;
	}
	//alert(ftCatList);
}
//
// tämän avulla toimii samat funktiot IE.ssä ja muissa, kun annetaan
// elementille class-attribuutti
function ft_classAttribute (obj, className) {
	if(selain == 'ie'){
		if (obj.getAttributeNode("class")) {
		  for (var i = 0; i < obj.attributes.length; i++) {
			 var attrName = obj.attributes[i].name.toUpperCase();
			 if (attrName == 'CLASS') {
				obj.attributes[i].value = className;
			 }
		  }
		// otherwise create a new attribute
		} else {
			obj.setAttribute("class", className);
		}
	}
	else {
		obj.setAttribute("class", className);
	}
}
// 

function keyBoardOn() {
	// Vaikuttako tämä IE-ongelmaan??
	if(selain == 'fox'){
		document.onkeydown = keyBoardMove;
		document.onkeyup = keyBoardMove;
	}
	else{

		ftMapDivElement.onkeydown = keyBoardMove;
		ftMapDivElement.onkeyup = keyBoardMove;
	}
}

//obj.setEvent("onkeydown", function(e) {this.trapkey (e);} );


function keyBoardOff() {
	if(selain == 'fox') {
		document.onkeydown = null;
		document.onkeyup = null;
	}
}

function keyBoardMove(e){
	//alert('painettu');
	if(selain == 'ie'){
		e = window.event;
	}
	kbkoodi = e.keyCode;
	//alert(kbkoodi);
	if(kbkoodi == 37){
		panMap(20,0);
	}
	else if(kbkoodi == 38){
		panMap(0,20);
	}
	else if(kbkoodi == 39){
		panMap(-20,0);
	}
	else if(kbkoodi == 40){
		panMap(0,-20);
	}
}

//
function umlToSkand (tex) {
	tex = tex.replace(/&auml;/g, 'ä');
	tex = tex.replace(/&Auml;/g, 'Ä');
	tex = tex.replace(/&ouml;/g, 'ö');
	tex = tex.replace(/&Ouml;/g, 'Ö');
	tex = tex.replace(/&aring;/g, 'å');
	tex = tex.replace(/&Aring;/g, 'Å');
	tex = tex.replace(/&quot;/g, '"');
	tex = tex.replace(/&aacute;/g, 'á');
	tex = tex.replace(/&Aacute;/g, 'Á');
	tex = tex.replace(/&eacute;/g, 'é');
	tex = tex.replace(/&Eacute;/g, 'É');
	tex = tex.replace(/&uuml;/g, 'ü');
	tex = tex.replace(/&Uuml;/g, 'Ü');
	tex = tex.replace(/&ecirc;/g, 'ê');
	tex = tex.replace(/&Uuml;/g, 'Ü');
	tex = tex.replace(/&amp;/g, '&');
	tex = tex.replace(/&acute;/g, '´');
	
//	&lt; <
//	&gt; >
//	&copy;  
	
	return tex
}
//
// tätä ei tarvita, koska char-coodaus toimii nyt cpaintissä
function skandToUml (tex) {
	tex = tex.replace(/ä/g, '&auml;');
	tex = tex.replace(/Ä/g, '&Auml;');
	tex = tex.replace(/ö/g, '&ouml;');
	tex = tex.replace(/Ö/g, '&Ouml;');
	tex = tex.replace(/å/g, '&aring;');
	tex = tex.replace(/Å/g, '&Aring;');
	return tex
}
//
//
function panMap(dX,dY) {
	ftMapX = ftMapX - ftMapScale/1000 * dX;
	ftMapY = ftMapY - ftMapScale/1000 * dY;
	calcMapCanvas();
	updatePOIList();
	drawCP();
	if(selain == 'ie')
		ftMapDivElement.focus(); // Konqurer antaa virheilmoituksen
}
//

function calcInfo (){
	//
	var ots = '&nbsp;&nbsp;CityGuide3D Beta 0.6 - 15.6.2006'
	str1 = "&nbsp;&nbsp;Width: " + ftWindowWidth + "," + ftWindowHeight + "." + "  |  X:" + ftMapX + ",Y:" + ftMapY + " | ftMapScale: " + ftMapScale;
	//str2 = '<br>DeltaX: ' + testD + ' | clX2: ' + clX2;
	str2 = ' | MapLev: ' + ftMapWidth + ', MapKor: ' + ftMapHeight;
	str = str0 + str1 + str2;
	str = ots + str + ftInfoTex3 + deg1;
	debugText(str);
}

function debugText (tex) {
	if (ftdebugAreaMode == 'debug') {
		debugDivElement = document.getElementById("debugArea");
		debugDivElement.innerHTML = '&nbsp;ftdebugAreaMode on: ' + ftdebugAreaMode + tex;
	}
//	debugDivElement = document.getElementById("debugArea");
//	debugDivElement.innerHTML = tex;
}

function mapSize(leveys, korkeus) {
	ftMapWidth  = leveys;
	//alert(ftMapWidth + ' flag: ' + editFlag);
	ftMapHeight = korkeus;
	// yläbanneri
	bannerElement = document.getElementById("upperbanner")
	debugDivElement = document.getElementById("debugArea");
	bannerElement.style.width=ftWindowWidth;
	debugDivElement.style.left = (ftWindowWidth - 728 ) / 2;
	ftMapDivElement.style.width =  ftMapWidth;
	ftMapDivElement.style.height = ftMapHeight;
	//
	//alert('ms3');
	clipMapDiv(ftMapDivElement);
	//alert('ms4');
	calcMapCanvas();
	//alert('ms5');
	calcInfo();
	//alert('ms6');
	drawCP();
	//alert('ms7');
	drawCopyRight();
	//alert('ms8');

	// tämä puuttui 0.8 versiosta korjattu 23.8.2007
	if(ftPoiList != null) {
		// Mitä jos vain poistetaan kaikki POIDivit ja tehdään uudet
		removePOIList(ftPoiList);
		createPOIList(ftPoiList);
		updatePOIList();
	}
	
	if (document.getElementById("editDiv") != null) {
		document.getElementById("editDiv").style.left= ftMapWidth + ftLeftDivWidth;
	}
} // function mapSize


function drawCopyRight() {
	//alert('Piirretään copyright');
	var crElement = document.getElementById("copyRight");
	crElement.style.left = ftLeftDivWidth + 10; //ftMapWidth + ftLeftDivWidth;


	crElement.style.top = ftUpperbannerHeight + ftMapHeight - 20;
	//crElement.style.top = 400;
	crElement.innerHTML =  ftCopyRightText;//'&copy;Fontus Ltd';
}


function zoomDivs (mScale) {
	if (ftMapScale == ftMapScale_1) {
		document.getElementById("z1").src = 'images/zoomOn.gif';
	}
	else {
		document.getElementById("z1").src = 'images/zoomOff.gif';
	}
	//
	if (ftMapScale == ftMapScale_2) {
		document.getElementById("z2").src = 'images/zoomOn.gif';
	}
	else {
		document.getElementById("z2").src = 'images/zoomOff.gif';
	}
	// 4 => 2000
	if (ftMapScale == ftMapScale_3) {
		document.getElementById("z4").src = 'images/zoomOn.gif';
	}
	else {
		document.getElementById("z4").src = 'images/zoomOff.gif';
	}
	// 8 => 4000
	if (ftMapScale == ftMapScale_4) {
		document.getElementById("z8").src = 'images/zoomOn.gif';
	}
	else {
		document.getElementById("z8").src = 'images/zoomOff.gif';
	}
	// 16 => 8000
	if (ftMapScale == ftMapScale_5) {
		document.getElementById("z16").src = 'images/zoomOn.gif';
	}
	else {
		document.getElementById("z16").src = 'images/zoomOff.gif';
	}
} // function zoomDivs


function doZoom (mScale) {
	//alert('dZ_0');
	ftMapScale = mScale;
	var mapDivEl = document.getElementById("mapDiv");
	//alert(mapDivEl);
	// poistetaankin hyödyntäen ftMapList-arrayta
	var lask=0;
	var liLen = ftMapList.length;
	for (i=0; i<liLen; i++) {
		var oldImageId = ftMapList[i];
		//alert(oldImageId);
		var oldImageEl = document.getElementById(oldImageId);
		//alert(oldImageEl);
		if (oldImageEl != null) {
			mapDivEl.removeChild(oldImageEl);
		}
		lask++
	}
	zoomDivs(mScale);
	clipMapDiv(mapDivEl);
	createCanvas ();
	calcInfo();
	drawCP();

	if(ftPoiList != null) {
		// Mitä jos vain poistetaan kaikki POIDivit ja tehdään uudet
		removePOIList(ftPoiList);
		createPOIList(ftPoiList);
		updatePOIList();
	}
} // function doZoom
//

//
function doZoomPlus () {
	if(ftMapScale == ftMapScale_1)
		var flag = '1';
	else if(ftMapScale == ftMapScale_2)
		ftMapScale = ftMapScale_1;
	else if(ftMapScale == ftMapScale_3)
		ftMapScale = ftMapScale_2;
	else if(ftMapScale == ftMapScale_4)
		ftMapScale = ftMapScale_3;
	else if(ftMapScale == ftMapScale_5)
		ftMapScale = ftMapScale_4;
	if(flag != '1')
		doZoom (ftMapScale);
} // function doZoomPlus
//
function doZoomMinus () {
	if(ftMapScale == ftMapScale_5)
		var flag = '1';
	else if(ftMapScale == ftMapScale_1)
		ftMapScale = ftMapScale_2;
	else if(ftMapScale == ftMapScale_2)
		ftMapScale = ftMapScale_3;

	else if(ftMapScale == ftMapScale_3)
		ftMapScale = ftMapScale_4;
	else if(ftMapScale == ftMapScale_4)
		ftMapScale = ftMapScale_5;
	if(flag != '1')
		doZoom (ftMapScale);
} // function doZoomPlus
//
//
function createPoiMoveDiv () {
	ftPoiMoveDiv = document.createElement("div");
	ftPoiMoveDiv.setAttribute("id", "ftPoiMoveDiv");
	ftPoiMoveDiv.style.position = 'absolute';
	ftPoiMoveDiv.style.left = '0px';
	//ftPoiMoveDiv.style.left = ftMapX;
	ftPoiMoveDiv.style.top = '0px';
	//ftPoiMoveDiv.style.top = ftMapY;
	ftPoiMoveDiv.style.width = 1;
	ftPoiMoveDiv.style.height = 1;
	ftPoiMoveDiv.style.zIndex = 500;
	ftMapDivElement.appendChild(ftPoiMoveDiv);
	//laitetaan muistiin alkuperäinen mapX ja mapY
	ftPoiMX = ftMapX;
	ftPoiMY = ftMapY
	//alert('ftPoiMX: ' + ftPoiMX);
}
//
//
function createPOI (poiId, poiDbId, category, poiX, poiY, poiHref, poiTitle, poiInfo) {
	// pikseleinä
	var mapHalfW = parseInt(ftMapWidth / 2);
	var mapHalfH = parseInt(ftMapHeight / 2);
	//alert('create poi alkaa');
	var id2 = poiId.substring(3); // otetaan edestä 'poi' pois, koska muuteen muuttaa div-objektiksi
	//
	if (ftMapScale == ftMapScale_5) {
		ftPoiWidth = 10;
	}
	else if (ftMapScale == ftMapScale_4) {
		ftPoiWidth = 10;
	}
	else if (ftMapScale == ftMapScale_3) {
		ftPoiWidth = 15;
	}
	else if (ftMapScale == ftMapScale_2) {
		ftPoiWidth = 20;
	}
	else if (ftMapScale == ftMapScale_1) {
		ftPoiWidth = 20;
	}
	var iconName = getPoiIcon (category);
	iconName = iconName + '_' + ftPoiWidth + '.gif';
	//alert(iconName);
	newPOI = document.createElement("div");
	newPOI.setAttribute("id", poiId);
	ft_classAttribute(newPOI, "poiDiv");
	newPOI.style.position = 'absolute';
	var eroX = (ftPoiMX - ftMapX) / (ftMapScale/1000);
	var eroY = (ftPoiMY - ftMapY) / (ftMapScale/1000);
	var xLeft = parseInt(ftPoiDbScale * (poiX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
	//newPOI.style.left = xLeft - ftPoiWidth/2; //
	newPOI.style.left = xLeft - ftPoiWidth/2 - eroX;
	var yTop = parseInt(ftPoiDbScale * (poiY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
	//newPOI.style.top  = yTop - ftPoiWidth/2;
	newPOI.style.top  = yTop - ftPoiWidth/2 - eroY;
	//ftMapDivElement.appendChild(newPOI);
	ftPoiMoveDiv.appendChild(newPOI);
	//
	poiLink = document.createElement("a");
	if (editFlag == false) {
		poiLink.href = poiHref;
		poiLink.target = "blank";
	}
	else {
		poiLink.href = "#";
	}
	//poiLink.innerHTML = '<img src="images/poiRed.gif" height="10" width="10" border="0">'
	poiLink.innerHTML = '<img src="images/' + iconName + '" height="' + ftPoiWidth + '" width="' + ftPoiWidth  + '" border="0">'
	/*
	ftCatNameList = new Array('rakennus', 'elokuva', 
		'teatteri', 'museo', 'konserttitalo', 'hotelli', 'kirkko',
		'ravintola', 'kahvila', 'kauppa','yritys', 'yksityinen' );

	ftCatNameList_eng = new Array('building', 'cinema', 
		'theatre', 'museum', 'consert', 'hotel', 'church',
		'restaurant', 'coffee shop', 'shop','company', 'personal' );
	*/
	if(ftLanguage == 'finnish'){
		cat = category.toUpperCase();
		//alert('cat: ' + cat);
	}
	else {
		if(category == 'none'){
			cat = 'NONE';
		}
		else if(category == 'rakennus')cat = 'BUILDING';
		else if(category == 'elokuva')cat = 'CINEMA';
		else if(category == 'teatteri')cat = 'THEATRE';
		else if(category == 'museo')cat = 'MUSEUM';
		else if(category == 'hotelli')cat = 'HOTEL';
		else if(category == 'ravintola')cat = 'RESTAURANT';
		else if(category == 'kahvila')cat = 'CAFE';
		else if(category == 'nahtavyys')cat = 'SIGHT';
		else if(category == 'kirkko')cat = 'CHURCH';
		else if(category == 'konserttitalo')cat = 'CONCERT';
		else if(category == 'kauppa')cat = 'SHOP';
		else if(category == 'ostoskeskus')cat = 'SHOPPING CENTER';
		else if(category == 'poliisi')cat = 'POLICE';
		else if(category == 'posti')cat = 'POST OFFICE';
		else if(category == 'pankki')cat = 'BANK';
		else if(category == 'yritys')cat = 'company';
		else if(category == 'yksityinen')cat = 'private';
		//alert('cat: ' + cat);
	}

	var olCa = cat + " - " + poiTitle;
	olCa = olCa.replace(/'/g, "&#39;");
	olCa = olCa.replace(/\u000d/g, "");
	olCa = olCa.replace(/\u000a/g, "");
	olCa = olCa.replace(/\u0009/g, "");
//	alert('olCa: ' + olCa);
	//olCa = olCa.slice(0,10);
	//alert(poiInfo);

	// escape-funktio muuttaa stringit html-muotoon, mm välilyönnin ja non-asciin
	// /g muuttaa globaalisti

	if(poiInfo != "") {
		var olText = poiInfo.replace(/\u000D/g, ""); //	Carriage return \r eli 	&#013;
		olText = poiInfo.replace(/\r/g, ""); //	varalle safaria varten
		olText = olText.replace(/\u000A/g, "<br>"); //	Line feed  eli \n  eli 	&#010;
		olText = olText.replace(/\n/g, "<br>"); // macin safaria varten
		olText = olText.replace(/\u0009/g, "");  // tab  eli \t  eli &#009; 
		olText = olText.replace(/\t/g, " ");  // tab macin safaria varten
		olText = olText.replace(/'/g, "&#39;"); // ' eli \u0027 
	}
	else {
		olText = "No info";
	}

	if(editFlag == true) {
		olText = olText + '<br>Id: ' +  poiId + ', IdDb: ' +  poiDbId ;
	}
	
	//var tex1 = 'Minä olen hämärä';
	//var tex2 = tex1.replace(/ä/g, "a");;
	//alert(tex1 + ' - ' + tex2);
	
	

	//alert('olText: ' + olText);
	//olText = olText.replace(/\u0026/g, "&amp;"); // Tätä ei voi tehdä, koska muuten &auml; ei toimi
	//olText = olText.slice(0,5);
	//alert('olText: ' + olText + ' - olCa: ' + olCa);
	//var olText = "Haisuli/Nokinenä";
	// Seuraava ei toimi safarilla, jos olTextissä on rivinvaihto
	poiLink.onmouseover = new Function("return overlib('" + olText + "',CAPTION, '" + olCa + "');");
	//alert(' 1 ');
	poiLink.onmouseout = new Function("return nd();");
//	alert(' 2 ');
	poiLink.onfocus = new Function("this.blur();");
//	alert(' 3 ');
	if (editFlag == true) {
		//poiLink.onclick = new Function("getPoiById(" + poiDbId + ");"); // toimii
		poiLink.onclick = new Function("getPoiById(" + poiDbId + ", " + id2  + ");"); // toimii
	}
	newPOI.appendChild(poiLink)
} //function createPOI

function createPOIList (ftPoiList) {
	//alert('function createPOIList   -  ' + ftPoiList);
	var pArr = ftPoiList;
//	for(i in pArr) { // }
	var ftpLen = pArr.length;
	for (i=0; i<ftpLen; i++) {
		poi = pArr[i];
		//createPOI(poi[0],poi[1],poi[2],poi[3],poi[4])
		createPOI(poi[0],poi[1],poi[2],poi[3],poi[4],poi[5],poi[6],poi[7])
	}
}

function removePOIList () {
	if(ftPoiList != null) {
		var ftpLen = ftPoiList.length;
		for (i=0; i<ftpLen; i++) {
			var sublist = ftPoiList[i];
			var poiId = sublist[0];
			//ftMapDivElement.removeChild(document.getElementById(poiId));
			ftPoiMoveDiv.removeChild(document.getElementById(poiId));
		}
	}
}

// poiObjektien liikuttelu
function updatePOIList () {
	//	alert('ftPoiList: ' + ftPoiList);


	// Jääkö tämä funktio kokonaan tarpeettomaksi, jos
	// ftPoiMoveDiv'ä liikutellaa aina???


	//alert(ftCategory);
	//if(ftPoiList != null && ftCategory != 'none') { //}
	if(ftPoiTemp != null) {
		var mapHalfW = parseInt(ftMapWidth / 2);
		var mapHalfH = parseInt(ftMapHeight / 2);
		var poiX = ftPoiTempX;
		var poiY = ftPoiTempY;
		var xLeft = parseInt(ftPoiDbScale * (poiX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
		ftPoiTemp.style.left = xLeft - ftPoiWidth/2; //
		var yTop = parseInt(ftPoiDbScale * (poiY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
		ftPoiTemp.style.top  = yTop - ftPoiWidth/2;
	}
	//if(ftPoiList != null ) {
		//var mapHalfW = parseInt(ftMapWidth / 2);
		//var mapHalfH = parseInt(ftMapHeight / 2);
		// testataan ftPoiMoveDiv:n liikuttelua
		
		// alun arvot ftPoiMX ja ftPoiMY
		var eroX = (ftPoiMX - ftMapX) / (ftMapScale/1000);
		var eroY = (ftPoiMY - ftMapY) / (ftMapScale/1000);


		//var mX = parseInt(ftPoiMoveDiv.style.left);
		//var mY = parseInt(ftPoiMoveDiv.style.top);
		ftPoiMoveDiv.style.left = eroX;
		ftPoiMoveDiv.style.top = eroY;
		deg1 =  ',  eroX: ' + eroX + ', eroY: ' + eroY;
		
		//var xLeft = parseInt(ftPoiDbScale * (mX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
		//var yTop = parseInt(ftPoiDbScale * (mY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
		//deg1 = ' | ftMapX: ' + ftMapX +  ',  mX: ' + mX + ', xLeft: ' + xLeft;
		//ftPoiMoveDiv.style.left = mX + xLeft; //
		//ftPoiMoveDiv.style.top  = mY + yTop;

		//poiX = ftPoiMoveDiv.style.left;
		//poiY = ftPoiMoveDiv.style.top;
		//var xLeft = parseInt(ftPoiDbScale * (poiX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
		//ftPoiMoveDiv.style.left = xLeft - ftPoiWidth/2; //
		//var yTop = parseInt(ftPoiDbScale * (poiY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
		//ftPoiMoveDiv.style.top  = yTop - ftPoiWidth/2;


		// Tällä liikutettiin niitä kutakin yhtä kerrallaan
		/*
		var ftpLen = ftPoiList.length;
		for (i=0; i<ftpLen; i++) {
			var poiArr = ftPoiList[i];
			//alert('poiArr: ' + poiArr.toString());
			var poiId = poiArr[0];
			var poiX = parseInt(poiArr[3]);
			var poiY = parseInt(poiArr[4]);
			//alert('poiId: ' + poiId + ' | poiX: ' + poiX  + ' | poiY: ' + poiY);
			var newPOI = document.getElementById(poiId);
			var xLeft = parseInt(ftPoiDbScale * (poiX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
			newPOI.style.left = xLeft - ftPoiWidth/2; //
			var yTop = parseInt(ftPoiDbScale * (poiY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
			newPOI.style.top  = yTop - ftPoiWidth/2;
		}
		*/
	//}

//	if( (poiX > (0 - ftMapX)) && (poiX < (0 - ftMapX) + ftMapWidth) && (poiY > (0 - ftMapY)) && (poiY < (0 - ftMapY) + ftMapHeight))
//		newPOI.style.visibility = 'visible';
//	else
//		newPOI.style.visibility = 'hidden';
}




//
function createCP () {
	//var ftMapDivElement = document.getElementById("mapDiv"); // toimii IE:ssä
	newCP = document.createElement("div");				// toimii IE:ssä
	newCP.setAttribute("id", "CP"); // tuntuu toimivan IE.ssä
	ft_classAttribute(newCP, "centerPointDiv");
	ftMapDivElement.appendChild(newCP);
	cX = parseInt(ftMapWidth  / 2 - ftMapX - 3);
	cY = parseInt(ftMapHeight / 2 - ftMapY - 3);
	newCP.style.left = cX;
	newCP.style.top  = cY;
}

// --------------------------------------------------------------------------------------------

// SEURAAVA TEKI OMITUISIA ONGELMIA
// remove-metodi
//Array.prototype.remove = function(s) {
//	for(i=0;i<this .length;i++){
//		if(s==this[i]) this.splice(i, 1);
//	}
//}

function arrayMember (arr, member) {
	var pit = arr.length;
	var raja = pit ;
	var flag = false;
	var lask = 0;
	while (lask < raja && flag != true ) {
		var element = arr[lask];
		if (element == member)
			flag = true;
		else
			lask++;
	}
	
	if (flag == false)
		return false;
	else
		return true;
}
//
// HUOM! tulos on +1
function arrayMones (arr, member) {
	var pit = arr.length;
	var raja = pit ;
	var flag = false;
	var lask = 0;
	while (lask < raja && flag != true ) {
		var element = arr[lask];
		if (element == member)
			flag = true;
		else
			lask++;
	}

	if (flag == false)
		return false;
	else
		return lask + 1;
}
/*
function testImage(URL) {
    var tester=new Image();
    //tester.onLoad=isGood;
    tester.onError=isBad;
    tester.src=URL;
}

//function isGood() {
//    alert('That image exists!');
//}

function isBad() {
	alert('That image does no exist!');
	
}
*/
//
//
function createCanvas () {
	//alert('createcanvas alkaa');
	//var ftMapDivElement = document.getElementById("mapDiv");
	clipMapDiv(ftMapDivElement);
	// mitat jatkossa aina metreissä 1Px=1 metri - ei enää 0.5 metreinä
	// OK 28.4. klo 15.25 metreiksi
	var leftEdgeX   = ftMapX - ftMapScale/1000 * ftMapWidth / 2;
	var rightEdgeX  = ftMapX + ftMapScale/1000 * ftMapWidth  / 2;
	var topEdgeY    = ftMapY - ftMapScale/1000 * ftMapHeight / 2 ;
	var bottomEdgeY = ftMapY + ftMapScale/1000 * ftMapHeight / 2 ;
	// pikseleinä
	var mapHalfW = parseInt(ftMapWidth / 2);
	var mapHalfH = parseInt(ftMapHeight / 2);
	//alert('leftEdgeX' + leftEdgeX + 'topEdgeY' + topEdgeY + ' | ftMapWidth:' + ftMapWidth  + ' | ftMapHeight:' + ftMapHeight);
	/*	
	testArr = new Array('ar', 'or', 'er', 'tr', 'tp', 'rr', 'ttr', 'rtr');
	alert(testArr);
	mones = arrayMember (testArr, 'ar');
	alert(mones);
	*/
	ftMapList = new Array();
	// etsitään ensimmäinen karttapala vasemmasta yläkulmasta
	// muutetaan metreistä pikseleiksi
	//var xruutuLkm = parseInt( (leftEdgeX )   / sliceW);
	// 
	var xruutuLkm = parseInt( (leftEdgeX /(ftMapScale/1000)) / sliceW);
	var xraja = xruutuLkm * sliceW;
	//alert('xraja: ' + xraja);
	var zoomTex = ftMapScale.toString();
	if(zoomTex == '500')
		zoomTex='0500';
	ftLaskuri = 0;
	// xraja on pikseleitä ja rightEdgeX on metrejä
	while (xraja * ftMapScale/1000  < rightEdgeX) {
		var yruutuLkm = parseInt( (topEdgeY /(ftMapScale/1000) )/ sliceH);
		var yraja = yruutuLkm * sliceH;
		while (yraja * ftMapScale/1000 < bottomEdgeY) {
			var idName = zoomTex + '_' + xraja + '_' + yraja; //OK
			//ftMapList[laskuri] = idName;
			ftMapList.push(idName);
			var filename = mapSliceName + idName + '.jpg';
			//alert('filename: ' + filename);
			var newMapImage = document.createElement("img");
			newMapImage.setAttribute("src", filename);
			newMapImage.setAttribute("id", idName);
			// seuraava tarpeeton, jos headin sisällä on jo <meta http-equiv="imagetoolbar" content="no" />
			//newMapImage.setAttribute("galleryImg", 'no');
			//ft_classAttribute(newMapImage, "mapImage");
			ftMapDivElement.appendChild(newMapImage);
			newMapImage.style.width  = sliceW;  //
			newMapImage.style.height = sliceH;  //
			newMapImage.style.position = 'absolute';
			noSelect (newMapImage);
			//
			var xLeft = xraja + mapHalfW - ftMapX /(ftMapScale/1000);
			//xLeft = xraja + mapHalfW - ftMapX * ftMapScale/1000;
			newMapImage.style.left = xLeft; //
			// ----
			var yTop = yraja + mapHalfH - ftMapY /(ftMapScale/1000);
			newMapImage.style.top  = yTop; //
			ftLaskuri++;
			yraja = yraja + sliceH;
		}
		xraja = xraja + sliceW;
	}	
	var pit = ftMapList.length;
	//alert('mapList pituus: ' + pit);
	//alert(ftMapList);
	//alert(leftEdgeX + ' ' + rightEdgeX + ' ' + topEdgeY + ' ' + bottomEdgeY);
} //function createCanvas

/*
function jaaListaksi (s) {
	var array2 = s.split('_');
	return array2;
}
*/


/*
function kuvaVirhe() {
	newMapImage.setAttribute("src", "maps/noMap.jpg");
	
	onError="alert('Image missing')
}
*/

//
function calcMapCanvas () {
	//var ftMapDivElement = document.getElementById("mapDiv");
	ftAlert('.1.');
	// metreinä
	var leftEdgeX   = ftMapX - ftMapScale/1000 * ftMapWidth / 2;
	var rightEdgeX  = ftMapX + ftMapScale/1000 * ftMapWidth  / 2;
	var topEdgeY    = ftMapY - ftMapScale/1000 * ftMapHeight / 2 ;
	var bottomEdgeY = ftMapY + ftMapScale/1000 * ftMapHeight / 2 ;
	// pikseleinä
	var mapHalfW = parseInt(ftMapWidth / 2);
	var mapHalfH = parseInt(ftMapHeight / 2);
	var aput = ' ';
	// siirretään olemassa olevia ja poistetaan tarpeettomat
	var lask = 0;
	var poistoLista = new Array();
	ftAlert('.2.');
//	for(i in ftMapList) { // }
	var liLen = ftMapList.length;
	for (i=0; i<liLen; i++) {
		var mapNimi = ftMapList[i];
		aput = aput + ' - ' + mapNimi;
		//var sana = mapId;
		var listaus = mapNimi.split('_');
		//var listaus = jaaListaksi(mapNimi);
		var zoomArvo = listaus[0];
		var xraja2 = parseInt(listaus[1]);
		var yraja2 = parseInt(listaus[2]);
		//alert(mapId + ' ' + xraja + ' ' + yraja);
		var newMapImage = document.getElementById(mapNimi);
		if (newMapImage != null) {
			var xLeft = xraja2 + mapHalfW - ftMapX /(ftMapScale/1000);
			newMapImage.style.left = xLeft;
			var yTop = yraja2 + mapHalfH - ftMapY /(ftMapScale/1000);
			newMapImage.style.top  = yTop;
			///
			/// Tutkitaan onko poissa näkymästä
			// yli oikean reunan
			// TÄHÄN CASE-RAKENNE !!!!!
			if(xraja2  * ftMapScale/1000 > rightEdgeX){
				var test = document.getElementById(mapNimi);
				if (test != null) {
					ftMapDivElement.removeChild(newMapImage); // VOI TULLA VIRHE
				}
				poistoLista.push(mapNimi);
				//ftMapList.splice(lask, 1)
				//mapList.remove(lask);
			}
			// yli vasemman reunan
			else if( (xraja2 + sliceW) * ftMapScale/1000 < leftEdgeX){
				test = document.getElementById(mapNimi);
				if (test != null) {
					ftMapDivElement.removeChild(newMapImage); // VOI TULLA VIRHE
				}
				//ftMapList.splice(lask, 1)
				poistoLista.push(mapNimi);
			}
			// yli yläreunan
			else if( (yraja2 + sliceH) * ftMapScale/1000 < topEdgeY){
				test = document.getElementById(mapNimi);
				if (test != null) {
					ftMapDivElement.removeChild(newMapImage); // VOI TULLA VIRHE
				}
				poistoLista.push(mapNimi);
				//ftMapList.splice(lask, 1)
			}
			// yli alareunan
			else if(yraja2 * ftMapScale/1000 > bottomEdgeY){
				test = document.getElementById(mapNimi);
				if (test != null) {
					ftMapDivElement.removeChild(newMapImage); // VOI TULLA VIRHE
				}
				poistoLista.push(mapNimi);
				//ftMapList.splice(lask, 1)
			}
		}
		else {
			//alert('Ongelma :' + mapNimi);
			//alert(ftMapList);
			poistoLista.push(mapNimi);
			//ftMapList.splice(lask, 1)
		}

		lask++
	} // loop: ftMapList
	//alert('poistoLista :' + poistoLista.toString());
	ftAlert('.3.');
	var lask4 = 0;
//	for(i in poistoLista) { //}
	var liLen = poistoLista.length;
	for (i=0; i<liLen; i++) {
		var mapNimi = poistoLista[i];
		// HUOM! koska javascriptille 0 = false, on seuraavan tulos 1+ jäsen arrayssa
		var mones = arrayMones (ftMapList, mapNimi);
		if (mones != false)
			ftMapList.splice(mones - 1, 1);
		lask4++;
	}
	//alert('ftMapList :' + ftMapList.toString());
	//alert('Poistolistasta : ' + lask4);
	///
	/// Seuraavaksi tutkitaan tarvittavat karttapalat ja lisätään uudet
	///
	var newMapList = new Array();
	var xruutuLkm = parseInt( (leftEdgeX /(ftMapScale/1000)) / sliceW);
	var xraja = xruutuLkm * sliceW;
	var zoomTex = ftMapScale.toString();
	if(zoomTex == '500')
		zoomTex='0500';

	ftAlert('.4a.');

	ftLaskuri = 0;
	while (xraja * ftMapScale/1000 < rightEdgeX) {
		var yruutuLkm = parseInt( (topEdgeY / (ftMapScale/1000) )/ sliceH);
		var yraja = yruutuLkm * sliceH;
		ftAlert('.4b.');
		while (yraja * ftMapScale/1000  < bottomEdgeY) {

			ftAlert('.4c.');
			var idName = zoomTex + '_' + xraja + '_' + yraja;
			if (arrayMember (ftMapList, idName)  == false) {
				//newMapList[laskuri] = idName;
				newMapList.push(idName);
				var filename = mapSliceName + idName + '.jpg';
				// MITEN TARKASTETAAN LÖYTYYKÖ?????? => noMap.jpg
				//alert('filename: ' + filename);
				newMapImage = document.createElement("img");
				//newMapImage.onError=kuvaVirhe;
				newMapImage.setAttribute("src", filename);
				newMapImage.setAttribute("id", idName);
				newMapImage.setAttribute("galleryImg", 'no');
				noSelect (newMapImage);
				//ft_classAttribute(newMapImage, "mapImage");
				ftMapDivElement.appendChild(newMapImage);
				newMapImage.style.width  = sliceW;  //
				newMapImage.style.height = sliceH;  //
				newMapImage.style.position = 'absolute';
				xLeft = xraja + mapHalfW - ftMapX /(ftMapScale/1000);
				newMapImage.style.left = xLeft; // OK
				// ----
				yTop = yraja + mapHalfH - ftMapY /(ftMapScale/1000);
				newMapImage.style.top  = yTop; // OK
			}
			ftAlert('.4d.');
			ftLaskuri++;
			yraja = yraja + sliceH;
		}
		xraja = xraja + sliceW;
	}
	/// yhdistetään ftMapList ja newMapList
	ftAlert('.5.');
	// concat
	ftMapList = ftMapList.concat(newMapList);
	var pitUusi = ftMapList.length; 
	//aput2 = ftMapList.toString();
	aput2 = '';
	var lask = 1;
//	for(i in ftMapList) { // }
	var liLen = ftMapList.length;
	for (i=0; i<liLen; i++) {
		var mapNimi = ftMapList[i];
		aput2 = aput2 + ' | ' + lask + ' :' + mapNimi;
		lask++
	}
	pit2=lask - 1;
	aput = aput + ' LOPPU '
	//if (virheLaskin == 50) {
	//
	//}
	// tarkistetaan DOM-puun virheet
	var lapsiArr = ftMapDivElement.childNodes;
	var lapsiArrPituus = lapsiArr.length;
	ftAlert('.6.');
	// seuraava ei enää ole voimassa, sillä mukana myös POI-objektit
	/*
	if(lapsiArrPituus - 2 > pitUusi) {
		//alert(lapsiArr);
		for(i in lapsiArr) {
			var lapsi = lapsiArr[i];
			nodeNimi = lapsi.nodeName;  // TÄMÄ ANTAA VIRHEITÄ !!!!!!!
			//alert(nodeNimi);
			if(nodeNimi == 'IMG') {
				var nodeId = lapsi.id;
				if (arrayMember (ftMapList, nodeId)  == false) {
					//alert('VirheNode: ' + nodeId);
					var virheMapImage = document.getElementById(nodeId);
					ftMapDivElement.removeChild(virheMapImage);
					virheLaskin++;
				}
			}
		}
	}
	//aput3 = ' | virheLask: ' + virheLaskin;
	*/
	
	aput3 = ' | lapsia: ' + lapsiArrPituus + ' | Korjattu DOM-virheitä: ' + virheLaskin + ' | PoistoLista: ' + lask4;
	ftInfoTex3 = '<br>&nbsp&nbsp;In use ' + pitUusi + '|' + pit2 + ' mapImg-objects - ' + aput3 + ftDragtext; 
	calcInfo();
} //function calcMapCanvas
//
// --------  Uudet funktiot tammikuussa 2006 -----------------------------------------
//
function doEditMode (eFlag) {
	//	alert('ftSelectedCatList: ' + ftSelectedCatList);
	editFlag = eFlag;
	//alert('doEditMode alkaa..');
	if(editFlag == true) {

		if(ftUsername == '') {
			if(ftLanguage == 'finnish')
				alert('Karttalinkkien editointi edellyttää sisäänkirjautumista!');
			else
				alert('If you want to create and edit map links, you must first log in!');
		}
		else {
			keyBoardOff();
			doOpenCatRadioWindow ();
			var edElement =document.getElementById("menuEditMap");
			edElement.onclick = new Function("doEditMode(false);");
			if(ftLanguage == 'finnish'){
				edElement.innerHTML = '&nbsp;Selaa karttaa';
			}
			else {
				edElement.innerHTML = '&nbsp;Browse map';
			}
			ftMapWidth = ftWindowWidth - ftLeftDivWidth - ftEditDivWidth;
			ftMapHeight = ftWindowHeight - ftStatusDivHeight - ftUpperbannerHeight - 2;
			//alert('0b');
			mapSize(ftMapWidth, ftMapHeight);
			if (document.getElementById("Poi0") != null) {
				removePOIList(ftPoiList);
				createPOIList(ftPoiList);
				updatePOIList();
			}
			//alert('1');
			var newEditDiv = document.createElement("div");
			newEditDiv.setAttribute("id", "editDiv");
			document.body.appendChild(newEditDiv);
			newEditDiv.style.left= ftMapWidth + ftLeftDivWidth;
			newEditDiv.style.top = ftStatusDivHeight + ftUpperbannerHeight;
			//alert('2');
			//
			// ------- Close-ruksi -------------------
			//
			var newCloseRuksiDiv = document.createElement("div");
			newCloseRuksiDiv.setAttribute("id", "newCloseRuksiDiv");
			newCloseRuksiDiv.onclick = new Function("doEditMode(false);");
			newEditDiv.appendChild(newCloseRuksiDiv);
			// ------- Status Title -------------------
			//
			var newStatusTitleDiv = document.createElement("div");
			newStatusTitleDiv.setAttribute("id", "newStatusTitleDiv");
			//newStatusTitleDiv.style.backgroundColor = '#99FF55';
			newStatusTitleDiv.style.position = 'absolute';
			newStatusTitleDiv.style.top = '3px';
			newStatusTitleDiv.style.left = '5px';
			newStatusTitleDiv.style.width = '225px';
			newStatusTitleDiv.style.height = '20px';
			//newStatusTitleDiv.style.backgroundColor = '#FFFF99';
			newStatusTitleDiv.style.fontSize = '13px';
			newStatusTitleDiv.style.fontFamily = 'arial, helvetica, sans-serif';
			newStatusTitleDiv.style.fontWeight = 'bold';
			if(ftLanguage == 'finnish')
				newStatusTitleDiv.innerHTML = newStatusTitleDivCapFin;
			else
				newStatusTitleDiv.innerHTML = newStatusTitleDivCapEng;
			newEditDiv.appendChild(newStatusTitleDiv);
			//
			// ------- Display owner div -------------------
			//
			var ownerDiv = document.createElement("div");
			ownerDiv.setAttribute("id", "ownerDiv");
			ownerDiv.innerHTML="";
			ownerDiv.style.position = 'absolute';
			ownerDiv.style.top = '2px';
			ownerDiv.style.left = '235px';
			ownerDiv.style.width = '120px';
			ownerDiv.style.height = '14px';
			//ownerDiv.style.backgroundcolor = '#EEFFCC';
			ownerDiv.style.fontsize = '12px';
			//ownerDiv.style.color = '#000000';
			if(ftAdminAlias == ftUsername)
				ownerDiv.innerHTML = 'admin';
			else
				ownerDiv.innerHTML = ftUsername;
			//ownerDiv.innerHTML = 'Moi!!';
			//ownerDiv.style.font-family: arial, helvetica, sans-serif;
			newEditDiv.appendChild(ownerDiv);
			//
			// ------- Display POI time -------------------
			//
			var timeDiv = document.createElement("div");
			timeDiv.setAttribute("id", "timeDiv");
			timeDiv.innerHTML="";
			timeDiv.style.position = 'absolute';
			timeDiv.style.top = '17px';
			timeDiv.style.left = '235px';
			timeDiv.style.width = '120px';
			timeDiv.style.height = '14px';
			//timeDiv.style.backgroundcolor = '#EE99CC';
			timeDiv.style.fontsize = '12px';
			timeDiv.style.color = '#000000';
			timeDiv.innerHTML = '';
			//ownerDiv.innerHTML = 'Moi!!';
			//ownerDiv.style.font-family: arial, helvetica, sans-serif;
			newEditDiv.appendChild(timeDiv);
			// ------- Display Id div -------------------
			//
			newDisplayIdDiv = document.createElement("div");
			newDisplayIdDiv.setAttribute("id", "newDisplayIdDiv");
			newDisplayIdDiv.innerHTML="";
			//newDisplayIdDiv.style.backgroundColor = '#55FF55';
			newEditDiv.appendChild(newDisplayIdDiv);
			//
			// ------- New Object Button ----------------
			//
			addNewObjectButton = document.createElement("input");
			addNewObjectButton.setAttribute("id", "addNewObjectButton");
			ft_classAttribute(addNewObjectButton, "addNewObjectButton");
			addNewObjectButton.setAttribute("type", "button");
			if(ftLanguage == 'finnish')
				addNewObjectButton.setAttribute("value", addNewObjectButtonCapFin);
			else
				addNewObjectButton.setAttribute("value", addNewObjectButtonCapEng);
			addNewObjectButton.onclick = new Function("addNewObject();");
			newEditDiv.appendChild(addNewObjectButton);
			//
			// ------- Copy Object Button ----------------
			//
			copyNewObjectButton = document.createElement("input");
			copyNewObjectButton.setAttribute("id", "copyNewObjectButton");
			ft_classAttribute(copyNewObjectButton, "copyNewObjectButton");
			copyNewObjectButton.setAttribute("type", "button");
			if(ftLanguage == 'finnish')
				copyNewObjectButton.setAttribute("value", 'Kopioi uudeksi linkki-objektiksi');
			else
				copyNewObjectButton.setAttribute("value", 'Copy to a new LinkObject');
			copyNewObjectButton.onclick = new Function("copyNewObject();");
			newEditDiv.appendChild(copyNewObjectButton);
			//
			// ------- Eng Title -------------------
			//
			newEngTitleDiv = document.createElement("div");
			newEngTitleDiv.setAttribute("id", "newEngTitleDiv");
			newEditDiv.appendChild(newEngTitleDiv);
			// label
			newEngTitleLabel = document.createElement("label");
			newEngTitleLabel.setAttribute = ("id", "newEngTitleLabel");
			newEngTitleLabel.setAttribute = ("for", "newEngTitleInput");
			if( ftLanguage == 'finnish')
				newEngTitleLabel.innerHTML = newEngTitleLabelFin;
			else
				newEngTitleLabel.innerHTML = newEngTitleLabelEng;
			newEngTitleDiv.appendChild(newEngTitleLabel);
			// Input
			newEngTitleInput = document.createElement("input");
	//		newEngTitleInput = document.createElement("textarea");
			ft_classAttribute(newEngTitleInput, "newEngTitleInput");
			newEngTitleInput.setAttribute("id", "newEngTitleInput");
			newEngTitleInput.setAttribute("type", "text");
			newEngTitleDiv.appendChild(newEngTitleInput);
			//
			// ------- Fin Title -------------------
			//
			newFinTitleDiv = document.createElement("div");
			newFinTitleDiv.setAttribute("id", "newFinTitleDiv");
			newEditDiv.appendChild(newFinTitleDiv);
			// Label
			newFinTitleLabel = document.createElement("label");
			newFinTitleLabel.setAttribute = ("id", "newFinTitleLabel");
			newFinTitleLabel.setAttribute = ("for", "newFinTitleInput");
			if( ftLanguage == 'finnish')
				newFinTitleLabel.innerHTML = newFinTitleLabelFin;
			else
				newFinTitleLabel.innerHTML = newFinTitleLabelEng;
			newFinTitleDiv.appendChild(newFinTitleLabel);
			// Input
			newFinTitleInput = document.createElement("input");
			ft_classAttribute(newFinTitleInput, "newFinTitleInput");
			newFinTitleInput.setAttribute("id", "newFinTitleInput");
			newFinTitleDiv.appendChild(newFinTitleInput);
			//
			// ------- Eng Descr -------------------
			//
			newEngDescrDiv = document.createElement("div");
			newEngDescrDiv.setAttribute("id", "newEngDescrDiv");
			newEditDiv.appendChild(newEngDescrDiv);
			// Label
			newEngDescrLabel = document.createElement("label");
			newEngDescrLabel.setAttribute = ("id", "newEngDescrLabel");
			newEngDescrLabel.setAttribute = ("for", "newEngDescrInput");
			if( ftLanguage == 'finnish')
				newEngDescrLabel.innerHTML = newEngDescrLabelFin;
			else
				newEngDescrLabel.innerHTML = newEngDescrLabelEng;
			newEngDescrDiv.appendChild(newEngDescrLabel);
			//newEngDescrDiv.innerHTML="English<br>Description:&nbsp;";
			// Input
			newEngDescrInput = document.createElement("textarea");

			ft_classAttribute(newEngDescrInput, "newEngDescrInput");
			newEngDescrInput.setAttribute("id", "newEngDescrInput");
			newEngDescrDiv.appendChild(newEngDescrInput);
			//
			// ------- Fin Descr -------------------
			//
			newFinDescrDiv = document.createElement("div");
			newFinDescrDiv.setAttribute("id", "newFinDescrDiv");
			newEditDiv.appendChild(newFinDescrDiv);
			// Label
			newFinDescrLabel = document.createElement("label");
			newFinDescrLabel.setAttribute = ("id", "newFinDescrLabel");
			newFinDescrLabel.setAttribute = ("for", "newFinDescrInput");
			if( ftLanguage == 'finnish')
				newFinDescrLabel.innerHTML = newFinDescrLabelFin;
			else
				newFinDescrLabel.innerHTML = newFinDescrLabelEng;
			newFinDescrDiv.appendChild(newFinDescrLabel);
			// Input
			newFinDescrInput = document.createElement("textarea");
			ft_classAttribute(newFinDescrInput, "newFinDescrInput");
			newFinDescrInput.setAttribute("id", "newFinDescrInput");
			newFinDescrDiv.appendChild(newFinDescrInput);
			//
			// ------- Eng URL -------------------
			//
			newEngUrlDiv = document.createElement("div");
			newEngUrlDiv.setAttribute("id", "newEngUrlDiv");
			newEditDiv.appendChild(newEngUrlDiv);
			// Label
			newEngUrlLabel = document.createElement("label");
			newEngUrlLabel.setAttribute = ("id", "newEngUrlLabel");
			newEngUrlLabel.setAttribute = ("for", "newEngUrlInput");
			if( ftLanguage == 'finnish')
				newEngUrlLabel.innerHTML = newEngUrlLabelFin;
			else
				newEngUrlLabel.innerHTML = newEngUrlLabelEng;
			newEngUrlDiv.appendChild(newEngUrlLabel);
			// Input
			newEngUrlInput = document.createElement("input");
			ft_classAttribute(newEngUrlInput, "newEngUrlInput");
			newEngUrlInput.setAttribute("id", "newEngUrlInput");
			newEngUrlInput.setAttribute("value", 'http://');
			newEngUrlDiv.appendChild(newEngUrlInput);
			//
			newEngUrlButton = document.createElement("input");
			ft_classAttribute(newEngUrlButton, "newEngUrlButton");
			newEngUrlButton.setAttribute("type", "button");
			newEngUrlButton.onclick = new Function("checkEngUrl();");
			newEngUrlDiv.appendChild(newEngUrlButton);
			//
			// ------- Fin URL -------------------
			//
			newFinUrlDiv = document.createElement("div");
			newFinUrlDiv.setAttribute("id", "newFinUrlDiv");
			newEditDiv.appendChild(newFinUrlDiv);
			// Label
			newFinUrlLabel = document.createElement("label");
			newFinUrlLabel.setAttribute = ("id", "newFinUrlLabel");
			newFinUrlLabel.setAttribute = ("for", "newFinUrlInput");
			if( ftLanguage == 'finnish')
				newFinUrlLabel.innerHTML = newFinUrlLabelFin;
			else
				newFinUrlLabel.innerHTML = newFinUrlLabelEng;
			newFinUrlDiv.appendChild(newFinUrlLabel);
			newFinUrlInput = document.createElement("input");
			ft_classAttribute(newFinUrlInput, "newFinUrlInput");
			newFinUrlInput.setAttribute("id", "newFinUrlInput");
			newFinUrlInput.setAttribute("value", 'http://');
			newFinUrlDiv.appendChild(newFinUrlInput);
			//
			newFinUrlButton = document.createElement("input");
			ft_classAttribute(newFinUrlButton, "newFinUrlButton");
			newFinUrlButton.setAttribute("type", "button");
			newFinUrlButton.onclick = new Function("checkFinUrl();");
			newFinUrlDiv.appendChild(newFinUrlButton);
			// ------- X,Y-coordinates -------------------
			newCoordDiv = document.createElement("div");
			newCoordDiv.setAttribute("id", "newCoordDiv");
			newEditDiv.appendChild(newCoordDiv);
			// X
			newXDiv = document.createElement("div");
			newXDiv.setAttribute("id", "newXDiv");
			newCoordDiv.appendChild(newXDiv);
			//
			newXDiv.innerHTML="X:&nbsp;";
			newXInput = document.createElement("input");
			ft_classAttribute(newXInput, "newXInput");
			newXInput.setAttribute("id", "newXInput");
			newXDiv.appendChild(newXInput);
			// Y
			newYDiv = document.createElement("div");
			newYDiv.setAttribute("id", "newYDiv");
			newCoordDiv.appendChild(newYDiv);
			//
			newYDiv.innerHTML="Y:&nbsp;";
			newYInput = document.createElement("input");
			ft_classAttribute(newYInput, "newYInput");
			newYInput.setAttribute("id", "newYInput");
			newYDiv.appendChild(newYInput);
			//
			newXYButton = document.createElement("input");
			newXYButton.setAttribute("id", "newXYButton");
			ft_classAttribute(newXYButton, "newXYButton");
			newXYButton.setAttribute("type", "button");
			//newXYButton.setAttribute("value", "Catch XY-coordinate from Canvas center point");
			newXYButton.onclick = new Function("catchXYcoord();");
			newCoordDiv.appendChild(newXYButton);
			// ------- Save To DBase Button ----------------
			saveToDbaseButton = document.createElement("input");
			saveToDbaseButton.setAttribute("id", "saveToDbaseButton");
			ft_classAttribute(saveToDbaseButton, "saveToDbaseButton");
			saveToDbaseButton.setAttribute("type", "button");
			//saveToDbaseButton.setAttribute("value", "Add To DataBase");
			saveToDbaseButton.onclick = new Function("saveToDbase();");
			newEditDiv.appendChild(saveToDbaseButton);
			// ------- Remove From DBase Button ----------------
			removeFromDbaseButton = document.createElement("input");
			removeFromDbaseButton.setAttribute("id", "removeFromDbaseButton");
			ft_classAttribute(removeFromDbaseButton, "removeFromDbaseButton");
			removeFromDbaseButton.setAttribute("type", "button");
			removeFromDbaseButton.onclick = new Function("removeFromDbase();");
			newEditDiv.appendChild(removeFromDbaseButton);
			if (ftLanguage == 'finnish') {
				newEngUrlButton.setAttribute("value", newEngUrlButtonCapFin);
				newFinUrlButton.setAttribute("value", newFinUrlButtonCapFin);
				newXYButton.setAttribute("value", newXYButtonCapFin);
				saveToDbaseButton.setAttribute("value", saveToDbaseButtonCapFin);
				removeFromDbaseButton.setAttribute("value", removeFromDbaseButtonCapFin);
			}
			else {
				newEngUrlButton.setAttribute("value", newEngUrlButtonCapEng);
				newFinUrlButton.setAttribute("value", newFinUrlButtonCapEng);
				newXYButton.setAttribute("value", newXYButtonCapEng);
				saveToDbaseButton.setAttribute("value", saveToDbaseButtonCapEng);
				removeFromDbaseButton.setAttribute("value", removeFromDbaseButtonCapEng);
			}
		}
	}
	else {
		keyBoardOn();
		//editFlag = false;
		//alert('a');
		var edElement =document.getElementById("menuEditMap");
		edElement.onclick = new Function("doEditMode(true);");
		if(ftLanguage == 'finnish')
			edElement.innerHTML = '&nbsp;Editoi linkkej&auml;';
		else
			edElement.innerHTML = '&nbsp;Edit links';
		//alert('c');
		document.body.removeChild(document.getElementById("editDiv"));
		//
		var leftSideDiv = document.getElementById('leftSideDiv');
		//document.body.removeChild(document.getElementById("catRadioDiv"));
		leftSideDiv.removeChild(document.getElementById("catRadioDiv"));
		//
		ftMapWidth = ftWindowWidth - ftLeftDivWidth;
		ftMapHeight = ftWindowHeight - ftStatusDivHeight - ftUpperbannerHeight - 2;
		mapSize(ftMapWidth, ftMapHeight);
		if (document.getElementById("Poi0") != null) {
			removePOIList(ftPoiList);
			createPOIList(ftPoiList);
			updatePOIList();
		}
	}
	//alert(editFlag);
} //function doEditMode
//
//

function toggleCatRadioElement (catNum) {
	var catPari = ftCatList[catNum];
	var catName = catPari[0];
	//alert('toggleCatRadioElement: ' + catName);
	document.getElementById(catName).checked = true;
	ftSelectedRadioCat = catName;
	removePOIList(ftPoiList);
	ftPoiList = null;
	showPoiCat (catName);
	ftSelectedCatList = null;
	ftSelectedCatList = new Array();
	ftSelectedCatList[0] = catName;
}


function doOpenCatRadioWindow () {
	// suljetaan Cat-ikkuna
	//if (catWindowFlag == true) {
	//	doCloseCatDiv();
	//}
	if( ftSelectedCatList != null) {
		ftSelectedRadioCat = ftSelectedCatList[0];
	}
	// poistetaan valitut categoriat
	removePOIList(ftPoiList);
	ftPoiList = null;
	showPoiCat (ftSelectedRadioCat);
	ftSelectedCatList = null;
	ftSelectedCatList = new Array();
	ftSelectedCatList[0] = ftSelectedRadioCat;
	//
	var leftSideDiv = document.getElementById('leftSideDiv');
	var mainCatRadioDiv = document.createElement("div");
	mainCatRadioDiv.setAttribute("id", "catRadioDiv");
	mainCatRadioDiv.style.position = 'absolute';
	mainCatRadioDiv.style.left= 1;  //ftLeftDivWidth + 2;
	//mainCatRadioDiv.style.top = ftStatusDivHeight + ftUpperbannerHeight; // + 65; // vika 30
	mainCatRadioDiv.style.top = 247;
	mainCatRadioDiv.style.width = ftLeftDivWidth - 5; // 200;
	mainCatRadioDiv.style.height = 235;
	//mainCatRadioDiv.style.paddingTop = '3px';
	mainCatRadioDiv.style.backgroundColor = '#FFFFFF';
	mainCatRadioDiv.style.fontSize = '10px';
	mainCatRadioDiv.style.fontFamily = 'arial, helvetica, sans-serif';
	mainCatRadioDiv.style.zIndex = 600;
	mainCatRadioDiv.style.borderStyle = 'solid';
	mainCatRadioDiv.style.borderColor = '#000000';
	mainCatRadioDiv.style.borderWidth = '1px';
	leftSideDiv.appendChild(mainCatRadioDiv);


	//alert('2');
	//
	// ------- Status Title -------------------
	//
	var newCatTitleDiv = document.createElement("div");
	newCatTitleDiv.setAttribute("id", "newCatTitleDiv");
	newCatTitleDiv.style.position = 'absolute';
	newCatTitleDiv.style.left= 3;
	newCatTitleDiv.style.top = 1;
	newCatTitleDiv.style.width = ftLeftDivWidth - 5; // 200;
	newCatTitleDiv.style.height = 20;
	//newCatTitleDiv.style.backgroundColor = '#FF6666';
	newCatTitleDiv.style.fontWeight = 'bold';
	newCatTitleDiv.style.fontSize = '13px'; /* 13  */
	if(ftLanguage == 'finnish')
		newCatTitleDiv.innerHTML = 'Valitse linkkikategoria';
	else
		newCatTitleDiv.innerHTML = 'Select Link Category';
	mainCatRadioDiv.appendChild(newCatTitleDiv);

	// ----------------
	newCarScrollDiv = document.createElement("div");
	newCarScrollDiv.setAttribute("id", "newCarScrollDiv");
	newCarScrollDiv.style.position = 'absolute';
	newCarScrollDiv.style.left= 1;
	newCarScrollDiv.style.backgroundColor = '#FFFFFF';
	newCarScrollDiv.style.top = 23; // vika 30
	newCarScrollDiv.style.width = ftLeftDivWidth - 9; // 200;
	newCarScrollDiv.style.height = 210;
	newCarScrollDiv.style.overflow = 'auto';
	mainCatRadioDiv.appendChild(newCarScrollDiv);
	// -----------------
	newCatDiv = document.createElement("div");
	newCatDiv.setAttribute("id", "catDiv");
	newCatDiv.style.position = 'absolute';
	newCatDiv.style.left= 0;  //ftLeftDivWidth + 2;
	newCatDiv.style.top = 0;  //ftStatusDivHeight + ftUpperbannerHeight + 65; // vika 30
	newCatDiv.style.width = ftLeftDivWidth - 35; // 200;
	newCatDiv.style.height = 205;
	newCatDiv.style.paddingTop = '0px';
	newCatDiv.style.backgroundColor = '#FFFFFF';
	newCatDiv.style.fontSize = '10px';
	newCatDiv.style.fontFamily = 'arial, helvetica, sans-serif';
	newCatDiv.style.zIndex = 600;
	newCarScrollDiv.appendChild(newCatDiv);

	// tehdään formi mm konqueria varten
	newCatForm = document.createElement("form");
	newCatDiv.appendChild(newCatForm);

	//
	// ------- POI-categoria-luettelo -------------------
	//
	// simuloidaan hash-tablea ("catnimi" false/true)
	//ftCatList // muotoa ('hotelli' . false)(elokuva . true)
	//alert(ftCatList);
	var catLkm = ftCatList.length;
	var topY = 5;  // 40
	for (i=0; i<catLkm; i++) {
		var catPari = ftCatList[i];
		//alert(catPari);
		var catName  = catPari[0];
		var catValue = catPari[1];
		if(selain == 'ie') {
			if( catName == ftSelectedRadioCat ) {
				var optionToggleElement = document.createElement('<input type="radio" name="catRadioSelect" checked>')
			}
			else {
				var optionToggleElement = document.createElement('<input type="radio" name="catRadioSelect">')
			}
		}
		else {
			var optionToggleElement = document.createElement("input");
			optionToggleElement.setAttribute("type", "radio");
			optionToggleElement.setAttribute("name", "catRadioSelect");
			if( catName == ftSelectedRadioCat ) {
				//alert('checked catName: ' + catName);
				optionToggleElement.checked = true;
			}
		}
		//optionToggleElement.name = 'catRadioSelect';
		optionToggleElement.setAttribute("id", catName);
		optionToggleElement.style.position = 'absolute';
		optionToggleElement.style.top  = topY;
		optionToggleElement.style.left  = 110;
		optionToggleElement.setAttribute("value", catName);
		optionToggleElement.onclick = new Function("toggleCatRadioElement(" + i + ");");
		newCatForm.appendChild(optionToggleElement);
		// --- label ---
		var toggleElementLabel = document.createElement("label");
		toggleElementLabel.setAttribute("id", 'Label-' + catName);
		toggleElementLabel.setAttribute("for", "optionToggleElement");
		if(ftLanguage == 'finnish') {
			toggleElementLabel.innerHTML = catName;
		}
		else {
			var jas = arrayMones (ftCatNameList, catName);
			var catNameEng = ftCatNameList_eng[jas - 1];
			toggleElementLabel.innerHTML = catNameEng;
		}
		toggleElementLabel.style.position = 'absolute';
		toggleElementLabel.style.top  = topY;
		toggleElementLabel.style.left  = 20;
		toggleElementLabel.style.fontSize  = "12px"; // Toimii nyt
		newCatForm.appendChild(toggleElementLabel);
		//
		/*
		// --- poi lukumäärä-teksti
		var optionToggleLkm = document.createElement("div");
		optionToggleLkm.setAttribute("id", catName + 'Lkm');
		optionToggleLkm.style.position = 'absolute';
		optionToggleLkm.style.top  = topY;
		optionToggleLkm.style.left  = 120;
		optionToggleLkm.style.fontSize  = "12px";
		optionToggleLkm.innerHTML = '0';
		mainCatRadioDiv.appendChild(optionToggleLkm);
		*/
		//
		// --- 
//		var iconName = getPoiIcon (catName);
//		var iconUrl = 'url(images/' + iconName + '_10.gif)';
		//
/*		var carIconDiv = document.createElement("div");
		carIconDiv.setAttribute("id", catName + 'Icon');
		carIconDiv.style.position = 'absolute';
		carIconDiv.style.top  = topY + 3;
		carIconDiv.style.left  = 5;
		carIconDiv.style.width  = 10;
		carIconDiv.style.height  = 10;
		carIconDiv.style.backgroundImage  = iconUrl;
		newCatForm.appendChild(carIconDiv); */
		//
		var iconName = getPoiIcon (catName);
		var iconUrl = 'images/' + iconName + '_10.gif';
		//var iconUrl = iconName + '_10.gif)';
		//alert(iconUrl);
		var carImage = document.createElement("img");
		carImage.setAttribute("src", iconUrl);
		carImage.setAttribute("id", catName + 'Icon');
		carImage.style.position = 'absolute';
		carImage.style.top  = topY + 3;
		carImage.style.left  = 5;
		carImage.style.width  = 10;  //
		carImage.style.height = 10;  //
		newCatForm.appendChild(carImage);
		//
		// ---
		topY = topY + 15;
	}

} //function doOpenCatRadioWindow


function drawCP () {
	//alert('cp0');
	newCP = document.getElementById("CP");
	var cX = ftMapWidth  / 2 - 3;
	var cY = ftMapHeight / 2 - 3;
	//alert('cp1');
	newCP.style.left = cX;
	//alert('cp2');
	newCP.style.top  = cY;
	//alert('cp3');
}

function clipMapDiv(element) {
	// clipataan emo-diviä eli mapDiv-objektia
	clipTop  = 0;
	clipLeft = 0;
	clipRight = clipLeft + ftMapWidth;
	clipBottom = clipTop + ftMapHeight;
	recbox = 'rect(' + clipTop + 'px ' + clipRight + 'px ' + clipBottom + 'px ' + clipLeft +'px)'
	//ftMapDivElement.style.clip  = recbox;
	element.style.clip  = recbox;
}

//-------------------------------
//
function addNewObject () {
	poiEditMode = 'new'; 'edit'/'new'
	if (ftLanguage == 'finnish') {
		document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapFin;
		document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapFin;
	}
	else {
		document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapEng;
		document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapEng;
	}
	document.getElementById('newDisplayIdDiv').innerHTML = '';
	document.getElementById('newEngTitleInput').value = '';
	document.getElementById('newFinTitleInput').value = '';
	document.getElementById('newEngDescrInput').value = '';
	document.getElementById('newFinDescrInput').value = '';
	document.getElementById('newEngUrlInput').value = 'http://';
	document.getElementById('newFinUrlInput').value = 'http://';
	document.getElementById('newXInput').value = '';
	document.getElementById('newYInput').value = '';
	document.getElementById('timeDiv').innerHTML = '';
	if(ftAdminAlias == ftUsername)
		ownerDiv.innerHTML = 'admin';
	else
		ownerDiv.innerHTML = ftUsername;
	//document.getElementById('ownerDiv').innerHTML = ftUsername;
} //function addNewObject
//
//
//-------------------------------
//
function copyNewObject () {
	poiEditMode = 'new'; 'edit'/'new'
	if (ftLanguage == 'finnish') {
		document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapFin;
		document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapFin;
	}
	else {
		document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapEng;
		document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapEng;
	}
	document.getElementById('timeDiv').innerHTML = '';
	if(ftAdminAlias == ftUsername)
		ownerDiv.innerHTML = 'admin';
	else
		ownerDiv.innerHTML = ftUsername;
	//document.getElementById('ownerDiv').innerHTML = ftUsername;
} //function copyNewObject
//
//
function catchXYcoord () {
	document.getElementById('newXInput').value = ftMapX;
	document.getElementById('newYInput').value = ftMapY;
	//ftPoiTempX = ftMapX;
	//ftPoiTempY = ftMapY;
	
	// poistetaan mahdollinen ftPoiTemp-objekti
	if(ftPoiTemp != null) {
		//ftMapDivElement.removeChild(document.getElementById('ftPoiTemp'));
		ftPoiMoveDiv.removeChild(document.getElementById('ftPoiTemp'));
		ftPoiTemp = null;
	}
	// luodaan uusi
	var tempX = parseInt(ftMapX / ftPoiDbScale) + ftPoiXMove;
	var tempY = Math.round( parseInt(ftMapY / ftPoiDbScale)  * 1.41421356) + ftPoiYMove;
	// ok tämä on sama muoto kuin tietokannassa
	//alert ('tempX: ' + tempX  + ' tempY: ' + tempY   );
	// muunnetaan takaisin createPoi-muotoon
	ftPoiTempX = tempX - ftPoiXMove;
	ftPoiTempY = Math.round((tempY - ftPoiYMove) * 0.707106);
	//
	var mapHalfW = parseInt(ftMapWidth / 2);
	var mapHalfH = parseInt(ftMapHeight / 2);
	//alert('create poi alkaa');
	poiWidth = 25;
	iconName = 'poiTemp_25.gif';
	ftPoiTemp = document.createElement("div");
	ftPoiTemp.setAttribute("id", "ftPoiTemp");
	ftPoiTemp.style.position = 'absolute';
	var xLeft = parseInt(ftPoiDbScale * (ftPoiTempX/(ftMapScale/1000)) + mapHalfW - ftMapX /(ftMapScale/1000));
	ftPoiTemp.style.left = xLeft - poiWidth/2; //
	var yTop = parseInt(ftPoiDbScale * (ftPoiTempY/(ftMapScale/1000)) + mapHalfH - ftMapY /(ftMapScale/1000));
	ftPoiTemp.style.top  = yTop - poiWidth/2;
	ftMapDivElement.appendChild(ftPoiTemp);
} //function catchXYcoord
//
//
function saveToDbase () {
	// poistetaan mahdollinen ftPoiTemp-objekti
	if(ftPoiTemp != null) {
		//ftMapDivElement.removeChild(document.getElementById('ftPoiTemp'));
		//ftPoiMoveDiv.removeChild(document.getElementById('ftPoiTemp'));
		ftMapDivElement.removeChild(document.getElementById('ftPoiTemp'));
		ftPoiTemp = null;
	}
	var ourDate = new Date();
	var aikaStr = ourDate.getTime();
	var owner = document.getElementById('ownerDiv').innerHTML;
	//
	//alert('0');
	var category = ftSelectedRadioCat;
	var poiTitle = document.getElementById('newEngTitleInput').value;
	var poiTitleFin = document.getElementById('newFinTitleInput').value;
	var poiInfo = document.getElementById('newEngDescrInput').value;
	//alert('1');
	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;
	var xNew = parseInt(xCoord / ftPoiDbScale) + ftPoiXMove;
	var yNew = Math.round( parseInt(yCoord / ftPoiDbScale)  * 1.41421356) + ftPoiYMove;  //0.7071067811865475244008443621052
	if ( poiEditMode == 'new') { //'edit'/'new'
		//alert('New to Dbase');
		//alert('function saveToDbase :' + ftPoiList);
		addDbPoi(category, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xNew, yNew, owner, aikaStr);
	}
	else {  // 'update'
		var id2 = document.getElementById('newDisplayIdDiv').innerHTML;
		var owner = document.getElementById('ownerDiv').innerHTML;
		if(owner == 'vieras' || owner == 'guest') {
			updateDbPoi(poiDbId, category, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xNew, yNew, owner, aikaStr);
		}
		else {
			if(ftUsername == 'vieras' || ftUsername == 'guest') {
				if (ftLanguage == 'finnish')
					alert('Et voi editoida karttalinkkiä vieraana, rekisteröidy ja kirjaudu ensin.');
				else
					alert('You cannot edit map link as a guest, register and login first.');
			}
			else {
				updateDbPoi(poiDbId, category, poiTitle, poiTitleFin, poiInfo, poiInfoFin, poiHref, poiHrefFin, xNew, yNew, owner, aikaStr);
			}
		}
	}
} //function saveToDbase
//
//
function removeFromDbase () {
	//alert('-0-');
	var owner = document.getElementById('ownerDiv').innerHTML;
	//if(ftAdminAlias == ftUsername)
	//alert('-1-');
	if(ftUsername == owner || ftUsername == 'admin' || ftUsername == ftAdminAlias ) {
		//alert('-2-');
		remDbPoi(poiDbId);
		
		//alert('selain: ' + selain);
		//alert('-3-');
		removePOIList(ftPoiList);
		if(selain == 'saf')alert('Safari 2');
		//alert('-4-');
		ftPoiList = null;
		if(selain == 'saf')alert('Safari 3');
		//alert('-5-');
		showPoiCat (ftSelectedRadioCat);
		//alert('-6-');
	}
	else {
		if (ftLanguage == 'finnish')
			alert('Et voi poistaa linkkiä, sillä karttalinkki ei ole sinun linkkisi!');
		else
			alert('You cannot remove map link because it is not your link!');
	}
} //function removeFromDbase
//
//
//
function checkEngUrl() {
	var poiHref = document.getElementById('newEngUrlInput').value;
	window.open(poiHref);
} //function checkFinUrl
//
//
function checkFinUrl() {
	var poiHrefFin = document.getElementById('newFinUrlInput').value;
	window.open(poiHrefFin);
} //function checkFinUrl
//


function doLanguage () {
	//alert('doLanguage alkaa..');
	if (document.getElementById("languageRadioFin").checked == true ) {
		//alert('-f-0-');
		ftLanguage = 'finnish'; //finnish/english/(swedish)
		//alert('doLanguage, ftSelectedCatList: ' + ftSelectedCatList);
		// poistetaan vanhat poiDivit, jos niitä on
		removePOIList();
		ftPoiList = null;
		if(ftSelectedCatList != 'none' && ftSelectedCatList != null) {
			for(var i = 0; i < ftSelectedCatList.length; i++) {
				var cat = ftSelectedCatList[i];
				showPoiCat(cat);
			}
		}
		//alert('-f-1-');
		document.getElementById("upperbanner").style.backgroundImage = "url(images/logobanner.jpg)";
		if(editFlag == false)
			document.getElementById('menuEditMap').innerHTML = '&nbsp;Editoi linkkej&auml;';
		else
			document.getElementById('menuEditMap').innerHTML = '&nbsp;Selaa karttaa';
		//
		document.getElementById('menuForum').innerHTML = 'Keskustelu';
		document.getElementById('menuHelpHeader').innerHTML = 'Ohje';
		document.getElementById('menuNetLinks').innerHTML = 'NettiLinkit';
		// käydään läpi lista, joka on cityguide3d.conf.js-tiedostossa
		for(var i = 0; i < ftLangListFin.length; i++) {
    		var pari = ftLangListFin[i];
    		var elNimi = pari[0];
    		var elArvo = pari [1]
			document.getElementById(elNimi).innerHTML = elArvo;
    	}
		//alert('-f-2-');
    	// Login-ikkuna
    	if(ftLoggedIn == true) {
	    	document.getElementById('tunnusText').innerHTML = '<b>' + ftUsername + '</b> on kirjautunut sisään.';
	    	document.getElementById('outDiv').innerHTML = 'Kirjaudu ulos';
		}    	
		else {
	    	document.getElementById('tunnusLabel').innerHTML = 'tunnus';
	    	document.getElementById('ssanaLabel').innerHTML = 'salasana';
	    	document.getElementById('rekisteroidu').innerHTML = '<a href="' + ftphpBBAddress + 'profile.php?mode=register&agreed=true" target="_blank">Rekisteröidy</a>';
	    	document.getElementById('whyRegister').innerHTML = 'Miksi rekisteröityä?';
	    	if(document.getElementById('tunnus').value == 'guest')
	    		document.getElementById('tunnus').value = 'vieras';
	    	if(document.getElementById('ssana').value == 'guest')
	    		document.getElementById('ssana').value = 'vieras';
		}

   	
    	//
		var helpElement = document.getElementById('menuHelp');
		helpElement.innerHTML = 'Ohjeita';
		document.getElementById('menuAbout').innerHTML = 'Tietoja sovelluksesta';
		document.getElementById('menuContact').innerHTML = 'Yhteystietoja';
		document.getElementById('menuProject').innerHTML = 'Tietoja projektista';
		//
		document.getElementById('menuTools').innerHTML = 'Ty&ouml;kalut';
		document.getElementById('menuSendF').innerHTML = 'L&auml;het&auml; kohde S&auml;hk&ouml;postina';
		// ------- etsintä ----------
		document.getElementById("searchLabel").innerHTML = '<b>HAKU</b>&nbsp;Kirjoita hakusana';
		document.getElementById("searchButton").innerHTML = 'Hae';
		document.getElementById("fastSearchOtsikko").innerHTML = 'Valitse hakusana';
		document.getElementById("fastSearchButton").innerHTML = 'Hae';
		// --------- cat Window -----------------
		if (catWindowFlag == true) {
			document.getElementById('newCatTitleDiv').innerHTML = 'Valitse linkkikategoriat';
			document.getElementById('totalLkmLabel').innerHTML = 'Valittu';
			//document.getElementById("OpenCatWindow").innerHTML = '&nbsp;Sulje Linkkimenu';
			// muutetaan cat_Labelit
			var catLkm = ftCatList.length;
			for (i=0; i<catLkm; i++) {
				var catPari = ftCatList[i];
				var catName  = catPari[0];
				document.getElementById('Label-' + catName).innerHTML = catName;
			}
		}
		else {
			var p = 1; //tyhjä rivi
			//document.getElementById("OpenCatWindow").innerHTML = '&nbsp;Avaa Linkkimenu';
		}
		var fastSearchLkm = ftfastSearchList.length;
		var pikahaluList = document.getElementById('fastSearchLista');
		for (i=0; i<fastSearchLkm; i++) {
			var hakuName  = ftfastSearchList[i];
			//var hakuItem = document.createElement("option");
			var hakuItem = document.getElementById("phOpt_" + i);
			//hakuItem.setAttribute("id", "phOpt_" + i);
			hakuItem.value = hakuName;
			hakuItem.innerHTML = hakuName;
			//pikahaluList.appendChild(hakuItem);
		}
		//
		// --------- editointi kaavake -----------------
		if (editFlag == true) {
			if(poiEditMode == 'new') {
				document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapFin;
			}
			else {
				document.getElementById('newStatusTitleDiv').innerHTML = 'Editoidaan Objektia Id: ' + poiDbId;
			}
			document.getElementById('addNewObjectButton').value = addNewObjectButtonCapFin;

			newEngTitleLabel.innerHTML = newEngTitleLabelFin;
			newFinTitleLabel.innerHTML = newFinTitleLabelFin;
			// miksi seuraava ei toimi, onneksi newEngTitleLabel on globaali
			//document.getElementById('newEngTitleLabel').innerHTML = newEngTitleLabelFin;
			//document.getElementById('newFinTitleLabel').innerHTML = newFinTitleLabelFin;

			newEngDescrLabel.innerHTML = newEngDescrLabelFin;
			newFinDescrLabel.innerHTML = newFinDescrLabelFin;
			newEngUrlLabel.innerHTML = newEngUrlLabelFin;
			newFinUrlLabel.innerHTML = newFinUrlLabelFin;
			//document.getElementById('newEngDescrDiv').innerHTML = newEngDescrDivCapFin;
			//document.getElementById('newFinDescrDiv').innerHTML = newFinDescrDivCapFin;
			//document.getElementById('newEngUrlDiv').innerHTML = newEngUrlDivCapFin;
			//document.getElementById('newFinUrlDiv').innerHTML = newFinUrlDivCapFin;

			newEngUrlButton.value = newEngUrlButtonCapFin;
			newFinUrlButton.value = newFinUrlButtonCapFin;
			newXYButton.setAttribute("value", newXYButtonCapFin);


			copyNewObjectButton.setAttribute("value", 'Kopioi uudeksi linkki-objektiksi');


			if(poiEditMode == 'new') {
				saveToDbaseButton.setAttribute("value", saveToDbaseButtonCapFin);
			}
			else {
				saveToDbaseButton.setAttribute("value", 'Päivitä tietokantaan');
			}


			removeFromDbaseButton.setAttribute("value", removeFromDbaseButtonCapFin);
			//document.getElementById('newEngUrlButton').value = newEngUrlButtonCapFin;
			//document.getElementById('newFinUrlButton').value = newFinUrlButtonCapFin;
			//document.getElementById('newXYButtonCap').value = newXYButtonCapFin;
			//document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapFin;
			//document.getElementById('removeFromDbaseButton').value = removeFromDbaseButtonCapFin;
			
			// --------- radioCat-ikkuna --------------
			document.getElementById('newCatTitleDiv').innerHTML = 'Valitse linkkikategoria';
			// muutetaan cat_Labelit
			var catLkm = ftCatList.length;
			for (i=0; i<catLkm; i++) {
				var catPari = ftCatList[i];
				var catName  = catPari[0];
				document.getElementById('Label-' + catName).innerHTML = catName;
			}
		}
	} // finnish
	else {
		//alert('-0-');
		ftLanguage = 'english'; //finnish/english/(swedish)
		// poistetaan vanhat poiDivit, jos niitä on
		removePOIList();
		ftPoiList = null;
		//alert('-1-');
		//alert('ftSelectedCatList: '  + ftSelectedCatList);
		if(ftSelectedCatList != 'none'  && ftSelectedCatList != null) {
			for(var i = 0; i < ftSelectedCatList.length; i++) {
				var cat = ftSelectedCatList[i];
				showPoiCat(cat);
			}
		}
		//
		//alert('-2-');
		document.getElementById("upperbanner").style.backgroundImage = "url(images/logobanner.jpg)";
		if(editFlag == false)
			document.getElementById('menuEditMap').innerHTML = '&nbsp;Edit Links';
		else
			document.getElementById('menuEditMap').innerHTML = '&nbsp;Browse map';
		document.getElementById('menuForum').innerHTML = 'BB Forum';
		document.getElementById('menuHelpHeader').innerHTML = 'Help';
		document.getElementById('menuNetLinks').innerHTML = 'Net Links';
		//alert('-3-');
		//
		// käydään läpi id-text lista, joka on cityguide3d.conf.js-tiedostossa
		for(var i = 0; i < ftLangListEng.length; i++) {
    		var elPari = ftLangListEng[i];
    		var elNimi = elPari[0];
    		var elArvo = elPari[1];
    		//alert(elArvo);
			document.getElementById(elNimi).innerHTML = elArvo;
    	}
		//alert('-4-');
		// Login-ikkuna
    	if(ftLoggedIn == true) {
	    	document.getElementById('tunnusText').innerHTML = '<b>' + ftUsername + '</b> is logged in.';
	    	document.getElementById('outDiv').innerHTML = 'Logout';
		}
		else {
	    	document.getElementById('tunnusLabel').innerHTML = 'username';
	    	document.getElementById('ssanaLabel').innerHTML = 'password';
	    	//document.getElementById('ssana').value = 'guest';
	    	document.getElementById('rekisteroidu').innerHTML = '<a href="' + ftphpBBAddress + 'profile.php?mode=register&agreed=true" target="_blank">Register</a>';
	    	document.getElementById('whyRegister').innerHTML = 'Why to register?';
	    	if(document.getElementById('tunnus').value == 'vieras')
	    		document.getElementById('tunnus').value = 'guest';
	    	if(document.getElementById('ssana').value == 'vieras')
	    		document.getElementById('ssana').value = 'guest';
		}
		//alert('-5-');
		var helpElement = document.getElementById('menuHelp');
		helpElement.innerHTML = 'Help';
		//helpElement.onClick = "openFtWindow(\'help_eng.html\')";

		document.getElementById('menuAbout').innerHTML = 'About application';
		document.getElementById('menuContact').innerHTML = 'Contact Information';
		document.getElementById('menuProject').innerHTML = 'About project';
		//
		document.getElementById('menuTools').innerHTML = 'Tools';
		document.getElementById('menuSendF').innerHTML = 'Send location in Email';
		//
		// ------- etsintä ----------
		document.getElementById("searchLabel").innerHTML = '<b>SEARCH</b>&nbsp;Write search word';
		document.getElementById("searchButton").innerHTML = 'Search';
		document.getElementById("fastSearchOtsikko").innerHTML = 'Select search word';
		document.getElementById("fastSearchButton").innerHTML = 'Search';
		//alert('-6-');
		// --------- cat Window -----------------
		if (catWindowFlag == true) {
			document.getElementById('newCatTitleDiv').innerHTML = 'Select Link Categories';;
			document.getElementById('totalLkmLabel').innerHTML = 'Selected';
			//document.getElementById("OpenCatWindow").innerHTML = '&nbsp;Close map Link menu';
			// muutetaan cat_Labelit
			var catLkm = ftCatList.length;
			for (i=0; i<catLkm; i++) {
				var catPari = ftCatList[i];
				var catName  = catPari[0];
				var jas = arrayMones (ftCatNameList, catName);
				var catNameEng = ftCatNameList_eng[jas - 1];
				document.getElementById('Label-' + catName).innerHTML = catNameEng;
			}
		}
		else {
			var p = 1; // tyhjä määräys
			//document.getElementById("OpenCatWindow").innerHTML = '&nbsp;Open map Link menu';
		}
		// 
		var fastSearchLkm = ftfastSearchList.length;
		var pikahaluList = document.getElementById('fastSearchLista');
		for (i=0; i<fastSearchLkm; i++) {
			var hakuName  = ftfastSearchList_eng[i];
			//var hakuItem = document.createElement("option");
			var hakuItem = document.getElementById("phOpt_" + i);
			//hakuItem.setAttribute("id", "phOpt_" + i);
			hakuItem.value = hakuName;
			hakuItem.innerHTML = hakuName;
			//pikahaluList.appendChild(hakuItem);
		}
		// --------- editointi kaavake -----------------
		if (editFlag == true) {
			if(poiEditMode == 'new') {
				document.getElementById('newStatusTitleDiv').innerHTML = newStatusTitleDivCapEng;
			}
			else {
				document.getElementById('newStatusTitleDiv').innerHTML = 'Editing Object Id: ' + poiDbId;
			}
			document.getElementById('addNewObjectButton').value = addNewObjectButtonCapEng;
			copyNewObjectButton.setAttribute("value", 'Copy to a new LinkObject');
			newEngTitleLabel.innerHTML = newEngTitleLabelEng;
			newFinTitleLabel.innerHTML = newFinTitleLabelEng;
			newEngDescrLabel.innerHTML = newEngDescrLabelEng;
			newFinDescrLabel.innerHTML = newFinDescrLabelEng;
			//document.getElementById('newEngTitleLabel').innerHTML = newEngTitleLabelEng;
			//document.getElementById('newFinTitleLabel').innerHTML = newFinTitleLabwlEng;
			//document.getElementById('newEngDescrDiv').innerHTML = newEngDescrDivCapEng;
			//document.getElementById('newFinDescrDiv').innerHTML = newFinDescrDivCapEng;

			newEngUrlLabel.innerHTML = newEngUrlLabelEng;
			newFinUrlLabel.innerHTML = newFinUrlLabelEng;
			newEngUrlButton.value = newEngUrlButtonCapEng;
			newFinUrlButton.value = newFinUrlButtonCapEng;
			//document.getElementById('newEngUrlDiv').innerHTML = newEngUrlDivCapEng;
			//document.getElementById('newFinUrlDiv').innerHTML = newFinUrlDivCapEng;
			//document.getElementById('newEngUrlButton').value = newEngUrlButtonCapEng;
			//document.getElementById('newFinUrlButton').value = newFinUrlButtonCapEng;

			newXYButton.setAttribute("value", newXYButtonCapEng);
			if(poiEditMode == 'new') {
				saveToDbaseButton.setAttribute("value", saveToDbaseButtonCapEng);
			}
			else {
				saveToDbaseButton.setAttribute("value", 'Update to Dbase');
			}
			removeFromDbaseButton.setAttribute("value", removeFromDbaseButtonCapEng);
			//document.getElementById('newXYButtonCap').value = newXYButtonCapEng;
			//document.getElementById('saveToDbaseButton').value = saveToDbaseButtonCapEng;
			//document.getElementById('removeFromDbaseButton').value = removeFromDbaseButtonCapEng;
			
			// ------------ radioCatWindow --------
			document.getElementById('newCatTitleDiv').innerHTML = 'Select Link Category';
			// muutetaan cat_Labelit
			var catLkm = ftCatList.length;
			for (i=0; i<catLkm; i++) {
				var catPari = ftCatList[i];
				var catName  = catPari[0];
				var jas = arrayMones (ftCatNameList, catName);
				var catNameEng = ftCatNameList_eng[jas - 1];
				document.getElementById('Label-' + catName).innerHTML = catNameEng;
			}
			
		}
	} //english

} // function doLanguage

function doSetfastSearchList(){
	var fastSearchLkm = ftfastSearchList.length;
	var pikahaluList = document.getElementById('fastSearchLista');
	for (i=0; i<fastSearchLkm; i++) {
		var hakuName  = ftfastSearchList[i];
		var hakuItem = document.createElement("option");
		hakuItem.setAttribute("id", "phOpt_" + i);
		hakuItem.value = hakuName;
		hakuItem.innerHTML = hakuName;
		pikahaluList.appendChild(hakuItem);
	}
}

function dofastSearch () {
	var listValinta = document.getElementById('fastSearchLista').value;
	//alert('listValinta on : ' + listValinta);
	var hakuAlku = 0; // + ''
	seachStringInDb(listValinta, ftLanguage, hakuAlku, ftHakuLkm);
}


function getPoiIcon (catName) {
	var iconName = null;
	if ( catName == 'rakennus') {
		iconName = 'poiViolet';
	}
	else if ( catName == 'yritys') {
		iconName = 'poiBrown';
	}
	else if ( catName == 'yksityinen') {
		iconName = 'poiGrey';
	}
	else if ( catName == 'museo' || catName == 'teatteri' || catName == 'konsertti' || catName == 'elokuva' ) {
		iconName = 'poiLightBlue';
	}
	else if ( catName == 'kirkko') {
		iconName = 'poiBlack';
	}
	else if ( catName == 'kauppa') {
		iconName = 'poiGreen';
	}
	else if ( catName == 'ravintola') {
		iconName = 'poiRed';
	}
	else if ( catName == 'kahvila') {
		iconName = 'poiRed';
	}
	else if ( catName == 'hotelli') {
		iconName = 'poiBlue';
	}
	else if ( catName == 'virasto') {
		iconName = 'poiYellow';
	}
	else if ( catName == 'pankki') {
		iconName = 'poiDarkGreen';
	}
	else if ( catName == 'liikenne') {
		iconName = 'poiOrange';
	}
	else {
		iconName = 'poiPink';
	}
	return iconName;
} //function getPoiIcon 


function doSearch () {
	var searchString = document.getElementById('searchText').value;
	//alert('Suoritetaan etsintä sanalla: ' + searchString);
	var hakuAlku = 0; // + ''
	seachStringInDb(searchString, ftLanguage, hakuAlku, ftHakuLkm);
}
//
function doSetLoginDiv () {
	var leftSideDiv = document.getElementById('leftSideDiv');
	mainLoginDiv = document.createElement("div");
	mainLoginDiv.setAttribute("id", "mainLoginDiv");
	mainLoginDiv.style.position = 'absolute';
	mainLoginDiv.style.left= 1;
	//mainLoginDiv.style.backgroundColor = '#FF8888';
	mainLoginDiv.style.top = 73;
	mainLoginDiv.style.width = ftLeftDivWidth - 5; // 200;
	mainLoginDiv.style.height = 80;
	mainLoginDiv.style.borderStyle = 'solid';
	mainLoginDiv.style.borderColor = '#000000';
	mainLoginDiv.style.borderWidth = '1px';
	mainLoginDiv.style.fontSize = '12px';
	leftSideDiv.appendChild(mainLoginDiv);
	//
	/*
	loginOtsikkoDiv = document.createElement("div");
	loginOtsikkoDiv.setAttribute("id", "loginOtsikkoDiv");
	loginOtsikkoDiv.style.position = 'absolute';
	loginOtsikkoDiv.style.left= 2;
	loginOtsikkoDiv.style.top = 2;
	loginOtsikkoDiv.style.width = ftLeftDivWidth - 10; // 200;
	loginOtsikkoDiv.style.height = 18;
	loginOtsikkoDiv.innerHTML = 'Kirjaudu sisään';
	mainLoginDiv.appendChild(loginOtsikkoDiv);
	*/
	//
	ssTunnusInput = document.createElement("input");
	ssTunnusInput.setAttribute("id", "tunnus");
	ssTunnusInput.style.position = 'absolute';
	ssTunnusInput.style.left= 65;
	ssTunnusInput.style.padding= 0;
	//ssTunnusInput.style.backgroundColor = '#FFFFFF';
	ssTunnusInput.style.top = 2;
	ssTunnusInput.style.width = 75; // 200;
	ssTunnusInput.style.height = 20;
	ssTunnusInput.style.fontSize = '12px';
	if (ftLanguage == 'finnish' ) {
		ssTunnusInput.value = 'vieras';
	}
	else {
		ssTunnusInput.value = 'guest';
	}
	mainLoginDiv.appendChild(ssTunnusInput);
	//
	tunnusLabelDiv = document.createElement("div");
	tunnusLabelDiv.setAttribute("id", "tunnusLabel");
	tunnusLabelDiv.style.position = 'absolute';
	tunnusLabelDiv.style.left= 6;
	//tunnusLabelDiv.style.backgroundColor = '#FFFFFF';
	tunnusLabelDiv.style.top = 2;
	tunnusLabelDiv.style.width = 50; // 200;
	tunnusLabelDiv.style.height = 18;
	if (ftLanguage == 'finnish' ) {
		tunnusLabelDiv.innerHTML = 'tunnus';
	}
	else {
		tunnusLabelDiv.innerHTML = 'username';
	}
	mainLoginDiv.appendChild(tunnusLabelDiv);
	//
	ssanaInput = document.createElement("input");
	ssanaInput.setAttribute("id", "ssana");
	ssanaInput.setAttribute("type", "password");
	//ssanaInput.style.type="password";
	ssanaInput.style.position = 'absolute';
	ssanaInput.style.left= 65;
	ssanaInput.style.padding= 0;
	//ssanaInput.style.backgroundColor = '#FFFFFF';
	ssanaInput.style.top = 22;
	ssanaInput.style.width = 75; // 200;
	ssanaInput.style.fontSize = '12px';
	ssanaInput.style.height = 20;
	if (ftLanguage == 'finnish' ) {
		ssanaInput.value = 'vieras';
	}
	else {
		ssanaInput.value = 'guest';
	}
	mainLoginDiv.appendChild(ssanaInput);
	//
	ssanaLabelDiv = document.createElement("div");
	ssanaLabelDiv.setAttribute("id", "ssanaLabel");
	ssanaLabelDiv.style.position = 'absolute';
	ssanaLabelDiv.style.left= 6;
	//ssanaLabelDiv.style.backgroundColor = '#FFFFFF';
	ssanaLabelDiv.style.top = 23;
	ssanaLabelDiv.style.width = 50; // 200;
	ssanaLabelDiv.style.height = 18;
	if (ftLanguage == 'finnish' ) {
		ssanaLabelDiv.innerHTML = 'salasana';
	}
	else {
		ssanaLabelDiv.innerHTML = 'password';
	}
	mainLoginDiv.appendChild(ssanaLabelDiv);
	//
	loginButton = document.createElement("button");
	loginButton.setAttribute("id", "login");
	//loginButton.setAttribute("type", "password");
	//loginButton.style.type="password";
	loginButton.style.position = 'absolute';
	loginButton.style.left = 145;
	loginButton.style.padding = 0;
	//loginButton.style.backgroundColor = '#FFFFFF';
	loginButton.style.top = 22;
	//loginButton.style.width = '32px'; // 200;
	//loginButton.style.height = '18px';
	loginButton.style.fontSize = '12px';
	loginButton.innerHTML = 'Ok';
	loginButton.onclick = function(){doLogIn('startUp')};
	mainLoginDiv.appendChild(loginButton);
	//
	registerDiv = document.createElement("div");
	registerDiv.setAttribute("id", "rekisteroidu");
	registerDiv.style.position = 'absolute';
	registerDiv.style.left= 6;
	//registerDiv.style.backgroundColor = '#FFFFFF';
	registerDiv.style.top = 44;
	registerDiv.style.width = 85; // 200;
	registerDiv.style.height = 18;
	if (ftLanguage == 'finnish' ) {
		registerDiv.innerHTML = '<a href="' + ftphpBBAddress + 'profile.php?mode=register&agreed=true" target="_blank">Rekisteröidy</a>';
	}
	else {
		registerDiv.innerHTML = '<a href="' + ftphpBBAddress + 'profile.php?mode=register&agreed=true" target="_blank">Register</a>';
	}
	mainLoginDiv.appendChild(registerDiv);
	//
	whyRegisterDiv = document.createElement("div");
	whyRegisterDiv.setAttribute("id", "whyRegister");
	whyRegisterDiv.style.position = 'absolute';
	whyRegisterDiv.style.left= 6;
	//whyRegisterDiv.style.backgroundColor = '#FFFFFF';
	whyRegisterDiv.style.top = 64;
	whyRegisterDiv.style.width = 160; // 200;
	whyRegisterDiv.style.height = 18;
	whyRegisterDiv.onclick = function(){doWhyRegister()};
	if (ftLanguage == 'finnish' ) {
		whyRegisterDiv.innerHTML = 'Miksi rekisteröityä?';
	}
	else {
		whyRegisterDiv.innerHTML = 'Why to register?';
	}
	whyRegisterDiv.style.cursor = 'pointer';
	mainLoginDiv.appendChild(whyRegisterDiv);
	//
	var ssana = getCookie('kmaarSsana');
	if(ssana == null)ssana='vieras';
	var tunnus = getCookie('kmaarTunnus');
	if(tunnus == null)tunnus='vieras';
	//alert(ssana);
	document.getElementById('ssana').value = ssana;
	document.getElementById('tunnus').value = tunnus;
} //function doSetLoginDiv
//
function doLogIn (vaihe) {
	var ftUsername = document.getElementById('tunnus').value;
	var ssana = document.getElementById('ssana').value;
	if( (ssana == 'vieras' && ftUsername == 'vieras') || (ssana == 'guest' && ftUsername == 'guest')) {
		setLogoutDiv(ftUsername);
	}
	else {
		phpbbLogIn (ftUsername, vaihe);
	}
} //
//
function setLogoutDiv(username) {
	var newLoginScreenDiv = document.getElementById('newLoginScreenDiv');
	if(newLoginScreenDiv != null) {
		document.body.removeChild(newLoginScreenDiv);
	}
	ftLoggedIn = true;
	ftUsername = username;
	// poistetaan LoginDiv
	var sivuDiv = document.getElementById('leftSideDiv');
	var loginDiv = document.getElementById('mainLoginDiv');
	//alert(loginDiv);
	sivuDiv.removeChild(loginDiv);
	// luodaan LogoutDiv
	var logoutDiv = document.createElement("div");
	logoutDiv.setAttribute("id", "logoutDiv");
	logoutDiv.style.position = 'absolute';
	logoutDiv.style.top = '73px';
	logoutDiv.style.left = '1px';
	logoutDiv.style.height = '80px';
	logoutDiv.style.width = ftLeftDivWidth - 5;
	logoutDiv.style.backgroundColor = '#FFFFFF'; 
	logoutDiv.style.textAlign = 'left';
	logoutDiv.style.fontSize = '12px';
	logoutDiv.style.fontFamily = 'arial, helvetica, sans-serif';
	logoutDiv.style.border = '1px solid black';
	sivuDiv.appendChild(logoutDiv);
	//
	var tunnusDiv = document.createElement("div");
	tunnusDiv.setAttribute("id", "tunnusText");
	tunnusDiv.style.position = 'absolute';
	tunnusDiv.style.top = '2px';
	tunnusDiv.style.left = '3px';
	tunnusDiv.style.height = '20px';
	tunnusDiv.style.width = ftLeftDivWidth - 6;
	if (ftLanguage == 'finnish' ) {
		tunnusDiv.innerHTML = '<b>' + ftUsername + '</b> on kirjautunut sisään.';
	}
	else {
		tunnusDiv.innerHTML = '<b>' + ftUsername + '</b> is logged in.';
	}
	logoutDiv.appendChild(tunnusDiv);
	//
	var outDiv = document.createElement("div");
	outDiv.setAttribute("id", "outDiv");
	outDiv.style.position = 'absolute';
	outDiv.style.top = '35px';
	outDiv.style.left = '3px';
	outDiv.style.height = '20px';
	outDiv.style.width = ftLeftDivWidth - 6;
	if (ftLanguage == 'finnish' ) {
		outDiv.innerHTML = 'Kirjaudu ulos';
	}
	else {
		outDiv.innerHTML = 'Logout';
	}
	outDiv.style.cursor = 'pointer';
	outDiv.onclick=function(){doLogOut()};
	logoutDiv.appendChild(outDiv);
} //function setLogoutDiv

//
function doLogOut () {
	// poistetaan LogoutDiv
	ftLoggedIn = false;
	ftUsername = '';
	var sivuDiv = document.getElementById('leftSideDiv');
	var logoutDiv = document.getElementById('logoutDiv');
	//alert(loginDiv);
	sivuDiv.removeChild(logoutDiv);
	doSetLoginDiv();
} //doLogOut
//
function doWhyRegister() {
	var srWinWidth = 460;
	var registerInfoDiv = document.createElement("div");
	registerInfoDiv.style.position = 'absolute';
	registerInfoDiv.setAttribute("id", "registerInfoDiv");
	registerInfoDiv.style.left= ftLeftDivWidth + 5;
	registerInfoDiv.style.top = 100;
	registerInfoDiv.style.width = srWinWidth; // 200;
	registerInfoDiv.style.height = 460;
	registerInfoDiv.style.backgroundColor = '#FFFFFF';
	registerInfoDiv.style.borderStyle = 'solid';
	registerInfoDiv.style.borderColor = '#000000';
	registerInfoDiv.style.borderWidth = '1px';
	registerInfoDiv.style.zIndex = 1500;
	document.body.appendChild(registerInfoDiv);
	//
	// ------- Close-ruksi -------------------
	//
	var newSearchCloseRuksiDiv = document.createElement("div");
	newSearchCloseRuksiDiv.setAttribute("id", "newSearchCloseRuksiDiv");
	newSearchCloseRuksiDiv.style.left= srWinWidth - 20;
	newSearchCloseRuksiDiv.onclick = new Function("doCloseSearchResultDiv('registerInfoDiv');");
	newSearchCloseRuksiDiv.style.cursor = 'pointer';
	registerInfoDiv.appendChild(newSearchCloseRuksiDiv);
	//
	// ------- Otsikot jne -------------------
	//
	var newSearchTitleDiv = document.createElement("div");
	newSearchTitleDiv.setAttribute("id", "newSearchTitleDiv");
	newSearchTitleDiv.style.width = srWinWidth - 60; // 200;
	if(ftLanguage == 'finnish')
		newSearchTitleDiv.innerHTML = '<h2>Miksi rekisteröityä?</h2>';
	else
		newSearchTitleDiv.innerHTML = '<h2>Why to register?</h2>';
	registerInfoDiv.appendChild(newSearchTitleDiv);
	//
	var textDiv = document.createElement("div");
	textDiv.setAttribute("id", "registertextDiv");
	textDiv.style.position = 'absolute';
	textDiv.style.left= 15;
	textDiv.style.top = 35;
	textDiv.style.width = srWinWidth - 30;
	textDiv.style.height = 380;
	textDiv.style.backgroundColor = '#FFFFFF';
	var ot1_fin  = '<h3>Rekisteröity käyttäjä?</h3>';
	var kpl1_fin = '<ul><li>voi lisätä omia karttalinkkejä, joita eivät voi poistaa muut kuin admin</li><li>voi muokata yleisiä karttalinkkejä</li><li>voi ottaa osa keskusteluun foorumin palstoilla</li></ul>';
	var kpl2_fin = 'Rekisteröityneen käyttäjän oikeudet voivat muuttua tulevaisuudessa palvelua kehitettäessä.<br>Sivuston admin voi poistaa epäasiallisen käyttäjän oikeudet.<br>';
	//
	var ot1_eng = '<h3>Registered user</h3>';
	var kpl1_eng = '<ul><li>can add own map links that can be deleted only by admin</li><li>can edit public map links.</li><li>can take part in the conversation in web site forum</li></ul>';
	var kpl2_eng = 'Rights of register used can be changed in the future when 3d map service is developed<br>Web site administration can remove right of an improper user<br>';
	// ---------------------
	var ot2_fin = '<h3>Kuinka rekisteröidyn?</h3>';
	var kpl3_fin = '<ul><li>mene rekisteröinti sivulle "Rekisteröidy"-linkistä</li><li>rekisteröidy lomakkeella</li><li>sama tunnus ja salasana toimivat sekä karttasivulla, että foorumissa, mutta kumpaankin pitää kirjautua erikseen.</li></ul>';
	var kpl4_fin = '<h3>Rekisteröimätön käyttäjä voi</h3><ul><li>tutkia karttaa ja sen linkkejä vapaasti</li><li>tehdä karttalinkkihakuja</li><li>voi kirjautua sisään vieraana.</li><li>tunnus: "vieras" salasana: "vieras". "Vieraana" tehtyjä linkkejä voi poistaa ja editoida kuka tahansa</li></ul>';
	//
	var ot2_eng = '<h3>How to register?</h3>';
	var kpl3_eng = '<ul><li>go to registeration page using "Register"link</li><li>register using t´he form</li><li>same user id and password work both on 3d map page and forum page. You must sign in seperately to both of them</li></ul>';
	var kpl4_eng = '<h3>Unregistered user can</h3><ul><li>browse 3d map and its links freely</li><li>can search map link data base</li><li>can sign in as a guest</li><li>user id: "guest" password: "guest". Anybaody can remove and edit map links made by guest</li></ul>';

	if(ftLanguage == 'finnish')
		textDiv.innerHTML = ot1_fin + kpl1_fin + kpl2_fin + ot2_fin + kpl3_fin + kpl4_fin;
	else
		textDiv.innerHTML = ot1_eng + kpl1_eng + kpl2_eng + ot2_eng + kpl3_eng + kpl4_eng;
	registerInfoDiv.appendChild(textDiv);

	var closeDiv = document.createElement("div");
	closeDiv.setAttribute("id", "closeDiv");
	closeDiv.style.position = 'absolute';
	closeDiv.style.left= srWinWidth / 2 - 50;
	closeDiv.style.top = 430;
	closeDiv.style.width = 100; // 200;
	closeDiv.style.height = 20;
	//closeDiv.style.backgroundColor = '#EEAAAA';
	closeDiv.style.cursor = 'pointer';
	if(ftLanguage == 'finnish')
		closeDiv.innerHTML = 'Sulje ikkuna';
	else
		closeDiv.innerHTML = 'Close window';

	closeDiv.onclick = new Function("doCloseSearchResultDiv('registerInfoDiv');");
	registerInfoDiv.appendChild(closeDiv);

	
}
//
function openSearchResultDiv (searchString, alkuLuku, lkmLuku, hakuLkm, ftSearchResultPoiList) {
	var srWinWidth = 600;
	var newSearchResultDiv = document.createElement("div");
	newSearchResultDiv.setAttribute("id", "searchResultDiv");
	document.body.appendChild(newSearchResultDiv);
	newSearchResultDiv.style.left= ftLeftDivWidth + 5;
	newSearchResultDiv.style.top = 100;  //ftStatusDivHeight + ftUpperbannerHeight + 5; // vika 30
	newSearchResultDiv.style.width = srWinWidth; // 200;
	newSearchResultDiv.style.height = 530;
	//
	// ------- Close-ruksi -------------------
	//
	var newSearchCloseRuksiDiv = document.createElement("div");
	newSearchCloseRuksiDiv.setAttribute("id", "newSearchCloseRuksiDiv");
	newSearchCloseRuksiDiv.style.left= srWinWidth - 20;
	newSearchCloseRuksiDiv.onclick = new Function("doCloseSearchResultDiv('searchResultDiv');");
	newSearchResultDiv.appendChild(newSearchCloseRuksiDiv);
	//
	// ------- Otsikot jne -------------------
	//
	var newSearchTitleDiv = document.createElement("div");
	newSearchTitleDiv.setAttribute("id", "newSearchTitleDiv");
	newSearchTitleDiv.style.width = srWinWidth - 60; // 200;
	newSearchTitleDiv.style.fontSize = 15;
	newSearchTitleDiv.style.top = 10;
	newSearchTitleDiv.style.left = 10;
	newSearchTitleDiv.style.textAlign= 'center';
	//
	var jaksonAlku = parseInt(alkuLuku) + 1;
	var jaksonLoppu = parseInt(alkuLuku) + parseInt(lkmLuku);
	//newSearchTitleDiv.innerHTML = '<h2>Etsint&auml;tulokset</h2>';
	if(ftLanguage == 'finnish')
		var ots = '<b>Hakutulokset</b> Hakusana:' + searchString + ' Jakso:' + jaksonAlku + '-' + jaksonLoppu + '. Osumia yhteensä ' + hakuLkm + ' kpl.';
	else
		var ots = '<b>Search results</b> Search string:' + searchString + ' Results:' + jaksonAlku + '-' + jaksonLoppu + '. Total hits ' + hakuLkm + '.';
	newSearchTitleDiv.innerHTML = ots;
	newSearchResultDiv.appendChild(newSearchTitleDiv);
	//
	// ------- Div-taulukkoa varten -------------------
	//
	var newSearchTableDiv = document.createElement("div");
	newSearchTableDiv.setAttribute("id", "searchTableDiv");
	newSearchTableDiv.style.position = 'absolute';
	newSearchTableDiv.style.top = '35px';
	newSearchTableDiv.style.left = '10px';
	newSearchTableDiv.style.height = '460px';
	newSearchTableDiv.style.backgroundColor = '#FFFFFF';
	newSearchTableDiv.style.zIndex = 500;
	newSearchTableDiv.style.overflow = 'auto'; 
	newSearchTableDiv.style.width = srWinWidth - 16;
	newSearchResultDiv.appendChild(newSearchTableDiv);
	// ------- Taulukko -------------------
	var newSearchTable = document.createElement("table");
	newSearchTable.setAttribute("id", "newSearchTable");
	//newSearchTable.style.left = 15; // 200;
	newSearchTable.style.width = srWinWidth - 32; // 200;
	newSearchTableDiv.appendChild(newSearchTable);
	// ------- tablebody -------------------
	var searchTableBody = document.createElement("tbody");
	searchTableBody.setAttribute("id", "searchTableBody");
	//newSearchTable.style.width = srWinWidth - 32; // 200;
	newSearchTable.appendChild(searchTableBody);
	// ------- vaakarivit -------------------
	// MUOTO: poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo
	var poiLkm = ftSearchResultPoiList.length;
	for (i=0; i<poiLkm; i++) {
		//
		var newRow = document.createElement("tr");
		newRow.setAttribute("id", "newRow" + i);
		searchTableBody.appendChild(newRow);
		//
		var subLista = ftSearchResultPoiList[i];
		var poiId = subLista[0];
		var poiDbId = subLista[1];
		var poiCat = subLista[2];
		var xNew = subLista[3];
		var yNew = subLista[4];
		var poiHref = subLista[5];
		var poiTitle = subLista[6];
		var poiInfo = subLista[7];
		var newTD1 = document.createElement("td");
		//newTD1.setAttribute("id", "idNro");
		ft_classAttribute(newTD1, "idNro");
		newTD1.innerHTML = poiDbId;
		newRow.appendChild(newTD1);
		// --
		var newTD2 = document.createElement("td");
		//newTD2.setAttribute("id", "title");
		ft_classAttribute(newTD2, "title");
		newTD2.innerHTML = poiTitle;
		newRow.appendChild(newTD2);
		// -------
		var newTD3 = document.createElement("td");
		//newTD3.setAttribute("id", "newTD3");
		ft_classAttribute(newTD3, "poiInfo");
		newTD3.innerHTML = poiInfo;
		newRow.appendChild(newTD3);
		// -------
		var newTD4 = document.createElement("td");
		//newTD4.setAttribute("id", "newTD3");
		ft_classAttribute(newTD4, "showPoi");
		if(ftLanguage == 'finnish')
			newTD4.innerHTML = 'N&auml;yt&auml; kartalla';
		else
			newTD4.innerHTML = 'Show on map';
		//alert('poiCat ' + poiCat);
		//	poiLink.onmouseover = new Function("return overlib('" + olText + "',CAPTION, '" + olCa + "');");
		newTD4.onclick = new Function("doShowOnMap('" + poiDbId + "','" + poiCat + "','" + xNew + "','" + yNew + "');");
		newRow.appendChild(newTD4);
	} //for

	//
	// ------- next prev div -------------------
	//
	var nextPrevDiv = document.createElement("div");
	nextPrevDiv.setAttribute("id", "nextPrevDiv");
	nextPrevDiv.style.position = 'absolute';
	nextPrevDiv.style.left= 20;
	nextPrevDiv.style.top= 502;
	nextPrevDiv.style.width= 700;
	nextPrevDiv.style.height= 18;
	//nextPrevDiv.style.backgroundColor = '#FFCCCC';
	nextPrevDiv.style.textAlign= 'left';
	nextPrevDiv.style.fontSize = 11;
	//nextPrevDiv.innerHTML = 'Osumia ' + hakuLkm + ' kpl.';
	//newTD6.innerHTML = 'Muokkaa';
	newSearchResultDiv.appendChild(nextPrevDiv);
	// --------------   -----------------------

	//hakuLkm
	var lukum = 1 + parseInt(hakuLkm / lkmLuku);
	//alert('hakuLkm:' + hakuLkm + ' lkmLuku:' + lkmLuku +  ' = lukum on:' + lukum);
	var vasen = 3;
	//var newAlku = alkuLuku + lkmLuku;
	//alert('Alkuluku on ' + alkuLuku);
	var newAlku = 0;
	for (i=0; i<lukum; i++) {
		var subDiv = document.createElement("div");
		subDiv.style.position = 'absolute';
		subDiv.style.left= vasen;
		subDiv.style.top= 0;
		subDiv.style.width= 18;
		subDiv.style.height= 18;
		subDiv.style.backgroundColor = '#FFFFFF';
		subDiv.style.textAlign= 'center';
		subDiv.style.fontSize = 11;
		var newLoppu = newAlku + parseInt(lkmLuku);
		//subDiv.innerHTML = ' ' + (newAlku + 1) + '-' + newLoppu;
		if(alkuLuku == newAlku) {
			subDiv.style.color = '#FF0000';
			subDiv.innerHTML = '<b>' + (i + 1) + '</b>';
		}
		else {
			subDiv.innerHTML = ' ' + (i + 1);
			subDiv.style.cursor= 'pointer';
			subDiv.onclick = new Function("seachStringInDb('" + searchString + "','" + ftLanguage + "','" +  newAlku + "','" + lkmLuku +  "');");
		}
		nextPrevDiv.appendChild(subDiv);
		newAlku = parseInt(newAlku) + parseInt(lkmLuku);
		vasen = vasen + 23;
	}
} //function openSearchResultDiv
//
function updateSearchResultDiv (searchString, alkuLuku, lkmLuku, hakuLkm, ftSearchResultMaarList) {

	var newSearchResultDiv = document.getElementById('searchResultDiv');
	var newSearchTitleDiv = document.getElementById('newSearchTitleDiv');
	var jaksonAlku = parseInt(alkuLuku) + 1;
	var jaksonLoppu = parseInt(alkuLuku) + parseInt(lkmLuku);
	if(ftLanguage == 'finnish')
		var ots = '<b>Hakutulokset</b> Hakusana:' + searchString + ' Jakso:' + jaksonAlku + '-' + jaksonLoppu + '. Osumia yhteensä ' + hakuLkm + ' kpl.';
	else
		var ots = '<b>Search results</b> Search string:' + searchString + ' Results:' + jaksonAlku + '-' + jaksonLoppu + '. Total hits ' + hakuLkm + '.';
	newSearchTitleDiv.innerHTML = ots;
	// ------- tablebody -------------------
	var searchTableBody = document.getElementById('searchTableBody');
	// poistetaan kaikki lapset
	while (searchTableBody.firstChild) {
		searchTableBody.removeChild(searchTableBody.firstChild);
	};
	// ------- vaakarivit -------------------
	// MUOTO: poiId, poiDbId, poiCat, xNew, yNew, poiHref, poiTitle, poiInfo
	var poiLkm = ftSearchResultPoiList.length;
	for (i=0; i<poiLkm; i++) {
		//
		var newRow = document.createElement("tr");
		newRow.setAttribute("id", "newRow" + i);
		searchTableBody.appendChild(newRow);
		//
		var subLista = ftSearchResultPoiList[i];
		var poiId = subLista[0];
		var poiDbId = subLista[1];
		var poiCat = subLista[2];
		var xNew = subLista[3];
		var yNew = subLista[4];
		var poiHref = subLista[5];
		var poiTitle = subLista[6];
		var poiInfo = subLista[7];
		var newTD1 = document.createElement("td");
		//newTD1.setAttribute("id", "idNro");
		ft_classAttribute(newTD1, "idNro");
		newTD1.innerHTML = poiDbId;
		newRow.appendChild(newTD1);
		// --
		var newTD2 = document.createElement("td");
		//newTD2.setAttribute("id", "title");
		ft_classAttribute(newTD2, "title");
		newTD2.innerHTML = poiTitle;
		newRow.appendChild(newTD2);
		// -------
		var newTD3 = document.createElement("td");
		//newTD3.setAttribute("id", "newTD3");
		ft_classAttribute(newTD3, "poiInfo");
		newTD3.innerHTML = poiInfo;
		newRow.appendChild(newTD3);
		// -------
		var newTD4 = document.createElement("td");
		//newTD4.setAttribute("id", "newTD3");
		ft_classAttribute(newTD4, "showPoi");
		if(ftLanguage == 'finnish')
			newTD4.innerHTML = 'N&auml;yt&auml; kartalla';
		else
			newTD4.innerHTML = 'Show on map';
		//alert('poiCat ' + poiCat);
		//	poiLink.onmouseover = new Function("return overlib('" + olText + "',CAPTION, '" + olCa + "');");
		newTD4.onclick = new Function("doShowOnMap('" + poiDbId + "','" + poiCat + "','" + xNew + "','" + yNew + "');");
		newRow.appendChild(newTD4);
	} //for
	//
	// ------- next prev div -------------------
	//
	var nextPrevDiv = document.getElementById('nextPrevDiv');
	// poistetaan kaikki lapset
	while (nextPrevDiv.firstChild) {
		nextPrevDiv.removeChild(nextPrevDiv.firstChild);
	};
	/*
	nextPrevDiv.setAttribute("id", "nextPrevDiv");
	nextPrevDiv.style.position = 'absolute';
	nextPrevDiv.style.left= 20;
	nextPrevDiv.style.top= 502;
	nextPrevDiv.style.width= 700;
	nextPrevDiv.style.height= 18;
	nextPrevDiv.style.textAlign= 'left';
	nextPrevDiv.style.fontSize = 11;
	newSearchResultDiv.appendChild(nextPrevDiv);
	*/
	// --------------   -----------------------

	//hakuLkm
	var lukum = 1 + parseInt(hakuLkm / lkmLuku);
	//alert('hakuLkm:' + hakuLkm + ' lkmLuku:' + lkmLuku +  ' = lukum on:' + lukum);
	var vasen = 3;
	//var newAlku = alkuLuku + lkmLuku;
	//alert('Alkuluku on ' + alkuLuku);
	var newAlku = 0;
	for (i=0; i<lukum; i++) {
		var subDiv = document.createElement("div");
		subDiv.style.position = 'absolute';
		subDiv.style.left= vasen;
		subDiv.style.top= 0;
		subDiv.style.width= 18;
		subDiv.style.height= 18;
		subDiv.style.backgroundColor = '#FFFFFF';
		subDiv.style.textAlign= 'center';
		subDiv.style.fontSize = 11;
		var newLoppu = newAlku + parseInt(lkmLuku);
		//subDiv.innerHTML = ' ' + (newAlku + 1) + '-' + newLoppu;
		if(alkuLuku == newAlku) {
			subDiv.style.color = '#FF0000';
			subDiv.innerHTML = '<b>' + (i + 1) + '</b>';
		}
		else {
			subDiv.innerHTML = ' ' + (i + 1);
			subDiv.style.cursor= 'pointer';
			subDiv.onclick = new Function("seachStringInDb('" + searchString + "','" + ftLanguage + "','" + newAlku + "','" + lkmLuku +  "');");
		}
		nextPrevDiv.appendChild(subDiv);
		newAlku = newAlku + parseInt(lkmLuku);
		vasen = vasen + 23;
	}
} //updateSearchResultDiv


function doCloseSearchResultDiv (divId) {
	document.body.removeChild(document.getElementById(divId));
}

function doShowOnMap (dbId, poiCat, xNew, yNew) {
	document.body.removeChild(document.getElementById("searchResultDiv"));
	ftMapX = ftPoiDbScale * xNew;
	ftMapY = ftPoiDbScale * yNew;
	calcMapCanvas();
	updatePOIList();
	drawCP();
	if (ftMapScale != 500) {
		doZoom (500);
	}
	// siiretään hieman, että keskipiste näkyy ja POI-objektiti tulee näkyviin ja kohdalleen.
	panMap(-10,-10);
	if(ftSelectedCatList == 'none' || ftSelectedCatList == null ) {
		showPoiCat (poiCat);
		ftSelectedCatList = new Array();
		ftSelectedCatList[0] = poiCat;
		if(selLinksFlag == true) {
			document.getElementById(poiCat).checked = true;
		}
	}
	else if(arrayMember(ftSelectedCatList, poiCat) != true ) {
		showPoiCat (poiCat);
		var pit = ftSelectedCatList.length;
		ftSelectedCatList[pit] = poiCat;
		if(selLinksFlag == true) {
			document.getElementById(poiCat).checked = true;
		}
	}
}

function doOpenCatWindow (eFlag) {
	//alert("doOpenCatWindow alkaa");
	var leftSideDiv = document.getElementById('leftSideDiv');
	selLinksFlag = eFlag;
	//alert('ftSelectedCatList: ' + ftSelectedCatList);
	if(selLinksFlag == true) {
		//alert('doOpenCatWindow alkaa');
		catWindowFlag = true;
		newMainCatDiv = document.createElement("div");
		newMainCatDiv.setAttribute("id", "catMainDiv");
		newMainCatDiv.style.position = 'absolute';
		newMainCatDiv.style.left= 1;
		//newMainCatDiv.style.backgroundColor = '#FF8888';
		//newMainCatDiv.style.top = ftStatusDivHeight + ftUpperbannerHeight + 65; // vika 30
		newMainCatDiv.style.top = 	247;
		newMainCatDiv.style.width = ftLeftDivWidth - 5; // 200;
		newMainCatDiv.style.height = 235;
		newMainCatDiv.style.borderStyle = 'solid';
		newMainCatDiv.style.borderColor = '#000000';
		newMainCatDiv.style.borderWidth = '1px';
		//newMainCatDiv.style.overflow = 'auto';
		leftSideDiv.appendChild(newMainCatDiv);
		//document.body.appendChild(newMainCatDiv);
		// ------- Status Title -------------------
		newCatTitleDiv = document.createElement("div");
		newCatTitleDiv.setAttribute("id", "newCatTitleDiv");
		newCatTitleDiv.style.position = 'absolute';
		newCatTitleDiv.style.top = '1px';
		newCatTitleDiv.style.left = '3px';
		newCatTitleDiv.style.height = '40px';
		newCatTitleDiv.style.paddingLeft = '0px';
		newCatTitleDiv.style.paddingTop = '0px';
		//newCatTitleDiv.style.backgroundColor = '#FFFFFF';
		newCatTitleDiv.style.fontSize = '13px';
		newCatTitleDiv.style.fontFamily = 'arial, helvetica, sans-serif';
		newCatTitleDiv.style.fontWeight = 'bold';
		newCatTitleDiv.style.width = ftLeftDivWidth - 5; // 200;
		if(ftLanguage == 'finnish')
			newCatTitleDiv.innerHTML = 'Valitse linkkikategoriat';
		else
			newCatTitleDiv.innerHTML = 'Select Link Categories';
		newMainCatDiv.appendChild(newCatTitleDiv);
		// ----------------
		newCarScrollDiv = document.createElement("div");
		newCarScrollDiv.setAttribute("id", "newCarScrollDiv");
		newCarScrollDiv.style.position = 'absolute';
		newCarScrollDiv.style.left= 1;
		newCarScrollDiv.style.backgroundColor = '#FFFFFF';
		newCarScrollDiv.style.top = 23; // vika 30
		newCarScrollDiv.style.width = ftLeftDivWidth - 9; // 200;
		newCarScrollDiv.style.height = 210;
		newCarScrollDiv.style.overflow = 'auto';
		newMainCatDiv.appendChild(newCarScrollDiv);
		// -----------------
		newCatDiv = document.createElement("div");
		newCatDiv.setAttribute("id", "catDiv");
		newCatDiv.style.position = 'absolute';
		newCatDiv.style.left= 0;  //ftLeftDivWidth + 2;
		newCatDiv.style.top = 0;  //ftStatusDivHeight + ftUpperbannerHeight + 65; // vika 30
		newCatDiv.style.width = ftLeftDivWidth - 35; // 200;
		newCatDiv.style.height = 235;
		newCatDiv.style.paddingTop = '0px';
		newCatDiv.style.backgroundColor = '#FFFFFF';
		newCatDiv.style.fontSize = '10px';
		newCatDiv.style.fontFamily = 'arial, helvetica, sans-serif';
		newCatDiv.style.zIndex = 600;
		newCarScrollDiv.appendChild(newCatDiv);
		//alert('2');
		//
		// ------- POI-categoria-luettelo -------------------
		//
		// simuloidaan hash-tablea ("catnimi" false/true)
		//ftCatList // muotoa ('hotelli' . false)(elokuva . true)
		//alert(ftCatList);
		var catLkm = ftCatList.length;
		var topY = 5;  // 40
		for (i=0; i<catLkm; i++) {
			var catPari = ftCatList[i];
			//alert(catPari);
			var catName  = catPari[0];
			var catValue = catPari[1];
			var optionToggleElement = document.createElement("input");
			optionToggleElement.setAttribute("id", catName);
			optionToggleElement.setAttribute("type", "checkbox");
			optionToggleElement.setAttribute("name", catName);
			optionToggleElement.style.position = 'absolute';
			optionToggleElement.style.top  = topY;
			optionToggleElement.style.left  = 105;
			if(ftLanguage == 'finnish')
				optionToggleElement.setAttribute("value", catName);
			else
				optionToggleElement.setAttribute("value", catName);
			//var tx = 'Cat_' + catName;
			//optionToggleElement.onclick = new Function("toggleCatElement(" + tx + ");");
			optionToggleElement.onclick = new Function("toggleCatElement(" + i + ");");
			newCatDiv.appendChild(optionToggleElement);
			// --- label ---
			var toggleElementLabel = document.createElement("label");
			toggleElementLabel.setAttribute("id", 'Label-' + catName);
			toggleElementLabel.setAttribute("for", "optionToggleElement");
			if(ftLanguage == 'finnish') {
				toggleElementLabel.innerHTML = catName;
			}
			else {
				var jas = arrayMones (ftCatNameList, catName);
				var catNameEng = ftCatNameList_eng[jas - 1];
				toggleElementLabel.innerHTML = catNameEng;
			}
			toggleElementLabel.style.position = 'absolute';
			toggleElementLabel.style.top  = topY;
			toggleElementLabel.style.left  = 20;
			toggleElementLabel.style.fontSize  = "12px"; // Toimii nyt
			newCatDiv.appendChild(toggleElementLabel);
			//
			// --- poi lukumäärä-teksti
			var optionToggleLkm = document.createElement("div");
			optionToggleLkm.setAttribute("id", catName + 'Lkm');
			optionToggleLkm.style.position = 'absolute';
			optionToggleLkm.style.top  = topY;
			optionToggleLkm.style.left  = 127;
			optionToggleLkm.style.fontSize  = "12px";
			optionToggleLkm.innerHTML = '0';
			newCatDiv.appendChild(optionToggleLkm);
			//
			// --- poi lukumäärä-teksti
/*			var carIconDiv = document.createElement("div");
			carIconDiv.setAttribute("id", catName + 'Icon');
			carIconDiv.style.position = 'absolute';
			carIconDiv.style.top  = topY + 3;
			carIconDiv.style.left  = 5;
			carIconDiv.style.width  = 10;
			carIconDiv.style.height  = 10;
			var iconName = getPoiIcon (catName);
			var iconUrl = 'url(images/' + iconName + '_10.gif)';
			carIconDiv.style.backgroundImage  = iconUrl;
			newCatDiv.appendChild(carIconDiv);
*/
			var iconName = getPoiIcon (catName);
			var iconUrl = 'images/' + iconName + '_10.gif';
			//var iconUrl = iconName + '_10.gif)';
			//alert(iconUrl);
			var carImage = document.createElement("img");
			carImage.setAttribute("src", iconUrl);
			carImage.setAttribute("id", catName + 'Icon');
			carImage.style.position = 'absolute';
			carImage.style.top  = topY + 3;
			carImage.style.left  = 5;
			carImage.style.width  = 10;  //
			carImage.style.height = 10;  //
			newCatDiv.appendChild(carImage);
			topY = topY + 15;
		}
		//
		var TotalLkmLabel = document.createElement("div");
		TotalLkmLabel.setAttribute("id", 'totalLkmLabel');
		TotalLkmLabel.style.position = 'absolute';
		TotalLkmLabel.style.top  = topY + 5;
		TotalLkmLabel.style.left  = 20;
		TotalLkmLabel.style.fontSize  = "12px";
		if(ftLanguage == 'finnish') {
			TotalLkmLabel.innerHTML = 'Valittu';
		}
		else {
			TotalLkmLabel.innerHTML = 'Selected';
		}
		newCatDiv.appendChild(TotalLkmLabel);
		//
		var optionTotalLkm = document.createElement("div");
		optionTotalLkm.setAttribute("id", 'totalLkm');
		optionTotalLkm.style.position = 'absolute';
		optionTotalLkm.style.top  = topY + 5;
		optionTotalLkm.style.left  = 78;
		optionTotalLkm.style.fontSize  = "12px";
		optionTotalLkm.innerHTML = '0';
		newCatDiv.appendChild(optionTotalLkm);
		//
		// onko muistissa ftSelectedCatList
		//alert('ftSelectedCatList: ' + ftSelectedCatList);
		var totalLask = 0;
		if ( ftSelectedCatList != null) {
			var pit = ftSelectedCatList.length;
			for (i=0; i<pit; i++) {
				var catName = ftSelectedCatList[i];
				//alert('catName: ' + catName);
				var catElem = document.getElementById(catName);
				catElem.checked = true;
				// Vielä pitäisi laskea montako kappaletta tätä categoriaa on ftPoiList-listassa
				if (ftPoiList != null) {
					var pit2 = ftPoiList.length;
				}
				else {
					var pit2 = 0;
				}
				var lask2 = 0;
				for (i2=0; i2<pit2; i2++) {
					var poiList = ftPoiList[i2];
					poiCat = poiList[2];
					if(poiCat == catName) {
						lask2++
						totalLask++
					}
				}
				document.getElementById(catName + 'Lkm').innerHTML = lask2;
			}
		}
		else {
			document.getElementById(catName + 'Lkm').innerHTML = '0';
		}
		if(ftPoiList == null) {
			document.getElementById('totalLkm').innerHTML = '0';
		}
		else {
			document.getElementById('totalLkm').innerHTML = '' + ftPoiList.length;
		}
		//
		/*
		var edElement =document.getElementById("OpenCatWindow");
		edElement.onclick = new Function("doOpenCatWindow(false);");
		edElement.style.backgroundImage  = 'url(images/widearrowup.jpg)';
		if(ftLanguage == 'finnish') {
			edElement.innerHTML = '&nbsp;Sulje Linkkimenu';
		}
		else {
			edElement.innerHTML = '&nbsp;Close map Link menu';
		}
		*/
	}
	else {
		doCloseCatDiv();
	}

} //function doOpenCatWindow


function toggleCatElement (catNum) {
	var catPari = ftCatList[catNum];
	var catName = catPari[0];
	var catElem = document.getElementById(catName);
	var val = catElem.checked;
	//alert(catName + ' = ' + val);
	if (val == true) {
		//document.getElementById(catName + 'Lkm').innerHTML = 'Haetaan...';
		showPoiCat (catName);
		// lisätään listaan
		if (ftSelectedCatList == null) {
			ftSelectedCatList = new Array();
			ftSelectedCatList[0] = catName;
		}
		else {
			var pit = ftSelectedCatList.length;
			ftSelectedCatList[pit] = catName;
		}
	}
	else {
		notShowPoiCat (catName);
		// poistetaan listasta
		mones = arrayMones(ftSelectedCatList, catName)
		ftSelectedCatList.splice(mones - 1, 1);
	}
	if(ftSelectedCatList.length == 0){
		ftSelectedCatList = null;
	}
	//alert(ftSelectedCatList);
} //function toggleCatElement


function notShowPoiCat (catName) {
	//document.getElementById(catName + 'Lkm').innerHTML = '0';
	var tempFtPoiList = ftPoiList;
	ftPoiList = new Array();
	var ftpLen = tempFtPoiList.length;
	// MUOTO: poiId, poiDbId, ftCategory, xNew, yNew, poiHref, poiTitle, poiInfo
	// rakennetaan uusi ftPoiList, niistä, jotka eivät ole == catName
	var poiLask = 0;
	for (i=0; i<ftpLen; i++) {
		var subList = tempFtPoiList[i];
		poiCat = subList[2];
		poiId = subList[0];
		if ( poiCat != catName) {
			ftPoiList[poiLask] = subList;
			poiLask++;
		}
		else {
			//ftMapDivElement.removeChild(document.getElementById(poiId));
			ftPoiMoveDiv.removeChild(document.getElementById(poiId));
		}
	}
	tempFtPoiList = null;
	document.getElementById('totalLkm').innerHTML = '' + ftPoiList.length;
} //function notShowPoiCat


function doCloseCatDiv () {
	//
	catWindowFlag = false;
	var edElement = document.getElementById("OpenCatWindow");
	edElement.onclick = new Function("doOpenCatWindow(true);");
	edElement.style.backgroundImage  = 'url(images/widearrowdown.jpg)';
	if(ftLanguage == 'finnish') {
		edElement.innerHTML = '&nbsp;Avaa Linkkimenu';
	}
	else {
		edElement.innerHTML = '&nbsp;Open map Link menu';
	}
	document.body.removeChild(document.getElementById("catDiv"));
}


function copyLinkToClipBoard () {
	var cpteksti = newEmailInput.createTextRange();
	cpteksti.execCommand("Copy");
	if(ftLanguage == 'finnish')
		alert('Linkki kopioitu leikepöydällesi \nKäytä Ctrl-v komentoa siirtääksesi ohjelmaasi.');
	else
		alert('Link was copied to your ClipBoard. \nUse Ctrl-v command to paste it to your program.');
}

// ----- send by email ------------------------------------------------------------------


function sendEmailF() {
	if (document.getElementById("newEmailDiv") != null)
		document.body.removeChild(document.getElementById("newEmailDiv"));
	newEmailDiv = document.createElement("div");
	newEmailDiv.setAttribute("id", "newEmailDiv");
	document.body.appendChild(newEmailDiv);
	newEmailDiv.style.left= 10;
	newEmailDiv.style.top = 185;
	// ----- Input-ikkuna ----
	newEmailInput = document.createElement("input");
	newEmailInput.setAttribute("id", "newEmailInput");
	newEmailDiv.appendChild(newEmailInput);
	// ---- emailTextDiv-----
	emailTextDiv = document.createElement("div");
	emailTextDiv.setAttribute("id", "emailTextDiv");
	newEmailDiv.appendChild(emailTextDiv);

	// VAIN IE
	if(selain == 'ie'){
		// ----- ClipBoardButton ----
		copyClipBoardButton = document.createElement("input");
		copyClipBoardButton.setAttribute("id", "copyClipBoardButton");
		copyClipBoardButton.setAttribute("type", "button");
		if(ftLanguage == 'finnish')
			copyClipBoardButton.setAttribute("value", 'Kopioi linkki leikepöydälle');
		else
			copyClipBoardButton.setAttribute("value", 'Copy Link to ClipBoard');

		copyClipBoardButton.onclick = new Function("copyLinkToClipBoard();");
		newEmailDiv.appendChild(copyClipBoardButton);
	}

	//  ---- mailtoDiv Linkki ----------
	mailtoDiv = document.createElement("div");
	mailtoDiv.setAttribute("id", "mailtoDiv");
	newEmailDiv.appendChild(mailtoDiv);
	// PHP-parametrit

	//alert(ftSelectedCatList);
	var catListString = null;
	if (ftSelectedCatList == null) {
		catListString = 'none';
	}
	else if (ftSelectedCatList.length == 0) {
		catListString = 'none';
	}
	else if (ftSelectedCatList.length == 1) {
		catListString = ftSelectedCatList[0];
		//catListString = '\'' + catListString + '\'';
	}
	else {
		//catListString = '';
		catListString = ftSelectedCatList[0];
		//catListString = '\'' + catListString + '\'';
		for (i=1; i<ftSelectedCatList.length; i++) {
			var catstr = ftSelectedCatList[i];
			//catstr = '\'' + catstr + '\'';
			catListString = catListString + ',' + catstr;
		}
	}
	var currentPar = '?X=' + ftMapX + '&Y=' + ftMapY + '&Sc=' + ftMapScale;
	currentPar = currentPar + '&lg=' + ftLanguage + '&ca=' + catListString;
	if(ftLanguage == 'finnish'){
		var str1 = '<h2>L&auml;het&auml; kartta-asetukset s&auml;hk&ouml;postina</h2><br>';
		str1 = str1 + '<p>Kopioi karttalinkki parametreineen alla olevasta ikkunasta s&auml;hk&ouml;postiohjelmaasi ' +
		'tai avaa oletus s&auml;hk&ouml;postiohjelmasi alla olevasta linkist&auml;.'
		str2 = siteaddr + currentPar;
	}
	else {
		var str1 = '<h2>Send map location and settings in email</h2><br>';
		str1 = str1 + '<p>Copy link with its parameters from the lower form window into your email ' +
		'or open your defaulr email program from the link at the bottom of the window.'
		str2 = siteaddr + currentPar;
	}
	emailTextDiv.innerHTML = str1;
	newEmailInput.value = str2;
	var vastaanottaja = '';
	if(ftLanguage == 'finnish'){
		var otsikko = 'subject=' + escape('Virtuaali-Helsingin 3D-kartta');
		var sisalto1 = 'body=' + escape('\n\nKatso Virtuaali-Helsingin kohdetta: \n');
		var sisalto2 = escape(str2 + '\n\n');
	}
	else {
		var otsikko = 'subject=' + escape('Virtual Helsinki 3D map');
		var sisalto1 = 'body=' + escape('\n\nGo to check Virtual Helsinki 3Dmap location:\n');
		var sisalto2 = escape(str2 + '\n\n');
	}
	mailtoLink = document.createElement("a");
	mailtoLink.setAttribute("id", "mailtoLink");
	mailtoDiv.appendChild(mailtoLink);
	mailtoLink.href = 'mailto:' + vastaanottaja + '?' + otsikko + '&' + sisalto1 + sisalto2;
	if(ftLanguage == 'finnish'){
		mailtoLink.innerHTML = "Avaa karttalinkki s&auml;hk&ouml;postiohjelmassasi";
		mailtoLink.alt = 'Avaa s&auml;hk&ouml;postiohjelmasi'
		mailtoLink.title = 'Avaa s&auml;hk&ouml;postiohjelmasi'
	}
	else {
		mailtoLink.innerHTML = "Open map link in your email program";
		mailtoLink.alt = 'Open your email program'
		mailtoLink.title = 'Open your email program'
	}
	//
	// ------- Close-ruksi -------------------
	emailCloseRuksiDiv = document.createElement("div");
	emailCloseRuksiDiv.setAttribute("id", "emailCloseRuksiDiv");
	emailCloseRuksiDiv.style.backgroundColor  = "#888888";
	var imUrl = 'url("images/close.gif")';
	emailCloseRuksiDiv.style.backgroundImage  = imUrl;
	emailCloseRuksiDiv.style.backgroundPosition = '0px 0px';
	emailCloseRuksiDiv.style.backgroundRepeat = 'no-repeat';
	emailCloseRuksiDiv.onclick = new Function("doCloseEmail();");
	newEmailDiv.appendChild(emailCloseRuksiDiv);
} //function sendEmailF() {

function doCloseEmail () {
	document.body.removeChild(document.getElementById("newEmailDiv"));
}

// ---
function openFtWindow(osoite){
	if(ftLanguage == 'finnish')
		var osoite2 = osoite + '_fin.html';
	else
		var osoite2 = osoite + '_eng.html';
	var maxX=screen.width;
	var maxY=screen.height;
	var w=700;
	var h=500;
	var windowprops = 'width='+ w +',height='+h+',location=no,scrollbars=yes,'+
	'toolbar=no,resizable=yes,status=no,screenX=' + (maxX-w)/2+',screenY=' + (maxY-h)/2 + ','+
	'left=' + (maxX-w)/2 + ',top=' + (maxY-h)/2;
	//alert(windowprops);
	imageWindow=window.open(osoite2, '', windowprops);
}


// -----------------------------------------------------------------------
// Tämä on menubaria varten ja vain ie:lle luulisin
function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}




