Subversion Repositories munaweb

Rev

Rev 2 | Rev 5 | 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
	//window.alert(vkbeautify.xml(my_xml));
374
 
375
	var xhr = new XMLHttpRequest();
376
	xhr.open('POST', configProxyUrl, true);
377
	xhr.setRequestHeader('Content-Type', 'text/xml');
378
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
379
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
380
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 381
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 382
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'GetSessionID');
383
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
384
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
385
 
386
	xhr.onload = function() {
387
		var obj = XMLparse(xhr.responseXML);
388
		//window.alert(JSON.stringify(obj));
389
		//window.alert(vkbeautify.xml(xhr.responseText));
390
 
391
		var returnCode = obj.Ack;
392
 
393
		if (returnCode == 'Success') {
394
			sessionId = xhr.responseXML.getElementsByTagName("SessionID")[0].childNodes[0].nodeValue;
395
 
396
			var win = window.open(configSigninUrl + '?SignIn&RuName=' + configRuName + '&SessID=' + sessionId, "eBay Login", "");
397
			var pollTimer = window.setInterval(function() {
398
				if (win.closed !== false) {
399
					window.clearInterval(pollTimer);
400
					getToken();
3 - 401
        		}
2 - 402
			}, 200);
403
		} else {
404
			requireNewLogin();
405
			var x = document.getElementById("results");
406
			if (x.className.indexOf("w3-show") == -1) {
407
				x.className += " w3-show";
408
			}
409
 
410
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
411
 
412
			var errors = obj.Errors;
413
			x.innerHTML += "<p>";
414
			if (errors.length > 0) {
415
				for (i = 0; i < errors.length; i++) {
416
					x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
417
				}
418
			} else {
419
				x.innerHTML += obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "<br/>";
420
			}
421
			x.innerHTML += "</p>";
422
		}
423
	};
424
 
425
	xhr.send(my_xml);
426
}
427
 
428
function getToken() {
429
	var x;
430
	var i;
431
	var xw = new XMLWriter('UTF-8', '1.0');
3 - 432
	var expDate;
2 - 433
 
434
	xw.writeStartDocument();
435
	xw.writeStartElement('FetchTokenRequest');
436
	xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
437
	xw.writeElementString('SessionID', sessionId);
438
	xw.writeEndElement(); /* FetchTokenRequest */
439
	xw.writeEndDocument();
440
 
441
	var my_xml = xw.flush();
442
	xw.close();
443
	//window.alert(vkbeautify.xml(my_xml));
444
 
445
	var xhr = new XMLHttpRequest();
446
	xhr.open('POST', configProxyUrl, true);
447
	xhr.setRequestHeader('Content-Type', 'text/xml');
448
	xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
449
	xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
450
	xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
3 - 451
	xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
2 - 452
	xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'FetchToken');
453
	xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
454
	xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
455
 
456
	xhr.onload = function() {
457
		var obj = XMLparse(xhr.responseXML);
458
		//window.alert(JSON.stringify(obj));
459
		//window.alert(vkbeautify.xml(xhr.responseText));
460
 
461
		var returnCode = obj.Ack;
462
 
463
		if (returnCode == 'Success') {
464
			eBayAuthToken = obj.eBayAuthToken;
3 - 465
			eBayAuthExpiration = new Date(obj.HardExpirationTime).toUTCString();
2 - 466
			writeCookie();
467
			connected();
468
		} else {
469
			requireNewLogin();
470
 
471
			x = document.getElementById("results");
472
			if (x.className.indexOf("w3-show") == -1) {
473
				x.className += " w3-show";
474
			}
475
 
476
			x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";
477
 
478
			var errors = obj.Errors;
479
			x.innerHTML += "<p>";
480
			if (errors.length > 0) {
481
				for (i = 0; i < errors.length; i++) {
482
					x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
483
				}
484
			} else {
485
				x.innerHTML += obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "<br/>";
486
			}
487
			x.innerHTML += "</p>";
488
		}
489
	};
490
 
491
	xhr.send(my_xml);
492
}
493
 
3 - 494
function getUrlParameter(win, name) {
495
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
496
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
497
    var results = regex.exec(win.location.search);
498
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
499
};
500
 
2 - 501
function feebackStarImage(score) {
502
	if (score > 999999) {
503
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootSlvr_25x25.gif" alt="Silver shooting star">';
504
	} else if (score > 499999) {
505
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootGrn_25x25.gif" alt="Green shooting star">';
506
	} else if (score > 99999) {
507
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootRed_25x25.gif" alt="Red shooting star">';
508
	} else if (score > 49999) {
509
		return '<img src="https://ir.ebaystatic.com/pictures/aw/icon/iconShootPrpl_25x25.gif" alt="Purple shooting star">';
510
	} else if (score > 24999) {
511
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootTeal_25x25.gif" alt="Turquoise shooting star">';
512
	} else if (score > 9999) {
513
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconShootYllw_25x25.gif" alt="Yellow shooting star">';
514
	} else if (score > 4999) {
515
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconGreenStar_25x25.gif" alt="Green star">';
516
	} else if (score > 999) {
517
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconRedStar_25x25.gif" alt="Red star">';
518
	} else if (score > 499) {
519
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconPurpleStar_25x25.gif" alt="Purple star">';
520
	} else if (score > 99) {
521
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconTealStar_25x25.gif" alt="Turquoise star">';
522
	} else if (score > 49) {
523
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconBlueStar_25x25.gif" alt="Blue star">';
524
	} else if (score > 9) {
525
		return '<img src="https://ir.ebaystatic.com/pictures/aw/pics/icon/iconYellowStar_25x25.gif" alt="Yellow star">';
526
	}
527
	return '';
528
}
529
 
530
function exportTableToCSV(tablename, filename) {
531
    var csv = [];
532
    var rows = document.getElementById(tablename).querySelectorAll("table tr");
533
    var dq;
534
 
535
    for (var i = 0; i < rows.length; i++) {
536
        var row = [], cols = rows[i].querySelectorAll("td, th");
537
 
538
        for (var j = 0; j < cols.length; j++) {
539
          if (cols[j].className.indexOf("w3-hide") == -1) {
540
            dq = (cols[j].innerText.contains(",") ? '"' : '');
541
            row.push(dq + cols[j].innerText.replace(/"/g, '""') + dq);
542
          }
543
        }
544
 
545
        csv.push(row.join(","));
546
    }
547
 
548
    // Download CSV file
549
    downloadCSV(csv.join("\n"), filename);
550
}
551
 
552
function downloadCSV(csv, filename) {
553
    var csvFile;
554
    var downloadLink;
555
 
556
    // CSV file
557
    csvFile = new Blob([csv], {type: "text/csv"});
558
 
559
    // Download link
560
    downloadLink = document.createElement("a");
561
 
562
    // File name
563
    downloadLink.download = filename;
564
 
565
    // Create a link to the file
566
    downloadLink.href = window.URL.createObjectURL(csvFile);
567
 
568
    // Hide download link
569
    downloadLink.style.display = "none";
570
 
571
    // Add the link to DOM
572
    document.body.appendChild(downloadLink);
573
 
574
    // Click download link
575
    downloadLink.click();
576
}
577
 
578
/* Progress Bar HTML
579
<div id="progressBarDiv" class="w3-container w3-padding w3-margin w3-card-4 w3-hide">
580
	<h2 id="progressBarHeader"></h2>
581
  <div class="w3-light-grey">
582
      <div id="progressBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>
583
  </div>
584
</div>
585
*/
586
function initProgressBar(title) {
587
  	var elem = document.getElementById("progressBar");
588
	  elem.style.width = 0 + '%';
589
  	elem.innerHTML = 0 + '%';
590
 
591
  	elem = document.getElementById("progressBarDiv");
592
	  if (elem.className.indexOf("w3-show") == -1) {
593
		    elem.className += " w3-show";
594
  	}
595
 
596
	  elem = document.getElementById("progressBarHeader");
597
  	elem.innerHTML = title;
598
}
599
 
600
function updateProgressBar(maximum, current) {
601
		var elem = document.getElementById("progressBar");
602
		var width = (current / maximum) * 100;
603
		elem.style.width = width + '%';
604
		elem.innerHTML = width.toFixed(0) + '%';
605
}
606
 
607
function endProgressBar() {
608
    var elem = document.getElementById("progressBarDiv");
609
		elem.className = elem.className.replace(" w3-show", "");
610
}
611
 
612
function sortHTMLTable(table, column = 0, type = 's', hasFooter = false) {
613
  var rows, switching, i, x, y, shouldSwitch;
614
  var nonData = (hasFooter ? 2 : 1);
615
  table = document.getElementById(table);
616
  switching = true;
617
  /* Make a loop that will continue until
618
  no switching has been done: */
619
  while (switching) {
620
    // Start by saying: no switching is done:
621
    switching = false;
622
    rows = table.rows;
623
    /* Loop through all table rows (except the
624
    first, which contains table headers): */
625
    for (i = 1; i < (rows.length - nonData); i++) {
626
      // Start by saying there should be no switching:
627
      shouldSwitch = false;
628
      /* Get the two elements you want to compare,
629
      one from current row and one from the next: */
630
      x = rows[i].getElementsByTagName("TD")[column];
631
      y = rows[i + 1].getElementsByTagName("TD")[column];
632
      // Check if the two rows should switch place:
633
      if (type == 'i') { // integer
634
        if (Number(x.innerHTML) > Number(y.innerHTML)) {
635
          // If so, mark as a switch and break the loop:
636
          shouldSwitch = true;
637
          break;
638
        }
639
      } else if (type == 'f') { // float
640
        if (Number(x.innerHTML).toFixed(2) > Number(y.innerHTML).toFixed(2)) {
641
          // If so, mark as a switch and break the loop:
642
          shouldSwitch = true;
643
          break;
644
        }
645
      } else if (type == 'c') { // currency
646
        if (Number(x.innerHTML.substr(1)).toFixed(2) > Number(y.innerHTML.substr(1)).toFixed(2)) {
647
          // If so, mark as a switch and break the loop:
648
          shouldSwitch = true;
649
          break;
650
        }
651
      } else if ('d') { // date
652
        if (Date(x.innerHTML) > Date(y.innerHTML)) {
653
          // If so, mark as a switch and break the loop:
654
          shouldSwitch = true;
655
          break;
656
        }
657
      } else { // string
658
        if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
659
          // If so, mark as a switch and break the loop:
660
          shouldSwitch = true;
661
          break;
662
        }
663
      }
664
    }
665
    if (shouldSwitch) {
666
      /* If a switch has been marked, make the switch
667
      and mark that a switch has been done: */
668
      rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
669
      switching = true;
670
    }
671
  }
672
}