PageSourceSearch

https://dmorph.com/js/_utils.js

js dmorph.com collected 2026-10-04 02:28:57 UTC 25,287 bytes, 797 lines download raw bytes

1//=============================================================
2//==  Stylesheets manipulations
3//=============================================================
4function setStateStyleSheet(title, state) {
5	var i, a;
6	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
7		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
8			if (a.getAttribute("title") == title) a.disabled = !state;
9    	}
10  	}
11}
12
13function getStateStyleSheet(title, state) {
14	var i, a, rez=-1;
15	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
16		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
17			if (a.getAttribute("title") == title) {
18				rez = a.disabled ? 0 : 1;
19				break;
20			}
21    	}
22  	}
23	return rez;
24}
25
26function setActiveStyleSheet(title, disableOther) {
27	var i, a, main;
28	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
29		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
30			if (disableOther) a.disabled = true;
31			if (a.getAttribute("title") == title) a.disabled = false;
32    	}
33  	}
34}
35
36function getActiveStyleSheet() {
37	var i, a;
38	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
39		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
40	}
41	return null;
42}
43
44function getPreferredStyleSheet() {
45	var i, a;
46	for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
47		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") )
48			return a.getAttribute("title");
49	}
50	return null;
51}
52
53
54//=============================================================
55//==  ListBox & ComboBox manipulations
56//=============================================================
57function addListBoxItem(box, val, text) {
58	var item = new Option();
59	item.value = val;
60	item.text = text;
61    box.options.add(item);
62}
63
64function clearListBox(box) {
65	for (var i=box.options.length-1; i>=0; i--)
66		box.options[i] = null;
67}
68
69function delListBoxItemByValue(box, val) {
70	for (var i=0; i<box.options.length; i++) {
71		if (box.options[i].value == val) {
72			box.options[i] = null;
73			break;
74		}
75	}
76}
77
78function delListBoxItemByText(box, txt) {
79	for (var i=0; i<box.options.length; i++) {
80		if (box.options[i].text == txt) {
81			box.options[i] = null;
82			break;
83		}
84	}
85}
86
87function findListBoxItemByValue(box, val) {
88	var idx = -1;
89	for (var i=0; i<box.options.length; i++) {
90		if (box.options[i].value == val) {
91			idx = i;
92			break;
93		}
94	}
95	return idx;
96}
97
98function findListBoxItemByText(box, txt) {
99	var idx = -1;
100	for (var i=0; i<box.options.length; i++) {
101		if (box.options[i].text == txt) {
102			idx = i;
103			break;
104		}
105	}
106	return idx;
107}
108
109function selectListBoxItemByValue(box, val) {
110	for (var i = 0; i < box.options.length; i++) {
111		box.options[i].selected = (val == box.options[i].value);
112	}
113}
114
115function selectListBoxItemByText(box, txt) {
116	for (var i = 0; i < box.options.length; i++) {
117		box.options[i].selected = (txt == box.options[i].text);
118	}
119}
120
121function getListBoxValues(box) {
122	var delim = arguments[1] ? arguments[1] : ',';
123	var str = '';
124	for (var i=0; i<box.options.length; i++) {
125		str += (str ? delim : '') + box.options[i].value;
126	}
127	return str;
128}
129
130function getListBoxTexts(box) {
131	var delim = arguments[1] ? arguments[1] : ',';
132	var str = '';
133	for (var i=0; i<box.options.length; i++) {
134		str += (str ? delim : '') + box.options[i].text;
135	}
136	return str;
137}
138
139function sortListBox(box)  {
140	var temp_opts = new Array();
141	var temp = new Option();
142	for(var i=0; i<box.options.length; i++)  {
143		temp_opts[i] = box.options[i].clone();
144	}
145	for(var x=0; x<temp_opts.length-1; x++)  {
146		for(var y=(x+1); y<temp_opts.length; y++)  {
147			if(temp_opts[x].text > temp_opts[y].text)  {
148				temp = temp_opts[x];
149				temp_opts[x] = temp_opts[y];
150				temp_opts[y] = temp;
151			}  
152		}  
153	}
154	for(var i=0; i<box.options.length; i++)  {
155		box.options[i] = temp_opts[i].clone();
156	}
157}
158
159function getListBoxSelectedIndex(box) {
160	for (var i = 0; i < box.options.length; i++) {
161		if (box.options[i].selected)
162			return i;
163	}
164	return -1;
165}
166
167function getListBoxSelectedValue(box) {
168	for (var i = 0; i < box.options.length; i++) {
169		if (box.options[i].selected) {
170			return box.options[i].value;
171		}
172	}
173	return null;
174}
175
176function getListBoxSelectedText(box) {
177	for (var i = 0; i < box.options.length; i++) {
178		if (box.options[i].selected) {
179			return box.options[i].text;
180		}
181	}
182	return null;
183}
184
185function getListBoxSelectedOption(box) {
186	for (var i = 0; i < box.options.length; i++) {
187		if (box.options[i].selected) {
188			return box.options[i];
189		}
190	}
191	return null;
192}
193
194
195//=============================================================
196//==  Radiobuttons manipulations
197//=============================================================
198function getRadioGroupValue(radioGroupObj) {
199	for (var i=0; i < radioGroupObj.length; i++)
200		if (radioGroupObj[i].checked) return radioGroupObj[i].value;
201	return null;
202}
203
204function setRadioGroupCheckedByNum(radioGroupObj, num) {
205	for (var i=0; i < radioGroupObj.length; i++)
206		if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false;
207		else if (i==num) radioGroupObj[i].checked=true;
208}
209
210function setRadioGroupCheckedByValue(radioGroupObj, val) {
211	for (var i=0; i < radioGroupObj.length; i++)
212		if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false;
213		else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true;
214}
215
216
217//=============================================================
218//==  Array manipulations
219//=============================================================
220function sortArray(thearray)  {
221	var caseSensitive = arguments[1] ? arguments[1] : false;
222	for (var x=0; x<thearray.length-1; x++)  {
223		for (var y=(x+1); y<thearray.length; y++)  {
224			if (caseSensitive) {
225				if (thearray[x] > thearray[y])  {
226					tmp = thearray[x];
227					thearray[x] = thearray[y];
228					thearray[y] = tmp;
229				}  
230			} else {
231				if (thearray[x].toLowerCase() > thearray[y].toLowerCase())  {
232					tmp = thearray[x];
233					thearray[x] = thearray[y];
234					thearray[y] = tmp;
235				}  
236			}
237		}  
238	}
239}
240
241
242//=============================================================
243//==  String functions
244//=============================================================
245function inList(list, str) {
246	var delim = arguments[2] ? arguments[2] : '|';
247	var icase = arguments[3] ? arguments[3] : true;
248	var retval = false;
249	if (icase) {
250		str = str.toLowerCase();
251		list = list.toLowerCase();
252	}
253	parts = list.split(delim);
254	for (var i=0; i<parts.length; i++) {
255		if (parts[i]==str) {
256			retval=true;
257			break;
258		}
259	}
260	return retval;
261}
262
263function alltrim(str) {
264	var dir = arguments[1] ? arguments[1] : 'a';
265	var rez = '';
266	var i, start = 0, end = str.length-1;
267	if (dir=='a' || dir=='l') {
268		for (i=0; i<str.length; i++) {
269			if (str.substr(i,1)!=' ') {
270				start = i;
271				break;
272			}
273		}
274	}
275	if (dir=='a' || dir=='r') {
276		for (i=str.length-1; i>=0; i--) {
277			if (str.substr(i,1)!=' ') {
278				end = i;
279				break;
280			}
281		}
282	}
283	return str.substring(start, end+1);
284}
285
286function ltrim(str) {
287	return alltrim(str, 'l');
288}
289
290function rtrim(str) {
291	return alltrim(str, 'r');
292}
293
294function padl(str, len) {
295	var char = arguments[2] ? arguments[2] : ' ';
296	var rez = str.substr(0,len);
297	if (rez.length < len) {
298		for (var i=0; i<len-str.length; i++)
299			rez += char;
300	}
301	return rez;
302}
303
304function padr(str, len) {
305	var char = arguments[2] ? arguments[2] : ' ';
306	var rez = str.substr(0,len);
307	if (rez.length < len) {
308		for (var i=0; i<len-str.length; i++)
309			rez = char + rez;
310	}
311	return rez;
312}
313
314function padc(str, len) {
315	var char = arguments[2] ? arguments[2] : ' ';
316	var rez = str.substr(0,len);
317	if (rez.length < len) {
318		for (var i=0; i<Math.floor((len-str.length)/2); i++)
319			rez = char + rez + char;
320	}
321	return rez+(rez.length<len ? char : '');
322}
323
324function replicate(str, num) {
325	rez = '';
326	for (var i=0; i<num; i++) {
327		rez += str;
328	}
329	return rez;
330}
331
332
333//=============================================================
334//==  Numbers functions
335//=============================================================
336
337// Clear number from any characters and append it with 0 to desired precision
338function clearNumber(num) {
339	var precision = arguments[1] ? arguments[1] : 0;
340	var defa = arguments[2] ? arguments[2] : 0;
341	var res = '';
342	var float = -1;
343	num = ""+num;
344	if (num=="") num=""+defa;
345	for (var i=0; i<num.length; i++) {
346		if (float==0) break;
347		else if (float>0) float--;
348		var ch = num.substr(i,1);
349		if (ch=='.') {
350			if (precision>0) {
351				res += ch;
352			}
353			float = precision;
354		} else if ((ch>=0 && ch<=9) || (ch=='-' && i==0))
355			res+=ch;
356	}
357	if (precision>0 && float!=0) {
358		if (float==-1) {
359			res += '.';
360			float = precision;
361		}
362		for (i=float; i>0; i--)
363			res +='0'; 
364	}
365	//if (isNaN(res)) res = clearNumber(defa, precision, defa);
366	return res;
367}
368
369function dec2hex(n) { 
370	return Number(n).toString(16);
371}
372
373function hex2dec(hex) {
374	return parseInt(hex,16); 
375}
376
377function roundNumber(num) {
378	var precision = arguments[1] ? arguments[1] : 0;
379	var p = Math.pow(10,precision);
380	return Math.round(num*p)/p;
381}
382
383//=============================================================
384//==  Color manipulations
385//=============================================================
386function rgb2hex(color) {
387	var aRGB;
388	color = color.replace(/\s/g,"").toLowerCase();
389	if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)')
390		color = 'transparent';
391	if (color.indexOf('rgba(')==0)
392		aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
393	else	
394		aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
395	
396	if (aRGB) {
397		color = '';
398		for (var i=1; i<=3; i++) 
399			color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
400	} else 
401		color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
402	return (color.substr(0,1)!='#' ? '#' : '') + color;
403}
404
405function _rgb2hex(r,g,b) {
406	return '#'+
407		Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
408		Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
409		Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
410}
411
412function split_rgb(color) {
413	color = rgb2hex(color);
414	var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
415	if (!matches) return false;
416	for (var i=1, rgb = new Array(3); i<=3; i++)
417		rgb[i-1] = parseInt(matches[i],16);
418	return rgb;
419}
420
421function hex_rgb(hex) {
422	var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
423	return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
424}
425
426function hex_hsb(hex) {
427	return rgb_hsb(hex_rgb(hex));
428}
429
430function rgb_hsb(rgb) {
431	var hsb = {};
432	hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
433	hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
434	hsb.b = Math.round((hsb.b /255)*100);
435	if((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0;
436	else if(rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
437	else if(rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60  + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
438	else if(rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
439	else if(rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
440	else if(rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
441	else if(rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
442	else hsb.h = 0;
443	hsb.h = Math.round(hsb.h);
444	return hsb;
445}
446
447function hsb_rgb(hsb) {
448	var rgb = {};
449	var h = Math.round(hsb.h);
450	var s = Math.round(hsb.s*255/100);
451	var v = Math.round(hsb.b*255/100);
452	if(s == 0) {
453		rgb.r = rgb.g = rgb.b = v;
454	} else {
455		var t1 = v;
456		var t2 = (255-s)*v/255;
457		var t3 = (t1-t2)*(h%60)/60;
458		if(h==360) h = 0;
459		if(h<60) {rgb.r=t1;	rgb.b=t2; rgb.g=t2+t3}
460		else if(h<120) {rgb.g=t1; rgb.b=t2;	rgb.r=t1-t3}
461		else if(h<180) {rgb.g=t1; rgb.r=t2;	rgb.b=t2+t3}
462		else if(h<240) {rgb.b=t1; rgb.r=t2;	rgb.g=t1-t3}
463		else if(h<300) {rgb.b=t1; rgb.g=t2;	rgb.r=t2+t3}
464		else if(h<360) {rgb.r=t1; rgb.g=t2;	rgb.b=t1-t3}
465		else {rgb.r=0; rgb.g=0;	rgb.b=0}
466	}
467	return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
468}
469
470function rgb_hex(rgb) {
471	var hex = [
472		rgb.r.toString(16),
473		rgb.g.toString(16),
474		rgb.b.toString(16)
475	];
476	jQuery.each(hex, function (nr, val) {
477		if (val.length == 1) {
478			hex[nr] = '0' + val;
479		}
480	});
481	return hex.join('');
482}
483function hsb_hex(hsb) {
484	return rgb_hex(hsb_rgb(hsb));
485}
486
487function iColorPicker(){
488	var colors = arguments[0] ? arguments[0] : 
489	'#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
490	+'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
491	+'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
492	+'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
493	+'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
494	+'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
495	+'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
496	var colorsList = colors.split(',');
497	var tbl = '<table class="colorPickerTable"><thead>';
498	for (var i=0; i<colorsList.length; i++) {
499		if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>';
500		tbl += '<td style="background-color:'+colorsList[i]+'"></td>';
501	}
502	tbl += '</tr></thead><tbody><tr><td style="border:1px solid #000;background:#fff;cursor:pointer;height:60px;-moz-background-clip:-moz-initial;-moz-background-origin:-moz-initial;-moz-background-inline-policy:-moz-initial;" colspan="16" align="center" id="colorPreview"><span style="color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;"></span></td></tr></tbody></table>';
503	//tbl += '<style>#iColorPicker input{margin:2px}</style>';
504
505	jQuery(document.createElement("div"))
506		.attr("id","iColorPicker")
507		.css('display','none')
508		.html(tbl)
509		.appendTo("body")
510		.on('mouseover', 'thead td', function(){
511			var aaa=rgb2hex(jQuery(this).css('background-color'));
512			jQuery('#colorPreview').css('background',aaa);
513			jQuery('#colorPreview span').text(aaa);
514		})
515		.on('click', 'thead td', function(){
516			var id = jQuery('#iColorPicker').data('fieldId');
517			var func = jQuery('#iColorPicker').data('func');
518			var aaa=rgb2hex(jQuery(this).css('background-color'));
519			if (id) jQuery("#"+id).val(aaa).css("background", aaa).trigger('change');
520			if (func!=null && func!='undefined') func(id, aaa);
521			jQuery("#iColorPickerBg").hide();
522			jQuery("#iColorPicker").fadeOut();
523		});
524	jQuery(document.createElement("div"))
525		.attr("id","iColorPickerBg")
526		.click(function() {
527			jQuery("#iColorPickerBg").hide();
528			jQuery("#iColorPicker").fadeOut();
529		})
530		.appendTo("body");
531	jQuery('#iColorPicker td')
532		.css({
533			'width':'12px',
534			'height':'14px',
535			'border':'1px solid #000',
536			'cursor':'pointer'
537		});
538	jQuery('#iColorPicker table')
539		.css({'border-collapse':'collapse'});
540	jQuery('#iColorPicker')
541		.css({
542			'border':'1px solid #ccc',
543			'background':'#333',
544			'padding':'5px',
545			'color':'#fff',
546			'z-index':999999
547		});
548	jQuery('#colorPreview')
549		.css({'height':'50px'});
550}
551
552function iColorShow(id, id2,func) { 
553	var eICP = jQuery("#"+id2).offset();
554	jQuery("#iColorPicker")
555		.data({fieldId: id, func: func})
556		.css({
557			'top':eICP.top+jQuery("#"+id).outerHeight()+"px",
558			'left':eICP.left-jQuery("#"+id).outerWidth()+"px",
559			'position':'absolute'
560		})
561		.fadeIn("fast");
562	jQuery("#iColorPickerBg")
563		.css({
564			'position':'fixed',
565			'top':0,
566			'left':0,
567			'width':'100%',
568			'height':'100%'
569		})
570		.fadeIn("fast");
571
572	var def=jQuery("#"+id).val();
573	jQuery('#colorPreview span').text(def);
574	jQuery('#colorPreview').css('background',def);
575	jQuery('#color').val(def);
576}
577
578
579//=============================================================
580//==  Cookies manipulations
581//=============================================================
582function getCookie(name) {
583	var defa = arguments[1]!='undefined' ? arguments[1] : null;
584	var start = document.cookie.indexOf(name + '=');
585	var len = start + name.length + 1;
586	if ((!start) && (name != document.cookie.substring(0, name.length))) {
587		return defa;
588	}
589	if (start == -1)
590		return defa;
591	var end = document.cookie.indexOf(';', len);
592	if (end == -1)
593		end = document.cookie.length;
594	return unescape(document.cookie.substring(len, end));
595}
596
597
598function setCookie(name, value, expires, path, domain, secure) {
599	var today = new Date();
600	today.setTime(today.getTime());
601	if (expires) {
602		expires = expires * 1000;		// * 60 * 60 * 24;
603	}
604	var expires_date = new Date(today.getTime() + (expires));
605	document.cookie = name + '='
606			+ escape(value)
607			+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
608			+ ((path)    ? ';path=' + path : '')
609			+ ((domain)  ? ';domain=' + domain : '')
610			+ ((secure)  ? ';secure' : '');
611}
612
613
614function deleteCookie(name, path, domain) {
615	if (getCookie(name))
616		document.cookie = name + '=' + ((path) ? ';path=' + path : '')
617				+ ((domain) ? ';domain=' + domain : '')
618				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
619}
620
621
622//=============================================================
623//==  Date manipulations
624//=============================================================
625
626// Return array[Year, Month, Day, Hours, Minutes, Seconds]
627// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
628function dateParse(dt) {
629	dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0];
630	var dt2 = dt.split(' ');
631	var d = dt2[0].split('-');
632	var t = dt2[1].split(':');
633	d.push(t[0], t[1], t[2]);
634	return d;
635}
636
637function dateDifference(dt1, dt2, short, sec) {
638	var dt2 = arguments[1]!==undefined ? arguments[1] : '';
639	var short = arguments[2]!==undefined ? arguments[2] : true;
640	var sec = arguments[3]!==undefined ? arguments[3] : false;
641	var a1 = dateParse(dt1);
642	dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]);
643	if (dt2 == '') {
644		dt2 = new Date();
645		var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
646	} else
647		var a2 = dateParse(dt2);
648	dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]);
649	var diff = Math.round((dt2 - dt1)/1000);
650	var days = Math.floor(diff / (24*3600));
651	diff -= days * 24 * 3600;
652	var hours = Math.floor(diff / 3600);
653	diff -= hours * 3600;
654	var minutes = Math.floor(diff / 60);
655	diff -= minutes * 60;
656	rez = '';
657	if (days > 0)
658		rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
659	if ((!short || rez=='') && hours > 0)
660		rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
661	if ((!short || rez=='') && minutes > 0)
662		rez +=  (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
663	if (sec || rez=='')
664		rez +=  rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
665	return rez;
666}
667
668
669
670//=============================================================
671//==  Form validation
672//=============================================================
673/*
674		// Usage example:
675		var error = formValidate(jQuery(form_selector), {				// -------- Options
676			error_message_show: true,									// Display or not error message
677			error_message_time: 5000,									// Time to display error message
678			error_message_class: 'sc_infobox sc_infobox_style_error',	// Class, appended to error message block
679			error_message_text: 'Global error text',					// Global error message text (if don't write message in checked field)
680			error_fields_class: 'error_fields_class',					// Class, appended to error fields
681			exit_after_first_error: false,								// Cancel validation and exit after first error
682			rules: [
683				{
684					field: 'author',																// Checking field name
685					min_length: { value: 1,	 message: 'The author name can\'t be empty' },			// Min character count (0 - don't check), message - if error occurs
686					max_length: { value: 60, message: 'Too long author name'}						// Max character count (0 - don't check), message - if error occurs
687				},
688				{
689					field: 'email',
690					min_length: { value: 7,	 message: 'Too short (or empty) email address' },
691					max_length: { value: 60, message: 'Too long email address'},
692					mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'}
693				},
694				{
695					field: 'comment',
696					min_length: { value: 1,	 message: 'The comment text can\'t be empty' },
697					max_length: { value: 200, message: 'Too long comment'}
698				},
699				{
700					field: 'pwd1',
701					min_length: { value: 5,	 message: 'The password can\'t be less then 5 characters' },
702					max_length: { value: 20, message: 'Too long password'}
703				},
704				{
705					field: 'pwd2',
706					equal_to: { value: 'pwd1',	 message: 'The passwords in both fields must be equals' }
707				}
708			]
709		});
710*/
711
712function formValidate(form, opt) {
713	var error_msg = '';
714	form.find(":input").each(function() {
715		if (error_msg!='' && opt.exit_after_first_error) return;
716		for (var i = 0; i < opt.rules.length; i++) {
717			if (jQuery(this).attr("name") == opt.rules[i].field) {
718				var val = jQuery(this).val();
719				var error = false;
720				if (typeof(opt.rules[i].min_length) == 'object') {
721					if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
722						if (error_msg=='') jQuery(this).get(0).focus();
723						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>'
724						error = true;
725					}
726				}
727				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
728					if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
729						if (error_msg=='') jQuery(this).get(0).focus();
730						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>'
731						error = true;
732					}
733				}
734				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
735					if (opt.rules[i].mask.value != '') {
736						var regexp = new RegExp(opt.rules[i].mask.value);
737						if (!regexp.test(val)) {
738							if (error_msg=='') jQuery(this).get(0).focus();
739							error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'
740							error = true;
741						}
742					}
743				}
744				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
745					if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) {
746						if (error_msg=='') jQuery(this).get(0).focus();
747						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>'
748						error = true;
749					}
750				}
751				if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error);
752			}
753		}
754	});
755	if (error_msg!='' && opt.error_message_show) {
756		error_msg_box = form.find(".result");
757		if (error_msg_box.length == 0) {
758			form.append('<div class="result"></div>');
759			error_msg_box = form.find(".result");
760		}
761		if (opt.error_message_class) error_msg_box.toggleClass(opt.error_message_class, true);
762		error_msg_box.html(error_msg).fadeIn();
763		setTimeout("error_msg_box.fadeOut()", opt.error_message_time);
764	}
765	return error_msg!='';
766}
767
768
769
770
771
772//=============================================================
773//==  Debug functions
774//=============================================================
775function objDisplay(obj) {
776	var html = arguments[1] ? arguments[1] : false;				// Tags decorate
777	var recursive = arguments[2] ? arguments[2] : false;		// Show inner objects (arrays)
778	var showMethods = arguments[3] ? arguments[3] : false;		// Show object's methods
779	var level = arguments[4] ? arguments[4] : 0;				// Nesting level (for inner use only)
780	var dispStr = "";
781	var addStr = "";
782	if (level>0) {
783		dispStr += (obj===null ? "null" : "Object") + (html ? "\n<br />" : "\n");
784		addStr = replicate(html ? '&nbsp;' : ' ', level*2);
785	}
786	if (obj!==null) {
787		for (var prop in obj) {
788			if (!showMethods && typeof(obj[prop])=='function')	// || prop=='innerHTML' || prop=='outerHTML' || prop=='innerText' || prop=='outerText')
789				continue;
790			if (recursive && (typeof(obj[prop])=='object' || typeof(obj[prop])=='array') && obj[prop]!=obj)
791				dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+objDisplay(obj[prop], html, recursive, showMethods, level+1);
792			else
793				dispStr += addStr + (html ? "<b>" : "")+prop+(html ? "</b>" : "")+'='+(typeof(obj[prop])=='string' ? '"' : '')+obj[prop]+(typeof(obj[prop])=='string' ? '"' : '')+(html ? "\n<br />" : "\n");
794		}
795	}
796	return dispStr;
797}

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.