<?php
  // column_chart.php
  // Google Column Chart supervisor
  // RJM Programming
  // January, 2016
  // 
  if (file_exists("csv.php")) {
    include "csv.php";
  } else if (file_exists("../csv.php")) { 
    include "../csv.php";
  }
  if (file_exists("bigemail.php")) {
    include "bigemail.php";
  } else if (file_exists("../bigemail.php")) { 
    include "../bigemail.php";
  }

  function retval($inv) {
    if (strpos($inv, "E-") !== false) return "0";
    return $inv;
  }
?>
<html>
  <head> <script type="text/javascript" src="http://www.rjmprogramming.com.au/gchartgen.js"></script>
    <title>Column Chart (differences) - RJM Programming - http://www.rjmprogramming.com.au (Copyright &copy; 2013 rjmprogramming.com.au all rights reserved.)</title>
<?php
  $data0 = "";
  if (isset($_GET['data0'])) {
    $data0 = "&data0=" . $_GET['data0'];
  } else if (isset($_POST['data0'])) {
    $data0 = "&data0=" . $_POST['data0'];
  } 
  
?>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
   
   function fillindata() {
     var bed=document.getElementById('bdataval');
     if (bed == null) {
       document.getElementById('bitsatend').innerHTML+='<input type="hidden" id="bdataval" value="' + encodeURIComponent(paramdata) + '"></input>';
     }
   }
   
   function filldata() {
     var bed=document.getElementById('bedata');
     if (bed != null) {
       if (bed.value == '') {
         bed.value=encodeURIComponent(paramdata);
       }
     }
   }
    
    var ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='';
<?php 
  echo "var chart, data, data0, columnChartBefore, columnChartAfter, columnChartDiff, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata), pardata0 = (location.search.split('data0=')[1] ? location.search.split('data0=')[1].split('&')[0] : ''), paramdata0=decodeURIComponent(pardata0); \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";
      
      $GETtitle = "Company Performance";
      $GETlabel = "Year";
      $GETvalue = "Sales,Expenses";
      $GETdata = ",['2004',1000,400],['2005',1170,460],['2006',660,1120],['2007',1030,540]";
      
      if (isset($_POST['data'])) {
       if (isset($_GET['title'])) {
       $GETtitle = str_replace("\\'", "'", $_GET['title']);
       } else {
       $GETtitle = str_replace("\\'", "'", $_POST['title']);
       }
       if (isset($_GET['label'])) {
       $GETlabel = str_replace("\\'", "'", $_GET['label']);
       } else {
       $GETlabel = str_replace("\\'", "'", $_POST['label']);
       }
       if (isset($_GET['value'])) {
       $GETvalue = str_replace("\\'", "'", $_GET['value']);
       } else {
       $GETvalue = str_replace("\\'", "'", $_POST['value']);
       }
       //$GETdata = str_replace("\\'", "'", $_POST['data']);
       $GETdata = str_replace("~", "'", str_replace("\\'", "'", urldecode(checkdatadata0('POST',$_POST['data']))));
       //echo "\n pardata = " . '"' . $_POST['data'] . '"; ' . " \n";
       echo "\n paramdata='" .  str_replace("'",'~',$GETdata) . "'; \n setTimeout(fillindata, 300); \n setTimeout(filldata, 3000); \n"; // = decodeURIComponent(pardata); " . " \n";
      }
      if (isset($_GET['data'])) {
       $GETtitle = str_replace("\\'", "'", $_GET['title']);
       $GETlabel = str_replace("\\'", "'", $_GET['label']);
       $GETvalue = str_replace("\\'", "'", $_GET['value']);
       $GETdata = str_replace("\\'", "'", $_GET['data']);
      }
      echo " var colnames= '" . $GETlabel . "," . str_replace("'", "", $GETvalue) . "'; \n";
      
      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 " ['" . $GETlabel . "','" . str_replace(",", "','", str_replace("'", "", $GETvalue)) . "'] \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 " ['" . $GETlabel . "','" . str_replace(",", "','", str_replace("'", "", $GETvalue)) . "'] \n";
      if (isset($_GET['data0'])) echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",,", ",0,", str_replace(",]", ",0]", $_GET['data0'])))));
      if (isset($_POST['data0'])) echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",,", ",0,", str_replace(",]", ",0]", $_POST['data0'])))));
      echo "        ]);\n";
      
      echo " columnChartBefore = new google.visualization.ColumnChart(document.getElementById('columnchart_before')); \n";
      echo " columnChartAfter = new google.visualization.ColumnChart(document.getElementById('columnchart_after')); \n";
      echo " columnChartDiff = new google.visualization.ColumnChart(document.getElementById('columnchart_diff')); \n";

      echo " var options = { legend: { position: 'top' } }; \n";

      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(columnChartBefore, 'select', myselectfunctionccb); \n function myselectfunctionccb() {
 if (ready) {
  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;
  var selection = columnChartBefore.getSelection();
  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    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;
      }
      var str = data0.getFormattedValue(item.row, item.column);
      //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) == 3) { 
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + 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)';
          ans=prompt('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, paramdata0);
          if (ans != null) {
            if (ans != '' && 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=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&r=') + item.row;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + '  ?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('Pardata=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //location.href=document.URL.replace(pardata0, 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 {
          predparts=dparts[eval(1 + item.row)].split(']');
          diffvalues=('~' + predparts[0] + '~').replace('~' + postdparts[0].replace(']','') + ',','~');
          if (eval(0 + item.column) == 1) {
            diffvalues=diffvalues.replace('~' + str + ',','').replace(/~/g,'');
          } else if (eval(colparts.length) == eval(1 + item.column)) {
            diffvalues=diffvalues.replace(',' + str + '~','').replace(/~/g,'');
          } else {
            diffvalues=diffvalues.replace(',' + str + ',',',').replace(/~/g,'');
          }
          diffcolnames=('~' + colnames + '~').replace('~' + colparts[0] + ',','~').replace('~' + colparts[eval(0 + item.column)] + ',','').replace(',' + colparts[eval(0 + item.column)] + '~','').replace(',' + colparts[eval(0 + item.column)] + ',',',').replace(/~/g,'');
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + 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)';
          ans=prompt('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + avblurb, paramdata0);
          if (ans != null) {
            if (ans != '' && 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=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&r=') + item.row;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&ccb=y&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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + ' ?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('pardata=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //location.href=document.URL.replace(pardata0, ourencodeURIComponent(ans));
             }
            }
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + avblurb);
          }
         }
        }
      }
      message += '{row:' + item.row + ',column:' + item.column + '} = ' + str;
    } else if (item.row != null) {
      var str = data.getFormattedValue(item.row, 0);
      message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str;
    } else if (item.column != null) {
      var str = data.getFormattedValue(0, item.column);
      message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str;
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='1 ' + message;
  if (1 == 2) console.log('You selected ' + message);
 }
 }     
     // );  
      ";
      }




      echo " columnChartBefore.draw(data0, options); \n";
      if ($GETr != "" && $GETc == "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " columnChartBefore.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunctionccb,4100); \n";
      if ($GETr == "" && $GETc != "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " columnChartBefore.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunctionccb,4100); \n";
      if ($GETr != "" && $GETc != "" && (isset($_GET['ccb']) || isset($_POST['ccb']))) echo " columnChartBefore.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunctionccb,4100); \n";



      if ($GETonclick != "") {
      echo "google.visualization.events.addListener(columnChartAfter, 'ready', function() { ready=true; }); \n";
      echo "google.visualization.events.addListener(columnChartAfter, 'select', myselectfunctioncca); \n function myselectfunctioncca() {
 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;
  var selection = columnChartAfter.getSelection();
  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    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;
      }
      var str = data.getFormattedValue(item.row, item.column);
      //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) == 3) { 
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + 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)';
          ans=prompt('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, 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 (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=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&r=') + item.row;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('pardata=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //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 {
          predparts=dparts[eval(1 + item.row)].split(']');
          diffvalues=('~' + predparts[0] + '~').replace('~' + postdparts[0].replace(']','') + ',','~');
          if (eval(0 + item.column) == 1) {
            diffvalues=diffvalues.replace('~' + str + ',','').replace(/~/g,'');
          } else if (eval(colparts.length) == eval(1 + item.column)) {
            diffvalues=diffvalues.replace(',' + str + '~','').replace(/~/g,'');
          } else {
            diffvalues=diffvalues.replace(',' + str + ',',',').replace(/~/g,'');
          }
          diffcolnames=('~' + colnames + '~').replace('~' + colparts[0] + ',','~').replace('~' + colparts[eval(0 + item.column)] + ',','').replace(',' + colparts[eval(0 + item.column)] + '~','').replace(',' + colparts[eval(0 + item.column)] + ',',',').replace(/~/g,'');
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + 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)';
          ans=prompt('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + 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 (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=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&r=') + item.row;
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&cca=y&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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + '    ?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('paRdata=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + avblurb);
          }
         }
        }
      }
      message += '{row:' + item.row + ',column:' + item.column + '} = ' + str;
    } else if (item.row != null) {
      var str = data.getFormattedValue(item.row, 0);
      message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str;
    } else if (item.column != null) {
      var str = data.getFormattedValue(0, item.column);
      message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str;
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='2 ' + message;
  if (1 == 2) console.log('You selected ' + message);
 }
 }     
     // );  
      ";
      }


      echo " columnChartAfter.draw(data, options); \n";
      if ($GETr != "" && $GETc == "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " columnChartAfter.setSelection([{'row': " . $GETr . ", 'column': null}]); setTimeout(myselectfunctioncca,4100); \n";
      if ($GETr == "" && $GETc != "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " columnChartAfter.setSelection([{'row': null, 'column': " . $GETc . "}]);  setTimeout(myselectfunctioncca,4100); \n";
      if ($GETr != "" && $GETc != "" && (isset($_GET['cca']) || isset($_POST['cca']))) echo " columnChartAfter.setSelection([{'row': " . $GETr . ", 'column': " . $GETc . "}]);  setTimeout(myselectfunctioncca,4100); \n";

      echo " var diffData = columnChartDiff.computeDiff(data0, data); \n";
      echo " columnChartDiff.draw(diffData, options);  \n } \n";
      
          
      echo " </script> \n";
      echo " </head> \n";
      echo " <body style='background-color: silver;'> \n";
      echo " <h1>" . $GETtitle . " Column Chart</h1> \n";

      echo " <span id='columnchart_before' style='width: 450px; height: 250px; display: inline-block'></span>\n";
      echo " <span id='columnchart_after' style='width: 450px; height: 250px; display: inline-block'></span>\n";
      echo " <span id='columnchart_diff' style='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 " ['" . $GETlabel . "','" . str_replace(",", "','", str_replace("'", "", $GETvalue)) . "'] \n";
      echo str_replace("~,", "',", str_replace("[~", "['", str_replace(",]", ",0]", str_replace(",,", ",0,", str_replace(",]", ",0]", $GETdata)))));
      echo "        ]);\n";
      
      echo "        var options = { \n";
      echo "        title: '" . $GETtitle . "', \n";
      echo "        hAxis: {title: '" . $GETlabel . "',  titleTextStyle: {color: 'red'}}" . " \n";
      echo "       }; \n";


      echo " chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); \n";
      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,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;
  var selection = chart.getSelection();
  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
    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;
      }
      var str = data.getFormattedValue(item.row, item.column);
      //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) == 3) { 
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + 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)';
          ans=prompt('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, 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 (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=') + 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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + '   ?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('PardAta=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //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 {
          predparts=dparts[eval(1 + item.row)].split(']');
          diffvalues=('~' + predparts[0] + '~').replace('~' + postdparts[0].replace(']','') + ',','~');
          if (eval(0 + item.column) == 1) {
            diffvalues=diffvalues.replace('~' + str + ',','').replace(/~/g,'');
          } else if (eval(colparts.length) == eval(1 + item.column)) {
            diffvalues=diffvalues.replace(',' + str + '~','').replace(/~/g,'');
          } else {
            diffvalues=diffvalues.replace(',' + str + ',',',').replace(/~/g,'');
          }
          diffcolnames=('~' + colnames + '~').replace('~' + colparts[0] + ',','~').replace('~' + colparts[eval(0 + item.column)] + ',','').replace(',' + colparts[eval(0 + item.column)] + '~','').replace(',' + colparts[eval(0 + item.column)] + ',',',').replace(/~/g,'');
          if (1 == 1) {
          avblurb+='Show this as Line Chart=L' + String.fromCharCode(10);
          avblurb+='Show this as Bar Chart=B' + String.fromCharCode(10);
          avblurb+='Show this as Area Chart=A' + String.fromCharCode(10) + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + 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('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + 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 (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=') + 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() == 'l') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/LineChart').replace('column_chart.php', 'line_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/AreaChart').replace('column_chart.php', 'area_chart.php');
              }
             } else if (ans.substring(0,1).toLowerCase() == 'b') {
              if (pardata == '') {
              location.href=iftoobig('',(document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(paramdata)).replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php'));
              } else {
              location.href=document.URL.replace('/ColumnChart', '/BarChart').replace('column_chart.php', 'bar_chart.php');
              }
             } else if (pardata == '') {
              //alert(document.URL + '   ?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
              location.href=iftoobig('',document.URL + '?title=" . urlencode(str_replace(",","`",$GETtitle)) . '&label=' . urlencode($GETlabel) . '&onclick=y&value=' . urlencode($GETvalue) . "&data=' + ourencodeURIComponent(ans));
             } else {
              //alert('PardatA=' + pardata);
              location.href=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));
              //location.href=document.URL.replace(pardata, ourencodeURIComponent(ans));
             }
            }
          }
          } else {
          alert('In ' + colparts[0] + ' ' + postdparts[0].replace(']','') + ' you clicked ' + colparts[item.column] + ' of ' + str + ' while (' + diffcolnames + ') were (' + diffvalues + ').' + avblurb);
          }
         }
        }
      }
      message += '{row:' + item.row + ',column:' + item.column + '} = ' + str;
    } else if (item.row != null) {
      var str = data.getFormattedValue(item.row, 0);
      message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str;
    } else if (item.column != null) {
      var str = data.getFormattedValue(0, item.column);
      message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str;
    }
  }
  if (message == '') {
    message = 'nothing';
  }
  //document.title='2 ' + message;
  if (1 == 2) console.log('You selected ' + message);
 }
 }     
      //);  
      ";
      }
      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 . " Column Chart</h1> \n";

      echo '<div id="chart_div"></div><div id="bitsatend" style="display:inline;"></div>' . " \n";
      }
      echo '<a title="Another Column Chart to show differences for" href="./column_chart_diff.php">Another column chart to show differences for?</a>' . " \n";
      echo '<' . 'script' . '>' . "\n " . " function later() { \n";
      if ((!isset($_GET['value']) && !isset($_POST['value'])) || $data0 == "") {
         if (isset($_GET['data'])) $data0 = "&data0=" . $_GET['data'];
         if (isset($_POST['data'])) $data0 = "&data0=" . $_POST['data'];
      
        echo ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = ""; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var ii = 0; ' . "\n";
        echo ' var thisdef = "0"; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        if (isset($_GET['data']) || isset($_POST['data'])) {
        echo " var title = '" . $GETtitle . "'; " . "\n";
        } else {
        echo ' var title = prompt("Enter Column Chart Title (suffix by &onclick=y for added onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        }
        echo ' if (title != null) { ' . "\n";
        if (isset($_GET['data']) || isset($_POST['data'])) {
          echo " var label = '" . $GETlabel . "'; " . "\n";
          echo " var value = '" . $GETvalue . "'; " . "\n";
        } else {
        echo ' var label = prompt("Enter Column Concept", "' . $GETlabel . '"); ' . "\n";
        echo ' var value = prompt("Enter Column " + label + " Measure(s) (separated by ,)", "' . $GETvalue . '"); ' . "\n";
        }
        echo ' if (value.indexOf(",") != (0 - 1)) { ' . "\n";
        echo '  for (ii=0; ii<value.length; ii++) { if (value.substring(ii,(ii+1)) == ",") thisdef = thisdef + ",0"; } ' . "\n";
        echo ' } ' . "\n";
        echo ' var datac = ""; ' . "\n";
        echo ' var sq = "' . "'" . '"; ' . "\n";
        echo ' datalineprefix = prompt("Enter " + label + " " + thisline, ""); ' . "\n";
        echo ' while (datalineprefix.length != 0 && (value.indexOf("ercent") == (0 - 1) || value.indexOf("  ercent ") != (0 - 1) || (value.indexOf("ercent") != (0 - 1) && totalleft > 0))) { ' . "\n";
        echo ' if (datalinesuffix.length != 0) datalineprefix = prompt("Enter " + label + " " + 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 (value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) extra = " (for " + totalleft + " enter nothing or hit Cancel button)";  ' . "\n";
        echo '     datalinesuffix = prompt("Enter " + value.replace("  ercent ", "") + " " + thisline + extra, thisdef); ' . "\n";
        echo '     if (datalinesuffix == null && value.indexOf("ercent") != (0 - 1) && value.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) && value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && value.indexOf("ercent") != (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       datalinesuffix = eval(totalleft); ' . "\n";
        echo '       totalleft = 0; ' . "\n";
        echo '     } else if (eval(datalinesuffix) > eval(totalleft) && value.indexOf("ercent") == (0 - 1) && value.indexOf("  ercent ") == (0 - 1)) { ' . "\n";
        echo '       value = value + "  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";
        echo ' window.location = "./column_chart_diff.php?title=" + title + yonclick + "&label=" + label + "&value=" + value.replace("  ercent ", "") + "' . $data0 . '&data=" + datac; ' . "\n";
        echo "} \n" . "} \n";
            }  else {
        echo " } \n";
      } 
      echo '</' . 'script' . '>' . "\n";
 
    ?>
  </body>
</html>
