PageSourceSearch

https://academie-saintonge.org/wp-content/themes/classter/js/_utils.js

js academie-saintonge.org collected 2026-10-02 11:18:36 UTC 36,224 bytes, 1,103 lines download raw bytes

1//=============================================================
2//==  Stylesheets manipulations
3//=============================================================
4function setStateStyleSheet(title, state) {
5	"use strict";
6	var i, a;
7	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
8		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
9			if (a.getAttribute("title") == title) a.disabled = !state;
10    	}
11  	}
12}
13
14function getStateStyleSheet(title, state) {
15	"use strict";
16	var i, a, rez=-1;
17	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
18		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
19			if (a.getAttribute("title") == title) {
20				rez = a.disabled ? 0 : 1;
21				break;
22			}
23    	}
24  	}
25	return rez;
26}
27
28function setActiveStyleSheet(title, disableOther) {
29	"use strict";
30	var i, a, main;
31	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
32		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
33			if (disableOther) a.disabled = true;
34			if (a.getAttribute("title") == title) a.disabled = false;
35    	}
36  	}
37}
38
39function getActiveStyleSheet() {
40	"use strict";
41	var i, a;
42	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
43		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
44	}
45	return null;
46}
47
48function getPreferredStyleSheet() {
49	"use strict";
50	var i, a;
51	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
52		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") )
53			return a.getAttribute("title");
54	}
55	return null;
56}
57
58
59//=============================================================
60//==  ListBox & ComboBox manipulations
61//=============================================================
62function addListBoxItem(box, val, text) {
63	"use strict";
64	var item = new Option();
65	item.value = val;
66	item.text = text;
67    box.options.add(item);
68}
69
70function clearListBox(box) {
71	"use strict";
72	for (var i=box.options.length-1; i>=0; i--)
73		box.options[i] = null;
74}
75
76function delListBoxItemByValue(box, val) {
77	"use strict";
78	for (var i=0; i<box.options.length; i++) {
79		if (box.options[i].value == val) {
80			box.options[i] = null;
81			break;
82		}
83	}
84}
85
86function delListBoxItemByText(box, txt) {
87	"use strict";
88	for (var i=0; i<box.options.length; i++) {
89		if (box.options[i].text == txt) {
90			box.options[i] = null;
91			break;
92		}
93	}
94}
95
96function findListBoxItemByValue(box, val) {
97	"use strict";
98	var idx = -1;
99	for (var i=0; i<box.options.length; i++) {
100		if (box.options[i].value == val) {
101			idx = i;
102			break;
103		}
104	}
105	return idx;
106}
107
108function findListBoxItemByText(box, txt) {
109	"use strict";
110	var idx = -1;
111	for (var i=0; i<box.options.length; i++) {
112		if (box.options[i].text == txt) {
113			idx = i;
114			break;
115		}
116	}
117	return idx;
118}
119
120function selectListBoxItemByValue(box, val) {
121	"use strict";
122	for (var i = 0; i < box.options.length; i++) {
123		box.options[i].selected = (val == box.options[i].value);
124	}
125}
126
127function selectListBoxItemByText(box, txt) {
128	"use strict";
129	for (var i = 0; i < box.options.length; i++) {
130		box.options[i].selected = (txt == box.options[i].text);
131	}
132}
133
134function getListBoxValues(box) {
135	"use strict";
136	var delim = arguments[1] ? arguments[1] : ',';
137	var str = '';
138	for (var i=0; i<box.options.length; i++) {
139		str += (str ? delim : '') + box.options[i].value;
140	}
141	return str;
142}
143
144function getListBoxTexts(box) {
145	"use strict";
146	var delim = arguments[1] ? arguments[1] : ',';
147	var str = '';
148	for (var i=0; i<box.options.length; i++) {
149		str += (str ? delim : '') + box.options[i].text;
150	}
151	return str;
152}
153
154function sortListBox(box)  {
155	"use strict";
156	var temp_opts = new Array();
157	var temp = new Option();
158	for(var i=0; i<box.options.length; i++)  {
159		temp_opts[i] = box.options[i].clone();
160	}
161	for(var x=0; x<temp_opts.length-1; x++)  {
162		for(var y=(x+1); y<temp_opts.length; y++)  {
163			if(temp_opts[x].text > temp_opts[y].text)  {
164				temp = temp_opts[x];
165				temp_opts[x] = temp_opts[y];
166				temp_opts[y] = temp;
167			}
168		}
169	}
170	for(var i=0; i<box.options.length; i++)  {
171		box.options[i] = temp_opts[i].clone();
172	}
173}
174
175function getListBoxSelectedIndex(box) {
176	"use strict";
177	for (var i = 0; i < box.options.length; i++) {
178		if (box.options[i].selected)
179			return i;
180	}
181	return -1;
182}
183
184function getListBoxSelectedValue(box) {
185	"use strict";
186	for (var i = 0; i < box.options.length; i++) {
187		if (box.options[i].selected) {
188			return box.options[i].value;
189		}
190	}
191	return null;
192}
193
194function getListBoxSelectedText(box) {
195	"use strict";
196	for (var i = 0; i < box.options.length; i++) {
197		if (box.options[i].selected) {
198			return box.options[i].text;
199		}
200	}
201	return null;
202}
203
204function getListBoxSelectedOption(box) {
205	"use strict";
206	for (var i = 0; i < box.options.length; i++) {
207		if (box.options[i].selected) {
208			return box.options[i];
209		}
210	}
211	return null;
212}
213
214
215//=============================================================
216//==  Radiobuttons manipulations
217//=============================================================
218function getRadioGroupValue(radioGroupObj) {
219	"use strict";
220	for (var i=0; i < radioGroupObj.length; i++)
221		if (radioGroupObj[i].checked) return radioGroupObj[i].value;
222	return null;
223}
224
225function setRadioGroupCheckedByNum(radioGroupObj, num) {
226	"use strict";
227	for (var i=0; i < radioGroupObj.length; i++)
228		if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false;
229		else if (i==num) radioGroupObj[i].checked=true;
230}
231
232function setRadioGroupCheckedByValue(radioGroupObj, val) {
233	"use strict";
234	for (var i=0; i < radioGroupObj.length; i++)
235		if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false;
236		else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true;
237}
238
239
240//=============================================================
241//==  Array manipulations
242//=============================================================
243function sortArray(thearray)  {
244	"use strict";
245	var caseSensitive = arguments[1] ? arguments[1] : false;
246	for (var x=0; x<thearray.length-1; x++)  {
247		for (var y=(x+1); y<thearray.length; y++)  {
248			if (caseSensitive) {
249				if (thearray[x] > thearray[y])  {
250					tmp = thearray[x];
251					thearray[x] = thearray[y];
252					thearray[y] = tmp;
253				}
254			} else {
255				if (thearray[x].toLowerCase() > thearray[y].toLowerCase())  {
256					tmp = thearray[x];
257					thearray[x] = thearray[y];
258					thearray[y] = tmp;
259				}
260			}
261		}
262	}
263}
264
265
266//=============================================================
267//==  String functions
268//=============================================================
269function inList(list, str) {
270	"use strict";
271	var delim = arguments[2] ? arguments[2] : '|';
272	var icase = arguments[3] ? arguments[3] : true;
273	var retval = false;
274	if (icase) {
275		str = str.toLowerCase();
276		list = list.toLowerCase();
277	}
278	var parts = list.split(delim);
279	for (var i=0; i<parts.length; i++) {
280		if (parts[i]==str) {
281			retval=true;
282			break;
283		}
284	}
285	return retval;
286}
287
288function alltrim(str) {
289	"use strict";
290	var dir = arguments[1] ? arguments[1] : 'a';
291	var rez = '';
292	var i, start = 0, end = str.length-1;
293	if (dir=='a' || dir=='l') {
294		for (i=0; i<str.length; i++) {
295			if (str.substr(i,1)!=' ') {
296				start = i;
297				break;
298			}
299		}
300	}
301	if (dir=='a' || dir=='r') {
302		for (i=str.length-1; i>=0; i--) {
303			if (str.substr(i,1)!=' ') {
304				end = i;
305				break;
306			}
307		}
308	}
309	return str.substring(start, end+1);
310}
311
312function ltrim(str) {
313	"use strict";
314	return alltrim(str, 'l');
315}
316
317function rtrim(str) {
318	"use strict";
319	return alltrim(str, 'r');
320}
321
322function padl(str, len) {
323	"use strict";
324	var ch = arguments[2] ? arguments[2] : ' ';
325	var rez = str.substr(0,len);
326	if (rez.length < len) {
327		for (var i=0; i<len-str.length; i++)
328			rez += ch;
329	}
330	return rez;
331}
332
333function padr(str, len) {
334	"use strict";
335	var ch = arguments[2] ? arguments[2] : ' ';
336	var rez = str.substr(0,len);
337	if (rez.length < len) {
338		for (var i=0; i<len-str.length; i++)
339			rez = ch + rez;
340	}
341	return rez;
342}
343
344function padc(str, len) {
345	"use strict";
346	var ch = arguments[2] ? arguments[2] : ' ';
347	var rez = str.substr(0,len);
348	if (rez.length < len) {
349		for (var i=0; i<Math.floor((len-str.length)/2); i++)
350			rez = ch + rez + ch;
351	}
352	return rez+(rez.length<len ? ch : '');
353}
354
355function replicate(str, num) {
356	"use strict";
357	var rez = '';
358	for (var i=0; i<num; i++) {
359		rez += str;
360	}
361	return rez;
362}
363
364
365//=============================================================
366//==  Numbers functions
367//=============================================================
368
369// Clear number from any characters and append it with 0 to desired precision
370function clearNumber(num) {
371	"use strict";
372	var precision = arguments[1] ? arguments[1] : 0;
373	var defa = arguments[2] ? arguments[2] : 0;
374	var res = '';
375	var decimals = -1;
376	num = ""+num;
377	if (num=="") num=""+defa;
378	for (var i=0; i<num.length; i++) {
379		if (decimals==0) break;
380		else if (decimals>0) decimals--;
381		var ch = num.substr(i,1);
382		if (ch=='.') {
383			if (precision>0) {
384				res += ch;
385			}
386			decimals = precision;
387		} else if ((ch>=0 && ch<=9) || (ch=='-' && i==0))
388			res+=ch;
389	}
390	if (precision>0 && decimals!=0) {
391		if (decimals==-1) {
392			res += '.';
393			decimals = precision;
394		}
395		for (i=decimals; i>0; i--)
396			res +='0';
397	}
398	//if (isNaN(res)) res = clearNumber(defa, precision, defa);
399	return res;
400}
401
402function dec2hex(n) {
403	"use strict";
404	return Number(n).toString(16);
405}
406
407function hex2dec(hex) {
408	"use strict";
409	return parseInt(hex,16);
410}
411
412function roundNumber(num) {
413	"use strict";
414	var precision = arguments[1] ? arguments[1] : 0;
415	var p = Math.pow(10,precision);
416	return Math.round(num*p)/p;
417}
418
419//=============================================================
420//==  Color manipulations
421//=============================================================
422function hex2rgb(hex) {
423	hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
424	return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
425}
426
427function rgb2hex(color) {
428	"use strict";
429	var aRGB;
430	color = color.replace(/\s/g,"").toLowerCase();
431	if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)')
432		color = 'transparent';
433	if (color.indexOf('rgba(')==0)
434		aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
435	else
436		aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
437
438	if(aRGB) {
439		color = '';
440		for (var i=1; i<=3; i++)
441			color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
442	} else
443		color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
444	return (color.substr(0,1)!='#' ? '#' : '') + color;
445}
446
447function _rgb2hex(r,g,b) {
448	"use strict";
449	return '#'+
450		Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
451		Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
452		Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
453}
454
455function hex2hsb(hex) {
456	"use strict";
457	return rgb2hsb(hex2rgb(hex));
458}
459
460function hsb2hex(hsb) {
461	var rgb = hsb2rgb(hsb);
462	return _rgb2hex(rgb.r, rgb.g, rgb.b);
463}
464
465function rgb2hsb(rgb) {
466	"use strict";
467	var hsb = {};
468	hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
469	hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
470	hsb.b = Math.round((hsb.b /255)*100);
471	if ((rgb.r==rgb.g) && (rgb.g==rgb.b))  hsb.h = 0;
472	else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
473	else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60  + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
474	else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
475	else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
476	else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
477	else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
478	else 								   hsb.h = 0;
479	hsb.h = Math.round(hsb.h);
480	return hsb;
481}
482
483function hsb2rgb(hsb) {
484	var rgb = {};
485	var h = Math.round(hsb.h);
486	var s = Math.round(hsb.s*255/100);
487	var v = Math.round(hsb.b*255/100);
488	if (s == 0) {
489		rgb.r = rgb.g = rgb.b = v;
490	} else {
491		var t1 = v;
492		var t2 = (255-s)*v/255;
493		var t3 = (t1-t2)*(h%60)/60;
494		if (h==360) h = 0;
495		if (h<60) 		{ rgb.r=t1;	rgb.b=t2;   rgb.g=t2+t3; }
496		else if (h<120) { rgb.g=t1; rgb.b=t2;	rgb.r=t1-t3; }
497		else if (h<180) { rgb.g=t1; rgb.r=t2;	rgb.b=t2+t3; }
498		else if (h<240) { rgb.b=t1; rgb.r=t2;	rgb.g=t1-t3; }
499		else if (h<300) { rgb.b=t1; rgb.g=t2;	rgb.r=t2+t3; }
500		else if (h<360) { rgb.r=t1; rgb.g=t2;	rgb.b=t1-t3; }
501		else 			{ rgb.r=0;  rgb.g=0;	rgb.b=0;	 }
502	}
503	return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) };
504}
505
506function split_rgb(color) {
507	"use strict";
508	color = rgb2hex(color);
509	var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
510	if (!matches) return false;
511	for (var i=1, rgb = new Array(3); i<=3; i++)
512		rgb[i-1] = parseInt(matches[i],16);
513	return rgb;
514}
515
516function iColorPicker(){
517	"use strict";
518	var id = arguments[0] ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000);
519	var colors = arguments[1] ? arguments[1] :
520	'#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
521	+'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
522	+'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
523	+'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
524	+'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
525	+'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
526	+'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
527	var colorsList = colors.split(',');
528	var tbl = '<table class="colorPickerTable"><thead>';
529	for (var i=0; i<colorsList.length; i++) {
530		if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>';
531		tbl += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
532	}
533	tbl += '</tr></thead><tbody>'
534		+ '<tr style="height:60px;">'
535		+ '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
536		+ '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />'
537		+ '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>'
538		+ '</td>'
539		+ '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
540		+ '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />'
541		+ '</td>'
542		+ '</tr></tbody></table>';
543	//tbl += '<style>#iColorPicker input{margin:2px}</style>';
544
545	jQuery(document.createElement("div"))
546		.attr("id", id)
547		.css('display','none')
548		.html(tbl)
549		.appendTo("body")
550		.addClass("iColorPickerTable")
551		.on('mouseover', 'thead td', function(){
552			"use strict";
553			var aaa=rgb2hex(jQuery(this).css('background-color'));
554			jQuery('#'+id+'_colorPreview').css('background',aaa);
555			jQuery('#'+id+'_colorPreview input').val(aaa);
556		})
557		.on('keypress', '#'+id+'_colorPreview input', function(key){
558			"use strict";
559			var aaa=jQuery(this).val()
560			if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) {
561				aaa += String.fromCharCode(key.which);
562			} else if (key.which == 8 && aaa.length>0) {
563				aaa = aaa.substring(0, aaa.length-1);
564			} else if (key.which===13 && (aaa.length===4 || aaa.length===7)) {
565				var fld  = jQuery('#'+id).data('field');
566				var func = jQuery('#'+id).data('func');
567				if (func!=null && func!='undefined') {
568					func(fld, aaa);
569				} else {
570					fld.val(aaa).css('backgroundColor', aaa).trigger('change');
571				}
572				jQuery('#'+id+'_Bg').fadeOut(500);
573				jQuery('#'+id).fadeOut(500);
574
575			} else {
576				key.preventDefault();
577				return false;
578			}
579			if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) {
580				jQuery('#'+id+'_colorPreview').css('background',aaa);
581			}
582		})
583		.on('click', 'thead td', function(e){
584			"use strict";
585			var fld  = jQuery('#'+id).data('field');
586			var func = jQuery('#'+id).data('func');
587			var aaa  = rgb2hex(jQuery(this).css('background-color'));
588			if (func!=null && func!='undefined') {
589				func(fld, aaa);
590			} else {
591				fld.val(aaa).css('backgroundColor', aaa).trigger('change');
592			}
593			jQuery('#'+id+'_Bg').fadeOut(500);
594			jQuery('#'+id).fadeOut(500);
595			e.preventDefault();
596			return false;
597		})
598		.on('click', 'tbody .iColorPicker_moreColors', function(e){
599			"use strict";
600			var thead  = jQuery(this).parents('table').find('thead');
601			var out = '';
602			if (thead.hasClass('more_colors')) {
603				for (var i=0; i<colorsList.length; i++) {
604					if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>';
605					out += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
606				}
607				thead.removeClass('more_colors').empty().html(out+'</tr>');
608				jQuery('#'+id+'_colorPreview').attr('colspan', 8);
609				jQuery('#'+id+'_colorOriginal').attr('colspan', 8);
610			} else {
611				var rgb=[0,0,0], i=0, j=-1;	// Set j=-1 or j=0 - show 2 different colors layouts
612				while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) {
613					if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>';
614					i++;
615					out += '<td style="background-color:'+_rgb2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'">&nbsp;</td>';
616					rgb[2]+=3;
617					if (rgb[2]>0xF) {
618						rgb[1]+=3;
619						if (rgb[1]>(j===0 ? 6 : 0xF)) {
620							rgb[0]+=3;
621							if (rgb[0]>0xF) {
622								if (j===0) {
623									j=1;
624									rgb[0]=0;
625									rgb[1]=9;
626									rgb[2]=0;
627								} else {
628									break;
629								}
630							} else {
631								rgb[1]=(j < 1 ? 0 : 9);
632								rgb[2]=0;
633							}
634						} else {
635							rgb[2]=0;
636						}
637					}
638				}
639				thead.addClass('more_colors').empty().html(out+'<td  style="background-color:#ffffff" colspan="8">&nbsp;</td></tr>');
640				jQuery('#'+id+'_colorPreview').attr('colspan', 9);
641				jQuery('#'+id+'_colorOriginal').attr('colspan', 9);
642			}
643			jQuery('#'+id+' table.colorPickerTable thead td')
644				.css({
645					'width':'12px',
646					'height':'14px',
647					'border':'1px solid #000',
648					'cursor':'pointer'
649				});
650			e.preventDefault();
651			return false;
652		});
653	jQuery(document.createElement("div"))
654		.attr("id", id+"_Bg")
655		.click(function(e) {
656			"use strict";
657			jQuery("#"+id+"_Bg").fadeOut(500);
658			jQuery("#"+id).fadeOut(500);
659			e.preventDefault();
660			return false;
661		})
662		.appendTo("body");
663	jQuery('#'+id+' table.colorPickerTable thead td')
664		.css({
665			'width':'12px',
666			'height':'14px',
667			'border':'1px solid #000',
668			'cursor':'pointer'
669		});
670	jQuery('#'+id+' table.colorPickerTable')
671		.css({'border-collapse':'collapse'});
672	jQuery('#'+id)
673		.css({
674			'border':'1px solid #ccc',
675			'background':'#333',
676			'padding':'5px',
677			'color':'#fff',
678			'z-index':999999
679		});
680	jQuery('#'+id+'_colorPreview')
681		.css({'height':'50px'});
682	return id;
683}
684
685function iColorShow(id, fld, func) {
686	"use strict";
687	if (id===null || id==='') {
688		id = jQuery('.iColorPickerTable').attr('id');
689	}
690	var eICP = fld.offset();
691	var w = jQuery('#'+id).width();
692	var h = jQuery('#'+id).height();
693	var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w;
694	var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13;
695	jQuery("#"+id)
696		.data({field: fld, func: func})
697		.css({
698			'top':t+"px",
699			'left':l+"px",
700			'position':'absolute',
701			'z-index':100001
702		})
703		.fadeIn(500);
704	jQuery("#"+id+"_Bg")
705		.css({
706			'position':'fixed',
707			'z-index':100000,
708			'top':0,
709			'left':0,
710			'width':'100%',
711			'height':'100%'
712		})
713		.fadeIn(500);
714	var def = fld.val().substr(0, 1)=='#' ? fld.val() : rgb2hex(fld.css('backgroundColor'));
715	jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def);
716	jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def);
717}
718
719
720//=============================================================
721//==  Cookies manipulations
722//=============================================================
723function getCookie(name) {
724	"use strict";
725	var defa = arguments[1]!='undefined' ? arguments[1] : null;
726	var start = document.cookie.indexOf(name + '=');
727	var len = start + name.length + 1;
728	if ((!start) && (name != document.cookie.substring(0, name.length))) {
729		return defa;
730	}
731	if (start == -1)
732		return defa;
733	var end = document.cookie.indexOf(';', len);
734	if (end == -1)
735		end = document.cookie.length;
736	return unescape(document.cookie.substring(len, end));
737}
738
739
740function setCookie(name, value, expires, path, domain, secure) {
741	"use strict";
742	var today = new Date();
743	today.setTime(today.getTime());
744	if (expires) {
745		expires = expires * 1000;		// * 60 * 60 * 24;
746	}
747	var expires_date = new Date(today.getTime() + (expires));
748	document.cookie = name + '='
749			+ escape(value)
750			+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
751			+ ((path)    ? ';path=' + path : '')
752			+ ((domain)  ? ';domain=' + domain : '')
753			+ ((secure)  ? ';secure' : '');
754}
755
756
757function deleteCookie(name, path, domain) {
758	"use strict";
759	if (getCookie(name))
760		document.cookie = name + '=' + ((path) ? ';path=' + path : '')
761				+ ((domain) ? ';domain=' + domain : '')
762				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
763}
764
765
766//=============================================================
767//==  Date manipulations
768//=============================================================
769
770// Return array[Year, Month, Day, Hours, Minutes, Seconds]
771// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
772function dateParse(dt) {
773	"use strict";
774	dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0];
775	var dt2 = dt.split(' ');
776	var d = dt2[0].split('-');
777	var t = dt2[1].split(':');
778	d.push(t[0], t[1], t[2]);
779	return d;
780}
781
782function dateDifference(dt1) {
783	"use strict";
784	var dt2 = arguments[1]!==undefined ? arguments[1] : '';
785	var short_date = arguments[2]!==undefined ? arguments[2] : true;
786	var sec = arguments[3]!==undefined ? arguments[3] : false;
787	var a1 = dateParse(dt1);
788	dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]);
789	if (dt2 == '') {
790		dt2 = new Date();
791		var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
792	} else
793		var a2 = dateParse(dt2);
794	dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]);
795	var diff = Math.round((dt2 - dt1)/1000);
796	var days = Math.floor(diff / (24*3600));
797	diff -= days * 24 * 3600;
798	var hours = Math.floor(diff / 3600);
799	diff -= hours * 3600;
800	var minutes = Math.floor(diff / 60);
801	diff -= minutes * 60;
802	rez = '';
803	if (days > 0)
804		rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
805	if ((!short_date || rez=='') && hours > 0)
806		rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
807	if ((!short_date || rez=='') && minutes > 0)
808		rez +=  (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
809	if (sec || rez=='')
810		rez +=  rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
811	return rez;
812}
813
814
815
816//=============================================================
817//==  Form validation
818//=============================================================
819/*
820		// Usage example:
821		var error = formValidate(jQuery(form_selector), {				// -------- Options
822			error_message_show: true,									// Display or not error message
823			error_message_time: 5000,									// Time to display error message
824			error_message_class: 'sc_infobox sc_infobox_style_error',	// Class, appended to error message block
825			error_message_text: 'Global error text',					// Global error message text (if don't write message in checked field)
826			error_fields_class: 'error_fields_class',					// Class, appended to error fields
827			exit_after_first_error: false,								// Cancel validation and exit after first error
828			rules: [
829				{
830					field: 'author',																// Checking field name
831					min_length: { value: 1,	 message: 'The author name can\'t be empty' },			// Min character count (0 - don't check), message - if error occurs
832					max_length: { value: 60, message: 'Too long author name'}						// Max character count (0 - don't check), message - if error occurs
833				},
834				{
835					field: 'email',
836					min_length: { value: 7,	 message: 'Too short (or empty) email address' },
837					max_length: { value: 60, message: 'Too long email address'},
838					mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'}
839				},
840				{
841					field: 'comment',
842					min_length: { value: 1,	 message: 'The comment text can\'t be empty' },
843					max_length: { value: 200, message: 'Too long comment'}
844				},
845				{
846					field: 'pwd1',
847					min_length: { value: 5,	 message: 'The password can\'t be less then 5 characters' },
848					max_length: { value: 20, message: 'Too long password'}
849				},
850				{
851					field: 'pwd2',
852					equal_to: { value: 'pwd1',	 message: 'The passwords in both fields must be equals' }
853				}
854			]
855		});
856*/
857
858function formValidate(form, opt) {
859	"use strict";
860	var error_msg = '';
861	form.find(":input").each(function() {
862		"use strict";
863		if (error_msg!='' && opt.exit_after_first_error) return;
864		for (var i = 0; i < opt.rules.length; i++) {
865			if (jQuery(this).attr("name") == opt.rules[i].field) {
866				var val = jQuery(this).val();
867				var error = false;
868				if (typeof(opt.rules[i].min_length) == 'object') {
869					if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
870						if (error_msg=='') jQuery(this).get(0).focus();
871						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].min_length.message)!='undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>'
872						error = true;
873					}
874				}
875				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
876					if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
877						if (error_msg=='') jQuery(this).get(0).focus();
878						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].max_length.message)!='undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>'
879						error = true;
880					}
881				}
882				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
883					if (opt.rules[i].mask.value != '') {
884						var regexp = new RegExp(opt.rules[i].mask.value);
885						if (!regexp.test(val)) {
886							if (error_msg=='') jQuery(this).get(0).focus();
887							error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'
888							error = true;
889						}
890					}
891				}
892				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
893					if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) {
894						if (error_msg=='') jQuery(this).get(0).focus();
895						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].equal_to.message)!='undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>'
896						error = true;
897					}
898				}
899				if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error);
900			}
901		}
902	});
903	if (error_msg!='' && opt.error_message_show) {
904		THEMEREX_error_msg_box = form.find(".result");
905		if (THEMEREX_error_msg_box.length == 0) {
906			form.append('<div class="result"></div>');
907			THEMEREX_error_msg_box = form.find(".result");
908		}
909		if (opt.error_message_class) THEMEREX_error_msg_box.toggleClass(opt.error_message_class, true);
910		THEMEREX_error_msg_box.html(error_msg).fadeIn();
911		setTimeout(function() { THEMEREX_error_msg_box.fadeOut(); }, opt.error_message_time);
912	}
913	return error_msg!='';
914}
915
916
917
918
919//=============================================================
920//==  Document manipulations
921//=============================================================
922
923// Animated scroll to selected id
924function animateTo(id) {
925	if (id.indexOf('#')==-1) id = '#' + id;
926	var obj = jQuery(id).eq(0);
927	if (obj.length == 0) return;
928	var oft = jQuery(id).offset().top;
929	var st  = jQuery(window).scrollTop();
930	var speed = Math.min(1600, Math.max(400, Math.round(Math.abs(oft-st) / jQuery(window).height() * 100)));
931	jQuery('body,html').animate( {scrollTop: oft - jQuery('#wpadminbar').height() - jQuery('header.fixedTopMenu .topWrap').height()}, speed, 'swing');
932}
933
934// Change browser address without reload page
935function setLocation(curLoc){
936	try {
937		history.pushState(null, null, curLoc);
938		return;
939	} catch(e) {}
940	location.href = curLoc;
941}
942
943
944
945
946//=============================================================
947//==  Browser detection
948//=============================================================
949function isMobile() {
950	var check = false;
951	(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
952	return check;
953}
954function isiOS() {
955	return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
956}
957
958
959
960
961//=============================================================
962//==  File functions
963//=============================================================
964function getFileName(path) {
965	path = path.replace(/\\/g, '/');
966	var pos = path.lastIndexOf('/');
967	if (pos >= 0)
968		path = path.substr(pos+1);
969	return path;
970}
971
972function getFileExt(path) {
973	var pos = path.lastIndexOf('.');
974	path = pos >= 0 ? path.substr(pos+1) : '';
975	return path;
976}
977
978
979
980
981//=============================================================
982//==  PHP-style functions
983//=============================================================
984function isset(obj) {
985	return obj != undefined;
986}
987
988function empty(obj) {
989	return obj == undefined || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && alltrim(obj)=='');
990}
991
992function is_array(obj)  {
993	"use strict";
994	return typeof(obj)=='array';
995}
996
997function is_object(obj)  {
998	"use strict";
999	return typeof(obj)=='object';
1000}
1001
1002function in_array(val, thearray)  {
1003	"use strict";
1004	var rez = false;
1005	for (var x=0; x<thearray.length-1; x++)  {
1006		if (thearray[x] == val)  {
1007			rez = true;
1008			break;
1009		}
1010	}
1011	return rez;
1012}
1013
1014function clone(obj) {
1015	if (obj == null || typeof(obj) != 'object') {
1016		return obj;
1017	}
1018	var temp = {};
1019	for (var key in obj) {
1020		temp[key] = clone(obj[key]);
1021	}
1022	return temp;
1023}
1024
1025
1026
1027//=============================================================
1028//==  Debug functions
1029//=============================================================
1030function objDisplay(obj) {
1031	"use strict";
1032	var html = arguments[1] ? arguments[1] : false;				// Tags decorate
1033	var recursive = arguments[2] ? arguments[2] : false;		// Show inner objects (arrays)
1034	var showMethods = arguments[3] ? arguments[3] : false;		// Show object's methods
1035	var level = arguments[4] ? arguments[4] : 0;				// Nesting level (for internal usage only)
1036	var dispStr = "";
1037	var addStr = "";
1038	if (level>0) {
1039		dispStr += (obj===null ? "null" : typeof(obj)) + (html ? "\n<br />" : "\n");
1040		addStr = replicate(html ? '&nbsp;' : ' ', level*2);
1041	}
1042	if (obj!==null) {
1043		for (var prop in obj) {
1044			if (!showMethods && typeof(obj[prop])=='function')	// || prop=='innerHTML' || prop=='outerHTML' || prop=='innerText' || prop=='outerText')
1045				continue;
1046			if (recursive && (typeof(obj[prop])=='object' || typeof(obj[prop])=='array') && obj[prop]!=obj)
1047				dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+objDisplay(obj[prop], html, recursive, showMethods, level+1);
1048			else
1049				dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+(typeof(obj[prop])=='string' ? '"' : '')+obj[prop]+(typeof(obj[prop])=='string' ? '"' : '')+(html ? "\n<br />" : "\n");
1050		}
1051	}
1052	return dispStr;
1053}
1054
1055function cl(s) { console.log(s); }
1056function cd(s) { console.log(objDisplay(s)); }
1057function al(s) { if (typeof THEMEREX_userLoggedIn != 'undefined' && THEMEREX_userLoggedIn) alert(s); }
1058function ad(s) { if (typeof THEMEREX_userLoggedIn != 'undefined' && THEMEREX_userLoggedIn) alert(objDisplay(s)); }
1059function dl(s) {
1060	if (typeof THEMEREX_userLoggedIn != 'undefined' && THEMEREX_userLoggedIn) {
1061		if (jQuery('#debugLog').length == 0) jQuery('body').append('<div id="debugLog"><span id="debugLogClose" onclick="jQuery(\'#debugLog\').hide();jQuery(\'#debugLogContent\').empty();">x</span><div id="debugLogContent"></div></div>');
1062		jQuery('#debugLogContent').append('<br>'+s);
1063		jQuery('#debugLog').show();
1064	}
1065}
1066function dd(s) {
1067	if (typeof THEMEREX_userLoggedIn != 'undefined' && THEMEREX_userLoggedIn) {
1068		if (jQuery('#debugLog').length == 0) jQuery('body').append('<div id="debugLog"><span id="debugLogClose" onclick="jQuery(\'#debugLog\').hide();">x</span><div id="debugLogContent"></div></div>');
1069		jQuery('#debugLogContent').html(objDisplay(s));
1070		jQuery('#debugLog').show();
1071	}
1072}
1073
1074
1075
1076
1077//=============================================================
1078//==  smartresize
1079//=============================================================
1080(function($,sr){
1081    var debounce = function (func, threshold, execAsap) {
1082        var timeout;
1083
1084        return function debounced () {
1085            var obj = this, args = arguments;
1086            function delayed () {
1087                if (!execAsap)
1088                    func.apply(obj, args);
1089                timeout = null;
1090            };
1091
1092            if (timeout)
1093                clearTimeout(timeout);
1094            else if (execAsap)
1095                func.apply(obj, args);
1096
1097            timeout = setTimeout(delayed, threshold || 500);
1098        };
1099    }
1100    // smartresize
1101    jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
1102
1103})(jQuery,'smartresize');

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