Cleanup Templates
jdarwood007

jdarwood007 commited on 2018-08-11 14:39:49
Showing 26 changed files, with 1198 additions and 1053 deletions.


Optimized templates and Javascript handling
Convert most hard coded Javascript into prototypes and make use of JQuery
Removed Collapsing quick reply as its not always on in SMF and no settings exists
Removed hard coded styles as appropriate.
... ...
@@ -7,15 +7,6 @@
7 7
 }
8 8
 
9 9
 /* SimpleDesk icons */
10
-.shd_smallicon {
11
-	width: 16px;
12
-	height: 20px;
13
-	margin-right: 4px;
14
-}
15
-.shd_icon_minihead {
16
-	position: relative;
17
-	top: 3px;
18
-}
19 10
 .shd_icon {
20 11
 	position: relative;
21 12
 	top: 3px;
... ...
@@ -204,9 +195,6 @@ form#postmodify .shd_ticket_roundframe {
204 195
 	position: relative;
205 196
 	left: 4px;
206 197
 }
207
-#shd_custom_fields_swap {
208
-	margin-top: 8px;
209
-}
210 198
 .shd_customfields input[type="text"]
211 199
 {
212 200
 	width: 85%;
... ...
@@ -253,8 +241,6 @@ form#postmodify .shd_ticket_roundframe {
253 241
 }
254 242
 /* Go advanced! */
255 243
 .shd_advancedbutton {
256
-	margin-top: 10px;
257
-	height: 15px;
258 244
 	background: url(../images/simpledesk/advanced.png) no-repeat left;
259 245
 	background-position: 10px;
260 246
 	padding: 10px;
... ...
@@ -263,6 +249,8 @@ form#postmodify .shd_ticket_roundframe {
263 249
 	font-weight: bold;
264 250
 	font-size: 100%;
265 251
 	margin-right: 10px;
252
+	border-top: 1px solid #ddd;
253
+	border-radius: 7px;
266 254
 }
267 255
 
268 256
 /* Edit settings*/
... ...
@@ -337,6 +325,10 @@ form#postmodify .shd_ticket_roundframe {
337 325
 	margin-right: 5%;
338 326
 	float: left;
339 327
 }
328
+dl.settings dt.shd_cust_fields_largetext, .shd_cust_fields_largetext textarea {
329
+	width: 100%;
330
+}
331
+
340 332
 
341 333
 /**********************************
342 334
 * Attachment stuff				  *
... ...
@@ -412,6 +404,9 @@ form#postmodify .shd_ticket_roundframe {
412 404
 #canned_replies {
413 405
 	margin-top: 1em;
414 406
 }
407
+#canned_replies #canned_title {
408
+	font-weight:bold;
409
+}
415 410
 
416 411
 /**********************************
417 412
 * General actions				 *
... ...
@@ -42,7 +42,7 @@
42 42
 
43 43
 }
44 44
 .shd_former_contributor {
45
-	color: #696969;
45
+	color: #6969E7;
46 46
 }
47 47
 .shd_bbc_list {
48 48
 	width: 33%;
... ...
@@ -8,7 +8,6 @@ function shd_getJSONDocument(sUrl, funcCallback, sMethod)
8 8
 	if (typeof(sMethod) == 'undefined')
9 9
 		sMethod = 'GET';
10 10
 
11
-	var oCaller = this;
12 11
 	var oMyDoc = $.ajax({
13 12
 		method: sMethod,
14 13
 		url: sUrl,
... ...
@@ -19,7 +18,7 @@ function shd_getJSONDocument(sUrl, funcCallback, sMethod)
19 18
 			{
20 19
 				ajax_indicator(false);
21 20
 
22
-				funcCallback.call(oCaller, responseJSON);
21
+				funcCallback.call(this, responseJSON);
23 22
 			}
24 23
 		},
25 24
 	});
... ...
@@ -35,23 +34,19 @@ function shd_sendJSONDocument(sUrl, funcCallback)
35 34
 /* The privacy toggle in AJAX */
36 35
 function shd_privacyControl(oOpts)
37 36
 {
38
-	shd_privacyControl.prototype.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
39
-	if (window.addEventListener)
40
-		window.addEventListener('load', shd_privacyControl.prototype.init, false);
41
-	else if (window.attachEvent)
42
-		window.attachEvent('onload', shd_privacyControl.prototype.init);
37
+	this.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
38
+	$(document).ready(this.init.bind(this));
43 39
 }
44 40
 
45 41
 shd_privacyControl.prototype.init = function ()
46 42
 {
47
-	var oDiv = document.getElementById(shd_privacyControl.prototype.opts.sSrcA);
48
-	if (oDiv !== null)
49
-		oDiv.onclick = shd_privacyControl.prototype.action;
43
+	$('#' + this.opts.sSrcA).on('click', this.action.bind(this));
50 44
 }
51 45
 
52
-shd_privacyControl.prototype.action = function ()
46
+shd_privacyControl.prototype.action = function (e)
53 47
 {
54
-	shd_getJSONDocument(shd_privacyControl.prototype.opts.sUrl + ';' + shd_privacyControl.prototype.opts.sSession, shd_privacyControl.prototype.callback);
48
+	e.preventDefault();
49
+	shd_getJSONDocument(this.opts.sUrl + ';' + this.opts.sSession, this.callback.bind(this));
55 50
 	return false;
56 51
 }
57 52
 
... ...
@@ -60,13 +55,10 @@ shd_privacyControl.prototype.callback = function (oRecvd)
60 55
 	if (oRecvd && oRecvd.success === false)
61 56
 		alert(oRecvd.error);
62 57
 	else if (oRecvd && oRecvd.message)
63
-	{
64
-		var oSpan = document.getElementById(shd_privacyControl.prototype.opts.sDestSpan);
65
-		oSpan.firstChild.nodeValue = oRecvd.message;
66
-	}
58
+		$('#' + this.opts.sDestSpan).html(oRecvd.message);
67 59
 	else
68 60
 		if (confirm(shd_ajax_problem))
69
-			window.location = smf_scripturl + '?action=helpdesk;sa=privacychange;ticket=' + shd_privacyControl.prototype.opts.ticket + ';' + shd_privacyControl.prototype.opts.sSession;
61
+			window.location = smf_scripturl + '?action=helpdesk;sa=privacychange;ticket=' + this.opts.ticket + ';' + this.opts.sSession;
70 62
 
71 63
 	return false;
72 64
 }
... ...
@@ -74,42 +66,41 @@ shd_privacyControl.prototype.callback = function (oRecvd)
74 66
 /* The urgency doodad */
75 67
 function shd_urgencyControl(oOpts)
76 68
 {
77
-	shd_urgencyControl.prototype.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
78
-	if (window.addEventListener)
79
-		window.addEventListener('load', shd_urgencyControl.prototype.init, false);
80
-	else if (window.attachEvent)
81
-		window.attachEvent('onload', shd_urgencyControl.prototype.init);
69
+	this.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
70
+	$(document).ready(this.init.bind(this));
82 71
 }
83 72
 
84 73
 shd_urgencyControl.prototype.init = function ()
85 74
 {
86
-	for (var i in shd_urgencyControl.prototype.opts.aButtonOps)
75
+	for (var i in this.opts.aButtonOps)
87 76
 	{
88
-		if (!shd_urgencyControl.prototype.opts.aButtonOps.hasOwnProperty(i))
77
+		if (!this.opts.aButtonOps.hasOwnProperty(i))
89 78
 			continue;
90 79
 
91
-		var oDiv = document.getElementById('urglink_' + shd_urgencyControl.prototype.opts.aButtonOps[i]);
80
+		var oDiv = $('#urglink_' + this.opts.aButtonOps[i]);
92 81
 		if (oDiv !== null && i == 'up')
93
-			oDiv.onclick = shd_urgencyControl.prototype.actionUp;
82
+			oDiv.on('click', this.actionUp.bind(this));
94 83
 		else if (oDiv !== null && i == 'down')
95
-			oDiv.onclick = shd_urgencyControl.prototype.actionDown; // I *did* try to make this a single parameterised function but it always fired when it wasn't supposed to
84
+			oDiv.on('click', this.actionDown.bind(this)); // I *did* try to make this a single parameterised function but it always fired when it wasn't supposed to
96 85
 	}
97 86
 }
98 87
 
99
-shd_urgencyControl.prototype.actionUp = function ()
88
+shd_urgencyControl.prototype.actionUp = function (e)
100 89
 {
101
-	return shd_urgencyControl.prototype.action('up');
90
+	e.preventDefault();
91
+	return this.action('up');
102 92
 }
103 93
 
104
-shd_urgencyControl.prototype.actionDown = function ()
94
+shd_urgencyControl.prototype.actionDown = function (e)
105 95
 {
106
-	return shd_urgencyControl.prototype.action('down');
96
+	e.preventDefault();
97
+	return this.action('down');
107 98
 }
108 99
 
109 100
 shd_urgencyControl.prototype.action = function (direction)
110 101
 {
111
-	shd_urgencyControl.prototype.opts.direction = direction;
112
-	shd_getJSONDocument(shd_urgencyControl.prototype.opts.sUrl + shd_urgencyControl.prototype.opts.aButtonOps[direction] + ';' + shd_urgencyControl.prototype.opts.sSession, shd_urgencyControl.prototype.callback);
102
+	this.direction = direction;
103
+	shd_getJSONDocument(this.opts.sUrl + this.opts.aButtonOps[direction] + ';' + this.opts.sSession, this.callback.bind(this));
113 104
 	return false;
114 105
 }
115 106
 
... ...
@@ -119,25 +110,24 @@ shd_urgencyControl.prototype.callback = function (oRecvd)
119 110
 		alert(oRecvd.error);
120 111
 	else if (oRecvd && oRecvd.message)
121 112
 	{
122
-		setInnerHTML(document.getElementById(shd_urgencyControl.prototype.opts.sDestSpan), oRecvd.message);
113
+		$('#' + this.opts.sDestSpan).html(oRecvd.message);
123 114
 
124
-		var btn_set = [ "increase", "decrease" ];
115
+		var btn_set = ['increase', 'decrease'];
125 116
 		for (var i in btn_set)
126 117
 		{
127 118
 			if (!btn_set.hasOwnProperty(i))
128 119
 				continue;
129 120
 
130 121
 			var oBtn = oRecvd[btn_set[i]];
131
-			var oSpan = document.getElementById('urgency_' + btn_set[i]);
132
-			setInnerHTML(oSpan, (oBtn ? oBtn : ''));
122
+			$('#urgency_' + btn_set[i]).html(oBtn ? oBtn : '');
133 123
 		}
134 124
 
135 125
 		// Attach JS events to new links
136
-		shd_urgencyControl.prototype.init();
126
+		this.init();
137 127
 	}
138 128
 	else
139 129
 		if (confirm(shd_ajax_problem))
140
-			window.location = smf_scripturl + '?action=helpdesk;sa=urgencychange;ticket=' + shd_urgencyControl.prototype.opts.ticket + ';change=' + shd_urgencyControl.prototype.opts.aButtonOps[shd_urgencyControl.prototype.opts.direction] + ';' + shd_urgencyControl.prototype.opts.sSession;
130
+			window.location = smf_scripturl + '?action=helpdesk;sa=urgencychange;ticket=' + this.opts.ticket + ';change=' + this.opts.aButtonOps[this.direction] + ';' + this.opts.sSession;
141 131
 
142 132
 	return false;
143 133
 }
... ...
@@ -275,26 +264,19 @@ shd_attach_select.prototype.checkActive = function()
275 264
 function QuickReply(oOptions)
276 265
 {
277 266
 	this.opt = oOptions;
278
-	this.bCollapsed = this.opt.bDefaultCollapsed;
267
+	$(this.opt.sRepliesSelector + ', ' + this.opt.sFirstPostSelector).on('click', this.quote.bind(this));
279 268
 }
280 269
 
281 270
 // When a user presses quote, put it in the quick reply box (if expanded).
282
-QuickReply.prototype.quote = function (iMessageId, sSessionId, sSessionVar)
271
+QuickReply.prototype.quote = function (e)
283 272
 {
284
-	if (this.bCollapsed)
285
-	{
286
-		window.location.href = smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=reply;quote=' + iMessageId + ';ticket=' + this.opt.iTicketId + '.' + this.opt.iStart + ';' + sSessionVar + '=' + sSessionId;
287
-		return false;
288
-	}
273
+	e.preventDefault();
274
+	iMessageId = e.currentTarget.dataset.id;
289 275
 
290
-	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=quote;quote=' + iMessageId + ';' + sSessionVar + '=' + sSessionId + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onQuoteReceived);
276
+	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=quote;quote=' + iMessageId + ';' + this.opt.sSession + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onQuoteReceived.bind(this));
291 277
 
292 278
 	// Move the view to the quick reply box.
293
-	if (navigator.appName == 'Microsoft Internet Explorer')
294
-		window.location.hash = this.opt.sJumpAnchor;
295
-	else
296
-		window.location.hash = '#' + this.opt.sJumpAnchor;
297
-
279
+	window.location.hash = navigator.appName == 'Microsoft Internet Explorer' ? this.opt.sJumpAnchor : '#' + this.opt.sJumpAnchor;
298 280
 	return false;
299 281
 }
300 282
 
... ...
@@ -305,30 +287,21 @@ QuickReply.prototype.onQuoteReceived = function (oRecvd)
305 287
 		oEditorHandle_shd_message.insertText(oRecvd.message, false, true);
306 288
 }
307 289
 
308
-// The function handling the swapping of the quick reply.
309
-QuickReply.prototype.swap = function ()
310
-{
311
-	document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
312
-	document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
313
-	document.getElementById(this.opt.sFooterId).style.display = this.bCollapsed ? '' : 'none';
314
-	document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
315
-
316
-	this.bCollapsed = !this.bCollapsed;
317
-}
318 290
 
319 291
 function CannedReply(oOptions)
320 292
 {
321 293
 	this.opt = oOptions;
322
-	document.getElementById("canned_replies").style.display = "";
294
+	$('#' + this.opt.sCannedRepliesContainerId).show();
295
+	$('#' + this.opt.sCannedRepliesContainerId + ' input.button').on('click', this.getReply.bind(this));
323 296
 }
324 297
 
325
-CannedReply.prototype.getReply = function ()
298
+CannedReply.prototype.getReply = function (e)
326 299
 {
327
-	var iReplyId = document.getElementById('canned_replies_select').value;
300
+	var iReplyId = $('#' + this.opt.sSelectContainerId).val();
328 301
 	if (!iReplyId || parseInt(iReplyId, 10) < 1)
329 302
 		return false;
330 303
 
331
-	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=canned;ticket=' + this.opt.iTicketId + ';reply=' + iReplyId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onReplyReceived);
304
+	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=canned;ticket=' + this.opt.iTicketId + ';reply=' + iReplyId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onReplyReceived.bind(this));
332 305
 
333 306
 	return false;
334 307
 }
... ...
@@ -347,51 +320,17 @@ function shd_quickTicketJump(id_ticket)
347 320
 	return false;
348 321
 }
349 322
 
350
-/* The action log in tickets - Not much. */
351
-
352
-function ActionLog(oOptions)
353
-{
354
-	this.opt = oOptions;
355
-	this.bCollapsed = false;
356
-	document.getElementById(this.opt.sImageId).style.display = '';
357
-	return false;
358
-}
359
-
360
-// The function handling the swapping of the ticket log.
361
-ActionLog.prototype.swap = function ()
362
-{
363
-	document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
364
-	document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
365
-	document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
366
-
367
-	this.bCollapsed = !this.bCollapsed;
368
-}
369
-
370
-function CustomFields(oOptions)
371
-{
372
-	this.opt = oOptions;
373
-	this.bCollapsed = false;
374
-}
375
-
376
-// Expand and collapse the additional information block
377
-CustomFields.prototype.infoswap = function ()
378
-{
379
-	document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
380
-	document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
381
-	document.getElementById(this.opt.sFooterId).style.display = this.bCollapsed ? '' : 'none';
382
-	document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
383
-
384
-	this.bCollapsed = !this.bCollapsed;
385
-}
386
-
387 323
 /* AJAX assignment */
388 324
 function AjaxAssign(oOptions)
389 325
 {
390 326
 	this.opt = oOptions;
391 327
 	this.bCollapsed = true;
328
+	this.opt.sUrlExpand = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=assign;ticket=' + this.opt.iTicketId;
329
+	this.opt.sUrlAssign = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=assign2;ticket=' + this.opt.iTicketId;
392 330
 
393 331
 	// Insert the expand/collapse button
394
-	document.getElementById(this.opt.sId).innerHTML = '<img src="' + this.opt.sImagesUrl + "/" + this.opt.sImageCollapsed + '" id="assign_' + this.opt.sSelf + '" class="shd_assign_button" onclick="' + this.opt.sSelf + '.click();">';
332
+	$('#' + this.opt.sId).html('<img src="' + this.opt.sImageCollapsed + '" id="assign_' + this.opt.sSelf + '" class="shd_assign_button">');
333
+	$('.shd_ticketdetails').on('click', '#assign_' + this.opt.sSelf, this.click.bind(this));
395 334
 }
396 335
 
397 336
 AjaxAssign.prototype.click = function ()
... ...
@@ -405,11 +344,10 @@ AjaxAssign.prototype.click = function ()
405 344
 AjaxAssign.prototype.expand = function ()
406 345
 {
407 346
 	this.bCollapsed = false;
408
-	var img = document.getElementById('assign_' + this.opt.sSelf);
409
-	img.setAttribute('src', this.opt.sImagesUrl + "/" + this.opt.sImageExpanded);
347
+	$('#assign_' + this.opt.sSelf).attr('src', this.opt.sImageExpanded);
410 348
 
411 349
 	// Fetch the list of items
412
-	shd_getJSONDocument.call(this, smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=assign;ticket=' + this.opt.iTicketId + ';' + sSessV + '=' + sSessI, this.expand_callback);
350
+	shd_getJSONDocument(this.opt.sUrlExpand + ';' + this.opt.sSession, this.expand_callback.bind(this));
413 351
 }
414 352
 
415 353
 AjaxAssign.prototype.expand_callback = function (oRecvd)
... ...
@@ -418,9 +356,7 @@ AjaxAssign.prototype.expand_callback = function (oRecvd)
418 356
 		alert(oRecvd.error);
419 357
 	else if (oRecvd && oRecvd.members)
420 358
 	{
421
-		var assign_list = document.getElementById(this.opt.sListId);
422
-		assign_list.innerHTML = '';
423
-		assign_list.setAttribute('style', 'display:block');
359
+		$('#' + this.opt.sListId).show();
424 360
 
425 361
 		var newhtml = '';
426 362
 		var cur = 0;
... ...
@@ -430,23 +366,20 @@ AjaxAssign.prototype.expand_callback = function (oRecvd)
430 366
 				continue;
431 367
 
432 368
 			cur = oRecvd.members[i];
433
-			newhtml += '<li class="shd_assignees" onclick="' + this.opt.sSelf + '.assign(' + cur.uid + ');">';
434
-
435
-			if (cur.admin)
436
-				newhtml += '<img src="' + smf_default_theme_url + '/images/simpledesk/' + (cur.admin == 'yes' ? 'admin' : 'staff') + '.png" alt="" class="shd_smallicon"> ';
437
-
438
-			newhtml += cur.name + '</li>';
369
+			newhtml += '<li class="shd_assignees" data-uid="' + cur.uid + '"><img src="' + (cur.admin == 'yes' ? this.opt.sImageAdmin : this.opt.sImageStaff) + '" alt="" class="shd_smallicon">' + cur.name + '</li>';
439 370
 		}
440 371
 
441
-		assign_list.innerHTML = newhtml;
372
+		$('#' + this.opt.sListId).html(newhtml);
373
+		$('#' + this.opt.sListId).on('click', 'li.shd_assignees', this.assign.bind(this));
442 374
 	}
443 375
 }
444 376
 
445
-AjaxAssign.prototype.assign = function (uid)
377
+AjaxAssign.prototype.assign = function (e)
446 378
 {
447 379
 	// Click handler for the assignment list, to issue the assign
448 380
 	ajax_indicator(true);
449
-	shd_getJSONDocument.call(this, smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=assign2;ticket=' + this.opt.iTicketId + ';to_user=' + uid + ';' + sSessV + '=' + sSessI, this.assign_callback);
381
+
382
+	shd_getJSONDocument(this.opt.sUrlAssign + ';to_user=' + e.currentTarget.dataset.uid + ';'+ this.opt.sSession, this.assign_callback.bind(this));
450 383
 }
451 384
 
452 385
 AjaxAssign.prototype.assign_callback = function(oRecvd)
... ...
@@ -457,20 +390,14 @@ AjaxAssign.prototype.assign_callback = function(oRecvd)
457 390
 	if (oRecvd && oRecvd.success === false)
458 391
 		alert(oRecvd.error);
459 392
 	else if (oRecvd && oRecvd.assigned)
460
-	{
461 393
 		document.getElementById(this.opt.sAssignedSpan).innerHTML = oRecvd.assigned;
462 394
 }
463
-}
464 395
 
465 396
 AjaxAssign.prototype.collapse = function ()
466 397
 {
467 398
 	this.bCollapsed = true;
468
-	var assign_list = document.getElementById(this.opt.sListId);
469
-	assign_list.innerHTML = '';
470
-	assign_list.setAttribute('style', 'display:none');
471
-
472
-	var img = document.getElementById('assign_' + this.opt.sSelf);
473
-	img.setAttribute('src', this.opt.sImagesUrl + "/" + this.opt.sImageCollapsed);
399
+	$('#' + this.opt.sListId).hide().html();
400
+	$('#assign_' + this.opt.sSelf).attr('src', this.opt.sImageCollapsed);
474 401
 }
475 402
 
476 403
 /* Ajax Notifications List */
... ...
@@ -484,17 +411,13 @@ function shd_notifications(iTicketId, oOptions)
484 411
 
485 412
 shd_notifications.prototype.init = function ()
486 413
 {
487
-	var oLink = document.getElementById(this.opt.sLinkId);
488
-
489
-	oLink.instanceRef = this;
490
-	oLink.onclick = function (oEvent) {return this.instanceRef.receiveNotifications(oEvent);};
491
-
492
-	document.getElementById(this.opt.sContainerId).style.display = "";
414
+	$('#' + this.opt.sLinkId).on('click', this.receiveNotifications.bind(this));
415
+	$('#' + this.opt.sContainerId).show();
493 416
 }
494 417
 
495 418
 shd_notifications.prototype.receiveNotifications = function ()
496 419
 {
497
-	shd_getJSONDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=helpdesk;sa=ajax;op=notify;ticket=" + this.ticketId + ";" + this.opt.sSessionVar + '=' + this.opt.sSessionId + (this.opt.sPinglist ? ";" + this.opt.sPinglist : ''), this.onReceiveNotifications);
420
+	shd_getJSONDocument(smf_prepareScriptUrl(smf_scripturl) + "action=helpdesk;sa=ajax;op=notify;ticket=" + this.ticketId + ";" + this.opt.sSessionVar + '=' + this.opt.sSessionId + (this.opt.sPinglist ? ";" + this.opt.sPinglist : ''), this.onReceiveNotifications.bind(this));
498 421
 	return false;
499 422
 }
500 423
 
... ...
@@ -585,5 +507,64 @@ shd_notifications.prototype.onReceiveNotifications = function (oRecvd)
585 507
 		newhtml += template.replace('%title%', oRecvd.optional_butoff_txt).replace('%subtemplate%', temphtml);
586 508
 	}
587 509
 
588
-	document.getElementById("shd_notifications_div").innerHTML = newhtml;
510
+	$('#' + this.opt.sContainerId).html(newhtml);
511
+}
512
+
513
+/* Go Advanced Handling */
514
+function goAdvanced(oOptions)
515
+{
516
+	this.opt = oOptions;
517
+	$('#' + this.opt.sAdvancedContainerId).on('click', this.click.bind(this));
518
+
519
+	$(document).ready(this.init.bind(this));
520
+}
521
+
522
+goAdvanced.prototype.init = function(e)
523
+{
524
+	$('#' + this.opt.sBbcContainerId +
525
+		', .' + this.opt.sBbcContainerEditorClass +
526
+		', #' + this.opt.sSmileyContainerId +
527
+		', .' + this.opt.sSmileyContainerEditorClass +
528
+		', .' + this.opt.sAttachContainerId +
529
+		', #' + this.opt.sAdditionalOptionsContainerId
530
+		).hide();
531
+}
532
+
533
+goAdvanced.prototype.click = function(e)
534
+{
535
+	e.preventDefault();
536
+
537
+	$('#' + this.opt.sBbcContainerId + ', .' + this.opt.sBbcContainerEditorClass).css('display', this.opt.bAllowBBC ? '' : 'none');
538
+	$('#' + this.opt.sSmileyContainerId + ', .' + this.opt.sSmileyContainerEditorClass).css('display', this.opt.bAllowSmileys ? '' : 'none');
539
+	$('#' + this.opt.sAttachContainerId).css('display', this.opt.bAllowAttach ? '' : 'none');
540
+	$('#' + this.opt.sAdditionalOptionsContainerId).show();
541
+	$('#' + this.opt.sAdvancedContainerId).hide();
542
+}
543
+
544
+/* Department Filters */
545
+function shd_dept_filter(oOptions)
546
+{
547
+	this.opt = oOptions;
548
+	$('#' + this.opt.sSelectContainerId).on('change', this.startFilter.bind(this));
549
+}
550
+
551
+shd_dept_filter.prototype.startFilter = function ()
552
+{
553
+	this.displayed = false;
554
+	$(this.opt.oFields).each(this.filterDept.bind(this));
555
+}
556
+
557
+shd_dept_filter.prototype.filterDept = function (index, value)
558
+{
559
+	this.currentDept = $('#' + this.opt.sSelectContainerId).val();
560
+
561
+	if (in_array(this.currentDept, this.opt.oFields[index]))
562
+	{
563
+		this.displayed = true;
564
+		$('#field_' + index + '_container').show();
565
+	}
566
+	else
567
+		$('#field_' + index + '_container').hide();
568
+
569
+	$('#' + this.opt.sCustomFieldsContainerId + ', #' + this.opt.sCustomFieldsTitleContainerId).toggle(this.displayed)
589 570
 }
... ...
@@ -1,17 +1,24 @@
1 1
 // Handle the JavaScript surrounding the admin center.
2
+$(document).ready(function(){
3
+	$('.shd_help').on('click', function(e) {
4
+		e.preventDefault();
5
+		return reqOverlayDiv(this.href);
6
+	});
7
+
8
+	/* If we have a submit with a save class, default the submitOnce check */
9
+	$('input[type="submit"].save').parent('form').on('submit', function(){
10
+		submitonce(this.currentTarget);
11
+	});
12
+	$('input[type="submit"].save').on('click', function(e){
13
+		submitThisOnce(this.currentTarget);
14
+	});
15
+});
16
+
2 17
 function sd_AdminIndex(oOptions)
3 18
 {
4 19
 	this.opt = oOptions;
5
-	this.init();
6
-}
7 20
 
8
-sd_AdminIndex.prototype.init = function ()
9
-{
10
-	window.adminIndexInstanceRef = this;
11
-	var fHandlePageLoaded = function () {
12
-		window.adminIndexInstanceRef.loadAdminIndex();
13
-	}
14
-	addLoadEvent(fHandlePageLoaded);
21
+	$(document).ready(this.loadAdminIndex.bind(this));
15 22
 }
16 23
 
17 24
 sd_AdminIndex.prototype.loadAdminIndex = function ()
... ...
@@ -27,19 +34,21 @@ sd_AdminIndex.prototype.loadAdminIndex = function ()
27 34
 	// Load the text box that sais there's a new version available.
28 35
 	if (this.opt.bLoadUpdateNotification)
29 36
 		this.checkUpdateAvailable();
30
-}
31 37
 
38
+	// Totoal Tickets link.
39
+	$('#' + this.opt.sTotalTicketsContainerId + ' a').on('click', this.TickekTotals.bind(this));
40
+}
32 41
 
33 42
 sd_AdminIndex.prototype.setAnnouncements = function ()
34 43
 {
35
-	if (!('sdAnnouncements' in window) || !('length' in window.sdAnnouncements))
44
+	if (!$('#sdAnnouncements').length)
36 45
 		return;
37 46
 
38 47
 	var sMessages = '';
39 48
 	for (var i = 0; i < window.sdAnnouncements.length; i++)
40 49
 		sMessages += this.opt.sAnnouncementMessageTemplate.replace('%href%', window.sdAnnouncements[i].href).replace('%subject%', window.sdAnnouncements[i].subject).replace('%time%', window.sdAnnouncements[i].time).replace('%message%', window.sdAnnouncements[i].message).replace('%author%', window.sdAnnouncements[i].author).replace('%readmore%', window.sdAnnouncements[i].href);
41 50
 
42
-	setInnerHTML(document.getElementById(this.opt.sAnnouncementContainerId), this.opt.sAnnouncementTemplate.replace('%content%', sMessages));
51
+	$('#' + this.opt.sAnnouncementContainerId).html(this.opt.sAnnouncementTemplate.replace('%content%', sMessages));
43 52
 }
44 53
 
45 54
 sd_AdminIndex.prototype.showCurrentVersion = function ()
... ...
@@ -47,18 +56,17 @@ sd_AdminIndex.prototype.showCurrentVersion = function ()
47 56
 	if (!('sdVersion' in window))
48 57
 		return;
49 58
 
50
-	var oSdVersionContainer = document.getElementById(this.opt.sSdVersionContainerId);
51
-	var oYourVersionContainer = document.getElementById(this.opt.sYourVersionContainerId);
59
+	var oSdVersionContainer = $('#' + this.opt.sSdVersionContainerId);
60
+	var oYourVersionContainer = $('#' + this.opt.sYourVersionContainerId);
52 61
 
53 62
 	// Handle a developer version cleaner.
54
-	if (this.opt.bDeveloperMode && 'sdDevVersion' in window)
55
-		setInnerHTML(oSdVersionContainer, window.sdDevVersion);
56
-	else
57
-		setInnerHTML(oSdVersionContainer, window.sdVersion);
63
+	oSdVersionContainer.html((this.opt.bDeveloperMode && 'sdDevVersion' in window) ? window.sdDevVersion : window.sdVersion)
58 64
 
59
-	var sCurrentVersion = getInnerHTML(oYourVersionContainer);
60
-	if (sCurrentVersion != window.sdVersion && !this.opt.bDeveloperMode)
61
-		setInnerHTML(oYourVersionContainer, this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion));
65
+	var sCurrentVersion = oYourVersionContainer.html();
66
+	if (this.opt.bDeveloperMode && 'sdDevVersion' in window && sCurrentVersion != window.sdDevVersion)
67
+		oYourVersionContainer.html(this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion));
68
+	else if (sCurrentVersion != window.sdVersion && !this.opt.bDeveloperMode)
69
+		oYourVersionContainer.html(this.opt.sVersionOutdatedTemplate.replace('%currentVersion%', sCurrentVersion));
62 70
 }
63 71
 
64 72
 sd_AdminIndex.prototype.checkUpdateAvailable = function ()
... ...
@@ -67,59 +75,71 @@ sd_AdminIndex.prototype.checkUpdateAvailable = function ()
67 75
 		return;
68 76
 
69 77
 	// We don't handle developer mode stuff here, best to get any developer edition to a supported edition.
70
-
71
-	var oContainer = document.getElementById(this.opt.sUpdateNotificationContainerId);
78
+	var oContainer = $('#' + this.opt.sUpdateNotificationContainerId);
72 79
 
73 80
 	// Are we setting a custom title and message?
74 81
 	var sTitle = 'sdUpdateTitle' in window ? window.sdUpdateTitle : this.opt.sUpdateNotificationDefaultTitle;
75 82
 	var sMessage = 'sdUpdateNotice' in window ? window.sdUpdateNotice : this.opt.sUpdateNotificationDefaultMessage;
76 83
 
77
-	setInnerHTML(oContainer, this.opt.sUpdateNotificationTemplate.replace('%title%', sTitle).replace('%message%', sMessage).replace('%criticaltitle%', sTitle));
84
+	oContainer.html(this.opt.sUpdateNotificationTemplate.replace('%title%', sTitle).replace('%message%', sMessage).replace('%criticaltitle%', sTitle));
78 85
 
79 86
 	// Parse in the package download URL if it exists in the string.
80
-	document.getElementById('update-link').href = this.opt.sUpdateNotificationLink.replace('%package%', window.sdUpdatePackage);
87
+	$('#update-link').attr('href', this.opt.sUpdateNotificationLink.replace('%package%', window.sdUpdatePackage));
81 88
 
82 89
 	if ('sdUpdateInformation' in window)
83 90
 	{
84
-		document.getElementById('information-link-span').style.display = 'block';
85
-		document.getElementById('information-link').href = this.opt.sUpdateInformationLink.replace('%information%', window.sdUpdateInformation);
91
+		$('#information-link-span').css('display', 'block');
92
+		$('#information-link').attr('href', this.opt.sUpdateInformationLink.replace('%information%', window.sdUpdateInformation));
86 93
 	}
87 94
 
88 95
 	// If we decide to override life into "red" mode, do it.
89 96
 	if ('sdUpdateCritical' in window && window.sdUpdateCritical === true)
90 97
 	{
91
-		document.getElementById('update_container').className = 'errorbox';
92
-		document.getElementById('update_critical_title').style.display = 'block';
93
-		document.getElementById('update_critical_alert').style.display = 'block';
94
-		document.getElementById('update_title').style.display = 'none';
95
-		document.getElementById('update_content').className = '';
98
+		$('#update_container').removeClass().addClass('errorbox');
99
+		$('#update_critical_title').show();
100
+		$('#update_critical_alert').show();
101
+		$('#update_title').hide();
96 102
 	}
97 103
 
98
-	document.getElementById('sd_update_section').style.display = 'block';
104
+	$('#sd_update_section').show();
99 105
 }
100 106
 
101 107
 // Ticket number information...
102
-function shd_ticket_total_information()
108
+sd_AdminIndex.prototype.TickekTotals = function ()
103 109
 {
104
-	var infocontainer = document.getElementById('shd_ticket_total_information');
105
-
106
-	if (infocontainer.style.display == 'none')
107
-		infocontainer.style.display = 'block';
108
-	else
109
-		infocontainer.style.display = 'none';
110
+	var infocontainer = $('#' + this.opt.sTotalTicketsInfoContainerID).toggle();
110 111
 }
111 112
 
112 113
 // Modified, SMF 2.0 ToggleItem
113
-function toggleItem(itemID, theme_url, txt_on, txt_off)
114
+function shd_plugins(oOptions)
115
+{
116
+	this.opt = oOptions;
117
+
118
+	$('#' + this.opt.sJSworkedID).val(1);
119
+	$('.' + this.opt.sFeaturesSwitchClass + ' a').on('click', this.togglePlugin.bind(this));
120
+	$(this.opt.oJSInstallablePlugins).each(this.setupPlugins.bind(this));
121
+}
122
+
123
+shd_plugins.prototype.setupPlugins = function (index, itemID)
124
+{
125
+	$('#' + this.opt.sJSFeatureClass.replace('%itemid%', itemID)).css('display', '');
126
+	$('#' + this.opt.sJSPlainFeatureClass.replace('%itemid%', itemID)).css('display', 'none');
127
+}
128
+
129
+shd_plugins.prototype.togglePlugin = function (e)
114 130
 {
131
+	e.preventDefault();
132
+	itemID = e.currentTarget.dataset.plugin;
133
+
115 134
 	// Toggle the hidden item.
116
-	var itemValueHandle = document.getElementById("feature_" + itemID);
117
-	itemValueHandle.value = itemValueHandle.value === 1 ? 0 : 1;
135
+	this.oItemValueHandle = $('#' + this.opt.sFeatureClass.replace('%itemid%', itemID));
136
+	this.bItemValue = this.oItemValueHandle.val() == 0 ? 1 : 0;
118 137
 
119 138
 	// Change the image, alternative text and the title.
120
-	document.getElementById("switch_" + itemID).src = theme_url + '/simpledesk/switch_' + (itemValueHandle.value === 1 ? 'on' : 'off') + '.png';
121
-	document.getElementById("switch_" + itemID).alt = itemValueHandle.value === 1 ? txt_off : txt_on;
122
-	document.getElementById("switch_" + itemID).title = itemValueHandle.value === 1 ? txt_off : txt_on;
139
+	$('#' + this.opt.sSwitchClass.replace('%itemid%', itemID)).attr('src', this.bItemValue === 1 ? this.opt.sPluginOnImg : this.opt.sPluginOffImg);
140
+	$('#' + this.opt.sSwitchClass.replace('%itemid%', itemID)).attr('alt', this.bItemValue === 1 ? this.opt.sPluginOnText : this.opt.sPluginOffText);
141
+	$('#' + this.opt.sSwitchClass.replace('%itemid%', itemID)).attr('title', this.bItemValue === 1 ? this.opt.sPluginOnText : this.opt.sPluginOffText);
142
+	$('#' + this.opt.sFeatureClass.replace('%itemid%', itemID)).val(this.bItemValue);
123 143
 
124 144
 	// Don't reload.
125 145
 	return false;
... ...
@@ -250,3 +271,151 @@ shd_custom_field_order.prototype.resort = function (currentOrder)
250 271
 			$('#option_' + key).val($('#option_' + key).attr('data-value-input'));
251 272
 	});
252 273
 }
274
+
275
+/* Reattribute Posts */
276
+function shd_AttributeValidate(oOptions)
277
+{
278
+	this.opt = oOptions;
279
+
280
+	this.init();
281
+}
282
+
283
+/* Reattribute Posts: Bind the events */
284
+shd_AttributeValidate.prototype.init = function ()
285
+{
286
+	/* Changing the radio */
287
+	$('#' + this.opt.sTypeEmailContainerId + ', #' + this.opt.sTypeStarterContainerId + ', #' + this.opt.sTypeFromContainerId).change(this.validator.bind(this));
288
+
289
+	/* Clicking into a field, special as we update the radio */
290
+	$('#' + this.opt.sEmailContainerId + ', #' + this.opt.sStarterContainerId + ', #' + this.opt.sFromContainerId + ', #' + this.opt.sToContainerId).focus(this.focusValidator.bind(this));
291
+
292
+	/* After typing a key */
293
+	$('#' + this.opt.sEmailContainerId + ', #' + this.opt.sStarterContainerId + ', #' + this.opt.sFromContainerId + ', #' + this.opt.sToContainerId).keyup(this.validator.bind(this));
294
+}
295
+
296
+/* Reattribute Posts: Does a radio change and processes the validator */
297
+shd_AttributeValidate.prototype.focusValidator = function (e)
298
+{
299
+	if (e.currentTarget.id == this.opt.sEmailContainerId)
300
+		$('#' + this.opt.sTypeEmailContainerId).prop('checked', true);
301
+	else if (e.currentTarget.id == this.opt.sStarterContainerId)
302
+		$('#' + this.opt.sTypeStarterContainerId).prop('checked', true);
303
+	else if (e.currentTarget.id == this.opt.sFromContainerId)
304
+		$('#' + this.opt.sTypeFromContainerId).prop('checked', true);
305
+
306
+	this.validator();
307
+}
308
+
309
+/* Reattribute Posts: Validate if we can start the process to reattribute */
310
+shd_AttributeValidate.prototype.validator = function ()
311
+{
312
+	origText = this.opt.sOrigText;
313
+	origTextStarter = this.opt.sOrigTextStarter;
314
+	valid = true;
315
+
316
+	// Do all the fields!
317
+	if (!$('#' + this.opt.sToContainerId).val())
318
+		valid = false;
319
+
320
+	warningMessage = origText.replace(/%member_to%/, $('#' + this.opt.sToContainerId).value);
321
+
322
+	if ($('#' + this.opt.sTypeEmailContainerId).is(":checked"))
323
+	{
324
+		$('#' + this.opt.sStarterContainerId + ', #' + this.opt.sFromContainerId).val("");
325
+			valid = $('#' + this.opt.sEmailContainerId).val() != '';
326
+		warningMessage = warningMessage.replace(/%type%/, this.opt.sEmailConfirmText).replace(/%find%/, $('#' + this.opt.sEmailContainerId).val());
327
+	}
328
+	else if ($('#' + this.opt.sTypeStarterContainerId).is(":checked"))
329
+	{
330
+		$('#' + this.opt.sEmailContainerId + ' #' + this.opt.sFromContainerId).val("");
331
+
332
+			valid = $('#' + this.opt.sStarterContainerId).val() != '';
333
+		warningMessage = origTextStarter.replace(/%member_to%/, $('#' + this.opt.sToContainerId).val()).replace(/%find%/, $('#' + this.opt.sStarterContainerId).val());			
334
+	}
335
+	else
336
+	{
337
+		$('#' + this.opt.sEmailContainerId + ' #' + this.opt.sStarterContainerId).val("");
338
+
339
+		valid = $('#' + this.opt.sFromContainerId).val() != '';
340
+		warningMessage = warningMessage.replace(/%type%/, this.opt.sFromConfirmText).replace(/%find%/, $('#' + this.opt.sFromContainerId).val());
341
+	}
342
+
343
+	$('#' + this.opt.sDoAttributeContainerId).prop("disabled", valid ? false : true);
344
+}
345
+
346
+/* Roles Management */
347
+function shd_role(oOptions)
348
+{
349
+	this.opt = oOptions;
350
+
351
+	this.init();
352
+}
353
+
354
+/* Roles Management: Bind the events */
355
+shd_role.prototype.init = function ()
356
+{
357
+	/* When they change a permission, change the icon */
358
+	this.iconInit();
359
+
360
+	this.toggleBlockInt();
361
+}
362
+
363
+/* Roles Management: Bind the events */
364
+shd_role.prototype.iconInit = function ()
365
+{
366
+	this.iconSelector = {
367
+		disallow: this.opt.sPermissionDisallowClass,
368
+		allow: this.opt.sPermissionAllowClass,
369
+		allow_own: this.opt.sPermissionAllowOwnClass,
370
+		allow_any: this.opt.sPermissionAllowAnyClass
371
+	};
372
+
373
+	$('dl.permsettings dd select[id*="perm_"]').on('change', this.icon.bind(this));
374
+}
375
+
376
+/* Roles Management: Handle changing the icon */
377
+shd_role.prototype.icon = function (e)
378
+{
379
+	$('#' + e.currentTarget.id + '_icon').attr('class', this.iconSelector[e.currentTarget.value] ? this.iconSelector[e.currentTarget.value] : '');
380
+}
381
+
382
+shd_role.prototype.toggleBlockInt = function ()
383
+{
384
+	$(this.opt.oHiddenBlocks).each(this.toggleBlock.bind(this));
385
+
386
+	$('div.cat_bar h3.catbg a').on('click', this.toggleBlock.bind(this));
387
+	$('input#' + this.opt.sDeleteContainerId).on('click', this.formConfirm.bind(this))
388
+}
389
+
390
+shd_role.prototype.toggleBlock = function (e, block)
391
+{
392
+	if (typeof e.currentTarget !== 'undefined')
393
+	{
394
+		e.preventDefault();
395
+		block = e.currentTarget.dataset.block;
396
+	}
397
+
398
+	if ($('#' + this.opt.sBlockHeader.replace('%block%', block)).hasClass('cat_collapsed'))
399
+	{
400
+		$('#' + this.opt.sBlockHeader.replace('%block%', block)).attr('class', 'cat_bar');
401
+		$('#' + this.opt.sBlockContent.replace('%block%', block)).css('display', '');
402
+		$('#' + this.opt.sBlockFooter.replace('%block%', block)).css('display', '');
403
+		$('#' + this.opt.sBlockIcon.replace('%block%', block)).attr('src', this.opt.sBlockIconExpandedImg);
404
+	}
405
+	else
406
+	{
407
+		$('#' + this.opt.sBlockHeader.replace('%block%', block)).attr('class', 'cat_bar cat_collapsed');
408
+		$('#' + this.opt.sBlockContent.replace('%block%', block)).css('display', 'none');
409
+		$('#' + this.opt.sBlockFooter.replace('%block%', block)).css('display', 'none');
410
+		$('#' + this.opt.sBlockIcon.replace('%block%', block)).attr('src', this.opt.sBlockIconCollapsedImg);
411
+	}
412
+
413
+	$('#' + this.opt.sBlockIcon.replace('%block%', block)).css('display', '');
414
+}
415
+
416
+shd_role.prototype.formConfirm = function (e)
417
+{
418
+	e.preventDefault();
419
+
420
+	return confirm(this.opt.sDeleteConfirmText);
421
+}
... ...
@@ -912,7 +912,8 @@ function shd_credits()
912 912
 					'desc' => $txt['shd_credits_devs_desc'],
913 913
 					'icon' => 'devs.png',
914 914
 					'members' => array(
915
-						array('Peter &quot;Arantor&quot; Spicer', false),
915
+						array('Jeremy &quot;SleePy&quot; Darwood', false),
916
+						array('Peter &quot;Arantor&quot; Spicer', true),
916 917
 						array('Jason &quot;JBlaze&quot; Clemons', true),
917 918
 						array('Marcus &quot;c&#963;&#963;&#1082;&#953;&#1108; &#1084;&#963;&#951;&#1109;&#1090;&#1108;&#1103;&quot; Forsberg', true),
918 919
 					),
... ...
@@ -922,8 +923,7 @@ function shd_credits()
922 923
 					'desc' => $txt['shd_credits_projectsupport_desc'],
923 924
 					'icon' => 'managers.png',
924 925
 					'members' => array(
925
-						array('Graeme &quot;Trekkie101&quot; Spence', false),
926
-						array('Jeremy &quot;SleePy&quot; Darwood', false),
926
+						array('Graeme &quot;Trekkie101&quot; Spence', true),
927 927
 					),
928 928
 				),
929 929
 				array(
... ...
@@ -931,7 +931,7 @@ function shd_credits()
931 931
 					'desc' => $txt['shd_credits_marketing_desc'],
932 932
 					'icon' => 'marketers.png',
933 933
 					'members' => array(
934
-						array('Brannon &quot;B&ordf;&quot; Hall', false),
934
+						array('Brannon &quot;B&ordf;&quot; Hall', true),
935 935
 					),
936 936
 				),
937 937
 				array(
... ...
@@ -957,9 +957,9 @@ function shd_credits()
957 957
 					'desc' => $txt['shd_credits_qualityassurance_desc'],
958 958
 					'icon' => 'qa.png',
959 959
 					'members' => array(
960
-						array('Sinan &quot;[SiNaN]&quot; &Ccedil;evik', false),
961
-						array('Paul &quot;tfs&quot; Laufer', false),
962
-						array('Shomari &quot;spoogs&quot; Scott', false),
960
+						array('Sinan &quot;[SiNaN]&quot; &Ccedil;evik', true),
961
+						array('Paul &quot;tfs&quot; Laufer', true),
962
+						array('Shomari &quot;spoogs&quot; Scott', true),
963 963
 						array('Alex &quot;Cleo&quot; Tokar', true),
964 964
 					),
965 965
 				),
... ...
@@ -968,21 +968,21 @@ function shd_credits()
968 968
 					'desc' => $txt['shd_credits_beta_desc'],
969 969
 					'icon' => 'testers.png',
970 970
 					'members' => array(
971
-						array('Chris &quot;ccbtimewiz&quot; Batista', false),
972
-						array('Wade &quot;&#1109;&#951;&#963;&#969;&quot; Poulsen', false),
973
-						array('Edwin &quot;Dismal Shadow&quot; Mendez', false),
974
-						array('Treznax', false),
975
-						array('Mark &quot;KiLLuMiNaTi&minus;7&minus;&quot; Longworth', false),
976
-						array('NIBOGO', false),
977
-						array('Robert &quot;Robbo&quot; Clancy', false),
978
-						array('Ya&#x11F;izcan Arslan', false),
979
-						array('MultiformeIngegno', false),
980
-						array('flapjack', false),
981
-						array('feline', false),
982
-						array('Sordell Media', false),
983
-						array('[FailSafe]', false),
984
-						array('chilly', false),
985
-						array('Tah Zonemaster', false),
971
+						array('Chris &quot;ccbtimewiz&quot; Batista', true),
972
+						array('Wade &quot;&#1109;&#951;&#963;&#969;&quot; Poulsen', true),
973
+						array('Edwin &quot;Dismal Shadow&quot; Mendez', true),
974
+						array('Treznax', true),
975
+						array('Mark &quot;KiLLuMiNaTi&minus;7&minus;&quot; Longworth', true),
976
+						array('NIBOGO', true),
977
+						array('Robert &quot;Robbo&quot; Clancy', true),
978
+						array('Ya&#x11F;izcan Arslan', true),
979
+						array('MultiformeIngegno', true),
980
+						array('flapjack', true),
981
+						array('feline', true),
982
+						array('Sordell Media', true),
983
+						array('[FailSafe]', true),
984
+						array('chilly', true),
985
+						array('Tah Zonemaster', true),
986 986
 					),
987 987
 				),
988 988
 				array(
... ...
@@ -528,7 +528,7 @@ function shd_ajax_assign2()
528 528
 		return array('error' => $txt['shd_no_ticket']);
529 529
 
530 530
 	if (!isset($_GET['to_user']) || !is_numeric($_GET['to_user']))
531
-		return array('success' => false, 'error' => $txt['shd_assigned_not_permitted'] . 'line459');
531
+		return array('success' => false, 'error' => $txt['shd_assigned_not_permitted']);
532 532
 
533 533
 	if (!shd_allowed_to('shd_assign_ticket_any', $dept) || $status == TICKET_STATUS_CLOSED || $status == TICKET_STATUS_DELETED)
534 534
 		return array('success' => false, 'error' => $txt['shd_cannot_assign']);
... ...
@@ -398,10 +398,12 @@ function shd_view_ticket()
398 398
 		);
399 399
 		if (!empty($field['options']) && empty($field['options']['inactive']))
400 400
 			$field['options']['inactive'] = array();
401
+		if (!empty($field['options']) && empty($field['options']['order']))
402
+			$field['options']['order'] = array();
401 403
 
402 404
 		if (in_array($field['type'], array(CFIELD_TYPE_RADIO, CFIELD_TYPE_SELECT, CFIELD_TYPE_MULTI)))
403 405
 			foreach ($field['options'] as $k => $v)
404
-				if ($k != 'inactive' && strpos($v, '[') !== false)
406
+				if ($k != 'inactive' && $k != 'order' && strpos($v, '[') !== false)
405 407
 					$field['options'][$k] = parse_bbc($v, false);
406 408
 
407 409
 		if (($row['field_loc'] & CFIELD_REPLY) && $field['editable'])
... ...
@@ -668,78 +670,8 @@ function shd_view_ticket()
668 670
 	$context['can_ping'] = $context['can_reply'] && shd_allowed_to('shd_singleton_email', $context['ticket']['dept']);
669 671
 
670 672
 	// Set up the fancy editor
671
-	shd_postbox('shd_message', '', array('post_button' => $txt['shd_reply_ticket']));
672
-
673
-	// Lastly, our magic AJAX stuff ;D and we know we already made html_headers exist in SimpleDesk.php, score!
674
-	$context['html_headers'] .= '
675
-	<script type="text/javascript"><!-- // --><![CDATA[
676
-	var sSessI = "' . $context['session_id'] . '";
677
-	var sSessV = "' . $context['session_var'] . '";';
678
-
679
-	if ($context['ticket']['privacy']['can_change'])
680
-		$context['html_headers'] .= '
681
-	var shd_ajax_problem = ' . JavaScriptEscape($txt['shd_ajax_problem']) . ';
682
-	var privacyCtl = new shd_privacyControl({
683
-		ticket: ' . $context['ticket_id'] . ',
684
-		sUrl: smf_scripturl + "?action=helpdesk;sa=ajax;op=privacy;ticket=' . $context['ticket_id'] . '",
685
-		sSession: sSessV + "=" + sSessI,
686
-		sSrcA: "privlink",
687
-		sDestSpan: "privacy"
688
-	});';
689
-
690
-	if ($context['ticket']['urgency']['increase'] || $context['ticket']['urgency']['decrease'])
691
-		$context['html_headers'] .= '
692
-	var urgencyCtl = new shd_urgencyControl({
693
-		ticket: ' . $context['ticket_id'] . ',
694
-		sUrl: smf_scripturl + "?action=helpdesk;sa=ajax;op=urgency;ticket=' . $context['ticket_id'] . ';change=",
695
-		sSession: sSessV + "=" + sSessI,
696
-		sDestSpan: "urgency",
697
-		aButtons: ["up", "down"],
698
-		aButtonOps: { up: "increase", down: "decrease" }
699
-	});';
700
-
701
-	if (!empty($options['display_quick_reply']))
702
-		$context['html_headers'] .= '
703
-	var oQuickReply = new QuickReply({
704
-		bDefaultCollapsed: ' . (!empty($options['display_quick_reply']) && $options['display_quick_reply'] == 2 ? 'false' : 'true') . ',
705
-		iTicketId: ' . $context['ticket_id'] . ',
706
-		iStart: ' . $context['start'] . ',
707
-		sScriptUrl: smf_scripturl,
708
-		sImagesUrl: "' . $settings['images_url'] . '",
709
-		sContainerId: "quickReplyOptions",
710
-		sImageId: "quickReplyExpand",
711
-		sImageCollapsed: "collapse.png",
712
-		sImageExpanded: "expand.png",
713
-		sJumpAnchor: "quickreply",
714
-		sHeaderId: "quickreplyheader",
715
-		sFooterId: "quickreplyfooter"
716
-	});';
717
-
718
-	$context['html_headers'] .= '
719
-	var oCustomFields = new CustomFields({
720
-		sImagesUrl: "' . $settings['images_url'] . '",
721
-		sContainerId: "additional_info",
722
-		sImageId: "shd_custom_fields_swap",
723
-		sImageCollapsed: "collapse.png",
724
-		sImageExpanded: "expand.png",
725
-		sHeaderId: "additionalinfoheader",
726
-		sFooterId: "additional_info_footer",
727
-	});';
728
-
729
-	if (!empty($options['display_quick_reply']) && $context['can_go_advanced'])
730
-		$context['html_headers'] .= '
731
-	function goAdvanced()
732
-	{
733
-		document.getElementById("shd_bbcbox").style.display = ' . (!empty($modSettings['shd_allow_ticket_bbc']) ? '""' : '"none"') . ';
734
-		document.getElementById("shd_smileybox").style.display = ' . (!empty($modSettings['shd_allow_ticket_smileys']) ? '""' : '"none"') . ';
735
-		document.getElementById("shd_attach_container").style.display = ' . (!empty($context['ticket_form']['do_attach']) ? '""' : '"none"') . ';
736
-		document.getElementById("shd_goadvancedbutton").style.display = "none";' . (!empty($context['controls']['richedit']['shd_message']['rich_active']) ? '
737
-		oEditorHandle_shd_message.toggleView(true);' : '') . '
738
-	}
739
-	';
673
+	shd_postbox('shd_message', '', array('post_button' => $txt['shd_reply_ticket']), '100%');
740 674
 
741
-	$context['html_headers'] .= '
742
-	// ]' . ']></script>';
743 675
 	$context['shd_display'] = true;
744 676
 	$context['controls']['richedit']['shd_message']['rich_active'] = 0; // we don't want it by default!
745 677
 
... ...
@@ -33,7 +33,9 @@ function shd_profile_main($memID)
33 33
 	global $context, $txt, $scripturl, $sourcedir, $user_info, $settings, $user_profile, $modSettings;
34 34
 
35 35
 	// Load the profile details
36
-	loadTemplate('sd_template/SimpleDesk-Profile', array('helpdesk', 'helpdesk_admin'));
36
+	loadTemplate('sd_template/SimpleDesk-Profile', array('helpdesk'));
37
+	loadJavascriptFile('helpdesk.js', array('defer' => false, 'minimize' => false), 'helpdesk');
38
+
37 39
 	shd_load_language('sd_language/SimpleDeskProfile');
38 40
 	$context['shd_preferences'] = shd_load_user_prefs();
39 41
 	shd_load_plugin_files('hdprofile');
... ...
@@ -36,6 +36,7 @@ function shd_search()
36 36
 	global $context, $smcFunc, $txt, $modSettings, $scripturl;
37 37
 
38 38
 	shd_is_allowed_to('shd_search', 0);
39
+	loadJavascriptFile('suggest.js', array('defer' => false, 'minimize' => false), 'suggest');
39 40
 
40 41
 	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
41 42
 		return fatal_lang_error('loadavg_search_disabled', false);
... ...
@@ -218,7 +218,10 @@ function shd_tickettotopic()
218 218
 	{
219 219
 		// Didn't we have any values? If not, prune it, not interested.
220 220
 		if (empty($field['values']))
221
+		{
221 222
 			unset($context['custom_fields'][$field_id]);
223
+			continue;
224
+		}
222 225
 
223 226
 		// If the user is an administrator, they can always see the fields.
224 227
 		if ($is_admin)
... ...
@@ -1145,8 +1145,7 @@ function shd_helpdesk_listing()
1145 1145
 			if (!empty($row['field_options']))
1146 1146
 			{
1147 1147
 				$row['field_options'] = smf_json_decode($row['field_options'], true);
1148
-				if (isset($row['field_options']['inactive']))
1149
-					unset($row['field_options']['inactive']);
1148
+				unset($row['field_options']['inactive'], $row['field_options']['order']);
1150 1149
 				foreach ($row['field_options'] as $k => $v)
1151 1150
 					if (strpos($v, '[') !== false)
1152 1151
 						$row['field_options'][$k] = parse_bbc($v);
... ...
@@ -32,7 +32,7 @@ function template_shd_admin()
32 32
 
33 33
 	// Update?
34 34
 	echo '
35
-		<div id="sd_update_section" class="tborder" style="display: none;"></div>';
35
+		<div id="sd_update_section" class="tborder hidden"></div>';
36 36
 
37 37
 	echo '
38 38
 		<div id="admin_main_section">';
... ...
@@ -44,7 +44,7 @@ function template_shd_admin()
44 44
 					<h3 class="catbg">
45 45
 						<img src="', $settings['default_images_url'], '/simpledesk/live.png" alt="*">
46 46
 						', $txt['shd_live_from'], '
47
-						<span class="righttext"><a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_live" onclick="return reqWin(this.href);"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a></span>
47
+						<span class="righttext"><a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_live" class="shd_help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a></span>
48 48
 					</h3>
49 49
 				</div>
50 50
 				<div class="windowbg nopadding">
... ...
@@ -59,7 +59,7 @@ function template_shd_admin()
59 59
 					<h3 class="catbg">
60 60
 						<img src="', $settings['default_images_url'], '/simpledesk/modification.png" alt="*">
61 61
 						', $txt['shd_mod_information'], '
62
-						<span class="righttext"><a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_modification" onclick="return reqWin(this.href);"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a></span>
62
+						<span class="righttext"><a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_modification" class="shd_help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a></span>
63 63
 					</h3>
64 64
 				</div>
65 65
 				<div class="windowbg nopadding">
... ...
@@ -74,9 +74,9 @@ function template_shd_admin()
74 74
 							<img src="', $settings['default_images_url'], '/simpledesk/ticket.png" alt="*" class="shd_icon_minihead"><strong>', $txt['shd_ticket_information'], ':</strong><br>
75 75
 							', $txt['shd_total_tickets'], ':
76 76
 						<em id="totalTickets">
77
-								<a href="javascript: shd_ticket_total_information();" >', $context['total_tickets'], '</a>
77
+								<a href="#">', $context['total_tickets'], '</a>
78 78
 						</em>
79
-						<div id="shd_ticket_total_information" style="display: none;">
79
+						<div id="shd_ticket_total_information" class="hidden">
80 80
 							&nbsp;&nbsp;&nbsp;', $txt['shd_open_tickets'], ': <em>', $context['open_tickets'], '</em><br>
81 81
 							&nbsp;&nbsp;&nbsp;', $txt['shd_closed_tickets'], ': <em>', $context['closed_tickets'], '</em><br>
82 82
 							&nbsp;&nbsp;&nbsp;', $txt['shd_recycled_tickets'], ': <em>', $context['recycled_tickets'], '</em><br>
... ...
@@ -102,9 +101,8 @@ function template_shd_admin()
102 101
 		<div id="sd_credits">
103 102
 			<div class="title_bar">
104 103
 				<h3 class="titlebg">
105
-					<a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_credits" onclick="return reqWin(this.href);"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a>
104
+					<a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_credits" class="shd_help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a>
106 105
 					', $txt['shd_credits'], '
107
-					<span class="righttext"><a href="', $scripturl, '?action=helpadmin;help=shd_admin_help_credits" onclick="return reqWin(this.href);"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '"></a></span>
108 106
 				</h3>
109 107
 			</div>';
110 108
 
... ...
@@ -159,7 +157,7 @@ function template_shd_admin()
159 157
 		</div>';
160 158
 
161 159
 	// The below functions include all the scripts needed from the simpledesk.net site. The language and format are passed for internationalization.
162
-	if (empty($modSettings['disable_smf_js']))
160
+	if (empty($modSettings['disable_smf_js']) && empty($modSettings['disable_sd_js']))
163 161
 		echo '
164 162
 		<script type="text/javascript" src="https://www.simpledesk.net/sd/current-version.js"></script>
165 163
 		<script type="text/javascript" src="https://www.simpledesk.net/sd/latest-news.js"></script>';
... ...
@@ -199,17 +193,17 @@ function template_shd_admin()
199 193
 				sUpdateNotificationDefaultTitle: ', JavaScriptEscape($txt['shd_update_available']), ',
200 194
 				sUpdateNotificationDefaultMessage: ', JavaScriptEscape($txt['shd_update_message']), ',
201 195
 				sUpdateNotificationTemplate: ', JavaScriptEscape('
202
-					<div class="cat_bar" id="update_title">
196
+					<div class="cat_bar hidden" id="update_title">
203 197
 						<h3 class="catbg">
204 198
 							<img src="' . $settings['default_images_url'] . '/simpledesk/update.png" alt="">
205 199
 							%title%
206
-							<span class="righttext"><a href="' . $scripturl . '?action=helpadmin;help=shd_admin_help_update" onclick="return reqWin(this.href);"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '"></a></span>
200
+							<span class="righttext"><a href="' . $scripturl . '?action=helpadmin;help=shd_admin_help_update" class="shd_help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '"></a></span>
207 201
 						</h3>
208 202
 					</div>
209 203
 					<div class="windowbg" id="update_container">
210 204
 						<div class="content" id="update_content">
211
-							<p id="update_critical_alert" class="alert" style="display: none;">!!</p>
212
-							<h3 id="update_critical_title" class="alert" style="display: none;">%criticaltitle%</h3>
205
+							<p id="update_critical_alert" class="alert hidden">!!</p>
206
+							<h3 id="update_critical_title" class="alert hidden">%criticaltitle%</h3>
213 207
 							<div id="update_message" class="smalltext">
214 208
 								<p>
215 209
 									%message%
... ...
@@ -220,6 +214,8 @@ function template_shd_admin()
220 214
 				'), ',
221 215
 				sUpdateNotificationLink: ', JavaScriptEscape($scripturl . '?action=admin;area=packages;pgdownload;auto;package=%package%;' . $context['session_var'] . '=' . $context['session_id']), ',
222 216
 				sUpdateInformationLink: \'%information%\',
217
+				sTotalTicketsContainerId: \'totalTickets\',
218
+				sTotalTicketsInfoContainerID: \'shd_ticket_total_information\',
223 219
 			});
224 220
 		// ]]></script>';
225 221
 }
... ...
@@ -247,39 +243,9 @@ function template_shd_show_settings()
247 243
 		echo '
248 244
 					<div class="errorbox">', sprintf($txt['settings_not_saved'], $context['saved_failed']), '</div>';
249 245
 
250
-	echo '
251
-	<script type="text/javascript"><!-- // --><![CDATA[
252
-		function invertList(state, id_list)
253
-		{
254
-			for (i in id_list)
255
-			{
256
-				var chk = document.getElementById(id_list[i]);
257
-				if (chk && chk.disabled == false)
258
-					chk.checked = state;
259
-			}
260
-		}';
261
-
262 246
 	if (!empty($context['settings_pre_javascript']))
263
-		echo $context['settings_pre_javascript'];
264
-
265
-	// If we have BBC selection we have a bit of JS.
266
-	if (!empty($context['bbc_sections']))
267
-	{
268
-		echo '
269
-		function toggleBBCDisabled(section, disable)
270
-		{
271
-			for (var i = 0; i < document.forms.bbcForm.length; i++)
272
-			{
273
-				if (typeof(document.forms.bbcForm[i].name) == "undefined" || (document.forms.bbcForm[i].name.substr(0, 11) != "enabledTags") || (document.forms.bbcForm[i].name.indexOf(section) != 11))
274
-					continue;
275
-
276
-				document.forms.bbcForm[i].disabled = disable;
277
-			}
278
-			document.getElementById("bbc_" + section + "_select_all").disabled = disable;
279
-		}';
280
-	}
281 247
 		echo '
282
-	// ]]></script>';
248
+	<script type="text/javascript"><!-- // --><![CDATA[', $context['settings_pre_javascript'], '// ]]></script>';
283 249
 
284 250
 	if (!empty($context['settings_insert_above']))
285 251
 		echo $context['settings_insert_above'];
... ...
@@ -323,7 +289,7 @@ function template_shd_show_settings()
323 289
 				echo '
324 290
 					<div class="cat_bar">
325 291
 						<h3 class="', !empty($config_var['class']) ? $config_var['class'] : 'catbg', '"', !empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '"' : '', '>
326
-							', ($config_var['help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $config_var['help'] . '" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '"></a>' : ''), '
292
+							', ($config_var['help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=' . $config_var['help'] . '" class="help shd_help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '"></a>' : ''), '
327 293
 							', $config_var['label'], '
328 294
 						</h3>
329 295
 					</div>';
... ...
@@ -362,27 +328,6 @@ function template_shd_show_settings()
362 328
 			if ($config_var['type'] == 'hidden')
363 329
 				echo '
364 330
 						<input type="hidden" name="', $config_var['name'], '" value="', $config_var['value'], '">';
365
-			// A check-all option?
366
-			elseif ($config_var['type'] == 'checkall')
367
-			{
368
-				$array = array();
369
-				foreach ($config_var['data'] as $k => $v)
370
-					$array[] = JavaScriptEscape($v[1]);
371
-
372
-				echo '
373
-					<dt></dt>
374
-					<dd>
375
-						<input type="checkbox" name="all" id="', $config_var['name'], '" value="" onclick="invert_', $config_var['name'], '(this);" class="floatleft">
376
-						<label for="check_all" class="floatleft">', $txt['check_all'], '</label>
377
-					</dd>
378
-					<script type="text/javascript"><!-- // --><![CDATA[
379
-					function invert_', $config_var['name'], '(obj)
380
-					{
381
-						var checks = [' . implode(',', $array), '];
382
-						invertList(obj.checked, checks);
383
-					}
384
-					// ]]></script>';
385
-			}
386 331
 			// Is this a span like a message?
387 332
 			elseif (in_array($config_var['type'], array('message', 'warning')))
388 333
 				echo '
... ...
@@ -393,7 +338,7 @@ function template_shd_show_settings()
393 338
 			else
394 339
 			{
395 340
 				echo '
396
-						<dt', is_array($config_var) && !empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '"' : '', is_array($config_var) && !empty($config_var['invisible']) ? ' style="display:none;"' : '', '>';
341
+						<dt', is_array($config_var) && !empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '"' : '', is_array($config_var) && !empty($config_var['invisible']) ? ' class="hidden"' : '', '>';
397 342
 
398 343
 				// Some quick helpers...
399 344
 				$javascript = $config_var['javascript'];
... ...
@@ -403,7 +348,7 @@ function template_shd_show_settings()
403 348
 				// Show the [?] button.
404 349
 				if ($config_var['help'])
405 350
 					echo '
406
-							<a id="setting_', $config_var['name'], '" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" border="0"></a><span', ($config_var['disabled'] ? ' class="disabled"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label id="label_', $config_var['name'], '" for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span>
351
+							<a id="setting_', $config_var['name'], '" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" class="help shd_help"><img src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" border="0"></a><span', ($config_var['disabled'] ? ' class="disabled"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label id="label_', $config_var['name'], '" for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span>
407 352
 						</dt>';
408 353
 				else
409 354
 					echo '
... ...
@@ -411,7 +356,7 @@ function template_shd_show_settings()
411 356
 						</dt>';
412 357
 
413 358
 				echo '
414
-						<dd', (!empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '_dd"' : ''), (is_array($config_var) && !empty($config_var['invisible']) ? ' style="display:none;"' : ''), '>',
359
+						<dd', (!empty($config_var['force_div_id']) ? ' id="' . $config_var['force_div_id'] . '_dd"' : ''), (is_array($config_var) && !empty($config_var['invisible']) ? ' class="hidden"' : ''), '>',
415 360
 							$config_var['preinput'];
416 361
 
417 362
 				// Show a check box.
... ...
@@ -453,7 +398,7 @@ function template_shd_show_settings()
453 398
 						foreach ($bbcColumn as $bbcTag)
454 399
 							echo '
455 400
 										<li class="list_bbc align_left shd_bbc_list">
456
-											<input type="checkbox" name="', $config_var['name'], '_enabledTags[]" id="tag_', $config_var['name'], '_', $bbcTag['tag'], '" value="', $bbcTag['tag'], '"', in_array($bbcTag['tag'], $context['enabled_tags'][$config_var['name']]) ? ' checked="checked"' : '', ' > <label for="tag_', $config_var['name'], '_', $bbcTag['tag'], '">', $bbcTag['tag'], '</label>', $bbcTag['show_help'] ? ' (<a href="' . $scripturl . '?action=helpadmin;help=tag_' . $bbcTag['tag'] . '" onclick="return reqWin(this.href);">?</a>)' : '', '
401
+											<input type="checkbox" name="', $config_var['name'], '_enabledTags[]" id="tag_', $config_var['name'], '_', $bbcTag['tag'], '" value="', $bbcTag['tag'], '"', in_array($bbcTag['tag'], $context['enabled_tags'][$config_var['name']]) ? ' checked="checked"' : '', '><label for="tag_', $config_var['name'], '_', $bbcTag['tag'], '">', $bbcTag['tag'], '</label>', $bbcTag['show_help'] ? ' (<a href="' . $scripturl . '?action=helpadmin;help=tag_' . $bbcTag['tag'] . '" class="shd_help">?</a>)' : '', '
457 402
 										</li>';
458 403
 
459 404
 					echo '			</ul>
... ...
@@ -485,7 +430,7 @@ function template_shd_show_settings()
485 430
 			else
486 431
 				echo '
487 432
 						<dd>
488
-							<strong>' . $config_var . '</strong>
433
+							<strong>', $config_var, '</strong>
489 434
 						</dd>';
490 435
 		}
491 436
 	}
... ...
@@ -550,38 +494,38 @@ function template_shd_action_log()
550 494
 			<tr class="title_bar">
551 495
 				<td width="38%" colspan="2">
552 496
 					<img src="', $settings['default_images_url'], '/simpledesk/action.png" class="shd_smallicon" alt="">
553
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog', $context['sort'] == $sort_types['action'] && !isset($_REQUEST['asc']) ? ';sort=action;asc' : ';sort=action', '">
497
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog;sort=action', $context['sort'] == $sort_types['action'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
554 498
 						', $txt['shd_admin_actionlog_action'], '
555 499
 					</a>
556
-					', ($context['sort'] == $sort_types['action'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
500
+					', ($context['sort'] == $sort_types['action'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
557 501
 				</td>
558 502
 				<td width="20%">
559 503
 					<img src="', $settings['default_images_url'], '/simpledesk/time.png" class="shd_smallicon" alt="">
560
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog', $context['sort'] == $sort_types['time'] && !isset($_REQUEST['asc']) ? ';sort=time;asc' : ';sort=time', '">
504
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog;sort=time', $context['sort'] == $sort_types['time'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
561 505
 						', $txt['shd_admin_actionlog_date'], '
562 506
 					</a>
563
-					', ($context['sort'] == $sort_types['time'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
507
+					', ($context['sort'] == $sort_types['time'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
564 508
 				</td>
565 509
 				<td width="16%">
566 510
 					<img src="', $settings['default_images_url'], '/simpledesk/user.png" class="shd_smallicon" alt="">
567
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog', $context['sort'] == $sort_types['member'] && !isset($_REQUEST['asc']) ? ';sort=member;asc' : ';sort=member', '">
511
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog;sort=member', $context['sort'] == $sort_types['member'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
568 512
 						', $txt['shd_admin_actionlog_member'], '
569 513
 					</a>
570
-					', ($context['sort'] == $sort_types['member'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
514
+					', ($context['sort'] == $sort_types['member'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
571 515
 				</td>
572 516
 				<td width="16%">
573 517
 					<img src="', $settings['default_images_url'], '/simpledesk/position.png" class="shd_smallicon" alt="">
574
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog', $context['sort'] == $sort_types['position'] && !isset($_REQUEST['asc']) ? ';sort=position;asc' : ';sort=position', '">
518
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog;sort=position', $context['sort'] == $sort_types['position'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
575 519
 						', $txt['shd_admin_actionlog_position'], '
576 520
 					</a>
577
-					', ($context['sort'] == $sort_types['position'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
521
+					', ($context['sort'] == $sort_types['position'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
578 522
 				</td>
579 523
 				<td width="10%">
580 524
 					<img src="', $settings['default_images_url'], '/simpledesk/ip.png" class="shd_smallicon" alt="">
581
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog', $context['sort'] == $sort_types['ip'] && !isset($_REQUEST['asc']) ? ';sort=ip;asc' : ';sort=ip', '">
525
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=actionlog;sort=ip', $context['sort'] == $sort_types['ip'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
582 526
 						', $txt['shd_admin_actionlog_ip'], '
583 527
 					</a>
584
-					', ($context['sort'] == $sort_types['ip'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png' ) . '" alt="">' : ''), '
528
+					', ($context['sort'] == $sort_types['ip'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
585 529
 				</td>
586 530
 				<td width="2%">&nbsp;</td>
587 531
 			</tr>';
... ...
@@ -640,38 +584,38 @@ function template_shd_admin_log()
640 584
 			<tr class="title_bar">
641 585
 				<td class="shd_33">
642 586
 					<img src="', $settings['default_images_url'], '/simpledesk/action.png" class="shd_smallicon" alt="">
643
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog', $context['sort'] == $sort_types['action'] && !isset($_REQUEST['asc']) ? ';sort=action;asc' : ';sort=action', '">
587
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog;sort=action', $context['sort'] == $sort_types['action'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
644 588
 						', $txt['shd_admin_actionlog_action'], '
645 589
 					</a>
646
-					', ($context['sort'] == $sort_types['action'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
590
+					', ($context['sort'] == $sort_types['action'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
647 591
 				</td>
648 592
 				<td class="shd_20">
649 593
 					<img src="', $settings['default_images_url'], '/simpledesk/time.png" class="shd_smallicon" alt="">
650
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog', $context['sort'] == $sort_types['time'] && !isset($_REQUEST['asc']) ? ';sort=time;asc' : ';sort=time', '">
594
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog;sort=time', $context['sort'] == $sort_types['time'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
651 595
 						', $txt['shd_admin_actionlog_date'], '
652 596
 					</a>
653
-					', ($context['sort'] == $sort_types['time'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
597
+					', ($context['sort'] == $sort_types['time'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
654 598
 				</td>
655 599
 				<td class="shd_20">
656 600
 					<img src="', $settings['default_images_url'], '/simpledesk/user.png" class="shd_smallicon" alt="">
657
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog', $context['sort'] == $sort_types['member'] && !isset($_REQUEST['asc']) ? ';sort=member;asc' : ';sort=member', '">
601
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog;sort=member', $context['sort'] == $sort_types['member'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
658 602
 						', $txt['shd_admin_actionlog_member'], '
659 603
 					</a>
660
-					', ($context['sort'] == $sort_types['member'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
604
+					', ($context['sort'] == $sort_types['member'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
661 605
 				</td>
662 606
 				<td class="shd_10">
663 607
 					<img src="', $settings['default_images_url'], '/simpledesk/position.png" class="shd_smallicon" alt="">
664
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog', $context['sort'] == $sort_types['position'] && !isset($_REQUEST['asc']) ? ';sort=position;asc' : ';sort=position', '">
608
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog;sort=position', $context['sort'] == $sort_types['position'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
665 609
 						', $txt['shd_admin_actionlog_position'], '
666 610
 					</a>
667
-					', ($context['sort'] == $sort_types['position'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
611
+					', ($context['sort'] == $sort_types['position'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
668 612
 				</td>
669 613
 				<td class="shd_10" ', $context['can_delete'] ? 'colspan="2"' : '', '>
670 614
 					<img src="', $settings['default_images_url'], '/simpledesk/ip.png" class="shd_smallicon" alt="">
671
-					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog', $context['sort'] == $sort_types['ip'] && !isset($_REQUEST['asc']) ? ';sort=ip;asc' : ';sort=ip', '">
615
+					<a href="', $scripturl, '?action=admin;area=helpdesk_info;sa=adminlog;sort=ip', $context['sort'] == $sort_types['ip'] && !isset($_REQUEST['asc']) ? ';asc' : '', '">
672 616
 						', $txt['shd_admin_actionlog_ip'], '
673 617
 					</a>
674
-					', ($context['sort'] == $sort_types['ip'] ? '<img src="' . $settings['default_images_url'] . '/' . (isset($_REQUEST['asc']) ? 'simpledesk/move_up.png' : 'simpledesk/move_down.png') . '" alt="">' : ''), '
618
+					', ($context['sort'] == $sort_types['ip'] ? '<img src="' . $settings['default_images_url'] . '/simpledesk/move_' . (isset($_REQUEST['asc']) ? 'up' : 'down') . '.png" alt="">' : ''), '
675 619
 				</td>
676 620
 				', $context['can_delete'] ? '<td class="shd_5">&nbsp;</td>' : '', '
677 621
 			</tr>';
... ...
@@ -134,11 +134,11 @@ function template_shd_edit_canned_category()
134 134
 					<dt><strong>', $txt['shd_admin_cannedreplies_categoryname'], '</strong></dt>
135 135
 					<dd><input type="text" name="catname" id="catname" size="30" value="', $context['category_name'], '"></dd>
136 136
 				</dl>
137
-				<input type="submit" value="', $context['page_title'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">';
137
+				<input type="submit" value="', $context['page_title'], '" accesskey="s" class="button save">';
138 138
 
139 139
 	if ($context['canned_category'] != 'new')
140 140
 		echo '
141
-				<input type="submit" name="delete" value="', $txt['shd_admin_cannedreplies_deletecat'], '" onclick="return confirm(', JavaScriptEscape($txt['shd_admin_cannedreplies_delete_confirm']), ') && submitThisOnce(this);" class="button">';
141
+				<input type="submit" name="delete" value="', $txt['shd_admin_cannedreplies_deletecat'], '" onclick="return confirm(', JavaScriptEscape($txt['shd_admin_cannedreplies_delete_confirm']), ')" class="button save">';
142 142
 
143 143
 	echo '
144 144
 				<input type="hidden" name="cat" value="', $context['canned_category'], '">
... ...
@@ -164,7 +164,7 @@ function template_shd_edit_canned_reply()
164 164
 		<div class="information">
165 165
 			', $txt['shd_admin_cannedreplies_homedesc'], '
166 166
 		</div>
167
-		<form action="', $scripturl, '?action=admin;area=helpdesk_cannedreplies;sa=savereply" method="post" accept-charset="', $context['character_set'], '" name="cannedreply" id="cannedreply" onsubmit="', 'submitonce(this);smc_saveEntities(\'cannedreply\', [\'title\', \'', $context['post_box_name'], '\']);" enctype="multipart/form-data" style="margin: 0;">
167
+		<form action="', $scripturl, '?action=admin;area=helpdesk_cannedreplies;sa=savereply" method="post" accept-charset="', $context['character_set'], '" name="cannedreply" id="cannedreply" onsubmit="', 'smc_saveEntities(\'cannedreply\', [\'title\', \'', $context['post_box_name'], '\']);" enctype="multipart/form-data">
168 168
 			<div class="cat_bar">
169 169
 				<h3 class="catbg">
170 170
 					<img src="', $settings['default_images_url'], '/simpledesk/additional_information.png" alt="*">
... ...
@@ -204,21 +204,19 @@ function template_shd_edit_canned_reply()
204 204
 				<dl class="settings">';
205 205
 
206 206
 	foreach ($context['canned_reply']['depts_available'] as $dept_id => $dept_name)
207
-	{
208 207
 		echo '
209 208
 					<dt><strong>', $dept_name, '</strong></dt>
210 209
 					<dd><input type="checkbox" name="dept_', $dept_id, '"', in_array($dept_id, $context['canned_reply']['depts_selected']) ? ' checked="checked"' : '', '></dd>';
211
-	}
212 210
 
213 211
 	echo '
214 212
 				</dl>
215 213
 			</div>
216 214
 			<br>
217
-			<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['save'], '" tabindex="', $context['tabindex']++, '" accesskey="s" class="button">';
215
+			<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['save'], '" tabindex="', $context['tabindex']++, '" accesskey="s" class="button save">';
218 216
 
219 217
 	if ($context['canned_reply']['id'] != 'new')
220 218
 		echo '
221
-			<input type="submit" name="delete" value="', $txt['shd_admin_cannedreplies_deletereply'], '" onclick="return confirm(', JavaScriptEscape($txt['shd_admin_cannedreplies_deletereply_confirm']), ') && submitThisOnce(this);" class="button">';
219
+			<input type="submit" name="delete" value="', $txt['shd_admin_cannedreplies_deletereply'], '" onclick="return confirm(', JavaScriptEscape($txt['shd_admin_cannedreplies_deletereply_confirm']), ');" class="button save">';
222 220
 
223 221
 	echo '
224 222
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
... ...
@@ -264,7 +262,7 @@ function template_shd_move_reply_cat()
264 262
 						</select>
265 263
 					</dd>
266 264
 				</dl>
267
-				<input type="submit" value="', $txt['shd_admin_cannedreplies_movereply'], '" onclick="return submitThisOnce(this);" class="button">
265
+				<input type="submit" value="', $txt['shd_admin_cannedreplies_movereply'], '" class="button save">
268 266
 				<input type="hidden" name="reply" value="', $context['canned_reply_id'], '">
269 267
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
270 268
 				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
... ...
@@ -93,74 +93,59 @@ function template_shd_custom_field_edit()
93 93
 {
94 94
 	global $context, $settings, $txt, $modSettings, $scripturl;
95 95
 
96
+	// !!! TOOD: Move this to admin.js
96 97
 	echo '
97 98
 				<script type="text/javascript"><!-- // --><![CDATA[
98 99
 				function set_fieldicon(filename)
99 100
 				{
100
-					document.getElementById("cf_fieldicon_icon").style.background = "url(" + ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/cf/'), ' + filename + ") no-repeat left";
101
+					$("#cf_fieldicon_icon").css("background", "url(" + ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/cf/'), ' + filename + ") no-repeat left");
101 102
 				}
103
+
102 104
 				function update_field_type(ftype)
103 105
 				{
104
-					var icons = new Array();';
105
-	foreach ($context['field_types'] as $field => $details)
106
-	{
107
-		list($field_desc, $class) = $details;
106
+					var icons = {';
107
+
108
+	foreach ($context['field_types'] as $field => list($field_desc, $class))
108 109
 		echo '
109
-					icons[', $field, '] = ', JavaScriptEscape('cf_ui_' . $class), ';';
110
-	}
110
+						', $field, ': ', JavaScriptEscape('cf_ui_' . $class), ',';
111 111
 
112 112
 	echo '
113
-					document.getElementById("cf_fieldtype_icon").setAttribute("class", icons[ftype]);
114
-
115
-					document.getElementById("max_length_dt").style.display = ftype == ', CFIELD_TYPE_TEXT, ' || ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
116
-					document.getElementById("max_length_dd").style.display = ftype == ', CFIELD_TYPE_TEXT, ' || ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
117
-					document.getElementById("dimension_dt").style.display = ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
118
-					document.getElementById("dimension_dd").style.display = ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
119
-					document.getElementById("bbc_dt").style.display = ftype == ', CFIELD_TYPE_TEXT, ' || ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
120
-					document.getElementById("bbc_dd").style.display = ftype == ', CFIELD_TYPE_TEXT, ' || ftype == ', CFIELD_TYPE_LARGETEXT, ' ? "" : "none";
121
-					document.getElementById("options_dt").style.display = ftype == ', CFIELD_TYPE_SELECT, ' || ftype == ', CFIELD_TYPE_RADIO, ' || ftype == ', CFIELD_TYPE_MULTI, ' ? "" : "none";
122
-					document.getElementById("options_dd").style.display = ftype == ', CFIELD_TYPE_SELECT, ' || ftype == ', CFIELD_TYPE_RADIO, ' || ftype == ', CFIELD_TYPE_MULTI, ' ? "" : "none";
123
-					document.getElementById("default_dt").style.display = ftype == ', CFIELD_TYPE_CHECKBOX, ' ? "" : "none";
124
-					document.getElementById("default_dd").style.display = ftype == ', CFIELD_TYPE_CHECKBOX, ' ? "" : "none";
125
-
126
-					var disp_radio = ftype != ', CFIELD_TYPE_MULTI, ' ? "" : "none";
127
-					var disp_multi = ftype == ', CFIELD_TYPE_MULTI, ' ? "" : "none";
128
-					for (i = 1; i <= startOptID; i++)
129
-					{
130
-						if (d = document.getElementById("radio_" + i))
131
-						{
132
-							d.style.display = disp_radio;
133
-							document.getElementById("multi_" + i).style.display = disp_multi;
134
-						}
135
-					}
136
-					document.getElementById("radio_0").style.display = disp_radio;
137
-					document.getElementById("radio_text_0").style.display = disp_radio;
138
-					document.getElementById("cf_options_radio_default").style.display = disp_radio;
139
-					document.getElementById("cf_options_multi_default").style.display = disp_multi;';
113
+					};
114
+					$("#cf_fieldtype_icon").attr("class", icons[ftype]);';
115
+
116
+	$options = array(
117
+		'max_length' => array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT),
118
+		'dimension' => array(CFIELD_TYPE_LARGETEXT),
119
+		'bbc' => array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT),
120
+		'options' => array(CFIELD_TYPE_SELECT, CFIELD_TYPE_RADIO, CFIELD_TYPE_MULTI),
121
+		'default' => array(CFIELD_TYPE_CHECKBOX)
122
+	);
123
+	foreach ($options as $elId => $ftype)
124
+		echo '
125
+					$("#', $elId, '_dt, #', $elId, '_dd").css("display", ftype == ', implode(' || ftype == ', $ftype), ' ? "" : "none");';
126
+
140 127
 	if (!empty($context['dept_fields']))
141
-	{
142 128
 		echo '
143 129
 					var field_list = [', implode(',', array_keys($context['dept_fields'])), '];
144
-					var cbstyle = ftype != ', CFIELD_TYPE_CHECKBOX, ' ? "" : "none";
145
-					for (i = 0, n = field_list.length; i < n; i++)
146
-					{
147
-						document.getElementById("required_dept" + field_list[i] + "_span").style.display = "";
148
-						document.getElementById("required_dept" + field_list[i]).style.display = ftype == ', CFIELD_TYPE_MULTI, ' ? "none" : "";
149
-						document.getElementById("required_dept_multi_" + field_list[i]).style.display = ftype != ', CFIELD_TYPE_MULTI, ' ? "none" : "";
150
-					}';
151
-	}
130
+					$(field_list).each(function(index, deptID){
131
+						$("#required_dept" + deptID + "_span").css("display", "");
132
+						$("#required_dept" + deptID).css("display", ftype == ', CFIELD_TYPE_MULTI, ' ? "none" : "");
133
+						$("#required_dept_multi_" + deptID).css("display", ftype != ', CFIELD_TYPE_MULTI, ' ? "none" : "");
134
+					});';
135
+
152 136
 	echo '
153 137
 				}
138
+
154 139
 				function updateDeptHidden(id)
155 140
 				{
156
-					var state = !document.getElementById("present_dept" + id).checked;
157
-					document.getElementById("required_dept" + id).disabled = state;
158
-					document.getElementById("required_dept_multi_" + id).disabled = state;
141
+					var state = !$("#present_dept" + id).is(":checked");
142
+					$("#required_dept" + id + ", #required_dept_multi_" + id).prop("disabled", state);
159 143
 				}
144
+
160 145
 				var startOptID = ', !empty($context['custom_field']['options']['order']) ? count($context['custom_field']['options']['order']) + 1 : 1, ';
161 146
 				function add_option()
162 147
 				{
163
-					var ftype = document.getElementById("cf_fieldtype").value;
148
+					var ftype = $("#cf_fieldtype").val();
164 149
 					var newHTML = \'<br id="break_\' + startOptID + \'"><input type="radio" id="radio_\' + startOptID + \'" name="default_select" value="\' + startOptID + \'" id="\' + startOptID + \'"\';
165 150
 					if (ftype == ', CFIELD_TYPE_MULTI, ')
166 151
 						newHTML += \' style="display:none;"\';
... ...
@@ -170,8 +155,8 @@ function template_shd_custom_field_edit()
170 155
 						newHTML += \' style="display:none;"\';
171 156
 					newHTML += \'><input type="text" id="option_\' + startOptID + \'" name="select_option[\' + startOptID + \']" value="">\' + "\n";
172 157
 					newHTML += \'<span id="order_\' + startOptID + \'" class="custom_field_order"><input id="order_\' + startOptID + \'_input" type="hidden" name="order[\' + startOptID + \']" value="\' + (startOptID - 1) + \'" data-key="\' + startOptID + \'">\' + "\n";
173
-					newHTML += \'<a href="#" class="custom_field_move_up" data-key="\' + startOptID + \'"><img src="', $settings['default_images_url'], '/simpledesk/move_up.png" class="icon" alt="', $txt['custom_edit_order_up'], '" title="', $txt['custom_edit_order_up'], '"/></a>\';
174
-					newHTML += \'<a href="#" class="custom_field_move_down" data-key="\' + startOptID + \'"><img src="', $settings['default_images_url'], '/simpledesk/move_down.png" class="icon" alt="', $txt['custom_edit_order_down'], '" title="', $txt['custom_edit_order_down'], '"/></a>\';
158
+					newHTML += \'<a href="#" class="custom_field_move_up" data-key="\' + startOptID + \'"><img src="', $settings['default_images_url'], '/simpledesk/move_up.png" class="icon" alt="', $txt['custom_edit_order_up'], '" title="', $txt['custom_edit_order_up'], '"></a>\';
159
+					newHTML += \'<a href="#" class="custom_field_move_down" data-key="\' + startOptID + \'"><img src="', $settings['default_images_url'], '/simpledesk/move_down.png" class="icon" alt="', $txt['custom_edit_order_down'], '" title="', $txt['custom_edit_order_down'], '"></a>\';
175 160
 					newHTML += \'</span>\' + "\n";
176 161
 
177 162
 					newHTML += \'<span id="addopt"></span>\';
... ...
@@ -181,38 +166,39 @@ function template_shd_custom_field_edit()
181 166
 
182 167
 					optionsOrder.resortNew();
183 168
 				}
169
+
184 170
 				function update_default_label(defstate)
185 171
 				{
186
-					if (defstate)
187
-						document.getElementById("default_label").innerHTML = "', $txt['shd_admin_default_state_on'], '";
188
-					else
189
-						document.getElementById("default_label").innerHTML = "', $txt['shd_admin_default_state_off'], '";
172
+					$("#default_label").html(defstate ? "', $txt['shd_admin_default_state_on'], '" : "', $txt['shd_admin_default_state_off'], '");
190 173
 				}
174
+
191 175
 				function update_required(state)
192 176
 				{
193 177
 					if (state)
194 178
 					{
195
-						document.getElementById("cf_display_empty").disabled = "disabled";
196
-						document.getElementById("cf_display_empty").checked = "";
197
-						document.getElementById("display_empty_dt").className = "disabled";
179
+						$("#cf_display_empty").css("disabled", "disabled").attr("checked", "");
180
+						$("#display_empty_dt").attr("class", "disabled");
198 181
 					}
199 182
 					else
200 183
 					{
201
-						document.getElementById("cf_display_empty").disabled = "";
202
-						document.getElementById("display_empty_dt").className = "";
184
+						$("#cf_display_empty").css("disabled", "");
185
+						$("#display_empty_dt").attr("className", "");
203 186
 					}
204 187
 				}
188
+
205 189
 				function update_permissions(state,role)
206 190
 				{
207
-					document.getElementById("edit_" + role).disabled = state == "on" ? "" : "disabled";
208
-					document.getElementById("edit_" + role).checked = state == "on" ? "" : "";
191
+					$("#edit_" + role).prop("disabled", state == "on" ? true : false);
192
+					$("#edit_" + role).attr("checked", state == "on" ? "" : "");
209 193
 				}
194
+
210 195
 				function update_field_location(loc)
211 196
 				{
212
-					document.getElementById("placement_dt").style.display = loc == ', CFIELD_TICKET, ' || loc == ', (CFIELD_TICKET | CFIELD_REPLY), ' ? "" : "none";
213
-					document.getElementById("placement_dd").style.display = loc == ', CFIELD_TICKET, ' || loc == ', (CFIELD_TICKET | CFIELD_REPLY), ' ? "" : "none";
197
+					$("#placement_dt").css("display", loc == ', CFIELD_TICKET, ' || loc == ', (CFIELD_TICKET | CFIELD_REPLY), ' ? "" : "none");
198
+					$("#placement_dd").css("display", loc == ', CFIELD_TICKET, ' || loc == ', (CFIELD_TICKET | CFIELD_REPLY), ' ? "" : "none");
214 199
 				}
215 200
 				// ]', ']></script>
201
+
216 202
 				<form action="', $scripturl, '?action=admin;area=helpdesk_customfield;sa=save', !empty($context['new_field']) ? ';new' : '', '" method="post">
217 203
 					<div class="cat_bar">
218 204
 						<h3 class="catbg">
... ...
@@ -242,12 +228,9 @@ function template_shd_custom_field_edit()
242 228
 								<span id="cf_fieldicon_icon"', $context['field_icon_value'] != '' ? ' style="background: url(' . $settings['images_url'] . '/simpledesk/cf/' . $context['field_icon_value'] . ') no-repeat left;"' : '', '></span>
243 229
 								<select name="field_icon" id="cf_fieldicon" onchange="javascript:set_fieldicon(this.value);">';
244 230
 
245
-	foreach ($context['field_icons'] as $icon)
246
-	{
247
-		list($file, $desc) = $icon;
231
+	foreach ($context['field_icons'] as list($file, $desc))
248 232
 		echo '
249 233
 									<option value="', $file, '"', $context['field_icon_value'] == $file ? ' selected="selected"' : '', '>', $desc, '</option>';
250
-	}
251 234
 
252 235
 	echo '
253 236
 								</select>
... ...
@@ -261,8 +244,8 @@ function template_shd_custom_field_edit()
261 244
 									<option value="', (CFIELD_TICKET | CFIELD_REPLY), '"', ($context['field_loc'] == (CFIELD_TICKET | CFIELD_REPLY) ? ' selected="selected"' : ''), '>', $txt['shd_admin_custom_fields_visible_both'], '</option>
262 245
 								</select>
263 246
 							</dd>
264
-							<dt id="placement_dt"', (($context['field_loc'] == CFIELD_TICKET || $context['field_loc'] == (CFIELD_TICKET | CFIELD_REPLY)) ? '' : ' style="display: none;"'), '><strong>', $txt['shd_admin_custom_field_placement'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_placement_desc'], '</span></dt>
265
-							<dd id="placement_dd"', (($context['field_loc'] == CFIELD_TICKET || $context['field_loc'] == (CFIELD_TICKET | CFIELD_REPLY)) ? '' : ' style="display: none;"'), '>
247
+							<dt id="placement_dt"', (($context['field_loc'] == CFIELD_TICKET || $context['field_loc'] == (CFIELD_TICKET | CFIELD_REPLY)) ? '' : ' class="hidden"'), '><strong>', $txt['shd_admin_custom_field_placement'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_placement_desc'], '</span></dt>
248
+							<dd id="placement_dd"', (($context['field_loc'] == CFIELD_TICKET || $context['field_loc'] == (CFIELD_TICKET | CFIELD_REPLY)) ? '' : ' class="hidden"'), '>
266 249
 								<select name="placement" id="cf_placement">
267 250
 									<option id="details" value="', CFIELD_PLACE_DETAILS, '"', ($context['placement'] == CFIELD_PLACE_DETAILS ? ' selected="selected"' : ''), '>', $txt['shd_admin_custom_field_placement_details'], '</option>
268 251
 									<option id="place_info" value="', CFIELD_PLACE_INFO, '"', ($context['placement'] == CFIELD_PLACE_INFO ? ' selected="selected"' : ''), '>', $txt['shd_admin_custom_field_placement_information'], '</option>
... ...
@@ -272,15 +255,15 @@ function template_shd_custom_field_edit()
272 255
 							</dd>
273 256
 							<dt><strong>', $txt['shd_admin_custom_field_can_see'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_can_see_desc'], '</span></dt>
274 257
 							<dd>
275
-								<input type="checkbox" name="see_users"', !empty($context['custom_field']['can_see'][0]) && $context['custom_field']['can_see'][0] == 1 ? ' checked="checked"' : '', ' onchange="javascript:update_permissions(this.value,\'users\');"/> <img src="', $settings['default_images_url'], '/simpledesk/user.png" class="icon" alt="', $txt['shd_admin_custom_field_users'], '" title="', $txt['shd_admin_custom_field_users'], '"/>
276
-								<input type="checkbox" name="see_staff"', !empty($context['custom_field']['can_see'][1]) && $context['custom_field']['can_see'][1] == 1 ? ' checked="checked"' : '', ' onchange="javascript:update_permissions(this.value,\'staff\');"/> <img src="', $settings['default_images_url'], '/simpledesk/staff.png" class="icon" alt="', $txt['shd_admin_custom_field_staff'], '" title="', $txt['shd_admin_custom_field_staff'], '"/>
258
+								<input type="checkbox" name="see_users"', !empty($context['custom_field']['can_see'][0]) && $context['custom_field']['can_see'][0] == 1 ? ' checked="checked"' : '', ' onchange="javascript:update_permissions(this.value,\'users\');"><img src="', $settings['default_images_url'], '/simpledesk/user.png" class="icon" alt="', $txt['shd_admin_custom_field_users'], '" title="', $txt['shd_admin_custom_field_users'], '">
259
+								<input type="checkbox" name="see_staff"', !empty($context['custom_field']['can_see'][1]) && $context['custom_field']['can_see'][1] == 1 ? ' checked="checked"' : '', ' onchange="javascript:update_permissions(this.value,\'staff\');"><img src="', $settings['default_images_url'], '/simpledesk/staff.png" class="icon" alt="', $txt['shd_admin_custom_field_staff'], '" title="', $txt['shd_admin_custom_field_staff'], '">
277 260
 								<input type="checkbox" name="see_admin" checked="checked" disabled="disabled"><img src="', $settings['default_images_url'], '/simpledesk/admin.png" class="icon" alt="', $txt['shd_admin_custom_field_admins'], '" title="', $txt['shd_admin_custom_field_admins'], '">
278 261
 							</dd>
279 262
 							<dt><strong>', $txt['shd_admin_custom_field_can_edit'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_can_edit_desc'], '</span></dt>
280 263
 							<dd>
281
-								<input type="checkbox" name="edit_users" id="edit_users"', !empty($context['custom_field']['can_edit'][0]) && $context['custom_field']['can_edit'][0] == 1 ? ' checked="checked"' : '', !empty($context['custom_field']['can_see'][0]) && $context['custom_field']['can_see'][0] == 1 ? '' : ' disabled="disabled"', '/> <img src="', $settings['default_images_url'], '/simpledesk/user.png" class="icon" alt="', $txt['shd_admin_custom_field_users'], '" title="', $txt['shd_admin_custom_field_users'], '"/>
282
-								<input type="checkbox" name="edit_staff" id="edit_staff"  ', !empty($context['custom_field']['can_edit'][1]) && $context['custom_field']['can_edit'][1] == 1 ? 'checked="checked"' : '', !empty($context['custom_field']['can_see'][1]) && $context['custom_field']['can_see'][1] == 1 ? '' : ' disabled="disabled"', '/> <img src="', $settings['default_images_url'], '/simpledesk/staff.png" class="icon" alt="', $txt['shd_admin_custom_field_staff'], '" title="', $txt['shd_admin_custom_field_staff'], '"/>
283
-								<input type="checkbox" name="edit_admin"  checked="checked" disabled="disabled"> <img src="', $settings['default_images_url'], '/simpledesk/admin.png" class="icon" alt="', $txt['shd_admin_custom_field_admins'], '" title="', $txt['shd_admin_custom_field_admins'], '"/>
264
+								<input type="checkbox" name="edit_users" id="edit_users"', !empty($context['custom_field']['can_edit'][0]) && $context['custom_field']['can_edit'][0] == 1 ? ' checked="checked"' : '', !empty($context['custom_field']['can_see'][0]) && $context['custom_field']['can_see'][0] == 1 ? '' : ' disabled="disabled"', '><img src="', $settings['default_images_url'], '/simpledesk/user.png" class="icon" alt="', $txt['shd_admin_custom_field_users'], '" title="', $txt['shd_admin_custom_field_users'], '">
265
+								<input type="checkbox" name="edit_staff" id="edit_staff"', !empty($context['custom_field']['can_edit'][1]) && $context['custom_field']['can_edit'][1] == 1 ? ' checked="checked"' : '', !empty($context['custom_field']['can_see'][1]) && $context['custom_field']['can_see'][1] == 1 ? '' : ' disabled="disabled"', '><img src="', $settings['default_images_url'], '/simpledesk/staff.png" class="icon" alt="', $txt['shd_admin_custom_field_staff'], '" title="', $txt['shd_admin_custom_field_staff'], '">
266
+								<input type="checkbox" name="edit_admin" checked="checked" disabled="disabled"><img src="', $settings['default_images_url'], '/simpledesk/admin.png" class="icon" alt="', $txt['shd_admin_custom_field_admins'], '" title="', $txt['shd_admin_custom_field_admins'], '">
284 267
 							</dd>
285 268
 						</dl>
286 269
 					</div>
... ...
@@ -297,42 +280,39 @@ function template_shd_custom_field_edit()
297 280
 								<span id="cf_fieldtype_icon" class="cf_ui_', $context['field_types'][$context['field_type_value']][1], '"></span>
298 281
 								<select name="field_type" id="cf_fieldtype" onchange="javascript:update_field_type(this.value);">';
299 282
 
300
-	foreach ($context['field_types'] as $field => $details)
301
-	{
302
-		list($field_desc,) = $details;
283
+	foreach ($context['field_types'] as $field => list($field_desc,))
303 284
 		echo '
304 285
 									<option value="', $field, '"', ($context['field_type_value'] == $field ? ' selected="selected"' : ''), '>', $field_desc, '</option>';
305
-	}
306 286
 
307 287
 	echo '
308 288
 								</select>
309 289
 							</dd>
310
-							<dt id="max_length_dt"', in_array($context['field_type_value'], array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT)) ? '' : ' style="display: none;"', '><strong>', $txt['shd_admin_custom_field_maxlength'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_maxlength_desc'], '</span></dt>
311
-							<dd id="max_length_dd"', in_array($context['field_type_value'], array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT)) ? '' : ' style="display: none;"', '>
290
+							<dt id="max_length_dt"', in_array($context['field_type_value'], array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT)) ? '' : ' class="hidden"', '><strong>', $txt['shd_admin_custom_field_maxlength'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_maxlength_desc'], '</span></dt>
291
+							<dd id="max_length_dd"', in_array($context['field_type_value'], array(CFIELD_TYPE_TEXT, CFIELD_TYPE_LARGETEXT)) ? '' : ' class="hidden"', '>
312 292
 								<input type="text" value="', isset($context['custom_field']['field_length']) ? $context['custom_field']['field_length'] : 255, '" size="7" maxlength="6" name="field_length" id="cf_field_length">
313 293
 							</dd>
314
-							<dt id="dimension_dt"', $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' style="display: none;"', '>
294
+							<dt id="dimension_dt"', $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' class="hidden"', '>
315 295
 								<strong>', $txt['shd_admin_custom_field_dimensions'], ':</strong>
316 296
 							</dt>
317
-							<dd id="dimension_dd"', $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' style="display: none;"', '>
297
+							<dd id="dimension_dd"', $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' class="hidden"', '>
318 298
 								<strong>', $txt['shd_admin_custom_field_dimensions_rows'], ':</strong><input type="text" name="rows" value="', !empty($context['custom_field']['dimensions'][0]) ? $context['custom_field']['dimensions'][0] : 4, '" size="5" maxlength="3">
319 299
 								<strong>', $txt['shd_admin_custom_field_dimensions_columns'], ':</strong><input type="text" name="cols" value="', !empty($context['custom_field']['dimensions'][1]) ? $context['custom_field']['dimensions'][1] : 30, '" size="5" maxlength="3">
320 300
 							</dd>
321
-							<dt id="bbc_dt"', $context['field_type_value'] == CFIELD_TYPE_TEXT || $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' style="display: none;"', '><strong', empty($modSettings['shd_allow_ticket_bbc']) ? ' class="disabled"' : '', '>', $txt['shd_admin_custom_field_bbc'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_bbc_note'], '</span><br>', empty($modSettings['shd_allow_ticket_bbc']) ? '<span class="smalltext error">' . sprintf($txt['shd_admin_custom_field_bbc_off'], $scripturl . '?action=admin;area=helpdesk_options;sa=posting'). '</span>' : '', '</dt>
322
-							<dd id="bbc_dd"', $context['field_type_value'] == CFIELD_TYPE_TEXT || $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' style="display: none;"', '>
301
+							<dt id="bbc_dt"', $context['field_type_value'] == CFIELD_TYPE_TEXT || $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' class="hidden"', '><strong', empty($modSettings['shd_allow_ticket_bbc']) ? ' class="disabled"' : '', '>', $txt['shd_admin_custom_field_bbc'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_bbc_note'], '</span><br>', empty($modSettings['shd_allow_ticket_bbc']) ? '<span class="smalltext error">' . sprintf($txt['shd_admin_custom_field_bbc_off'], $scripturl . '?action=admin;area=helpdesk_options;sa=posting'). '</span>' : '', '</dt>
302
+							<dd id="bbc_dd"', $context['field_type_value'] == CFIELD_TYPE_TEXT || $context['field_type_value'] == CFIELD_TYPE_LARGETEXT ? '' : ' class="hidden"', '>
323 303
 								<input type="checkbox" name="bbc" id="cf_bbc"',empty($modSettings['shd_allow_ticket_bbc']) ? ' disabled="disabled"' : (!empty($context['custom_field']['bbc']) ? ' checked="checked"' : ''), '>
324 304
 							</dd>
325
-							<dt id="options_dt"', in_array($context['field_type_value'], array(CFIELD_TYPE_SELECT, CFIELD_TYPE_RADIO, CFIELD_TYPE_MULTI)) ? '' : ' style="display: none;"', '>
305
+							<dt id="options_dt"', in_array($context['field_type_value'], array(CFIELD_TYPE_SELECT, CFIELD_TYPE_RADIO, CFIELD_TYPE_MULTI)) ? '' : ' class="hidden"', '>
326 306
 								<strong>', $txt['shd_admin_custom_field_options'], ':</strong>
327 307
 								<div class="smalltext">
328 308
 									', $txt['shd_admin_custom_field_options_desc'], '
329
-									<span id="cf_options_radio_default"', $context['field_type_value'] == CFIELD_TYPE_SELECT || $context['field_type_value'] == CFIELD_TYPE_RADIO ? ' style=""' : ' style="display:none;"', '>', $txt['shd_admin_custom_field_options_radio'], '</span>
330
-									<span id="cf_options_multi_default"', $context['field_type_value'] == CFIELD_TYPE_MULTI ? ' style=""' : ' style="display:none;"', '>', $txt['shd_admin_custom_field_options_multi'], '</span>
309
+									<span id="cf_options_radio_default"', $context['field_type_value'] == CFIELD_TYPE_SELECT || $context['field_type_value'] == CFIELD_TYPE_RADIO ? '' : ' class="hidden"', '>', $txt['shd_admin_custom_field_options_radio'], '</span>
310
+									<span id="cf_options_multi_default"', $context['field_type_value'] == CFIELD_TYPE_MULTI ? '' : ' class="hidden"', '>', $txt['shd_admin_custom_field_options_multi'], '</span>
331 311
 								</div>
332 312
 							</dt>
333
-							<dd id="options_dd"', in_array($context['field_type_value'], array(CFIELD_TYPE_SELECT, CFIELD_TYPE_RADIO, CFIELD_TYPE_MULTI)) ? '' : ' style="display: none;"', '>								
334
-								<input type="radio" id="radio_0" name="default_select" value="0"', $context['custom_field']['default_value'] == 0 ? ' checked="checked"' : '', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' style="display:none;"', '>
335
-								<span id="radio_text_0"', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' style="display:none;"', '>', $txt['shd_admin_custom_field_no_selected_default'], '</span>
313
+							<dd id="options_dd"', in_array($context['field_type_value'], array(CFIELD_TYPE_SELECT, CFIELD_TYPE_RADIO, CFIELD_TYPE_MULTI)) ? '' : ' class="hidden"', '>								
314
+								<input type="radio" id="radio_0" name="default_select" value="0"', $context['custom_field']['default_value'] == 0 ? ' checked="checked"' : '', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' class="hidden"', '>
315
+								<span id="radio_text_0"', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' class="hidden"', '>', $txt['shd_admin_custom_field_no_selected_default'], '</span>
336 316
 								<div id="custom_fields_list">';
337 317
 
338 318
 	// Convert it to an array for displaying the main doodah
... ...
@@ -347,13 +327,13 @@ function template_shd_custom_field_edit()
347 327
 
348 328
 		echo '
349 329
 									<br id="break_', $k, '">
350
-									<input type="radio" id="radio_', $k, '" name="default_select" value="', $k, '"', $context['field_type_value'] != CFIELD_TYPE_MULTI && $context['custom_field']['default_value'] == $k ? ' checked="checked"' : '', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' style="display:none;"', '>
351
-									<input type="checkbox" id="multi_', $k, '" name="default_select_multi[', $k, ']" value="', $k, '"', $context['field_type_value'] == CFIELD_TYPE_MULTI && in_array($k, $context['custom_field']['default_value']) ? ' checked="checked"' : '', $context['field_type_value'] == CFIELD_TYPE_MULTI ? '' : ' style="display:none;"', '>
330
+									<input type="radio" id="radio_', $k, '" name="default_select" value="', $k, '"', $context['field_type_value'] != CFIELD_TYPE_MULTI && $context['custom_field']['default_value'] == $k ? ' checked="checked"' : '', $context['field_type_value'] != CFIELD_TYPE_MULTI ? '' : ' class="hidden"', '>
331
+									<input type="checkbox" id="multi_', $k, '" name="default_select_multi[', $k, ']" value="', $k, '"', $context['field_type_value'] == CFIELD_TYPE_MULTI && in_array($k, $context['custom_field']['default_value']) ? ' checked="checked"' : '', $context['field_type_value'] == CFIELD_TYPE_MULTI ? '' : ' class="hidden"', '>
352 332
 									<input type="text" id="option_', $k, '" name="select_option[', $k, ']" value="', $option, '">
353 333
 									<span id="order_', $k, '" class="custom_field_order"><input id="order_', $k, '_input" type="hidden" name="order[', $k, ']" value="', $order, '" data-key="', $k, '">';
354 334
 
355
-			echo '<a href="#" class="custom_field_move_up" data-key="', $k, '"', $context['custom_field']['order_first'] == $k ? ' style="display:none;"' : '', '><img src="', $settings['default_images_url'], '/simpledesk/move_up.png" class="icon" alt="', $txt['custom_edit_order_up'], '" title="', $txt['custom_edit_order_up'], '"/></a>';
356
-			echo '<a href="#" class="custom_field_move_down" data-key="', $k, '"', $context['custom_field']['order_last'] == $k ? ' style="display:none;"' : '', '><img src="', $settings['default_images_url'], '/simpledesk/move_down.png" class="icon" alt="', $txt['custom_edit_order_down'], '" title="', $txt['custom_edit_order_down'], '"/></a>';
335
+			echo '<a href="#" class="custom_field_move_up" data-key="', $k, '"', $context['custom_field']['order_first'] == $k ? ' style="display:none;"' : '', '><img src="', $settings['default_images_url'], '/simpledesk/move_up.png" class="icon" alt="', $txt['custom_edit_order_up'], '" title="', $txt['custom_edit_order_up'], '"></a>';
336
+			echo '<a href="#" class="custom_field_move_down" data-key="', $k, '"', $context['custom_field']['order_last'] == $k ? ' style="display:none;"' : '', '><img src="', $settings['default_images_url'], '/simpledesk/move_down.png" class="icon" alt="', $txt['custom_edit_order_down'], '" title="', $txt['custom_edit_order_down'], '"></a>';
357 337
 
358 338
 		echo '</span>';
359 339
 
... ...
@@ -364,16 +344,16 @@ function template_shd_custom_field_edit()
364 344
 								</div>
365 345
 								<span id="addopt_link">[<a href="" onclick="add_option(); return false;">', $txt['more'], '</a>]</span>
366 346
 							</dd>
367
-							<dt id="default_dt"', $context['field_type_value'] == CFIELD_TYPE_CHECKBOX ? '' : ' style="display: none;"', '>
347
+							<dt id="default_dt"', $context['field_type_value'] == CFIELD_TYPE_CHECKBOX ? '' : ' class="hidden"', '>
368 348
 								<strong>', $txt['shd_admin_custom_field_default_state'], ':</strong>
369 349
 							</dt>
370
-							<dd id="default_dd"', $context['field_type_value'] == CFIELD_TYPE_CHECKBOX ? '' : ' style="display: none;"', '>
350
+							<dd id="default_dd"', $context['field_type_value'] == CFIELD_TYPE_CHECKBOX ? '' : ' class="hidden"', '>
371 351
 								<input type="checkbox" name="default_check" ',($context['custom_field']['default_value'] == 1 ? ' checked="checked"' : ''), ' onclick="update_default_label(this.checked);">
372 352
 								<span class="smalltext" id="default_label">', $txt['shd_admin_default_state_' . ($context['custom_field']['default_value'] == 1 ? 'on' : 'off')], '</span>
373 353
 							</dd>
374 354
 							<dt id="display_empty_dt"><strong>', $txt['shd_admin_custom_field_display_empty'], ':</strong><br><span class="smalltext">', $txt['shd_admin_custom_field_display_empty_desc'], '</span></dt>
375 355
 							<dd id="display_empty_dd">
376
-								<input type="checkbox" ', (!empty($context['custom_field']['display_empty']) && $context['custom_field']['display_empty'] == 1 ? ' checked="checked"' : ''), ' name="display_empty" id="cf_display_empty"', (!empty($context['custom_field']['required']) && $context['custom_field']['required'] == 1 ? ' disabled="disabled"' : ''), '/>
356
+								<input type="checkbox" ', (!empty($context['custom_field']['display_empty']) && $context['custom_field']['display_empty'] == 1 ? ' checked="checked"' : ''), ' name="display_empty" id="cf_display_empty"', (!empty($context['custom_field']['required']) && $context['custom_field']['required'] == 1 ? ' disabled="disabled"' : ''), '>
377 357
 							</dd>
378 358
 						</dl>
379 359
 					</div>';
... ...
@@ -130,7 +130,7 @@ function template_shd_create_dept()
130 130
 					<dd><textarea name="dept_desc" rows="3" cols="35" style="width: 99%"></textarea></dd>
131 131
 					<dt><strong>', $txt['shd_dept_boardindex_cat'], '</strong></dt>
132 132
 					<dd>
133
-						<select name="dept_cat" id="dept_cat" onchange="document.getElementById(\'dept_beforeafter\').disabled = (this.value == 0);">';
133
+						<select name="dept_cat" id="dept_cat" onchange="$(\'#dept_beforeafter\').attr(\'disabled\' ? (this.value == 0));">';
134 134
 
135 135
 	foreach ($context['shd_cat_list'] as $id_cat => $cat_name)
136 136
 		echo '
... ...
@@ -180,10 +180,10 @@ function template_shd_edit_dept()
180 180
 					<dt><strong>', $txt['shd_department_name'], '</strong></dt>
181 181
 					<dd><input type="text" name="dept_name" id="dept_name" value="', $context['shd_dept']['dept_name'], '" size="30"></dd>
182 182
 					<dt><strong>', $txt['shd_dept_description'], '</strong></dt>
183
-					<dd><textarea name="dept_desc" rows="3" cols="35" style="width: 99%">', $context['shd_dept']['description'], '</textarea></dd>
183
+					<dd><textarea name="dept_desc" rows="3" cols="35">', $context['shd_dept']['description'], '</textarea></dd>
184 184
 					<dt><strong>', $txt['shd_dept_boardindex_cat'], '</strong></dt>
185 185
 					<dd>
186
-						<select name="dept_cat" id="dept_cat" onchange="document.getElementById(\'dept_beforeafter\').disabled = (this.value == 0);">';
186
+						<select name="dept_cat" id="dept_cat" onchange="$(\'#dept_beforeafter\').attr(\'disabled\' ? (this.value == 0));">';
187 187
 
188 188
 	foreach ($context['shd_cat_list'] as $id_cat => $cat_name)
189 189
 		echo '
... ...
@@ -263,7 +263,7 @@ function template_shd_edit_dept()
263 263
 				<br>
264 264
 			</div>
265 265
 			<div class="floatleft">
266
-				<input type="submit" value="', $txt['shd_edit_dept'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
266
+				<input type="submit" value="', $txt['shd_edit_dept'], '" accesskey="s" class="button save">
267 267
 				<input type="submit" value="', $txt['shd_delete_dept'], '" onclick="return confirm(' . JavaScriptEscape($txt['shd_delete_dept_confirm']) . ');" name="delete" class="button">
268 268
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
269 269
 				<input type="hidden" name="dept" value="', $context['shd_dept']['id_dept'], '">
... ...
@@ -40,40 +40,9 @@ function template_shd_admin_maint_home()
40 40
 
41 41
 		function checkAttributeValidity()
42 42
 		{
43
-			origText = \'', $txt['shd_reattribute_confirm'], '\';
44
-			origTextStarter = \'', $txt['shd_reattribute_confirm_starter'], '\';
45
-			valid = true;
46 43
 
47
-			// Do all the fields!
48
-			if (!document.getElementById(\'to\').value)
49
-				valid = false;
50
-			warningMessage = origText.replace(/%member_to%/, document.getElementById(\'to\').value);
51
-
52
-			if (document.getElementById(\'type_email\').checked)
53
-			{
54
-				if (!document.getElementById(\'from_email\').value)
55
-					valid = false;
56
-				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['shd_reattribute_confirm_email'], "'"), '\').replace(/%find%/, document.getElementById(\'from_email\').value);
57
-			}
58
-			else if (document.getElementById(\'type_starter\').checked)
59
-			{
60
-				if (!document.getElementById(\'from_starter\').value)
61
-					valid = false;
62
-				warningMessage = origTextStarter.replace(/%member_to%/, document.getElementById(\'to\').value).replace(/%find%/, document.getElementById(\'from_starter\').value);			
63
-			}
64
-			else
65
-			{
66
-				if (!document.getElementById(\'from_name\').value)
67
-					valid = false;
68
-				warningMessage = warningMessage.replace(/%type%/, \'', addcslashes($txt['shd_reattribute_confirm_username'], "'"), '\').replace(/%find%/, document.getElementById(\'from_name\').value);
69 44
 		}
70
-
71
-			document.getElementById(\'do_attribute\').disabled = valid ? \'\' : \'disabled\';
72
-
73
-			setTimeout("checkAttributeValidity();", 500);
74
-			return valid;
75
-		}
76
-		setTimeout("checkAttributeValidity();", 500);
45
+		/*setTimeout("checkAttributeValidity();", 500);*/
77 46
 		// ]]></script>
78 47
 		<div class="cat_bar">
79 48
 			<h3 class="catbg">
... ...
@@ -92,19 +62,21 @@ function template_shd_admin_maint_home()
92 62
 						<label for="type_email"><input type="radio" name="type" id="type_email" value="email" checked="checked">', $txt['shd_admin_maint_reattribute_posts_email'], '</label>
93 63
 					</dt>
94 64
 					<dd>
95
-						<input type="text" name="from_email" id="from_email" value="" onclick="document.getElementById(\'type_email\').checked = \'checked\'; document.getElementById(\'from_name\').value = \'\'; document.getElementById(\'from_starter\').value = \'\';">
65
+						<input type="text" name="from_email" id="from_email" value="">
96 66
 					</dd>
67
+
97 68
 					<dt>
98 69
 						<label for="type_name"><input type="radio" name="type" id="type_name" value="name">', $txt['shd_admin_maint_reattribute_posts_user'], '</label>
99 70
 					</dt>
100 71
 					<dd>
101
-						<input type="text" name="from_name" id="from_name" value="" onclick="document.getElementById(\'type_name\').checked = \'checked\'; document.getElementById(\'from_email\').value = \'\'; document.getElementById(\'from_starter\').value = \'\';" >
72
+						<input type="text" name="from_name" id="from_name" value="">
102 73
 					</dd>
74
+
103 75
 					<dt>
104 76
 						<label for="type_name"><input type="radio" name="type" id="type_starter" value="starter">', $txt['shd_admin_maint_reattribute_posts_starter'], '</label>
105 77
 					</dt>
106 78
 					<dd>
107
-						<input type="text" name="from_starter" id="from_starter" value="" onclick="document.getElementById(\'type_starter\').checked = \'checked\'; document.getElementById(\'from_email\').value = \'\'; document.getElementById(\'from_name\').value = \'\';" >
79
+						<input type="text" name="from_starter" id="from_starter" value="">
108 80
 					</dd>
109 81
 				</dl>
110 82
 				<dl class="settings">
... ...
@@ -115,32 +87,47 @@ function template_shd_admin_maint_home()
115 87
 						<input type="text" name="to" id="to" value="">
116 88
 					</dd>
117 89
 				</dl>
118
-				<input type="submit" id="do_attribute" value="', $txt['shd_admin_maint_reattribute_btn'], '" onclick="if (!checkAttributeValidity()) return false; return confirm(warningMessage);" class="button">
90
+				<input type="submit" id="do_attribute" value="', $txt['shd_admin_maint_reattribute_btn'], '" onclicks="if (!checkAttributeValidity()) return false; return confirm(warningMessage);" class="button">
119 91
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
120 92
 			</form>
121 93
 		</div>
122 94
 		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?rc5"></script>
123 95
 		<script type="text/javascript"><!-- // --><![CDATA[
124 96
 			var oAttributeMemberSuggest = new smc_AutoSuggest({
125
-				sSelf: \'oAttributeMemberSuggest\',
126
-				sSessionId: \'', $context['session_id'], '\',
127
-				sSessionVar: \'', $context['session_var'], '\',
128
-				sSuggestId: \'attributeMember\',
129
-				sControlId: \'to\',
130
-				sSearchType: \'member\',
131
-				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
97
+				sSelf: "oAttributeMemberSuggest",
98
+				sSessionId: "', $context['session_id'], '",
99
+				sSessionVar: "', $context['session_var'], '",
100
+				sSuggestId: "attributeMember",
101
+				sControlId: "to",
102
+				sSearchType: "member",
103
+				sTextDeleteItem: ', JavaScriptEscape($txt['autosuggest_delete_item']), ',
132 104
 				bItemList: false
133 105
 			});
134 106
 			var oAttributeMemberSuggestStarter = new smc_AutoSuggest({
135
-				sSelf: \'oAttributeMemberSuggestStarter\',
136
-				sSessionId: \'', $context['session_id'], '\',
137
-				sSessionVar: \'', $context['session_var'], '\',
138
-				sSuggestId: \'attributeStarter\',
139
-				sControlId: \'from_starter\',
140
-				sSearchType: \'member\',
141
-				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
107
+				sSelf: "oAttributeMemberSuggestStarter",
108
+				sSessionId: "', $context['session_id'], '",
109
+				sSessionVar: "', $context['session_var'], '",
110
+				sSuggestId: "attributeStarter",
111
+				sControlId: "from_starter",
112
+				sSearchType: "member",
113
+				sTextDeleteItem: ', JavaScriptEscape($txt['autosuggest_delete_item']), ',
142 114
 				bItemList: false
143 115
 			});
116
+
117
+			var oAttributeValidator = new shd_AttributeValidate({
118
+				sOrigText: ', JavaScriptEscape($txt['shd_reattribute_confirm']), ',
119
+				sOrigTextStarter: ', JavaScriptEscape($txt['shd_reattribute_confirm_starter']), ',
120
+				sDoAttributeContainerId: "do_attribute",
121
+				sToContainerId: "to",
122
+				sTypeEmailContainerId: "type_email",
123
+				sEmailContainerId: "from_email",
124
+				sEmailConfirmText: ', JavaScriptEscape($txt['shd_reattribute_confirm_email']), ',
125
+				sTypeStarterContainerId: "type_starter",
126
+				sStarterContainerId: "from_starter",
127
+				sTypeFromContainerId: "type_name",
128
+				sFromContainerId: "from_name",
129
+				sFromConfirmText: ', JavaScriptEscape($txt['shd_reattribute_confirm_username']), ',
130
+			});
144 131
 		// ]]></script>';
145 132
 
146 133
 	// Moving home?
... ...
@@ -184,7 +171,7 @@ function template_shd_admin_maint_home()
184 171
 					<dt><input type="checkbox" id="movelast_less" name="movelast_less"> ', sprintf($txt['shd_admin_maint_massdeptmove_lastupd_less'], '<input type="text" name="movelast_less_days" value="30" size="3">'), '</dt>
185 172
 					<dt><input type="checkbox" id="movelast_more" name="movelast_more"> ', sprintf($txt['shd_admin_maint_massdeptmove_lastupd_more'], '<input type="text" name="movelast_more_days" value="30" size="3">'), '</dt>
186 173
 				</dl>
187
-				<input type="submit" value="', $txt['shd_admin_maint_massdeptmove'], '" onclick="return submitThisOnce(this);" class="button">
174
+				<input type="submit" value="', $txt['shd_admin_maint_massdeptmove'], '" class="button save">
188 175
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
189 176
 			</form>
190 177
 		</div>';
... ...
@@ -195,16 +182,14 @@ function template_shd_admin_maint_findrepairdone()
195 182
 {
196 183
 	global $context, $settings, $txt, $scripturl;
197 184
 
198
-	if (empty($context['maintenance_result']))
199
-	{
200 185
 	// Yay everything was fine.
186
+	if (empty($context['maintenance_result']))
201 187
 		echo '
202 188
 		<div class="windowbg">
203 189
 			', $txt['maintain_no_errors'], '
204 190
 			<br>
205 191
 			<a href="', $scripturl, '?action=admin;area=helpdesk_maint;', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_admin_maint_back'], '</a>
206 192
 		</div>';
207
-	}
208 193
 	else
209 194
 	{
210 195
 		echo '
... ...
@@ -214,27 +199,10 @@ function template_shd_admin_maint_findrepairdone()
214 199
 
215 200
 		// Heh, super squeeky buns time!
216 201
 		// Each test has potentially its own feedback to give. So we'll handle each one separately.
217
-		if (!empty($context['maintenance_result']['zero_tickets']))
218
-			echo '
219
-				<p class="padding">', sprintf($txt['shd_maint_zero_tickets'], $context['maintenance_result']['zero_tickets']), '</p>';
220
-		if (!empty($context['maintenance_result']['zero_msgs']))
221
-			echo '
222
-				<p class="padding">', sprintf($txt['shd_maint_zero_msgs'], $context['maintenance_result']['zero_msgs']), '</p>';
223
-		if (!empty($context['maintenance_result']['deleted']))
224
-			echo '
225
-				<p class="padding">', sprintf($txt['shd_maint_deleted'], $context['maintenance_result']['deleted']), '</p>';
226
-		if (!empty($context['maintenance_result']['first_last']))
227
-			echo '
228
-				<p class="padding">', sprintf($txt['shd_maint_first_last'], $context['maintenance_result']['first_last']), '</p>';
229
-		if (!empty($context['maintenance_result']['status']))
230
-			echo '
231
-				<p class="padding">', sprintf($txt['shd_maint_status'], $context['maintenance_result']['status']), '</p>';
232
-		if (!empty($context['maintenance_result']['starter_updater']))
233
-			echo '
234
-				<p class="padding">', sprintf($txt['shd_maint_starter_updater'], $context['maintenance_result']['starter_updater']), '</p>';
235
-		if (!empty($context['maintenance_result']['invalid_dept']))
202
+		foreach (array('zero_tickets', 'zero_msgs', 'deleted', 'first_last', 'status', 'starter_updater', 'invalid_dept') as $maintResult)
203
+			if (!empty($context['maintenance_result'][$maintResult]))
236 204
 				echo '
237
-				<p class="padding">', sprintf($txt['shd_maint_invalid_dept'], $context['maintenance_result']['invalid_dept']), '</p>';
205
+				<p class="padding">', sprintf($txt['shd_maint_' . $maintTxt], $context['maintenance_result'][$maintResult]), '</p>';
238 206
 
239 207
 		echo '
240 208
 				<p class="padding">
... ...
@@ -319,7 +287,7 @@ function template_shd_admin_maint_search()
319 287
 						<input type="text" name="shd_search_max_size" size="4" value="', $modSettings['shd_search_max_size'], '">
320 288
 					</dd>
321 289
 					<dt>
322
-						<a id="setting_shd_search_prefix_size" href="', $scripturl, '?action=helpadmin;help=shd_search_prefix_size_help" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="?"></a>
290
+						<a id="setting_shd_search_prefix_size" href="', $scripturl, '?action=helpadmin;help=shd_search_prefix_size_help" class="help shd_help"><img src="', $settings['images_url'], '/helptopics.png" class="icon" alt="?"></a>
323 291
 						<span>', $txt['shd_search_prefix_size'], '</span>
324 292
 					</dt>
325 293
 					<dd>
... ...
@@ -43,7 +43,6 @@ function template_shd_permissions_home()
43 43
 			</tr>';
44 44
 
45 45
 	foreach ($context['shd_permissions']['roles'] as $role_id => $role_details)
46
-	{
47 46
 		echo '
48 47
 			<tr class="windowbg">
49 48
 				<td>', !empty($role_details['icon']) ? ('<img src="' . $settings['default_images_url'] . '/simpledesk/' . $role_details['icon'] . '" alt="">') : '', '</td>
... ...
@@ -53,7 +52,6 @@ function template_shd_permissions_home()
53 52
 				</td>
54 53
 				', template_shd_display_permission_list($role_details['permissions']), '
55 54
 			</tr>';
56
-	}
57 55
 
58 56
 	echo '
59 57
 		</table>
... ...
@@ -75,12 +73,10 @@ function template_shd_permissions_home()
75 73
 			</tr>';
76 74
 
77 75
 	if (empty($context['shd_permissions']['user_defined_roles']))
78
-	{
79 76
 		echo '
80 77
 			<tr class="windowbg">
81 78
 				<td colspan="', count($context['shd_permissions']['group_display']) + 4, '" class="centertext">', $txt['shd_no_defined_roles'], '</td>
82 79
 			</tr>';
83
-	}
84 80
 	else
85 81
 	{
86 82
 		foreach ($context['shd_permissions']['user_defined_roles'] as $role => $role_details)
... ...
@@ -136,13 +132,11 @@ function template_shd_display_permission_list($permissions)
136 132
 	global $context, $txt, $settings;
137 133
 	$permission_set = array();
138 134
 
139
-	foreach ($context['shd_permissions']['permission_list'] as $permission => $details)
135
+	foreach ($context['shd_permissions']['permission_list'] as $permission => list($ownany, $group, $icon))
140 136
 	{
141
-		list($ownany, $group, $icon) = $details;
142 137
 		if (empty($icon))
143 138
 			continue;
144
-
145
-		if (empty($permission_set[$group]))
139
+		elseif (empty($permission_set[$group]))
146 140
 			$permission_set[$group] = array();
147 141
 
148 142
 		$permtitle = '';
... ...
@@ -161,10 +155,8 @@ function template_shd_display_permission_list($permissions)
161 155
 			}
162 156
 		}
163 157
 		else
164
-		{
165 158
 			if (!empty($permissions[$permission]) && $permissions[$permission] == ROLEPERM_ALLOW)
166 159
 				$permtitle = empty($txt['permissionname_' . $permission]) ? '' : $txt['permissionname_' . $permission];
167
-		}
168 160
 
169 161
 		if (!empty($permtitle))
170 162
 			$permission_set[$group][] = '<img src="' . shd_image_url($icon) . '" alt="" title="' . $permtitle . '">';
... ...
@@ -176,10 +168,8 @@ function template_shd_display_permission_list($permissions)
176 168
 							<td class="shd_valign_top">';
177 169
 
178 170
 		foreach ($rows as $rowitem => $rowicon)
179
-		{
180 171
 			if (!empty($permission_set[$rowitem]))
181 172
 				echo $txt['shd_permgroup_short_' . $rowitem], ': ', implode(' ', $permission_set[$rowitem]), '<br>';
182
-		}
183 173
 
184 174
 		echo '</td>';
185 175
 	}
... ...
@@ -221,7 +211,7 @@ function template_shd_create_role()
221 211
 					<dt><strong>', $txt['shd_create_name'], '</strong></dt>
222 212
 					<dd><input type="text" name="rolename" id="rolename" value="" size="30"></dd>
223 213
 				</dl>
224
-				<input type="submit" value="', $txt['shd_create_role'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
214
+				<input type="submit" value="', $txt['shd_create_role'], '" accesskey="s" class="button save">
225 215
 				<input type="hidden" name="template" value="', $context['role_template_id'], '">
226 216
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
227 217
 				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
... ...
@@ -253,45 +243,8 @@ function template_shd_edit_role()
253 243
 			', $txt['shd_admin_permissions_homedesc'], '
254 244
 		</div>
255 245
 		<script type="text/javascript"><!-- // --><![CDATA[
256
-		function shd_chicon(obj)
257
-		{
258
-			var sSelect = document.getElementById(obj.id).value;
259
-			var newClass = "";
260
-			switch(sSelect)
261
-			{
262
-				case "disallow":
263
-					newClass = "shd_no"; break;
264
-				case "allow":
265
-					newClass = "shd_yes"; break;
266
-				case "allow_own":
267
-					newClass = "shd_own"; break;
268
-				case "allow_any":
269
-					newClass = "shd_any"; break;
270
-				default:
271
-					newClass = ""; break;
272
-			}
273
-			document.getElementById(obj.id + "_icon").setAttribute("class", newClass);
274
-		}
275 246
 
276
-		function shd_toggleblock(block)
277
-		{
278
-			var collapsed = (document.getElementById("permheader_" + block).getAttribute("class") == "cat_bar");
279
-			if (collapsed)
280
-			{
281
-				document.getElementById("permheader_" + block).setAttribute("class", "cat_bar cat_collapsed");
282
-				document.getElementById("permcontent_" + block).style.display = "";
283
-				document.getElementById("permfooter_" + block).style.display = "";
284
-				document.getElementById("permexpandicon_" + block).src = ', JavaScriptEscape($settings['images_url'] . '/selected_open.png'), ';
285
-			}
286
-			else
287
-			{
288
-				document.getElementById("permheader_" + block).setAttribute("class", "cat_bar");
289
-				document.getElementById("permcontent_" + block).style.display = "none";
290
-				document.getElementById("permfooter_" + block).style.display = "none";
291
-				document.getElementById("permexpandicon_" + block).src = ', JavaScriptEscape($settings['images_url'] . '/selected.png'), ';
292
-			}
293
-			document.getElementById("permexpandicon_" + block).style.display = "";
294
-		}
247
+
295 248
 
296 249
 		// ]', ']></script>
297 250
 		<form action="', $scripturl, '?action=admin;area=helpdesk_permissions;sa=saverole" method="post">
... ...
@@ -317,13 +270,10 @@ function template_shd_edit_role()
317 270
 	// Get ready to display the actual permissions
318 271
 	$permission_set = array();
319 272
 	foreach ($context['shd_permissions']['permission_list'] as $permission => $details)
320
-	{
321 273
 		if (!empty($details[2]))
322 274
 			$permission_set[$details[1]][] = $permission;
323
-	}
324 275
 
325 276
 	$displayed_sets = array();
326
-
327 277
 	foreach ($context['shd_permissions']['group_display'] as $cell => $rows)
328 278
 	{
329 279
 		echo '
... ...
@@ -340,12 +289,12 @@ function template_shd_edit_role()
340 289
 				<div class="cat_bar" id="permheader_', $rowitem, '">
341 290
 					<h3 class="catbg">
342 291
 						<span class="floatright">
343
-							<a class="permcollapse" href="#" onclick="shd_toggleblock(\'', $rowitem, '\'); return false;">
292
+							<a class="permcollapse" href="#" data-block="', $rowitem, '">
344 293
 								<img src="', $settings['images_url'], '/selected_open.png" id="permexpandicon_', $rowitem, '" style="display:none;">
345 294
 							</a>
346 295
 						</span>
347 296
 						<img src="', $settings['default_images_url'], '/simpledesk/', $rowicon, '" alt="*">
348
-						<a href="#" onclick="shd_toggleblock(\'', $rowitem, '\'); return false;">', $txt['shd_permgroup_' . $rowitem], '</a>
297
+						<a href="#" data-block="', $rowitem, '">', $txt['shd_permgroup_' . $rowitem], '</a>
349 298
 					</h3>
350 299
 				</div>
351 300
 				<div class="roundframe" id="permcontent_', $rowitem, '">
... ...
@@ -377,20 +326,16 @@ function template_shd_edit_role()
377 326
 						<dt', (empty($txt['permissionhelp_' . $permission]) ? '' : ' title="' . $txt['permissionhelp_' . $permission] . '"') . '><img src="', shd_image_url($icon), '" alt="*">', $txt['permissionname_' . $permission], '</dt>
378 327
 						<dd>
379 328
 							<span id="perm_', $permission, '_icon" class="', $perm_class, '"></span>
380
-							<select name="perm_', $permission, '" id="perm_', $permission, '" onchange="javascript:shd_chicon(this);">
329
+							<select name="perm_', $permission, '" id="perm_', $permission, '">
381 330
 								<option value="disallow"', ($perm_value == 'disallow' ? ' selected="selected"' : ''), '>', (empty($txt['permissionname_' . $permission . '_no']) ? $txt['shd_roleperm_disallow'] : $txt['permissionname_' . $permission . '_no']), '&nbsp;</option>';
382 331
 
383 332
 				if ($ownany)
384
-				{
385 333
 					echo '
386 334
 								<option value="allow_own"', ($perm_value == 'allow_own' ? ' selected="selected"' : ''), '>', $txt['permissionname_' . $permission . '_own'], '&nbsp;</option>
387 335
 								<option value="allow_any"', ($perm_value == 'allow_any' ? ' selected="selected"' : ''), '>', $txt['permissionname_' . $permission . '_any'], '&nbsp;</option>';
388
-				}
389 336
 				else
390
-				{
391 337
 					echo '
392 338
 								<option value="allow"', ($perm_value == 'allow' ? ' selected="selected"' : ''), '>', (empty($txt['permissionname_' . $permission . '_yes']) ? $txt['shd_roleperm_allow'] : $txt['permissionname_' . $permission . '_yes']), '&nbsp;</option>';
393
-				}
394 339
 
395 340
 				echo '
396 341
 							</select>
... ...
@@ -408,25 +353,8 @@ function template_shd_edit_role()
408 353
 			</div>';
409 354
 	}
410 355
 
411
-	if (!empty($displayed_sets))
412
-	{
413
-		echo '
414
-				<script type="text/javascript"><!-- // --><![CDATA[';
415
-
416
-		if (!empty($displayed_sets))
417
-			echo '
418
-				var hidden_blocks = ["', implode('","', $displayed_sets), '"];
419
-				for (i in hidden_blocks)
420
-				{
421
-					shd_toggleblock(hidden_blocks[i]);
422
-				}';
423
-
424
-		echo '
425
-				// ]', ']></script>';
426
-	}
427
-
428 356
 	echo '
429
-		<div class="floatleft" style="width: 100%;">
357
+		<div class="floatleft">
430 358
 			<div class="cat_bar">
431 359
 				<h3 class="catbg">
432 360
 					<img src="', $settings['default_images_url'], '/simpledesk/roles.png" alt="*">
... ...
@@ -484,22 +412,40 @@ function template_shd_edit_role()
484 412
 					</tr>';
485 413
 
486 414
 	foreach ($context['role_depts'] as $id_dept => $dept)
487
-	{
488 415
 		echo '
489 416
 					<tr class="windowbg">
490 417
 						<td>', $dept['dept_name'], '</td>
491 418
 						<td><input type="checkbox" name="dept', $id_dept, '"', !empty($dept['is_role']) ? ' checked="checked"' : '', '></td>
492 419
 					</tr>';
493
-	}
494 420
 
495 421
 	echo '
496 422
 				</table>
497 423
 			</div>
498 424
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
499 425
 			<input type="hidden" name="role" value="', $context['shd_role_id'], '">
500
-			<input type="submit" value="', $txt['shd_edit_role'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
501
-			<input type="submit" value="', $txt['shd_delete_role'], '" onclick="return confirm(' . JavaScriptEscape($txt['shd_delete_role_confirm']) . ');" name="delete" class="button">
502
-		</form>';
426
+			<input type="submit" value="', $txt['shd_edit_role'], '" accesskey="s" class="button save">
427
+			<input type="submit" value="', $txt['shd_delete_role'], '" name="delete" class="button" id="delete" onclick="return confirm(\"Shall\");">
428
+		</form>
429
+
430
+		<script type="text/javascript"><!-- // --><![CDATA[
431
+			var oRoles = new shd_role({
432
+				sPermissionDisallowClass: "shd_no",
433
+				sPermissionAllowClass: "shd_yes",
434
+				sPermissionAllowOwnClass: "shd_own",
435
+				sPermissionAllowAnyClass: "shd_any",
436
+
437
+				oHiddenBlocks: [', !empty($displayed_sets) ? '"' . implode('","', $displayed_sets) . '"' : '', '],
438
+				sBlockHeader: "permheader_%block%",
439
+				sBlockContent: "permcontent_%block%",
440
+				sBlockFooter: "permfooter_%block%",
441
+				sBlockIcon: "permexpandicon_%block%",
442
+				sBlockIconExpandedImg: ', JavaScriptEscape($settings['images_url'] . '/selected_open.png'), ',
443
+				sBlockIconCollapsedImg: ', JavaScriptEscape($settings['images_url'] . '/selected.png'), ',
444
+
445
+				sDeleteContainerId: "delete",
446
+				sDeleteConfirmText: ', JavaScriptEscape($txt['shd_delete_role_confirm']), ',
447
+			});
448
+		// ]]></script>';
503 449
 }
504 450
 
505 451
 /**
... ...
@@ -540,7 +486,7 @@ function template_shd_copy_role()
540 486
 					<dt><strong>', $txt['shd_copy_role_groups'], '</strong></dt>
541 487
 					<dd><input type="checkbox" name="copygroups" id="copygroups" value="1"></dd>
542 488
 				</dl>
543
-				<input type="submit" value="', $txt['shd_copy_role'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
489
+				<input type="submit" value="', $txt['shd_copy_role'], '" accesskey="s" class="button save">
544 490
 				<input type="hidden" name="role" value="', $context['shd_role_id'], '">
545 491
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
546 492
 				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
... ...
@@ -51,18 +51,17 @@ function template_shd_plugin_listing()
51 51
 	foreach ($context['plugins'] as $id => $plugin)
52 52
 	{
53 53
 		echo '
54
-			<div class="windowbg">
54
+			<div class="windowbg shd_plugins">
55 55
 				<div class="features">';
56 56
 
57 57
 		if (!empty($plugin['installable']))
58 58
 			echo '
59 59
 					<div class="features_switch" id="js_feature_', $id, '" style="display: none;">
60
-						<a href="', $scripturl, '?action=admin;area=helpdesk_plugins;save;', $context['session_var'], '=', $context['session_id'], ';toggle=', $id, ';state=', $plugin['enabled'] ? 0 : 1, '" onclick="return toggleItem(\'', $id, '\', \'', $settings['images_url'], '\', \'', $txt['shd_admin_plugins_on'], '\',  \'', $txt['shd_admin_plugins_off'], '\');">
61
-							<input type="hidden" name="feature_', $id, '" id="feature_', $id, '" value="', $plugin['enabled'] ? 1 : 0, '"><img src="', $settings['images_url'], '/simpledesk/switch_', $plugin['enabled'] ? 'on' : 'off', '.png" id="switch_', $id, '" style="margin-top: 1.3em;" alt="', $txt['shd_admin_plugins_' . ($plugin['enabled'] ? 'off' : 'on')], '" title="', $txt['shd_admin_plugins_' . ($plugin['enabled'] ? 'off' : 'on')], '">
60
+						<a href="', $scripturl, '?action=admin;area=helpdesk_plugins;save;', $context['session_var'], '=', $context['session_id'], ';toggle=', $id, ';state=', $plugin['enabled'] ? 0 : 1, '" data-plugin="', $id, '">
61
+							<input type="hidden" name="feature_', $id, '" id="feature_', $id, '" value="', $plugin['enabled'] ? 1 : 0, '"><img src="', $settings['images_url'], '/simpledesk/switch_', $plugin['enabled'] ? 'on' : 'off', '.png" id="switch_', $id, '" alt="', $txt['shd_admin_plugins_' . ($plugin['enabled'] ? 'off' : 'on')], '" title="', $txt['shd_admin_plugins_' . ($plugin['enabled'] ? 'off' : 'on')], '">
62 62
 						</a>
63 63
 					</div>';
64 64
 		else
65
-		{
66 65
 			echo '
67 66
 					<div class="features_switch" id="js_feature_', $id, '">
68 67
 						<div class="error">', $txt['shd_admin_plugins_wrong_version'], '</div>
... ...
@@ -71,18 +70,17 @@ function template_shd_plugin_listing()
71 70
 							<li>', implode('</li><li>', $plugin['details']['compatibility']), '</li>
72 71
 						</ul>
73 72
 					</div>';
74
-		}
75 73
 
76 74
 		if (!empty($plugin['languages']))
77 75
 		{
78 76
 			echo '
79 77
 					<div class="langblock">', $txt['shd_admin_plugins_languages'], ':<br>';
78
+
80 79
 			foreach ($plugin['languages'] as $language)
81
-			{
82 80
 				if (!empty($txt['shd_admin_plugins_lang_' . $language]))
83 81
 					echo '
84 82
 						<img src="', $settings['default_images_url'], '/simpledesk/flags/', $language, '.png" alt="', $txt['shd_admin_plugins_lang_' . $language], '" title="', $txt['shd_admin_plugins_lang_' . $language], '">';
85
-			}
83
+
86 84
 			echo '
87 85
 					</div>';
88 86
 		}
... ...
@@ -116,14 +115,27 @@ function template_shd_plugin_listing()
116 115
 		</form>
117 116
 	</div>
118 117
 	<script type="text/javascript"><!-- // --><![CDATA[
119
-		document.getElementById(\'js_worked\').value = "1";';
118
+		var installablePlugins = [];';
119
+
120 120
 		foreach ($context['plugins'] as $id => $plugin)
121
-		{
122 121
 			if (!empty($plugin['installable']))
123 122
 				echo '
124
-		document.getElementById(\'js_feature_', $id, '\').style.display = "";
125
-		document.getElementById(\'plain_feature_', $id, '\').style.display = "none";';
126
-		}
123
+		installablePlugins.push(', JavaScriptEscape($id), ');';
124
+
127 125
 	echo '
126
+		var oPlugins = new shd_plugins({
127
+			sJSworkedID: "js_worked",
128
+			sJSFeatureClass: "js_feature_%itemid%",
129
+			sJSPlainFeatureClass: "plain_feature_%itemid%",
130
+			oJSInstallablePlugins: installablePlugins,
131
+			sFeaturesSwitchClass: "features_switch",
132
+			sFeatureClass: "feature_%itemid%",
133
+			sSwitchClass: "switch_%itemid%",
134
+			sPluginOffText: ', JavaScriptEscape($txt['shd_admin_plugins_off']), ',
135
+			sPluginOnText: ', JavaScriptEscape($txt['shd_admin_plugins_on']), ',
136
+			sPluginOnImg: ', JavaScriptEscape($settings['images_url'] . '/simpledesk/switch_on.png'), ',
137
+			sPluginOffImg: ', JavaScriptEscape($settings['images_url'] . '/simpledesk/switch_off.png'), ',
138
+
139
+		});
128 140
 	// ]]></script>';
129 141
 }
130 142
\ No newline at end of file
... ...
@@ -36,7 +36,7 @@ function template_assign()
36 36
 		</h3>
37 37
 	</div>
38 38
 	<div class="roundframe">
39
-		<form action="', $scripturl, '?action=helpdesk;sa=assign2;ticket=', $context['ticket_id'], '" method="post" onsubmit="submitonce(this);">
39
+		<form action="', $scripturl, '?action=helpdesk;sa=assign2;ticket=', $context['ticket_id'], '" method="post">
40 40
 			<dl class="settings">
41 41
 				<dt>
42 42
 					<strong>', $txt['shd_ticket_assignedto'], ':</strong>
... ...
@@ -58,8 +58,8 @@ function template_assign()
58 58
 					</select>
59 59
 				</dd>
60 60
 			</dl>
61
-			<input type="submit" name="cancel" value="', ($context['shd_return_to'] == 'home' ? $txt['shd_cancel_home'] : $txt['shd_cancel_ticket']), '" accesskey="c" class="button">
62
-			<input type="submit" value="', $txt['shd_ticket_assign_ticket'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
61
+			<input type="submit" name="cancel" value="', ($context['shd_return_to'] == 'home' ? $txt['shd_cancel_home'] : $txt['shd_cancel_ticket']), '" accesskey="c" class="button save">
62
+			<input type="submit" value="', $txt['shd_ticket_assign_ticket'], '" accesskey="s" class="button save">
63 63
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">';
64 64
 
65 65
 	if ($context['shd_return_to'] == 'home')
... ...
@@ -26,33 +26,29 @@ function template_viewticket()
26 26
 {
27 27
 	global $context, $txt, $scripturl, $settings, $modSettings, $options;
28 28
 
29
-	// Back to the helpdesk.
30
-	template_button_strip(array($context['navigation']['back'], $context['navigation']['replies'], $context['navigation']['ticketlog']));
31
-
29
+	// SMF style icons go first.
32 30
 	if ($modSettings['shd_ticketnav_style'] == 'smf')
33
-	{
34 31
 		template_button_strip($context['ticket_navigation'], 'right');
35
-	}
32
+
33
+	// Back to the helpdesk.
34
+	template_button_strip(array($context['navigation']['back'], $context['navigation']['replies'], $context['navigation']['ticketlog']));
36 35
 
37 36
 	echo '
38 37
 		<div class="cat_bar">
39 38
 			<h3 class="catbg">
40 39
 				<span class="floatright smalltext shd_ticketlinks" id="ticket">';
41 40
 
41
+	// SimpleDesk style Icons go here.
42 42
 	if ($modSettings['shd_ticketnav_style'] == 'sd')
43
-	{
44 43
 		foreach ($context['ticket_navigation'] as $button)
45 44
 			if (!empty($button['display']))
46 45
 				echo '
47 46
 					<a href="', $button['url'], '"', (!empty($button['is_last']) ? ' id="last"' : ''), '', (!empty($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : ''), '><img src="', $settings['default_images_url'], '/simpledesk/', $button['icon'], '.png" alt="', $button['alt'], '" title="', $txt[$button['text']], '"> ', $txt[$button['text']], '</a>';
48
-	}
49 47
 	elseif ($modSettings['shd_ticketnav_style'] == 'sdcompact')
50
-	{
51 48
 		foreach ($context['ticket_navigation'] as $button)
52 49
 			if (!empty($button['display']))
53 50
 				echo '
54 51
 					<a href="', $button['url'], '"', (!empty($button['is_last']) ? ' id="last"' : ''), '', (!empty($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : ''), '><img src="', $settings['default_images_url'], '/simpledesk/', $button['icon'], '.png" alt="', $button['alt'], '" title="', $txt[$button['text']], '"></a>';
55
-	}
56 52
 
57 53
 	echo '
58 54
 				</span>
... ...
@@ -82,9 +78,9 @@ function template_viewticket()
82 78
 						<dt><img src="', $settings['default_images_url'], '/simpledesk/staff.png" alt="" class="shd_smallicon"> ', $txt['shd_ticket_assignedto'], ':</dt>
83 79
 						<dd><span id="assigned_to">', $context['ticket']['assigned']['link'], '</span><span id="assigned_button"></span></dd>
84 80
 						<dt class="shd_assignees_list">
85
-							<ul id="assigned_list" style="display:none;"></ul>
81
+							<ul id="assigned_list" class="hidden"></ul>
86 82
 						</dt>
87
-						<dt><img src="', $settings['default_images_url'], '/simpledesk/status.png" alt="" class="shd_smallicon"/> ', $txt['shd_ticket_status'], ':</dt>
83
+						<dt><img src="', $settings['default_images_url'], '/simpledesk/status.png" alt="" class="shd_smallicon"> ', $txt['shd_ticket_status'], ':</dt>
88 84
 						<dd>', $context['ticket']['status']['label'], '</dd>
89 85
 						<dt><img src="', $settings['default_images_url'], '/simpledesk/replies.png" alt="" class="shd_smallicon"> ', $txt['shd_ticket_num_replies'], ':</dt>
90 86
 						<dd><a href="#replies">', (empty($context['ticket']['display_recycle']) ? $context['ticket']['num_replies'] : (int) $context['ticket']['num_replies'] + (int) $context['ticket']['deleted_replies']), '</a></dd>';
... ...
@@ -128,7 +124,7 @@ function template_viewticket()
128 124
 						{
129 125
 							echo '
130 126
 								<li>
131
-									<dl>
127
+									<dl class="stats">
132 128
 										<dt>', !empty($field['icon']) ? '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" class="shd_smallicon">' : '', ' ', $field['name'], ':</dt>
133 129
 										<dd>';
134 130
 
... ...
@@ -178,7 +174,7 @@ function template_viewticket()
178 174
 				if ($content)
179 175
 				{
180 176
 					echo '
181
-					<div class="information shd_additional_details">
177
+					<div class="shd_additional_details">
182 178
 						<strong><img src="', $settings['default_images_url'], '/simpledesk/additional_details.png" alt="" class="shd_smallicon shd_icon_minihead"> ', $txt['shd_ticket_additional_details'], '</strong>
183 179
 						<hr>
184 180
 							<ul>';
... ...
@@ -273,12 +269,10 @@ function template_viewticket()
273 269
 							', $context['ticket']['body'];
274 270
 
275 271
 			if (!empty($modSettings['show_modify']) && !empty($context['ticket']['modified']))
276
-			{
277 272
 				echo '
278 273
 						<div class="smalltext shd_modified">
279 274
 							&#171; <em>', sprintf($txt['last_edit_by'], $context['ticket']['modified']['time'], $context['ticket']['modified']['link']), '</em> &#187;
280 275
 						</div>';
281
-			}
282 276
 
283 277
 			echo '
284 278
 					</div>';
... ...
@@ -292,7 +286,7 @@ function template_viewticket()
292 286
 			if ($context['can_quote'])
293 287
 				echo '
294 288
 					<div class="information shd_quotebutton floatright" id="shd_quotebutton">
295
-						<a onclick="return oQuickReply.quote(', $context['ticket']['first_msg'], ', \'', $context['session_id'], '\', \'', $context['session_var'], '\', true);" href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';quote=', $context['ticket']['first_msg'], ';num_replies=', $context['ticket']['num_replies'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_ticket_quote'], '</a><br>
289
+						<a data-id="', $context['ticket']['first_msg'], '" href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';quote=', $context['ticket']['first_msg'], ';num_replies=', $context['ticket']['num_replies'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_ticket_quote'], '</a><br>
296 290
 					</div>';
297 291
 
298 292
 			template_inline_attachments($context['ticket']['first_msg']);
... ...
@@ -322,23 +316,8 @@ function template_viewticket()
322 316
 	// The ticket action log, lastly.
323 317
 	template_ticketactionlog();
324 318
 
325
-	// And lastly, the Javascript for AJAX assignment. Since this is onload stuff, it needs to know the HTML already exists.
326
-	if (!empty($context['ajax_assign']))
327
-		echo '
328
-	<script type="text/javascript"><!-- // --><![CDATA[
329
-	var oAjaxAssign = new AjaxAssign({
330
-		sSelf: "oAjaxAssign",
331
-		sScriptUrl: smf_scripturl,
332
-		iTicketId: ' . $context['ticket_id'] . ',
333
-		sId: "assigned_button",
334
-		sListId: "assigned_list",
335
-		sAssignedSpan: "assigned_to",
336
-		sImagesUrl: "' . $settings['default_images_url'] . '/simpledesk",
337
-		sImageCollapsed: "ajax_assign.png",
338
-		sImageExpanded: "ajax_assign_cancel.png"
339
-	});
340
-	// ]' . ']></script>';
341
-
319
+	// Javascript?
320
+	template_scripts_footer();
342 321
 }
343 322
 
344 323
 /**
... ...
@@ -368,14 +347,12 @@ function template_ticket_leftcolumn()
368 347
 	$context['leftcolumndone'] = true; // for the rest of the template later
369 348
 
370 349
 	echo '
350
+		<br class="clear">
371 351
 		<div class="shd_ticket_leftcolumn floatleft">
372 352
 			<div class="shd_attachmentcolumn">';
373 353
 
374 354
 	foreach ($context['leftcolumn_templates'] as $template)
375
-	{
376
-		$var = 'template_' . $template;
377
-		$var();
378
-	}
355
+		call_user_func('template_' . $template);
379 356
 
380 357
 	echo '
381 358
 			</div>
... ...
@@ -393,8 +370,6 @@ function template_viewticketattach()
393 370
 {
394 371
 	global $context, $settings, $txt, $scripturl;
395 372
 
396
-	$remove_txt = JavaScriptEscape($txt['shd_delete_attach_confirm']);
397
-
398 373
 	if (!empty($context['ticket_attach']['ticket']))
399 374
 	{
400 375
 		echo '
... ...
@@ -428,7 +403,7 @@ function template_viewticketattach()
428 403
 
429 404
 			if (!empty($attachment['can_delete']))
430 405
 				echo '
431
-							<a href="', $scripturl, '?action=helpdesk;sa=deleteattach;ticket=', $context['ticket_id'], ';attach=', $attachment['id'], '" onclick="return confirm(', $remove_txt, ');"><img src="', $settings['default_images_url'], '/simpledesk/delete.png" title="', $txt['shd_delete_attach'], '" alt="', $txt['shd_delete_attach'], '"></a>';
406
+							<a href="', $scripturl, '?action=helpdesk;sa=deleteattach;ticket=', $context['ticket_id'], ';attach=', $attachment['id'], '" onclick="return confirm(', JavaScriptEscape($txt['shd_delete_attach_confirm']), ');"><img src="', $settings['default_images_url'], '/simpledesk/delete.png" title="', $txt['shd_delete_attach'], '" alt="', $txt['shd_delete_attach'], '"></a>';
432 407
 
433 408
 			echo '
434 409
 						</span>
... ...
@@ -577,19 +553,18 @@ function template_additional_fields()
577 553
 		echo '
578 554
 			<div class="title_bar" id="additionalinfoheader">
579 555
 				<h3 class="titlebg">
580
-					<span class="floatright"><a href="javascript:oCustomFields.infoswap();"><img src="', $settings['images_url'], '/collapse.png" alt="+" id="shd_custom_fields_swap" class="icon"></a></span>
581
-					<img src="', $settings['default_images_url'], '/simpledesk/additional_information.png" alt="x">
582
-					<a href="javascript:oCustomFields.infoswap();">', $txt['shd_ticket_additional_information'], '</a>
556
+					<span class="toggle_up floatright" id="shd_custom_fields_swap"></span>
557
+					<a href="#" id="shd_custom_fields_swap_link">', $txt['shd_ticket_additional_information'], '</a>
583 558
 				</h3>
584 559
 			</div>
585
-			<div class="roundframe" id="additional_info">';
560
+			<div id="additional_info">';
586 561
 
587 562
 			foreach ($context['ticket']['custom_fields']['information'] as $field)
588 563
 			{
589 564
 				if ($field['display_empty'] || !empty($field['value']) || $field['type'] == CFIELD_TYPE_CHECKBOX)
590 565
 				{
591 566
 					echo '
592
-					<div class="information">
567
+					<div class="roundframe">
593 568
 						', !empty($field['icon']) ? '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" class="shd_smallicon">' : '', '
594 569
 						<strong>', $field['name'], ':</strong><hr>';
595 570
 
... ...
@@ -637,27 +612,23 @@ function template_quickreply()
637 612
 {
638 613
 	global $context, $scripturl, $options, $txt, $settings;
639 614
 
640
-	if ($context['can_reply'] && !empty($options['display_quick_reply']))
641
-	{
642 615
 	echo '
643 616
 		<div class="title_bar" id="quickreplyheader">
644 617
 			<h3 class="titlebg">
645
-					<span class="floatright"><a href="#" onclick="oQuickReply.swap(); return false;"><img src="', $settings['images_url'], '/', $options['display_quick_reply'] == 2 ? 'selected_open' : 'selected', '.png" alt="+" id="quickReplyExpand" class="icon" style="display:none;"></a></span>
618
+				<span class="floatright"><a href="#" onclick="oQuickReply.swap(); return false;"><img src="', $settings['images_url'], '/selected_open.png" alt="+" id="quickReplyExpand" class="icon" style="display:none;"></a></span>
646 619
 				<img src="', $settings['default_images_url'], '/simpledesk/respond.png" alt="x">
647 620
 				<a href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';num_replies=', $context['ticket']['num_replies'], ';', $context['session_var'], '=', $context['session_id'], '" onclick="oQuickReply.swap(); return false;">', $txt['shd_reply_ticket'], '</a>
648 621
 			</h3>
649 622
 		</div>
650
-			<div class="roundframe" id="quickReplyOptions"', $options['display_quick_reply'] != 2 ? ' style="display: none"' : '', '>
623
+		<div class="roundframe" id="quickReplyOptions">
651 624
 			<div class="content">
652
-					<form action="', $scripturl, '?action=helpdesk;sa=savereply" method="post" accept-charset="', $context['character_set'], '" name="postreply" id="postreply" onsubmit="submitonce(this);smc_saveEntities(\'postreply\', [\'shd_reply\'], \'field\');" enctype="multipart/form-data" style="margin: 0;">';
625
+				<form action="', $scripturl, '?action=helpdesk;sa=savereply" method="post" accept-charset="', $context['character_set'], '" name="postreply" id="postreply" onsubmit="smc_saveEntities(\'postreply\', [\'shd_reply\'], \'field\');" enctype="multipart/form-data" style="margin: 0;">';
653 626
 
654 627
 	if ($context['can_go_advanced'])
655
-		{
656 628
 		echo '
657
-					<div class="information shd_advancedbutton floatright" id="shd_goadvancedbutton" style="display:none;">
658
-						<a onclick="goAdvanced(); return false;" href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_go_advanced'], '</a><br>
629
+				<div class="information shd_advancedbutton floatright" id="shd_goadvancedbutton">
630
+					<a href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_go_advanced'], '</a><br>
659 631
 				</div>';
660
-		}
661 632
 
662 633
 	template_ticket_postbox();
663 634
 	template_ticket_meta();
... ...
@@ -666,12 +637,7 @@ function template_quickreply()
666 637
 				</form>
667 638
 			</div>
668 639
 		</div>
669
-			<span id="quickreplyfooter" ', $options['display_quick_reply'] == 2 ? '' : ' style="display: none"', '></span>
670
-		<script type="text/javascript"><!-- // --><![CDATA[
671
-		document.getElementById("quickReplyExpand").style.display = "";
672
-		document.getElementById("shd_goadvancedbutton").style.display = "";
673
-		// ]]></script>';
674
-	}
640
+		<span id="quickreplyfooter"></span>';
675 641
 }
676 642
 
677 643
 /**
... ...
@@ -770,10 +736,8 @@ function template_viewreplies()
770 736
 		<div id="replies">';
771 737
 
772 738
 	if (empty($reply_request))
773
-	{
774 739
 		echo '
775 740
 			<div class="roundframe">', $txt['shd_no_replies'], '</div>';
776
-	}
777 741
 	else
778 742
 	{
779 743
 		while ($reply = $context['get_replies']())
... ...
@@ -809,9 +773,10 @@ function template_viewreplies()
809 773
 						<div class="shd_replyarea">
810 774
 							<div class="smalltext">
811 775
 								<span class="floatright shd_ticketlinks">';
776
+
812 777
 			if ($context['can_quote'])
813 778
 				echo '
814
-									<img src="', $settings['default_images_url'], '/simpledesk/quote.png" class="shd_smallicon" alt="*"><a onclick="return oQuickReply.quote(', $reply['id'], ', \'', $context['session_id'], '\', \'', $context['session_var'], '\', true);" href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';quote=', $reply['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_ticket_quote_short'], '</a>';
779
+									<img src="', $settings['default_images_url'], '/simpledesk/quote.png" class="shd_smallicon" alt="*"><a class="quick_reply" data-id="', $reply['id'], '" href="', $scripturl, '?action=helpdesk;sa=reply;ticket=', $context['ticket_id'], ';quote=', $reply['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_ticket_quote_short'], '</a>';
815 780
 			if ($reply['can_edit'])
816 781
 				echo '
817 782
 									<img src="', $settings['default_images_url'], '/simpledesk/edit.png" class="shd_smallicon" alt="*"><a href="', $scripturl, '?action=helpdesk;sa=editreply;ticket=', $context['ticket_id'], ';msg=', $reply['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['shd_ticket_edit'], '</a>';
... ...
@@ -871,12 +836,10 @@ function template_viewreplies()
871 836
 		}
872 837
 
873 838
 			if (!empty($settings['show_modify']) && !empty($reply['modified']))
874
-			{
875 839
 				echo '
876 840
 							<div class="smalltext shd_modified" style="margin-top:20px;">
877 841
 								&#171; <em>', $txt['last_edit'], ': ', $reply['modified']['time'], ' ', $txt['by'], ' ', $reply['modified']['link'], '</em> &#187;
878 842
 							</div>';
879
-			}
880 843
 
881 844
 			template_inline_attachments($reply['id']);
882 845
 
... ...
@@ -961,7 +924,7 @@ function template_viewrelationships()
961 924
 					<input type="text" name="otherticket" value="" size="5">
962 925
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
963 926
 					<input type="hidden" name="ticket" value="', $context['ticket_id'], '">
964
-					<input type="submit" class="button" value="', $txt['shd_go'], '">
927
+					<input type="submit" class="button save" value="', $txt['shd_go'], '">
965 928
 				</form>';
966 929
 		}
967 930
 
... ...
@@ -982,14 +945,14 @@ function template_ticketactionlog()
982 945
 {
983 946
 	global $context, $settings, $txt, $scripturl;
984 947
 
985
-	if (!empty($context['display_ticket_log']))
986
-	{
948
+	if (empty($context['display_ticket_log']))
949
+		return;
950
+
987 951
 	echo '
988
-			<div class="cat_bar" id="ticket_log_header">
952
+		<div class="title_bar" id="ticket_log_header">
989 953
 			<h3 class="titlebg">
990
-					<span class="floatright shd_ticket_log_expand_container"> <a href="#" onclick="ActionLog.swap(); return false;"><img src="', $settings['images_url'], '/selected.png" alt="+" id="shd_ticket_log_expand" class="icon" style="display:none;"></a></span>
991
-					<img src="', $settings['default_images_url'], '/simpledesk/log.png" class="icon" alt="*">
992
-					<a href="#" onclick="ActionLog.swap(); return false;">', $txt['shd_ticket_log'], '</a>
954
+				<span class="toggle_up floatright" id="shd_ActionLogToggle"></span>
955
+				<span id="shd_ActionLogLink"><img src="', $settings['default_images_url'], '/simpledesk/log.png" class="icon" alt="*"> ', $txt['shd_ticket_log'], '</span>
993 956
 				<span class="smalltext">(', $context['ticket_log_count'] == 1 ? $txt['shd_ticket_log_count_one'] : sprintf($txt['shd_ticket_log_count_more'], $context['ticket_log_count']), ')</span>
994 957
 			</h3>
995 958
 		</div>
... ...
@@ -1015,9 +978,7 @@ function template_ticketactionlog()
1015 978
 				<td colspan="3" class="shd_noticket">', $txt['shd_ticket_log_none'], '</td>
1016 979
 			</tr>';
1017 980
 	else
1018
-		{
1019 981
 		foreach ($context['ticket_log'] as $action)
1020
-			{
1021 982
 			echo '
1022 983
 			<tr class="windowbg">
1023 984
 				<td class="smalltext">', $action['time'], '</td>
... ...
@@ -1027,8 +988,6 @@ function template_ticketactionlog()
1027 988
 					', $action['action_text'], '
1028 989
 				</td>
1029 990
 			</tr>';
1030
-			}
1031
-		}
1032 991
 
1033 992
 	echo '
1034 993
 			<tr class="bot_page">
... ...
@@ -1037,19 +996,7 @@ function template_ticketactionlog()
1037 996
 					', !empty($context['ticket_full_log']) ? '<span class="smalltext shd_main_log"><img src="' . $settings['default_images_url'] . '/simpledesk/browse.png" alt=""><a href="' . $scripturl . '?action=admin;area=helpdesk_info;sa=actionlog">' . $txt['shd_ticket_log_full'] . '</a></span>' : '', '
1038 997
 				</td>
1039 998
 			</tr>
1040
-			</table>
1041
-			<script type="text/javascript"><!-- // --><![CDATA[
1042
-			var ActionLog = new ActionLog({
1043
-				sImagesUrl: "', $settings['images_url'], '",
1044
-				sContainerId: "ticket_log",
1045
-				sImageId: "shd_ticket_log_expand",
1046
-				sImageCollapsed: "selected_open.png",
1047
-				sImageExpanded: "selected.png",
1048
-				sHeaderId: "ticket_log_header",
1049
-			});
1050
-			ActionLog.swap();
1051
-			// ]', ']></script>';
1052
-	}
999
+		</table>';
1053 1000
 }
1054 1001
 
1055 1002
 /**
... ...
@@ -1072,5 +1019,224 @@ function template_shd_display_nojs_above()
1072 1019
 */
1073 1020
 function template_shd_display_nojs_below()
1074 1021
 {
1022
+}
1023
+
1024
+/**
1025
+ *	All of the Javascript we have.
1026
+ *
1027
+ *	@since 2.1
1028
+*/
1029
+function template_scripts_footer()
1030
+{
1031
+	global $context;
1032
+
1033
+	$jsTemplates = array(
1034
+		'privacy' => !empty($context['ticket']['privacy']['can_change']),
1035
+		'urgency' => !empty($context['ticket']['urgency']['increase']) || !empty($context['ticket']['urgency']['decrease']),
1036
+		'ajax_assign' => !empty($context['ajax_assign']),
1037
+		'quickreply' => true,
1038
+		'custom_fields_display' => true,
1039
+		'action_log' => !empty($context['display_ticket_log']),
1040
+		'advanced_quickreply' => !empty($context['can_go_advanced']),
1041
+	);
1042
+
1043
+	echo '
1044
+	<script type="text/javascript"><!-- // --><![CDATA[';
1045
+
1046
+	foreach ($jsTemplates as $template => $enabled)
1047
+		if ($enabled)
1048
+			call_user_func('template_shd_js_' . $template);
1049
+
1050
+	echo '
1051
+	// ]' . ']></script>';
1052
+}
1053
+
1054
+/**
1055
+ *	Javascript for Privacy
1056
+ *
1057
+ *	@since 2.1
1058
+*/
1059
+function template_shd_js_privacy()
1060
+{
1061
+	global $context, $txt;
1062
+
1063
+	echo '
1064
+		var shd_ajax_problem = ', JavaScriptEscape($txt['shd_ajax_problem']), ';
1065
+		var privacyCtl = new shd_privacyControl({
1066
+			ticket: ', $context['ticket_id'], ',
1067
+			sUrl: smf_scripturl + "?action=helpdesk;sa=ajax;op=privacy;ticket=', $context['ticket_id'], '",
1068
+			sSession: smf_session_var + "=" + smf_session_id,
1069
+			sSrcA: "privlink",
1070
+			sDestSpan: "privacy"
1071
+		});';
1072
+}
1073
+
1074
+/**
1075
+ *	Javascript for Urgency
1076
+ *
1077
+ *	@since 2.1
1078
+*/
1079
+function template_shd_js_urgency()
1080
+{
1081
+	global $context;
1082
+
1083
+	echo '
1084
+		var urgencyCtl = new shd_urgencyControl({
1085
+			ticket: ', $context['ticket_id'], ',
1086
+			sUrl: smf_scripturl + "?action=helpdesk;sa=ajax;op=urgency;ticket=', $context['ticket_id'], ';change=",
1087
+			sSession: smf_session_var + "=" + smf_session_id,
1088
+			sDestSpan: "urgency",
1089
+			aButtons: ["up", "down"],
1090
+			aButtonOps: { up: "increase", down: "decrease" }
1091
+		});';
1092
+}
1093
+
1094
+/**
1095
+ *	Javascript for Quick Reply
1096
+ *
1097
+ *	@since 2.1
1098
+*/
1099
+function template_shd_js_quickreply()
1100
+{
1101
+	global $context, $settings;
1075 1102
 
1103
+	echo '
1104
+		var oQuickReply = new QuickReply({
1105
+			iTicketId: ', $context['ticket_id'], ',
1106
+			sScriptUrl: smf_scripturl,
1107
+			sJumpAnchor: "quickReplyOptions",
1108
+			sSession: smf_session_var + "=" + smf_session_id,
1109
+			sRepliesSelector: "span.shd_ticketlinks a.quick_reply",
1110
+			sFirstPostSelector: "div#shd_quotebutton a"
1111
+		});';
1112
+}
1113
+
1114
+/**
1115
+ *	Javascript for Ajax Assign
1116
+ *
1117
+ *	@since 2.1
1118
+*/
1119
+function template_shd_js_custom_fields_display()
1120
+{
1121
+	global $context, $options, $txt;
1122
+
1123
+	echo '
1124
+		var oCustomFields = new smc_Toggle({
1125
+			bToggleEnabled: true,
1126
+			bCurrentlyCollapsed: ', empty($options['collapse_shd_customFields']) ? 'false' : 'true', ',
1127
+			aSwappableContainers: [
1128
+				\'additional_info\'
1129
+			],
1130
+			aSwapImages: [
1131
+				{
1132
+					sId: \'shd_custom_fields_swap\',
1133
+				}
1134
+			],
1135
+			aSwapLinks: [
1136
+				{
1137
+					sId: \'shd_custom_fields_swap_link\',
1138
+					msgCollapsed: ', JavaScriptEscape($txt['shd_ticket_additional_information']), ',
1139
+					msgExpanded: ', JavaScriptEscape($txt['shd_ticket_additional_information']), ',
1140
+				},
1141
+			],
1142
+			oThemeOptions: {
1143
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
1144
+				sOptionName: \'collapse_shd_customFields\',
1145
+				sSessionId: smf_session_id,
1146
+				sSessionVar: smf_session_var,
1147
+			},
1148
+			oCookieOptions: {
1149
+				bUseCookie: false,
1150
+				sCookieName: \'shd_customFields\'
1151
+			}
1152
+		});';
1153
+}
1154
+
1155
+/**
1156
+ *	Javascript for Ajax Assign
1157
+ *
1158
+ *	@since 2.1
1159
+*/
1160
+function template_shd_js_ajax_assign()
1161
+{
1162
+	global $context, $settings;
1163
+
1164
+	echo '
1165
+		var oAjaxAssign = new AjaxAssign({
1166
+			sSelf: "oAjaxAssign",
1167
+			sScriptUrl: smf_scripturl,
1168
+			iTicketId: ' . $context['ticket_id'] . ',
1169
+			sId: "assigned_button",
1170
+			sListId: "assigned_list",
1171
+			sAssignedSpan: "assigned_to",
1172
+			sImagesUrl: ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk'), ',
1173
+			sImageCollapsed: ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/ajax_assign.png'), ',
1174
+			sImageExpanded: ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/ajax_assign_cancel.png'), ',
1175
+			sImageAdmin: ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/admin.png'), ',
1176
+			sImageStaff: ', JavaScriptEscape($settings['default_images_url'] . '/simpledesk/staff.png'), ',
1177
+			sSession: smf_session_var + "=" + smf_session_id,
1178
+		});';
1179
+}
1180
+
1181
+/**
1182
+ *	Javascript for Action Log
1183
+ *
1184
+ *	@since 2.1
1185
+*/
1186
+function template_shd_js_action_log()
1187
+{
1188
+	global $context, $options, $settings, $txt;
1189
+
1190
+	echo '
1191
+		var oActionLog = new smc_Toggle({
1192
+			bToggleEnabled: true,
1193
+			bCurrentlyCollapsed: ', empty($options['collapse_shd_actionLog']) ? 'false' : 'true', ',
1194
+			aSwappableContainers: [
1195
+				\'ticket_log\'
1196
+			],
1197
+			aSwapImages: [
1198
+				{ sId: \'shd_ActionLogToggle\',},
1199
+			],
1200
+			aSwapLinks: [
1201
+				{
1202
+					sId: \'shd_ActionLogLink\',
1203
+					msgCollapsed: ', JavaScriptEscape('<img src="' . $settings['default_images_url'] . '/simpledesk/log.png" class="icon" alt="*"> ' . $txt['shd_ticket_log']), ',
1204
+					msgExpanded: ', JavaScriptEscape('<img src="' . $settings['default_images_url'] . '/simpledesk/log.png" class="icon" alt="*"> ' . $txt['shd_ticket_log']), ',
1205
+				},
1206
+			],
1207
+			oThemeOptions: {
1208
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
1209
+				sOptionName: \'collapse_shd_actionLog\',
1210
+				sSessionId: smf_session_id,
1211
+				sSessionVar: smf_session_var,
1212
+			},
1213
+			oCookieOptions: {
1214
+				bUseCookie: false,
1215
+				sCookieName: \'shd_customFields\'
1216
+			}
1217
+		});';
1218
+}
1219
+
1220
+/**
1221
+ *	Javascript for Advanced QuickRely
1222
+ *
1223
+ *	@since 2.1
1224
+*/
1225
+function template_shd_js_advanced_quickreply()
1226
+{
1227
+	global $context, $modSettings;
1228
+
1229
+	echo '
1230
+		var oGoAdvanced = new goAdvanced({
1231
+			sBbcContainerId: "shd_bbcbox",
1232
+			sBbcContainerEditorClass: "sceditor-group",
1233
+			sSmileyContainerId: "shd_smileybox",
1234
+			sSmileyContainerEditorClass: "sceditor-insertemoticon",
1235
+			sAttachContainerId: "shd_attach_container",
1236
+			sAdvancedContainerId: "shd_goadvancedbutton",
1237
+			sAdditionalOptionsContainerId: "shd_additional_options_box",
1238
+			bAllowBBC: ', !empty($modSettings['shd_allow_ticket_bbc']) ? 'true' : 'false', ',
1239
+			bAllowSmileys: ', !empty($modSettings['shd_allow_ticket_smileys']) ? 'true' : 'false', ',
1240
+			bAllowAttach: ', !empty($context['ticket_form']['do_attach']) ? 'true' : 'false', ',
1241
+		});';
1076 1242
 }
1077 1243
\ No newline at end of file
... ...
@@ -35,7 +35,7 @@ function template_movedept()
35 35
 		</h3>
36 36
 	</div>
37 37
 	<div class="roundframe">
38
-		<form action="', $scripturl, '?action=helpdesk;sa=movedept2;ticket=', $context['ticket_id'], '" method="post" onsubmit="submitonce(this);">
38
+		<form action="', $scripturl, '?action=helpdesk;sa=movedept2;ticket=', $context['ticket_id'], '" method="post">
39 39
 			<dl class="settings">
40 40
 				<dt>
41 41
 					<strong>', $txt['shd_current_dept'], ':</strong>
... ...
@@ -63,7 +63,7 @@ function template_movedept()
63 63
 					<strong>', $txt['shd_move_send_pm'], ':</strong>
64 64
 				</dt>
65 65
 				<dd>
66
-					<input type="checkbox" name="send_pm" id="send_pm" checked="checked" onclick="document.getElementById(\'pm_message\').style.display = this.checked ? \'block\' : \'none\';" >
66
+					<input type="checkbox" name="send_pm" id="send_pm" checked="checked">
67 67
 				</dd>
68 68
 			</dl>
69 69
 			<fieldset id="pm_message">
... ...
@@ -84,7 +84,10 @@ function template_movedept()
84 84
 
85 85
 	echo '
86 86
 			<input type="submit" name="cancel" value="', ($context['shd_return_to'] == 'home' ? $txt['shd_cancel_home'] : $txt['shd_cancel_ticket']), '" accesskey="c" class="button">
87
-			<input type="submit" value="', $txt['shd_ticket_move'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
87
+			<input type="submit" value="', $txt['shd_ticket_move'], '" accesskey="s" class="button save">
88 88
 		</form>
89
-	</div>';
89
+	</div>
90
+	<script type="text/javascript"><!-- // --><![CDATA[
91
+		$("#send_pm").on("change", function(){$("#pm_message").toggle();});
92
+	// ]' . ']></script>';
90 93
 }
91 94
\ No newline at end of file
... ...
@@ -65,11 +64,11 @@ function template_ticket_option($option)
65 64
 	{
66 65
 		echo '
67 66
 								<select name="shd_' . $option . '">';
67
+
68 68
 		foreach ($context['ticket_form'][$option]['options'] as $value => $caption)
69
-		{
70 69
 			echo '
71 70
 									<option value="', $value, '"', ($value == $context['ticket_form'][$option]['setting'] ? ' selected="selected"' : ''), '>', $txt[$caption], '</option>';
72
-		}
71
+
73 72
 		echo '
74 73
 								</select>';
75 74
 	}
... ...
@@ -82,7 +81,7 @@ function template_ticket_info()
82 81
 	global $context, $txt, $scripturl, $settings, $modSettings, $options;
83 82
 
84 83
 	echo '
85
-			<form action="', $context['ticket_form']['form_action'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" onsubmit="', 'submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\'], \'field\');" enctype="multipart/form-data" style="margin: 0;">
84
+			<form action="', $context['ticket_form']['form_action'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" onsubmit="smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\'], \'field\');" enctype="multipart/form-data">
86 85
 			<div class="cat_bar">
87 86
 				<h3 class="catbg">
88 87
 					<img src="', $settings['default_images_url'], '/simpledesk/ticket.png" alt="x"> ', $context['ticket_form']['form_title'], '
... ...
@@ -119,7 +118,7 @@ function template_ticket_info()
119 118
 							<li><img src="', $settings['default_images_url'], '/simpledesk/staff.png" alt="" class="shd_smallicon"> ', $txt['shd_ticket_assignedto'], ': ', !empty($context['ticket_form']['assigned']['link']) ? $context['ticket_form']['assigned']['link'] : '<span class="error">' . $txt['shd_unassigned'] . '</span>', '</li>';
120 119
 
121 120
 	echo '
122
-							<li><img src="', $settings['default_images_url'], '/simpledesk/status.png" alt="" class="shd_smallicon"/> ', $txt['shd_ticket_status'], ': ', $txt['shd_status_' . $context['ticket_form']['status']], '</li>';
121
+							<li><img src="', $settings['default_images_url'], '/simpledesk/status.png" alt="" class="shd_smallicon"> ', $txt['shd_ticket_status'], ': ', $txt['shd_status_' . $context['ticket_form']['status']], '</li>';
123 122
 
124 123
 	if (!empty($context['display_private']))
125 124
 		echo '
... ...
@@ -151,12 +150,12 @@ function template_ticket_custom_fields()
151 150
 
152 151
 	echo '
153 152
 				<br class="clear">
154
-				<div class="title_bar"', empty($context['ticket_form']['dept']) ? ' style="display:none;"' : '', '>
153
+				<div  id="shd_customfields_title" class="title_bar', empty($context['ticket_form']['dept']) ? ' hidden' : '', '">
155 154
 					<h3 class="titlebg">
156 155
 						<a href="#">', $txt['shd_ticket_additional_details'], '</a>
157 156
 					</h3>
158 157
 				</div>
159
-				<div class="shd_customfields" id="shd_customfields"', empty($context['ticket_form']['dept']) ? ' style="display:none;"' : '', '>';
158
+				<div class="shd_customfields', empty($context['ticket_form']['dept']) ? ' hidden' : '', '" id="shd_customfields">';
160 159
 
161 160
 		// Loop through each custom field
162 161
 		// See also template_ticket_subjectbox() for the department selector which affects these.
... ...
@@ -180,13 +179,13 @@ function template_ticket_custom_fields()
180 179
 				if ($field['value'] == $field['default_value'])
181 180
 					$field['value'] = '';
182 181
 				echo '
183
-					<div id="field_', $field['id'], '_container"', $field['hidden'] ? ' style="display:none;"' : '', '>
182
+					<div id="field_', $field['id'], '_container"', $field['hidden'] ? ' class="hidden"' : '', '>
184 183
 						<dl class="settings">
185
-							<dt id="field-' . $field['id'] . '" style="width:98%;">
184
+							<dt id="field-' . $field['id'] . '" class="shd_cust_fields_largetext">
186 185
 								', !empty($field['icon']) ? '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="">' : '', '
187 186
 								<strong>' . $field['name'] . ': </strong><br>
188 187
 								<span class="smalltext">' . $field['desc'] . '</span><br>
189
-								<textarea name="field-', $field['id'], '"', !empty($field['default_value']) ? ' rows="' . $field['default_value'][0] . '" cols="' . $field['default_value'][1] . '" ' : '', ' style="width:auto; height:auto;">', $field['value'], '</textarea>
188
+								<textarea name="field-', $field['id'], '"', !empty($field['default_value']) ? ' rows="' . $field['default_value'][0] . '" cols="' . $field['default_value'][1] . '" ' : '', '>', $field['value'], '</textarea>
190 189
 							</dt>
191 190
 						</dl>
192 191
 						<hr>
... ...
@@ -195,7 +194,7 @@ function template_ticket_custom_fields()
195 194
 			else
196 195
 			{
197 196
 				echo '
198
-					<div id="field_', $field['id'], '_container"', $field['hidden'] ? ' style="display:none;"' : '', '>
197
+					<div id="field_', $field['id'], '_container"', $field['hidden'] ? ' class="hidden"' : '', '>
199 198
 						<dl class="settings">
200 199
 							<dt id="field-' . $field['id'] . '">
201 200
 								', !empty($field['icon']) ? '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="">' : '', '
... ...
@@ -205,22 +204,16 @@ function template_ticket_custom_fields()
205 204
 
206 205
 				// Text
207 206
 				if ($field['type'] == CFIELD_TYPE_TEXT)
208
-				{
209 207
 					echo '
210 208
 							<dd><input type="text" name="field-', $field['id'], '" value="', $field['value'], '"></dd>';
211
-				}
212 209
 				// Integers only
213 210
 				elseif ($field['type'] == CFIELD_TYPE_INT)
214
-				{
215 211
 					echo '
216 212
 							<dd><input name="field-', $field['id'], '" value="', $field['value'], '" size="10"></dd>';
217
-				}
218 213
 				// Floating numbers
219 214
 				elseif ($field['type'] == CFIELD_TYPE_FLOAT)
220
-				{
221 215
 					echo '
222 216
 							<dd><input name="field-', $field['id'], '" value="', $field['value'], '" size="10"></dd>';
223
-				}
224 217
 				// Select boxes
225 218
 				elseif ($field['type'] == CFIELD_TYPE_SELECT)
226 219
 				{
... ...
@@ -246,10 +239,8 @@ function template_ticket_custom_fields()
246 239
 				}
247 240
 				// Checkboxes!
248 241
 				elseif ($field['type'] == CFIELD_TYPE_CHECKBOX)
249
-				{
250 242
 					echo '
251 243
 							<dd><input name="field-', $field['id'], '" type="checkbox"', !empty($field['value']) ? ' checked="checked"' : '', '></dd>';
252
-				}
253 244
 				// Magical multi-select!
254 245
 				elseif ($field['type'] == CFIELD_TYPE_MULTI)
255 246
 				{
... ...
@@ -324,7 +315,7 @@ function template_ticket_posterrors()
324 315
 		$context['shd_errors'] = array();
325 316
 
326 317
 	echo '
327
-						<div class="errorbox" id="errors"', empty($context['shd_errors']) ? ' style="display:none;"' : '', '>
318
+						<div class="errorbox', empty($context['shd_errors']) ? ' hidden' : '', '" id="errors">
328 319
 							<dl>
329 320
 								<dt>
330 321
 									<strong style="" id="error_serious">', $txt['shd_ticket_post_error'], ':</strong>
... ...
@@ -358,8 +350,9 @@ function template_ticket_subjectbox()
358 350
 		echo '
359 351
 						<br>
360 352
 						<img src="', $settings['default_images_url'], '/simpledesk/departments.png" alt="" class="shd_smallicon"><strong>', $txt['shd_ticket_dept'], '</strong>
361
-						<select name="newdept" onchange="updateDeptCFs(this.value)">
353
+						<select id="newdept" name="newdept">
362 354
 							<option value="0">', $txt['shd_select_dept'], '</option>';
355
+
363 356
 		foreach ($context['postable_dept_list'] as $id => $dept)
364 357
 			echo '
365 358
 							<option value="', $id, '"', $context['ticket_form']['dept'] == $id ? ' selected="selected"' : '', '>', $dept, '</option>';
... ...
@@ -367,49 +360,16 @@ function template_ticket_subjectbox()
367 360
 		echo '
368 361
 						</select>';
369 362
 
370
-		if (!empty($context['ticket_form']['custom_fields'][$context['ticket_form']['custom_fields_context']]))
371
-		{
372
-			echo '
373
-						<script type="text/javascript"><!-- // --><![CDATA[
374
-						var fields = new Array();';
375
-			foreach ($context['ticket_form']['custom_fields'][$context['ticket_form']['custom_fields_context']] as $field)
376
-			{
377
-				if (!$field['editable'])
378
-					continue;
379
-				echo '
380
-						fields[', $field['id'], '] = [', implode(',', $field['depts']), '];';
381
-			}
382
-			echo '
383
-						function updateDeptCFs(dept)
384
-						{
385
-							var displayed = 0;
386
-							for (i in fields)
387
-							{
388
-								if (dept != 0 && in_array(dept, fields[i]))
389
-								{
390
-									document.getElementById("field_" + i + "_container").style.display = "";
391
-									displayed++;
392
-								}
393
-								else
394
-								{
395
-									document.getElementById("field_" + i + "_container").style.display = "none";
396
-								}
397
-								document.getElementById("shd_customfields").style.display = (displayed == 0) ? "none" : "";
398
-							}
399
-						}
400
-						// ]', ']></script>';
401
-		}
363
+		template_shd_js_custom_fields();
402 364
 	}
403 365
 
404 366
 	// Are we dealing with proxy tickets?
405 367
 	if (!empty($context['can_post_proxy']))
406
-	{
407 368
 		echo '
408 369
 						<br>
409 370
 						<input type="hidden" name="proxy" value="">
410 371
 						<img src="', $settings['default_images_url'], '/simpledesk/proxy.png" alt="" class="shd_smallicon"><strong>', $txt['shd_ticket_proxy'], ':</strong>
411 372
 						<input type="text" name="proxy_author" id="proxy_author" size="50" maxlength="100" value="', (empty($context['ticket_form']['proxy']) ? '' : $context['ticket_form']['proxy']), '" tabindex="', $context['tabindex']++, '">';
412
-	}
413 373
 
414 374
 	echo '
415 375
 						<hr><br>';
... ...
@@ -451,13 +412,11 @@ function template_ticket_content()
451 412
 							', $context['ticket_form']['message'];
452 413
 
453 414
 	if (!empty($settings['show_modify']) && !empty($context['ticket']['modified']))
454
-	{
455 415
 		echo '
456 416
 						<div class="smalltext shd_modified" style="margin-top:20px;">
457 417
 							&#171; <em>', $txt['last_edit'], ': ', $context['ticket']['modified']['time'], ' ', $txt['by'], ' ', $context['ticket']['modified']['link'], '</em> &#187;
458 418
 						</div>';
459 419
 }
460
-}
461 420
 
462 421
 function template_ticket_meta()
463 422
 {
... ...
@@ -515,8 +474,8 @@ function template_ticket_postbox()
515 474
 
516 475
 	// The postbox
517 476
 	echo '
518
-						<div id="shd_bbcbox"', ((empty($modSettings['shd_allow_ticket_bbc']) || !empty($context['shd_display'])) ? ' style="display:none;"' : ''), '></div>
519
-						<div id="shd_smileybox"', ((empty($modSettings['shd_allow_ticket_smileys']) || !empty($context['shd_display'])) ? ' style="display:none;"' : ''), '></div>';
477
+						<div id="shd_bbcbox"', ((empty($modSettings['shd_allow_ticket_bbc']) || !empty($context['shd_display'])) ? ' class="hidden"' : ''), '></div>
478
+						<div id="shd_smileybox"', ((empty($modSettings['shd_allow_ticket_smileys']) || !empty($context['shd_display'])) ? ' class="hidden"' : ''), '></div>';
520 479
 
521 480
 	if ($editor_context['width'] == ((int) $editor_context['width']) . '%')
522 481
 	{
... ...
@@ -553,8 +512,8 @@ function template_ticket_cannedreplies()
553 512
 		return;
554 513
 
555 514
 	echo '
556
-					<div id="canned_replies" style="display:none;">
557
-						<div style="font-weight:bold; padding: 0.5em;">', $txt['canned_replies'], '</div>
515
+					<div id="canned_replies" class="hidden">
516
+						<div id="canned_title">', $txt['canned_replies'], '</div>
558 517
 						<select id="canned_replies_select">
559 518
 							<option value="0">', $txt['canned_replies_select'], '</option>';
560 519
 
... ...
@@ -573,16 +532,10 @@ function template_ticket_cannedreplies()
573 532
 
574 533
 	echo '
575 534
 						</select>
576
-						<input type="button" class="button" value="', $txt['canned_replies_insert'], '" onclick="oCannedReplies.getReply();">
577
-					</div>
578
-					<script type="text/javascript"><!-- // --><![CDATA[
579
-					var oCannedReplies = new CannedReply({
580
-						iTicketId: ', $context['ticket_id'], ',
581
-						sScriptUrl: smf_scripturl,
582
-						sSessionVar: "', $context['session_var'], '",
583
-						sSessionId: "', $context['session_id'], '"
584
-					});
585
-					// ]]></script>';
535
+						<input type="button" class="button" value="', $txt['canned_replies_insert'], '">
536
+					</div>';
537
+
538
+	template_shd_js_canned_replies();
586 539
 }
587 540
 
588 541
 function template_ticket_footer()
... ...
@@ -590,12 +543,10 @@ function template_ticket_footer()
590 543
 	global $settings, $context, $txt;
591 544
 
592 545
 	if (!empty($settings['show_modify']) && !empty($context['ticket_form']['modified']))
593
-	{
594 546
 		echo '
595
-						<div class="smalltext shd_modified" style="margin-top:20px;">
547
+						<div class="smalltext shd_modified">
596 548
 							&#171; <em>', $txt['last_edit'], ': ', $context['ticket_form']['modified']['time'], ' ', $txt['by'], ' ', $context['ticket_form']['modified']['link'], '</em> &#187;
597 549
 						</div>';
598
-	}
599 550
 
600 551
 	echo '
601 552
 					</div>
... ...
@@ -609,8 +560,9 @@ function template_preview()
609 560
 {
610 561
 	global $context, $txt, $settings;
611 562
 
612
-	if (!empty($context['ticket_form']['preview']))
613
-	{
563
+	if (empty($context['ticket_form']['preview']))
564
+		return;
565
+
614 566
 	echo '
615 567
 		<div class="tborder">
616 568
 		<div class="title_bar">
... ...
@@ -627,13 +579,13 @@ function template_preview()
627 579
 		</div>
628 580
 		<br>';
629 581
 }
630
-}
631 582
 
632 583
 function template_ticket_additional_options()
633 584
 {
634 585
 	global $context, $options, $txt, $modSettings, $settings;
635 586
 
636 587
 	echo '
588
+				<div id="shd_additional_options_box">
637 589
 					<br class="clear">
638 590
 					<div class="title_bar">
639 591
 						<h3 class="titlebg">
... ...
@@ -645,11 +597,9 @@ function template_ticket_additional_options()
645 597
 						<ul class="post_options">';
646 598
 
647 599
 	foreach ($context['ticket_form']['additional_opts'] as $key => $details)
648
-	{
649 600
 		if (!empty($details['show']))
650 601
 			echo '
651 602
 							<li><label for="', $key, '"><input type="checkbox" name="', $key, '" id="', $key, '"', (!empty($details['checked']) ? ' checked="checked"' : ''), ' value="1"> ', $details['text'], '</label></li>';
652
-	}
653 603
 
654 604
 	echo '
655 605
 						</ul>';
... ...
@@ -659,33 +609,13 @@ function template_ticket_additional_options()
659 609
 	template_add_attachments();
660 610
 
661 611
 	echo '
662
-					</div>
663
-					<script>
664
-						var oAdditionalOptionsToggle = new smc_Toggle({
665
-							bToggleEnabled: true,
666
-							bCurrentlyCollapsed: ', empty($options['collapse_shd_additionalOptions']) ? 'false' : 'true', ',
667
-							aSwappableContainers: [
668
-								\'postAdditionalOptionsHeader\'
669
-							],
670
-							aSwapImages: [
671
-								{
672
-									sId: \'shd_additionalOptionsToggle\',
673
-								}
674
-							],
675
-							oThemeOptions: {
676
-								bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
677
-								sOptionName: \'collapse_shd_additionalOptions\',
678
-								sSessionId: smf_session_id,
679
-								sSessionVar: smf_session_var,
680
-							},
681
-							oCookieOptions: {
682
-								bUseCookie: false,
683
-								sCookieName: \'shd_additionalOptions\'
684
-							}
685
-						});
686
-					</script>';
612
+					</div>';
687 613
 
614
+	tempalte_shd_js_additional_options();
688 615
 	template_singleton_email();
616
+
617
+	echo '
618
+				</div>';
689 619
 }
690 620
 
691 621
 /**
... ...
@@ -730,11 +660,9 @@ function template_show_attachments()
730 660
 							</dd>';
731 661
 	}
732 662
 	else
733
-	{
734 663
 		foreach ($context['current_attachments'] as $attachment)
735 664
 			echo '
736 665
 							<dd class="smalltext">', $attachment['name'], '</dd>';
737
-	}
738 666
 
739 667
 	echo '
740 668
 						</dl>';
... ...
@@ -784,28 +712,7 @@ function template_add_attachments()
784 712
 							</dd>
785 713
 						</dl>';
786 714
 
787
-	echo '
788
-					<script type="text/javascript"><!-- // --><![CDATA[
789
-	var oAttach = new shd_attach_select({
790
-		file_item: "shd_attach",
791
-		file_container: "shd_attachlist_container",
792
-		max: ', $context['ticket_form']['num_allowed_attachments'], ',
793
-		message_txt_delete: ', JavaScriptEscape($txt['remove']);
794
-
795
-	if (!empty($modSettings['attachmentExtensions']) && !empty($modSettings['attachmentCheckExtensions']))
796
-	{
797
-		$ext = explode(',', $modSettings['attachmentExtensions']);
798
-		foreach ($ext as $k => $v)
799
-			$ext[$k] = JavaScriptEscape($v);
800
-
801
-		echo ',
802
-		message_ext_error: ', JavaScriptEscape(str_replace('{attach_exts}', $context['allowed_extensions'], $txt['shd_cannot_attach_ext'])), ',
803
-		attachment_ext: [', implode(',', $ext), ']';
804
-	}
805
-
806
-	echo '
807
-	});
808
-					// ]]></script>';
715
+	tempalte_shd_js_attachments();
809 716
 }
810 717
 
811 718
 /**
... ...
@@ -822,7 +729,7 @@ function template_singleton_email()
822 729
 		return;
823 730
 
824 731
 	echo '
825
-						<div id="shd_notifications_div" style="display:none;">
732
+						<div id="shd_notifications_div" class="hidden">
826 733
 							<a href="#" id="shd_getAjaxNotifications">', $txt['shd_select_notifications'], '</a>';
827 734
 
828 735
 	if (!empty($context['notification_ping_list']))
... ...
@@ -831,26 +738,9 @@ function template_singleton_email()
831 738
 
832 739
 	echo '
833 740
 							<br class="clear">
834
-						</div>
835
-						<script type="text/javascript"><!-- // --><![CDATA[
836
-	var shd_oNotifications = new shd_notifications(', $context['ticket_id'], ', {
837
-		sContainerId: "shd_notifications_div",
838
-		sLinkId: "shd_getAjaxNotifications",
839
-		sPinglist: "', (!empty($context['notification_ping_list']) ? $context['notification_ping_list'] : ''), '",
840
-		sSessionId: smf_session_id,
841
-		sSessionVar: smf_session_var,
842
-		oMainTemplate: ', JavaScriptEscape('
843
-			<span class=\'shd_ajax_head\'>%title%</span><br>%subtemplate%<br>
844
-							'), ',
845
-		oNotifiedTemplate: ', JavaScriptEscape('%name%, '), ',
846
-		oOptionalTemplate: ', JavaScriptEscape('
847
-				<div class=\'shd_ajaxnotify\'><input type=\'checkbox\' name=\'notify[%index%]\' value=\'%index%\'%checked%>%name%</div>
848
-								'), ',
849
-		oOptionalOffTemplate: ', JavaScriptEscape('
850
-				<div class=\'shd_ajaxnotify\'><input type=\'checkbox\' name=\'notify[%index%]\' value=\'%index%\'%checked%>%name%</div>
851
-								'), ',
852
-	});
853
-						// ]]></script>';
741
+						</div>';
742
+
743
+	tempalte_shd_js_notifications();
854 744
 }
855 745
 
856 746
 function template_ticket_begin_replies()
... ...
@@ -877,9 +767,19 @@ function template_ticket_do_replies()
877 767
 			<div class="content">';
878 768
 
879 769
 	if (!empty($reply_request))
880
-	{
881 770
 		while ($reply = $context['get_replies']())
771
+			template_ticket_do_single_reply($reply);
772
+
773
+	echo '
774
+				</div>
775
+			</div>
776
+		</div>';
777
+}
778
+
779
+function template_ticket_do_single_reply($reply)
882 780
 {
781
+	global $context, $modSettings, $settings, $txt;
782
+
883 783
 	echo '
884 784
 					<div class="windowbg" id="reply', $reply['id'], '">
885 785
 						<div class="poster">
... ...
@@ -916,12 +816,10 @@ function template_ticket_do_replies()
916 816
 							<br><br>';
917 817
 
918 818
 	if (!empty($settings['show_modify']) && !empty($reply['modified']))
919
-			{
920 819
 		echo '
921
-							<div class="smalltext shd_modified" style="margin-top:20px;">
820
+							<div class="smalltext shd_modified">
922 821
 								&#171; <em>', $txt['last_edit'], ': ', $reply['modified']['time'], ' ', $txt['by'], ' ', $reply['modified']['link'], '</em> &#187;
923 822
 							</div>';
924
-			}
925 823
 
926 824
 	if (!empty($context['ticket_attach']['reply'][$reply['id']]))
927 825
 	{
... ...
@@ -950,13 +848,6 @@ function template_ticket_do_replies()
950 848
 						<br>
951 849
 					</div>';
952 850
 }
953
-	}
954
-
955
-	echo '
956
-				</div>
957
-			</div>
958
-		</div>';
959
-}
960 851
 
961 852
 function template_ticket_end_replies()
962 853
 {
... ...
@@ -998,6 +888,166 @@ function template_shd_thank_posting()
998 888
 	<br>';
999 889
 }
1000 890
 
891
+/**
892
+ *	Javascript for Custom Fields
893
+ *
894
+ *	@since 2.1
895
+*/
896
+function template_shd_js_custom_fields()
897
+{
898
+	global $context;
899
+
900
+	if (empty($context['ticket_form']['custom_fields'][$context['ticket_form']['custom_fields_context']]))
901
+		return;
902
+
903
+	echo '
904
+						<script type="text/javascript"><!-- // --><![CDATA[
905
+						var fields = new Array();';
906
+
907
+	foreach ($context['ticket_form']['custom_fields'][$context['ticket_form']['custom_fields_context']] as $field)
908
+		if ($field['editable'])
909
+			echo '
910
+						fields[', $field['id'], '] = [', implode(',', $field['depts']), '];';
911
+
912
+	echo '
913
+						var oDeptSelector = new shd_dept_filter({
914
+							sSelectContainerId: "newdept",
915
+							sCustomFieldsContainerId: "shd_customfields",
916
+							sCustomFieldsTitleContainerId: "shd_customfields_title",
917
+							oFields: fields,
918
+						});
919
+						// ]', ']></script>';
920
+}
921
+
922
+/**
923
+ *	Javascript for Canned repleis
924
+ *
925
+ *	@since 2.1
926
+*/
927
+function template_shd_js_canned_replies()
928
+{
929
+	global $context;
930
+
931
+	echo '
932
+					<script type="text/javascript"><!-- // --><![CDATA[
933
+					var oCannedReplies = new CannedReply({
934
+						iTicketId: ', $context['ticket_id'], ',
935
+						sScriptUrl: smf_scripturl,
936
+						sSessionVar: "', $context['session_var'], '",
937
+						sSessionId: "', $context['session_id'], '",
938
+						sCannedRepliesContainerId: "canned_replies",
939
+						sSelectContainerId: "canned_replies_select",
940
+					});
941
+					// ]]></script>';
942
+}
943
+
944
+/**
945
+ *	Javascript for Additional Options
946
+ *
947
+ *	@since 2.1
948
+*/
949
+function tempalte_shd_js_additional_options()
950
+{
951
+	global $context, $options, $txt;
952
+
953
+	echo '
954
+					<script>
955
+						var oAdditionalOptionsToggle = new smc_Toggle({
956
+							bToggleEnabled: true,
957
+							bCurrentlyCollapsed: ', empty($options['collapse_shd_additionalOptions']) ? 'false' : 'true', ',
958
+							aSwappableContainers: [
959
+								\'postAdditionalOptionsHeader\'
960
+							],
961
+							aSwapImages: [
962
+								{
963
+									sId: \'shd_additionalOptionsToggle\',
964
+								}
965
+							],
966
+							aSwapLinks: [
967
+								{
968
+									sId: \'shd_additionalOptionsLink\',
969
+									msgCollapsed: ', JavaScriptEscape($txt['shd_ticket_additional_information']), ',
970
+									msgExpanded: ', JavaScriptEscape($txt['shd_ticket_additional_information']), ',
971
+								},
972
+							],
973
+							oThemeOptions: {
974
+								bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
975
+								sOptionName: \'collapse_shd_additionalOptions\',
976
+								sSessionId: smf_session_id,
977
+								sSessionVar: smf_session_var,
978
+							},
979
+							oCookieOptions: {
980
+								bUseCookie: false,
981
+								sCookieName: \'shd_additionalOptions\'
982
+							}
983
+						});
984
+					</script>';
985
+}
986
+
987
+/**
988
+ *	Javascript for Attachments
989
+ *
990
+ *	@since 2.1
991
+*/
992
+function tempalte_shd_js_attachments()
993
+{
994
+	global $context, $modSettings, $txt;
995
+
996
+	echo '
997
+					<script type="text/javascript"><!-- // --><![CDATA[
998
+	var oAttach = new shd_attach_select({
999
+		file_item: "shd_attach",
1000
+		file_container: "shd_attachlist_container",
1001
+		max: ', $context['ticket_form']['num_allowed_attachments'], ',
1002
+		message_txt_delete: ', JavaScriptEscape($txt['remove']);
1003
+
1004
+	if (!empty($modSettings['attachmentExtensions']) && !empty($modSettings['attachmentCheckExtensions']))
1005
+	{
1006
+		$ext = explode(',', $modSettings['attachmentExtensions']);
1007
+		foreach ($ext as $k => $v)
1008
+			$ext[$k] = JavaScriptEscape($v);
1009
+
1010
+		echo ',
1011
+		message_ext_error: ', JavaScriptEscape(str_replace('{attach_exts}', $context['allowed_extensions'], $txt['shd_cannot_attach_ext'])), ',
1012
+		attachment_ext: [', implode(',', $ext), ']';
1013
+	}
1014
+
1015
+	echo '
1016
+	});
1017
+					// ]]></script>';
1018
+}
1019
+
1020
+/**
1021
+ *	Javascript for Notifications
1022
+ *
1023
+ *	@since 2.1
1024
+*/
1025
+function tempalte_shd_js_notifications()
1026
+{
1027
+	global $context;
1028
+
1029
+	echo '
1030
+						<script type="text/javascript"><!-- // --><![CDATA[
1031
+	var shd_oNotifications = new shd_notifications(', $context['ticket_id'], ', {
1032
+		sContainerId: "shd_notifications_div",
1033
+		sLinkId: "shd_getAjaxNotifications",
1034
+		sPinglist: "', (!empty($context['notification_ping_list']) ? $context['notification_ping_list'] : ''), '",
1035
+		sSessionId: smf_session_id,
1036
+		sSessionVar: smf_session_var,
1037
+		oMainTemplate: ', JavaScriptEscape('
1038
+			<span class=\'shd_ajax_head\'>%title%</span><br>%subtemplate%<br>
1039
+							'), ',
1040
+		oNotifiedTemplate: ', JavaScriptEscape('%name%, '), ',
1041
+		oOptionalTemplate: ', JavaScriptEscape('
1042
+				<div class=\'shd_ajaxnotify\'><input type=\'checkbox\' name=\'notify[%index%]\' value=\'%index%\'%checked%>%name%</div>
1043
+								'), ',
1044
+		oOptionalOffTemplate: ', JavaScriptEscape('
1045
+				<div class=\'shd_ajaxnotify\'><input type=\'checkbox\' name=\'notify[%index%]\' value=\'%index%\'%checked%>%name%</div>
1046
+								'), ',
1047
+	});
1048
+						// ]]></script>';
1049
+}
1050
+
1001 1051
 /**
1002 1052
  *	Displays a header that Javascript should be enabled while in the administration panel area of SimpleDesk.
1003 1053
  *
... ...
@@ -72,10 +73,6 @@ function template_shd_profile_main()
72 73
 					<dt>', $txt['username'], ': </dt>
73 74
 					<dd>', $context['member']['username'], '</dd>';
74 75
 
75
-		// Is this member requiring activation and/or banned?
76
-		if (!empty($context['activate_message']) || !empty($context['member']['bans']))
77
-		{
78
-
79 76
 		// If the person looking at the summary has permission, and the account isn't activated, give the viewer the ability to do it themselves.
80 77
 		if (!empty($context['activate_message']))
81 78
 			echo '
... ...
@@ -85,8 +82,8 @@ function template_shd_profile_main()
85 82
 		if (!empty($context['member']['bans']))
86 83
 		{
87 84
 			echo '
88
-					<dt class="clear"><span class="alert">', $txt['user_is_banned'], '</span>&nbsp;[<a href="#" onclick="document.getElementById(\'ban_info\').style.display = document.getElementById(\'ban_info\').style.display == \'none\' ? \'\' : \'none\';return false;">' . $txt['view_ban'] . '</a>]</dt>
89
-					<dt class="clear" id="ban_info" style="display: none;">
85
+					<dt class="clear"><span class="alert">', $txt['user_is_banned'], '</span>&nbsp;[<a href="#" onclick="$(\'#ban_info\').toggle();">' . $txt['view_ban'] . '</a>]</dt>
86
+					<dt class="clear hidden" id="ban_info">
90 87
 						<strong>', $txt['user_banned_by_following'], ':</strong>';
91 88
 
92 89
 			foreach ($context['member']['bans'] as $ban)
... ...
@@ -96,7 +93,6 @@ function template_shd_profile_main()
96 93
 			echo '
97 94
 					</dt>';
98 95
 		}
99
-		}
100 96
 
101 97
 		echo '
102 98
 					<dt>', $txt['date_registered'], ': </dt>
... ...
@@ -166,8 +162,8 @@ function template_shd_profile_preferences()
166 162
 				</div>';
167 163
 
168 164
 	echo '
169
-				<div class="cat_bar">
170
-					<h3 class="catbg">
165
+				<div class="title_bar">
166
+					<h3 class="titlebg">
171 167
 						<img src="', $settings['default_images_url'], '/simpledesk/preferences.png" class="icon" alt="*">
172 168
 						', sprintf($txt['shd_profile_preferences_header'], $context['member']['name']), '
173 169
 					</h3>
... ...
@@ -194,9 +190,6 @@ function template_shd_profile_preferences()
194 190
 				<form action="', $scripturl, '?action=profile;area=hd_prefs;u=', $context['member']['id'], ';save" method="post">';
195 191
 
196 192
 	$display_save = false;
197
-	$displayed_groups = array();
198
-	$checkall_items = array();
199
-
200 193
 	foreach ($context['shd_preferences_options']['groups'] as $group => $details)
201 194
 	{
202 195
 		if (empty($details['groups']))
... ...
@@ -208,13 +201,9 @@ function template_shd_profile_preferences()
208 201
 		echo '<br>
209 202
 						<div class="cat_bar" id="prefheader_', $group, '">
210 203
 							<h3 class="catbg">
211
-								<span id="prefexpand_', $group, '" class="floatright toggle_up" onclick="shd_toggleblock(\'', $group, '\'); return false;">&nbsp;<!--
212
-									<a class="permcollapse" href="#" onclick="shd_toggleblock(\'', $group, '\'); return false;">
213
-										<img src="', $settings['images_url'], '/selected_open.png" id="prefexpandicon_', $group, '" style="display:none;">
214
-									</a>-->
215
-								</span>
204
+								<span class="toggle_up floatright" id="prefexpandicon_', $group, '"></span>
216 205
 								<img src="', shd_image_url($details['icon']), '" class="icon" alt="*">
217
-								<a class="prefcollapse" href="#prefheader_', $group, '" onclick="shd_toggleblock(\'', $group, '\'); return false;">', $txt['shd_pref_group_' . $group], '</a>
206
+								<a class="prefcollapse" href="#prefheader_', $group, '" id="prefexpand_', $group, '_swap_link">', $txt['shd_pref_group_' . $group], '</a>
218 207
 							</h3>
219 208
 						</div>
220 209
 						<div class="roundframe noup" id="prefgroup_', $group, '">
... ...
@@ -261,14 +250,11 @@ function template_shd_profile_preferences()
261 250
 
262 251
 		// Only display if the preference group is set to actually have said option, and if 3+ were actually being displayed, otherwise it looks stupid.
263 252
 		if (!empty($details['check_all']) && count($details['groups']) > 2)
264
-		{
265 253
 			echo '
266
-								<div id="checkall_div_', $group, '" style="display:none;">
254
+								<div id="checkall_div_', $group, '">
267 255
 									<input type="checkbox" name="all" id="check_all" value="" onclick="invertAll(this, this.form, \'', $group, '\');" class="floatleft">
268 256
 									<label for="check_all" class="floatleft">', $txt['check_all'], '</label>
269 257
 								</div>';
270
-			$checkall_items[] = $group;
271
-		}
272 258
 
273 259
 		echo '
274 260
 							</div>
... ...
@@ -276,37 +262,11 @@ function template_shd_profile_preferences()
276 262
 						<span id="preffooter_', $group, '"></span>';
277 263
 	}
278 264
 
279
-	// And the JS required to hide everything.
280
-	if (!empty($displayed_groups) || !empty($checkall_items))
281
-	{
282
-		echo '
283
-						<script type="text/javascript"><!-- // --><![CDATA[';
284
-
285
-		if (!empty($displayed_groups))
286
-			echo '
287
-						var hidden_blocks = ["', implode('","', $displayed_groups), '"];
288
-						for (i in hidden_blocks)
289
-						{
290
-							shd_toggleblock(hidden_blocks[i]);
291
-						}';
292
-
293
-		if (!empty($checkall_items))
294
-			echo '
295
-						var checkall_items = ["', implode('","', $checkall_items), '"];
296
-						for (i in checkall_items)
297
-						{
298
-							document.getElementById("checkall_div_" + checkall_items[i]).style.display = "";
299
-						}';
300
-
301
-		echo '
302
-						// ]', ']></script>';
303
-	}
304
-
305 265
 	if ($display_save)
306 266
 		echo '
307 267
 						<br>
308 268
 						<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
309
-						<input type="submit" value="', $txt['shd_profile_save_prefs'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">';
269
+						<input type="submit" value="', $txt['shd_profile_save_prefs'], '" accesskey="s" class="button save">';
310 270
 	else
311 271
 		echo '
312 272
 						<br>
... ...
@@ -325,6 +285,8 @@ function template_shd_profile_preferences()
325 285
 
326 286
 	echo '
327 287
 				</form>';
288
+
289
+	template_shd_profile_js_preferences();
328 290
 }
329 291
 
330 292
 function template_shd_profile_show_tickets()
... ...
@@ -350,7 +312,7 @@ function template_shd_profile_show_tickets()
350 312
 	<div class="tborder">
351 313
 		<div class="title_bar">
352 314
 			<h3 class="titlebg">
353
-				<img src="', $settings['default_images_url'], '/simpledesk/', $context['can_haz_replies'] ? 'replies' : 'ticket', '.png" class="floatright shd_icon_fullhead" alt=""/>
315
+				<img src="', $settings['default_images_url'], '/simpledesk/', $context['can_haz_replies'] ? 'replies' : 'ticket', '.png" class="floatright shd_icon_fullhead" alt="">
354 316
 				<span class="smalltext">', $context['page_index'], '</span>
355 317
 			</h3>
356 318
 		</div>';
... ...
@@ -384,7 +346,7 @@ function template_shd_profile_show_tickets()
384 346
 	echo '
385 347
 		<div class="title_bar">
386 348
 			<h3 class="titlebg">
387
-				<img src="', $settings['default_images_url'], '/simpledesk/', $context['can_haz_replies'] ? 'replies' : 'ticket', '.png" class="floatright shd_icon_fullhead" alt=""/>
349
+				<img src="', $settings['default_images_url'], '/simpledesk/', $context['can_haz_replies'] ? 'replies' : 'ticket', '.png" class="floatright shd_icon_fullhead" alt="">
388 350
 				<span class="smalltext">', $context['page_index'], '</span>
389 351
 			</h3>
390 352
 		</div>
... ...
@@ -422,16 +384,12 @@ function template_shd_profile_show_notify_override()
422 384
 					</tr>';
423 385
 
424 386
 	if (empty($context['tickets']))
425
-	{
426 387
 		echo '
427 388
 					<tr class="windowbg">
428 389
 						<td colspan="7">', $txt['shd_error_no_tickets'], '</td>
429 390
 					</tr>';
430
-	}
431 391
 	else
432
-	{
433 392
 		foreach ($context['tickets'] as $ticket)
434
-		{
435 393
 			echo '
436 394
 						<tr class="windowbg">
437 395
 							<td width="4%" class="smalltext">', $ticket['id_ticket_display'], '</td>
... ...
@@ -442,8 +400,6 @@ function template_shd_profile_show_notify_override()
442 400
 							<td class="smalltext">', $txt['shd_urgency_' . $ticket['urgency']], '</td>
443 401
 							<td class="smalltext">', $ticket['updated'], '</td>
444 402
 						</tr>';
445
-		}
446
-	}
447 403
 
448 404
 	echo '
449 405
 					</table>';
... ...
@@ -462,9 +418,9 @@ function template_shd_profile_permissions()
462 418
 						</h3>
463 419
 					</div>';
464 420
 
421
+	// Whoa, this dude's special. Tidy up and BAIL!
465 422
 	if (!empty($context['member']['has_all_permissions']))
466 423
 	{
467
-		// Whoa, this dude's special. Tidy up and BAIL!
468 424
 		echo '
469 425
 					<p class="information">
470 426
 						', $txt['shd_profile_permissions_all_admin'], '
... ...
@@ -520,12 +477,10 @@ function template_shd_profile_permissions()
520 477
 						</tr>';
521 478
 
522 479
 	if (empty($context['member_roles']))
523
-	{
524 480
 		echo '
525 481
 						<tr class="windowbg">
526 482
 							<td colspan="3" class="centertext">', $txt['shd_profile_no_roles'], '</td>
527 483
 						</tr>';
528
-	}
529 484
 	else
530 485
 	{
531 486
 		foreach ($context['member_roles'] as $role)
... ...
@@ -698,9 +654,7 @@ function template_shd_profile_actionlog()
698 654
 							<td colspan="2" class="shd_noticket">', $txt['shd_profile_log_none'], '</td>
699 655
 						</tr>';
700 656
 	else
701
-	{
702 657
 		foreach ($context['action_log'] as $action)
703
-		{
704 658
 			echo '
705 659
 						<tr class="windowbg">
706 660
 							<td class="smalltext">', $action['time'], '</td>
... ...
@@ -709,8 +663,6 @@ function template_shd_profile_actionlog()
709 663
 								', $action['action_text'], '
710 664
 							</td>
711 665
 						</tr>';
712
-		}
713
-	}
714 666
 
715 667
 	echo '
716 668
 						<tr class="titlebg">
... ...
@@ -731,18 +683,15 @@ function template_shd_profile_navigation_above()
731 683
 			<div class="tborder shd_profile_navigation">
732 684
 				<div class="roundframe">
733 685
 					<ul class="', !empty($options['use_sidebar_menu']) ? 'shd_profile_nav_inline' : 'shd_profile_nav_list', '">';
686
+
734 687
 	foreach ($context['shd_profile_menu'] as $menuitem)
735
-	{
736 688
 		if (!empty($menuitem['show']))
737
-		{
738 689
 			echo '
739 690
 						<li', (!empty($menuitem['is_last']) ? ' class="shd_inline_last"' : ''), '>
740 691
 							<img src="', $settings['default_images_url'], '/simpledesk/', $menuitem['image'], '" alt="x" class="floatright">
741 692
 							<a href="', $menuitem['link'], '"><strong>', $menuitem['text'], '</strong></a>
742 693
 							', (empty($options['use_sidebar_menu']) && empty($menuitem['is_last'])) ? '<hr>' : '', '
743 694
 						</li>';
744
-		}
745
-	}
746 695
 
747 696
 	echo '
748 697
 					</ul>
... ...
@@ -842,3 +791,52 @@ function template_profile_shd_theme_settings()
842 791
 						<dl>
843 792
 							<dd></dd>';
844 793
 }
794
+
795
+/**
796
+ *	Javascript for Preferences
797
+ *
798
+ *	@since 2.1
799
+*/
800
+function template_shd_profile_js_preferences()
801
+{
802
+	global $context, $options, $txt;
803
+
804
+	echo '
805
+	<script type="text/javascript"><!-- // --><![CDATA[';
806
+
807
+	foreach ($context['shd_preferences_options']['groups'] as $group => $details)
808
+		echo '
809
+		var oPreferences', $group, ' = new smc_Toggle({
810
+			bToggleEnabled: true,
811
+			bCurrentlyCollapsed: ', empty($options['collapse_shd_profile_' . $group]) ? 'false' : 'true', ',
812
+			aSwappableContainers: [
813
+				\'prefgroup_', $group, '\'
814
+			],
815
+			aSwapImages: [
816
+				{
817
+					sId: \'prefexpandicon_', $group, '\',
818
+				}
819
+			],
820
+			aSwapLinks: [
821
+				{
822
+					sId: \'prefexpand_', $group, '_swap_link\',
823
+					msgCollapsed: ', JavaScriptEscape($txt['shd_pref_group_' . $group]), ',
824
+					msgExpanded: ', JavaScriptEscape($txt['shd_pref_group_' . $group]), ',
825
+				},
826
+			],
827
+			oThemeOptions: {
828
+				bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
829
+				sOptionName: \'collapse_shd_profile_', $group, '\',
830
+				sSessionId: smf_session_id,
831
+				sSessionVar: smf_session_var,
832
+			},
833
+			oCookieOptions: {
834
+				bUseCookie: false,
835
+				sCookieName: \'collapse_shd_profile_', $group, '\'
836
+			}
837
+		});';
838
+
839
+	echo '
840
+	// ]' . ']></script>';
841
+
842
+}
845 843
\ No newline at end of file
... ...
@@ -66,11 +66,8 @@ function template_search()
66 66
 				</dl>';
67 67
 
68 68
 	if (count($context['dept_list']) == 1)
69
-	{
70
-		$array = array_keys($context['dept_list']);
71 69
 		echo '
72
-					<input type="hidden" name="search_dept[]" value="', $array[0], '">';
73
-	}
70
+					<input type="hidden" name="search_dept[]" value="', array_keys($context['dept_list'])[0], '">';
74 71
 	else
75 72
 	{
76 73
 		echo '
... ...
@@ -140,40 +137,14 @@ function template_search()
140 137
 						<input type="text" name="assignee_name" id="assignee_name" size="40" maxlength="100" value="">
141 138
 						<div id="assignee_name_container"></div>
142 139
 					</dd>
143
-				</dl>
140
+				</dl>';
144 141
 
145
-				<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?20fin"></script>
146
-				<script type="text/javascript"><!-- // --><![CDATA[
147
-					var oTicketStarter = new smc_AutoSuggest({
148
-						sSelf: \'oTicketStarter\',
149
-						sSessionId: \'', $context['session_id'], '\',
150
-						sSessionVar: \'', $context['session_var'], '\',
151
-						sControlId: \'starter_name\',
152
-						sSuggestId: \'starter\',
153
-						sSearchType: \'member\',
154
-						sPostName: \'starter_name_form\',
155
-						sURLMask: \'action=profile;u=%item_id%\',
156
-						bItemList: true,
157
-						sItemListContainerId: \'starter_name_container\',
158
-						aListItems: []
159
-					});
160
-					var oTicketAssignee = new smc_AutoSuggest({
161
-						sSelf: \'oTicketAssignee\',
162
-						sSessionId: \'', $context['session_id'], '\',
163
-						sSessionVar: \'', $context['session_var'], '\',
164
-						sControlId: \'assignee_name\',
165
-						sSuggestId: \'assignee\',
166
-						sSearchType: \'member\',
167
-						sPostName: \'assigned_name_form\',
168
-						sURLMask: \'action=profile;u=%item_id%\',
169
-						bItemList: true,
170
-						sItemListContainerId: \'assignee_name_container\',
171
-						aListItems: []
172
-					});
173
-				// ]', ']></script>
142
+	template_shd_js_search();
143
+
144
+	echo '
174 145
 				<hr>
175 146
 				<br>
176
-				<input type="submit" value="', $txt['shd_search'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
147
+				<input type="submit" value="', $txt['shd_search'], '" accesskey="s" class="button save">
177 148
 			</div>
178 149
 		</form>
179 150
 	</div>';
... ...
@@ -319,7 +290,7 @@ function template_search_results()
319 290
 	<div class="search_results_posts">
320 291
 		<div class="windowbg core_posts">
321 292
 			<div class="content flow_auto">
322
-				<div class="topic_details floatleft" style="width: 94%">
293
+				<div class="topic_details floatleft">
323 294
 					<div class="counter">', $result['result'], '</div>
324 295
 					<h5>', $result['dept_link'], '<a href="', $scripturl, '?action=helpdesk;sa=ticket;ticket=', $result['id_ticket'], '">', sprintf($result['is_ticket'] ? $txt['shd_search_result_ticket'] : $txt['shd_search_result_reply'], $result['display_id']), '</a> - ', $result['subject'], ' (', $txt['shd_search_last_updated'], ' ', timeformat($result['last_updated']), ')</h5>
325 296
 					<span class="smalltext">&#171;&nbsp;<strong>', $result['is_ticket'] ? $txt['shd_search_ticket_opened_by'] : $txt['shd_search_ticket_replied_by'], ' ', shd_profile_link($result['poster_name'], $result['id_member']), '</strong>&nbsp;', $txt['on'], '&nbsp;<em>', timeformat($result['poster_time']), '</em>&nbsp;&#187;</span>
... ...
@@ -370,11 +341,8 @@ function template_search_navigation($page = 'next')
370 341
 
371 342
 	// Departments.
372 343
 	if (count($context['dept_list']) == 1)
373
-	{
374
-		$array = array_keys($context['dept_list']);
375 344
 		echo '
376
-		<input type="hidden" name="search_dept[]" value="', $array[0], '">';
377
-	}
345
+		<input type="hidden" name="search_dept[]" value="', array_keys($context['dept_list'])[0], '">';
378 346
 	elseif (isset($context['search_params']['visible_depts']))
379 347
 		foreach ($context['search_params']['visible_depts'] as $dept)
380 348
 		echo '
... ...
@@ -412,15 +380,55 @@ function template_search_navigation($page = 'next')
412 380
 	if ($page === 'prev')
413 381
 		echo '
414 382
 		<input type="hidden" name="page" value="', $context['prev_page'], '">
415
-		<input type="submit" value="Previous" onclick="return submitThisOnce(this);" class="button floatleft">';
383
+		<input type="submit" value="Previous" class="button save floatleft">';
416 384
 	elseif (is_int($page) && $page > 0)
417 385
 		echo '
418 386
 		<input type="hidden" name="page" value="', $page, '">
419
-		<input type="submit" value="Page ', $page, '" onclick="return submitThisOnce(this);" class="button floatleft', $context['current_page'] == $page ? ' active' : '', '">';
387
+		<input type="submit" value="Page ', $page, '" class="button save floatleft', $context['current_page'] == $page ? ' active' : '', '">';
420 388
 	else
421 389
 		echo '
422 390
 		<input type="hidden" name="page" value="', $context['next_page'], '">
423
-		<input type="submit" value="Next" onclick="return submitThisOnce(this);" class="button">';
391
+		<input type="submit" value="Next" class="button save">';
424 392
 
425 393
 	echo '</form>';
426 394
 }
395
+
396
+/**
397
+ *	Javascript for Search
398
+ *
399
+ *	@since 2.1
400
+*/
401
+function template_shd_js_search()
402
+{
403
+	global $context, $settings;
404
+
405
+	echo '
406
+				<script type="text/javascript"><!-- // --><![CDATA[
407
+					var oTicketStarter = new smc_AutoSuggest({
408
+						sSelf: \'oTicketStarter\',
409
+						sSessionId: \'', $context['session_id'], '\',
410
+						sSessionVar: \'', $context['session_var'], '\',
411
+						sControlId: \'starter_name\',
412
+						sSuggestId: \'starter\',
413
+						sSearchType: \'member\',
414
+						sPostName: \'starter_name_form\',
415
+						sURLMask: \'action=profile;u=%item_id%\',
416
+						bItemList: true,
417
+						sItemListContainerId: \'starter_name_container\',
418
+						aListItems: []
419
+					});
420
+					var oTicketAssignee = new smc_AutoSuggest({
421
+						sSelf: \'oTicketAssignee\',
422
+						sSessionId: \'', $context['session_id'], '\',
423
+						sSessionVar: \'', $context['session_var'], '\',
424
+						sControlId: \'assignee_name\',
425
+						sSuggestId: \'assignee\',
426
+						sSearchType: \'member\',
427
+						sPostName: \'assigned_name_form\',
428
+						sURLMask: \'action=profile;u=%item_id%\',
429
+						bItemList: true,
430
+						sItemListContainerId: \'assignee_name_container\',
431
+						aListItems: []
432
+					});
433
+				// ]', ']></script>';
434
+}
427 435
\ No newline at end of file
... ...
@@ -36,7 +36,7 @@ function template_shd_tickettotopic()
36 36
 			</h3>
37 37
 		</div>
38 38
 		<div class="roundframe noup">
39
-		<form action="', $scripturl, '?action=helpdesk;sa=tickettotopic2;ticket=', $context['ticket_id'], '" method="post" onsubmit="submitonce(this);">
39
+		<form action="', $scripturl, '?action=helpdesk;sa=tickettotopic2;ticket=', $context['ticket_id'], '" method="post">
40 40
 				<dl class="settings">
41 41
 					<dt>
42 42
 						<strong>', $txt['shd_ticket_board'], ':</strong>
... ...
@@ -63,10 +63,10 @@ function template_shd_tickettotopic()
63 63
 						<strong>', $txt['shd_change_ticket_subject'], ':</strong>
64 64
 					</dt>
65 65
 					<dd>
66
-						<input type="checkbox" name="change_subject" id="change_subject" onclick="document.getElementById(\'new_subject\').style.display = this.checked ? \'block\' : \'none\';" >
66
+						<input type="checkbox" name="change_subject" id="change_subject" onclick="$(\'#new_subject\').toggle();">
67 67
 					</dd>
68 68
 				</dl>
69
-				<dl class="settings" style="display: none;" id="new_subject">
69
+				<dl class="settings hidden" id="new_subject">
70 70
 					<dt>
71 71
 						<strong>', $txt['shd_new_subject'], ':</strong>
72 72
 					</dt>
... ...
@@ -79,7 +79,7 @@ function template_shd_tickettotopic()
79 79
 						<strong>', $txt['shd_move_send_pm'], ':</strong>
80 80
 					</dt>
81 81
 					<dd>
82
-						<input type="checkbox" name="send_pm" id="send_pm" checked="checked" onclick="document.getElementById(\'pm_message\').style.display = this.checked ? \'block\' : \'none\';" >
82
+						<input type="checkbox" name="send_pm" id="send_pm" checked="checked" onclick="$(\'#pm_message\').toggle();">
83 83
 					</dd>
84 84
 				</dl>
85 85
 				<fieldset id="pm_message">
... ...
@@ -94,7 +94,6 @@ function template_shd_tickettotopic()
94 94
 				</fieldset>';
95 95
 
96 96
 	if (!empty($context['deleted_prompt']))
97
-	{
98 97
 		echo '
99 98
 				<fieldset id="deleted_replies">
100 99
 					<dl class="settings">
... ...
@@ -110,7 +109,6 @@ function template_shd_tickettotopic()
110 109
 						</dd>
111 110
 					</dl>
112 111
 				</fieldset>';
113
-	}
114 112
 
115 113
 	if (!empty($context['custom_fields']))
116 114
 	{
... ...
@@ -181,7 +179,7 @@ function template_shd_tickettotopic()
181 179
 	}
182 180
 
183 181
 	echo '
184
-				<input type="submit" value="', $txt['shd_move_ticket'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
182
+				<input type="submit" value="', $txt['shd_move_ticket'], '" accesskey="s" class="button save">
185 183
 				<input type="submit" name="cancel" value="', $txt['shd_cancel_ticket'], '" accesskey="c" class="button">
186 184
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
187 185
 				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
... ...
@@ -217,10 +215,10 @@ function template_shd_topictoticket()
217 215
 						<strong>', $txt['shd_change_topic_subject'], ':</strong>
218 216
 					</dt>
219 217
 					<dd>
220
-						<input type="checkbox" name="change_subject" id="change_subject" onclick="document.getElementById(\'new_subject\').style.display = this.checked ? \'block\' : \'none\';" >
218
+						<input type="checkbox" name="change_subject" id="change_subject" onclick="$(\'#new_subject\').toggle();">
221 219
 					</dd>
222 220
 				</dl>
223
-				<dl class="settings" style="display: none;" id="new_subject">
221
+				<dl class="settings hidden" id="new_subject">
224 222
 					<dt>
225 223
 						<strong>', $txt['shd_new_subject'], ':</strong>
226 224
 					</dt>
... ...
@@ -233,7 +231,7 @@ function template_shd_topictoticket()
233 231
 						<strong>', $txt['shd_move_send_pm_topic'], ':</strong>
234 232
 					</dt>
235 233
 					<dd>
236
-						<input type="checkbox" name="send_pm" id="send_pm" checked="checked" onclick="document.getElementById(\'pm_message\').style.display = this.checked ? \'block\' : \'none\';" >
234
+						<input type="checkbox" name="send_pm" id="send_pm" checked="checked" onclick="$(\'#pm_message\').toggle();">
237 235
 					</dd>
238 236
 				</dl>
239 237
 				<fieldset id="pm_message">
... ...
@@ -247,16 +245,13 @@ function template_shd_topictoticket()
247 245
 					</dl>
248 246
 				</fieldset>';
249 247
 
250
-	if (count($context['dept_list']) == 1)
251
-	{
252
-		$dept = array_keys($context);
253 248
 	// We can only see one department, so that's the one we will use.
249
+	if (count($context['dept_list']) == 1)
254 250
 		echo '
255 251
 				<dl class="settings">
256 252
 					<dt>', $context['ttm_move_dept'], '</dt>
257
-					<input type="hidden" name="dept" value="', $dept[0], '">
253
+					<input type="hidden" name="dept" value="', array_keys($context)[0], '">
258 254
 				</dl>';
259
-	}
260 255
 	else
261 256
 	{
262 257
 		// We can see multiple departments, so tell the moderator and also provide a list to pick from.
... ...
@@ -280,7 +275,7 @@ function template_shd_topictoticket()
280 275
 	}
281 276
 
282 277
 	echo '
283
-				<input type="submit" value="', $txt['shd_move_topic'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button">
278
+				<input type="submit" value="', $txt['shd_move_topic'], '" accesskey="s" class="button save">
284 279
 				<input type="submit" name="cancel" value="', $txt['shd_cancel_topic'], '" accesskey="c" class="button">
285 280
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
286 281
 				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
... ...
@@ -51,16 +51,12 @@ function template_shd_unread_below()
51 51
 						</tr>';
52 52
 
53 53
 	if (empty($context['shd_unread_info']))
54
-	{
55 54
 		echo '
56 55
 					<tr class="windowbg">
57 56
 							<td colspan="7">', $txt['shd_error_no_tickets'], '</td>
58 57
 						</tr>';
59
-	}
60 58
 	else
61
-	{
62 59
 		foreach ($context['shd_unread_info'] as $ticket)
63
-		{
64 60
 			echo '
65 61
 					<tr class="windowbg">
66 62
 							<td width="4%" class="smalltext">', $ticket['id_ticket_display'], '</td>
... ...
@@ -72,9 +68,6 @@ function template_shd_unread_below()
72 68
 							<td class="smalltext">', $ticket['updated'], '</td>
73 69
 						</tr>';
74 70
 
75
-		}
76
-	}
77
-
78 71
 	echo '
79 72
 				</table>';
80 73
 }
81 74
\ No newline at end of file
82 75