<?php
  // intensity_chart.php
  // Google Intensity Chart supervisor
  // RJM Programming
  // November, 2015
  // 
  if (file_exists("csv.php")) {
    include "csv.php";
  } else if (file_exists("../csv.php")) { 
    include "../csv.php";
  }
  if (file_exists("bigemail.php")) {
    include "bigemail.php";
  } else if (file_exists("../bigemail.php")) { 
    include "../bigemail.php";
  }


$lastgo = "";

function server_remote_addr($inst) {
    global $lastgo;
    $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;
    if (isset($_GET['population'])) {
      $file_handle = fopen("TestIntensityChart_" . $rma . ".html", "w");
      fwrite($file_handle, $_SERVER['REQUEST_URI']);
      fclose($file_handle);
      $timesuff = date("Y-m-d-H-i-s");
      while (file_exists("IntensityChart_" . $rma . "_" . $timesuff . ".html")) {
       $timesuff = date("Y-m-d-H-i-s");
      }
      $file_handle = fopen("IntensityChart_" . $timesuff . ".html", "w");
      fwrite($file_handle, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="//www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script><meta http-equiv="Refresh" content="5;url=' . $_SERVER['REQUEST_URI'] . '"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" /> <link rel="stylesheet" href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /><script src="//code.jquery.com/jquery-1.8.2.min.js"></script><script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      if (file_exists("../GeoChart/geo_chart.php")) {
      $file_handle = fopen("../GeoChart/GeoChart_" . $timesuff . ".html", "w");
      fwrite($file_handle, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="//www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script><meta http-equiv="Refresh" content="5;url=' . $_SERVER['REQUEST_URI'] . '"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" /> <link rel="stylesheet" href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /><script src="//code.jquery.com/jquery-1.8.2.min.js"></script><script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      }
      $lastgo = "&nbsp;&nbsp;&nbsp;<a target=_blank title='Last Intensity Map' href='" . $_SERVER['REQUEST_URI'] . "'>Last</a>" . "&nbsp;&nbsp;<a href='mailto:rmetcalfe15@gmail.com?subject=Email Last Intensity Map link to " . $_GET['title'] . " //www.rjmprogramming.com.au/PHP/IntensityChart/IntensityChart_" . $timesuff . ".html" . "&body=Change Email Address then Email Last Intensity Map link to " . $_GET['title'] . " //www.rjmprogramming.com.au/PHP/IntensityChart/IntensityChart_" . $timesuff . ".html&cc=&bcc='>Email</a>&nbsp;&nbsp;<a style='display:none;' onclick='var qqq=document.getElementById(" . '"' . "ourw" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Width?' href='#'>W?</a>&nbsp;&nbsp;<a style='display:none;' onclick='var qqq=document.getElementById(" . '"' . "ourh" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Height?' href='#'>H?</a>&nbsp;&nbsp;<a title='Geo Map?' href='../GeoChart/geo_chart.php?isMobile=y'>-</a>";
      if (isset($_GET['isMobile'])) {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Intensity Map" href="./intensity_chart.php?isMobile=y">&nbsp;Another?</a>' . $lastgo . "\n";
      } else {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Intensity Map" href="./intensity_chart.php">&nbsp;Another?</a>';
      }
    } else if (strlen($inst) > 0 && file_exists("TestIntensityChart_" . $rma . ".url")) {
      $file_handle = fopen("TestIntensityChart_" . $rma . ".url", "r");
      $rma=fgets($file_handle);
      fclose($file_handle);
      $timesuff = date("Y-m-d-H-i-s");
      while (file_exists("IntensityChart_" . $rma . "_" . $timesuff . ".html")) {
       $timesuff = date("Y-m-d-H-i-s");
      }
      $file_handle = fopen("IntensityChart_" . $timesuff . ".html", "w");
      fwrite($file_handle, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="//www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script><meta http-equiv="Refresh" content="5;url=' . $rma . '"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" /> <link rel="stylesheet" href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /><script src="//code.jquery.com/jquery-1.8.2.min.js"></script><script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      if (file_exists("../GeoChart/geo_chart.php")) {
      $file_handle = fopen("../GeoChart/GeoChart_" . $timesuff . ".html", "w");
      fwrite($file_handle, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="//www.w3.org/1999/xhtml"><head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script><meta http-equiv="Refresh" content="5;url=' . $rma . '"><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" /> <link rel="stylesheet" href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /><script src="//code.jquery.com/jquery-1.8.2.min.js"></script><script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      }
      $rma = "&nbsp;&nbsp;&nbsp;<a target=_blank title='Last Intensity Map' href='" . $rma . "'>Last</a>" . "&nbsp;&nbsp;<a href='mailto:rmetcalfe15@gmail.com?subject=Email Last Intensity Map link to //www.rjmprogramming.com.au/PHP/IntensityChart/IntensityChart_" . $timesuff . ".html" . "&body=Change Email Address then Email Last Intensity Map link to //www.rjmprogramming.com.au/PHP/IntensityChart/IntensityChart_" . $timesuff . ".html&cc=&bcc='>Email</a>&nbsp;&nbsp;<a style='display:none;' onclick='var qqq=document.getElementById(" . '"' . "ourw" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Width?' href='#'>W?</a>&nbsp;&nbsp;<a style='display:none;' onclick='var qqq=document.getElementById(" . '"' . "ourh" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Height?' href='#'>H?</a>";
      if (isset($_GET['isMobile'])) {
      $rma .= '<br><br>&nbsp;&nbsp;<a title="Another Intensity Map" href="./intensity_chart.php?isMobile=y">&nbsp;Another?</a>' . $lastgo . "\n";
      } else {
      $rma .= '<br><br>&nbsp;&nbsp;<a title="Another Intensity Map" href="./intensity_chart.php">&nbsp;Another?</a>';
      }
      $lastgo = $rma;
    }
    return $rma;
}

  function retval($inv) {
    if (strpos($inv, "E-") !== false) return "0";
    return $inv;
  }


//localhost:8888/geo_chart.php?title=My%20World%20Population%20and%20Area%20Map&onclick=y&wxdth=300&hxeight=300&country=Country&area=Area%20%28km2%29&popularity=Population%20%28mil%29&data=%20[~IT~,56045]%200%20[~AU~,45067]&width=556&height=347

    echo '<!doctype html><html>' . "\n";
    echo '<head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script>' . "\n";
    echo '<title>Intensity Map - RJM Programming - //www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>' . "\n";
    echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\n";
    echo '<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" />' . "\n";
    echo '<script type="text/javascript" src="https://www.google.com/jsapi"></script>' . "\n";
    echo '<script type="text/javascript">' . "\n var exra=''; \n var comma=','; \n";

    echo "var alturl='',selection, item, ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint=''; \n";   
?>    
   var xpnum=1; // done here at supervisor
   var allowed=true; // done here at supervisor
   var nojwinextra=""; // done here at supervisor
<?php
  if (!isset($_POST['data'])) {
  echo "
   if (document.URL.indexOf('nojwin') == -1 && navigator.userAgent.match(/iPhone|iPad/i)) {
     if (document.URL.indexOf('?') == -1) {
       location.href=document.URL.split('#')[0] + '?nojwin=Q';
     } else {
       location.href=document.URL.split('#')[0] + '&nojwin=Q';
     }
   }
   ";
  }
?>
   if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     nojwinextra="&nojwinyes=Y";
   }

<?php
 echo "
  function selectevent(ans) {
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
             if (ansbits[0].indexOf('@') != -1) {
              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';
              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 (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&r=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&r=') + item.row;
              //if (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 (ans.substring(0,1).toLowerCase() == 'p') {
              location.href=document.URL.replace('/IntensityChart', '/PieChart').replace('intensity_chart.php', 'pie_chart.php');
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }  
  }
  
  function selecteventtwo(ans) {
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
             if (ansbits[0].indexOf('@') != -1) {
              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';
              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 (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&r=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&r=') + item.row;
              //if (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 (ans.substring(0,1).toLowerCase() == 'p') {
              location.href=document.URL.replace('/IntensityChart', '/PieChart').replace('intensity_chart.php', 'pie_chart.php');
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }  
  }
 ";

      $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";
?>

       alturl=document.URL.replace(/,/g,'.0000000000').replace('&c=','&c=0').replace('&r=','&r=0').replace(/~.0000000000/g,'~,').replace(/%20.0000000000%20/g,'%20,%20').replace(/\] .0000000000 \[/g,']' + ' , ' + ' [').replace('/IntensityChart','/GeoChart').replace('intensity_chart.php','geo_chart.php').replace('population=','popularity=').replace('width=','wxdth=').replace('height=','hxeight=').replace('data=,','data=').replace('data=.0000000000','data=') + '&width=556&height=347';
       while (alturl.indexOf("] .0000000000 [") != -1) {
         alturl=alturl.replace("] .0000000000 [","] " + "," + " [");
       }
       while (alturl.indexOf("%20.0000000000%20") != -1) {
         alturl=alturl.replace("%20.0000000000%20","%20,%20");
       }


<?php
 
    echo "var data, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata); \n";
 
      $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";

      $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";
      }

    echo "\n
    function saveSelection(e) {
    //alert(98);
  selection = chart.getSelection();
  item=selection[0];
        ir=e.row; 
  sliceid = ir;
  item.row=ir;
    }
    \n";
     
      $xgd = ""; 
      $gd = ""; 
      $ntt=false;
      $nondefs=" ";


      if (isset($_GET['population'])) server_remote_addr("");
      $GETtitle = "My World Population and Area Map";
      $GETcountry = "Country";
      $GETpopulation = "Population (mil)";
      $GETarea = "Area (km2)";      
      $GETdata = ",['CN',1324,9640821],['IN',1133,3287263],['US',304,9629091],['ID',232,1904569],['BR',187,8514877]";
      if (isset($_GET['isMobile']) || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
      $GETwidth = "300"; //"305";
      $GETheight = "300"; //"190";
      } else {
      $GETwidth = "300"; //"556";
      $GETheight = "300"; //"347";
      }
      if (isset($_GET['population'])) {
       $GETtitle = $_GET['title'];
       $GETcountry = $_GET['country'];
       $GETpopulation = $_GET['population'];
       $GETarea = $_GET['area'];
       $GETdata = strtoupper($_GET['data']);
       $GETwidth = $_GET['width'];
       $GETheight = $_GET['height'];
      }

      echo " var colnames= '" . $GETcountry . "," . str_replace("'", "", $GETpopulation) . "," . str_replace("'", "", $GETarea) . "'; \n";

      $nondefs="width: " . $GETwidth . ", height: " . $GETheight;
      $newextras.=$nondefs;
      
      echo "   var sliceid = 0; /" . "/ thanks to https://gist.github.com/alexrainman/bb8d49357250df0859c0  \n";
      echo "   var refresh=0; prerefresh=0;   \n";
      echo ' google.load("visualization", "1", {packages:["intensitymap"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
 if ((isset($_GET['data']) || isset($_POST['data'])) && (isset($_GET['tooltip']) || isset($_POST['tooltip']) || strpos($GETdata, "'") !== false || strpos($GETdata, '"') !== false)) {
      $ntt=true;
  //$newextras=$nondefs . ", focusTarget: 'category', tooltip: {isHtml: true} ";
  $newextras=$nondefs . ", tooltip: {isHtml: true}, showTip: true"; //, selectionMode: 'multiple', tooltip: {trigger: 'selection'}, aggregationTarget: 'none' ";
  echo "       var tooltip = [ \n";
  $bits=explode("~,", substr($GETdata,1));
  $delts="";
  for ($iy=1; $iy<sizeof($bits); $iy++) {
   $postbits=explode(",", $bits[$iy]);
   $xgd.=str_replace("%3C", "<", str_replace("%3E", ">", $postbits[0]));
   echo $delts . str_replace("%3C", "<", str_replace("%3E", ">", $postbits[0]));
   $delts=",";
  }
  echo "]; \n";
  $gd=$GETdata;
  for ($iy=1; $iy<sizeof($bits); $iy++) {
   $postbits=explode(",", $bits[$iy]);
   $gd=str_replace("," . $postbits[0] . "", "", $gd);
  }
  $GETdata=$gd;
  echo "     data = new google.visualization.DataTable();  \n";
  echo "   data.addColumn('string', '" . $GETcountry . "');  \n";
  //echo "   data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});  \n";
  $things=explode(",",$GETpopulation . ',' . $GETarea);
  for ($it=0; $it<sizeof($things); $it++) { 
    echo "   data.addColumn('number', '" . $things[$it] . "');  \n";
  }
  echo " data.addRows([ \n";
  //echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", substr($GETdata,1))))));
  echo str_replace("~", "'", substr($GETdata,1));
  echo "   ]); \n";
 } else {
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
      echo " ['" . $GETcountry . "','" . $GETpopulation . "','" . $GETarea . "'] \n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))));
      echo "        ]);\n";
 }
 
      echo " chart = new google.visualization.IntensityMap(document.getElementById('chart_div')); \n";

 if ($ntt) {
   
      //echo "   var selection; \n";

      echo "   function checkhere() { prerefresh++; if (prerefresh == 20) { if (refresh == 0) { refresh=1; document.getElementById('ihide').value=1;  } } \n";
      echo "   refresh=document.getElementById('ihide').value; if (refresh != 0) { prerefresh=0; refresh++; document.getElementById('ihide').value=refresh; if (refresh == 10) { var huhss=document.URL.split('&xx='); if (huhss.length == 1) {  top.location.href=document.URL + '&xx=1'; } else { var two=eval(huhss[1]); two++; top.location.href=huhss[0] + '&xx=' + two;  }  }    } setTimeout(checkhere,1000); \n } \n";

      echo "   checkhere(); \n";
  
      echo "   function eventHandler(e){ \n";
      //echo "     chart.setSelection([e]); \n";
      echo "     try { \n";
      echo "       selection = chart.getSelection(); \n";
      echo "       sliceid = selection[0].row; \n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(0)").css("font-weight", "bold"); ' . "\n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(1)").html(tooltip[sliceid]).css("font-family", "Arial");  ' . "\n";
      echo "     } \n";
      echo "     catch(err) { \n";
      echo "       ; \n";
      echo "     } \n";
      echo "   } \n";
  
      echo "   function ceventHandler(e){   \n";
      //echo "   google.visualization.events.addListener(chart, 'select', eventHandler); \n";
      //echo "     chart.setSelection([e]); \n";
      echo "     try { \n";
      echo "       selection = chart.getSelection(); \n";
      echo "       sliceid = selection[0].row; \n if (1 == 2) { alert(tooltip[sliceid]); } document.getElementById('chart_div').innerHTML+=' '; \n document.getElementById('ihide').value='1'; \n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(0)").css("font-weight", "bold"); ' . "\n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(1)").html(tooltip[sliceid]).css("font-family", "Verdana");  ' . "\n";
      echo "     } \n";
      echo "     catch(err) {   \n";
      echo "       ; \n";
      echo "     } \n";
      echo "   } \n";
  
  
      if (strpos($xgd, "<") !== false) {
        echo "   google.visualization.events.addListener(chart, 'select', ceventHandler); \n";
        echo "   google.visualization.events.addListener(chart, 'onmouseover', eventHandler);  \n";
      } else {
        echo "   google.visualization.events.addListener(chart, 'onmouseover', eventHandler); \n";
      }
}
      $GETonclick = "";
      if (isset($_GET['onclick'])) $GETonclick = urldecode($_GET['onclick']);
      if (isset($_POST['onclick'])) $GETonclick = urldecode($_POST['onclick']);
      if ($GETonclick != "") {
      echo " document.getElementById('geochart').innerHTML='<iframe style=\"width:600px;height:600px;\" id=mygeo src=' + alturl + '></iframe>'; document.getElementById('geochart').style.display='block'; " . "\n";
      echo "google.visualization.events.addListener(chart, 'ready', function() {  ready=true; }); \n";
      echo "google.visualization.events.addListener(chart, 'onmouseover', saveSelection); \n";
      echo "google.visualization.events.addListener(chart, 'select', myselectfunction); \n function myselectfunction(e) {
 if (ready) {
//alert(988);
  var relist=['remail',''],sl=0,ire,ansbits,avblurb=talkingpoint,ioffset=0,ans=null,doit=true,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues, str;
//alert(1988);
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
    sl=1;
    } else {
//alert(2988);
  selection = chart.getSelection();
//alert(3988);
  sliceid = selection[0].row;
  sl=selection.length;
    }

  for (var i = 0; i < sl; i++) {
    if ((eval(ir) < 0 && eval(ic) < 0)) {
     item = selection[i];
    }
    if ((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;
      }
      //document.title=str;
      message=document.head.innerHTML.replace('[' + String.fromCharCode(39),'[ ' + String.fromCharCode(39)).replace('[' + String.fromCharCode(39),', [' + String.fromCharCode(39)).substring(ioffset);
      while (message.indexOf(', [') != -1) {
       message=message.replace(', [',',[');
      }
      dparts=message.split(',[');
        //document.title='';
        colav.push(0.0);
      for (kl=1; kl<colparts.length; kl++) {
        //document.title=1;
        colav.push(0.0);
        doit=true;
        num=1;
        for (lk=1; lk<dparts.length; lk++) {
         if (doit) {
        //document.title=3;
         thisnum=dparts[lk].replace(']',',').split(',');
         //if (kl == 1) document.title+=4 + ' .. '  + eval(thisnum[kl]) + ' ... ' + lk + ' ... ' + colav[kl] + ' ... ' + thisnum.length + ' ... ' + dparts[lk];
         colav[kl] = eval(eval(colav[kl] * eval(-1 + num)) + eval(thisnum[kl])) / eval(0.0 + num);
        //document.title=5;
         if (dparts[lk].indexOf(';') != -1) doit=false;
         if (doit) num++;
         }
        }
        //document.title=7;
        if (avblurb == '') avblurb+=String.fromCharCode(10) + String.fromCharCode(10);
        //document.title=8;
        //avblurb+='Average ' + colparts[kl] + ' over ' + num + ' ' + colparts[0] + ' values is ' + colav[kl] + String.fromCharCode(10);
        //document.title=7;
      }
      if (avblurb != '') avblurb+=String.fromCharCode(10) + String.fromCharCode(10);
      if (eval(dparts.length) >= eval(1 + item.row)) {
        postdparts=dparts[eval(1 + item.row)].replace(']',',').split(',');
        if (eval(postdparts.length) >= eval(1 + item.column)) {
         if (eval(colparts.length) == 2) { 
          if (1 == 1) {
          avblurb+='Show this as Pie Chart=P' + String.fromCharCode(10) + String.fromCharCode(10);
          avblurb+='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) + '' + String.fromCharCode(10);
          avblurb+='Change data as required below (keeping it the same or being blank or choosing Cancel leaves the status quo)';
          ans=prompt('For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + avblurb, paramdata);
          if (ans != null) {
			selectevent(ans);
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while ' + colparts[eval(3 - item.column)] + ' were ' + postdparts[eval(3 - item.column)].replace(']','') + ' the difference being ' + eval(eval(postdparts[1].replace(']','')) - eval(postdparts[2].replace(']',''))) + avblurb);
          }
         }
        }
      }
    } 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);
      message += '{row:' + item.row + ',column:' + item.column + '} = ' + str;
    } 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);
      //document.title=str;
      //document.title=str;
      message=document.head.innerHTML.replace('[' + String.fromCharCode(39),'[ ' + String.fromCharCode(39)).replace('[' + String.fromCharCode(39),', [' + String.fromCharCode(39)).substring(ioffset);
      while (message.indexOf(', [') != -1) {
       message=message.replace(', [',',[');
      }
      dparts=message.split(',[');
        //document.title='';
        colav.push(0.0);
      for (kl=1; kl<colparts.length; kl++) {
        //document.title=1;
        colav.push(0.0);
        doit=true;
        num=1;
        for (lk=1; lk<dparts.length; lk++) {
         if (doit) {
        //document.title=3;
         thisnum=dparts[lk].replace(']',',').split(',');
         //if (kl == 1) document.title+=4 + ' .. '  + eval(thisnum[kl]) + ' ... ' + lk + ' ... ' + colav[kl] + ' ... ' + thisnum.length + ' ... ' + dparts[lk];
         colav[kl] = eval(eval(colav[kl] * eval(-1 + num)) + eval(thisnum[kl])) / eval(0.0 + num);
        //document.title=5;
         if (dparts[lk].indexOf(';') != -1) doit=false;
         if (doit) num++;
         }
        }
        //document.title=7;
        if (avblurb == '') avblurb+=String.fromCharCode(10) + String.fromCharCode(10);
        //document.title=8;
        //avblurb+='Average ' + colparts[kl] + ' over ' + num + ' ' + colparts[0] + ' values is ' + colav[kl] + String.fromCharCode(10);
        //document.title=7;
      }
      if (avblurb != '') avblurb+=String.fromCharCode(10) + String.fromCharCode(10);
      if (eval(dparts.length) >= eval(1 + item.row)) {
        postdparts=dparts[eval(1 + item.row)].replace(']',',').split(',');
        if (eval(postdparts.length) >= eval(1 + item.column)) {
         if (eval(colparts.length) == 2) { 
          if (1 == 1) {
          avblurb+='Show this as Pie Chart=P' + String.fromCharCode(10) + String.fromCharCode(10);
          avblurb+='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) + '' + String.fromCharCode(10);
          avblurb+='Change data as required below (keeping it the same or being blank or choosing Cancel leaves the status quo)';
          ans=prompt(' For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + avblurb, paramdata);
          if (ans != null) {
			selecteventtwo(ans);
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while ' + colparts[eval(3 - item.column)] + ' were ' + postdparts[eval(3 - item.column)].replace(']','') + ' the difference being ' + eval(eval(postdparts[1].replace(']','')) - eval(postdparts[2].replace(']',''))) + avblurb);
          }
         }
        }
      }

    } 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);
      message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str;
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  if (1 == 2) console.log('You selected ' + message);
 }
 ir=-1;
 ic=-1;    
 } 
      //);  
      ";
      }      

     // echo " chart.draw(data, null); /" . "/ {width: " . $GETwidth . ", height: " . $GETheight . "});  \n";
      echo " chart.draw(data, {" . $newextras . "}); \n";
      if ($GETr != "" && $GETc == "") echo " if (1 == 2) { chart.setSelection([{'row': " . $GETr . ", 'column': null}]); } setTimeout(myselectfunction,4100); \n";
      if ($GETr == "" && $GETc != "") echo " chart.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      if ($GETr != "" && $GETc != "") echo " chart.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      echo " } \n";
      
      
      echo " </script> \n";
      if (isset($_GET['data']) || isset($_POST['data'])) echo ' <!--meta name="viewport" content="width=device-width, initial-scale=0.75"--> <link rel="stylesheet" href="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /><script src="//code.jquery.com/jquery-1.8.2.min.js"></script><script src="//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js">';
      echo '</script></head>' . " \n";
      //echo " <body onload='setTimeout(prelater, 2 * 1000);'> \n";
      echo " <body style='background-color:lightgray;'><div data-role='page'><div data-role='header'> \n";
      if (isset($_GET['isMobile'])) {
      echo " <h2>" . $GETtitle . " Intensity Map</h2></div><!-- /header --><div data-role='content'> \n";
      } else {
      echo " <h1>" . $GETtitle . " Intensity Map</h1></div><!-- /header --><div data-role='content'> \n";
      }
      if (!isset($_GET['isMobile']) || isset($_GET['population'])) {
      echo '<div id="chart_div" style="padding-bottom:50px;"></div><div id="geochart" style="width:600px;height:600px;display:none;"></div><div id="bitsatend"></div>' . "\n";
      if (isset($_GET['isMobile'])) {
       echo '<a id=another title="Another Intensity Map" href="./intensity_chart.php?isMobile=y">&nbsp;Another intensity map?</a>' . $lastgo . "\n";
      } else {
       echo '<a id=another title="Another Intensity Map" href="./intensity_chart.php">&nbsp;Another intensity map?</a>' . $lastgo . "\n";
      }
      }
      if (!isset($_GET['population'])) {
      
        if (isset($_GET['isMobile'])) {
      echo '<div id="chart_div" style="width: ' . $GETwidth . 'px; height: ' . $GETheight . 'px;padding-bottom:50px;"></div>' . "\n";
         echo '<form style="margin-top:-10px;" action="./intensity_chart.php" method="GET">' . "\n";
         echo '<input name="isMobile" type="hidden" value="y"></input><br>' . "\n";
         echo '<table cellpadding=0 style="background-color:pink;"><tr><td>Title</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . ' style="background-color:yellow;" id="title" name="title" type="text" value="' . $GETtitle . '"></input></td></tr>' . "\n";
         echo '<tr id="ourw" style="display:none;"><td>Width</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . ' style="background-color:white;" id="width" name="width" type="text" value="' . $GETwidth . '"></input></td></tr>' . "\n";
         echo '<tr id="ourh" style="display:none;"><td>Height</td><td><input style="background-color:white;" id="height" name="height" type="text" value="' . $GETheight . '"></input></td></tr>' . "\n";
         echo '<tr><td>Via</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . '  style="background-color:yellow;" id="country" name="country" type="text" value="' . $GETcountry . '"></input></td></tr>' . "\n";
         echo '<tr><td>Basis1</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . '  style="background-color:yellow;" id="population" name="population" type="text" value="' . $GETpopulation . '"></input></td></tr>' . "\n";
         echo '<tr><td>Basis2</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . '  style="background-color:yellow;" id="area" name="area" type="text" value="' . $GETarea . '"></input></td></tr>' . "\n";
         echo '<tr><td><input style="background-color:yellow;" type="button" onclick=' . "'" . 'later(document.getElementById("title").value,document.getElementById("width").value,document.getElementById("height").value,document.getElementById("country").value,document.getElementById("population").value,document.getElementById("area").value,"&amp;isMobile=y");' . "'" . ' value="Data"></input></td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . ' style="width:240px;font-size:6px;background-color:yellow;" id="data" name="data" type="text" value="' . $GETdata . '"></input></td></tr>' . "\n";     
         echo '<tr><td><input style="background-color:green;" id="submit" type="submit" value="Show"></input></td><td><input style="background-color:yellow;" id="clear" type="button" value="Clear" onclick="clearit();"></input>' . server_remote_addr('1') . '</td></tr></table>' . "\n";
         echo '</form></div><!-- /content -->' . "\n";
      //echo '<div id="chart_div"></div>' . "\n";
      if (strpos($lastgo, "Another") === false) {
      if (isset($_GET['isMobile'])) {
       echo '<a title="Another Intensity Map" href="./intensity_chart.php?isMobile=y">&nbsp;Another intensity map?</a>' . $lastgo . "\n";
      } else {
       echo '<a title="Another Intensity Map" href="./intensity_chart.php">&nbsp;Another intensity map?</a>' . $lastgo . "\n";
      }
      }
        }
      
        echo '<' . 'script' . ' type="text/javascript">' . "\n ";
          if (!isset($_GET['isMobile'])) {
   //echo '<' . 'script type="text/javascript">' . "\n";
   echo ' setTimeout(prelater, 2 * 1000);' . "\n";
   //echo '<' . '/' . 'script>' . "\n";
  }

        echo ' function clearit() {  ' . "\n" . ' if (document.getElementById("data").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("data").value=""; ' . "\n";
        echo ' if (document.getElementById("title").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("title").value=""; ' . "\n";
        echo ' if (document.getElementById("width").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("width").value=""; ' . "\n";
        echo ' if (document.getElementById("height").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("height").value=""; ' . "\n";
        echo ' if (document.getElementById("country").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("country").value=""; ' . "\n";
        echo ' if (document.getElementById("population").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("population").value=""; ' . "\n";
        echo ' if (document.getElementById("area").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("area").value=""; ' . "\n" . ' }  ' . "\n";

        echo "function prelater() { \n later('','','','','','',''); \n } \n function later(t,w,h,c,p,a,m) { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = "", four; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        echo ' var title = ""; ' . "\n";
        echo ' var width = "' . $GETwidth . '"; ' . "\n";
        echo ' var height = "' . $GETheight . '"; ' . "\n";
        echo ' var country = ""; ' . "\n";
        echo ' var population = ""; ' . "\n";
        echo ' var area = ""; ' . "\n";
        echo ' if ((t.length + w.length + h.length + c.length + p.length + a.length) == 0) { ' . "\n";
        echo '   title = prompt("Enter Intensity Map Title (suffix by &onclick=y for added onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        echo ' }  ' . "\n";
        echo ' if ((t.length + w.length + h.length + c.length + p.length + a.length) != 0) { ' . "\n";
        echo ' title = t; ' . "\n";
        echo ' width = w; ' . "\n";
        echo ' height = h; ' . "\n";
        echo ' country = c; ' . "\n";
        echo ' population = p; ' . "\n";
        echo ' area = a; ' . "\n";
        echo ' } else if (title != null) { ' . "\n";
        echo ' if (1 == 2) { ' . "\n";
        echo ' width = prompt("Enter Intensity Map Width", "' . $GETwidth . '"); ' . "\n";
        echo ' height = prompt("Enter Intensity Map Height", "' . $GETheight . '"); ' . "\n";
        echo ' }  ' . "\n";
        echo ' country = prompt("Enter Country Label", "' . $GETcountry . '"); ' . "\n";
        echo ' population = prompt("Enter " + country + " first Measure", "' . $GETpopulation . '"); ' . "\n";
        echo ' area = prompt("Enter " + country + " second Measure", "' . $GETarea . '"); ' . "\n";
        echo ' }  ' . "\n";
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = prompt("Enter " + country + " Two Letter Code " + thisline, "");  if (datalineprefix == null) { datalineprefix=""; } ' . "\n";
        echo ' while (datalineprefix.length != 0 && (population.indexOf("ercent") == (0 - 1) || population.indexOf("  ercent ") != (0 - 1) || (population.indexOf("ercent") != (0 - 1) && totalleft > 0))) { ' . "\n";
        echo ' if (datalinesuffix.length != 0) datalineprefix = prompt("Enter " + country + " Two Letter Code " + thisline + " (for no more hit Cancel button)", ""); ' . "\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 (population.indexOf("ercent") != (0 - 1) && population.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     datalinesuffix = prompt("Enter " + population.replace("  ercent ", "") + "," + area.replace("  ercent ", "") + " " + thisline + extra, "0,0"); ' . "\n";
        echo '     if (datalinesuffix == null && population.indexOf("ercent") != (0 - 1) && population.indexOf("  ercent ") == (0 - 1)) datalinesuffix = totalleft; ' . "\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) && population.indexOf("ercent") != (0 - 1) && population.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && population.indexOf("ercent") != (0 - 1) && population.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && population.indexOf("ercent") == (0 - 1) && population.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       population = population + "  ercent "; ' . "\n";
        echo '     } else { ' . "\n";
        echo '       totalleft = eval(totalleft) - eval(datalinesuffix); ' . "\n";
        echo '     } ' . "\n";
        */
        //echo '     datac = datac + ",[~" + datalineprefix + "~," + datalinesuffix + "]"; ' . "\n";
        echo '     if (datalineprefix.indexOf("' . "'" . '") == -1) {  four=datalinesuffix.split(","); if (exra != "") { exra=String.fromCharCode(39) + "Regarding " + popularity + four[0] + String.fromCharCode(39) + ","; }  datac = datac + comma + " [~" + datalineprefix + "~," + exra + datalinesuffix + "] "; } ' . "\n";
        echo '     if (datalineprefix.indexOf("' . "'" . '") != -1) {  four=datalinesuffix.split(","); exra=String.fromCharCode(39) + "Regarding " + popularity + four[0] + String.fromCharCode(39) + ","; datac = datac + comma + " [~" + datalineprefix.replace(",", "~,") +  "," + datalinesuffix + "] "; } ' . "\n"; 
        echo '     thisline++;  comma=",";  ' . "\n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
          if (!isset($_GET['isMobile'])) {
        echo ' if (allowed) window.location = "./intensity_chart.php?title=" + title + m + nojwinextra + "&width=" + width + "&height=" + height + "&country=" + country + "&area=" + area.replace("  ercent ", "") + "&population=" + population.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
		  } else {
        echo ' if (allowed) window.location = "./intensity_chart.php?isMobile=y&title=" + title + m + nojwinextra + "&width=" + width + "&height=" + height + "&country=" + country + "&area=" + area.replace("  ercent ", "") + "&population=" + population.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
          }
        echo "} \n"; // . "} \n";
        echo '</' . 'script' . '>' . "\n";
      } 
  echo '</div><!-- /page --><a target="top" title="menu" href="//www.rjmprogramming.com.au/PHP/butsel.php?justmenu=justmenu">Menu</a>' . "\n";
  //if (!isset($_GET['isMobile'])) {
  // echo '<' . 'script type="text/javascript">' . "\n";
  // echo 'setTimeout(prelater, 2 * 1000);' . "\n";
  // echo '<' . '/' . 'script>' . "\n";
  //}
    ?>
<script type='text/javascript'>
if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
  //document.getElementById('pch1').innerHTML+='.';
  var xansis='x', hiddenbits='';
  xpnum=1;
  if (document.URL.indexOf('?') != -1) {
    var pairing, argsare=document.URL.split('#')[0].split('?')[1].split('&');
    for (var iargsare=0; iargsare<argsare.length; iargsare++) {
      pairing=argsare[iargsare].split('=');
      if (('*' + pairing[0]).indexOf('*val') == -1 && ('*' + pairing[0]).indexOf('*prompt') == -1 && ('*' + pairing[0]).indexOf('*OK') == -1 && ('*' + pairing[0]).indexOf('*Cancel') == -1) {
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input>";
      }
    }
  }
  while (xansis != '') {
   xansis=location.search.split('val' + xpnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + xpnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : '';
   if (document.URL.indexOf('val' + xpnum + '=') != -1) {
     hiddenbits+="<input type=hidden name=val" + xpnum + " value='" + encodeURIComponent(xansis) + "'></input>";
     xpnum++;
     xansis='x';
   } else {
     xansis='';
   }
  }
  if (document.URL.indexOf('nojwinyes=') != -1) { 
  document.write("<form onsubmit=\" if (document.getElementById('val" + xpnum + "').value.replace('null','') != '') { if (decodeURIComponent(document.getElementById('prompt').value).indexOf('  For ') == 0) {  selecteventthree(document.getElementById('val" + xpnum + "').value);  } else if (decodeURIComponent(document.getElementById('prompt').value).indexOf(' For ') == 0) {  selecteventtwo(document.getElementById('val" + xpnum + "').value);  } else { selectevent(document.getElementById('val" + xpnum + "').value); } } else if (document.URL.indexOf('&data=') != -1) { location.href=document.URL; } else { this.style.display='none'; } xpnum++; return false; \" enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=5 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='....';
  } else {
  document.write("<form enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=2 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='..';
  }
  if (document.getElementById('another')) {
    if (document.getElementById('another').href.indexOf('nojwin') == -1) {
     document.getElementById('another').href+='?nojwin=Y';
    }
  }
}
</script>
</body>
</html>
