<html>
<head>
<title>Using Javascript Map Object - RJM Programming - August, 2024 ... thanks to https://www.w3schools.com/js/tryit.asp?filename=tryjs_map_groupby and https://medium.com/@sotoer/your-foreach-example-has-the-wrong-order-of-params-which-you-are-also-demonstrating-in-your-sample-42f5491b604e</title>
<style>
body {
background-color: #f9f9f9;
}

table {
background-color: #f0f0d0;
}

td {
vertical-align: top;
background-color: #ffffff;
}

#demo, #droppable {
background-color: yellow;
}

input[type=number] {
background-color: lightgreen;
}

th:not([colspan=4]) {
background-color: #d0f0f0;
}

select {
background-color: lightblue;
}
</style>
<script type=text/javascript>

var m = new Map();
//m.set('b', 2);
//m.set('a', 1);
//m.forEach((k, v, m) => console.log(`key:${k} value:${v} map:${m}`));

var undone=false;
var wheres=[];
var orderbys=[];
var wheresn=[];
var orderbysn=[];
var ors=[];
var ands=[];
var mappings=[];
eval('mappings.push({ from: "1", to:"' + 'Name' + '"})');
eval('mappings.push({ from: "2", to:"' + 'Quantity' + '"})');
var fromplace='';
var sqlis='';

var lasttr='';
var ify=0;
var compositename='';
var compositequantity='';
var elines=[];
var eelines=[];
var efields=[];
var goselv='';
var outv='';

var tippingpoint=200;
var tabletds='';
var rspan=1;
var doadd=false;
var text="";
var ddone=false;
var okaytext="These fruits are Ok:<br>";
var lowtext="<br>These fruits are low:<br>";
var lowword="low";
var okayword="ok";
var altered=false;
var thiscont='';
var geovalis='';
var aconto=null;
var rawhtml='';
var zhr=null;

var enterall='';

// Fish~`~taylor,300;barramundi,400;perch,100;mullet,234
// https://www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php?title=Country%20Populations&onclick=y&task=Country&desc=Populations&data=,%20[~https;China,1347000000,India,1241000000,United%20States,312000000,Indonesia,238000000,Brazil,197000000,Pakistan,177000000,Nigeria,162000000,Bangladesh,151000000,Russia,143000000,Japan,128000000,Mexico,115000000,Philippines,96000000,Vietnam,88000000,Ethiopia,87000000,Germany,81800000,Egypt,82600000,Iran,78000000,Turkey,74000000,Thailand,69500000,Congo,67800000,France,63300000,United%20Kingdom,62700000,Italy,60800000~,100]" href="https://www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php?title=Country%20Populations&onclick=y&task=Country&desc=Population&data=,%20[~https;China,1347000000,India,1241000000,United%20States,312000000,Indonesia,238000000,Brazil,197000000,Pakistan,177000000,Nigeria,162000000,Bangladesh,151000000,Russia,143000000,Japan,128000000,Mexico,115000000,Philippines,96000000,Vietnam,88000000,Ethiopia,87000000,Germany,81800000,Egypt,82600000,Iran,78000000,Turkey,74000000,Thailand,69500000,Congo,67800000,France,63300000,United%20Kingdom,62700000,Italy,60800000~,100]" target="_blank">https://www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php?title=Country%20Populations&onclick=y&task=Country&desc=Populations&data=,%20[~https;China,1347000000,India,1241000000,United%20States,312000000,Indonesia,238000000,Brazil,197000000,Pakistan,177000000,Nigeria,162000000,Bangladesh,151000000,Russia,143000000,Japan,128000000,Mexico,115000000,Philippines,96000000,Vietnam,88000000,Ethiopia,87000000,Germany,81800000,Egypt,82600000,Iran,78000000,Turkey,74000000,Thailand,69500000,Congo,67800000,France,63300000,United%20Kingdom,62700000,Italy,60800000~,100]
// http://www.rjmprogramming.com.au/PHP/HistogramChart/histogram_chart.php?title=huh&onclick=y&task=Number&desc=Count&data=,[~11~,184],[~21~,182],[~27~,142],[~36~,147],[~62~,79],[~24~,187],[~14~,184],[~18~,183],[~49~,109],[~67~,72],[~31~,124],[~43~,103],[~47~,127],[~20~,181],[~06~,167],[~30~,132],[~53~,118],[~56~,116],[~19~,178],[~05~,168],[~23~,186],[~40~,121],[~50~,114],[~37~,126],[~52~,123],[~58~,115],[~10~,181],[~44~,120],[~01~,171],[~03~,176],[~13~,164],[~26~,158],[~45~,126],[~65~,64],[~28~,149],[~02~,169],[~42~,109],[~55~,120],[~32~,155],[~33~,145],[~16~,166],[~48~,113],[~15~,157],[~17~,172],[~63~,90],[~07~,170],[~04~,169],[~51~,111],[~54~,127],[~57~,115],[~60~,62],[~69~,82],[~08~,170],[~12~,176],[~41~,125],[~46~,108],[~61~,93],[~34~,116],[~38~,122],[~39~,147],[~35~,118],[~22~,171],[~66~,70],[~25~,167],[~68~,75],[~09~,161],[~64~,82],[~59~,131],[~29~,131]
// https://www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=World%20Map&width=834&height=520&country=Country&popularity=Popularity&data=%20[~IT~,2]

// Create an Array
var fruits = [
{name:"apples", quantity:300},
{name:"bananas", quantity:500},
{name:"oranges", quantity:200},
{name:"kiwi", quantity:150}
];

var fruity = [
{name:"apples", quantity:"300"},
{name:"bananas", quantity:"500"},
{name:"oranges", quantity:"200"},
{name:"kiwi", quantity:"150"}
];


// Callback function to select low volumes
function myCallback({ quantity }) {
return (('' + quantity).trim() == '' ? 0 : eval(('' + quantity).split(',')[0])) > eval('' + tippingpoint) ? okayword : lowword;
}

function asit(inid) {
var sdfa=inid.split(' as ');
if (eval('' + sdfa.length) > 1) {
return sdfa[eval(-1 + sdfa.length)];
}
return inid;
}

function alertsql() {
var ij=0, jk=0;
console.log(mappings);
sqlis='SELECT ';
if (document.getElementById('thname').innerHTML == 'Name' && document.getElementById('thquantity').innerHTML == 'Quantity') {
sqlis+=document.getElementById('thname').innerHTML;
sqlis+=',' + document.getElementById('thquantity').innerHTML + ' ';
} else {
if (document.getElementById('thquantity').innerHTML.indexOf(',') != -1) {
sqlis+=document.getElementById('thname').innerHTML;
console.log(mappings);
sqlis+=',' + document.getElementById('thquantity').innerHTML;
} else {
sqlis+=document.getElementById('thname').innerHTML;
sqlis+=',(' + document.getElementById('thquantity').innerHTML + ') as field2 ';
}
}
if (fromplace.trim() != '') {
sqlis+=' FROM ' + fromplace + ' ';
}
if (eval('' + wheres.length) > 0) {
console.log(wheres);
for (ij=0; ij<wheres.length; ij++) {
wheresn.push(wheres[ij]);
for (jk=0; jk<mappings.length; jk++) {
wheres[ij]=asit(wheres[ij].replace(' ' + mappings[jk].from, ' ' + mappings[jk].to));
}
console.log(wheres);
if (ij == 0) {
sqlis+=' WHERE ' + wheres[ij].trim().replace(/^\!/g, ' NOT ') + ' ';
} else {
sqlis+=' AND ' + wheres[ij].trim().replace(/^\!/g, ' NOT ') + ' ';
}
}
}
if (eval('' + orderbys.length) > 0) {
for (ij=0; ij<orderbys.length; ij++) {
ordersbyn.push(ordersby[ij]);
for (jk=0; jk<mappings.length; jk++) {
orderbys[ij]=asit(orderbys[ij].replace(' ' + mappings[jk].from, ' ' + mappings[jk].to));
}
if (ij == 0) {
if (orderbys[ij].indexOf('~') != -1) {
sqlis+=' ORDER BY ' + orderbys[ij].trim().replace(/\~/g, '').replace(/\`/g, '') + ' ASC ';
} else {
sqlis+=' ORDER BY ' + orderbys[ij].trim().replace(/\~/g, '').replace(/\`/g, '') + ' DESC ';
}
} else {
if (orderbys[ij].indexOf('~') != -1) {
sqlis+=' AND ' + orderbys[ij].trim().replace(/\~/g, '').replace(/\`/g, '') + ' ASC ';
} else {
sqlis+=' AND ' + orderbys[ij].trim().replace(/\~/g, '').replace(/\`/g, '') + ' DESC ';
}
}
}
}
//document.title=sqlis;
//var xsew=prompt(sqlis, '');
document.body.title=sqlis;
}

function mappingsget(what) {
var ij;
//alert('mappings.length=' + mappings.length);
for (ij=0; ij<mappings.length; ij++) {
if (('' + mappings[ij].from) == ('' + what)) {
return true;
}
}
return false;
}

function doalias(twocomp) {
if (!mappingsget("2") || undone) {
//alert('(' + twocomp + ') as field2');
eval('mappings.unshift({ from: "2", to:"' + '(' + twocomp + ') as field2' + '"})');
undone=false;
} else if (1 == 6 && eval('' + mappings.length) == 0) {
//alert(1);
eval('mappings.push({ from: "1", to:"' + 'Name' + '"})');
//alert(11);
eval('mappings.push({ from: "2", to:"' + '(' + twocomp + ') as field2' + '"})');
} else if (1 == 6 && eval('' + mappings.length) == 1) {
//alert(2);
eval('mappings.push({ from: "2", to:"' + '(' + twocomp + ') as field2' + '"})');
} else if (1 == 6) {
//alert(3);
eval('mappings.unshift({ from: "2", to:"' + '(' + twocomp + ') as field2' + '"})');
}
}

function mysimpleCallback(qty) {
//alert(qty);
return (('' + qty).trim() == '' ? 0 : eval(('' + qty).split(',')[0])) > eval('' + tippingpoint) ? okayword : lowword;
}

function maybenotdefn(inidea) {
var startcn=compositename, outidea=inidea, fieldnum='', ii;
if (eval('' + efields.length) > 0) {
efields[eval(-1 + efields.length)]=efields[eval(-1 + efields.length)].split(' //')[0].split('// ')[0];
}
if (compositename != '') {
outidea='';
while (startcn != '') {
fieldnum='' + startcn.split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0];
if (!mappingsget(fieldnum)) {
for (ii=fieldnum; ii>=1; ii--) {
if (!mappingsget(ii)) {
//if (ii == 1) { alert('Oops'); }
eval('mappings.push({ from: "' + fieldnum + '", to: "field' + ii + '" })');
}
}
}
startcn=startcn.replace(fieldnum,'');
outidea+=('' + efields[eval(-1 + eval('' + fieldnum))]).replace(/\,/g,' ').substring(0,1).toUpperCase() + ('' + efields[eval(-1 + eval('' + fieldnum))] + ' ').replace(/\,/g,' ').substring(1).replace(/\ $/g,'').toLowerCase();
if (startcn != '') {
if (startcn.substring(1) != '') {
outidea+=',';
startcn=startcn.substring(1);
} else {
startcn='';
}
}
}
return outidea;
}
return inidea;
}

function maybenotdefq(inidea) {
var startcn=compositequantity, outidea=inidea, fieldnum='';
if (eval('' + efields.length) > 0) {
efields[eval(-1 + efields.length)]=efields[eval(-1 + efields.length)].split(' //')[0].split('// ')[0];
}
if (compositequantity != '') {
outidea='';
while (startcn != '') {
fieldnum='' + startcn.split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0];
if (!mappingsget(fieldnum)) {
for (ii=fieldnum; ii>=1; ii--) {
if (!mappingsget(ii)) {
//if (ii == 1) { alert('OOps'); }
eval('mappings.push({ from: "' + fieldnum + '", to: "field' + ii + '" })');
}
}
}
startcn=startcn.replace(fieldnum,'');
outidea+=('' + efields[eval(-1 + eval('' + fieldnum))]).replace(/\,/g,' ').substring(0,1).toUpperCase() + ('' + efields[eval(-1 + eval('' + fieldnum))] + ' ').replace(/\,/g,' ').substring(1).replace(/\ $/g,'').toLowerCase();
if (startcn != '') {
if (startcn.substring(1) != '') {
outidea+=',';
startcn=startcn.substring(1);
} else {
startcn='';
}
}
}
return outidea;
}
return inidea;
}

function maybenotvaln(inidea) {
var startcn=compositename, outidea=inidea, fieldnum='';
if (eval('' + efields.length) > 0) {
efields[eval(-1 + efields.length)]=efields[eval(-1 + efields.length)].split(' //')[0].split('// ')[0];
}
if (compositename != '') {
//console.log('fruity.length=' + fruity.length);
if (eval('' + fruity.length) > 0) {
for (var ijk=0; ijk<fruity.length; ijk++) {
if (('' + inidea).split(',')[0] == ('' + fruity[ijk].name).split(',')[0]) {
return ('' + fruity[ijk].name);
}
}
}
outidea='';
while (startcn != '') {
fieldnum='' + startcn.split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0];
if (!mappingsget(fieldnum)) {
for (ii=fieldnum; ii>=1; ii--) {
if (!mappingsget(ii)) {
//if (ii == 1) { alert('OoPs'); }
eval('mappings.push({ from: "' + fieldnum + '", to: "field' + ii + '" })');
}
}
}
startcn=startcn.replace(fieldnum,'');
outidea+=('' + efields[eval(-1 + eval('' + fieldnum))]).replace(/\,/g,' ');
if (startcn != '') {
if (startcn.substring(1) != '') {
outidea+=',';
startcn=startcn.substring(1);
} else {
startcn='';
}
}
}
return outidea;
}
return inidea;
}

function maybenotvalq(injdea, injdean) {
var startcn=compositequantity, outjdea=injdea, fieldnum='', isnotanumber=true, isthenumber=0, lastop=' ', istwonumber=0;
if (eval('' + efields.length) > 0) {
efields[eval(-1 + efields.length)]=efields[eval(-1 + efields.length)].split(' //')[0].split('// ')[0];
}
if (compositequantity != '') {
//console.log('fruity.length=' + fruity.length);
if (eval('' + fruity.length) > 0 && 7 == 7) {
for (var ijk=0; ijk<fruity.length; ijk++) {
if (('' + injdean).split(',')[0] == ('' + fruity[ijk].name).split(',')[0]) {
//alert(injdea + ' and ' + ('' + fruity[ijk].quantity));
if (('' + fruity[ijk].quantity).indexOf(',') != -1 && thqit(compositequantity) != '') { return ('' + fruity[ijk].quantity); }
if (('' + fruity[ijk].quantity).indexOf(',') == -1 && ('' + injdea) != ('' + fruity[ijk].quantity) && thqit(compositequantity) == '') { return ('' + fruity[ijk].quantity); }
}
}
}
outjdea='';
while (startcn != '') {
fieldnum='' + startcn.split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0];
if (!mappingsget(fieldnum)) {
for (ii=fieldnum; ii>=1; ii--) {
if (!mappingsget(ii)) {
//if (ii == 1) { alert('OopS'); }
eval('mappings.push({ from: "' + fieldnum + '", to: "field' + ii + '" })');
}
}
}
if (1 == 1) {
if (fieldnum.trim() == '') { isnotanumber=true; } else if (!isnotanumber || lastop.trim() == '') { isnotanumber=isNaN('' + fieldnum); }
if (!isnotanumber && lastop.trim() == '') {
isthenumber=efields[-1 + eval('' + fieldnum)];
isnotanumber=isNaN('' + isthenumber);
if (!isnotanumber) { isthenumber=eval('' + isthenumber); }
} else if (!isnotanumber && (lastop == '+' || lastop == '-' || lastop == '*' || lastop == '/' || lastop == '%')) {
istwonumber=efields[-1 + eval('' + fieldnum)];
isnotanumber=isNaN('' + istwonumber);
if (!isnotanumber) { istwonumber=eval('' + istwonumber); }
if (!isnotanumber) {
if (lastop == '+') {
isthenumber+=eval('' + istwonumber);
} else if (lastop == '-') {
isthenumber-=eval('' + istwonumber);
} else if (lastop == '*') {
isthenumber*=eval('' + istwonumber);
} else if (lastop == '/') {
isthenumber/=eval('' + istwonumber);
} else if (lastop == '%') {
isthenumber%=eval('' + istwonumber);
} else if (lastop == '^') {
isthenumber^=eval('' + istwonumber);
} else {
isnotanumber=true;
lastop=',';
}
}
}
}
startcn=startcn.replace('' + fieldnum,'');
if (eval('' + efields.length) > eval(-1 + eval('' + fieldnum))) {
outjdea+=('' + efields[eval(-1 + eval('' + fieldnum))]).replace(/\,/g,' ');
}
if (startcn != '') {
if (startcn.substring(1) != '') {
outjdea+=',';
lastop=startcn.substring(0,1).replace('&',',');
startcn=startcn.substring(1);
} else {
startcn='';
}
}
}
if (!isnotanumber && lastop.replace(' ','&').replace(',','&') != '&') { document.getElementById('thquantity').innerHTML=document.getElementById('thquantity').innerHTML.replace(/\,/g,lastop); doalias(document.getElementById('thquantity').innerHTML); return '' + isthenumber + ','; }
//alert('outjdea=' + outjdea + ' and efields.length=' + efields.length + ' and injdea=' + injdea + ' and compositequantity=' + compositequantity);
return outjdea;
}
return injdea;
}

function process(what) {
document.getElementById('demo').innerHTML=thiscont;
fruits=[];
fruity=[];
m = new Map();
alteredstate(document.getElementById('demo'), true);
return thiscont;
}

function andthendo(inthing) {
document.getElementById('thname').innerHTML=location.search.split('thname=')[1] ? decodeURIComponent(location.search.split('thname=')[1].split('&')[0].split('#')[0]) : document.getElementById('thname').innerHTML;
document.getElementById('thquantity').innerHTML=location.search.split('thquantity=')[1] ? decodeURIComponent(location.search.split('thquantity=')[1].split('&')[0].split('#')[0]) : document.getElementById('thquantity').innerHTML;
document.getElementById('topic').innerHTML=location.search.split('topic=')[1] ? decodeURIComponent(location.search.split('topic=')[1].split('&')[0].split('#')[0]) : document.getElementById('topic').innerHTML;
document.getElementById('threport').innerHTML=location.search.split('threport=')[1] ? decodeURIComponent(location.search.split('threport=')[1].split('&')[0].split('#')[0]) : document.getElementById('threport').innerHTML;
return inthing;
}

function moreencodeURIComponent(intodo) {
var indemo=null;
outstuff=encodeURIComponent(intodo);
indemo=document.getElementById('thname');
if (outstuff == '') {
outstuff+='?thname=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&thname=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('thquantity');
if (outstuff == '') {
outstuff+='?thquantity=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&thquantity=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('topic');
if (outstuff == '') {
outstuff+='?topic=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&topic=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('threport');
if (outstuff == '') {
outstuff+='?threport=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&threport=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
return outstuff;
}

function alteredstate(indemo, readd) {
var reprecs=[], ireprecs=0, recwords=[];
//alert(('' + (indemo.innerText | indemo.contentWindow | indemo.contentDocument)) + ' vs ' + indemo.innerHTML);
var theses=('' + (indemo.innerHTML)).split('These ');
if (eval('' + theses.length) == 3) {
//alert('Ok oOps=' + theses.length + ' and fruits.length=' + fruits.length);
if (theses[1].indexOf(':') != -1 && theses[2].indexOf(':') != -1) {
//alert('Okay oOps=' + theses.length);
altered=true;
okaytext='These ' + theses[1].split(':')[0] + ':<br>';
lowtext='<br>These ' + theses[2].split(':')[0] + ':<br>';
if (theses[1].indexOf(' are ') != -1) {
//alert('Yes ' + okaytext);
document.getElementById('topic').innerHTML=theses[1].split(' are ')[0].substring(0,1).toUpperCase() + theses[1].split(' are ')[0].substring(1).toLowerCase().replace(/s$/g,'');
okayword=theses[1].split(' are ')[1].split(':')[0].toLowerCase();
document.getElementById('spanok').innerHTML=theses[1].split(' are ')[1].split(':')[0];
document.getElementById('itip').step=0.001;
if (('' + readd).replace(/^undefined$/g, '') != '') {
//alert('yes ' + okaytext.replace('These ','') + ' RE ' + theses[1]);
//alert(theses[1].split(okaytext.replace('These ',''))[1].split('<br>These ')[0]);
reprecs=theses[1].split(okaytext.replace('These ',''))[1].split('<br>These ')[0].split('<br>');
for (ireprecs=0; ireprecs<reprecs.length; ireprecs++) {
recwords=reprecs[ireprecs].split(' ');
if (eval('' + recwords.length) > 1) {
if (reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() != '') {
//alert('ok: ' + reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() + ' and fruits.length=' + fruits.length);
if (reprecs[ireprecs].indexOf(',') != -1) { efields=reprecs[ireprecs].split(','); }
//alert('reprecs[ireprecs]=' + reprecs[ireprecs]);
addone(reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim(), recwords[eval(-1 + recwords.length)]);
}
}
}
}
}
if (theses[2].indexOf(' are ') != -1) {
document.getElementById('topic').innerHTML=theses[2].split(' are ')[0].substring(0,1).toUpperCase() + theses[2].split(' are ')[0].substring(1).toLowerCase().replace(/s$/g,'');
lowword=theses[2].split(' are ')[1].split(':')[0].toLowerCase();
document.getElementById('spanlow').innerHTML=theses[2].split(' are ')[1].split(':')[0];
document.getElementById('itip').step=0.001;
if (('' + readd).replace(/^undefined$/g, '') != '') {
reprecs=theses[2].split(lowtext.replace('<br>These ',''))[1].split('<br>');
for (ireprecs=0; ireprecs<reprecs.length; ireprecs++) {
recwords=reprecs[ireprecs].split(' ');
if (eval('' + recwords.length) > 1) {
if (reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() != '') {
//alert('low: ' + reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() + ' and fruits.length=' + fruits.length);
if (reprecs[ireprecs].indexOf(',') != -1) { efields=reprecs[ireprecs].split(','); }
//alert('reprecs[ireprecs] =' + reprecs[ireprecs]);
addone(reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim(), recwords[eval(-1 + recwords.length)]);
}
}
}
}
}
}
}
if (('' + readd).replace(/^undefined$/g, '') != '') {
document.getElementById('itip').value=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
tippingpoint=eval('' + document.getElementById('itip').value);
beadjustable();
}
}

function addone(knownname, knownquantity) {
doadd=true;
var kval='';
var qval='';
//alert(knownname);
//alert(knownquantity);
if (('' + knownname) != 'undefined' && ('' + knownquantity) != 'undefined') {
if (('' + knownquantity).indexOf(',') != -1 || ('' + knownname).indexOf(',') != -1) {
fruits.push({name:knownname, quantity:eval(('' + knownquantity).split(',')[0])});
qval=maybenotvalq(('' + knownquantity), knownname);
fruity.push({name:maybenotvaln(knownname), quantity:qval});
m.set(maybenotvaln(knownname), qval);
} else {
fruits.push({name:knownname, quantity:knownquantity});
qval=maybenotvalq(('' + knownquantity), knownname);
fruity.push({name:maybenotvaln(knownname), quantity:qval});
m.set(maybenotvaln(knownname), qval);
}
} else if (('' + knownname) != 'undefined') {
fruits.push({name:knownname, quantity:0});
fruity.push({name:knownname, quantity:"0"});
m.set(maybenotvaln(knownname), maybenotvalq("0",knownname));
} else {
fruits.push({name:"", quantity:0});
qval=0; //maybenotvalq("0","");
fruity.push({name:"", quantity:qval});
m.set('', qval);
setTimeout(function(){ if (document.getElementById('tdquantity' + fruity.length)) { document.getElementById('tdquantity' + fruity.length).innerHTML='0'; } if (document.getElementById('tdname' + fruity.length)) { document.getElementById('tdname' + fruity.length).scrollIntoView(); } }, 3000);
}
doadd=false;
beadjustable();
}

function fix(tdo) {
var idx=0, needto=true;
if (tdo.id.indexOf('tdname') == 0) {
if (tdo.id != 'tdname') { idx=eval(('' + tdo.id).substring(6)); idx--; }
while (!fruits[idx]) { fruits.push({name:'',quantity:0}); fruity.push({name:'',quantity:0}); }
fruits[idx].name=('' + tdo.innerHTML).split(',')[0];
fruity[idx].name=('' + tdo.innerHTML);
if (m.has("")) {
m.delete("");
m.set(fruity[idx].name, fruity[idx].quantity);
tdo.setAttribute('contenteditable', false);
}
if (needto) { beadjustable(); }
} else {
if (tdo.id != 'tdquantity') { idx=eval(('' + tdo.id).substring(10)); idx--; }
//alert(tdo.outerHTML);
//alert('idx=' + idx + ' and ' + ('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument)) + ' and fruits[idx].name=' + fruits[idx].name);
if (m.has(fruity[idx].name)) {
if (('' + fruity[idx].quantity) == ('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument))) { needto=false; }
}
if (needto) {
while (!fruits[idx]) { fruits.push({name:'',quantity:0}); fruity.push({name:'',quantity:0}); }
fruits[idx].quantity=('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument)).split(',')[0];
fruity[idx].quantity=('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument));
if (m.has(fruits[idx].name)) {
m.set(fruity[idx].name, fruity[idx].quantity);
}
}
if (needto) { beadjustable(); }
}
}

function thecall() {
var kk=0;

// Group by ok and low
if (altered) {
text=okaytext;
} else {
text="These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are Ok:<br>";
}
try {
const result = Map.groupBy(fruity, myCallback);

// Display Results
try {
for (let x of result.get(okayword)) {
if (x.name != '' || x.quantity != 0) {
text += "" + x.name.split(',')[0] + " " + x.quantity.split(',')[0] + "<br>";
}
if (!m.has(x.name)) {
m.set(x.name, x.quantity);
}
}
} catch(ebad) { }
if (altered) {
text+=lowtext;
} else {
text += "<br>These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are low:<br>";
}
try {
for (let x of result.get(lowword)) {
if (x.name != '' || x.quantity != 0) {
text += "" + x.name.split(',')[0] + " " + x.quantity.split(',')[0] + "<br>";
}
if (!m.has(x.name)) {
m.set(x.name, x.quantity);
}
}
//console.log(result.get(okayword));
} catch(ebad) { }
} catch(overebad) {
if (altered) {
text=okaytext;
} else {
text="These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are Ok:<br>";
}
for (kk=0; kk<fruity.length; kk++) {
if (('' + fruity[kk].quantity).replace('-','').substring(0,1) >= '0' && ('' + fruity[kk].quantity).replace('-','').substring(0,1) <= '9') {
//alert('fruity[kk].quantity=' + fruity[kk].quantity);
if (mysimpleCallback(fruity[kk].quantity) == 'ok') {
//alert(fruity[kk].name);
text += "" + fruity[kk].name.split(',')[0] + " " + fruity[kk].quantity.split(',')[0] + "<br>";
//alert('2:' + fruity[kk].name);
if (!m.has(fruity[kk].name)) {
//alert('3:' + fruity[kk].name);
m.set(fruity[kk].name, fruity[kk].quantity);
//alert('4:' + fruity[kk].name);
}
}
}
}
if (altered) {
text+=lowtext;
} else {
text += "<br>These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are low:<br>";
}
for (kk=0; kk<fruity.length; kk++) {
if (('' + fruity[kk].quantity).replace('-','').substring(0,1) >= '0' && ('' + fruity[kk].quantity).replace('-','').substring(0,1) <= '9') {
if (mysimpleCallback(fruity[kk].quantity) == 'low') {
text += "" + fruity[kk].name.split(',')[0] + " " + fruity[kk].quantity.split(',')[0] + "<br>";
if (!m.has(fruity[kk].name)) {
m.set(fruity[kk].name, fruity[kk].quantity);
}
}
}
}

}
document.getElementById("demo").innerHTML = text;

}

function maybetr(inid) {
var rrspan='' + rspan + ' ';
if (tabletds.replace('' + rrspan, '').replace('' + rrspan, '').indexOf(inid.replace('' + rrspan, '').replace('' + rrspan, '')) != -1 || ('' + inid).indexOf('undefined') != -1) {
//alert(22);
return '';
}
if (lasttr.replace('' + rrspan, '').replace('' + rrspan, '') == inid.replace('' + rrspan, '').replace('' + rrspan, '')) {
//alert(2);
return '';
}
//if (lasttr.indexOf('1.601554') != -1 && inid.indexOf('1,601554') != -1) {
// alert(rrspan + ' ' + lasttr + ' ... ' + inid);
//}
if (lasttr.replace('' + rrspan, '').replace('' + rrspan, '').indexOf(inid.replace('' + rrspan, '').replace('' + rrspan, '').split('</td>')[0]) != -1) {
return '';
var thistr=inid.split('</td>')[0] + '</td>' + lasttr.split(inid.split('</td>')[0] + '</td>')[1];
var newlast=thistr.split('</td></tr>')[0] + ',' + inid.split('</td></tr>')[0].split('>')[eval(-1 + inid.split('</td></tr>')[0].split('>').length)] + '</td></tr>';
//alert('found ' + thistr + ' via inid=' + inid + ' and newlast=' + newlast + ' ' + tabletds.length + ' ' + tabletds.replace(lasttr, newlast).length);
tabletds=tabletds.replace(thistr, newlast);
lasttr=newlast;
return '';
}
lasttr=inid;
return inid;
}

function consolelog(inrec) {
// console.log('' + inrec);
var interim='';
var dl='';
if (eval('' + eelines.length) > ify) {
efields=eelines[ify].split(',');
dl=''; //' title="' + eelines[ify] + '"';
}
if (rspan == 0 || document.getElementById("tdname").innerHTML == '') {
document.getElementById("tdname").innerHTML=maybenotvaln(inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]);
interim=maybenotvalq(inrec.split('key:')[1].split(' value:')[0].split(' map:')[0], inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]);
//alert(interim);
document.getElementById("tdquantity").innerHTML=interim; //maybenotvalq(inrec.split('key:')[1].split(' value:')[0].split(' map:')[0], document.getElementById("tdname").innerHTML);
document.getElementById("tdquantity").title=interim; //maybenotvalq(inrec.split('key:')[1].split(' value:')[0].split(' map:')[0], document.getElementById("tdname").innerHTML);
rspan=1;
} else if (inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] == '') {
interim=maybenotvalq(inrec.split('key:')[1].split(' value:')[0].split(' map:')[0], inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]);
tabletds+=maybetr('<tr' + dl + '><td contenteditable=true id=tdname' + rspan + ' onblur=fix(this);>' + maybenotvaln(inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]) + '</td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this); title="' + inrec.split('key:')[1].split(' value:')[0].split(' map:')[0] + ',' + inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] + '">' + interim + '</td></tr>');
rspan++;
// console.log('here1:' + rspan);
} else {
interim=maybenotvalq(inrec.split('key:')[1].split(' value:')[0].split(' map:')[0], inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]);
tabletds+=maybetr('<tr' + dl + '><td contenteditable=false id=tdname' + rspan + ' onblur=fix(this);>' + maybenotvaln(inrec.split('value:')[1].split(' key:')[0].split(' map:')[0]) + '</td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this); title="' + inrec.split('key:')[1].split(' value:')[0].split(' map:')[0] + ',' + inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] + '">' + interim + '</td></tr>');
rspan++;
// console.log('here2:' + rspan);
}
//alert(inrec);
if (doadd) {
fruits.push({name:"", quantity:0});
fruity.push({name:maybenotvaln(""), quantity:maybenotvalq('0','')});
m.set('', 0);
tabletds+=maybetr('<tr' + dl + '><td contenteditable=true id=tdname' + rspan + ' onblur=fix(this);>' + maybenotvaln('') + '</td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this); title="">' + maybenotvalq('0','') + '</td></tr>');
rspan++;
// console.log('here3:' + rspan);
doadd=false;
}
ify++;
}

function dragElement(elmnt) { // thanks to https://www.w3schools.com/howto/howto_js_draggable.asp
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}

function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}

function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
alert('Here');
}

function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}


function allowDrop(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
ev.preventDefault();
}

function drag(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
ev.dataTransfer.setData("text", ev.target.id);
}

function doemail(data) {
var a=null;
a = document.createElement("a");
var contis=(document.getElementById('demo').innerText || document.getElementById('demo').contentWindow || document.getElementById('demo').contentDocument);
var topicis=(document.getElementById('topic').innerText || document.getElementById('topic').contentWindow || document.getElementById('topic').contentDocument);
var subjis=(document.getElementById('threport').innerText || document.getElementById('threport').contentWindow || document.getElementById('threport').contentDocument);
a.href='mailto:?subject=' + encodeURIComponent(topicis) + '%20' + encodeURIComponent(subjis) + '&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + '?tippingvalue=' + moreencodeURIComponent(document.getElementById('itip').value) + '#data=') + encodeURIComponent(encodeURIComponent(contis.replace(/\<bJUNKr\>/g, String.fromCharCode(10))));
a.click();
}

function dosms(data) {
var a=null;
a = document.createElement("a");
var contis=(document.getElementById('demo').innerText || document.getElementById('demo').contentWindow || document.getElementById('demo').contentDocument);
var topicis=(document.getElementById('topic').innerText || document.getElementById('topic').contentWindow || document.getElementById('topic').contentDocument);
a.href='sms:&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + '?tippingvalue=' + moreencodeURIComponent(document.getElementById('itip').value) + '#data=') + encodeURIComponent(encodeURIComponent(contis.replace(/\<bJUNKr\>/g, String.fromCharCode(10))));
a.click();
}

function drop(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
var ssrect=null, isemail=true, a=null;
ssrect=document.getElementById('droppable').getBoundingClientRect();
if (eval(ssrect.right - ev.clientX) < eval(ev.clientX - ssrect.left)) { isemail=false; }
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
if (isemail) {
//a = document.createElement("a");
//a.href='mailto:?subject=' + encodeURIComponent(document.getElementById('topic').innerHTML) + '%20Report%20of%20Inventory&body=' + encodeURIComponent(document.getElementById(data).innerHTML.replace(/\<bJUNKr\>/g, String.fromCharCode(10)));
//a.click();
doemail(data);
} else if (!isemail) {
//a = document.createElement("a");
//a.href='sms:&body=' + encodeURIComponent(document.getElementById(data).innerHTML.replace(/\<bJUNKr\>/g, String.fromCharCode(10)));
//a.click();
dosms(data);
} else {
ev.target.appendChild(document.getElementById(data));
}
}

function weedout(intrs) {
var outrs=intrs, ju=2, vsju=2;
var trlines=intrs.split('</td></tr>');
if (eval('' + trlines.length) > 1) {
outrs='';
if (trlines[0].split('</td>')[0].split('>')[eval(-1 + trlines[0].split('</td>')[0].split('>').length)] != document.getElementById('tdname').innerHTML) { outrs+=trlines[0].replace(/\,$/g,'') + '</td></tr>'; }
for (var iu=1; iu<trlines.length; iu++) {
if (trlines[iu].trim().indexOf('tdname') != -1 && trlines[iu].split('</td>')[0].split('>')[eval(-1 + trlines[iu].split('</td>')[0].split('>').length)] != trlines[-1 + iu].split('</td>')[0].split('>')[eval(-1 + trlines[-1 + iu].split('</td>')[0].split('>').length)]) {
//alert(trlines[iu]);
vsju=trlines[iu].split('tdname')[1].split(' ')[0];
outrs+=trlines[iu].replace('tdname' + vsju + ' ', 'tdname' + ju + ' ').replace('tdquantity' + vsju + ' ', 'tdquantity' + ju + ' ') + '</td></tr>';
ju++;
}
}
}
return outrs;
}


function beadjustable() {
var srect=null;
var tpis=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
if (!ddone) {
ddone=true;
if (('' + location.hash).indexOf('#data') == 0) {
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
thiscont=decodeURIComponent(('' + location.hash).substring(5).replace(/^\=/g,'').replace(/^\%3d/g,'').replace(/^\%3D/g,'').replace(/\%0A/g,encodeURIComponent('<br>')));
setTimeout(function(){ document.getElementById('tdname').innerHTML=''; document.getElementById('tdquantity').innerHTML=''; document.getElementById('demo').innerHTML=process(decodeURIComponent(('' + location.hash).substring(5).replace(/^\=/g,'').replace(/^\%3d/g,'').replace(/^\%3D/g,'').replace(/\%0A/g,encodeURIComponent('<br>')))); }, 3000);
}
srect=document.getElementById('droppable').getBoundingClientRect();
document.getElementById('droppable').style.border='1px pink dotted';
document.getElementById('droppable').style.position='absolute';
document.getElementById('droppable').style.top='' + srect.top + 'px';
document.getElementById('droppable').style.left='' + srect.left + 'px';
// Make the DIV element draggable ... thanks to https://www.w3schools.com/howto/howto_js_draggable.asp
dragElement(document.getElementById('droppable'));
}
tippingpoint=eval('' + document.getElementById('itip').value);
document.getElementById("mysup").title='Add an editable ' + document.getElementById('topic').innerHTML.toLowerCase();
thecall();
tabletds='';
//rspan=0;
eelines=[];
ify=0;
m.forEach((k, v, m) => consolelog(`key:${k} value:${v} map:${m}`));
document.getElementById("thd").innerHTML = document.getElementById("thd").innerHTML.split(document.getElementById("demo").innerHTML)[0] + document.getElementById("demo").innerHTML + '</td></tr>' + weedout(tabletds);
var tds=document.getElementsByTagName('td');
var toc=',,';
if (document.getElementById('thquantity').innerHTML.indexOf(',') != -1) { toc=','; }
if (document.getElementById('tdquantity').outerHTML.indexOf(',</td>') != -1) { document.getElementById('tdquantity').innerHTML=document.getElementById('tdquantity').innerHTML.replace(/\,$/g,''); }
for (var itd=0; itd<tds.length; itd++) {
if (('' + tds[itd].title).replace(',',toc).indexOf(',,') != -1) {
tds[itd].innerHTML=(tds[itd].title).replace(',',',,').split(',,')[0];
}
}
document.getElementById("demo").rowSpan = rspan;
document.getElementById("tdtip").rowSpan = rspan;
document.getElementById('itip').value = tippingpoint;
if (tpis != tippingpoint) {
setTimeout(function(){
document.getElementById('itip').value=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
tippingpoint=eval('' + document.getElementById('itip').value);
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
beadjustable();
}, 2000);
}
ddone=true;
if (document.getElementById('dif').innerHTML != '' && document.getElementById('myifis')) {
document.getElementById('myifis').src=datait(document.getElementById('myifis').src.split('&data=')[0] + '&data=');
}
}

function anal(inen) {
var ibn=0;
var xenterrall=inen;
//alert(4987);
if (('' + inen).replace(/^undefined/g,'').trim() == '') {
xenterall=prompt('Optionally enter a # (hashtag) delimited composite field scenario to apply for next input data (perhaps CSV) file application, such as in examples below. ' + String.fromCharCode(10) + String.fromCharCode(10) + 'Examples ...' + String.fromCharCode(10) + '#1,3&2&4' + String.fromCharCode(10) + '#4,2*3' + String.fromCharCode(10) + '#1&4,3+2', '');
} else {
undone=true;
mappings=[];
eval('mappings.push({ from: "1", to:"' + 'Name' + '"})');
eval('mappings.push({ from: "2", to:"' + 'Quantity' + '"})');
console.log(mappings);
xenterall=inen;
}
if (xenterall.split('#')[0].indexOf(',') == -1 && xenterall.trim() != '' && xenterall.indexOf('~`~') == -1) {
compositename='';
compositequantity='';
wheres=[];
orderbys=[];
ors=[];
ands=[];
if (xenterall.indexOf('#') != -1) {
var compstuff=xenterall.split('#')[1];
xenterall=xenterall.split('#')[0];
var csfs=compstuff.split(',');
for (ibn=0; ibn<csfs.length; ibn++) {
if (csfs[ibn].replace('!','=').replace('<','=').replace('>','=').indexOf('=') != -1) { // where
wheres.push(' ' + csfs[ibn]);
if (compstuff.indexOf(csfs[ibn] + ',') != -1) {
compstuff=compstuff.replace(csfs[ibn] + ',', '');
} else if (compstuff.indexOf(',' + csfs[ibn]) != -1) {
compstuff=compstuff.replace(',' + csfs[ibn], '');
} else {
compstuff=compstuff.replace(csfs[ibn], '');
}
} else if (csfs[ibn].replace('~','`').indexOf('`') != -1) { // order by
orderbys.push(' ' + csfs[ibn]);
if (compstuff.indexOf(csfs[ibn] + ',') != -1) {
compstuff=compstuff.replace(csfs[ibn] + ',', '');
} else if (compstuff.indexOf(',' + csfs[ibn]) != -1) {
compstuff=compstuff.replace(',' + csfs[ibn], '');
} else {
compstuff=compstuff.replace(csfs[ibn], '');
}
}
}
csfs=compstuff.split(',');
compositename=csfs[0];
if (compositename != '') {
if (eval(('' + compositename).split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0]) > 1 && eval('' + csfs.length) <= 1) {
compositequantity='1';
} else if (eval('' + csfs.length) > 1) {
compositequantity=csfs[1];
}
}
//alert(xenterall);
//alert(compositename);
//alert(compositequantity);
}
xenterall='';
}
xenterall='';
}

function askall(preenterall) {
var je=1;
var isfirst=true;
var delall=false;
enterall=('' + preenterall).replace(/^undefined$/g,'');
if (enterall == '') {
enterall=prompt('Optionally copy all your CSV (comma separated values) data to apply here (where ; or | can be record delimiters). Or specify a URL we shall try to extract from where a # (hashtag) delimiter can separate composite field scenarios such as in example below. Optionally prefix this CSV data with your topic followed by ~`~' + String.fromCharCode(10) + 'Examples ...' + String.fromCharCode(10) + 'Fish~`~taylor,300;barramundi,400;perch,100;mullet,234' + String.fromCharCode(10) + 'https://www.rjmprogramming.com.au/HTMLCSS/country.csv#1,3&2&4', '');
if (enterall == null) { enterall=''; }
//alert(enterall);
if (enterall.split('#')[0].indexOf(',') == -1 && enterall.trim() != '' && enterall.indexOf('~`~') == -1) {
compositename='';
compositequantity='';
if (enterall.indexOf('#') != -1) {
var compstuff=enterall.split('#')[1];
anal('#' + compstuff);
enterall=enterall.split('#')[0];
}
//document.getElementById('dif').innerHTML='';
//alert(enterall);
fruits=[];
fruity=[];
m = new Map();
rspan=0;
eelines=[];
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
document.body.style.cursor='progress';
ajaxit(enterall.replace(/^https\:/g,'').replace(/^http\:/g,'')); //document.getElementById('ifmy').src=enterall.replace(/^https\:/g,'').replace(/^http\:/g,'');
enterall='';
}
} //else {
//alert(enterall);
//}
if (enterall.indexOf('~`~') != -1) { document.getElementById('topic').innerHTML=enterall.split('~`~')[0]; enterall=enterall.replace(enterall.split('~`~')[0] + '~`~', ''); }
if (enterall.indexOf(',') != -1) {
elines=[];
if (enterall.indexOf(String.fromCharCode(10)) != -1) {
elines=enterall.split(String.fromCharCode(10));
} else if (enterall.indexOf(';') != -1) {
elines=enterall.split(';');
} else if (enterall.indexOf('|') != -1) {
elines=enterall.split('|');
}
var ke=0;
for (var ie=0; ie<elines.length; ie++) {
elines[ie]=elines[ie].split(' //')[0].split('// ')[0];
if (elines[ie].indexOf(',') != -1) { efields=elines[ie].split(','); }
if (isfirst && eval('' + elines.length) > 1 && elines[ie].indexOf(',') != -1 && elines[ie].replace(/9/g,'0').replace(/8/g,'0').replace(/7/g,'0').replace(/6/g,'0').replace(/5/g,'0').replace(/4/g,'0').replace(/3/g,'0').replace(/2/g,'0').replace(/1/g,'0').indexOf('0') == -1) {
efields=elines[ie].replace(/\"/g,'').split(',');
if (elines[je].replace(/^\"/g,'').substring(0).replace('-','').substring(0,1) >= '0' && elines[je].replace(/^\"/g,'').substring(0).replace('-','').substring(0,1) <= '9') {
for (ke=0; ke<efields.length; ke++) {
eval('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
}
document.getElementById('topic').innerHTML=elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1));
} else {
for (ke=0; ke<efields.length; ke++) {
//alert('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
eval('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
}
document.getElementById('topic').innerHTML=elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1));
}
isfirst=false;
//alert('isfirst');
}
je++;
if (eval('' + ie) != 0 || isfirst) {
//alert(elines[ie]);
if (elines[ie].indexOf(',') != -1) { eelines.push(elines[ie]); efields=elines[ie].split(','); }
if (elines[ie].indexOf('","') != -1 && elines[ie].indexOf('","') < elines[ie].indexOf(',')) {
//efields=elines[ie].split('","');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(1);
addone(elines[ie].split('","')[1].split('"')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(2);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('","')[1].split('"')[0]);
}
} else if (elines[ie].indexOf('",') != -1 && elines[ie].indexOf('",') < elines[ie].indexOf(',')) {
efields[0]=efields[0].replace(/\"$/g,'').replace(/^\"$/g,'');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(3);
addone(elines[ie].split('",')[1].split(',')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(4);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('",')[1].split(',')[0]);
}
} else if (elines[ie].indexOf(',"') != -1 && elines[ie].indexOf(',"') == elines[ie].indexOf(',')) {
efields[1]=efields[1].replace(/\"$/g,'').replace(/^\"$/g,'');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(5);
addone(elines[ie].split(',"')[1].split('"')[0], elines[ie].substring(0).split(',')[0]);
} else {
//alert(6);
addone(elines[ie].substring(0).split(',')[0], elines[ie].split(',"')[1].split('"')[0]);
}
} else if (elines[ie].indexOf(',') != -1) {
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(7);
if (9 == 7 && isfirst && ((elines[ie].substring(0).split(',')[0] + ' ').replace('-','').substring(0,1) < '0' || (elines[ie].substring(0).split(',')[0] + ' ').replace('-','').substring(0,1) > '9')) {
document.getElementById('topic').innerHTML=elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1));
} else {
addone(elines[ie].substring(0).split(',')[1], elines[ie].substring(0).split(',')[0]);
}
} else {
//alert(8);
if (9 == 7 && isfirst && ((elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) < '0' || (elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) > '9')) {
document.getElementById('topic').innerHTML=elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1));
} else {
addone(elines[ie].substring(0).split(',')[0], elines[ie].substring(0).split(',')[1]);
}
}
}
isfirst=false;
}
isfirst=false;
}
beadjustable();
}
}

function extractContent(s, space) { // thanks to https://stackoverflow.com/questions/28899298/extract-the-text-out-of-html-string-using-javascript
var xmlret='';
if (s.split('>')[0].indexOf('xml') != -1 && eval('' + s.split('>').length) > 1) {
var innards=s.split('>');
for (var iri=1; iri<innards.length; iri++) {
xmlret+=innards[iri].split('<')[0];
}
return xmlret;
}
var span= document.createElement('span');
span.innerHTML= s;
if (space) {
var children= span.querySelectorAll('*');
for(var i = 0 ; i < children.length ; i++) {
if(children[i].textContent)
children[i].textContent+= ' ';
else
children[i].innerText+= ' ';
}
}
return [span.textContent || span.innerText].toString().replace(/ +/g,' ');
}

function yesthreethree(restis) {
//alert(1987);
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
if (restis.indexOf(';base64,') != -1) {
var icontent=window.atob(restis.split(';base64,')[1]);
if ((('' + icontent).trim() + ' ').replace(/^\[caption/g,'<').substring(0,1) == '<') {
askall(extractContent(icontent,true));
} else {
askall(icontent);
}
} else {
askall(restis);
}
setTimeout(function(){ fromplace=document.getElementById('outputname').value.replace(/\./g, '_'); }, 3000);
}

function alatr() {
if (document.getElementById('psubm')) {
document.getElementById('psubm').click();
}
}

function toolong(inup) {
if (inup.split('&emailto=').length > 2) {
while (inup.split('&emailto=').length > 2) {
inup=inup.replace('&emailto=' + inup.split('&emailto=')[1].split('&')[0],'');
}
}
if (inup.split('&emailsubject=').length > 2) {
while (inup.split('&emailsubject=').length > 2) {
inup=inup.replace('&emailsubject=' + inup.split('&emailsubject=')[1].split('&')[0],'');
}
}
if (inup.split('&emailcc=').length > 2) {
while (inup.split('&emailcc=').length > 2) {
inup=inup.replace('&emailcc=' + inup.split('&emailcc=')[1].split('&')[0],'');
}
}
if (inup.split('&emailbcc=').length > 2) {
while (inup.split('&emailbcc=').length > 2) {
inup=inup.replace('&emailbcc=' + inup.split('&emailbcc=')[1].split('&')[0],'');
}
}
if (inup.indexOf('&email') > inup.indexOf('&data')) {
var putb=inup.substring(inup.indexOf('&email'));
inup=inup.replace(putb,'');
inup=inup.replace('&data', putb + '&data');
}
if (window.top && 2 == 5) {
if (top.document.getElementById('myform') || top.document.indexOf('/map_test.htm') != -1) {
top.document.title='86';
alert(86);
if (top.document.getElementById('myform').action.indexOf('#pleaseno') != -1) {
if (inup.length < 900) {
var xszc=prompt('pform', inup);
}
}
}
}
if (inup.length < 900) return inup;
var texr=' target=_self ';
if (document.getElementById('specf')) { texr=' target=specf '; }
var pform='<form' + texr + ' method=POST style=display:none; action=' + inup.split('?')[0] + '><input type=hidden name=wouldlikeyoutoseekpermission value=y></input><input type=submit id=psubm></input></form>';
var pars=inup.replace('?','&').split('#')[0].split('&');
for (var ipars=1; ipars<pars.length; ipars++) {
if (decodeURIComponent(pars[ipars].split('=')[1]).indexOf("data:") != -1) {
pform=pform.replace('</form>', '<input type=hidden name="' + pars[ipars].split('=')[0] + '" value="' + decodeURIComponent(pars[ipars].replace(pars[ipars].split('=')[0] + '=','')).replace(/\+/g,'%2b') + '"></input></form>');
} else {
pform=pform.replace('</form>', '<input type=hidden name="' + pars[ipars].split('=')[0] + '" value="' + decodeURIComponent(pars[ipars].replace(pars[ipars].split('=')[0] + '=','')) + '"></input></form>');
}
}
if (window.top && 3 == 7) {
if (top.document.getElementById('myform') || top.document.indexOf('/map_test.htm') != -1) {
top.document.title='286';
alert(286);
if (top.document.getElementById('myform').action.indexOf('#pleaseno') != -1) {
var xzc=prompt(pform, pform);
}
}
}
//top.document.title='2:' + pform;
document.body.innerHTML+=pform;
//alert(pform.split(' name="task"')[1]);
setTimeout(alatr, 2000); //document.getElementById('psubm').click();
return '#';
}

function nooneencodeURIComponent(compm) {
return encodeURIComponent(('' + compm)).replace(/\'/g,'`').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',');
}

function geoitdependsoneencodeURIComponent(compm, compv) {
if (thqit(compositequantity) != '') {
var fgh=document.getElementById('thquantity').innerHTML;
if (fgh.indexOf('ongitude') != -1 && fgh.indexOf('atitude') != -1 && fgh.indexOf(',') != -1) {
if (fgh.indexOf('atitude') < fgh.indexOf('ongitude')) {
if (outv.indexOf('&aregeographicals=') == -1) { outv=outv.replace('&','&aregeographicals=y&'); }
return ('' + compv).split(',')[0] + '|' + ('' + compv).split(',')[1] + '|~' + (compm).split(',')[0].replace(/\'/g,'`').replace(/\ /g,'%20'); // .replace(/\%20/g,'+');
} else {
if (outv.indexOf('&aregeographicals=') == -1) { outv=outv.replace('&','&aregeographicals=y&'); }
return ('' + compv).split(',')[1] + '|' + ('' + compv).split(',')[0] + '|~' + (compm).split(',')[0].replace(/\'/g,'`').replace(/\ /g,'%20'); // .replace(/\%20/g,'+');
}
}
}
return '~' + oneencodeURIComponent(compm);
}

function itdependsoneencodeURIComponent(compm) {
if (goselv.indexOf('PHP/Histogram') != -1 || goselv.indexOf('PHP/Pie') != -1 || goselv.indexOf('PHP/Line') != -1 || goselv.indexOf('PHP/Area') != -1 || goselv.indexOf('PHP/Column') != -1 || goselv.indexOf('PHP/Bar') != -1) {
if (compositename != '' && thqit(compositequantity) != '') {
return encodeURIComponent(compm.split(',')[eval(-1 + compm.split(',').length)].replace(/\'/g,'`')); // .replace(/\%20/g,'+');
}
}
return oneencodeURIComponent(compm);
}

function oneencodeURIComponent(compm) {
return encodeURIComponent(('' + compm).split(',')[0].replace(/\'/g,'`').replace(/\[/g,' ').replace(/\]/g,' '));
}

function nojustone(compm) {
return (('' + compm)).replace(/\'/g,'`');
}

function justone(compm) {
return (('' + compm).split(',')[0]).replace(/\'/g,'`');
}

function geojustone(compm) {
// https://www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php/PHP/GeoChart/geo_chart.php?onclick=y&retsvg=y&overlay=aHT&shade=HT&iso=HT&text=text&wouldlikeyoutoseekpermission=y&width=834&height=520&country=Places&popularity=&aregeographicals=y&title=HT%3BHaiti&data=%20[19.45|-72.6833|~Artibonite+department~,2]%20,%20[19.15|-72.0167|~Centre+department~,2]%20,%20[18.6667|-74.1167|~Grand%2527Anse+department~,2]%20,%20[18.450|-73.100|~Nippes~,2]%20,%20[19.7667|-72.2|~Nord+Haitian+department~,2]%20,%20[19.6678|-71.8397|~Nord-Est+department~,2]%20,%20[19.95|-72.8333|~Nord-Ouest+department~,2]%20,%20[18.2|-73.75|~Sud+department~,2]%20,%20[18.2333|-72.5333|~Sud-Est+department~,2]%20,%20[18.450|-73.100|~Nippes~,2]%20
if (thqit(compositequantity) != '') {
return (('' + compm).split(',')[0]); // '2';
}
return encodeURIComponent(('' + compm).split(',')[0]);
}

function thqit(prop) {
if (document.getElementById('thquantity').innerHTML.indexOf(',') == -1) {
return '';
}
return prop;
}

function datait(oselv) {
var kk=0, firstdelim='';
var ov='';
var fromis='youllneverfindthis', tois='youllneverfindthis';
outv=oselv;
goselv=oselv;
//alert(outv);
if (outv != '') {
//alert('Fruits.length=' + fruits.length);
if (oselv.indexOf('PHP/Pie') != -1) {
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML;
document.getElementById('task').value=document.getElementById('thquantity').innerHTML;
document.getElementById('country').value=document.getElementById('thname').innerHTML;
document.getElementById('desc').value=document.getElementById('thname').innerHTML;

document.getElementById('value').value=document.getElementById('thquantity').innerHTML;
document.getElementById('label').value=document.getElementById('thname').innerHTML;
outv=outv.replace('value=Quantity', 'value=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
outv=outv.replace('popularity=Popularity', 'popularity=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('country=Country', 'country=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));
outv=outv.replace('task=Popularity', 'task=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('desc=Country', 'desc=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

for (kk=0; kk<fruits.length; kk++) {
if (('~,' + fruits[kk].quantity + ']').replace(/\~\,\]/g,'~,0]').indexOf('-') == -1 || 7 == 7) {
outv+=',[~' + itdependsoneencodeURIComponent(fruity[kk].name) + ('~,' + justone(('' + fruity[kk].quantity).replace(/\,$/g,'')) + ']').replace(/\~\,\]/g,'~,0]').replace('-','');
}
}
if (('' + outv).length > 600) { document.getElementById('lhashis').value='#' + outv.replace('],[', ']#,[').split('#')[1]; ov=outv.replace('],[', ']#,['); outv=ov.split('#')[0] + '#' + encodeURIComponent(ov.split('#')[1]); return outv; }
} else if (oselv.indexOf('PHP/Histogram') != -1) {
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML;
document.getElementById('task').value=document.getElementById('thquantity').innerHTML;
document.getElementById('country').value=document.getElementById('thname').innerHTML;
document.getElementById('desc').value=document.getElementById('thname').innerHTML;

document.getElementById('value').value=document.getElementById('thquantity').innerHTML;
document.getElementById('label').value=document.getElementById('thname').innerHTML;
outv=outv.replace('value=Quantity', 'value=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
andnext=' or ';
} else {
wheresor.push(andnext);
andnext=' and ';
}
}
wheres.push(' ' + csfs[ibn].replace(/\|$/g, ' OR '));
if (compstuff.indexOf(csfs[ibn] + ',') != -1) {
compstuff=compstuff.replace(csfs[ibn] + ',', '');
} else if (compstuff.indexOf(',' + csfs[ibn]) != -1) {
compstuff=compstuff.replace(',' + csfs[ibn], '');
} else {
compstuff=compstuff.replace(csfs[ibn], '');
}
} else if (csfs[ibn].trim().replace('`','|').replace('~','|').indexOf('|') == 0) { // order by
orderbys.push((' ' + (csfs[ibn] + ' ').replace(/\|\ $/g,' |').replace(' | ',' |1 ').replace(' ~ ',' ~1 ').replace(' ` ',' |1 ')));
if (compstuff.indexOf(csfs[ibn] + ',') != -1) {
compstuff=compstuff.replace(csfs[ibn] + ',', '');
} else if (compstuff.indexOf(',' + csfs[ibn]) != -1) {
compstuff=compstuff.replace(',' + csfs[ibn], '');
} else {
compstuff=compstuff.replace(csfs[ibn], '');
}
}
}
csfs=compstuff.split(',');
compositename=csfs[0];
if (compositename != '') {
if (eval(('' + compositename).split('&')[0].split('+')[0].split('/')[0].split('*')[0].split('-')[0].split('%')[0].split('^')[0]) > 1 && eval('' + csfs.length) <= 1) {
compositequantity='1';
} else if (eval('' + csfs.length) > 1) {
compositequantity=csfs[1];
}
}
//alert(xenterall);
//alert(compositename);
//alert(compositequantity);
}
xenterall='';
}
xenterall='';
}

function askall(preenterall) {
var je=1;
var isfirst=true;
var delall=false;
enterall=('' + preenterall).replace(/^undefined$/g,'');
if (enterall == '') {
enterall=prompt('Optionally copy all your CSV (comma separated values) data to apply here (where ; or | can be record delimiters). Or specify a URL we shall try to extract from where a # (hashtag) delimiter can separate composite field scenarios such as in example below. Optionally prefix this CSV data with your topic followed by ~`~' + String.fromCharCode(10) + 'Examples ...' + String.fromCharCode(10) + 'Fish~`~taylor,300;barramundi,400;perch,100;mullet,234' + String.fromCharCode(10) + 'https://www.rjmprogramming.com.au/HTMLCSS/country.csv#1,3&2&4', '');
if (enterall == null) { enterall=''; }
//alert(enterall);
if (enterall.split('#')[0].indexOf(',') == -1 && enterall.trim() != '' && enterall.indexOf('~`~') == -1) {
compositename='';
compositequantity='';
if (enterall.indexOf('#') != -1) {
var compstuff=enterall.split('#')[1];
anal('#' + compstuff);
enterall=enterall.split('#')[0];
}
//document.getElementById('dif').innerHTML='';
//alert(enterall);
fruits=[];
fruity=[];
m = new Map();
rspan=0;
eelines=[];
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
document.body.style.cursor='progress';
simplegroupby='';
ajaxit(enterall.replace(/^https\:/g,'').replace(/^http\:/g,'')); //document.getElementById('ifmy').src=enterall.replace(/^https\:/g,'').replace(/^http\:/g,'');
enterall='';
}
} //else {
//alert(enterall);
//}
if (enterall.indexOf('~`~') != -1) { document.getElementById('topic').innerHTML=enterall.split('~`~')[0]; enterall=enterall.replace(enterall.split('~`~')[0] + '~`~', ''); }
if (enterall.indexOf(',') != -1) {
elines=[];
if (enterall.indexOf(String.fromCharCode(10)) != -1) {
elines=enterall.split(String.fromCharCode(10));
} else if (enterall.indexOf(';') != -1) {
elines=enterall.split(';');
} else if (enterall.indexOf('|') != -1) {
elines=enterall.split('|');
}
var ke=0;
for (var ie=0; ie<elines.length; ie++) {
elines[ie]=elines[ie].split(' //')[0].split('// ')[0];
if (elines[ie].indexOf(',') != -1) { efields=elines[ie].split(','); }
if (isfirst && eval('' + elines.length) > 1 && elines[ie].indexOf(',') != -1 && elines[ie].replace(/9/g,'0').replace(/8/g,'0').replace(/7/g,'0').replace(/6/g,'0').replace(/5/g,'0').replace(/4/g,'0').replace(/3/g,'0').replace(/2/g,'0').replace(/1/g,'0').indexOf('0') == -1) {
efields=elines[ie].replace(/\"/g,'').split(',');
if (elines[je].replace(/^\"/g,'').substring(0).replace('-','').substring(0,1) >= '0' && elines[je].replace(/^\"/g,'').substring(0).replace('-','').substring(0,1) <= '9') {
for (ke=0; ke<efields.length; ke++) {
eval('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
}
document.getElementById('topic').innerHTML=elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1));
} else {
for (ke=0; ke<efields.length; ke++) {
//alert('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
eval('mappings.unshift({ from: "' + eval(ke + 1) + '", to: "' + efields[ke] + '"})');
}
document.getElementById('topic').innerHTML=elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[0].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(0,1).toUpperCase() + elines[ie].replace(/^\"/g,'').substring(0).split('"')[0].split(',')[1].substring(1));
}
isfirst=false;
//alert('isfirst');
}
je++;
if (eval('' + ie) != 0 || isfirst) {
//alert(elines[ie]);
if (elines[ie].indexOf(',') != -1) { eelines.push(elines[ie]); efields=elines[ie].split(','); }
if (elines[ie].indexOf('","') != -1 && elines[ie].indexOf('","') < elines[ie].indexOf(',')) {
//efields=elines[ie].split('","');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(1);
addone(elines[ie].split('","')[1].split('"')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(2);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('","')[1].split('"')[0]);
}
} else if (elines[ie].indexOf('",') != -1 && elines[ie].indexOf('",') < elines[ie].indexOf(',')) {
efields[0]=efields[0].replace(/\"$/g,'').replace(/^\"$/g,'');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(3);
addone(elines[ie].split('",')[1].split(',')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(4);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('",')[1].split(',')[0]);
}
} else if (elines[ie].indexOf(',"') != -1 && elines[ie].indexOf(',"') == elines[ie].indexOf(',')) {
efields[1]=efields[1].replace(/\"$/g,'').replace(/^\"$/g,'');
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(5);
addone(elines[ie].split(',"')[1].split('"')[0], elines[ie].substring(0).split(',')[0]);
} else {
//alert(6);
addone(elines[ie].substring(0).split(',')[0], elines[ie].split(',"')[1].split('"')[0]);
}
} else if (elines[ie].indexOf(',') != -1) {
if (!delall) {
delall=true;
fruits=[];
fruity=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(7);
if (9 == 7 && isfirst && ((elines[ie].substring(0).split(',')[0] + ' ').replace('-','').substring(0,1) < '0' || (elines[ie].substring(0).split(',')[0] + ' ').replace('-','').substring(0,1) > '9')) {
document.getElementById('topic').innerHTML=elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1));
} else {
addone(elines[ie].substring(0).split(',')[1], elines[ie].substring(0).split(',')[0]);
}
} else {
//alert(8);
if (9 == 7 && isfirst && ((elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) < '0' || (elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) > '9')) {
document.getElementById('topic').innerHTML=elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1);
document.getElementById('thname').innerHTML=maybenotdefn(elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1));
document.getElementById('thquantity').innerHTML=maybenotdefq(elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1));
} else {
addone(elines[ie].substring(0).split(',')[0], elines[ie].substring(0).split(',')[1]);
}
}
}
isfirst=false;
}
isfirst=false;
}
beadjustable();
}
}

function extractContent(s, space) { // thanks to https://stackoverflow.com/questions/28899298/extract-the-text-out-of-html-string-using-javascript
var xmlret='';
if (s.split('>')[0].indexOf('xml') != -1 && eval('' + s.split('>').length) > 1) {
var innards=s.split('>');
for (var iri=1; iri<innards.length; iri++) {
xmlret+=innards[iri].split('<')[0];
}
return xmlret;
}
var span= document.createElement('span');
span.innerHTML= s;
if (space) {
var children= span.querySelectorAll('*');
for(var i = 0 ; i < children.length ; i++) {
if(children[i].textContent)
children[i].textContent+= ' ';
else
children[i].innerText+= ' ';
}
}
return [span.textContent || span.innerText].toString().replace(/ +/g,' ');
}

function yesthreethree(restis) {
//alert(1987);
simplegroupby='';
document.getElementById('tdname').innerHTML='';
document.getElementById('tdquantity').innerHTML='';
if (restis.indexOf(';base64,') != -1) {
var icontent=window.atob(restis.split(';base64,')[1]);
if ((('' + icontent).trim() + ' ').replace(/^\[caption/g,'<').substring(0,1) == '<') {
askall(maybesort(extractContent(icontent,true)));
} else {
askall(maybesort(icontent));
}
} else {
askall(maybesort(restis));
}
alertsql();
setTimeout(function(){ fromplace=document.getElementById('outputname').value.replace(/\./g, '_'); }, 3000);
}

function alatr() {
if (document.getElementById('psubm')) {
document.getElementById('psubm').click();
}
}

function toolong(inup) {
if (inup.split('&emailto=').length > 2) {
while (inup.split('&emailto=').length > 2) {
inup=inup.replace('&emailto=' + inup.split('&emailto=')[1].split('&')[0],'');
}
}
if (inup.split('&emailsubject=').length > 2) {
while (inup.split('&emailsubject=').length > 2) {
inup=inup.replace('&emailsubject=' + inup.split('&emailsubject=')[1].split('&')[0],'');
}
}
if (inup.split('&emailcc=').length > 2) {
while (inup.split('&emailcc=').length > 2) {
inup=inup.replace('&emailcc=' + inup.split('&emailcc=')[1].split('&')[0],'');
}
}
if (inup.split('&emailbcc=').length > 2) {
while (inup.split('&emailbcc=').length > 2) {
inup=inup.replace('&emailbcc=' + inup.split('&emailbcc=')[1].split('&')[0],'');
}
}
if (inup.indexOf('&email') > inup.indexOf('&data')) {
var putb=inup.substring(inup.indexOf('&email'));
inup=inup.replace(putb,'');
inup=inup.replace('&data', putb + '&data');
}
if (window.top && 2 == 5) {
if (top.document.getElementById('myform') || top.document.indexOf('/map_test.htm') != -1) {
top.document.title='86';
alert(86);
if (top.document.getElementById('myform').action.indexOf('#pleaseno') != -1) {
if (inup.length < 900) {
var xszc=prompt('pform', inup);
}
}
}
}
if (inup.length < 900) return inup;
var texr=' target=_self ';
if (document.getElementById('specf')) { texr=' target=specf '; }
var pform='<form' + texr + ' method=POST style=display:none; action=' + inup.split('?')[0] + '><input type=hidden name=wouldlikeyoutoseekpermission value=y></input><input type=submit id=psubm></input></form>';
var pars=inup.replace('?','&').split('#')[0].split('&');
for (var ipars=1; ipars<pars.length; ipars++) {
if (decodeURIComponent(pars[ipars].split('=')[1]).indexOf("data:") != -1) {
pform=pform.replace('</form>', '<input type=hidden name="' + pars[ipars].split('=')[0] + '" value="' + decodeURIComponent(pars[ipars].replace(pars[ipars].split('=')[0] + '=','')).replace(/\+/g,'%2b') + '"></input></form>');
} else {
pform=pform.replace('</form>', '<input type=hidden name="' + pars[ipars].split('=')[0] + '" value="' + decodeURIComponent(pars[ipars].replace(pars[ipars].split('=')[0] + '=','')) + '"></input></form>');
}
}
if (window.top && 3 == 7) {
if (top.document.getElementById('myform') || top.document.indexOf('/map_test.htm') != -1) {
top.document.title='286';
alert(286);
if (top.document.getElementById('myform').action.indexOf('#pleaseno') != -1) {
var xzc=prompt(pform, pform);
}
}
}
//top.document.title='2:' + pform;
document.body.innerHTML+=pform;
//alert(pform.split(' name="task"')[1]);
setTimeout(alatr, 2000); //document.getElementById('psubm').click();
return '#';
}

function nooneencodeURIComponent(compm) {
return encodeURIComponent(('' + compm)).replace(/\'/g,'|').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',').replace(encodeURIComponent(','),',');
}

function geoitdependsoneencodeURIComponent(compm, compv) {
if (thqit(compositequantity) != '') {
var fgh=document.getElementById('thquantity').innerHTML;
if (fgh.indexOf('ongitude') != -1 && fgh.indexOf('atitude') != -1 && fgh.indexOf(',') != -1) {
if (fgh.indexOf('atitude') < fgh.indexOf('ongitude')) {
if (outv.indexOf('&aregeographicals=') == -1) { outv=outv.replace('&','&aregeographicals=y&'); }
return ('' + compv).split(',')[0] + '|' + ('' + compv).split(',')[1] + '|~' + (compm).split(',')[0].replace(/\'/g,'|').replace(/\ /g,'%20'); // .replace(/\%20/g,'+');
} else {
if (outv.indexOf('&aregeographicals=') == -1) { outv=outv.replace('&','&aregeographicals=y&'); }
return ('' + compv).split(',')[1] + '|' + ('' + compv).split(',')[0] + '|~' + (compm).split(',')[0].replace(/\'/g,'|').replace(/\ /g,'%20'); // .replace(/\%20/g,'+');
}
}
}
return '~' + oneencodeURIComponent(compm);
}

function itdependsoneencodeURIComponent(compm) {
if (goselv.indexOf('PHP/Histogram') != -1 || goselv.indexOf('PHP/Pie') != -1 || goselv.indexOf('PHP/Line') != -1 || goselv.indexOf('PHP/Area') != -1 || goselv.indexOf('PHP/Column') != -1 || goselv.indexOf('PHP/Bar') != -1) {
if (compositename != '' && thqit(compositequantity) != '') {
return encodeURIComponent(compm.split(',')[eval(-1 + compm.split(',').length)].replace(/\'/g,'|')); // .replace(/\%20/g,'+');
}
}
return oneencodeURIComponent(compm);
}

function oneencodeURIComponent(compm) {
return encodeURIComponent(('' + compm).split(',')[0].replace(/\'/g,'|').replace(/\[/g,' ').replace(/\]/g,' '));
}

function nojustone(compm) {
return (('' + compm)).replace(/\'/g,'|');
}

function justone(compm) {
return (('' + compm).split(',')[0]).replace(/\'/g,'|');
}

function geojustone(compm) {
// https://www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php/PHP/GeoChart/geo_chart.php?onclick=y&retsvg=y&overlay=aHT&shade=HT&iso=HT&text=text&wouldlikeyoutoseekpermission=y&width=834&height=520&country=Places&popularity=&aregeographicals=y&title=HT%3BHaiti&data=%20[19.45|-72.6833|~Artibonite+department~,2]%20,%20[19.15|-72.0167|~Centre+department~,2]%20,%20[18.6667|-74.1167|~Grand%2527Anse+department~,2]%20,%20[18.450|-73.100|~Nippes~,2]%20,%20[19.7667|-72.2|~Nord+Haitian+department~,2]%20,%20[19.6678|-71.8397|~Nord-Est+department~,2]%20,%20[19.95|-72.8333|~Nord-Ouest+department~,2]%20,%20[18.2|-73.75|~Sud+department~,2]%20,%20[18.2333|-72.5333|~Sud-Est+department~,2]%20,%20[18.450|-73.100|~Nippes~,2]%20
if (thqit(compositequantity) != '') {
return (('' + compm).split(',')[0]); // '2';
}
return encodeURIComponent(('' + compm).split(',')[0]);
}

function thqit(prop) {
if (document.getElementById('thquantity').innerHTML.indexOf(',') == -1) {
return '';
}
return prop;
}

function datait(oselv) {
var kk=0, firstdelim='';
var ov='';
var fromis='youllneverfindthis', tois='youllneverfindthis';
outv=oselv;
goselv=oselv;
//alert(outv);
if (outv != '') {
//alert('Fruits.length=' + fruits.length);
if (oselv.indexOf('PHP/Pie') != -1) {
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML;
document.getElementById('task').value=document.getElementById('thquantity').innerHTML;
document.getElementById('country').value=document.getElementById('thname').innerHTML;
document.getElementById('desc').value=document.getElementById('thname').innerHTML;

document.getElementById('value').value=document.getElementById('thquantity').innerHTML;
document.getElementById('label').value=document.getElementById('thname').innerHTML;
outv=outv.replace('value=Quantity', 'value=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
outv=outv.replace('popularity=Popularity', 'popularity=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('country=Country', 'country=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));
outv=outv.replace('task=Popularity', 'task=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('desc=Country', 'desc=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

for (kk=0; kk<fruits.length; kk++) {
if (('~,' + fruits[kk].quantity + ']').replace(/\~\,\]/g,'~,0]').indexOf('-') == -1 || 7 == 7) {
outv+=',[~' + itdependsoneencodeURIComponent(fruity[kk].name) + ('~,' + justone(('' + fruity[kk].quantity).replace(/\,$/g,'')) + ']').replace(/\~\,\]/g,'~,0]').replace('-','');
}
}
if (('' + outv).length > 600) { document.getElementById('lhashis').value='#' + outv.replace('],[', ']#,[').split('#')[1]; ov=outv.replace('],[', ']#,['); outv=ov.split('#')[0] + '#' + encodeURIComponent(ov.split('#')[1]); return outv; }
} else if (oselv.indexOf('PHP/Histogram') != -1) {
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML;
document.getElementById('task').value=document.getElementById('thquantity').innerHTML;
document.getElementById('country').value=document.getElementById('thname').innerHTML;
document.getElementById('desc').value=document.getElementById('thname').innerHTML;

document.getElementById('value').value=document.getElementById('thquantity').innerHTML;
document.getElementById('label').value=document.getElementById('thname').innerHTML;
outv=outv.replace('value=Quantity', 'value=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
outv=outv.replace('popularity=Popularity', 'popularity=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('country=Country', 'country=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));
outv=outv.replace('task=Popularity', 'task=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('desc=Country', 'desc=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

for (kk=0; kk<fruits.length; kk++) {
outv+=',[~' + itdependsoneencodeURIComponent(fruity[kk].name) + ('~,' + justone(('' + fruity[kk].quantity).replace(/\,$/g,'')) + ']').replace(/\~\,\]/g,'~,0]');
}
//alert(outv);
if (('' + outv).length > 600) { document.getElementById('lhashis').value='#' + outv.replace('],[', ']#,[').split('#')[1]; return outv.replace('],[', ']#,['); }
} else if (oselv.indexOf('PHP/Geo') != -1) {
if (thqit(compositequantity) == '') { outv=outv.replace('aregeographicals=', 'notare='); }
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML.split(',')[0];
document.getElementById('task').value=document.getElementById('thquantity').innerHTML.split(',')[0];
document.getElementById('country').value=document.getElementById('thname').innerHTML.split(',')[0];
document.getElementById('desc').value=document.getElementById('thname').innerHTML.split(',')[0];

document.getElementById('value').value=document.getElementById('thquantity').innerHTML.split(',')[0];
document.getElementById('label').value=document.getElementById('thname').innerHTML.split(',')[0];
outv=outv.replace('value=Quantity', 'value=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML.split(',')[0]));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
outv=outv.replace('popularity=Popularity', 'popularity=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML.split(',')[0])); //document.getElementById('thquantity').innerHTML));
outv=outv.replace('country=Country', 'country=' + oneencodeURIComponent(document.getElementById('thname').innerHTML.split(',')[0]));
outv=outv.replace('task=Popularity', 'task=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML.split(',')[0]));
outv=outv.replace('desc=Country', 'desc=' + oneencodeURIComponent(document.getElementById('thname').innerHTML.split(',')[0]));

for (kk=0; kk<fruits.length; kk++) {
//if (kk == 0) { fromis=firstdelim + '%20[' + geoitdependsoneencodeURIComponent(fruity[kk].name,fruity[kk].quantity) + ('~,' + geojustone('' + fruity[kk].quantity) + ']').replace(/\~\,\]/g,'~,0]') + '%20'; }
outv+=firstdelim + ('%20[' + geoitdependsoneencodeURIComponent(fruity[kk].name,fruity[kk].quantity) + ('~,' + geojustone(('' + fruity[kk].quantity).replace(/\,$/g,'')) + ']').replace(/\~\,\]/g,'~,0]')).replace(String.fromCharCode(39),'~') + '%20';
//if (kk == 0) { tois=encodeURIComponent(fromis); }
firstdelim=',';
}
//if (('' + outv).length > 600) { return outv=outv.replace('onclick=y&','').replace('?', '#onclick=y&').replace('&data=%20','&data=%2C'); }
if (('' + outv).length > 600) { document.getElementById('lhashis').value='#' + outv.replace(']%20,%20[', ']%20#,%20[').replace('],[', ']#,[').split('#')[1]; if (thqit(compositequantity) != 'JUNK') { ov=outv.replace(']%20,%20[', ']%20#,%20[').replace('],[', ']#,['); outv=ov.split('#')[0].replace(fromis,tois) + '#' + (ov.split('#')[1]); return outv; } }
} else if (oselv.indexOf('PHP/Line') != -1 || oselv.indexOf('PHP/Area') != -1 || oselv.indexOf('PHP/Column') != -1 || oselv.indexOf('PHP/Bar') != -1) {
firstdelim=',';
document.getElementById('title').value=document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report';
document.getElementById('popularity').value=document.getElementById('thquantity').innerHTML;
document.getElementById('task').value=document.getElementById('thquantity').innerHTML;
document.getElementById('country').value=document.getElementById('thname').innerHTML;
document.getElementById('desc').value=document.getElementById('thname').innerHTML;

document.getElementById('value').value=document.getElementById('thquantity').innerHTML;
document.getElementById('label').value=document.getElementById('thname').innerHTML;
outv=outv.replace('value=Quantity', 'value=' + nooneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('label=Name', 'label=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

outv=outv.replace('title=Title', 'title=' + oneencodeURIComponent(document.getElementById('topic').innerHTML + ' ' + document.getElementById('spanok').innerHTML + ' versus ' + document.getElementById('spanlow').innerHTML + ' Report'));
outv=outv.replace('popularity=Popularity', 'popularity=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('country=Country', 'country=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));
outv=outv.replace('task=Popularity', 'task=' + oneencodeURIComponent(document.getElementById('thquantity').innerHTML));
outv=outv.replace('desc=Country', 'desc=' + oneencodeURIComponent(document.getElementById('thname').innerHTML));

for (kk=0; kk<fruits.length; kk++) {
outv+=firstdelim + '%20[~' + itdependsoneencodeURIComponent(fruity[kk].name) + ('~,' + nojustone(('' + fruity[kk].quantity).replace(/\,$/g,'')) + ']').replace(/\~\,\]/g,'~,0]') + '%20';
//if (kk == 0) { var zxs=prompt(outv,outv); }
firstdelim=',';
}
if (('' + outv).length > 600) { document.getElementById('lhashis').value='#' + outv.replace(']%20,%20[', ']%20#,%20[').replace('],[', ']#,[').split('#')[1]; return outv.replace(']%20,%20[', ']%20#,%20[').replace('],[', ']#,['); }
}
}
document.getElementById('lhashis').value='';
if (('' + outv).length > 600) {
document.getElementById('data').value=',' + outv.split('&data=')[1].replace(/\%20/g,' ');
document.getElementById('myform').method='POST';
document.getElementById('myform').action=outv.split('?')[0] + '#pleasenolocationhref';
outv='./map_test.html';
//var xx=prompt(document.getElementById('myform').outerHTML,document.getElementById('myform').innerHTML);
setTimeout(function(){ document.getElementById('mysub').click(); }, 3000);
} else if (2 == 2) {
document.getElementById('data').value=outv.split('&data=')[1].replace(/\%20/g,' ');
document.getElementById('myform').method='GET';
document.getElementById('myform').action=outv.split('?')[0];
//outv='./map_test.html';
setTimeout(function(){ document.getElementById('mysub').click(); }, 3000);
}
return outv;
}

function selit(osel) {
if (osel.value != '') {
geovalis=osel.value;
document.getElementById('defopt').innerText='Google Chart display of ... relevant ' + osel.value.split('PHP/')[1].split('/')[0].replace('Chart',' Chart') + ' below ...';
document.getElementById('dif').innerHTML='<br><br><a id=atop href="#myh1">Back to top ...</a><br><br><iframe name=myifis id=myifis src="' + datait(osel.value) + '" style="width:100%;height:700px;"></iframe>';
document.getElementById('dif').style.display='block';
}
osel.value='';
location.href='#atop';
}

function iifopen(iois) {
if (iois != null) {
aconto = (iois.contentWindow || iois.contentDocument);
if (aconto.document) { aconto = aconto.document; }
if (aconto != null) {