/*
Utility functions
969818
function findCanvas(canvasId) {	
	for (var i = 0; i < canvases.length; i++)
		if(canvases[i].id == canvasId)
			return canvases[i];
	return null;
}
896650
function (src, filter) {
    var out = {}, i;
    for (i=0; i<filter.length; i++) {
      if (src[filter[i]] !== undefined) {
        out[filter[i]] = src[filter[i]];
      }
    }
    return out;
  }
78142
function _fnConvertToWidth ( sWidth, nParent )
		{
			if ( !sWidth || sWidth === null || sWidth === '' )
			{
				return 0;
			}
			
			if ( !nParent )
			{
				nParent = document.getElementsByTagName('body')[0];
			}
			
			var iWidth;
			var nTmp = document.createElement( "div" );
			nTmp.style.width = _fnStringToCss( sWidth );
			
			nParent.appendChild( nTmp );
			iWidth = nTmp.offsetWidth;
			nParent.removeChild( nTmp );
			
			return ( iWidth );
		}
74851
function lazyVisitChildren(len, children, i, f, k) {
    while (i < len) {
        var child = children[i++];
        if (child && !isEmptyNode(child)) return lazyVisit(child, f, [len, children, i, f, k]);
    }
    return appk(k);
}
442192
function(array) {
    var firstNode = array.length - 2;
    var nextNode = array.length - 1;
    var currentDepth, availableNodes, lastNode, i;

    for (currentDepth = 1, availableNodes = 2;
         availableNodes > 0;
         currentDepth++) {
      lastNode = firstNode;
      firstNode = first (array, lastNode - 1, 0);

      for (i = availableNodes - (lastNode - firstNode); i > 0; i--) {
        array[nextNode--] = currentDepth;
      }

      availableNodes = (lastNode - firstNode) << 1;
    }
  }
152526
function(array, fn)
	{
		if (array != null && fn != null)
		{
			for (var i = 0; i < array.length; i++)
			{
				fn(array[i]);
			}
		}
		
		return array;
	}
873549
function sanicShift(array) {
    if (!(array instanceof Array)) {
        throw new TypeError('array is not an Array');
    }
    if (!array.length) {
        return undefined;
    }

    let oldElement = array[0];

    let i = 1;
    const iMax = array.length;

    for (; i < iMax; i++) {
        array[i-1] = array[i];
    }

    array.length--;

    return oldElement;
}
564365
function convertDiffToMessages(diff, actualOnly = false, includeTimeouts = false, timeout = undefined, comparisonLines = [], paths = []) {
    if (diff.tree && Object.keys(diff.tree).length > 0) {
        const keys = Object.keys(diff.tree);
        keys.forEach(key => {
            const _paths = [...paths];
            _paths.push(key);
            convertDiffToMessages(diff.tree[key], actualOnly, includeTimeouts, timeout, comparisonLines, _paths);
        });
    }
    else {
        let _paths = paths.join('');
        if (_paths.charAt(0) === '.') {
            _paths = _paths.substring(1);
        }
        const _actual = printValue(diff.actual);
        const _expected = printValue(diff.expected);
        let compareStr = '';
        if (actualOnly) {
            compareStr = (typeof diff.actual === 'undefined') ?
                '' : `{actual: <${_actual}>}\n`;
        }
        else {
            compareStr = (typeof diff.actual === 'undefined' && typeof diff.expected === 'undefined') ?
                '' : `{actual: <${_actual}>, expected: <${_expected}>}\n`;
        }
        const timeoutStr = (includeTimeouts) ? ` within ${timeout || diff.timeout}ms` : '';
        comparisonLines.push(`${diff.constructorName} at path '${_paths}'${timeoutStr}\n${compareStr}( ${diff.selector} )`);
    }
    return comparisonLines;
}
295314
function (applySwitchMargins) {
            var value;
            var binding = this._binding;
            if (!binding) {
                return;
            }

            value = binding.inside[binding.to];
            if (value == null) {
                value = 0;
            }
            if (value < 0) {
                value = 0;
            }
            if (value > 1) {
                value = 1;
            }
            if (this._isSwitch && applySwitchMargins) {
                if (value >= this._switchThreshold) {
                    value = 1;
                } else {
                    value = 0;
                }
            }
            this._value = value;
            this._storeValue();
        }
18680
function (data) {
            if (!data) {
                return;
            }

            return _.union.apply(null, _.map(_.values(data), _.keys));
        }
68053
function (item) {
        let x;
        switch (item.type) {
            case Type.STRING:
            case Type.NUMBER:
            case Type.BOOLEAN:
            case Type.UNDEFINED:
                return item.value;
            case Type.ARRAY:
                x = [];
                item.value.forEach(function (e) {
                    let key = e.key.substring(e.key.lastIndexOf('[') + 1, e.key.lastIndexOf(']'));
                    x[parseInt(key, 10)] = _fromPersistable(e);
                });
                return x;
            case Type.OBJECT:
                x = {};
                item.value.forEach(function (e) {
                    let key = e.key.substring(e.key.lastIndexOf('[') + 1, e.key.lastIndexOf(']'));
                    x[key] = _fromPersistable(e);
                });
                return x;
            default:
                _logUnknownType(item.type);
        }
    }
979234
function(obj) {
			var data = [];

			$.each(obj, function(i, value) {
				value = value.toString();
				
				if(value.length == 1) {
					value = '0'+value;
				}
				
				for(var x = 0; x < value.length; x++) {
					data.push(value.charAt(x));
				}				
			});

			if(data.length > this.minimumDigits) {
				this.minimumDigits = data.length;
			}
			
			if(this.minimumDigits > data.length) {
				for(var x = data.length; x < this.minimumDigits; x++) {
					data.unshift('0');
				}
			}

			return data;
		}
1046253
function(value, element, param) {
			return this.optional(element) || this.getLength($.trim(value), element) >= param;
		}
644219
function ($div, isInit, isForce, isOwn) {
            var data = $div.data('data');
            if (!data) return;

            var value = (data.tempValue !== undefined) ? data.tempValue : data.value;

            if (!isForce && data.oldValue !== undefined && data.oldValue == value && !data.ack) return;

            if (data.wType === 'number') {
                value = parseFloat((value || 0).toString().replace(',', '.'));
            }
            data.oldValue = value;

            if (data.temperature) {
                data.state = 'normal';
            } else if (value == data.min) {
                data.state = 'normal';
            } else if (value == data.max) {
                data.state = 'active';
            } else if (data.max &&
                (value === null    ||
                 value === ''      ||
                 value === undefined ||
                 value === 'false' ||
                 value === false))  {
                data.state = 'normal';
            } else {
                if (data.wType === 'number') {
                    if (data.max) {
                        if (value > data.min) {
                            data.state = 'active';
                        } else {
                            data.state = 'normal';
                        }
                    } else if (value) {
                        data.state = 'active';
                    } else {
                        data.state = 'normal';
                    }
                } else {
                    if (data.max) {
                        if (value == data.max) {
                            data.state = 'active';
                        } else {
                            data.state = 'normal';
                        }
                    } else if (value) {
                        data.state = 'active';
                    } else {
                        data.state = 'normal';
                    }
                }
            }

            if (vis.editMode && data.testActive) {
                data.state = (data.state === 'normal') ? 'active' : 'normal';
            }

            if (value !== null && value !== undefined) {
                $div.find('.vis-hq-nodata').remove();
            }

            switch (data.state) {
                case 'normal':
                    $('#' + data.wid + ' .vis-hq-main')
                        .removeClass(data.styleActive)
                        .addClass(data.styleNormal);

                    if (data.iconName || data.iconOn) {
                        var $img  = $div.find('.vis-hq-icon-img');

                        if ($img.attr('src') !== (data.iconName || '')) {
                            $img.attr('src', (data.iconName || ''));
                            vis.binds.hqwidgets.button.centerImage($div, data, $img);
                        }
                    }
                    if (data.captionOn) {
                        $div.find('.vis-hq-text-caption').html(data.caption || '');
                    }
                    break;
                case 'active':
                    $('#' + data.wid + ' .vis-hq-main')
                        .removeClass(data.styleNormal)
                        .addClass(data.styleActive);

                    if (data.iconName || data.iconOn) {
                        var $img  = $div.find('.vis-hq-icon-img');

                        if ($img.attr('src') !== (data.iconOn || data.iconName)) {
                            $img.attr('src', (data.iconOn || data.iconName));
                            vis.binds.hqwidgets.button.centerImage($div, data, $img);
                        }
                    }
                    if (data.captionOn) {
                        $div.find('.vis-hq-text-caption').html(data.captionOn);
                    }
                    break;
            }
            if (data.digits !== null && value !== null && value !== undefined) {
                if (typeof value !== 'number') value = parseFloat(value) || 0;
                value = value.toFixed(data.digits);
            }
            if (data.is_comma && value) value = value.toString().replace('.', ',');

            vis.binds.hqwidgets.button.showRightInfo($div, value);

            if ((!data.ack && !data['oid-working']) || (data['oid-working'] && data.working)) {
                $div.find('.vis-hq-working').show();
            } else {
                $div.find('.vis-hq-working').hide();
            }

            if (data['oid-battery']) $div.batteryIndicator('show', data.battery || false);

            if (data['oid-signal']) {
                $div.find('.vis-hq-signal').html(data.signal);
            }

            if (data['oid-humidity']) {
                var $h = $div.find('.vis-hq-humidity');
                if (!$h.length) {
                    vis.binds.hqwidgets.button.showCenterInfo($div, false, true);
                } else {
                    $h.html(Math.round(data.humidity || 0));
                }
            }

            if (data['oid-actual']) {
                var $a = $div.find('.vis-hq-actual');
                if (!$a.length) {
                    vis.binds.hqwidgets.button.showCenterInfo($div, false, true);
                } else {
                    if (typeof data.actual !== 'number') data.actual = parseFloat(data.actual) || 0;
                    $a.html((data.digits !== null) ? (data.actual || 0).toFixed(data.digits) : (data.actual || 0));
                }
            }

            if (data['oid-drive']) {
                $div.find('.vis-hq-drive').html(data.drive || 0);
            }

            // Show change effect
            if (data.changeEffect && ((!isInit && !isOwn) || (vis.editMode && data.testActive))) {
                var $main = $div.find('.vis-hq-main');
                $main.animateDiv(data.changeEffect, {color: data.waveColor});
            }
        }
65463
function(apiKey, templateId, pieceTitle,
        category, fromAddress, toAddress, ccAddress, bccAddresses, subject,
        textBody, htmlBody, contentType, mergeContext) {}
520585
function distinct(parent$, fn = (a, b) => valuesChanged(a, b)) {
  let newStream = fork$(parent$, value => value);
  parent$.listeners.push(function deepSelectValue(value) {
    if (fn(newStream.value, value)) {
      newStream(value);
    }
  });
  return newStream;
}
926731
function each (obj, fn) {
		const nth = obj.length;
		let i = -1;

		while (++i < nth) {
			if (fn.call(obj, obj[i], i) === false) {
				break;
			}
		}

		return obj;
	}