<?php
// media_via_pb.php
// RJM Programming
// December, 2025
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>Image Capture Email - RJM Programming - October, 2018 - Thanks to https://www.w3.org/TR/html-media-capture/</title>
<style>
 * { font-family: Verdana; }
 #hxtml,#bxody { overflow: hidden; }
 summary { width:100%; background-color:#f0f0f0; }
 #topdmenu { background-color:#e0e0e0; }
 hr { height:2px; background-color:orange; }
 details { background-color:#d0d0d0; }
 #topmostmenu { background-color:#c0c0c0; }
 input { background-color:#f0b0d0; }
 textarea { background-color:#f7f7f7; }
 select { background-color:silver; }
</style>
<!--script type='text/javascript' src='/canvas_svg.js?rand=75647654'></script-->
<!--script type='text/javascript' src='/img_svg.js'></script-->
<script type='text/javascript'>
 
var ls_datauri='';
var ls_datauri_name='';
var ls_datauri_cmds=[];

var ls_datauri_select='';

var cemailorig='';

var nicknameprefix='';
var ccoffset=0;
var lasttext='';
var parentblob=null;
var lastdo=null;

var eventstopPropagation=false;
var nonscribbledone=false;
var dotsofar='';
var nothanks=false;
var jijk=1;
var filezerosize=-1;
var filezerobig=false;
var fnames=[""];

var canvasmode=false;

var allowc = false;
var ie = 11;
var mode = 1;
var amode = 1;
//var elem;
//var elemLeft = 0;
var cf = "18px Verdana";
//var elemTop = 0;
//var context;
var elements = [];
var img;
var x=0, y=0, lastx=0, lasty=0;
var clickno = 0;
var ourlat, ourlong;

var xlworld = 'world';
var xuworld = 'World';
var xuubits=document.URL.split('.htm');
var xuuubits=xuubits[0].split('/');
xlworld=xuuubits[eval(-1 + xuuubits.length)];
xuworld=xlworld.substring(0,1).toUpperCase() + xlworld.substring(1);

var retx = 0.0, rety = 0.0;


var q = '';
var twp = '4' + '5%;';
var we600 = 'wid' + 'th="600"';
var fpc = '5' + '0%';
var af = 'qm' + 'yf';
var floating_form = true;   // two modes of use ... if true can make the canvas bigger ... which may affect "var threehundred" below

var threehundred=300;

var topic=''; 
var issuedata=['']; 
var thisissue=''; 
var ofstring=' 1'; 
var iof=1; 

var twothousand=4000;
var ask="y";
var info=" ... ";
var infoemail="fill.in.email@address";
var gptext="";

var ConBubbleColour = "red";
var ProBubbleColour = "green";
var ConBigFontSize = "18px";
var ProBigFontSize = "18px";
var ConNormalFontSize = "14px";
var ProNormalFontSize = "14px";
var ConFontName = "Verdana";
var ProFontName = "Verdana";
var ConNormalFontName = "Verdana";
var ConBigFontName = "Verdana";
var ProNormalFontName = "Verdana";
var ProBigFontName = "Verdana";

var cfb = ProBigFontSize + " " + ProBigFontName;  //"18px Verdana";
var cf = ProNormalFontSize + " " + ProNormalFontName;  //"14px Verdana";

var canvasf=null;

var firsttime=1;

var iscanvas=-1;

var score=3000;
var goes=0;

var wis=400;
var his=400;

//var elemzero;
//var elemLeftzero;
//var elemTopzero;
//var contextzero;

var partx = 0;
var party = 0;

var firstX = -999.0;
var firstY = -999.0;
var secondX = -999.0;
var secondY = -999.0;

var yourfirstX = -999.0;
var yourfirstY = -999.0;
var yoursecondX = -999.0;
var yoursecondY = -999.0;


var elem=null; //= document.getElementById('canvaselement');
var elemLeft=0; //= elem.offsetLeft;
var elemTop=0; //= elem.offsetTop;
var context=null; //= elem.getContext('2d');


var documentURL=document.URL;
var x=0, y=0;
var lasttop=0;
var cdatestr='';
var atop=0;
var awidth=0;
var c=null;
var ctx=null;
var tops=new Array(0);
var img=[];
var cfile=null;
var imgURL=[];
var kk=0;
var cimg=[];
var form=null, formspares=[null], xhrs=[null], newform=null;
var xhr=null, newxhr=null;
var notfirstinsession=0;
var done=false;
var dhuh=null;
var dnhuh=0;
var swir='0';
var nocamera=false;
var firstdetails=null;
var dot='yoUwiLlneVerFiNdtHis';
var dotfile='';
var dotfiles='';

var pbb=' (0 of ' + swir.replace('0','1') + ')';
var pbval=0;
var pbmax=10485760;

var thismediais='image';

var elemtoDataURL='';

var extras=(location.search.split('extras=')[1] ? decodeURIComponent(location.search.split('extras=')[1].split('&')[0]) : '');
var pextras='', qextras='', aia='', was='extras=', ecomma=encodeURIComponent(','), videoplus='?extras=' + encodeURIComponent('video/*'), audioplus='?extras=' + encodeURIComponent('audio/*'), imageplus='?extras=' + encodeURIComponent('image/*'), imageis='extras=' + encodeURIComponent('image/*,'), audiois='extras=' + encodeURIComponent('audio/*,'), videois='extras=' + encodeURIComponent('video/*,');
var xcs, pex='&extras=', qex='?extras=';
if (extras != '') {
 pextras='&extras=' + encodeURIComponent(extras);
 qextras='?extras=' + encodeURIComponent(extras);
} else {
 xcs=decodeURIComponent(cookieVal('imagecapture')).split(',');
 if (xcs.length > 1) {
  if (xcs[1].replace('true','').replace('false','').length > 0) {
    extras=decodeURIComponent(xcs[1].replace('true','').replace('false',''));
    pextras=pex + encodeURIComponent(extras);
    qextras=qex + encodeURIComponent(extras);
  }
 }
}


var selprefix='<select onchange="location.href=document.URL.replace(/image/g,this.value).replace(was,was + ecomma + imageplus.substring(8));"><option value="image">';
var selsuffix='</option><option value="audio">Audio</option><option value="video">Video</option></select>';


if (extras.indexOf("audio") != -1 && extras.indexOf("video") != -1) {
  aia=' and/or Audio and/or Video';
} else if (extras.indexOf("audio") != -1) {
  aia=' and/or Audio and/or <a onclick="location.href=document.URL + ecomma + videoplus.substring(8);" style="text-decoration:underline;cursor:pointer;">Video</a>';
} else if (extras.indexOf("video") != -1) {
  aia=' and/or Video and/or <a onclick="location.href=document.URL + ecomma + audioplus.substring(8);" style="text-decoration:underline;cursor:pointer;">Audio</a>';
} else {
  aia=' and/or <a onclick="location.href=document.URL + audioplus.substring(0,8) + ecomma + audioplus.substring(8);" style="text-decoration:underline;cursor:pointer;">Audio</a> <a onclick="location.href=document.URL + videoplus.substring(0,8) + ecomma + videoplus.substring(8) + ecomma + audioplus.substring(8);;" style="text-decoration:underline;cursor:pointer;">and</a>/or <a onclick="location.href=document.URL + videoplus.substring(0,8) + ecomma + videoplus.substring(8);" style="text-decoration:underline;cursor:pointer;">Video</a>';
}

var ourmimetype='';
var types = ["video/mp4","image/svg","audio/wav","audio/x-wav","audio/x-pn-realaudio","audio/x-mpegurl","audio/x-aiff","audio/mpeg","audio/mid",
      "audio/basic","audio/ogg","video/x-sgi-movie","video/x-msvideo","video/quicktime","audio/mp3","video/mp4","video/mpeg",
      "video/x-la-asf","video/ogg","video/webm","audio/mp4", "image/jpeg", "image/jpeg", "image/png", "image/gif", "image/bmp", "image/tif",
      "text/html", "text/html", "text/html", "text/javascript", "text/css", "text/plain", "text/xml", "text/csv",
      "application/vnd.ms-word", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/x-php", "application/pdf",
      "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-powerpoint",
      "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
var exts = [".mp4",".svg",".wav",".wav",".ram",".m3u",".aiff",".mp3",".rmi",
      ".snd",".ogg",".movie",".avi",".mov",".mp3",".m4v",".mpeg",
      ".lsx",".ogv",".webm",".m4a", ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif",
      ".htm", ".html", ".htmls", ".js", ".css", ".txt", ".xml", ".csv", 
      ".doc", ".docx", ".php", ".pdf",
      ".pptx", ".ppt",
      ".xls", ".xlsx"];

 var kisipn='';

function preread(whatgifmaybe) { // thanks to https://stackoverflow.com/questions/69564118/how-to-get-duration-of-gif-image-in-javascript#:~:text=Mainly%20use%20parseGIF()%20%2C%20then,duration%20of%20a%20GIF%20image.
if ((whatgifmaybe.toLowerCase().trim().split('#')[0] + '?').indexOf('.gif?') != -1) {
fetch(whatgifmaybe)
  .then(res => res.arrayBuffer())
  .then(ab => isGifAnimated(new Uint8Array(ab)))
  .then(console.log);
}
}

/** @param {Uint8Array} uint8 */
function isGifAnimated (uint8) { // thanks to https://stackoverflow.com/questions/69564118/how-to-get-duration-of-gif-image-in-javascript#:~:text=Mainly%20use%20parseGIF()%20%2C%20then,duration%20of%20a%20GIF%20image.
  let duration = 0;
  for (let i = 0, len = uint8.length; i < len; i++) {
    if (uint8[i] == 0x21
      && uint8[i + 1] == 0xF9
      && uint8[i + 2] == 0x04
      && uint8[i + 7] == 0x00) 
    {
      const delay = (uint8[i + 5] << 8) | (uint8[i + 4] & 0xFF);
      duration += delay < 2 ? 10 : delay;
    }
  }
  //alert('' + eval(duration / 100));
  return duration / 100; // if 0.1 is not an animated GIF
}
 
 function dannoit() {
  document.getElementById('dito').innerHTML='<iframe style=display:none; src=/img_maker.php></iframe>';
 }
 
 function getpblob() {
   return parentblob;
 }
 
 function ifbcf(iois) {
   if (iois.src.indexOf('About_Us.htm') == -1) {
   }
 }

 function checkbci() {
   if (document.getElementById('bci').title.indexOf(' ... ') != -1) {
     var pt=document.getElementById('bci').title.split(' ... ')[1];
     document.getElementById('bci').title=document.getElementById('bci').title.split(' ... ')[0];
     alert('Associated barcode points to' + (' ' + pt).replace('HTTPS:','https:').replace('HTTP:','http:').replace(' http',' double clickable http'));
     if (lastdo && pt.toLowerCase().indexOf('http') == 0) {
       lastdo.ondblclick = function() { window.open(pt,'_blank','top=100,left=100,width=800,height=800'); };
     }
   }
   lastdo=null;
 }
 
 function isipn(inf) {
   if (kisipn == '') {
     if (("/" + inf).replace(("\\").substring(0,1) + "image.","/image.").indexOf("/image.") != -1) {
       kisipn="_PuTiPhErE";
       return inf.replace('image.', 'image' + kisipn + '.').split('/')[eval(-1 + inf.replace('image.', 'image' + kisipn + '.').split('/').length)].split("\\".substring(0,1))[eval(-1 + inf.replace('image.', 'image' + kisipn + '.').split('/')[eval(-1 + inf.replace('image.', 'image' + kisipn + '.').split('/').length)].split("\\".substring(0,1)).length)];
     }
   } else {
     return inf.replace('.', kisipn + '.').split('/')[eval(-1 + inf.replace('.', kisipn + '.').split('/').length)].split("\\".substring(0,1))[eval(-1 + inf.replace('.', kisipn + '.').split('/')[eval(-1 + inf.replace('.', kisipn + '.').split('/').length)].split("\\".substring(0,1)).length)];
   }
   return inf.split('/')[eval(-1 + inf.split('/').length)].split("\\".substring(0,1))[eval(-1 + inf.split('/')[eval(-1 + inf.split('/').length)].split("\\".substring(0,1)).length)];;
 }
 
 function jsipn(inf) {
   if (kisipn != '') {
     return inf.replace('.', kisipn + '.').split('/')[eval(-1 + inf.replace('.', kisipn + '.').split('/').length)].split("\\".substring(0,1))[eval(-1 + inf.replace('.', kisipn + '.').split('/')[eval(-1 + inf.replace('.', kisipn + '.').split('/').length)].split("\\".substring(0,1)).length)];
   }
   return inf.split('/')[eval(-1 + inf.split('/').length)].split("\\".substring(0,1))[eval(-1 + inf.split('/')[eval(-1 + inf.split('/').length)].split("\\".substring(0,1)).length)];;
 }


//nicknameprefix="line2"; doline(); nrecord(1); 

function nrecord(notscribble) {
  if (notscribble == 0) {  // start of scribble
  } else if (nicknameprefix.indexOf('scribble') != -1) { // end of scribble
    if (!nonscribbledone) {
     var ecanvas = document.getElementById('canvaselement');
     try {
     canvasf = ecanvas.mozGetAsFile('canvasimage.jpg');
     } catch(eee) {
     //copycanvas();
     //alert('Sorry, but best we could do was copy your canvas ready for you to paste into your own email.');
     }
     ccoffset=canvascommands.length;
    }
  } else { // end of
    nonscribbledone=true;
    if (nicknameprefix.indexOf('(') == -1 && nicknameprefix.indexOf('2') != -1) {
      nicknameprefix=nicknameprefix.replace('2', '(' + lastx + ',' + lasty + ' to ' + x + ',' + y + ')');
    } else if (nicknameprefix.indexOf('(') == -1 && nicknameprefix.indexOf('2') != -1) {
      nicknameprefix=nicknameprefix.replace('1', '(' + x + ',' + y + ' with ' + lasttext + ')');
    }
    if (canvascommands[eval(-1 + canvascommands.length)].indexOf(' // ' + nicknameprefix) == -1) {
      canvascommands[eval(-1 + canvascommands.length)]+=' // ' + nicknameprefix;
    }
  }
}

function detopenmaybe() {
  //document.title='here';
  var ido=document.getElementById('detcanvas');
  if (eventstopPropagation) {
    ido.setAttribute('open','true');
    eventstopPropagation=false;
  }
}

function clientemail(whoto) {
  var cemailhref="";
     copycanvas();
     cemailhref=cemailorig;
     cemailhref=cemailhref.replace(':?', ':' + whoto + '?');
   if (document.getElementById('cc').value.indexOf('@') != -1) {
     cemailhref=cemailhref.replace('&cc=', '&cc=' + encodeURIComponent(document.getElementById('cc').value));
   }
   if (document.getElementById('bcc').value.indexOf('@') != -1) {
     cemailhref=cemailhref.replace('&bcc=', '&bcc=' + encodeURIComponent(document.getElementById('bcc').value));
   }
   if (document.getElementById('body').value != '') {
     cemailhref=cemailhref.replace('&body=', '&body=' + encodeURIComponent(document.getElementById('body').value));
   }
   if (document.getElementById('subject').value != '') {
     cemailhref=cemailhref.replace('?subject=', '?subject=' + encodeURIComponent(document.getElementById('subject').value));
   } else {
     cemailhref=cemailhref.replace('?subject=', '?subject=' + encodeURIComponent('Canvas Image in email'));
   }
     document.getElementById('cemail').href=cemailhref;
       document.getElementById('cemail').click();
}
    
function email() {
  var cemailhref="";
  var whoto=document.getElementById('to').value;
  if (whoto.indexOf('@') == -1) {
  whoto=prompt('Email To? (answer with space to open email client where in body section you can paste the canvas contents)','');
  if (whoto == null) { whoto=''; }
  //if (whoto.indexOf('@') != -1) {  document.getElementById('to').value=whoto;  }
  }
  if (whoto.indexOf('@') == -1) {
     whoto='';
     clientemail(whoto);
  } else if (whoto.indexOf('@') != -1) {
  var ecanvas = document.getElementById('canvaselement');
     try {
     canvasf = ecanvas.mozGetAsFile('canvasimage.png');
     form = new FormData();
     xhr = new XMLHttpRequest();   
     var ereader = new FileReader();
  ereader.readAsDataURL(canvasf);
      
  ereader.onloadend = function() {
    
   form.append('to', whoto);
   if (document.getElementById('cc').value.indexOf('@') != -1) {
   form.append('cc', document.getElementById('cc').value);
   }
   if (document.getElementById('bcc').value.indexOf('@') != -1) {
   form.append('bcc', document.getElementById('bcc').value);
   }
   if (document.getElementById('body').value != '') {
   form.append('body', document.getElementById('body').value);
   }
   if (document.getElementById('subject').value != '') {
    form.append('subject', document.getElementById('subject').value);
   } else {
    form.append('subject', 'Canvas Image in email');
   }
   form.append('filename', isipn('canvasimage.png'));
   form.append('image', canvasf);
  pbval+=canvasf.size;
  if (pbval > pbmax) { pbmax=pbval; document.getElementById('sbig').innerHTML='' + eval(pbmax / 1048576.0) + 'mB' + pbb; document.getElementById('pb').max='' + pbmax; document.getElementById('pb').style.borderRight='5px inset red';  } else {  document.getElementById('pb').style.borderRight='0px inset red';  document.getElementById('sbig').innerHTML='10mB' + pbb; } 
  document.getElementById('pb').value='' + pbval;
  document.getElementById('pb').title='' + eval(pbval / 1048576.0) + 'mB';
   if (document.getElementById('zipname').value != '') {
    form.append('zipname', jsipn(document.getElementById('zipname').value));
   } else {
    form.append('zipname', jsipn('canvasimage.png'));
   }
   form.append('preksh', toccbcc());
   xhr.open('post', 'mailto.php', true);
   xhr.setRequestHeader('Cache-Control', 'no-cache');
   xhr.send(form);

  if (1 == 1) {
  if (document.getElementById('myh3').innerHTML.indexOf('Emailed to ') != -1) {
  document.getElementById('myh3').innerHTML=document.getElementById('myh3').innerHTML.split('Emailed to ')[0] + 'Emailed to ' + whoto + ' (' + document.getElementById('pb').title + ' <a style=text-decoration:underline;cursor:pointer; onclick="clientemail(' + "'" + whoto + "'" + ');" title="Use client email instead of PHP mail where canvas content can be Pasted into email body section">in a canvas image</a> media file)';
  } else {
  document.getElementById('myh3').innerHTML+='<br>Emailed to ' + whoto + ' (' + document.getElementById('pb').title + ' <a style=text-decoration:underline;cursor:pointer; onclick="clientemail(' + "'" + whoto + "'" + ');" title="Use client email instead of PHP mail where canvas content can be Pasted into email body section">in a canvas image</a> media file)';
  }
  } else {
  alert('Emailed to ' + whoto + ' (' + document.getElementById('pb').title + ' in a canvas image media file)');
  }

  };
     } catch(eee) {
     var huhe=confirm('Sorry, but best we could do was copy your canvas ready for you to paste into your own email, that will open if you click OK button.');
     if (huhe) {
       clientemail(whoto);
     }
     }
  }
}

function toccbcc() {
  var pk="";
  if (document.getElementById('to').value.indexOf('@') != -1) {
  pk=".";
  pk+=document.getElementById('to').value.replace(/\@/g,'--a--');
  if (document.getElementById('cc').value.indexOf('@') != -1) {
  pk+='--cc--' + document.getElementById('cc').value.replace(/\@/g,'--a--');
  }
  if (document.getElementById('bcc').value.indexOf('@') != -1) {
  pk+='--bcc--' + document.getElementById('bcc').value.replace(/\@/g,'--a--');
  }
  }
  return pk;
}

function getccbccbody(inch) {
  if (inch.indexOf('||') != -1) {
     if (inch.indexOf('||||') != -1) {
       document.getElementById('body').value=decodeURIComponent(inch.split('||||')[1]);
       inch=inch.split('||||')[0];
     }
     if (inch.indexOf('|||') != -1) {
       document.getElementById('bcc').value=inch.split('|||')[1].replace(/\|/g,',');
       inch=inch.split('|||')[0];
     }
     if (inch.indexOf('||') != -1) {
       document.getElementById('cc').value=inch.split('||')[1].replace(/\|/g,',');
       inch=inch.split('||')[0];
     }
     if (document.getElementById('detemail')) {
       document.getElementById('detemail').setAttribute('open', 'true');
     }
     return inch;
  } else {
     return inch;
  }
}

function setCookie(thisg) { // thanks to JavaScript and Ajax by Tom Negrino and Dori Smith
   var tn="", qsprefix="?", qs="";
   var expireDate = new Date();
   var cc_bcc_body="";
   if (document.getElementById('cc').value.indexOf('@') != -1) {
     cc_bcc_body+='||' + document.getElementById('cc').value.replace(/\,/g,'|');
   }
   if (document.getElementById('bcc').value.indexOf('@') != -1) {
     cc_bcc_body+='|||' + document.getElementById('bcc').value.replace(/\,/g,'|');
   }
   if (document.getElementById('body').value != '') {
     cc_bcc_body+='||||' + encodeURIComponent(document.getElementById('body').value);
   }

   if (document.getElementById('zipname').value.indexOf(expireDate.getFullYear() + ("0" + eval(1 + expireDate.getMonth())).slice(-2) + ("0" + expireDate.getDate()).slice(-2)) != -1) {
    if (document.getElementById('nocamera').checked) {
     tn=document.getElementById('to').value.replace(/\,/g,'|') + cc_bcc_body + ',true' + encodeURIComponent(extras) + ',' + document.getElementById('zipname').value.replace(expireDate.getFullYear() + ("0" + eval(1 + expireDate.getMonth())).slice(-2) + ("0" + expireDate.getDate()).slice(-2),"yyyymmdd") + ',' + document.getElementById('swir').value + ',' + document.getElementById('subject').value;
     qs+=qsprefix + "to=" + encodeURIComponent(document.getElementById('to').value); // tn);
     qsprefix="&";
    } else {
     tn=document.getElementById('to').value.replace(/\,/g,'|') + cc_bcc_body + ',false' + encodeURIComponent(extras) + ',' + document.getElementById('zipname').value.replace(expireDate.getFullYear() + ("0" + eval(1 + expireDate.getMonth())).slice(-2) + ("0" + expireDate.getDate()).slice(-2),"yyyymmdd") + ',' + document.getElementById('swir').value + ',' + document.getElementById('subject').value;
     qs+=qsprefix + "to=" + encodeURIComponent(document.getElementById('to').value); // tn);
     qsprefix="&";
    }
   } else {
    if (document.getElementById('nocamera').checked) {
     tn=document.getElementById('to').value.replace(/\,/g,'|') + cc_bcc_body + ',true' + encodeURIComponent(extras) + ',' + document.getElementById('zipname').value + ',' + document.getElementById('swir').value + ',' + document.getElementById('subject').value;
     qs+=qsprefix + "to=" + encodeURIComponent(document.getElementById('to').value); // tn);
     qsprefix="&";
    } else {
     tn=document.getElementById('to').value.replace(/\,/g,'|') + cc_bcc_body + ',false' + encodeURIComponent(extras) + ',' + document.getElementById('zipname').value + ',' + document.getElementById('swir').value + ',' + document.getElementById('subject').value;
     qs+=qsprefix + "to=" + encodeURIComponent(document.getElementById('to').value); // tn);
     qsprefix="&";
    }
   }
   expireDate.setMonth(expireDate.getMonth()+6);
   document.cookie = thisg + "=" + encodeURIComponent(tn) + ";expires=" + expireDate.toGMTString();
   
   if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) { 
    if (!cfile && qs != '' && documentURL.indexOf('to=') == -1) {   

     qs+=qsprefix + "cc=" + encodeURIComponent(document.getElementById('cc').value); // tn);
     qsprefix="&";
     qs+=qsprefix + "bcc=" + encodeURIComponent(document.getElementById('bcc').value); // tn);
     qsprefix="&";
     qs+=qsprefix + "body=" + encodeURIComponent(document.getElementById('body').value); // tn);
     qsprefix="&";
     qs+=qsprefix + "subject=" + encodeURIComponent(document.getElementById('subject').value); // tn);
     qsprefix="&";
     qs+=qsprefix + "swir=" + encodeURIComponent(document.getElementById('swir').value); // tn);
     qsprefix="&";
     qs+=qsprefix + "zipname=" + encodeURIComponent(document.getElementById('zipname').value.replace(expireDate.getFullYear() + ("0" + eval(1 + expireDate.getMonth())).slice(-2) + ("0" + expireDate.getDate()).slice(-2),"yyyymmdd")); // tn);
     qsprefix="&";
     if (document.getElementById('nocamera').checked) {
     qs+=qsprefix + "nocamera=" + encodeURIComponent('true'); // tn);
     } else {
     qs+=qsprefix + "nocamera=" + encodeURIComponent('false'); // tn);
     }
     qsprefix="&";
     if (forever && 1 == 2) {
     qs+=qsprefix + "forever=" + encodeURIComponent('y'); // tn);
     qsprefix="&";
     }
     
     if ((document.URL.split('#')[0].split('?')[0] + qs).length < 900) {
       location.href=document.URL.split('#')[0].split('?')[0] + qs;
     }

    }
   }
}

function superex(mn) {
 if (document.URL.indexOf('?to=') != -1) {
   return mn + '&' + document.URL.split('?')[1].replace('nocamera=','noXcamera=');
 } else if (document.URL.indexOf('?to=') != -1 && mn == '') {
   return mn + '?' + document.URL.split('?')[1].replace('nocamera=','noXcamera=');
 } else {
   return mn;
 }
}

function dells(tv) {
 var jik=0, huhis='', imgl=null;
 if (tv == 'reshow') {
      imgl = new Image();

      imgl.onload = function() {
        var iik=0, jjk=0, cmds=[];
        elem.width = this.width;
        elem.height = this.height;
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
         cmds=ls_datauri_cmds[iik].split(';');
         for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
         }
        }
      };

      imgl.src = ls_datauri;      
 } else if (tv == 'edit') {
      imgl = new Image();

      imgl.onload = function() {
        var iik=0, jjk=0, cmds=[], huhis='';
        elem.width = this.width;
        elem.height = this.height;
        context.clearRect(0,0,elem.width,elem.height);
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
        huhis=prompt('Optionally change away for ' + document.getElementById('optsel' + eval(1 + iik)).title, ls_datauri_cmds[iik]);
        if (huhis != null) {
          cmds=huhis.split(';');
        } else {
          cmds=ls_datauri_cmds[iik].split(';');
        }
        for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
        }
        }
      };

      imgl.src = ls_datauri;  
      
  } else if (tv == 'editthese') {
      imgl = new Image();

      imgl.onload = function() {
        var ois=document.getElementById('lssel');
        var i=0, iik=0, jjk=0, cmds=[], huhis='';
        elem.width = this.width;
        elem.height = this.height;
        context.clearRect(0,0,elem.width,elem.height);
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
        if (ois.options[eval(1 + iik)].selected) {
        huhis=prompt('Optionally change away for ' + document.getElementById('optsel' + eval(1 + iik)).title, ls_datauri_cmds[iik]);
        } else {
        huhis=ls_datauri_cmds[iik];
        }
        if (huhis != null) {
          cmds=huhis.split(';');
        } else {
          cmds=ls_datauri_cmds[iik].split(';');
        }
        for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
        }
        }
      };

      imgl.src = ls_datauri;  
      
  } else if (tv == 'editothers') {
      imgl = new Image();

      imgl.onload = function() {
        var ois=document.getElementById('lssel');
        var i=0, iik=0, jjk=0, cmds=[], huhis='';
        elem.width = this.width;
        elem.height = this.height;
        context.clearRect(0,0,elem.width,elem.height);
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
        if (ois.options[eval(1 + iik)].selected) {
        huhis=ls_datauri_cmds[iik];
        } else {
        huhis=prompt('Optionally change away for ' + document.getElementById('optsel' + eval(1 + iik)).title, ls_datauri_cmds[iik]);
        }
        if (huhis != null) {
          cmds=huhis.split(';');
        } else {
          cmds=ls_datauri_cmds[iik].split(';');
        }
        for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
        }
        }
      };

      imgl.src = ls_datauri;  
      
  } else if (tv == 'onlyshowthese') {  // value=editthese value=editothers value=onlyshowthese value=onlyshowothers
      imgl = new Image();

      imgl.onload = function() {
        var ois=document.getElementById('lssel');
        var i=0, iik=0, jjk=0, cmds=[], huhis=' ';
        elem.width = this.width;
        elem.height = this.height;
        context.clearRect(0,0,elem.width,elem.height);
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
        if (ois.options[eval(1 + iik)].selected) {
        huhis=ls_datauri_cmds[iik];
        } else {
        huhis='';
        }
        if (huhis != null) {
          cmds=huhis.split(';');
        } else {
          cmds=ls_datauri_cmds[iik].split(';');
        }
        if (huhis != '') {
        for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
        }
        }
        }
      };

      imgl.src = ls_datauri;  
      
      
  } else if (tv == 'onlyshowothers') {
      imgl = new Image();

      imgl.onload = function() {
        var ois=document.getElementById('lssel');
        var i=0, iik=0, jjk=0, cmds=[], huhis=' ';
        elem.width = this.width;
        elem.height = this.height;
        context.clearRect(0,0,elem.width,elem.height);
        context.drawImage(imgl, 0, 0);
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
        if (ois.options[eval(1 + iik)].selected) {
        huhis='';
        } else {
        huhis=ls_datauri_cmds[iik];
        }
        if (huhis != null) {
          cmds=huhis.split(';');
        } else {
          cmds=ls_datauri_cmds[iik].split(';');
        }
        if (huhis != '') {
        for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
        }
        }
        }
      };

      imgl.src = ls_datauri;  

           
          
 } else {
      localStorage.removeItem("imagecapture");
      localStorage.removeItem("imagecapture_name");
      localStorage.removeItem("imagecapture_cmds");
 }
}

function huhhuh(fg) {
  var ofg=fg;
  if (fg.indexOf('context.strokeText(') != -1 && fg.indexOf('context.strokeText("') == -1 && fg.indexOf("context.strokeText('") == -1) {
   lasttext=fg.split('ntext.strokeText(')[1].split(',')[0];
   return fg.split('ntext.strokeText(')[0] + "ntext.strokeText(\"" + fg.split('ntext.strokeText(')[1].split(',')[0] + "\"" + fg.replace(fg.split(',')[0],'');
  } else if (fg.indexOf('context.strokeText("') != -1) {
   lasttext=fg.split('ntext.strokeText("')[1].split('"')[0];
  } else if (fg.indexOf("context.strokeText('") != -1) {
   lasttext=fg.split("ntext.strokeText('")[1].split("'")[0];
  }
  return ofg;
}

function convertoBase64Image(img) { // thanks to https://stackoverflow.com/questions/24972617/using-localstorage-base64-image-in-chrome-content-script

  // Create an empty canvas element
  var canvas = document.createElement("canvas");
  canvas.width = img.width;
  canvas.height = img.height;

  // Copy the image contents to the canvas
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img, 0, 0);

  // Get the data-URL formatted image
  // Firefox supports PNG and JPEG. You could check img.src to guess the
  // original format, but be aware the using "image/jpg" will re-encode the image.
  var dataURL = canvas.toDataURL("image/png");
  return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}

function lsset() {
  var cfn='';
  if (elemtoDataURL == '') {
       elemtoDataURL=elem.toDataURL('image/jpeg',0.5).replace(";base64,",";charset=utf-8;base64,").replace(/^daXta:image\/(png|jpg|jpeg);base64,/, "");
  }
  if (cfile == null) {
    cfn='canvasimage.jpg';
  } else {
    cfn=cfile[0]``.name``;
  }
  try {
  localStorage.setItem("imagecapture", elemtoDataURL); //elem.toDataURL());
  } catch(eee) {
  alert('Not stored');
  }
  //alert(elemtoDataURL);
  localStorage.setItem("imagecapture_name", encodeURIComponent(cfn));
  var ccc="";
  for (var icc=0; icc<canvascommands.length; icc++) {
   if (canvascommands[icc].length > 5) {
    if (canvascommands[icc].indexOf('//') != -1) {
     ccc+=huhhuh(canvascommands[icc].replace(String.fromCharCode(10),' ')) + ' ' + String.fromCharCode(10);
    } else {
     ccc+=huhhuh(canvascommands[icc].replace(String.fromCharCode(10),' ')) + ' ';
    }
   }
  }
  localStorage.setItem("imagecapture_cmds", encodeURIComponent(ccc));
  //alert(ccc);
}

function specialdecodeURIComponent(instrg) {
      var stringit=[" context.strokeStyle", " context.beginPath", " context.moveTo", " context.lineTo"];
      var rval=decodeURIComponent(instrg);
      var rvals=rval.split(';');
      var ik=0, jk=0;
      for (ik=0; ik<rvals.length; ik++) {
        for (jk=0; jk<stringit.length; jk++) {
          if (rvals[ik].indexOf(stringit[jk].trim()) != -1) {
            rval=rval.replace((rvals[ik] + ";"), (rvals[ik] + ";").replace(");", ") ;").replace("';", "' ;")).replace(String.fromCharCode(10),' ');
          }
        }
      }
      return rval;
}

function precookieVal() {
  return cookieVal("imagecapture");
}

function cookieVal(cName) {
   if (localStorage) {
    if (localStorage.getItem("imagecapture")) {
      ls_datauri_name=decodeURIComponent(localStorage.getItem("imagecapture_name"));
      ls_datauri_select="<select onclick='eventstopPropagation=true;' size=1 id=lssel multiple><option id=optsel0 value=>" + ls_datauri_name + "</option></select>"
      var c_ls_datauri_cmds=decodeURIComponent(localStorage.getItem("imagecapture_cmds"));
      //alert(c_ls_datauri_cmds);
      var c_ls=1, nickname='';
      var cc_ls_datauri_cmds=c_ls_datauri_cmds.split(String.fromCharCode(10));
      for (var ik=0; ik<cc_ls_datauri_cmds.length; ik++) {
       nickname='';
       if ((' ' + cc_ls_datauri_cmds[ik]).split(' // ').length > 1) {
           nickname=(' ' + cc_ls_datauri_cmds[ik]).split(' // ')[1];
           cc_ls_datauri_cmds[ik]=cc_ls_datauri_cmds[ik].replace('// ' + nickname,'');
       } else {
           nickname=cc_ls_datauri_cmds[ik].replace(/\)\ \;/g,');').replace(/\'\ \;/g,"';");
       }
       if (eval('' + cc_ls_datauri_cmds[ik].length) > 5) { // && cc_ls_datauri_cmds[ik].replace(String.fromCharCode(10),'').replace(/\)/g,'').replace(/\;/g,'').trim() != '') {
        ls_datauri_cmds.push(cc_ls_datauri_cmds[ik]); // + ');');
        ls_datauri_select=ls_datauri_select.replace("</select>", "<option id=optsel" + c_ls + " title='" + nickname + "' value='" + cc_ls_datauri_cmds[ik].replace(/\)\ \;/g,');').replace(/\'\ \;/g,"';") + "'>" + nickname + "</option></select>");
        ls_datauri_select=ls_datauri_select.replace(' size=' + c_ls, ' size=' + eval(eval('' + 1) + eval('' + c_ls)));
        c_ls++;
       }
      }
      ls_datauri=localStorage.getItem("imagecapture");
      var imgl = new Image();

      imgl.onload = function() {
        //alert(this.width);
        var iik=0, jjk=0, cmds=[];
        elem = document.getElementById('canvaselement');
        context = elem.getContext("2d");
        elem.width = this.width;
        elem.height = this.height;
        //alert(1);
        if (document.getElementById('detcanvas')) {
          document.getElementById('detcanvas').setAttribute('open', 'true');
        }
        context.drawImage(imgl, 0, 0);
        if (1 == 1) {
        //alert(2);
        //if (document.getElementById('detcanvas')) {
        //  document.getElementById('detcanvas').setAttribute('open', 'true');
        //}
        document.getElementById('sumcanvas').innerHTML=document.getElementById('sumcanvas').innerHTML.replace(' below ...', ' ... last saved ' + ls_datauri_select + ' <select onclick="eventstopPropagation=true;" onchange=dells(this.value);><option value=>below</option><option value=deleted>deleted</option><option value=reshow>reshow all</option><option value=edit>reshow edit all</option><option value=editthese>edit selections</option><option value=editothers>edit non selections</option><option value=onlyshowthese>only show selections</option><option value=onlyshowothers>only show non selections</option></select> ...');
        for (iik=0; iik<ls_datauri_cmds.length; iik++) {
         cmds=ls_datauri_cmds[iik].split(';');
         for (jjk=0; jjk<cmds.length; jjk++) {
          eval(cmds[jjk]);
          if (typeof canvascommands === 'undefined') {
          jjk=jjk;
          } else {
          canvascommands.push((cmds[jjk] + ';').replace(';;',';'));
          }
         }
        }
        }
      };

      imgl.src = ls_datauri;      
    }
   }
   var tCookie=document.cookie.split("; ");
  
   for (var j=0; j<tCookie.length; j++) {
    if (cName == tCookie[j].split("=")[0]) {
      return decodeURIComponent(tCookie[j].split("=")[1]);
    }
   }
   return '';
}

function deleteAllCookies(cName) {
 var expireDate = new Date();
 expireDate.setDate(expireDate.getDate()-1);
 if (document.cookie != '') {
   var tCookie=document.cookie.split("; ");
  
   for (var j=0; j<tCookie.length; j++) {
    if (cName == tCookie[j].split("=")[0]) {
     document.cookie = goodname + "=;expires=" + expireDate.toGMTString();
    }
   }
 }
}

function bp() {
   var exDate = new Date();
   var exstr=exDate.getFullYear() + ("0" + eval(1 + exDate.getMonth())).slice(-2) + ("0" + exDate.getDate()).slice(-2);

var to=location.search.split('to=')[1] ? decodeURIComponent(location.search.split('to=')[1].split('&')[0]) : '';
var cc=location.search.split('cc=')[1] ? decodeURIComponent(location.search.split('cc=')[1].split('&')[0]) : '';
var bcc=location.search.split('bcc=')[1] ? decodeURIComponent(location.search.split('bcc=')[1].split('&')[0]) : '';
var body=location.search.split('body=')[1] ? decodeURIComponent(location.search.split('body=')[1].split('&')[0]) : '';
var subject=location.search.split('subject=')[1] ? decodeURIComponent(location.search.split('subject=')[1].split('&')[0]) : '';
var zipname=location.search.split('zipname=')[1] ? decodeURIComponent(location.search.split('zipname=')[1].split('&')[0]).replace('yyyymmdd', exstr) : '';
swir=location.search.split('swir=')[1] ? location.search.split('swir=')[1].split('&')[0] : '0';
var forever=location.search.split('forever=')[1] ? true : false;
var prenocamera=location.search.split('nocamera=')[1] ? decodeURIComponent(location.search.split('nocamera=')[1].split('&')[0]) : ' ';
if (prenocamera != ' ' && prenocamera != extras) {
  if (prenocamera != 'false') { nocamera=true; }
}
//nocamera=location.search.split('nocamera=')[1] ? true : false;
var cval=cookieVal('imagecapture');
//if (document.URL.indexOf('xxx=') != -1) {  alert(decodeURIComponent(cval).split(',')[1] + ' ... ' + cval);  }

pbb=' (0 of ' + swir.replace('0','1') + ')';

dhuh=document.getElementById('adhuh'); //document.body;
if (dhuh == null) { dhuh=document.body; }

if (to == '' && subject == '' && zipname == '' && forever) {
  deleteAllCookies('imagecapture');
} else if (cval == '') {
  document.getElementById('to').value=to;
  document.getElementById('cc').value=cc;
  document.getElementById('bcc').value=bcc;
  document.getElementById('body').value=body;
  document.getElementById('subject').value=subject;
  document.getElementById('zipname').value=zipname;
  if (nocamera) {  document.getElementById('nocamera').checked=true; }
  if (forever) { setCookie('imagecapture'); } 
} else {
  var cs=decodeURIComponent(cval).split(',');
  if (cs.length > 4) {
   if (cs[0] != '') { document.getElementById('to').value=getccbccbody(cs[0]).replace(/\|/g,','); } else { document.getElementById('to').value=getccbccbody(to).replace(/\|/g,',');  }
   if (cs[1].substring(0,4) == 'true') { if (extras == '' && cs[1].length > 4) { extras=decodeURiComponent(cs[1].substring(4)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   } nocamera=true; document.getElementById('nocamera').checked=nocamera; } else if (cs[1].substring(0,4) == 'fals') { if (extras == '' && cs[1].length > 5) { extras=decodeURiComponent(cs[1].substring(5)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   }   nocamera=false; document.getElementById('nocamera').checked=nocamera; } else { document.getElementById('nocamera').checked=nocamera;  }
   if (cs[2] != '') { document.getElementById('zipname').value=cs[2].replace('yyyymmdd', exstr); } else { document.getElementById('zipname').value=zipname;  }
   if (cs[3] != '') { document.getElementById('swir').value=cs[3]; swir=cs[3]; } else { document.getElementById('swir').value='' + swir;  }
   if (cs[4] != '') { document.getElementById('subject').value=decodeURIComponent(cval).replace(cs[0] + ',' + cs[1] + ',' + cs[2] + ',' + cs[3] + ',',''); } else { document.getElementById('subject').value=subject;  }
  } else if (cs.length > 3) {
   if (cs[0] != '') { document.getElementById('to').value=getccbccbody(cs[0]).replace(/\|/g,','); } else { document.getElementById('to').value=getccbccbody(to).replace(/\|/g,',');  }
   if (cs[1].substring(0,4) == 'true') {  if (extras == '' && cs[1].length > 4) { extras=decodeURiComponent(cs[1].substring(4)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   } nocamera=true; document.getElementById('nocamera').checked=nocamera; } else if (cs[1].substring(0,4) == 'fals') { if (extras == '' && cs[1].length > 5) { extras=decodeURiComponent(cs[1].substring(5)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   }   nocamera=false; document.getElementById('nocamera').checked=nocamera; } else { document.getElementById('nocamera').checked=nocamera;  }
   if (cs[2] != '') { document.getElementById('zipname').value=cs[2].replace('yyyymmdd', exstr); } else { document.getElementById('zipname').value=zipname;  }
   if (cs[3] != '') { document.getElementById('swir').value=cs[3]; swir=cs[3]; } else { document.getElementById('swir').value='' + swir;  }
   document.getElementById('subject').value=subject;
  } else if (cs.length > 2) {
   if (cs[0] != '') { document.getElementById('to').value=getccbccbody(cs[0]).replace(/\|/g,','); } else { document.getElementById('to').value=getccbccbody(to).replace(/\|/g,',');  }
   if (cs[1].substring(0,4) == 'true') {  if (extras == '' && cs[1].length > 4) { extras=decodeURiComponent(cs[1].substring(4)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   } nocamera=true; document.getElementById('nocamera').checked=nocamera; } else if (cs[1].substring(0,4) == 'fals') { if (extras == '' && cs[1].length > 5) { extras=decodeURiComponent(cs[1].substring(5)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   }   nocamera=false; document.getElementById('nocamera').checked=nocamera; } else { document.getElementById('nocamera').checked=nocamera;  }
   if (cs[2] != '') { document.getElementById('zipname').value=cs[2].replace('yyyymmdd', exstr); } else { document.getElementById('zipname').value=zipname;  }
   document.getElementById('swir').value=swir;
   document.getElementById('subject').value=subject;
  } else if (cs.length > 1) {
   if (cs[0] != '') { document.getElementById('to').value=getccbccbody(cs[0]).replace(/\|/g,','); } else { document.getElementById('to').value=getccbccbody(to).replace(/\|/g,',');  }
   if (cs[1].substring(0,4) == 'true') {  if (extras == '' && cs[1].length > 4) { extras=decodeURiComponent(cs[1].substring(4)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   } nocamera=true; document.getElementById('nocamera').checked=nocamera; } else if (cs[1].substring(0,4) == 'fals') { if (extras == '' && cs[1].length > 5) { extras=decodeURiComponent(cs[1].substring(5)); pextras=pex + encodeURIComponent(extras); qextras=qex + encodeURIComponent(extras);   }  nocamera=false; document.getElementById('nocamera').checked=nocamera; } else { document.getElementById('nocamera').checked=nocamera;  }
   document.getElementById('zipname').value=zipname;
   document.getElementById('swir').value=swir;
   document.getElementById('subject').value=subject;
  } else {
   if (cs[0] != '') { document.getElementById('to').value=getccbccbody(cs[0]).replace(/\|/g,','); } else { document.getElementById('to').value=getccbccbody(to).replace(/\|/g,',');  }
   document.getElementById('nocamera').checked=nocamera;
   document.getElementById('zipname').value=zipname;
   document.getElementById('swir').value=swir;
   document.getElementById('subject').value=subject;
  }
  if (forever) { setCookie('imagecapture'); } 
}
if (document.getElementById('zipname').value != '') {  document.getElementById('zipname').style.display='inline-block';   }

nocamera=location.search.split('nocamera=')[1] ? true : false;
try {
if (nocamera) { document.getElementById('cimage').removeAttribute('capture'); }
} catch(ee) {
}
if (nocamera) {  document.getElementById('nocamera').checked=true; }

var input = document.getElementById('cimage'); // .querySelector('input[type=file]'); // .getElementById('cimage'); // see Example 4
var mampca="<?php if (PHP_OS == 'Darwin') { echo 'http://localhost:8888/media_via_pb.php?mvp=';  } ?>";
mampca=(('' + navigator.platform).toLowerCase().substring(0,3).replace('win','mac') == 'mac' ? "<?php echo 'http://localhost' . $ifport . '/media_via_pb.php?' . $premvp . 'mvp=='; ?>" : "");

input.onchange = function () {
  var file = input.files; //[0];
  var dem='=';
  mampca=mampca.split('==')[0];
  cfile = file;
  
  done=false;
  for (var ii=0; ii<file.length; ii++) {
  pbval+=file[ii].size;
  if (pbval > pbmax) { pbmax=pbval; document.getElementById('sbig').innerHTML='' + eval(pbmax / 1048576.0) + 'mB' + pbb; document.getElementById('pb').max='' + pbmax; document.getElementById('pb').style.borderRight='5px inset red';  } else {  document.getElementById('pb').style.borderRight='0px inset red';  document.getElementById('sbig').innerHTML='10mB' + pbb; } 
  document.getElementById('pb').value='' + pbval;
  document.getElementById('pb').title='' + eval(pbval / 1048576.0) + 'mB';
  //if (ii == 0) { pref(file[0]); }
  
  if (kk == 0) {
    fnames=[""];
    fnames[0]=file[ii].name;
    if (mampca != '') { mampca+=dem + encodeURIComponent(file[ii].name + '##' + file[ii].size);  dem=encodeURIComponent(',');  } 
  } else if (ii >= fnames.length) {
    fnames.push(file[ii].name);
    if (mampca != '') { mampca+=dem + encodeURIComponent(file[ii].name + '##' + file[ii].size);  dem=encodeURIComponent(',');  } 
  } else {
    fnames[ii]=file[ii].name;
    if (mampca != '') { mampca+=dem + encodeURIComponent(file[ii].name + '##' + file[ii].size);  dem=encodeURIComponent(',');  } 
  }
  
  
 ourmimetype="";
 for (var ji=0; ji<exts.length; ji++) {
      if (("." + file[ii].name.split('.')[eval(-1 + file[ii].name.split('.').length)]).toLowerCase() == exts[ji].toLowerCase()) {
        ourmimetype=types[ji];
      }
 }

  if (ii == 0) { displayAsImage(file);  } // see Example 7
  if (ii == 0) { done=upload(file); }
  if (eval(1 + eval('' + ii)) == file.length) { if (ourmimetype == '' || ourmimetype.indexOf('image') != -1) { whenokdrawOnCanvas(); }  }  // see Example 6
//  if (eval(1 + eval('' + ii)) == file.length) {  done=upload(file);   }  // see Example 6
  }
  //if (done) { done=false; notfirstinsession=0; }
  
  if (mampca != '' && mampca != (mampca.split('==')[0] + '=')) {  if (document.getElementById('to').value != '' || '<?php echo $ifmamp; ?>' == '<?php echo strtoupper($ifmamp); ?>') { mampca=mampca.replace('?','?mailto=' + encodeURIComponent(document.getElementById('to').value) + (document.getElementById('subject').value != '' ? '&subject=' + encodeURIComponent(document.getElementById('subject').value) : '') + '&');  if ('<?php echo $ifmamp; ?>' == '<?php echo strtoupper($ifmamp); ?>') {  window.open(mampca, '<?php echo strtolower($ifmamp); ?>', 'top=50,left=50,width=600,height=600');  } else { document.getElementById('ifmamp').src=mampca; } } else {  window.open(mampca, '<?php echo $ifmamp; ?>', 'top=50,left=50,width=600,height=600'); } }
  mampca=(('' + navigator.platform).toLowerCase().substring(0,3).replace('win','mac') == 'mac' ? "<?php echo 'http://localhost' . $ifport . '/media_via_pb.php?' . $premvp . 'mvp=='; ?>" : "");
  if (document.getElementById('to').value != '' && mampca != '' &&  '<?php echo $ifmamp; ?>' == '<?php echo strtoupper($ifmamp); ?>') { document.getElementById('bemail').href=document.getElementById('bemail').href.replace(':?',':' + encodeURIComponent(document.getElementById('to').value) + '?cc=' + encodeURIComponent(document.getElementById('to').value) + '&bcc=' + encodeURIComponent(document.getElementById('to').value) + '&');  document.getElementById('bemail').click();    }
};

var cdate = new Date();
cdatestr=cdate.getFullYear() + ("0" + eval(1 + cdate.getMonth())).slice(-2) + ("0" + cdate.getDate()).slice(-2);
document.getElementById('zipname').placeholder+=' ... imagezip_' + cdatestr + '.zip';
}

function swirit() {
 document.getElementById('swir').value='' + swir;
}

function goagain(file) {
 if (file) {
  notfirstinsession=0;
  kk=0;
  //pbval=0;
  //pbmax=10485760;
  done=false;
  for (var ii=0; ii<file.length; ii++) {
  //pbval+=file[ii].size;
  //if (pbval > pbmax) { pbmax=pbval; document.getElementById('sbig').innerHTML='' + eval(pbmax / 1048576.0) + 'mB'; document.getElementById('pb').max='' + pbmax; document.getElementById('pb').style.borderRight='5px inset red';  } else {  document.getElementById('pb').style.borderRight='0px inset red';  document.getElementById('sbig').innerHTML='10mB'; } 
  //document.getElementById('pb').value='' + pbval;
  //document.getElementById('pb').title='' + eval(pbval / 1048576.0) + 'mB';
  //if (ii == 0) { displayAsAudio(file); } // see Example 7
  if (ii == 0) { done=upload(file); }
  }
 }
}


function upload(file) {
  dotsofar='';
  //var dot='yoUwiLlneVerFiNdtHis', dotfile='', dotfiles='';
  //formspares=[null];
  //xhrs=[null];
  var ioff=0;
  if (!form) { form = new FormData(); }
  if (!xhr) { xhr = new XMLHttpRequest(); }
  
  var tmi='image';

  
 ourmimetype="";
 for (var ji=0; ji<exts.length; ji++) {
      if (("." + file[0].name.split('.')[eval(-1 + file[0].name.split('.').length)]).toLowerCase() == exts[ji].toLowerCase()) {
        ourmimetype=types[ji];
      }
 }

  
  if (ourmimetype.indexOf('video') != -1) {
    tmi='video';
  } else if (ourmimetype.indexOf('audio') != -1) {
    tmi='audio';
  }


  if (notfirstinsession == 0) {
  if (document.getElementById('to').value.indexOf('@') != -1) {
   form.append('to', document.getElementById('to').value);
   if (document.getElementById('cc').value.indexOf('@') != -1) {
   form.append('cc', document.getElementById('cc').value);
   }
   if (document.getElementById('bcc').value.indexOf('@') != -1) {
   form.append('bcc', document.getElementById('bcc').value);
   }
   if (document.getElementById('body').value != '') {
   form.append('body', document.getElementById('body').value);
   }
   if (document.getElementById('subject').value != '') {
    form.append('subject', document.getElementById('subject').value);
   } else {
    form.append('subject', 'Image in email');
   }
   form.append('filename', isipn(file[0].name));
   form.append('preksh', toccbcc());
   dotfile=isipn(file[0].name);
   dotfiles=',' + isipn(file[0].name) + ',';
  }
  notfirstinsession++;
  form.append(tmi, file[0]);
  if (document.getElementById('zipname').value != '') {
   form.append('zipname', jsipn(document.getElementById('zipname').value));
  }
  if (!filezerobig && (file.length > 1 || eval('' + swir) > 1)) {
  if (filezerosize < 0) { filezerosize=file[0].size; }
  filezerobig=false;
  if (filezerosize > 1000000) { formspare=null; filezerobig=true; }  // 1,156,109
  //if (filezerosize > 1) { formspare=null; filezerobig=true; }  // 1,156,109
  if (filezerobig) {
   if (document.getElementById('zipname').value == '') {
   form.append('zipname', jsipn(document.getElementById('zipname').placeholder));
   }
   form.append('of', '' + eval('' + swir) + 'of' + eval('' + swir));
  }
  }
  if (file.length > 1) {
  for (var iii=1; iii<file.length; iii++) {
 tmi='image';

  
 ourmimetype="";
 for (var ji=0; ji<exts.length; ji++) {
      if (("." + file[iii].name.split('.')[eval(-1 + file[iii].name.split('.').length)]).toLowerCase() == exts[ji].toLowerCase()) {
        ourmimetype=types[ji];
      }
 }

  
  if (ourmimetype.indexOf('video') != -1) {
    tmi='video';
  } else if (ourmimetype.indexOf('audio') != -1) {
    tmi='audio';
  }
  
   if (document.getElementById('to').value.indexOf('@') != -1) {
    if (filezerobig) {
    if (formspares[0] == null) {
    formspares[0]=new FormData(); 
    xhrs[0]=new XMLHttpRequest();
    newform=new FormData(); 
    newxhr=new XMLHttpRequest();
  if (document.getElementById('zipname').value != '') {
   newform.append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   newform.append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
   newform.append('of', '000' + eval('' + swir) + 'of' + eval('' + swir));
   newform.append('filename', file[0].name);
   newform.append(tmi, file[0]);
   newform.append('preksh', toccbcc());
    } else {
    formspares.push(new FormData()); 
    xhrs.push(new XMLHttpRequest());
    }
    if (iii == 1) { formspares[eval(-1 + formspares.length)].append('of', '0of' + eval('' + swir)); } else {  formspares[eval(-1 + formspares.length)].append('of', '0' + iii + 'of' + eval('' + swir));   }
    if (file[iii].name == dotfile) {  dot='.';     formspares[eval(-1 + formspares.length)].append('asterisk', dotsofar + file[iii].name.replace(dot,'*' + dot));  dotsofar+=file[iii].name.replace(dot,'*' + dot) + ' ';  } else if (dotfiles.indexOf(',' + file[iii].name + ',') != -1) { dot='.';   formspares[eval(-1 + formspares.length)].append('asterisk', dotsofar + file[iii].name.replace(dot,'*' + dot));   dotsofar+=file[iii].name.replace(dot,'*' + dot) + ' ';  } else { dotfiles+=file[iii].name + ','; dot='yoUwiLlneVerFiNdtHis'; }
    formspares[eval(-1 + formspares.length)].append('filename', jsipn(file[iii].name.replace(dot,'_' + iii + dot)));
    formspares[eval(-1 + formspares.length)].append('preksh', toccbcc());
  if (document.getElementById('zipname').value != '') {
   formspares[eval(-1 + formspares.length)].append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   formspares[eval(-1 + formspares.length)].append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
    } else {
    if (jsipn(file[iii].name) == dotfile) {  dot='.';     form.append('asterisk', dotsofar + jsipn(file[iii].name).replace(dot,'*' + dot));    dotsofar+=jsipn(file[iii].name).replace(dot,'*' + dot) + ' ';  } else if (dotfiles.indexOf(',' + jsipn(file[iii].name) + ',') != -1) { dot='.';   form.append('asterisk', dotsofar + jsipn(file[iii].name).replace(dot,'*' + dot));   dotsofar+=jsipn(file[iii].name).replace(dot,'*' + dot) + ' ';  } else { dotfiles+=jsipn(file[iii].name) + ','; dot='yoUwiLlneVerFiNdtHis'; }
    form.append('filename' + iii, jsipn(file[iii].name).replace(dot,'_' + iii + dot));
    }
   }
   notfirstinsession++;
   if (filezerobig) {
   if (formspares[0] == null) { 
     formspares[0]=new FormData(); 
     xhrs[0]=new XMLHttpRequest();
     newform=new FormData(); 
     newxhr=new XMLHttpRequest();
  if (document.getElementById('zipname').value != '') {
   newform.append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   newform.append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
   newform.append('of', '000' + eval('' + swir) + 'of' + eval('' + swir));
   newform.append('filename', isipn(file[0].name));
   newform.append(tmi, file[0]);
   newform.append('preksh', toccbcc());
   } 
   formspares[eval(-1 + formspares.length)].append('msuffix', '' + iii);
   formspares[eval(-1 + formspares.length)].append(tmi + iii, file[iii]);
   //xhr.open('post', 'mailto.php', true);
   //xhr.setRequestHeader('Cache-Control', 'no-cache');
   //xhr.send(formspares[eval(-1 + formspares.length)]);
   if (eval(-1 + xhrs.length) == 0) {
     if (1 == 2) { setTimeout(prexs,200); }
   } else if (1 == 2) {
   xhrs[eval(-1 + xhrs.length)].open('post', 'mailto.php', true);
   xhrs[eval(-1 + xhrs.length)].setRequestHeader('Cache-Control', 'no-cache');
   xhrs[eval(-1 + xhrs.length)].send(formspares[eval(-1 + formspares.length)]);
   }
//for (var value of formspares[eval(-1 + formspares.length)].values()) {
//   alert('0:' + value); 
//}
   //if (eval(1 + iii) < file.length || eval('' + notfirstinsession) >= eval('' + swir)) {  formspares.push(new FormData());   xhrs.push(new XMLHttpRequest());    }
   } else {
   form.append(tmi + iii, file[iii]);
   }
  }
  }
  } else {
  //alert('TheRe=' + file.length);
  ioff=notfirstinsession;
  var jjoff=eval('' + notfirstinsession);
  jjoff+=eval('' + file.length);

  pbb=' (' + jjoff + ' of ' + eval('' + swir) + ')';
  //alert('pbb=' + pbb);
  document.getElementById('sbig').innerHTML=document.getElementById('sbig').innerHTML.split(' (')[0] + pbb;

  for (var iiii=0; iiii<file.length; iiii++) {
 tmi='image';

  
 ourmimetype="";
 for (var ji=0; ji<exts.length; ji++) {
      if (("." + file[iiii].name.split('.')[eval(-1 + file[iiii].name.split('.').length)]).toLowerCase() == exts[ji].toLowerCase()) {
        ourmimetype=types[ji];
      }
 }

  
  if (ourmimetype.indexOf('video') != -1) {
    tmi='video';
  } else if (ourmimetype.indexOf('audio') != -1) {
    tmi='audio';
  }
  
   if (document.getElementById('to').value.indexOf('@') != -1) {
    if (filezerobig) {
    if (formspares[0] == null) {
    formspares[0]=new FormData();
    xhrs[0]=new XMLHttpRequest();
    newform=new FormData(); 
    newxhr=new XMLHttpRequest();
  if (document.getElementById('zipname').value != '') {
   newform.append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   newform.append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
   newform.append('of', '000' + eval('' + swir) + 'of' + eval('' + swir));
   newform.append('filename', isipn(file[0].name));
   newform.append(tmi, file[0]);
   newform.append('preksh', toccbcc());
    } else {
    formspares.push(new FormData()); 
    xhrs.push(new XMLHttpRequest());
    }
    if (ioff == 1) { formspares[eval(-1 + formspares.length)].append('of', '0of' + eval('' + swir)); } else {  formspares[eval(-1 + formspares.length)].append('of', '0' + ioff + 'of' + eval('' + swir));   }
    if (file[iiii].name == dotfile) {  dot='.';     formspares[eval(-1 + formspares.length)].append('asterisk', dotsofar + jsipn(file[iiii].name).replace(dot,'*' + dot));   dotsofar+=jsipn(file[iiii].name).replace(dot,'*' + dot) + ' ';  } else if (dotfiles.indexOf(',' + jsipn(file[iiii].name) + ',') != -1) { dot='.';   formspares[eval(-1 + formspares.length)].append('asterisk', dotsofar + jsipn(file[iiii].name).replace(dot,'*' + dot));   dotsofar+=jsipn(file[iiii].name).replace(dot,'*' + dot) + ' ';   } else { dotfiles+=jsipn(file[iiii].name) + ','; dot='yoUwiLlneVerFiNdtHis'; }
    formspares[eval(-1 + formspares.length)].append('filename', jsipn(file[iiii].name).replace(dot,'_' + ioff + dot));
    formspares[eval(-1 + formspares.length)].append('preksh', toccbcc());
  if (document.getElementById('zipname').value != '') {
   formspares[eval(-1 + formspares.length)].append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   formspares[eval(-1 + formspares.length)].append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
    } else {
    if (jsipn(file[iiii].name) == dotfile) {  dot='.';     form.append('asterisk', dotsofar + jsipn(file[iiii].name).replace(dot,'*' + dot));   dotsofar+=jsipn(file[iiii].name).replace(dot,'*' + dot) + ' ';   } else if (dotfiles.indexOf(',' + jsipn(file[iiii].name) + ',') != -1) { dot='.';   form.append('asterisk', dotsofar + jsipn(file[iiii].name).replace(dot,'*' + dot));    dotsofar+=jsipn(file[iiii].name).replace(dot,'*' + dot) + ' ';  } else { dotfiles+=jsipn(file[iiii].name) + ','; dot='yoUwiLlneVerFiNdtHis'; }
    form.append('filename' + ioff, jsipn(file[iiii].name).replace(dot,'_' + ioff + dot));
    }
   }
   notfirstinsession++;
   //alert('notfirstinsession becomes ' + notfirstinsession);
   if (filezerobig) {
   if (formspares[0] == null) { 
    formspares[0]=new FormData(); 
    xhrs[0]=new XMLHttpRequest();
    newform=new FormData(); 
    newxhr=new XMLHttpRequest();
  if (document.getElementById('zipname').value != '') {
   newform.append('zipname', jsipn(document.getElementById('zipname').value));
  } else {
   newform.append('zipname', jsipn(document.getElementById('zipname').placeholder));
  }
   newform.append('of', '000' + eval('' + swir) + 'of' + eval('' + swir));
   newform.append('filename', isipn(file[0].name));
   newform.append(tmi, file[0]);
   newform.append('preksh', toccbcc());
   } 
   formspares[eval(-1 + formspares.length)].append('msuffix', '' + ioff);
   formspares[eval(-1 + formspares.length)].append(tmi + ioff, jsipn(file[iiii]));
   //xhr.open('post', 'mailto.php', true);
   //xhr.setRequestHeader('Cache-Control', 'no-cache');
   //xhr.send(formspares[eval(-1 + formspares.length)]);
   if (eval(-1 + xhrs.length) == 0) {
     if (1 == 2) { setTimeout(prexs,200); }
   } else if (1 == 2) {
   xhrs[eval(-1 + xhrs.length)].open('post', 'mailto.php', true);
   xhrs[eval(-1 + xhrs.length)].setRequestHeader('Cache-Control', 'no-cache');
   xhrs[eval(-1 + xhrs.length)].send(formspares[eval(-1 + formspares.length)]);
   }
//for (var value of formspares[eval(-1 + formspares.length)].values()) {
//   alert('1:' + value); 
//}
   //if (eval(1 + iii) < file.length || eval('' + notfirstinsession) >= eval('' + swir)) {   formspares.push(new FormData());   xhrs.push(new XMLHttpRequest());    }
   } else {
   form.append(tmi + ioff, file[iiii]);
   }
   //alert('here is ioff=' + ioff);
   ioff++;
  }
  }
  if (eval('' + notfirstinsession) < eval('' + swir)) {
  pbb=' (' + eval('' + notfirstinsession) + ' of ' + eval('' + swir) + ')';
  //alert('pbb=' + pbb);
  document.getElementById('sbig').innerHTML=document.getElementById('sbig').innerHTML.split(' (')[0] + pbb;
  } else if (eval('' + notfirstinsession) >= eval('' + swir)) {
  pbb=' (' + eval('' + notfirstinsession) + ' of ' + eval('' + notfirstinsession) + ')';
  //alert('PBB=' + pbb);
  document.getElementById('sbig').innerHTML=document.getElementById('sbig').innerHTML.split(' (')[0] + pbb;
  //alert('here is');
  if (filezerobig) {
  if (1 == 1) { setTimeout(prexs,200); }
  //setTimeout(xs, 4000);
  } else {
  xhr.open('post', 'mailto.php', true);
  xhr.setRequestHeader('Cache-Control', 'no-cache');
  xhr.send(form);
  }
//for (var value of form.values()) {
//   alert('2:' + value); 
//}
  if (document.getElementById('to').value.indexOf('@') != -1) {
  if (1 == 1) {
  if (document.getElementById('myh3').innerHTML.indexOf('Emailed to ') != -1) {
  document.getElementById('myh3').innerHTML=document.getElementById('myh3').innerHTML.split('Emailed to ')[0] + 'Emailed to ' + document.getElementById('to').value + ' (' + document.getElementById('pb').title + ' in ' + notfirstinsession + ' media files)';
  } else {
  document.getElementById('myh3').innerHTML+='<br>Emailed to ' + document.getElementById('to').value + ' (' + document.getElementById('pb').title + ' in ' + notfirstinsession + ' media files)';
  }
  } else {
  alert('Emailed to ' + document.getElementById('to').value + ' (' + document.getElementById('pb').title + ' in ' + notfirstinsession + ' media files)');
  }
  }
  notfirstinsession=0;
  pbval=0;
  pbmax=10485760;
  setTimeout(andthen, 3000);  
  return true;
  //} else if (eval('' + swir) > 0) {
  //alert('here is notfirstinsession=' + notfirstinsession + ' and swir=' + swir);
  } 
  return false;
}

function andthen() {
  pbb=' (0 of ' + swir + ')';
  document.getElementById('sbig').innerHTML=document.getElementById('sbig').innerHTML.split(' (')[0] + pbb;
  document.getElementById('pb').title='0mB';
}


function prexs() {
  var ijk=0;
  nothanks=true;
  if (xhrs[0] != null) {
  //alert(xhrs.length);
  while (ijk < xhrs.length) {
   if (ijk == 0) {
    xhrs[ijk].open('post', 'mailto.php', true);
    xhrs[ijk].setRequestHeader('Cache-Control', 'no-cache');
    xhrs[ijk].send(formspares[ijk]);
   } else if (ijk == 1) {
    setTimeout(npostxs, 200);
    jijk=ijk;
    setTimeout(postxs, 400);
   }
   ijk++;
  }
  }
}

function npostxs() {
    if (dotsofar != '') {
      newform.append('asterisk', dotsofar);
    }
    newxhr.open('post', 'mailto.php', true);
    newxhr.setRequestHeader('Cache-Control', 'no-cache');
    newxhr.send(newform);
}

function postxs() {
    xhrs[jijk].open('post', 'mailto.php', true);
    xhrs[jijk].setRequestHeader('Cache-Control', 'no-cache');
    xhrs[jijk].send(formspares[jijk]);
    jijk++;
    if (jijk < xhrs.length) {
     setTimeout(postxs, 200);
    } else {
     nothanks=false; 
     setTimeout(xs, 7200);
    }
}

function xs() {
 if (!nothanks) {
  if (dotsofar != '') {
      form.append('asterisk', dotsofar);
  }
  xhr.open('post', 'mailto.php', true);
  xhr.setRequestHeader('Cache-Control', 'no-cache');
  xhr.send(form);
 }
 nothanks=false;
}

function whenokdrawOnCanvas() {
    if (kk == cfile.length) { 
     var preimgs=document.getElementsByTagName('img'), imgs=[];
     for (var xjjjk=0; xjjjk<eval('' + preimgs.length); xjjjk++) {
       if (('' + preimgs[xjjjk].className) != 'menu') {
         imgs.push(preimgs[xjjjk]);
       }
     }
     var ztop=0, zztop=0;
     tops[0] = 0;
     for (var jjjk=0; jjjk<eval('' + imgs.length); jjjk++) {
       document.title='';  // + imgs[jjjk].style.height;
       zztop=eval('' + imgs[jjjk].style.height.replace('px',''));
       for (var jjjkx=0; jjjkx<zztop; jjjkx++) {
         ztop++;
       }
       //ztop=eval(eval('' + ztop) + eval('' + zztop));
       if (('' + ztop) != '') { if (eval(1 + eval('' + jjjk)) >= tops.length && 1 == 1) {  tops.push(eval('' + ztop));  } else {  tops[eval(1 +  eval('' + jjjk))]=eval('' + ztop); } }
     }
     if (ztop > atop) { atop=ztop; } 
     tops[0] = 0;
     //alert(swir + ' --- ' + atop + ' ... ' + tops[1]);
     c = document.getElementById('canvaselement'); //querySelector('canvas'), // see Example 4
     ctx = c.getContext('2d'),
  c.width = awidth;
  c.height = Math.abs(atop);
  if (atop < 0) {
      atop = -atop;
  }
  if (swir == 0) {
     lasttop=0;
     for (var zjk=0; zjk<kk; zjk++) {
     drawOnCanvas(cfile[zjk], tops[zjk]);  
     }
  } else {
     lasttop=0;
     var jk=0;
     for (var jjk=0; jjk<imgs.length; jjk++) {
     ctx.drawImage(imgs[jjk], 0, tops[jjk]);
     lasttop++;
     jk++;  
     }
     for (var mjk=0; mjk<kk; mjk++) {
     if (eval(jk + mjk) < tops.length) {
     //alert('tops[' + eval(jk + mjk) + ']=' + tops[eval(jk + mjk)]);
     drawOnCanvas(cfile[mjk], tops[eval(jk + mjk)]);  
     }
     }
  }
     kk=0;
     if (done) { done=false; notfirstinsession=0; }
     //elemtoDataURL=elem.toDataURL('image/png').replace(";base64,",";charset=utf-8;base64,").replace(/^daXta:image\/(png|jpg|jpeg);base64,/, "");
     canvascommands=[];
     ccoffset=canvascommands.length;
    } else {
     setTimeout(whenokdrawOnCanvas);
    }
}

function displayAsImage(file) {
  var tmi='image';
  for (var ii=0; ii<file.length; ii++) {

 ourmimetype="";
 for (var ji=0; ji<exts.length; ji++) {
      if (("." + file[ii].name.split('.')[eval(-1 + file[ii].name.split('.').length)]).toLowerCase() == exts[ji].toLowerCase()) {
        ourmimetype=types[ji];
      }
 }
  
  tmi='image';
  
  if (ourmimetype.indexOf('video') != -1) {
    tmi='video';
  } else if (ourmimetype.indexOf('audio') != -1) {
    tmi='audio';
  }


  imgURL.push(URL.createObjectURL(file[ii]));
  
  if (ourmimetype.indexOf('video/') != -1) {
   dhuh=document.getElementById('video' + dhuh.id);
   img.push(document.createElement('source')); //'audio'));
   img[eval(-1 + img.length)].onload = function() {
    URL.revokeObjectURL(imgURL[eval(-1 + imgURL.length)]);
    if (eval(('' + this.width).replace('px','')) > awidth) {
      awidth=eval(('' + this.width).replace('px',''));
    }
    var imgs=document.getElementsByTagName('video');
    var ztop=0;
    for (var jjjk=0; jjjk<imgs.length; jjjk++) {
       ztop+=eval('' + imgs[jjjk].style.height.replace('px',''));
    }
    if (ztop > atop) { atop=ztop; } 
    atop+=eval(('' + this.height).replace('px',''));
    tops.push(atop);
    this.id=tmi + kk;
    this.style.height='' + this.height + 'px';
    kk++;
  };
  } else if (ourmimetype.indexOf('audio/') != -1) {
   dhuh=document.getElementById('audio' + dhuh.id);
   img.push(document.createElement('source')); //'audio'));
   img[eval(-1 + img.length)].onload = function() {
    URL.revokeObjectURL(imgURL[eval(-1 + imgURL.length)]);
    if (eval(('' + this.width).replace('px','')) > awidth) {
      awidth=eval(('' + this.width).replace('px',''));
    }
    var imgs=document.getElementsByTagName('audio');
    var ztop=0;
    for (var jjjk=0; jjjk<imgs.length; jjjk++) {
       ztop+=eval('' + imgs[jjjk].style.height.replace('px',''));
    }
    if (ztop > atop) { atop=ztop; } 
    atop+=eval(('' + this.height).replace('px',''));
    tops.push(atop);
    this.id=tmi + kk;
    this.style.height='' + this.height + 'px';
    kk++;
  };
  } else { 
  img.push(document.createElement('img'));
  img[eval(-1 + img.length)].onload = function() {
    URL.revokeObjectURL(imgURL[eval(-1 + imgURL.length)]);
    if (eval(('' + this.width).replace('px','')) > awidth) {
      awidth=eval(('' + this.width).replace('px',''));
    }
     var preimgs=document.getElementsByTagName('img'), imgs=[];
     for (var xjjjk=0; xjjjk<eval('' + preimgs.length); xjjjk++) {
       if (('' + preimgs[xjjjk].className) != 'menu') {
         imgs.push(preimgs[xjjjk]);
       }
     }
    //var imgs=document.getElementsByTagName('img');
    var ztop=0;
    for (var jjjk=0; jjjk<imgs.length; jjjk++) {
       ztop+=eval('' + imgs[jjjk].style.height.replace('px',''));
    }
    if (ztop > atop) { atop=ztop; } 
    atop+=eval(('' + this.height).replace('px',''));
    tops.push(atop);
    this.id=tmi + kk;
    this.style.height='' + this.height + 'px';
    kk++;
  };
  }

  if (ourmimetype.indexOf('image/') == -1) {
  if (ourmimetype != '') {
  img[eval(-1 + img.length)].setAttribute("type",ourmimetype);
  } else {
  img[eval(-1 + img.length)].setAttribute("type","video/mp4");
  }
  dhuh.setAttribute("controls",true);
  img[eval(-1 + img.length)].setAttribute("src", imgURL[eval(-1 + imgURL.length)]);
  } else {
  img[eval(-1 + img.length)].src=imgURL[eval(-1 + imgURL.length)];
  }
  
  if (firstdetails) {
    firstdetails.removeAttribute('open');
  }
  if (document.getElementById('summary' + dhuh.id.replace('audio','').replace('video','').replace('image',''))) {
    document.getElementById('summary' + dhuh.id.replace('audio','').replace('video','').replace('image','')).innerHTML=file[ii].name;
  }
  if (document.getElementById('details' + dhuh.id.replace('audio','').replace('video','').replace('image',''))) {
    if (!firstdetails || 1 == 1) { firstdetails=document.getElementById('details' + dhuh.id.replace('audio','').replace('video','').replace('image','')); }
    document.getElementById('details' + dhuh.id.replace('audio','').replace('video','').replace('image','')).style.display='block';
    document.getElementById('details' + dhuh.id.replace('audio','').replace('video','').replace('image','')).setAttribute('open','true');
  }
  
  //if (img[eval(-1 + img.length)]) { alert(dhuh.id + ' ... ' + eval(-1 + img.length)); }
  parentblob=img[eval(-1 + img.length)];
  dhuh.appendChild(img[eval(-1 + img.length)]);
  if (ourmimetype.indexOf('image/') != -1 && dhuh.outerHTML.indexOf('huh') != -1) {
    //alert(dhuh.innerHTML);
    if (dhuh.innerHTML.indexOf(' id="') != -1) {
    //alert(2);
      document.getElementById('bci').title=dhuh.innerHTML.split(' id="')[1].split('"')[0];
      document.getElementById('bci').value=dhuh.innerHTML.split(' id="')[1].split('"')[0];
      lastdo=document.getElementById(document.getElementById('bci').title);
    //alert(document.getElementById('bci').title);
      document.getElementById('ifbc').src='./barcode_check.html?rand=' + Math.floor(Math.random() * 19876754);
      setTimeout(checkbci, 2000);
    } else if (dhuh.innerHTML.indexOf('"blob:') != -1) {
      lastdo=dhuh;
      document.getElementById('bci').title='' + dhuh.id;
      document.getElementById('bci').value='' + dhuh.id;
    //alert(document.getElementById('bci').title);
      document.getElementById('ifbc').src='./barcode_check.html?rand=' + Math.floor(Math.random() * 19876754);
      setTimeout(checkbci, 2000);
    }
  }
  
  var db=document.body;
  if (firstdetails) {
    var dtl=document.createElement('details');
    dtl.style.display='none';
    dtl.id='detailsdnhuh' + dnhuh;
    dtl.setAttribute('open','true');
    var dts=document.createElement('summary');
    dts.id='summarydnhuh' + dnhuh;
    dtl.appendChild(dts);
    document.body.appendChild(dtl);
    db=dtl;
  }
  
  var dv=document.createElement('div');
  dv.id='dnhuh' + dnhuh;
  //dhuh.appendChild(dv);
  db.appendChild(dv);
  var dva=document.createElement('audio');
  dva.id='audiodnhuh' + dnhuh;
  db.appendChild(dva);
  var dvv=document.createElement('video');
  dvv.id='videodnhuh' + dnhuh;
  db.appendChild(dvv);
  dhuh=document.getElementById('dnhuh' + dnhuh);
  dnhuh++;
  }
}

function cdi(iois, ileft, itop) {
   if (lasttop == 0) {
      ctx.drawImage(iois, ileft, itop);
      //document.title+='' + swir + 'bad' + lasttop + ':' + itop + ' ';
      lasttop++;
   } else {
      ctx.drawImage(iois, ileft, tops[lasttop]);
      //document.title+='' + swir + 'good' + lasttop + ':' + tops[lasttop] + ' ';
      //alert(tops[lasttop]);
      lasttop++;
   }
}

function pref(file) {
  if (filezerosize < 0) { 
  var readerf = new FileReader();
  readerf.onload = function (e) {
    filezerosize=e.target.result.length;
  }
  readerf.readAsDataURL(file);
  }
}

function drawOnCanvas(file, xtop) {
  var reader = new FileReader();

  reader.onload = function (e) {
    var dataURL = e.target.result, imgl = new Image();
    //if (filezerosize < 0) { filezerosize=dataURL.length; alert('filezerosize=' + filezerosize); }
    //    c = document.querySelector('canvas'), // see Example 4
    //    ctx = c.getContext('2d'),
        

    imgl.onload = function() {
      //elem.width = imgl.width;
      //elem.height = imgl.height;
      this.style.height='' + this.height + 'px';
      if (1 == 1) {
      c = document.getElementById('canvaselement'); //querySelector('canvas'), // see Example 4
      ctx = c.getContext('2d');
      if (isNaN(xtop)) {
      //alert(xtop);
      ctx.drawImage(imgl, 0, 0);
      } else {
      //alert('xtop=' + xtop);
      ctx.drawImage(imgl, 0, xtop);
      }
      } else {
      cdi(imgl, 0, xtop);
      }
      elemtoDataURL=c.toDataURL('image/jpeg',0.5).replace(";base64,",";charset=utf-8;base64,").replace(/^daXta:image\/(png|jpg|jpeg);base64,/, "");
    };

    imgl.src = dataURL;
  };

  reader.readAsDataURL(file);
}


 function onbb(event, theev, ois) {
  if (elem == null) {
    elem = document.getElementById('canvaselement');
    context = elem.getContext("2d");
  }
  elemLeft = elem.offsetLeft;
  elemTop = elem.offsetTop;
 }

 function wasonbb(event, theev, ois) {
  if (elem == null) {
    elem = document.getElementById('canvaselement');
    context = elem.getContext("2d");
  }
  elemLeft = elem.offsetLeft;
  elemTop = elem.offsetTop;
  if (event.clientX || event.clientY) {
       x = event.clientX - elemLeft;
       y = event.clientY - elemTop;
  } else {
       x = event.pageX - elemLeft;
       y = event.pageY - elemTop;
  }
  var whichimage=0;
  for (var iw=0; iw<tops.length; iw++) {
    if (fnames.length > iw) {
      if (eval(iw + 1) < tops.length) {
        if (y >= tops[iw] && y <= tops[eval(1 + iw)]) {
          whichimage=iw;
        }
      }
    }
  }
  var annot=prompt("Would you like to annotate at (" + x + "," + eval(y - tops[whichimage]) + ") for " + fnames[whichimage] + "?","");
 }


function fontcolours(which,ia) {
  var curcolour = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BubbleColour"); 
  var curbigfontsize = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BigFontSize"); 
  var curfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "FontName");
  var curbigfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BigFontName");
  var curnormalfontsize = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "NormalFontSize"); 
  var curnormalfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "NormalFontName");
  
  var defis = curcolour + " " + curnormalfontsize + " " + curnormalfontname + "/" + curbigfontsize + " " + curbigfontname;
  if (ia == null) return defis;
  var ylmk = prompt("Here are " + which + " display parameters currently for 'Colour Normal/Big' What We Stand For Report considerations.  Change, keeping the format the same, as you desire.   You can leave out things as you move right (ie. you can just give a colour, for instance).", defis);
  if (ylmk != null) {
    if (ylmk != defis && ylmk.length > 0) {
      var normb = ylmk.split(" ");
      if (normb.length == 1) {
        eval(which + "BubbleColour='" + ylmk + "'");
        ia.innerHTML = which;
        ia.style.color = ylmk;
      } else {
        eval(which + "BubbleColour='" + normb[0] + "'");
        ia.innerHTML = which;
        ia.style.color = normb[0];
        var normbb = (ylmk.replace(normb[0] + " ", "")).split("/");
        var normbbb = normbb[0].split(" ");
        if (normbb.length == 1) {
          if (normbbb[0].length > 0) {
            eval(which + "NormalFontSize='" + normbbb[0] + "'");
            if (normbbb.length > 1) {
              eval(which + "NormalFontName='" + normbb[0].replace(normbbb[0] + " ", "") + "'");
              eval(which + "FontName='" + normbb[0].replace(normbbb[0] + " ", "") + "'");
              ia.style.fontFamily = normbb[0].replace(normbbb[0] + " ", "");
            }
          }
        } else {
          if (normbbb[0].length > 0) {
            eval(which + "NormalFontSize='" + normbbb[0] + "'");
            if (normbbb.length > 1) {
              eval(which + "NormalFontName='" + normbb[0].replace(normbbb[0] + " ", "") + "'");
            }
          }
          normbbb = normbb[1].split(" ");
          if (normbbb[0].length > 0) {
            eval(which + "BigFontSize='" + normbbb[0] + "'");
            if (normbbb.length > 1) {
              eval(which + "BigFontName='" + normbb[1].replace(normbbb[0] + " ", "") + "'");
              ia.style.fontFamily = normbb[1].replace(normbbb[0] + " ", "");
            }
          }
        }
      }
    }
    
    curcolour = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BubbleColour"); 
    curbigfontsize = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BigFontSize"); 
    curfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "FontName");
    curbigfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "BigFontName");
    curnormalfontsize = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "NormalFontSize"); 
    curnormalfontname = eval(which.replace('Not so much','Con').replace('Definitely', 'Pro') + "NormalFontName");  
    defis = curcolour + " " + curnormalfontsize + " " + curnormalfontname + "/" + curbigfontsize + " " + curbigfontname;
    ia.title = which + " colour and normal font / big font is " + defis + " ... click to change.";
  }
}


function allowctrue() {
  allowc = true;
  alert('allowc = true');
}

function allowcfalse() {
 if (!allowc) {
  allowc = false;
 } else if ((x != 0 || y != 0) && (lastx != 0 || lasty != 0)) {
  allowc = false;
 } else if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
  allowc = false;
 } else if ((x != 0 || y != 0)) {
  setTimeout(allowcfalse, 100);
 } else {
  setTimeout(allowcfalse, 1000);
 }
}

function effectiveDeviceWidth() {  // thanks to http://stackoverflow.com/questions/9477028/how-to-programmatically-find-the-device-width-in-phonegap-jquery-mobile
    var deviceWidth = window.orientation == 0 ? window.screen.width : window.screen.height;
    // iOS returns available pixels, Android returns pixels / pixel ratio
    // http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html
    if (navigator.userAgent.indexOf('Android') >= 0 && window.devicePixelRatio) {
        deviceWidth = deviceWidth / window.devicePixelRatio;
    }
    return deviceWidth;
}

function makeitshow() {
 if (document.getElementById(q + 'myf').style.display == 'none') {
  document.getElementById(q + 'myf').style.display = 'inline';
  setTimeout(allowcfalse, 2000);
  document.getElementById(q + 'issue').focus();
 }
}

function checkfloat(firstgo) {    // cater for new floating form idea ... 1/4/2015
  var ok=1;
  if (floating_form) {
    if (document.body.innerHTML.indexOf(af) == -1 && firstgo && document.URL.indexOf("nofloat") != -1) {
      firstgo = false;
      floating_form = false;
      ok = 0;
    }
    if (document.body.innerHTML.indexOf(af) == -1 && firstgo) {
      var dw = effectiveDeviceWidth();
      var omyfih = document.getElementById('myf').innerHTML;
      omyfih = omyfih.replace(/rating/g, "qrating");
      omyfih = omyfih.replace(/weighting/g, "qweighting");
      omyfih = omyfih.replace(/topic/g, "qtopic");
      omyfih = omyfih.replace(/issue/g, "qissue");
      omyfih = omyfih.replace(/bact/g, "qbact");
      omyfih = omyfih.replace(/esnap/g, "qesnap");
      omyfih = omyfih.replace(/mycnt/g, "qmycnt");
      omyfih = omyfih.replace(/thisqissue/g, "thisissue");
      omyfih = omyfih.replace(/qissuedata/g, "issuedata");
      threehundred = eval(dw / 2);
      var xx=document.getElementById('myfname2').value;
      var xxx=document.getElementById('mylemail').value;
      var preqmxyf="<div id=divform><form id='" + af + "' action='#' style='opacity:0.8; z-index:5; position:absolute; top: 225px; left: " + eval(dw * 2 / 3) + "px; border: 3px solid red; background-color: pink;'><h2>&nbsp;" + document.getElementById('myh1').innerHTML.replace('Capture Email', 'Canvas Annotation').replace('Game', 'Report').replace('gsc', 'qgsc').replace(/nofloat/g, 'float').split(' and')[0] + " Canvas Annotation <font size=1>(best to scribble first)</font>" + "</h2>" + omyfih + "</form></div>";
      document.body.innerHTML = document.body.innerHTML.replace(fpc, '100%').replace(we600, 'width="' + dw + '"').replace(twp, '4' + '5%;display:none;');
      
      document.getElementById('danno').innerHTML=preqmxyf; //document.getElementById('qm x yf').outerHTML;
      document.getElementById('myfname2').value = xx;
      document.getElementById('mylemail').value = xxx;

      elem = document.getElementById('canvaselement');
      elemLeft = elem.offsetLeft;
      elemTop = elem.offsetTop;
      if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
        elem.width = eval(threehundred * 2);
      } 
      context = elem.getContext('2d');

      document.getElementById('myf').style.display = 'none';
      q = 'q';
      setTimeout(allowcfalse, 2000); 
      document.getElementById(q + 'topic').focus();
      setInterval(makeitshow, 8000);
    }
  } 
  
  if (!firstgo && ok != 0) {
    if (floating_form) {
      location.href = "whatdowestandfor.html?float=float";
    } else {
      location.href = "whatdowestandfor.html?nofloat=nofloat";
    }
  }
}


function nextbit() {
 if (firsttime == 1) {
 var pemail=null; //prompt("Optionally, if you want to email snapshot What Do We Stand For Reports, who would it be to?  Cancel for no emails in this session.", document.getElementById('mylemail').value.replace("fill.in.email@address", ""));
 if (pemail != null) {
   if (pemail.replace("fill.in.email@address", "").indexOf("@") != -1) {
     document.getElementById('mylemail').value=pemail.replace("fill.in.email@address", "");
     document.getElementById('myh2').innerHTML = "Email " + pemail.replace("fill.in.email@address", "") + (" <br>via click/touch outside canvases<br>").substring(0,5) + document.getElementById('myh2').innerHTML;
     document.getElementById('myiframe').src='./whatdowestandfor.php?set=' + pemail.replace("fill.in.email@address", "");
     twothousand=9000;
     //alert("1:" + document.getElementById('mylemail').value);
   }
 } else {
   ask="";
 }
 firstX = 5;
 } else {
 firstX = Math.floor((Math.random()*wis)+50);
 }
 firstY = Math.floor((Math.random()*his)+50);
 //contextzero.beginPath();
 //contextzero.lineWidth="2";
 //contextzero.fillStyle = "green";
 //contextzero.strokeStyle="black"; // Black path
 //contextzero.moveTo(firstX, firstY);
 if (firsttime == 1) {
 secondX = 5;
 } else {
 secondX = Math.floor((Math.random()*wis)+50);
 }
 secondY = Math.floor((Math.random()*his)+50);
 
 
 //contextzero.lineTo(secondX, secondY);
 //contextzero.stroke();
 //contextzero.fillStyle = "yellow";
 //contextzero.beginPath();
 //contextzero.arc(((secondX + firstX) / 2.0), ((secondY + firstY) / 2.0), (Math.sqrt((secondX - firstX)*(secondX - firstX) + (secondY - firstY)*(secondY - firstY)) / 2.0),0,2*Math.PI);
 //contextzero.fill();

 //contextzero.beginPath();
 //contextzero.lineWidth="1";
 //contextzero.fillStyle = "green";
 //if (firsttime == 1) {
 //contextzero.strokeStyle="magenta"; 
 //} else {
 //contextzero.strokeStyle="brown"; // Brown path
 //}
 //contextzero.moveTo((firstX - ((secondY - firstY) / 2.0)), (firstY + ((secondX - firstX) / 2.0)));
 //contextzero.lineTo((firstX + ((secondY - firstY) / 2.0)), (firstY - ((secondX - firstX) / 2.0)));
 //contextzero.stroke();

 firsttime=0;
}


function onl() {
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();
  var hh = today.getHours();
  var minm = today.getMinutes(); //January is 0!
  var ss = today.getSeconds();
  document.getElementById('myfname2').value = "whatdowestandfor_" + yyyy + "_" + mm + "_" + hh + "_" + minm + "_" + ss + ".png"; 
  
  // New floating form logic 1/4/2015
  checkfloat(true);
} 

function ourdraw() {
  var ii, total=0, prototal=0, contotal=0, things, ithing=0, biggestprod=0, biggestcond=0, dzero=0.0;
  var diameters=[0], thisxpro=5, thisxcon=threehundred, thisypro=90, thisycon=90, offs, iii;
  var magnification = 5.0, offset=0;
  
  thisxcon += 5;
  
  if (floating_form) document.getElementById(q + 'myf').style.display = 'none';
  
  //alert(1);
  context.strokeStyle = "black";
  context.font = andso(cfb, "Pro", "Big");
  topic = document.getElementById(q + 'topic').value.replace(/\n/g, "<br>").replace(",", " ");
  info = "%20...%20regarding%20" + topic.replace(/ /g, "%20").replace(/<br>/g, "%20");
  //alert(11);
  if (topic.indexOf("<br>") != -1) {
    offs = topic.split("<br>");
    context.strokeText(offs[0],105, eval(offset + 30));
    for (ii=1; ii<offs.length; ii++) {
      offset = eval(30 + offset);
      context.strokeText(offs[ii],105, eval(offset + 30));
    }
  } else {
    context.strokeText(document.getElementById(q + 'topic').value,105, eval(offset + 30));
  }
  //alert(111);

  context.beginPath();
  context.lineWidth="2";
  context.strokeStyle="black"; // Black path
  context.moveTo(0, eval(offset + 40));
  context.lineTo(eval(threehundred * 2), eval(offset + 40));
  context.stroke();
  //alert(1111);
  context.beginPath();
  context.lineWidth="2";
  context.strokeStyle="brown"; // Black path
  context.moveTo(threehundred, eval(offset + 40));
  context.lineTo(threehundred, 1500);
  context.stroke();
  
  //context.strokeStyle = "green";
  context.strokeStyle = andso("green", "Pro", "BubbleColour");
  //context.font = cfb;
  context.font = andso(cfb, "Pro", "Big");
  context.strokeText("Definitely",5,eval(offset + 60));
  context.strokeStyle = andso("red", "Con", "BubbleColour");
  //context.font = cfb;
  context.font = andso(cfb, "Con", "Big");
  context.strokeText("Not so much",eval(threehundred + 5),eval(offset + 60));
  
  context.beginPath();
  context.lineWidth="2";
  context.strokeStyle="black"; // Black path
  context.moveTo(0, eval(offset + 70));
  context.lineTo(eval(threehundred * 2), eval(offset + 70));
  context.stroke();

  //alert(11111);

  for (ii=1; ii<issuedata.length; ii++) {
    things = issuedata[ii].split(",");
    ithing = eval((things[1].replace("-", "")));
    if (issuedata[ii].indexOf(",-") != -1) {
      diameters.push(eval(-2.0 * Math.sqrt((ithing / Math.PI))));
      if (biggestcond < eval(2.0 * Math.sqrt((ithing / Math.PI)))) biggestcond = eval(2.0 * Math.sqrt((ithing / Math.PI)));
      //contotal = eval(contotal + ithing); // (things[1].replace("-", "")));
      contotal += ithing; // (things[1].replace("-", "")));
      //total = eval(total - ithing); //(things[1].replace("-", "")));
      total -= ithing; //(things[1].replace("-", "")));
      //alert("Con: " + issuedata[ii] + " contotal=" + contotal + " prototal=" + prototal + " total=" + total + " thisdiameter=" + diameters[ii]);
    } else {
      if (biggestprod < eval(2.0 * Math.sqrt((ithing / Math.PI)))) biggestprod = eval(2.0 * Math.sqrt((ithing / Math.PI)));
      diameters.push(eval(2.0 * Math.sqrt((ithing / Math.PI))));
      //prototal = eval(prototal + ithing); //(things[1]));
      prototal += ithing; //(things[1]));
      //total = eval(total + ithing); // (things[1]));
      total += ithing; //(things[1].replace("-", "")));
      //alert("Con: " + issuedata[ii] + " contotal=" + contotal + " prototal=" + prototal + " total=" + total + " thisdiameter=" + diameters[ii]);
    }
  }
  
  dzero = eval(2.0 * Math.sqrt((Math.abs(total) / Math.PI)));
  thisxpro = eval(thisxpro + biggestprod * magnification / 2.0);
  thisxcon = eval(thisxcon + biggestcond * magnification / 2.0);
  
  var gthan = -1;
  if (party != 0) gthan = eval(issuedata.length - 2);
  
  for (ii=1; ii<issuedata.length; ii++) {
    things = issuedata[ii].split(",");
    if (diameters[ii] < 0) {  // con
      context.fillStyle = andso("red", "Con", "BubbleColour");
      context.beginPath();
      if (thisycon == 90) {
        thisycon = eval(thisycon + offset - (diameters[ii] * magnification / 2.0));
      } else {
        thisycon = eval(thisycon - (diameters[ii] * magnification / 1.0));
      }
      context.arc(thisxcon, thisycon, eval(-0.5 * (diameters[ii] * magnification)), 0, 2*Math.PI);
    } else {  // pro
      //context.fillStyle = "green";
      context.fillStyle = andso("green", "Pro", "BubbleColour");
      context.beginPath();
      if (thisypro == 90) {
        thisypro = eval(thisypro + offset + (diameters[ii] * magnification / 2.0));
      } else {
        thisypro = eval(thisypro + (diameters[ii] * magnification / 1.0));
      }
      context.arc(thisxpro, thisypro, eval(0.5 * (diameters[ii] * magnification)), 0, 2*Math.PI);
    }
    if (ii > gthan) context.fill();
    
    offs = things[0].split("<br>");
    
    if (diameters[ii] < 0) {  // con
      thisycon = eval(thisycon + 15 - (diameters[ii] * magnification / 2.0)); //+ 30);
      context.strokeStyle = andso("red", "Con", "BubbleColour");
      //context.font = cf;
      context.font = andso(cf, "Con", "Normal");
      if (things[0].indexOf("<br>") != -1) {
       if (ii > gthan) context.strokeText(offs[0], thisxcon, thisycon);
       for (iii=1; iii<offs.length; iii++) {
        thisycon = eval(thisycon + 30);
        if (ii > gthan) context.strokeText(offs[iii], thisxcon, thisycon);
       }
      } else {
       if (ii > gthan) context.strokeText(things[0], thisxcon, thisycon);
      }
    } else {  // pro
      thisypro = eval(thisypro + 15 + (diameters[ii] * magnification / 2.0)); //+ 30);
      //context.strokeStyle = "green";
      context.strokeStyle = andso("green", "Pro", "BubbleColour");
      //context.font = cf;
      context.font = andso(cf, "Pro", "Normal");
      if (things[0].indexOf("<br>") != -1) {
       if (ii > gthan) context.strokeText(offs[0], thisxpro, thisypro);
       for (iii=1; iii<offs.length; iii++) {
        thisypro = eval(thisypro + 30);
        if (ii > gthan) context.strokeText(offs[iii], thisxpro, thisypro);
       }
      } else {
       if (ii > gthan) context.strokeText(things[0], thisxpro, thisypro);
      }
    }

  }
  
  if (issuedata.length > 1 && thisypro >= thisycon) {
        context.beginPath();
        context.strokeStyle="black"; // Black path
        party = eval(thisypro + 25);
        context.moveTo(0, eval(thisypro + 30));
        context.lineTo(eval(threehundred * 2), eval(thisypro + 30));
        context.stroke();
        thisypro = eval(thisypro + 100.0 + (dzero * magnification / 2.0));
        thisxpro = eval(threehundred - (dzero * magnification / 2.0));
        context.beginPath();
        
        if (eval(total) < 0) {
              context.fillStyle = andso("red", "Con", "BubbleColour");
            if (contotal != 0) {
  //alert(ithing + " ::: " + prototal + " ... " + contotal + " ... " + total);
              thisxpro = eval(threehundred);
            }
        } else {
              //context.fillStyle = "green";
              context.fillStyle = andso("green", "Pro", "BubbleColour");
            if (contotal != 0) {
  //alert(ithing + " ::: " + prototal + " ... " + contotal + " ... " + total);
              thisxpro = eval(threehundred - eval(contotal / eval(contotal + prototal)) * (dzero * magnification / 1.0));
            }
        }

        if (contotal != 0) { // && prototal != 0 
          thisxpro = eval(thisxpro + eval(contotal / eval(contotal + prototal)) * (dzero * magnification / 2.0));
        }

        context.arc(thisxpro, thisypro, eval(0.5 * (dzero * magnification)), 0, 2*Math.PI);
        context.fill();

        
        thisypro = eval(thisypro + 60);
        context.beginPath();
        context.strokeStyle = "black";
        //context.font = cfb;
        context.font = andso(cfb, "Pro", "Big");
        context.strokeText("Total", thisxpro, thisypro);
        thisypro = eval(thisypro + 60);
        context.beginPath();
        context.strokeStyle="black"; // Black path
        context.moveTo(0, eval(thisypro + 30));
        context.lineTo(eval(threehundred * 2), eval(thisypro + 30));
        context.stroke();
  } else if (issuedata.length > 1 && thisypro < thisycon) {
        party = eval(thisycon + 25);
        context.beginPath();
        context.strokeStyle="black"; // Black path
        context.moveTo(0, eval(thisycon + 30));
        context.lineTo(eval(threehundred * 2), eval(thisycon + 30));
        context.stroke();
        context.beginPath();
        thisycon = eval(thisycon + 100.0 + (dzero * magnification / 2.0));
        thisxcon = eval(threehundred + (dzero * magnification / 2.0));
        
        if (eval(total) < 0) {
              context.fillStyle = andso("red", "Con", "BubbleColour");
            if (prototal != 0) {
              thisxcon = eval(threehundred + eval(prototal / eval(contotal + prototal)) * (dzero * magnification / 1.0));
        }
        } else {
              //context.fillStyle = "green";
              context.fillStyle = andso("green", "Pro", "BubbleColour");
            if (prototal != 0) {
  //alert(ithing + " :;: " + prototal + " ... " + contotal + " ... " + total);
              thisxcon = eval(threehundred);
            }
        }

        if (prototal != 0) { // && contotal != 0) {
          thisxcon = eval(thisxcon - eval(prototal / eval(contotal + prototal)) * (dzero * magnification / 2.0));
        }

        context.arc(thisxcon, thisycon, eval(0.5 * (dzero * magnification)), 0, 2*Math.PI);
        context.fill();

        
        thisycon = eval(thisycon + 60);
        context.beginPath();
        context.strokeStyle = "black";
        //context.font = cfb;
        context.font = andso(cfb, "Pro", "Big");
        context.strokeText("Total", thisxcon, thisycon);
        thisypro = eval(thisycon + 60);
        context.beginPath();
        context.strokeStyle="black"; // Black path
        context.moveTo(0, eval(thisycon + 30));
        context.lineTo(eval(threehundred * 2), eval(thisycon + 30));
        context.stroke();
  }
  

  document.getElementById(q + 'esnap').style.display = 'block'; 
  document.getElementById(q + 'bactfloat').style.display = 'none'; 
  
  document.getElementById(q + 'mycnt').innerHTML = etc(ofstring); 
  document.getElementById(q + 'rating').value = 0;
  document.getElementById(q + 'weighting').value = 1;
  document.getElementById(q + 'issue').value = ''; 
  document.getElementById(q + 'esnap').value = 'Email Snapshot';
  document.getElementById(q + 'issue').focus();
  
}


function etc(iniof) {
   var ij, suff="";
   var upto=eval(iniof.replace(" ",""));
   for (ij=1; ij<=upto; ij++) {
    if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
     if (ij == 1) {
       suff="&nbsp;&nbsp;&nbsp;";
     } else if (issuedata[eval(-1 + ij)] != ',0') {
       suff=suff.replace("&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;<a href='#' title='Delete designated issue number of link to right ...' style='text-decoration:none;'>x</a>&nbsp;") + "<a href='#' onclick=\"  delit(this.title,'" + q + "mysel');  \" title=\"" + eval(-1 + ij) + "\">" + eval(-1 + ij) + "</a>&nbsp;";
     }
    } else if (issuedata[eval(-1 + ij)] != ',0') {
     if (ij == 1) {
       suff="&nbsp;<select id=" + q + "mysel onchange=' delit(this.value,this.id); ' title='Delete designated issue number'><option value='' selected></option></select>";
     } else {
       suff=suff.replace("></option>", ">x</option>").replace("<option ", "<option value=" + eval(-1 + ij) + ">x" + eval(-1 + ij) + "</option><option ");
     }
    }
   }
   return iniof + suff;
}

function andso(proposed, tmode, askidea) {
  var fs="", fn="";
  if (askidea == "Big" || askidea == "Normal") {
    fs = eval(tmode + askidea + "FontSize");
    fn = eval(tmode + askidea + "FontName");
    return fs + " " + fn;
  }
  return eval(tmode + askidea);
}

function drawt() {
 onl();
 
 document.getElementById(q + 'bactcon').title = document.getElementById(q + 'bactcon').title + " is " + fontcolours("Not so much", null) + " ... click to change.";
 document.getElementById(q + 'bactpro').title = document.getElementById(q + 'bactpro').title + " is " + fontcolours("Definitely", null) + " ... click to change.";
 
 //elemzero = document.getElementById('canvaselementzero');
 //elemLeftzero = elemzero.offsetLeft;
 //elemTopzero = elemzero.offsetTop;
 
 if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
 twothousand=9000;
 wis = eval(wis / 2);
 //elemzero.width = eval(500 / 2);
 //elemzero.style.left = eval(510 / 2);
 
 //contextzero = elemzero.getContext('2d');
 if (document.URL.indexOf("nofloat") != -1) {
 if (1 == 2) { setTimeout(nextbit, 1000); }
 //document.getElementById(q + 'myf').style.zIndex = "2";
 } else {
 if (1 == 2) { setTimeout(nextbit, 1000); }
 }
 } else {
 firsttime=0;
 //document.getElementById('mylemail').style.display='block';
 
 //contextzero = elemzero.getContext('2d');
 if (1 == 2) { setTimeout(nextbit, 1000); }
 } 
 
}


function ourcapture(toh, tos, toe, toehref) {
  //alert(0);
  var things = document.URL.split("?");
  var tis=toehref.split("body=");
  toe.href = tis[0] + "body=" + (things[0].replace("#","") + "/~").replace("whatdowestandfor.html/~", document.getElementById('myfname2').value).replace("index.html/~", document.getElementById('myfname2').value).replace("//~", "/" + document.getElementById('myfname2').value).replace("/~", "/" + document.getElementById('myfname2').value).replace("whatdowestandfor.htm/~", document.getElementById('myfname2').value).replace("index.html/~", document.getElementById('myfname2').value).replace("//~", "/" + document.getElementById('myfname2').value).replace("/~", "/" + document.getElementById('myfname2').value);
  var pretoh = elem.toDataURL();
  toh.value = pretoh.substr(22, pretoh.length); 
  tos.click();
  //alert(1);
  if (twothousand == 2000) {
  //alert(toe.href);
    toe.click();
  //alert(111);
  } else {
  //alert(1111);
    document.getElementById('myh2').innerHTML=document.getElementById('myh2').innerHTML.replace('Email ', 'Emailed ');
  //alert(11111);
  }
  //alert(10);
  setTimeout(onl, 2000);
}

function presnapshot() {
  if (yourfirstX != -999.0 || yourfirstY != -999.0) {
   infoemail=document.getElementById('mylemail').value.replace("fill.in.email@address", "");
   if (infoemail.indexOf("@") != -1) snapshot();
   return infoemail;
  }
  return '';
}

function snapshot() {
   var ik=0;
   if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
    var xinfoemail=document.getElementById('mylemail').value.replace("fill.in.email@address", "");
    if (xinfoemail.indexOf("@") != -1) {
      var bem=document.getElementById('myemail').href.split("&body");
      if (bem.length > 1) {
      document.getElementById('mymobile2').value=(bem[0] + "&body=").replace('For&body=', 'For' + info + '&body=').replace('fill.in.email@address', xinfoemail);
      } else {
      document.getElementById('mymobile2').value=document.getElementById('myemail').href.replace('For&body=', 'For' + info + '&body=').replace('fill.in.email@address', xinfoemail);
      }
      if (document.getElementById(q + 'esnap').value.indexOf("@") == -1) {
        document.getElementById(q + 'esnap').value = 'Emailed ' + xinfoemail + ' Snapshot';
      } else if (document.getElementById(q + 'esnap').value.indexOf("Email ") != -1) {
        document.getElementById(q + 'esnap').value = 'Emailed ' + xinfoemail + ' Snapshot';
      }
    }
    //alert(document.getElementById('mymobile2').value);
    ourcapture(document.getElementById('mydurl2'),document.getElementById('submit2'),document.getElementById('myemail'),document.getElementById('myemail').href.replace('For&body=', 'For' + info + '&body=').replace('fill.in.email@address', xinfoemail));
    ik=1;
   } //else {
    //context.strokeStyle = "blue";
    //context.font = cf;
    //var pgt=gptext.split(" ... ");
    //context.strokeText(pgt[0].replace(" the ", " "),5,30);
    //context.strokeText(pgt[1].replace(" the ", " "),5,60);
   //}
   if (ik == 0) ourcapture(document.getElementById('mydurl2'),document.getElementById('submit2'),document.getElementById('myemail'),document.getElementById('myemail').href.replace('For&body=', 'For' + info + '&body=').replace('fill.in.email@address', infoemail));
}

function postic() {
  iscanvas=0;
}

function resetic() {
  iscanvas=1;
  document.getElementById('myh2').innerHTML=document.getElementById('myh2').innerHTML.replace('Emailed ', 'Email ');
  //setTimeout(postic,400);
}

function later() {
  document.getElementById('myh2').innerHTML=document.getElementById('myh2').innerHTML.replace('Emailed ', 'Email ');
  if (iscanvas != 1) { if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {  if (ask != '') { iscanvas=-1; var xif=presnapshot();  if (xif.indexOf('@') != -1) { document.getElementById('myh2').innerHTML=document.getElementById('myh2').innerHTML.replace('Email ', 'Emailed '); } } } } 
  iscanvas=0; 
}

function canc(event) {
elem = document.getElementById('canvaselement');
elemLeft = elem.offsetLeft;
elemTop = elem.offsetTop;
       //document.getElementById('qm' + 'yf').style.position='sticky';
       document.getElementById('qm' + 'yf').style.top=eval(-200 + eval('' + elem.offsetTop) / 2 + eval('' + getBodyScrollTop())) + 'px'; //document.body.style.scrollTop;
       //document.title='' + eval(-200 + eval('' + elem.offsetTop) + eval('' + getBodyScrollTop())); //document.body.style.scrollTop;
       //alert('' + eval(eval('' + elem.offsetTop) + eval('' + getBodyScrollTop())) + ' ' + elem.offsetTop + ' ... ' + getBodyScrollTop() + ' ... ' + document.getElementById('divform').innerHTML);
       //if (eval(x) <= eval(elem.width) && eval(y) <= eval(elem.height) && allowc) {
       if (allowc || 1 == 1) {
       if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
       if (event.pageX || event.pageY) {
       x = event.pageX - elemLeft;
       y = event.pageY - elemTop;
       } else {
       x = event.clientX - elemLeft;
       y = event.clientY - elemTop;
       }
       lastx=x;
       lasty=y;
       } else {
       lastx=x;
       lasty=y;
       if (event.pageX || event.pageY) {
       x = event.pageX - elemLeft;
       y = event.pageY - elemTop;
       } else {
       x = event.clientX - elemLeft;
       y = event.clientY - elemTop;
       }
       }
       
    //alert('click');
       }
       

       elements.push({
        colour: '#ff0000',
        width: 5,
        height: 5,
        top: y,
        left: x
        });
        
    clickno = clickno + 1;

    
    if (1 == 2 && (x != lastx || y != lasty)) {
      document.getElementById('divannotation').style.display='block';
      document.getElementById('myisubject').style.display = 'inline';
      document.getElementById('myiemail').style.display = 'inline';
  }



}

function getBodyScrollTop() { 
  const el = document.scrollingElement || document.documentElement;
  return el.scrollTop;
}

function copycanvas() {
var wimg = document.createElement('img');
wimg.src = elem.toDataURL();

var wdiv = document.createElement('div');
wdiv.contentEditable = true;
wdiv.appendChild(wimg);
document.body.appendChild(wdiv);

// do copy
SelectText(wdiv);
document.execCommand('Copy');
document.body.removeChild(wdiv);
}

function SelectText(element) { // thanks to https://stackoverflow.com/a/40547470/1118626
    var doc = document;
    if (doc.body.createTextRange) {
        var range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        var selection = window.getSelection();
        var range = document.createRange();
        range.selectNodeContents(element);
        selection.removeAllRanges();
        selection.addRange(range);
    }
}
</script>
</head>
<body ontouchend=" setTimeout(later,2000); " onload='if (2 == 1) {  bp();  }' style='background-color:lightgreen;'>
<div id=topmostmenu>
<script type='text/javascript'>
  document.write('<h1 id=myh1>Image ' + aia + ' Capture Email</h1>');
</script>
<!--h1>Image Capture Email</h1-->
<h3 id=myh3>RJM Programming - October, 2018 - Thanks to <a target=_blank title='https://www.w3.org/TR/html-media-capture/' href='//www.w3.org/TR/html-media-capture/'>https://www.w3.org/TR/html-media-capture/</a></h3>
</div>
<div id=topdmenu>
<script type='text/javascript'>
if (nocamera) {
  document.write('<input style="display:inline-block;" type="file" name="image" id="cimage" accept="image/*' + extras + '" multiple>');
} else {
  document.write('<input style="display:inline-block;" type="file" name="image" id="cimage" accept="image/*' + extras + '" multiple capture>');
}
</script>
&nbsp;<input onblur="if (this.value.indexOf('@') != -1 && this.value != '@') {  document.getElementById('zipname').style.display='inline-block'; } " id="to" name="to" type="text" style="inline-block;" placeholder="Optionally email to" value="">&nbsp;<input id="subject" name="subject" type="text" style="inline-block;" placeholder="Optional email subject" value="">&nbsp;<input onclick="if (this.value == '' && this.placeholder.indexOf(' ... ') != -1) { this.value=this.placeholder.split(' ... ')[1];  } " style="display:none;width:20%;" id="zipname" name="zipname" type="text" placeholder="Optional zipfile email attachment name" value="">&nbsp;<select name=swir id=swir onchange="if (this.value.length == 0) { goagain(cfile); setTimeout(swirit,3000);  } else { swir=eval(this.value); }"><option value='0'>Send Each Time</option><option value='1'>Send 1 or Over</option><option value='2'>Send 2 or Over</option><option value='3'>Send 3 or Over</option><option value='4'>Send 4 or Over</option><option value='5'>Send 5 or Over</option><option value='6'>Send 6 or Over</option><option value='7'>Send 7 or Over</option><option value='8'>Send 8 or Over</option><option value='9'>Send 9 or Over</option><option value=''>Resend Now</option></select>&nbsp;<input onclick="nocamera=!nocamera; if (nocamera) { location.href=document.URL.split('#')[0].split('?')[0] + '?nocamera=true' + superex(pextras); } else if (document.URL.indexOf('nocamera=') != -1) { location.href=(document.URL.split('#')[0].split('?')[0] + superex(qextras)).replace('.htm&','.htm?');  } " type='checkbox' id='nocamera' style='display:inline-block;'>No Camera</input>&nbsp;<input type='checkbox' id='forever' onclick="documentURL=''; setCookie('imagecapture');" style='display:inline-block;'>Remember Me?</input>
</div>
<!--hr><div id=demail></div><hr-->
<script type='text/javascript'>

function isIEorEDGE() {
  return navigator.appName == 'Microsoft Internet Explorer' || (navigator.appName == "Netscape" && navigator.appVersion.indexOf('Edge') > -1);
}

if (isIEorEDGE()) {
  document.write('<hr><input type=button value="More Email and Canvas Annotation Ideas" onclick="document.getElementById(' + "'dmore'" + ').style.display=' + "'block'" + '; this.style.display=' + "'none'" + '; "></input>&nbsp;&nbsp;<span id=ssmall>0mB</span>&nbsp;<progress title=0mB id=pb value=0 max=10000000></progress>&nbsp;<span id=sbig>10mB' + pbb + '</span><div id=dmore style=width:100%;display:none;><input style=width:30%; type=text id=cc placeholder="Optional CC email address"></input><br><input style=width:30%; type=text id=bcc placeholder="Optional BCC email address"></input><br><textarea rows=15 cols=57 id=body placeholder="Optional Body Text"></textarea><div id=danno></div></div>');
} else {
  document.write('<hr><details onclick=setTimeout(detopenmaybe,200); id=detemail><summary>More Email and Canvas Annotation Ideas&nbsp;&nbsp;<span id=ssmall>0mB</span>&nbsp;<progress id=pb value=0 max=10000000></progress>&nbsp;<span id=sbig>10mB' + pbb + '</span></summary><input style=width:30%; type=text id=cc placeholder="Optional CC email address"></input><br><input style=width:30%; type=text id=bcc placeholder="Optional BCC email address"></input><br><textarea rows=15 cols=57 id=body placeholder="Optional Body Text"></textarea><div id=danno></div></details>');
}

document.write('<hr><div id=demail></div><hr>');

if (isIEorEDGE()) {
  document.write('<br><span id=sumcanvas>Canvas image(s) via [canvasContext].drawImage() is Clickable (for scribble and non-scribble annotations) below ...</span><br><button onclick=dannoit();>Save As...</button><br><canvas id="canvaselement" style="-webkit-overflow-scrolling:touch;" onclick="canc(event);" ontouchstart="canc(event);" data-onclick=" onbb(event,' + "'" + 'onclick' + "'" + ', this); " data-onmousedown=" onbb(event,' + "'" + 'onmousedown' + "'" + ', this); "  data-ontouchdown=" onbb(event,' + "'" + 'ontouchdown' + "'" + ', this); " ></canvas>');
} else {
  document.write('<details onclick=setTimeout(detopenmaybe,100); id=detcanvas><summary id=sumcanvas>Canvas image(s) via [canvasContext].drawImage() is Clickable (for scribble and non-scribble annotations) below ...</summary><button onclick=dannoit();>Save As...</button><br><canvas id="canvaselement" style="-webkit-overflow-scrolling:touch;" onclick="canc(event);" ontouchstart="canc(event);" data-onclick=" onbb(event,' + "'" + 'onclick' + "'" + ', this); " data-onmousedown=" onbb(event,' + "'" + 'onmousedown' + "'" + ', this); "  data-ontouchdown=" onbb(event,' + "'" + 'ontouchdown' + "'" + ', this); " ></canvas></details>');
}
document.write('<hr><p>' + selprefix + 'Image' + selsuffix + aia + '(s) below ...</p>');
if (!isIEorEDGE() && 1 == 1) {
  document.write('<details id=detailsadhuh style=display:none; open><summary id=summaryadhuh></summary>');
}
document.write('<audio id=audioadhuh></audio>');
document.write('<video id=videoadhuh></video>');
document.write('<div id=adhuh></div>');
if (!isIEorEDGE() && 1 == 1) {
  document.write('</details>');
}
</script>

<!--audio id='audioadhuh'></audio>
<video id='videoadhuh'></video>
<div id='adhuh'></div-->
<form id='myf' action='#' style='border: 3px solid red; background-color: pink;'>
<br>
<div id=hide style=display:none;>
<label>&nbsp;Topic: <textarea rows=5 cols=60 name='topic' id='topic' onblur="  if (this.value.length > 0) { party=0;  topic=this.value.replace(/\n/g,'<br>'); issuedata= ['']; ofstring=' 1'; iof=1; } " value=""></textarea></label><br>
<hr>
<label>&nbsp;Issue<span id='mycnt'> 1</span>: <br>&nbsp;<textarea onclick="  if (this.value.length == 0) { this.value=' '; } " rows=5 cols=60 name='issue' id='issue' onblur=" if (this.value.length > 0) {  document.getElementById('mycnt').innerHTML = etc(ofstring);  thisissue=this.value.replace(/,/g, ' ').replace(/\n/g,'<br>'); } "  value=''></textarea></label><br>
<label>&nbsp;Rating -10 to 10 (negative <font color='red'><a href='#' id='bactcon' onclick=" fontcolours('Not so much',this); " title="Not so much colour and normal font / big font" style=" colour:red;font-family:verdana; "><font color='red'>Not so much</font></a></font>, &nbsp;positive <font color='green'><a href='#' id='bactpro' onclick=" fontcolours('Definitely',this); " title="Definitely colour and normal font / big font" style=" colour:green;font-family:verdana; "><font color='green'>Definitely</font></a></font>): <br>&nbsp;<input type='number' name='rating' id='rating' value='0'></input></label><br>
<label>&nbsp;Weighting for This Issue: <br>&nbsp;<input type='number' name='weighting' id='weighting' value='1'></input></label><br>
<hr>
</div>
<div align='center'><div id=hide2 style=display:none;>&nbsp;<input type='button' name='bact' id='bact' value='Update and Draw to Left' onclick=" x=0; y=0; lastx=0; lasty=0; setTimeout(allowctrue, 1000);  andthen();    iof=eval(1 + iof); ofstring=' ' + iof;  issuedata.push(thisissue + ',' + eval(document.getElementById('rating').value * document.getElementById('weighting').value)); ourdraw(); "></input>
&nbsp;<input type='button' name='bactfloat' id='bactfloat' value='Toggle Form Float' onclick=" floating_form=!floating_form; checkfloat(false); " style="display:block;"></input>
&nbsp;<input type='button' name='esnap' id='esnap' value='Email Snapshot' onclick=" if (this.value.indexOf('ed ') == -1) { iscanvas=1; snapshot(); } " style="display:none;"></input>
</div>
<div id='divannotation' style='display:block;'>
    <!--h4>Your Annotations++</h4-->
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/line.png' onclick=' nicknameprefix="line2"; doline(); nrecord(1); ' alt='Line' title='Line'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/rectangle.png' onclick=' nicknameprefix="rectangle2"; dorectangle(); nrecord(1);  ' alt='Rectangle' title='Rectangle'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/rectangleborder.png' onclick=' nicknameprefix="rectangle2"; dorectangleborder(); nrecord(1);  ' alt='Rectangle Border' title='Rectangle Border'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/circle.png' onclick=' nicknameprefix="circle2"; docircle(); nrecord(1);  ' alt='Circle' title='Circle'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/clear.png' onclick=' nicknameprefix="clear2";  clearall(); nrecord(1);  ' alt='Clear' title='Clear'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/sline.png' onclick=" nicknameprefix='scribble'; nrecord(0);  alert('Ready to Scribble in two seconds.  Any key stroke stops scribbling.'); setTimeout(intwo,2000); " alt='Scribble' title=''></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/zline.png' onclick=" nicknameprefix='endscribble'; nrecord(1);  if (isScribble == 2 || isScribble == 1) { storecanvascommands('context=context;', true); } isScribble=0; " alt='End of scribble' title='End of scribble'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/minus.png' onclick=" nicknameprefix='minus'; if (isScribble == 2 || isScribble == 1) { isScribble=0; storecanvascommands('context=context;', true); }  undo(); " alt='Undo' title='Undo'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/plus.png' onclick=" nicknameprefix='plus'; if (isScribble == 2 || isScribble == 1) { isScribble=0; storecanvascommands('context=context;', true); }  redo(); " alt='Redo' title='Redo'></img>
    &nbsp;<a style='text-decoration:none;cursor:pointer;font-size:48px;' onclick=" lsset(); " alt='Save Canvas' title='Save Canvas'>&#127912;</a>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/image.png' onclick=" if (1 == 1) { document.getElementById('cimage').click(); } if (1 == 2) {  document.getElementById('file').style.display='block';  document.getElementById('dpf').style.display='block'; } " alt='Image' title='Image'></img>
    &nbsp;<img class='menu' src='//www.rjmprogramming.com.au/MarkItUp/copy.png' onclick=" copycanvas(); " alt='Canvas Copy' title='Canvas Copy'></img>
    &nbsp;<a style='text-decoration:none;cursor:pointer;font-size:48px;' onclick=" canvasmode=true; email(); canvasmode=false;  " alt='Canvas Email' title='Canvas Email'>&#128231;</a><input style='display:none;' id='file' type='file' name='file'></input><div id=dpf style='display:BLOCK;'>&nbsp;&nbsp;<span class='readBytesButtons'><button style='display:none;' data-endbyte='4' data-startbyte='0'>1-5</button><button style='display:none;' data-endbyte='14' data-startbyte='5'>6-15</button><button style='display:none;' data-endbyte='7' data-startbyte='6'>7-8</button>
    <br>... vs Image URL: <input id='vsiurl' type='url' value='+' onblur='if (1 == 2) { preread(this.value); } readUBlob(this.value,0,0);' style='width:40%;'></input>
    <br>... Offset X: <input style='width:10%;' id='xoff' type='number' value='0'></input> Offset Y: <input style='width:10%;' id='yoff' type='number' value='0'></input>
    <br><button onclick='readBlob(0,0);'>Place into Canvas</button><button onclick='readOBlob(0,0);'>Overlay into Canvas</button></div><div id='byte_range' style='display:none;'></div><div id='byte_content' style='display:none;'></div><input id='fil' value='' type='hidden'></input><img class='menu' id='spareimg' src='' style='display:none;'></img>
    <br>Annotation (optional): <input onblur=' nicknameprefix="text(" + x + "," + y + " with " + this.value + ")";  placeannotation(this); nrecord(1); ' id='iannotation' type='text' value=''></input>
    <br><span>Anno B&amp;W (optional): <input onblur='  nicknameprefix="text(" + x + "," + y + " with " + this.value + ")";  placeannotation(this); nrecord(1); ' id='jannotation' type='text' value=''></input>
    <br>Style: <input type='text' id='myfont' value='18px Verdana'></input>
    <br>Colour: <input type='color' id='mycolour' value='#000000'></input>&nbsp;Rotation (deg): <input style='width:10%;' type='number' step=1 min='-360' max='360' id='rotation' value='0'></input><input type='hidden' id='rof' value=''></input></span><br>
</div></div>
</form>
<br>
<br><br>
</td><td style="width:5%;display:none;">
</td></tr>
</table>
<!--h2 id='myh2' align="right">Your Try for the <br>What We Stand For (over at left) ... <br>Click to Start at Tangent <br>and to Finish <br>the Circle Diameter Line</h2><br>
<h3 id='myh3' align="right">Score: 3000 Goes: 0</h3><br-->
<div id=hide3 style=display:none;><form style='display:none;' id='myform2' name='myform' method='POST' action='./whatdowestandfor.php?mode=1' target='myiframe'>
<input type='hidden' name='mymobile' id='mymobile2' value=''></input>
<input type='hidden' name='myfname' id='myfname2' value=''></input>
<input type='hidden' name='mydurl' id='mydurl2' value=''></input>
<input type='submit' name='submit' id='submit2' value='Submit' style='display:none;'></input></form>
<iframe style='display:none;' id='myiframe' src='./whatdowestandfor.php?get='></iframe>
<a style='display:none;' id='myemail' href='mailto:fill.in.email@address?subject=My%20What%20Do%20We%20Stand%20For&body='>Email</a>
<input style='display:none;' id='mylemail' type='text' value='fill.in.email@address' />

    <form style='display:none;' id='myform' method='POST' enctype='application/x-www-urlencoded' action='world.php' target='myiframetwo'>
    <input type='hidden' name='mysubject' id='mysubject' value='My What Do We Stand For'></input>
    <input type='hidden' name='myfname' id='myfname' value=''></input>
    <input type='submit' id='bsubmit' value='Submit' style='display:none;'></input>
    <input type='hidden' name='ismobile' id='ismobile' value=''></input>
    <input type='hidden' name='mode' id='mode' value='1'></input>
    <input type='hidden' name='to' id='to' value=''></input>
    <input type='hidden' name='mydurl' id='mydurl' value=''></input>
    </form>
    <iframe style='display:none;' id='myiframetwo' src='world.php'></iframe>

    <input style='display:BLOCK;width:250px;' onblur='fixmyemail(this.value + String.fromCharCode(32),1);' type='text' id='myisubject' value='My What Do We Stand For '></input>&nbsp;<input style='background-color: yellow;' type='button' value='Email (optional)' onclick="  capture(document.getElementById('mydurl'),document.getElementById('submit2'),document.getElementById('myemail'));   "></input>&nbsp;<a style='display:none;' target='_blank' id='myemail' href='mailto:fill.in.email@address?subject=My%20What%20Do%20We%20Stand%20For&body='></a><input style='display:BLOCK;width:250px;' onblur='fixmyemail(this.value,0);' type='email' id='myiemail' value='' title='Fill this in for emailed attachment'></input>
</div>
<div id=dito></div>

<a id=cemail style=display:none; href='mailto:?subject=&body=&cc=&bcc='>Email Canvas</a> 
<div id=dsnapshot></div>
<script language="JavaScript">


window.onload = function() {

cemailorig=document.getElementById('cemail').href;
elem = document.getElementById('canvaselement');
elemLeft = elem.offsetLeft;
elemTop = elem.offsetTop;
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) { 
 var ourdw = effectiveDeviceWidth();
 //alert(ourdw + " versus " + eval(threehundred * 2));
 if (eval(threehundred * 2) > eval(ourdw / 2)) threehundred = eval((ourdw * 2) / 9);
 elem.width = eval(threehundred * 2);
} 
context = elem.getContext('2d');
  
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();
  var hh = today.getHours();
  var minm = today.getMinutes(); //January is 0!
  var ss = today.getSeconds();
  
  if (document.getElementById('myfname2')) document.getElementById('myfname2').value = xlworld + "_" + yyyy + "_" + mm + "_" + hh + "_" + minm + "_" + ss + ".png"; 
  if (document.getElementById('myfname')) document.getElementById('myfname').value = xlworld + "_" + yyyy + "_" + mm + "_" + hh + "_" + minm + "_" + ss + ".png"; 


  if (document.getElementById('myform')) document.getElementById('myform').action = document.getElementById('myform').action.replace('?mode=1', '');
  if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
   if (document.getElementById('mode')) {
    document.getElementById('mode').value = '';
    document.getElementById('ismobile').value = 'y';
    document.getElementById('myisubject').style.display = 'inline';
    document.getElementById('myiemail').style.display = 'inline';
    document.getElementById('myform').action = document.getElementById('myform').action.replace('?mode=1', '');
    document.getElementById('myform').action = document.getElementById('myform').action.replace('mode=1', 'mode=');
    //document.getElementById('myemail').href = '#' + document.getElementById('myemail').href;
   }
  }

    elem = document.getElementById('canvaselement');
    context = elem.getContext("2d");
    //context.drawImage(img,0,0);
    elemLeft = elem.offsetLeft;
    elemTop = elem.offsetTop;
    // Add event listener for `click` events.
    document.body.addEventListener('click', function(event) {
       //document.getElementById('qm' + 'yf').style.position='sticky'; //'absolute';
       //document.getElementById('qm' + 'yf').style.top=getBodyScrollTop(); //document.body.style.scrollTop;
       //document.title='' + getBodyScrollTop(); //document.body.style.scrollTop;
elemLeft = elem.offsetLeft;
elemTop = elem.offsetTop;
       //if (allowc || 1 == 1) {
       if (eval(x) <= eval(elem.width) && eval(y) <= eval(elem.height) && allowc) {
       //document.title='top click';
       if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
       if (event.pageX || event.pageY) {
       x = event.pageX - elemLeft;
       y = event.pageY - elemTop;
       } else {
       x = event.clientX - elemLeft;
       y = event.clientY - elemTop;
       }
       lastx=x;
       lasty=y;
       } else {
       //document.title='nontop click';
       lastx=x;
       lasty=y;
       if (event.pageX || event.pageY) {
       x = event.pageX - elemLeft;
       y = event.pageY - elemTop;
       } else {
       x = event.clientX - elemLeft;
       y = event.clientY - elemTop;
       }
       }
       
    //alert('click');
       }
       
       elements.push({
        colour: '#ff0000',
        width: 5,
        height: 5,
        top: y,
        left: x
        });
        
    clickno = clickno + 1;

    
    if (1 == 2 && (x != lastx || y != lasty)) {
      document.getElementById('divannotation').style.display='block';
      document.getElementById('myisubject').style.display = 'inline';
      document.getElementById('myiemail').style.display = 'inline';
  }



    });
    //alert('set up click');
    
    drawt(); 
    allowc = false; 
    document.getElementById('topic').focus(); 
    };
    
 setTimeout(bp,3500);
</script>
<input type=hidden title='' value='' id=bci></input>
<iframe id=ifbc style='display:none;' src='//www.rjmprogramming.com.au/About_Us.html' onload='ifbcf(this);'></iframe>
<iframe id=ifmamp name=ifmamp style='display:none;' src='//www.rjmprogramming.com.au/About_Us.html'></iframe>
<a style=display:none; id=bemail target=_top href='mailto:<?php echo $mto . "subject=Slide%20" . urlencode(basename($thingo)) . "%20in%20clipboard%20ready%20for%20you%20to%20paste%20as%20attachment%20below&20" . $subjsuff . "%20...&body="; ?>'>Email</a>

<script type='text/javascript' src='world.js' defer></script>

</body>
</html>

<?php


exit;


$cont=file_get_contents($ourpath . str_replace("+"," ",urldecode($_GET['filename'])));

if (strpos($cont, "data:") !== false) {

 // "plonk" these in HTML surrounds supporting the relevant (mimetype derived (via file extension array matching)) element's src property contents

if (strpos($cont, "data:image/") !== false) {

echo '<html><body><img src="';

passthru('pbpaste');

echo '"></img></body></html>';

} else if (strpos($cont, "data:video/") !== false) {

if ($ourmimetype == "") {

echo '<html><body><video controls><source src="';

} else {

echo '<html><body><video controls><source type="' . $ourmimetype . '" src="';

}

passthru('pbpaste');

echo '"></source></video></body></html>';

} else if (strpos($cont, "data:audio/") !== false) {

if ($ourmimetype == "") {

echo '<html><body><audio controls><source src="';

} else {

echo '<html><body><audio controls><source type="' . $ourmimetype . '" src="';

}

passthru('pbpaste');

echo '"></source></audio></body></html>';

} else if (strpos($cont, "data:text/") !== false) {

header('Content-type: text/' . str_replace('jpg','jpeg',$ext));

passthru('pbpaste');

} else if ($ourpath == '' && $ourmimetype == '') {

header('Location: ' . str_replace("+"," ",urldecode($_GET['filename'])));

} else if ($ourmimetype != '') {

header('Content-type: ' . $ourmimetype);

passthru('pbpaste');

} else {

header('Location: ' . str_replace("+"," ",urldecode($_GET['filename'])));

}

} else if ($ourmimetype != '') {  // we know mimetype via file extension

 header('Content-type: ' . $ourmimetype);

 passthru('pbpaste');

} else {

 header('Location: ' . str_replace("+"," ",urldecode($_GET['filename'])));

}

?>
