<?php
  // calendar_chart.php
  // Google Calendar Chart supervisor
  // RJM Programming
  // November, 2015
  // 
  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;
  }

$burl="";
$bdivstart="";
$bdivend="";
$cdivc="background-color: yellow;";
$nondefs="";
  
$amwv=false;
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile/') !== false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari/') == false)) {
  $amwv=true;
}


function tzldates($inwith) {
   $inwithtz=urldecode($inwith);
   if (strpos("~" . strtolower($inwithtz), "~http") !== false) { // co-ordinates via net
     //if (isset($_GET['xx'])) {
     //  echo str_replace("<","&lt;",str_replace(">","&gt;",file_get_contents(str_replace("HTTPS:","http:",str_replace("Https:","http:",str_replace("https:","http:",$inwithtz))))));
     //  exit;
     //}
     $inwithtz=read_and_date_array(file_get_contents(str_replace("HTTPS:","http:",str_replace("Https:","http:",str_replace("https:","http:",$inwithtz)))), str_replace('calendarchart.php','calendar_chart.php',str_replace('index.php','calendar_chart.php',$_SERVER['REQUEST_URI'])));
   } else if (strpos($inwithtz, "[") === false) { // label and dates via clipboard
     $inwithtz=str_replace("`","",str_replace("`,","",'`' . read_and_date_array($inwithtz, str_replace('calendarchart.php','calendar_chart.php',str_replace('index.php','calendar_chart.php',$_SERVER['REQUEST_URI'])))));
   } else {
     return $inwith;
   }
   echo "\n pardata=\"" . str_replace("+","%20",urlencode("" . $inwithtz)) . "\"; paramdata=decodeURIComponent(pardata);  \n var xxpardata=\"" . ("" . $inwithtz) . "\"; \n";
   return urlencode($inwithtz);
}

?>
<!doctype html>
<html>
  <head> <script type="text/javascript" src="//www.rjmprogramming.com.au/gchartgen.js"></script>
    <title>Calendar Chart - RJM Programming - //www.rjmprogramming.com.au (Copyright &copy; 2014 rjmprogramming.com.au all rights reserved.)</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=4, user-scalable=yes" />
 <script type="text/javascript" src="//www.rjmprogramming.com.au/moodle20/lib/yui/2.8.2/build/yahoo/yahoo.js"></script> 
 <script type="text/javascript" src="//www.rjmprogramming.com.au/moodle20/lib/yui/2.8.2/build/event/event.js" ></script> 
 <script type="text/javascript" src="//www.rjmprogramming.com.au/moodle20/lib/yui/2.8.2/build/dom/dom.js" ></script> 
 <script type="text/javascript" src="//www.rjmprogramming.com.au/moodle20/lib/yui/2.8.2/build/calendar/calendar.js"></script> 
 <script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>
<?php 
  echo "\n" . '<link type="text/css" rel="stylesheet" href="//www.rjmprogramming.com.au/moodle20/lib/yui/2.8.2/build/calendar/assets/skins/sam/calendar.css"> ' . "\n";
?>
    <!--script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualisation','version':'1.1','packages':['calendar']}]}"></script-->
    <script type="text/javascript">

     var documentURL="" , locationhref='', etodi='emailee', etodicc='EmailCC', etodibcc='EmailBCC', etodisubject='EmailSubject';
     var ddurl=(document.URL + "");
     if (document.URL.indexOf('file:') != 0) {
     documentURL=ddurl;
     documentURL=documentURL.split('#')[0];
     }
     



    var firstgo=true;
    var assumenumber = -1;
    var str="";
    var num = 0;
    var cdone = 0;
    var retval = "";
    var ttitle = "";
    var ttask = "";
    if (typeof YAHOO === "undefined") {
         ttask=ttask
    } else {
 	    YAHOO.namespace("example.calendar"); 	
   	} 
	    //YAHOO.example.calendar.init = function() { 
	    // YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1SContainer"); 
	    // YAHOO.example.calendar.cal1.render(); 
	    //} 	 
	    //YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.init); 	    
 
 
<?php
       if (isset($_POST['data'])) {
         $appval="";
         $appvald="?";
         if (strlen($_SERVER['QUERY_STRING']) > 1) {
           $appvald.=$_SERVER['QUERY_STRING'] . "&";
         }
         foreach ($_POST as $name => $val) {
           if (htmlspecialchars($name) == "data") {
             $appval.=$appvald . htmlspecialchars($name) . "=" . str_replace("+","%20",urlencode(tzldates(htmlspecialchars($val))));
           } else {
             $appval.=$appvald . htmlspecialchars($name) . "=" . str_replace("+","%20",urlencode(htmlspecialchars($val)));
           }
           $appvald="&";
         }
         echo "\n documentURL=( documentURL.split('#')[0].split('?')[0] + \"" . $appval . "\" ).replace('.php&','.php?');   \n";
       }
?>

 
   var wwl;
   var prevtlbit='', thistlbit='', prevdate='', prevval=-1, ready=false, x=-1, y=-1, elemLeft=0, elemTop=0, ir=-1, ic=-1, talkingpoint='';
   var tlurls=documentURL.replace('/CalendarChart/','/TimelineChart/').replace('calendar_chart.php','timeline_chart.php').split('&data=');
   var tlurl=tlurls[0];
   
   function fillindata() {
     var bed=document.getElementById('bdataval');
     if (bed == null) {
       document.getElementById('bitsatend').innerHTML+='<input type="hidden" id="bdataval" value="' + encodeURIComponent(paramdata) + '"></input>';
     }
   }
   
   function filldata() {
     var bed=document.getElementById('bedata');
     if (bed != null) {
       if (bed.value == '') {
         bed.value=encodeURIComponent(paramdata);
       }
     }
   }
   
   
   function retnum(viad) {
     var retval=0;
     var yrs=viad.split(',');
     if (yrs.length == 2) {
       var mts=yrs[0].split(' ');
       if (mts.length == 2) {
         var mth='';
         if (mts[0].substring(0,3).toLowerCase() == 'jan') mth=0;
         if (mts[0].substring(0,3).toLowerCase() == 'feb') mth=1;
         if (mts[0].substring(0,3).toLowerCase() == 'mar') mth=2;
         if (mts[0].substring(0,3).toLowerCase() == 'apr') mth=3;
         if (mts[0].substring(0,3).toLowerCase() == 'may') mth=4;
         if (mts[0].substring(0,3).toLowerCase() == 'jun') mth=5;
         if (mts[0].substring(0,3).toLowerCase() == 'jul') mth=6;
         if (mts[0].substring(0,3).toLowerCase() == 'aug') mth=7;
         if (mts[0].substring(0,3).toLowerCase() == 'sep') mth=8;
         if (mts[0].substring(0,3).toLowerCase() == 'oct') mth=9;
         if (mts[0].substring(0,3).toLowerCase() == 'nov') mth=10;
         if (mts[0].substring(0,3).toLowerCase() == 'dec') mth=11;
         //alert('[new Date(' + yrs[1].replace(' ','') + ',' + mth + ',' + mts[1] + '),');
         thistlbit='new Date(' + yrs[1].replace(' ','') + ',' + mth + ',' + mts[1] + ')';
         var hbits=document.head.innerHTML.split('google.visual' + 'ization.Calendar(container)')[1].split('[new Date(' + yrs[1].replace(' ','') + ',' + mth + ',' + mts[1] + '),');
         if (hbits.length == 2) {
          var vls=hbits[1].split(']');
          return eval(vls[0]);
         }
       }
     } 
     return retval;
   } 

<?php 
  echo "var dataTable, chart, pardata = (location.search.split('data=')[1] ? location.search.split('data=')[1].split('&')[0] : ''), paramdata=decodeURIComponent(pardata); \n";
?>

   
   var xpnum=1; // done here at supervisor
   var allowed=true; // done here at supervisor
   var nojwinx="", nojwinextra=""; // done here at supervisor
<?php
  if (!isset($_POST['data'])) {
  echo "
   if (document.URL.indexOf('nojwin') == -1 && navigator.userAgent.match(/iPhone|iPad/i)) {
     if (document.URL.indexOf('?') == -1) {
       wwl=iftoobig('',document.URL.split('#')[0] + '?nojwin=Q');  if (wwl != '#') { location.href=wwl; } 
     } else {
       wwl=iftoobig('',document.URL.split('#')[0] + '&nojwin=Q');  if (wwl != '#') { location.href=wwl; } 
     }
   }
   ";
  }
?>
   if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
     nojwinextra="&nojwinyes=Y";
     nojwinx="?nojwin=Y";
   }

<?php
 echo "
 function selectevent(ans) {
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
             if (ansbits[0].indexOf('@') != -1) {
              if (document.getElementById('altemail')) {
              document.getElementById('altemail').value=ansbits[0];
              document.getElementById('remail').href=document.getElementById('remail').href.replace('mt=','mt=' + ansbits[0] + '&junk=youshallneverfindthis').replace('get=','mt=' + ansbits[0] + '&junk=youshallneverfindthis');
              }
              if (document.getElementById('email')) relist[1]='email';
              for (ire=0; ire<2; ire++) {
              if (relist[ire] != '') {
              document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace('fillin.email@address', ansbits[0]);
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&r=') + ir) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&r=') + item.row;
              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' || ans.substring(0,1).toLowerCase() == 'n') {
              if (eval(ans.length) > 1) {
               pstr=ans.substring(1);
              }
              if (tlurl.indexOf('data=') == -1) {
               tlurl+='&data=';
              } else {
               tlurl+=',';
              }
              tlurl+='[~' + encodeURIComponent(pstr) + '~,' + prevtlbit + ',' + thistlbit + ']';
              if (ans.substring(0,1).toLowerCase() == 'n') {
                if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
                document.getElementById('woend').innerHTML='<iframe style=width:100%;height:600px; title=CalendarChart src=\"' + iftoobig('',tlurl) + '\"></iframe>';
                location.href='#woend';
                } else {
                //alert(tlurl);
                window.open(iftoobig('',tlurl), '_blank', 'top=100,left=100,width=500,height=500');
                }
              } else {
                if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
                document.getElementById('woend').innerHTML='<iframe style=width:100%;height:600px; title=CalendarChart src=\"' + iftoobig('',tlurl) + '\"></iframe>';
                location.href='#woend';
                } else {
                //alert(tlurl);
                window.open(iftoobig('',tlurl), '_blank', 'top=100,left=100,width=500,height=500');
                }
              }
             } else if (ans.substring(0,1).toLowerCase() == 'c') {
              if (allowed) { wwl=iftoobig('',tlurl); if (wwl != '#') { location.href=wwl; } } 
             } else if (ans.substring(0,1).toLowerCase() == 't') {
              var d1 = new Date(prevdate);
              var d2 = new Date(str);
              alert('It is ' + Math.floor((d2 - d1) / (1000*60*60*24)) + ' days from ' + prevdate + ' to ' + str + '.  ' + String.fromCharCode(10) + 'On ' + prevdate + ' ' + colparts[0] + ' was ' + prevval + ' while on ' + str + ' ' + colparts[0] + ' was ' + thisval + ' representing a change in ' + colparts[0] + ' of ' + eval(thisval - prevval) + '.');
             } else if (ans.substring(0,1).toLowerCase() == 'o') {
              window.open('https://www.google.com/search?q=' + str.replace(',','%2C').replace(' ','+').replace(' ','+'), '_blank', 'top=100,left=100,width=400,height=400');
             } else if (document.URL.indexOf('&data=') == -1) {
              wwl=iftoobig('',document.URL + '&data=' + ourencodeURIComponent(ans));  if (wwl != '#') { location.href=wwl; }
             } else {
              wwl=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));   if (wwl != '#') { location.href=wwl; }
             }
            } 
   }
 
   function selecteventtwo(ans) {
   
            if (ans != '' && ans != paramdata) {
             if ((ans.toLowerCase() + '~').indexOf('.csv~') != -1 && ans.toLowerCase().indexOf('&') == -1) ans=paramdata + '&csv=' + ans;
             ansbits=ans.split(' ');
             if (ansbits[0].indexOf('@') != -1) {
              if (document.getElementById('altemail')) {
              document.getElementById('altemail').value=ansbits[0];
              document.getElementById('remail').href=document.getElementById('remail').href.replace('mt=','mt=' + ansbits[0] + '&junk=youshallneverfindthis').replace('get=','mt=' + ansbits[0] + '&junk=youshallneverfindthis');
              }
              if (document.getElementById('email')) relist[1]='email';
              for (ire=0; ire<2; ire++) {
              if (relist[ire] != '') {
              document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace('fillin.email@address', ansbits[0]);
              if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&r=') + item.row) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&r=') + item.row;
              //if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&c=') + item.column) == -1) document.getElementById(relist[ire]).href+=encodeURIComponent('&c=') + item.column;
              if (ansbits.length > 1) {
                ans=ans.replace(ansbits[0] + ' ','');
                while (ans.indexOf(' ') != -1) {
                  ans=ans.replace(' ','%20');
                }
                while (ans.indexOf('?') != -1) {
                  ans=ans.replace('?','%3f');
                }
                while (ans.indexOf('&') != -1) {
                  ans=ans.replace('&','%26');
                }
                if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&tp=')) == -1 && document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('?tp=')) == -1) {
                  document.getElementById(relist[ire]).href+=encodeURIComponent('&tp=') + encodeURIComponent(ans);
                } else if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('&tp=')) != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(encodeURIComponent('&tp='), encodeURIComponent('&tp=') + encodeURIComponent(ans) + String.fromCharCode(96));
				} else if (document.getElementById(relist[ire]).href.indexOf(encodeURIComponent('?tp=')) != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(encodeURIComponent('?tp='), encodeURIComponent('?tp=') + encodeURIComponent(ans) + String.fromCharCode(96));
                }
                while (document.getElementById(relist[ire]).href.indexOf(' ') != -1) {
                  document.getElementById(relist[ire]).href=document.getElementById(relist[ire]).href.replace(' ','%20');
                }
                //alert(document.getElementById(relist[ire]).href);
              }
              document.getElementById(relist[ire]).click();
              }
              }
             } else if (ans.substring(0,1).toLowerCase() == 'a' || ans.substring(0,1).toLowerCase() == 'n') {
              if (eval(ans.length) > 1) {
               pstr=ans.substring(1);
              }
              if (tlurl.indexOf('data=') == -1) {
               tlurl+='&data=';
              } else {
               tlurl+=',';
              }
              tlurl+='[~' + encodeURIComponent(pstr) + '~,' + prevtlbit + ',' + thistlbit + ']';
              if (ans.substring(0,1).toLowerCase() == 'n') {
                if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
                document.getElementById('woend').innerHTML='<iframe style=width:100%;height:600px; title=CalendarChart src=\"' + iftoobig('',tlurl) + '\"></iframe>';
                location.href='#woend';
                } else {
                //alert(tlurl);
                window.open(iftoobig('',tlurl), '_blank', 'top=100,left=100,width=500,height=500');
                }
              } else {
                if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
                document.getElementById('woend').innerHTML='<iframe style=width:100%;height:600px; title=CalendarChart src=\"' + iftoobig('',tlurl) + '\"></iframe>';
                location.href='#woend';
                } else {
                //alert(tlurl);
                window.open(iftoobig('',tlurl), '_blank', 'top=100,left=100,width=500,height=500');
                }
              }
             } else if (ans.substring(0,1).toLowerCase() == 'c') {
              if (allowed) { wwl=iftoobig('',tlurl); if (wwl != '#') { location.href=wwl; } } 
             } else if (ans.substring(0,1).toLowerCase() == 't') {
              var d1 = new Date(prevdate);
              var d2 = new Date(str);
              alert('It is ' + Math.floor((d2 - d1) / (1000*60*60*24)) + ' days from ' + prevdate + ' to ' + str + '.  ' + String.fromCharCode(10) + 'On ' + prevdate + ' ' + colparts[0] + ' was ' + prevval + ' while on ' + str + ' ' + colparts[0] + ' was ' + thisval + ' representing a change in ' + colparts[0] + ' of ' + eval(thisval - prevval) + '.');
             } else if (ans.substring(0,1).toLowerCase() == 'o') {
              window.open('https://www.google.com/search?q=' + str.replace(',','%2C').replace(' ','+').replace(' ','+'), '_blank', 'top=100,left=100,width=400,height=400');
             } else if (document.URL.indexOf('&data=') == -1) {
              wwl=iftoobig('',document.URL + '&data=' + ourencodeURIComponent(ans));  if (wwl != '#') { location.href=wwl; }
             } else {
              wwl=iftoobig('',document.URL.replace(pardata, ourencodeURIComponent(ans)));  if (wwl != '#') { location.href=wwl; }
             }
            }   
   }
 ";

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

      $GETtitle = "Red Sox Attendance";
      $GETtask = ""; //"Task";
      $GETdesc = "Won/Loss";
      $GETdata = "[ new Date(2012, 3, 13), 37032 ],
          [ new Date(2012, 3, 14), 38024 ],
          [ new Date(2012, 3, 15), 38024 ],
          [ new Date(2012, 3, 16), 38108 ],
          [ new Date(2012, 3, 17), 38229 ],
          [ new Date(2013, 9, 4), 38177 ],
          [ new Date(2013, 9, 5), 38705 ],
          [ new Date(2013, 9, 12), 38210 ],
          [ new Date(2013, 9, 13), 38029 ],
          [ new Date(2013, 9, 19), 38823 ],
          [ new Date(2013, 9, 23), 38345 ],
          [ new Date(2013, 9, 24), 38436 ],
          [ new Date(2013, 9, 30), 38447 ]";
          
      $mg=$GETdata;    
          
      if (isset($_POST['data'])) {
       $GETdata = str_replace('~','"',urldecode(checkdatadata0('POST',tzldates($_POST['data']))));
       //echo "\n pardata = " . '"' . $_POST['data'] . '"; ' . " \n";
       echo "\n paramdata='" . $GETdata . "'; \n setTimeout(fillindata, 300); \n setTimeout(filldata, 3000); \n"; // = decodeURIComponent(pardata); " . " \n";
      } else if (isset($_GET['data'])) {
       $prevg=str_replace('~','"',urldecode(tzldates($_GET['data'])));
       $GETdata = str_replace('~','"',urldecode(checkdatadata0('GET',tzldates($_GET['data']))));
       if ($prevg != $GETdata) {
        echo "\n paramdata='" . $GETdata . "'; \n setTimeout(fillindata, 300); \n setTimeout(filldata, 3000); \n"; // = decodeURIComponent(pardata); " . " \n";
       }
      }
      
      
      if ($mg == $GETdata && strpos($_SERVER['QUERY_STRING'],"title=") !== false) {
       $bbits = explode("data=", file_get_contents('php://input'));
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode(explode('&',explode("title=", $_SERVER['QUERY_STRING'])[1])[0])))));
       $GETdesc = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", str_replace("\\'", "'", urldecode(explode('&',explode("desc=", $_SERVER['QUERY_STRING'])[1])[0])))));
       $GETtask = str_replace("\\'", "'", urldecode(explode('&',explode("task=", $_SERVER['QUERY_STRING'])[1])[0])); //$_GET['task'];
       if (sizeof($bbits) > 1) {
         $GETdata = str_replace("~", "'", str_replace("\\'", "'", urldecode(explode('&',$bbits[1])[0])));
       } else {
         $GETdata = "";
       }
      } else if (isset($_POST['title'])) {
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", urldecode(urldecode($_POST['title'])))));
       titlebits($burl, $GETtitle, $cdivc, $bdivstart, $bdivend, $nondefs);
       $GETtask = urldecode($_POST['task']);
       $GETdesc = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", urldecode(urldecode($_POST['desc'])))));
      } else if (isset($_GET['title'])) {
       //$GETtitle = str_replace("~~", "##", $_GET['title']);
       $GETtitle = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", urldecode(urldecode($_GET['title'])))));
       titlebits($burl, $GETtitle, $cdivc, $bdivstart, $bdivend, $nondefs);
       //$GETtitle = str_replace("##", "'", $GETtitle);
       $GETtask = $_GET['task'];
       //$GETdesc = str_replace("~~", "##", $_GET['desc']);
       $GETdesc = str_replace("~~", "'", str_replace('~', '"', str_replace("`", "'", urldecode(urldecode($_GET['desc'])))));
       //$GETdesc = str_replace("##", "'", $GETdesc);
      } 
      echo " var colnames= '" . str_replace("'", "", $GETdesc) . "'; \n";

      echo " function myselectfunction() {
 if (ready) {
  var pstr='',relist=['remail',''],ire,thisval,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;
  if (firstgo) {
    firstgo=false;
      if (eval(ir) >= 0 && eval(ic) < 0) {
      str = dataTable.getFormattedValue(ir, 0);
//alert(71111 + ' ... ' + str);
      message += '{row:' + ir + ', column:none}; value (col 0) = ' + str;
          thisval=retnum(str);
          pstr=prevval + ' to ' + thisval + ' ' + colparts[0];
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'On This Day=O' + String.fromCharCode(10);
          if (prevdate != '') avblurb+='On These Daisies=T (relative to ' + prevdate + ')' + String.fromCharCode(10);
          if (prevtlbit != '') avblurb+='Add to a Timeline Representation=A (relative to ' + prevdate + ') (anything after A overrides Timeline label of [' + pstr + '])' + String.fromCharCode(10);
          if (prevtlbit != '') avblurb+='Add to a Timeline Representation and Show in New Window=N (as above)' + String.fromCharCode(10);
          if (tlurl.indexOf('data=') != -1) avblurb+='Show the Current Timeline Representation on Top of This Calendar Chart=C ' + String.fromCharCode(10);
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + '' + String.fromCharCode(10);
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'Change data as required below (keeping it the same or being blank or choosing Cancel leaves the status quo)';
          ans=prompt('Regarding ' + colparts[0] + ' (' + thisval + ') you clicked date of ' + str + avblurb, paramdata);
          if (ans != null) {
			selectevent(ans);
          }
          prevdate=str;
          prevval=thisval;
          prevtlbit=thistlbit;
      }
      ic=-1;
      ir=-1;
      return;
  }
  var selection = chart.getSelection();
  for (var i = 0; i < selection.length; i++) {
    var item = selection[i];
//alert(111);
    if ((item.row != null && item.column != null) || (eval(ir) >= 0 && eval(ic) >= 0)) {
//alert(1111);
      if (eval(ir) >= 0 && eval(ic) >= 0) {
  //alert(999);
        item.row=ir;
        item.column=ic;
  //alert(9999);
        ir=-1;
        ic=-1;
      } else {
//alert(61111);
        ir=item.row;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = dataTable.getFormattedValue(item.row, item.column);

    } 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 {
//alert(61111);
        ir=item.row;
        ic=-1;
        //document.title=ir + ',' + ic;
      }
      str = dataTable.getFormattedValue(item.row, 0);
//alert(71111 + ' ... ' + str);
      message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str;
          thisval=retnum(str);
          pstr=prevval + ' to ' + thisval + ' ' + colparts[0];
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'On This Day=O' + String.fromCharCode(10);
          if (prevdate != '') avblurb+='On These Daisies=T (relative to ' + prevdate + ')' + String.fromCharCode(10);
          if (prevtlbit != '') avblurb+='Add to a Timeline Representation=A (relative to ' + prevdate + ') (anything after A overrides Timeline label of [' + pstr + '])' + String.fromCharCode(10);
          if (prevtlbit != '') avblurb+='Add to a Timeline Representation and Show in New Window=N (as above)' + String.fromCharCode(10);
          if (tlurl.indexOf('data=') != -1) avblurb+='Show the Current Timeline Representation on Top of This Calendar Chart=C ' + String.fromCharCode(10);
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'Comma Separated Values Spreadsheet Export=filename.csv' + String.fromCharCode(10) + '' + String.fromCharCode(10) + 'Email with or without Talking Point=fillin.email@address This is when the improvement started.  Robert' + String.fromCharCode(10) + '' + String.fromCharCode(10);
          avblurb+=String.fromCharCode(10) + String.fromCharCode(10) + 'Change data as required below (keeping it the same or being blank or choosing Cancel leaves the status quo)';
          ans=prompt(' Regarding ' + colparts[0] + ' (' + thisval + ') you clicked date of ' + str + avblurb, paramdata);
          if (ans != null) {
			selecteventtwo(ans);
          }
          prevdate=str;
          prevval=thisval;
          prevtlbit=thistlbit;
    } 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 {
//alert(61111);
        ir=-1;
        ic=item.column;
        //document.title=ir + ',' + ic;
      }
      str = dataTable.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;
}     
      //);  
      ";



      
      $gdata = str_replace("~~", "'", str_replace("newDate", "new Date", str_replace("%2c", ",", str_replace("%27", "'", str_replace("%20", " ", str_replace("%28", "(", str_replace("%29", ")", str_replace("%5b", "[", str_replace("`", "'",str_replace("%5d", "]",str_replace('~,', '",', str_replace('[~', '["', str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))))))))))))));
      //echo "\n var xassumenumber = '" . $gdata . "'; \n";
      $thing = "number";
      if (strpos($gdata, "'") !== false) {
        $thing = "string";
        echo "\n assumenumber = 0; \n";
      } else if (strpos($gdata, '"') !== false) {
        $thing = "string";
        echo "\n assumenumber = 0; \n";
      } else if (strpos($gdata, '~') !== false) {
        $thing = "string";
        echo "\n assumenumber = 0; \n";
      }
      
      //echo ' google.load("visualization", "1", {packages:["corechart"]}); ' . "\n";
      echo ' google.charts.load("current", {packages:["calendar"]}); ' . "\n";
      echo ' google.setOnLoadCallback(drawChart); ' . "\n";  // old
      echo ' function drawChart() { ' . "\n";
      echo " var container = document.getElementById('chart_div'); \n";

      echo " chart = new google.visualization.Calendar(document.getElementById('chart_div')); \n";
      //echo " chart = new google.visualization.DataTable(); \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";
      //echo "google.visualization.events.addListener(chart, 'onmouseover', myselectfunction); \n";
      }

      echo ' dataTable = new google.visualization.DataTable(); ' . "\n";
      //echo " dataTable.addColumn({ type: 'string', id: '" . $GETdesc . "' }); \n";
      echo " dataTable.addColumn({ type: 'date', id: 'Date' }); \n";
      echo " dataTable.addColumn({ type: '" . $thing . "', id: '" . $GETdesc . "' }); \n";

      if ($GETdata == "") {
      echo ' var prewert=" data.addRows([ "; ' . "\n";
      echo " prewert+=parent.document.getElementById('data').value.substring(0).replace(/\,\]/g,',0]').replace(/\]\~/g,'[\"').replace(/\~\,/g,'\",').replace(/\%5d/g,']').replace(/\`/g,\"'\").replace(/\%5b/g,'[').replace(/\%29/g,')').replace(/\%28/g,'(').replace(/\%20/g,' ').replace(/\%27/g,\"'\").replace(/\%2c/g,',').replace(/newDate/g,'new Date').replace(/\~\~/g,\"'\"); " . "\n";
      echo ' prewert+=" ])";' . "\n";
      echo ' eval(prewert); ' . "\n";
      } else {
      echo ' dataTable.addRows([' . "\n";
      if ($thing == "number") {
      echo str_replace("~~", "'", str_replace("newDate", "new Date", str_replace("%2c", ",", str_replace("%27", "'", str_replace("%20", " ", str_replace("%28", "(", str_replace("%29", ")", str_replace("%5b", "[", str_replace("`", "'",str_replace("%5d", "]",str_replace(',~', ',"', str_replace('~]', '"]', str_replace(",]", ",0]", str_replace(",]", ",0]", str_replace(",]", ",0]", $GETdata)))))))))))))));
      } else {
      echo str_replace("~~", "'", str_replace("newDate", "new Date", str_replace("%2c", ",", str_replace("%27", "'", str_replace("%20", " ", str_replace("%28", "(", str_replace("%29", ")", str_replace("%5b", "[", str_replace("`", "'",str_replace("%5d", "]",str_replace(',~', ',"', str_replace('~]', '"]', str_replace(",]", ",\"\"]", str_replace(",]", ",\"\"]", str_replace(",]", ",0]", $GETdata)))))))))))))));
      }
      echo "]);\n";
      }
      //echo " var chart = new google.visualization.Calendar(document.getElementById('chart_div')); \n";


       if ($nondefs == "") {
        echo "        var options = { \n";
        echo "        title:'Red Sox Attendance', \n";
        echo "        height: 350 \n";
        echo "        }; \n";
        echo " chart.draw(dataTable,options); \n";
       } else {
        echo "        var options = { \n";
        echo "        " . str_replace(",","",$nondefs) . " \n";
        echo "        }; \n";
        echo " chart.draw(dataTable,options); \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";
      
      $ic = 1;
      
      for ($ic=1; $ic<100; $ic++) {
 echo ' function cals' . $ic . '(inhuh,mode) {' . "\n";
 echo ' if (inhuh > ' . $ic . ') { return cals' . ($ic + 1) . '(inhuh,mode); } else if (inhuh < ' . $ic . ') { return cals' . ($ic - 1) . '(inhuh,mode); } else { ' . "\n";
 echo ' if (mode == 0) {YAHOO.example.calendar.cals' . $ic . ' = new YAHOO.widget.Calendar("cals' . $ic . '","cal' . $ic . 'SContainer");  ' . "\n";
 echo ' YAHOO.example.calendar.cals' . $ic . '.render();  ' . "\n";
 echo ' YAHOO.example.calendar.cale' . $ic . ' = new YAHOO.widget.Calendar("cals' . $ic . '","cal' . $ic . 'EContainer");  ' . "\n";
 echo ' YAHOO.example.calendar.cale' . $ic . '.render(); ' . "\n"; 
 echo ' } else { ' . "\n"; 
 echo ' retval = "";  ' . "\n"; 
 echo ' var iput = document.getElementById("i' . $ic . 'put"); ' . "\n"; 
 echo " retval = retval + '[" . '"' . "' + iput.value + '" . '"' . ",'; " . "\n"; 
 echo ' var pDates = YAHOO.example.calendar.cals' . $ic . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' var pDatee = YAHOO.example.calendar.cals' . $ic . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDates) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDates.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDates.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDates.getDate() + "),"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      } else { ' . "\n"; 
 echo '  pDates = YAHOO.example.calendar.cals' . ($ic - 1) . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDates) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDates.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDates.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDates.getDate() + "),"; ' . "\n"; 
 //echo ' retval = retval + pDates.getDate() + ".";	         ' . "\n"; 
 echo '      }  ' . "\n"; 
 echo '      } ' . "\n"; 
 echo ' if (pDatee) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDatee.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDatee.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDatee.getDate() + ")]"; ' . "\n"; 
 //echo ' retval = retval + pDatee.getDate() + ".";	         ' . "\n"; 
 echo '     } else { ' . "\n"; 
 echo '  pDatee = YAHOO.example.calendar.cals' . ($ic + 1) . '.getSelectedDates()[0]; ' . "\n"; 
 echo ' if (pDatee) { ' . "\n"; 
 echo ' retval = retval + "newDate(" + eval(1900 + pDatee.getYear()) + ","; ' . "\n"; 
 echo ' retval = retval + eval(0 + pDatee.getMonth()) + ","; ' . "\n"; 
 echo ' retval = retval + pDatee.getDate() + ")]"; ' . "\n"; 
 //echo ' retval = retval + pDatee.getDate() + ".";	         ' . "\n"; 
 echo '     }  ' . "\n"; 
 echo '      }  ' . "\n"; 
 echo '  return rework(retval);  } ' . "\n"; 
 echo ' } return ""; } ' . "\n";
      }
      
?>
   function cals0(huh,huh2) {
   }
   function cals100(huh,huh2) {
   }
   
   function rework(huh) {
      //alert(huh);
      var maptozero = 0;
      var huhs = huh.split(",");
      var huhzero = huhs[0].replace("[","").replace('~','').replace('~','').replace('"','').replace('"','');
      if (assumenumber == -1) {
          if (isNaN(parseInt(huhzero))) {
            assumenumber = 0;
            maptozero = 1;
          } else {
            assumenumber = 1;
          }
      } else {
          if (isNaN(parseInt(huhzero))) {
            maptozero = 1;
          } else {
            maptozero = 0;
          }
      }
      if (maptozero == 1) {
        huhs[0] = "0";
        if (cdone == 0) {
          cdone = 1;
          alert("Non-numerics will be mapped to 0");
        }
      }
      //alert("[" + huhs[1] + ","  + huhs[2] + "," + huhs[3] + "," + huhs[0].replace("[","").replace('"','').replace('"','') + "]");
      if (assumenumber == 0 && 1 == 2) {
        return "[" + huhs[1] + ","  + huhs[2] + "," + huhs[3] + "," + huhs[0].replace("[","") + "]";
      }
      return "[" + huhs[1] + ","  + huhs[2] + "," + huhs[3] + "," + huhs[0].replace("[","").replace('"','').replace('"','') + "]";
   }

   function goforth() {
   //alert(99);
     var ii=1;
     var dt = "";
     var ci = "";
     while (ii <= num) {
       dt = dt + ci + cals1(ii,1);
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       dt = dt.replace("'", "~~").replace('"', '~');
       ttitle = ttitle.replace("'", "~~").replace('"', '~');
       ttitle = ttitle.replace("'", "~~").replace('"', '~');
       ci = ",";
       ii = ii + 1;
       //alert(dt);
     }
     if (allowed) { wwl = iftoobig("","./calendar_chart.php?title=" + ttitle.replace("'", "~~").replace('"', '~') + "&desc=" + ttitle.replace("'", "~~").replace('"', '~').replace('onclick=','qc=') + nojwinextra + "&data=" + dt.replace("'", "~~").replace('"', '~'));  if (wwl != '#') { location.href=wwl; } } 
   }
<?php
      echo " </script> \n";
      echo " </head> \n";
      if (!isset($_GET['desc']) && !isset($_POST['desc'])) {
      echo " <body class='yui-skin-sam' onload='setTimeout(later, 2 * 1000);'> \n";
      } else {
      echo " <body class='yui-skin-sam'> \n";
      }
      echo " <h1>" . $GETtitle . " Calendar Chart</h1> \n";
?>
    <?php echo $bdivstart; ?><div id="chart_div" style="<?php echo $cdivc; ?>width: 920px; height: 200px; background-color: yellow;"></div><?php echo $bdivend; ?><div id="bitsatend" style="display:inline;"></div>
    <div id="calendar_table"></div>
    <a id=another title="Another Calendar Chart" href="./calendar_chart.php">Another calendar chart?</a>
    <?php 
      if (!isset($_GET['desc']) && !isset($_POST['desc'])) {
      
        echo '<' . 'script' . '>' . "\n " . " function later() { \n" . ' var datalineprefix = " "; ' . "\n";
        echo ' var datalinesuffix = ""; ' . "\n";
        echo ' var extra = ""; ' . "\n";
        echo ' var bits = ""; ' . "\n";
        echo ' var task = ""; ' . "\n";
        echo ' var ict = 0; ' . "\n";
        echo ' var thisline = 1; ' . "\n";
        echo ' var totalleft = 100.0; ' . "\n";
        echo ' var title = prompt("Enter Calendar Chart Title (background image URL or background image data URI ; separated (followed by ;) before title are available options, and suffix by &onclick=y for added onclick functionality)", "' . $GETtitle . '"); ' . "\n";
        
        echo ' if (title != null) { ' . "\n";
        echo ' ttitle = title; ' . "\n" . ' task = prompt("Enter Number of " + title.replace(' . '"' . '&onclick=y' . '"' . ',' . '"' . '' . '"' . ') + " (can enter URL whose contents contains description,date1,date2 sets or your own list entered here comma separated)", "0"); ttask = task; ' . "\n";
        
        
        echo ' if (task == null) { ' . "\n";
        echo '  title = title; ' . "\n";
        echo ' } else if (("~" + task.toLowerCase().replace(",","~http")).indexOf("~http") != -1) { ' . "\n";
        echo ' if (allowed) { wwl = iftoobig("","./calendar_chart.php?title=" + ttitle.replace(String.fromCharCode(39), "~~").replace(String.fromCharCode(34), String.fromCharCode(126)) + "&desc=" + ttitle.replace(String.fromCharCode(39), "~~").replace(String.fromCharCode(34), String.fromCharCode(126)) + nojwinextra + "&data=" + encodeURIComponent(task));  if (wwl != "#") { location.href=wwl; } } ' . "\n";
        echo ' } else if (task != "0" && task.indexOf("-") == -1 && (task.length == 1 || task.length == 2)) { ' . "\n";
        echo '  bits = "<br><a id=wafo href=# onclick=' . "'" . 'goforth();' . "'" . ' title=' . "'" . 'Show' . "'" . '>Click here to Show Chart when All Filled out Below ...</a><br><table border=1><tr><td>From</td><td>" + title + " (non-numerics mapped to 0)</td><td style=\'display:none;\'>To</td></tr>";' . "\n";

        echo '  num = task;' . "\n" . 'while (ict != task) { ' . "\n";
        echo '    bits = bits + "<tr>";' . "\n";
        echo '    ict = ict + 1;' . "\n";
        echo '    bits = bits + "<td><div id=cal" + ict + "SContainer></div></td>";' . "\n";
        echo '    bits = bits + "<td><input id=i" + ict + "put type=text></input></td>";' . "\n";
        echo '    bits = bits + "<td style=\'display:none;\'><div id=cal" + ict + "EContainer></div></td>";' . "\n";
        echo '    bits = bits + "</tr>";' . "\n";
        //echo '  alert(ict + " -- " + bits);' . "\n";
        echo '    } ' . "\n";

        echo '  } else { alert("Can only handle 99 or less."); window.location = "./calendar_chart.php" + nojwinx; }' . "\n";
        echo '  bits = bits + "</table>";' . "\n";
        //echo '  alert(bits);' . "\n";
        echo ' var ct = document.getElementById("calendar_table"); ' . "\n";
        echo '  ct.innerHTML = bits; location.href="#wafo"; ' . "\n";
        //echo '  alert(ct.innerHTML);' . "\n";
        echo '    if (ict != 0) { ict = 0; ' . "\n";
        echo '  while (ict != task) { ' . "\n";
        echo '    ict = ict + 1;' . "\n";
        echo '    cals1(ict,0);' . "\n";
        echo '    } } ' . "\n";
        echo ' } ' . "\n";
        

        echo "} \n" . '</' . 'script' . '>' . "\n";
      } else {
        echo '<' . 'script' . '>' . "\n " . " function later() { \n" . '  ' . "\n";
        echo "} \n" . '</' . 'script' . '>' . "\n";
      } 
    ?>
<script type='text/javascript'>
if (document.URL.indexOf('nojwin') != -1 || navigator.userAgent.match(/iPhone|iPad/i)) {
  //document.getElementById('pch1').innerHTML+='.';
  var xansis='x', hiddenbits='';
  xpnum=1;
  if (document.URL.indexOf('?') != -1) {
    var pairing, argsare=document.URL.split('#')[0].split('?')[1].split('&');
    for (var iargsare=0; iargsare<argsare.length; iargsare++) {
      pairing=argsare[iargsare].split('=');
      if (('*' + pairing[0]).indexOf('*val') == -1 && ('*' + pairing[0]).indexOf('*prompt') == -1 && ('*' + pairing[0]).indexOf('*OK') == -1 && ('*' + pairing[0]).indexOf('*Cancel') == -1) {
       hiddenbits+="<input type=hidden name=" + pairing[0] + " value='" + pairing[1] + "'></input>";
      }
    }
  }
  while (xansis != '') {
   xansis=location.search.split('val' + xpnum + '=')[1] ? decodeURIComponent(decodeURIComponent(location.search.split('val' + xpnum + '=')[1].split('&')[0]).replace(/\+/g,' ')) : '';
   if (document.URL.indexOf('val' + xpnum + '=') != -1) {
     hiddenbits+="<input type=hidden name=val" + xpnum + " value='" + encodeURIComponent(xansis) + "'></input>";
     xpnum++;
     xansis='x';
   } else {
     xansis='';
   }
  }
  var durl=(document.URL + "");
  if (document.URL.indexOf('nojwinyes=') != -1) { 
  document.write("<form onsubmit=\" if (document.getElementById('val" + xpnum + "').value.replace('null','') != '') { if (decodeURIComponent(document.getElementById('prompt').value).indexOf(' Regarding ') == 0) {  selecteventtwo(document.getElementById('val" + xpnum + "').value);  } else { selectevent(document.getElementById('val" + xpnum + "').value); } } else if (durl.indexOf('&data=') != -1) { location.href=document.URL; } else { this.style.display='none'; } xpnum++; return false; \" enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70px;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=5 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='....';
  } else {
  document.write("<form enctype='text/plain' style='opacity:0.9;display:none;position:absolute;top:70px;left:2%;z-index:56;width:48%;background-color:rgba(255,165,0,0.8);border:2px solid red;' id=safariform method=GET action=" + document.URL.split('#')[0].split('?')[0] + " readonly>" + hiddenbits + "<textarea style='width:96%;background-color:#eeeeee;' rows=2 id='prompt' readonly='readonly'></textarea><br><input type=hidden value='' name=val" + xpnum + " id=hval" + xpnum + "></input><input onkeypress=\"checkEnter(event);\" onblur=\" document.getElementById('h' + this.id).value=encodeURIComponent(this.value); \" style='width:50%;background-color:yellow;' type=text value='' id=val" + xpnum + "></input>&nbsp;&nbsp;<input style='float:right;width:25%;' type=submit value=OK name=OK id=OK></input>&nbsp;<input style='display:none;' type=submit value=Cancel name=Cancel id=Cancel></input>&nbsp;<input type=button value=Cancel id=bCancel onclick=\" document.getElementById('val" + xpnum + "').value='null'; document.getElementById('hval" + xpnum + "').value=encodeURIComponent('null'); this.style.display='none';  document.getElementById('Cancel').style.display='block'; document.getElementById('Cancel').click(); \"></input>&nbsp;</input></form>"); 
  //document.getElementById('pch1').innerHTML+='..';
  }
  if (document.getElementById('another')) {
    if (document.getElementById('another').href.indexOf('nojwin') == -1) {
     document.getElementById('another').href+='?nojwin=Y';
    }
  }
}

function dub() { 
   if (documentURL.indexOf('&data=') == -1) documentURL=(document.URL + ''); 
   if (documentURL.indexOf('&data=') != -1) { 
   paramdata=(documentURL + '&').split('&data=')[1].split('&')[0]; 
   pardata=encodeURIComponent(paramdata);   
   }  
}

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

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

//setTimeout(onl,1000);
</script>
<div id="thedivemail"></div>
</body>
</html>
