<?php
// Latitude, Longitude Place Name Dropdown Tool from RJM Programming ... November 2013 
// November 2013
// Thanks to:
//   http://stutzfamily.com/mrstutz/LatLong/latlonglist.htm#AFGHANISTAN

//<pre><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a NAME="AFGHANISTAN"></a><b>AFGHANISTAN
//</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kabul&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 34&deg; 35' N&nbsp;&nbsp;&nbsp;&nbsp; 69&deg; 12' E</font></pre>

//<pre><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a NAME="ALGERIA"></a><b>ALGERIA
//</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Algiers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 36&deg; 46' N&nbsp;&nbsp;&nbsp;&nbsp; 30&deg; 3' E</font></pre>

// ...


//</body>
//</html>
echo "<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0'><link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'><title>Geographicals from RJM Programming</title>
<scr" . "ipt type='text/javascript' src='/check_viewport.js?r=" . rand(0,19876545) . "'></scr" . "ipt><scr" . "ipt type='text/javascript'>
 // Thanks to ideas via https://uigradients.com/ below
 var ideas=['#d3cbb8,#6d6027', '#74ebd5,#acb6e5', '#f7b733,#fc4a1a', '#00f260,#0575e6', '#ffc0cb,#800080', '#f3f9a7,#cac531', '#605c3c,#3c3b3f', '#fffbd5,#b20a2c', '#03001e,#7303c0,#ec38bc,#fdeff9', '#ada996,#f2f2f2,#dbdbdb,#eaeaea'];
 var wasone=-1;
 var aconto=null;
 function vsgeo(iois) {
   if (iois != null) {
    aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
     if (aconto.document) { aconto = aconto.document; }
     if (('' + aconto.referrer).indexOf('/PHP/GeoChart/geo_chart.php') == -1) {
     var xas=aconto.getElementsByTagName('a');
     for (var iou=0; iou<xas.length; iou++) {
       if (xas[iou].innerHTML == 'Geo') {
          xas[iou].click();
       }
     }
     }
    }
   }
 }
 function randgrad() {
   if (wasone < 0) {
    wasone=Math.floor(Math.random() * ideas.length);
    document.getElementById('xbody').className='s' + wasone;
    wasone=-1;
   } 
   setTimeout(randgrad,5000);
 }
</scr" . "ipt>
<style>
  .s0 { background:linear-gradient(90deg,#d3cbb8,#6d6027) !important; }
  .s1 { background:linear-gradient(90deg,#74ebd5,#acb6e5) !important; }
  .s2 { background:linear-gradient(90deg,#f7b733,#fc4a1a) !important; }
  .s3 { background:linear-gradient(90deg,#00f260,#0575e6) !important; }
  .s4 { background:linear-gradient(90deg,#ffc0cb,#800080) !important; }
  .s5 { background:linear-gradient(90deg,#f3f9a7,#cac531) !important; }
  .s6 { background:linear-gradient(90deg,#605c3c,#3c3b3f) !important; }
  .s7 { background:linear-gradient(90deg,#03001e,#7303c0,#ec38bc,#fdeff9) !important; }
  .s8 { background:linear-gradient(90deg,#ada996,#f2f2f2,#dbdbdb,#eaeaea) !important; }
</style>
</head><body id=xbody class='s0' onload='randgrad();' style='background:linear-gradient(90deg,  #d3cbb8, #6d6027);'>";
$latarr = array('nowayjose' => -1000.0);
$longarr = array('nowayjose' => -1000.0);
$cntryarr = array('nowayjose' => '');
$valuearr = array('nowayjose' => '');
$bigscript = "";
$mapidea = "<div id=stylediv></div><iframe onload='vsgeo(this);' style='width:620px;height:500px;' src=\"//www.rjmprogramming.com.au/PHP/Map/map.php?title=Places&label=['Lat',&value='Lon', 'Name']&data="; //, [-1,-2,~dsv~], [-11,-21,~dsv2~]


// Generic functions below

function find_nearest($inlat, $inlong) {
  global $latarr, $longarr, $cntryarr, $valuearr;
  $valis = array('', '');
  $valis[0] = "";
  $valis[1] = "";
  $nearestdist = -1.0;
  for ($ip=0; $ip<sizeof($latarr); $ip++) {
    if ((abs($latarr[$ip] - $inlat) + abs($longarr[$ip] - $inlong) < $nearestdist) || $nearestdist < 0.0) {
      $nearestdist = (abs($latarr[$ip] - $inlat) + abs($longarr[$ip] - $inlong));
      $valis[0] = $valuearr[$latarr[$ip].key];
    }
  }
  $valis[1] =  str_replace("/Geographicals/", "/HTML_CSS/",str_replace("place_latlong.", "get_weather.",$valis[0]));
  $valis[1] =  str_replace('/Coriolis/', '/HTML_CSS/',str_replace('place_latlong.', 'get_weather.',$valis[1]));
  $valis[1] =  str_replace('/SunAngle/', '/HTML_CSS/',str_replace('coriolis_force_at.', 'get_weather.',$valis[1]));
  $valis[1] =  str_replace('sun_angle_now_at.', 'get_weather.',str_replace('sun_angle_now_at_plus.', 'get_weather.',$valis[1]));
  $valis[1] =  str_replace('moon_angle_now_at_plus.', 'get_weather.',str_replace('/MoonAngle/', '/HTML_CSS/',$valis[1]));
  $valis[1] =  str_replace('/Distance/', '/HTML_CSS/',str_replace('moon_angle_now_at.', 'get_weather.',$valis[1]));
  $valis[1] =  str_replace('distance.', 'get_weather.',str_replace('distance_plus.', 'get_weather.',$valis[1]));
  return $valis;
}

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARTDED_FOR'] != '') {
      $rma = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} else {
      $rma = $_SERVER['REMOTE_ADDR'];
    }
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    return $rma;
}

function geography_dropdowns($outmode = 7, $countryparam = "", $fromparam = "", $toparam = "") {
global $latarr, $longarr, $cntryarr, $valuearr, $bigscript, $mapidea;
$bigscript = "";
$scnt = 0;
$outddata = "";
$extrainfo = '';
$cont = "";
$country = "";
$i = 0;
$zero = "0";
$disp = "none";
$outddata = "";
$extras = "";
$preextras = "<h1>Geographicals</h1><h3 style='margin-top:-20px;'>RJM Programming - November, 2019 ... Choose a Place</h3>";

if (!file_exists(dirname(__FILE__) . "/place_latlong_data.txt")) exec("curl http://stutzfamily.com/mrstutz/LatLong/latlonglist.htm#AFGHANISTAN > " . dirname(__FILE__) . "/place_latlong_data.txt");
if (file_exists(dirname(__FILE__) . "/place_latlong_data.txt")) {

$outddata = "\n<script type='text/javascript'>";
$outddata .= "\n latarr = []; "; //new Array(); ";
$outddata .= "\n longarr = []; "; // new Array(); ";
$outddata .= "\n cntryarr = []; "; // new Array(); ";
$outddata .= "\n valuearr = []; "; // new Array(); ";
$outddata .= "\n placearr = []; "; // new Array(); ";


$outddata .= "\n function find_nearest(inlat, inlong) { ";
$outddata .= "\n var valis = ['','']; ";
$outddata .= "\n var nearestdist = -1.0; ";
$outddata .= "\n for (var ip=0; ip<latarr.length; ip++) { ";
$outddata .= "\n if ((Math.abs(latarr[ip] - inlat) + Math.abs(longarr[ip] - inlong) < nearestdist) || nearestdist < 0.0) { ";
$outddata .= "\n nearestdist = (Math.abs(latarr[ip] - inlat) + Math.abs(longarr[ip] - inlong)); ";
$outddata .= "\n valis[0] = valuearr[ip]; ";
$outddata .= "\n } ";
$outddata .= "\n } ";
$outddata .= "\n valis[1] = valis[0].replace('/Geographicals/', '/HTML_CSS/'); ";
$outddata .= "\n valis[1] = valis[1].replace('place_latlong.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('/Coriolis/', '/HTML_CSS/'); ";
$outddata .= "\n valis[1] = valis[1].replace('coriolis_force_at.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('/SunAngle/', '/HTML_CSS/'); ";
$outddata .= "\n valis[1] = valis[1].replace('sun_angle_now_at_plus.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('sun_angle_now_at.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('/MoonAngle/', '/HTML_CSS/'); ";
$outddata .= "\n valis[1] = valis[1].replace('moon_angle_now_at_plus.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('moon_angle_now_at.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('/Distance/', '/HTML_CSS/'); ";
$outddata .= "\n valis[1] = valis[1].replace('distance_plus.', 'get_weather.'); ";
$outddata .= "\n valis[1] = valis[1].replace('distance.', 'get_weather.'); ";
$outddata .= "\n return valis; ";
$outddata .= "\n } \n";

$outddata .= "\n function countrychange(ocountry) { ";
$outddata .= " location.href = ocountry.value;  ";
$outddata .= "\n } ";
$outddata .= "\n function fromchange(ofrom) { ";
$outddata .= " location.href = ofrom.value;  ";
$outddata .= "\n } ";
$outddata .= "\n function tochange(oto) { ";
$outddata .= " var xt = oto.value.indexOf('?') + 1;  var suf = '&' + oto.value.substring(xt);  var xtoc = 'country=';  var toc = oto.value.indexOf(xtoc) + xtoc.length; var ctoc = oto.value.substring(toc);  toc = ctoc.indexOf('&');   ctoc = ctoc.substring(0, toc);  ";


if (isset($_GET['from']) && basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"]) ) {
 if ($_GET['from'] == "country") $countryparam = "country=" . str_replace("country=", "", $_GET['country']);
 if ($_GET['from'] == "from") $fromparam = "place=" . str_replace("place=", "", $_GET['place']);
 if ($_GET['from'] == "from") $countryparam = "country=" . str_replace("country=", "", $_GET['country']);
 if ($_GET['from'] == "to") {
   if (file_exists(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt")) {
     $chuh = fopen(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt", "r");
     $countryparam = fgets($chuh, 4096);
     fclose($chuh);
     unlink(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt");
   }
   if (file_exists(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt")) {
     $fhuh = fopen(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt", "r");
     $fromparam = fgets($fhuh, 4096);
     fclose($fhuh);
     unlink(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt");
   }
   $toparam = $_GET['place'];
 } else {
   if ($countryparam != "") {
     $chuh = fopen(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt", "w");
     fwrite($chuh, "country=" . str_replace("country=", "", $countryparam));
     fclose($chuh);
   }
   if ($fromparam != "") {
     $fhuh = fopen(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt", "w");
     fwrite($fhuh, "place=" . str_replace("place=", "", $fromparam));
     fclose($fhuh);
   }
   
 }
} else if (isset($_POST['from']) && basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"]) ) {
 if ($_POST['from'] == "country") $countryparam = "country=" . str_replace("country=", "", $_POST['country']);
 if ($_POST['from'] == "from") $fromparam = "place=" . str_replace("place=", "", $_POST['place']);
 if ($_POST['from'] == "from") $countryparam = "country=" . str_replace("country=", "", $_POST['country']);
 if ($_POST['from'] == "to") {
   if (file_exists(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt")) {
     $chuh = fopen(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt", "r");
     $countryparam = fgets($chuh, 4096);
     fclose($chuh);
     unlink(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt");
   }
   if (file_exists(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt")) {
     $fhuh = fopen(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt", "r");
     $fromparam = fgets($fhuh, 4096);
     fclose($fhuh);
     unlink(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt");
   }
   $toparam = $_POST['place'];
 } else {
   if ($countryparam != "") {
     $chuh = fopen(dirname(__FILE__) . "/lastcountry" . server_remote_addr() . ".txt", "w");
     fwrite($chuh, "country=" . str_replace("country=", "", $countryparam));
     fclose($chuh);
   }
   if ($fromparam != "") {
     $fhuh = fopen(dirname(__FILE__) . "/lastfrom" . server_remote_addr() . ".txt", "w");
     fwrite($fhuh, "place=" . str_replace("place=", "", $fromparam));
     fclose($fhuh);
   }
   
 }
}

if ($countryparam != "" || $fromparam != "") {
$fromparam = str_replace("'", "&quot;", $fromparam);
$toparam = str_replace("'", "&quot;", $toparam);
$fromrest = "";
if (isset($_GET['latd'])) {
$fromrest = "&fromlatd=" . $_GET['latd'] . "&fromlatm=" . $_GET['latm'] . "&fromlats=" . $_GET['lats'] . "&fromlongd=" . $_GET['longd'] . "&fromlongm=" . $_GET['longm'] . "&fromlongs=" . $_GET['longs'] . "&fromplace=" . $_GET['place'] . "&fromcountry=" . $_GET['country'];
$mapidea .= ", [" . $_GET['latd'] . str_replace("0.",".",(($_GET['latm'] / 60.0) + ($_GET['lats'] / 3600.0))) . "," .  $_GET['longd'] . str_replace("0.",".",(($_GET['longm'] / 60.0) + ($_GET['longs'] / 3600.0))) . ",~" . $_GET['place'] . "(" . $_GET['country'] . ")" . "~]";
if (isset($_GET['fromlatd'])) {
  $mapidea .= ", [" . $_GET['fromlatd'] . str_replace("0.",".",(($_GET['fromlatm'] / 60.0) + ($_GET['fromlats'] / 3600.0))) . "," .  $_GET['fromlongd'] . str_replace("0.",".",(($_GET['fromlongm'] / 60.0) + ($_GET['fromlongs'] / 3600.0))) . ",~" . $_GET['fromplace'] . "(" . $_GET['fromcountry'] . ")" . "~]";
}
} else if (isset($_POST['latd'])) {
$fromrest = "&fromlatd=" . $_POST['latd'] . "&fromlatm=" . $_POST['latm'] . "&fromlats=" . $_POST['lats'] . "&fromlongd=" . $_POST['longd'] . "&fromlongm=" . $_POST['longm'] . "&fromlongs=" . $_POST['longs'] . "&fromplace=" . $_POST['place'] . "&fromcountry=" . $_POST['country'];
$mapidea .= ", [" . $_POST['latd'] . str_replace("0.",".",(($_POST['latm'] / 60.0) + ($_POST['lats'] / 3600.0))) . "," .  $_POST['longd'] . str_replace("0.",".",(($_POST['longm'] / 60.0) + ($_POST['longs'] / 3600.0))) . ",~" . $_POST['place'] . "(" . $_POST['country'] . ")" . "~]";
if (isset($_POST['fromlatd'])) {
  $mapidea .= ", [" . $_POST['fromlatd'] . str_replace("0.",".",(($_POST['fromlatm'] / 60.0) + ($_POST['fromlats'] / 3600.0))) . "," .  $_POST['fromlongd'] . str_replace("0.",".",(($_POST['fromlongm'] / 60.0) + ($_POST['fromlongs'] / 3600.0))) . ",~" . $_POST['fromplace'] . "(" . $_POST['fromcountry'] . ")" . "~]";
}
}
//$outddata .= " window.location = oto.value + '&done=' + ctoc + '" . $fromrest . "';  ";
$outddata .= " location.href = oto.value + '&done=' + ctoc + '" . $fromrest . "';  ";
$outddata .= "\n } ";
$extras .= "<ul>";
if ($countryparam != "") {
  $preextras = "<iframe id='myf' src='javascript:false;' style='border:0;display:none;width:100%;height:350;margin-top:-30px;'></iframe>&nbsp;" . $preextras;
  $extras .= "<li><a target='_blank' id='acountrygs' title='" . str_replace("country=", "", $countryparam) . " Google Search' href='https://www.google.com.au/search?q=" . str_replace("country=", "", $countryparam) . "&client=firefox-a&rls=org.mozilla:en-US:official&source=lnms&sa=X&ei=de-XUrCELIXSkwXL9ICIDg&ved=0CAgQ_AUoAA&biw=1243&bih=609&dpr=1'>" . str_replace("country=", "", $countryparam) . " Google Search ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='_blank' id='bcountrygs' title='Google Image Search for " . str_replace("country=", "", $countryparam) . "' href='https://www.google.com.au/search?q=" . str_replace("country=", "", $countryparam) . "&client=firefox-a&hs=D7Y&rls=org.mozilla:en-US:official&source=lnms&tbm=isch&sa=X&ei=S-2XUuLfL8qpiAe6lIGgCA&ved=0CAkQ_AUoAQ&biw=1243&bih=609'>Google Image Search for " . str_replace("country=", "", $countryparam) . " ... new window</a>&nbsp;</li>"; 
}
if ($fromparam != "") {
  $preextras = "<iframe id='myf' src='javascript:false;' style='border:0;display:none;width:100%;height:350;'></iframe>&nbsp;" . $preextras;
  if ($toparam != "") {
  $extras .= "<li><a target='_blank' id='ccountrygs' title='" . str_replace("place=", "", $toparam) . " Google Search' href='https://www.google.com.au/search?q=" . str_replace("place=", "", $toparam) . "&client=firefox-a&rls=org.mozilla:en-US:official&source=lnms&sa=X&ei=de-XUrCELIXSkwXL9ICIDg&ved=0CAgQ_AUoAA&biw=1243&bih=609&dpr=1'>" . str_replace("place=", "", $toparam) . " Google Search ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='_blank' id='dcountrygs' title='Google Image Search for " . str_replace("place=", "", $toparam) . "' href='https://www.google.com.au/search?q=" . str_replace("place=", "", $toparam) . "&client=firefox-a&hs=D7Y&rls=org.mozilla:en-US:official&source=lnms&tbm=isch&sa=X&ei=S-2XUuLfL8qpiAe6lIGgCA&ved=0CAkQ_AUoAQ&biw=1243&bih=609'>Google Image Search for " . str_replace("place=", "", $toparam) . " ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='dist' title='Distance on Great Circle from " . str_replace("place=", "", $fromparam) . " to " . str_replace("place=", "", $toparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/Distance/distance.php?" . str_replace("from=to", "from=" . str_replace("place=", "", $fromparam), $_SERVER['QUERY_STRING']) . "\"; ' href='//www.rjmprogramming.com.au/PHP/Distance/distance.php?" . str_replace("from=to", "from=" . str_replace("place=", "", $fromparam), $_SERVER['QUERY_STRING']) . "'>Distance on Great Circle from " . str_replace("place=", "", $fromparam) . " to " . str_replace("place=", "", $toparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromsun' title='Distance on Great Circle from " . str_replace("place=", "", $fromparam) . " to " . str_replace("place=", "", $toparam) . "' href='//www.rjmprogramming.com.au/PHP/Distance/distance.php?" . str_replace("from=to", "from=" . str_replace("place=", "", $fromparam), $_SERVER['QUERY_STRING']) . "'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromsun' title='Sun Noon Angle Today at " . str_replace("place=", "", $toparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='http://www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Sun Noon Angle Today at " . str_replace("place=", "", $toparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromsun' title='Sun Noon Angle Today at " . str_replace("place=", "", $toparam) . "' href='http://www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='frommoon' title='Moon Noon Angle Today at " . str_replace("place=", "", $toparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='http://www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Moon Noon Angle Today at " . str_replace("place=", "", $toparam) . " ... here</a>&nbsp;<a target='myf' id='bfrommoon' title='Moon Noon Angle Today at " . str_replace("place=", "", $toparam) . "' href='http://www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromcoriolis' title='Coriolis Effect at " . str_replace("place=", "", $toparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='http://www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Coriolis Effect at " . str_replace("place=", "", $toparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromcoriolis' title='Coriolis Effect at " . str_replace("place=", "", $toparam) . "' href='http://www.rjmprogramming.com.au/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromweather' title='Weather at " . str_replace("place=", "", $toparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Weather at " . str_replace("place=", "", $toparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromweather' title='Weather at " . str_replace("place=", "", $toparam) . "' href='//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  } else {
  $extras .= "<li><a target='_blank' id='ccountrygs' title='" . str_replace("place=", "", $fromparam) . " Google Search' href='https://www.google.com.au/search?q=" . str_replace("place=", "", $fromparam) . "&client=firefox-a&rls=org.mozilla:en-US:official&source=lnms&sa=X&ei=de-XUrCELIXSkwXL9ICIDg&ved=0CAgQ_AUoAA&biw=1243&bih=609&dpr=1'>" . str_replace("place=", "", $fromparam) . " Google Search ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='_blank' id='dcountrygs' title='Google Image Search for " . str_replace("place=", "", $fromparam) . "' href='https://www.google.com.au/search?q=" . str_replace("place=", "", $fromparam) . "&client=firefox-a&hs=D7Y&rls=org.mozilla:en-US:official&source=lnms&tbm=isch&sa=X&ei=S-2XUuLfL8qpiAe6lIGgCA&ved=0CAkQ_AUoAQ&biw=1243&bih=609'>Google Image Search for " . str_replace("place=", "", $fromparam) . " ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromsun' title='Sun Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='//www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Sun Noon Angle Today at " . str_replace("place=", "", $fromparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromsun' title='Sun Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' href='//www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='frommoon' title='Moon Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='//www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Moon Noon Angle Today at " . str_replace("place=", "", $fromparam) . " ... here</a>&nbsp;<a target='myf' id='bfrommoon' title='Moon Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' href='//www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromcoriolis' title='Coriolis Effect at " . str_replace("place=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='//www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Coriolis Effect at " . str_replace("place=", "", $fromparam) . " ... here</a>&nbsp;<a target='myf' id='bfromcoriolis' title='Coriolis Efect at " . str_replace("place=", "", $fromparam) . "' href='//www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  $extras .= "<li><a target='myf' id='fromweather' title='Weather at " . str_replace("place=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y\"; ' href='//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y'>Weather at " . str_replace("place=", "", $fromparam) . " ... here</a>&nbsp;<a target='myf' id='bfromweather' title='Weather at " . str_replace("place=", "", $fromparam) . "' href='//www.rjmprogramming.com.au/HTML_CSS/get_weather.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  }
}
$extras .= "</ul>";
} else {
//$outddata .= " window.location = oto.value + '&done=' + ctoc;  ";
$outddata .= " location.href = oto.value + '&done=' + ctoc;  ";
$outddata .= "\n } ";
}

if ($outddata != "") $outddata .= "\n</script>";

$selcountry = "\n<select style='background-color: yellow;font-size:8px;margin-top:-20px;' onchange='countrychange(this);' title='Country' id='country'><option value=''>Country ...</option>";
$selfrom = "\n<select style='background-color: lightblue;font-size:8px;margin-top:-20px;' onchange='fromchange(this);' title='Place from' id='from'><option value=''>Place from ...</option>";
$selto = "\n<select style='background-color: lightgreen;font-size:8px;margin-top:-20px;' onchange='tochange(this);' title='Place to' id='to'><option value=''>Place to ...</option>";
$zthing = '<pre>';
$zfhuh = fopen(dirname(__FILE__) . "/place_latlong_data.txt", "r");
$zcont = "";
while (($zbuffer = fgets($zfhuh, 4096)) !== false) {
         $zcont .= $zbuffer;
}
fclose($zfhuh);
//unlink(dirname(__FILE__) . "/place_latlong_data.txt");
$zonp = strpos($zcont, $zthing);
$lastcountry = "";

while ($zonp !== false) {
  //echo $i;
  $i += 1;
  $cont = substr($zcont, $zonp);
  $dq = strpos($cont, '"');
  $cont = substr($cont, ($dq + 1));
  //echo "2-" . $i;
  $i += 1;
  $country = str_replace("canada", "CANADA", str_replace("usa", "USA", str_replace("x", " ", str_replace('"', '', substr($cont, 0, strpos($cont, '"'))))));
  $dq = strpos($cont, '</b>&nbsp;');
  $cont = substr($cont, ($dq + 4));
  $ef = strpos($cont, '</font>');
  //echo "3-" . $i;
  $i += 1;
  $ctrydata = substr($cont, 0, $ef);
  //echo "4-" . $ctrydata;
  $i += 1;
  $pieces = array_filter(explode("' ", $ctrydata));  
  //echo "5-" . $i;
  $i += 1;
  //echo var_dump($pieces);
  $j = 0;
  while ($j < sizeof($pieces)) {
   //if (strlen($pieces[$j + 0]) > 1) {
   if (substr($pieces[$j + 0], 0, 1) == "E") {
   $minipieces = array_filter(explode(" ", substr($pieces[$j + 0],2))); 
   } else if (substr($pieces[$j + 0], 0, 1) == "W") {
   $minipieces = array_filter(explode(" ", substr($pieces[$j + 0],2))); 
   } else {
   $minipieces = array_filter(explode(" ", substr($pieces[$j + 0],0))); 
   }
   $latm = $minipieces[sizeof($minipieces) - 1];
   $latd = substr($minipieces[sizeof($minipieces) - 2], 0, (strlen($minipieces[sizeof($minipieces) - 2] - 1)));
   $lats = 0;
   if (substr($pieces[$j + 1], 0, 1) == "S") {
     $latd = -$latd;
     $maxipieces = array_filter(explode(" ", substr($pieces[$j + 1],2))); 
   } else if (substr($pieces[$j + 1], 0, 1) == "N") {
     $maxipieces = array_filter(explode(" ", substr($pieces[$j + 1],2))); 
   } else {
     $maxipieces = array_filter(explode(" ", substr($pieces[$j + 1],0))); 
   }
   $longm = str_replace("&deg;", "", $maxipieces[sizeof($maxipieces) - 1]);
   $longd = substr($maxipieces[sizeof($maxipieces) - 2], 0, (strlen($maxipieces[sizeof($maxipieces) - 2] - 1)));
   $longs = 0;
   if (($j + 2) < sizeof($pieces)) {
    if (substr($pieces[$j + 2], 0, 1) == "W") {
     $longd = -$longd;
    }
   }
   //echo " latd=" . $latd;
   //echo " latm=" . $latm;
   //echo " longd=" . $longd;
   //echo " longm=" . $longm;
   $placeis = ltrim(rtrim(str_replace("~", "", str_replace("~W", "", str_replace("~E", "", str_replace("&nbsp;", " ", ("~" . $minipieces[0])))))));
   for ($jk=1; $jk<(sizeof($minipieces) - 2);  $jk++) {
     $placeis = ltrim(rtrim($placeis)) . " " . ltrim(rtrim(str_replace("&nbsp;", " ", $minipieces[$jk])));
   }
   if ($placeis == "Addis Ababa" && $latd == 90) $latd = 9;
   if ($placeis == "Algiers" && $latd == 30) $latd = 3;
   if (strpos($placeis, "Djamena") !== false && $country == "CHAD" && $latd < 0) $latd = -$latd;
   //echo " placeis=" . ltrim(rtrim($placeis));
   if (strlen(ltrim(rtrim($placeis))) > 2) {
     if ($lastcountry != $country) {
       $countrythis = "\n<option value=\"" . $_SERVER['PHP_SELF'] . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=country&country=" . $country . "&place=" . ltrim(rtrim($placeis)) . "\">" . $country . "</option>";
       if ($countryparam != "" && strpos($countrythis, $countryparam) !== false) {
         $selcountry .=  str_replace("option value=", "option selected='selected' value=", $countrythis);
       } else {
         $selcountry .=  $countrythis;
       }
     }
     $lastcountry = $country;
     $latarr[strtolower(ltrim(rtrim($placeis)))] = $latd + $latm / 60.0 + $lats / 3600.0;
     $longarr[strtolower(ltrim(rtrim($placeis)))] = $longd + $longm / 60.0 + $longs / 3600.0;
     $cntryarr[strtolower(ltrim(rtrim($placeis)))] = strtolower($country);
     $valuearr[strtolower(ltrim(rtrim($placeis)))] = str_replace("/GeogrXXXaphicals/", "/HTML_CSS/",str_replace("place_lXXXatlong.", "get_weather.",$_SERVER['PHP_SELF'])) . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=from&country=" . $country . "&place=" . ltrim(rtrim($placeis));
     if ($bigscript == "") $bigscript = "\n<" . "script>\n";
     $bigscript .= "\n placearr[" . $scnt . "] = '" . str_replace("'","&apost;",strtolower(ltrim(rtrim($placeis)))) . "';";
     $bigscript .= "\n latarr[" . $scnt . "] = " . ($latd + $latm / 60.0 + $lats / 3600.0) . ";";
     $bigscript .= "\n longarr[" . $scnt . "] = " . ($longd + $longm / 60.0 + $longs / 3600.0) . ";";
     $bigscript .= "\n cntryarr[" . $scnt . "] = '" . strtolower($country) . "';";
     $bigscript .= "\n valuearr[" . $scnt . "] = '" . $_SERVER['PHP_SELF'] . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=from&country=" . $country . "&place=" . str_replace("'","&apost;",ltrim(rtrim($placeis))) . "';";
     $fromthis = "\n<option value=\"" . str_replace("/GeograpXXXhicals/", "/HTML_CSS/",str_replace("place_latXXXlong.", "get_weather.",$_SERVER['PHP_SELF'])) . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=from&country=" . $country . "&place=" . str_replace("'","&apost;",ltrim(rtrim($placeis))) . "\">" . str_replace("'","&apost;",ltrim(rtrim($placeis))) . " ... " . $country . "</option>";
     $scnt += 1;
     if ($fromparam != "" && strpos($fromthis, $fromparam) !== false) {
         $selfrom .=  str_replace("option value=", "option selected='selected' value=", $fromthis);
     } else {
         $selfrom .=  $fromthis;
     }
     $tothis = "\n<option value=\"" . $_SERVER['PHP_SELF'] . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=to&country=" . $country . "&place=" . str_replace("'","&apost;",ltrim(rtrim($placeis))) . "\">" . str_replace("'","&apost;",ltrim(rtrim($placeis))) . " ... " . $country . "</option>";
     if ($toparam != "" && strpos($tothis, $toparam) !== false) {
         $selto .=  str_replace("option value=", "option selected='selected' value=", $tothis);
     } else {
         $selto .=  $tothis;
     }
   }
   //}
   $j += 2;
  }
  
  
  $zcont = $cont;
  $zonp = strpos($zcont, $zthing);
}
$selcountry .= "\n</select>";
$selfrom .= "\n</select>";
$selto .= "\n</select>";
if (strlen(str_replace("&data=,", "", $mapidea)) == strlen($mapidea)) {
  $mapidea = "";
} else {
  $mapidea .= "\"></iframe>";
}
if ($bigscript != "") {
  $bigscript .= "\n </" . "script>\n" . $mapidea;
  $mapidea = "";
}
if ($outmode == 7) {
  return $outddata . $preextras . "<table><tr><td>" . $selcountry . "</td><td>" . $selfrom . "</td><td>" . $selto . "</td></tr><tr><td colspan=3>" . $extras . "</td></tr></table>" . $bigscript;
} else if ($outmode == 3) {
  return $outddata . $preextras . "<table><tr><td>" . $selfrom . "</td><td>" . $selto . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>" . $bigscript;
} else if ($outmode == 6) {
  return $outddata . $preextras . "<table><tr><td>" . $selcountry . "</td><td>" . $selfrom . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>" . $bigscript;
} else if ($outmode == 5) {
  return $outddata . $preextras . "<table><tr><td>" . $selcountry . "</td><td>" . $selto . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>" . $bigscript;
} else if ($outmode == 1) {
  return $outddata . $preextras . $selto . $extras . $bigscript;
} else if ($outmode == 2) {
  return $outddata . $preextras . $selfrom . $extras . $bigscript;
} else if ($outmode == 4) {
  return $outddata . $preextras . $selcountry . $extras . $bigscript;
} else if ($outmode == -7) {
  return $outddata . $selcountry . $selfrom . $selto . $bigscript;
} else if ($outmode == -3) {
  return $outddata . $selfrom . $selto . $bigscript;
} else if ($outmode == -6) {
  return $outddata . $selcountry . $selfrom . $bigscript;
} else if ($outmode == -5) {
  return $outddata . $selcountry . $selto . $bigscript;
} else if ($outmode == -1) {
  return $outddata . $selto . $bigscript;
} else if ($outmode == -2) {
  return $outddata . $selfrom . $bigscript;
} else if ($outmode == -4) {
  return $outddata . $selcountry . $bigscript;

}
}
return $outddata . $bigscript . $mapidea . "";
}

// Generic functions above
if ( basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"]) ) {
  echo geography_dropdowns() . "</body></html>";
}

?>
