Subversion Repositories munaweb

Rev

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