<?php
  // histogram_chart.php
  // Google Histogram Chart supervisor
  // RJM Programming
  // January, 2016
  // 
require('../php_database.php');

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

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

  
  $tally_poll_template="";
  $myfnameis="val";
  $dbval="";
  $dbval = include_get_params(dirname(__FILE__) . '/../php_database.php?' . $myfnameis . '=');  
  $njsuff="";
  if (strpos($_SERVER['QUERY_STRING'], "nojwin") !== false) $njsuff="&nojwinyes=Y";
  
  
  if (($dbval != "" && isset($_GET['tally']))) {
   $tally_poll_template="https://www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php?title=Tally" . $njsuff . "&task=Tally&desc=Count&data=,%20[~a~,7]%20,%20[~b~,8]%20,%20[~m~,3]";
  }
  
?>
<html>
  <head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script>
    <title>Histogram - RJM Programming - //www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
  var tmapname=[], tmapcount=[], tmapis=[], tallymode=-1, tally_poll_template="", documentURL=document.URL;    
  var teledata='', data, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : '');
  var xeparamdata='';
<?php 
     if (isset($_POST['data'])) {
        echo "\n pardata=\"" . str_replace("+","%20",urlencode($_POST['data'])) . "\"; \n";
        echo "\n xeparamdata=\"" . str_replace("+","%20",$_POST['data']) . "\"; \n";
        echo "\n if (documentURL.indexOf('?') == -1) { documentURL=document.URL + '?title=" . urlencode(str_replace("+"," ",$_POST['title'])) . '&task=' . urlencode($_POST['task']) . '&onclick=y&desc=' . urlencode($_POST['desc']) . "&data=' + pardata; } \n"; 

     }  
?>
  var paramdata=decodeURIComponent(pardata), eparamdata=paramdata;
    
   var oblurb=null;
   
   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 (documentURL.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=documentURL.split('#')[0] + '&nojwin=Q';
     }
   }
   ";
  }
?>

   if (documentURL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     var lastbit = ' (for no more leave blank and hit OK)'; 
     nojwinextra='&nojwinyes=Y';
   } else {
     var lastbit = ' (for no more hit Cancel button)'; 
   }

<?php
 echo "
 
 function selectevent(ans) {
 
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
             if (ansbits[0].indexOf('@') != -1) {
              if (document.getElementById('altemail')) {
              document.getElementById('altemail').value=ansbits[0];
              document.getElementById('remail').href=document.getElementById('remail').href.replace('mt=','mt=' + ansbits[0] + '&junk=youshallneverfindthis').replace('get=','mt=' + ansbits[0] + '&junk=youshallneverfindthis');
              }
              if (document.getElementById('email')) relist[1]='email';
              for (ire=0; ire<2; ire++) {
              if (relist[ire] != '') {
              // %3Ftitle%3DLengths%2520of%2520dinosaurs%2C%2520in%2520meters%26onclick%3Dy%26task%3DDinosaur%26desc%3DLength%26data%3D
              //alert('document.getElementById(' + relist[ire] + ').href=' + document.getElementById(relist[ire]).href);
              if (document.getElementById(relist[ire]).href.indexOf('histogram_chart.php' + '%' + '3') == -1 && document.getElementById(relist[ire]).href.indexOf('histogram_chart.php') != -1) {
                document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href + '%3Ftitle=" . urlencode(str_replace(",","`",$GETtitle)) . '%26task=' . urlencode($GETtask) . '%26onclick=y%26desc=' . urlencode($GETdesc) . "&data=' + xeparamdata; 
                //alert('document.getElementById(' + relist[ire] + ').href=' + document.getElementById(relist[ire]).href);
              } //else {
                //alert('Document.getElementById(' + relist[ire] + ').href=' + document.getElementById(relist[ire]).href);
              //}
              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);
              }

                while (document.getElementById(relist[ire]).href.indexOf(' ') != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(' ','+');
                }
                //while (document.getElementById(relist[ire]).href.indexOf('%20') != -1) {
                //  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace('%20','+');
                //}

              document.getElementById(relist[ire]).click();
              }
              }
             } else if (ans.substring(0,1).toLowerCase() == 'p' || ans.substring(0,1).toLowerCase() == 'c' || ans.substring(0,1).toLowerCase() == 'l' || ans.substring(0,1).toLowerCase() == 'b' || ans.substring(0,1).toLowerCase() == 'a') {
              var lh='';
              var huhsvg=null;
              if (pardata == '') {
              lh=document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&task=' . urlencode($GETtask) . '&onclick=y&desc=' . urlencode($GETdesc) . "&data=' + ourencodeURIComponent(ans);
              } else {
              lh=documentURL.replace(pardata, ourencodeURIComponent(ans));
              }
              if (teledata == '') {
                huhsvg=document.getElementsByTagName('svg');
                if (1 == 1) { //huhsvg.length != 0) {
                  analyzesvg(document.body.innerHTML);  // mobile fix
                  //alert(teledata);
                }
              }
              var dbits=lh.split('&data=');
              var urlgo=dbits[0].replace('/HistogramChart', '/PieChart').replace('histogram_chart.php', 'pie_chart.php').replace('&task=','&country=').replace('&desc=','&popularity=') + '&desc=' + teledata;
              if (urlgo.indexOf('title=&country=&onclick=y&popularity=&desc=&') != -1) {
                urlgo=urlgo.replace('&popularity=&', '&popularity=' + '" . ('' . $_POST['desc']) . "&').replace('&country=&', '&country=' + '" . ('' . $_POST['task']) . "&').replace('title=&', 'title=' + '" . ('' . $_POST['title']) . "&');
              }
              if (oblurb != null) {
              ohref=urlgo; //,ans.substring(0,1).toLowerCase();
              window.open(ohref,'_blank','top=20,left=20,width=800,height=660');
              } else {
              ohref=maybeothers(urlgo,ans.substring(0,1).toLowerCase());
              if (ohref != '') {
              location.href=ohref;
              }
              }
             } else if (pardata == '') {
              location.href=document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&task=' . urlencode($GETtask) . '&onclick=y&desc=' . urlencode($GETdesc) . "&data=' + ourencodeURIComponent(ans);
             } else {
              location.href=documentURL.replace(pardata, ourencodeURIComponent(ans));
             }
            } 
   }
   
   function infillit(urltgo) {
     var pbitsare=decodeURIComponent(paramdata).split('~,'), iminis=0, imaxis=0, cntsare=[];
     var ustg=urltgo.split('[%27');
     var totnum=eval(-1 + eval('' + pbitsare.length));
     var iut=0, jut=0;
     utgo=urltgo;
     if (tts.length > 0) {
     if (tts[0] == '') {
     
     for (jut=1; jut<ustg.length; jut++) {
        iminis=eval('' + ustg[jut].split('%20')[0]);
        imaxis=-1;
        if (ustg[jut].indexOf('%20to%20') != -1) { imaxis=eval('' + ustg[jut].split('%20to%20')[1].split(',')[0]); } 
        cntsare.push(eval('' + ustg[jut].split(',')[1].split(']')[0]));
     
      if (jut == 1) {
        tts[0]=',' + String.fromCharCode(34) + '<P onmouseover=console.log(54);' + '>&#931;: '.substring(0,1) + cntsare[eval(-1 + jut)] + '&nbsp;(' + eval(eval(eval('' + cntsare[eval(-1 + jut)]) * 100) / totnum).toFixed(1) + '%) </P>' + String.fromCharCode(34);
      } else {
        tts.push(',' + String.fromCharCode(34) + '<P onmouseover=console.log(354);' + '>&#931;: '.substring(0,1) + cntsare[eval(-1 + jut)] + '&nbsp;(' + eval(eval(eval('' + cntsare[eval(-1 + jut)]) * 100) / totnum).toFixed(1) + '%) </P>' + String.fromCharCode(34));
      }
    
         
     }
     
     for (iut=1; iut<pbitsare.length; iut++) {
      for (jut=1; jut<ustg.length; jut++) {
        iminis=eval('' + ustg[jut].split('%20')[0]);
        imaxis=-1;
        if (ustg[jut].indexOf('%20to%20') != -1) { imaxis=eval('' + ustg[jut].split('%20to%20')[1].split(',')[0]); } 
        if (eval('' + pbitsare[iut].split(']')[0].replace('+','')) >= eval('' + iminis) && (('' + imaxis) == '-1' || eval('' + pbitsare[iut].split(']')[0].replace('+','')) <= eval('' + imaxis))) {
        if (tts[eval(-1 + jut)].indexOf(' via ') == -1) {
          tts[eval(-1 + jut)]=tts[eval(-1 + jut)].replace(' </P>',  ' via <font size=1><a target=_blank title=Histogram href=' + documentURL.replace('&val1=','&jvla=').replace(/\+/g,'%20') + '>' + pbitsare[iut].split(']')[0].replace('+','') + ' </P>');
        } else {
          tts[eval(-1 + jut)]=tts[eval(-1 + jut)].replace(' </P>', ' ' + pbitsare[iut].split(']')[0].replace('+','') + ' </P>');
        }
        }
      }
     }
     
     for (jut=1; jut<ustg.length; jut++) {
       if (tts[eval(-1 + jut)].indexOf('<a') != -1) { tts[eval(-1 + jut)]=tts[eval(-1 + jut)].replace(' </P>', '</a>&nbsp;&#10549;</font><br><style> iframe { transform:scale(0.5);transform-origin:0px 0px; } </style><iframe src=' + documentURL.replace('&val1=','&jvla=').replace(/\+/g,'%20') + ' style=width:800px;height:620px;opacity:0.8;></iframe></P>');  }
       if (eval('' + tts.length) >= jut) {
         utgo=utgo.replace(ustg[jut], ustg[jut].replace(',', ',' + String.fromCharCode(34) + encodeURIComponent(tts[eval(-1 + jut)].substring(2,eval(-1 + tts[eval(-1 + jut)].length))) + String.fromCharCode(34) + ','));
       }
     } 
     utgo=utgo.replace(/\]\,\[/g, ']%20,%20[').replace(/\,\[/g, ',%20[').replace(/\[\%27/g,'[~').replace(/\%27\,/g,'~,');
     tts=[''];    
     
     }
     }
     
     return utgo;
   }
 
   function maybeothers(urltogo, ansistogo) {
     if (ansistogo.substring(0,1).toLowerCase() == 'p') {
       var returl=infillit(urltogo.replace(/\'/g,'%27').replace(/\ /g,'%20'));
       if (eval('' + returl.length) > 900) {
          if (returl.indexOf('title=') != -1) {
          document.getElementById('mypietitle').value=decodeURIComponent(returl.split('title=')[1].split('&')[0]).replace(/\+/g,' ');
          }
          if (returl.indexOf('country=') != -1) {
          document.getElementById('mypiecountry').value=decodeURIComponent(returl.split('country=')[1].split('&')[0]).replace(/\+/g,' ');
          document.getElementById('mypietask').value=decodeURIComponent(returl.split('country=')[1].split('&')[0]).replace(/\+/g,' ');
          }
          if (returl.indexOf('popularity=') != -1) {
          document.getElementById('mypiepopularity').value=decodeURIComponent(returl.split('popularity=')[1].split('&')[0]).replace(/\+/g,' ');
          document.getElementById('mypiedesc').value=decodeURIComponent(returl.split('popularity=')[1].split('&')[0]).replace(/\+/g,' ');
          }
          if (returl.indexOf('&r=') != -1) {
          document.getElementById('mypier').value='1'; //decodeURIComponent(returl.split('&r=')[1].split('&')[0]).replace(/\+/g,' ');
          }
          if (returl.indexOf('&c=') != -1) {
          document.getElementById('mypiec').value='1'; //decodeURIComponent(returl.split('&c=')[1].split('&')[0]).replace(/\+/g,' ');
          }
          if (returl.indexOf('data=') != -1) {
          document.getElementById('mypiedata').value=decodeURIComponent(returl.split('data=')[1].split('&')[0]);
          }
          //alert(document.getElementById('mypieform').innerHTML.split('mypiedata')[1]);
          document.getElementById('mypiego').click();
          return '';
       } else {
          return returl;
       }
     } else if (ansistogo.substring(0,1).toLowerCase() == 'c') {
     } else if (ansistogo.substring(0,1).toLowerCase() == 'l') {
     } else if (ansistogo.substring(0,1).toLowerCase() == 'b') {
     } else if (ansistogo.substring(0,1).toLowerCase() == 'a') {
     } 
     return urltogo.replace(/\'/g,'%27').replace(/\ /g,'%20');
   }
 
   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' || ans.substring(0,1).toLowerCase() == 'c' || ans.substring(0,1).toLowerCase() == 'l' || ans.substring(0,1).toLowerCase() == 'b' || ans.substring(0,1).toLowerCase() == 'a') {
              var lh='';
              var huhsvg=null;
              if (pardata == '') {
              lh=document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&task=' . urlencode($GETtask) . '&onclick=y&desc=' . urlencode($GETdesc) . "&data=' + ourencodeURIComponent(ans);
              } else {
              lh=documentURL.replace(pardata, ourencodeURIComponent(ans));
              }
              if (teledata == '') {
                huhsvg=document.getElementsByTagName('svg');
                if (1 == 1) { //huhsvg.length != 0) {
                  analyzesvg(document.body.innerHTML);  // mobile fix
                  //alert(teledata);
                }
              }
              var dbits=lh.split('&data=');
              var urlgo=dbits[0].replace('/HistogramChart', '/PieChart').replace('histogram_chart.php', 'pie_chart.php').replace('&task=','&country=').replace('&desc=','&popularity=') + '&desc=' + teledata;
              if (urlgo.indexOf('title=&country=&onclick=y&popularity=&desc=&') != -1) {
                urlgo=urlgo.replace('&popularity=&', '&popularity=' + '" . ('' . $_POST['desc']) . "&').replace('&country=&', '&country=' + '" . ('' . $_POST['task']) . "&').replace('title=&', 'title=' + '" . ('' . $_POST['title']) . "&');
              }
              if (oblurb != null) {
              ohref=urlgo; //,ans.substring(0,1).toLowerCase();
              window.open(ohref,'_blank','top=20,left=20,width=800,height=660');
              } else {
              ohref=maybeothers(urlgo,ans.substring(0,1).toLowerCase());
              if (ohref != '') {
              location.href=ohref;
              }
              }
             } else if (pardata == '') {
              location.href=document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&task=' . urlencode($GETtask) . '&onclick=y&desc=' . urlencode($GETdesc) . "&data=' + ourencodeURIComponent(ans);
             } else {
              location.href=documentURL.replace(pardata, ourencodeURIComponent(ans));
             }
            }   
   }
 
 
 ";
?>
 
        function prelater() {
        if (("" + document.referrer).indexOf("/PieChart") == -1 && (documentURL + '&').toLowerCase().indexOf('&val1=p&') != -1) { 
          selectevent('p');
        }
        if (documentURL.indexOf('data=') == -1) { 
        var sfbits=[], nfgval=0, fgval="";
        tally_poll_template="https://www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php?title=Tally&task=Tally&desc=Count&data=,%20[~a~,7]%20,%20[~b~,8]%20,%20[~m~,3]";
        sfbits=tally_poll_template.split("&data=");
        tally_poll_template="";
        while (fgval.length <= 0) { 
         fgval = prompt("Enter Tally Polling numbers either comma separated or we see it as a one character representation (where space separated prefixing [character]=Label list will be honoured).  A plus + at end of list means you want to add more.", "");  
         if (fgval == null) { 
          fgval=" "; 
          tally_poll_template=""; //sfbits[0].split("?")[0]; 
         } else {
         nfgval=fgval.length; 
         if (nfgval <= 0) { 
          fgval=""; 
         } else { 
          fgval=analyze_return(fgval, sfbits[0]);  
         }
         }
        }
        if (tally_poll_template != "") window.location = tally_poll_template;  
        }
       } 

function analyze_return(intb, pprefix) { 
        var eql=[], outb=intb, wasis='', thisis='', thisname='', found=-1, jfound=0, csvb=[], icsvb;
          if ((intb + '~`').indexOf('+~`') != -1) {
            outb=(intb + '~`').replace('+~`','');
          } else {
            outb=' ';
          }
          if (tally_poll_template.length == 0) {
          if (intb.trim().length > 0) {
          tallymode=intb.indexOf(',');
          tally_poll_template=pprefix + '&tally=y&data=';
          }
          }
          
          eql=intb.split('=');
          if (eql.length > 1) {
            for (var ieql=1; ieql<eql.length; ieql++) {
              wasis=eql[eval(-1 + ieql)].split(' ')[eval(-1 + eql[eval(-1 + ieql)].split(' ').length)];
              found=-1;
              for (jfound=0; jfound<tmapis.length; jfound++) {
                if (tmapis[jfound] == wasis) found=jfound;
              }
              if (found >= 0) {
              thisis=eql[eval(0 + ieql)].split(' ')[eval(-1 + eql[eval(0 + ieql)].split(' ').length)];
              tmapname[found]=encodeURIComponent((eql[eval(0 + ieql)] + '~`').replace((thisis + '~`'),'').trim());
              intb=intb.replace(wasis + '=' + thisis, '');
              } else {
              tmapis.push(wasis);
              tmapcount.push(0);
              thisis=eql[eval(0 + ieql)].split(' ')[eval(-1 + eql[eval(0 + ieql)].split(' ').length)];
              tmapname.push((eql[eval(0 + ieql)] + '~`').replace((thisis + '~`'),'').trim());
              intb=intb.replace(wasis + '=' + thisis, '');
              }
            }
          }
          
          intb=intb.trim();
          
          if (tallymode < 0) {
            if (intb.length > 0) {
            for (icsvb=0; icsvb<intb.length; icsvb++) {
              found=-1;
              for (jfound=0; jfound<tmapis.length; jfound++) {
                if (tmapis[jfound] == intb.substring(icsvb,eval(1 + icsvb))) found=jfound;
              }
              if (found < 0) {
              tmapis.push(intb.substring(icsvb,eval(1 + icsvb)));
              tmapcount.push(1);
              tmapname.push(intb.substring(icsvb,eval(1 + icsvb)));
              } else {
              tmapcount[found]++;
              }        
            }
          } else {
            var csvb=intb.split(',');
            for (icsvb=0; icsvb<csvb.length; icsvb++) {
              found=-1;
              for (jfound=0; jfound<tmapis.length; jfound++) {
                if (tmapis[jfound] == csvb[icsvb]) found=jfound;
              }
              if (found < 0) {
              tmapis.push(csvb[icsvb]);
              tmapcount.push(1);
              tmapname.push(csvb[icsvb]);
              } else {
              tmapcount[found]++;
              }        
            }
          }
          if (outb.trim().length == 0 && outb != '') {
            for (icsvb=0; icsvb<tmapname.length; icsvb++) {
              tally_poll_template+=',%20[~' + tmapname[icsvb] + '~,' + tmapcount[icsvb] + ']%20';
            }
          }
          return outb;
        }
    }

 
  function getlast() {
        var xmessage='', xdparts;
        xdparts=document.head.innerHTML.split('google.visualization.');
        xmessage=xdparts[2].substring(0);
        while (xmessage.indexOf(', [') != -1) {
        xmessage=xmessage.replace(', [',',[');
        } 
        xdparts=xmessage.split(',['); 
        //alert(xdparts.length);
        return eval(-2 + xdparts.length); 
   }
   
   function fillindata() {
     var bed=document.getElementById('bdataval');
     if (bed == null) {
       document.getElementById('bitsatend').innerHTML+='<input type="hidden" id="bdataval" value="' + encodeURIComponent(paramdata) + '"></input>';
     }
   }
   
   function filldata() {
     var bed=document.getElementById('bedata');
     if (bed != null) {
       if (bed.value == '') {
         bed.value=encodeURIComponent(paramdata);
       }
     }
   }
   
   function preanalyzesvg() {
     analyzesvg('');
   }
   
   function analyzesvg(svgsisvgsinnerHTML) {
     // ,['Work',11]
     // var teledata='&data=,';
     var ismobile=false;
     var ix=0, xspo, spo, lastones, isvgs=0, its=0, jts=0, firsty=-1.0, ts, thisones, prevone='', xs, zs, ns, thist='', telex='', telez='', teleih='', tdsuff='', tdelim='', tsuffix=' ';
     var svgs=document.getElementsByTagName('svg');

     if (svgsisvgsinnerHTML != '') {
       if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) ismobile=false; //true;
     }
     
     for (isvgs=0; isvgs<svgs.length; isvgs++) {
     if (svgsisvgsinnerHTML == '') {
      svgsisvgsinnerHTML=svgs[isvgs].innerHTML;
     }
       if (svgsisvgsinnerHTML.indexOf('<text ') != -1) {
         teledata='&data=,';
         ts=svgsisvgsinnerHTML.split('text-anchor="middle"');
         
         
//0 ... <text fill="#444444" stroke-width="0" stroke="none" font-size="14" font-family="Arial" y="425.9" x="161.5"    
//1 ... >0</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="14" font-family="Arial" y="425.9" x="277.1"      
//2 ... >10</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="14" font-family="Arial" y="425.9" x="392.70000000000005" 
//3 ... 
         lastones=ts[0].split('<');
         for (its=1; its<ts.length; its++) {
           xspo=ts[its].split('>')
           thisones=xspo[1].split('<');
           if (tdelim == '') {
             prevone=thisones[0];
             if (ismobile == true) alert('ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
           } else if (tsuffix == ' ' && Math.abs(Math.abs(eval(prevone) - eval(thisones[0])) - 1) < 0.001 && ("" + thisones[0] + "" + prevone).indexOf(".") == -1) {
             if (ismobile == true) alert('2 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='';
             teledata+=tsuffix + tdsuff;
           } else  if (tsuffix == ' ' && ("" + thisones[0] + "" + prevone).indexOf(".") == -1) {
             if (ismobile == true) alert('3 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='  to ' + eval(thisones[0] - 1);
             teleih+=tsuffix.replace(' ','');
             teledata+=tsuffix.replace(' ','') + tdsuff;
             tsuffix='  and up';
             if (eval(1 + its) < eval(ts.length)) {
               if (ismobile == true) alert(eval(1 + its) + ' < ' + ts.length);
               if (ismobile == true) alert(ts[eval(1 + eval(its))]);
               jts=eval(thisones[0]);
               //thisones=ts[eval(1 + eval(its))].replace('>','').split('<');
               spo=ts[eval(1 + eval(its))].split('>')
               thisones=spo[1].split('<');
               if (eval(thisones[0] - 1) == eval(jts)) {
               tsuffix='';
               } else {
               tsuffix='  to ' + eval(thisones[0] - 1);
               }
               //thisones=ts[its].replace('>','').split('<');
               xspo=ts[its].split('>')
               thisones=xspo[1].split('<');
             }
           } else  if (tsuffix == ' ') {
             if (ismobile == true) alert('4 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='  and up';
             teledata+=tsuffix.replace(' ','') + tdsuff;
           } else if (Math.abs(Math.abs(eval(prevone) - eval(thisones[0])) - 1) < 0.001 && ("" + thisones[0] + "" + prevone).indexOf(".") == -1) {
             if (ismobile == true) alert('5 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='';
           } else if (("" + thisones[0] + "" + prevone).indexOf(".") == -1) {
             if (ismobile == true) alert('6 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='  and up';
             if (eval(1 + its) < eval(ts.length)) {
               //alert(eval(1 + its) + '< ' + ts.length);
               //alert(ts[eval(1 + eval(its))]);
               jts=eval(thisones[0]);
               //thisones=ts[eval(1 + eval(its))].replace('>','').split('<');
               spo=ts[eval(1 + eval(its))].split('>')
               thisones=spo[1].split('<');
               if (eval(thisones[0] - 1) == eval(jts)) {
               tsuffix='';
               } else {
               tsuffix='  to ' + eval(thisones[0] - 1);
               }
               //thisones=ts[its].replace('>','').split('<');
               xspo=ts[its].split('>')
               thisones=xspo[1].split('<');
             }
           } else {
             if (ismobile == true) alert('7 ts[' + its + ']=' + ts[its] + ' thisones[0]=' + thisones[0]);
             tsuffix='  and up';
           }
             if (ismobile == true) alert('a');
           telez+=tdelim + '0';
             if (ismobile == true) alert('aa');
           teleih+=tdelim + thisones[0] + tsuffix.replace(' ','');
             if (ismobile == true) alert('aaa');
           teledata+=tdelim + "['" + thisones[0] + tsuffix.replace(' ','') + tdsuff;
             if (ismobile == true) alert('aaaa');
           thist = '<' + lastones[-1 + lastones.length] + 'text-anchor="middle">' + thisones[0] + '</text>';
           if (thist.indexOf('<text text-anchor=') != -1) {
             //alert(ts[its]);
             xspo=ts[its].split('font-');
             thist = '<' + xspo[0] + ' text-anchor="middle">' + thisones[0] + '</text>';
           }
             if (ismobile == true) alert('aaaaa');
           thisones=thist.split(' x="');
             if (ismobile == true) alert(thist);
           lastones=thisones[1].split('"');
             if (ismobile == true) alert('a7');
           telex+=tdelim + lastones[0];
           if (ismobile == true) alert(teledata);
           lastones=ts[its].split('<g><');
           tdelim=',';
           tdsuff="',0]";
         }
         if (ismobile == true) alert(1);
         xs=telex.split(',');
         if (ismobile == true) alert(11);
         zs=teleih.split(',');
         if (ismobile == true) alert(111);
         ns=telez.split(',');
         if (ismobile == true) alert(1111);
         ts=svgsisvgsinnerHTML.split('<rect ');
         if (ismobile == true) alert(ts.length + ' ... ' + teledata + ' +++ ' + ts[1]);
         if (ismobile == true) alert(teledata);
         for (its=3; its<ts.length; its++) {
            if (ismobile == true) alert(ts[its]);
            thisones=(' ' + ts[its]).replace(' x= ',' x=').split(' x="');
            if ((' ' + ts[its]).replace(' x= ','x=').indexOf(' x="') != -1) {
            lastones=thisones[1].split('"');
            } else if ((' ' + ts[its]).replace(' x= ','x=').indexOf(' x=') != -1) {
            thisones=ts[its].replace(' x= ',' x=').split(' x=');
            lastones=thisones[1].substring(1).split(thisones[1].substring(0,1));
            } else {
            thisones=(' ' + ts[its]).replace(' x= ',' x=').split(' x="');
            lastones='-999"'.split('"');
            }
         //if (eval(its) < 5 && navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) alert(lastones[0] + ' vs ' + ts[its]);
           if (ts[its].indexOf('height="1"') == -1 && ts[its].indexOf('height="') != -1 && ts[its].indexOf('fill-opacity=') == -1) {
            for (jts=0; jts<xs.length; jts++) {
              //if (zs[jts].indexOf('3') != -1 && navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) alert(eval(lastones[0]) + ' - ' +  eval(xs[jts]));
              //if (jts == 0 && navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) alert(telex + ' ... ' + eval(lastones[0]) + ' - ' +  eval(xs[jts]));
              if (Math.abs(eval(lastones[0]) - eval(xs[jts])) < 1.8) {  // used to be 1.0 (22/2/2021)
                if (tts.length == 0) {
                  tts.push('');
                }
                if (ismobile == true) alert("(" + teledata + ").replace('" + zs[jts] + ',' + ns[jts] + "','" + zs[jts] + ',' + eval(1 + ns[jts]) + "')=" + teledata.replace(zs[jts] + ',' + ns[jts], zs[jts] + ',' + eval(1 + ns[jts])));
                teledata=teledata.replace("'" + zs[jts] + "'," + ns[jts], "'" + zs[jts] + "'," + eval(1 + eval(ns[jts])));
                if (ismobile == true) alert(teledata);
                ns[jts]=eval(1 + eval(ns[jts]));
              }
            }
           }
         }
       }
     }
     // //localhost:8888/PHP/HistogramChart/histogram_chart.php?title=Lengths%20of%20dinosaurs,%20in%20meters&onclick=y&task=Dinosaur&desc=Length&data=,%20[~wrgw~,6]%20,%20[~ewgwsr~,6]%20,%20[~shbtdgjnrf~,4]%20,%20[~ewsgerxfhrft~,4]%20,%20[~esgrshtdhjn~,3]
     //alert(teledata);
     //return teledata;
   }
   
   var ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='', onego=true;   
<?php 
  $gr="";
  //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";

      $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']);

      $GETx = "";
      $GETy = "";
      if (isset($_GET['x'])) $GETx = urldecode($_GET['x']);
      if (isset($_POST['x'])) $GETx = urldecode($_POST['x']);
      if (isset($_GET['y'])) $GETy = urldecode($_GET['y']);
      if (isset($_POST['y'])) $GETy = urldecode($_POST['y']);
      if ($GETx != "" && $GETy != "") {
        echo "\n x=eval('" . $GETx . "'); \n";
        echo "\n y=eval('" . $GETy . "'); \n";
      }

      $GETtitle = "Lengths of dinosaurs, in meters";
      $GETtask = "Dinosaur";
      $GETdesc = "Length";
      $GETdata = ",['Acrocanthosaurus (top-spined lizard)', 12.2],['Albertosaurus (Alberta lizard)', 9.1],['Allosaurus (other lizard)', 12.2],['Apatosaurus (deceptive lizard)', 22.9],['Archaeopteryx (ancient wing)', 0.9],['Argentinosaurus (Argentina lizard)', 36.6],['Baryonyx (heavy claws)', 9.1],['Brachiosaurus (arm lizard)', 30.5],['Ceratosaurus (horned lizard)', 6.1],['Coelophysis (hollow form)', 2.7],['Compsognathus (elegant jaw)', 0.9],['Deinonychus (terrible claw)', 2.7],['Diplodocus (double beam)', 27.1],['Dromicelomimus (emu mimic)', 3.4],['Gallimimus (fowl mimic)', 5.5],['Mamenchisaurus (Mamenchi lizard)', 21.0],['Megalosaurus (big lizard)', 7.9],['Microvenator (small hunter)', 1.2],['Ornithomimus (bird mimic)', 4.6],['Oviraptor (egg robber)', 1.5],['Plateosaurus (flat lizard)', 7.9],['Sauronithoides (narrow-clawed lizard)', 2.0],['Seismosaurus (tremor lizard)', 45.7],['Spinosaurus (spiny lizard)', 12.2],['Supersaurus (super lizard)', 30.5],['Tyrannosaurus (tyrant lizard)', 15.2],['Ultrasaurus (ultra lizard)', 30.5],['Velociraptor (swift robber)', 1.8]";
            
      if (isset($_POST['data'])) {
       if (isset($_GET['title'])) {
       $GETtitle = str_replace("\\'", "'", $_GET['title']);
       } else {
       $GETtitle = str_replace("\\'", "'", $_POST['title']);
       }
       if (isset($_GET['task'])) {
       $GETtask = str_replace("\\'", "'", $_GET['task']);
       } else {
       $GETtask = str_replace("\\'", "'", $_POST['task']);
       }
       if (isset($_GET['desc'])) {
       $GETdesc = str_replace("\\'", "'", $_GET['desc']);
       } else {
       $GETdesc = str_replace("\\'", "'", $_POST['desc']);
       }
       //$GETdata = str_replace("\\'", "'", $_POST['data']);
       $GETdata = str_replace('~','"',urldecode(checkdatadata0('POST',$_POST['data'])));
       //echo "\n pardata = " . '"' . $_POST['data'] . '"; ' . " \n";
       echo "\n paramdata='" . str_replace('"','~',$GETdata) . "'; \n  eparamdata=encodeURIComponent('" . str_replace('"','~',str_replace(' ','+',$GETdata)) . "'); \n setTimeout(fillindata, 300); \n setTimeout(filldata, 3000); \n"; // = decodeURIComponent(pardata); " . " \n";
      }
      if (isset($_GET['data'])) {
       $GETtitle = str_replace("\\'", "'", $_GET['title']);
       $GETtask = str_replace("\\'", "'", $_GET['task']);
       $GETdesc = str_replace("\\'", "'", $_GET['desc']);
       $GETdata = str_replace("\\'", "'", $_GET['data']);
      }

      
      if (!isset($_GET['data']) && !isset($_POST['data']) && strpos($_SERVER['QUERY_STRING'],"title=") !== false) {
       $bbits = explode("data=", file_get_contents('php://input'));
         $GETtitle = str_replace("\\'", "'", urldecode(explode('&',explode("title=", $_SERVER['QUERY_STRING'])[1])[0]));
         $GETtask = str_replace("\\'", "'", urldecode(explode('&',explode("task=", $_SERVER['QUERY_STRING'])[1])[0]));
         $GETdesc = str_replace("\\'", "'", urldecode(explode('&',explode("desc=", $_SERVER['QUERY_STRING'])[1])[0]));
       if (sizeof($bbits) > 1) {
         $GETdata = str_replace("\\'", "'", urldecode(explode('&',$bbits[1])[0]));
       } else {
         $GETdata = "";
       }
      }      

      //if (isset($_GET['desc'])) {
      // $GETtitle = $_GET['title'];
      // $GETtask = $_GET['task'];
      // $GETdesc = $_GET['desc'];
      // $GETdata = $_GET['data'];
      //}
      
      if ($GETr != "") {
        if (substr($GETr,0,1) != "-" && (substr($GETr,0,1) < "0" || substr($GETr,0,1) > "9")) {
          $gr="ir=getlast();";
          echo "\n ir=getlast(); \n";
        } else {
          echo "\n ir=eval('" . $GETr . "'); \n";
        }
      }
      if ($GETc != "") {
        echo "\n ic=eval('" . $GETc . "'); \n";
      }
      
      echo " var colnames= '" . str_replace("'", "", $GETtask) . "," . str_replace("'", "", $GETdesc) . "', tts=[], thefor='For', theansis='', thepb='', ohref=''; \n";
      
      echo ' google.load("visualization", "1", {packages:["corechart"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      if ($GETdata == "") {
      echo ' var wert="data=google.visualization.arrayToDataTable([ ' . "'" . $GETtask . "','" . $GETdesc . "'" . ']"; ' . "\n";
      echo " wert+=parent.document.getElementById('data').value.replace(/\,\]/g,\",0\").replace(/\[\~/g,\"['\").replace(/\~\,/g,\"',\"); " . "\n";
      echo ' wert+=" ])";' . "\n";
      echo ' eval(wert); ' . "\n";
      } else {
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
      echo " ['" . $GETtask . "','" . $GETdesc . "'] \n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace('+',' ',urldecode($GETdata)))))));
      echo "        ]);\n";
      }
      echo "        var options = { \n";
      echo "        title: '" . $GETtitle . "', \n";
      echo "        legend: { position: 'none' }, \n";
      echo "        }; \n";

      echo " chart = new google.visualization.Histogram(document.getElementById('chart_div')); \n";
      
      $GETonclick = "";
      if (isset($_GET['onclick'])) $GETonclick = urldecode($_GET['onclick']);
      if (isset($_POST['onclick'])) $GETonclick = urldecode($_POST['onclick']);
      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(chart, 'ready', function() { ready=true; }); \n";
      echo "google.visualization.events.addListener(chart, 'select', myselectfunction); \n function myselectfunction() {
 //alert(1);
 if (ready) {
 //alert(2);
  var relist=['remail',''],ire,ansbits,avblurb=talkingpoint,ioffset=0,ans=null,doit=true,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), maxdelim='', maxnum=0, maxval=0, minval=0, medianlist='', modelist='', colmedian=new Array(), colmode=new Array(), suffj=' ', jcc, colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues, str;
  oblurb=parent.document.getElementById('blurb');
//alert(3);
 " . $gr . " 
  selection = chart.getSelection();
 //alert(4);
 // sliceid = selection[0].row;
 //alert(5);

  for (var i = 0; i < selection.length; i++) {
 //alert(22);
    var item = selection[i];
    if (item.row != null) ir = item.row;
    if (item.column != null) ic = item.column;
//alert(222 + ' ' + ir + ' ' + ic + ':' + item.row + ';' + item.column);
  //alert('ir=' + ir + ' ic=' + ic);
    if ((eval(ir) >= 0 && eval(ic) >= 0)) { //eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) >= 0) { //eval(ic) < 0) {
  //alert(999);
        item.row=ir;
        //item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
 //alert(12);
        ir=item.row;
        //ic=item.column;
        //document.title=ir + ',' + ic;
      }
      //document.title=str;
      //message=document.head.innerHTML.substring(ioffset);
      var xmessage='', xdparts;
      xdparts=document.head.innerHTML.split('google.visualization.');
      message=xdparts[2].substring(0);
      while (message.indexOf(', [') != -1) {
       message=message.replace(', [',',[');
      }
      // colparts[0] = 'Dinosaur'  , colparts[1] = 'Length'
      // , ['hjhgnmfhj',5] , ['rwgw4gr',5] , ['wfwefw',3] , ['wgegfwr',2] , ['wregfwrg',5] , ['qfefweaf',3] , ['fewfwef',2] , ['sdgvwrsgdv',5]        ]);
      dparts=message.split(',[');  // dparts[0] = 'hjhgnmfhj',5]
 //alert(212 + ' dparts.length=' + dparts.length + ' vs message=' + message);
        //document.title='';
        colav.push(0.0);
        colmode.push(0.0);
        colmedian.push(0.0);
      for (kl=1; kl<colparts.length; kl++) {
      //alert('kl=' + kl);
        //document.title=1;
        medianlist='';
        modelist=' ';
        minval=0;
        maxval=0;
        maxnum=0;
        maxdelim='';
        colav.push(0.0);
        colmode.push(0.0);
        colmedian = new Array();
        doit=true;
        num=1;
        for (lk=1; lk<dparts.length; lk++) {
      //alert('lk=' + lk + ' of dparts.length=' + dparts.length);
         if (doit) {
         thisnum=dparts[lk].replace(']',',').split(',');  // thisnum[1] = number
         if (thisnum.length > kl) {
          if (thisnum[kl].indexOf(']') != -1) doit=false;
         } else {
          doit=false;
         }
         }
         if (doit) {
        //document.title=3;
         colmedian.push(eval(thisnum[kl]));
         //if (kl == 1) document.title+=4 + ' .. '  + eval(thisnum[kl]) + ' ... ' + lk + ' ... ' + colav[kl] + ' ... ' + thisnum.length + ' ... ' + dparts[lk];
      //alert('thisnum[kl]=' + thisnum[kl] + ' colav[kl]=' + colav[kl]);
         colav[kl] = eval(eval(colav[kl] * eval(-1 + num)) + eval(thisnum[kl])) / eval(0.0 + num);
         if (num == 1) {
          maxval=eval(thisnum[kl]);
          minval=eval(thisnum[kl]);
          colmode[kl] = eval(thisnum[kl]);
          //colmedian[kl] = eval(thisnum[kl]);
          maxdelim+=' ';
          modelist+=eval(thisnum[kl]) + maxdelim;
          //alert('first value for ' + thisnum[eval(-1 + kl)] + ' (' + eval(thisnum[kl]) + ')');
         } else if ((' ' + modelist).indexOf(' ' + eval(thisnum[kl]) + ' ') != -1) {
          if ((' ' + modelist).indexOf(' ' + eval(thisnum[kl]) + maxdelim) != -1) {
           modelist=modelist.replace(' ' + eval(thisnum[kl]) + maxdelim, ' ' + eval(thisnum[kl]) + maxdelim + ' ');
           maxdelim+=' ';
           colmode[kl] = eval(thisnum[kl]);
           //alert('new max for ' + thisnum[eval(-1 + kl)] + ' (' + eval(thisnum[kl]) + ')');
          } else if ((' ' + modelist).indexOf(' ' + eval(thisnum[kl]) + ' ') != -1) { 
           //alert('no for *' + maxdelim.replace(' ','.').replace(' ','.').replace(' ','.').replace(' ','.').replace(' ','.') + '*  !' + modelist + '! '  + thisnum[eval(-1 + kl)] + ' (' + eval(thisnum[kl]) + ')');
           modelist=modelist.replace(' ' + eval(thisnum[kl]) + ' ', ' ' + eval(thisnum[kl]) + '  ');
          }
         } else {
          modelist+=eval(thisnum[kl]) + ' ';
          //alert('first go for ' + thisnum[eval(-1 + kl)] + ' (' + eval(thisnum[kl]) + ')');
         }
        //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] + ' value over ' + num + ' ' + colparts[0] + ' values is ' + colav[kl] + String.fromCharCode(10);
        //document.title=7;
        colmedian.sort(function(a, b){return a-b});
        if (eval(num % 2) == 0) {
         avblurb+='Median ' + colparts[kl] + ' value over ' + num + ' ' + colparts[0] + ' values is ' + eval((colmedian[Math.floor(eval(num / 2)) - 1] + colmedian[Math.floor(eval(num / 2))]) / 2) + ' ( = (' + colmedian[Math.floor(eval(num / 2)) - 1] + ' + ' + colmedian[Math.floor(eval(num / 2))] + ') / 2 )' + String.fromCharCode(10);
        } else {
         avblurb+='Median ' + colparts[kl] + ' value over ' + num + ' ' + colparts[0] + ' values is ' + colmedian[Math.floor(eval(num / 2))] + String.fromCharCode(10);
        }
        suffj=' ';
        if (maxdelim.length != 1) colmedian[kl]=colmode[kl];
        colmode=modelist.split(maxdelim);
        if (maxdelim.length == 1) {
         if (eval(colmedian.length) > 1) suffj='s ';
         avblurb+='Mode ' + colparts[kl] + ' value' + suffj + ' over ' + num + ' ' + colparts[0] + ' values are'; // + colmode[kl] + ' ( occurring ' + maxdelim.length + ' times )' + String.fromCharCode(10);
         suffj=' ';
         for (jcc=0; jcc<colmedian.length; jcc++) {
           avblurb+=suffj + colmedian[jcc];
           suffj=' and ';
         }
         avblurb+=' ( occurring once for each )' + String.fromCharCode(10);
        } else if (eval(colmode.length) > 2) {
         avblurb+='Mode ' + colparts[kl] + ' values over ' + num + ' ' + colparts[0] + ' values are'; // + colmode[kl] + ' ( occurring ' + maxdelim.length + ' times )' + String.fromCharCode(10);
         for (jcc=0; jcc<colmode.length; jcc++) {
           colmedian=colmode[jcc].split(' ');
           if (colmedian[eval(-1 + colmedian.length)] != '') avblurb+=suffj + colmedian[eval(-1 + colmedian.length)];
           suffj=' and ';
         }
         avblurb+=' ( occurring ' + maxdelim.length + ' times each )' + String.fromCharCode(10);
        } else {
         avblurb+='Mode ' + colparts[kl] + ' value over ' + num + ' ' + colparts[0] + ' values is ' + colmedian[kl] + ' ( occurring ' + maxdelim.length + ' times )' + String.fromCharCode(10);
        }
      }
      //alert(312);
      avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'Show this as Pie Chart=P' + String.fromCharCode(10);
      if (avblurb != '') avblurb+=String.fromCharCode(10) + String.fromCharCode(10);
      //alert('dparts.length=' + dparts.length + ' vs 2');
      if (eval(dparts.length) >= eval(1 + item.row)) {
      //alert('dparts[eval(1 + item.row)]++=' + dparts[eval(1 + item.row)].replace(']',',') + ' vs split by ,');
        postdparts=dparts[eval(1 + item.row)].replace(']',',').split(',');
        if (eval(postdparts.length) >= eval(1 + item.column)) {
         //alert('colparts.length=' + colparts.length + ' postdparts.length=' + postdparts.length);
         if (eval(colparts.length) == 2) { 
          if (1 == 1) {
          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)';
          //alert(987);
          if (oblurb != null && onego == true) {
          if (document.getElementById('safariform')) { document.getElementById('safariform').style.top='70px';   } 
          oblurb.innerHTML=('For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + ' ' + avblurb).replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>').replace(String.fromCharCode(10),'<br>');
          } else {
          if (document.getElementById('safariform')) { document.getElementById('safariform').style.top='70px';   }
          if (theansis.length == 1 && thepb == colparts[0] + ' ' + postdparts[0].replace(']','')) {
          ans=theansis;
          if (ohref != '') { location.href=ohref; }
          } else { 
          ans=prompt(thefor + ' ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + ' ' + avblurb, paramdata);
          if (ans != null) { if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { theansis=theansis; } else { theansis=ans; thepb=colparts[0] + ' ' + postdparts[0].replace(']',''); } }
          }
          //thefor='FOR';
          }
          onego=false;
          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(7999);
        item.row=ir;
        item.column=ic;
  //alert(79999);
        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(8999);
        item.row=ir;
        //item.column=ic;
  //alert(89999);
        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.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 Area Chart=A' + String.fromCharCode(10);
          //avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          //avblurb+='Show this as Column Chart=C' + 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)';
          if (document.getElementById('safariform')) { document.getElementById('safariform').style.top='70px';   } 
          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(3999);
        //item.row=ir;
        item.column=ic;
  //alert(39999);
        //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, options); \n \n";
      if (substr($GETr,0,1) != "-" && (substr($GETr,0,1) < "0" || substr($GETr,0,1) > "9")) {
      if ($GETr != "" && $GETc != "") echo " chart.setSelection([{'row': getlast(), 'column': " . $GETc . "}]);  setTimeout(myselectfunction,2100); \n";
      } else {
      if ($GETr != "" && $GETc == "") echo " chart.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunction,4100); \n";
      if ($GETr == "" && $GETc != "") echo " chart.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      if ($GETr != "" && $GETc != "") echo " chart.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      }
      echo " }  \n";
      
      echo " </script> \n";
      echo " </head> \n";
      //echo " <body onload='setTimeout(later, 2 * 1000);'> \n";
      if ($dbval != '' && isset($_GET['tally'])) {
      echo " <body onload=' setTimeout(prelater, 2 * 1000); '> \n";
      } else if ((!isset($_GET['desc']) && !isset($_POST['desc']))) {
      echo " <body onload=' " . $gr . " setTimeout(later, 2 * 1000);'> \n";
      } else {
      echo " <body" . str_replace("ir=getlast();", " onload=' ir=getlast(); '", $gr) . "> \n";
      }
      echo " <h1>" . $GETtitle . " Histogram</h1> \n";
?>
    <div id="chart_div" style="width: 900px; height: 500px; background-color: yellow;"></div><div id="bitsatend" style="display:inline;"></div>
    <a id=another title="Another Histogram" href="./histogram_chart.php">Another histogram?</a>
    <?php 
      if (!isset($_GET['desc']) || isset($_GET['tally'])) {
      
        echo '<' . 'script' . '>' . "\n";
        echo " function later() { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = ""; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        echo ' if (("" + document.referrer).indexOf("/PieChart") == -1 && (documentURL + "&").toLowerCase().indexOf("&val1=p&") != -1) { selectevent("p");  } ' . "\n";
        echo ' var sfbits=[], nfgval=0, fgval="", datalinesuffix = ""; ' . "\n";
        if ($tally_poll_template != "") {
        echo ' tally_poll_template="' . $tally_poll_template . '"; ' . "\n";
        echo ' sfbits=tally_poll_template.split("&data=");' . "\n";
        echo ' if (fgval.length <= 0) { while (fgval.length <= 0) { fgval = prompt("Enter Tally Polling numbers either comma separated or we see it as a one character representation (where space separated prefixing [character]=Label list will be honoured).  A plus + at end of list means you want to add more.", "");  if (fgval == null) { fgval=" "; tally_poll_template=sfbits[0].split("?")[0]; } nfgval=fgval.length; if (nfgval <= 0) { fgval=""; } } } else { fgval=analyze_return(fgval, sfbits[0]);  } ' . "\n";
        echo ' window.location = tally_poll_template; ' . "\n";
        } else {
        if ($dbval != "") {
        echo ' if (documentURL.indexOf("tally=") != -1) { ' . "\n";
        echo ' tally_poll_template="https://www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php?title=Tally&task=Tally&desc=Count&data=,%20[~a~,7]%20,%20[~b~,8]%20,%20[~m~,3]"; ' . "\n";
        echo ' sfbits=tally_poll_template.split("&data=");' . "\n";
        echo ' if (fgval.length <= 0) { while (fgval.length <= 0) { fgval = prompt("Enter Tally Polling numbers either comma separated or we see it as a one character representation (where space separated prefixing [character]=Label list will be honoured).  A plus + at end of list means you want to add more.", "");  if (fgval == null) { fgval=" "; tally_poll_template=sfbits[0].split("?")[0]; } nfgval=fgval.length; if (nfgval <= 0) { fgval=""; } } } else { fgval=analyze_return(fgval, sfbits[0]);  } ' . "\n";
        echo ' window.location = tally_poll_template; ' . "\n";
        echo ' } else { ' . "\n";
        echo ' var title = prompt("Enter Histogram Title (suffix by &onclick=y for added onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        echo ' } ' . "\n";
        } else {
        echo ' var title = prompt("Enter Histogram Title (suffix by &onclick=y for added onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        }
        echo ' if (title != null) { ' . "\n";
        echo ' var task = prompt("Enter Subject of Study", "' . $GETtask . '"); ' . "\n";
        echo ' var desc = prompt("Enter " + task + " Measure", "' . $GETdesc . '"); ' . "\n";
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = prompt("Enter " + task + " Name " + thisline, ""); ' . "\n";
        echo ' while (datalineprefix.length != 0 && (desc.indexOf("ercent") == (0 - 1) || desc.indexOf("  ercent ") != (0 - 1) || (desc.indexOf("ercent") != (0 - 1) && totalleft > 0))) { ' . "\n";
        echo ' if (datalinesuffix.length != 0) datalineprefix = prompt("Enter " + task + " Name " + thisline + lastbit, ""); ' . "\n";
        echo ' if (datalineprefix == null) { ' . "\n";
        echo '     datalineprefix = ""; ' . "\n";
        echo '     if (nojwinextra != "") allowed=false; ' . "\n";
        echo '     totalleft = 0; ' . "\n";
        echo ' } else if (datalineprefix.length != 0) { ' . "\n";
        echo '     extra = "";  ' . "\n";
        echo '     if (desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     datalinesuffix = prompt("Enter " + datalineprefix + " " + desc.replace("  ercent ", "") + " " + thisline + extra, "0"); ' . "\n";
        echo '     if (datalinesuffix == null && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) datalinesuffix = totalleft; ' . "\n";
        echo '     if (datalinesuffix == null) datalinesuffix = "0"; ' . "\n";
        echo '     if (datalinesuffix.length == 0) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(totalleft) == eval(datalinesuffix) && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && desc.indexOf("ercent") == (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       desc = desc + "  ercent "; ' . "\n";
        echo '     } else { ' . "\n";
        echo '       totalleft = eval(totalleft) - eval(datalinesuffix); ' . "\n";
        echo '     } ' . "\n";
        echo '     datac = datac + ", [~" + datalineprefix + "~," + datalinesuffix + "] "; ' . "\n";
        echo '     thisline++; ' . "\n";
        echo '   } else { ' . "\n";
        echo '     if (nojwinextra != "") allowed=true; ' . "\n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
        echo ' if (allowed) window.location = "./histogram_chart.php?title=" + title + "&task=" + task + "&desc=" + desc.replace("  ercent ", "") + nojwinextra + "&data=" + datac; ' . "\n";
        echo "} \n";
        }
        echo "} \n" . '</' . 'script' . '>' . "\n";
      } 
    ?>
<script type='text/javascript'>
setTimeout(preanalyzesvg, 1100); 
if (documentURL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
  //document.getElementById('pch1').innerHTML+='.';
  var xansis='x', hiddenbits='';
  xpnum=1;
  if (documentURL.indexOf('?') != -1) {
    var pairing, argsare=documentURL.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 (documentURL.indexOf('val' + xpnum + '=') != -1) {
     hiddenbits+="<input type=hidden name=val" + xpnum + " value='" + encodeURIComponent(xansis) + "'></input>";
     xpnum++;
     xansis='x';
   } else {
     xansis='';
   }
  }

  if (documentURL.indexOf('nojwinyes=') != -1) { 
  document.write("<form onsubmit=\" if (document.getElementById('val" + xpnum + "').value.replace('null','') != '') { if (decodeURIComponent(document.getElementById('prompt').value).indexOf(' For ') == 0) {  selecteventtwo(document.getElementById('val" + xpnum + "').value);  } else { selectevent(document.getElementById('val" + xpnum + "').value); } } else if (document.URL.indexOf('&data=') != -1) { location.href=document.URL; } else { this.style.display='none'; } xpnum++; return false; \" enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=5 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='....';
  } else if (documentURL.indexOf('&val5=') != -1 && documentURL.indexOf('&data=') == -1 && eval(eval((documentURL.split('&OK=')[0].split('&Cancel=')[0].split('=')[Math.max(0,-2 + documentURL.split('&OK=')[0].split('&Cancel=')[0].split('=').length)] + '&0').split('&')[1].replace('val','')) % 2) == 1) {
  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=" + documentURL.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 style=display:none; 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>"); 
  } 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=" + documentURL.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>
<form target=_blank id=mypieform action='//www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php' method='POST' style='display:none;'>
<input type=hidden name=title value='' id=mypietitle></input>
<input type=hidden name=onclick value='y' id=mypieonclick></input>
<input type=hidden name=country value='' id=mypiecountry></input>
<input type=hidden name=popularity value='' id=mypiepopularity></input>
<input type=hidden name=r value='' id=mypier></input>
<input type=hidden name=c value='' id=mypiec></input>
<input type=hidden name=desc value='' id=mypiedesc></input>
<input type=hidden name=task value='' id=mypietask></input>
<input type=hidden name=data id=mypiedata value=''></input>
<input type='hidden' name='wouldlikeyoutoseekpermission' id='wouldlikeyoutoseekpermission' value=''></input>
<input type=submit value=Go style=display:none; id=mypiego></input>
</form>
</body>
</html>
