<?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><title>Geographicals from RJM Programming</title><body>";

// Generic functions below

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 = "") {
$outddata = "";
$extrainfo = '';
$cont = "";
$country = "";
$i = 0;
$zero = "0";
$disp = "none";
$outddata = "";
$extras = "";
$preextras = "<h1>Choose a Place</h1>";

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 function countrychange(ocountry) { ";
$outddata .= " window.location = ocountry.value;  ";
$outddata .= "\n } ";
$outddata .= "\n function fromchange(ofrom) { ";
$outddata .= " window.location = 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'];
} 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'];
}
$outddata .= " window.location = 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;'></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=\"http://www.rjmprogramming.com.au/PHP/Distance/distance.php?" . str_replace("from=to", "from=" . str_replace("place=", "", $fromparam), $_SERVER['QUERY_STRING']) . "\"; ' href='http://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='http://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=\"http://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=\"http://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=\"http://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='bfromsun' 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>"; 
  } 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=\"http://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=", "", $fromparam) . " ... here</a>&nbsp;<a target='_blank' id='bfromsun' title='Sun Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' 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=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"http://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=", "", $fromparam) . " ... here</a>&nbsp;<a target='myf' id='bfrommoon' title='Moon Noon Angle Today at " . str_replace("place=", "", $fromparam) . "' 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=", "", $fromparam) . "' onmousedown=' var xx=document.getElementById(\"myf\"); xx.style.display=\"block\"; xx.src=\"http://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=", "", $fromparam) . " ... here</a>&nbsp;<a target='myf' id='bfrommoon' title='Coriolis Efect at " . str_replace("place=", "", $fromparam) . "' href='http://www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?" . $_SERVER['QUERY_STRING'] . "&done=y'> ... new window</a>&nbsp;</li>"; 
  }
}
$extras .= "</ul>";
} else {
$outddata .= " window.location = oto.value + '&done=' + ctoc;  ";
$outddata .= "\n } ";
}

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

$selcountry = "\n<select style='background-color: yellow;' onchange='countrychange(this);' title='Country' id='country'><option value=''>Country ...</option>";
$selfrom = "\n<select style='background-color: lightblue;' onchange='fromchange(this);' title='Place from' id='from'><option value=''>Place from ...</option>";
$selto = "\n<select style='background-color: lightgreen;' 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;
     $fromthis = "\n<option value=\"" . $_SERVER['PHP_SELF'] . "?latd=" . $latd . "&latm=" . $latm . "&lats=" . $lats . "&longd=" . $longd . "&longm=" . $longm . "&longs=" . $longs . "&from=from&country=" . $country . "&place=" . ltrim(rtrim($placeis)) . "\">" . ltrim(rtrim($placeis)) . " ... " . $country . "</option>";
     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=" . ltrim(rtrim($placeis)) . "\">" . 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 ($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>";
} else if ($outmode == 3) {
  return $outddata . $preextras . "<table><tr><td>" . $selfrom . "</td><td>" . $selto . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>";
} else if ($outmode == 6) {
  return $outddata . $preextras . "<table><tr><td>" . $selcountry . "</td><td>" . $selfrom . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>";
} else if ($outmode == 5) {
  return $outddata . $preextras . "<table><tr><td>" . $selcountry . "</td><td>" . $selto . "</td></tr><tr><td colspan=2>" . $extras . "</td></tr></table>";
} else if ($outmode == 1) {
  return $outddata . $preextras . $selto . $extras;
} else if ($outmode == 2) {
  return $outddata . $preextras . $selfrom . $extras;
} else if ($outmode == 4) {
  return $outddata . $preextras . $selcountry . $extras;
} else if ($outmode == -7) {
  return $outddata . $selcountry . $selfrom . $selto;
} else if ($outmode == -3) {
  return $outddata . $selfrom . $selto;
} else if ($outmode == -6) {
  return $outddata . $selcountry . $selfrom;
} else if ($outmode == -5) {
  return $outddata . $selcountry . $selto ;
} else if ($outmode == -1) {
  return $outddata . $selto;
} else if ($outmode == -2) {
  return $outddata . $selfrom;
} else if ($outmode == -4) {
  return $outddata . $selcountry;

}
}
return $outddata;
}

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

?>