<?php
// map.php
// RJM Programming
// December, 2016
// Interface to Google Charts Map Chart


  if (file_exists("csv.php")) {
    include "csv.php";
  } else if (file_exists("../csv.php")) { 
    include "../csv.php";
  }
  function retval($inv) {
    if (strpos($inv, "E-") !== false) return "0";
    return $inv;
  }

  function dlltf($gettzname, $getgmtoff, $getrightnow, $dllmode, $dllbitsmode) {
      global $dllt, $dlltbits;
      if ($dllmode >= 0 && $dllbitsmode >= 0) {
       $dllarr=explode("|", $dllt);
       $dllbitsarr=explode("|", $dlltbits);
       if (sizeof($dllarr) > $dllmode && sizeof($dllbitsarr) > $dllbitsmode) {
        return $dllarr[$dllmode] . "|" . $dllbitsarr[$dllbitsmode];
       } else if (sizeof($dllarr) > $dllmode) {
        return $dllarr[$dllarr] . "|";
       } else if (sizeof($dllbitsarr) > $dllbitsmode) {
        return "|" . $dllbitsarr[$dllbitsarr];
       } else {
        return "|";
       }
      } else if ($dllmode >= 0) {
       $dllarr=explode("|", $dllt);
       if (sizeof($dllarr) > $dllmode) {
        return $dllarr[$dllmode];
       } else {
        return "";
       }
      } else if ($dllbitsmode >= 0) {
       $dllbitsarr=explode("|", $dlltbits);
       if (sizeof($dllbitsarr) > $dllbitsmode) {
        return $dllbitsarr[$dllbitsmode];
       } else {
        return "";
       }
      } else {
       if ($getgmtoff != "" && $gettzname != "") {
        $arrdll=explode("|", $dllt);
        if ($dllt != "") $dllt.="|";
        if ($dlltbits != "") {
          $dlltbits.=" else if (ir == " . (0 + sizeof($arrdll)) . ") { ";
        } else {
          $dlltbits=" if (ir == " . (-1 + sizeof($arrdll)) . ") { ";
        }
        if ($getrightnow != "") {
         $dlltm="TimeZone " . $gettzname . " (GMT " . str_replace("+-","-",("+" . $getgmtoff)) . ") (where it is " . $getrightnow . ") Information=T";
         $dllt.=$dlltm; //"TimeZone " . $gettzname . " (GMT " . str_replace("+-","-",("+" . $getgmtoff)) . ") (where it is " . $getrightnow . ") Information=T";
        } else {
         $dlltm="TimeZone " . $gettzname . " (GMT " . str_replace("+-","-",("+" . $getgmtoff)) . ") Information=T";
         $dllt.=$dlltm; //"TimeZone " . $gettzname . " (GMT " . str_replace("+-","-",("+" . $getgmtoff)) . ") Information=T";
        }
        $dlltbitsm="window.open('http://timezoneconverter.com/cgi-bin/zoneinfo?tz=" . urldecode($gettzname) . "','_blank');";
        $dlltbits.=$dlltbitsm; //"window.open('http://timezoneconverter.com/cgi-bin/zoneinfo?tz=" . urldecode($gettzname) . "','_blank');";
        echo "\n" . ' tzarr.push("' . $dlltm . '"); ' . "\n";
        echo "\n" . ' tzarrbits.push("' . $dlltbitsm . '"); ' . "\n";
        $dlltbits.=" } ";
      // }
      } else {
       $arrdll=explode("|", $dllt);
       $dllt.="|";
       if ($dlltbits != "") {
          $dlltbits.=" else if (ir == " . (0 + sizeof($arrdll)) . ") { ir=ir; } ";
       } else {
          $dlltbits=" if (ir == " . (-1 + sizeof($arrdll)) . ") { ir=ir } ";
       }
      }
      }
      return "";
  }

  function tzlook($inwithtz) {  // am expecting PlaceName|TimeZoneName|GMTOffset|TimeRightNow from inside data 
   global $dllt, $dlltbits;
   $outwithouttz=$inwithtz;
   if (strpos($inwithtz, "|") !== false) {
     if ($dllt == "") {
       $withinbar=explode("|", $inwithtz);
       $outwithouttz=$withinbar[0];
       for ($iwb=1; $iwb<sizeof($withinbar); $iwb+=3) {
         if (strpos($withinbar[$iwb + 2], "~") !== false) {
          $withoutbar=explode("~", $withinbar[$iwb + 2]);
          $outwithouttz.=str_replace($withoutbar[0],"",$withinbar[$iwb + 2]);
          dlltf($withinbar[$iwb], $withinbar[$iwb + 1], $withoutbar[0], -1, -1);
         } else if (strpos($withinbar[$iwb + 2], '"') !== false) {
          $withoutbar=explode('"', $withinbar[$iwb + 2]);
          $outwithouttz.=str_replace($withoutbar[0],"",$withinbar[$iwb + 2]);
          dlltf($withinbar[$iwb], $withinbar[$iwb + 1], $withoutbar[0], -1, -1);
         } else if (strpos($withinbar[$iwb + 2], "'") !== false) {
          $withoutbar=explode("'", $withinbar[$iwb + 2]);
          $outwithouttz.=str_replace($withoutbar[0],"",$withinbar[$iwb + 2]);
          dlltf($withinbar[$iwb], $withinbar[$iwb + 1], $withoutbar[0], -1, -1);
         } else {
          $outwithouttz.="";
         }
       }
     }
   }
   return $outwithouttz;
  }

?>
<html>
  <head> 
    <title>Map - RJM Programming - http://www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

   var dllw='', dllt='', dllwbits='', dlltbits='', dllc='Draw Link Lines=D', lastel=null, ifoeo='', x=-1, y=-1, prevx=-1, prevy=-1, posx=-1, posy=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='', lcnt=0, lasttrip='', thisplace='', lastplace='';   

   var tzarr=[], tzarrbits=[];

<?php echo "\n var topdocumentURL='" . $_SERVER['HTTP_REFERER'] . "'; \n"; ?>

function ourencodeURIComponent(insis) {
  var outsis=encodeURIComponent(insis), ebits;
  var kbits=insis.split('&');
  var jbits=insis.split('=');
  var altsis='';
  if (eval(kbits.length) > 1 && eval(jbits.length) > 1 && eval(kbits.length) == eval(jbits.length) && eval(jbits[0].length) > eval(kbits[0].length)) {
    altsis=encodeURIComponent(kbits[0]);
    for (var iu=1; iu<eval(jbits.length); iu++) {
        ebits=kbits[iu].split('=');
        altsis+='&' + ebits[0] + '='; // &title=
        altsis+=encodeURIComponent(ebits[1]);  // hello
    }
  }
  if (altsis != '') return altsis;
  return outsis;
}

function maybeir(indl, inir) {
  if (tzarr.length > inir) {
    if (tzarr[inir] != "") {
     return tzarr[inir] + String.fromCharCode(10);
    } else {
     return indl;
    }
  }
  return indl;
}

function handleStart(evt) {
  evt.preventDefault();
  more(lastel, 1);
}

function draw_a_line() {
  lcnt++;
  //document.getElementById('xydiv').innerHTML+='<svg height="' + Math.abs(y - prevy) + '" width="' + Math.abs(x - prevx) + '" title="' + lasttrip + '" id="sl' + lcnt + '"  style="position:absolute;z-index:8;margin-top:0px;margin-left:0px;" xmlns="http://www.w3.org/2000/svg"><line title="' + lasttrip + '" id="l' + lcnt + '" onclick="more(this);" style="stroke:red;stroke-width:4;" x1="' + prevx + '" y1="' + prevy + '" x2="' + x + '" y2="' + y + '" /></svg>';
  //document.getElementById('xydiv').innerHTML+='<svg id="sl' + lcnt + '"  style="position:absolute;z-index:8;margin-top:0px;margin-left:0px;top:' + prevy + 'px;" xmlns="http://www.w3.org/2000/svg"><g><title>' + lasttrip + '</title><line id="l' + lcnt + '" onmouseover="more(this,0);" onclick="more(this,1);" style="stroke:red;stroke-width:4;" x1="' + prevx + '" y1="' + 0 + '" x2="' + x + '" y2="' + eval(y - prevy) + '" /></g></svg>';
  document.getElementById('xydiv').innerHTML='<svg id="sl' + lcnt + '"  style="position:absolute;z-index:8;margin-top:0px;margin-left:0px;top:' + prevy + 'px;" xmlns="http://www.w3.org/2000/svg"><g><title>' + distmore(lasttrip) + '</title><line id="l' + lcnt + '" onmouseover="more(this,0);" onclick="more(this,1);" style="stroke:red;stroke-width:4;" x1="' + prevx + '" y1="' + 0 + '" x2="' + x + '" y2="' + eval(y - prevy) + '" /></g></svg>';
  lastel=document.getElementById(document.getElementById('l' + lcnt));
  if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
    lastel.addEventListener("touchstart", handleStart, false);  // idea via https://developer.mozilla.org/en-US/docs/Web/API/Touch_events
  }
  more(lastel, 0);
}

<?php  
      $opa='';     
      $dllc='Draw Link Lines=D';
      $dllw='';
      $dllt='';
      $dllwbits='';
      $dlltbits='';
      if (isset($_GET['wlink'])) $dllw="Weather=W";
      if (isset($_POST['wlink'])) $dllw="Weather=W";
      if (isset($_GET['gmtoff']) && isset($_GET['tzname'])) {
        if (isset($_GET['rightnow'])) {
         $dllt="TimeZone " . urldecode($_GET['tzname']) . " (GMT " . str_replace("+-","-",("+" . $_GET['gmtoff'])) . ") (where it is " . urldecode($_GET['rightnow']) . ") Information=T";
        } else {
         $dllt="TimeZone " . urldecode($_GET['tzname']) . " (GMT " . str_replace("+-","-",("+" . $_GET['gmtoff'])) . ") Information=T";
        }
        $dlltbits="window.open('http://timezoneconverter.com/cgi-bin/zoneinfo?tz=" . urldecode($_GET['tzname']) . "','_blank');";
      }
      if (isset($_POST['gmtoff']) && isset($_POST['tzname'])) {
        if (isset($_POST['rightnow'])) {
         $dllt="TimeZone " . urldecode($_POST['tzname']) . " (GMT " . str_replace("+-","-",("+" . $_POST['gmtoff'])) . ") (where it is " . urldecode($_POST['rightnow']) . ") Information=T";
        } else {
         $dllt="TimeZone " . urldecode($_POST['tzname']) . " (GMT " . str_replace("+-","-",("+" . $_POST['gmtoff'])) . ") Information=T";
        }
        $dlltbits="window.open('http://timezoneconverter.com/cgi-bin/zoneinfo?tz=" . urldecode($_POST['tzname']) . "','_blank');";
      }
      if (isset($_GET['wlink'])) $dllwbits="window.open('" . urldecode($_GET['wlink']) . "','_blank');";
      if (isset($_POST['wlink'])) $dllwbits="window.open('" . urldecode($_POST['wlink']) . "','_blank');";
      $GETtp="";
      if (isset($_GET['tp'])) $GETtp = urldecode($_GET['tp']);
      if (isset($_POST['tp'])) $GETtp = urldecode($_POST['tp']);
      if ($GETtp != "") echo "\n talkingpoint=String.fromCharCode(10) + String.fromCharCode(10) + " . '"' . str_replace("`", '" + String.fromCharCode(10) + "', str_replace("\n", '" + String.fromCharCode(10) + "', $GETtp)) . '"' . " + String.fromCharCode(10) + String.fromCharCode(10); \n";

      $GETr = "";
      $GETc = "";
      if (isset($_GET['r'])) $GETr = urldecode($_GET['r']);
      if (isset($_POST['r'])) $GETr = urldecode($_POST['r']);
      if (isset($_GET['c'])) $GETc = urldecode($_GET['c']);
      if (isset($_POST['c'])) $GETc = urldecode($_POST['c']);
      if ($GETr != "") echo "\n ir=eval('" . $GETr . "'); \n";
      if ($GETc != "") echo "\n ic=eval('" . $GETc . "'); \n";

      $GETx = "";
      $GETy = "";
      if (isset($_GET['x'])) $GETx = urldecode($_GET['x']);
      if (isset($_POST['x'])) $GETx = urldecode($_POST['x']);
      if (isset($_GET['y'])) $GETy = urldecode($_GET['y']);
      if (isset($_POST['y'])) $GETy = urldecode($_POST['y']);
      if ($GETx != "" && $GETy != "") {
        echo "\n x=eval('" . $GETx . "'); \n";
        echo "\n y=eval('" . $GETy . "'); \n";
      }

      $GETtitle = "Places";
      $GETlabel = "['Lat',";
      $GETvalue = "'Lon', 'Name']";
      $GETdata = ",[37.4232, -122.0853, 'Work'],[37.4289, -122.1697, 'University'],[37.6153, -122.3900, 'Airport'],[37.4422, -122.1731, 'Shopping']";
            
      if (isset($_GET['value'])) {
       $GETtitle = $_GET['title'];
       $GETlabel = str_replace("\\","",$_GET['label']);
       $GETvalue = str_replace("\\","",$_GET['value']);
       $GETdata = tzlook($_GET['data']);
      } else if (isset($_POST['value']) && isset($_POST['wellinever'])) {
       $GETtitle = urldecode($_POST['title']);
       $GETlabel = str_replace("\\","",urldecode($_POST['label']));
       $GETvalue = str_replace("\\","",urldecode($_POST['value']));
       $GETdata = tzlook(urldecode($_POST['data']));
      }
      
      
      $hdgs = split(",", $GETvalue);
      $GETval = "";
      if (isset($hdgs[0])) $GETval = "'" . str_replace("'", "", $hdgs[0]) . "'";
      if (isset($hdgs[1])) $GETval .= ",'" . str_replace("'", "", $hdgs[1]) . "'";
      if (isset($hdgs[2])) $GETval .= ",'" . str_replace("'", "", $hdgs[2]) . "'";
      if (isset($hdgs[3])) $GETval .= ",'" . str_replace("'", "", $hdgs[3]) . "'";
      
      $ifoeo="";
      
      echo "var data, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata);\n";
      echo "var xparamdata=\"" . str_replace('"',"'",$GETdata) . "\";\n";
      $GETonclick = "";
      if (isset($_GET['onclick'])) $GETonclick = urldecode($_GET['onclick']) + " ";
      if (isset($_POST['onclick'])) $GETonclick = urldecode($_POST['onclick']) + " ";
      $GETlines = "";
      $GETlinescall = "";
      if (isset($_GET['lines'])) $GETlines = "\n if (eval(prevx) >= 0 && eval(prevy) >= 0 && eval(x) >= 0 && eval(y) >= 0) { setTimeout(draw_a_line,500); } \n";
      if (isset($_POST['lines'])) $GETlines =  "\n if (eval(prevx) >= 0 && eval(prevy) >= 0 && eval(x) >= 0 && eval(y) >= 0) { setTimeout(draw_a_line,500); } \n";
      if ($GETlines != "") $GETlinescall = "\n postcollectclick(olat + '~' + olong + '~' + oplace); \n";
      if ($GETlines != "") $dllc='Link Lines Pen Up=D';
      if ($GETlines != "") $opa='opacity:0.8;';
      echo "\n dllc='" . $dllc . "'; \n";
      if ($dllw != "") echo "\n dllw='" . $dllw . "' + String.fromCharCode(10) + String.fromCharCode(10); \n";
      if ($dllwbits != "") echo "\n dllwbits=\"" . str_replace('"',"'",$dllwbits) . "\" + String.fromCharCode(10) + String.fromCharCode(10); \n";
      if ($dllt != "") echo "\n dllt='" . $dllt . "' + String.fromCharCode(10) + String.fromCharCode(10); \n";
      if ($dlltbits != "") echo "\n dlltbits=\"" . str_replace('"',"'",$dlltbits) . "\" + String.fromCharCode(10) + String.fromCharCode(10); \n";
      echo " var selonclick='" . $GETonclick . str_replace("\n","",$GETlines) . "';\n";
      echo " google.load('visualization', '1', {packages:['map']}); " . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
 if ((isset($_GET['value']) || isset($_POST['value'])) && (isset($_GET['tooltip']) || isset($_POST['tooltip']) || strpos($GETdata, "'") !== false || strpos($GETdata, '"') !== false)) {
  echo "     data = new google.visualization.DataTable(); /" . "/" . $GETlabel . $GETvalue . " \n";
  echo "   data.addColumn('number', '" . str_replace("'","",str_replace(",","",str_replace("['","",$GETlabel))) . "');  \n";
  //echo "   data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});  \n";
  echo "   data.addColumn('number', " . str_replace(",", "); data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}}); data.addColumn('string', ", str_replace("]","",$GETvalue)) . ");  \n";
  echo " data.addRows([ \n";
      echo str_replace("''" . "''", "''", str_replace("~", "'", substr($GETdata,1)));
  echo "   ]); \n";
 } else {
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
      echo " " . $GETlabel . $GETvalue . " \n";
      echo str_replace("''" . "''", "''", str_replace("~", "'", $GETdata));
      echo "        ]);\n";
 }
      
      //echo "        var options = { \n";
      //if (isset($hdgs[3])) {
      //echo "        title: '" . $GETtitle . "', \n";
      //echo "        hAxis: {title: '" . $hdgs[0] . "'}," . " \n";
      //echo "        vAxis: {title: '" . $hdgs[1] . "'}," . " \n";
      //echo "        Map: {textStyle: {fontSize: 11}} \n";
      //} else {
      //echo "        colorAxis: {colors: ['yellow', 'red']} \n";
      //}
      //echo "       }; \n";

      
      if ($GETlines != "" && (!isset($_GET['onclick']) && !isset($_POST['onclick']))) $ifoeo=" if (1 == 2) ";
      
      echo "\n ifoeo='" . $ifoeo . "'; \n";


      echo " chart = new google.visualization.Map(document.getElementById('chart_div')); \n";
      //echo " chart.draw(data, {showTip: true, focusTarget: 'category', tooltip: {isHtml: true}}); \n } \n";
      //echo " chart.draw(data, {focusTarget: 'category',  tooltip: {isHtml: true}, showTip: true}); \n } \n";
      //echo " chart.draw(data, {focusTarget: 'category',  tooltip.isHtml: true, showTip: true}); \n } \n";
      //echo " chart.draw(data, { tooltip: {isHtml: true}, showTip: true }); \n } \n";
      $GEToptions = "";
      if (isset($_GET['options'])) $GEToptions = urldecode($_GET['options']);
      if (isset($_POST['options'])) $GEToptions = urldecode($_POST['options']);
      echo " chart.draw(data, { useMapTypeControl:true, tooltip: {isHtml: true}" . $GEToptions . ", showTip: true  }); \n"; // } \n";
  $cssis="";
      if ($GETr != "" && $GETc == "") $cssis=" if (1 == 2) { chart.setSelection([{'row': " . $GETr . "}]); } setTimeout(selectHandler,4100); \n";
      if ($GETr == "" && $GETc != "") $cssis=" if (1 == 2) { chart.setSelection([{'column': " . $GETc . "}]); }  setTimeout(selectHandler,4100); \n";
      if ($GETr != "" && $GETc != "") $cssis=" if (1 == 2) { chart.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]); }  setTimeout(selectHandler,4100); \n";

echo "
 if (selonclick != '') { " . $cssis . "
  google.visualization.events.addListener(chart, 'select', selectHandler);
 }
}

function getirplace(idea) {
  var qpbirs=paramdata.split('[');
  if (paramdata == '') qpbirs=xparamdata.split('[');
  var xqpbirs;
  if (eval(1 + ir) >= qpbirs.length) {
    //alert(paramdata);
    return idea;
  }
  if (qpbirs[eval(1 + ir)].indexOf('~') != -1) {
    xqpbirs=qpbirs[eval(1 + ir)].split('~');
    return xqpbirs[1];
  }
  return qpbirs[eval(1 + ir)].split(',')[2];
}

function getirlat(idea) {
  var qpbirs=paramdata.split('[');
  if (paramdata == '') qpbirs=xparamdata.split('[');
  if (eval(1 + ir) >= qpbirs.length) {
    //alert(paramdata);
    return idea;
  }
  return qpbirs[eval(1 + ir)].split(',')[0];
}

function getirlong(idea) {
  var qpbirs=paramdata.split('[');
  if (paramdata == '') qpbirs=xparamdata.split('[');
  if (eval(1 + ir) >= qpbirs.length) {
    //alert(paramdata);
    return idea;
  }
  return qpbirs[eval(1 + ir)].split(',')[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 ourdist;
}

function distmore(tofrominfo1) {
    var twoplaces=tofrominfo1.split('_');
    if (twoplaces.length > 1 && tofrominfo1.indexOf(' km)') == -1) {
     for (var ipl=1; ipl<twoplaces.length; ipl++) {
       qbitsare=twoplaces[eval(-1 + ipl)].split('~');
       qlatfrom=eval(qbitsare[0]);
       qlongfrom=eval(qbitsare[1]);
       qplacefrom=twoplaces[eval(-1 + ipl)].replace(qlatfrom + '~' + qlongfrom + '~','').replace(/~/g, ' ');
       qbitsare=twoplaces[ipl].split('~');
       qlatto=eval(qbitsare[0]);
       qlongto=eval(qbitsare[1]);
       qplaceto=twoplaces[ipl].replace(qlatto + '~' + qlongto + '~','').replace(/~/g, ' ');
       var dis=Math.floor(eval(eval(0.001 * great_circle_distance(qlatfrom,qlongfrom,qlatto,qlongto)) + 0.5));
       return tofrominfo1 + ' (' + dis + ' km)';
     }
    }
    return tofrominfo1;
}

function more(svgo,dmode) {
  var qlatfrom=0, qlongfrom=0, qplacefrom='', qlatto=0, qlongto=0, qplaceto='', qbitsare, dih='', dihs, ds;
  if (svgo) {
  dihs=document.body.innerHTML.split('<svg id=' + String.fromCharCode(34) + 's' + svgo.id + '' + String.fromCharCode(34) + '');
  if (dihs.length > 1) {
  dih=dihs[1];
  } else if (document.getElementById('s' + svgo.id)) {
  dih=document.getElementById('s' + svgo.id).innerHTML;
  } 
  var tofrominfo=dih.replace('</title>','<title>').split('<title>');
  if (tofrominfo.length > 1) {
    var twoplaces=tofrominfo[1].split('_');
    if (twoplaces.length > 1) {
     for (var ipl=1; ipl<twoplaces.length; ipl++) {
       qbitsare=twoplaces[eval(-1 + ipl)].split('~');
       qlatfrom=eval(qbitsare[0]);
       qlongfrom=eval(qbitsare[1]);
       qplacefrom=twoplaces[eval(-1 + ipl)].replace(qlatfrom + '~' + qlongfrom + '~','').replace(/~/g, ' ');
       qbitsare=twoplaces[ipl].split('~');
       qlatto=eval(qbitsare[0]);
       qlongto=eval(qbitsare[1]);
       qplaceto=twoplaces[ipl].replace(qlatto + '~' + qlongto + '~','').replace(/~/g, ' ');
       if (qplaceto.indexOf(' km)') != -1 && qplaceto.indexOf(' (') != -1) {
         ds=qplaceto.split(' (');
         qplaceto=ds[0];
       }
       if (Math.floor(eval(eval(0.001 * great_circle_distance(qlatfrom,qlongfrom,qlatto,qlongto)) + 0.5)) > 0) {
       if (dmode == 0) {
        document.title=Math.floor(eval(eval(0.001 * great_circle_distance(qlatfrom,qlongfrom,qlatto,qlongto)) + 0.5)) + ' kilometres separate ' + qplacefrom + ' (' + qlatfrom + ',' + qlongfrom + ') from ' + qplaceto + ' (' + qlatto + ',' + qlongto + ') as the crow flies.';
        document.getElementById('dh1').innerHTML='<font size=1>' + 'As the crow flies it is ' + Math.floor(eval(eval(0.001 * great_circle_distance(qlatfrom,qlongfrom,qlatto,qlongto)) + 0.5)) + ' kilometres from ' + qplacefrom + ' (' + qlatfrom + ',' + qlongfrom + ') to ' + qplaceto + ' (' + qlatto + ',' + qlongto + ').' + '</font>';
       } else {
        alert('As the crow flies it is ' + Math.floor(eval(eval(0.001 * great_circle_distance(qlatfrom,qlongfrom,qlatto,qlongto)) + 0.5)) + ' kilometres from ' + qplacefrom + ' (' + qlatfrom + ',' + qlongfrom + ') to ' + qplaceto + ' (' + qlatto + ',' + qlongto + ').');
       }
       }
     }
    }
  }
  }
}

function collectclick(event) {
       if (event.clientX || event.clientY) {
       posx = event.clientX - elemLeft;
       posy = event.clientY - elemTop;
       } else {
       posx = event.pageX - elemLeft;
       posy = event.pageY - elemTop;
       }
}

function postcollectclick(aplace) {
       if (eval(x) >= 0 && eval(y) >= 0) {
       if (  eval((eval(posx) - eval(x)) * (eval(posx) - eval(x)) +  (eval(posy) - eval(y)) * (eval(posy) - eval(y)) ) > 5) {
        lastplace=thisplace;
        prevx=x;
        prevy=y;
       } else {
        prevx=-1;
        prevy=-1;
       }
       }
       x = posx;
       y = posy;
       thisplace=aplace.replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~').replace(' ','~');
       if (lastplace != '') lasttrip=lastplace + '_' + thisplace;
       " . $GETlines . "       
}

function selectHandler() {
  var relist=['remail',''],ire,andthen='', str, oplace='', numthing='4', ansbits,avblurb=talkingpoint,ans='',mc,mctwo;
  var selection = chart.getSelection();
  var jj=eval(selection.length);
  if (jj == 0 && (eval(ir) >= 0 || eval(ic) >= 0)) jj=1;
  var clong, message = '', olat='-190.0', olong='-190.0', latlongs, delim='',ij;
  var documentheadinnerHTML=document.head.innerHTML;
  mc=documentheadinnerHTML.split('data.a' + 'ddRows([');
  if (mc.length == 2) {
    documentheadinnerHTML=mc[1].replace('[',',[');
  } 
  for (var i = 0; i < jj; i++) {
    var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      str = data.getFormattedValue(ir, 0);
      latlongs=documentheadinnerHTML.replace(/, \[/g,',[').split(',['); // + str + ',');
      olat=eval(str);
      if (1 == 1) {
        oplace='';
        mc=latlongs[eval(1 + ir)].split('>');
        if (mc.length > 1) {
          mctwo=mc[1].split('<');
          oplace=mctwo[0];
        }
        clong=latlongs[eval(1 + ir)].replace(str + ',', '').replace(']',',').split(',');
        olong=eval(clong[0]);
        if (oplace == '') oplace=clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'');
      } else if (eval(eval(latlongs.length) - eval(ir)) == 2) {
        clong=latlongs[eval(1 + ir)].replace(']',',').split(',');
        olong=eval(clong[0]);
        oplace=clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'');
      } else if (eval(eval(latlongs.length) - eval(ir)) > 2) {
        olong='';
        oplace='()';
        for (ij=1; ij<latlongs.length; ij++) {
         clong=latlongs[ij].replace(']',',').split(',');
         olong+=(delim + eval(clong[0]));
         oplace=oplace.replace(')',(delim + (clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'')) + ')'));
         if (delim == '' && selonclick.length > 0 && eval(olong) >= -180.0 && eval(olong) <= 180.0 && eval(olat) >= -90.0 && eval(olat) <= 90.0) {
          andthen=' ';
         } else if (delim == '') {
          oplace='';
         }
         delim=',';
        }
        if (andthen == ' ') {
         andthen='';
         clong=olong.split(',');
         if (ifoeo == '') {
           
           var tprop='';
           if (topdocumentURL.indexOf('rjmprogramming.com.au') != -1) {
           if (top.document.getElementById('mapphpmailbox')) {
             if (parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_'))) {
              tprop=parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_')).title;
              if (top.document.getElementById('mapphpmailbox').value.indexOf(tprop) == -1) {
                if (top.document.getElementById('mapphpmailbox').value == '') {
                  top.document.getElementById('mapphpmailbox').value=tprop;
                } else {
                  top.document.getElementById('mapphpmailbox').value+=';' + tprop;
                }
                tprop=String.fromCharCode(10) + 'As you click multiple places see TimeZone Places supervisor dropdown options' + String.fromCharCode(10);
              }
             }
           }
           }
           
           andthen=prompt('Is there something you want to try with Latitude ' + olat + ' and one of Longitudes ' + ('(' + olong + ')').replace('(','([').replace(',','],') + '' + oplace.replace('(','([').replace(',','],').split('|')[0] + ' ? ' + String.fromCharCode(10) + '' + String.fromCharCode(10) + avblurb + '' + 'Google Map=G (optional, plus zoom factor[10])' + String.fromCharCode(10) + '' + 'Sun Angle at Noon=S' + String.fromCharCode(10) + 'Moon Angle at Noon=M' + String.fromCharCode(10) + 'Coriolis Force=C' + String.fromCharCode(10) + '' + 'Nearest Airports=A (optional, plus number of nearest airports[4])' + String.fromCharCode(10) + '' + dllc + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + tprop + String.fromCharCode(10) + dllw + dllt + '' + '... and please suffix answer by comma and preferred Longitude to use, else leave as blank or as is or choose Cancel to leave the status quo.', paramdata);
         }
         if (andthen == null) andthen='';
         if (andthen.indexOf(',') == -1 && andthen != '') {
           olong=eval(clong[0]);
         } else if (andthen != '') {
           clong=andthen.split(',');
           olong=eval(clong[1]);
           andthen=clong[0];
         }
        }
      }
         " . $GETlinescall . "       
    } else if ((item.row != null && item.column != null) || (eval(ir) >= 0 && eval(ic) >= 0)) {
      if (eval(ir) >= 0 && eval(ic) >= 0) {
  //alert(999);
        item.row=ir;
        item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
        ir=item.row;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(item.row, item.column);
      clong = str.replace('[','').replace(']','').replace('{','').replace('}','').split(',');
      olat=eval(clong[0]);
      olong=eval(clong[1]);
         " . $GETlinescall . "       
    } else if ((item.row != null) || (eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        item.row=ir;
        //item.column=ic;
  //alert(9999);
        ir=-1;
        //ic=-1;
      } else {
        ir=item.row;
        //ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(item.row, 0);
      latlongs=documentheadinnerHTML.replace(/, \[/g,',[').split(',['); // + str + ',');
      olat=eval(str);
      if (1 == 1) {
        oplace='';
        mc=latlongs[eval(1 + item.row)].split('>');
        if (mc.length > 1) {
          mctwo=mc[1].split('<');
          oplace=mctwo[0];
        }
        clong=latlongs[eval(1 + item.row)].replace(str + ',', '').replace(']',',').split(',');
        olong=eval(clong[0]);
        if (oplace == '') oplace=clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'');
      } else if (eval(eval(latlongs.length) - eval(item.row)) == 2) {
        clong=latlongs[eval(1 + item.row)].replace(']',',').split(',');
        olong=eval(clong[0]);
        oplace=clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'');
      } else if (eval(eval(latlongs.length) - eval(item.row)) > 2) {
        olong='';
        oplace='()';
        for (ij=1; ij<latlongs.length; ij++) {
         clong=latlongs[ij].replace(']',',').split(',');
         olong+=(delim + eval(clong[0]));
         oplace=oplace.replace(')',(delim + (clong[1].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'')) + ')'));
         if (delim == '' && selonclick.length > 0 && eval(olong) >= -180.0 && eval(olong) <= 180.0 && eval(olat) >= -90.0 && eval(olat) <= 90.0) {
          andthen=' ';
         } else if (delim == '') {
          oplace='';
         }
         delim=',';
        }
        if (andthen == ' ') {
         andthen='';
         clong=olong.split(',');
         if (ifoeo == '') {
         
           var tptrop='';
           if (topdocumentURL.indexOf('rjmprogramming.com.au') != -1) {
           if (top.document.getElementById('mapphpmailbox')) {
             if (parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_'))) {
              tptrop=parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_')).title;
              if (top.document.getElementById('mapphpmailbox').value.indexOf(tprop) == -1) {
                if (top.document.getElementById('mapphpmailbox').value == '') {
                  top.document.getElementById('mapphpmailbox').value=tptrop;
                } else {
                  top.document.getElementById('mapphpmailbox').value+=';' + tptrop;
                }
                tptrop=String.fromCharCode(10) + 'As you click multiple places see TimeZone Places supervisor dropdown options' + String.fromCharCode(10);
              }
             }
           }
           }

           andthen=prompt('Is there something you want to try with Latitude ' + olat + ' and one of Longitudes ' + ('(' + olong + ')').replace('(','([').replace(',','],') + '' + oplace.replace('(','([').replace(',','],').split('|')[0] + ' ? ' + String.fromCharCode(10) + '' + String.fromCharCode(10) + avblurb + '' + 'Google Map=G (optional, plus zoom factor[10])' + String.fromCharCode(10) + '' + 'Sun Angle at Noon=S' + String.fromCharCode(10) + 'Moon Angle at Noon=M' + String.fromCharCode(10) + 'Coriolis Force=C' + String.fromCharCode(10) + '' + 'Nearest Airports=A (optional, plus number of nearest airports[4])' + String.fromCharCode(10) + '' + dllw + maybeir(dllt,ir) + dllc + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + tptrop + String.fromCharCode(10) + '' + '... and please suffix answer by comma and preferred Longitude to use, else leave as blank or as is or choose Cancel to leave the status quo.', paramdata);
         }
         if (andthen == null) andthen='';
         if (andthen.indexOf(',') == -1 && andthen != '') {
           olong=eval(clong[0]);
         } else if (andthen != '') {
           clong=andthen.split(',');
           olong=eval(clong[1]);
           andthen=clong[0];
         }
        }
      }
         " . $GETlinescall . "       
    } else if ((item.column != null) || (eval(ir) < 0 && eval(ic) >= 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        //item.row=ir;
        item.column=ic;
  //alert(9999);
        //ir=-1;
        ic=-1;
      } else {
        //ir=item.row;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(0, item.column);
      latlongs=documentheadinnerHTML.split(',' + str + ',');
      olong=eval(str);
      if (eval(latlongs.length) == 2) {
        clong=latlongs[0].split('[');
        olat=eval(clong[eval(-1 + clong.length)]);
        clong=latlongs[1].split(']');
        oplace=clong[0].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'');
      } else if (eval(latlongs.length) > 2) {
        olat='';
        oplace='()';
        for (ij=1; ij<latlongs.length; ij++) {
         clong=latlongs[ij].replace(']',',').split(',');
         oplace=oplace.replace(')',(delim + (clong[0].replace(String.fromCharCode(39),'').replace(String.fromCharCode(39),'')) + ')'));
         clong=latlongs[eval(-1 + ij)].replace(']',',').split('[');
         olat+=(delim + eval(clong[eval(-1 + clong.length)]));
         if (delim == '' && selonclick.length > 0 && eval(olong) >= -180.0 && eval(olong) <= 180.0 && eval(olat) >= -90.0 && eval(olat) <= 90.0) {
          andthen=' ';
         } else if (delim == '') {
          oplace='';
         }
         delim=',';
        }
        if (andthen == ' ') {
         andthen='';
         clong=olat.split(',');
         if (ifoeo == '') {
         
           var xtprop='';
           if (topdocumentURL.indexOf('rjmprogramming.com.au') != -1) {
           if (top.document.getElementById('mapphpmailbox')) {
             if (parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_'))) {
              xtprop=parent.document.getElementById('aof_' + oplace.replace('(','([').replace(',','],').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_')).title;
              if (top.document.getElementById('mapphpmailbox').value.indexOf(tprop) == -1) {
                if (top.document.getElementById('mapphpmailbox').value == '') {
                  top.document.getElementById('mapphpmailbox').value=xtprop;
                } else {
                  top.document.getElementById('mapphpmailbox').value+=';' + xtprop;
                }
                xtprop=String.fromCharCode(10) + 'As you click multiple places see TimeZone Places supervisor dropdown options' + String.fromCharCode(10);
              }
             }
           }
           }
           
           andthen=prompt('Is there something you want to try with one of Latitudes ' + ('(' + olat + ')').replace('(','([').replace(',','],') + ' and Longitude ' + olong + ' ' + oplace.replace('(','([').replace(',','],').split('|')[0] + ' ? ' + String.fromCharCode(10) + '' + String.fromCharCode(10) + avblurb + '' + 'Google Map=G (optional, plus zoom factor[10])' + String.fromCharCode(10) + '' + 'Sun Angle at Noon=S' + String.fromCharCode(10) + 'Moon Angle at Noon=M' + String.fromCharCode(10) + 'Coriolis Force=C' + String.fromCharCode(10) + '' + 'Nearest Airports=A (optional, plus number of nearest airports[4])' + String.fromCharCode(10) + '' + dllw + maybeir(dllt,ir) + dllc + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + xtprop + String.fromCharCode(10) + '' + '... and please suffix answer by comma and preferred Latitude to use, else leave as blank or as is or choose Cancel to leave the status quo.', paramdata);
         }
         if (andthen == null) andthen='';
         if (andthen.indexOf(',') == -1 && andthen != '') {
           olat=eval(clong[0]);
         } else if (andthen != '') {
           clong=andthen.split(',');
           olat=eval(clong[1]);
           andthen=clong[0];
         }
        }
      }
         " . $GETlinescall . "       
    }
  }
  if (selonclick.length > 0 && eval(olong) >= -180.0 && eval(olong) <= 180.0 && eval(olat) >= -90.0 && eval(olat) <= 90.0) {
    if (andthen == '' && ifoeo == '') {
      olat=getirlat(olat);  // new idea as of September, 2016
      olong=getirlong(olong);
      oplace=getirplace(oplace);

           var ytprop='';
           if (topdocumentURL.indexOf('rjmprogramming.com.au') != -1) {
           if (top.document.getElementById('mapphpmailbox')) {
             if (parent.document.getElementById('aof_' + oplace.replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_'))) {
              ytprop=parent.document.getElementById('aof_' + oplace.replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_').replace(' ','_')).title;
              if (top.document.getElementById('mapphpmailbox').value.indexOf(tprop) == -1) {
                if (top.document.getElementById('mapphpmailbox').value == '') {
                  top.document.getElementById('mapphpmailbox').value=ytprop;
                } else {
                  top.document.getElementById('mapphpmailbox').value+=';' + ytprop;
                }
                ytprop=String.fromCharCode(10) + 'As you click multiple places see TimeZone Places supervisor dropdown options' + String.fromCharCode(10);
              }
             }
           }
           }

      andthen=prompt('Is there something you want to try with Latitude ' + olat + ' and Longitude ' + olong + ' ' + oplace.split('|')[0] + ' ? ' + String.fromCharCode(10) + '' + String.fromCharCode(10) + avblurb + '' + 'Google Map=G (optional, plus zoom factor[10])' + String.fromCharCode(10) + '' + 'Sun Angle at Noon=S' + String.fromCharCode(10) + 'Moon Angle at Noon=M' + String.fromCharCode(10) + 'Coriolis Force=C' + String.fromCharCode(10) + '' + 'Nearest Airports=A (optional, plus number of nearest airports[4])' + String.fromCharCode(10) + '' + dllw + maybeir(dllt,ir) + dllc + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + ytprop + String.fromCharCode(10) + '' + '...  else leave as blank or as is or choose Cancel to leave the status quo.', paramdata);
    }
    if (andthen == null) andthen='';
  }
  
  if (andthen.length > 0) {
    if (andthen.toLowerCase().substring(0,1) == 'd')  {
     if (dllc != 'Draw Link Lines=D') {
      x=-1; 
      y=-1; 
      prevx=-1; 
      prevy=-1; 
      andthen='';
     } else {
      andthen=paramdata + '&lines=y';
     }
    }
    if ((andthen.toLowerCase() + '~').indexOf('.csv~') != -1 && andthen.toLowerCase().indexOf('&') == -1) andthen=paramdata + '&csv=' + andthen;
    ans=andthen;
    ansbits=ans.split(' ');
    
                  if (document.getElementById('altemail')) {
              document.getElementById('altemail').value=ansbits[0];
              document.getElementById('remail').href=document.getElementById('remail').href.replace('mt=','mt=' + ansbits[0] + '&junk=youshallneverfindthis').replace('get=','mt=' + ansbits[0] + '&junk=youshallneverfindthis');
              }
              if (document.getElementById('email')) relist[1]='email';

    
             if (ansbits[0].indexOf('@') != -1) {
               for (ire=0; ire<2; ire++) {
              if (relist[ire] != '') {
             document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace('fillin.email@address', ansbits[0]);
              if (item.row != null && document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&r=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&r=') + item.row;
              if (item.column != null && document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&c=') + item.column;
              if (ansbits.length > 1) {
                ans=ans.replace(ansbits[0] + ' ','');
                while (ans.indexOf(' ') != -1) {
                  ans=ans.replace(' ','%20');
                }
                while (ans.indexOf('?') != -1) {
                  ans=ans.replace('?','%3f');
                }
                while (ans.indexOf('&') != -1) {
                  ans=ans.replace('&','%26');
                }
                if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&tp=')) == -1 && document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('?tp=')) == -1) {
                  document.getElementById(relist[ire]).href+=encodeURIComponent('&tp=') + encodeURIComponent(ans);
                } else if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&tp=')) != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(encodeURIComponent('&tp='), encodeURIComponent('&tp=') + encodeURIComponent(ans) + String.fromCharCode(96));
				} else if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('?tp=')) != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(encodeURIComponent('?tp='), encodeURIComponent('?tp=') + encodeURIComponent(ans) + String.fromCharCode(96));
                }
                while (document.getElementById(relist[ire]).href.indexOf(' ') != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(' ','%20');
                }
                //alert(document.getElementById(relist[ire]).href);
              }
              document.getElementById(relist[ire]).click();
              }
              }
             } else if (andthen.toLowerCase().substring(0,1) == 'w') {
      " . $dllwbits . "
             } else if (andthen.toLowerCase().substring(0,1) == 't') {
      " . $dlltbits . "
             } else if (andthen.toLowerCase().substring(0,1) == 'a') {
      andthen=andthen.replace('a','').replace('A','');
      numthing='4';
      if ((andthen + ' ').substring(0,1) >= '1' && (andthen + ' ').substring(0,1) <= '9') {
       numthing=andthen;
      }
      //andthen=document.getElementById('chart_div').innerHTML;
      //alert('airports');
      document.getElementById('cdiv').innerHTML='<a id=mya href=#></a><iframe id=myiframe src=' + String.fromCharCode(34) + 'http://www.rjmprogramming.com.au/PHP/Map/map.php?title=Your%20Place%20and%20Airports&label=[%27Lat%27,&value=%27Lon%27,%27Name%27]&data=,[' + olat + ',' + olong + ',~' + encodeURIComponent(oplace) + '~]' + String.fromCharCode(34) + ' width=450 height=450></iframe><iframe id=mypiframe src=' + String.fromCharCode(34) + 'http://www.rjmprogramming.com.au/HTMLCSS/intair.php?num=' + numthing + String.fromCharCode(38) + 'lat=' + olat + String.fromCharCode(38) + 'long=' + olong + String.fromCharCode(34) + ' style=display:none></iframe>';
      //window.open('http://www.rjmprogramming.com.au/HTMLCSS/intair.php?num=' + numthing + '&lat=' + olat + '&long=' + olong, '_blank');
    } else if (andthen.toLowerCase().substring(0,1) == 'g') {
      andthen=andthen.replace('g','').replace('G','');
      numthing='10';
      if ((andthen + ' ').substring(0,1) >= '1' && (andthen + ' ').substring(0,1) <= '9') {
       numthing=andthen;
      }
      //alert('google map');
      if (('' + olat).indexOf('.') == -1) olat='' + olat + '.0';
      if (eval(olong) >= 0.0) olong='+' + olong;
      window.open('http://maps.google.com/maps?z=' + numthing + '&t=m&q=loc:' + olat + olong, '_blank','top=50,left=450,width=600,height=600');
    } else if (andthen.toLowerCase().substring(0,1) == 's') {
      var latss=('' + olat).split('.'), latd,latm=0,lats=0;
      if (latss.length == 1) {
        latd=eval(latss[0]);
      } else {
        latd=eval(latss[0]);
        latm=Math.floor(60.0 * eval('0.' + latss[1]));
        lats=Math.floor(eval(3600.0 * (Math.abs(eval(olat)) -  (Math.abs(eval(latd)) + eval(latm / 60.0)) )));
      }
      var longss=('' + olong).split('.'), longd,longm=0,longs=0;
      if (longss.length == 1) {
        longd=eval(longss[0]);
      } else {
        longd=eval(longss[0]);
        longm=Math.floor(60.0 * eval('0.' + longss[1]));
        longs=Math.floor(eval(3600.0 * (Math.abs(eval(olong)) -  (Math.abs(eval(longd)) + eval(longm / 60.0)) )));
      }
      window.open('http://www.rjmprogramming.com.au/PHP/SunAngle/sun_angle_now_at.php?latd=' + latd + '&latm=' + latm + '&lats=' + lats + '&longd=' + longd + '&longm=' + longm + '&longs=' + longs + '&from=from&done=y', '_blank','top=80,left=480,width=600,height=600');
    } else if (andthen.toLowerCase().substring(0,1) == 'm') {
      var latss=('' + olat).split('.'), latd,latm=0,lats=0;
      if (latss.length == 1) {
        latd=eval(latss[0]);
      } else {
        latd=eval(latss[0]);
        latm=Math.floor(60.0 * eval('0.' + latss[1]));
        lats=Math.floor(eval(3600.0 * (Math.abs(eval(olat)) -  (Math.abs(eval(latd)) + eval(latm / 60.0)) )));
      }
      var longss=('' + olong).split('.'), longd,longm=0,longs=0;
      if (longss.length == 1) {
        longd=eval(longss[0]);
      } else {
        longd=eval(longss[0]);
        longm=Math.floor(60.0 * eval('0.' + longss[1]));
        longs=Math.floor(eval(3600.0 * (Math.abs(eval(olong)) -  (Math.abs(eval(longd)) + eval(longm / 60.0)) )));
      }
      window.open('http://www.rjmprogramming.com.au/PHP/MoonAngle/moon_angle_now_at.php?latd=' + latd + '&latm=' + latm + '&lats=' + lats + '&longd=' + longd + '&longm=' + longm + '&longs=' + longs + '&from=from&done=y', '_blank','top=100,left=500,width=600,height=600');
    } else if (andthen.toLowerCase().substring(0,1) == 'c') {
      var latss=('' + olat).split('.'), latd,latm=0,lats=0;
      if (latss.length == 1) {
        latd=eval(latss[0]);
      } else {
        latd=eval(latss[0]);
        latm=Math.floor(60.0 * eval('0.' + latss[1]));
        lats=Math.floor(eval(3600.0 * (Math.abs(eval(olat)) -  (Math.abs(eval(latd)) + eval(latm / 60.0)) )));
      }
      var longss=('' + olong).split('.'), longd,longm=0,longs=0;
      if (longss.length == 1) {
        longd=eval(longss[0]);
      } else {
        longd=eval(longss[0]);
        longm=Math.floor(60.0 * eval('0.' + longss[1]));
        longs=Math.floor(eval(3600.0 * (Math.abs(eval(olong)) -  (Math.abs(eval(longd)) + eval(longm / 60.0)) )));
      }
      window.open('http://www.rjmprogramming.com.au/PHP/Coriolis/coriolis_force_at.php?latd=' + latd + '&latm=' + latm + '&lats=' + lats + '&longd=' + longd + '&longm=' + longm + '&longs=' + longs + '&from=from&done=y', '_blank','top=120,left=520,width=600,height=600');
    } else if (andthen != paramdata && andthen != '') {
      location.href=document.URL.replace(pardata, ourencodeURIComponent(andthen));
    }
  }
  ir=-1;
  ic=-1; 
}
";
      
      echo " </script> \n";
      echo " </head> \n";
      
      
      if (!isset($_GET['value']) && !isset($_POST['value'])) {
      echo " <body ontouchstart=' collectclick(event); ' onmousedown=' collectclick(event); ' onload='if (later) { setTimeout(later, 2 * 1000); }' style='background-color: silver;'> \n";
      } else {
      echo " <body ontouchstart=' collectclick(event); ' onmousedown=' collectclick(event); ' style='background-color: silver;'> \n";
      }
      echo " <h1 id='myh1'>" . $GETtitle . " Map <div id='dh1'></div></h1> \n";

      echo '<div id="chart_div" style="width: 400px; height: 300px;' . $opa . '" ontouchstart=" collectclick(event); " onmousedown=" collectclick(event); "></div>' . " \n";
      echo '<a title="Another Map" href="./map.php">Another Map?</a>' . '&nbsp;&nbsp;<a href="MAILTO:fillin.email@address?subject=Google%20Chart%20Snapshot&body=' . urlencode("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']) . '" style="display:inline;" title="To email a snapshot of this Google Chart click me." id="remail">Email snapshot of Google Chart ...</a>' . " \n";
      echo '<' . 'script' . ' type="text/javascript">' . "\n " . " function later() { \n"; 
      if (!isset($_GET['value']) && !isset($_POST['value'])) {
      
        echo ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var prethisline = "", extra = ""; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var ii = 0; ' . "\n";
        echo ' var thisdef = "0"; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";


        echo ' var title = prompt("Enter Map Title (suffix by &lines=y for overlay clickable link lines and/or suffix by &onclick=y for all types of onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        echo ' if (title != null) { ' . "\n";
        echo ' if (title.indexOf("&onclick=") != -1) { prethisline=" (note, here, suffix of |TimeZoneName|GMTOffset|TimeNow is recognized in the onclick select event prompt window later ... for example Sydney|Australia/Sydney|+11|12:32 uses this functionality) "; } ' . "\n";
        echo ' var label = "' . $GETlabel . '"; ' . "\n";
        echo ' if (label == null) label = ""; ' . "\n";
        echo ' var xlabel = "' . "'" . '" + label.replace("' . "'" . '","") + "' . "'" . '"; ' . "\n";
        //echo ' var value = prompt("Enter Map " + xlabel + " Criteria (separated by ,) ...  decimal latitude and longitude ", "' . $GETvalue . '"); ' . "\n";
        echo ' var value = "' . $GETvalue . '"; ' . "\n";


        echo ' if (value.indexOf(",") != (0 - 1)) { ' . "\n";
        echo '  for (ii=0; ii < value.length; ii++) { if (value.substring(ii,(ii+1)) == ",") { if (value.substring((ii+1),(ii+2)) == "' . "'" . '") {  thisdef = thisdef + ",' . "'0'" . '"; } else { thisdef = thisdef + ",0"; } } } ' . "\n";
        echo ' } ' . "\n";


        echo ' var dlsa, dlp2="", datac = ""; ' . "\n";
        echo ' var dataprefix2 = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = "' . "''" . '";' . "\n";
        echo ' if (label.length != 0) { datalineprefix2 = prompt("Enter ' . " " . $GETtitle . ' Name' . " " . ' " + prethisline + thisline, ""); if (datalineprefix2 != null) { dlp2=datalineprefix2; } } ' . "\n";


        echo ' while (datalineprefix.length != 0 && (value.indexOf("ercent") == (0 - 1) || value.indexOf("  ercent ") != (0 - 1) || (value.indexOf("ercent") != (0 - 1) && totalleft > 0))) { ' . "\n";
        echo ' datalineprefix = "' . "''" . '";' . "\n";
        echo ' if (datalinesuffix.length != 0 && label.length != 0) { datalineprefix = prompt("Enter ' . " " . $GETtitle . ' Name' . " " . ' " + prethisline + thisline + " (for no more hit Cancel button)", ""); if (datalineprefix != null) { datalineprefix2=""; dlp2=datalineprefix; } } ' . "\n";
        echo ' if (datalineprefix == null) { ' . "\n";
        echo '     datalineprefix = ""; ' . "\n";
        echo '     totalleft = 0; ' . "\n";
        echo ' } else if (datalineprefix.length != 0) { ' . "\n";
        echo '     extra = "";  ' . "\n";
        echo '     if (value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo "     datalinesuffix = prompt('Enter decimal Latitude,Longitude ' + thisline + extra +  ' (for no more hit Cancel button and append with ' + '\\n\\n' + ',\"A tooltip and clicking link for Google Map of <a target=_blank href=' + \"'\" + 'https://www.google.com.au/maps/place/' + encodeURIComponent(dlp2) + \"'\" + '>' + dlp2 + '</a>\" ' + '\\n\\n' + ' or maybe perhaps ' + '\\n\\n' + ',\"A tooltip and clicking link for Google Map based on latitude and longitude of <a target=_blank href=' + \"'\" + 'https://maps.google.com.au/maps?' + encodeURIComponent('z=15&t=m&q=loc:') + '{latitude}{longitude}' + \"'\" + '>' + dlp2 + '</a>\"' + '\\n\\n' + ' optionally (as (just) two examples of what is possible with HTML included (activates with onclick bit not onmouseover))', thisdef); " . "\n";
        echo '     if (datalinesuffix != null) { datalinesuffix=datalinesuffix.replace(/#/g, "%23");  if (datalinesuffix.indexOf("{latitude}") != -1) { dlsa=datalinesuffix.split(","); if (dlsa[0].indexOf(".") == -1) { dlsa[0]=dlsa[0]+".0";  } if (dlsa[0].indexOf("-") == -1) { datalinesuffix=datalinesuffix.replace("{latitude}",encodeURIComponent("" + dlsa[0]));  } else { datalinesuffix=datalinesuffix.replace("{latitude}",encodeURIComponent(dlsa[0]));  }  } if (datalinesuffix.indexOf("{longitude}") != -1) { dlsa=datalinesuffix.split(","); if (dlsa.length > 1) {  if (dlsa[0].indexOf(".") == -1) { dlsa[0]=dlsa[0]+".0";  }  if (dlsa[1].indexOf(".") == -1) { dlsa[1]=dlsa[1]+".0";  } if (dlsa[1].indexOf("-") == -1) { datalinesuffix=datalinesuffix.replace("{longitude}",encodeURIComponent("+" + dlsa[1]));  } else { datalinesuffix=datalinesuffix.replace("{longitude}","+" + encodeURIComponent(dlsa[1])); }  }  }  datalinesuffix=("@!@" + datalinesuffix).replace(/loc:+/g, "loc:").replace(/,0,/g, ",0.00000001,").replace(/@!@0,/g, "0.00000001,").replace(/@!@/g, "");    } ' . "\n";
        echo '     if (datalinesuffix == null && value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) datalinesuffix = totalleft; ' . "\n";
        echo '     if (datalinesuffix == null) break; ' . "\n";
        echo '     if (datalinesuffix == null) datalinesuffix = "0,0"; ' . "\n";
        echo '     if (datalinesuffix.length == 0) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(totalleft) == eval(datalinesuffix) && value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && value.indexOf("ercent") == (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       value = value + "  ercent "; ' . "\n";
        echo '     } else { ' . "\n";
        echo '       totalleft = eval(totalleft) - eval(datalinesuffix); ' . "\n";
        echo '     } ' . "\n";
        echo '     if (datalineprefix2 != "") datalineprefix = datalineprefix2;  ' . "\n";
        echo '     if (datalinesuffix.indexOf("' . "'" . '") == -1) datac = datac + ", [" + datalinesuffix + ",~" + datalineprefix + "~] "; ' . "\n";
        echo '     if (datalinesuffix.indexOf("' . "'" . '") != -1) datac = datac + ", [" + datalinesuffix + ",' . "'" . '" + datalineprefix + "~] "; ' . "\n";
        echo '     dataprefix2 = ""; ' . "\n";
        echo '     thisline++; ' . "\n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
        echo ' window.location = "./map.php?title=" + title + "&label=" + label + "&value=" + value.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
        echo "} \n"; 
      } 
      echo "} \n" . '</' . 'script' . '>' . "\n";
    ?>
  <a title='menu' href='http://www.rjmprogramming.com.au/PHP/butsel.php?justmenu=justmenu'>Menu</a>
  <div id='cdiv'></div><div id='xydiv'></div></body>
</html>
