Subversion Repositories munaweb

Rev

Rev 3 | Rev 6 | 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
//
103
function round(value, decimals) {
104
  return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
105
}
106
 
107
// Polyfill for Internet Explorer
108
Math.trunc = Math.trunc || function(x) {
109
	var n = x - x % 1;
110
	return n === 0 && (x < 0 || (x === 0 && (1 / x !== 1 / 0))) ? -0 : n;
111
};
112
 
113
function tableCell(str) {
114
	return ('<td>' + str + '</td>');
115
}
116
 
117
function tableCellHidden(str) {
118
	return ('<td class="w3-hide">' + str + '</td>');
119
}
120
 
121
function tableHeader(str) {
122
	return ('<th>' + str + '</th>');
123
}
124
 
125
function tableCellLabel(str) {
126
	return ('<td id="' + str + '"></td>');
127
}
128
 
129
function tableCellLabelHidden(str, val) {
130
	return ('<td id="' + str + '" class="w3-hide">' + val + '</td>');
131
}
132
 
133
function tableCellAndLabel(str, label) {
134
	return ('<td id="' + label + '">' + str + '</td>');
135
}
136
 
137
function tableHeaderHidden(str) {
138
	return ('<th class="w3-hide">' + str + '</th>');
139
}
140
 
141
function tableHeaderCheckbox(table) {
142
	return ('<th class="sorter-checkbox filter-false"><input type="checkbox"></th>');
143
}
144
 
145
function tableCellCheckbox() {
146
	return ('<td><input type="checkbox"></td>');
147
}
148
 
149
function escapeHtml(unsafe) {
150
	return unsafe
151
		.replace(/&/g, "&amp;")
152
		.replace(/</g, "&lt;")
153
		.replace(/>/g, "&gt;")
154
		.replace(/"/g, "&quot;")
155
		.replace(/'/g, "&#039;");
156
}
157
 
158
function pad(num, size) {
159
    var s = num+"";
160
    while (s.length < size) s = "0" + s;
161
    return s;
162
}
163
 
164
function isset () {
165
  var a = arguments;
166
  var l = a.length;
167
  var i = 0;
168
  var undef;
169
 
170
  if (l === 0) {
171
    return false;
172
  }
173
 
174
  while (i !== l) {
175
    if (a[i] === undef || a[i] === null) {
176
      return false;
177
    }
178
    i++;
179
  }
180
 
181
  return true;
182
}
183
 
184
function getJsonValue(obj){
185
  return (isset(obj) ? obj : "");
186
}
187
 
188
function writeCookie() {
189
	document.cookie = 'eBayAuthToken=' + encodeURIComponent(eBayAuthToken) + ';expires=' + eBayAuthExpiration + ';';
190
}
191
 
192
function readCookie() {
193
	var name = 'eBayAuthToken=';
194
	var decodedCookie = decodeURIComponent(document.cookie);
195
	var ca = decodedCookie.split(';');
196
	for (var i = 0; i < ca.length; i++) {
197
		var c = ca[i];
198
		while (c.charAt(0) == ' ') {
199
			c = c.substring(1);
200
		}
201
		if (c.indexOf(name) === 0) {
202
			return c.substring(name.length, c.length);
203
		}
204
	}
205
	return "";
206
}
207
 
208
function isNumeric(input) {
209
	return (input - 0) == input && ('' + input).trim().length > 0;
210
}
211
 
212
function getRadioValue(name) {
213
	var group = document.getElementsByName(name);
214
 
215
	for (var i = 0; i < group.length; i++) {
216
		if (group[i].checked) {
217
			return group[i].value;
218
		}
219
	}
220
 
221
	return '';
222
}
223
 
224
function removeDuplicateRows($table){
225
    function getVisibleRowText($row){
226
        return $row.find('td:visible').text().toLowerCase();
227
    }
228
 
229
    $table.find('tr').each(function(index, row){
230
        var $row = $(row);
231
 
232
        $row.nextAll('tr').each(function(index, next){
233
            var $next = $(next);
234
            if(getVisibleRowText($next) == getVisibleRowText($row)) {
235
                $next.remove();
236
            }
237
        });
238
    });
239
}
240
 
241
function isValidUpcOrEanCode(str) {
242
	if (!isNumeric(str)) {
243
		return(false);
244
	}
245
 
246
	if (str.length == 12) {
247
		return(isValidUpcCode(str));
248
	} else if (str.length == 13) {
249
		return(isValidEanCode(str) === 0 ? true : false);
250
	}
251
 
252
	return(false);
253
}
254
 
255
function isValidEanCode(ean) {
256
    var result = 0;
257
    for (var counter = (ean.length - 1); counter >= 0; counter--) {
258
        result = result + parseInt(ean.charAt(counter)) * (1 + (2 * (counter % 2)));
259
    }
260
 
261
    return (10 - (result % 10)) % 10;
262
}
263
 
264
function isValidUpcCode(upc) {
265
	var i;
266
 
267
	if (!isNumeric(upc) || upc.length !== 12) {
268
		return false;
269
	}
270
 
271
	var sum = 0;
272
 
273
	for (i = 0; i < 11; i += 2) {
274
		sum += (parseInt(upc.substr(i, 1)) * 3);
275
	}
276
 
277
	for (i = 1; i < 11; i += 2) {
278
		sum += parseInt(upc.substr(i, 1));
279
	}
280
 
281
	var res = sum % 10;
282
 
283
	if (res > 0) {
284
		res = 10 - res;
285
	}
286
 
287
	if (Number(upc.substr(11, 1)) != res) {
288
		return false;
289
	}
290
 
291
	return true;
292
}
293
 
294
function isValidISBNCode(isbn) {
295
	var sum, weight, digit, check, i;
296
 
297
	if (isbn.length == 13) {
298
		sum = 0;
299
		for (i = 0; i < 12; i++) {
300
			digit = parseInt(isbn[i]);
301
			if (i % 2 == 1) {
302
				sum += 3 * digit;
303
			} else {
304
				sum += digit;
305
			}
306
		}
307
		check = (10 - (sum % 10)) % 10;
308
		return (check == isbn[isbn.length - 1]);
309
	}
310
 
311
	if (isbn.length == 10) {
312
		weight = 10;
313
		sum = 0;
314
		for (i = 0; i < 9; i++) {
315
			digit = parseInt(isbn[i]);
316
			sum += weight * digit;
317
			weight--;
318
		}
319
		check = 11 - (sum % 11);
320
		if (check == 10) {
321
			check = 'X';
322
		}
323
		return (check == isbn[isbn.length - 1].toUpperCase());
324
	}
325
 
326
	return false;
327
}
328
 
329
function escapeXml(unsafe) {
330
	return unsafe.replace(/[<>&'"]/g, function(c) {
331
		switch (c) {
332
			case '<':
333
				return '&lt;';
334
			case '>':
335
				return '&gt;';
336
			case '&':
337
				return '&amp;';
338
			case '\'':
339
				return '&apos;';
340
			case '"':
341
				return '&quot;';
342
		}
343
	});
344
}
345
 
346
 
347
/*
348
/ eBay Login
349
*/
350
function eBayLogin() {
351
	if (eBayAuthTokenFlag === false) {
352
		getSessionID();
353
	}
354
}
355
 
356
function getSessionID() {
357
	// Expects function requireNewLogin
358
	// Expects <div id="results">
359
 
360
	var i;
3 - 361
	var statusCode = '';
2 - 362
	var xw = new XMLWriter('UTF-8', '1.0');
363
 
364
	xw.writeStartDocument();
365
	xw.writeStartElement('GetSessionIDRequest');
366
	xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
367
	xw.writeElementString('RuName', configRuName);
368
	xw.writeEndElement(); /* GetSessionIDRequest */
369
	xw.writeEndDocument();
370
 
371
	var my_xml = xw.flush();
372
	xw.close();
373
 
374
	var xhr = new XMLHttpRequest();
375
	xhr.open('POST', configProxyUrl, true);
376
	xhr.setRequestHeader('Content-Type', 'text/xml');
377
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
378
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
379
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 380
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 381
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetSessionID');
382
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
383
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
384
 
385
	xhr.onload = function() {
5 - 386
        var xmlDoc = xhr.responseXML;
387
		var returnCode = xmlDoc.getElementsByTagName("Ack")[0].childNodes[0].nodeValue;
2 - 388
 
389
		if (returnCode == 'Success') {
5 - 390
			sessionId = xmlDoc.getElementsByTagName("SessionID")[0].childNodes[0].nodeValue;
2 - 391
 
392
			var win = window.open(configSigninUrl + '?SignIn&RuName=' + configRuName + '&SessID=' + sessionId, "eBay Login", "");
393
			var pollTimer = window.setInterval(function() {
394
				if (win.closed !== false) {
395
					window.clearInterval(pollTimer);
396
					getToken();
3 - 397
        		}
2 - 398
			}, 200);
399
		} else {
400
			requireNewLogin();
5 - 401
 
2 - 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>";
5 - 408
			var errors = xmlDoc.getElementsByTagName("Errors");
2 - 409
			x.innerHTML += "<p>";
5 - 410
			for (i = 0; i < errors.length; i++) {
411
				x.innerHTML += errors[0].getElementsByTagName("SeverityCode")[0].innerHTML + " (" + errors[0].getElementsByTagName("ErrorCode")[0].innerHTML + "): " + escapeHtml(errors[0].getElementsByTagName("LongMessage")[0].innerHTML) + "<br/>";
2 - 412
			}
413
			x.innerHTML += "</p>";
414
		}
415
	};
416
 
417
	xhr.send(my_xml);
418
}
419
 
420
function getToken() {
421
	var x;
422
	var i;
423
	var xw = new XMLWriter('UTF-8', '1.0');
3 - 424
	var expDate;
2 - 425
 
426
	xw.writeStartDocument();
427
	xw.writeStartElement('FetchTokenRequest');
428
	xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
429
	xw.writeElementString('SessionID', sessionId);
430
	xw.writeEndElement(); /* FetchTokenRequest */
431
	xw.writeEndDocument();
432
 
433
	var my_xml = xw.flush();
434
	xw.close();
435
 
436
	var xhr = new XMLHttpRequest();
437
	xhr.open('POST', configProxyUrl, true);
438
	xhr.setRequestHeader('Content-Type', 'text/xml');
439
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
440
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
441
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 442
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 443
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'FetchToken');
444
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
445
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
446
 
447
	xhr.onload = function() {
5 - 448
        var xmlDoc = xhr.responseXML;
449
		var returnCode = xmlDoc.getElementsByTagName("Ack")[0].childNodes[0].nodeValue;
2 - 450
 
451
		if (returnCode == 'Success') {
5 - 452
			eBayAuthToken = xmlDoc.getElementsByTagName("eBayAuthToken")[0].childNodes[0].nodeValue;
453
			eBayAuthExpiration = new Date(xmlDoc.getElementsByTagName("HardExpirationTime")[0].childNodes[0].nodeValue).toUTCString();
2 - 454
			writeCookie();
455
			connected();
456
		} else {
457
			requireNewLogin();
458
 
459
			x = document.getElementById("results");
460
			if (x.className.indexOf("w3-show") == -1) {
461
				x.className += " w3-show";
462
			}
463
 
464
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
465
 
5 - 466
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
467
			var errors = xmlDoc.getElementsByTagName("Errors");
2 - 468
			x.innerHTML += "<p>";
5 - 469
			for (i = 0; i < errors.length; i++) {
470
				x.innerHTML += errors[0].getElementsByTagName("SeverityCode")[0].innerHTML + " (" + errors[0].getElementsByTagName("ErrorCode")[0].innerHTML + "): " + escapeHtml(errors[0].getElementsByTagName("LongMessage")[0].innerHTML) + "<br/>";
2 - 471
			}
472
			x.innerHTML += "</p>";
473
		}
474
	};
475
 
476
	xhr.send(my_xml);
477
}
478
 
3 - 479
function getUrlParameter(win, name) {
480
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
481
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
482
    var results = regex.exec(win.location.search);
483
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
484
};
485
 
2 - 486
function feebackStarImage(score) {
487
	if (score > 999999) {
488
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootSlvr_25x25.gif" alt="Silver shooting star">';
489
	} else if (score > 499999) {
490
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootGrn_25x25.gif" alt="Green shooting star">';
491
	} else if (score > 99999) {
492
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootRed_25x25.gif" alt="Red shooting star">';
493
	} else if (score > 49999) {
494
		return '<img src="https://ir.ebaystatic.com/pictures/aw/icon/iconShootPrpl_25x25.gif" alt="Purple shooting star">';
495
	} else if (score > 24999) {
496
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootTeal_25x25.gif" alt="Turquoise shooting star">';
497
	} else if (score > 9999) {
498
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootYllw_25x25.gif" alt="Yellow shooting star">';
499
	} else if (score > 4999) {
500
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconGreenStar_25x25.gif" alt="Green star">';
501
	} else if (score > 999) {
502
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconRedStar_25x25.gif" alt="Red star">';
503
	} else if (score > 499) {
504
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconPurpleStar_25x25.gif" alt="Purple star">';
505
	} else if (score > 99) {
506
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconTealStar_25x25.gif" alt="Turquoise star">';
507
	} else if (score > 49) {
508
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconBlueStar_25x25.gif" alt="Blue star">';
509
	} else if (score > 9) {
510
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconYellowStar_25x25.gif" alt="Yellow star">';
511
	}
512
	return '';
513
}
514
 
515
function exportTableToCSV(tablename, filename) {
516
    var csv = [];
517
    var rows = document.getElementById(tablename).querySelectorAll("table tr");
518
    var dq;
519
 
520
    for (var i = 0; i < rows.length; i++) {
521
        var row = [], cols = rows[i].querySelectorAll("td, th");
522
 
523
        for (var j = 0; j < cols.length; j++) {
524
          if (cols[j].className.indexOf("w3-hide") == -1) {
525
            dq = (cols[j].innerText.contains(",") ? '"' : '');
526
            row.push(dq + cols[j].innerText.replace(/"/g, '""') + dq);
527
          }
528
        }
529
 
530
        csv.push(row.join(","));
531
    }
532
 
533
    // Download CSV file
534
    downloadCSV(csv.join("\n"), filename);
535
}
536
 
537
function downloadCSV(csv, filename) {
538
    var csvFile;
539
    var downloadLink;
540
 
541
    // CSV file
542
    csvFile = new Blob([csv], {type: "text/csv"});
543
 
544
    // Download link
545
    downloadLink = document.createElement("a");
546
 
547
    // File name
548
    downloadLink.download = filename;
549
 
550
    // Create a link to the file
551
    downloadLink.href = window.URL.createObjectURL(csvFile);
552
 
553
    // Hide download link
554
    downloadLink.style.display = "none";
555
 
556
    // Add the link to DOM
557
    document.body.appendChild(downloadLink);
558
 
559
    // Click download link
560
    downloadLink.click();
561
}
562
 
563
/* Progress Bar HTML
564
<div id="progressBarDiv" class="w3-container w3-padding w3-margin w3-card-4 w3-hide">
565
	<h2 id="progressBarHeader"></h2>
566
  <div class="w3-light-grey">
567
      <div id="progressBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>
568
  </div>
569
</div>
570
*/
571
function initProgressBar(title) {
572
  	var elem = document.getElementById("progressBar");
573
	  elem.style.width = 0 + '%';
574
  	elem.innerHTML = 0 + '%';
575
 
576
  	elem = document.getElementById("progressBarDiv");
577
	  if (elem.className.indexOf("w3-show") == -1) {
578
		    elem.className += " w3-show";
579
  	}
580
 
581
	  elem = document.getElementById("progressBarHeader");
582
  	elem.innerHTML = title;
583
}
584
 
585
function updateProgressBar(maximum, current) {
586
		var elem = document.getElementById("progressBar");
587
		var width = (current / maximum) * 100;
588
		elem.style.width = width + '%';
589
		elem.innerHTML = width.toFixed(0) + '%';
590
}
591
 
592
function endProgressBar() {
593
    var elem = document.getElementById("progressBarDiv");
594
		elem.className = elem.className.replace(" w3-show", "");
595
}
596
 
597
function sortHTMLTable(table, column = 0, type = 's', hasFooter = false) {
598
  var rows, switching, i, x, y, shouldSwitch;
599
  var nonData = (hasFooter ? 2 : 1);
600
  table = document.getElementById(table);
601
  switching = true;
602
  /* Make a loop that will continue until
603
  no switching has been done: */
604
  while (switching) {
605
    // Start by saying: no switching is done:
606
    switching = false;
607
    rows = table.rows;
608
    /* Loop through all table rows (except the
609
    first, which contains table headers): */
610
    for (i = 1; i < (rows.length - nonData); i++) {
611
      // Start by saying there should be no switching:
612
      shouldSwitch = false;
613
      /* Get the two elements you want to compare,
614
      one from current row and one from the next: */
615
      x = rows[i].getElementsByTagName("TD")[column];
616
      y = rows[i + 1].getElementsByTagName("TD")[column];
617
      // Check if the two rows should switch place:
618
      if (type == 'i') { // integer
619
        if (Number(x.innerHTML) > Number(y.innerHTML)) {
620
          // If so, mark as a switch and break the loop:
621
          shouldSwitch = true;
622
          break;
623
        }
624
      } else if (type == 'f') { // float
625
        if (Number(x.innerHTML).toFixed(2) > Number(y.innerHTML).toFixed(2)) {
626
          // If so, mark as a switch and break the loop:
627
          shouldSwitch = true;
628
          break;
629
        }
630
      } else if (type == 'c') { // currency
631
        if (Number(x.innerHTML.substr(1)).toFixed(2) > Number(y.innerHTML.substr(1)).toFixed(2)) {
632
          // If so, mark as a switch and break the loop:
633
          shouldSwitch = true;
634
          break;
635
        }
636
      } else if ('d') { // date
637
        if (Date(x.innerHTML) > Date(y.innerHTML)) {
638
          // If so, mark as a switch and break the loop:
639
          shouldSwitch = true;
640
          break;
641
        }
642
      } else { // string
643
        if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
644
          // If so, mark as a switch and break the loop:
645
          shouldSwitch = true;
646
          break;
647
        }
648
      }
649
    }
650
    if (shouldSwitch) {
651
      /* If a switch has been marked, make the switch
652
      and mark that a switch has been done: */
653
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
654
      switching = true;
655
    }
656
  }
657
}