<?php
header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' ); 
  if (file_exists("csv.php")) {
    include "csv.php";
  } else if (file_exists("../csv.php")) { 
    include "../csv.php";
  }

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

<html>
  <head> 
  <!--script type="text/javascript" src="http://www.rjmprogramming.com.au/gchartgen.js"></script-->
  <script type="text/javascript" src="gchartgen.js"></script>
    <title>Pie Chart - RJM Programming - http://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 src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
   
   var ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='';   

<?php 
  echo "var data, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata); \n";
 
      $GETtp="";
      if (isset($_GET['tp'])) $GETtp = urldecode($_GET['tp']);
      if (isset($_POST['tp'])) $GETtp = urldecode($_POST['tp']);
      if ($GETtp != "") echo "\n talkingpoint=String.fromCharCode(10) + String.fromCharCode(10) + " . '"' . str_replace("`", '" + String.fromCharCode(10) + "', str_replace("\n", '" + String.fromCharCode(10) + "', $GETtp)) . '"' . " + String.fromCharCode(10) + String.fromCharCode(10); \n";

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

      
      $xgd = ""; 
      $gd = ""; 
      $ntt=false;
      $nondefs=",  is3D: true ";
      $GETtitle = "My Daily Activities";
      $GETtask = "Task";
      $GETdesc = "Hours per Day";
      $GETdata = ",['Work',11],['Eat',2],['Commute',2],['Watch TV', 2],['Sleep',7]";
      
      if (isset($_POST['data']) && isset($_POST['wouldlikeyoutoseekpermission'])) {
       if (isset($_GET['title'])) {
       $ourtitles=explode(";", $_GET['title']);
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "2d") !== false) {
        $nondefs="";
       }
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "donut") !== false) {
        $nondefs=",  pieHole: 0.4 ";
       }
       $GETtitle = str_replace("\\'", "'", $ourtitles[sizeof($ourtitles) - 1]);
       } else {
       $ourtitles=explode(";", $_POST['title']);
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "2d") !== false) {
        $nondefs="";
       }
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "donut") !== false) {
        $nondefs=",  pieHole: 0.4 ";
       }
       $GETtitle = str_replace("\\'", "'", $ourtitles[sizeof($ourtitles) - 1]);
       }
       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']);
      }
      if (isset($_GET['data'])) {
       $ourtitles=explode(";", $_GET['title']);
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "2d") !== false) {
        $nondefs="";
       }
       if (sizeof($ourtitles) > 1 && strpos(strtolower($ourtitles[0]), "donut") !== false) {
        $nondefs=",  pieHole: 0.4 ";
       }
       $GETtitle = str_replace("\\'", "'", $ourtitles[sizeof($ourtitles) - 1]);
       $GETtask = str_replace("\\'", "'", $_GET['task']);
       $GETdesc = str_replace("\\'", "'", $_GET['desc']);
       $GETdata = str_replace("\\'", "'", $_GET['data']);
      }
      $newextras=$nondefs;
      echo " var colnames= '" . $GETtask . "," . str_replace("'", "", $GETdesc) . "'; \n";
      
      echo ' google.load("visualization", "1", {packages:["corechart"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";
      echo ' function drawChart() { ' . "\n";
      
      
      // A column for custom tooltip content
 if ((isset($_GET['data']) || isset($_POST['data'])) && (isset($_GET['tooltip']) || isset($_POST['tooltip']) || strpos($GETdata, "'") !== false || strpos($GETdata, '"') !== false)) {
      $ntt=true;
  //$newextras=$nondefs . ", focusTarget: 'category', tooltip: {isHtml: true} ";
  $newextras=$nondefs . ",legend:'none', pieSliceText: 'label',     chartArea: {  left: '3%',   top: '3%',   height: '94%',   width: '94%'  }, tooltip: { isHtml: true } ";
  echo "       var tooltip = [ \n";
  $bits=explode("~,", substr($GETdata,1));
  $delts="";
  for ($iy=1; $iy<sizeof($bits); $iy++) {
   $postbits=explode(",", $bits[$iy]);
   $xgd.=str_replace("%3C", "<", str_replace("%3E", ">", $postbits[0]));
   echo $delts . str_replace("%3C", "<", str_replace("%3E", ">", $postbits[0]));
   $delts=",";
  }
  echo "]; \n";
  $gd=$GETdata;
  for ($iy=1; $iy<sizeof($bits); $iy++) {
   $postbits=explode(",", $bits[$iy]);
   $gd=str_replace("," . $postbits[0], "", $gd);
  }
  $GETdata=$gd;
  echo "     data = new google.visualization.DataTable();  \n";
  //echo "   data.addColumn({type: 'string', role: 'domain'}, 'Task');  \n";
  echo "   data.addColumn('string', 'Task');  \n";
  //echo "   data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});  \n";
  echo "   data.addColumn('number', 'Percentage');  \n";
  echo " data.addRows([ \n";
  echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", substr($GETdata,1))))));
  echo "   ]); \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]", substr($GETdata,0))))));
      echo "        ]);\n";
 }    
      
      echo "        var options = { \n";
      echo "        title: '" . $GETtitle . "'" . $newextras . " \n";
      echo "        }; \n";

      echo " chart = new google.visualization.PieChart(document.getElementById('chart_div')); \n";

 if ($ntt) {
   
      //echo "   var selection; \n";
      echo "   var sliceid = 0; /" . "/ thanks to https://gist.github.com/alexrainman/bb8d49357250df0859c0  \n";
  
      echo "   function eventHandler(e){ \n";
      echo "     chart.setSelection([e]); \n";
      echo "     try { \n";
      echo "       selection = chart.getSelection(); \n";
      echo "       sliceid = selection[0].row;  \n";
      echo "     } \n";
      echo "     catch(err) { \n";
      echo "       ; \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 "       ; \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";
      }
}
      $GETonclick = "";
      if (isset($_GET['onclick'])) $GETonclick = urldecode($_GET['onclick']);
      if (isset($_POST['onclick'])) $GETonclick = urldecode($_POST['onclick']);
      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(chart, 'ready', function() { ready=true; }); \n";
      echo "google.visualization.events.addListener(chart, 'select', myselectfunction); \n function myselectfunction() {
 if (ready) {
  var relist=['remail',''],ire,ansbits,avblurb=talkingpoint,ioffset=0,ans=null,doit=true,kl,lk, thisnum, num=0,message = '', dparts, colparts=colnames.split(','), colav=new Array(), predparts, postdparts, diffcolnames=colnames,diffvalues, str;
  selection = chart.getSelection();
  sliceid = selection[0].row;

  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    if ((eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        item.row=ir;
        //item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
        ir=item.row;
        //ic=item.column;
        //document.title=ir + ',' + ic;
      }
      //document.title=str;
      message=document.head.innerHTML.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)';
          ans=prompt('For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + avblurb, paramdata);
          if (ans != null) {
            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() == 'a') {
              location.href=document.URL.replace('/LineChart', '/AreaChart').replace('line_chart.php', 'area_chart.php');
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              location.href=document.URL.replace('/LineChart', '/BarChart').replace('line_chart.php', 'bar_chart.php');
             } else if (ans.substring(0,1).toLowerCase() == 'c') {
              location.href=document.URL.replace('/LineChart', '/ColumnChart').replace('line_chart.php', 'column_chart.php');
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while ' + colparts[eval(3 - item.column)] + ' were ' + postdparts[eval(3 - item.column)].replace(']','') + ' the difference being ' + eval(eval(postdparts[1].replace(']','')) - eval(postdparts[2].replace(']',''))) + avblurb);
          }
         }
        }
      }
    } else if ((item.row != null && item.column != null) || (eval(ir) >= 0 && eval(ic) >= 0)) {
      if (eval(ir) >= 0 && eval(ic) >= 0) {
  //alert(999);
        item.row=ir;
        item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
        ir=item.row;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(item.row, item.column);
      message += '{row:' + item.row + ',column:' + item.column + '} = ' + str;
    } else if ((item.row != null) || (eval(ir) >= 0 && eval(ic) < 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        item.row=ir;
        //item.column=ic;
  //alert(9999);
        ir=-1;
        //ic=-1;
      } else {
        ir=item.row;
        //ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(item.row, 0);
      //document.title=str;
      //document.title=str;
      message=document.head.innerHTML.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)';
          ans=prompt('For ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[1] + ' of ' + postdparts[1].replace(']','') + avblurb, paramdata);
          if (ans != null) {
            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() == 'a') {
              location.href=document.URL.replace('/LineChart', '/AreaChart').replace('line_chart.php', 'area_chart.php');
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              location.href=document.URL.replace('/LineChart', '/BarChart').replace('line_chart.php', 'bar_chart.php');
             } else if (ans.substring(0,1).toLowerCase() == 'c') {
              location.href=document.URL.replace('/LineChart', '/ColumnChart').replace('line_chart.php', 'column_chart.php');
             } else {
              location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while ' + colparts[eval(3 - item.column)] + ' were ' + postdparts[eval(3 - item.column)].replace(']','') + ' the difference being ' + eval(eval(postdparts[1].replace(']','')) - eval(postdparts[2].replace(']',''))) + avblurb);
          }
         }
        }
      }

    } else if ((item.column != null) || (eval(ir) < 0 && eval(ic) >= 0)) {
      if (eval(ir) >= 0 && eval(ic) < 0) {
  //alert(999);
        //item.row=ir;
        item.column=ic;
  //alert(9999);
        //ir=-1;
        ic=-1;
      } else {
        //ir=item.row;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = data.getFormattedValue(0, item.column);
      message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str;
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  if (1 == 2) console.log('You selected ' + message);
 }
 ir=-1;
 ic=-1;    
 } 
      //);  
      ";
      }      echo " chart.draw(data, options); \n   \n";
      if ($GETr != "" && $GETc == "") echo " chart.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunction,4100); \n";
      if ($GETr == "" && $GETc != "") echo " chart.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      if ($GETr != "" && $GETc != "") echo " chart.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunction,4100); \n";
      echo " } \n";
      
      echo " </script> \n";
      echo " </head> \n";
      if (!isset($_GET['desc']) && !isset($_POST['desc'])) {
      echo " <body onload='setTimeout(later, 2 * 1000);'> \n";
      } else {
      echo " <body> \n";
      }
      echo " <h1>" . $GETtitle . " Pie Chart</h1> \n";
?>
    <div id="chart_div" style="width: 900px; height: 500px; background-color: yellow;"></div><div id="bitsatend" style="display:inline;"></div>
    <a title="Another Pie Chart" href="./pie_chart.php">Another pie chart?</a>
    <?php 
        echo '<' . 'script' . '>' . "\n " . " function later() { \n" . ' var datalineprefix = " "; ' . "\n";
      if (!isset($_GET['desc']) && !isset($_POST['desc'])) {
      
        echo ' var dlsa, dlp2="", exra = ""; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var iof=0, extra = ""; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        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)", "My Daily Activities"); ' . "\n";
        echo ' if (title != null) { if (title == "justmenu") { location.href="http://www.rjmprogramming.com.au/PHP/butsel.php?justmenu=justmenu"; } ' . "\n";
        echo ' var titles = title.split(";"); ' . "\n";
        echo ' var task = prompt("Enter Activity Type", "Task"); ' . "\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 +  ' (optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {percent}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={task}' + \"'\" + '>{task}</a>\" ' + '\\n\\n' + ' or maybe perhaps ' + '\\n\\n' + ',\"A tooltip (regarding {percent}) of some sort like <a target=_blank href=' + \"'\" + 'https://en.wikipedia.org/wiki/{task}' + \"'\" + '>{task}</a>\"' + '\\n\\n' + ' as an example of what is possible with HTML included)', ''); " . "\n";
        echo ' if (datalineprefix != null) { iof=0; dlsa=datalineprefix.split(","); if (dlsa.length > 1 && (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(",")))) { while (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(","))) { datalineprefix=datalineprefix.replace(",", "%2C"); iof+=0;   }  }    datalineprefix=datalineprefix.replace(/#/g, "%23"); if (datalineprefix.indexOf("{task}") != -1 && datalineprefix.indexOf(",") != -1) { dlsa=datalineprefix.split(","); if (dlsa.length > 1) {  datalineprefix=datalineprefix.replace("{task}",encodeURIComponent(dlsa[0])).replace("{task}",encodeURIComponent(dlsa[0]));   } }   } ' . "\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) { ' . "\n";
        //echo '    datalineprefix = prompt("Enter " + task + " Type " + thisline + " (for no more hit Cancel button)", ""); ' . "\n";
        echo "    datalineprefix = prompt('Enter ' + task + ' Type ' + thisline +  ' (for no more please hit Cancel button and optionally append with ' + '\\n\\n' + ',\"A tooltip (regarding {percent}) of some sort like <a target=_blank href=' + \"'\" + 'https://www.google.com/#q={task}' + \"'\" + '>{task}</a>\" ' + '\\n\\n' + ' or maybe perhaps ' + '\\n\\n' + ',\"A tooltip (regarding {percent}) of some sort like <a target=_blank href=' + \"'\" + 'https://en.wikipedia.org/wiki/{task}' + \"'\" + '>{task}</a>\"' + '\\n\\n' + ' as an example of what is possible with HTML included)', ''); " . "\n";
        echo '    if (datalineprefix != null) {  iof=0; dlsa=datalineprefix.split(","); if (dlsa.length > 1 && (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(",")))) { while (eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(39))) > eval(datalineprefix.indexOf(",")) && eval(-1 + iof + datalineprefix.indexOf(String.fromCharCode(34))) > eval(datalineprefix.indexOf(","))) { datalineprefix=datalineprefix.replace(",", "%2C"); iof+=0;   }  }   datalineprefix=datalineprefix.replace(/#/g, "%23"); if (datalineprefix.indexOf("{task}") != -1 && datalineprefix.indexOf(",") != -1) { dlsa=datalineprefix.split(","); if (dlsa.length > 1) {  datalineprefix=datalineprefix.replace("{task}",encodeURIComponent(dlsa[0])).replace("{task}",encodeURIComponent(dlsa[0]));   } }   } ' . "\n";
        echo ' } ' . "\n";
        echo ' if (datalineprefix == null) { ' . "\n";
        echo '     datalineprefix = ""; ' . "\n";
        echo '     totalleft = 0; ' . "\n";
        echo ' } else if (datalineprefix.length != 0) { ' . "\n";
        echo '     extra = "";  ' . "\n";
        echo '     if (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 != null) datalineprefix = datalineprefix.replace("{percent}", datalinesuffix + "%"); ' . "\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 '     if (datalineprefix.indexOf(",") != -1 && (datalineprefix.indexOf(String.fromCharCode(39)) != -1 || datalineprefix.indexOf(String.fromCharCode(34)) != -1)) { exra=String.fromCharCode(39) + String.fromCharCode(39) + ","; datac = datac + ", [~" + datalineprefix.replace(",","~,").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E").replace("<","%3C").replace(">","%3E") + "," + datalinesuffix + "] "; ' . "\n";
        echo '     } else { if (exra != "") { exra=String.fromCharCode(39) + datalinesuffix + "%" + String.fromCharCode(39) + ","; } datac = datac + ", [~" + datalineprefix + "~," + exra + datalinesuffix + "] "; ' . "\n";
        echo '     } ' . "\n" . ' thisline++; ' . "\n";
        echo '   } ' . "\n";
        echo ' } ' . "\n";
        echo ' window.location = "./pie_chart.php?title=" + title + "&task=" + task + "&desc=" + desc.replace("  ercent ", "") + "&data=" + datac; ' . "\n";
        echo "} \n";
      }
      echo "} \n";
            echo "\n function fixmenu() { \n";
            $mo="-1";
if (preg_match("/(android|ipad|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])) $mo="-99"; // {
       echo "  if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) || document.URL.indexOf('just' + 'menu') != " . $mo . ") {   var oiagc=document.getElementById('iagc'); \n if (oiagc != null) {  oiagc.style.width=600;  oiagc.style.height=400;  \n";
       if (file_exists("../justmenuWebView.html")) {
         echo " oiagc.src='http://www.rjmprogramming.com.au/PHP/justmenuWebView.html';  var oiagcs=document.getElementsByTagName('a'); \n for (var ity=0; ity<oiagcs.length; ity++) {   if (oiagcs[ity].innerHTML == 'Menu') { oiagcs[ity].href='http://www.rjmprogramming.com.au/PHP/justmenuWebView.html'; } } ";
       }
       echo " } } \n";
//}
       echo " }  \n";
       echo "\n setTimeout(fixmenu, 4000); \n";

      echo '</' . 'script' . '>' . "\n";
    ?>
  </body>
</html>
