PageSourceSearch

https://groveland-fl.gov/1657590475.js

js groveland-fl.gov collected 2026-10-02 11:05:24 UTC 79,448 bytes, 2,375 lines download raw bytes

1/*
2The following errors were found when attempting to minify this file:
3- Line 1911: Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option.
4- Line 2252: Parse error. Unsupported syntax: CONST
5*/
6/// <reference name="MicrosoftAjax.js" />
7// Normal bulk actions.
8var bulkActionNumPublished_total = 0;
9var bulkActionNumUnpublished_total = 0;
10var bulkActionNumUnpublished_checked = 0;
11var bulkActionNumPublished_checked = 0;
12// Dual item/category bulk actions (used by Archiving).
13var bulkActionNumPublishedCat_total = 0;
14var bulkActionNumUnpublishedCat_total = 0;
15var bulkActionNumUnpublishedCat_checked = 0;
16var bulkActionNumPublishedCat_checked = 0;
17// Multiple/grouped normal bulk actions per page (used by Group Admin).
18var arrBulkActionNumPublished_total;
19var arrBulkActionNumUnpublished_total;
20var arrBulkActionNumUnpublished_checked;
21var arrBulkActionNumPublished_checked;
22var bulkActionInitDone = false;
23var numBulkActionGroups = 0;
24var bulkActionPluralNoun = '';
25var numberOfRowChecked = 0;
26
27// Handles two sets of checkboxes on-screen at a time (categories and items sharing a list)
28function BulkActionProcessDuo(form, actionType, ysnPublisher, moduleID) {
29	var doSubmit = true;
30	var c;
31	var ysnUnpubMarked = 0;
32	var ysnPubMarked = 0;
33	var ysnUnpubMarkedCat = 0;
34	var ysnPubMarkedCat = 0;
35
36	var lstTmp = form.cboxPublished;
37	if (lstTmp && ysnPublisher) {
38		if (lstTmp.length == null)
39			ysnPubMarked = lstTmp.checked;
40		else
41			for (c = 0; c < lstTmp.length && !ysnPubMarked; c++)
42			if (lstTmp[c].checked) {
43			ysnPubMarked = true;
44			break;
45		}
46	}
47	var lstTmp = form.cboxPublishedCat;
48	if (lstTmp && ysnPublisher) {
49		if (lstTmp.length == null)
50			ysnPubMarkedCat = lstTmp.checked;
51		else
52			for (c = 0; c < lstTmp.length && !ysnPubMarkedCat; c++)
53			if (lstTmp[c].checked) {
54			ysnPubMarkedCat = true;
55			break;
56		}
57	}
58	lstTmp = form.cboxUnpublished;
59	if (lstTmp) {
60		if (lstTmp.length == null)
61			ysnUnpubMarked = lstTmp.checked;
62		else
63			for (c = 0; c < lstTmp.length && !ysnUnpubMarked; c++)
64			if (lstTmp[c].checked) {
65			ysnUnpubMarked = true;
66			break;
67		}
68	}
69	lstTmp = form.cboxUnpublishedCat;
70	if (lstTmp) {
71		if (lstTmp.length == null)
72			ysnUnpubMarkedCat = lstTmp.checked;
73		else
74			for (c = 0; c < lstTmp.length && !ysnUnpubMarkedCat; c++)
75			if (lstTmp[c].checked) {
76			ysnUnpubMarkedCat = true;
77			break;
78		}
79	}
80
81	switch (actionType) {
82		case "ArchiveHideAll":
83			{
84				if (!ysnPubMarked && !ysnPubMarkedCat) {
85					doSubmit = false;
86					alert("No items or categories are selected that can be hidden.");
87				}
88				actionType = "ArchiveHide";
89				break;
90			}
91		case "ArchiveShowAll":
92			{
93				if (!ysnUnpubMarked && !ysnUnpubMarkedCat) {
94					doSubmit = false;
95					alert("No items or categories are selected that can be shown.");
96				}
97				actionType = "ArchiveShow";
98				break;
99			}
100		case "ArchiveDeleteAll":
101			{
102				if (!(ysnUnpubMarked || ysnUnpubMarkedCat || ysnPubMarked || ysnPubMarkedCat)) {
103					doSubmit = false;
104					alert("No archived items or categories are selected that can be deleted.");
105				} else {
106					var confirmText = "";
107					if (moduleID == 71)
108						confirmText = "Submitted data will also be deleted. ";
109
110					if ((ysnPubMarkedCat || ysnUnpubMarkedCat) && (ysnPubMarked || ysnUnpubMarked))
111						doSubmit = (confirm(confirmText + "Are you sure you want to delete the selected archived item(s) and category(s)?"));
112					else if (ysnPubMarkedCat || ysnUnpubMarkedCat)
113						doSubmit = (confirm("Are you sure you want to delete the selected archived category(s)?"));
114					else
115						doSubmit = (confirm(confirmText + "Are you sure you want to delete the selected archived item(s)?"));
116				}
117				actionType = "ArchiveDelete";
118				break;
119			}
120		default:
121			{
122				doSubmit = false;
123				break;
124			}
125	}
126
127	if (doSubmit) {
128		// Work-around for Firefox behavior with <button> tag in DC. Harder to read but avoids costly string concats.
129		setTimeout("BulkDisableIfExists(document.getElementById('btnBulkActionShow')); BulkDisableIfExists(document.getElementById('btnBulkActionHide'));", 15);
130		form.strBulkAction.value = actionType;
131		form.submit();
132	}
133}
134
135// Normal bulk actions code,;8 supporting a list of categories or items (not both at once).
136// lngSource parameter is used to distinguish whether this method is called for items or categories
137function BulkActionProcess(form, actionType, ysnPublisher, archiveNotImplemented, lngSource) {
138	var doSubmit = true;
139	var c;
140	var ysnUnpubMarked = false;
141	var ysnPubMarked = false;
142
143	var lstTmp = form.cboxPublished;
144	if (lstTmp && ysnPublisher) {
145		if (lstTmp.length == null || lstTmp.length == undefined)
146			ysnPubMarked = lstTmp.checked;
147		else
148			for (c = 0; c < lstTmp.length && !ysnPubMarked; c++)
149			if (lstTmp[c].checked) {
150			ysnPubMarked = true;
151			break;
152		}
153	}
154
155	lstTmp = form.cboxUnpublished;
156	var selectedDraftCategoryIds = '';
157	var moduleId = form.lngResourceID != undefined ? form.lngResourceID.value : '';
158
159	if (lstTmp) {
160		if (lstTmp.length == null || lstTmp.length == undefined) {
161			ysnUnpubMarked = lstTmp.checked;
162			selectedDraftCategoryIds = lstTmp.value;
163		}
164		else
165			for (c = 0; c < lstTmp.length; c++)
166			if (lstTmp[c].checked) {
167				ysnUnpubMarked = true;
168				selectedDraftCategoryIds += ',' + lstTmp[c].value;			
169		}
170	}
171
172	switch (actionType) {
173		case "Unpublish":
174			{
175				if (!ysnPubMarked) {
176					doSubmit = false;
177					alert("No items are selected that can be unpublished.");
178				}
179				break;
180			}
181		case "Publish":
182			{
183				if (!ysnUnpubMarked) {
184					doSubmit = false;
185					alert("No items are selected that can be published.");
186				}
187				break;
188			}
189		case "Submit":
190			{
191				if (!ysnUnpubMarked) {
192					doSubmit = false;
193					alert("No items are selected that can be submitted.");
194				}
195				break;
196			}
197		case "Reject":
198			{
199				if (!ysnUnpubMarked) {
200					doSubmit = false;
201					alert("No items are selected that can be Declined.");
202				}
203				break;
204			}
205		case "Unlock":
206			{
207				if (ysnPublisher)
208					doSubmit = ysnUnpubMarked || ysnPubMarked;
209				else
210					doSubmit = ysnUnpubMarked;
211
212				if (!doSubmit)
213					alert("No items are selected that can be unlocked.");
214				break;
215			}
216		case "DeleteUnpub":
217			{
218				var source = lngSource != undefined && lngSource != '' ? lngSource : 'item';
219				var deleteCatMessage = source === 'category' ? GetDeleteCategoryMessage(moduleId, selectedDraftCategoryIds):'';
220				doSubmit = ysnUnpubMarked;
221				if (doSubmit) {
222					if (ysnPubMarked) {
223						if (archiveNotImplemented)
224							doSubmit = (confirm("Only unpublished " + source + "s can be deleted.\n" + deleteCatMessage +"Are you sure you want to delete the selected unpublished "+source+"(s)?"));
225						else
226							doSubmit = (confirm("Only unpublished " + source + "s can be deleted.To remove published " + source + "s, select an archive action.\n" + deleteCatMessage +"\nAre you sure you want to delete the selected unpublished "+source+"(s)?"));
227					}
228					else
229						doSubmit = (confirm(deleteCatMessage+"Are you sure you want to delete the "+source+"(s)?"));
230
231					if (doSubmit)
232						actionType = "Delete";
233				}
234				else {
235					if (ysnPubMarked) {
236						if (archiveNotImplemented)
237							alert("Only unpublished items can be deleted.");
238						else
239							alert("Only unpublished items can be deleted.  To remove published items, select an archive Action.");
240					}
241					else
242						alert("No items are selected that can be deleted.");
243				}
244				break;
245			}
246		case "Delete":
247			{
248				if (ysnPublisher)
249					doSubmit = ysnUnpubMarked || ysnPubMarked;
250				else
251					doSubmit = ysnUnpubMarked;
252				if (doSubmit)
253					doSubmit = confirm("Are you sure you want to delete the item(s)?");
254				else
255					alert("No items are selected that can be deleted.");
256				break;
257			}
258		case "DeleteMediaCenterVideos":
259			{
260				if (ysnPublisher)
261					doSubmit = ysnUnpubMarked || ysnPubMarked;
262				else
263					doSubmit = ysnUnpubMarked;
264				if (doSubmit)
265					doSubmit = confirm("Are you sure you want to delete this video(s)?  By removing videos, you may not be following documentation laws required by your state.");
266				else
267					alert("No items are selected that can be deleted.");
268				break;
269			}
270		case "Archive":
271			{
272				if (!ysnPubMarked) {
273					if (ysnUnpubMarked)
274						alert("Only published items can be Archived.  To remove unpublished items, use the Delete action.");
275					else
276						alert("No items are selected that can be archived.");
277					doSubmit = false;
278				} else
279					doSubmit = confirm((ysnUnpubMarked ? 'Only published items will be Archived.  ' : '') + 'Archiving is a PERMANENT action!\nYou will not be able to edit, publish, unpublish, submit, reject, or move these item(s) out of the archive!\nAre you sure you want to archive these item(s)?');
280				break;
281			}
282		case "ArchiveHide":
283			{
284				if (!ysnPubMarked) {
285					doSubmit = false;
286					alert("No items are selected that can be hidden.");
287				}
288				break;
289			}
290		case "ArchiveShow":
291			{
292				if (!ysnUnpubMarked) {
293					doSubmit = false;
294					alert("No items are selected that can be shown.");
295				}
296				break;
297			}
298		case "ArchiveDelete":
299			{
300				if (!(ysnUnpubMarked || ysnPubMarked)) {
301					doSubmit = false;
302					alert("No archived items are selected that can be deleted.");
303				} else
304					doSubmit = (confirm("Are you sure you want to delete the selected archived item(s)?"));
305				break;
306			}
307		case "PublishCat":
308			{
309				if (!ysnUnpubMarked) {
310					doSubmit = false;
311					alert("No categories are selected that can be published.");
312				}
313				break;
314			}
315		case "UnpublishCat":
316			{
317				if (!ysnPubMarked) {
318					doSubmit = false;
319					alert("No categories are selected that can be unpublished.");
320				}
321				break;
322			}
323		case "SubmitCat":
324			{
325				if (!ysnUnpubMarked) {
326					doSubmit = false;
327					alert("No categories are selected that can be submitted.");
328				}
329				break;
330			}
331		case "RejectCat":
332			{
333				if (!ysnUnpubMarked) {
334					doSubmit = false;
335					alert("No categories are selected that can be declined.");
336				}
337				break;
338			}
339		case "DeleteUnpubCat":
340			{
341				doSubmit = ysnUnpubMarked;
342				if (doSubmit) {
343					if (ysnPubMarked) {
344						doSubmit = (confirm("Only unpublished categories can be deleted.\nTo remove published categories, select an archive action.\n" + GetDeleteCategoryMessage(moduleId, selectedDraftCategoryIds) +"Are you sure you want to delete the selected unpublished category(s)?"));
345					}
346					else
347						doSubmit = (confirm("Only categories with no published items will be deleted.\n"+GetDeleteCategoryMessage(moduleId,selectedDraftCategoryIds)+"Are you sure you want to delete the category(s)?"));
348
349					if (doSubmit)
350						actionType = "DeleteCat";
351				}
352				else {
353					if (ysnPubMarked) {
354						alert("Only unpublished categories can be deleted. \nTo remove published categories, select an archive action.");
355					}
356					else
357						alert("No categories are selected that can be deleted.");
358				}
359				break;
360			}
361		case "DeleteCatWithNoItems":
362			{
363				var canDelete = $("input:checkbox:checked[data-candelete='True']").length > 0;
364				if (canDelete) {
365					doSubmit = (confirm("Only categories with no items will be deleted.\n" + GetDeleteCategoryMessage(moduleId, selectedDraftCategoryIds)+"Are you sure you want to delete the category(s)?"));
366					if (doSubmit) {
367						actionType = "DeleteCat";
368						var deletableCategories = $("input:checkbox:checked[data-candelete='True']");
369						var commaSeparatedDeletableIDs = "";
370						for (i = 0; i < deletableCategories.length; i++) {
371							if (i > 0)
372								commaSeparatedDeletableIDs = commaSeparatedDeletableIDs + "," + deletableCategories[i].value;
373							else
374								commaSeparatedDeletableIDs = deletableCategories[i].value;
375						}
376						form.deletableIDs.value = commaSeparatedDeletableIDs;
377					}
378				}
379				else {
380					alert("Only categories with no items can be deleted. \nNo categories are selected that can be deleted.");
381					doSubmit = false;
382				}
383				break;
384			}
385		case "ArchivePubCatWithNoItems":
386			{
387				var canArchive = $("input:checkbox:checked[data-canarchive='True']").length > 0;
388				if (canArchive) {
389					doSubmit = confirm('Only published categories with no items will be archived. \nArchiving is a PERMANENT action!\nYou will not be able to edit, publish, unpublish, submit, reject, or move these category(s) out of the archive!\n\nAre you sure you want to archive these category(s)?');
390					if (doSubmit) {
391						actionType = "ArchiveCat";
392						var archivableCategories = $("input:checkbox:checked[data-canarchive='True']");
393						var commaSeparatedArchivableIDs = "";
394						for (i = 0; i < archivableCategories.length; i++) {
395							if (i > 0)
396								commaSeparatedArchivableIDs = commaSeparatedArchivableIDs + "," + archivableCategories[i].value;
397							else
398								commaSeparatedArchivableIDs = archivableCategories[i].value;
399						}
400						form.archivableIDs.value = commaSeparatedArchivableIDs;
401					}
402				}
403				else {
404					alert("Only published categories with no items can be archived. To remove other categories, use the delete action. \nNo categories are selected that can be archived.");
405					doSubmit = false;
406				}
407				break;
408			}
409		case "ArchiveCat":
410			{
411				if (!ysnPubMarked) {
412					if (ysnUnpubMarked)
413						alert("Only published categories can be archived. To remove unpublished categories, use the delete action.");
414					else
415						alert("No categories are selected that can be archived.");
416					doSubmit = false;
417				}
418				else
419					doSubmit = confirm((ysnUnpubMarked ? 'Only published categories will be archived.  ' : '') + 'Archiving is a PERMANENT action!\nYou will not be able to edit, publish, unpublish, submit, reject, or move these category(s) out of the archive!\nOnly categories with no published items will be archived. \n\nAre you sure you want to archive these category(s)?');
420				break;
421			}
422		case "ArchiveHideCat":
423			{
424				if (!ysnPubMarked) {
425					doSubmit = false;
426					alert("No categories are selected that can be hidden.");
427				}
428				actionType = "ArchiveHide";
429				break;
430			}
431		case "ArchiveShowCat":
432			{
433				if (!ysnUnpubMarked) {
434					doSubmit = false;
435					alert("No categories are selected that can be shown.");
436				}
437				actionType = "ArchiveShow";
438				break;
439			}
440		case "ArchiveDeleteCat":
441			{
442				if (!(ysnUnpubMarked || ysnPubMarked)) {
443					doSubmit = false;
444					alert("No archived categories are selected that can be deleted.");
445				} else
446					doSubmit = (confirm("Are you sure you want to delete the selected archived category(s)?"));
447				actionType = "ArchiveDelete";
448				break;
449			}
450		default:
451			{
452				doSubmit = false;
453				break;
454			}
455	}
456
457	if (doSubmit) {
458		// Work-around for Firefox behavior with <button> tag in DC. Harder to read but avoids costly string concats.
459		setTimeout("BulkDisableIfExists(document.getElementById('btnBulkActionPublish')); BulkDisableIfExists(document.getElementById('btnBulkActionReject')); BulkDisableIfExists(document.getElementById('btnBulkActionUnpublish')); BulkDisableIfExists(document.getElementById('btnBulkActionSubmit')); BulkDisableIfExists(document.getElementById('btnBulkActionDelete')); BulkDisableIfExists(document.getElementById('btnBulkActionUnlock')); BulkDisableIfExists(document.getElementById('btnBulkActionArchive')); BulkDisableIfExists(document.getElementById('btnBulkActionShow')); BulkDisableIfExists(document.getElementById('btnBulkActionHide'));", 15);
460		form.strBulkAction.value = actionType;
461		form.submit();
462	}
463}
464
465function BulkDisableIfExists(formElem) {
466	if (formElem)
467		formElem.disabled = true;
468}
469
470function BulkActionCheckBoxesMarkDuo(form, check, fname) {
471	if (fname == "cboxUnpublishedCat")
472		fname = "cboxUnpublished";
473	else if (fname == "cboxPublishedCat")
474		fname = "cboxPublished";
475
476	var el = eval('form.' + fname);
477	if (el) {
478		el.checked = check;
479		for (var c = 0; c < el.length; c++)
480			el[c].checked = check;
481
482		if (check) {
483			if (fname == "cboxUnpublished")
484				bulkActionNumUnpublished_checked = bulkActionNumUnpublished_total;
485			else
486				bulkActionNumPublished_checked = bulkActionNumPublished_total;
487		}
488		else {
489			if (fname == "cboxUnpublished")
490				bulkActionNumUnpublished_checked = 0;
491			else
492				bulkActionNumPublished_checked = 0;
493		}
494	}
495
496	var elc = eval('form.' + fname + 'Cat');
497	if (elc) {
498		elc.checked = check;
499		for (var c = 0; c < elc.length; c++)
500			elc[c].checked = check;
501
502		if (check) {
503			if (fname == "cboxUnpublished")
504				bulkActionNumUnpublishedCat_checked = bulkActionNumUnpublishedCat_total;
505			else
506				bulkActionNumPublishedCat_checked = bulkActionNumPublishedCat_total;
507		}
508		else {
509			if (fname == "cboxUnpublished")
510				bulkActionNumUnpublishedCat_checked = 0;
511			else
512				bulkActionNumPublishedCat_checked = 0;
513		}
514	}
515}
516
517function BulkActionCheckBoxesMark(form, check, fname) {
518	var el = eval('form.' + fname)
519
520	if (el) {
521		el.checked = check;
522		for (var c = 0; c < el.length; c++)
523			el[c].checked = check;
524
525		if (check)
526			if (fname == "cboxUnpublished")
527			bulkActionNumUnpublished_checked = bulkActionNumUnpublished_total;
528		else
529			bulkActionNumPublished_checked = bulkActionNumPublished_total;
530		else
531			if (fname == "cboxUnpublished")
532			bulkActionNumUnpublished_checked = 0;
533		else
534			bulkActionNumPublished_checked = 0;
535	}
536}
537
538function BulkActionCheckBoxesMainDuo(form, check, item, otherParent) {
539	if (check) {
540		var otherElem = document.getElementById(otherParent);
541		if (otherElem.disabled || otherElem.checked)
542			document.getElementById("cboxBulkAll").checked = true;
543	}
544	else
545		document.getElementById("cboxBulkAll").checked = false;
546
547	BulkActionCheckBoxesMarkDuo(form, check, item);
548}
549
550function BulkActionCheckBoxesMain(form, check, item, otherParent) {
551	if (check) {
552		var otherElem = document.getElementById(otherParent);
553		if (otherElem.disabled || otherElem.checked)
554			document.getElementById("cboxBulkAll").checked = true;
555	}
556	else
557		document.getElementById("cboxBulkAll").checked = false;
558	BulkActionCheckBoxesMark(form, check, item);
559}
560
561function BulkActionCheckBoxesAllDuo(form, check) {
562	var cboxLU = document.getElementById("cboxUnPub");
563	var cboxLP = document.getElementById("cboxPub")
564
565	if (cboxLU && !cboxLU.disabled) {
566		cboxLU.checked = check;
567		BulkActionCheckBoxesMainDuo(form, check, "cboxUnpublished", "cboxPub");
568	}
569	if (cboxLP && !cboxLP.disabled) {
570		cboxLP.checked = check;
571		BulkActionCheckBoxesMainDuo(form, check, "cboxPublished", "cboxUnPub");
572	}
573}
574
575function BulkActionCheckBoxesAll(form, check) {
576	var cboxLU = document.getElementById("cboxUnPub");
577	var cboxLP = document.getElementById("cboxPub")
578
579	if (cboxLU && !cboxLU.disabled) {
580		cboxLU.checked = check;
581		BulkActionCheckBoxesMain(form, check, "cboxUnpublished", "cboxPub");
582	}
583	if (cboxLP && !cboxLP.disabled) {
584		cboxLP.checked = check;
585		BulkActionCheckBoxesMain(form, check, "cboxPublished", "cboxUnPub");
586	}
587}
588
589function BulkActionAllCheckedDuo(item) {
590	if (item == "cboxUnpublished" || item == "cboxUnpublishedCat")
591		return bulkActionNumUnpublished_total + bulkActionNumUnpublishedCat_total == bulkActionNumUnpublished_checked + bulkActionNumUnpublishedCat_checked;
592	else
593		return bulkActionNumPublished_total + bulkActionNumPublishedCat_total == bulkActionNumPublished_checked + bulkActionNumPublishedCat_checked;
594}
595
596function BulkActionAllCheckedCat(item) {
597	if (item == "cboxUnpublishedCat")
598		return bulkActionNumUnpublishedCat_total == bulkActionNumUnpublishedCat_checked;
599	else
600		return bulkActionNumPublishedCat_total == bulkActionNumPublishedCat_checked;
601}
602
603function BulkActionAllCheckedItem(item) {
604	if (item == "cboxUnpublished")
605		return bulkActionNumUnpublished_total == bulkActionNumUnpublished_checked;
606	else
607		return bulkActionNumPublished_total == bulkActionNumPublished_checked;
608}
609
610// Used for AJAX + bulk actions (see Group Admin).
611function BulkActionReinit(form) {
612	var chkBB = document.getElementById('cboxBulkAll');
613	chkBB.checked = false;
614	chkBB.disabled = false;
615	bulkActionInitDone = false;
616	bulkActionNumPublished_total = 0;
617	bulkActionNumUnpublished_total = 0;
618	bulkActionNumUnpublished_checkeBulkActiond = 0;
619	bulkActionNumPublished_checked = 0;
620	BulkActionInit(form);
621}
622
623function BulkActionCheckBoxCategory(form, check, item, itemParent, otherParent) {
624	if (check) {
625		(item == "cboxUnpublishedCat" ?
626			++bulkActionNumUnpublishedCat_checked : ++bulkActionNumPublishedCat_checked);
627
628		if (BulkActionAllCheckedDuo(item)) {
629			document.getElementById(itemParent).checked = true;
630			var otherElem = document.getElementById(otherParent);
631			if (otherElem.checked || otherElem.disabled)
632				document.getElementById("cboxBulkAll").checked = true;
633		}
634	}
635	else {
636		document.getElementById(itemParent).checked = false;
637		document.getElementById("cboxBulkAll").checked = false;
638
639		(item == "cboxUnpublishedCat" ?
640			--bulkActionNumUnpublishedCat_checked : --bulkActionNumPublishedCat_checked);
641	}
642}
643
644
645function BulkActionCheckBoxItem(form, check, item, itemParent, otherParent) {
646	if (check) {
647		(item == "cboxUnpublished" ?
648			++bulkActionNumUnpublished_checked : ++bulkActionNumPublished_checked);
649
650		if (BulkActionAllCheckedDuo(item)) {
651			document.getElementById(itemParent).checked = true;
652			var otherElem = document.getElementById(otherParent);
653			if (otherElem.checked || otherElem.disabled)
654				document.getElementById("cboxBulkAll").checked = true;
655		}
656	}
657	else {
658		document.getElementById(itemParent).checked = false;
659		document.getElementById("cboxBulkAll").checked = false;
660
661		(item == "cboxUnpublished" ?
662			--bulkActionNumUnpublished_checked : --bulkActionNumPublished_checked);
663	}
664}
665
666function BulkActionCalendarEventCheckBoxItem(form, check, item, itemParent, otherParent) {
667	var calendarEventCount = document.getElementById("hdnAllCurrentEventCount");
668	var hdnShowAllCalendars = document.getElementById("hdnShowAllCalendars").value.toLowerCase();
669	numberOfRowChecked = calendarEventCount.value;
670
671	if (check) {
672		(item == "cboxUnpublished" ?
673			++bulkActionNumUnpublished_checked : ++bulkActionNumPublished_checked);
674
675		if (BulkActionAllCheckedDuo(item)) {
676			document.getElementById(itemParent).checked = true;
677			var otherElem = document.getElementById(otherParent);
678			if (otherElem.checked || otherElem.disabled)
679				document.getElementById("cboxBulkAll").checked = true;
680		}
681		++numberOfRowChecked;
682	}
683	else {
684		document.getElementById(itemParent).checked = false;
685		document.getElementById("cboxBulkAll").checked = false;
686		document.getElementById("hdnAllEventsChk").value = "false";
687
688		(item == "cboxUnpublished" ?
689			--bulkActionNumUnpublished_checked : --bulkActionNumPublished_checked);
690
691		if (numberOfRowChecked > 0)
692			--numberOfRowChecked;
693	}
694
695	var sellectAllRowsEnabled = window.FeatureToggles.isActive("CMS.Site.SelectAllItems");
696
697	if (sellectAllRowsEnabled && hdnShowAllCalendars != "true") {
698		var maxItemsPerPage = document.getElementById("hdnMaxItemsPerPage");
699		var pAllRowEventCount = document.getElementById("pCalendarEventCount");
700		var allEventCount = document.getElementById("hdnallAllEventCount");
701		var chkBulkAll = document.getElementById("cboxBulkAll");
702		var chkallEventIds = document.getElementById("hdnAllEventsChk").value;
703		var isChecked = chkBulkAll.checked;
704		calendarEventCount.value = numberOfRowChecked;
705
706		var maxItemsPerPageValue = parseInt(maxItemsPerPage.value, 10);
707		var calendarEventCountValue = parseInt(calendarEventCount.value, 10);
708		var allEventCountValue = parseInt(allEventCount.value, 10);
709
710		if (allEventCount && calendarEventCount && maxItemsPerPage) {
711
712			if (!isNaN(maxItemsPerPageValue) && !isNaN(calendarEventCountValue) && !isNaN(allEventCountValue)) {
713
714				if (chkallEventIds === "false") {
715					// Display the number of selected rows in this page
716					if (calendarEventCountValue === 0)
717						pAllRowEventCount.innerHTML = "";
718					else if (calendarEventCountValue === allEventCountValue)
719						pAllRowEventCount.innerHTML = "All " + allEventCountValue + " rows in this calendar selected ";
720					else if (calendarEventCountValue != allEventCountValue && isChecked)
721						pAllRowEventCount.innerHTML = "All " + calendarEventCountValue + " rows in this page selected ";
722					else if (calendarEventCountValue != allEventCountValue)
723						pAllRowEventCount.innerHTML = calendarEventCountValue + " rows selected in this page";
724					else
725						pAllRowEventCount.innerHTML = "";
726
727					// Check if "Bulk All" is checked and update the button visibility
728					if (isChecked) {
729						btnAllRowCalendar.style.display = maxItemsPerPageValue >= allEventCountValue ? "none" : "block";
730					} else {
731						// "Bulk All" is not checked, hide the button
732						btnAllRowCalendar.style.display = "none";
733					}
734				}
735			}
736			else {
737				console.log("Error parsing values as integers.");
738			}
739		}
740		else {
741			console.log("Hidden elements not found.");
742		}
743	}
744}
745
746function BulkActionInitDuo(form) {
747	if (!bulkActionInitDone) {
748		if (form) {
749			bulkActionInitDone = true;
750
751			var el = form.cboxUnpublished;
752			if (el)
753				if (el.length == null)
754				bulkActionNumUnpublished_total = 1;
755			else
756				bulkActionNumUnpublished_total = el.length;
757			else
758				bulkActionNumUnpublished_total = 0;
759			el = form.cboxUnpublishedCat;
760			if (el)
761				if (el.length == null)
762				bulkActionNumUnpublishedCat_total = 1;
763			else
764				bulkActionNumUnpublishedCat_total = el.length;
765			else
766				bulkActionNumUnpublishedCat_total = 0;
767			el = form.cboxPublished;
768			if (el)
769				if (el.length == null)
770				bulkActionNumPublished_total = 1;
771			else
772				bulkActionNumPublished_total = el.length;
773			else
774				bulkActionNumPublished_total = 0;
775			el = form.cboxPublishedCat;
776			if (el)
777				if (el.length == null)
778				bulkActionNumPublishedCat_total = 1;
779			else
780				bulkActionNumPublishedCat_total = el.length;
781			else
782				bulkActionNumPublishedCat_total = 0;
783
784			if (bulkActionNumUnpublished_total + bulkActionNumUnpublishedCat_total == 0)
785				BulkDisableIfExists(document.getElementById("cboxUnPub"));
786			if (bulkActionNumPublished_total + bulkActionNumPublishedCat_total == 0)
787				BulkDisableIfExists(document.getElementById("cboxPub"));
788			if (bulkActionNumUnpublished_total + bulkActionNumUnpublishedCat_total == 0 && bulkActionNumPublished_total + bulkActionNumPublishedCat_total == 0)
789				BulkDisableIfExists(document.getElementById("cboxBulkAll"));
790		}
791		else {
792			bulkActionNumUnpublished_total = 0;
793			bulkActionNumPublished_total = 0;
794			bulkActionNumUnpublishedCat_total = 0;
795			bulkActionNumPublishedCat_total = 0;
796		}
797	}
798}
799
800function BulkActionInit(form) {
801	if (!bulkActionInitDone) {
802		if (form) {
803			bulkActionInitDone = true;
804
805			var el = form.cboxUnpublished;
806			if (el)
807				if (el.length == null)
808				bulkActionNumUnpublished_total = 1;
809			else
810				bulkActionNumUnpublished_total = el.length;
811			else
812				bulkActionNumUnpublished_total = 0;
813
814			el = form.cboxPublished;
815			if (el)
816				if (el.length == null)
817				bulkActionNumPublished_total = 1;
818			else
819				bulkActionNumPublished_total = el.length;
820			else
821				bulkActionNumPublished_total = 0;
822
823			if (bulkActionNumUnpublished_total == 0)
824				BulkDisableIfExists(document.getElementById("cboxUnPub"));
825			if (bulkActionNumPublished_total == 0)
826				BulkDisableIfExists(document.getElementById("cboxPub"));
827			if (bulkActionNumUnpublished_total == 0 && bulkActionNumPublished_total == 0)
828				BulkDisableIfExists(document.getElementById("cboxBulkAll"));
829		}
830		else {
831			bulkActionNumUnpublished_total = 0;
832			bulkActionNumPublished_total = 0;
833		}
834	}
835}
836
837/****** Multiple (Grouped) Normal Bulk Actions Code ******/
838function BulkActionProcessMulti(form, actionType, ysnPublisher) {
839	var doSubmit = true;
840	var c;
841	var ysnUnpubMarked = false;
842	var ysnPubMarked = false;
843	var lstTmp;
844
845	for (var cv = 0;
845 cv < numBulkActionGroups; cv++) {
846		if (!ysnPubMarked) {
847			lstTmp = form["cboxPublished" + cv];
848			if (lstTmp && ysnPublisher) {
849				if (lstTmp.length == null)
850					ysnPubMarked = lstTmp.checked;
851				else
852					for (c = 0; c < lstTmp.length && !ysnPubMarked; c++)
853					if (lstTmp[c].checked) {
854					ysnPubMarked = true;
855					break;
856				}
857			}
858		}
859		if (!ysnUnpubMarked) {
860			lstTmp = form["cboxUnpublished" + cv];
861			if (lstTmp) {
862				if (lstTmp.length == null)
863					ysnUnpubMarked = lstTmp.checked;
864				else
865					for (c = 0; c < lstTmp.length && !ysnUnpubMarked; c++)
866					if (lstTmp[c].checked) {
867					ysnUnpubMarked = true;
868					break;
869				}
870			}
871		}
872	}
873
874	switch (actionType) {
875		case "Unpublish":
876			{
877				if (!ysnPubMarked) {
878					doSubmit = false;
879					alert("No " + bulkActionPluralNoun + " are selected that can be unpublished.");
880				}
881				break;
882			}
883		case "Publish":
884			{
885				if (!ysnUnpubMarked) {
886					doSubmit = false;
887					alert("No " + bulkActionPluralNoun + " are selected that can be published.");
888				}
889				break;
890			}
891		case "Submit":
892			{
893				if (!ysnUnpubMarked) {
894					doSubmit = false;
895					alert("No " + bulkActionPluralNoun + " are selected that can be submitted.");
896				}
897				break;
898			}
899		case "Reject":
900			{
901				if (!ysnUnpubMarked) {
902					doSubmit = false;
903					alert("No " + bulkActionPluralNoun + " are selected that can be rejected.");
904				}
905				break;
906			}
907		case "Unlock":
908			{
909				if (ysnPublisher)
910					doSubmit = ysnUnpubMarked || ysnPubMarked;
911				else
912					doSubmit = ysnUnpubMarked;
913
914				if (!doSubmit)
915					alert("No " + bulkActionPluralNoun + " are selected that can be unlocked.");
916				break;
917			}
918		case "Delete":
919			{
920				if (ysnPublisher)
921					doSubmit = ysnUnpubMarked || ysnPubMarked;
922				else
923					doSubmit = ysnUnpubMarked;
924				if (doSubmit)
925					doSubmit = confirm("Are you sure you want to delete the selected " + bulkActionPluralNoun + "?");
926				else
927					alert("No " + bulkActionPluralNoun + " are selected that can be deleted.");
928				break;
929			}
930		default:
931			{
932				doSubmit = false;
933				break;
934			}
935	}
936
937	if (doSubmit) {
938		// Work-around for Firefox behavior with <button> tag in DC. Harder to read but avoids costly string concats.
939		setTimeout("BulkDisableIfExists(document.getElementById('btnBulkActionPublish')); BulkDisableIfExists(document.getElementById('btnBulkActionReject')); BulkDisableIfExists(document.getElementById('btnBulkActionUnpublish')); BulkDisableIfExists(document.getElementById('btnBulkActionSubmit')); BulkDisableIfExists(document.getElementById('btnBulkActionDelete')); BulkDisableIfExists(document.getElementById('btnBulkActionUnlock')); BulkDisableIfExists(document.getElementById('btnBulkActionArchive')); BulkDisableIfExists(document.getElementById('btnBulkActionShow')); BulkDisableIfExists(document.getElementById('btnBulkActionHide'));", 15);
940		form.strBulkAction.value = actionType;
941		form.submit();
942	}
943}
944function BulkActionCheckBoxesMarkMulti(form, check, fname, groupNum) {
945	var el = eval('form.' + fname + groupNum)
946
947	if (el) {
948		el.checked = check;
949		for (var c = 0; c < el.length; c++)
950			el[c].checked = check;
951
952		if (check)
953			if (fname == "cboxUnpublished" + groupNum)
954			arrBulkActionNumUnpublished_checked[groupNum] = arrBulkActionNumUnpublished_total[groupNum];
955		else
956			arrBulkActionNumPublished_checked[groupNum] = arrBulkActionNumPublished_total[groupNum];
957		else
958			if (fname == "cboxUnpublished" + groupNum)
959			arrBulkActionNumUnpublished_checked[groupNum] = 0;
960		else
961			arrBulkActionNumPublished_checked[groupNum] = 0;
962	}
963}
964
965function BulkActionCheckBoxesMainMulti(form, check, item, otherParent, groupNum) {
966	if (check) {
967		var otherElem = document.getElementById(otherParent + groupNum);
968		if (otherElem.disabled || otherElem.checked)
969			document.getElementById("cboxBulkAll" + groupNum).checked = true;
970	}
971	else
972		document.getElementById("cboxBulkAll" + groupNum).checked = false;
973
974	BulkActionCheckBoxesMarkMulti(form, check, item, groupNum);
975}
976
977function BulkActionCheckBoxesAllMulti(form, check, groupNum) {
978	var cboxLU = document.getElementById("cboxUnPub" + groupNum);
979	var cboxLP = document.getElementById("cboxPub" + groupNum)
980
981	if (cboxLU && !cboxLU.disabled) {
982		cboxLU.checked = check;
983		BulkActionCheckBoxesMainMulti(form, check, "cboxUnpublished", "cboxPub", groupNum);
984	}
985	if (cboxLP && !cboxLP.disabled) {
986		cboxLP.checked = check;
987		BulkActionCheckBoxesMainMulti(form, check, "cboxPublished", "cboxUnPub", groupNum);
988	}
989}
990
991function BulkActionInitMulti(form, numGroups, pluralNoun) {
992	if (!bulkActionInitDone) {
993		bulkActionPluralNoun = pluralNoun;
994		numBulkActionGroups = numGroups;
995		arrBulkActionNumPublished_total = new Array();
996		arrBulkActionNumUnpublished_total = new Array();
997		arrBulkActionNumUnpublished_checked = new Array();
998		arrBulkActionNumPublished_checked = new Array();
999		for (var cv = 0;
999 cv < numGroups; cv++) {
1000			arrBulkActionNumPublished_total.push(0);
1001			arrBulkActionNumUnpublished_total.push(0);
1002			arrBulkActionNumUnpublished_checked.push(0);
1003			arrBulkActionNumPublished_checked.push(0);
1004		}
1005		if (form) {
1006			for (var cv = 0; cv < numGroups; cv++)
1007				BulkActionInitMultiHelper(form, cv);
1008			bulkActionInitDone = true;
1009		}
1010	}
1011}
1012function BulkActionInitMultiHelper(form, arrIdx) {
1013	var el = form["cboxUnpublished" + arrIdx];
1014	if (el)
1015		if (el.length == null)
1016		arrBulkActionNumUnpublished_total[arrIdx] = 1;
1017	else
1018		arrBulkActionNumUnpublished_total[arrIdx] = el.length;
1019	else
1020		arrBulkActionNumUnpublished_total[arrIdx] = 0;
1021
1022	el = form["cboxPublished" + arrIdx];
1023	if (el)
1024		if (el.length == null)
1025		arrBulkActionNumPublished_total[arrIdx] = 1;
1026	else
1027		arrBulkActionNumPublished_total[arrIdx] = el.length;
1028	else
1029		arrBulkActionNumPublished_total[arrIdx] = 0;
1030
1031	if (arrBulkActionNumUnpublished_total[arrIdx] == 0)
1032		BulkDisableIfExists(document.getElementById("cboxUnPub" + arrIdx));
1033	if (arrBulkActionNumPublished_total[arrIdx] == 0)
1034		BulkDisableIfExists(document.getElementById("cboxPub" + arrIdx));
1035	if (arrBulkActionNumUnpublished_total[arrIdx] == 0 && arrBulkActionNumPublished_total[arrIdx] == 0)
1036		BulkDisableIfExists(document.getElementById("cboxBulkAll" + arrIdx));
1037}
1038function BulkActionCheckBoxItemMulti(form, check, item, itemParent, otherParent, groupNum) {
1039	if (check) {
1040		(item == "cboxUnpublished" ?
1041			++arrBulkActionNumUnpublished_checked[groupNum] : ++arrBulkActionNumPublished_checked[groupNum]);
1042
1043		if (BulkActionAllCheckedMulti(item, groupNum)) {
1044			document.getElementById(itemParent + groupNum).checked = true;
1045			var otherElem = document.getElementById(otherParent + groupNum);
1046			if (otherElem.checked || otherElem.disabled)
1047				document.getElementById("cboxBulkAll" + groupNum).checked = true;
1048		}
1049	}
1050	else {
1051		document.getElementById(itemParent + groupNum).checked = false;
1052		document.getElementById("cboxBulkAll" + groupNum).checked = false;
1053
1054		(item == "cboxUnpublished" ?
1055			--arrBulkActionNumUnpublished_checked[groupNum] : --arrBulkActionNumPublished_checked[groupNum]);
1056	}
1057}
1058function BulkActionAllCheckedMulti(item, groupNum) {
1059	if (item == "cboxUnpublished")
1060		return (arrBulkActionNumUnpublished_total[groupNum] == arrBulkActionNumUnpublished_checked[groupNum]);
1061	else
1062		return (arrBulkActionNumPublished_total[groupNum] == arrBulkActionNumPublished_checked[groupNum]);
1063}
1064
1065// Public. Gets any child inputs of a node that match the type specified.
1066function getAnyChildInputs(node, type) {
1067	var retList = [];
1068	var nodeList = node.getElementsByTagName('input');
1069
1070	for (var i = 0, len = nodeList.length; i < len; i++) {
1071		if (nodeList.item(i) && nodeList.item(i).type == type)
1072			retList.push(nodeList.item(i));
1073	}
1074
1075	return retList;
1076}
1077
1078// Public. Gets checkboxes directly inside the container specified (doesn't search children of children).
1079// containerID = The ID of the container containing the checkboxes.
1080function getChildCheckBoxes(containerID, includeDisabled) {
1081	var container = document.getElementById(containerID);
1082	var child = container.firstChild;
1083	var children = new Array();
1084	
1085	if (includeDisabled == null)
1086		includeDisabled = false;
1087	
1088	while (child != null) {
1089		if (child.nodeType == 1 && child.nodeName == 'INPUT' && child.type == 'checkbox') {
1090			if (includeDisabled || (!includeDisabled && child.disabled == false))
1091				children.push(child);
1092		}
1093		
1094		child = child.nextSibling;
1095	}
1096	
1097	return children;
1098}
1099
1100// Public. Converts a NodeList object to an array for methods that require arrays.
1101// Useful for converting form input lists (checkboxes/radiobuttons) to arrays.
1102// Notes:
1103//   * If argument is an array, it is returned.
1104//   * If argument is a NodeList, it is converted to an array.
1105//   * If argument is neither and not null, it is placed in an array and returned.
1106//	 * If argument is null, an empty array is returned.
1107// nodeList = The NodeList to convert to an array (e.g. document.myForm.checkboxes).
1108Array.fromNodeList = function (nodeList) {
1109	if (nodeList instanceof Array)
1110		return nodeList;
1111	else if (nodeList != null) {
1112		if (nodeList.length && nodeList.item) {
1113			var ret = new Array();
1114
1115			for (var i = 0, len = nodeList.length; i < len; i++)
1116				ret.push(nodeList.item(i));
1117
1118			return ret;
1119		}
1120		else
1121			return [nodeList];
1122	}
1123	else
1124		return new Array();
1125}
1126
1127// Public. Gets elements by IDs specified (param array), returns array of elements.
1128function elementsByIds() {
1129	var retVal = new Array();
1130
1131	for (var i = 0, len = arguments.length; i < len; i++)
1132		retVal.push(document.getElementById(arguments[i]));
1133
1134	return retVal;
1135}
1136
1137// Used by Newsflash, Polls, FAQ, Archive Center, Notify Me, Pages, and Possibly
1138// other modules to determine which buttons to show during a copy operation.
1139function updateButtonsCategoryDropDownChanged(self, btnSave, btnSavePublish, btnSaveSubmit) {
1140	var rightsMode = self.options[self.selectedIndex].className.substr(7);
1141	var styleButtonSave = btnSave.style;
1142	var styleButtonSavePub = btnSavePublish.style;
1143	var styleButtonSaveSub = btnSaveSubmit.style;
1144
1145	switch (rightsMode) {
1146		case 'v':
1147		case 'r':
1148			styleButtonSavePub.display = "none";
1149			styleButtonSaveSub.display = "none";
1150			styleButtonSave.display = "none";
1151			break;
1152		case 'a':
1153			styleButtonSavePub.display = "none";
1154			styleButtonSaveSub.display = "";
1155			styleButtonSave.display = "";
1156			break;
1157		case 'o':
1158		case 'p':
1159			styleButtonSavePub.display = "";
1160			styleButtonSaveSub.display = "none";
1161			styleButtonSave.display = "";
1162			break;
1163	}
1164}
1165
1166function removeIEParagraphs(editor) {
1167	editor.attachEventHandler("onkeyup", function (e) {
1168		if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 13) {
1169			var result = '';
1170			var re = new RegExp("<[P]>&nbsp;<\\/[P]>", "gi");
1171
1172			var m = re.exec(editor.get_html(true));
1173
1174			if (m == null) {
1175				return;
1176			} else {
1177				result = editor.get_html(true).replace(re, '<BR>');
1178				editor.set_html(result);
1179			}
1180
1181		}
1182	});
1183}
1184
1185//To toggle the slide show and image manger menu items based on if the img is a from a slide show or not.
1186function setMenuItems(editor) {
1187	var contextMenu = editor.getContextMenuByTagName("IMG");
1188	if (!contextMenu) return;
1189
1190	//Attach to the context menu show event, obtain editor selection and determine which tools to show
1191	contextMenu.add_show(function () {
1192		//Must be an image, the context menu would not fire   
1193		var sel = editor.getSelectedElement();
1194
1195		//An array of menu item objects
1196		var menuItems = contextMenu.get_items();
1197		var menuItem = null;
1198
1199		//reset to show all and then disable the menu item based on currently selection
1200		for (i = 0; i < menuItems.length; i++) {
1201			menuItems[i].get_element().style.display = "";
1202			menuItems[i].get_element().parentNode.style.display = "";
1203		} //end for
1204
1205		if (sel.getAttribute("slideshowimage")) {
1206			menuItem = menuItems[menuItems.length - 3];
1207			menuItem.get_element().style.display = "none";
1208			menuItem.get_element().parentNode.style.display = "none";
1209
1210			menuItem = menuItems[menuItems.length - 2];
1211			menuItem.get_element().style.display = "none";
1212			menuItem.get_element().parentNode.style.display = "none";
1213
1214		} else {
1215			menuItem = menuItems[menuItems.length - 1];
1216			menuItem.get_element().style.display = "none";
1217			menuItem.get_element().parentNode.style.display = "none";
1218		}
1219	});
1220}
1221
1222function showHideDetails() {
1223	var item = document.getElementById('advanced');
1224
1225	if (item.style.display == 'block') {
1226		item.style.display = 'none';
1227		document.getElementById("a_advanced").innerHTML = '&#9658;&nbsp;Show Additional Details';
1228		document.cookie = "showAddDetails=false;";
1229	}
1230	else {
1231		item.style.display = 'block';
1232		document.getElementById("a_advanced").innerHTML = '&#9660;&nbsp;Hide Additional Details';
1233		document.cookie = "showAddDetails=true;";
1234		//typeof InstallTrigger !== 'undefined' is used to detect mozilla browser
1235		if (typeof InstallTrigger !== 'undefined' && $telerik.$(".RadEditor").length > 0) {
1236			$find($telerik.$(".RadEditor")[0].id).onParentNodeChanged();
1237		}
1238	}
1239}
1240
1241// Tab-related
1242function tabs(x, max) {
1243	document.getElementById("current").removeAttribute("id");
1244	document.getElementById("tabs" + x).firstChild.setAttribute("id", "current");
1245	for (var a = 1; a <= max; a++) {
1246	    if (document.getElementById("tab" + a) != null)
1247	        document.getElementById("tab" + a).style.display = "none";
1248	}
1249	document.getElementById("tab" + x).style.display = "block";
1250	return false;
1251}
1252
1253function tryTabs(desired, max) {
1254	if (ysnPageMenuLoaded)
1255		tabs(desired, max);
1256	else
1257		alert('The page is not finished loading. Please try again in a few seconds.');
1258}
1259
1260// 2 functions below are for sending emails through the email notification window on the f end. This functionality has been put here to
1261// match the way its done on front end for live edits.
1262//The extra arguments added to the end of this method are for making it work with MVC modules until we write the MVC way of notify me integartion. It won't effect the 
1263//old modules. - VB
1264function publishItemBE(ysnSend, ysnSendAtStart, ysnSendBeforeDays, frmMain, from, argument) {
1265	if (frmMain.name == 'frmBulkActions' || frmMain.name == 'frmBidBulkActions' || frmMain.name == 'frmBlogBulkActions' || frmMain.name == 'frmJobBulkActions')
1266		frmMain.strBulkAction.value = 'Publish';
1267	frmMain.ysnSave.value = 1;
1268	frmMain.ysnSend.value = ysnSend;
1269	frmMain.ysnSendAtStart.value = ysnSendAtStart;
1270	frmMain.ysnSendBeforeDays.value = ysnSendBeforeDays;
1271	var msgMobileElem = document.frmSendEmail.txtMsgMobile;
1272	if (msgMobileElem)
1273		frmMain.txtSMSComments.value = msgMobileElem.value;
1274
1275	if (frmMain.name != 'frmBulkActions' && frmMain.name != 'frmBidBulkActions' && frmMain.name != 'frmBlogBulkActions' && frmMain.name != 'frmJobBulkActions') {
1276		switch (from) {
1277		    case 'civicalerts':
1278		        switch (frmMain.name) {
1279		            case 'frmAlertInfo':
1280		                frmMain.ysnPublishDetail.value = 1;
1281		                break;
1282		            case 'frmAlertDetail':
1283		                frmMain.strPage.value = "CivicAlertItemPublish";
1284		                break;
1285		            case 'aspnetForm':
1286						window.parent.notifyMePopUpCallBack(frmMain, argument);
1287		                return;
1288		        }
1289		        break;
1290		    case 'bids':
1291				if (frmMain.curPage && frmMain.curPage.value == 'BidItemForm') {
1292					frmMain.strPage.value = 'BidItemSave';
1293					frmMain.txtAfterSaveAction.value = 'publish';
1294				}
1295				else
1296					frmMain.strPage.value = 'BidItemPublish';
1297				break;
1298			case 'jobs':
1299				if (frmMain.curPage && frmMain.curPage.value == 'JobItemForm') {
1300					frmMain.strPage.value = 'JobItemSave';
1301					frmMain.txtAfterSaveAction.value = 'publish';
1302				}
1303				else
1304					frmMain.strPage.value = 'JobItemPublish';
1305				break;
1306            case 'Blog':
1307            case 'blog':
1308            case 'blogs':
1309				if (frmMain.curPage && frmMain.curPage.value == 'BlogItemForm') {
1310					frmMain.strPage.value = 'BlogItemSave';
1311					//frmMain.txtAfterSaveAction.value = 'publish';
1312				}
1313				else
1314					frmMain.strPage.value = 'BlogItemPublish';
1315				break;
1316            case 'calendar':
1317				window.parent.notifyMePopUpCallBack(frmMain, argument);
1318                break;
1319            case 'alertcenter':
1320                // alert center notify me handler
1321				window.parent.notifyMePopUpCallBack(argument);
1322                return;
1323			case 'jobsii':
1324				// jobs notify me handler
1325				window.parent.notifyMePopUpCallBack(argument);
1326				return;
1327			case 'AgendaCenter':
1328				window.parent.notifyMePopUpCallBack(argument);
1329				return;
1330		}
1331	}
1332	if (from != 'calendar')
1333		frmMain.submit();
1334}
1335
1336function validNumber(num) {
1337	return (parseInt(num) == num);
1338}
1339
1340function closeModalDialog(behaviourID) {
1341	var behavior = $find(behaviourID);
1342
1343	if (behavior)
1344		behavior.hide();
1345}
1346
1347function cancelBE(needsConfirm) {
1348	if (needsConfirm) {
1349		if (!confirm("You will discard any unsaved changes. Do you want to proceed?"))
1350			return;
1351	}
1352	window.parent.closeModalDialog('editItemBehavior');
1353	return false;
1354}
1355
1356function createAndSetNewModifiedToggleIfNeeded(frmMain, frmFQF) {
1357    // remove any duplicates in DOM that might send false values
1358    if (frmMain.newModifiedToggle) {
1359        var element = frmMain.newModifiedToggle;
1360
1361        if (element && !element.length) {
1362            element.parentNode.removeChild(element);
1363        } else {
1364            for (var index = element.length - 1; index >= 0; index--) {
1365                element[index].parentNode.removeChild(element[index]);
1366            }
1367        }
1368    }
1369
1370    if (!frmFQF.newModifiedToggle || !frmFQF.newModifiedToggle.checked) {
1371          return; // don't create a field for the toggle if it isn't even enabled or doesn't exist.
1372    }
1373    var input = document.createElement("input");
1374
1375    input.setAttribute("type", "hidden");
1376    input.setAttribute("name", "newModifiedToggle");
1377    input.setAttribute("value", frmFQF.newModifiedToggle.value);
1378    
1379    frmMain.appendChild(input);
1380}
1381
1382function createAndSetIncludeLinkIntoSmsIfNeeded(frmMain, frmFQF) {
1383	// remove any duplicates in DOM that might send false values
1384	if (frmMain.includeLinkIntoSms) {
1385		var element = frmMain.includeLinkIntoSms;
1386
1387		if (element && !element.length) {
1388			element.parentNode.removeChild(element);
1389		} else {
1390			for (var index = element.length - 1; index >= 0; index--) {
1391				element[index].parentNode.removeChild(element[index]);
1392			}
1393		}
1394	}
1395
1396	if (!frmFQF.includeLinkIntoSms || !frmFQF.includeLinkIntoSms.checked) {
1397		return; // don't create a field for the toggle if it isn't even enabled or doesn't exist.
1398	}
1399	var input = document.createElement("input");
1400
1401	input.setAttribute("type", "hidden");
1402	input.setAttribute("name", "includeLinkIntoSms");
1403	input.setAttribute("value", frmFQF.includeLinkIntoSms.value);
1404
1405	frmMain.appendChild(input);
1406}
1407
1408//The extra arguments added to the end of this method are for making it work with MVC modules until we write the MVC way of notify me integartion. It won't effect the 
1409//old modules. - VB
1410function sendEmailBE(event, frmMain, from, ysnRadioButtonSelected, argument) {
1411    var send;
1412	var frmFQF = document.frmSendEmail;
1413	var frmMain = window.parent.document.getElementById(frmMain);
1414	if (!ysnRadioButtonSelected) {
1415		event.target.disabled = true;
1416		publishItemBE(false, false, false, frmMain, from, argument);
1417		publishItemBE = function () { return false; }; //disabling the input can be buggy, so hijacking publishItemBE function as an extra precaution
1418	} else {
1419		for (var i = 0; i < frmFQF.one.length; i++) {
1420			if (frmFQF.one[i].checked) {
1421				send = frmFQF.one[i].value;
1422			}
1423		}
1424		if (send == "Send") {
1425			event.target.disabled = true;
1426			if (frmFQF.txtMsgSubject && frmMain.txtSubject) {
1427				frmMain.txtSubject.value = (argument == "bulkActionPublish" || argument.comingFrom == "bulkActionsPublish")
1428					? ""
1429					: frmFQF.txtMsgSubject.value.replace(/\n/g, ' ');
1430			}
1431			frmMain.txtComments.value = frmFQF.txtMsgComments.value;
1432			createAndSetNewModifiedToggleIfNeeded(frmMain, frmFQF);
1433			createAndSetIncludeLinkIntoSmsIfNeeded(frmMain, frmFQF);
1434			publishItemBE(true, false, false, frmMain, from, argument);
1435			publishItemBE = function () { return false; };//disabling the input can be buggy, so hijacking publishItemBE function as an extra precaution
1436		} else if (send == "SendAtStart") {
1437			event.target.disabled = true;
1438			if (frmFQF.txtMsgSubject && frmMain.txtSubject) {
1439				frmMain.txtSubject.value = (argument == "bulkActionPublish" || argument.comingFrom == "bulkActionsPublish")
1440					? ""
1441					: frmFQF.txtMsgSubject.value.replace(/\n/g, ' ');
1442			}
1443			frmMain.txtComments.value = frmFQF.txtMsgComments.value;
1444			createAndSetNewModifiedToggleIfNeeded(frmMain, frmFQF);
1445			createAndSetIncludeLinkIntoSmsIfNeeded(frmMain, frmFQF);
1446			publishItemBE(false, true, false, frmMain, from, argument);
1447		} else if (send == "SendBeforeDays") {
1448			var userValue = frmFQF.numDays.value;
1449			if (validNumber(userValue)) {
1450				event.target.disabled = true;
1451				if (frmFQF.txtMsgSubject && frmMain.txtSubject) {
1452					frmMain.txtSubject.value = (argument == "bulkActionPublish" || argument.comingFrom == "bulkActionsPublish")
1453						? ""
1454						: frmFQF.txtMsgSubject.value.replace(/\n/g, ' ');
1455				}
1456				frmMain.txtComments.value = frmFQF.txtMsgComments.value;
1457				createAndSetNewModifiedToggleIfNeeded(frmMain, frmFQF);
1458				createAndSetIncludeLinkIntoSmsIfNeeded(frmMain, frmFQF);
1459				frmMain.intSendBeforeDays.value = frmFQF.numDays.value;
1460				publishItemBE(false, false, true, frmMain, from, argument);
1461				publishItemBE = function () { return false; };//disabling the input can be buggy, so hijacking publishItemBE function as an extra precaution
1462			} else if (userValue == '') {
1463				alert('The number of days before the event was not specified.');
1464			} else {
1465				alert('An invalid value was entered for the number of days. Please enter a valid value.');
1466			}
1467		} else
1468			alert('A send time must be selected.');
1469	}
1470}
1471
1472/*********************************************************
1473* START - NEW METHODS INTRODUCED FOR POTENTIALLY COMMONIZING THE NOTIFY POPUP CODE. SUBJECT TO CHANGE
1474THESE WILL BE REFACTORED/MOVED TO SOME OTHER LOCATION WHEN WE RE-WRITE 
1474NOTIFY ME THE PROPER MVC WAY.
1475**********************************************************/
1476
1477//Opens the notify me popup for sending notifications when an item is published. 
1478function openNotifyMeModal(url, modalTitle, className) {
1479	var behaviorID = $find('editItemBehavior');
1480	if (behaviorID) {
1481		var ifrID = document.getElementById('NotifyMeDialog');
1482		ifrID.src = url;
1483		ifrID.style.display = 'block';
1484
1485		setModalClass(className == null ? 'notifyMe' : className, behaviorID);
1486		setModalTitle(modalTitle, behaviorID);
1487
1488		behaviorID.show();
1489	}
1490}
1491
1492//Closes the notify popup modal.
1493function closeNotifyPopup(needsConfirm) {
1494	if (needsConfirm) {
1495		if (!confirm("You will discard any unsaved changes. Do you want to proceed?"))
1496			return;
1497	}
1498	window.parent.closeModalDialog('editItemBehavior');
1499	return false;
1500}
1501
1502/*********************************************************
1503* STOP - NEW METHODS INTRODUCED FOR POTENTIALLY COMMONIZING THE NOTIFY POPUP CODE. SUBJECT TO CHANGE
1504**********************************************************/
1505
1506function itemList() {
1507	var frm = document.aspnetForm;
1508	frm.strPage.value = '';
1509	frm.fromViewOptions.value = 1;
1510	frm.submit();
1511}
1512
1513function categoryList() {
1514	var frm = document.aspnetForm;
1515	frm.strPage.value = '';
1516	frm.fromViewOptions.value = 1;
1517	frm.submit();
1518}
1519
1520function displayActions(control) {
1521	var printActions = document.getElementById('printActions');
1522	var bulkActions = document.getElementById('bulkActions');
1523	var exportActions = document.getElementById('export');
1524	var exportPdfActions = document.getElementById('exportPdf');
1525	var exportAttachmentsActions = document.getElementById('exportAttachments');
1526	var viewOptions = document.getElementById('viewOptions');
1527	
1528	var li_printActions = document.getElementById('li_printActions');
1529	var li_bulkActions = document.getElementById('li_bulkActions');
1530	var li_exportActions = document.getElementById('li_export');
1531	var li_exportPdfActions = document.getElementById('li_exportPdf');
1532	var li_exportAttachmentsActions = document.getElementById('li_exportAttachments');
1533	var li_viewOptions = document.getElementById('li_viewOptions');
1534
1535	var span_printactions = document.getElementById('span_printactions');
1536	var span_viewoptions = document.getElementById('span_viewoptions');
1537	var span_bulkactions = document.getElementById('span_bulkactions');
1538	var span_export = document.getElementById('span_export');
1539	var span_exportPdf = document.getElementById('span_exportPdf');
1540	var span_exportAttachments = document.getElementById('span_exportAttachments');
1541
1542	var viewOptionsAlert = document.getElementById('viewOptionsAlert');
1543	var searchBar = document.getElementById('searchBar');
1544
1545	var arrClosedArrows = [span_printactions, span_viewoptions, span_bulkactions, span_export, span_exportPdf, span_exportAttachments];
1546	var arrRemoveClass = [li_viewOptions, li_exportActions, li_bulkActions, li_printActions, li_exportPdfActions, li_exportAttachmentsActions];
1547	var arrDisplayNone = [viewOptions, exportActions, bulkActions, printActions, viewOptionsAlert, searchBar, exportPdfActions, exportAttachmentsActions];
1548	var doNotCloseArrow = -1, doNotRemoveClass = -1, doNotDisplayNone = -1;doNotDisplayNone2 = -1;
1549
1550	// Toggle display/arrow/class based on active tab.
1551	// NOTE: control == 9 is reserved for close, do not use it.
1552	if (control == 0 && li_bulkActions.className != 'active') {
1553		doNotCloseArrow = span_bulkactions;
1554		doNotRemoveClass = li_bulkActions;
1555		doNotDisplayNone = bulkActions;
1556	}
1557	else if (control == 1 && li_viewOptions.className != 'active') {
1558		doNotCloseArrow = span_viewoptions;
1559		doNotRemoveClass = li_viewOptions;
1560		doNotDisplayNone = viewOptions;
1561		doNotDisplayNone2 = viewOptionsAlert;
1562		if (viewOptionsAlert && GetCookie('wrenchDisplayedOnce') != '1') { // wrench Has to be displayed only once when the user goes there for the first time.  - AK 
1563			viewOptionsAlert.style.display = 'block';
1564			document.cookie = "wrenchDisplayedOnce=1;expires=12/31/2999 23:59:59";
1565		}
1566	}
1567	else if (control == 2 && li_exportActions.className != 'active') {
1568		doNotCloseArrow = span_export;
1569		doNotRemoveClass = li_exportActions;
1570		doNotDisplayNone = exportActions;
1571	}
1572	else if (control == 3 && li_printActions.className != 'active') {
1573		doNotCloseArrow = span_printactions;
1574		doNotRemoveClass = li_printActions;
1575		doNotDisplayNone = printActions;
1576	}
1577	else if (control == 4 && li_exportPdfActions.className != 'active') {
1578		doNotCloseArrow = span_exportPdf;
1579		doNotRemoveClass = li_exportPdfActions;
1580		doNotDisplayNone = exportPdfActions;
1581	}
1582	else if (control == 5 && li_exportAttachmentsActions.className != 'active') {
1583		doNotCloseArrow = span_exportAttachments;
1584		doNotRemoveClass = li_exportAttachmentsActions;
1585		doNotDisplayNone = exportAttachmentsActions;
1586	}
1587	else {
1588		if (searchBar) {
1589			searchBar.style.display = '';
1590
1591			arrDisplayNone.splice(
1592				arrDisplayNone.indexOf(searchBar), 1);
1593		}
1594	}
1595
1596	if (doNotDisplayNone != -1)
1597		doNotDisplayNone.style.display = 'block';
1598
1599	if (doNotRemoveClass)
1600		doNotRemoveClass.className = 'active';
1601
1602	if (doNotCloseArrow)
1603		doNotCloseArrow.innerHTML = '&#9650;';
1604
1605	// Hide elements in arrDisplayNone array.
1606	for (var i = 0, len = arrDisplayNone.length; i < len; i++) {
1607		if (arrDisplayNone[i] && arrDisplayNone[i] != doNotDisplayNone && arrDisplayNone[i] != doNotDisplayNone2 && arrDisplayNone[i].style)
1608			arrDisplayNone[i].style.display = 'none';
1609	}
1610
1611	// Remove class name from classes in arrRemoveClass array.
1612	for (var i = 0, len = arrRemoveClass.length; i < len; i++) {
1613		if (arrRemoveClass[i] && arrRemoveClass[i] != doNotRemoveClass)
1614			arrRemoveClass[i].className = '';
1615	}
1616
1617	// Use closed arrays for elements in arrClosedArrows array.
1618	for (var i = 0, len = arrClosedArrows.length; i < len; i++) {
1619		if (arrClosedArrows[i] && arrClosedArrows[i] != doNotCloseArrow)
1620			arrClosedArrows[i].innerHTML = '&#9660;';
1621	}
1622}
1623
1624///Gets the value of the specified cookie.
1625function GetCookie(name) {
1626	var arg = name + "=";
1627	var argLen = arg.length;
1628	var cookielen = document.cookie.length;
1629	var i = 0;
1630	while (i < cookielen) {
1631		var j = i + argLen;
1632		if (document.cookie.substring(i, j) == arg) {
1633			var endstr = document.cookie.indexOf(";", j);
1634			if (endstr == -1) { endstr = cookielen; }
1635			return unescape(document.cookie.substring(j, endstr));
1636		}
1637		i = document.cookie.indexOf(" ", i) + 1;
1638		if (i == 0) break;
1639	}
1640	return null;
1641}
1642
1643function moreActions(id, event) {
1644	openPopUp(id, event);
1645}
1646
1647function openPopUp(id, event) {
1648	var $popUp = $('#' + id);
1649	if ($popUp.hasClass('popped')) {
1650		//do not do anything if popup is already open.
1651		return false;
1652	}
1653
1654	//Hide all popups already open if nesessary.
1655	$('.popUp').fadeOut(200).removeClass('popped');
1656	$('.popUpParent').removeClass('popped');
1657
1658	//Open popup
1659	$popUp.fadeIn(200);
1660	$popUp.addClass('popped');
1661	$popUp.parents('.popUpParent').addClass('popped');
1662
1663	//prevent triggering any other event.
1664	if (window.event)
1665		window.event.cancelBubble = true;
1666	else
1667		event.stopPropagation();
1668}
1669
1670function cancelModal(needsConfirm) {
1671	if (needsConfirm) {
1672		if (!confirm("You will discard any unsaved changes. Do you want to proceed?"))
1673			return;
1674	}
1675	window.parent.closeModalDialog('editItemBehavior');
1676	return false;
1677}
1678
1679//Allows login to CPC
1680function adminGetHelp(helpUrl, newWindow) {
1681	if (helpUrl === "/")
1682		helpUrl = "https://www.civicengagecentral.civicplus.help/hc/en-us" + helpUrl;
1683	window.open(helpUrl, 'CPwindow');
1684	}
1685
1686//Validates the integer fields.
1687function isInteger(numToValidate) {
1688	return (numToValidate.toString().search(/^-?[0-9]+$/) == 0);
1689}
1690
1691function isIntegerAllowBlank(numToValidate) {
1692	if (numToValidate == '') 
1693		return true;
1694	return (numToValidate.toString().search(/^-?[0-9]+$/) == 0);
1695}
1696
1697//Validates the time format to make sure time is entered in AM/PM format.
1698function timeFormatValidate(id) {
1699	if ($('#' + id).length > 0) {
1700		var startTime = $('#' + id).val().toUpperCase().trim();
1701		if (startTime != '') {
1702			var startTimeAMPM = '';
1703			if (startTime.indexOf('AM') != -1) {
1704				startTimeAMPM = 'AM';
1705				startTime = startTime.substring(0, startTime.indexOf('AM')).replace(" ", "");
1706			}
1707			else if (startTime.indexOf('PM') != -1) {
1708				startTimeAMPM = 'PM';
1709				startTime = startTime.substring(0, startTime.indexOf('PM')).replace(" ", "");
1710			}
1711			var objDate = new dateValidator();
1712			if (!objDate.timeValidate(startTime, true, "Start time")) {
1713				if (objDate.error) alert(objDate.error);
1714				else alert("unknown error");
1715				return false;
1716			}
1717			else {
1718				$('#' + id).val(startTime + " " + startTimeAMPM.toLowerCase())
1719			}
1720		}
1721	}
1722	if ($('#' + id).val() != '') {
1723		if ($('#' + id).val().toUpperCase().trim().indexOf(' AM') == -1 && $('#' + id).val().toUpperCase().trim().indexOf(' PM') == -1) {
1724			alert('Time has to be entered in AM/PM format.\nEnter time like example of 8:00 AM.');
1725			return false;
1726		}		
1727	}
1728	return true;
1729}
1730
1731function htmlEncode(value) {
1732	return String(value)
1733            .replace(/&/g, '&amp;')
1734            .replace(/"/g, '&quot;')
1735            .replace(/'/g, '&#39;')
1736            .replace(/</g, '&lt;')
1737            .replace(/>/g, '&gt;');
1738}
1739
1740function OnRadEditorClientSelectionChange(editor) {
1741         replaceBoldItalicUnderlineStrikeTags(editor);
1742}
1743
1744function replaceBoldItalicUnderlineStrikeTags(editor) {
1745    var element = document.all ? editor.get_document().body : editor.get_document();
1746    var $element = $(element);
1747    replaceTag($element, 'b', 'strong');
1748    replaceTag($element, 'i', 'em');   
1749    var element = document.all ? editor.get_document().body : editor.get_document();
1750    var $element = $(element);
1751    replaceTag($element, 'strike', 's');
1752    $element.find("u").each(function () {
1753            var $el = $(this);
1754            var text = $el.html();        
1755            $el.replaceWith('<span style="text-decoration: underline">
1755' + text + '</span>');        
1756        }); 
1757}
1758
1759// Protects against JavaScript injection when a JavaScript string is written into a JavaScript statement for evaluation.
1760function jsEvalValueSanitizer(normalString) {
1761	return normalString.replace(/\\/g, "\\\\")
1762		.replace(/'/g, "\\'")
1763		.replace(/"/g, "\\x22")
1764		.replace(/\r/g, "\\r")
1765		.replace(/\n/g, "\\n");
1766}
1767;
1768$(document).ready(function () {
1769	// Minimum characters required for search
1770	var minPrefixLength = 3;
1771	// Debounce delay (ms)
1772	var searchDebounceDelay = 500;
1773
1774
1775	// Hiding search menu
1776	$('.searchCategory').hide();
1777
1778	// Opening/closing menus when clicked
1779	$('.searchDropdown > a').click(function (e) {
1780		e.preventDefault();
1781
1782		var $toggle = $(this).parent(),
1783			target = $(this).attr('href'),
1784			$menu = $(target);
1785
1786		if ($toggle.hasClass('open')) {
1787			$menu.fadeOut(100);
1788		} else {
1789			$('.showing').removeClass('showing').fadeOut(100);
1790			$('.open').removeClass('open');
1791			$menu.fadeIn(100).addClass('showing');
1792		}
1793		$toggle.toggleClass('open');
1794	});
1795	var divSearchStandard = $('#divSearchStandard');
1796	var divSearchAdvanced = $('#divSearchAdvanced');
1797
1798	var txtSearchNot = $('#txtSearchNot');
1799	var txtSearchAnd = $('#txtSearchAnd');
1800	var txtSearchPhrase = $('#txtSearchPhrase');
1801	var txtSearchOr = $('#txtSearchOr');
1802	var txtSearchString = $('#txtSearchString');
1803
1804	$('#searchPhrase').keypress(function (e) {
1805		if (e.which == 13 || e.keyCode == 13) {
1806			e.cancelBubble = true;
1807			e.returnValue = false;
1808			// enforce minimum prefix length
1809			var term = ($('#searchPhrase').val() || "").trim();
1810			if (term.length < minPrefixLength) {
1811				$('#searchPhrase').focus();
1812				return false;
1813			}
1814			LoadSearchKeyResult()
1815		}
1816	});
1817
1818	$(".searchSite").click(function () {
1819		// enforce minimum prefix length
1820		var term = ($('#searchPhrase').val() || "").trim();
1821		if (term.length < minPrefixLength) {
1822			$('#searchPhrase').focus();
1823			return;
1824		}
1825		LoadSearchKeyResult()
1826	});
1827	
1828	function getQs() {
1829		var deptId = $("#selectedDepartmentHeader").val();
1830		var qs = deptId ? ('?departmentId=' + deptId) : '';
1831		return qs;
1832	}
1833
1834	if ($('#UseAutoComplete').length > 0 && $('#UseAutoComplete')[0].value.toLowerCase() === "true") {
1835		var autoCompleteCache = {};
1836		var autoCompleteCacheKeys = [];
1837		var autoCompleteCacheLimit = 25;
1838		var currentRequest = null;
1839		var currentRequestKey = null;
1840		var autoCompleteDebounceTimer = null;
1841		var autoCompleteDebounceKey = null;
1842		var pendingAutoCompleteResponses = [];
1843
1844		function normalizeAutoCompleteTerm(term) {
1845			return $.trim((term || "") + "").replace(/\s+/g, " ");
1846		}
1847
1848		function getAutoCompleteCacheKey(requestUrl, term) {
1849			return requestUrl + "|" + term.toLowerCase();
1850		}
1851
1852		function cacheAutoCompleteResult(cacheKey, data) {
1853			if (!Object.prototype.hasOwnProperty.call(autoCompleteCache, cacheKey)) {
1854				autoCompleteCacheKeys.push(cacheKey);
1855				if (autoCompleteCacheKeys.length > autoCompleteCacheLimit) {
1856					delete autoCompleteCache[autoCompleteCacheKeys.shift()];
1857				}
1858			}
1859			autoCompleteCache[cacheKey] = data;
1860		}
1861
1862		function respondToPendingAutoComplete(data) {
1863			var responses = pendingAutoCompleteResponses;
1864			pendingAutoCompleteResponses = [];
1865			for (var i = 0; i < responses.length; i++) {
1866				responses[i](data);
1867			}
1868		}
1869
1870		function cancelPendingAutoComplete() {
1871			clearTimeout(autoCompleteDebounceTimer);
1872			autoCompleteDebounceKey = null;
1873			if (currentRequest != null) {
1874				currentRequest.abort();
1875				currentRequest = null;
1876			}
1877			currentRequestKey = null;
1878			respondToPendingAutoComplete([]);
1879		}
1880
1881		var $searchPhase = $('#searchPhrase').autocomplete({
1882			minLength: minPrefixLength,
1883			source: function (request, response) {
1884				// enforce minimum prefix length before calling server
1885				var term = normalizeAutoCompleteTerm(request.term);
1886				if (term.length < minPrefixLength) {
1887					response([]);
1888					return;
1889				}
1890
1891				var requestUrl = '/Search/AutoComplete' + getQs();
1892				var cacheKey = getAutoCompleteCacheKey(requestUrl, term);
1893				if (Object.prototype.hasOwnProperty.call(autoCompleteCache, cacheKey)) {
1894					response(autoCompleteCache[cacheKey]);
1895					$('.autoCompleteError').remove();
1896					return;
1897				}
1898
1899				if (currentRequestKey === cacheKey || autoCompleteDebounceKey === cacheKey) {
1900					pendingAutoCompleteResponses.push(response);
1901					return;
1902				}
1903
1904				cancelPendingAutoComplete();
1905				autoCompleteDebounceKey = cacheKey;
1906				pendingAutoCompleteResponses.push(response);
1907				autoCompleteDebounceTimer = setTimeout(function () {
1908					autoCompleteDebounceKey = null;
1909					currentRequestKey = cacheKey;
1910					currentRequest = $.ajax({
1911						url: requestUrl,
1912						dataType: "json",
1913						timeout: 10000,
1914						data:
1915							{
1916								term: term,
1917							},
1918						success: function (data) {
1919							if (currentRequestKey === cacheKey) {
1920								cacheAutoCompleteResult(cacheKey, data);
1921								respondToPendingAutoComplete(data);
1922								$('.autoCompleteError').remove();
1923							}
1924						},
1925						error: function (xmlhttprequest, textstatus, message) {
1926							if (textstatus === "abort") {
1927								return;
1928							}
1929
1930							if (textstatus === "timeout") {
1931								if ($("#searchPhrase").siblings('.autoCompleteError').length === 0)
1932									$('<span class="autoCompleteError"><p class="alert error">Search autocomplete is currently not responding. Please try again later.</p></span>').insertAfter($('#searchPhrase'));
1933								console.log('hit');
1934								$('#searchTabs').css('padding-top', '2em');
1935							}
1936							else {
1937								$('#searchTabs').css('padding-top', '');
1938							}
1939
1940							respondToPendingAutoComplete([]);
1941						},
1942						complete: function (xmlhttprequest) {
1943							if (currentRequest === xmlhttprequest) {
1944								currentRequest = null;
1945								currentRequestKey = null;
1946							}
1947						}
1948					});
1949				}, searchDebounceDelay);
1950			},
1951			html: true,
1952			delay: 0,
1953			select: function (event, ui) {
1954				$(this).val(ui.item.value);
1955				$(this).next().click();
1956			}
1957		});
1958		$searchPhase.data("ui-autocomplete")._renderItem = function (ul, item) {
1959			return $("<li class=\"itemList\"></li>")
1960				.data("ui-autocomplete-item", item)
1961				.append("<a>" + item.label + "</a>")
1962				.appendTo(ul);
1963		};
1964	}
1965
1966	$('.advSearchBox').change(function () {
1967		$('.cp-search-input').val(makeAdvancedSearchString());
1968	});
1969	$('#SearchContentType').change(function () {
1970		$('.cp-search-input').val(makeAdvancedSearchString());
1971	});
1972	$('#selectedDepartmentHeader').change(function () {
1973		$('.cp-search-input').val(makeAdvancedSearchString());
1974	});
1975
1976	// Load search results only after page is loaded
1977	LoadSearchKeyResult();
1978});
1979
1980function toggleSearch() {
1981	if (divSearchStandard.style.display == "block") {
1982		divSearchStandard.style.display = "none";
1983		divSearchAdvanced.style.display = "block";
1984	}
1985	else {
1986		divSearchStandard.style.display = "block";
1987		divSearchAdvanced.style.display = "none";
1988	}
1989}
1990
1991function getSearchPhrase() {
1992	var searchPhrase = $('#searchPhrase').val();
1993	searchPhrase = searchPhrase.replace(/</g, '').replace(/>/g, '');
1994	searchPhrase = encodeURIComponent(searchPhrase);
1995	return searchPhrase;
1996}
1997
1998function validateSearchForm() {
1999	var doSubmit = true;
2000	var advancedSearchString = "";
2001	var txtSearchNot = $('#txtSearchNot').val() || "";
2002	var txtSearchAnd = $('#txtSearchAnd').val() || "";
2003	var txtSearchPhrase = $('#txtSearchPhrase').val() || "";
2004	var txtSearchOr = $('#txtSearchOr').val() || "";
2005	var txtSearchString = $('#txtSearchString') || "";
2006
2007	if (txtSearchNot != "") {
2008		if (txtSearchAnd == ""
2009			&& txtSearchPhrase == ""
2010			&& txtSearchOr == "") {
2011			doSubmit = false;
2012			alert('You cannot use the \'without the words\' option without specifying other search terms.');
2013		}
2014	}
2015
2016	if (doSubmit) {
2017		advancedSearchString = makeAdvancedSearchString();
2018		advancedSearchString = advancedSearchString.replace(/</g, '').replace(/>/g, '');
2019		advancedSearchString = encodeURIComponent(advancedSearchString);
2020		if ($('#paginationOption').val() == undefined) {
2021			$('.cp-search-input').val(makeAdvancedSearchString());
2022			GetSearchResults(advancedSearchString, 1, 10);
2023		}
2024		else {
2025			$('.cp-search-input').val(makeAdvancedSearchString());
2026			GetSearchResults(advancedSearchString, 1, $('#paginationOption').val());
2027		}
2028	}
2029}
2030
2031function LoadSearchKeyResult() {
2032	$('.ui-autocomplete-input').autocomplete("close");
2033	if ($('#cp-SearchTab-Clerk').length > 0 || $('#cp-MuniCode-Site').length > 0) {
2034		if ($('#cp-SearchTab-Site').hasClass('is-active')) {
2035			switchToSiteContentTab();
2036			loadSiteSearchResults();
2037		}
2038		if ($('#cp-SearchTab-Clerk').hasClass('is-active')) {
2039			$('input[Name="SearchCriteria"][value=Items]').prop('checked', true);
2040			loadCivicClerkIndexResults(0, 10);
2041		}
2042		if ($('#cp-MuniCode-Site').hasClass('is-active')) {
2043			$('input[Name="MuniCodeSearchCriteria"][value=CODES]').prop('checked', true);
2044			switchToMuniCodeSearchTab();
2045			loadMunicodeSearch(1, 10);
2046		}
2047	}
2048	else {
2049		loadSiteSearchResults();
2050	}
2051	return false;
2052}
2053
2054function loadSiteSearchResults() {
2055	if ($('#paginationOption').val() == undefined) {
2056		GetSearchResults(getSearchPhrase(), 1, 10);
2057	}
2058	else {
2059		GetSearchResults(getSearchPhrase(), 1, $('#paginationOption').val());
2060	}
2061}
2062
2063function makeAdvancedSearchString() {
2064	var optelectedDepartmentHeadSer = $('#selectedDepartmentHeader');
2065	var departmentPage = optelectedDepartmentHeadSer.val();
2066	var optSearchContentType = $('#SearchContentType');
2067	var contentType = optSearchContentType.val();
2068	var searchString = "";
2069	var txtSearchNot = $('#txtSearchNot').val() || "";
2070	var txtSearchAnd = $('#txtSearchAnd').val() || "";
2071	var txtSearchPhrase = $('#txtSearchPhrase').val() || "";
2072	var txtSearchOr = $('#txtSearchOr').val() || "";
2073	var trimmedAnd = TrimString(txtSearchAnd);
2074	var trimmedPhrase = TrimString(txtSearchPhrase);
2075	var trimmedOr = TrimString(txtSearchOr);
2076	var trimmedNot = TrimString(txtSearchNot);
2077
2078	if (trimmedAnd.length > 0) {
2079		var searchAndArray = trimmedAnd.split(/\s/);
2080		if (TrimString(searchString).length > 0) {
2081			searchString += " AND ";
2082		}
2083		for (var i = 0; i < searchAndArray.length; i++) {
2084			searchString += TrimString(searchAndArray[i]);
2085			if (i != searchAndArray.length - 1) {
2086				searchString += " AND ";
2087			}
2088		}
2089	}
2090
2091	if (contentType != 'all') {
2092		if (searchString.length != 0) {
2093			searchString += " AND content:" + contentType;
2094		}
2095		else {
2096			searchString += "content:" + contentType;
2097		}
2098	}
2099	if (departmentPage != undefined) {
2100		$('#departmentId').val(departmentPage);
2101	}
2102	if (trimmedPhrase.length > 0) {
2103		if (TrimString(searchString).length > 0) {
2104			searchString += " AND ";
2105		}
2106		searchString += '"' + trimmedPhrase + '"';
2107	}
2108	if (trimmedOr.length > 0) {
2109		var searchOrArray = trimmedOr.split(/\s/);
2110		if (TrimString(searchString).length > 0) {
2111			searchString += " AND ";
2112		}
2113		if (searchOrArray.length > 1) {
2114			searchString += "(";
2115		}
2116
2117		for (var i = 0; i < searchOrArray.length; i++) {
2118			searchString += TrimString(searchOrArray[i]);
2119			if (i != searchOrArray.length - 1) {
2120				searchString += " OR ";
2121			}
2122		}
2123		if (searchOrArray.length > 1) {
2124			searchString += ")";
2125		}
2126	}
2127	if (trimmedNot.length > 0) {
2128		var searchNotArray = trimmedNot.split(/\s/);
2129		for (var i = 0; i < searchNotArray.length; i++) {
2130			searchString += " -" + TrimString(searchNotArray[i]);
2131		}
2132	}
2133	return searchString;
2134}
2135
2136function validateSearchFormStandard() {
2137	var submitForm = document.frmStandardSearch;
2138
2139	if (TrimString(txtSearchString.value).length == 0)
2140		alert('You must enter a search term');
2141	else {
2142		submitForm.SearchString.value = txtSearchString.value;
2143		submitForm.submit();
2144	}
2145}
2146
2147function handleEnter2(evt) {
2148	if (window.clipboardData) { // internet explorer
2149		if (evt.keyCode == 13) { // return key
2150			validateSearchFormStandard();
2151			return false;
2152		}
2153	}
2154	else {
2155		if (evt.which == 13) { // return key
2156			validateSearchFormStandard();
2157			return false;
2158		}
2159	}
2160	return true;
2161}
2162
2163function handleEnter(evt) {
2164	if (window.clipboardData) { // internet explorer
2165		if (evt.keyCode == 13) { // return key
2166			validateSearchForm();
2167			return false;
2168		}
2169	}
2170	else {
2171		if (evt.which == 13) { // return key
2172			validateSearchForm();
2173			return false;
2174		}
2175	}
2176	return true;
2177}
2178
2179function GetSearchResults(phrase, page, noOfItemsPerPage) {
2180	var url = '/Search/Results?searchPhrase=' + phrase + '&pageNumber=' + page + '&perPage=' + noOfItemsPerPage;
2181	if ($('#departmentId').val() !== "") {
2182		url += '&departmentId=' + $('#departmentId').val();
2183	}
2184	AJAX(url, 'GET', {}, function (response) {
2185		$('#divSearchResults').html(response);
2186		if (history.pushState) {
2187			var newurl = window.location.pathname
2188				+ '?searchPhrase=' + phrase + '&pageNumber=' + page + '&perPage=' + noOfItemsPerPage;
2189			if ($('#departmentId').val() !== "") {
2190				newurl += '&departmentId=' + $('#departmentId').val();
2191			}
2192			window.history.pushState({ path: newurl }, '', newurl);
2193			var trackerName = typeof ga === "function" && ga.getAll()[0].get('name');
2194			trackerName && ga(trackerName + '.send', 'pageview', newurl);
2195		}
2196		getSearchResultFocus();
2197	});
2198}
2199
2200function getSearchResultFocus() {
2201	//To focus on result Tab
2202	var elmnt = document.getElementById("breadCrumbs");
2203	elmnt.scrollIntoView(true);
2204}
2205
2206
2207//**********PAGINATION FUNCTIONS FOR SEARCH RESULTS FRONT END****************//
2208function changePage(paginationControl, page) {
2209	loadSearchResultPageList(page, $('#paginationOption').val());
2210}
2211
2212function loadSearchResultPageList(page, noOfItemsPerPage) {
2213	GetSearchResults(getSearchPhrase(), page, noOfItemsPerPage);
2214}
2215
2216//**********Functions for displaying CivicClerk Search results with site search****************//
2217function changePageAgenda(paginationControl, page) {
2218	loadCivicClerkIndexResults(page - 1, $('select#' + paginationControl).val());
2219}
2220
2221function loadCivicClerkIndexResults(page, noOfItemsPerPage) {
2222	var indexIdentifier = $('input[Name="SearchCriteria"]:checked').val();
2223	$('#advancedSearch').hide();
2224	GetCivicClerkSearchResults(getSearchPhrase(), page, noOfItemsPerPage, indexIdentifier);
2225}
2226
2227function GetCivicClerkSearchResults(phrase, page, noOfItemsPerPage, indexIdentifier) {
2228	var url = '/Search/CivicClerk/';
2229	var queryString = '?keyword=' + phrase + '&page=' + page + '&resultsperpage=' + noOfItemsPerPage;
2230	switch (indexIdentifier) {
2231		case 'Agendas':
2232			url +='agendas';
2233			break;
2234		case 'Attachments':
2235			url +='attachments';
2236			break;
2237		case 'Minutes':
2238			url +='agendafiles';
2239			break;
2240		default:
2241			url +='agendaItems';
2242			break;
2243	}
2244	url += queryString;
2245
2246	AJAX(url, 'GET', {}, function (response) {
2247		hideMainSearch();
2248		hideAdvancedSearch();
2249		showCivicClerkSearch();
2250		hideMunicodeSearch();
2251		$('#divSearchResultsCivicClerk').html(response);
2252		getSearchResultFocus();
2253	});
2254}
2255
2256function loadTabResults($target) {
2257	const targetId = $target.attr('id');
2258
2259	if (targetId === 'siteSearch') {
2260		switchToSiteContentTab();
2261		$('#divMuniCodeSearch').hide();
2262		loadSearchResultPageList(1, 10);
2263		return;
2264	}
2265
2266	if (targetId === 'MuniCodeSearch') {
2267		$('input[Name="MuniCodeSearchCriteria"][value=CODES]').prop('checked', true);
2268		switchToMuniCodeSearchTab();
2269		loadMunicodeSearch(1, 10);
2270		return;
2271	}
2272
2273	if (targetId === "ArchiveSocialSearch") {
2274		$target.trigger("click");
2275		return;
2276	}
2277
2278	if (targetId === "NextRequestSearch") {
2279		$target.trigger("click");
2280		return;
2281	}
2282
2283	//Back to default
2284	$('input[Name="SearchCriteria"][value=Items]').prop('checked', true);
2285	loadCivicClerkIndexResults(0, 10);
2286}
2287
2288function switchToSiteContentTab() {
2289	hideAdvancedSearch();
2290	hideCivicClerkSearch();
2291	hideMunicodeSearch();
2292	showMainSearch();
2293}
2294
2295//**********Functions for displaying Municipal Code Search results with site search****************//
2296
2297function changePageMuniCode(paginationControl, page) {
2298	loadMunicodeSearch(page, $('select#' + paginationControl).val());
2299}
2300
2301function switchToMuniCodeSearchTab() {
2302	hideMainSearch();
2303	hideAdvancedSearch();
2304	hideCivicClerkSearch();
2305	showMunicodeSearch();
2306}
2307
2308function loadMunicodeSearch(pageNum, pageSize) {
2309	$('#advancedSearch').hide();
2310	var contentTypeId = $('input[Name="MuniCodeSearchCriteria"]:checked').val();
2311	GetMuniCodeSearchResults(getSearchPhrase(), contentTypeId, pageNum, pageSize);
2312}
2313
2314function GetMuniCodeSearchResults(phrase, contentTypeId, pageNum, pageSize) {
2315	var url = '/Search/MuniCode/' + contentTypeId;
2316	var queryString = '?keyword=' + phrase + '&pageNum=' + pageNum + '&pageSize=' + pageSize;
2317	url += queryString;
2318
2319	AJAX(url, 'GET', {}, function (response) {
2320		switchToMuniCodeSearchTab();
2321		$('#divSearchResultsMuniCode').html(response);
2322		getSearchResultFocus();
2323	});
2324}
2325
2326function showMainSearch() {
2327	$('#siteSearch').parent('li').addClass('is-active');
2328	$('#advancedSearch').show();
2329	$('#divSearchResults').show();
2330	$('#cp-SearchTab-Site').attr('aria-selected', 'true');
2331}
2332
2333function hideMainSearch() {
2334	$('#siteSearch').parent('li').removeClass('is-active');
2335	$('#advancedSearch').hide();
2336	$('#divSearchResults').hide();
2337	$('#cp-SearchTab-Site').attr('aria-selected', 'false');
2338}
2339
2340function hideAdvancedSearch() {
2341	$('#advSearchForm').addClass('cp-search-advanced--hidden');
2342	$('#standardSearch').hide();
2343}
2344
2345function showCivicClerkSearch() {
2346	$('#siteSearchCivicClerk').parent('li').addClass('is-active');
2347	$('#divClerkIndexStrip').show();
2348	$('#divSearchResultsCivicClerk').show();
2349	$('#cp-SearchTab-Clerk').attr('aria-selected', 'true');
2350}
2351
2352function hideCivicClerkSearch() {
2353	$('#siteSearchCivicClerk').parent('li').removeClass('is-active');
2354	$('#divClerkIndexStrip').hide();
2355	$('#divSearchResultsCivicClerk').hide();
2356	$('#cp-SearchTab-Clerk').attr('aria-selected', 'false');
2357}
2358
2359function showMunicodeSearch() {
2360	$('#divMunicodeStrip').show();
2361	$('#MuniCodeSearch').parent('li').addClass('is-active');
2362	$('#divMuniCodeSearch').show();
2363	$('#divSearchResultsMuniCode').show();
2364	$('#cp-MuniCode-Site').attr('aria-selected', 'true');
2365}
2366
2367function hideMunicodeSearch() {
2368	$('#divMunicodeStrip').hide();
2369	$('#divMuniCodeSearch').hide();
2370	$('#divSearchResultsMuniCode').hide();
2371	$('#MuniCodeSearch').parent('li').removeClass('is-active');
2372	$('#cp-MuniCode-Site').attr('aria-selected', 'false');
2373}
2374;
2375

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.