-
Notifications
You must be signed in to change notification settings - Fork 262
/
BingVisualSearchApp.html
637 lines (552 loc) · 28.5 KB
/
BingVisualSearchApp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<!-- the above Mark of the Web lets IE run this page in the Internet security zone,
avoiding the permission prompt for running active content such as JavaScript -->
<html>
<head>
<meta charset="UTF-8">
<title>Bing Image Search API Demo</title>
<base target="_blank">
<style type="text/css">
html, body, div, p, h1, h2 {font-family: Verdana, "Lucida Sans", sans-serif; color: #000;}
html, body, div, p {font-weight: normal;}
body {background-color: #fff;}
h1, h2, h3 {font-weight: bold; color: #087;}
sup {font-weight: normal;}
html, body, div, p {font-size: 12px;}
h1 {font-size: 20px; margin-top: 30px;}
h2 {font-size: 16px; clear: left;}
h3 {font-size: 14px; clear: left;}
#sidebar {font-size: 10px; text-align: right; display: flex; padding: 0px 10px;
float: right; margin-left: 15px; margin-right: 0px;}
#sidebar p {margin-top: 0px; font-size: 10px;}
#sidebar img {display: inline-block; float: none; padding-right: 0px;}
#pole p {font-size: 14px;}
#pole, #mainline, #json, #http, #sidebar, #error, #paging1, #paging2
{display: none;}
#term {width: 100%;}
#logo {padding: 15px; float: right; border-left: 2px solid #ccc;}
#query {float: left;}
img {vertical-align: top; float: left; margin-right: 10px; margin-bottom: 10px;}
p.images {display: inline-block; font-size: 9px; vertical-align: top;}
p.images img {float: none;}
p.relatedSearches {clear: none;}
#logo p, p.news, p.webPages, p.images {clear: left;}
a[href="#"]:link {color: blue;}
a[href="#"]:visited {color: blue;}
h3 a:visited {color: #087 !important;}
h3 a:link {color: #087 !important;}
</style>
<script type="text/javascript">
// cookie names for data we store
// YOUR API KEY DOES NOT GO IN THIS CODE; don't paste it in.
IS_API_KEY_COOKIE = "bing-imagesearch-api-key";
VS_API_KEY_COOKIE = "bing-visualsearch-api-key";
CLIENT_ID_COOKIE = "bing-search-client-id";
// Bing Search API endpoint
BING_ENDPOINT = "https://api.cognitive.microsoft.com/bing/v7.0/images/search";
// Various browsers differ in their support for persistent storage by local
// HTML files (IE won't use localStorage, but Chrome won't use cookies). So
// use localStorage if we can, otherwise use cookies.
try {
localStorage.getItem; // try localStorage
window.retrieveValue = function (name) {
return localStorage.getItem(name) || "";
}
window.storeValue = function(name, value) {
localStorage.setItem(name, value);
}
} catch (e) {
window.retrieveValue = function (name) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var keyvalue = cookies[i].split("=");
if (keyvalue[0].trim() === name) return keyvalue[1];
}
return "";
}
window.storeValue = function (name, value) {
var expiry = new Date();
expiry.setFullYear(expiry.getFullYear() + 1);
document.cookie = name + "=" + value.trim() + "; expires=" + expiry.toUTCString();
}
}
// get stored API subscription key, or prompt if it's not found
function getSubscriptionKey(API_name) {
if (API_name == 'image_search'){
var key = retrieveValue(IS_API_KEY_COOKIE);
var message = "Enter Bing Image Search API subscription key:"
while (key.length !== 32) {
key = prompt(message, "").trim();
}
// always set the cookie in order to update the expiration date
storeValue(IS_API_KEY_COOKIE, key);
} else if (API_name == 'visual_search') {
var key = retrieveValue(VS_API_KEY_COOKIE);
var message = "Enter Bing Visual Search API subscription key:"
while (key.length !== 32) {
key = prompt(message, "").trim();
}
// always set the cookie in order to update the expiration date
storeValue(VS_API_KEY_COOKIE, key);
}
return key;
}
// invalidate stored API subscription key so user will be prompted again
function invalidateSubscriptionKey(API_name) {
if(API_name == 'image_search') {
storeValue(IS_API_KEY_COOKIE, "");
} else if (API_name == 'visual_search'){
storeValue(VS_API_KEY_COOKIE, "");
}
}
// escape text for use in HTML
function escape(text) {
return text.replace(/&/g, "&").replace(/</g, "<").
replace(/'/g, "'").replace(/"/g, """);
}
// get the host portion of a URL, stripping out search result formatting and www too
function getHost(url) {
return url.replace(/<\/?b>/g, "").replace(/^https?:\/\//, "").split("/")[0].replace(/^www\./, "");
}
// format plain text for display as an HTML <pre> element
function preFormat(text) {
text = "" + text;
return "<pre>" + text.replace(/&/g, "&").replace(/</g, "<") + "</pre>"
}
// put HTML markup into a <div> and reveal it
function showDiv(id, html) {
var content = document.getElementById("_" + id)
if (content) content.innerHTML = html;
var wrapper = document.getElementById(id);
if (wrapper) wrapper.style.display = html.trim() ? "block" : "none";
}
// hides the specified <div>s
function hideDivs() {
for (var i = 0; i < arguments.length; i++) {
var element = document.getElementById(arguments[i])
if (element) element.style.display = "none";
}
}
// render functions for various types of search results
searchItemRenderers = {
images: function (item, index, count) {
var height = 120;
var width = Math.max(Math.round(height * item.thumbnail.width / item.thumbnail.height), 120);
var html = [];
if (index === 0) html.push("<p class='images'>");
var title = escape(item.name) + "\n" + getHost(item.hostPageDisplayUrl);
html.push("<p class='images' style='max-width: " + width + "px'>");
html.push("<img src='"+ item.thumbnailUrl + "&h=" + height + "&w=" + width +
"' height=" + height + " width=" + width + "'>");
html.push("<br>");
html.push("<nobr><a href='" + item.contentUrl + "'>Image</a> - ");
html.push("<a href='" + item.hostPageUrl + "'>Page</a></nobr><br>");
html.push("<a href='javascript:bingVisualSearch(\"" + item.imageInsightsToken + "\");'>find similar</a><br>");
html.push(title.replace("\n", " (").replace(/([a-z0-9])\.([a-z0-9])/g, "$1.<wbr>$2") + ")</p>");
return html.join("");
},
relatedSearches: function(item) {
var html = [];
html.push("<p class='relatedSearches'>");
html.push("<a href='#' onclick='return doRelatedSearch("" +
escape(item.text) + "")'>");
html.push(item.displayText + "</a>");
return html.join("");
}
}
// render image search results
function renderImageResults(items) {
var len = items.length;
var html = [];
if (!len) {
showDiv("noresults", "No results.");
hideDivs("paging1", "paging2");
return "";
}
for (var i = 0; i < len; i++) {
html.push(searchItemRenderers.images(items[i], i, len));
}
return html.join("\n\n");
}
// render related items
function renderRelatedItems(items) {
var len = items.length;
var html = [];
for (var i = 0; i < len; i++) {
html.push(searchItemRenderers.relatedSearches(items[i], i, len));
}
return html.join("\n\n");
}
// render the search results given the parsed JSON response
function renderSearchResults(results) {
// add Prev / Next links with result count
var pagingLinks = renderPagingLinks(results);
showDiv("paging1", pagingLinks);
showDiv("paging2", pagingLinks);
showDiv("results", renderImageResults(results.value));
if (results.relatedSearches)
showDiv("sidebar", renderRelatedItems(results.relatedSearches));
}
function renderErrorMessage(message) {
showDiv("error", preFormat(message));
showDiv("noresults", "No results.");
}
// handle Bing search request results
function handleBingResponse() {
hideDivs("noresults");
var json = this.responseText.trim();
var jsobj = {};
// try to parse JSON results
try {
if (json.length) jsobj = JSON.parse(json);
} catch(e) {
renderErrorMessage("Invalid JSON response");
}
// show raw JSON and HTTP request
showDiv("json", preFormat(JSON.stringify(jsobj, null, 2)));
showDiv("http", preFormat("GET " + this.responseURL + "\n\nStatus: " + this.status + " " +
this.statusText + "\n" + this.getAllResponseHeaders()));
// if HTTP response is 200 OK, try to render search results
if (this.status === 200) {
var clientid = this.getResponseHeader("X-MSEdge-ClientID");
if (clientid) retrieveValue(CLIENT_ID_COOKIE, clientid);
if (json.length) {
if (jsobj._type === "Images") {
if (jsobj.nextOffset) document.forms.bing.nextoffset.value = jsobj.nextOffset;
renderSearchResults(jsobj);
} else {
renderErrorMessage("No search results in JSON response");
}
} else {
renderErrorMessage("Empty response (are you sending too many requests too quickly?)");
}
}
// Any other HTTP response is an error
else {
// 401 is unauthorized; force re-prompt for API key for next request
if (this.status === 401) invalidateSubscriptionKey('image_search');
// some error responses don't have a top-level errors object
var errors = jsobj.errors || [jsobj];
var errmsg = [];
// display HTTP status code
errmsg.push("HTTP Status " + this.status + " " + this.statusText + "\n");
// add all fields from all error responses
for (var i = 0; i < errors.length; i++) {
if (i) errmsg.push("\n");
for (var k in errors[i]) errmsg.push(k + ": " + errors[i][k]);
}
// also display Bing Trace ID if it isn't blocked by CORS
var traceid = this.getResponseHeader("BingAPIs-TraceId");
if (traceid) errmsg.push("\nTrace ID " + traceid);
// and display the error message
renderErrorMessage(errmsg.join("\n"));
}
}
// perform a search given query, options string, and API key
function bingImageSearch(query, options, key) {
// scroll to top of window
window.scrollTo(0, 0);
if (!query.trim().length) return false; // empty query, do nothing
showDiv("noresults", "Working. Please wait.");
hideDivs("results", "related", "_json", "_http", "paging1", "paging2", "error");
var request = new XMLHttpRequest();
var queryurl = BING_ENDPOINT + "?q=" + encodeURIComponent(query) + "&" + options;
// open the request
try {
request.open("GET", queryurl);
}
catch (e) {
renderErrorMessage("Bad request (invalid URL)\n" + queryurl);
return false;
}
// add request headers
request.setRequestHeader("Ocp-Apim-Subscription-Key", key);
request.setRequestHeader("Accept", "application/json");
var clientid = retrieveValue(CLIENT_ID_COOKIE);
if (clientid) request.setRequestHeader("X-MSEdge-ClientID", clientid);
// event handler for successful response
request.addEventListener("load", handleBingResponse);
// event handler for erorrs
request.addEventListener("error", function() {
renderErrorMessage("Error completing request");
});
// event handler for aborted request
request.addEventListener("abort", function() {
renderErrorMessage("Request aborted");
});
// send the request
request.send();
return false;
}
// build query options from the HTML form
function bingSearchOptions(form) {
var options = [];
options.push("mkt=" + form.where.value);
options.push("SafeSearch=" + (form.safe.checked ? "strict" : "off"));
if (form.when.value.length) options.push("freshness=" + form.when.value);
var aspect = "all";
for (var i = 0; i < form.aspect.length; i++) {
if (form.aspect[i].checked) {
aspect = form.aspect[i].value;
break;
}
}
options.push("aspect=" + aspect);
if (form.color.value) options.push("color=" + form.color.value);
options.push("count=" + form.count.value);
options.push("offset=" + form.offset.value);
return options.join("&");
}
// toggle display of a div (used by JSON/HTTP expandos)
function toggleDisplay(id) {
var element = document.getElementById(id);
if (element) {
var display = element.style.display;
if (display === "none") {
element.style.display = "block";
window.scrollBy(0, 200);
} else {
element.style.display = "none";
}
}
return false;
}
// perform a related search (used by related search links)
function doRelatedSearch(query) {
var bing = document.forms.bing;
bing.query.value = query;
return newBingImageSearch(bing);
}
// generate the HTML for paging links (prev/next)
function renderPagingLinks(results) {
var html = [];
var bing = document.forms.bing;
var offset = parseInt(bing.offset.value, 10);
var count = parseInt(bing.count.value, 10);
html.push("<p class='paging'><i>Results " + (offset + 1) + " to " + (offset + count));
html.push(" of about " + results.totalEstimatedMatches + ".</i> ");
html.push("<a href='#' onclick='return doPrevSearchPage()'>Prev</a> | ");
html.push("<a href='#' onclick='return doNextSearchPage()'>Next</a>");
return html.join("");
}
// go to the next page (used by next page link)
function doNextSearchPage() {
var bing = document.forms.bing;
var query = bing.query.value;
var offset = parseInt(bing.offset.value, 10);
var stack = JSON.parse(bing.stack.value);
stack.push(parseInt(bing.offset.value, 10));
bing.stack.value = JSON.stringify(stack);
bing.offset.value = bing.nextoffset.value;
return bingImageSearch(query, bingSearchOptions(bing), getSubscriptionKey('image_search'));
}
// go to the previous page (used by previous page link)
function doPrevSearchPage() {
var bing = document.forms.bing;
var query = bing.query.value;
var stack = JSON.parse(bing.stack.value);
if (stack.length) {
var offset = stack.pop();
var count = parseInt(bing.count.value, 10);
bing.stack.value = JSON.stringify(stack);
bing.offset.value = offset;
return bingImageSearch(query, bingSearchOptions(bing), getSubscriptionKey('image_search'));
}
alert("You're already at the beginning!");
return false;
}
function newBingImageSearch(form) {
form.offset.value = "0";
form.stack.value = "[]";
return bingImageSearch(form.query.value, bingSearchOptions(form), getSubscriptionKey('image_search'));
}
function handleVisualSearchResponse(){
if(this.status !== 200){
console.log(this.responseText);
// 401 is unauthorized; force re-prompt for Visual Search API key for next request
if(this.status == 401){
invalidateSubscriptionKey('visual_search');
}
return;
}
let json = this.responseText;
let response = JSON.parse(json);
for (let i =0; i < response.tags.length; i++) {
let tag = response.tags[i];
if (tag.displayName === '') {
for (let j = 0; j < tag.actions.length; j++) {
let action = tag.actions[j];
if (action.actionType === 'VisualSearch') {
let html = '';
for (let k = 0; k < action.data.value.length; k++) {
let item = action.data.value[k];
let height = 120;
let width = Math.max(Math.round(height * item.thumbnail.width / item.thumbnail.height), 120);
html += "<img src='"+ item.thumbnailUrl + "&h=" + height + "&w=" + width + "' height=" + height + " width=" + width + "'>";
}
showDiv("insights", html);
window.scrollTo({top: document.getElementById("insights").getBoundingClientRect().top, behavior: "smooth"});
}
}
}
}
}
function bingVisualSearch(insightsToken){
let visualSearchBaseURL = 'https://api.cognitive.microsoft.com/bing/v7.0/images/visualsearch',
boundary = 'boundary_ABC123DEF456',
startBoundary = '--' + boundary,
endBoundary = '--' + boundary + '--',
newLine = "\r\n",
bodyHeader = 'Content-Disposition: form-data; name="knowledgeRequest"' + newLine + newLine;
let postBody = {
imageInfo: {
imageInsightsToken: insightsToken
}
}
let requestBody = startBoundary + newLine;
requestBody += bodyHeader;
requestBody += JSON.stringify(postBody) + newLine + newLine;
requestBody += endBoundary + newLine;
let request = new XMLHttpRequest();
try {
request.open("POST", visualSearchBaseURL);
}
catch (e) {
renderErrorMessage("Error performing visual search: " + e.message);
}
request.setRequestHeader("Ocp-Apim-Subscription-Key", getSubscriptionKey('visual_search'));
request.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
request.addEventListener("load", handleVisualSearchResponse);
request.send(requestBody);
}// --></script>
</head>
<body onload="document.forms.bing.query.focus();">
<form name="bing" onsubmit="return newBingImageSearch(this)">
<div id="logo"><!-- logo block including search market/language -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAAyCAIAAAAYxYiPAAAAA3NCSVQICAjb4U/gAAARMElEQVR42u2bCVRUV5rHi8VxaeNuOumYTs706aTTZrp7TqbTk5g+9kn3OZN0pjudpZM5SfdJzEzPyZmO1gbIJhmNmijy6hUFsisCgsqigoCt7IoKgoDgUgXILntR+/aWzHfvfQUFFEURsU8cKe/hFFL16r3f++53/9//uyXSWUwjZgPDshzHcy4PnuMXHvP4EJ1qufpPyRHby3Iv93XqbDY7y7IC9QU48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e+zWetiQnD5KFlES186sj/9Rp0ef6HsYf4WLVx9p1H304TP/Wix8+vcrpWEICggnB+PCwsuPz1oMo7zEk1N9nhYHI6yLs2bOXHPJu0E8Q/77HGGYR/yL+DjvgkLGUNRV/F6TsIzh75cHxe+IjpouTJwOR24Mib46cRdsPkm/ELR1f5uG+l1OS0ekYeDQinVOTbqmP9t0A98XEM2MDNsr17X0N9T1aWBErSkSwNlt2Z0SG+DpOCm8fJ/b7k8gBQkHh4AAAAASUVORK5CYII=">
<I>api</I>
<p><select name="where">
<option value="es-AR">Argentina (Spanish)</option>
<option value="en-AU">Australia (English)</option>
<option value="de-AT">Austria (German)</option>
<option value="nl-BE">Belgium (Dutch)</option>
<option value="fr-BE">Belgium (French)</option>
<option value="pt-BR">Brazil (Portuguese)</option>
<option value="en-CA">Canada (English)</option>
<option value="fr-CA">Canada (French)</option>
<option value="es-CL">Chile (Spanish)</option>
<option value="da-DK">Denmark (Danish)</option>
<option value="fi-FI">Finland (Finnish)</option>
<option value="fr-FR">France (French)</option>
<option value="de-DE">Germany (German)</option>
<option value="zh-HK">Hong Kong (Traditional Chinese)</option>
<option value="en-IN">India (English)</option>
<option value="en-ID">Indonesia (English)</option>
<option value="it-IT">Italy (Italian)</option>
<option value="ja-JP">Japan (Japanese)</option>
<option value="ko-KR">Korea (Korean)</option>
<option value="en-MY">Malaysia (English)</option>
<option value="es-MX">Mexico (Spanish)</option>
<option value="nl-NL">Netherlands (Dutch)</option>
<option value="en-NZ">New Zealand (English)</option>
<option value="no-NO">Norway (Norwegian)</option>
<option value="zh-CN">People's Republic of China (Chinese)</option>
<option value="pl-PL">Poland (Polish)</option>
<option value="pt-PT">Portugal (Portuguese)</option>
<option value="en-PH">Philippines (English)</option>
<option value="ru-RU">Russia (Russian)</option>
<option value="ar-SA">Saudi Arabia (Arabic)</option>
<option value="en-ZA">South Africa (English)</option>
<option value="es-ES">Spain (Spanish)</option>
<option value="sv-SE">Sweden (Swedish)</option>
<option value="fr-CH">Switzerland (French)</option>
<option value="de-CH">Switzerland (German)</option>
<option value="zh-TW">Taiwan (Traditional Chinese)</option>
<option value="tr-TR">Turkey (Turkish)</option>
<option value="en-GB">United Kingdom (English)</option>
<option value="en-US" selected>United States (English)</option>
<option value="es-US">United States (Spanish)</option>
</select>
<p>from Microsoft Cognitive Services
</div>
<div id="query"><!-- query controls including search field and options -->
<h1>Bing Image Search API demo</h2>
<input type="text" name="query" id="term" placeholder="Search for images" autocomplete=off>
<p>Aspect
<input type=radio name="aspect" id="any" value="all" checked>
<label for="any">Any</label>
<input type=radio name="aspect" id="square" value="square">
<label for="square">Square</label>
<input type=radio name="aspect" id="wide" value="wide">
<label for="wide">Wide</label>
<input type=radio name="aspect" id="tall" value="tall">
<label for="tall">Tall</label>
Color
<select name="color">
<option value="" selected>Any</option>
<option value="coloronly">Only Color</option>
<option value="monochrome">Black and White</option>
<option value="black">Black</option>
<option value="blue">Blue</option>
<option value="black">Brown</option>
<option value="gray">Gray</option>
<option value="green">Green</option>
<option value="orange">Orange</option>
<option value="pink">Pink</option>
<option value="purple">Purple</option>
<option value="red">Red</option>
<option value="teal">Teal</option>
<option value="white">White</option>
<option value="yellow">Yellow</option>
</select>
From
<select name="when">
<option value="" selected>All time</option>
<option value="month">Past month</option>
<option value="week">Past week</option>
<option value="day">Last 24 hours</option>
</select>
<input type=checkbox id="safe" name="safe" value="on" checked><label for="safe">SafeSearch</label>
<!-- these hidden fields control paging -->
<input type=hidden name="count" value="25">
<input type=hidden name="offset" value="0">
<input type=hidden name="nextoffset" value="">
<input type=hidden name="stack" value="[]">
</form>
</div>
<div id="error">
<h2>Error</h2>
<div id="_error">
</div>
</div>
<h2>Results</h2>
<div id="paging1">
<div id="_paging1"></div>
</div>
<div id="noresults">
<div id="_noresults">None yet.</div>
</div>
<div id="sidebar">
<div id="_sidebar"></div>
</div>
<div id="results">
<div id="_results"></div>
</div>
<div id="paging2">
<div id="_paging2"></div>
</div>
<div id="insights">
<h3><a href="#" onclick="return toggleDisplay('_insights')">Similar</a></h3>
<div id="_insights" style="display: none"></div>
</div>
<div id="json">
<h3><a href="#" onclick="return toggleDisplay('_json')">JSON</a></h3>
<div id="_json" style="display: none"></div>
</div>
<div id="http">
<h3><a href="#" onclick="return toggleDisplay('_http')">HTTP</a></h3>
<div id="_http" style="display: none"></div>
</div>
</body>
</html>