<!-- author, publisher, copyright ARiS websitewerk - www.websitewerk.nl-->
function checkchar(mychar) {
if ((mychar=="N") || (mychar=="E") || (mychar=="n") || (mychar=="e") || (mychar=="O") || (mychar=="o")) return "signpositive";
if ((mychar=="S") || (mychar=="W") || (mychar=="s") || (mychar=="w") || (mychar=="Z") || (mychar=="z") || (mychar=="-") || (mychar=="_")) return "signnegative";
if ((mychar=="0") || (mychar=="1") || (mychar=="2") || (mychar=="3") || (mychar=="4") || (mychar=="5")) return "value";
if ((mychar=="6") || (mychar=="7") || (mychar=="8") || (mychar=="9")) return "value";
if (mychar==" ") return "space";
if (mychar==".") return "point";
if (mychar==",") return "comma";

}
function latlongdd(latitudelongitude) {
latfirst = 0;
latlast = 0;
longfirst = 0;
longlast = 0;
state = "start";
latfactor = 1.0;
longfactor = 1.0; index=0;
while ((index < latitudelongitude.length) && (index < 51) && (state!="longready"))
{
	result = checkchar (latitudelongitude.substr(index, 1));
	if (state=="start"){
		if (result=="signnegative") {latfactor=-1.0;}
		if (result=="value") {state="latfound"; latfirst = index;}
	} else if (state=="latfound") {
		if ((result!="value")&&(result!="point"))  {state="latready"; latlast = index-1;}
	} else if (state=="latready") {
		if (result=="signnegative") {longfactor=-1.0;}
		if (result=="value") {state="longfound"; longfirst = index;}
	} 
	if (state=="longfound") {// one digit at the end is possible
		if ((result!="value")&&(result!="point")) {
			state="longready"; longlast = index-1;
		} else if (index == latitudelongitude.length-1) {
			state="longready"; longlast = index;
		}		
	}
	index++;
}
if (state=="longready"){
	latitude = parseFloat (latitudelongitude.substr(latfirst, latlast - latfirst + 1));
	latitude = latitude * latfactor;
	longitude = parseFloat (latitudelongitude.substr(longfirst, longlast - longfirst + 1));
	longitude = longitude * longfactor;
} else {
	document.getElementById('latlong').value = "unknown format";
}
}
function latlongddmm(latitudelongitude) {
lat1first = 0; lat1last = 0;
lat2first = 0; lat2last = 0;
long1first = 0; long1last = 0;
long2first = 0; long2last = 0;
state = "start";
latfactor = 1.0;
longfactor = 1.0; index=0;
while ((index < latitudelongitude.length) && (index < 51) && (state!="longready"))
{
	result = checkchar (latitudelongitude.substr(index, 1));
	if (state=="start"){
		if (result=="signnegative") {latfactor=-1.0;}
		if (result=="value") {state="lat1found"; lat1first = index;}
	} else if (state=="lat1found") {
		if (result!="value")  {state="lat1ready"; lat1last = index-1;}
	} else if (state=="lat1ready") {
		if (result=="value")  {state="lat2found"; lat2first = index;}
	} else if (state=="lat2found") {
		if ((result!="value")&&(result!="point"))  {state="latready"; lat2last = index-1;}
	} else if (state=="latready") {
		if (result=="signnegative") {longfactor=-1.0;}
		if (result=="value") {state="long1found"; long1first = index;}
	} else if (state=="long1found") {
		if (result!="value")  {state="long1ready"; long1last = index-1;}
	} else if (state=="long1ready") {
		if (result=="value")  {state="long2found"; long2first = index;}
	} 
	if (state=="long2found") {// one digit at the end is possible
		if ((result!="value")&&(result!="point")) {
			state="longready"; long2last = index-1;
		} else if (index == latitudelongitude.length-1) {
			state="longready"; long2last = index;
		}		
	}
	index++;
}
if (state=="longready"){
	latitude = parseFloat (latitudelongitude.substr(lat1first, lat1last - lat1first + 1));
	latitude = latitude + (parseFloat (latitudelongitude.substr(lat2first, lat2last - lat2first + 1)) / 60.0);
	latitude = latitude * latfactor;
	longitude = parseFloat (latitudelongitude.substr(long1first, long1last - long1first + 1));
	longitude = longitude + (parseFloat (latitudelongitude.substr(long2first, long2last - long2first + 1)) / 60.0);
	longitude = longitude * longfactor;
} else {
	document.getElementById('latlong').value = "unknown format";
}
}

function latlongddmmss(latitudelongitude) {
lat1first = 0; lat1last = 0;
lat2first = 0; lat2last = 0;
lat3first = 0; lat3last = 0;
long1first = 0; long1last = 0;
long2first = 0; long2last = 0;
long3first = 0; long3last = 0;
state = "start";
latfactor = 1.0;
longfactor = 1.0; index=0;
while ((index < latitudelongitude.length) && (index < 51) && (state!="longready"))
{
	result = checkchar (latitudelongitude.substr(index, 1));
	if (state=="start"){
		if (result=="signnegative") {latfactor=-1.0;}
		if (result=="value") {state="lat1found"; lat1first = index;}
	} else if (state=="lat1found") {
		if (result!="value")  {state="lat1ready"; lat1last = index-1;}
	} else if (state=="lat1ready") {
		if (result=="value")  {state="lat2found"; lat2first = index;}
	} else if (state=="lat2found") {
		if (result!="value")  {state="lat2ready"; lat2last = index-1;}
	} else if (state=="lat2ready") {
		if (result=="value")  {state="lat3found"; lat3first = index;}
	} else if (state=="lat3found") {
		if ((result!="value")&&(result!="point"))  {state="latready"; lat3last = index-1;}
	} else if (state=="latready") {
		if (result=="signnegative") {longfactor=-1.0;}
		if (result=="value") {state="long1found"; long1first = index;}
	} else if (state=="long1found") {
		if (result!="value")  {state="long1ready"; long1last = index-1;}
	} else if (state=="long1ready") {
		if (result=="value")  {state="long2found"; long2first = index;}
	} else if (state=="long2found") {
		if (result!="value")  {state="long2ready"; long2last = index-1;}
	} else if (state=="long2ready") {
		if (result=="value")  {state="long3found"; long3first = index;}
	} 
	if (state=="long3found") {// one digit at the end is possible
		if ((result!="value")&&(result!="point")) {
			state="longready"; long3last = index-1;
		} else if (index == latitudelongitude.length-1) {
			state="longready"; long3last = index;
		}		
	}
	index++;
}
if (state=="longready"){
	latitude = parseFloat (latitudelongitude.substr(lat1first, lat1last - lat1first + 1));
	latitude = latitude + (parseFloat (latitudelongitude.substr(lat2first, lat2last - lat2first + 1)) / 60.0);
	latitude = latitude + (parseFloat (latitudelongitude.substr(lat3first, lat3last - lat3first + 1)) / 3600.0);
	latitude = latitude * latfactor;
	longitude = parseFloat (latitudelongitude.substr(long1first, long1last - long1first + 1));
	longitude = longitude + (parseFloat (latitudelongitude.substr(long2first, long2last - long2first + 1)) / 60.0);
	longitude = longitude + (parseFloat (latitudelongitude.substr(long3first, long3last - long3first + 1)) / 3600.0);
	longitude = longitude * longfactor;
} else {
	document.getElementById('latlong').value = "unknown format";
}
}



