PageSourceSearch

https://www.seabreezecomputers.com/animal/quiz.js

js seabreezecomputers.com collected 2026-09-24 10:43:37 UTC 25,838 bytes, 825 lines download raw bytes

1var quiz_div;
2
3// define groups array
4var groups = [];
5
6// define question numbers
7var quest_num = 1;
8
9// define no, maybe, yes
10var no = 0;
11var maybe = 1;
12var yes = 2;
13
14// define groups on/off variables
15var on = 1;
16var off = 0;
17
18
19function change(who, n, yesno)
20{	
21	//document.getElementById('test').innerHTML += n;
22	if (yesno == yes)
23	{
24		quiz_items[who].points += parseFloat(n);	
25	}
26	else if (yesno == no)
27	{
28		// In this statement 2 is yes or the maximum points for each question
29		quiz_items[who].points = quiz_items[who].points + (number_of_options-1) - parseFloat(n);
30		
31		// Old way of doing above statement
32		/*if (n == 0)
33			quiz_items[who].points += 2;
34		else if (n == 1)
35			quiz_items[who].points += 1;
36		else if (n == 2)
37			quiz_items[who].points += 0;
38		*/	
39	}
40	else // if yesno == maybe
41	{
42		if (number_of_options == 3)
43		{
44			if (n == 0) // no
45				quiz_items[who].points += 0;
46			else if (n == 1) // maybe
47				quiz_items[who].points += 2;
48			else if (n == 2) // yes
49				quiz_items[who].points += 1;
50		}
51		else // if number_of_options == 5
52		{
53			if (n == 0) // no
54				quiz_items[who].points += 0;
55			else if (n == 1) // maybe
56				quiz_items[who].points += 2;
57			else if (n == 2) // maybe
58				quiz_items[who].points += 4;
59			else if (n == 3) // maybe
60				quiz_items[who].points += 2;
61			else if (n == 4) // maybe
62				quiz_items[who].points += 1;		
63		}
64	}
65} // end function change(who, n, yesno)
66
67
68function highlight_questions(span, item_name)
69{
70	/* This function will highlight all the questions that affect item_name for testing purposes*/
71	//console.log(item_name);
72	
73	// First make all table cells transparent
74	var cells = document.getElementById('question_table').getElementsByTagName('td');
75	for (var t = 0; t < cells.length; t++)
76	{
77		cells[t].style.backgroundColor = "transparent";
78		if (span.style.backgroundColor.match(/yellow/i))
79			cells[t].style.display = "block";
80		else
81			cells[t].style.display = "none";
82	}
83	
84	// If current item span is alreay selected (highlighted yellow)
85	if (span.style.backgroundColor.match(/yellow/i))
86	{
87		span.style.backgroundColor = "transparent"; // then make it transparent
88		return; // and return 	
89	}
90	
91	
92	// Make all other items in test_div transparent
93	var items = document.getElementById('test_div').getElementsByTagName('span');
94	for (var t = 0; t < items.length; t++)
95	{
96		items[t].style.backgroundColor = "transparent";
97	}
98	
99
100	// Then highlight the span clicked on
101	span.style.backgroundColor = "yellow";
102	
103	var re; // reg expression
104	for (var i = 0; i < questions.length; i++) // loop through questions
105	{	
106		//document.write("Question "+i+"<br>");
107		for (var key in questions[i]) 
108		{
109			if (!key.match(/^question|^group|^switch/i))
110			{	
111				re = new RegExp( '^'+key,'i'); // insensative case search: 'i'; beginning of string: ^
112					if (item_name.match(re)) // find a quiz_item name that matches key name
113					{
114						// highlight the <TD>
115						document.getElementById('question'+i).style.backgroundColor = "yellow";
116						document.getElementById('question'+i).style.display = "block";
117					}	
118			}
119
120		}
121	}
122
123} // end function highlight_questions(item_name)
124
125
126function write_questions()
127{
128	var group_name;
129	var string = ''; // Unless I add to a string innerHTML will close form tags and table tags
130	
131	string += "<table border='1' width='100%' id='question_table'>";
132	for (var i = 0; i < questions.length; i++) // loop through questions
133	{	
134		for (var key in questions[i]) 
135		{
136			if (key.match(/^question/i))
137			{
138				//if (key !== key.toLowerCase()) questions[i][key.toLowerCase()] = questions[i][key]; // One way to lower case "Question"
139				var question = questions[i]['question'] || questions[i]['Question'];
140				string += "<tr><td id='question"+i+"'>";
141				if (line_numbers)
142					string += quest_num+". ";
143				quest_num++;
144				string += question+"<br>";
145				if (number_of_options == 3)
146				{
147					string += '<label>(No)<input type="radio" name="quest'+i+'" value="0" onclick="update()"></label>'+
148					'<label>(Maybe)<input type="radio" name="quest'+i+'" value="1" onclick="update()"></label>'+
149					'<label>(Yes)<input type="radio" name="quest'+i+'" value="2" onclick="update()"></label>'+
150					'</td></tr>';
151				}
152				else // if number_of_options == 5
153				{
154					string += '<label>
154(No)<input type="radio" name="quest'+i+'" value="0" onclick="update()"></label>'+
155					'<label><input type="radio" name="quest'+i+'" value="1" onclick="update()"></label>'+
156					'<label><input type="radio" name="quest'+i+'" value="2" onclick="update()"></label>'+
157					'<label><input type="radio" name="quest'+i+'" value="3" onclick="update()"></label>'+
158					'<label><input type="radio" name="quest'+i+'" value="4" onclick="update()">(Yes)</label>'+
159					'</td></tr>';
160				
161				}
162		
163			}
164			else if (key.match(/^group/i))
165			{
166				group_name = questions[i][key].toLowerCase();
167				// If group name is in groups array then we are closing the group
168				if (groups[group_name])
169				{
170					string += "</tbody>";
171					if (test_mode) // show group div in test mode
172						string += "<tr><th><b>End "+group_name+"</b></th></tr>";
173				}
174				else
175				{
176					// Make div for group
177					string += "<tbody id='group_"+group_name+"' style='display:block;'>";
178					// Add group_name to groups array
179					groups[group_name] = 1;
180					if (test_mode) // show group div in test mode
181					{
182						string += "<tr><th><b>Start "+group_name+"</b></th></tr>";
183					}
184				}
185			}
186	
187			
188		} // end for loop
189	}	// end i loop
190	string += "</table>";
191	return(string)
192} // end function write_questions()
193
194
195
196function update()
197{
198	event = event || window.event;
199	var question_name = event.srcElement.name || event.target.name;
200	//document.getElementById('test').innerHTML = question_name;
201	var question;
202	var group_name;
203	//var quest_num = 0; // Start w/ 0 because first question does quest_num++ for number 1
204	
205	// Reset all points to 0
206	// array iteration reset
207	for (var n = 0; n < quiz_items.length; n++)
208		quiz_items[n].points = 0;
209	
210	// object iteration reset
211	for (var key in quiz_items) 
212	{
213  		if (quiz_items.hasOwnProperty(key)) 
214  			quiz_items[key].points = 0;
215  	}
216  	
217  	/* Loop through questions array. Look for quiz_item matching the items in the questions array */
218	var re; // reg expression
219	for (var i = 0; i < questions.length; i++) // loop through questions
220	{	
221		//document.write("Question "+i+"<br>");
222		for (var key in questions[i]) 
223		{
224			if (!key.match(/^question|^group|^switch/i))
225			{
226				question = document.getElementsByName('quest'+i);	
227				re = new RegExp( '^'+key,'i'); // insensative case search: 'i'; beginning of string: ^
228				for (var n = 0; n < quiz_items.length; n++) // loop through quiz_items
229					if(quiz_items[n].name.match(re)) // find a quiz_item name that matches key name
230					{
231						for (var a = no; a <= (number_of_options-1); a++) // Loop through yes, maybe, no of quest+i
232							if ((question[a].checked && test_mode != 2) ||
233								(question[a].checked && test_mode == 2 && question[a].name == question_name))
234								change(n, question[a].value, questions[i][key]); 	
235						//document.write("&nbsp;&nbsp;"+quiz_items[n].name+": "+questions[i][key]+"<br>"); // print value of key
236					}	
237			}
238			else if (key.match(/^switch/i))
239			{
240				question = document.getElementsByName('quest'+i);
241				group_name = questions[i]["switch"]["group"].toLowerCase();
242				if (document.getElementById("group_"+group_name)) // Only if the group was actually created in questions
243				for (var a = no; a <= (number_of_options-1); a++) // Loop through yes, maybe, no of quest+i
244					if (question[a].checked)
245					{
246							if ((question[a].value == (number_of_options-1) && questions[i]["switch"]["clause"] == yes)
247							|| (question[a].value == no && questions[i]["switch"]["clause"] == no))
248							{
249								if (questions[i]["switch"]["dir"] == on)
250									document.getElementById("group_"+group_name).style.display = "block";
251								else // off
252									document.getElementById("group_"+group_name).style.display = "none";
253							}
254							else if ((question[a].value == no && questions[i]["switch"]["clause"] == yes)
255								|| (question[a].value == (number_of_options-1) && questions[i]["switch"]["clause"] == no))
256							{
257								if (questions[i]["switch"]["dir"] == on)
258									document.getElementById("group_"+group_name).style.display = "none";
259								else // off
260									document.getElementById("group_"+group_name).style.display = "block";
261							}
262					}		
263							
264			}
265			
266		}
267	}	
268	
269	reset_css(); // Reset checked labels
270	
271	updatePercent();
272	
273	// The stuff below this line is for testing
274	// to display the scores while answering:
275	if (test_mode)
276	{
277		// Array iteration
278		for (var i = 0; i < quiz_items.length; i++)
279		{
280			var perc = quiz_items[i].perc.toString();
281			document.getElementById('score'+i).innerHTML = perc;
282		}
283		
284	} // end if test_mode
285	
286
287} // end function update()
288
289
290function updatePercent()
291{
292	/* There are a total of 18 questions with a possible point value of up to 3 per question.
293		So 18 * 3 = 54 possible points.
294		Online has a possible 54
295		TERM has a possible 53
296		Flipped has a possible 50
297		Pathway has a possible 54
298		So we are turning the result percentages into 100% max.
299		Example: score / max = perc (or 50 / 54 = .96 * 100 = 96) 
300	*/
301	var total_questions = 0;
302	var possible_points = 0;
303	
304	// Reset all possible questions that affect the item to 0
305	// array iteration reset
306	for (var n = 0; n < quiz_items.length; n++)
307	{
308		quiz_items[n].possible = 0;
309	}
310	
311	// Count total number of questions and possible questions that affect each quiz result
312	// and add it to the possible variable in the quiz_items array
313	var re; // reg expression
314	for (var i = 0; i < questions.length; i++) // loop through questions
315	{	
316		//console.log("Question "+i);
317		for (var key in questions[i]) 
318		{
319			if (key.match(/^question/i))
320			{
321				total_questions++;
322			}
323			if (!key.match(/^question|^group|^switch/i))
324			if (questions[i].hasOwnProperty(key)) 
325			{
326				re = new RegExp( '^'+key,'i'); // insensative case search: 'i'; beginning of string: ^
327				for (var n = 0; n < quiz_items.length; n++) // loop through quiz_items
328					if(quiz_items[n].name.match(re)) // find a quiz_item name that matches key name
329					{
330						quiz_items[n].possible++; // Add to possible number of questions that affect this result (quiz_item)
331		
332					}	
333			}
334		}
335	}
336	// Now calculate the percentage based out of 100%
337	for (var n=0; n < quiz_items.length; n++)
338	{
339		// The total possible points for a result is the possible questions that affect
340		// that result item * number_of_options-1 (or 2 if number_of_options=3)
341		possible_points = quiz_items[n].possible * (number_of_options-1);
342		quiz_items[n].perc = Math.round(quiz_items[n].points / possible_points * 100);		
343	}
344} // end function updatePercent()
345
346
347function doneButton()
348{
349	update(); // Call update one last time
350	updatePercent(); // update percent to 100% based
351	
352	/*parent.location = 'result.htm?'+
353		'a='+quiz_items[0].perc+
354		'&b='+quiz_items[1].perc+
355		'&c='+quiz_items[2].perc+
356		'&d='+quiz_items[3].perc;
357	*/	
358	
359	var result_cookie = "";
360	for (var i = 0; i < quiz_items.length; i++)
361		result_cookie += i+'='+quiz_items[i].perc+'&';
362	setCookie("result", result_cookie, 20); // Set cookie for 20 minutes	
363	
364	var sorted_items = clone(quiz_items);
365	sorted_items.sort(sortByPerc); 
366	var result_url = ((window.location.search.indexOf('?') == -1) ? '?result=' : '&result=')+sorted_items[0].id;
367	window.location = window.location.href+result_url;
368		
369} // end doneButton()
370
371
372function create_test_div()
373{	
374	quiz_div.style.height = "320px";
375	var test_div = document.createElement('div');
376	var submit_div = document.getElementById('submit_div');
377	test_div.id = "test_div";
378	test_div.style.fontFamily = "Courier New"; // monospace font
379	test_div.style.border = "1px solid orange";
380	test_div.style.height = "320px";
381	test_div.style.overflow = "scroll";
382	
383	var cols = 1;
384	var string = "";
385	var item_name = "";
386	var span_style = "<span style='border: 1px solid black'";
387	
388	string += "<table border='0'><tr>";
389	
390	for (var i = 0; i < quiz_items.length; i++)
391	{
392		string += "<td>";
393		var perc = quiz_items[i].perc.toString();
394		item_name = quiz_items[i].name.substr(0, 17); // Only get 17 characters of the name
395		len = item_name.length + perc.length;
396		string += span_style + " onclick='highlight_questions(this, \""+quiz_items[i].name+"\");'>" +
397			item_name + "</span> : <span id='score"+i+"'>" + quiz_items[i].perc + "</span>";
398
399		//for (num = len; num < 20; num++)
400		//	string += "&nbsp;";  // add spaces to 20
401		string += "</td>";
402			
403		cols++;
404		if (cols == 7)
405		{
406			cols = 1;
407			string += "</tr><tr>";
408		}
409	}
410	string += "</table>";
411	test_div.innerHTML = string;
412	quiz_div.parentNode.insertBefore(test_div, submit_div.nextSibling);
413
414} // end function create_test_div()
415
416// End testing
417
418function reset_css()
419{
420	// Loop through form questions. Add CSS to checked label
421	for (var i = 0; i < questions.length; i++) // loop through questions
422	{
423		question = document.getElementsByName('quest'+i);
424		for (var a = no; a <= (number_of_options-1); a++)
425		{
426			if (question[a].checked && !question[a].parentNode.className.match(/(?:^|\s)label_checked(?!\S)/)) 
427				question[a].parentNode.className += " label_checked";
428			else if (!question[a].checked)
429				question[a].parentNode.className = question[a].parentNode.className.replace(/(?:^|\s)label_checked(?!\S)/g , '' );
430		}
431	}
432}
433
434function reset_form()
435{
436	document.getElementById("fm").reset();
437	animate_to_top(); // First animate body to top
438	animate_to_top(document.getElementById('quiz_div')); // then animate quiz_div to top
439	reset_css(); // Reset checked labels
440
441} // end function reset_form()
442
443function animate_to_top(element)
444{
445	var scroll_top = 0;
446	
447	if (typeof element === "undefined" || element == document.body)
448	{
449		element = document.body;
450		scroll_top = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
451	}
452	else
453		scroll_top = element.scrollTop;
454	//console.log(scroll_top);
455	if (scroll_top > 1)
456	{
457		element.scrollTop = scroll_top - 100;
458		//window.scrollBy(0, -100); // horizontal and vertical scroll increments
459    	scrolldelay = setTimeout(function() { animate_to_top(element);}, 10);
460	}
461}
462
463
464function create_quiz_div()
465{
466	var quiz_script = document.getElementById('quiz_script');	
467	
468	// Create share_buttons_div
469	/*var share_buttons_div = document.createElement('div');
470	share_buttons_div.id = "share_buttons_div";
471	share_buttons_div.className = "share_buttons_div";
472	//share_buttons_div.style.float = "left";
473	//share_buttons_div.style.display = "block";
474	quiz_script.parentNode.insertBefore(share_buttons_div, quiz_script);
475	// Dynamically load sharebuttons.js
476	loadscript("sharebuttons.js", null); // Removed old share buttons 12/26/2016 */	
477	
478	// create quiz div
479	quiz_div = document.createElement('div');
480	quiz_div.id = "quiz_div";
481	quiz_div.className = "quiz_div";
482	quiz_script.parentNode.insertBefore(quiz_div, quiz_script.nextSibling);
483	
484	// Create submit div
485	var submit_div = document.createElement('div');
486	var string = '';
487	string += '<input type="reset" name="Reset" onclick="reset_form();">';
488	string += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
489	string += '<input type="button" name="Done" value="Done" onclick="doneButton()">';
490	submit_div.innerHTML = string;
491	submit_div.id = "submit_div";
492	submit_div.style.display = "none";
493	quiz_div.parentNode.insertBefore(submit_div, quiz_div.nextSibling);
494	//quiz_div.appendChild(submit_div);
495	
496	// Create result_div
497	var result_div = document.createElement('div');
498	result_div.id = "result_div";
499	result_div.className = "result_div";
500	//result_div.style.float = "left";
501	result_div.style.display = "none";
502	quiz_div.parentNode.insertBefore(result_div, quiz_div.nextSibling);
503	
504	// Create scroll_msg_div
505	var scroll_msg_div = document.createElement('div');
506	string = '';
507	string+= '<br><br><br><br><br><br><br><--- Scroll Down';
508	scroll_msg_div.innerHTML = string;
509	scroll_msg_div.id = "scroll_down_msg";
510	scroll_msg_div.style.float = "left";
511	quiz_div.parentNode.insertBefore(scroll_msg_div, quiz_div.nextSibling);	
512	
513	// Now make clear:both div
514	var clear_div = document.createElement('div');
515	clear_div.style.clear = "both";
516	scroll_msg_div.parentNode.insertBefore(clear_div, scroll_msg_div.nextSibling);
517	
518	// create top share div
519	/* share_div = document.createElement('div');
520	share_div.id = "share_div";
521	share_div.className = "share_div";
522	share_div.innerHTML = "Hi there";
523	quiz_script.parentNode.insertBefore(share_div, quiz_script.nextSibling);
524	*/
525} // end function create_submit()
526
527
528/* It is not possible to get certain styles set in css such as display using 
529the normal javascript.  So we have to use this function taken from:
530http://www.quirksmode.org/dom/getstyles.html */
531function getStyle(el,styleProp)
532{
533	// if el is a string of the id or the actual object of the element
534	var x = (document.getElementById(el)) ? document.getElementById(el) : el;
535	if (x.currentStyle) // IE
536		var y = x.currentStyle[styleProp];
537	else if (window.getComputedStyle)  // FF
538		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
539	return y;
540}
541
542
543function loadscript(script_url, callback)
544{
545	/* loadscript() dynamically loads the js file specified in 'script_url'
546		and then calls the callback function in 'callback'.
547		Compatible with all browsers
548	*/
549	var done = false; //IE 9+ supports onreadystatechange AND onload so we need the 'done' variable 
550	var head = document.getElementsByTagName("head")[0] || document.documentElement;
551	var script = document.createElement("script");	
552	
553	script.src = script_url;
554
555	// IE and Opera
556	script.onreadystatechange = function()
557	{
558        if (!done && (script.readyState == "loaded" || script.readyState == "complete"))
559		{
560            done = true;
561			script.onreadystatechange = null;
562            if (typeof callback === "function")
563				callback();
564        }
565	};
566	// Webkit (Safari, FF, Chrome, IE 9+)
567	script.onload = function()
568	{
569		if (!done)
570		{
571			done = true;
572			if (typeof callback === "function")
573				callback();
574		}
575	};
576
577	head.insertBefore( script, head.firstChild );
578	return (script);
579
580} // end function loadscript(script_url, callback)
581
582
583// This function gets the data on the url search string
584// and returns the one called 'name'
585function get(name) 
586{
587	var string = window.location.search;
588	
589	//unescape converts the %20 (space) and %26 (&) etc.
590	string = unescape(string);
591	
592	if (string) // if there is search paramaters
593	{
594    	// Drop the leading "?"
595    	string = string.substr(1);
596    	
597    	// create an array containing each item
598		var string_array = string.split("&"); 
599    	
600    	for (i = 0; i < string_array.length; i++)
601    	{
602			// split the name from the data
603			result_array = string_array[i].split("=");
604			// if it is the name we are looking for
605			if (result_array[0] == name)
606				return(result_array[1]); // then return the data
607		}
608	}
609	// return false if the name is not found
610	return(false);    	
611} // end function get(name)
612
613function reviver(key, value)
614{
615	/* This JSON reviver function just changes a string of numbers "656" into a 
615number 656 */
616	/* It also works with negative values */
617	if (typeof value === 'string')
618	{
619		if (!isNaN(value)) // if ! is Not a Number (NaN)
620		{
621			// Ok, it is a number so process it
622			value = Number(value);
623		}	
624	}
625	return value;
626} // end function reviver(key, value)
627
628
629function fix_errors(obj)
630{
631	// If they accidentally put "yes" instead of yes then fix it
632	// Fixes yes, no, on, off, maybe
633	for (var key in obj)
634	{
635		if (obj.hasOwnProperty(key))
636		{
637			if (key !== key.toLowerCase()) {
638				obj[key.toLowerCase()] = obj[key]; // One way to lower case "Question"
639				delete obj[key];
640				key = key.toLowerCase();
641			}
642			//console.log(key+":"+obj[key]);
643			if (typeof(obj[key])=="object")
644			{ 
645				fix_errors(obj[key]); 
646			}
647			else
648			{	
649				if (isNaN(obj[key])) // if is Not a Number
650				{	
651					if (obj[key].match(/^yes$/i))
652						obj[key] = yes;
653					else if (obj[key].match(/^no$/i))
654						obj[key] = no;
655					else if (obj[key].match(/^on$/i))
656						obj[key] = on;
657					else if (obj[key].match(/^off$/i))
658						obj[key] = off;
659					else if (obj[key].match(/^maybe$/i))
660						obj[key] = maybe;
661				}
662			}
663		}
664	}
665} // end function fix_errors(obj)
666
667
668function show_quiz()
669{
670	var string = '';
671	
672	// Reset all percents to 0 and all possible questions that affect the item to 0
673	// array iteration reset
674	for (var n = 0; n < quiz_items.length; n++)
675	{
676		quiz_items[n].points = 0;
677		quiz_items[n].perc = 0;
678		quiz_items[n].possible = 0;
679		quiz_items[n].id = n;
680	}
681	
682	fix_errors(questions);
683	
684	string += '<form name="fm" id="fm">'+write_questions()+"<br />";
685	string += '<input type="reset" name="Reset" onclick="reset_form();">';
686	string += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
687	string += '<input type="button" name="Done" value="Done" onclick="doneButton()">';
688		
689	create_quiz_div();
690	quiz_div.innerHTML = string;
691	
692	if (test_mode)
693		create_test_div();
694	
695	// If mobile device then make title shorter
696	if (getStyle(scroll_down_msg, "display") == "none") // mobile display
697		document.title = quiz_short_title;
698	else if (navigator.userAgent.match(/(iPad|iPhone|iPod|Android|Silk)/gi))
699		document.title = quiz_short_title;
700		
701	// Show results if result cookie and result on search url
702	if (window.location.search.match(/[?&]result=/))
703	if (getCookie("result"))
704	{
705		var result_cookie = getCookie("result").split("&");
706		for (var i = 0; i < quiz_items.length; i++)
707		{
708			quiz_items[i].perc = parseInt(result_cookie[i].split("=")[1]); 
709			if (test_mode)
710			{
711				var perc = quiz_items[i].perc.toString();
712				document.getElementById('score'+i).innerHTML = perc;
713			}
714		}
715		displayScore();
716	}
717
718} // end function show_quiz()
719
720
721/* function to clone object */
722function clone(obj) {
723    if (null == obj || "object" != typeof obj) return obj;
724    var copy = obj.constructor();
725    for (var attr in obj) {
726        if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
727    }
728    return copy;
729}
730
731
732function sortByPerc(a, b) {
733    var x = a.perc;
734    var y = b.perc;
735	  
736    if (x < y) return 1;
737  	if (x > y) return -1;
738  	if (x == y) return 0;
739  	//document.write(x);
740  	// reverse the -1 and the 1 to do reverse order list
741}  // end function sortByPerc
742
743
744function displayScore()
745{
746	var result_div = document.getElementById('result_div');
747	var string = "";
748	quiz_items.sort(sortByPerc);
749	
750	//string += '<table><tr><td>';
751	string += '<p>Your result:';
752	string += '<b>  <font size=6>';
753	string += quiz_items[0].name + '</font></b>';
754	
755	var desc = quiz_items[0].desc;
756	var picture = quiz_items[0].picture;
757	
758	string += '<div id="desc_div">';
759	string += desc;
760	if (picture)
761		string += '<br><img id="image_div" src="' + picture + '">';
762	
763	
764	var medium_url = window.location.href.replace(/index\.php$|index.html?$/, "");
765	var parameter = "result"; // remove "result=5" from query string
766	medium_url = medium_url.replace(new RegExp('[?&]' + parameter + '=[^&#]*(#.*)?$'), '$1');
767	var short_url = medium_url.replace(/https?:\/\//i, "");
768	
769	string += '<br /><a href="'+medium_url+'">';
770	string += quiz_long_title+'</a><br>';
771	string += '<a href="'+medium_url+'">';
772	string += short_url+'</a><br>';
773	string += '</div>';
774	
775	string += '<div id="percent_div">';
776	if (top_results_limit > 1)
777			string += "Your top "+top_results_limit+" out of "+quiz_items.length;
778	//string += '<table><tr><td valign="top">';
779	string += '<table>';
780	if (top_results_limit == 0) top_results_limit = quiz_items.length;
781	for (a = 0; a < top_results_limit; a++)
782	{
783		string += '<tr><td>' + quiz_items[a].name;
784		string += '</td><td>
784<hr align=left noshade size="4" width=' + quiz_items[a].perc + '>';
785		string += '</td><td> ' + quiz_items[a].perc + '%</td></tr>';
786	}	
787	string += '</table>';
788	string += '</div>';	
789	
790	string += '<div style="clear:both;"></div>';
791	
792	//string += '</td></tr></table></div>';
793	document.getElementById('share_result_div').style.display = "block"; // 6/13/2017
794	quiz_div.style.display = "none";
795	document.getElementById('submit_div').style.display = "none";
796	document.getElementById('scroll_down_msg').style.display = "none";
797	
798	result_div.innerHTML = string;
799	result_div.style.display = "block";
800	//document.getElementById('share_buttons_div').style.display = "block"; // Removed old share buttons 12/26/2016
801	// Dynamically load sharebuttons.js
802	//loadscript("sharebuttons.js", null);
803	document.body.scrollTop = document.documentElement.scrollTop = 0;
804
805	
806} // end displayscore()
807
808function setCookie(cname, cvalue, minutes) {
809    var d = new Date();
810    d.setTime(d.getTime() + (minutes * 60 * 1000));
811    var expires = "expires="+d.toUTCString();
812    document.cookie = cname + "=" + cvalue + "; " + expires;
813}
814
815function getCookie(name) {
816    var match = document.cookie.match(RegExp('(?:^|;\\s*)' + name + '=([^;]*)'));
817    return match ? match[1] : null;
818}
819	
820// Dynamically load data.js and then call show_quiz()
821loadscript("data.js", show_quiz);
822
823
824
825

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.