<!doctype html>
<html>
<head>
<title>The Other Side of the World - RJM Programming - March, 2017</title>
<head>
<script type='text/javascript'>
var url = "http://www.rjmprogramming.com.au/PHP/Map/map.php?title=Other%20Side%20Of%20the%20World&onclick=y&label=['Lat',&value='Lon','Name']&data=";
var place=["placearr["], country=["cntryarr["], ylat=["latarr["], xlong=["longarr["], distfrom=[], distto=[], iplaces=0, jplace=0, topfivefrom=[-1.0, -1.0, -1.0, -1.0, -1.0], topfiveto=[-1.0, -1.0, -1.0, -1.0, -1.0];
var divisor=10.0, divl=1;

function great_circle_distance(talis, gnolis, latis, longis) {
var ourdist=0.0;
var rgnol=eval((gnolis) * Math.PI / 180.0);
var rtal=eval((talis) * Math.PI / 180.0);
var rlong=eval((longis) * Math.PI / 180.0);
var rlat=eval((latis) * Math.PI / 180.0);

var deltalong = Math.abs(eval(((gnolis)-(longis)) * Math.PI / 180.0));


var acof = eval(Math.sin(rtal) * Math.sin(rlat)) + (Math.cos(rtal) * Math.cos(rlat) * Math.cos(deltalong)); // via http://en.wikipedia.org/wiki/Great-circle_distance ... thanks

ourdist = eval(Math.round((Math.acos(acof) * 6371000.0) + 0.00001) * 100) / 100;
return eval(ourdist / 1000.0);
}

function pregleanlatlong() {
gleanlatlong(document.getElementById('iandt'));
}

// Thanks to:
// http://stutzfamily.com/mrstutz/LatLong/latlonglist.htm#AFGHANISTAN
function gleanlatlong(iois) {
var rawhtml, k, kk, finished=false, spare='', spares, inlat=0.0, inlong=0.0;
if (iois != null) {
var aconto = (iois.contentWindow || iois.contentDocument);
if (aconto != null) {
if (aconto.document) { aconto = aconto.document; }
if (aconto.body != null) {
rawhtml=aconto.body.innerHTML.split('placearr[0]');
place=('placearr[0]' + rawhtml[1]).split(place[0]);
country=('placearr[0]' + rawhtml[1]).split(country[0]);
ylat=('placearr[0]' + rawhtml[1]).split(ylat[0]);
xlong=('placearr[0]' + rawhtml[1]).split(xlong[0]);
//alert(place.length + ' vs ' + country.length + ' vs ' + ylat.length + ' vs ' + xlong.length);
iplaces=eval(-1 + country.length);
while (divisor <= iplaces) {
divisor*=10.0;
divl++;
}
for (jplace=1; jplace<=iplaces; jplace++) {
//if (jplace == iplaces || jplace == 1) {
// alert('hopefully okay below?');
//}
//alert(ylat[eval(0 + jplace)] + ' ... ' + ylat[eval(0 + jplace)].split('=')[1].split(';')[0].trim());
ylat[eval(-1 + jplace)]=eval(ylat[eval(0 + jplace)].split('=')[1].split(';')[0].trim());
//alert(2);
xlong[eval(-1 + jplace)]=eval(xlong[eval(0 + jplace)].split('=')[1].split(';')[0].trim());
//alert(22);
spare=('' + place[eval(0 + jplace)]);
place[eval(-1 + jplace)]='';
if (spare.indexOf("'") != -1 && spare.indexOf("=") != -1) {
place[eval(-1 + jplace)]=('' + place[eval(0 + jplace)]).split('=')[1].split("'")[1];
//alert(222);
if (place[eval(-1 + jplace)].indexOf(' ') != -1) {
spares=place[eval(-1 + jplace)].split(' ');
place[eval(-1 + jplace)]=spares[0].substring(0,1).toUpperCase() + spares[0].substring(1);
for (kk=1; kk<spares.length; kk++) {
place[eval(-1 + jplace)]+=' ' + spares[kk].substring(0,1).toUpperCase() + spares[kk].substring(1);
}
if (place[eval(-1 + jplace)].indexOf('(') != -1) {
spares=place[eval(-1 + jplace)].split('(');
place[eval(-1 + jplace)]=spares[0].substring(0,1).toUpperCase() + spares[0].substring(1);
for (kk=1; kk<spares.length; kk++) {
place[eval(-1 + jplace)]+='(' + spares[kk].substring(0,1).toUpperCase() + spares[kk].substring(1);
}
}
} else {
place[eval(-1 + jplace)]=place[eval(-1 + jplace)].substring(0,1).toUpperCase() + place[eval(-1 + jplace)].substring(1);
}
}
//alert(2222);
spare=('' + country[eval(0 + jplace)]);
country[eval(-1 + jplace)]='';
if (spare.indexOf("'") != -1 && spare.indexOf("=") != -1) {
country[eval(-1 + jplace)]=('' + country[eval(0 + jplace)]).split('=')[1].split("'")[1];
//alert(22222);
if (country[eval(-1 + jplace)].indexOf(' ') != -1) {
spares=country[eval(-1 + jplace)].split(' ');
country[eval(-1 + jplace)]=spares[0].substring(0,1).toUpperCase() + spares[0].substring(1);
for (kk=1; kk<spares.length; kk++) {
country[eval(-1 + jplace)]+=' ' + spares[kk].substring(0,1).toUpperCase() + spares[kk].substring(1);
}
if (country[eval(-1 + jplace)].indexOf('(') != -1) {
spares=country[eval(-1 + jplace)].split('(');
country[eval(-1 + jplace)]=spares[0].substring(0,1).toUpperCase() + spares[0].substring(1);
for (kk=1; kk<spares.length; kk++) {
country[eval(-1 + jplace)]+='(' + spares[kk].substring(0,1).toUpperCase() + spares[kk].substring(1);
}
}
} else {
country[eval(-1 + jplace)]=country[eval(-1 + jplace)].substring(0,1).toUpperCase() + country[eval(-1 + jplace)].substring(1);
}
//alert(222222);
}
//if (jplace == iplaces) {
// alert(ylat[eval(-1 + iplaces)]);
// alert(country[eval(-1 + iplaces)]);
//} else if (jplace == 1) {
// alert('?');
// alert(ylat[eval(-1 + jplace)]);
// alert(country[eval(-1 + jplace)]);
//}

//cleartop();
more(0.0,0.0,jplace);
inlat=0.0;
inlong=0.0;
if (1 == 2) {

var inlatoe=eval(-inlat), inlongoe=(eval(inlong) < 0.0 ? eval(180.000000 + (inlong)) : eval(inlong - 180.0));
distfrom[eval(-1 + jplace)]=Math.floor(great_circle_distance(inlat, inlong, ylat[eval(-1 + jplace)], xlong[eval(-1 + jplace)]));
distto[eval(-1 + jplace)]=Math.floor(great_circle_distance(inlatoe, inlongoe, ylat[eval(-1 + jplace)], xlong[eval(-1 + jplace)]));

finished=false;
for (k=0; k<topfivefrom.length; k++) {
if (!finished) {
if (eval(topfivefrom[k]) < 0.0) {
topfivefrom[k]=eval('' + distfrom[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
} else if (eval(topfivefrom[k]) > (eval(distfrom[eval(-1 + jplace)]) + eval(jplace / divisor))) {
for (kk=eval(-2 + topfivefrom.length); kk>=k; kk--) {
topfivefrom[eval(1 + kk)]=topfivefrom[kk];
}
topfivefrom[k]=eval('' + distfrom[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
}
}
}
finished=false;
for (k=0; k<topfiveto.length; k++) {
if (!finished) {
if (eval(topfiveto[k]) < 0.0) {
topfiveto[k]=eval('' + distto[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
} else if (eval(topfiveto[k]) > (eval(distto[eval(-1 + jplace)]) + eval(jplace / divisor))) {
for (kk=eval(-2 + topfiveto.length); kk>=k; kk--) {
topfiveto[eval(1 + kk)]=topfiveto[kk];
}
topfiveto[k]=eval('' + distto[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
}
}
}

}
}
}
}
}
fillinsfromto();
}

function pretotalmore() {
topfivefrom.push(-1.0);
topfiveto.push(-1.0);
totalmore();
}

function totalmore() {
var inlat=eval(document.getElementById('latitude').value);
var inlong=eval(document.getElementById('longitude').value);
for (var lplace=1; lplace<iplaces; lplace++) {
more(inlat, inlong, lplace);
}
fillinsfromto();
}

function more(inlat, inlong, kplace) {
var jplace, finished=false, k;
for (jplace=kplace; jplace<=kplace; jplace++) {
var inlatoe=eval(-inlat), inlongoe=(eval(inlong) < 0.0 ? eval(180.000000 + (inlong)) : eval(inlong - 180.0));
distfrom[eval(-1 + jplace)]=Math.floor(great_circle_distance(inlat, inlong, ylat[eval(-1 + jplace)], xlong[eval(-1 + jplace)]));
distto[eval(-1 + jplace)]=Math.floor(great_circle_distance(inlatoe, inlongoe, ylat[eval(-1 + jplace)], xlong[eval(-1 + jplace)]));
finished=false;
for (k=0; k<topfivefrom.length; k++) {
if (!finished) {
if (eval(topfivefrom[k]) < 0.0) {
topfivefrom[k]=eval('' + distfrom[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
} else if (eval(topfivefrom[k]) > (eval(distfrom[eval(-1 + jplace)]) + eval(jplace / divisor))) {
for (kk=eval(2 - topfivefrom.length); kk>=k; kk--) {
topfivefrom[kk + 1]=topfivefrom[kk];
}
topfivefrom[k]=eval('' + distfrom[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
}
}
}
finished=false;
for (k=0; k<topfiveto.length; k++) {
if (!finished) {
if (eval(topfiveto[k]) < 0.0) {
topfiveto[k]=eval('' + distto[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
} else if (eval(topfiveto[k]) > (eval(distto[eval(-1 + jplace)]) + eval(jplace / divisor))) {
for (kk=eval(2 - topfiveto.length); kk>=k; kk--) {
topfiveto[kk + 1]=topfiveto[kk];
}
topfiveto[k]=eval('' + distto[eval(-1 + jplace)]) + eval(jplace / divisor);
finished=true;
}
}
}
}
}

function cleartop() {
for (var k=0; k<topfivefrom.length; k++) {
topfivefrom[k] = -1.0;
topfiveto[k] = -1.0;
}
}

function fillinsfromto() {
var sih='', csih='', csses, k;
sih="<option value=''>See closest places to " + document.getElementById('place').value + " ...</option>";
for (k=0; k<topfivefrom.length; k++) {
if (eval(topfivefrom[k]) >= 0.0) {
//alert('' + topfivefrom[k]);
csses=('' + topfivefrom[k]).split('.');
while (('' + csses[1]).length < divl) {
csses[1]+='0';
}
sih+='<option value="' + ',[' + ylat[eval(-1 + eval(csses[1]))] + ',' + xlong[eval(-1 + eval(csses[1]))] + ',~' + encodeURIComponent(place[eval(-1 + eval(csses[1]))] + ' (' + country[eval(-1 + eval(csses[1]))]) + ')~]' + '">' + place[eval(-1 + eval(csses[1]))] + ',' + country[eval(-1 + eval(csses[1]))] + ' (' + csses[0] + ')' + '</option>';
}
}
document.getElementById('sfrom').innerHTML=sih;
sih="<option value=''>See closest places to Other Side of the World to " + document.getElementById('place').value + " ...</option>";
for (k=0; k<topfiveto.length; k++) {
if (eval(topfiveto[k]) >= 0.0) {
csses=('' + topfiveto[k]).split('.');
while (('' + csses[1]).length < divl) {
csses[1]+='0';
}
sih+='<option value="' + ',[' + ylat[eval(-1 + eval(csses[1]))] + ',' + xlong[eval(-1 + eval(csses[1]))] + ',~' + encodeURIComponent(place[eval(-1 + eval(csses[1]))] + ' (' + country[eval(-1 + eval(csses[1]))]) + ')~]' + '">' + place[eval(-1 + eval(csses[1]))] + ',' + country[eval(-1 + eval(csses[1]))] + ' (' + csses[0] + ')' + '</option>';
}
}
document.getElementById('sto').innerHTML=sih;
cleartop();
document.getElementById('sfrom').value='';
document.getElementById('sto').value='';
}

function andshowit(sval) {
//alert("sval.value=" + sval.value);
if (sval.value != "") {
var thingos=sval.value.replace(',[','').split(',');
document.getElementById('place').value=sval.options[sval.selectedIndex].text;
document.getElementById('latitude').value=thingos[0];
document.getElementById('longitude').value=thingos[1];
totalmore();
showit();
}
}

function showit() {
var oururl=url;
oururl+=',[' + document.getElementById('latitude').value + ',' + document.getElementById('longitude').value + ',~' + encodeURIComponent(document.getElementById('place').value) + '~]' + document.getElementById('sfrom').value;
oururl+=',[' + eval(0.000000 - document.getElementById('latitude').value) + ',' + (eval(document.getElementById('longitude').value) < 0.0 ? eval(180.000000 + (document.getElementById('longitude').value)) : eval(document.getElementById('longitude').value - 180.0)) + ',~' + encodeURIComponent("Other side of the world to ... " + document.getElementById('place').value) + '~]' + document.getElementById('sto').value;
//alert(oururl.replace(',-180',',-179.99999').replace(',180',',179.99999'));
document.getElementById("myiframe").style.display="block";
document.getElementById("myiframe").src=oururl.replace(',-180',',179.99999').replace(',180',',179.99999');
}
</script>
</head>
<body style="background-color:lightgreen;">
<table><tbody><tr><td style="vertical-align:top;">
<h1>The Other Side of the World</h1>
<h3>RJM Programming - March, 2017</h3>
<div>
Place Name: <input onblur="totalmore();" id="place" type="text" value="My Place"></input><br><select onclick="andshowit(this);" onchange="showit();" id="sfrom"></select> <select onclick="andshowit(this);" onchange="showit();" id="sto"></select> <input type=button onclick="pretotalmore();" value="+"></input><br>
Latitude: <input onblur="totalmore();" onchange="totalmore();" id="latitude" type="number" step="0.000001" value="0.000000" min="-90.000000" max="90.000000"></input><br>
Longitude: <input onblur="totalmore();" onchange="totalmore();" id="longitude" type="number" step="0.000001" value="0.000000" min="-180.000000" max="180.000000"></input><br><br>
<input id="mysb" onclick="showit();" type="button" value="Show Your Place and 'Other Side of the World' to the Right"></input>
</div>
</td><td style="vertical-align:top;">
<iframe name="myiframe" id="myiframe" style="display:none;height:500px;width:500px;" src="about:blank"></iframe>
</td></tr></tbody></table>
<iframe id='iandt' onload="setTimeout(pregleanlatlong,3000);" src='//www.rjmprogramming.com.au/PHP/LatLong/index.php?latd=55&latm=52&lats=0&longd=-4&longm=17&longs=0&from=from&country=UNITED%20KINGDOM&place=Glasgow' style='display:none;' title='City Lat/Long list'></iframe>
</body>
</html>