<?php
  if (file_exists("csv.php")) {
    include "csv.php";
  } else if (file_exists("../csv.php")) { 
    include "../csv.php";
  }
  
  $pd0="";
  $pdp0="";
  $pd="";
  $pdp="";
  
  $ntt=false;
  $gdata0="";

  $data0 = "";
  if (isset($_GET['data0'])) {
      $getdata0=$_GET['data0'];
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if ($getdata0 != "" && strpos($getdata0, "[") !== false && strpos($getdata0, "[") < strpos($getdata0, ",")) {
   $data0 = "&data0=," . $getdata0;
      } else {
   $data0 = "&data0=" . $getdata0;
      }
   $gdata0=str_replace("&data0=","",$data0);
  }
  if (isset($_POST['data0'])) {
      $getdata0=tzl0($_POST['data0']);
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if (strpos($getdata0, "%") !== false) $getdata0=str_replace('+',' ',urldecode($getdata0));
      if ($getdata0 != "" && strpos($getdata0, "[") !== false && strpos($getdata0, "[") < strpos($getdata0, ",")) {
   $data0 = "&data0=," . $getdata0;
      } else {
   $data0 = "&data0=" . $getdata0;
      }
  }
  
 
function tzl($inwith) {
  global $pd, $pdp;
   $inwithtz=urldecode($inwith);
   if (strpos($inwithtz, "~http;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~http;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Http;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~Http;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTP;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~HTTP;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~https;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~https;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Https;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~Https;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTPS;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~HTTPS;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~http") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http" . explode("~",explode("~http", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Http") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http" . explode("~",explode("~Http", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTP") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("HTTP" . explode("~",explode("~HTTP", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos(str_replace("https;","http;",substr(strtolower($inwithtz . "      "),0,6)), "http;") !== false) { // co-ordinates longhand via prompt
     $inwithtz=read_and_array($inwithtz, str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos(str_replace("https:","http:",substr(strtolower($inwithtz . "      "),0,6)), "http:") !== false) { // co-ordinates via URL via net
     $inwithtz=read_and_array($inwithtz, str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else {
     if (isset($_POST['data'])) {
        $pd = "\n pardata=\"" . str_replace("+","%20",urlencode($inwith)) . "\"; \n";
        $pdp = "\n paramdata=\"" . str_replace('"','" + String.fromCharCode(34) + "',urldecode(str_replace("+","%20",$inwith))) . "\"; \n";
     }
     return $inwith;
   }
   $pd = "\n pardata=\"" . urlencode($inwithtz) . "\"; ";
   $pdp = "\n paramdata=\"" . str_replace('"','" + String.fromCharCode(34) + "',urldecode(str_replace("+","%20",$inwithz))) . "\"; \n";   // decodeURIComponent(pardata); \n";
   return $inwithtz;
}
  

function tzl0($inwith) {
  global $pd0, $pdp0;
   $inwithtz=urldecode($inwith);
   if (strpos($inwithtz, "~http;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~http;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Http;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~Http;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTP;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~HTTP;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~https;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~https;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Https;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~Https;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTPS;") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http;" . explode("~",explode("~HTTPS;", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~http") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http" . explode("~",explode("~http", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~Http") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("http" . explode("~",explode("~Http", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "~HTTP") !== false) { // co-ordinates via net
     $inwithtz=read_and_array("HTTP" . explode("~",explode("~HTTP", $inwithtz)[1])[0], str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos(str_replace("https;","http;",substr(strtolower($inwithtz . "      "),0,6)), "http;") !== false) { // co-ordinates longhand via prompt
     $inwithtz=read_and_array($inwithtz, str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos(str_replace("https:","http:",substr(strtolower($inwithtz . "      "),0,6)), "http:") !== false) { // co-ordinates via URL via net
     $inwithtz=read_and_array($inwithtz, str_replace('pie_chart_diff.php','pie_chart_diff.php',str_replace('index.php','pie_chart_diff.php',$_SERVER['REQUEST_URI'])));
   } else {
     if (isset($_POST['data0'])) {
        $pd0 = "\n pardata0=\"" . str_replace("+","%20",urlencode($inwith)) . "\"; \n";
        $pdp0 = "\n paramdata0=\"" . str_replace('"','" + String.fromCharCode(34) + "',urldecode(str_replace("+","%20",$inwith))) . "\"; \n";
        tzl(str_replace("+"," ",urldecode($_POST['data'])));
     }
     return $inwith;
   }
   $pd0 = "\n pardata0=\"" . urlencode($inwithtz) . "\"; ";
   $pdp0 = "\n paramdata0=\"" . str_replace('"','" + String.fromCharCode(34) + "',urldecode(str_replace("+","%20",$inwithz))) . "\"; \n";   // decodeURIComponent(pardata); \n";
   return $inwithtz;
}
 


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

<html>
  <head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js?x=xd"></script>
    <title>Pie Chart (Differences) - 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">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" />
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
   var pardata='', pardata0='', paramdata='', paramdata0='';
   
   var operc=-1, ready=true, readyb=true, readya=true, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='', targ=null, targ0=null, datasetis='data';   
   var isokagain=true, isokagaindata=true, isokagaindata0=true;
    
   var xpnum=1; // done here at supervisor
   var allowed=true; // done here at supervisor
   var nojwinextra=""; // done here at supervisor
   var cvals="", secondset="";
   var defname="", lastp="", wourl="", wocmd="";
   
   function nocvals(insis) {
     var outsis=insis;
     if (cvals != '') outsis=insis.replace(cvals,'');
     if (document.getElementById('safariform')) {
     if (document.getElementById('safariform').innerHTML.indexOf('nojwinyes') == -1 && document.getElementById('safariform').innerHTML.indexOf('nojwin') != -1) {
     document.getElementById('safariform').innerHTML=document.getElementById('safariform').innerHTML.replace('nojwin','nojwinyes');
     }
     }
     return outsis.replace('nojwin=','nojwinyes=').replace(/\ /g,'%20');
   }
   
   
<?php

  if (!isset($_POST['data'])) {
  echo "
   if (document.URL.indexOf('nojwin') == -1 && navigator.userAgent.match(/iPhone|iPad/i)) {
     if (document.URL.indexOf('?') == -1) {
       location.href=document.URL.split('#')[0] + '?nojwin=Q';
     } else {
       location.href=document.URL.split('#')[0] + '&nojwin=Q';
     }
   }
   ";
  }
?>
   if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     nojwinextra="&nojwinyes=Y";
   }
   
 function wolater() {
   if (wocmd != "") {
     wourl='';
     var wcmdis=wocmd;
     wocmd=" ";
     eval(wcmdis);
     if (wourl != "") {
     var xwurlis=wourl;
     wourl='';
     //document.getElementById('chart_div').click();
     //document.title=xwurlis;
     window.open(xwurlis,'_blank');
     }
   } else if (wourl != "") {
     var wurlis=wourl;
     wourl='';
     //document.getElementById('chart_div').click();
     //document.title=wurlis;
     window.open(wurlis,'_blank');
   }
 }
   
 function selectevent(ans,retry) {
      if (ans != null) {
            if (ans.replace('null','') != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
                  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';

    
             if (ansbits[0].indexOf('@') != -1) {
               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=') + ir) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&r=') + ir;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + ic) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&c=') + ic;
              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 (document.getElementById('safariform')) {
              //document.title='where';
              //var oo=window.open('','_blank');
              //oo.document.write('where ' + ans);
              //allowed=false;
              if (document.getElementById('hdata')) {
              document.getElementById('hdata').value=ans;
              }
              document.getElementById('dvals').innerHTML='';
              if (1 == 2) {
              //document.getElementById('safariform').action=document.URL.split('#')[0].split('?')[0];
              document.getElementById('safariform').submit();
              } else {
              //document.title='91';
              wourl=document.URL.replace('data=','datxa=') + '&data=' + ourencodeURIComponent(ans);
              if (retry) wocmd= "selectevent('" + ans + "',false);";
              //document.title=wourl;
              setTimeout(wolater,1000);
              //window.open(document.URL.replace('data=','datxa=') + '&data=' + ourencodeURIComponent(ans),'_blank');
              }
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
        }
 }
 
 function selecteventtwo(ans,retry) {
     if (ans != null) {
            if (ans.replace('null','') != '' && ans != paramdata0) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata0 + '&csv0=' + ans;
             ansbits=ans.split(' ');
                  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';

    
             if (ansbits[0].indexOf('@') != -1) {
               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=') + ir) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&r=') + ir;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + ic) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&c=') + ic;
              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 (document.getElementById('safariform')) {
              //document.title='there';
              //var oo=window.open('','_blank');
              //oo.document.write('there ' + ans);
              //allowed=false;
              if (document.getElementById('hdata0')) {
              document.getElementById('hdata0').value=ans;
              }
              document.getElementById('dvals').innerHTML='';
              //location.href=document.URL.replace('data0=','datxa0=') + '&data0=' + ourencodeURIComponent(ans);
              if (1 == 2) {
              //document.getElementById('safariform').action=document.URL.split('#')[0].split('?')[0];
              document.getElementById('safariform').submit();
              } else {
              //document.title='92';
              wourl=document.URL.replace('data0=','datxa0=') + '&data0=' + ourencodeURIComponent(ans);
              //document.title=wourl;
              if (retry) wocmd= "selecteventtwo('" + ans + "',false);";
              setTimeout(wolater,1000);
              //window.open(document.URL.replace('data0=','datxa0=') + '&data0=' + ourencodeURIComponent(ans),'_blank');
              }
             } else {
              location.href=document.URL.replace(pardata0, ourencodeURIComponent(ans));
             }
            }
            }
         }

  function selecteventthree(ans,retry) {
      if (ans != null) {
            if (ans.replace('null','') != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
                  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';

    
             if (ansbits[0].indexOf('@') != -1) {
               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=') + ir) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&r=') + ir;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + ic) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&c=') + ic;
              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 (document.getElementById('safariform')) {
              //document.title='here';
              //var oo=window.open('','_blank');
              //oo.document.write('here ' + ans);
              //allowed=false;
              if (document.getElementById('hdata')) {
              document.getElementById('hdata').value=ans;
              }
              document.getElementById('dvals').innerHTML='';
              //location.href=document.URL.replace('data=','datxa=') + '&data=' + ourencodeURIComponent(ans);
              if (1 == 2) {
              //document.getElementById('safariform').action=document.URL.split('#')[0].split('?')[0];
              document.getElementById('safariform').submit();
              } else {
              //document.title='93';
              wourl=document.URL.replace('data=','datxa=') + '&data=' + ourencodeURIComponent(ans);
              //document.title=wourl;
              if (retry) wocmd= "selecteventthree('" + ans + "',false);";
              setTimeout(wolater,1000);
              //window.open(document.URL.replace('data=','datxa=') + '&data=' + ourencodeURIComponent(ans),'_blank');
              }
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
            }
      }

function PieClick() { // thanks to //stackoverflow.com/questions/17728880/how-to-add-different-click-events-on-each-pie-of-a-pie-chart-created-by-highchar
    var sliceClicked = this.name;
    

    // do something
}
<?php 
      echo "   var textras='', pieChartBefore, pieChartAfter, pieChartDiff, data, chart, data0; \n" . $pd . $pdp . $pd0 . $pdp0;
      echo "   if (pardata.length == 0) { pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''); paramdata=decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(pardata))))).replace(/\+/g,''); } \n"; 
      echo "   if (pardata0.length == 0) { pardata0 = (location.search.split('data0=')[1] ? location.search.split('data0=')[1].split('&')[0] : ''); paramdata0=decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(pardata0))))).replace(/\+/g,''); } \n"; 
      echo "   var sliceid = 0; /" . "/ thanks to https://gist.github.com/alexrainman/bb8d49357250df0859c0  \n";
      echo "   var selection, sselection;   \n";

      if (isset($_GET['onclickhuh'])) echo "\n textras='&onclick=" . urldecode($_GET['onclickhuh']) . "'; \n";
      if (isset($_POST['onclickhuh'])) echo "\n textras='&onclick=" . urldecode($_POST['onclickhuh']) . "'; \n";
      
      
      if (isset($_GET['emailto'])) echo "\n textras+='&emailto=" . urldecode($_GET['emailto']) . "'; \n";
      if (isset($_POST['emailto'])) echo "\n textras+= '&emailto=" . urldecode($_POST['emailto']) . "'; \n";
      if (isset($_GET['emailsubject'])) echo "\n textras+='&emailsubject=" . urldecode($_GET['emailsubject']) . "'; \n";
      if (isset($_POST['emailsubject'])) echo "\n textras+='&emailsubject=" . urldecode($_POST['emailsubject']) . "'; \n";
      if (isset($_GET['emailcc'])) echo "\n textras+='&emailcc=" . urldecode($_GET['emailcc']) . "'; \n";
      if (isset($_POST['emailcc'])) echo "\n textras+='&emailcc=" . urldecode($_POST['emailcc']) . "'; \n";
      if (isset($_GET['emailbcc'])) echo "\n textras+='&emailbcc=" . urldecode($_GET['emailbcc']) . "'; \n";
      if (isset($_POST['emailbcc'])) echo "\n textras+='&emailbcc=" . urldecode($_POST['emailbcc']) . "'; \n";

 
      $GETtp="";
      if (isset($_GET['tp'])) $GETtp = urldecode($_GET['tp']);
      if (isset($_POST['tp'])) $GETtp = urldecode($_POST['tp']);
      if ($GETtp != "") echo "\n talkingpoint=String.fromCharCode(10) + String.fromCharCode(10) + " . '"' . str_replace("`", '" + String.fromCharCode(10) + "', str_replace("\n", '" + String.fromCharCode(10) + "', $GETtp)) . '"' . " + String.fromCharCode(10) + String.fromCharCode(10); \n";

      $GETr = "";
      $GETc = "";
      if (isset($_GET['r'])) $GETr = urldecode($_GET['r']);
      if (isset($_POST['r'])) $GETr = urldecode($_POST['r']);
      if (isset($_GET['c'])) $GETc = urldecode($_GET['c']);
      if (isset($_POST['c'])) $GETc = urldecode($_POST['c']);
      if ($GETr != "") echo "\n ir=eval('" . $GETr . "'); \n";
      if ($GETc != "") echo "\n ic=eval('" . $GETc . "'); \n";

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

 
      $GETonclick = "";
      $GETyonclick = "";
      if (isset($_GET['onclick'])) { $GETonclick = urldecode($_GET['onclick']);  }
      if (isset($_POST['onclick'])) { $GETonclick = urldecode($_POST['onclick']); }
      if (isset($_GET['onclick'])) $GETyonclick = '&onclick=' + urldecode($_GET['onclick']);
      if (isset($_POST['onclick'])) $GETyonclick = '&onclick=' + urldecode($_POST['onclick']);
      
      echo "var yonclick='" . $GETyonclick . "'; \n";
      
     
      
      $xgd = ""; 
      $gd = ""; 
      $nondefs=", is3D: true ";
      $GETtitle = "My Daily Activities";
      $GETtask = "Task";
      $GETdesc = "Hours per Day";
      if (isset($_GET['deschuh'])) $GETdesc = urldecode($_GET['deschuh']);
      if (isset($_POST['deschuh'])) $GETdesc = urldecode($_POST['deschuh']);
      $GETdata = ",['Work',11],['Eat',2],['Commute',2],['Watch TV', 2],['Sleep',7]";
      

      $GETmoreopt = "";
      if (isset($_GET['moreopt'])) { $GETmoreopt = str_replace("+"," ",urldecode($_GET['moreopt'])); }
      if (isset($_POST['moreopt'])) { $GETmoreopt = str_replace("+"," ",urldecode($_POST['moreopt'])); }


       if (isset($_GET['country'])) {
       $GETtask = str_replace("\\'", "'", $_GET['country']);
       } else if (isset($_POST['country'])) {
       $GETtask = str_replace("\\'", "'", $_POST['country']);
       }
       if (isset($_GET['popularity'])) {
       $GETdesc = str_replace("\\'", "'", $_GET['popularity']);
       } else if (isset($_POST['popularity'])) {
       $GETdesc = str_replace("\\'", "'", $_POST['popularity']);
       }



      if (isset($_GET['desc']) || isset($_POST['desc'])) {
      if (isset($_GET['desc'])) {
       $GETtitle = urldecode(urldecode(urldecode(urldecode(urldecode($_GET['title'])))));
       $GETtask = urldecode(urldecode(urldecode(urldecode(urldecode($_GET['task'])))));
       $GETdesc = urldecode(urldecode(urldecode(urldecode(urldecode($_GET['desc'])))));
   if (isset($_GET['data'])) {
      $getdata=$_GET['data'];
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if ($getdata != "" && strpos($getdata, "[") !== false && strpos($getdata, "[") < strpos($getdata, ",")) {
   $GETdata = "," . $getdata;
      } else {
   $GETdata = "" . $getdata;
      }
    }
       //$GETdata = $_GET['data'];
      } else if (isset($_POST['desc'])) {
       $GETtitle = $_POST['title'];
       $GETtask = $_POST['task'];
       $GETdesc = $_POST['desc'];
       $GETdata = tzl(urldecode($_POST['data']));
      }

       if (isset($_GET['country'])) {
       $GETtask = str_replace("\\'", "'", $_GET['country']);
       } else if (isset($_POST['country'])) {
       $GETtask = str_replace("\\'", "'", $_POST['country']);
       }
       if (isset($_GET['popularity'])) {
       $GETdesc = str_replace("\\'", "'", $_GET['popularity']);
       } else if (isset($_POST['popularity'])) {
       $GETdesc = str_replace("\\'", "'", $_POST['popularity']);
       }


      
      //if ($GETdata != "" && strpos($GETdata, "[") !== false && strpos($GETdata, "[") < strpos($GETdata, ",")) {
      // $GETdata="," . $GETdata;
      //}

      $newextras=$nondefs;
      echo " var colnames= '" . $GETtask . "," . str_replace("'", "", $GETdesc) . "'; \n";
      

      
      if ($GETdata != "" && strpos($GETdata, "[") !== false && strpos($GETdata, "[") < strpos($GETdata, ",")) {
       $GETdata="," . $GETdata;
      }

      //if ($GETonclick == "") {
      //echo "\n function myselectfunctioncca() { } \n\n function myselectfunctionccb() { } \n";
      //}
      if ($GETonclick != "") {
      echo " function myselectfunctioncca() {
 if (readya) {
  var relist=['remail',''],ire,ansbits,ioffset=0,ans=null,doit=true,avblurb=talkingpoint,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues;
  //selection = pieChartAfter.getSelection();
  //if (e && 1 == 2) {  pieChartAfter.setSelection([e]);   }
   sselection = pieChartAfter.getSelection()[0];
    if (sselection) {
      //alert('here ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection.column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
   for (var i = 0; i < 1; i++) { //selection.length; i++) {
    //var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        ir=ir;
        //ic=ic;
  //alert(9999);
        //ir=-1;
        //ic=-1;
      } else {
        //ir=ir;
        //ic=ic;
        //document.title=ir + ',' + ic;
      }
      var str = data.getFormattedValue(ir, 0);
      //alert(str);
      //document.title=str;
      message=document.head.innerHTML.substring(ioffset);
      while (message.indexOf(', ' + '[') != -1) {
       message=message.replace(', ' + '[',',' + '[');
      }
      dparts=message.split(',' + '[');
      //alert('ir=' + ir + ' ic=' + ic + ' str=' + str + ' dparts.length=' +  dparts.length + ' relevant first is ' + dparts[1] + ' second last is ' + dparts[eval(-2 + dparts.length)] + ' last is ' + dparts[eval(-1 + dparts.length)] + ' message=' + message);
      postdparts=dparts[eval(1 + ir)].replace(']',',').split(',');
      var prevals=message.split('[' + String.fromCharCode(39) + str.split(String.fromCharCode(9))[0]); // + String.fromCharCode(39) + ',');
      if (prevals.length > 1) {
        var postvals=prevals[1].replace(']',',').split(',');
        avblurb+=String.fromCharCode(10) + '' + String.fromCharCode(10) + '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 ((operc.trim() + ' ').substring(0,1) != '<') {
        lastp='Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' (' + operc + '%) ' + avblurb;
        } else {
        lastp='Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' ' + avblurb;
        } 
        if (document.getElementById('lastp')) {
          document.getElementById('lastp').value=lastp;
        }
        ans=prompt(lastp, paramdata);
          if (ans != null) {
			selectevent(ans,true);
          }
        ir=-1;
      }
      
      message += '{row:' + ir + ',column:' + ic + '} = ' + str;
    } else if (ir != null) {
      var str = data.getFormattedValue(ir, 0);
      message += '{row:' + ir + ', column:none}; value (col 0) = ' + str;
      //alert(message);
    } else if (ic != null) {
      var str = data.getFormattedValue(0, ic);
      message += '{row:none, column:' + ic + '}; value (row 0) = ' + str;
      //alert(message);
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='2 ' + message;
  if (1 == 1) console.log('YoU selected ' + sliceid + ' ' + message.split('{row')[eval(-1 + message.split('{row').length)]);
 }
 }     
     // );  
      ";
      

      echo " function premyselectfunctionccb(e) {
 if (readyb) {
  pieChartBefore.setSelection([e]);  
  sselection = pieChartBefore.getSelection()[0];
    if (sselection) {
      //alert('herE ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection.column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
 }
       }    
      
 function premyselectfunctioncca(e) {
 if (readya) {
  pieChartAfter.setSelection([e]);  
  sselection = pieChartAfter.getSelection()[0];
    if (sselection) {
      //alert('herE ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection.column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
 }
       }    
      
      
 function premyselectfunction(e) {
 if (ready) {
  chart.setSelection([e]);  
  sselection = chart.getSelection()[0];
    if (sselection) {
      //alert('herE ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection.column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
 }
       }    
      
       function myselectfunctionccb() {
 if (readyb) {
  var relist=['remail',''],ire,ansbits,ioffset=document.head.innerHTML.indexOf(']);'),ans=null,doit=true,avblurb=talkingpoint,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues;
  //if (e && 1 == 2) {  pieChartBefore.setSelection([e]);   }
  sselection = pieChartBefore.getSelection()[0];
    if (sselection) {
      //alert('herE ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection.column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
  for (var i = 0; i < 1; i++) { //selection.length; i++) {
    //var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        ir=ir;
        //ic=ic;
  //alert(9999);
        //ir=-1;
        //ic=-1;
      } else {
        ir=ir;
        //ic=ic;
        //document.title=ir + ',' + ic;
      }
      //alert('ir=' + ir);
      var str = data0.getFormattedValue(ir, 0);
      //alert(str);
      //document.title=str;
      message=document.head.innerHTML.substring(ioffset);
      while (message.indexOf(', ' + '[') != -1) {
       message=message.replace(', ' + '[',',' + '[');
      }
      dparts=message.split(',' + '[');
      //alert('ir=' + ir + ' ic=' + ic + ' str=' + str + ' Dparts.length=' +  dparts.length + ' relevant first is ' + dparts[1] + ' second last is ' + dparts[eval(-2 + dparts.length)] + ' last is ' + dparts[eval(-1 + dparts.length)] + ' message=' + message);
      postdparts=dparts[eval(1 + ir)].replace(']',',').split(',');
      var prevals=message.split('[' + String.fromCharCode(39) + str.split(String.fromCharCode(9))[0]); // + String.fromCharCode(39) + ',');
      if (prevals.length > 1) {
        var postvals=prevals[1].replace(']',',').split(',');
        avblurb+=String.fromCharCode(10) + '' + String.fromCharCode(10) + '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 ((operc.trim() + ' ').substring(0,1) != '<') {
        lastp=' Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' (' + operc + '%) ' + avblurb;
        } else {
        lastp=' Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' ' + avblurb;
        }
        if (document.getElementById('lastp')) {
          document.getElementById('lastp').value=lastp;
        }
        ans=prompt(lastp, paramdata0);
          if (ans != null) {
			selecteventtwo(ans,true);
          }
        ir=-1;
      }

      message += '{row:' + ir + ',column:' + ic + '} = ' + str;
    } else if (ir >= 0) {
      var str = data.getFormattedValue(ir, 0);
      message += '{row:' + ir + ', column:none}; value (col 0) = ' + str;
      //alert(message);
    } else if (ic >= 0) {
      var str = data.getFormattedValue(0, ic);
      message += '{row:none, column:' + ic + '}; value (row 0) = ' + str;
      //alert(message);
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='1 ' + message;
  if (1 == 1) console.log('YOU selected ' +  sliceid + ' ' + message.split('{row')[eval(-1 + message.split('{row').length)]);
 }
 }     
     // );  
      ";
      

      echo " function myselectfunction() {
 if (ready) {
  var relist=['remail',''],ire,ansbits,ioffset=0,ans=null,doit=true,avblurb=talkingpoint,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues;
  //if (e && 1 == 2) {  chart.setSelection([e]);   }
  sselection = chart.getSelection()[0];
    if (sselection) {
      //alert('heRe ');
      if (sselection.row) { ir=sselection.row; sliceid = sselection.row;  } else { ir=sselection.row; }
      //alert(ir);
      if (sselection[0].column) { ic=sselection.column; } else { ic=sselection.column; }
      //alert(ic);
    }
  for (var i = 0; i < 1; i++) { //selection.length; i++) {
    //var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
                ir=ir;
        //ic=ic;
  //alert(9999);
        //ir=-1;
        //ic=-1;
      } else {
        //ir=ir;
        //ic=ic;
        //document.title=ir + ',' + ic;
      }
      var str = data.getFormattedValue(ir, 0);
        //    alert(str);
      //document.title=str;
      message=document.head.innerHTML.substring(ioffset);
      while (message.indexOf(', ' + '[') != -1) {
       message=message.replace(', ' + '[',',' + '[');
      }
      dparts=message.split(',' + '[');
      //alert('ir=' + ir + ' ic=' + ic + ' str=' + str + ' DParts.length=' +  dparts.length + ' relevant first is ' + dparts[1] + ' second last is ' + dparts[eval(-2 + dparts.length)] + ' last is ' + dparts[eval(-1 + dparts.length)] + ' message=' + message);
      postdparts=dparts[eval(1 + ir)].replace(']',',').split(',');
      var prevals=message.split('[' + String.fromCharCode(39) + str.split(String.fromCharCode(9))[0]); // + String.fromCharCode(39) + ',');
      if (prevals.length > 1) {
        var postvals=prevals[1].replace(']',',').split(',');
        avblurb+=String.fromCharCode(10) + '' + String.fromCharCode(10) + '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 ((operc.trim() + ' ').substring(0,1) != '<') {
        lastp='  Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' (' + operc + '%) ' + avblurb;
        } else {
        lastp='  Regarding ' + colparts[0] + ' ' + str + ' you clicked ' + postvals[0].replace(']','') + ' ' + avblurb;
        }
        if (document.getElementById('lastp')) {
          document.getElementById('lastp').value=lastp;
        }
        ans=prompt(lastp, paramdata);
          if (ans != null) {
			selecteventthree(ans,true);
          }
        ir=-1;
      }
      
      message += '{row:' + ir + ',column:' + ic + '} = ' + str;
    } else if (ir != null) {
      var str = data.getFormattedValue(ir, 0);
      message += '{row:' + ir + ', column:none}; value (col 0) = ' + str;
      //alert(message);
    } else if (ic != null) {
      var str = data.getFormattedValue(0, ic);
      message += '{row:none, column:' + ic + '}; value (row 0) = ' + str;
      //alert(message);
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='2 ' + message;
  if (1 == 1) console.log('You selected ' +  sliceid + ' ' + message.split('{row')[eval(-1 + message.split('{row').length)]);
 }
 }     
     // );  
      ";
}      


      
       if (isset($_GET['data0']) || isset($_POST['data0'])) { 
      echo " google.load('visualization', '1.1', {packages:['corechart']}); " . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
      echo " ['" . $GETtask . "','" . $GETdesc . "'] \n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))));
      echo "        ]);\n";
      echo ' data0 = google.visualization.arrayToDataTable([ ' . "\n";
      echo " ['" . $GETtask . "','" . $GETdesc . "'] \n";
      if (isset($_POST['data0'])) {
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", urldecode($_POST['data0']))))));
      } else {
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $gdata0))))); //$_GET['data0'])))));
      }
      echo "        ]);\n";

      
      echo " pieChartBefore = new google.visualization.PieChart(document.getElementById('piechart_before')); \n";
      echo " pieChartAfter = new google.visualization.PieChart(document.getElementById('piechart_after')); \n";
      echo " pieChartDiff = new google.visualization.PieChart(document.getElementById('piechart_diff')); \n";

      //echo " var options = { pieSliceText: 'none' }; \n";

      if (strpos(urldecode($GETdesc), ",") !== false) {
        $others=explode(",", urldecode($GETdesc));
      echo "        var optionszero = {  " . str_replace("right","none",$GETmoreopt) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $others[0] . "'" . $newextras . " \n";
      echo "        }; \n";
      echo "        var optionsone = { " . str_replace("right","none",$GETmoreopt) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $others[1] . "'" . $newextras . " \n";
      echo "        }; \n";
        
      } 
      echo "        var options = { " .  str_replace("right","left",str_replace("620,","820,",$GETmoreopt)) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $GETtitle . "'" . $newextras . " \n";
      echo "        }; \n";
      
      echo "        var optionsz = { " . str_replace("right","none",$GETmoreopt) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $GETtitle . "'" . $newextras . " \n";
      echo "        }; \n";
 }  // huh?
   
      //echo "   var selection; \n";

 if ($ntt) {
  
      echo "   function eventHandler(e){ \n";
      echo "     chart.setSelection([e]); \n";
      echo "     try { \n";
      echo "       selection = chart.getSelection(); \n";
      echo "       sliceid = selection[0].row;  \n";
      echo "     } \n";
      echo "     catch(err) { \n";
      echo "       chart=chart; \n";
      echo "     } \n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(0)").css("font-weight", "bold"); ' . "\n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(1)").html(tooltip[sliceid]).css("font-family", "Arial"); ' . "\n";
      echo "   } \n";
  
      echo "   function ceventHandler(e){ \n";
      echo "     chart.setSelection([e]); \n";
      echo "     try { \n";
      echo "       selection = chart.getSelection(); \n";
      echo "       sliceid = selection[0].row;  \n";
      echo "     } \n";
      echo "     catch(err) { \n";
      echo "       chart=chart; \n";
      echo "     } \n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(0)").css("font-weight", "bold"); ' . "\n";
      echo '    $(".google-visualization-tooltip-item-list li:eq(1)").html(tooltip[sliceid]).css("font-family", "Verdana"); ' . "\n";
      echo "   } \n";
    
      if (strpos($xgd, "<") !== false) {
       // echo "   google.visualization.events.addListener(chart, 'select', ceventHandler); \n";
        echo "   google.visualization.events.addListener(chart, 'onmouseover', ceventHandler); \n";
      } else {
        echo "   google.visualization.events.addListener(chart, 'onmouseover', eventHandler); \n";
      }
}

      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(pieChartBefore, 'ready', function() { readyb=true; }); \n";
      echo "google.visualization.events.addListener(pieChartBefore, 'onmouseover', premyselectfunctionccb); \n";
      //echo "google.visualization.events.addListener(pieChartBefore, 'select', myselectfunctionccb); \n";
      }


      if (strpos(urldecode($GETdesc), ",") !== false) {
      echo " pieChartBefore.draw(data0, optionszero); \n";
      } else {
      echo " pieChartBefore.draw(data0, optionsz); \n";
      }
      if ($GETr != "" && $GETc == "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " pieChartBefore.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunctionccb,4100); \n";
      if ($GETr == "" && $GETc != "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " pieChartBefore.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunctionccb,4100); \n";
      if ($GETr != "" && $GETc != "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " pieChartBefore.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunctionccb,4100); \n";



      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(pieChartAfter, 'ready', function() { readya=true; }); \n";
      echo "google.visualization.events.addListener(pieChartAfter, 'onmouseover', premyselectfunctioncca); \n";
      //echo "google.visualization.events.addListener(pieChartAfter, 'select', myselectfunctioncca); \n";
      }

      if (strpos(urldecode($GETdesc), ",") !== false) {
      echo " pieChartAfter.draw(data, optionsone); \n";
      } else {
      echo " pieChartAfter.draw(data, optionsz); \n";
      }
      if ($GETr != "" && $GETc == "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " pieChartAfter.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunctioncca,4100); \n";
      if ($GETr == "" && $GETc != "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " pieChartAfter.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunctioncca,4100); \n";
      if ($GETr != "" && $GETc != "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " pieChartAfter.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunctioncca,4100); \n";

      echo " var diffData = pieChartDiff.computeDiff(data0, data); \n";
      echo " pieChartDiff.draw(diffData, options);  \n } \n";
      
      // Thanks to //www.quirksmode.org/js/events_properties.html
      echo "\n function ocdata0(e) { 
       isokagaindata0=false; 
      var prevtarg0=targ0;
	if (!e) var e = window.event;
	if (e.target) targ0 = e.target;
	else if (e.srcElement) targ0 = e.srcElement;
	if (targ0.nodeType == 3) targ0 = targ.parentNode;
		if (1 == 4 && targ0.innerHTML.length > 0) { alert(targ0.innerHTML); }
		if (targ0 == null && prevtarg0 != null) {
		 targ0=prevtarg0;
		} else if (targ0 != null) {
		 if (targ0.innerHTML.length > 0 && targ0.innerHTML.indexOf('%') != -1) {
		  datasetis='data0';
		  prevtarg0=targ0;
		 } else if (prevtarg0 != null) {
		  targ0=prevtarg0;
		 }
		}
		 }  \n";
		 
       echo "\n function ocdata(e) { 
        isokagaindata=false; 
      var prevtarg=targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
		if (1 == 4 && targ.innerHTML.length > 0) { alert(targ.innerHTML); }
		if (targ == null && prevtarg != null) {
		 targ=prevtarg;
		} else if (targ != null) {
		 if (targ.innerHTML.length > 0 && targ.innerHTML.indexOf('%') != -1) {
		  datasetis='data';
		  prevtarg=targ;
		 } else if (prevtarg != null) {
		  targ=prevtarg;
		 }
		}
		 }  \n";
		 
     echo "\n function postoc(e) {  var selection, item; \n
		 	if (datasetis == 'data') { ocdata(e);	if (targ) { if (targ.innerHTML.length > 0) { ir=wio(data, targ.innerHTML.replace('%','')); if (myselectfunctioncca) { myselectfunctioncca(); isokagaindata=true; } } } } else {  ocdata0(e);	if (targ0) { if (targ0.innerHTML.length > 0) { ir=wio(data0, targ0.innerHTML.replace('%',''));  if (myselectfunctionccb) { myselectfunctionccb();   isokagaindata0=true;  } } }   }
	 }  \n";
		 
	 echo "\n function wio(ad, perc) { \n
	  var sofarleast=0.0, thisfarleast=0.0, sfl=0;
	  operc=perc;
	  //alert(operc);
	  var retval=0, ex, totx=0.0, numx=0, thisnumx=0.0, ij=0, iok=1, ioffset=0, xdps, ada=new Array();
	  var dhi=document.head.innerHTML.replace(/, \[/g, ',' + '[').replace(/ = /g, '=');
	  ioffset=dhi.indexOf(datasetis + '=google.visualization.arrayToDataTable(');
	  var dps=dhi.substring(ioffset).split(',' + '[');
	  while (iok == 1) {
	   try {
	    xdps=dps[eval(1 + ij)].replace(']',',').split(',');
	    //alert(dps[eval(1 + ij)].replace(']',',') + ' ... ' + xdps.length);
	    //alert('thisnumx=' + datasetis + '.getFormattedValue(ij, 0)');
	    //eval('thisnumx=' + datasetis + '.getFormattedValue(ij, 0)');
	    thisnumx=eval(xdps[1]);
	    ada.push(thisnumx);
	    totx+=eval(thisnumx);
	    //alert('thisnumx=' + thisnumx);
	    ij++;
	    numx++;
	    if (xdps[2].indexOf(']);') != -1) iok=0;
	    if (eval(ij) >= dps.length) iok=0; 
	   } catch (ex) {
	    //alert('Error:' + ex.message);
	    iok=0;
	   }
	  }
	  //alert('numx=' + numx + ' and totx=' + totx);
	  for (ij=0; ij<numx; ij++) {
	    try {
	    if (ij == 0) { sofarleast=Math.abs(eval(ada[ij] * 100.0 / totx) - eval(perc)); }
	    thisfarleast=Math.abs(eval(ada[ij] * 100.0 / totx) - eval(perc));
	    if (thisfarleast < sofarleast) { sofarleast=thisfarleast; sfi=ij; retval=sfi; }
	    if (thisfarleast <= 0.1) {
	      return ij;
	    }
	    } catch(anwer) {
	      retval=retval; //return retval;
	    }
	  }
	  return retval;
	 } \n";
	 

          
      echo " </script> \n";
      echo " </head> \n";
      echo " <body onmousedown='postoc(event);'> \n";
      echo " <h1>" . $GETtitle . " Pie Chart Differences</h1> \n";
 
      echo " <span onmouseover='ocdata0(event);' id='piechart_before' style='vertical-align:top !important;width: 450px; height: 250px; display: inline-block'></span>\n";
      echo " <span onmouseover='ocdata(event);' id='piechart_after' style='vertical-align:top !important;width: 450px; height: 250px; display: inline-block'></span>\n";
      echo " <span id='piechart_diff' style='vertical-align:top !important;width: 450px; height: 250px; display: inline-block'></span>\n";
       } else {
      echo ' data0 = "";' . "\n";
      echo ' google.load("visualization", "1", {packages:["corechart"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      echo ' data = google.visualization.arrayToDataTable([ ' . "\n";
      echo " ['" . $GETtask . "','" . $GETdesc . "'] \n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))));
      echo "        ]);\n";
      echo "        var options = { " . str_replace("right","left",str_replace("620,","820,",$GETmoreopt)) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $GETtitle . "' \n";
      echo "        }; \n";
      echo "        var optionsz = { " . str_replace("right","none",$GETmoreopt) . "\n";
      //echo "        width: 620,
      //        height: 1200,
      //        chartArea: {  width: \"50%\", height: \"70%\" }, \n";
      echo "        title: '" . $GETtitle . "' \n";
      echo "        }; \n";

      echo " chart = new google.visualization.PieChart(document.getElementById('chart_div')); \n";
      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(chart, 'ready', function() { ready=true; }); \n";
      echo "google.visualization.events.addListener(chart, 'onmouseover', premyselectfunction); \n";
      //echo "google.visualization.events.addListener(chart, 'select', myselectfunction); \n";
      }
      echo " chart.draw(data, options); \n";
      if ($GETr != "" && $GETc == "" && (!isset($_GET['cca']) && !isset($_POST['cca']))) echo " chart.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunction,4100); \n";
      if ($GETr == "" && $GETc != "" && (!isset($_GET['cca']) && !isset($_POST['cca']))) echo " chart.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      if ($GETr != "" && $GETc != "" && (!isset($_GET['cca']) && !isset($_POST['cca']))) echo " chart.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      echo "  } \n";
       
      echo " </script> \n";
      echo " </head> \n";
      if ($GETonclick != "") {
      echo " <body style='background-color: silver;'> \n";
      } else {
      echo " <body onload='setTimeout(later, 2 * 1000);' style='background-color: silver;'> \n";
      }
      echo " <h1>" . $GETtitle . " Pie Chart Differences</h1> \n";
      echo '<div id="chart_div" style="width: 900px; height: 500px; background-color: yellow;"></div><div id="bitsatend" style="display:inline;"></div>' . "\n";
       }
?>
    <a id=another title="Another Pie Chart to show differences for" href="./pie_chart_diff.php">Another pie chart to show differences for?</a>
    <?php 
       if ((!isset($_GET['desc']) && !isset($_POST['desc']) && !isset($_GET['popularity']) && !isset($_POST['popularity'])) || $data0 == "") { // || (!isset($_GET['data0']) && !isset($_POST['data0']))) {
 
 
 
   if (isset($_GET['data'])) {
      $getdata=$_GET['data'];
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if (strpos($getdata, "%") !== false) $getdata=str_replace('+',' ',urldecode($getdata));
      if ($getdata != "" && strpos($getdata, "[") !== false && strpos($getdata, "[") < strpos($getdata, ",")) {
   $data0 = "&data0=," . $getdata;
      } else {
   $data0 = "&data0=" . $getdata;
      }
    }

        echo '<' . 'script' . '>' . "\n " . " 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";
        if (isset($_GET['data'])) {
          echo " var title = '" . $GETtitle . "'; " . "\n";
        } else {
          echo ' var title = prompt("Enter Pie Chart Title (prefixes 2d or donut (followed by ;) before title are available options, and suffix by &onclick=y for added onclick functionality,  Email Attachment Title suffixes are &emailto=[emailTo] &emailsubject=[EmailSubject])", "My Daily Activities"); ' . "\n";
        }
        echo ' if (title != null) { ' . "\n";
         if (isset($_GET['data'])) {
          echo " var task = '" . $GETtask . "'; " . "\n";
          echo " var desc = '" . $GETdesc . "'; " . "\n";
          } else {
        echo ' var task = prompt("Enter Activity Type", "' . $GETtask . '"); ' . "\n";
        echo ' var desc = prompt("Enter " + task + " Measure", "Percentage"); ' . "\n";
          }
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = prompt("Enter " + task + " Type " + 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 + " Type " + thisline + " (for no more hit Cancel button)", ""); ' . "\n";
        echo ' if (datalineprefix == null) { ' . "\n";
        echo '     datalineprefix = ""; ' . "\n";
        echo '     totalleft = 0; ' . "\n";
        echo ' } else if (datalineprefix.length != 0) { ' . "\n";
        echo '     extra = "";  ' . "\n";
        echo '     if (desc.indexOf("ercent") != (0 - 1) && desc.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     datalinesuffix = prompt("Enter " + 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 '   } ' . "\n";
        echo ' } ' . "\n";
        if (!isset($_GET['data0']) && isset($_GET['nojwin'])) {
        echo "   if (allowed && nojwinextra != '') {  allowed=false;  if (('' + secondset).replace('null','') == '') { document.title=datac; document.getElementById('dhidden').innerHTML+='<input name=data0 type=hidden value=' + encodeURIComponent(datac) + '></input>';  document.getElementById('dhidden').innerHTML+='<input name=task type=hidden value=' + encodeURIComponent(task) + '></input>';   document.getElementById('dhidden').innerHTML+='<input name=title type=hidden value=' + encodeURIComponent(title.split('&')[0]) + '></input>'; if (title.indexOf('&onclick') != -1) {   document.getElementById('dhidden').innerHTML+='<input name=onclick type=hidden value=y></input>';   }   document.getElementById('dhidden').innerHTML+='<input name=desc type=hidden value=' + encodeURIComponent(desc.replace('  ercent ', '')) + '></input>'; } \n if (defname.indexOf('val') == 0) {  document.getElementById('dvals').innerHTML=''; document.getElementById('safariform').innerHTML=document.getElementById('safariform').innerHTML.replace('name=\"' + defname + '\"',  'name=\"data\"');  } secondset=prompt('Second data set?',datac);  if (('' + secondset).replace('null','') != '') {   allowed=true;   document.getElementById('dhidden').innerHTML+='<input name=data type=hidden value=' + encodeURIComponent(('' + secondset)) + '></input>'; window.location = nocvals(\"./pie_chart_diff.php?title=\" + title + \"&task=\" + task + textras + nojwinextra + \"&desc=\" + desc.replace(\"  ercent \", \"\") + \"&data0=' + decodeURIComponent(decodeURIComponent(datac.replace(/\ /g,''))) + '&nojwinyes=y&data=\" + (('' + secondset).replace(/\ /g,'')));  datac=('' + secondset);   }  } " . "\n";
        }
        //if (!isset($_GET['data']) && isset($_GET['nojwin'])) {

           
            //echo "\n if (allowed && document.URL.indexOf('nojwin') != -1 && secondset == '') window.location = nocvals(\"./pie_chart_diff.php?title=\" + title.replace(\"onclick=\",\"onclickhuh=\") + nojwinextra + \"&task=\" + task + cvals + \"&deschuh=\" + desc.replace(\"  ercent \", \"\") + \"&data=\" + encodeURIComponent(datac)); " . "\n";
            //echo "\n if (allowed && document.URL.indexOf('nojwin') != -1 && secondset != '') window.location = nocvals(\"./pie_chart_diff.php?title=\" + title + \"&task=\" + task + textras + nojwinextra + \"&desc=\" + desc.replace(\"  ercent \", \"\") + \"' . $data0 . '&data=\" + encodeURIComponent(secondset)); " . "\n";
            //echo "\n if (allowed && document.URL.indexOf('nojwin') != -1) allowed=false; \n";
        //} 
        //echo ' if (document.URL.indexOf("&") == -1) alert(allowed + " ... " + nocvals("./pie_chart_diff.php?title=" + title.replace("onclick=","onclickhuh=") + nojwinextra + "&task=" + task + "&deschuh=" + desc.replace("  ercent ", "") + "&data=" + datac)); ' . "\n";
        //echo ' if (document.URL.indexOf("&") == -1 && allowed) alert(nocvals("./pie_chart_diff.php?title=" + title.replace("onclick=","onclickhuh=") + nojwinextra + "&task=" + task + "&deschuh=" + desc.replace("  ercent ", "") + "&data=" + datac)); ' . "\n";
        //echo ' if (document.URL.indexOf("&") != -1 && allowed) alert(887); ' . "\n";
        echo ' if (document.URL.indexOf("&") == -1 && allowed) window.location = nocvals("./pie_chart_diff.php?title=" + title.replace("onclick=","onclickhuh=") + nojwinextra + "&task=" + task + "&deschuh=" + desc.replace("  ercent ", "") + "&data=" + datac); ' . "\n";
        //if (strpos($data0, "&data0=") === false) {


        //echo ' if (document.URL.indexOf("&") != -1 && allowed) window.location = "./pie_chart_diff.php?title=" + title + "&task=" + task + textras + nojwinextra + "&deschuh=" + desc.replace("  ercent ", "") + "' . $data0 . '&data=" + datac; ' . "\n";
        //} else {
        echo ' if (document.URL.indexOf("&") != -1 && allowed) window.location = nocvals("./pie_chart_diff.php?title=" + title + "&task=" + task + textras + nojwinextra + "&desc=" + desc.replace("  ercent ", "") + "' . $data0 . '&data=" + datac); ' . "\n";
        //}
        
        echo "} \n" . "} \n" . '</' . 'script' . '>' . "\n";
      } 
    ?>
<script type='text/javascript'>
if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
  //document.getElementById('pch1').innerHTML+='.';
  var xansis='x', hiddenbits='';
  xpnum=1;
  defname="";
  if (document.URL.indexOf('?') != -1) {
    var pairing, argsare=document.URL.split('#')[0].split('?')[1].split('&');
    for (var iargsare=0; iargsare<argsare.length; iargsare++) {
      pairing=argsare[iargsare].split('=');
      if (('*' + pairing[0]).indexOf('*lastp') != -1) {
       lastp=decodeURIComponent(pairing[1]);
       hiddenbits+="<input type=hidden id=" + pairing[0] + "  name=" + pairing[0] + " value='" + decodeURIComponent(pairing[1]) + "'></input>";
      } else if (('*' + pairing[0]).indexOf('*val') == -1 && ('*' + pairing[0]).indexOf('*prompt') == -1 && ('*' + pairing[0]).indexOf('*OK') == -1 && ('*' + pairing[0]).indexOf('*Cancel') == -1) {
  if (document.URL.indexOf('nojwinyes=') != -1) { 
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + decodeURIComponent(pairing[1]) + "'></input>";
  } else {
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input>";
  }
      } else if (('*' + pairing[0]).indexOf('*data') != -1) {
       if (document.URL.indexOf('data=') == -1 || document.URL.indexOf('data0=') == -1) defname="data";
       hiddenbits+="<div id=ddesc><input type=hidden id=h" + pairing[0] + " name=" + pairing[0] + " value='" + decodeURIComponent(decodeURIComponent(pairing[1])) + "'></input></div>";
      } else if (('*' + pairing[0] + '*').indexOf('*desc*') != -1) {
  if (document.URL.indexOf('nojwinyes=') != -1) { 
       hiddenbits+="<div id=ddesc><input type=hidden name=" + pairing[0] + " value='" + decodeURIComponent(pairing[1]) + "'></input></div>";
  } else {
       hiddenbits+="<div id=ddesc><input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input></div>";
  }
      } else if (('*' + pairing[0] + '*').indexOf('*deschuh*') != -1) {
       hiddenbits+="<div id=ddeschuh><input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input></div>";
      } else if (('*' + pairing[0] + '*').indexOf('*title*') != -1 && decodeURIComponent(decodeURIComponent(pairing[1])).indexOf('&onclick=') != -1) {
       hiddenbits+="<input type=hidden name=onclick value=y></input>";
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + encodeURIComponent(decodeURIComponent(decodeURIComponent(pairing[1])).split('&')[0]) + "'></input>";
      } else if (('*' + pairing[0] + '*').indexOf('*title*') != -1) {
  if (document.URL.indexOf('nojwinyes=') != -1) { 
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + decodeURIComponent(pairing[1]) + "'></input>";
  } else {
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input>";
  }
      }
    }
  }
  hiddenbits+="<div id=dhidden></div><div id=dvals>"
  while (xansis != '') {
   xansis=location.search.split('val' + xpnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + xpnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : '';
   if (document.URL.indexOf('val' + xpnum + '=') != -1) {
     if (xansis.indexOf(',' + '[') != -1) {
     hiddenbits+="<input type=hidden id=hdata name=data value=''></input>";
     hiddenbits+="<input type=hidden id=hdata0 name=data0 value='" + (xansis) + "'></input>";
     //hiddenbits+="<input type=hidden name=data0 value='" + (xansis) + "'></input>";
     cvals+="&val" + xpnum + "=" + encodeURIComponent(xansis);
     if (document.URL.indexOf('data=') == -1 || document.URL.indexOf('data0=') == -1) defname="data";
     } else {
     hiddenbits+="<input type=hidden name=val" + xpnum + " value='" + encodeURIComponent(xansis) + "'></input>";
     cvals+="&val" + xpnum + "=" + encodeURIComponent(xansis);
     }
     xpnum++;
     xansis='x';
   } else {
     xansis='';
   }
  }
  hiddenbits+="</div>"
  if (defname == "") {
    defname="val" + xpnum;
  } else if (document.URL.indexOf('nojwinyes=') == -1 && hiddenbits.indexOf('nojwinyes') == -1 && hiddenbits.indexOf('nojwin') != -1) {
    hiddenbits=hiddenbits.replace('nojwin','nojwinyes');
  }
  if (document.URL.indexOf('nojwinyes=') != -1) { 
  if (hiddenbits.indexOf('id=lastp') == -1) {
       hiddenbits+="<input type=hidden id=lastp  name=lastp value=''></input>";
  }
  document.write("<form onsubmit=\" if (lastp != '') { if (lastp.indexOf('  Regarding ') == 0) {  selecteventthree(document.getElementById('hval" + xpnum + "').value,true); } else if (lastp.indexOf(' Regarding ') == 0) {  selecteventtwo(document.getElementById('hval" + xpnum + "').value,true);  } else { selectevent(document.getElementById('hval" + xpnum + "').value,true); } } else if (document.URL.indexOf('&data=') != -1) { location.href=document.URL; } else { this.style.display='none'; } xpnum++; return false; \" 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=" + defname + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" if (document.getElementById('h' + this.id).name == 'data') { document.getElementById('h' + this.id).value=(this.value);   } else { document.getElementById('h' + this.id).value=encodeURIComponent(this.value); } \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='....';
  } else {
  document.write("<form enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=2 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=" + defname + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" if (document.getElementById('h' + this.id).name == 'data') { document.getElementById('h' + this.id).value=(this.value);   } else { 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';
    }
  }
}

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

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

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