<?php
// City Guess Country Game
// RJM Programming
// January, 2016
// Thanks to http://www.webserviceX.NET
set_time_limit(200);

$preget="";

function getih($indefe) {
global $preget;
$preget='';
if (strlen(trim($indefe)) == 2) {  $preget='|' . trim(strtoupper($indefe)); };
$lri="ABCDEFGHIJKLMNOPQRSTUVWXYZ^$";
$zri="abcdefghijklmnopqrstuvwxyz^$0123456789#@!~`";
$dri=["127462","127463","127464","127465","127466","127467","127468","127469","127470","127471","127472","127473","127474","127475","127476","127477","127478","127479","127480","127481","127482","127483","127484","127485","127486","127487","127988","917631"];
$sri=["917601","917602","917603","917604","917605","917606","917607","917608","917609","917610","917611","917612","917613","917614","917615","917616","917617","917618","917619","917620","917621","917622","917623","917624","917625","917626","127988","917631","30","31","32","33","34","35","36","37","38","39","127937","65039","8205","127752","127987"];
      $thiscc=$indefe;
      $ccsuff='';
      $ccchar=' ';
      $cde='&#';
      for ($iccsuff=0; $iccsuff<strlen($thiscc); $iccsuff++) {
        $ccchar=substr($thiscc, $iccsuff, (1 + $iccsuff));
        if (strtolower($ccchar) == $ccchar) {
        $ccsuff.=$cde . $sri[strpos($lri,$ccchar)] . ';'; //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
        } else {
        $ccsuff.=$cde . $dri[strpos($lri,$ccchar)] . ';'; //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
        }
      }
      return $ccsuff;
}

$egoes="0";
$escore="0";
$emdef="";

if (isset($_POST['thiscity']) && isset($_POST['ucountry']) && isset($_POST['eanswer'])) {
  if ($_POST['ucountry'] == $_POST['eanswer']) {
    $egoes="1  Well done!  " . str_replace("+"," ",urldecode($_POST['thiscity'])) . " is indeed in " . str_replace("+"," ",urldecode($_POST['eanswer'])) . ".";
    $escore="1";
  } else {
    $egoes="1  Sorry, <a title='Google image search' style=cursor:pointer;text-decoration:underline; onclick=woit(this.innerHTML);>" . str_replace("+"," ",urldecode($_POST['thiscity'])) . "</a> is in " . str_replace("+"," ",urldecode($_POST['eanswer'])) . " but is not in " . str_replace("+"," ",urldecode($_POST['ucountry'])) . ".";
  }
  if (isset($_POST['emailfrom'])) {
    $emdef=str_replace("+"," ",urldecode($_POST['emailfrom']));
  }
} else if (isset($_GET['thiscity']) && isset($_GET['ucountry']) && isset($_GET['eanswer'])) {
  if ($_GET['ucountry'] == $_GET['eanswer']) {
    $egoes="1  Well done!  " . str_replace("+"," ",urldecode($_GET['thiscity'])) . " is indeed in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . ".";
    $escore="1";
  } else {
    $egoes="1  Sorry, <a title='Google image search' style=cursor:pointer;text-decoration:underline; onclick=woit(this.innerHTML);>" . str_replace("+"," ",urldecode($_GET['thiscity'])) . "</a> is in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . " but is not in " . str_replace("+"," ",urldecode($_GET['ucountry'])) . ".";
  }
  if (isset($_GET['emailfrom'])) {
    $emdef=str_replace("+"," ",urldecode($_GET['emailfrom']));
  }
}

$citiesarr=[];
$uniquecountries=",";
$countriesarr=[];
$countriesisotwo=[];

$ctyisotwo=file_get_contents("http://www.nationsonline.org/oneworld/country_code_list.htm");
$ctyisotwo=str_replace("Lao PDR","Laos",$ctyisotwo);
$ctyisotwo=str_replace("Tanzania</a>, United Republic of","Tanzania</a>",$ctyisotwo);
$ctyisotwo=str_replace("Iran, Islamic Republic of","Iran",$ctyisotwo);
$ctyisotwo=str_replace("Macedonia, the Former Yugoslav Republic of","Macedonia",$ctyisotwo);
$ctyisotwo=str_replace("Korea</a> (North)","North Korea</a>",$ctyisotwo);
$ctyisotwo=str_replace("Korea</a> (South)","South Korea</a>",$ctyisotwo);
// <tr>
// <td><div class="flag" id="AFG"></div></td>
// <td class="abs"><a href="afghanistan.htm">Afghanistan</a></td>
// <td style="text-align:center"> AF</td>
// <td style="text-align:center">AFG</td>
// <td style="text-align:center">004</td>
// </tr>

foreach (glob("*.zip") as $zipfile) {
     $zip = zip_open($zipfile);
     if ($zip) {
      $outxml=" ";
      while ($zip_entry = zip_read($zip)) {
       $ourfilename=zip_entry_name($zip_entry);
       $regexpok=0;
       if (strpos($ourfilename, "_MACOSX/") === false) {
        //$regexp="/^[\S]" . str_replace('[\s\S]?','[\s\S]*',str_replace('*','[\s\S]?',str_replace('?',',',str_replace('%',',',str_replace('.','[.]',$ofwhat))))) . "$/";
        //$regexpok=preg_match($regexp, explode("/",$ourfilename)[-1 + sizeof(explode("/",$ourfilename))]);
        $regexpok=1;
        if ($regexpok !== 0) {
         if ($outxml == " ") { $outxml=""; }
         $fchunk=zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
         
         if (strpos(strtolower($ourfilename), ".xml") !== false && strpos($fchunk, "<City>") !== false && strpos($fchunk, "<Country>") !== false) {
       //echo strtoupper($ourfilename) . "\n";
 $bits=explode("<City>", $fchunk);
 for ($i=1; $i<sizeof($bits); $i++) {
  $thistwobits=explode("<", $bits[$i]);
  $citiesarr[sizeof($citiesarr)]=$thistwobits[0];
  $thistwobits=explode("<Country>", $bits[-1 + $i]);
  $thosetwobits=explode("<", $thistwobits[-1 + sizeof($thistwobits)]);
  $countriesarr[sizeof($countriesarr)]=$thosetwobits[0];
  if (strpos($ctyisotwo, ">" . $thosetwobits[0]) !== false) {
    $countriesisotwo[sizeof($countriesisotwo)]=getih(trim(explode("<",explode('">', explode(">" . $thosetwobits[0],$ctyisotwo)[1])[1])[0]));
  } else {
    $countriesisotwo[sizeof($countriesisotwo)]=trim("  ");
  }
  if (!strstr($uniquecountries, "," . urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",")) {
   $uniquecountries .= urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",";
   //echo $thosetwobits[0] . "\n";
  }
  
  $countriesarr[-1 + sizeof($countriesarr)].=$countriesisotwo[-1 + sizeof($countriesisotwo)];
  $countriesisotwo[-1 + sizeof($countriesisotwo)]='';

 //echo "0:" . sizeof($countriesarr) . "\n";
 }
         } else if (strpos(strtolower($ourfilename), ".csv") !== false) { // thanks to https://simplemaps.com/data/world-cities
// "city","city_ascii","lat","lng","country","iso2","iso3","admin_name","capital","population","id"
// "Tokyo","Tokyo","35.6897","139.6922","Japan","JP","JPN","Tōkyō","primary","37977000","1392685764"
// "Jakarta","Jakarta","-6.2146","106.8451","Indonesia","ID","IDN","Jakarta","primary","34540000","1360771077"

       //echo strtolower($ourfilename) . "\n";
 $bits=explode("\n", $fchunk);
 $hbit=str_replace('"','',strtolower($bits[0]));
 $hbits=explode(",", $hbit);
 $citycol=-1;
 $countrycol=-1;
 $isocol=-1;
 if (strpos(("," . $hbit . ","), ",city") !== false && strpos(("," . $hbit . ","), ",country") !== false && strpos($hbit, ",") !== false) {
 for ($i=0; $i<sizeof($hbits); $i++) {
   if ($citycol == -1 && strpos($hbits[$i], "city") !== false) {
     $citycol=$i;
   } else if ($countrycol == -1 && strpos($hbits[$i], "country") !== false) {
     $countrycol=$i;
   } else if ($isocol == -1 && strpos($hbits[$i], "iso") !== false) {
     $isocol=$i;
   }  
 }
 if ($citycol >=0 && $countrycol >= 0) {
 for ($i=1; $i<sizeof($bits); $i++) {
  if (substr(str_replace('"','',explode(",",$bits[$i])[$countrycol]),0,1) >= "A") {
  if (substr($bits[$i],0,1) == '"') {
  $citiesarr[sizeof($citiesarr)]=str_replace('"','',explode('","',$bits[$i])[$citycol]);
  } else {
  $citiesarr[sizeof($citiesarr)]=explode(",",$bits[$i])[$citycol];
  }
  if (substr($bits[$i],0,1) == '"') {
  $countriesarr[sizeof($countriesarr)]=str_replace('"','',explode(",",$bits[$i])[$countrycol]);
  } else {
  $countriesarr[sizeof($countriesarr)]=explode(",",$bits[$i])[$countrycol];
  }
  if ($isocol >= 0) {
    if (substr($bits[$i],0,1) == '"') {
    $countriesisotwo[sizeof($countriesisotwo)]=getih(str_replace('"','',explode(",",$bits[$i])[$isocol]));
    } else {
    $countriesisotwo[sizeof($countriesisotwo)]=getih(explode(",",$bits[$i])[$isocol]);
    }
  } else {
    $countriesisotwo[sizeof($countriesisotwo)]=trim("  ");
  }
  if (!strstr($uniquecountries, "," . urlencode(str_replace('"','',explode(",",$bits[$i])[$countrycol]) . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",")) {
   $uniquecountries .= urlencode(str_replace('"','',explode(",",$bits[$i])[$countrycol]) . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",";
 //echo str_replace('"','',explode(",",$bits[$i])[$countrycol]) . "\n";
  }
  
  $countriesarr[-1 + sizeof($countriesarr)].=$countriesisotwo[-1 + sizeof($countriesisotwo)];
  $countriesisotwo[-1 + sizeof($countriesisotwo)]='';
  }
 }
 }
 }
         }
         
         
         //$outxml.=$outd . $ourfilename . "@!@!@" . str_replace("'", "' + String.fromCharCode(39) + '", str_replace( "\r", " ", str_replace("\n"," ",str_replace('<','&lt;',str_replace('>','&gt;',$isc)))));
         //$outxml.=$outd . $ourfilename . "@!@!@" . $fchunk;
         //$outd="!@!@!";
        }
       }
      }
      zip_close($zip);
      $zip=null;
     }
 //echo "1:" . sizeof($countriesarr) . "\n";
}
//echo "\n finished\n";

if (1 == 2) {
foreach (glob("*cities*.xml") as $filename) {
 $fchunk=file_get_contents($filename);
 $bits=explode("<City>", $fchunk);
 for ($i=1; $i<sizeof($bits); $i++) {
  $thistwobits=explode("<", $bits[$i]);
  $citiesarr[sizeof($citiesarr)]=$thistwobits[0];
  $thistwobits=explode("<Country>", $bits[-1 + $i]);
  $thosetwobits=explode("<", $thistwobits[-1 + sizeof($thistwobits)]);
  $countriesarr[sizeof($countriesarr)]=$thosetwobits[0];
  if (strpos($ctyisotwo, ">" . $thosetwobits[0]) !== false) {
    $countriesisotwo[sizeof($countriesisotwo)]=getih(trim(explode("<",explode('">', explode(">" . $thosetwobits[0],$ctyisotwo)[1])[1])[0]));
  } else {
    $countriesisotwo[sizeof($countriesisotwo)]=trim("  ");
  }
  if (!strstr($uniquecountries, "," . urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",")) {
   $uniquecountries .= urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",";
  }
  
  $countriesarr[-1 + sizeof($countriesarr)].=$countriesisotwo[-1 + sizeof($countriesisotwo)];
  $countriesisotwo[-1 + sizeof($countriesisotwo)]='';

 }
}

$caplist=file_get_contents("http://www.rjmprogramming.com.au/PHP/country_capital_quiz.php");
// countries.push("Afghanistan");  countryids.push("Afghanistan");  capitals.push("Kabul"); num++;
// countries.push("Albania");  countryids.push("Albania");  capitals.push("Tirana"); num++;

$clarr=explode('countries.push("', $caplist);
for ($ihg=1; $ihg<sizeof($clarr); $ihg++) {
  $countriesarr[sizeof($countriesarr)]=explode('"', $clarr[$ihg])[0];
  
  if (strpos($ctyisotwo, ">" . explode('"', $clarr[$ihg])[0]) !== false) {
    $countriesisotwo[sizeof($countriesisotwo)]=getih(trim(explode("<",explode('">', explode(">" . explode('"', $clarr[$ihg])[0],$ctyisotwo)[1])[1])[0]));
  } else {
    $countriesisotwo[sizeof($countriesisotwo)]=trim("  ");
  }
  
  if (!strstr($uniquecountries, "," . urlencode(explode('"', $clarr[$ihg])[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",")) {
   $uniquecountries .= urlencode(explode('"', $clarr[$ihg])[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)] . $preget) . ",";
  }
  
  $countriesarr[-1 + sizeof($countriesarr)].=$countriesisotwo[-1 + sizeof($countriesisotwo)];
  $countriesisotwo[-1 + sizeof($countriesisotwo)]='';

  $citiesarr[sizeof($citiesarr)]=explode('"', explode('capitals.push("', $clarr[$ihg])[1])[0];
}
}
//echo "\n really finished\n";


function cmp($a, $b) { // alphabetical comparison method
    $ta=explode("title=", $a);
    $tb=explode("title=", $b);
    if ($ta[sizeof($ta) - 1] == $tb[sizeof($tb) - 1]) {
        return 0;
    }
    return ($ta[sizeof($ta) - 1] < $tb[sizeof($tb) - 1]) ? -1 : 1;
}

function showucountries() {
 global $uniquecountries, $preget;
 $ret="<select title='Can select, also, via two uppercase character ISO Country Code or lowercase character autocompletion Country list (until unique) shown here' data-topiso='' style='background-color:pink;width:70%;height:60px;font-size:32px;' name='ucountry' id='ucountry' onchange='if (this.value.trim().length > 0) { picked(this.value,this); }'><option data-iso='' data-defih='Please select Country ...' value='' id=oneopt>Please select Country ...</option></select>";
 $ucountriesarr=explode(",", $uniquecountries);
 usort($ucountriesarr, "cmp");
 for ($i=0; $i<sizeof($ucountriesarr); $i++) {
   if (strlen($ucountriesarr[$i]) != 0) { $preget=""; if (strpos(urldecode($ucountriesarr[$i]), "|") !== false) { $preget=explode("|", urldecode($ucountriesarr[$i]))[1];  } $ret=str_replace("</select>", "<option title='" . $preget . "' data-iso='" . $preget . "' value='" . explode("|",urldecode($ucountriesarr[$i]))[0] . "'>" . explode("|",urldecode($ucountriesarr[$i]))[0] . "</option></select>", $ret);  }
 }
 return $ret;
}

function notshowucities() {
 global $citiesarr, $countriesarr;
 $ret="<select name='ucity' id='ucity' style='display:none;'></select>";
 //echo "" . sizeof($countriesarr) . "\n";
 $zerois=0;
 $oneinc=1;
 $ii=0;
 if (sizeof($countriesarr) > 1000) {  $oneinc=floor(sizeof($countriesarr) / 1000); $zerois=rand(0,994); }
 for ($i=$zerois; $i<sizeof($countriesarr); $i+=$oneinc) {
   $ret=str_replace("</select>", "<option id='o" . $i . "' value='" . ($citiesarr[$i]) . "'>" . ($countriesarr[$i]) . "</option></select>", $ret);
   $ii++;
 }
 return $ret;
}

function shownextcity() {
 global $citiesarr, $countriesarr, $egoes, $escore, $emdef;
 $ret="<s" . "cript type='text/javascript'>\n var completefinding='', kbsofar='', notc=''; \n var urlprefix='//www.google.com.au/search?tbm=isch&q='; \n var emdef='" . $emdef . "'; \n var firstgo=true; \n var goes=" . explode(" ", $egoes)[0] . "; \n var score=" . $escore . "; \n var lcity=''; \n var oucity=null; var numc=" . sizeof($citiesarr) . ";\n var ans=false; var lastg=-1;\n var ccountry=''; \n 
 function askemail() {
 if (document.getElementById('emailto').value.indexOf('@') == -1) {
 var emis=prompt('Please enter Email To address?',emdef);
 if (emis) {
 if (emis.indexOf('@') != -1) {
 document.getElementById('emailto').value=emis;
 }
 }
 }
 if (document.getElementById('emailto').value.indexOf('@') != -1) {
 document.getElementById('htmlis').value=document.getElementById('htmlis').value.replace(' value=\" \"', ' value=\"' + emis + '\"');
 document.getElementById('contact').click();
 }
 }
 function woit(incity) {
 window.open(urlprefix + encodeURIComponent(incity), '_blank', 'top=50,left=50,width=400,height=400');  
 }
 function gethtmlready(incval) {
 var huhsel='<input' + document.getElementById('cgcform').outerHTML.split('<input')[eval(-1 + document.getElementById('cgcform').outerHTML.split('<input').length)].split('>')[0] + '>';
 document.getElementById('htmlis').value='<html><head><meta charset=\"utf-8\"></head><body><h1>City Guess Country Game</h1><h3>Which Country is City In?</h3>' + document.getElementById('cgcform').outerHTML.replace(' action=\"//',' action=\"https://').replace(' value=\"\"',' value=\"' + incval + '\"').replace(huhsel + '</input>','').replace(huhsel,'').replace('display:none','display:inline-block').replace('>','><input name=eanswer type=hidden value=\"' + ccountry + '\"></input><input name=emailfrom type=hidden value=\"' + ' ' + '\"></input>') + '</body></html>';
 }
 function picked(gcountry, gcselo) { 
 gcselo.setAttribute('data-topiso', '' + gcselo.options[gcselo.selectedIndex].getAttribute('data-iso'));
 notc=' (not ' + gcountry + ')';
 if (document.getElementById('bemail')) { 
 document.getElementById('bemail').style.display='inline-block'; 
 }  
 goes++; 
 if (gcountry == ccountry) { 
 score++; document.getElementById('score').innerHTML='Score: ' + score + ' Goes: ' + goes; 
 notc='';
 document.getElementById('ucountry').title=document.getElementById('ucountry').title.split(' ... ')[0];
 if (firstgo) { ans=confirm('Well done.  OK does a Google (image) search.'); 
 } 
 } else {  
 document.getElementById('score').innerHTML='Score: ' + score + ' Goes: ' + goes; 
 ans=confirm('Sorry, but answer is ' + ccountry + notc + '.   OK does a Google (image) search.');  
 notc='';
 document.getElementById('ucountry').title=document.getElementById('ucountry').title.split(' ... ')[0];
 } 
 firstgo=false; 
 if (ans == true) { 
 window.open(urlprefix + encodeURIComponent(lcity), '_blank', 'top=50,left=50,width=400,height=400');  
 } 
 document.getElementById('ucountry').value=''; 
 document.getElementById('oneopt').innerHTML='Please select Country ...';
 kbsofar='';
 getnext(); 
 } \n  
 function getnext() { 
 if (document.getElementById('bemail')) { 
 document.getElementById('bemail').style.display='inline-block'; 
 }  
 if (!oucity) { 
 oucity=document.getElementById('ucity'); 
 } 
 var rnum=lastg; 
 while (rnum == lastg) { 
 rnum=Math.floor(Math.random() * numc); 
 if (!document.getElementById('o' + rnum)) { rnum=lastg;    } 
 } \n 
 lastg=rnum; 
 var ois=document.getElementById('o' + rnum); \n 
 document.getElementById('ucity').value=ois.value; \n 
 lcity=ois.value; \n 
 document.getElementById('thiscity').value=ois.value; 
 document.getElementById('thiscity').title=ois.value; 
 document.getElementById('thcity').innerHTML='City<br><font size=1>' + ois.value + '</font>'; 
 ccountry=ois.innerHTML; 
 gethtmlready(ois.value); \n 
 } \n 
 function dodecide() {
         if (completefinding.trim() != '') {
            document.getElementById('ucountry').value=completefinding;
            notc=' (not ' + completefinding + ')';
            picked(document.getElementById('ucountry').value, document.getElementById('ucountry'));
            kbsofar='';
            completefinding='';
            // location.href='#cgcform';
        }
 } \n 
 function crokp(event) {
     if (event.keyCode == 13) {
        if (completefinding.trim() != '') {
            document.getElementById('ucountry').value=completefinding;
            notc=' (not ' + completefinding + ')';
            picked(document.getElementById('ucountry').value, document.getElementById('ucountry'));
            kbsofar='';
            completefinding='';
            // location.href='#cgcform';
        } else if (document.getElementById('bemail')) { 
        document.getElementById('bemail').click();
        }
     }
 } \n 
 function okp(event) {
    var optl=[], joptl=0, jdone=false, findings='', findingsd='', lendiff='', lendiffd='';
    completefinding='';
    if (event.keyCode >= 65 && event.keyCode <= 90) {
      kbsofar+=String.fromCharCode(event.keyCode);
      //document.title=kbsofar;
      if (kbsofar.length == 2 && kbsofar == kbsofar.toUpperCase()) {
        optl=document.getElementsByTagName('option');
        for (joptl=1; joptl<optl.length; joptl++) {
          if (('' + optl[joptl].getAttribute('data-iso')) == kbsofar && !jdone) {
            //alert(optl[joptl].outerHTML);
            jdone=true;
            document.getElementById('ucountry').value=optl[joptl].value;
            notc=' (not ' + optl[joptl].innerHTML + ')';
            picked(document.getElementById('ucountry').value, document.getElementById('ucountry'));
            kbsofar='';
          }
        }
      } else {
        optl=document.getElementsByTagName('option');
        for (joptl=1; joptl<optl.length; joptl++) {
          if (optl[joptl].value != '' && ('' + optl[joptl].innerHTML.toLowerCase()).indexOf(kbsofar.toLowerCase()) == 0 && ('' + optl[joptl].outerHTML).indexOf(' data-') != -1) {
            lendiff+=lendiffd + eval(eval('' + optl[joptl].value.length) - eval('' + kbsofar.length));
            lendiffd=',';
            if (eval(eval('' + optl[joptl].value.length) - eval('' + kbsofar.length)) <= 4) {
              if (completefinding == '') {
                completefinding=optl[joptl].value;
              } else {
                completefinding=' ';
              }
            }
            findings+=findingsd + optl[joptl].value;
            findingsd=',';
          }
        }
        if (findings == '') {
        document.getElementById('oneopt').innerHTML='Please select Country ...';
        kbsofar='';
        } else if (findings.indexOf(',') != -1) {
        document.getElementById('oneopt').innerHTML=findings;
        document.getElementById('ucountry').title=document.getElementById('ucountry').title.split(' ... ')[0] + ' ... ' + findings;
        //document.title=lendiff + ' .... ' + completefinding;
        if (completefinding.trim() != '') {
          setTimeout(dodecide,2000);
        }
        } else {
            document.getElementById('ucountry').value=findings;
            notc=' (not ' + findings + ')';
            picked(document.getElementById('ucountry').value, document.getElementById('ucountry'));
            kbsofar='';
            // location.href='#cgcform';
        }
      }
    } else if ((event.keyCode >= 97 && event.keyCode <= 122) || event.keyCode == 32) {
      kbsofar+=String.fromCharCode(event.keyCode);
        optl=document.getElementsByTagName('option');
        for (joptl=1; joptl<optl.length; joptl++) {
          if (optl[joptl].value != '' && ('' + optl[joptl].innerHTML.toLowerCase()).indexOf(kbsofar.toLowerCase()) == 0 && ('' + optl[joptl].outerHTML).indexOf(' data-') != -1) {
            lendiff+=lendiffd + eval(eval('' + optl[joptl].value.length) - eval('' + kbsofar.length));
            lendiffd=',';
            if (eval(eval('' + optl[joptl].value.length) - eval('' + kbsofar.length)) <= 4) {
              if (completefinding == '') {
                completefinding=optl[joptl].value;
              } else {
                completefinding=' ';
              }
            }
            findings+=findingsd + optl[joptl].value;
            findingsd=',';
          }
        }
        if (findings == '') {
        document.getElementById('oneopt').innerHTML='Please select Country ...';
        kbsofar='';
        } else if (findings.indexOf(',') != -1) {
        document.getElementById('oneopt').innerHTML=findings;
        document.getElementById('ucountry').title=document.getElementById('ucountry').title.split(' ... ')[0] + ' ... ' + findings;
        //document.title=lendiff + ' ... ' + completefinding;
        if (completefinding.trim() != '') {
          setTimeout(dodecide,2000);
        }
        } else {
            document.getElementById('ucountry').value=findings;
            notc=' (not ' + findings + ')';
            picked(document.getElementById('ucountry').value, document.getElementById('ucountry'));
            kbsofar='';
            // location.href='#cgcform';
        }
    }
    return false;
}
 </s" . "cript>";
 return $ret;
}

echo "<!doctype html><html><head><meta charset='utf-8'><link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'><title>City Guess Country Game</title>" . shownextcity() . "</head><body onkeydown='crokp(event);' onkeypress='return okp(event);' style='background-color: olive;' onload='setTimeout(getnext,1000);'>
 <h1 align='center'>City Guess Country Game</h1><br>
 <h2 style='color: white;' align='center'>Which Country is City In?</h2><br>
 <h3 style='color: white;' id='score' align='center'>Score: " . $escore . " Goes: " . $egoes . "</h3><br>
 <div align='centre' style='background-color: #f0f0f0;'>
 <form target=iemail style=display:none; action='//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php' method=POST>
 <input type=hidden name=inline value=''></input>
 <input type=hidden name=emailto id=emailto value=''></input>
 <input type=hidden name=subject id=subject value='City Guess Country Game'></input>
 <textarea style=display:none; name=htmlis id=htmlis value=''></textarea>
 <input type=submit style=display:none; id=contact value=Email></input>
 </form>" . notshowucities() . "<form target=_top id=cgcform action='//www.rjmprogramming.com.au/Games/CityGuessCountry/city_guess.php' method=GET><table cellpadding=5 cellspacing=5 border=20 align='center' style='width:100%;'><tr><th id=thcity>City</th><th>Country</th></tr><tr><td><input name='thiscity' id='thiscity' type='text' value='' style='width:90%;background-color:yellow;height:60px;font-size:32px;' onchange='this.value=lcity;'></input></td><td>" . showucountries() . "&nbsp;<input name=check style=display:none;background-color:pink; value=Check type=submit></input>&nbsp;<input onclick=askemail(); name=email id=bemail style=display:none;background-color:lightblue;height:60px;font-size:32px;align:right; value=Email type=button></input></form></td></tr></table></div>
 <iframe name=iemail src=//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php style=display:none;></iframe>
 </body></html>";

?>
