// check if element in array
function in_array(array, element)
{
	for (i=0; i < array.length; i++)
	{
		if (array[i] == element)
			return true;
	}
	return false;
}



// encode html-entities
function htmlentities(str,typ) {
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
 	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) str=str.replace(String.fromCharCode(i), html[i]);
	var entity=new Array(
		"&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
		"&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
		"&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
		"&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
		"&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
		"&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
		"&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
		"&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
		"&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
		"&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
		"&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
		"&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
	);
	for(var i in entity) str=str.replace(String.fromCharCode(i*1+160), entity[i])
	return str;
}


// decode html-entities
function html_entities_decode(str,typ) {

	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
 	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) str=str.replace(html[i], String.fromCharCode(i));

	var entity=new Array(
		"&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
		"&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
		"&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
		"&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
		"&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
		"&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
		"&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
		"&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
		"&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
		"&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
		"&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
		"&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
		);
	for(var i in entity) str=str.replace(entity[i], String.fromCharCode(i*1+160));
	return str;
}

// object for position values of a tour (longitude, latitude, percentage in the tour)
function LonLatPos(lon, lat, pos)
{
	this.lon = lon;
	this.lat = lat;
	this.posvalue = pos;
}

// object for altitude values of a tour (altitude, percentage in the tour)
function AltPos(alt, pos)
{
	this.value = alt;
	this.posvalue = pos;
}

// object for GE-icons (name, longitude, latitude)
function GEIcon(id, name, lat, lon)
{
	this.id = id;
	this.name = name;
	this.lat = lat;
	this.lon = lon;
}

/* Rundet eine Zahl auf eine bestimmte Stellenzahl */
function roundNumber(Wert, Stellen)
{
	if (Wert == 0)
		return 0
	else
		with (Math) {
			// Bereinigung der Stellenzahl
			Stellen = floor(abs(Stellen))
			if (Stellen == 0) { Stellen = 1 }
	
			var Exponent = round(log(abs(Wert)) * LOG10E)
			if (abs(Wert) < pow(10, Exponent)) { Exponent-- }
			var Potenz = pow(10, 1 + Exponent - Stellen)
			return ((Wert < 0) ? "-" : "") + round(abs(Wert) / Potenz) * Potenz
		}
}