script.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687
  1. var smf_formSubmitted = false;
  2. var lastKeepAliveCheck = new Date().getTime();
  3. var smf_editorArray = new Array();
  4. // Some very basic browser detection - from Mozilla's sniffer page.
  5. var ua = navigator.userAgent.toLowerCase();
  6. var is_opera = ua.indexOf('opera') != -1;
  7. var is_ff = (ua.indexOf('firefox') != -1 || ua.indexOf('iceweasel') != -1 || ua.indexOf('icecat') != -1 || ua.indexOf('shiretoko') != -1 || ua.indexOf('minefield') != -1) && !is_opera;
  8. var is_gecko = ua.indexOf('gecko') != -1 && !is_opera;
  9. var is_chrome = ua.indexOf('chrome') != -1;
  10. var is_safari = ua.indexOf('applewebkit') != -1 && !is_chrome;
  11. var is_webkit = ua.indexOf('applewebkit') != -1;
  12. var is_ie = ua.indexOf('msie') != -1 && !is_opera;
  13. // Stupid Microsoft...
  14. var is_ie11 = ua.indexOf('trident') != -1 && ua.indexOf('gecko') != -1;
  15. var is_iphone = ua.indexOf('iphone') != -1 || ua.indexOf('ipod') != -1;
  16. var is_android = ua.indexOf('android') != -1;
  17. var ajax_indicator_ele = null;
  18. // Define XMLHttpRequest for IE
  19. if (!('XMLHttpRequest' in window) && 'ActiveXObject' in window)
  20. window.XMLHttpRequest = function () {
  21. return new ActiveXObject('MSXML2.XMLHTTP');
  22. };
  23. // Some older versions of Mozilla don't have this, for some reason.
  24. if (!('forms' in document))
  25. document.forms = document.getElementsByTagName('form');
  26. // Versions of ie < 9 do not have this built in
  27. if (!('getElementsByClassName' in document))
  28. {
  29. document.getElementsByClassName = function(className)
  30. {
  31. return $('".' + className + '"');
  32. }
  33. }
  34. // Load an XML document using XMLHttpRequest.
  35. function getXMLDocument(sUrl, funcCallback)
  36. {
  37. if (!window.XMLHttpRequest)
  38. return null;
  39. var oMyDoc = new XMLHttpRequest();
  40. var bAsync = typeof(funcCallback) != 'undefined';
  41. var oCaller = this;
  42. if (bAsync)
  43. {
  44. oMyDoc.onreadystatechange = function () {
  45. if (oMyDoc.readyState != 4)
  46. return;
  47. if (oMyDoc.responseXML != null && oMyDoc.status == 200)
  48. {
  49. if (funcCallback.call)
  50. {
  51. funcCallback.call(oCaller, oMyDoc.responseXML);
  52. }
  53. // A primitive substitute for the call method to support IE 5.0.
  54. else
  55. {
  56. oCaller.tmpMethod = funcCallback;
  57. oCaller.tmpMethod(oMyDoc.responseXML);
  58. delete oCaller.tmpMethod;
  59. }
  60. }
  61. };
  62. }
  63. oMyDoc.open('GET', sUrl, bAsync);
  64. oMyDoc.send(null);
  65. return oMyDoc;
  66. }
  67. // Send a post form to the server using XMLHttpRequest.
  68. function sendXMLDocument(sUrl, sContent, funcCallback)
  69. {
  70. if (!window.XMLHttpRequest)
  71. return false;
  72. var oSendDoc = new window.XMLHttpRequest();
  73. var oCaller = this;
  74. if (typeof(funcCallback) != 'undefined')
  75. {
  76. oSendDoc.onreadystatechange = function () {
  77. if (oSendDoc.readyState != 4)
  78. return;
  79. if (oSendDoc.responseXML != null && oSendDoc.status == 200)
  80. funcCallback.call(oCaller, oSendDoc.responseXML);
  81. else
  82. funcCallback.call(oCaller, false);
  83. };
  84. }
  85. oSendDoc.open('POST', sUrl, true);
  86. if ('setRequestHeader' in oSendDoc)
  87. oSendDoc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  88. oSendDoc.send(sContent);
  89. return true;
  90. }
  91. // A property we'll be needing for php_to8bit.
  92. String.prototype.oCharsetConversion = {
  93. from: '',
  94. to: ''
  95. };
  96. // Convert a string to an 8 bit representation (like in PHP).
  97. String.prototype.php_to8bit = function ()
  98. {
  99. if (smf_charset == 'UTF-8')
  100. {
  101. var n, sReturn = '';
  102. for (var i = 0, iTextLen = this.length; i < iTextLen; i++)
  103. {
  104. n = this.charCodeAt(i);
  105. if (n < 128)
  106. sReturn += String.fromCharCode(n)
  107. else if (n < 2048)
  108. sReturn += String.fromCharCode(192 | n >> 6) + String.fromCharCode(128 | n & 63);
  109. else if (n < 65536)
  110. sReturn += String.fromCharCode(224 | n >> 12) + String.fromCharCode(128 | n >> 6 & 63) + String.fromCharCode(128 | n & 63);
  111. else
  112. sReturn += String.fromCharCode(240 | n >> 18) + String.fromCharCode(128 | n >> 12 & 63) + String.fromCharCode(128 | n >> 6 & 63) + String.fromCharCode(128 | n & 63);
  113. }
  114. return sReturn;
  115. }
  116. else if (this.oCharsetConversion.from.length == 0)
  117. {
  118. switch (smf_charset)
  119. {
  120. case 'ISO-8859-1':
  121. this.oCharsetConversion = {
  122. from: '\xa0-\xff',
  123. to: '\xa0-\xff'
  124. };
  125. break;
  126. case 'ISO-8859-2':
  127. this.oCharsetConversion = {
  128. from: '\xa0\u0104\u02d8\u0141\xa4\u013d\u015a\xa7\xa8\u0160\u015e\u0164\u0179\xad\u017d\u017b\xb0\u0105\u02db\u0142\xb4\u013e\u015b\u02c7\xb8\u0161\u015f\u0165\u017a\u02dd\u017e\u017c\u0154\xc1\xc2\u0102\xc4\u0139\u0106\xc7\u010c\xc9\u0118\xcb\u011a\xcd\xce\u010e\u0110\u0143\u0147\xd3\xd4\u0150\xd6\xd7\u0158\u016e\xda\u0170\xdc\xdd\u0162\xdf\u0155\xe1\xe2\u0103\xe4\u013a\u0107\xe7\u010d\xe9\u0119\xeb\u011b\xed\xee\u010f\u0111\u0144\u0148\xf3\xf4\u0151\xf6\xf7\u0159\u016f\xfa\u0171\xfc\xfd\u0163\u02d9',
  129. to: '\xa0-\xff'
  130. };
  131. break;
  132. case 'ISO-8859-5':
  133. this.oCharsetConversion = {
  134. from: '\xa0\u0401-\u040c\xad\u040e-\u044f\u2116\u0451-\u045c\xa7\u045e\u045f',
  135. to: '\xa0-\xff'
  136. };
  137. break;
  138. case 'ISO-8859-9':
  139. this.oCharsetConversion = {
  140. from: '\xa0-\xcf\u011e\xd1-\xdc\u0130\u015e\xdf-\xef\u011f\xf1-\xfc\u0131\u015f\xff',
  141. to: '\xa0-\xff'
  142. };
  143. break;
  144. case 'ISO-8859-15':
  145. this.oCharsetConversion = {
  146. from: '\xa0-\xa3\u20ac\xa5\u0160\xa7\u0161\xa9-\xb3\u017d\xb5-\xb7\u017e\xb9-\xbb\u0152\u0153\u0178\xbf-\xff',
  147. to: '\xa0-\xff'
  148. };
  149. break;
  150. case 'tis-620':
  151. this.oCharsetConversion = {
  152. from: '\u20ac\u2026\u2018\u2019\u201c\u201d\u2022\u2013\u2014\xa0\u0e01-\u0e3a\u0e3f-\u0e5b',
  153. to: '\x80\x85\x91-\x97\xa0-\xda\xdf-\xfb'
  154. };
  155. break;
  156. case 'windows-1251':
  157. this.oCharsetConversion = {
  158. from: '\u0402\u0403\u201a\u0453\u201e\u2026\u2020\u2021\u20ac\u2030\u0409\u2039\u040a\u040c\u040b\u040f\u0452\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u2122\u0459\u203a\u045a\u045c\u045b\u045f\xa0\u040e\u045e\u0408\xa4\u0490\xa6\xa7\u0401\xa9\u0404\xab-\xae\u0407\xb0\xb1\u0406\u0456\u0491\xb5-\xb7\u0451\u2116\u0454\xbb\u0458\u0405\u0455\u0457\u0410-\u044f',
  159. to: '\x80-\x97\x99-\xff'
  160. };
  161. break;
  162. case 'windows-1253':
  163. this.oCharsetConversion = {
  164. from: '\u20ac\u201a\u0192\u201e\u2026\u2020\u2021\u2030\u2039\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u2122\u203a\xa0\u0385\u0386\xa3-\xa9\xab-\xae\u2015\xb0-\xb3\u0384\xb5-\xb7\u0388-\u038a\xbb\u038c\xbd\u038e-\u03a1\u03a3-\u03ce',
  165. to: '\x80\x82-\x87\x89\x8b\x91-\x97\x99\x9b\xa0-\xa9\xab-\xd1\xd3-\xfe'
  166. };
  167. break;
  168. case 'windows-1255':
  169. this.oCharsetConversion = {
  170. from: '\u20ac\u201a\u0192\u201e\u2026\u2020\u2021\u02c6\u2030\u2039\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u02dc\u2122\u203a\xa0-\xa3\u20aa\xa5-\xa9\xd7\xab-\xb9\xf7\xbb-\xbf\u05b0-\u05b9\u05bb-\u05c3\u05f0-\u05f4\u05d0-\u05ea\u200e\u200f',
  171. to: '\x80\x82-\x89\x8b\x91-\x99\x9b\xa0-\xc9\xcb-\xd8\xe0-\xfa\xfd\xfe'
  172. };
  173. break;
  174. case 'windows-1256':
  175. this.oCharsetConversion = {
  176. from: '\u20ac\u067e\u201a\u0192\u201e\u2026\u2020\u2021\u02c6\u2030\u0679\u2039\u0152\u0686\u0698\u0688\u06af\u2018\u2019\u201c\u201d\u2022\u2013\u2014\u06a9\u2122\u0691\u203a\u0153\u200c\u200d\u06ba\xa0\u060c\xa2-\xa9\u06be\xab-\xb9\u061b\xbb-\xbe\u061f\u06c1\u0621-\u0636\xd7\u0637-\u063a\u0640-\u0643\xe0\u0644\xe2\u0645-\u0648\xe7-\xeb\u0649\u064a\xee\xef\u064b-\u064e\xf4\u064f\u0650\xf7\u0651\xf9\u0652\xfb\xfc\u200e\u200f\u06d2',
  177. to: '\x80-\xff'
  178. };
  179. break;
  180. default:
  181. this.oCharsetConversion = {
  182. from: '',
  183. to: ''
  184. };
  185. break;
  186. }
  187. var funcExpandString = function (sSearch) {
  188. var sInsert = '';
  189. for (var i = sSearch.charCodeAt(0), n = sSearch.charCodeAt(2); i <= n; i++)
  190. sInsert += String.fromCharCode(i);
  191. return sInsert;
  192. };
  193. this.oCharsetConversion.from = this.oCharsetConversion.from.replace(/.\-./g, funcExpandString);
  194. this.oCharsetConversion.to = this.oCharsetConversion.to.replace(/.\-./g, funcExpandString);
  195. }
  196. var sReturn = '', iOffsetFrom = 0;
  197. for (var i = 0, n = this.length; i < n; i++)
  198. {
  199. iOffsetFrom = this.oCharsetConversion.from.indexOf(this.charAt(i));
  200. sReturn += iOffsetFrom > -1 ? this.oCharsetConversion.to.charAt(iOffsetFrom) : (this.charCodeAt(i) > 127 ? '&#' + this.charCodeAt(i) + ';' : this.charAt(i));
  201. }
  202. return sReturn
  203. }
  204. // Character-level replacement function.
  205. String.prototype.php_strtr = function (sFrom, sTo)
  206. {
  207. return this.replace(new RegExp('[' + sFrom + ']', 'g'), function (sMatch) {
  208. return sTo.charAt(sFrom.indexOf(sMatch));
  209. });
  210. }
  211. // Simulate PHP's strtolower (in SOME cases PHP uses ISO-8859-1 case folding).
  212. String.prototype.php_strtolower = function ()
  213. {
  214. return typeof(smf_iso_case_folding) == 'boolean' && smf_iso_case_folding == true ? this.php_strtr(
  215. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\x8a\x8c\x8e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde',
  216. 'abcdefghijklmnopqrstuvwxyz\x9a\x9c\x9e\xff\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe'
  217. ) : this.php_strtr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
  218. }
  219. String.prototype.php_urlencode = function()
  220. {
  221. return escape(this).replace(/\+/g, '%2b').replace('*', '%2a').replace('/', '%2f').replace('@', '%40');
  222. }
  223. String.prototype.php_htmlspecialchars = function()
  224. {
  225. return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  226. }
  227. String.prototype.php_unhtmlspecialchars = function()
  228. {
  229. return this.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&');
  230. }
  231. String.prototype.php_addslashes = function()
  232. {
  233. return this.replace(/\\/g, '\\\\').replace(/'/g, '\\\'');
  234. }
  235. String.prototype._replaceEntities = function(sInput, sDummy, sNum)
  236. {
  237. return String.fromCharCode(parseInt(sNum));
  238. }
  239. String.prototype.removeEntities = function()
  240. {
  241. return this.replace(/&(amp;)?#(\d+);/g, this._replaceEntities);
  242. }
  243. String.prototype.easyReplace = function (oReplacements)
  244. {
  245. var sResult = this;
  246. for (var sSearch in oReplacements)
  247. sResult = sResult.replace(new RegExp('%' + sSearch + '%', 'g'), oReplacements[sSearch]);
  248. return sResult;
  249. }
  250. // Open a new window
  251. function reqWin(desktopURL, alternateWidth, alternateHeight, noScrollbars)
  252. {
  253. if ((alternateWidth && self.screen.availWidth * 0.8 < alternateWidth) || (alternateHeight && self.screen.availHeight * 0.8 < alternateHeight))
  254. {
  255. noScrollbars = false;
  256. alternateWidth = Math.min(alternateWidth, self.screen.availWidth * 0.8);
  257. alternateHeight = Math.min(alternateHeight, self.screen.availHeight * 0.8);
  258. }
  259. else
  260. noScrollbars = typeof(noScrollbars) == 'boolean' && noScrollbars == true;
  261. window.open(desktopURL, 'requested_popup', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=' + (noScrollbars ? 'no' : 'yes') + ',width=' + (alternateWidth ? alternateWidth : 480) + ',height=' + (alternateHeight ? alternateHeight : 220) + ',resizable=no');
  262. // Return false so the click won't follow the link ;).
  263. return false;
  264. }
  265. // Open a overlay div
  266. function reqOverlayDiv(desktopURL, sHeader, sIcon)
  267. {
  268. // Set up our div details
  269. var sAjax_indicator = '<div class="centertext"><img src="' + smf_images_url + '/loading.gif" ></div>';
  270. var sIcon = smf_images_url + '/' + (typeof(sIcon) == 'string' ? sIcon : 'helptopics.png');
  271. var sHeader = typeof(sHeader) == 'string' ? sHeader : help_popup_heading_text;
  272. // Create the div that we are going to load
  273. var oContainer = new smc_Popup({heading: sHeader, content: sAjax_indicator, icon: sIcon});
  274. var oPopup_body = $('#' + oContainer.popup_id).find('.popup_content');
  275. // Load the help page content (we just want the text to show)
  276. $.ajax({
  277. url: desktopURL,
  278. type: "GET",
  279. dataType: "html",
  280. beforeSend: function () {
  281. },
  282. success: function (data, textStatus, xhr) {
  283. var help_content = $('<div id="temp_help">').html(data).find('a[href$="self.close();"]').hide().prev('br').hide().parent().html();
  284. oPopup_body.html(help_content);
  285. },
  286. error: function (xhr, textStatus, errorThrown) {
  287. oPopup_body.html(textStatus);
  288. }
  289. });
  290. return false;
  291. }
  292. // Create the popup menus for the top level/user menu area.
  293. function smc_PopupMenu(oOptions)
  294. {
  295. this.opt = (typeof oOptions == 'object') ? oOptions : {};
  296. this.opt.menus = {};
  297. }
  298. smc_PopupMenu.prototype.add = function (sItem, sUrl)
  299. {
  300. var $menu = $('#' + sItem + '_menu'), $item = $('#' + sItem + '_menu_top');
  301. if ($item.length == 0)
  302. return;
  303. this.opt.menus[sItem] = {open: false, loaded: false, sUrl: sUrl, itemObj: $item, menuObj: $menu };
  304. $item.click({obj: this}, function (e) {
  305. e.preventDefault();
  306. if (e.target != this)
  307. return;
  308. e.data.obj.toggle(sItem);
  309. });
  310. }
  311. smc_PopupMenu.prototype.toggle = function (sItem)
  312. {
  313. if (!!this.opt.menus[sItem].open)
  314. this.close(sItem);
  315. else
  316. this.open(sItem);
  317. }
  318. smc_PopupMenu.prototype.open = function (sItem)
  319. {
  320. this.closeAll();
  321. if (!this.opt.menus[sItem].loaded)
  322. {
  323. this.opt.menus[sItem].menuObj.html('<div class="loading">' + (typeof(ajax_notification_text) != null ? ajax_notification_text : '') + '</div>');
  324. this.opt.menus[sItem].menuObj.load(this.opt.menus[sItem].sUrl);
  325. this.opt.menus[sItem].loaded = true;
  326. }
  327. this.opt.menus[sItem].menuObj.addClass('visible');
  328. this.opt.menus[sItem].itemObj.addClass('open');
  329. this.opt.menus[sItem].open = true;
  330. // Now set up closing the menu if we click off.
  331. $(document).on('click.menu', {obj: this}, function(e) {
  332. if ($(e.target).closest('#top_info').length)
  333. return;
  334. e.data.obj.closeAll();
  335. $(document).off('click.menu');
  336. });
  337. }
  338. smc_PopupMenu.prototype.close = function (sItem)
  339. {
  340. this.opt.menus[sItem].menuObj.removeClass('visible');
  341. this.opt.menus[sItem].itemObj.removeClass('open');
  342. this.opt.menus[sItem].open = false;
  343. $(document).off('click.menu');
  344. }
  345. smc_PopupMenu.prototype.closeAll = function ()
  346. {
  347. for (var prop in this.opt.menus)
  348. if (!!this.opt.menus[prop].open)
  349. this.close(prop);
  350. }
  351. // *** smc_Popup class.
  352. function smc_Popup(oOptions)
  353. {
  354. this.opt = oOptions;
  355. this.popup_id = this.opt.custom_id ? this.opt.custom_id : 'smf_popup';
  356. this.show();
  357. }
  358. smc_Popup.prototype.show = function ()
  359. {
  360. popup_class = 'popup_window ' + (this.opt.custom_class ? this.opt.custom_class : 'description');
  361. icon = this.opt.icon ? '<img src="' + this.opt.icon + '" class="icon" alt="" /> ' : '';
  362. // Create the div that will be shown
  363. $('body').append('<div id="' + this.popup_id + '" class="popup_container"><div class="' + popup_class + '"><div class="catbg popup_heading"><a href="javascript:void(0);" class="hide_popup"></a>' + icon + this.opt.heading + '</div><div class="popup_content">' + this.opt.content + '</div></div></div>');
  364. // Show it
  365. this.popup_body = $('#' + this.popup_id).children('.popup_window');
  366. this.popup_body.css({top: '25%', left: '50%', margin: '-' + ($(this.popup_body).height() / 2) + 'px 0 0 -' + ($(this.popup_body).width() / 2) + 'px'}).parent().fadeIn(300);
  367. // Trigger hide on escape or mouse click
  368. var popup_instance = this;
  369. $(document).mouseup(function (e) {
  370. if ($('#' + popup_instance.popup_id).has(e.target).length === 0)
  371. popup_instance.hide();
  372. }).keyup(function(e){
  373. if(e.keyCode == 27)
  374. popup_instance.hide();
  375. });
  376. $('#' + this.popup_id).find('.hide_popup').click(function (){ return popup_instance.hide(); });
  377. return false;
  378. }
  379. smc_Popup.prototype.hide = function ()
  380. {
  381. $('#' + this.popup_id).fadeOut(300, function(){ $(this).remove(); });
  382. return false;
  383. }
  384. // Remember the current position.
  385. function storeCaret(oTextHandle)
  386. {
  387. // Only bother if it will be useful.
  388. if ('createTextRange' in oTextHandle)
  389. oTextHandle.caretPos = document.selection.createRange().duplicate();
  390. }
  391. // Replaces the currently selected text with the passed text.
  392. function replaceText(text, oTextHandle)
  393. {
  394. // Attempt to create a text range (IE).
  395. if ('caretPos' in oTextHandle && 'createTextRange' in oTextHandle)
  396. {
  397. var caretPos = oTextHandle.caretPos;
  398. caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
  399. caretPos.select();
  400. }
  401. // Mozilla text range replace.
  402. else if ('selectionStart' in oTextHandle)
  403. {
  404. var begin = oTextHandle.value.substr(0, oTextHandle.selectionStart);
  405. var end = oTextHandle.value.substr(oTextHandle.selectionEnd);
  406. var scrollPos = oTextHandle.scrollTop;
  407. oTextHandle.value = begin + text + end;
  408. if (oTextHandle.setSelectionRange)
  409. {
  410. oTextHandle.focus();
  411. var goForward = is_opera ? text.match(/\n/g).length : 0;
  412. oTextHandle.setSelectionRange(begin.length + text.length + goForward, begin.length + text.length + goForward);
  413. }
  414. oTextHandle.scrollTop = scrollPos;
  415. }
  416. // Just put it on the end.
  417. else
  418. {
  419. oTextHandle.value += text;
  420. oTextHandle.focus(oTextHandle.value.length - 1);
  421. }
  422. }
  423. // Surrounds the selected text with text1 and text2.
  424. function surroundText(text1, text2, oTextHandle)
  425. {
  426. // Can a text range be created?
  427. if ('caretPos' in oTextHandle && 'createTextRange' in oTextHandle)
  428. {
  429. var caretPos = oTextHandle.caretPos, temp_length = caretPos.text.length;
  430. caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
  431. if (temp_length == 0)
  432. {
  433. caretPos.moveStart('character', -text2.length);
  434. caretPos.moveEnd('character', -text2.length);
  435. caretPos.select();
  436. }
  437. else
  438. oTextHandle.focus(caretPos);
  439. }
  440. // Mozilla text range wrap.
  441. else if ('selectionStart' in oTextHandle)
  442. {
  443. var begin = oTextHandle.value.substr(0, oTextHandle.selectionStart);
  444. var selection = oTextHandle.value.substr(oTextHandle.selectionStart, oTextHandle.selectionEnd - oTextHandle.selectionStart);
  445. var end = oTextHandle.value.substr(oTextHandle.selectionEnd);
  446. var newCursorPos = oTextHandle.selectionStart;
  447. var scrollPos = oTextHandle.scrollTop;
  448. oTextHandle.value = begin + text1 + selection + text2 + end;
  449. if (oTextHandle.setSelectionRange)
  450. {
  451. var goForward = is_opera ? text1.match(/\n/g).length : 0, goForwardAll = is_opera ? (text1 + text2).match(/\n/g).length : 0;
  452. if (selection.length == 0)
  453. oTextHandle.setSelectionRange(newCursorPos + text1.length + goForward, newCursorPos + text1.length + goForward);
  454. else
  455. oTextHandle.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length + goForwardAll);
  456. oTextHandle.focus();
  457. }
  458. oTextHandle.scrollTop = scrollPos;
  459. }
  460. // Just put them on the end, then.
  461. else
  462. {
  463. oTextHandle.value += text1 + text2;
  464. oTextHandle.focus(oTextHandle.value.length - 1);
  465. }
  466. }
  467. // Checks if the passed input's value is nothing.
  468. function isEmptyText(theField)
  469. {
  470. // Copy the value so changes can be made..
  471. if (typeof(theField) == 'string')
  472. var theValue = theField;
  473. else
  474. var theValue = theField.value;
  475. // Strip whitespace off the left side.
  476. while (theValue.length > 0 && (theValue.charAt(0) == ' ' || theValue.charAt(0) == '\t'))
  477. theValue = theValue.substring(1, theValue.length);
  478. // Strip whitespace off the right side.
  479. while (theValue.length > 0 && (theValue.charAt(theValue.length - 1) == ' ' || theValue.charAt(theValue.length - 1) == '\t'))
  480. theValue = theValue.substring(0, theValue.length - 1);
  481. if (theValue == '')
  482. return true;
  483. else
  484. return false;
  485. }
  486. // Only allow form submission ONCE.
  487. function submitonce(theform)
  488. {
  489. smf_formSubmitted = true;
  490. // If there are any editors warn them submit is coming!
  491. for (var i = 0; i < smf_editorArray.length; i++)
  492. smf_editorArray[i].doSubmit();
  493. }
  494. function submitThisOnce(oControl)
  495. {
  496. // oControl might also be a form.
  497. var oForm = 'form' in oControl ? oControl.form : oControl;
  498. var aTextareas = oForm.getElementsByTagName('textarea');
  499. for (var i = 0, n = aTextareas.length; i < n; i++)
  500. aTextareas[i].readOnly = true;
  501. return !smf_formSubmitted;
  502. }
  503. // Deprecated, as innerHTML is supported everywhere.
  504. function setInnerHTML(oElement, sToValue)
  505. {
  506. oElement.innerHTML = sToValue;
  507. }
  508. function getInnerHTML(oElement)
  509. {
  510. return oElement.innerHTML;
  511. }
  512. // Set the "outer" HTML of an element.
  513. function setOuterHTML(oElement, sToValue)
  514. {
  515. if ('outerHTML' in oElement)
  516. oElement.outerHTML = sToValue;
  517. else
  518. {
  519. var range = document.createRange();
  520. range.setStartBefore(oElement);
  521. oElement.parentNode.replaceChild(range.createContextualFragment(sToValue), oElement);
  522. }
  523. }
  524. // Checks for variable in theArray.
  525. function in_array(variable, theArray)
  526. {
  527. for (var i in theArray)
  528. if (theArray[i] == variable)
  529. return true;
  530. return false;
  531. }
  532. // Checks for variable in theArray.
  533. function array_search(variable, theArray)
  534. {
  535. for (var i in theArray)
  536. if (theArray[i] == variable)
  537. return i;
  538. return null;
  539. }
  540. // Find a specific radio button in its group and select it.
  541. function selectRadioByName(oRadioGroup, sName)
  542. {
  543. if (!('length' in oRadioGroup))
  544. return oRadioGroup.checked = true;
  545. for (var i = 0, n = oRadioGroup.length; i < n; i++)
  546. if (oRadioGroup[i].value == sName)
  547. return oRadioGroup[i].checked = true;
  548. return false;
  549. }
  550. function selectAllRadio(oInvertCheckbox, oForm, sMask, sValue)
  551. {
  552. for (var i = 0; i < oForm.length; i++)
  553. if (oForm[i].name != undefined && oForm[i].name.substr(0, sMask.length) == sMask && oForm[i].value == sValue)
  554. oForm[i].checked = true;
  555. }
  556. // Invert all checkboxes at once by clicking a single checkbox.
  557. function invertAll(oInvertCheckbox, oForm, sMask, bIgnoreDisabled)
  558. {
  559. for (var i = 0; i < oForm.length; i++)
  560. {
  561. if (!('name' in oForm[i]) || (typeof(sMask) == 'string' && oForm[i].name.substr(0, sMask.length) != sMask && oForm[i].id.substr(0, sMask.length) != sMask))
  562. continue;
  563. if (!oForm[i].disabled || (typeof(bIgnoreDisabled) == 'boolean' && bIgnoreDisabled))
  564. oForm[i].checked = oInvertCheckbox.checked;
  565. }
  566. }
  567. // Keep the session alive - always!
  568. var lastKeepAliveCheck = new Date().getTime();
  569. function smf_sessionKeepAlive()
  570. {
  571. var curTime = new Date().getTime();
  572. // Prevent a Firefox bug from hammering the server.
  573. if (smf_scripturl && curTime - lastKeepAliveCheck > 900000)
  574. {
  575. var tempImage = new Image();
  576. tempImage.src = smf_prepareScriptUrl(smf_scripturl) + 'action=keepalive;time=' + curTime;
  577. lastKeepAliveCheck = curTime;
  578. }
  579. window.setTimeout('smf_sessionKeepAlive();', 1200000);
  580. }
  581. window.setTimeout('smf_sessionKeepAlive();', 1200000);
  582. // Set a theme option through javascript.
  583. function smf_setThemeOption(option, value, theme, cur_session_id, cur_session_var, additional_vars)
  584. {
  585. // Compatibility.
  586. if (cur_session_id == null)
  587. cur_session_id = smf_session_id;
  588. if (typeof(cur_session_var) == 'undefined')
  589. cur_session_var = 'sesc';
  590. if (additional_vars == null)
  591. additional_vars = '';
  592. var tempImage = new Image();
  593. tempImage.src = smf_prepareScriptUrl(smf_scripturl) + 'action=jsoption;var=' + option + ';val=' + value + ';' + cur_session_var + '=' + cur_session_id + additional_vars + (theme == null ? '' : '&th=' + theme) + ';time=' + (new Date().getTime());
  594. }
  595. function smf_avatarResize()
  596. {
  597. var possibleAvatars = document.getElementsByTagName('img');
  598. for (var i = 0; i < possibleAvatars.length; i++)
  599. {
  600. var tempAvatars = []; j = 0;
  601. if (possibleAvatars[i].className != 'avatar')
  602. continue;
  603. // Image.prototype.avatar = possibleAvatars[i];
  604. tempAvatars[j] = new Image();
  605. tempAvatars[j].avatar = possibleAvatars[i];
  606. tempAvatars[j].onload = function()
  607. {
  608. this.avatar.width = this.width;
  609. this.avatar.height = this.height;
  610. if (smf_avatarMaxWidth != 0 && this.width > smf_avatarMaxWidth)
  611. {
  612. this.avatar.height = (smf_avatarMaxWidth * this.height) / this.width;
  613. this.avatar.width = smf_avatarMaxWidth;
  614. }
  615. if (smf_avatarMaxHeight != 0 && this.avatar.height > smf_avatarMaxHeight)
  616. {
  617. this.avatar.width = (smf_avatarMaxHeight * this.avatar.width) / this.avatar.height;
  618. this.avatar.height = smf_avatarMaxHeight;
  619. }
  620. }
  621. tempAvatars[j].src = possibleAvatars[i].src;
  622. j++;
  623. }
  624. if (typeof(window_oldAvatarOnload) != 'undefined' && window_oldAvatarOnload)
  625. {
  626. window_oldAvatarOnload();
  627. window_oldAvatarOnload = null;
  628. }
  629. }
  630. function hashLoginPassword(doForm, cur_session_id, token)
  631. {
  632. // Compatibility.
  633. if (cur_session_id == null)
  634. cur_session_id = smf_session_id;
  635. if (typeof(hex_sha1) == 'undefined')
  636. return;
  637. // Are they using an email address?
  638. if (doForm.user.value.indexOf('@') != -1)
  639. return;
  640. // Unless the browser is Opera, the password will not save properly.
  641. if (!('opera' in window))
  642. doForm.passwrd.autocomplete = 'off';
  643. doForm.hash_passwrd.value = hex_sha1(hex_sha1(doForm.user.value.php_to8bit().php_strtolower() + doForm.passwrd.value.php_to8bit()) + cur_session_id + token);
  644. // It looks nicer to fill it with asterisks, but Firefox will try to save that.
  645. if (is_ff != -1)
  646. doForm.passwrd.value = '';
  647. else
  648. doForm.passwrd.value = doForm.passwrd.value.replace(/./g, '*');
  649. }
  650. function hashAdminPassword(doForm, username, cur_session_id, token)
  651. {
  652. // Compatibility.
  653. if (cur_session_id == null)
  654. cur_session_id = smf_session_id;
  655. if (typeof(hex_sha1) == 'undefined')
  656. return;
  657. doForm.admin_hash_pass.value = hex_sha1(hex_sha1(username.php_to8bit().php_strtolower() + doForm.admin_pass.value.php_to8bit()) + cur_session_id + token);
  658. doForm.admin_pass.value = doForm.admin_pass.value.replace(/./g, '*');
  659. }
  660. function hashModeratePassword(doForm, username, cur_session_id, token)
  661. {
  662. if (typeof(hex_sha1) == 'undefined')
  663. return;
  664. doForm.moderate_hash_pass.value = hex_sha1(hex_sha1(username.php_to8bit().php_strtolower() + doForm.moderate_pass.value.php_to8bit()) + cur_session_id + token);
  665. doForm.moderate_pass.value = doForm.moderate_pass.value.replace(/./g, '*');
  666. }
  667. // Shows the page numbers by clicking the dots (in compact view).
  668. function expandPages(spanNode, baseURL, firstPage, lastPage, perPage)
  669. {
  670. var replacement = '', i, oldLastPage = 0;
  671. var perPageLimit = 50;
  672. // Prevent too many pages to be loaded at once.
  673. if ((lastPage - firstPage) / perPage > perPageLimit)
  674. {
  675. oldLastPage = lastPage;
  676. lastPage = firstPage + perPageLimit * perPage;
  677. }
  678. // Calculate the new pages.
  679. for (i = firstPage; i < lastPage; i += perPage)
  680. replacement += '<a class="navPages" href="' + baseURL.replace(/%1\$d/, i).replace(/%%/g, '%') + '">' + (1 + i / perPage) + '</a> ';
  681. if (oldLastPage > 0)
  682. replacement += '<span class="expand_pages" onclick="expandPages(this, \'' + baseURL + '\', ' + lastPage + ', ' + oldLastPage + ', ' + perPage + ');"> ... </span>';
  683. // Replace the dots by the new page links.
  684. setOuterHTML(spanNode, replacement);
  685. }
  686. function smc_preCacheImage(sSrc)
  687. {
  688. if (!('smc_aCachedImages' in window))
  689. window.smc_aCachedImages = [];
  690. if (!in_array(sSrc, window.smc_aCachedImages))
  691. {
  692. var oImage = new Image();
  693. oImage.src = sSrc;
  694. }
  695. }
  696. // *** smc_Cookie class.
  697. function smc_Cookie(oOptions)
  698. {
  699. this.opt = oOptions;
  700. this.oCookies = {};
  701. this.init();
  702. }
  703. smc_Cookie.prototype.init = function()
  704. {
  705. if ('cookie' in document && document.cookie != '')
  706. {
  707. var aCookieList = document.cookie.split(';');
  708. for (var i = 0, n = aCookieList.length; i < n; i++)
  709. {
  710. var aNameValuePair = aCookieList[i].split('=');
  711. this.oCookies[aNameValuePair[0].replace(/^\s+|\s+$/g, '')] = decodeURIComponent(aNameValuePair[1]);
  712. }
  713. }
  714. }
  715. smc_Cookie.prototype.get = function(sKey)
  716. {
  717. return sKey in this.oCookies ? this.oCookies[sKey] : null;
  718. }
  719. smc_Cookie.prototype.set = function(sKey, sValue)
  720. {
  721. document.cookie = sKey + '=' + encodeURIComponent(sValue);
  722. }
  723. // *** smc_Toggle class.
  724. function smc_Toggle(oOptions)
  725. {
  726. this.opt = oOptions;
  727. this.bCollapsed = false;
  728. this.oCookie = null;
  729. this.init();
  730. }
  731. smc_Toggle.prototype.init = function ()
  732. {
  733. // The master switch can disable this toggle fully.
  734. if ('bToggleEnabled' in this.opt && !this.opt.bToggleEnabled)
  735. return;
  736. // If cookies are enabled and they were set, override the initial state.
  737. if ('oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie)
  738. {
  739. // Initialize the cookie handler.
  740. this.oCookie = new smc_Cookie({});
  741. // Check if the cookie is set.
  742. var cookieValue = this.oCookie.get(this.opt.oCookieOptions.sCookieName)
  743. if (cookieValue != null)
  744. this.opt.bCurrentlyCollapsed = cookieValue == '1';
  745. }
  746. // If the init state is set to be collapsed, collapse it.
  747. if (this.opt.bCurrentlyCollapsed)
  748. this.changeState(true, true);
  749. // Initialize the images to be clickable.
  750. if ('aSwapImages' in this.opt)
  751. {
  752. for (var i = 0, n = this.opt.aSwapImages.length; i < n; i++)
  753. {
  754. var oImage = document.getElementById(this.opt.aSwapImages[i].sId);
  755. if (typeof(oImage) == 'object' && oImage != null)
  756. {
  757. // Display the image in case it was hidden.
  758. if (oImage.style.display == 'none')
  759. oImage.style.display = '';
  760. oImage.instanceRef = this;
  761. oImage.onclick = function () {
  762. this.instanceRef.toggle();
  763. this.blur();
  764. }
  765. oImage.style.cursor = 'pointer';
  766. // Preload the collapsed image.
  767. smc_preCacheImage(this.opt.aSwapImages[i].srcCollapsed);
  768. }
  769. }
  770. }
  771. // Initialize links.
  772. if ('aSwapLinks' in this.opt)
  773. {
  774. for (var i = 0, n = this.opt.aSwapLinks.length; i < n; i++)
  775. {
  776. var oLink = document.getElementById(this.opt.aSwapLinks[i].sId);
  777. if (typeof(oLink) == 'object' && oLink != null)
  778. {
  779. // Display the link in case it was hidden.
  780. if (oLink.style.display == 'none')
  781. oLink.style.display = '';
  782. oLink.instanceRef = this;
  783. oLink.onclick = function () {
  784. this.instanceRef.toggle();
  785. this.blur();
  786. return false;
  787. }
  788. }
  789. }
  790. }
  791. }
  792. // Collapse or expand the section.
  793. smc_Toggle.prototype.changeState = function(bCollapse, bInit)
  794. {
  795. // Default bInit to false.
  796. bInit = typeof(bInit) == 'undefined' ? false : true;
  797. // Handle custom function hook before collapse.
  798. if (!bInit && bCollapse && 'funcOnBeforeCollapse' in this.opt)
  799. {
  800. this.tmpMethod = this.opt.funcOnBeforeCollapse;
  801. this.tmpMethod();
  802. delete this.tmpMethod;
  803. }
  804. // Handle custom function hook before expand.
  805. else if (!bInit && !bCollapse && 'funcOnBeforeExpand' in this.opt)
  806. {
  807. this.tmpMethod = this.opt.funcOnBeforeExpand;
  808. this.tmpMethod();
  809. delete this.tmpMethod;
  810. }
  811. // Loop through all the images that need to be toggled.
  812. if ('aSwapImages' in this.opt)
  813. {
  814. for (var i = 0, n = this.opt.aSwapImages.length; i < n; i++)
  815. {
  816. var oImage = document.getElementById(this.opt.aSwapImages[i].sId);
  817. if (typeof(oImage) == 'object' && oImage != null)
  818. {
  819. // Only (re)load the image if it's changed.
  820. var sTargetSource = bCollapse ? this.opt.aSwapImages[i].srcCollapsed : this.opt.aSwapImages[i].srcExpanded;
  821. if (oImage.src != sTargetSource)
  822. oImage.src = sTargetSource;
  823. oImage.alt = oImage.title = bCollapse ? this.opt.aSwapImages[i].altCollapsed : this.opt.aSwapImages[i].altExpanded;
  824. }
  825. }
  826. }
  827. // Loop through all the links that need to be toggled.
  828. if ('aSwapLinks' in this.opt)
  829. {
  830. for (var i = 0, n = this.opt.aSwapLinks.length; i < n; i++)
  831. {
  832. var oLink = document.getElementById(this.opt.aSwapLinks[i].sId);
  833. if (typeof(oLink) == 'object' && oLink != null)
  834. setInnerHTML(oLink, bCollapse ? this.opt.aSwapLinks[i].msgCollapsed : this.opt.aSwapLinks[i].msgExpanded);
  835. }
  836. }
  837. // Now go through all the sections to be collapsed.
  838. for (var i = 0, n = this.opt.aSwappableContainers.length; i < n; i++)
  839. {
  840. if (this.opt.aSwappableContainers[i] == null)
  841. continue;
  842. var oContainer = document.getElementById(this.opt.aSwappableContainers[i]);
  843. if (typeof(oContainer) == 'object' && oContainer != null)
  844. {
  845. if (bCollapse)
  846. $(oContainer).slideUp();
  847. else
  848. $(oContainer).slideDown();
  849. }
  850. }
  851. // Update the new state.
  852. this.bCollapsed = bCollapse;
  853. // Update the cookie, if desired.
  854. if ('oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie)
  855. this.oCookie.set(this.opt.oCookieOptions.sCookieName, this.bCollapsed ? '1' : '0');
  856. if (!bInit && 'oThemeOptions' in this.opt && this.opt.oThemeOptions.bUseThemeSettings)
  857. smf_setThemeOption(this.opt.oThemeOptions.sOptionName, this.bCollapsed ? '1' : '0', 'sThemeId' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sThemeId : null, smf_session_id, smf_session_var, 'sAdditionalVars' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sAdditionalVars : null);
  858. }
  859. smc_Toggle.prototype.toggle = function()
  860. {
  861. // Change the state by reversing the current state.
  862. this.changeState(!this.bCollapsed);
  863. }
  864. function ajax_indicator(turn_on)
  865. {
  866. if (ajax_indicator_ele == null)
  867. {
  868. ajax_indicator_ele = document.getElementById('ajax_in_progress');
  869. if (ajax_indicator_ele == null && typeof(ajax_notification_text) != null)
  870. {
  871. create_ajax_indicator_ele();
  872. }
  873. }
  874. if (ajax_indicator_ele != null)
  875. {
  876. ajax_indicator_ele.style.display = turn_on ? 'block' : 'none';
  877. }
  878. }
  879. function create_ajax_indicator_ele()
  880. {
  881. // Create the div for the indicator.
  882. ajax_indicator_ele = document.createElement('div');
  883. // Set the id so it'll load the style properly.
  884. ajax_indicator_ele.id = 'ajax_in_progress';
  885. // Set the text. (Note: You MUST append here and not overwrite.)
  886. ajax_indicator_ele.innerHTML += ajax_notification_text;
  887. // Finally attach the element to the body.
  888. document.body.appendChild(ajax_indicator_ele);
  889. }
  890. function createEventListener(oTarget)
  891. {
  892. if (!('addEventListener' in oTarget))
  893. {
  894. if (oTarget.attachEvent)
  895. {
  896. oTarget.addEventListener = function (sEvent, funcHandler, bCapture) {
  897. oTarget.attachEvent('on' + sEvent, funcHandler);
  898. }
  899. oTarget.removeEventListener = function (sEvent, funcHandler, bCapture) {
  900. oTarget.detachEvent('on' + sEvent, funcHandler);
  901. }
  902. }
  903. else
  904. {
  905. oTarget.addEventListener = function (sEvent, funcHandler, bCapture) {
  906. oTarget['on' + sEvent] = funcHandler;
  907. }
  908. oTarget.removeEventListener = function (sEvent, funcHandler, bCapture) {
  909. oTarget['on' + sEvent] = null;
  910. }
  911. }
  912. }
  913. }
  914. // This function will retrieve the contents needed for the jump to boxes.
  915. function grabJumpToContent(elem)
  916. {
  917. var oXMLDoc = getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=xmlhttp;sa=jumpto;xml');
  918. var aBoardsAndCategories = new Array();
  919. var bIE5x = !('implementation' in document);
  920. ajax_indicator(true);
  921. if (oXMLDoc.responseXML)
  922. {
  923. var items = oXMLDoc.responseXML.getElementsByTagName('smf')[0].getElementsByTagName('item');
  924. for (var i = 0, n = items.length; i < n; i++)
  925. {
  926. aBoardsAndCategories[aBoardsAndCategories.length] = {
  927. id: parseInt(items[i].getAttribute('id')),
  928. isCategory: items[i].getAttribute('type') == 'category',
  929. name: items[i].firstChild.nodeValue.removeEntities(),
  930. is_current: false,
  931. childLevel: parseInt(items[i].getAttribute('childlevel'))
  932. }
  933. }
  934. }
  935. ajax_indicator(false);
  936. for (var i = 0, n = aJumpTo.length; i < n; i++)
  937. aJumpTo[i].fillSelect(aBoardsAndCategories);
  938. if (bIE5x)
  939. elem.options[iIndexPointer].selected = true;
  940. // Internet Explorer needs this to keep the box dropped down.
  941. elem.style.width = 'auto';
  942. elem.focus();
  943. }
  944. // This'll contain all JumpTo objects on the page.
  945. var aJumpTo = new Array();
  946. // *** JumpTo class.
  947. function JumpTo(oJumpToOptions)
  948. {
  949. this.opt = oJumpToOptions;
  950. this.dropdownList = null;
  951. this.showSelect();
  952. }
  953. // Show the initial select box (onload). Method of the JumpTo class.
  954. JumpTo.prototype.showSelect = function ()
  955. {
  956. var sChildLevelPrefix = '';
  957. for (var i = this.opt.iCurBoardChildLevel; i > 0; i--)
  958. sChildLevelPrefix += this.opt.sBoardChildLevelIndicator;
  959. setInnerHTML(document.getElementById(this.opt.sContainerId), this.opt.sJumpToTemplate.replace(/%select_id%/, this.opt.sContainerId + '_select').replace(/%dropdown_list%/, '<select ' + (this.opt.bDisabled == true ? 'disabled="disabled" ' : '') + (this.opt.sClassName != undefined ? 'class="' + this.opt.sClassName + '" ' : '') + 'name="' + (this.opt.sCustomName != undefined ? this.opt.sCustomName : this.opt.sContainerId + '_select') + '" id="' + this.opt.sContainerId + '_select" ' + ('implementation' in document ? '' : 'onmouseover="grabJumpToContent(this);" ') + ('onbeforeactivate' in document ? 'onbeforeactivate' : 'onfocus') + '="grabJumpToContent(this);"><option value="' + (this.opt.bNoRedirect != undefined && this.opt.bNoRedirect == true ? this.opt.iCurBoardId : '?board=' + this.opt.iCurBoardId + '.0') + '">' + sChildLevelPrefix + this.opt.sBoardPrefix + this.opt.sCurBoardName.removeEntities() + '</option></select>&nbsp;' + (this.opt.sGoButtonLabel != undefined ? '<input type="button" class="button_submit" value="' + this.opt.sGoButtonLabel + '" onclick="window.location.href = \'' + smf_prepareScriptUrl(smf_scripturl) + 'board=' + this.opt.iCurBoardId + '.0\';" />' : '')));
  960. this.dropdownList = document.getElementById(this.opt.sContainerId + '_select');
  961. }
  962. // Fill the jump to box with entries. Method of the JumpTo class.
  963. JumpTo.prototype.fillSelect = function (aBoardsAndCategories)
  964. {
  965. var iIndexPointer = 0;
  966. // Create an option that'll be above and below the category.
  967. var oDashOption = document.createElement('option');
  968. oDashOption.appendChild(document.createTextNode(this.opt.sCatSeparator));
  969. oDashOption.disabled = 'disabled';
  970. oDashOption.value = '';
  971. if ('onbeforeactivate' in document)
  972. this.dropdownList.onbeforeactivate = null;
  973. else
  974. this.dropdownList.onfocus = null;
  975. if (this.opt.bNoRedirect)
  976. this.dropdownList.options[0].disabled = 'disabled';
  977. // Create a document fragment that'll allowing inserting big parts at once.
  978. var oListFragment = document.createDocumentFragment();
  979. // Loop through all items to be added.
  980. for (var i = 0, n = aBoardsAndCategories.length; i < n; i++)
  981. {
  982. var j, sChildLevelPrefix, oOption;
  983. // If we've reached the currently selected board add all items so far.
  984. if (!aBoardsAndCategories[i].isCategory && aBoardsAndCategories[i].id == this.opt.iCurBoardId)
  985. {
  986. this.dropdownList.insertBefore(oListFragment, this.dropdownList.options[0]);
  987. oListFragment = document.createDocumentFragment();
  988. continue;
  989. }
  990. if (aBoardsAndCategories[i].isCategory)
  991. oListFragment.appendChild(oDashOption.cloneNode(true));
  992. else
  993. for (j = aBoardsAndCategories[i].childLevel, sChildLevelPrefix = ''; j > 0; j--)
  994. sChildLevelPrefix += this.opt.sBoardChildLevelIndicator;
  995. oOption = document.createElement('option');
  996. oOption.appendChild(document.createTextNode((aBoardsAndCategories[i].isCategory ? this.opt.sCatPrefix : sChildLevelPrefix + this.opt.sBoardPrefix) + aBoardsAndCategories[i].name));
  997. if (!this.opt.bNoRedirect)
  998. oOption.value = aBoardsAndCategories[i].isCategory ? '#c' + aBoardsAndCategories[i].id : '?board=' + aBoardsAndCategories[i].id + '.0';
  999. else
  1000. {
  1001. if (aBoardsAndCategories[i].isCategory)
  1002. oOption.disabled = 'disabled';
  1003. else
  1004. oOption.value = aBoardsAndCategories[i].id;
  1005. }
  1006. oListFragment.appendChild(oOption);
  1007. if (aBoardsAndCategories[i].isCategory)
  1008. oListFragment.appendChild(oDashOption.cloneNode(true));
  1009. }
  1010. // Add the remaining items after the currently selected item.
  1011. this.dropdownList.appendChild(oListFragment);
  1012. // Add an onchange action
  1013. if (!this.opt.bNoRedirect)
  1014. this.dropdownList.onchange = function() {
  1015. if (this.selectedIndex > 0 && this.options[this.selectedIndex].value)
  1016. window.location.href = smf_scripturl + this.options[this.selectedIndex].value.substr(smf_scripturl.indexOf('?') == -1 || this.options[this.selectedIndex].value.substr(0, 1) != '?' ? 0 : 1);
  1017. }
  1018. }
  1019. // A global array containing all IconList objects.
  1020. var aIconLists = new Array();
  1021. // *** IconList object.
  1022. function IconList(oOptions)
  1023. {
  1024. if (!window.XMLHttpRequest)
  1025. return;
  1026. this.opt = oOptions;
  1027. this.bListLoaded = false;
  1028. this.oContainerDiv = null;
  1029. this.funcMousedownHandler = null;
  1030. this.funcParent = this;
  1031. this.iCurMessageId = 0;
  1032. this.iCurTimeout = 0;
  1033. // Add backwards compatibility with old themes.
  1034. if (!('sSessionVar' in this.opt))
  1035. this.opt.sSessionVar = 'sesc';
  1036. this.initIcons();
  1037. }
  1038. // Replace all message icons by icons with hoverable and clickable div's.
  1039. IconList.prototype.initIcons = function ()
  1040. {
  1041. for (var i = document.images.length - 1, iPrefixLength = this.opt.sIconIdPrefix.length; i >= 0; i--)
  1042. if (document.images[i].id.substr(0, iPrefixLength) == this.opt.sIconIdPrefix)
  1043. setOuterHTML(document.images[i], '<div title="' + this.opt.sLabelIconList + '" onclick="' + this.opt.sBackReference + '.openPopup(this, ' + document.images[i].id.substr(iPrefixLength) + ')" onmouseover="' + this.opt.sBackReference + '.onBoxHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onBoxHover(this, false)" style="background: ' + this.opt.sBoxBackground + '; cursor: pointer; padding: 3px; text-align: center;"><img src="' + document.images[i].src + '" alt="' + document.images[i].alt + '" id="' + document.images[i].id + '" style="margin: 0px; padding: ' + (is_ie ? '3px' : '3px 0px 3px 0px') + ';" /></div>');
  1044. }
  1045. // Event for the mouse hovering over the original icon.
  1046. IconList.prototype.onBoxHover = function (oDiv, bMouseOver)
  1047. {
  1048. oDiv.style.border = bMouseOver ? this.opt.iBoxBorderWidthHover + 'px solid ' + this.opt.sBoxBorderColorHover : '';
  1049. oDiv.style.background = bMouseOver ? this.opt.sBoxBackgroundHover : this.opt.sBoxBackground;
  1050. oDiv.style.padding = bMouseOver ? (3 - this.opt.iBoxBorderWidthHover) + 'px' : '3px'
  1051. }
  1052. // Show the list of icons after the user clicked the original icon.
  1053. IconList.prototype.openPopup = function (oDiv, iMessageId)
  1054. {
  1055. this.iCurMessageId = iMessageId;
  1056. if (!this.bListLoaded && this.oContainerDiv == null)
  1057. {
  1058. // Create a container div.
  1059. this.oContainerDiv = document.createElement('div');
  1060. this.oContainerDiv.id = 'iconList';
  1061. this.oContainerDiv.style.display = 'none';
  1062. this.oContainerDiv.style.cursor = 'pointer';
  1063. this.oContainerDiv.style.position = 'absolute';
  1064. this.oContainerDiv.style.background = this.opt.sContainerBackground;
  1065. this.oContainerDiv.style.border = this.opt.sContainerBorder;
  1066. this.oContainerDiv.style.padding = '6px 0px';
  1067. document.body.appendChild(this.oContainerDiv);
  1068. // Start to fetch its contents.
  1069. ajax_indicator(true);
  1070. sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + 'action=xmlhttp;sa=messageicons;board=' + this.opt.iBoardId + ';xml', '', this.onIconsReceived);
  1071. createEventListener(document.body);
  1072. }
  1073. // Set the position of the container.
  1074. var aPos = smf_itemPos(oDiv);
  1075. this.oContainerDiv.style.top = (aPos[1] + oDiv.offsetHeight) + 'px';
  1076. this.oContainerDiv.style.left = (aPos[0] - 1) + 'px';
  1077. this.oClickedIcon = oDiv;
  1078. if (this.bListLoaded)
  1079. this.oContainerDiv.style.display = 'block';
  1080. document.body.addEventListener('mousedown', this.onWindowMouseDown, false);
  1081. }
  1082. // Setup the list of icons once it is received through xmlHTTP.
  1083. IconList.prototype.onIconsReceived = function (oXMLDoc)
  1084. {
  1085. var icons = oXMLDoc.getElementsByTagName('smf')[0].getElementsByTagName('icon');
  1086. var sItems = '';
  1087. for (var i = 0, n = icons.length; i < n; i++)
  1088. sItems += '<span onmouseover="' + this.opt.sBackReference + '.onItemHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onItemHover(this, false);" onmousedown="' + this.opt.sBackReference + '.onItemMouseDown(this, \'' + icons[i].getAttribute('value') + '\');" style="padding: 2px 3px; line-height: 20px; border: ' + this.opt.sItemBorder + '; background: ' + this.opt.sItemBackground + '"><img src="' + icons[i].getAttribute('url') + '" alt="' + icons[i].getAttribute('name') + '" title="' + icons[i].firstChild.nodeValue + '" style="vertical-align: middle" /></span>';
  1089. setInnerHTML(this.oContainerDiv, sItems);
  1090. this.oContainerDiv.style.display = 'block';
  1091. this.bListLoaded = true;
  1092. if (is_ie)
  1093. this.oContainerDiv.style.width = this.oContainerDiv.clientWidth + 'px';
  1094. ajax_indicator(false);
  1095. }
  1096. // Event handler for hovering over the icons.
  1097. IconList.prototype.onItemHover = function (oDiv, bMouseOver)
  1098. {
  1099. oDiv.style.background = bMouseOver ? this.opt.sItemBackgroundHover : this.opt.sItemBackground;
  1100. oDiv.style.border = bMouseOver ? this.opt.sItemBorderHover : this.opt.sItemBorder;
  1101. if (this.iCurTimeout != 0)
  1102. window.clearTimeout(this.iCurTimeout);
  1103. if (bMouseOver)
  1104. this.onBoxHover(this.oClickedIcon, true);
  1105. else
  1106. this.iCurTimeout = window.setTimeout(this.opt.sBackReference + '.collapseList();', 500);
  1107. }
  1108. // Event handler for clicking on one of the icons.
  1109. IconList.prototype.onItemMouseDown = function (oDiv, sNewIcon)
  1110. {
  1111. if (this.iCurMessageId != 0)
  1112. {
  1113. ajax_indicator(true);
  1114. this.tmpMethod = getXMLDocument;
  1115. var oXMLDoc = this.tmpMethod(smf_prepareScriptUrl(smf_scripturl) + 'action=jsmodify;topic=' + this.opt.iTopicId + ';msg=' + this.iCurMessageId + ';' + smf_session_var + '=' + smf_session_id + ';icon=' + sNewIcon + ';xml');
  1116. delete this.tmpMethod;
  1117. ajax_indicator(false);
  1118. var oMessage = oXMLDoc.responseXML.getElementsByTagName('smf')[0].getElementsByTagName('message')[0];
  1119. if (oMessage.getElementsByTagName('error').length == 0)
  1120. {
  1121. if (this.opt.bShowModify && oMessage.getElementsByTagName('modified').length != 0)
  1122. setInnerHTML(document.getElementById('modified_' + this.iCurMessageId), oMessage.getElementsByTagName('modified')[0].childNodes[0].nodeValue);
  1123. this.oClickedIcon.getElementsByTagName('img')[0].src = oDiv.getElementsByTagName('img')[0].src;
  1124. }
  1125. }
  1126. }
  1127. // Event handler for clicking outside the list (will make the list disappear).
  1128. IconList.prototype.onWindowMouseDown = function ()
  1129. {
  1130. for (var i = aIconLists.length - 1; i >= 0; i--)
  1131. {
  1132. aIconLists[i].funcParent.tmpMethod = aIconLists[i].collapseList;
  1133. aIconLists[i].funcParent.tmpMethod();
  1134. delete aIconLists[i].funcParent.tmpMethod;
  1135. }
  1136. }
  1137. // Collapse the list of icons.
  1138. IconList.prototype.collapseList = function()
  1139. {
  1140. this.onBoxHover(this.oClickedIcon, false);
  1141. this.oContainerDiv.style.display = 'none';
  1142. this.iCurMessageId = 0;
  1143. document.body.removeEventListener('mousedown', this.onWindowMouseDown, false);
  1144. }
  1145. // Handy shortcuts for getting the mouse position on the screen - only used for IE at the moment.
  1146. function smf_mousePose(oEvent)
  1147. {
  1148. var x = 0;
  1149. var y = 0;
  1150. if (oEvent.pageX)
  1151. {
  1152. y = oEvent.pageY;
  1153. x = oEvent.pageX;
  1154. }
  1155. else if (oEvent.clientX)
  1156. {
  1157. x = oEvent.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  1158. y = oEvent.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  1159. }
  1160. return [x, y];
  1161. }
  1162. // Short function for finding the actual position of an item.
  1163. function smf_itemPos(itemHandle)
  1164. {
  1165. var itemX = 0;
  1166. var itemY = 0;
  1167. if ('offsetParent' in itemHandle)
  1168. {
  1169. itemX = itemHandle.offsetLeft;
  1170. itemY = itemHandle.offsetTop;
  1171. while (itemHandle.offsetParent && typeof(itemHandle.offsetParent) == 'object')
  1172. {
  1173. itemHandle = itemHandle.offsetParent;
  1174. itemX += itemHandle.offsetLeft;
  1175. itemY += itemHandle.offsetTop;
  1176. }
  1177. }
  1178. else if ('x' in itemHandle)
  1179. {
  1180. itemX = itemHandle.x;
  1181. itemY = itemHandle.y;
  1182. }
  1183. return [itemX, itemY];
  1184. }
  1185. // This function takes the script URL and prepares it to allow the query string to be appended to it.
  1186. function smf_prepareScriptUrl(sUrl)
  1187. {
  1188. return sUrl.indexOf('?') == -1 ? sUrl + '?' : sUrl + (sUrl.charAt(sUrl.length - 1) == '?' || sUrl.charAt(sUrl.length - 1) == '&' || sUrl.charAt(sUrl.length - 1) == ';' ? '' : ';');
  1189. }
  1190. var aOnloadEvents = new Array();
  1191. function addLoadEvent(fNewOnload)
  1192. {
  1193. // If there's no event set, just set this one
  1194. if (typeof(fNewOnload) == 'function' && (!('onload' in window) || typeof(window.onload) != 'function'))
  1195. window.onload = fNewOnload;
  1196. // If there's just one event, setup the array.
  1197. else if (aOnloadEvents.length == 0)
  1198. {
  1199. aOnloadEvents[0] = window.onload;
  1200. aOnloadEvents[1] = fNewOnload;
  1201. window.onload = function() {
  1202. for (var i = 0, n = aOnloadEvents.length; i < n; i++)
  1203. {
  1204. if (typeof(aOnloadEvents[i]) == 'function')
  1205. aOnloadEvents[i]();
  1206. else if (typeof(aOnloadEvents[i]) == 'string')
  1207. eval(aOnloadEvents[i]);
  1208. }
  1209. }
  1210. }
  1211. // This isn't the first event function, add it to the list.
  1212. else
  1213. aOnloadEvents[aOnloadEvents.length] = fNewOnload;
  1214. }
  1215. function smfFooterHighlight(element, value)
  1216. {
  1217. element.src = smf_images_url + '/' + (value ? 'h_' : '') + element.id + '.png';
  1218. }
  1219. // Get the text in a code tag.
  1220. function smfSelectText(oCurElement, bActOnElement)
  1221. {
  1222. // The place we're looking for is one div up, and next door - if it's auto detect.
  1223. if (typeof(bActOnElement) == 'boolean' && bActOnElement)
  1224. var oCodeArea = document.getElementById(oCurElement);
  1225. else
  1226. var oCodeArea = oCurElement.parentNode.nextSibling;
  1227. if (typeof(oCodeArea) != 'object' || oCodeArea == null)
  1228. return false;
  1229. // Start off with my favourite, internet explorer.
  1230. if ('createTextRange' in document.body)
  1231. {
  1232. var oCurRange = document.body.createTextRange();
  1233. oCurRange.moveToElementText(oCodeArea);
  1234. oCurRange.select();
  1235. }
  1236. // Firefox at el.
  1237. else if (window.getSelection)
  1238. {
  1239. var oCurSelection = window.getSelection();
  1240. // Safari is special!
  1241. if (oCurSelection.setBaseAndExtent)
  1242. {
  1243. var oLastChild = oCodeArea.lastChild;
  1244. oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
  1245. }
  1246. else
  1247. {
  1248. var curRange = document.createRange();
  1249. curRange.selectNodeContents(oCodeArea);
  1250. oCurSelection.removeAllRanges();
  1251. oCurSelection.addRange(curRange);
  1252. }
  1253. }
  1254. return false;
  1255. }
  1256. // A function needed to discern HTML entities from non-western characters.
  1257. function smc_saveEntities(sFormName, aElementNames, sMask)
  1258. {
  1259. if (typeof(sMask) == 'string')
  1260. {
  1261. for (var i = 0, n = document.forms[sFormName].elements.length; i < n; i++)
  1262. if (document.forms[sFormName].elements[i].id.substr(0, sMask.length) == sMask)
  1263. aElementNames[aElementNames.length] = document.forms[sFormName].elements[i].name;
  1264. }
  1265. for (var i = 0, n = aElementNames.length; i < n; i++)
  1266. {
  1267. if (aElementNames[i] in document.forms[sFormName])
  1268. document.forms[sFormName][aElementNames[i]].value = document.forms[sFormName][aElementNames[i]].value.replace(/&#/g, '&#38;#');
  1269. }
  1270. }
  1271. // A function used to clean the attachments on post page
  1272. function cleanFileInput(idElement)
  1273. {
  1274. // Simpler solutions work in Opera, IE, Safari and Chrome.
  1275. if (is_opera || is_ie || is_safari || is_chrome)
  1276. {
  1277. document.getElementById(idElement).outerHTML = document.getElementById(idElement).outerHTML;
  1278. }
  1279. // What else can we do? By the way, this doesn't work in Chrome and Mac's Safari.
  1280. else
  1281. {
  1282. document.getElementById(idElement).type = 'input';
  1283. document.getElementById(idElement).type = 'file';
  1284. }
  1285. }
  1286. function applyWindowClasses(oList)
  1287. {
  1288. var bAlternate = false;
  1289. oListItems = oList.getElementsByTagName("LI");
  1290. for (i = 0; i < oListItems.length; i++)
  1291. {
  1292. // Skip dummies.
  1293. if (oListItems[i].id == "")
  1294. continue;
  1295. oListItems[i].className = "windowbg" + (bAlternate ? "2" : "");
  1296. bAlternate = !bAlternate;
  1297. }
  1298. }
  1299. function reActivate()
  1300. {
  1301. document.forms.postmodify.message.readOnly = false;
  1302. }
  1303. // The actual message icon selector.
  1304. function showimage()
  1305. {
  1306. document.images.icons.src = icon_urls[document.forms.postmodify.icon.options[document.forms.postmodify.icon.selectedIndex].value];
  1307. }
  1308. function pollOptions()
  1309. {
  1310. var expire_time = document.getElementById('poll_expire');
  1311. if (isEmptyText(expire_time) || expire_time.value == 0)
  1312. {
  1313. document.forms.postmodify.poll_hide[2].disabled = true;
  1314. if (document.forms.postmodify.poll_hide[2].checked)
  1315. document.forms.postmodify.poll_hide[1].checked = true;
  1316. }
  1317. else
  1318. document.forms.postmodify.poll_hide[2].disabled = false;
  1319. }
  1320. function generateDays(offset)
  1321. {
  1322. // Work around JavaScript's lack of support for default values...
  1323. offset = typeof(offset) != 'undefined' ? offset : 0;
  1324. var days = 0, selected = 0;
  1325. var dayElement = document.getElementById("day" + offset), yearElement = document.getElementById("year" + offset), monthElement = document.getElementById("month" + offset);
  1326. monthLength[1] = 28;
  1327. if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
  1328. monthLength[1] = 29;
  1329. selected = dayElement.selectedIndex;
  1330. while (dayElement.options.length)
  1331. dayElement.options[0] = null;
  1332. days = monthLength[monthElement.value - 1];
  1333. for (i = 1; i <= days; i++)
  1334. dayElement.options[dayElement.length] = new Option(i, i);
  1335. if (selected < days)
  1336. dayElement.selectedIndex = selected;
  1337. }
  1338. function toggleLinked(form)
  1339. {
  1340. form.board.disabled = !form.link_to_board.checked;
  1341. }
  1342. function initSearch()
  1343. {
  1344. if (document.forms.searchform.search.value.indexOf("%u") != -1)
  1345. document.forms.searchform.search.value = unescape(document.forms.searchform.search.value);
  1346. }
  1347. function selectBoards(ids, aFormID)
  1348. {
  1349. var toggle = true;
  1350. var aForm = document.getElementById(aFormID);
  1351. for (i = 0; i < ids.length; i++)
  1352. toggle = toggle & aForm["brd" + ids[i]].checked;
  1353. for (i = 0; i < ids.length; i++)
  1354. aForm["brd" + ids[i]].checked = !toggle;
  1355. }
  1356. function expandCollapseBoards()
  1357. {
  1358. var current = document.getElementById("searchBoardsExpand").style.display != "none";
  1359. $("#searchBoardsExpand").slideToggle(300);
  1360. document.getElementById("expandBoardsIcon").src = smf_images_url + (current ? "/expand.png" : "/collapse.png");
  1361. }
  1362. function expandCollapseLabels()
  1363. {
  1364. var current = document.getElementById("searchLabelsExpand").style.display != "none";
  1365. $("#searchLabelsExpand").slideToggle();
  1366. document.getElementById("expandLabelsIcon").src = smf_images_url + (current ? "/expand.png" : "/collapse.png");
  1367. }
  1368. function updateRuleDef(optNum)
  1369. {
  1370. if (document.getElementById("ruletype" + optNum).value == "gid")
  1371. {
  1372. document.getElementById("defdiv" + optNum).style.display = "none";
  1373. document.getElementById("defseldiv" + optNum).style.display = "";
  1374. }
  1375. else if (document.getElementById("ruletype" + optNum).value == "bud" || document.getElementById("ruletype" + optNum).value == "")
  1376. {
  1377. document.getElementById("defdiv" + optNum).style.display = "none";
  1378. document.getElementById("defseldiv" + optNum).style.display = "none";
  1379. }
  1380. else
  1381. {
  1382. document.getElementById("defdiv" + optNum).style.display = "";
  1383. document.getElementById("defseldiv" + optNum).style.display = "none";
  1384. }
  1385. }
  1386. function updateActionDef(optNum)
  1387. {
  1388. if (document.getElementById("acttype" + optNum).value == "lab")
  1389. {
  1390. document.getElementById("labdiv" + optNum).style.display = "";
  1391. }
  1392. else
  1393. {
  1394. document.getElementById("labdiv" + optNum).style.display = "none";
  1395. }
  1396. }
  1397. function updateAuthMethod()
  1398. {
  1399. // What authentication method is being used?
  1400. if (!document.getElementById("auth_openid") || !document.getElementById("auth_openid").checked)
  1401. currentAuthMethod = "passwd";
  1402. else
  1403. currentAuthMethod = "openid";
  1404. // No openID?
  1405. if (!document.getElementById("auth_openid"))
  1406. return true;
  1407. document.forms.creator.openid_url.disabled = currentAuthMethod == "openid" ? false : true;
  1408. document.forms.creator.smf_autov_pwmain.disabled = currentAuthMethod == "passwd" ? false : true;
  1409. document.forms.creator.smf_autov_pwverify.disabled = currentAuthMethod == "passwd" ? false : true;
  1410. document.getElementById("smf_autov_pwmain_div").style.display = currentAuthMethod == "passwd" ? "" : "none";
  1411. document.getElementById("smf_autov_pwverify_div").style.display = currentAuthMethod == "passwd" ? "" : "none";
  1412. if (currentAuthMethod == "passwd")
  1413. {
  1414. verificationHandle.refreshMainPassword();
  1415. verificationHandle.refreshVerifyPassword();
  1416. document.forms.creator.openid_url.style.backgroundColor = "";
  1417. document.getElementById("auth_openid_div").style.display = "none";
  1418. document.getElementById("auth_pass_div").style.display = "";
  1419. }
  1420. else
  1421. {
  1422. document.forms.creator.smf_autov_pwmain.style.backgroundColor ="";
  1423. document.forms.creator.smf_autov_pwverify.style.backgroundColor = "";
  1424. document.forms.creator.openid_url.style.backgroundColor = "#FCE184";
  1425. document.getElementById("auth_openid_div").style.display = "";
  1426. document.getElementById("auth_pass_div").style.display = "none";
  1427. }
  1428. }