Subversion Repositories munaweb

Rev

Rev 5 | Rev 7 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
//
2
// Globals
3
//
4
var configServiceEndpoint = 'https://api.ebay.com/ws/api.dll';
5
var configRuName = 'Uwe_Jacobs-UweJacob-MUNATr-jwkrg';
6
var configWarningLevel = "Low";
7
var configAppid = 'UweJacob-MUNATrad-PRD-d132041a0-85284729';
8
var configDevid = '00fd6fda-3751-4095-b733-3899b20431ad';
9
var configCertid = 'PRD-132041a078aa-1ee6-4300-9454-6c5b';
10
var configSigninUrl = 'https://signin.ebay.com/ws/eBayISAPI.dll';
3 - 11
var configeBayLoginUrl = 'https://ujsoftware.linkpc.net/ebay/ebayLogin.php';
12
var configOauthTokenUrl = 'https://api.ebay.com/identity/v1/oauth2/token';
2 - 13
var configDiscogsToken = 'zFvVdCdHTtQnDHCxEFTJiBhalyHFUsjdyFPCjbqP&ty';
14
var configXmlRequestEntriesPerPage = '100';
15
var configUSPSUserId = '275MUNAT7574';
16
var configLinkedPayPal = 'paypal@munatrading.com';
17
var configListingUrl = 'https://ujsoftware.linkpc.net/ebay/listings/';
18
var configDiscogsBaseUrl = 'https://www.discogs.com';
19
var configDiscogsApiUrl = 'https://api.discogs.com/database/search';
20
var configDiscogsUserAgent = 'MUNA_Trading/1.0 +http://www.munatrading.com';
21
var configProxyUrl = 'https://ujsoftware.linkpc.net/proxy.php';
22
var configShopifyUrl = 'https://41f0d3bf0e8e114496b198938996d9d8:f169694c488f45ccf187c92676765889@muna-trading.myshopify.com/admin/';
23
var configShopifyProductsUrl = 'products.json';
24
var configShopifyOrdersUrl = 'orders.json';
25
var configShopifyTransactionsUrl1 = 'orders/';
26
var configShopifyTransactionsUrl2 = '/transactions.json';
27
var configShopifyOrderLimit = 250;
28
var configeBayTradingVersion = '1085';
29
var configeBayMarketingVersion = 'v1.4.0';
30
var configeBayFinding = 'https://svcs.ebay.com/services/search/FindingService/v1';
31
var configeBayFindingVersion = '1.13.0';
32
var configeBayShopping = 'http://open.api.ebay.com/shopping';
33
var configeBayShoppingVersion = '1063';
34
var configeBayAdCampaign = 'https://api.ebay.com/sell/marketing/v1/ad_campaign/';
35
var configUPSAccessKey = 'DD53C5F37DF74D28';
36
var configUPSUrl = 'https://onlinetools.ups.com/ups.app/xml/Track';
37
var configUPSUsername = 'muna_trading';
38
var configUPSPassword = 'ZX83tbf!w7';
39
var configUSPSUrl = 'https://secure.shippingapis.com/ShippingApi.dll';
40
var configGoogleMapsKey = 'AIzaSyBeSjH1CypAnYMYy_LIHqe8ngaAC6O-FWE';
41
 
42
var configTaxStateId = 'VA';
43
var configTaxRate = '6.000';
44
var configZip = '20120';
45
var configGetRecommendations = true;
46
var configDoesNotApply = 'Does not apply';
47
var configDefaultCountry = 'United States';
48
var configDefaultLanguage = 'English';
49
var configImage1Extension = ' Front.jpg';
50
var configImage2Extension = ' Rear.jpg';
51
var configdescriptionImageExtension = ' Front and Rear - small.jpg';
52
var configeBaySellerName = 'muna_trading';
53
var configAutoAcceptPrice = 0.85000;
54
var configMinBestOfferPrice = 0.65000;
55
 
56
var sessionId = '';
57
var eBayAuthToken = '';
58
var eBayAuthExpiration = '';
59
var eBayAuthTokenFlag = false;
60
 
61
 
62
 
63
//
64
// Prototypes
65
//
66
String.prototype.hashCode = function() {
67
	var hash = 0,
68
		i, chr;
69
	if (this.length === 0) return hash;
70
	for (i = 0; i < this.length; i++) {
71
		chr = this.charCodeAt(i);
72
		hash = ((hash << 5) - hash) + chr;
73
		hash |= 0; // Convert to 32bit integer
74
	}
75
 
76
	return (hash < 0 ? (hash * -1) : hash);
77
};
78
 
79
Number.prototype.pad = function(size) {
80
	var s = String(this);
81
	while (s.length < (size || 2)) {
82
		s = "0" + s;
83
	}
84
	return s;
85
};
86
 
87
String.prototype.toProperCase = function () {
88
    return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
89
};
90
 
91
Date.prototype.yyyymmdd = function() {
92
	var mm = this.getMonth() + 1; // getMonth() is zero-based
93
	var dd = this.getDate();
94
 
95
	return [this.getFullYear(), (mm > 9 ? '' : '0') + mm, (dd > 9 ? '' : '0') + dd].join('-');
96
};
97
 
98
String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
99
 
100
//
101
// Functions
102
//
6 - 103
function getJsonArray(val) {
104
    if (val === undefined) {
105
        return ([]);
106
    }
107
 
108
    return(val instanceof Array ? val : [val]);
109
}
110
 
2 - 111
function round(value, decimals) {
112
  return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
113
}
114
 
115
// Polyfill for Internet Explorer
116
Math.trunc = Math.trunc || function(x) {
117
	var n = x - x % 1;
118
	return n === 0 && (x < 0 || (x === 0 && (1 / x !== 1 / 0))) ? -0 : n;
119
};
120
 
121
function tableCell(str) {
122
	return ('<td>' + str + '</td>');
123
}
124
 
125
function tableCellHidden(str) {
126
	return ('<td class="w3-hide">' + str + '</td>');
127
}
128
 
129
function tableHeader(str) {
130
	return ('<th>' + str + '</th>');
131
}
132
 
133
function tableCellLabel(str) {
134
	return ('<td id="' + str + '"></td>');
135
}
136
 
137
function tableCellLabelHidden(str, val) {
138
	return ('<td id="' + str + '" class="w3-hide">' + val + '</td>');
139
}
140
 
141
function tableCellAndLabel(str, label) {
142
	return ('<td id="' + label + '">' + str + '</td>');
143
}
144
 
145
function tableHeaderHidden(str) {
146
	return ('<th class="w3-hide">' + str + '</th>');
147
}
148
 
6 - 149
function tableHeaderCheckbox() {
2 - 150
	return ('<th class="sorter-checkbox filter-false"><input type="checkbox"></th>');
151
}
152
 
153
function tableCellCheckbox() {
154
	return ('<td><input type="checkbox"></td>');
155
}
156
 
157
function escapeHtml(unsafe) {
158
	return unsafe
159
		.replace(/&/g, "&amp;")
160
		.replace(/</g, "&lt;")
161
		.replace(/>/g, "&gt;")
162
		.replace(/"/g, "&quot;")
163
		.replace(/'/g, "&#039;");
164
}
165
 
166
function pad(num, size) {
167
    var s = num+"";
168
    while (s.length < size) s = "0" + s;
169
    return s;
170
}
171
 
172
function isset () {
173
  var a = arguments;
174
  var l = a.length;
175
  var i = 0;
176
  var undef;
177
 
178
  if (l === 0) {
179
    return false;
180
  }
181
 
182
  while (i !== l) {
183
    if (a[i] === undef || a[i] === null) {
184
      return false;
185
    }
186
    i++;
187
  }
188
 
189
  return true;
190
}
191
 
192
function getJsonValue(obj){
193
  return (isset(obj) ? obj : "");
194
}
195
 
196
function writeCookie() {
197
	document.cookie = 'eBayAuthToken=' + encodeURIComponent(eBayAuthToken) + ';expires=' + eBayAuthExpiration + ';';
198
}
199
 
200
function readCookie() {
201
	var name = 'eBayAuthToken=';
202
	var decodedCookie = decodeURIComponent(document.cookie);
203
	var ca = decodedCookie.split(';');
204
	for (var i = 0; i < ca.length; i++) {
205
		var c = ca[i];
206
		while (c.charAt(0) == ' ') {
207
			c = c.substring(1);
208
		}
209
		if (c.indexOf(name) === 0) {
210
			return c.substring(name.length, c.length);
211
		}
212
	}
213
	return "";
214
}
215
 
216
function isNumeric(input) {
217
	return (input - 0) == input && ('' + input).trim().length > 0;
218
}
219
 
220
function getRadioValue(name) {
221
	var group = document.getElementsByName(name);
222
 
223
	for (var i = 0; i < group.length; i++) {
224
		if (group[i].checked) {
225
			return group[i].value;
226
		}
227
	}
228
 
229
	return '';
230
}
231
 
232
function removeDuplicateRows($table){
233
    function getVisibleRowText($row){
234
        return $row.find('td:visible').text().toLowerCase();
235
    }
236
 
237
    $table.find('tr').each(function(index, row){
238
        var $row = $(row);
239
 
240
        $row.nextAll('tr').each(function(index, next){
241
            var $next = $(next);
242
            if(getVisibleRowText($next) == getVisibleRowText($row)) {
243
                $next.remove();
244
            }
245
        });
246
    });
247
}
248
 
249
function isValidUpcOrEanCode(str) {
250
	if (!isNumeric(str)) {
251
		return(false);
252
	}
253
 
254
	if (str.length == 12) {
255
		return(isValidUpcCode(str));
256
	} else if (str.length == 13) {
257
		return(isValidEanCode(str) === 0 ? true : false);
258
	}
259
 
260
	return(false);
261
}
262
 
263
function isValidEanCode(ean) {
264
    var result = 0;
265
    for (var counter = (ean.length - 1); counter >= 0; counter--) {
266
        result = result + parseInt(ean.charAt(counter)) * (1 + (2 * (counter % 2)));
267
    }
268
 
269
    return (10 - (result % 10)) % 10;
270
}
271
 
272
function isValidUpcCode(upc) {
273
	if (!isNumeric(upc) || upc.length !== 12) {
274
		return false;
275
	}
276
 
6 - 277
	res = calculateUpcRes(upc.substr(0, 11));
278
 
279
	if (parseInt(upc.substr(11, 1)) != res) {
280
		return false;
281
	}
282
 
283
	return true;
284
}
285
 
286
function calculateUpcRes(upc) {
287
	var i;
288
 
289
	if (!isNumeric(upc) || upc.length !== 11) {
290
		return -1;
291
	}
292
 
2 - 293
	var sum = 0;
294
 
295
	for (i = 0; i < 11; i += 2) {
296
		sum += (parseInt(upc.substr(i, 1)) * 3);
297
	}
298
 
299
	for (i = 1; i < 11; i += 2) {
300
		sum += parseInt(upc.substr(i, 1));
301
	}
302
 
303
	var res = sum % 10;
304
 
305
	if (res > 0) {
306
		res = 10 - res;
307
	}
308
 
6 - 309
	return res;
2 - 310
}
311
 
6 - 312
 
2 - 313
function isValidISBNCode(isbn) {
314
	var sum, weight, digit, check, i;
315
 
316
	if (isbn.length == 13) {
317
		sum = 0;
318
		for (i = 0; i < 12; i++) {
319
			digit = parseInt(isbn[i]);
320
			if (i % 2 == 1) {
321
				sum += 3 * digit;
322
			} else {
323
				sum += digit;
324
			}
325
		}
326
		check = (10 - (sum % 10)) % 10;
327
		return (check == isbn[isbn.length - 1]);
328
	}
329
 
330
	if (isbn.length == 10) {
331
		weight = 10;
332
		sum = 0;
333
		for (i = 0; i < 9; i++) {
334
			digit = parseInt(isbn[i]);
335
			sum += weight * digit;
336
			weight--;
337
		}
338
		check = 11 - (sum % 11);
339
		if (check == 10) {
340
			check = 'X';
341
		}
342
		return (check == isbn[isbn.length - 1].toUpperCase());
343
	}
344
 
345
	return false;
346
}
347
 
348
function escapeXml(unsafe) {
349
	return unsafe.replace(/[<>&'"]/g, function(c) {
350
		switch (c) {
351
			case '<':
352
				return '&lt;';
353
			case '>':
354
				return '&gt;';
355
			case '&':
356
				return '&amp;';
357
			case '\'':
358
				return '&apos;';
359
			case '"':
360
				return '&quot;';
361
		}
362
	});
363
}
364
 
365
 
366
/*
367
/ eBay Login
368
*/
369
function eBayLogin() {
370
	if (eBayAuthTokenFlag === false) {
371
		getSessionID();
372
	}
373
}
374
 
375
function getSessionID() {
376
	// Expects function requireNewLogin
377
	// Expects <div id="results">
378
 
379
	var i;
380
	var xw = new XMLWriter('UTF-8', '1.0');
381
 
382
	xw.writeStartDocument();
383
	xw.writeStartElement('GetSessionIDRequest');
384
	xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
385
	xw.writeElementString('RuName', configRuName);
386
	xw.writeEndElement(); /* GetSessionIDRequest */
387
	xw.writeEndDocument();
388
 
389
	var my_xml = xw.flush();
390
	xw.close();
391
 
392
	var xhr = new XMLHttpRequest();
393
	xhr.open('POST', configProxyUrl, true);
394
	xhr.setRequestHeader('Content-Type', 'text/xml');
395
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
396
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
397
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 398
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 399
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetSessionID');
400
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
401
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
402
 
403
	xhr.onload = function() {
5 - 404
        var xmlDoc = xhr.responseXML;
405
		var returnCode = xmlDoc.getElementsByTagName("Ack")[0].childNodes[0].nodeValue;
2 - 406
 
407
		if (returnCode == 'Success') {
5 - 408
			sessionId = xmlDoc.getElementsByTagName("SessionID")[0].childNodes[0].nodeValue;
2 - 409
 
410
			var win = window.open(configSigninUrl + '?SignIn&RuName=' + configRuName + '&SessID=' + sessionId, "eBay Login", "");
411
			var pollTimer = window.setInterval(function() {
412
				if (win.closed !== false) {
413
					window.clearInterval(pollTimer);
414
					getToken();
3 - 415
        		}
2 - 416
			}, 200);
417
		} else {
418
			requireNewLogin();
6 - 419
 
2 - 420
			var x = document.getElementById("results");
421
			if (x.className.indexOf("w3-show") == -1) {
422
				x.className += " w3-show";
423
			}
424
 
425
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
5 - 426
			var errors = xmlDoc.getElementsByTagName("Errors");
2 - 427
			x.innerHTML += "<p>";
5 - 428
			for (i = 0; i < errors.length; i++) {
429
				x.innerHTML += errors[0].getElementsByTagName("SeverityCode")[0].innerHTML + " (" + errors[0].getElementsByTagName("ErrorCode")[0].innerHTML + "): " + escapeHtml(errors[0].getElementsByTagName("LongMessage")[0].innerHTML) + "<br/>";
2 - 430
			}
431
			x.innerHTML += "</p>";
432
		}
433
	};
434
 
435
	xhr.send(my_xml);
436
}
437
 
438
function getToken() {
439
	var x;
440
	var i;
441
	var xw = new XMLWriter('UTF-8', '1.0');
442
 
443
	xw.writeStartDocument();
444
	xw.writeStartElement('FetchTokenRequest');
445
	xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
446
	xw.writeElementString('SessionID', sessionId);
447
	xw.writeEndElement(); /* FetchTokenRequest */
448
	xw.writeEndDocument();
449
 
450
	var my_xml = xw.flush();
451
	xw.close();
452
 
453
	var xhr = new XMLHttpRequest();
454
	xhr.open('POST', configProxyUrl, true);
455
	xhr.setRequestHeader('Content-Type', 'text/xml');
456
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
457
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
458
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 459
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 460
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'FetchToken');
461
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
462
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
463
 
464
	xhr.onload = function() {
5 - 465
        var xmlDoc = xhr.responseXML;
466
		var returnCode = xmlDoc.getElementsByTagName("Ack")[0].childNodes[0].nodeValue;
2 - 467
 
468
		if (returnCode == 'Success') {
5 - 469
			eBayAuthToken = xmlDoc.getElementsByTagName("eBayAuthToken")[0].childNodes[0].nodeValue;
470
			eBayAuthExpiration = new Date(xmlDoc.getElementsByTagName("HardExpirationTime")[0].childNodes[0].nodeValue).toUTCString();
2 - 471
			writeCookie();
472
			connected();
473
		} else {
474
			requireNewLogin();
475
 
476
			x = document.getElementById("results");
477
			if (x.className.indexOf("w3-show") == -1) {
478
				x.className += " w3-show";
479
			}
480
 
481
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
482
 
5 - 483
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
484
			var errors = xmlDoc.getElementsByTagName("Errors");
2 - 485
			x.innerHTML += "<p>";
5 - 486
			for (i = 0; i < errors.length; i++) {
487
				x.innerHTML += errors[0].getElementsByTagName("SeverityCode")[0].innerHTML + " (" + errors[0].getElementsByTagName("ErrorCode")[0].innerHTML + "): " + escapeHtml(errors[0].getElementsByTagName("LongMessage")[0].innerHTML) + "<br/>";
2 - 488
			}
489
			x.innerHTML += "</p>";
490
		}
491
	};
492
 
493
	xhr.send(my_xml);
494
}
495
 
3 - 496
function getUrlParameter(win, name) {
497
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
498
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
499
    var results = regex.exec(win.location.search);
500
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
6 - 501
}
3 - 502
 
2 - 503
function feebackStarImage(score) {
504
	if (score > 999999) {
505
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootSlvr_25x25.gif" alt="Silver shooting star">';
506
	} else if (score > 499999) {
507
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootGrn_25x25.gif" alt="Green shooting star">';
508
	} else if (score > 99999) {
509
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootRed_25x25.gif" alt="Red shooting star">';
510
	} else if (score > 49999) {
511
		return '<img src="https://ir.ebaystatic.com/pictures/aw/icon/iconShootPrpl_25x25.gif" alt="Purple shooting star">';
512
	} else if (score > 24999) {
513
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootTeal_25x25.gif" alt="Turquoise shooting star">';
514
	} else if (score > 9999) {
515
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootYllw_25x25.gif" alt="Yellow shooting star">';
516
	} else if (score > 4999) {
517
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconGreenStar_25x25.gif" alt="Green star">';
518
	} else if (score > 999) {
519
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconRedStar_25x25.gif" alt="Red star">';
520
	} else if (score > 499) {
521
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconPurpleStar_25x25.gif" alt="Purple star">';
522
	} else if (score > 99) {
523
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconTealStar_25x25.gif" alt="Turquoise star">';
524
	} else if (score > 49) {
525
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconBlueStar_25x25.gif" alt="Blue star">';
526
	} else if (score > 9) {
527
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconYellowStar_25x25.gif" alt="Yellow star">';
528
	}
529
	return '';
530
}
531
 
532
function exportTableToCSV(tablename, filename) {
533
    var csv = [];
534
    var rows = document.getElementById(tablename).querySelectorAll("table tr");
6 - 535
    var dq = '"';
536
    var nq = "'";
2 - 537
 
538
    for (var i = 0; i < rows.length; i++) {
539
        var row = [], cols = rows[i].querySelectorAll("td, th");
540
 
541
        for (var j = 0; j < cols.length; j++) {
6 - 542
            if (cols[j].className.indexOf("w3-hide") == -1) {
543
                if (isNaN(cols[j].innerText)) {
544
                    row.push(dq + cols[j].innerText.replace(/"/g, '""') + dq);
545
                } else {
546
                    row.push((cols[j].innerText.length > 11 ? nq : "") + cols[j].innerText);
547
                }
548
            }
2 - 549
        }
550
 
551
        csv.push(row.join(","));
552
    }
553
 
554
    // Download CSV file
555
    downloadCSV(csv.join("\n"), filename);
556
}
557
 
558
function downloadCSV(csv, filename) {
559
    var csvFile;
560
    var downloadLink;
561
 
562
    // CSV file
563
    csvFile = new Blob([csv], {type: "text/csv"});
564
 
565
    // Download link
566
    downloadLink = document.createElement("a");
567
 
568
    // File name
569
    downloadLink.download = filename;
570
 
571
    // Create a link to the file
572
    downloadLink.href = window.URL.createObjectURL(csvFile);
573
 
574
    // Hide download link
575
    downloadLink.style.display = "none";
576
 
577
    // Add the link to DOM
578
    document.body.appendChild(downloadLink);
579
 
580
    // Click download link
581
    downloadLink.click();
582
}
583
 
584
/* Progress Bar HTML
585
<div id="progressBarDiv" class="w3-container w3-padding w3-margin w3-card-4 w3-hide">
586
	<h2 id="progressBarHeader"></h2>
587
  <div class="w3-light-grey">
588
      <div id="progressBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>
589
  </div>
590
</div>
591
*/
592
function initProgressBar(title) {
593
  	var elem = document.getElementById("progressBar");
594
	  elem.style.width = 0 + '%';
595
  	elem.innerHTML = 0 + '%';
596
 
597
  	elem = document.getElementById("progressBarDiv");
598
	  if (elem.className.indexOf("w3-show") == -1) {
599
		    elem.className += " w3-show";
600
  	}
601
 
602
	  elem = document.getElementById("progressBarHeader");
603
  	elem.innerHTML = title;
604
}
605
 
606
function updateProgressBar(maximum, current) {
607
		var elem = document.getElementById("progressBar");
608
		var width = (current / maximum) * 100;
609
		elem.style.width = width + '%';
610
		elem.innerHTML = width.toFixed(0) + '%';
611
}
612
 
613
function endProgressBar() {
614
    var elem = document.getElementById("progressBarDiv");
615
		elem.className = elem.className.replace(" w3-show", "");
616
}
617
 
6 - 618
// xxxxx WIP
2 - 619
function sortHTMLTable(table, column = 0, type = 's', hasFooter = false) {
620
  var rows, switching, i, x, y, shouldSwitch;
621
  var nonData = (hasFooter ? 2 : 1);
622
  table = document.getElementById(table);
623
  switching = true;
624
  /* Make a loop that will continue until
625
  no switching has been done: */
626
  while (switching) {
627
    // Start by saying: no switching is done:
628
    switching = false;
629
    rows = table.rows;
630
    /* Loop through all table rows (except the
631
    first, which contains table headers): */
632
    for (i = 1; i < (rows.length - nonData); i++) {
633
      // Start by saying there should be no switching:
634
      shouldSwitch = false;
635
      /* Get the two elements you want to compare,
636
      one from current row and one from the next: */
637
      x = rows[i].getElementsByTagName("TD")[column];
638
      y = rows[i + 1].getElementsByTagName("TD")[column];
639
      // Check if the two rows should switch place:
640
      if (type == 'i') { // integer
641
        if (Number(x.innerHTML) > Number(y.innerHTML)) {
642
          // If so, mark as a switch and break the loop:
643
          shouldSwitch = true;
644
          break;
645
        }
646
      } else if (type == 'f') { // float
647
        if (Number(x.innerHTML).toFixed(2) > Number(y.innerHTML).toFixed(2)) {
648
          // If so, mark as a switch and break the loop:
649
          shouldSwitch = true;
650
          break;
651
        }
652
      } else if (type == 'c') { // currency
653
        if (Number(x.innerHTML.substr(1)).toFixed(2) > Number(y.innerHTML.substr(1)).toFixed(2)) {
654
          // If so, mark as a switch and break the loop:
655
          shouldSwitch = true;
656
          break;
657
        }
658
      } else if ('d') { // date
659
        if (Date(x.innerHTML) > Date(y.innerHTML)) {
660
          // If so, mark as a switch and break the loop:
661
          shouldSwitch = true;
662
          break;
663
        }
664
      } else { // string
665
        if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
666
          // If so, mark as a switch and break the loop:
667
          shouldSwitch = true;
668
          break;
669
        }
670
      }
671
    }
672
    if (shouldSwitch) {
673
      /* If a switch has been marked, make the switch
674
      and mark that a switch has been done: */
675
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
676
      switching = true;
677
    }
678
  }
679
}