<?php
  // geo_chart.php
  // Google Geo 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";
  }

$burl="";
$bdivstart="";
$bdivend="";
$cdivc="background-color: yellow;";
      $nondefs=" ";

$guess="";
$guessquestion="";
if (isset($_POST['guess'])) {
 $nondefs="legend: 'none',";
 $guess=urldecode($_POST['guess']);
if (isset($_POST['question'])) {
 $guessquestion=urldecode($_POST['question']);
} else if (isset($_GET['question'])) {
 $guessquestion=urldecode($_GET['question']);
}
} else if (isset($_GET['guess'])) {
 $nondefs="legend: 'none',";
 $guess=urldecode($_GET['guess']);
if (isset($_POST['question'])) {
 $guessquestion=urldecode($_POST['question']);
} else if (isset($_GET['question'])) {
 $guessquestion=urldecode($_GET['question']);
}
} else {
 $nondefs="";
}

$top="";
if (isset($_POST['area']) || isset($_GET['area'])) $top=" ";
$ntop="1";
$roff="0";
$mtop="1";
$newextras="";
$lastgo = "";
$GETimage = "<img src='geo_chart.jpg'></img>";
$myextras = " + ' or maybe perhaps ' + '\\n\\n' + ',\"A tooltip (regarding {popularity}) of some sort like <a target=_blank href=' + \"'\" + 'https://en.wikipedia.org/wiki/{country}' + \"'\" + '>{country}</a>\"' + '\\n\\n'";


$inplace="";
$iso_country_codes=['AF','Afghanistan',
'AX','Aland Islands',
'AL','Albania',
'DZ','Algeria',
'AS','American Samoa',
'AD','Andorra',
'AO','Angola',
'AI','Anguilla',
'AQ','Antarctica',
'AG','Antigua and Barbuda',
'AR','Argentina',
'AM','Armenia',
'AW','Aruba',
'AU','Australia',
'AT','Austria',
'AZ','Azerbaijan',
'BS','Bahamas the',
'BH','Bahrain',
'BD','Bangladesh',
'BB','Barbados',
'BY','Belarus',
'BE','Belgium',
'BZ','Belize',
'BJ','Benin',
'BM','Bermuda',
'BT','Bhutan',
'BO','Bolivia',
'BA','Bosnia and Herzegovina',
'BW','Botswana',
'BV','Bouvet Island (Bouvetoya)',
'BR','Brazil',
'IO','British Indian Ocean Territory (Chagos Archipelago)',
'VG','British Virgin Islands',
'BN','Brunei Darussalam',
'BG','Bulgaria',
'BF','Burkina Faso',
'BI','Burundi',
'KH','Cambodia',
'CM','Cameroon',
'CA','Canada',
'CV','Cape Verde',
'KY','Cayman Islands',
'CF','Central African Republic',
'TD','Chad',
'CL','Chile',
'CN','China',
'CX','Christmas Island',
'CC','Cocos (Keeling) Islands',
'CO','Colombia',
'KM','Comoros the',
'CD','Congo',
'CG','Congo the',
'CK','Cook Islands',
'CR','Costa Rica',
'CI','Cote d\'Ivoire',
'HR','Croatia',
'CU','Cuba',
'CY','Cyprus',
'CZ','Czech Republic',
'DK','Denmark',
'DJ','Djibouti',
'DM','Dominica',
'DO','Dominican Republic',
'EC','Ecuador',
'EG','Egypt',
'SV','El Salvador',
'GQ','Equatorial Guinea',
'ER','Eritrea',
'EE','Estonia',
'ET','Ethiopia',
'FO','Faroe Islands',
'FK','Falkland Islands (Malvinas)',
'FJ','Fiji the Fiji Islands',
'FI','Finland',
'FR','France, French Republic',
'GF','French Guiana',
'PF','French Polynesia',
'TF','French Southern Territories',
'GA','Gabon',
'GM','Gambia the',
'GE','Georgia',
'DE','Germany',
'GH','Ghana',
'GI','Gibraltar',
'GR','Greece',
'GL','Greenland',
'GD','Grenada',
'GP','Guadeloupe',
'GU','Guam',
'GT','Guatemala',
'GG','Guernsey',
'GN','Guinea',
'GW','Guinea-Bissau',
'GY','Guyana',
'HT','Haiti',
'HM','Heard Island and McDonald Islands',
'VA','Holy See (Vatican City State)',
'HN','Honduras',
'HK','Hong Kong',
'HU','Hungary',
'IS','Iceland',
'IN','India',
'ID','Indonesia',
'IR','Iran',
'IQ','Iraq',
'IE','Ireland',
'IM','Isle of Man',
'IL','Israel',
'IT','Italy',
'JM','Jamaica',
'JP','Japan',
'JE','Jersey',
'JO','Jordan',
'KZ','Kazakhstan',
'KE','Kenya',
'KI','Kiribati',
'KP','Korea',
'KR','Korea',
'KW','Kuwait',
'KG','Kyrgyz Republic',
'LA','Laos',
'LV','Latvia',
'LB','Lebanon',
'LS','Lesotho',
'LR','Liberia',
'LY','Libyan Arab Jamahiriya',
'LI','Liechtenstein',
'LT','Lithuania',
'LU','Luxembourg',
'MO','Macao',
'MK','Macedonia',
'MG','Madagascar',
'MW','Malawi',
'MY','Malaysia',
'MV','Maldives',
'ML','Mali',
'MT','Malta',
'MH','Marshall Islands',
'MQ','Martinique',
'MR','Mauritania',
'MU','Mauritius',
'YT','Mayotte',
'MX','Mexico',
'FM','Micronesia',
'MD','Moldova',
'MC','Monaco',
'MN','Mongolia',
'ME','Montenegro',
'MS','Montserrat',
'MA','Morocco',
'MZ','Mozambique',
'MM','Myanmar',
'NA','Namibia',
'NR','Nauru',
'NP','Nepal',
'AN','Netherlands Antilles',
'NL','Netherlands the',
'NC','New Caledonia',
'NZ','New Zealand',
'NI','Nicaragua',
'NE','Niger',
'NG','Nigeria',
'NU','Niue',
'NF','Norfolk Island',
'MP','Northern Mariana Islands',
'NO','Norway',
'OM','Oman',
'PK','Pakistan',
'PW','Palau',
'PS','Palestinian Territory',
'PA','Panama',
'PG','Papua New Guinea',
'PY','Paraguay',
'PE','Peru',
'PH','Philippines',
'PN','Pitcairn Islands',
'PL','Poland',
'PT','Portugal, Portuguese Republic',
'PR','Puerto Rico',
'QA','Qatar',
'RE','Reunion',
'RO','Romania',
'RU','Russian Federation',
'RW','Rwanda',
'BL','Saint Barthelemy',
'SH','Saint Helena',
'KN','Saint Kitts and Nevis',
'LC','Saint Lucia',
'MF','Saint Martin',
'PM','Saint Pierre and Miquelon',
'VC','Saint Vincent and the Grenadines',
'WS','Samoa',
'SM','San Marino',
'ST','Sao Tome and Principe',
'SA','Saudi Arabia',
'SN','Senegal',
'RS','Serbia',
'SC','Seychelles',
'SL','Sierra Leone',
'SG','Singapore',
'SK','Slovakia (Slovak Republic)',
'SI','Slovenia',
'SB','Solomon Islands',
'SO','Somalia, Somali Republic',
'ZA','South Africa',
'GS','South Georgia and the South Sandwich Islands',
'ES','Spain',
'LK','Sri Lanka',
'SD','Sudan',
'SR','Suriname',
'SJ','Svalbard & Jan Mayen Islands',
'SZ','Swaziland',
'SE','Sweden',
'CH','Switzerland, Swiss Confederation',
'SY','Syrian Arab Republic',
'TW','Taiwan',
'TJ','Tajikistan',
'TZ','Tanzania',
'TH','Thailand',
'TL','Timor-Leste',
'TG','Togo',
'TK','Tokelau',
'TO','Tonga',
'TT','Trinidad and Tobago',
'TN','Tunisia',
'TR','Turkey',
'TM','Turkmenistan',
'TC','Turks and Caicos Islands',
'TV','Tuvalu',
'UG','Uganda',
'UA','Ukraine',
'AE','United Arab Emirates',
'GB','United Kingdom',
'US','United States of America',
'UM','United States Minor Outlying Islands',
'VI','United States Virgin Islands',
'UY','Uruguay, Eastern Republic of',
'UZ','Uzbekistan',
'VU','Vanuatu',
'VE','Venezuela',
'VN','Vietnam',
'WF','Wallis and Futuna',
'EH','Western Sahara',
'YE','Yemen',
'ZM','Zambia',
'ZW','Zimbabwe'];


function tzl($inwith, $dc) {
   if (!$dc) $inwithtz=($inwith);
   if ($dc) $inwithtz=urldecode($inwith);
   if (strpos($inwithtz, "~http;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~http;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~Http;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~Http;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~HTTP;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~HTTP;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~https;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~https;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~Https;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~Https;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~HTTPS;") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http;" . explode("~",explode("~HTTPS;", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~http") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http" . explode("~",explode("~http", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~Http") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("http" . explode("~",explode("~Http", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos($inwithtz, "~HTTP") !== false) { // co-ordinates via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array("HTTP" . explode("~",explode("~HTTP", $inwithtz)[1])[0], str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos(str_replace("https;","http;",substr(strtolower($inwithtz . "      "),0,6)), "http;") !== false) { // co-ordinates longhand via prompt
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array($inwithtz, str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else if (strpos(str_replace("https:","http:",substr(strtolower($inwithtz . "      "),0,6)), "http:") !== false) { // co-ordinates via URL via net
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_array($inwithtz, str_replace('geo_chart.php','pie_chart.php',str_replace('index.php','pie_chart.php',$_SERVER['REQUEST_URI'])))));
   } else {
     return $inwith;
   }
   echo "\n pardata=\"" . urlencode("," . $inwithtz) . "\"; paramdata=decodeURIComponent(pardata);  \n  xcom=paramdata.replace(/, 66]/g,'').replace(/,66]/g,'').replace(/\\[/g,'').replace(/~/g,'').replace(/'/g,''); \n var xxpardata=\"" . ("," . $inwithtz) . "\"; \n";
   return $inwithtz;
}

function recode($iniso) {
  global $iso_country_codes, $inplace;
  $outiso=$iniso . $inplace;
  for ($ic=0; $ic<sizeof($iso_country_codes); $ic+=2) {
    if ($iso_country_codes[$ic] == $iniso) return $iniso . " (" . $iso_country_codes[1 + $ic] . ")";
  }
  return $outiso;
}

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['popularity'])) {
      $file_handle = fopen("TestGeoChart_" . $rma . ".html", "w");
      fwrite($file_handle, $_SERVER['REQUEST_URI']);
      fclose($file_handle);
      $timesuff = date("Y-m-d-H-i-s");
      while (file_exists("GeoChart_" . $rma . "_" . $timesuff . ".html")) {
       $timesuff = date("Y-m-d-H-i-s");
      }
      $file_handle = fopen("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?c=h"></script> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js?d=f"></script><meta http-equiv="Refresh" content="5;url=' . $_SERVER['REQUEST_URI'] . '"><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"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      $lastgo = "&nbsp;&nbsp;&nbsp;<a target=_blank title='Last Geo Map' href='" . $_SERVER['REQUEST_URI'] . "'>Last</a>" . "&nbsp;&nbsp;<a href='mailto:rmetcalfe15@gmail.com?subject=Email Last Geo Map link to " . $GETtitle . " //www.rjmprogramming.com.au/PHP/GeoChart/GeoChart_" . $timesuff . ".html" . "&body=Change Email Address then Email Last Geo Map link to " . $GETtitle . " //www.rjmprogramming.com.au/PHP/GeoChart/GeoChart_" . $timesuff . ".html&cc=&bcc='>Email</a>&nbsp;&nbsp;<a onclick='var qqq=document.getElementById(" . '"' . "ourw" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Width?' href='#'>W?</a>&nbsp;&nbsp;<a onclick='var qqq=document.getElementById(" . '"' . "ourh" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Height?' href='#'>H?</a>&nbsp;&nbsp;<a title='Intensity Map?' href='../IntensityChart/intensity_chart.php?isMobile=y'>+</a>";
      if (isset($_GET['isMobile']) || isset($_POST['isMobile'])) {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?isMobile=y">Another?</a>' . $lastgo . "\n";
  } else {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?isMobile=yjustmenu">Another?</a>' . $lastgo . "\n";
  }
      } else {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php">Another?</a>';
  } else {
      $lastgo .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?justmenu=justmenu">Another?</a>';
  }
      }
    } else if (strlen($inst) > 0 && file_exists("TestGeoChart_" . $rma . ".url")) {
      $file_handle = fopen("TestGeoChart_" . $rma . ".url", "r");
      $rma=fgets($file_handle);
      fclose($file_handle);
      $timesuff = date("Y-m-d-H-i-s");
      while (file_exists("GeoChart_" . $rma . "_" . $timesuff . ".html")) {
       $timesuff = date("Y-m-d-H-i-s");
      }
      $file_handle = fopen("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?w=g"></script><meta http-equiv="Refresh" content="5;url=' . $rma . '"><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"></script></head><body> <div data-role="page"></div><!-- /page --></body></html>');
      fclose($file_handle);
      $rma = "&nbsp;&nbsp;&nbsp;<a target=_blank title='Last Geo Map' href='" . $rma . "'>Last</a>" . "&nbsp;&nbsp;<a href='mailto:rmetcalfe15@gmail.com?subject=Email Last Geo Map link to //www.rjmprogramming.com.au/PHP/GeoChart/GeoChart_" . $timesuff . ".html" . "&body=Change Email Address then Email Last Geo Map link to //www.rjmprogramming.com.au/PHP/GeoChart/GeoChart_" . $timesuff . ".html&cc=&bcc='>Email</a>&nbsp;&nbsp;<a onclick='var qqq=document.getElementById(" . '"' . "ourw" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Width?' href='#'>W?</a>&nbsp;&nbsp;<a onclick='var qqq=document.getElementById(" . '"' . "ourh" . '"' . "); qqq.style.display=" . '"' . "block" . '";' . "' title='Height?' href='#'>H?</a>&nbsp;&nbsp;<a title='Intensity Map?' href='../IntensityChart/intensity_chart.php?isMobile=y'>+</a>";
      if (isset($_GET['isMobile']) || isset($_POST['isMobile'])) {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
      $rma .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?isMobile=y">Another?</a>' . $lastgo . "\n";
  } else {
      $rma .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?isMobile=yjustmenu">Another?</a>' . $lastgo . "\n";
  }
      } else {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
      $rma .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php">Another?</a>';
  } else {
      $rma .= '&nbsp;&nbsp;<a title="Another Geo Map" href="./geo_chart.php?justmenu=justmenu">Another?</a>';
  }
      }
      $lastgo = $rma;
    }
    return $rma;
}

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



    echo '<html>' . "\n";
    echo '<head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js?c=f"></script> ' . "\n";
    echo '<title>Geo 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=0.75">' . "\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 fti=false,ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint=''; "  . "\n"; 
    echo "var xpnum=1; /" . "/ done here at supervisor "  . "\n"; 
    echo "var allowed=true; /" . "/ done here at supervisor "  . "\n"; 
    echo "var nojwinextra=''; /" . "/ done here at supervisor "  . "\n"; 
  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';
     }
   }
   ";
  }

    echo "  if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     nojwinextra='&nojwinyes=Y';
     }  
     ";
     
 echo "
 
 function dlp(thisris) {
      if (thisris != null) {
        var commacount=thisris.toLowerCase().replace(/\\<\\/td\\>/g,'  ,  ').indexOf(',');
        if (thisris.toLowerCase().replace('https:','http:').indexOf('http:') == 0) {
             fti=true;
             allowed=true;
             datac=thisris;
        } else if (commacount >= 0) {   
             var thatris=thisris.replace(/\\ \\" . '"' . "/g,String.fromCharCode(10) + '" . '"' . "').replace(/\\<tr\\>/g,'').replace(/\\<\\/td\\>\\<td\\>/g,',').replace(/\\<\\/tr\\>/g,String.fromCharCode(10)).replace(/\\<\\/td\\>/g,',').replace(/\\,\\,/g,',').replace(/\\,\\,/g,',').replace(',' + String.fromCharCode(10),String.fromCharCode(10));
             var zisok=true, fldq=thatris.split(',');
             var pielines=thatris.split(String.fromCharCode(10));
             if ((fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) > '9') {
              if ((fldq[eval(-1 + fldq.length)].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[eval(-1 + fldq.length)].replace('" . '"' . "','').trim() + ' ').substring(0,1) > '9') {
               zisok=false;
              }
             }
             if (!zisok && pielines.length > 1) {
             fldq=pielines[1].split(',');
             zisok=true;
             if ((fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) > '9') {
              if ((fldq[eval(-1 + fldq.length)].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[eval(-1 + fldq.length)].replace('" . '"' . "','').trim() + ' ').substring(0,1) > '9') {
               zisok=false;
              }
             }
             }
             if (zisok) {
             while (thatris.indexOf(String.fromCharCode(10)) != -1) {
              var inpies, pied='';
              thatris='';
              var sthatris='';
              for (var ipie=0; ipie<pielines.length; ipie++) {
               inpies=pielines[ipie].split(',');
               if (inpies.length > 1) {
                if ((inpies[0].trim() + ' ').substring(0,1) == '" . '"' . "' && (inpies[1].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','') + ',' + inpies[1].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','');
                } else if ((inpies[0].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','') + ',' + inpies[1].trim().replace('%','').replace('" . '"' . "','');
                } else if ((inpies[1].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','');
                } else {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().replace('%','').replace('" . '"' . "','');
                }
                inpies=sthatris.replace(pied,'').split(',');
                //alert(sthatris + ' ' + inpies[0] + ' ' + inpies[1]);
                if (((inpies[0].trim() + ' ').substring(0,1) >= '0' && (inpies[0].trim() + ' ').substring(0,1) <= '9') || ((inpies[1].trim() + ' ').substring(0,1) >= '0' && (inpies[1].trim() + ' ').substring(0,1) <= '9')) {
                thatris+=sthatris;
                //alert(thatris);
                pied=',';
                }
               }
              }
             }
             thatris=thatris.replace(/\\,\\,/g,',');
             fti=true;
             allowed=true;
             datac='http;' + thatris;
             thisris='http;' + thatris;   
             }
        }
      }
      
      return thisris;
      
 }
";    
     

 echo "
 
     function selectevent(ans) {
            var relist;
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             var 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 (var 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('/GeoChart', '/PieChart').replace('geo_chart.php', 'pie_chart.php');
             } else if (document.URL.indexOf(pardata) != -1) {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             } else if (document.URL.indexOf('data=') != -1) {
              location.href=document.URL.replace(document.URL.split('data=')[1].split('&')[0], ourencodeURIComponent(('`' + ans).replace('`,','').replace('`','')));
             }
            }     
     }

     function selecteventtwo(ans) {
            var relist;
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             var 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 (var 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('/GeoChart', '/PieChart').replace('geo_chart.php', 'pie_chart.php');
             } else if (document.URL.indexOf(pardata) != -1) {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             } else if (document.URL.indexOf('data=') != -1) {
              location.href=document.URL.replace(document.URL.split('data=')[1].split('&')[0], ourencodeURIComponent(('`' + ans).replace('`,','').replace('`','')));
             }
            }     
     
     }

    ";




    echo "var data, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata) , xcom=paramdata.replace(/, 66]/g,'').replace(/,66]/g,'').replace(/\[/g,'').replace(/~/g,'').replace(/'/g,''); \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";

      $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 != "") {
       if (substr($GETr,0,1) == "0" && strlen($GETr) > 1) {
        $top="top.";
        $ntop="2";
        $mtop="1";
        $roff="1";
       }
       echo "\n ir=eval('" . $GETr . "'); \n";
      }
      if ($GETc != "") {
       if (substr($GETc,0,1) == "0" && strlen($GETc) > 1) {
        $top="top.";
        $ntop="2";
        $mtop="1";
        $roff="1";
       }
       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";
      }

      

      $xgd = ""; 
      $gd = ""; 
      $ntt=false;
      $GETarea="";
      if (isset($_GET['area'])) {
         if ($top == "") $top=" ";
         $GETarea = str_replace("~","",str_replace(",~~", "", ",~" . $_GET['area'] . "~"));
      }
      if (isset($_GET['popularity']) || isset($_POST['popularity'])) server_remote_addr("");
      $GETtitle = "My World Survey";
      $GETcountry = "Country";
      $GETpopularity = "Popularity";
      $GETdata = "['Germany',200],['United States',300],['Brazil',400],['Canada',500],['France',600],['RU',700] ";      
      if (isset($_GET['isMobile']) || isset($_POST['isMobile']) || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
      $GETwidth = "305";
      $GETheight = "190";
      $myextras = "";
      } else {
      $GETwidth = "556";
      $GETheight = "347";
      }
      if (isset($_GET['isMobile']) || isset($_POST['isMobile'])) $GETimage="";
      if (isset($_GET['popularity'])) {
       if ($GETimage == "" && strpos($_GET['data'], "%2C") === false) {
       $GETtitle = $_GET['title'];
       titlebits($burl, $GETtitle, $cdivc, $bdivstart, $bdivend, $nondefs);
       $GETcountry = $_GET['country'];
       $GETpopularity = $_GET['popularity'];
       $GETdata = tzl($_GET['data'],true);
       $GETwidth = $_GET['width'];
       $GETheight = $_GET['height'];
       if (isset($_GET['area'])) {
         if ($top == "") $top=" ";
         $GETarea = str_replace("~","",str_replace(",~~", "", ",~" . $_GET['area'] . "~"));
       }
       } else {
       $GETtitle = urldecode($_GET['title']);
       titlebits($burl, $GETtitle, $cdivc, $bdivstart, $bdivend, $nondefs);
       $GETcountry = urldecode($_GET['country']);
       $GETpopularity = urldecode($_GET['popularity']);
       $GETdata = tzl(urldecode($_GET['data']),false);
       $GETwidth = urldecode($_GET['width']);
       $GETheight = urldecode($_GET['height']);
       if (isset($_POST['area'])) {
         if ($top == "") $top=" ";
         $GETarea = str_replace("~","",str_replace(",~~", "", ",~" . urldecode($_POST['area']) . "~"));
       }
       }
       $ourtitles=explode(";", $GETtitle);
       if (sizeof($ourtitles) > 1) {
        $newextras="region: '" . $ourtitles[0] . "', displayMode: 'markers', colorAxis: {colors: ['green', 'blue']}, ";
       }
       $GETtitle = $ourtitles[sizeof($ourtitles) - 1];
       $GETimage="";
      } else if (isset($_POST['popularity']) && (isset($_POST['isMobile']) || isset($_POST['wouldlikeyoutoseekpermission']))) {
       $GETimage="";
       $GETtitle = urldecode($_POST['title']);
       titlebits($burl, $GETtitle, $cdivc, $bdivstart, $bdivend, $nondefs);
       $ourtitles=explode(";", $GETtitle);
       if (sizeof($ourtitles) > 1) {
        $newextras="region: '" . $ourtitles[0] . "', displayMode: 'markers', colorAxis: {colors: ['green', 'blue']}, ";
       }
       $GETtitle = $ourtitles[sizeof($ourtitles) - 1];
       $GETcountry = urldecode($_POST['country']);
       $GETpopularity = urldecode($_POST['popularity']);
       $GETdata = tzl(urldecode($_POST['data']),false);
       $GETwidth = urldecode($_POST['width']);
       $GETheight = urldecode($_POST['height']);
       if (isset($_POST['area'])) {
         if ($top == "") $top=" ";
         $GETarea = str_replace("~","",str_replace(",~~", "", ",~" . urldecode($_POST['area']) . "~"));
       }
      }

      echo " var colnames= '" . $GETcountry . "," . str_replace("'", "", $GETpopularity) . $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:["geochart"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      
      if ($GETarea == '') {
       echo "\nfunction unzero(cin) { return cin; } \n";
      } else {
       echo "\nfunction unzero(cin) { return cin.replace('.0000000000', ' and " . str_replace(","," ",$GETarea) . " of '); } \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";
  if (isset($_GET['aregeographicals']) || isset($_POST['aregeographicals'])) {
  echo "   data.addColumn('number', 'Lat'); \n";
  echo "   data.addColumn('number', 'Lon'); \n";
  }
  echo "   data.addColumn('string', '" . $GETcountry . "');  \n";
  //echo "   data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});  \n";
  $things=explode(",",$GETpopularity);
  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("|", ",", str_replace("~", "'", substr($GETdata,1)));
  echo "   ]); \n";
 } else {
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
  if (isset($_GET['aregeographicals']) || isset($_POST['aregeographicals'])) {
      echo " ['Lat','Long','" . $GETcountry . "','" . str_replace(",", "','", $GETpopularity) . "'], \n";
  } else {
      echo " ['" . $GETcountry . "','" . str_replace(",", "','", $GETpopularity) . "'], \n";
  }
      echo str_replace("|", ",", str_replace("~", "'", str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata))))) ));
      echo "        ]);\n";
 }
      echo " chart = new google.visualization.GeoChart(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 "google.visualization.events.addListener(chart, 'ready', function() { ready=true; }); \n";
      echo "google.visualization.events.addListener(chart, 'select', myselectfunction); \n function myselectfunction() {
 if (ready) {
  var relist=['remail',''],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;
  selection = chart.getSelection();
  sliceid = selection[0].row;

  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        item.row=eval(ir + " . $roff . ");
        //item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
        ir=item.row;
        //ic=item.column;
        //document.title=ir + ',' + ic;
        if ('" . $top . "' == ' ') {
         top.document.location=top.document.URL.replace('&r=','&xr=').replace('?','?r=' + ir + '&');
         return;
        }
      }
      //document.title=str;
      message=" . $top . "document.head.innerHTML.replace(/, \[/g,',' + '[').replace('[' + String.fromCharCode(39),'[ ' + String.fromCharCode(39)).replace('[' + String.fromCharCode(39),', [' + String.fromCharCode(39)).substring(ioffset);
      while (message.indexOf(',' + ' [') != -1) {
       message=message.replace(',' + ' [',',' + '[');
      }
      //alert(message);
      dparts=message.split(',[');
        //document.title='';
        colav.push(0.0);
      for (kl=" . $ntop . "; kl<colparts.length; kl++) {
        //alert('dp[1]=' + dparts[1]);
        //document.title=1;
        colav.push(0.0);
        doit=true;
        num=1;
        for (lk=" . $mtop . "; lk<dparts.length; lk++) {
         if (doit) {
        //document.title=3;
        //alert('dparts[' + lk + ']=' + dparts[lk].replace(']',','));
         thisnum=dparts[lk].replace(']);',',').replace(']',',').split(',');
         //if (kl == 1) document.title+=4 + ' .. '  + eval(thisnum[kl]) + ' ... ' + lk + ' ... ' + colav[kl] + ' ... ' + thisnum.length + ' ... ' + dparts[lk];
         //alert(dparts[lk].replace(']',',') + ' 77 ' + thisnum.length + ' vs ' + kl);
        colav[kl] = eval(eval(colav[kl] * eval(-1 + num)) + eval(thisnum[kl])) / eval(0.0 + num);
        //alert(777);
        //document.title=5;
         if (dparts[lk].indexOf(';') != -1) doit=false;
         if (doit) num++;
         }
        }
        //alert(7);
        //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);
        //alert(dparts.length + ' bigger than ' + eval(1 + item.row));
      if (eval(dparts.length) >= eval(1 + item.row)) {
      //alert(97);
        postdparts=dparts[eval(1 + item.row)].replace(']',',').split(',');
       //alert(977);
       if (eval(postdparts.length) >= eval(1 + item.column)) {
      //alert(197);
         if (eval(colparts.length) >= 2) { 
      //alert(397);
          if (1 == 1) {
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + '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=null; \n";

  if ($guess != "") {
          echo "\n var agoes=[0,0]; pscore='';\n if (parent.document.getElementById('score')) {\n pscore=parent.document.getElementById('score').innerHTML;\n agoes=pscore.replace('Score:','').split('/');\n }\n if (eval(('' + postdparts[0].replace(']','')).indexOf('" . $guess . "') / 2) >= 0) {\n if (pscore == '') {\n alert('Correct.'); }\n else if (agoes.length == 2) {\n parent.document.getElementById('score').innerHTML='Score: ' + eval(1 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0]));\n    } else if (agoes.length == 1) { parent.document.getElementById('score').innerHTML='' + eval(1 + eval(agoes[0]));   } } else { var huhhuh='Your guess of ' + postdparts[0].replace(']','') + ' is not correct.  The correct answer is ' + '" . $guess . ".';  if (agoes.length == 2) {\n parent.document.getElementById('score').innerHTML='Score: ' + eval(0 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0]));\n    } else if (agoes.length == 1) { parent.document.getElementById('score').innerHTML=' ' + eval(0 + eval(agoes[0]));   }  alert(huhhuh);  } \n"; 
  } else {
          echo "\n ans=prompt(unzero('For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','')) + avblurb, paramdata); \n";
  }

      echo "
          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=eval(ir + " . $roff . ");
        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;
        if ('" . $top . "' == ' ') {
         top.document.location=top.document.URL.replace('&r=','&xr=').replace('?','?r=' + ir + '&');
         return;
        }
      }
      str = data.getFormattedValue(item.row, 0);
      //document.title=str;
      //document.title=str;
      message=" . $top . "document.head.innerHTML.replace(/, \[/g,',' + '[').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=" . $ntop . "; kl<colparts.length; kl++) {
        //document.title=1;
        colav.push(0.0);
        doit=true;
        num=1;
        for (lk=" . $mtop . "; lk<dparts.length; lk++) {
         if (doit) {
        //document.title=3;
         //alert(dparts[lk].replace(']',','));
         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++;
         }
        }
        //alert('07');
        //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+=String.fromCharCode(10) + String.fromCharCode(10) + '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=null; \n";

  if ($guess != "") {
          echo "\n var agoes=[0,0]; pscore='';\n if (parent.document.getElementById('score')) {\n pscore=parent.document.getElementById('score').innerHTML;\n agoes=pscore.replace('Score:','').split('/');\n }\n if (eval(('' + postdparts[0].replace(']','')).indexOf('" . $guess . "') / 2) >= 0) {\n if (pscore == '') {\n alert('Correct.'); }\n else if (agoes.length == 2) {\n parent.document.getElementById('score').innerHTML='Score: ' + eval(1 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0]));\n    } else if (agoes.length == 1) { parent.document.getElementById('score').innerHTML='' + eval(1 + eval(agoes[0]));   } } else { var huhhuh='Your guess of ' + postdparts[0].replace(']','') + ' is not correct.  The correct answer is ' + '" . $guess . ".';  if (agoes.length == 2) {\n parent.document.getElementById('score').innerHTML='Score: ' + eval(0 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0]));\n    } else if (agoes.length == 1) { parent.document.getElementById('score').innerHTML=' ' + eval(0 + eval(agoes[0]));   } alert(huhhuh);  } \n"; 
 } else {
          echo "\n ans=prompt(unzero(' For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','')) + avblurb, paramdata); \n";
  }
      echo "
          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;    
 } 
      //);  
      ";
      }      

      $optstuff=str_replace("'none' width","'none',width",str_replace("{,","{","{" . $newextras)) . "}";
      if (strpos($optstuff, "markers") === false && (isset($_GET['areplaces']) || isset($_POST['areplaces']) || isset($_GET['aregeographicals']) || isset($_POST['aregeographicals']))) $optstuff=str_replace("}",", displayMode: 'markers'}",$optstuff);      
      echo " chart.draw(data," . $optstuff . "); \n";
      if ($GETr != "" && $GETc == "") echo " 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";
      
      if ($guess != "") {
       if ($guessquestion != "") {
        echo "\n function guesswork() { ouralert('" . $guessquestion . "  Click country answer below." . "'); } \n";
       } else {
        echo "\n function guesswork() { ouralert('Click country answer below." . "'); } \n";
       }
       echo "\n\n setTimeout(guesswork,2300); \n\n";
      }      


 echo "   function ouralert(ourpis) {
   var postdparts0='';
   var phuh=" . sizeof($ourtitles) . "; 
if (phuh == 2 || navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) || ('" . $guess . "' != '' && '" . $guess . "'.replace('Andorra','').replace('Monaco','').replace('Vatican City','').replace('Monaco','').replace('Liechtenstein','').replace('Luxembourg','').replace('San Marino','').replace('Nauru','').replace('Maldives','').replace('Grenada','').replace('Malta','').replace('Saint Kitts and Nevis','') == '')) {
if (xcom.length < 300) {
if (phuh == 2) {
postdparts0=prompt(ourpis.replace('Click ','We think that clicks below may not work so you could type country code " . recode($ourtitles[0]) . " city name from ' + xcom + ' or you can try click '),'');
} else {
postdparts0=prompt(ourpis.replace('Click ','We think that clicks below may not work so you could type country from ' + xcom + ' or you can try click '),'');
}
if (postdparts0 == null) postdparts0='';
} else {
if (phuh == 2) {
postdparts0=prompt(ourpis.replace('Click ','We think that clicks below may not work so you could type country code " . recode($ourtitles[0]) . " city name below or you can try click '),'');
} else {
postdparts0=prompt(ourpis.replace('Click ','We think that clicks below may not work so you could type country below or you can try click '),'');
}
if (postdparts0 == null) postdparts0='';
}
  var agoes=[0,0]; pscore='';
  if (parent.document.getElementById('score')) {           pscore=parent.document.getElementById('score').innerHTML;  agoes=pscore.replace('Score:','').split('/');
 }
 if (eval(('' + postdparts0.toLowerCase().replace(']','')).indexOf('" . $guess . "'.toLowerCase()) / 2) >= 0) {
 if (pscore == '') {
alert('Correct.'); 
} else if (agoes.length == 2) {
parent.document.getElementById('score').innerHTML='Score: ' + eval(1 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0])); 
} else if (agoes.length == 1) { 
parent.document.getElementById('score').innerHTML='' + eval(1 + eval(agoes[0])); 
 }
} else if (postdparts0 != '') {
if (agoes.length == 2) {
parent.document.getElementById('score').innerHTML='Score: ' + eval(0 + eval(agoes[0])) + '/' + eval(1 + eval(agoes[1].split(' ')[0])) + ' The correct answer is " . $guess . "'; 
} else if (agoes.length == 1) { 
parent.document.getElementById('score').innerHTML=' ' + eval(0 + eval(agoes[0])); 
 }
}
 } else {
  alert(ourpis);
 }
} \n\n  ";


      echo " </script> \n";
      if ((!isset($_GET['onclick']) && !isset($_POST['onclick'])) && (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']) || isset($_POST['isMobile'])) {
      echo " <h2>" . $GETtitle . " Geo Map</h2></div><!-- /header --><div data-role='content'>" . $GETimage . " \n";
      } else {
      echo " <h1>" . $GETtitle . " Geo Map</h1></div><!-- /header --><div data-role='content'>" . $GETimage . " \n";
      }
      if ((!isset($_GET['isMobile']) && !isset($_POST['isMobile'])) || isset($_GET['popularity'])) {
      echo $bdivstart . '<div id="chart_div" style="' . $cdivc . '"></div>' . $bdivend . "\n";
      if (isset($_GET['isMobile']) || isset($_POST['isMobile'])) {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php?isMobile=y">Another geo map?</a>' . $lastgo . "\n";
  } else {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php?isMobile=yjustmenu">Another geo map?</a>' . $lastgo . "\n";
  }
      } else {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php">Another geo map?</a>' . $lastgo . "\n";
  } else {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php?justmenu=justmenu">Another geo map?</a>' . $lastgo . "\n";
  }
      }
      }
      if (!isset($_GET['popularity']) && !isset($_POST['popularity']) && strpos($_SERVER['QUERY_STRING'], "x=x") === false) {
      
        if ((isset($_GET['isMobile']) || isset($_POST['isMobile'])) && strpos($_SERVER['QUERY_STRING'], "x=x") === false) {
      echo '<div id="chart_div"></div>' . "\n";
         echo '<form target="_top" style="margin-top:-10px;" action="./geo_chart.php" method="GET">' . "\n";
         echo '<input name="isMobile" type="hidden" value="y"></input><input name="x" type="hidden" value="x"></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>Basis</td><td><input onclick=' . "'" . 'this.style.backgroundColor = "white"; ' . "'" . '  style="background-color:yellow;" id="popularity" name="popularity" type="text" value="' . $GETpopularity . '"></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("popularity").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="prompt" type="button" value="Prompt Me" onclick="location.href=' . "'" . './geo_chart.php' . "'" . ';"></input><input style="background-color:yellow;" id="clear" type="button" value="Clear" onclick="clearit();"></input>' . server_remote_addr('1') . '</td></tr></table>' . "\n";
         echo '<tr><td><input style="background-color:green;" id="submit" type="submit" value="Show"></input></td><td><input style="background-color:yellow;" id="prompt" type="button" value="Prompt Me" onclick="top.location.href=' . "'" . './geo_chart.php' . "'" . ';"></input><input style="background-color:yellow;" id="clear" type="button" value="Clear" onclick="clearit();"></input></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']) || isset($_POST['isMobile'])) {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
       echo '<a d=another title="Another Geo Map" href="./geo_chart.php?isMobile=y">Another geo map?</a>' . $lastgo . "\n";
  } else {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php?isMobile=yjustmenu">Another geo map?</a>' . $lastgo . "\n";
  }
      } else {
  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php">Another geo map?</a>' . $lastgo . "\n";
  } else {
       echo '<a id=another title="Another Geo Map" href="./geo_chart.php?justmenu=justmenu">Another geo map?</a>' . $lastgo . "\n";
  }
      }
      }
        }
      
        echo '<' . 'script' . ' type="text/javascript">' . "\n ";
          if (!isset($_GET['isMobile']) && !isset($_POST['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("popularity").style.backgroundColor.indexOf("yellow") != (0 - 1)) document.getElementById("popularity").value=""; ' . "\n" . ' }  ' . "\n";

        echo "function prelater() { \n later('','','','','',''); \n } \n function later(t,w,h,c,p,m) { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var dlpll = ""; ' . "\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 = ""; ' . "\n";
        echo ' var height = ""; ' . "\n";
        echo ' var country = ""; ' . "\n";
        echo ' var popularity = ""; ' . "\n";
        echo ' if ((t.length + w.length + h.length + c.length + p.length) == 0) { ' . "\n";
        echo '   title = prompt("Enter Geo Map Title (background image URL or background image data URI ; separated (followed by ;) before title are available options, and you can prefix by a Region Code (eg. IT) (followed by ;) before title as an available options, and you can suffix by &onclick=y for added onclick functionality and/or &aregeographicals=y for you prefixing Labels by lat|long| values and/or &areplaces=y for places rather than countries, Email Attachment Title suffixes are &emailto=[emailTo] &emailsubject=[EmailSubject] (and to make a quiz question for someone after all your entries also append (things like) &guess=Brazil&question=Which country had Tijuana brass?))", "' . $GETtitle . '"); ' . "\n";
        echo ' }  ' . "\n";
        echo ' if ((t.length + w.length + h.length + c.length + p.length) != 0) { ' . "\n";
        echo ' title = t; ' . "\n";
        echo ' width = w; ' . "\n";
        echo ' height = h; ' . "\n";
        echo ' country = c; ' . "\n";
        echo ' popularity = p; ' . "\n";
        echo ' } else if (title != null) { ' . "\n";
        echo ' width = prompt("Enter Geo Map Width", "' . $GETwidth . '"); ' . "\n";
        echo ' height = prompt("Enter Geo Map Height", "' . $GETheight . '"); ' . "\n";
        echo ' if (title.indexOf("&are") != -1) { country = prompt("Enter Places Label", "Places");  } else { country = prompt("Enter Country Label", "' . $GETcountry . '"); } ' . "\n";
        echo ' popularity = prompt("Enter " + country + " Numerical Measure(s) (ie. can be comma separated)", "' . $GETpopularity . '"); ' . "\n";
        echo ' }  ' . "\n";
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        //echo ' datalineprefix = prompt("Enter " + country + " Name " + thisline, ""); ' . "\n";
        echo "    if (fti) { datalineprefix = ''; dlpll = '';  } else { dlpll=''; if (title.indexOf('&aregeographicals=') != -1) {  datalineprefix = prompt(\"Enter Latitude|Longitude|\" + country + \" Name (can enter URL whose contents contains country,numerical sets or your own list entered here comma separated) \" + thisline +  ' (optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {popularity}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={country}' + \"'\" + '>{country}</a>\" ' + '\\n\\n'" . $myextras . " + ' as an example of what is possible with HTML included)', ''); if (datalineprefix == null) { datalineprefix='';   } dlpll=datalineprefix.split('|')[0]; if (dlpll != '') { dlpll+='|' + datalineprefix.split('|')[1] + '|'; datalineprefix=datalineprefix.replace(dlpll,''); } } else { dlpll = '';   datalineprefix = prompt(\"Enter \" + country + \" Name (can enter URL whose contents contains country,numerical sets or your own list entered here comma separated) \" + thisline +  ' (optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {popularity}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={country}' + \"'\" + '>{country}</a>\" ' + '\\n\\n'" . $myextras . " + ' as an example of what is possible with HTML included)', '');  } } " . "\n";
        echo ' if (datalineprefix == null) { datalineprefix="";   } ' . "\n" . ' if (datalineprefix != null) { datalineprefix=dlp(datalineprefix); iof=0; dlsa=datalineprefix.split(","); if (dlsa.length > 1 && (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(",")))) { while (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(","))) { datalineprefix=datalineprefix.replace(",", "%2C"); iof+=0;   }  }    datalineprefix=datalineprefix.replace(/#/g, "%23"); if (datalineprefix.indexOf("{country}") != -1 && datalineprefix.indexOf(",") != -1) { dlsa=datalineprefix.split(","); if (dlsa.length > 1) {  datalineprefix=datalineprefix.replace("{country}",encodeURIComponent(dlsa[0])).replace("{country}",encodeURIComponent(dlsa[0]));   } }   } ' . "\n";
        echo ' while (datalineprefix.length != 0 && (popularity.indexOf("ercent") == (0 - 1) || popularity.indexOf("  ercent ") != (0 - 1) || (popularity.indexOf("ercent") != (0 - 1) && totalleft > 0))) { ' . "\n";
        echo ' if (datalinesuffix.length != 0) { ' . "\n";
        echo "    if (fti) { datalineprefix = ''; dlpll = '';  } else { dlpll=''; if (title.indexOf('&aregeographicals=') != -1) {  datalineprefix = prompt(\"Enter Latitude|Longitude|\" + country + \" Name (can enter URL whose contents contains country,numerical sets or your own list entered here comma separated) \" + thisline +  ' (for no more please hit Cancel button and optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {popularity}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={country}' + \"'\" + '>{country}</a>\" ' + '\\n\\n'" . $myextras . " + ' as an example of what is possible with HTML included)', ''); if (datalineprefix == null) { datalineprefix='';   } dlpll=datalineprefix.split('|')[0]; if (dlpll != '') { dlpll+='|' + datalineprefix.split('|')[1] + '|'; datalineprefix=datalineprefix.replace(dlpll,''); } } else { dlpll = '';  datalineprefix = prompt(\"Enter \" + country + \" Name (can enter URL whose contents contains country,numerical sets or your own list entered here comma separated) \" + thisline +  ' (for no more please hit Cancel button and optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {popularity}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={country}' + \"'\" + '>{country}</a>\" ' + '\\n\\n'" . $myextras . " + ' as an example of what is possible with HTML included)', ''); } } " . "\n";
        echo '    if (datalineprefix != null) {  datalineprefix=dlp(datalineprefix); iof=0; dlsa=datalineprefix.split(","); if (dlsa.length > 1 && (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(",")))) { while (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(","))) { datalineprefix=datalineprefix.replace(",", "%2C"); iof+=0;   }  }   datalineprefix=datalineprefix.replace(/#/g, "%23"); if (datalineprefix.indexOf("{country}") != -1 && datalineprefix.indexOf(",") != -1) { dlsa=datalineprefix.split(","); if (dlsa.length > 1) {  datalineprefix=datalineprefix.replace("{country}",encodeURIComponent(dlsa[0])).replace("{country}",encodeURIComponent(dlsa[0]));   } }   } ' . "\n";
        echo ' } ' . "\n";
        //echo ' } ' . "\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 (popularity.indexOf("ercent") != (0 - 1) && popularity.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     if (fti) { datalinesuffix = "";  } else {  datalinesuffix = prompt("Enter " + popularity.replace("  ercent ", "") + " " + thisline + extra, "0"); }  ' . "\n";
        echo '     if (datalinesuffix == null && popularity.indexOf("ercent") != (0 - 1) && popularity.indexOf("  ercent ") == (0 - 1)) datalinesuffix = totalleft; ' . "\n";
        echo '     if (datalinesuffix == null) datalinesuffix = "0"; ' . "\n";
        echo '     if (datalinesuffix != null) datalineprefix = datalineprefix.replace("{popularity}", datalinesuffix); ' . "\n";
        echo '     if (datalinesuffix.length == 0) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(totalleft) == eval(datalinesuffix) && popularity.indexOf("ercent") != (0 - 1) && popularity.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && popularity.indexOf("ercent") != (0 - 1) && popularity.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && popularity.indexOf("ercent") == (0 - 1) && popularity.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       popularity = popularity + "  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 + " [" + dlpll + "~" + 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 + " [" + dlpll + "~" + datalineprefix.replace(",", "~,") +  "," + datalinesuffix + "] "; } ' . "\n"; 
        echo '     thisline++; ' . "\n comma=','; \n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
          if (!isset($_GET['isMobile']) && !isset($_POST['isMobile'])) {
        echo ' if (allowed) window.location = "./geo_chart.php?title=" + title + m + "&width=" + width + "&height=" + height + "&country=" + country + nojwinextra + "&popularity=" + popularity.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
		  } else {
        echo ' if (allowed) window.location = "./geo_chart.php?isMobile=y&title=" + title + m + "&width=" + width + "&height=" + height + "&country=" + country + nojwinextra + "&popularity=" + popularity.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
          }
        echo "} \n"; // . "} \n";
        echo '</' . 'script' . '>' . "\n";
      } 
      
    echo "\n" . '<input type="hidden" id="ihide" value="0"></input>' . "\n";

   

  if (strpos($_SERVER['QUERY_STRING'], "justmenu") === false && strpos($_SERVER['HTTP_REFERER'], "justmenu") === false) {
  echo '</div><!-- /page -->' . "\n";
  } else {   
  echo '</div><!-- /page -->&nbsp;&nbsp;&nbsp;<a target="top" title="menu" href="//www.rjmprogramming.com.au/PHP/butsel.php?justmenu=justmenu">Menu</a>' . "\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].split(decodeURIComponent('#'))[0].split('#')[0] + "'></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.split(decodeURIComponent('#'))[0].split('#')[0]) + "'></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) {  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.indexOf('?') == -1) {
     document.getElementById('another').href+='?nojwin=Y';
    } else if (document.getElementById('another').href.indexOf('nojwin') == -1) {
     document.getElementById('another').href+='&nojwin=Y';
    }
  }
}

function preclickforemail() {
<?php 
 if (isset($_POST['emailto'])) {
   if (strpos(urldecode($_POST['emailto']), '@') !== false) {
      if (isset($_POST['emailto'])) echo "\n if (document.getElementById('theto') && yesgo) { document.getElementById('theto').value='" . urldecode($_POST['emailto']) . "'; } \n";
      if (isset($_POST['emailsubject'])) echo "\n if (document.getElementById('thesubject') && yesgo) { document.getElementById('thesubject').innerHTML=\"" . urldecode($_POST['emailsubject']) . "\"; } \n";
      if (isset($_POST['emailcc'])) echo "\n if (document.getElementById('thecc') && yesgo) { document.getElementById('thecc').value='" . urldecode($_POST['emailcc']) . "'; } \n";
      if (isset($_POST['emailbcc'])) echo "\n if (document.getElementById('thebcc') && yesgo) { document.getElementById('thebcc').value='" . urldecode($_POST['emailbcc']) . "'; } \n";
    echo "\n 
    if (yesgo) {
    yesgo3='MAILTO:" . urldecode($_POST['emailto']) . "';
    nogo3='MAILTO:fillin.email@address';
    yesgo2='\"' + document.URL.split('#')[0].split('?')[0].substring(0,10) + document.URL.split('#')[0].split('?')[0].substring(10).split('/')[0] + '/PHP/butsel.php';
    nogo2='\"//www.rjmprogramming.com.au/PHP/butsel.php';
    if (document.getElementById('another')) {
    yesgo=document.getElementById('another').href=document.URL.split('#')[0].split('?')[0];
    nogo='./' + document.URL.split('#')[0].split('?')[0].split('/')[eval(-1 + document.URL.split('#')[0].split('?')[0].split('/').length)];
    }
    }
     \n ";
      echo "\n if (clickforemail) { clickforemail(); } else if (document.getElementById('thesemail')) { document.getElementById('thesemail').click(); } \n";
   }
 }
?>
}

<?php 
 if (isset($_POST['emailto'])) {
   if (strpos(urldecode($_POST['emailto']), '@') !== false) {
     echo "\n setTimeout(preclickforemail,4000); \n";
   }
 }
?>


</script>
<div id="thedivemail"></div>
</body>
</html>
