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

// Thanks to https://gist.github.com/vxnick/380904
$countries = array
(
	'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',
	'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',
	'BR' => 'Brazil',
	'IO' => 'British Indian Ocean Territory',
	'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',
	'CC' => 'Cocos and Keeling Islands',
	'CO' => 'Colombia',
	'KM' => 'Comoros',
	'CG' => 'Congo',
	'CD' => 'Congo, Democratic Republic',
	'cd' => 'Democratic Republic of Congo',
	'CK' => 'Cook Islands',
	'CR' => 'Costa Rica',
	'CI' => 'Cote D\'Ivoire',
	'CI' => 'Ivory Coast',
	'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',
	'FK' => 'Falkland Islands (Malvinas)',
	'fk' => 'Falkland Islands',
	'FO' => 'Faroe Islands',
	'FJ' => 'Fiji',
	'FI' => 'Finland',
	'FR' => 'France',
	'GF' => 'French Guiana',
	'PF' => 'French Polynesia',
	'TF' => 'French Southern Territories',
	'GA' => 'Gabon',
	'GM' => 'Gambia',
	'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 & Mcdonald Islands',
	'Hm' => 'Heard Island and Mcdonald Islands',
	'hm' => 'Heard Island',
	'VA' => 'Holy See (Vatican City State)',
	'va' => 'Vatican City',
	'HN' => 'Honduras',
	'HK' => 'Hong Kong',
	'HU' => 'Hungary',
	'IS' => 'Iceland',
	'IN' => 'India',
	'ID' => 'Indonesia',
	'IR' => 'Iran, Islamic Republic Of',
	'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',
	'KR' => 'Republic of Korea',
	'KP' => 'Democratic People\'s Republic of Korea',
	'kp' => 'North Korea',
	'Kr' => 'South Korea',
	'kr' => 'Korea',
	'KW' => 'Kuwait',
	'KG' => 'Kyrgyzstan',
	'LA' => 'Lao People\'s Democratic Republic',
	'la' => 'Laos',
	'LV' => 'Latvia',
	'LB' => 'Lebanon',
	'LS' => 'Lesotho',
	'LR' => 'Liberia',
	'LY' => 'Libyan Arab Jamahiriya',
	'ly' => 'Libya',
	'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, Federated States Of',
	'fm' => 'Micronesia',
	'MD' => 'Moldova',
	'MC' => 'Monaco',
	'MN' => 'Mongolia',
	'ME' => 'Montenegro',
	'MS' => 'Montserrat',
	'MA' => 'Morocco',
	'MZ' => 'Mozambique',
	'MM' => 'Myanmar',
	'NA' => 'Namibia',
	'NR' => 'Nauru',
	'NP' => 'Nepal',
	'NL' => 'Netherlands',
	'AN' => 'Netherlands Antilles',
	'AN' => 'Antilles',
	'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, Occupied',
	'PS' => 'Palestine',
	'PA' => 'Panama',
	'PG' => 'Papua New Guinea',
	'PY' => 'Paraguay',
	'PE' => 'Peru',
	'PH' => 'Philippines',
	'PN' => 'Pitcairn',
	'PL' => 'Poland',
	'PT' => 'Portugal',
	'PR' => 'Puerto Rico',
	'QA' => 'Qatar',
	'RE' => 'Reunion',
	'RO' => 'Romania',
	'RU' => 'Russian Federation',
	'RU' => 'Russia',
	'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 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',
	'SI' => 'Slovenia',
	'SB' => 'Solomon Islands',
	'SO' => 'Somalia',
	'ZA' => 'South Africa',
	'GS' => 'South Georgia And Sandwich Isl.',
	'GS' => 'South Georgia And Sandwich Island',
	'GS' => 'South Georgia',
	'ES' => 'Spain',
	'LK' => 'Sri Lanka',
	'SD' => 'Sudan',
	'SR' => 'Suriname',
	'SJ' => 'Svalbard And Jan Mayen',
	'SZ' => 'Swaziland',
	'SE' => 'Sweden',
	'CH' => 'Switzerland',
	'SY' => 'Syrian Arab Republic',
	'SY' => 'Syria',
	'TW' => 'Taiwan',
	'TJ' => 'Tajikistan',
	'TZ' => 'Tanzania',
	'TH' => 'Thailand',
	'TL' => 'Timor-Leste',
	'tl' => 'East Timor',
	'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',
	'gb' => 'Great Britain',
	'US' => 'United States',
	'UM' => 'United States Outlying Islands',
	'UY' => 'Uruguay',
	'UZ' => 'Uzbekistan',
	'VU' => 'Vanuatu',
	'VE' => 'Venezuela',
	'VN' => 'Viet Nam',
	'vn' => 'Vietnam',
	'VG' => 'Virgin Islands, British',
	'VI' => 'Virgin Islands, U.S.',
	'VI' => 'Virgin Islands',
	'WF' => 'Wallis And Futuna',
	'EH' => 'Western Sahara',
	'YE' => 'Yemen',
	'ZM' => 'Zambia',
	'ZW' => 'Zimbabwe',
);


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 tzl($inwith, $dc) {
   global $countries;
   if (!$dc) $inwithtz=($inwith);
   if ($dc) $inwithtz=urldecode($inwith);
   if (strpos(strtolower($inwithtz), "http;") !== false && strpos(strtolower($inwithtz), "~http") === false && strpos(strtolower($inwithtz), "',") !== false) {
     $inwithtz=str_replace("http;","~http;",str_replace("HTTP;","~http;",str_replace("Http;","~http;",  str_replace("https;","~https;",str_replace("HTTPs;","~https;",str_replace("Https;","~https;",    str_replace("',","~,",$inwithtz) ))))));
   } else if (strpos(strtolower($inwithtz), "https;") !== false && strpos(strtolower($inwithtz), "~http") === false && strpos(strtolower($inwithtz), "',") !== false) {
     $inwithtz=str_replace("http;","~http;",str_replace("HTTP;","~http;",str_replace("Http;","~http;",  str_replace("https;","~https;",str_replace("HTTPs;","~https;",str_replace("Https;","~https;",    str_replace("',","~,",$inwithtz) ))))));
   }
   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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_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('intensity_chart.php','intensity_chart.php',str_replace('index.php','intensity_chart.php',$_SERVER['REQUEST_URI'])))));
   } else {
   $oldinwith=$inwith;
   $iwt=explode(",",$inwith);
   for ($jwt=0; $jwt<sizeof($iwt); $jwt++) {
   $country_that_you_want_to_convert=trim(str_replace('"','',str_replace('[','',str_replace(']','',str_replace('~','',$iwt[$jwt])))));
   if (trim($country_that_you_want_to_convert) != "") {
     $iso_code = array_search(strtolower($country_that_you_want_to_convert), array_map('strtolower', $countries));
     if (strlen(("" . $iso_code)) == 2) { // Thanks to https://gist.github.com/vxnick/380904
       $inwith=str_replace($country_that_you_want_to_convert, strtoupper($iso_code), $inwith);
     }
   }
   }
   
   if ($oldinwith != $inwith) {
    echo "\n
       if (document.URL.indexOf('data=') != -1) {
       alturl=document.URL.replace(document.URL.split('data=')[1].split('&')[0], ourencodeURIComponent(('`' + \"" . $inwith . "\").replace('`,','').replace('`','')));
       alturl=alturl.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';
       } else {
       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';
       }
       alturl=alturl.replace('&data=%20%2C%20','&data=%20');
       while (alturl.indexOf('] .0000000000 [') != -1) {
         alturl=alturl.replace('] .0000000000 [','] ' + ',' + ' [');
       }
       while (alturl.indexOf('%20.0000000000%20') != -1) {
         alturl=alturl.replace('%20.0000000000%20','%20,%20');
       }
       ";
   }
   
     return $inwith;
   }
   $iwt=explode(",",$inwithtz);
   for ($jwt=0; $jwt<sizeof($iwt); $jwt++) {
   $country_that_you_want_to_convert=trim(str_replace('"','',str_replace('[','',str_replace(']','',str_replace('~','',$iwt[$jwt])))));
   if (trim($country_that_you_want_to_convert) != "") {
     $iso_code = array_search(strtolower($country_that_you_want_to_convert), array_map('strtolower', $countries));
     if (strlen(("" . $iso_code)) == 2) { // Thanks to https://gist.github.com/vxnick/380904
       $inwithtz=str_replace($country_that_you_want_to_convert, strtoupper($iso_code), $inwithtz);
     }
   }
   }
   $iwt=explode(",",$inwithtz);
   $ginwithtz=$iwt[0];
   for ($jwt=0; $jwt<sizeof($iwt); $jwt++) {
   if ($jwt > 0) {
   if (strpos($iwt[$jwt], "]") !== false) {
   $ginwithtz.="]" . explode("]",$iwt[$jwt])[1];
   } else {
   $ginwithtz.="," . $iwt[$jwt];
   }
   }
   }
   echo "\n pardata=\"" . urlencode(" ," . $inwithtz) . "\"; paramdata=decodeURIComponent(pardata);  \n var xxpardata=\"" . ("," . $inwithtz) . "\"; \n";
   echo "\n
       if (document.URL.indexOf('data=') != -1) {
       alturl=document.URL.replace(document.URL.split('data=')[1].split('&')[0], ourencodeURIComponent(('`' + \"" . $ginwithtz . "\").replace('`,','').replace('`','')));
       alturl=alturl.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';
       } else {
       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';
       }
       alturl=alturl.replace('&data=%20%2C%20','&data=%20');
       while (alturl.indexOf('] .0000000000 [') != -1) {
         alturl=alturl.replace('] .0000000000 [','] ' + ',' + ' [');
       }
       while (alturl.indexOf('%20.0000000000%20') != -1) {
         alturl=alturl.replace('%20.0000000000%20','%20,%20');
       }
       ";
   return $inwithtz;
}


  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 fti=false,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 dlp(thisris) {
      if (thisris != null) {
        var commacount=thisris.toLowerCase().replace(/\\<\\/td\\>/g,'  ,  ').indexOf(',');
        if (commacount != -1) {
             commacount=(thisris + ' ').substring(eval(1 + commacount)).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 > 2) {
             fldq=pielines[1].split(',');
             var fldqlength=3; //fldq.length;
             zisok=true;
             if ((fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[0].replace('" . '"' . "','').trim() + ' ').substring(0,1) > '9') {
              if ((fldq[eval(-1 + fldqlength)].replace('" . '"' . "','').trim() + ' ').substring(0,1) < '0' || (fldq[eval(-1 + fldqlength)].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 > 2) {
                if ((inpies[0].trim() + ' ').substring(0,1) == '" . '"' . "' && (inpies[1].trim() + ' ').substring(0,1) == '" . '"' . "' && (inpies[2].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(',','') + ',' + inpies[2].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','');

                } else 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(',','') + ',' + inpies[2].trim().replace('%','').replace('" . '"' . "','');

                } else if ((inpies[0].trim() + ' ').substring(0,1) == '" . '"' . "' && (inpies[2].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','') + ',' + inpies[1].trim().replace('%','').replace('" . '"' . "','') + ',' + inpies[2].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','');

                } else if ((inpies[1].trim() + ' ').substring(0,1) == '" . '"' . "' && (inpies[2].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','') + ',' + inpies[2].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('" . '"' . "','') + ',' + inpies[2].trim().replace('%','').replace('" . '"' . "','');
                } else if ((inpies[1].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().replace('%','').replace('" . '"' . "','') + ',' + inpies[2].trim().replace('%','').replace('" . '"' . "','');


                } else if ((inpies[2].trim() + ' ').substring(0,1) == '" . '"' . "') {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','') + ',' + inpies[2].trim().substring(1).split('" . '"' . "')[0].trim().replace('%','').replace(',','').replace(',','');

                } else {
                sthatris=pied + inpies[0].trim().replace('%','') + ',' + inpies[1].trim().replace('%','').replace('" . '"' . "','') + ',' + inpies[2].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') || ((inpies[2].trim() + ' ').substring(0,1) >= '0' && (inpies[2].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) {
            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 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) {
            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 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('`','')));
             }
            }  
  }
 ";

      $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']);
       $GETdata = tzl(strtoupper($_GET['data']),true);
       $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 ' if (fti) { datalineprefix = "";  } else { datalineprefix = prompt("Enter " + country + " Two Letter Code (can enter URL whose contents contains country,numerical1,numerical2 sets or your own list entered here comma separated) " + thisline, ""); }  if (datalineprefix == null) { datalineprefix=""; } else {   datalineprefix=dlp(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) { if (fti) { datalineprefix = "";  } else { datalineprefix = prompt("Enter " + country + " Two Letter Code (can enter URL whose contents contains country,numerical1,numerical2 sets or your own list entered here comma separated) " + 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 '     if (fti) { datalinesuffix = "0,0"; } else { 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>
