PageSourceSearch

https://alpenverein-passau.de/wp-content/themes/wanderic/js/utils.js?reload=1076067566

js alpenverein-passau.de collected 2026-09-28 13:44:23 UTC 54,120 bytes, 1,621 lines download raw bytes

1/**
2 * Javascript utilities
3 *
4 * @package WANDERIC
5 * @since WANDERIC 1.0
6 */
7
8/* global jQuery, WANDERIC_STORAGE */
9
10/* Global variables manipulations
11---------------------------------------------------------------- */
12
13(function(){
14	"use strict";
15
16	// Global variables storage
17	if (typeof WANDERIC_STORAGE == 'undefined') {
18		window.WANDERIC_STORAGE = {};
19	}
20
21	// Get global variable
22	window.wanderic_storage_get = function(var_name) {
23		return wanderic_isset( WANDERIC_STORAGE[var_name] ) ? WANDERIC_STORAGE[var_name] : '';
24	};
25
26	// Set global variable
27	window.wanderic_storage_set = function(var_name, value) {
28		WANDERIC_STORAGE[var_name] = value;
29	};
30
31	// Inc/Dec global variable with specified value
32	window.wanderic_storage_inc = function(var_name) {
33		var value                  = arguments[1] === undefined ? 1 : arguments[1];
34		WANDERIC_STORAGE[var_name] += value;
35	};
36
37	// Concatenate global variable with specified value
38	window.wanderic_storage_concat = function(var_name, value) {
39		WANDERIC_STORAGE[var_name] += '' + value;
40	};
41
42	// Get global array element
43	window.wanderic_storage_get_array = function(var_name, key) {
44		return wanderic_isset( WANDERIC_STORAGE[var_name][key] ) ? WANDERIC_STORAGE[var_name][key] : '';
45	};
46
47	// Set global array element
48	window.wanderic_storage_set_array = function(var_name, key, value) {
49		if ( ! wanderic_isset( WANDERIC_STORAGE[var_name] )) {
50			WANDERIC_STORAGE[var_name] = {};
51		}
52		WANDERIC_STORAGE[var_name][key] = value;
53	};
54
55	// Inc/Dec global array element with specified value
56	window.wanderic_storage_inc_array = function(var_name, key) {
57		var value                       = arguments[2] === undefined ? 1 : arguments[2];
58		WANDERIC_STORAGE[var_name][key] += value;
59	};
60
61	// Concatenate global array element with specified value
62	window.wanderic_storage_concat_array = function(var_name, key, value) {
63		WANDERIC_STORAGE[var_name][key] += '' + value;
64	};
65
66	/* PHP-style functions
67	---------------------------------------------------------------- */
68	window.wanderic_isset = function(obj) {
69		return typeof(obj) != 'undefined';
70	};
71
72	window.wanderic_empty = function(obj) {
73		return typeof(obj) == 'undefined' || (typeof(obj) == 'object' && obj == null) || (typeof(obj) == 'array' && obj.length == 0) || (typeof(obj) == 'string' && wanderic_alltrim( obj ) == '') || obj === 0;
74	};
75
76	window.wanderic_is_array = function(obj)  {
77		return typeof(obj) == 'array';
78	};
79
80	window.wanderic_is_object = function(obj)  {
81		return typeof(obj) == 'object';
82	};
83
84	window.wanderic_clone_object = function(obj) {
85		if (obj === null || typeof(obj) != 'object') {
86			return obj;
87		}
88		var temp = {};
89		for (var key in obj) {
90			temp[key] = wanderic_clone_object( obj[key] );
91		}
92		return temp;
93	};
94
95	window.wanderic_merge_objects = function(obj1, obj2)  {
96		for (var i in obj2) {
97			obj1[i] = obj2[i];
98		}
99		return obj1;
100	};
101
102	window.wanderic_array_merge = function(a1, a2) {
103		for (var i in a2) {
104			a1[i] = a2[i];
105		}
106		return a1;
107	};
108
109	window.wanderic_array_first_key = function(arr) {
110		var rez = null;
111		for (var i in arr) {
112			rez = i;
113			break;
114		}
115		return rez;
116	};
117
118	window.wanderic_array_first_value = function(arr) {
119		var rez = null;
120		for (var i in arr) {
121			rez = arr[i];
122			break;
123		}
124		return rez;
125	};
126
127	// Generates a storable representation of a value
128	window.wanderic_serialize = function(mixed_val) {
129		var obj_to_array = arguments.length == 1 || argument[1] === true;
130
131		switch (typeof(mixed_val)) {
132
133			case "number":
134				if (isNaN( mixed_val ) || ! isFinite( mixed_val )) {
135					return false;
136				} else {
137					return (Math.floor( mixed_val ) == mixed_val ? "i" : "d") + ":" + mixed_val + ";";
138				}
139
140			case "string":
141				return "s:" + mixed_val.length + ":\"" + mixed_val + "\";";
142
143			case "boolean":
144				return "b:" + (mixed_val ? "1" : "0") + ";";
145
146			case "object":
147				if (mixed_val == null) {
148					return "N;";
149				} else if (mixed_val instanceof Array) {
150					var idxobj = { idx: -1 };
151					var map    = [];
152					for (var i = 0; i < mixed_val.length; i++) {
153						idxobj.idx++;
154						var ser = wanderic_serialize( mixed_val[i] );
155						if (ser) {
156							map.push( wanderic_serialize( idxobj.idx ) + ser );
157						}
158					}
159					return "a:" + mixed_val.length + ":{" + map.join( "" ) + "}";
160				} else {
161					var class_name = wanderic_get_class( mixed_val );
162					if (class_name == undefined) {
163						return false;
164					}
165					var props = new Array();
166					for (var prop in mixed_val) {
167						var ser = wanderic_serialize( mixed_val[prop] );
168						if (ser) {
169							props.push( wanderic_serialize( prop ) + ser );
170						}
171					}
172					if (obj_to_array) {
173						return "a:" + props.length + ":{" + props.join( "" ) + "}";
174					} else {
175						return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join( "" ) + "}";
176					}
177				}
178
179			case "undefined":
180				return "N;";
181		}
182		return false;
183	};
184
185	// Encode / Decode Unicode string to / from single-byte characters
186	( function( $ ) {
187		var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
188		a256 = '',
189		r64 = [256],
190		r256 = [256],
191		i = 0;
192
193		var UTF8 = {
194
195			/**
196			 * Encode multi-byte Unicode string into utf-8 multiple single-byte characters
197			 * (BMP / basic multilingual plane only)
198			 *
199			 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
200			 *
201			 * @param {String} strUni Unicode string to be encoded as UTF-8
202			 * @returns {String} encoded string
203			 */
204			encode: function(strUni) {
205				// use regular expressions & String.replace callback function for better efficiency than procedural approaches
206				var strUtf = strUni
207								.replace(
208									/[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
209									function(c) {
210										var cc = c.charCodeAt(0);
211										return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
212									}
213								)
214								.replace(
215									/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
216									function(c) {
217										var cc = c.charCodeAt(0);
218										return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
219									}
220								);
221				return strUtf;
222			},
223
224			/**
225			* Decode utf-8 encoded string back into multi-byte Unicode characters
226			*
227			* @param {String} strUtf UTF-8 string to be decoded back to Unicode
228			* @returns {String} decoded string
229			*/
230			decode: function(strUtf) {
231				// note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
232				var strUni = strUtf
233								.replace(
234									/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
235									function(c) { // (note parentheses for precence)
236										var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f);
237										return String.fromCharCode(cc);
238									}
239								)
240								.replace(
241									/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
242									function(c) { // (note parentheses for precence)
243										var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
244										return String.fromCharCode(cc);
245									}
246								);
247				return strUni;
248			}
249		};
250
251		while( i < 256 ) {
252			var c = String.fromCharCode(i);
253			a256 += c;
254			r256[i] = i;
255			r64[i] = b64.indexOf(c);
256			++i;
257		}
258
259		function code(s, discard, alpha, beta, w1, w2) {
260			s = String(s);
261			var buffer = 0,
262				i = 0,
263				length = s.length,
264				result = '',
265				bitsInBuffer = 0;
266
267			while (i < length) {
268				var c = s.charCodeAt(i);
269				c = c < 256 ? alpha[c] : -1;
270
271				buffer = (buffer << w1) + c;
272				bitsInBuffer += w1;
273
274				while (bitsInBuffer >= w2) {
275					bitsInBuffer -= w2;
276					var tmp = buffer >> bitsInBuffer;
277					result += beta.charAt(tmp);
278					buffer ^= tmp << bitsInBuffer;
279				}
280				++i;
281			}
282			if ( ! discard && bitsInBuffer > 0) {
283				result += beta.charAt(buffer << (w2 - bitsInBuffer));
284			}
285			return result;
286		}
287
288		var Plugin = $.wanderic_encoder = function(dir, input, encode) {
289			return input ? Plugin[dir](input, encode) : dir ? null : this;
290		};
291
292		Plugin.btoa = Plugin.encode = function(plain, utf8encode) {
293			plain = Plugin.raw === false || Plugin.utf8encode || utf8encode
294						? UTF8.encode(plain)
295						: plain;
296			plain = code(plain, false, r256, b64, 8, 6);
297			return plain + '===='.slice((plain.length % 4) || 4);
298		};
299
300		Plugin.atob = Plugin.decode = function(coded, utf8decode) {
301			coded = String(coded).split('=');
302			var i = coded.length;
303			do {
304				--i;
305				coded[i] = code(coded[i], true, r64, a256, 6, 8);
306			} while (i > 0);
307			coded = coded.join('');
308			return Plugin.raw === false || Plugin.utf8decode || utf8decode
309					? UTF8.decode(coded)
310					: coded;
311		};
312	}(jQuery) );
313
314	// Returns the name of the class of an object
315	window.wanderic_get_class = function(obj) {
316		if (obj instanceof Object && ! (obj instanceof Array) && ! (obj instanceof Function) && obj.constructor) {
317			var arr = obj.constructor.toString().match( /function\s*(\w+)/ );
318			if (arr && arr.length == 2) {
319				return arr[1];
320			}
321		}
322		return false;
323	};
324
325
326	/* Wordpress-style functions
327	---------------------------------------------------------------- */
328
329	// Add filter's handler
330	window.wanderic_add_filter = function( filter, callback, priority ) {
331		if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) {
332			wp.hooks.addFilter( filter, 'wanderic', callback, priority == undefined ? 10 : priority );
333		}
334	};
335
336	// Apply filter's handlers
337	window.wanderic_apply_filters = function( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) {
338		if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) {
339			return wp.hooks.applyFilters( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 );
340		} else {
341			return null;
342		}
343	};
344
345	// Add action's handler
346	window.wanderic_add_action = function( action, callback, priority ) {
347		if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) {
348			wp.hooks.addAction( action, 'wanderic', callback, priority == undefined ? 10 : priority );
349		}
350	};
351
352	// Do action's handlers
353	window.wanderic_do_actions = function( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) {
354		if ( typeof wp != 'undefined' && typeof wp.hooks != 'undefined' ) {
355			wp.hooks.doActions( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 );
356		}
357	};
358
359
360	/* String functions
361	---------------------------------------------------------------- */
362
363	window.wanderic_in_list = function(str, list) {
364		var delim  = arguments[2] !== undefined ? arguments[2] : '|';
365		var icase  = arguments[3] !== undefined ? arguments[3] : true;
366		var retval = false;
367		if (icase) {
368			if (typeof(str) == 'string') {
369				str = str.toLowerCase();
370			}
371			list = list.toLowerCase();
372		}
373		var parts = list.split( delim );
374		for (var i = 0; i < parts.length; i++) {
375			if (parts[i] == str) {
376				retval = true;
377				break;
378			}
379		}
380		return retval;
381	};
382
383	window.wanderic_alltrim = function(str) {
384		var dir      = arguments[1] !== undefined ? arguments[1] : 'a';
385		var rez      = '';
386		var i, start = 0, end = str.length - 1;
387		if (dir == 'a' || dir == 'l') {
388			for (i = 0; i < str.length; i++) {
389				if (str.substr( i,1 ) != ' ') {
390					start = i;
391					break;
392				}
393			}
394		}
395		if (dir == 'a' || dir == 'r') {
396			for (i = str.length - 1; i >= 0; i--) {
397				if (str.substr( i,1 ) != ' ') {
398					end = i;
399					break;
400				}
401			}
402		}
403		return str.substring( start, end + 1 );
404	};
405
406	window.wanderic_ltrim = function(str) {
407		return wanderic_alltrim( str, 'l' );
408	};
409
410	window.wanderic_rtrim = function(str) {
411		return wanderic_alltrim( str, 'r' );
412	};
413
414	window.wanderic_padl = function(str, len) {
415		var ch  = arguments[2] !== undefined ? arguments[2] : ' ';
416		var rez = str.substr( 0,len );
417		if (rez.length < len) {
418			for (var i = 0; i < len - str.length; i++) {
419				rez += ch;
420			}
421		}
422		return rez;
423	};
424
425	window.wanderic_padr = function(str, len) {
426		var ch  = arguments[2] !== undefined ? arguments[2] : ' ';
427		var rez = str.substr( 0,len );
428		if (rez.length < len) {
429			for (var i = 0; i < len - str.length; i++) {
430				rez = ch + rez;
431			}
432		}
433		return rez;
434	};
435
436	window.wanderic_padc = function(str, len) {
437		var ch  = arguments[2] !== undefined ? arguments[2] : ' ';
438		var rez = str.substr( 0,len );
439		if (rez.length < len) {
440			for (var i = 0; i < Math.floor( (len - str.length) / 2 ); i++) {
441				rez = ch + rez + ch;
442			}
443		}
444		return rez + (rez.length < len ? ch : '');
445	};
446
447	window.wanderic_replicate = function(str, num) {
448		var rez = '';
449		for (var i = 0; i < num; i++) {
450			rez += str;
451		}
452		return rez;
453	};
454
455	window.wanderic_prepare_macros = function(str) {
456		return str
457			.replace( /\{\{/g, "<i>" )
458			.replace( /\}\}/g, "</i>" )
459			.replace( /\(\(/g, "<b>" )
460			.replace( /\)\)/g, "</b>" )
461			.replace( /\|\|/g, "<br>" );
462	};
463
464	/* Numbers functions
465	---------------------------------------------------------------- */
466
467	// Round number to specified precision.
468	// For example: num=1.12345, prec=2,  rounded=1.12
469	//              num=12345,   prec=-2, rounded=12300
470	window.wanderic_round_number = function(num) {
471		var precision = arguments[1] !== undefined ? arguments[1] : 0;
472		var p         = Math.pow( 10, precision );
473		return Math.round( num * p ) / p;
474	};
475
476	// Clear number from any characters and append it with 0 to desired precision
477	// For example: num=test1.12dd, prec=3, cleared=1.120
478	window.wanderic_clear_number = function(num) {
479		var precision = arguments[1] !== undefined ? arguments[1] : 0;
480		var defa      = arguments[2] !== undefined ? arguments[2] : 0;
481		var res       = '';
482		var decimals  = -1;
483		num           = "" + num;
484		if (num == "") {
485			num = "" + defa;
486		}
487		for (var i = 0; i < num.length; i++) {
488			if (decimals == 0) {
489				break;
490			} else if (decimals > 0) {
491				decimals--;
492			}
493			var ch = num.substr( i,1 );
494			if (ch == '.') {
495				if (precision > 0) {
496					res += ch;
497				}
498				decimals = precision;
499			} else if ((ch >= 0 && ch <= 9) || (ch == '-' && i == 0)) {
500				res += ch;
501			}
502		}
503		if (precision > 0 && decimals != 0) {
504			if (decimals == -1) {
505				res     += '.';
506				decimals = precision;
507			}
508			for (i = decimals; i > 0; i--) {
509				res += '0';
510			}
511		}
512		//if (isNaN(res)) res = clearNumber(defa, precision, defa);
513		return res;
514	};
515
516	// Convert number from decimal to hex
517	window.wanderic_dec2hex = function(n) {
518		return Number( n ).toString( 16 );
519	};
520
521	// Convert number from hex to decimal
522	window.wanderic_hex2dec = function(hex) {
523		return parseInt( hex,16 );
524	};
525
526	/* Array manipulations
527	---------------------------------------------------------------- */
528
529	window.wanderic_in_array = function(val, thearray)  {
530		var rez = false;
531		for (var i = 0; i < thearray.length - 1; i++) {
532			if (thearray[i] == val) {
533				rez = true;
534				break;
535			}
536		}
537		return rez;
538	};
539
540	window.wanderic_sort_array = function(thearray)  {
541		var caseSensitive = arguments[1] !== undefined ? arguments[1] : false;
542		var tmp           = '';
543		for (var x = 0; x < thearray.length - 1; x++) {
544			for (var y = (x + 1); y < thearray.length; y++) {
545				if (caseSensitive) {
546					if (thearray[x] > thearray[y]) {
547						tmp         = thearray[x];
548						thearray[x] = thearray[y];
549						thearray[y] = tmp;
550					}
551				} else {
552					if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) {
553						tmp         = thearray[x];
554						thearray[x] = thearray[y];
555						thearray[y] = tmp;
556					}
557				}
558			}
559		}
560		return thearray;
561	};
562
563	/* Date manipulations
564	---------------------------------------------------------------- */
565
566	// Return array[Year, Month, Day, Hours, Minutes, Seconds]
567	// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
568	window.wanderic_parse_date = function(dt) {
569		dt      = dt.replace( /\//g, '-' ).replace( /\./g, '-' ).replace( /T/g, ' ' ).split( '+' )[0];
570		var dt2 = dt.split( ' ' );
571		var d   = dt2[0].split( '-' );
572		var t   = dt2[1].split( ':' );
573		d.push( t[0], t[1], t[2] );
574		return d;
575	};
576
577	// Return difference string between two dates
578	window.wanderic_get_date_difference = function(dt1) {
579		var dt2        = arguments[1] !== undefined ? arguments[1] : '';
580		var short_date = arguments[2] !== undefined ? arguments[2] : true;
581		var sec        = arguments[3] !== undefined ? arguments[3] : false;
582		var a1         = wanderic_parse_date( dt1 );
583		dt1            = Date.UTC( a1[0], a1[1], a1[2], a1[3], a1[4], a1[5] );
584		if (dt2 == '') {
585			dt2    = new Date();
586			var a2 = [dt2.getFullYear(), dt2.getMonth() + 1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
587		} else {
588			var a2 = wanderic_parse_date( dt2 );
589		}
590		dt2         = Date.UTC( a2[0], a2[1], a2[2], a2[3], a2[4], a2[5] );
591		var diff    = Math.round( (dt2 - dt1) / 1000 );
592		var days    = Math.floor( diff / (24 * 3600) );
593		diff       -= days * 24 * 3600;
594		var hours   = Math.floor( diff / 3600 );
595		diff       -= hours * 3600;
596		var minutes = Math.floor( diff / 60 );
597		diff       -= minutes * 60;
598		var rez     = '';
599		if (days > 0) {
600			rez += (rez !== '' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
601		}
602		if (( ! short_date || rez == '') && hours > 0) {
603			rez += (rez !== '' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
604		}
605		if (( ! short_date || rez == '') && minutes > 0) {
606			rez += (rez !== '' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
607		}
608		if (sec || rez == '') {
609			rez += rez !== '' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
610		}
611		return rez;
612	};
613
614	/* Colors functions
615	---------------------------------------------------------------- */
616
617	window.wanderic_hex2rgb = function(hex) {
618		hex = parseInt( ((hex.indexOf( '#' ) > -1) ? hex.substring( 1 ) : hex), 16 );
619		return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
620	};
621
622	window.wanderic_hex2rgba = function(hex, alpha) {
623		var rgb = wanderic_hex2rgb( hex );
624		return 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + alpha + ')';
625	};
626
627	window.wanderic_rgb2hex = function(color) {
628		var aRGB;
629		color = color.replace( /\s/g,"" ).toLowerCase();
630		if (color == 'rgba(0,0,0,0)' || color == 'rgba(0%,0%,0%,0%)') {
631			color = 'transparent';
632		}
633		if (color.indexOf( 'rgba(' ) == 0) {
634			aRGB = color.match( /^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i );
635		} else {
636			aRGB = color.match( /^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i );
637		}
638
639		if (aRGB) {
640			color = '';
641			for (var i = 1; i <= 3; i++) {
642				color += Math.round( (aRGB[i][aRGB[i].length - 1] == "%" ? 2.55 : 1) * parseInt( aRGB[i] ) ).toString( 16 ).replace( /^(.)$/,'0$1' );
643			}
644		} else {
645			color = color.replace( /^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3' );
646		}
647		return (color.substr( 0,1 ) != '#' ? '#' : '') + color;
648	};
649
650	window.wanderic_components2hex = function(r,g,b) {
651		return '#' +
652			Number( r ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' ) +
653			Number( g ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' ) +
654			Number( b ).toString( 16 ).toUpperCase().replace( /^(.)$/,'0$1' );
655	};
656
657	window.wanderic_rgb2components = function(color) {
658		color       = wanderic_rgb2hex( color );
659		var matches = color.match( /^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i );
660		if ( ! matches) {
661			return false;
662		}
663		for (var i = 1, rgb = new Array( 3 ); i <= 3; i++) {
664			rgb[i - 1] = parseInt( matches[i],16 );
665		}
666		return rgb;
667	};
668
669	window.wanderic_hex2hsb = function(hex) {
670		var h   = arguments[1] !== undefined ? arguments[1] : 0;
671		var s   = arguments[2] !== undefined ? arguments[2] : 0;
672		var b   = arguments[3] !== undefined ? arguments[3] : 0;
673		var hsb = wanderic_rgb2hsb( wanderic_hex2rgb( hex ) );
674		hsb.h   = Math.min( 359, Math.max( 0, hsb.h + h ) );
675		hsb.s   = Math.min( 100, Math.max( 0, hsb.s + s ) );
676		hsb.b   = Math.min( 100, Math.max( 0, hsb.b + b ) );
677		return hsb;
678	};
679
680	window.wanderic_hsb2hex = function(hsb) {
681		var rgb = wanderic_hsb2rgb( hsb );
682		return wanderic_components2hex( rgb.r, rgb.g, rgb.b );
683	};
684
685	window.wanderic_rgb2hsb = function(rgb) {
686		var hsb = {};
687		hsb.b   = Math.max( Math.max( rgb.r,rgb.g ),rgb.b );
688		hsb.s   = (hsb.b <= 0) ? 0 : Math.round( 100 * (hsb.b - Math.min( Math.min( rgb.r,rgb.g ),rgb.b )) / hsb.b );
689		hsb.b   = Math.round( (hsb.b / 255) * 100 );
690		if ((rgb.r == rgb.g) && (rgb.g == rgb.b)) {
691			hsb.h = 0;
692		} else if (rgb.r >= rgb.g && rgb.g >= rgb.b) {
693			hsb.h = 60 * (rgb.g - rgb.b) / (rgb.r - rgb.b);
694		} else if (rgb.g >= rgb.r && rgb.r >= rgb.b) {
695			hsb.h = 60 + 60 * (rgb.g - rgb.r) / (rgb.g - rgb.b);
696		} else if (rgb.g >= rgb.b && rgb.b >= rgb.r) {
697			hsb.h = 120 + 60 * (rgb.b - rgb.r) / (rgb.g - rgb.r);
698		} else if (rgb.b >= rgb.g && rgb.g >= rgb.r) {
699			hsb.h = 180 + 60 * (rgb.b - rgb.g) / (rgb.b - rgb.r);
700		} else if (rgb.b >= rgb.r && rgb.r >= rgb.g) {
701			hsb.h = 240 + 60 * (rgb.r - rgb.g) / (rgb.b - rgb.g);
702		} else if (rgb.r >= rgb.b && rgb.b >= rgb.g) {
703			hsb.h = 300 + 60 * (rgb.r - rgb.b) / (rgb.r - rgb.g);
704		} else {
705			hsb.h = 0;
706		}
707		hsb.h = Math.round( hsb.h );
708		return hsb;
709	};
710
711	window.wanderic_hsb2rgb = function(hsb) {
712		var rgb = {};
713		var h   = Math.round( hsb.h );
714		var s   = Math.round( hsb.s * 255 / 100 );
715		var v   = Math.round( hsb.b * 255 / 100 );
716		if (s == 0) {
717			rgb.r = rgb.g = rgb.b = v;
718		} else {
719			var t1 = v;
720			var t2 = (255 - s) * v / 255;
721			var t3 = (t1 - t2) * (h % 60) / 60;
722			if (h == 360) {
723				h = 0;
724			}
725			if (h < 60) {
726				rgb.r = t1;	rgb.b = t2;   rgb.g = t2 + t3; } else if (h < 120) {
727				rgb.g = t1; rgb.b = t2;	rgb.r = t1 - t3; } else if (h < 180) {
728					rgb.g = t1; rgb.r = t2;	rgb.b = t2 + t3; } else if (h < 240) {
729					rgb.b = t1; rgb.r = t2;	rgb.g = t1 - t3; } else if (h < 300) {
730							rgb.b = t1; rgb.g = t2;	rgb.r = t2 + t3; } else if (h < 360) {
731							rgb.r = t1; rgb.g = t2;	rgb.b = t1 - t3; } else {
732								rgb.r = 0;  rgb.g = 0;	rgb.b = 0;	 }
733		}
734		return { r:Math.round( rgb.r ), g:Math.round( rgb.g ), b:Math.round( rgb.b ) };
735	};
736
737	window.wanderic_color_picker = function(){
738		var id         = arguments[0] !== undefined ? arguments[0] : "iColorPicker" + Math.round( Math.random() * 1000 );
739		var colors     = arguments[1] !== undefined ? arguments[1] :
740		'#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
741		+ '#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
742		+ '#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
743		+ '#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
744		+ '#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
745		+ '#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
746		+ '#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
747		var colorsList = colors.split( ',' );
748		var tbl        = '<table class="colorPickerTable"><thead>';
749		for (var i = 0; i < colorsList.length; i++) {
750			if (i % 16 == 0) {
751				tbl += (i > 0 ? '</tr>' : '') + '<tr>';
752			}
753			tbl += '<td style="background-color:' + colorsList[i] + '">&nbsp;</td>';
754		}
755		tbl += '</tr></thead><tbody>'
756			+ '<tr style="height:60px;">'
757			+ '<td colspan="8" id="' + id + '_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
758			+ '<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" />'
759			+ '<a href="#" id="' + id + '_moreColors" class="iColorPicker_moreColors"></a>'
760			+ '</td>'
761			+ '<td colspan="8" id="' + id + '_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
762			+ '<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" />'
763			+ '</td>'
764			+ '</tr></tbody></table>';
765
766		jQuery( document.createElement( "div" ) )
767			.attr( "id", id )
768			.css( 'display','none' )
769			.html( tbl )
770			.appendTo( "body" )
771			.addClass( "iColorPickerTable" )
772			.on( 'mouseover', 'thead td', function(){
773					var aaa = wanderic_rgb2hex( jQuery( this ).css( 'background-color' ) );
774					jQuery( '#' + id + '_colorPreview' ).css( 'background',aaa );
775					jQuery( '#' + id + '_colorPreview input' ).val( aaa );
776				}
777			)
778			.on( 'keypress', '#' + id + '_colorPreview input', function(key){
779					var aaa = jQuery( this ).val();
780					if (aaa.length < 7 && ((key.which >= 48 && key.which <= 57) || (key.which >= 97 && key.which <= 102) || (key.which === 35 || aaa.length === 0))) {
781						aaa += String.fromCharCode( key.which );
782					} else if (key.which == 8 && aaa.length > 0) {
783						aaa = aaa.substring( 0, aaa.length - 1 );
784					} else if (key.which === 13 && (aaa.length === 4 || aaa.length === 7)) {
785						var fld  = jQuery( '#' + id ).data( 'field' );
786						var func = jQuery( '#' + id ).data( 'func' );
787						if (func !== null && func != 'undefined') {
788							func( fld, aaa );
789						} else {
790							fld.val( aaa ).css( 'backgroundColor', aaa ).trigger( 'change' );
791						}
792						jQuery( '#' + id + '_Bg' ).fadeOut( 500 );
793						jQuery( '#' + id ).fadeOut( 500 );
794
795					} else {
796						key.preventDefault();
797						return false;
798					}
799					if (aaa.substr( 0,1 ) === '#' && (aaa.length === 4 || aaa.length === 7)) {
800						jQuery( '#' + id + '_colorPreview' ).css( 'background',aaa );
801					}
802					return true;
803				}
804			)
805			.on( 'click', 'thead td', function(e){
806					var fld  = jQuery( '#' + id ).data( 'field' );
807					var func = jQuery( '#' + id ).data( 'func' );
808					var aaa  = wanderic_rgb2hex( jQuery( this ).css( 'background-color' ) );
809					if (func !== null && func != 'undefined') {
810						func( fld, aaa );
811					} else {
812						fld.val( aaa ).css( 'backgroundColor', aaa ).trigger( 'change' );
813					}
814					jQuery( '#' + id + '_Bg' ).fadeOut( 500 );
815					jQuery( '#' + id ).fadeOut( 500 );
816					e.preventDefault();
817					return false;
818				}
819			)
820			.on( 'click', 'tbody .iColorPicker_moreColors', function(e){
821					var thead = jQuery( this ).parents( 'table' ).find( 'thead' );
822					var out   = '';
823					if (thead.hasClass( 'more_colors' )) {
824						for (var i = 0; i < colorsList.length; i++) {
825							if (i % 16 == 0) {
826								out += (i > 0 ? '</tr>' : '') + '<tr>';
827							}
828							out += '<td style="background-color:' + colorsList[i] + '">&nbsp;</td>';
829						}
830						thead.removeClass( 'more_colors' ).empty().html( out + '</tr>' );
831						jQuery( '#' + id + '_colorPreview' ).attr( 'colspan', 8 );
832						jQuery( '#' + id + '_colorOriginal' ).attr( 'colspan', 8 );
833					} else {
834						var rgb = [0,0,0], i = 0, j = -1;	// Set j=-1 or j=0 - show 2 different colors layouts
835						while (rgb[0] < 0xF || rgb[1] < 0xF || rgb[2] < 0xF) {
836							if (i % 18 === 0) {
837								out += (i > 0 ? '</tr>' : '') + '<tr>';
838							}
839							i++;
840							out    += '<td style="background-color:' + wanderic_components2hex( rgb[0] * 16 + rgb[0],rgb[1] * 16 + rgb[1],rgb[2] * 16 + rgb[2] ) + '">&nbsp;</td>';
841							rgb[2] += 3;
842							if (rgb[2] > 0xF) {
843								rgb[1] += 3;
844								if (rgb[1] > (j === 0 ? 6 : 0xF)) {
845									rgb[0] += 3;
846									if (rgb[0] > 0xF) {
847										if (j === 0) {
848											j      = 1;
849											rgb[0] = 0;
850											rgb[1] = 9;
851											rgb[2] = 0;
852										} else {
853											break;
854										}
855									} else {
856										rgb[1] = (j < 1 ? 0 : 9);
857										rgb[2] = 0;
858									}
859								} else {
860									rgb[2] = 0;
861								}
862							}
863						}
864						thead.addClass( 'more_colors' ).empty().html( out + '<td  style="background-color:#ffffff" colspan="8">&nbsp;</td></tr>' );
865						jQuery( '#' + id + '_colorPreview' ).attr( 'colspan', 9 );
866						jQuery( '#' + id + '_colorOriginal' ).attr( 'colspan', 9 );
867					}
868					jQuery( '#' + id + ' table.colorPickerTable thead td' )
869					.css(
870						{
871							'width':'12px',
872							'height':'14px',
873							'border':'1px solid #000',
874							'cursor':'pointer'
875						}
876					);
877					e.preventDefault();
878					return false;
879				}
880			);
881		jQuery( document.createElement( "div" ) )
882			.attr( "id", id + "_Bg" )
883			.on( 'click', function(e) {
884					jQuery( "#" + id + "_Bg" ).fadeOut( 500 );
885					jQuery( "#" + id ).fadeOut( 500 );
886					e.preventDefault();
887					return false;
888				}
889			)
890			.appendTo( "body" );
891		jQuery( '#' + id + ' table.colorPickerTable thead td' )
892			.css(
893				{
894					'width':'12px',
895					'height':'14px',
896					'border':'1px solid #000',
897					'cursor':'pointer'
898				}
899			);
900		jQuery( '#' + id + ' table.colorPickerTable' )
901			.css( {'border-collapse':'collapse'} );
902		jQuery( '#' + id )
903			.css(
904				{
905					'border':'1px solid #ccc',
906					'background':'#333',
907					'padding':'5px',
908					'color':'#fff'
909				}
910			);
911		jQuery( '#' + id + '_colorPreview' )
912			.css( {'height':'50px'} );
913		return id;
914	};
915
916	window.wanderic_color_picker_show = function(id, fld, func) {
917		if (id === null || id === '') {
918			id = jQuery( '.iColorPickerTable' ).attr( 'id' );
919		}
920		var eICP = fld.offset();
921		var w    = jQuery( '#' + id ).width();
922		var h    = jQuery( '#' + id ).height();
923		var l    = eICP.left + w < jQuery( window ).width() - 10 ? eICP.left : jQuery( window ).width() - 10 - w;
924		var t    = eICP.top + fld.outerHeight() + h < jQuery( document ).scrollTop() + jQuery( window ).height() - 10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13;
925		jQuery( "#" + id )
926			.data( {field: fld, func: func} )
927			.css(
928				{
929					'top':t + "px",
930					'left':l + "px",
931					'position':'absolute',
932					'z-index':999999
933				}
934			)
935			.fadeIn( 500 );
936		jQuery( "#" + id + "_Bg" )
937			.css(
938				{
939					'position':'fixed',
940					'z-index':999998,
941					'top':0,
942					'left':0,
943					'width':'100%',
944					'height':'100%'
945				}
946			)
947			.fadeIn( 500 );
948		var def = fld.val().substr( 0, 1 ) == '#' ? fld.val() : wanderic_rgb2hex( fld.css( 'backgroundColor' ) );
949		jQuery( '#' + id + '_colorPreview input,#' + id + '_colorOriginal input' ).val( def );
950		jQuery( '#' + id + '_colorPreview,#' + id + '_colorOriginal' ).css( 'background',def );
951	};
952
953	/* Cookies manipulations
954	---------------------------------------------------------------- */
955
956	window.wanderic_get_cookie = function(name) {
957		var defa  = arguments[1] !== undefined ? arguments[1] : null;
958		var start = document.cookie.indexOf( name + '=' );
959		var len   = start + name.length + 1;
960		if (( ! start) && (name != document.cookie.substring( 0, name.length ))) {
961			return defa;
962		}
963		if (start == -1) {
964			return defa;
965		}
966		var end = document.cookie.indexOf( ';', len );
967		if (end == -1) {
968			end = document.cookie.length;
969		}
970		return unescape( document.cookie.substring( len, end ) );
971	};
972
973	window.wanderic_set_cookie = function(name, value) {
974		var expires = arguments[2] !== undefined ? arguments[2] : 0;
975		var path    = arguments[3] !== undefined ? arguments[3] : '/';
976		var domain  = arguments[4] !== undefined ? arguments[4] : '';
977		var secure  = arguments[5] !== undefined ? arguments[5] : '';
978		var today   = new Date();
979		today.setTime( today.getTime() );
980		var expires_date = new Date( today.getTime() + (expires * 1) );
981		document.cookie  = name + '='
982				+ escape( value )
983				+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
984				+ ((path) ? ';path=' + path : '')
985				+ ((domain) ? ';domain=' + domain : '')
986				+ ((secure) ? ';secure' : '');
987	};
988
989	window.wanderic_del_cookie = function(name) {
990		var path   = arguments[1] !== undefined ? arguments[1] : '/';
991		var domain = arguments[2] !== undefined ? arguments[2] : '';
992		if (wanderic_get_cookie( name )) {
993			document.cookie = name + '=' + ((path) ? ';path=' + path : '')
994					+ ((domain) ? ';domain=' + domain : '')
995					+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
996		}
997	};
998
999	/* Local storage manipulations
1000	---------------------------------------------------------------- */
1001
1002	window.wanderic_is_local_storage_exists = function() {
1003		try {
1004			return 'localStorage' in window && window['localStorage'] !== null;
1005		} catch (e) {
1006			return false;
1007		}		
1008	};
1009	
1010	window.wanderic_get_storage = function(name) {
1011		var defa = arguments[1] !== undefined ? arguments[1] : null;
1012		var val = null;
1013		if (wanderic_is_local_storage_exists()) {
1014			val = window['localStorage'].getItem(name);
1015			if (val === null) val = defa;
1016		} else {
1017			val = wanderic_get_cookie(name, defa);
1018		}
1019		return val;
1020	};
1021	
1022	window.wanderic_set_storage = function(name, value) {
1023		if (wanderic_is_local_storage_exists())
1024			window['localStorage'].setItem(name, value);
1025		else 
1026			wanderic_set_cookie(name, value, 365 * 24 * 60 * 60 * 1000);   // 1 year
1027	};
1028	
1029	window.wanderic_del_storage = function(name) {
1030		if (wanderic_is_local_storage_exists())
1031			window['localStorage'].removeItem(name);
1032		else 
1033			wanderic_del_cookie(name);
1034	};
1035	
1036	window.wanderic_clear_storage = function() {
1037		if (wanderic_is_local_storage_exists())
1038			window['localStorage'].clear();
1039	};
1040
1041	/* ListBox and ComboBox manipulations
1042	---------------------------------------------------------------- */
1043
1044	window.wanderic_clear_listbox = function(box) {
1045		for (var i = box.options.length - 1; i >= 0; i--) {
1046			box.options[i] = null;
1047		}
1048	};
1049
1050	window.wanderic_add_listbox_item = function(box, val, text) {
1051		var item   = new Option();
1052		item.value = val;
1053		item.text  = text;
1054		box.options.add( item );
1055	};
1056
1057	window.wanderic_del_listbox_item_by_value = function(box, val) {
1058		for (var i = 0; i < box.options.length; i++) {
1059			if (box.options[i].value == val) {
1060				box.options[i] = null;
1061				break;
1062			}
1063		}
1064	};
1065
1066	window.wanderic_del_listbox_item_by_text = function(box, txt) {
1067		for (var i = 0; i < box.options.length; i++) {
1068			if (box.options[i].text == txt) {
1069				box.options[i] = null;
1070				break;
1071			}
1072		}
1073	};
1074
1075	window.wanderic_find_listbox_item_by_value = function(box, val) {
1076		var idx = -1;
1077		for (var i = 0; i < box.options.length; i++) {
1078			if (box.options[i].value == val) {
1079				idx = i;
1080				break;
1081			}
1082		}
1083		return idx;
1084	};
1085
1086	window.wanderic_find_listbox_item_by_text = function(box, txt) {
1087		var idx = -1;
1088		for (var i = 0; i < box.options.length; i++) {
1089			if (box.options[i].text == txt) {
1090				idx = i;
1091				break;
1092			}
1093		}
1094		return idx;
1095	};
1096
1097	window.wanderic_select_listbox_item_by_value = function(box, val) {
1098		for (var i = 0; i < box.options.length; i++) {
1099			box.options[i].selected = (val == box.options[i].value);
1100		}
1101	};
1102
1103	window.wanderic_select_listbox_item_by_text = function(box, txt) {
1104		for (var i = 0; i < box.options.length; i++) {
1105			box.options[i].selected = (txt == box.options[i].text);
1106		}
1107	};
1108
1109	window.wanderic_get_listbox_values = function(box) {
1110		var delim = arguments[1] !== undefined ? arguments[1] : ',';
1111		var str   = '';
1112		for (var i = 0; i < box.options.length; i++) {
1113			str += (str ? delim : '') + box.options[i].value;
1114		}
1115		return str;
1116	};
1117
1118	window.wanderic_get_listbox_texts = function(box) {
1119		var delim = arguments[1] !== undefined ? arguments[1] : ',';
1120		var str   = '';
1121		for (var i = 0; i < box.options.length; i++) {
1122			str += (str ? delim : '') + box.options[i].text;
1123		}
1124		return str;
1125	};
1126
1127	window.wanderic_sort_listbox = function(box)  {
1128		var temp_opts = new Array(),
1129			temp      = new Option(),
1130			i, x, y;
1131		for (i = 0; i < box.options.length; i++) {
1132			temp_opts[i] = box.options[i].clone();
1133		}
1134		for (x = 0; x < temp_opts.length - 1; x++) {
1135			for (y = (x + 1); y < temp_opts.length; y++) {
1136				if (temp_opts[x].text > temp_opts[y].text) {
1137					temp         = temp_opts[x];
1138					temp_opts[x] = temp_opts[y];
1139					temp_opts[y] = temp;
1140				}
1141			}
1142		}
1143		for (i = 0; i < box.options.length; i++) {
1144			box.options[i] = temp_opts[i].clone();
1145		}
1146	};
1147
1148	window.wanderic_get_listbox_selected_index = function(box) {
1149		for (var i = 0; i < box.options.length; i++) {
1150			if (box.options[i].selected) {
1151				return i;
1152			}
1153		}
1154		return -1;
1155	};
1156
1157	window.wanderic_get_listbox_selected_value = function(box) {
1158		for (var i = 0; i < box.options.length; i++) {
1159			if (box.options[i].selected) {
1160				return box.options[i].value;
1161			}
1162		}
1163		return null;
1164	};
1165
1166	window.wanderic_get_listbox_selected_text = function(box) {
1167		for (var i = 0; i < box.options.length; i++) {
1168			if (box.options[i].selected) {
1169				return box.options[i].text;
1170			}
1171		}
1172		return null;
1173	};
1174
1175	window.wanderic_get_listbox_selected_option = function(box) {
1176		for (var i = 0; i < box.options.length; i++) {
1177			if (box.options[i].selected) {
1178				return box.options[i];
1179			}
1180		}
1181		return null;
1182	};
1183
1184	/* Radio buttons manipulations
1185	---------------------------------------------------------------- */
1186
1187	window.wanderic_get_radio_value = function(radioGroupObj) {
1188		for (var i = 0; i < radioGroupObj.length; i++) {
1189			if (radioGroupObj[i].checked) {
1190				return radioGroupObj[i].value;
1191			}
1192		}
1193		return null;
1194	};
1195
1196	window.wanderic_set_radio_checked_by_num = function(radioGroupObj, num) {
1197		for (var i = 0; i < radioGroupObj.length; i++) {
1198			if (radioGroupObj[i].checked && i != num) {
1199				radioGroupObj[i].checked = false;
1200			} else if (i == num) {
1201				radioGroupObj[i].checked = true;
1202			}
1203		}
1204	};
1205
1206	window.wanderic_set_radio_checked_by_value = function(radioGroupObj, val) {
1207		for (var i = 0; i < radioGroupObj.length; i++) {
1208			if (radioGroupObj[i].checked && radioGroupObj[i].value != val) {
1209				radioGroupObj[i].checked = false;
1210			} else if (radioGroupObj[i].value == val) {
1211				radioGroupObj[i].checked = true;
1212			}
1213		}
1214	};
1215
1216	/* Form manipulations
1217	---------------------------------------------------------------- */
1218
1219	/*
1220	// Usage example:
1221	var error = wanderic_form_validate(jQuery(form_selector), {		// -------- Options ---------
1222		error_message_show: true,									// Display or not error message
1223		error_message_time: 5000,									// Time to display error message
1224		error_message_class: 'message_box message_box_error',		// Class, appended to error message block
1225		error_message_text: 'Global error text',					// Global error message text (if don't write message in checked field)
1226		error_fields_class: 'error_field',							// Class, appended to error fields
1227		exit_after_first_error: false,								// Cancel validation and exit after first error
1228		rules: [
1229			{
1230				field: 'author',																// Checking field name
1231				min_length: { value: 1,	 message: 'The author name can\'t be empty' },			// Min character count (0 - don't check), message - if error occurs
1232				max_length: { value: 60, message: 'Too long author name'}						// Max character count (0 - don't check), message - if error occurs
1233			},
1234			{
1235				field: 'email',
1236				min_length: { value: 7,	 message: 'Too short (or empty) email address' },
1237				max_length: { value: 60, message: 'Too long email address'},
1238				mask: { value: '^([a-zA-Z0-9_\\-]+\\.)*[a-zA-Z0-9_\\-]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*\\.[a-zA-Z]{2,6}$', message: 'Invalid email address'}
1239			},
1240			{
1241				field: 'comment',
1242				min_length: { value: 1,	 message: 'The comment text can\'t be empty' },
1243				max_length: { value: 200, message: 'Too long comment'}
1244			},
1245			{
1246				field: 'pwd1',
1247				min_length: { value: 5,	 message: 'The password can\'t be less then 5 characters' },
1248				max_length: { value: 20, message: 'Too long password'}
1249			},
1250			{
1251				field: 'pwd2',
1252				equal_to: { value: 'pwd1',	 message: 'The passwords in both fields must be equals' }
1253			}
1254		]
1255	});
1256	*/
1257
1258	window.wanderic_form_validate = function(form, opt) {
1259		var error_msg = '';
1260		form.find( ":input" ).each(
1261			function() {
1262				if (error_msg !== '' && opt.exit_after_first_error) {
1263					return;
1264				}
1265				for (var i = 0; i < opt.rules.length; i++) {
1266					if (jQuery( this ).attr( "name" ) == opt.rules[i].field) {
1267						var val   = jQuery( this ).val();
1268						var error = false;
1269						if (typeof(opt.rules[i].min_length) == 'object') {
1270							if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
1271								if (error_msg == '') {
1272									jQuery( this ).get( 0 ).focus();
1273								}
1274								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>';
1275								error      = true;
1276							}
1277						}
1278						if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
1279							if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
1280								if (error_msg == '') {
1281									jQuery( this ).get( 0 ).focus();
1282								}
1283								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>';
1284								error      = true;
1285							}
1286						}
1287						if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
1288							if (opt.rules[i].mask.value !== '') {
1289								var regexp = new RegExp( opt.rules[i].mask.value );
1290								if ( ! regexp.test( val )) {
1291									if (error_msg == '') {
1292										jQuery( this ).get( 0 ).focus();
1293									}
1294									error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message) != 'undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>';
1295									error      = true;
1296								}
1297							}
1298						}
1299						if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') {
1300							if (opt.rules[i].state.value == 'checked' && ! jQuery( this ).get( 0 ).
1300checked) {
1301								if (error_msg == '') {
1302									jQuery( this ).get( 0 ).focus();
1303								}
1304								error_msg += '<p class="error_item">' + (typeof(opt.rules[i].state.message) != 'undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>';
1305								error      = true;
1306							}
1307						}
1308						if (( ! error || ! opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
1309							if (opt.rules[i].equal_to.value !== '' && val != jQuery( jQuery( this ).get( 0 ).form[opt.rules[i].equal_to.value] ).val()) {
1310								if (error_msg == '') {
1311									jQuery( this ).get( 0 ).focus();
1312								}
1313								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>';
1314								error      = true;
1315							}
1316						}
1317						if (opt.error_fields_class !== '') {
1318							jQuery( this ).toggleClass( opt.error_fields_class, error );
1319						}
1320					}
1321				}
1322			}
1323		);
1324		if (error_msg !== '' && opt.error_message_show) {
1325			var error_message_box = form.find( ".result" );
1326			if (error_message_box.length == 0) {
1327				error_message_box = form.parent().find( ".result" );
1328			}
1329			if (error_message_box.length == 0) {
1330				form.append( '<div class="result"></div>' );
1331				error_message_box = form.find( ".result" );
1332			}
1333			if (opt.error_message_class) {
1334				error_message_box.toggleClass( opt.error_message_class, true );
1335			}
1336			error_message_box.html( error_msg ).fadeIn();
1337			setTimeout( function() { error_message_box.fadeOut(); }, opt.error_message_time );
1338		}
1339		return error_msg !== '';
1340	};
1341
1342	/* Document manipulations
1343	---------------------------------------------------------------- */
1344
1345	// Animated scroll to selected id
1346	window.wanderic_document_animate_to = function(id) {
1347		var speed    = arguments.length > 1 ? arguments[1] : -1;
1348		var callback = arguments.length > 2 ? arguments[2] : undefined;
1349		var oft = ! isNaN( id ) ? Number( id ) : 0,
1350			oft2 = -1;
1351		if (isNaN( id )) {
1352			if (id.indexOf( '#' ) == -1) {
1353				id = '#' + id;
1354			}
1355			var obj = jQuery( id ).eq( 0 );
1356			if (obj.length == 0) {
1357				return;
1358			}
1359			oft = obj.offset().top;
1360			oft2  = Math.max( 0, oft - wanderic_fixed_rows_height() );
1361		}
1362		if (speed < 0) {
1363			speed = Math.min( 1000, Math.max( 300, Math.round( Math.abs( ( oft2 < 0 ? oft : oft2 ) - jQuery( window ).scrollTop() ) / jQuery( window ).height() * 300 ) ) );
1364		}
1365		if (oft2 >= 0) {
1366			setTimeout(
1367				function() {
1368					if (isNaN( id )) {
1369						oft = obj.offset().top;
1370					}
1371					oft2 = Math.max( 0, oft - wanderic_fixed_rows_height() );
1372					jQuery( 'body,html' ).stop( true ).animate( {scrollTop: oft2}, Math.floor( speed / 2 ), 'linear', callback );
1373				}, Math.floor( speed / 2 )
1374			);
1375		} else {
1376			oft2 = oft;
1377		}
1378		if ( speed > 0 ) {
1379			jQuery( 'body,html' ).stop( true ).animate( {scrollTop: oft2}, speed, 'linear', callback );
1380		} else {
1381			jQuery( 'body,html' ).stop( true ).scrollTop( oft2 );
1382			if ( callback ) {
1383				callback( id, speed );
1384			}
1385		}
1386	};
1387
1388	// Detect fixed rows height
1389	window.wanderic_fixed_rows_height = function() {
1390		var with_admin_bar  = arguments.length > 0 ? arguments[0] : true;
1391		var with_fixed_rows = arguments.length > 1 ? arguments[1] : true;
1392		var oft             = 0;
1393		// Admin bar height (if visible and fixed)
1394		if ( with_admin_bar ) {
1395			var admin_bar = jQuery( '#wpadminbar' );
1396			oft          += admin_bar.length > 0 && admin_bar.css( 'display' ) != 'none' && admin_bar.css( 'position' ) == 'fixed'
1397							? admin_bar.height()
1398							: 0;
1399		}
1400		// Fixed rows height
1401		if ( with_fixed_rows && ! jQuery( 'body' ).hasClass( 'hide_fixed_rows' ) ) {
1402			jQuery( '.sc_layouts_row_fixed_on' ).each(
1403				function() {
1404					if (jQuery( this ).css( 'position' ) == 'fixed') {
1405						oft += jQuery( this ).height();
1406					}
1407				}
1408			);
1409		}
1410		return oft;
1411	};
1412
1413	// Change browser address without reload page
1414	window.wanderic_document_set_location = function(curLoc){
1415		try {
1416			history.pushState( null, null, curLoc );
1417			return;
1418		} catch (e) {
1419		}
1420		location.href = curLoc;
1421	};
1422
1423	// Add/Change arguments to the url address
1424	window.wanderic_add_to_url = function(loc, prm) {
1425		var ignore_empty = arguments[2] !== undefined ? arguments[2] : true;
1426		var q            = loc.indexOf( '?' );
1427		var attr         = {};
1428		if (q > 0) {
1429			var qq    = loc.substr( q + 1 ).split( '&' );
1430			var parts = '';
1431			for (var i = 0; i < qq.length; i++) {
1432				var parts      = qq[i].split( '=' );
1433				attr[parts[0]] = parts.length > 1 ? parts[1] : '';
1434			}
1435		}
1436		for (var p in prm) {
1437			attr[p] = prm[p];
1438		}
1439		loc   = (q > 0 ? loc.substr( 0, q ) : loc) + '?';
1440		var i = 0;
1441		for (p in attr) {
1442			if (ignore_empty && attr[p] == '') {
1443				continue;
1444			}
1445			loc += (i++ > 0 ? '&' : '') + p + '=' + attr[p];
1446		}
1447		return loc;
1448	};
1449
1450	// Check if url is page-inner (local) link
1451	window.wanderic_is_local_link = function(url) {
1452		var rez = url !== undefined;
1453		if (rez) {
1454			var url_pos = url.indexOf( '#' );
1455			if (url_pos == 0 && url.length == 1) {
1456				rez = false;
1457			} else {
1458				if (url_pos < 0) {
1459					url_pos = url.length;
1460				}
1461				var loc     = window.location.href;
1462				var loc_pos = loc.indexOf( '#' );
1463				if (loc_pos > 0) {
1464					loc = loc.substring( 0, loc_pos );
1465				}
1466				rez = url_pos == 0;
1467				if ( ! rez) {
1468					rez = loc == url.substring( 0, url_pos );
1469				}
1470			}
1471		}
1472		return rez;
1473	};
1474
1475	/* Browsers detection
1476	---------------------------------------------------------------- */
1477
1478	window.wanderic_browser_is_mobile = function() {
1479		var check = false;
1480		(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 ) )) {
1481				check = true}
1482		})( navigator.userAgent || navigator.vendor || window.opera );
1483		return check;
1484	};
1485
1486	window.wanderic_browser_is_ios = function() {
1487		return navigator.userAgent.match( /iPad|iPhone|iPod/i ) != null;
1488	};
1489
1490	window.wanderic_is_retina = function() {
1491		var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)';
1492		return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia( mediaQuery ).matches);
1493	};
1494
1495	/* File functions
1496	---------------------------------------------------------------- */
1497
1498	window.wanderic_get_file_name = function(path) {
1499		path    = path.replace( /\\/g, '/' );
1500		var pos = path.lastIndexOf( '/' );
1501		if (pos >= 0) {
1502			path = path.substr( pos + 1 );
1503		}
1504		return path;
1505	};
1506
1507	window.wanderic_get_file_ext = function(path) {
1508		var pos = path.lastIndexOf( '.' );
1509		path    = pos >= 0 ? path.substr( pos + 1 ) : '';
1510		return path;
1511	};
1512
1513	/* Image functions
1514	---------------------------------------------------------------- */
1515
1516	// Return true, if all images in the specified container are loaded
1517	window.wanderic_is_images_loaded = function(cont) {
1518		var complete = true;
1519		cont.find( 'img' ).each(
1520			function() {
1521				// If any of previous images is not loaded - skip rest
1522				if ( ! complete) {
1523					return;
1524				}
1525				var img = jQuery( this ).get( 0 );
1526				if (typeof img.naturalWidth == 'number' && typeof img.naturalHeight == 'number') {
1527					// See if "naturalWidth" and "naturalHeight" properties are available
1528					complete = ! (this.naturalWidth == 0 && this.naturalHeight == 0);
1529				} else if (typeof img.complete == 'boolean') {
1530					// See if "complete" property is available
1531					complete = img.complete;
1532				}
1533			}
1534		);
1535		return complete;
1536	};
1537
1538	// Call function when all images in the specified container are loaded
1539	window.wanderic_when_images_loaded = function(cont, callback, max_delay) {
1540		if (max_delay === undefined) {
1541			var max_delay = 3000;
1542		}
1543		if (max_delay <= 0 || wanderic_is_images_loaded( cont )) {
1544			callback();
1545		} else {
1546			setTimeout(
1547				function(){
1548					wanderic_when_images_loaded( cont, callback, max_delay - 200 );
1549				}, 200
1550			);
1551		}
1552	};
1553
1554	/* Debug functions
1555	---------------------------------------------------------------- */
1556	window.wanderic_debug_object = function(obj) {
1557		var recursive   = arguments[1] ? arguments[1] : 0;			// Show inner objects (arrays) in depth
1558		var showMethods = arguments[2] ? arguments[2] : false;		// Show object's methods
1559		var level       = arguments[3] ? arguments[3] : 0;				// Nesting level (for internal usage only)
1560		var dispStr     = "";
1561		var addStr      = "";
1562		var curStr      = "";
1563		if (level > 0) {
1564			dispStr += (obj === null ? "null" : typeof(obj)) + "\n";
1565			addStr   = wanderic_replicate( ' ', level * 2 );
1566		}
1567		if (obj !== null && (typeof(obj) == 'object' || typeof(obj) == 'array')) {
1568			for (var prop in obj) {
1569				if ( ! showMethods && typeof(obj[prop]) == 'function') {	// || prop=='innerHTML' || prop=='outerHTML' || prop=='innerText' || prop=='outerText')
1570					continue;
1571				}
1572				if (level < recursive && (typeof(obj[prop]) == 'object' || typeof(obj[prop]) == 'array') && obj[prop] != obj) {
1573					dispStr += addStr + prop + '=' + wanderic_debug_object( obj[prop], recursive, showMethods, level 
1573+ 1 );
1574				} else {
1575					try {
1576						curStr = "" + obj[prop];
1577					} catch (e) {
1578						curStr = "--- Not evaluate ---";
1579					}
1580					dispStr += addStr + prop + '=' + (typeof(obj[prop]) == 'string' ? '"' : '') + curStr + (typeof(obj[prop]) == 'string' ? '"' : '') + "\n";
1581				}
1582			}
1583		} else if (typeof(obj) != 'function') {
1584			dispStr += addStr + (typeof(obj) == 'string' ? '"' : '') + obj + (typeof(obj) == 'string' ? '"' : '') + "\n";
1585		}
1586
1587		return dispStr;	//decodeURI(dispStr);
1588	};
1589
1590	window.wanderic_debug_log = function(s, clr) {
1591		if (WANDERIC_STORAGE['user_logged_in']) {
1592			if (jQuery( '#debug_log' ).length == 0) {
1593				jQuery( 'body' ).append( '<div id="debug_log"><span id="debug_log_close">x</span><pre id="debug_log_content"></pre></div>' );
1594				jQuery( "#debug_log_close" ).on(
1595					'click', function(e) {
1596						jQuery( '#debug_log' ).hide();
1597						e.preventDefault();
1598						return false;
1599					}
1600				);
1601			}
1602			if (clr) {
1603				jQuery( '#debug_log_content' ).empty();
1604			}
1605			jQuery( '#debug_log_content' ).prepend( s + ' ' );
1606			jQuery( '#debug_log' ).show();
1607		}
1608	};
1609
1610	window.dcl === undefined && (window.dcl = function(s) { console.log( s ); });
1611	window.dco === undefined && (window.dco = function(s,r) { console.log( wanderic_debug_object( s,r ) ); });
1612	window.dal === undefined && (window.dal = function(s) { if (WANDERIC_STORAGE['user_logged_in']) {
1613			alert( s );
1614	} });
1615	window.dao === undefined && (window.dao = function(s,r) { if (WANDERIC_STORAGE['user_logged_in']) {
1616			alert( wanderic_debug_object( s,r ) );
1617	} });
1618	window.ddl === undefined && (window.ddl = function(s,c) { wanderic_debug_log( s,c ); });
1619	window.ddo === undefined && (window.ddo = function(s,r,c) { wanderic_debug_log( wanderic_debug_object( s,r ),c ); });
1620
1621})();

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.