/**
 * This method has been added to the ECMAScript 6 specification and may not be
 * available in all JavaScript implementations yet. However, you can polyfill
 * String.prototype.endsWith() with the following snippet: Not support on IE and
 * Opera
 */
if (!String.prototype.endsWith) {
	String.prototype.endsWith = function(searchString, position) {
		var subjectString = this.toString();
		if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
			position = subjectString.length;
		}
		position -= searchString.length;
		var lastIndex = subjectString.lastIndexOf(searchString, position);
		return lastIndex !== -1 && lastIndex === position;
	};
}

/**
 * Change the label value associated with the field with the specified id
 * 
 * @param id
 * @param value
 */
function changeLabel(id, value) {
	var $element = $(document.getElementById(id));
	var $label = $("label[for='" + $element.attr('id') + "']");
	$label.text(value);
}

/**
 * Show or Hide the row associated with the field with the specified id
 * 
 * @param id
 * @param value
 */
function rowVisible(id, value) {
	var $element = $(document.getElementById(id));
	if (value) {
		$element.closest('tr').show();
	} else {
		$element.closest('tr').hide();
	}
}

function showForm() {
	$("#workarea\\:input\\:dynaFormGroup").css("visibility", "visible");
	$("#workarea\\:input\\:tabs").css("visibility", "visible");
}

/**
 * Show or Hide the object associated with the field with the specified id
 * 
 * @param id
 * @param value
 */
function objVisible(id, value) {
	var $element = $(document.getElementById(id));
	if (value) {
		$element.show();
	} else {
		$element.hide();
	}
}

function tabVisible(id, value) {
	try {
		var $element = $('a[href="' + id + '"]');
		if (value) {
			$element.parent().show();
		} else {
			$element.parent().hide();
		}
	} catch (err) {
		console.log(err);
	}
}

function layoutNoTabVisible(id, value) {
	try {
		id = id.replace(/:/g, "\\:");
		var $element = $(id);
		if (value) {
			$element.show();
		} else {
			$element.hide();
		}
	} catch (err) {
		console.log(err);
	}
}

function buttonVisibleId(id, bool) {
	var $element = $('a[id$="' + id + '"]');
	if (bool) {
		$element.css('display', 'inline-table');
	} else {
		$element.css('display', 'none');
	}
}

var lastFocus;
function buttonVisiblePriv(value, priv) {
	var $element = $(document.getElementById(document.activeElement.id));
	if (value) {
		lastFocus = $element.parent().find('a');
		if (priv) {
			$element.parent().find('a').css('display', 'inline-table');
		}
	} else {
		lastFocus.hide();
	}
}

function buttonVisible(value) {
	buttonVisiblePriv(value, true);
}

var lastFocus;
function acButtonVisible(value, ac1, ac2, margin) {
	var $element = $(document.getElementById(document.activeElement.id));
	if (value) {
		lastFocus = $element.parent().parent().find('a');
		$element.parent().parent().find('a').show();
		if (ac1 && ac2) {
			$('span.ui-xis-icon-small-ac-add').css('display', 'inline-table');
			if ($element[0].value) {
				$('span.ui-xis-icon-small-ac-edit').css({
					'display' : 'inline-table',
					'vertical-align' : 'top',
					'margin-left' : '0px'
				});
			} else {
				$('span.ui-xis-icon-small-ac-edit').css('display', 'none');
			}
		} else if (!ac1 && !ac2) {
			$('span.ui-xis-icon-small-ac-add').css('display', 'none');
			$('span.ui-xis-icon-small-ac-edit').css('display', 'none');
		} else if (ac1) {
			$('span.ui-xis-icon-small-ac-add').css('display', 'inline-table');
			$('span.ui-xis-icon-small-ac-edit').css('display', 'none');
		} else if (ac2) {
			$('span.ui-xis-icon-small-ac-add').css('display', 'none');
			if ($element[0].value) {
				$('span.ui-xis-icon-small-ac-edit').css({
					'display' : 'inline-table',
					'vertical-align' : 'top',
					'margin-left' : margin + "px"
				});
			} else {
				$('span.ui-xis-icon-small-ac-edit').css('display', 'none');
			}
		}
	} else {
		lastFocus.hide();
	}
}

function acButtonVisibleDiv(elem, value, ac1, ac2, margin) {
	if (value) {
		var $element = jQuery(elem);
		lastFocus = $element.find('a');
		$element.find('a').show();
		ac1 = ac1 && ($element.children().eq(1).find('.ui-state-disabled').length == 0);
		ac2 = ac2 && $element.children().eq(0).val();
		if (ac1 && ac2) {
			$element.find('span.ui-xis-icon-small-ac-add').css('display', 'inline-table');
			$element.find('span.ui-xis-icon-small-ac-edit').css({
				'display' : 'inline-table',
				'vertical-align' : 'top',
				'margin-left' : '0px'
			});
		} else if (!ac1 && !ac2) {
			$element.find('span.ui-xis-icon-small-ac-add').css('display', 'none');
			$element.find('span.ui-xis-icon-small-ac-edit').css('display', 'none');
		} else if (ac1) {
			$element.find('span.ui-xis-icon-small-ac-add').css('display', 'inline-table');
			$element.find('span.ui-xis-icon-small-ac-edit').css('display', 'none');
		} else if (ac2) {
			$element.find('span.ui-xis-icon-small-ac-add').css('display', 'none');
			$element.find('span.ui-xis-icon-small-ac-edit').css({
				'display' : 'inline-table',
				'vertical-align' : 'top',
				'margin-left' : margin + "px"
			});
		}
	} else {
		lastFocus.hide();
	}
}

function forceLoseFocus() {
	var $element = $(document.getElementById(document.activeElement.id));
	$element.blur();
}

/**
 * Update value associated with the field with the specified id
 * 
 * @param id
 * @param value
 */
function setValue(id, value) {
	var $element = $(document.getElementById(id));
	$element.val(value);
}

/**
 * Resize height of inner work area, that displays output list or input form.
 * Based on window size - toolbar and footer
 * 
 */
function resize() {
	var browser = getBrowser();
	var os = getOperativeSystem();
	var marginInput = '149';
	var marginOutput = '241';
	var marginDashboard = '93';
	var offset = -4;
	var footerHeight = 33;
	var bottomMargin = 15.6;

	if (browser != 'ie' && browser != 'netscape' && browser != 'edge') {
		marginInput = calculateMarginInput(os, browser);
	}

	if (browser != 'ie' && browser != 'netscape' && browser != 'edge') {
		marginOutput = calculateMarginOutput(os, browser);
	}

	if (os != 'win') {
		marginDashboard = calculateMarginDashboard(os, browser);
	}

	var $windowHeight = $(window).height();
	if (document.getElementById("workarea:input:dynaFormGroup") != null) {
		$("#contentlayout").height($windowHeight - 140 + offset + footerHeight - 6);
		$(document.getElementById("workarea:input:dynaFormGroup")).height($windowHeight - marginInput + offset + footerHeight - 8);
		var headerFooterOffset = 0;
		if ($("#workarea\\:input\\:headerTabsLayout").length > 0) {
			headerFooterOffset = headerFooterOffset + $("#workarea\\:input\\:headerTabsLayout").outerHeight() + 10;
		}
		if ($("#workarea\\:input\\:footerTabsLayout").length > 0) {
			headerFooterOffset = headerFooterOffset + $("#workarea\\:input\\:footerTabsLayout").outerHeight();
		}
		if ($("#workarea\\:input\\:centerTabsLayout").length > 0) {
			$("#workarea\\:input\\:centerTabsLayout").css("height", "calc(100% - " + headerFooterOffset + "px)");
			if ($("#workarea\\:input\\:centerTabsLayout .ui-layout-unit-content").length > 0) {
				$("#workarea\\:input\\:centerTabsLayout .ui-layout-unit-content").css("height", "100%");
			}
		} else if ($("#workarea\\:input\\:centerNoTabsLayout").length > 0) {
			$("#workarea\\:input\\:centerNoTabsLayout").css("height", "calc(100% - " + headerFooterOffset + "px)");
			if ($("#workarea\\:input\\:centerNoTabsLayout .ui-layout-unit-content").length > 0) {
				$("#workarea\\:input\\:centerNoTabsLayout .ui-layout-unit-content").css("height", "100%");
			}
		}
	} else if (document.getElementById("workarea:input:tabs:dynaFormGroup") != null) {
		$("#contentlayout").height($windowHeight - 143 + offset + footerHeight);
		$(document.getElementById("workarea:input:tabs:dynaFormGroup")).height($windowHeight - 149 + offset + footerHeight);
	} else if (document.getElementById("workarea:outputlist:records") != null) {
		$(".ui-datatable-scrollable-body").height($windowHeight - marginOutput + offset + footerHeight - 17 - bottomMargin);

	} else if (document.getElementById("matchForm:recordsMatchA") != null || document.getElementById("matchForm:recordsMatchB") != null) {
		$(".ui-datatable-scrollable-body").each(function() {
			try {
				var header = $("div#matchForm\\:recordsMatchA_paginator_top").height();
				if (!header) {
					header = 0;
				}
				$(this).height($windowHeight - 162 - header);
				$(this).css('max-height', $windowHeight - 162 - header);
			} catch (err) {
				console.log(err);
			}
		});
		//inputlistmatch footer
		try {
			var height = $("#matchForm\\:recordsMatchA #matchForm\\:recordsMatchA_paginator_top").outerHeight(true)
					+ $("#matchForm\\:recordsMatchA .ui-datatable-scrollable-header").outerHeight(true)
					+ $("#matchForm\\:recordsMatchA .ui-datatable-scrollable-body").outerHeight(true);
			$("#matchForm\\:myDynaForm").height(height + 1);

		} catch (err) {
			console.log(err);
		}

	} else if (document.getElementById("workarea:splash:board") != null) {
		$("#contentlayout").height($windowHeight - marginDashboard + offset + footerHeight);

	} else if (document.getElementById("empty") != null) {
		// No resize

	} else {
		$("#contentlayout").height($windowHeight - 145 + offset + footerHeight);
	}

}

/**
 * @param os
 * @param browser
 * @returns margin (in px)
 */
function calculateMarginInput(os, browser) {
	var margin = '149';

	if (os == 'win') {
		if (browser == 'firefox') {
			margin = '151';
		}

	} else if (os == 'linux') {
		if (browser == 'firefox' || browser == 'chrome') {
			margin = '151';
		}
	}
	return margin;
}

/**
 * @param os
 * @param browser
 * @returns margin (in px)
 */
function calculateMarginOutput(os, browser) {
	var margin = '241';

	if (os == 'win') {
		if (browser == 'ie' || browser == 'netscape' || browser == 'edge') {
			margin = '241';
		} else if (browser == 'firefox') {
			margin = '248';
		} else if (browser == 'chrome') {
			margin = '240';
		}

	} else if (os == 'linux') {
		if (browser == 'ie' || browser == 'netscape' || browser == 'edge') {
			margin = '241';
		} else if (browser == 'firefox' || browser == 'chrome') {
			margin = '248';
		}
	}
	return margin;
}

/**
 * @param os
 * @param browser
 * @returns margin (in px)
 */
function calculateMarginDashboard(os, browser) {
	var margin = '93';
	if (os == 'win') {
		if (browser == 'ie' || browser == 'netscape') {
			return margin = '93';
		}
	} else if (os == 'linux') {
		return margin = '95';
	}
	return margin;
}
/**
 * Detects client operative system
 * 
 * @returns OSName
 */
function getOperativeSystem() {
	var OSName = "win";
	if (window.navigator.userAgent.indexOf("Windows") != -1)
		return OSName = "win";
	else if (window.navigator.userAgent.indexOf("Mac") != -1)
		return OSName = "mac";
	else if (window.navigator.userAgent.indexOf("X11") != -1)
		return OSName = "linux";
	else if (window.navigator.userAgent.indexOf("Linux") != -1)
		return OSName = "linux";

	return OSName;
}

/**
 * Detects client browser
 * 
 * @returns browserName
 */
var browserCache;

function getBrowser() {
	if (typeof browserCache !== 'undefined') {
		return browserCache;
	}
	if (localStorage.getItem('xcBrowser') !== null) {
		browserCache = localStorage.getItem('xcBrowser');
		return browserCache;
	}
	
	var nAgt = navigator.userAgent;
	var browserName = navigator.appName;
	var nameOffset, verOffset, ix;

	if ((verOffset = nAgt.indexOf("Edge")) != -1) {
		browserName = "edge";
	} else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
		browserName = "ie";
	} else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
		browserName = "firefox";
	} else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
		browserName = "chrome";
	} else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
		browserName = "safari";
	} else if ((verOffset = nAgt.indexOf("Opera")) != -1) {
		browserName = "opera";
	} else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
		browserName = nAgt.substring(nameOffset, verOffset);
	} else if (browserName.toLowerCase() == browserName.toUpperCase()) {
		browserName = navigator.appName.toLowerCase();

	}
	browserCache = browserName.toLowerCase();
	localStorage.setItem('xcBrowser', browserCache);
	return browserCache;
}

function setPreferencesAndSubmit(type, origin, data) {
	if (type != 'error') {
		var returnValue;
		returnValue = data;
		processAppletReply([ {
			name : 'origin',
			value : origin
		}, {
			name : 'value',
			value : returnValue
		} ]);
	} else {
		processAppletReply([ {
			name : 'origin',
			value : origin
		}, {
			name : 'value',
			value : type
		} ]);
	}

	PF('fullblockWV').unblock();
}

function alertMessage(msgtype, msgsum, msg) {
	showMsg(msgtype, msgsum, msg);
}

function setOutputListFilter(col, value) {
	var j_idt = $('[role="columnheader"]').next().attr('id');
	j_idt = j_idt.replace(':0', '');
	j_idt = j_idt.replace('workarea:outputlist:records:', '');
	$('#workarea\\:outputlist\\:records\\:' + j_idt + '\\:' + col + '\\:filter').val(value);
	PF('recordsWV').filter();
}

function silentRedraw() {
	var n = document.createTextNode('.');
	$('#content').append(n);
	setTimeout(function() {
		// n.parentNode.removeChild(n);
	}, 0);
}

function openSecondDialog() {
	$("[id$='remoteSelectEntity']").click();
}

function openFirstDialog() {
	$("[id$='clinkremote']").click();
}

function messageBrowserTab(command, id, origin, data) {
	message_broadcast({
		'command' : command,
		'id' : id,
		'origin' : origin,
		'data' : data,
		'uid' : (new Date).getTime() + Math.random()
	});
}

function closeBrowserTab(command, id, origin, data) {
	messageBrowserTab(command, id, origin, data);
	logoutClose();
}

function openBrowserTab(location, id) {
	listenTo.push(id);
	window.open(location);
}

// Messaging

var listenTo = new Array();

function message_broadcast(message) {
	localStorage.setItem('message', JSON.stringify(message));
	localStorage.removeItem('message');
}

function message_receive(ev) {
	var message = "";
	try {
		if (ev.originalEvent.key != 'message')
			return;

		if (ev.originalEvent.newValue == null || ev.originalEvent.newValue == '')
			return;

		message = JSON.parse(ev.originalEvent.newValue);

	} catch (e) {
	}

	if (!message)
		return;

	for (var i = 0; i < listenTo.length; i++) {
		if (listenTo[i] == message.origin) {
			if (message.command.search('close') != -1 || message.command.search("alertMessage") != -1
					|| message.command.search("setPreferencesAndSubmit") != -1) {
				listenTo.splice(i, 1);
			}
			extMsg(message.command, message.id, message.data);
			return;
		}
	}
}

function stopRefreshDashboard() {
	if (PF('refreshDashboard') == undefined) {
		// Not in page
	} else {
		PF('refreshDashboard').stop();
	}
}
function moveScrollPOS(listName, pos) {
	var browser = getBrowser();
	var rowHeight = 35;
	if (browser == 'firefox') {
		rowHeight = 39;
	}
	var $scroll;
	$scroll = $("div[id$='" + listName + "']").find(".ui-datatable-scrollable-body");
	$scroll.scrollTop((pos + 1) * rowHeight);

}

function moveScroll(listName, pos, rowNumber) {
	var browser = getBrowser();
	var rowHeight = 23;
//	if (browser == 'firefox') {
//		rowHeight = 24;
//	}

	var $scroll;
	if (listName.endsWith('iListT')) {
		$scroll = $("div[id$='" + listName + "']").find(".ui-treetable-scrollable-body");
	} else {
		$scroll = $("div[id$='" + listName + "']").find(".ui-datatable-scrollable-body");
	}
	
	var rows = $scroll.find("tr");
	var totalSize = 0; // size in pixels
	var totalSizeBottom = 0; // size in pixels
	var rowsCount = $(rows).length;
	var isLazy = false;

	if (rows.length > 2) {
		rowHeight = $(rows.get(1)).outerHeight();
	}
	
	if (!rowNumber) {
		//rowNumber = 8;
		rowNumber = $scroll.outerHeight() / rowHeight
	}
	
	try {
		if ($scroll.prevObject) {
			if ($scroll.prevObject.hasClass('ui-xis-inputlistlazy')) {
				isLazy = true;
			}
		}
	} catch (err) {
		console.log(err);
	}

	if (isLazy) {
		try {
//			var firstRowHeight = rowHeight;
//			if (rows.length > 2) {
//				// first line is header
//				firstRowHeight = $(rows.get(1)).outerHeight();
//			}
//			if (firstRowHeight) {
//				rowHeight = firstRowHeight;
//			}
			totalSize = pos * rowHeight;
			var target = totalSize;
			var viewPortSize = rowHeight * rowNumber;
			if (target > $scroll.scrollTop() + viewPortSize || (target < $scroll.scrollTop())) {
				if (target > $scroll.scrollTop() + viewPortSize) {
					$scroll.scrollTop((target) - viewPortSize + 1);
				}
				if (target < $scroll.scrollTop()) {
					$scroll.scrollTop(target - rowHeight);
				}
				if (updating) {
					updating = false;
				}
			}
		} catch (err) {
			console.log(err);
		}
	} else {
		for (var linePos = 1; linePos < rowsCount; linePos++) {
			if (pos == linePos) {
				totalSizeBottom = totalSize + $(rows.get(linePos)).height() + 2;
				break;
			}
			totalSize = totalSize + $(rows.get(linePos)).height() + 2;
		}

		if ($scroll.scrollTop() > (totalSize) || ($scroll.scrollTop() - 1 + (rowNumber * rowHeight)) <= (totalSize)) {
			if ($scroll.scrollTop() > (totalSize)) {
				$scroll.scrollTop((totalSize));
			} else if (($scroll.scrollTop() - 1 + (rowNumber * rowHeight)) <= (totalSize)) {
				$scroll.scrollTop(1 + totalSizeBottom - (rowNumber * rowHeight));
			}
		}
	}
}

function galleriaSetStyle(galleria, current) {
	$("div[id$='" + galleria + "']").find(".ui-datagrid-column > a").parent().css("border-width", "0px");
	$("div[id$='" + galleria + "']").find(".ui-datagrid-column > a").parent().css("border-style", "dotted");
	if (current >= 0) {
		$("div[id$='" + galleria + "']").find("[id$='" + current + ":loadiframe']").parent().css("border-width", "1px");
		$("div[id$='" + galleria + "']").find("[id$='" + current + ":loadiframe']").parent().css("border-style", "solid");
	}
}

function setMenuSelectCSS() {
	$("<style>").prop("type", "text/css").html(
			"[id*='menuleft'] .ui-menuitem .ui-state-hover {color: #ffffff !important;border-color: " + $('#colorstyle').css("background-color")
					+ " !important;background: " + $('#colorstyle').css("background-color") + " !important;padding-right:0.3em;}").appendTo("head");
}

function applyFeatureDialogStyle() {
	var node = document.createElement('style');
	node.innerHTML = ".ui-dialog-titlebar {display:none;} .ui-dialog {opacity: 0.97;background:transparent;"
			+ "box-shadow: 0 0px 0px 0 rgba(0,0,0,0)!important;" + "-webkit-box-shadow: 0 0px 0px 0 rgba(0,0,0,0)!important;" + "}";
	document.body.appendChild(node);
}

function restoreDialogStyle() {
	var node = document.createElement('style');
	node.innerHTML = ".ui-dialog-titlebar {display:block;} .ui-dialog {opacity: 0.95;background:#fff;}";
	document.body.appendChild(node);
}

function blurUI() {
	$('#uipaneln').addClass('xis-dialog-blur');
	$('#uipanelc').addClass('xis-dialog-blur');
	if ($('#uipanels') != null) {
		$('#uipanels').addClass('xis-dialog-blur');
	}
}

function unBlurUI() {
	window.parent.document.getElementById('uipaneln').className = window.parent.document.getElementById('uipaneln').className.replace('xis-dialog-blur', '');
	window.parent.document.getElementById('uipanelc').className = window.parent.document.getElementById('uipanelc').className.replace('xis-dialog-blur', '');
	if (window.parent.document.getElementById('uipanels') != null) {
		window.parent.document.getElementById('uipanels').className = window.parent.document.getElementById('uipanels').className
				.replace('xis-dialog-blur', '');
	}
}

function focusColor(selectedColor) {
	var x = document.getElementsByClassName(selectedColor);
	var i;
	for (i = 0; i < x.length; i++) {
		if (hasClass(x[i], 'ui-xis-home-color')) {
			x[i].className = x[i].className + ' color-picker-active';
		}
	}
}

function removeAllColorFocus() {
	var x = document.getElementsByClassName('ui-xis-home-color');
	var i;
	for (i = 0; i < x.length; i++) {
		x[i].className = x[i].className.replace('color-picker-active', '');
	}
}

function focusIcon(selectedIcon, color) {
	var iconName = selectedIcon;
	if (iconName.indexOf('ui-xis-home-') == -1) {
		iconName = 'ui-xis-home-' + selectedIcon;
	}
	var x = document.getElementsByClassName(iconName);
	var i;
	for (i = 0; i < x.length; i++) {
		x[i].className = x[i].className + ' ' + color + ' icon-picker-active';
	}
}

function removeAllIconFocus() {
	var x = $("span[class^='ui-xis-home-icon-']")
	var i;
	for (i = 0; i < x.length; i++) {
		x[i].className = x[i].className.replace('ui-xis-home-color', '');
		x[i].className = x[i].className.replace('icon-picker-active', '');

	}
}

function hasClass(elem, klass) {
	return (" " + elem.className + " ").indexOf(" " + klass + " ") > -1;
}

var rtime;
var timeout = false;
var delta = 500;
$(window).resize(function() {
	rtime = new Date();
	if (timeout === false) {
		timeout = true;
		setTimeout(resizeend, delta);
	}
});

function resizeend() {
	if (new Date() - rtime < delta) {
		setTimeout(resizeend, delta);
	} else {
		timeout = false;
		resize();
	}
}

$(window).ready(function() {
	resize();
	$(window).trigger('resize');
	setMenuSelectCSS();
});

var previousBodyWidth = 0;

function footerMatchUpdate(footerInfo, side) {
	try {
		var json = JSON.stringify(footerInfo), obj = JSON.parse(json);
		for (var i = 0; i < obj.length; i++) {
			var position = obj[i].position;
			var value = obj[i].value;
			if (value == null) {
				value = "";
			}
			if (document.getElementById("matchForm:recordsMatch" + side + ":columns:" + (position) + ":footerInfo")) {
				document.getElementById("matchForm:recordsMatch" + side + ":columns:" + (position) + ":footerInfo").innerHTML = value;
			}
		}
	} catch (err) {
		console.log(err);
	}
}

function footerUpdate(footerInfo) {
	var json = JSON.stringify(footerInfo), obj = JSON.parse(json);
	for (var i = 0; i < obj.length; i++) {
		var position = obj[i].position;
		var value = obj[i].value;
		if (value == null) {
			value = "???";
		}
		try {
			if (document.getElementById("workarea:outputlist:records:columns:" + (position) + ":footerInfo")) {
				document.getElementById("workarea:outputlist:records:columns:" + (position) + ":footerInfo").innerHTML = value;
			}
		} catch (err) {
			console.log(err);
		}
	}
}

function footerInputListUpdate(wv, footerInfo) {
	var json = JSON.stringify(footerInfo), obj = JSON.parse(json);
	for (var i = 0; i < obj.length; i++) {
		var position = obj[i].position;
		var value = obj[i].value;
		if (value == null) {
			value = "???";
		}
		try {
			if (PF(wv).footerCols && position < PF(wv).footerCols.length && PF(wv).footerCols[position]) {
				if (PF(wv).footerCols[position].firstElementChild) {
					PF(wv).footerCols[position].firstElementChild.innerHTML = value;
				}
			}
		} catch (err) {
			console.log(err);
		}
	}
}

navigator.getBrowserAndVersion = (function() {
	var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
	if (/trident/i.test(M[1])) {
		tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
		return 'IE ' + (tem[1] || '');
	}
	if (M[1] === 'Chrome') {
		tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
		if (tem != null)
			return tem.slice(1).join(' ').replace('OPR', 'Opera');
	}
	M = M[2] ? [ M[1], M[2] ] : [ navigator.appName, navigator.appVersion, '-?' ];
	if ((tem = ua.match(/version\/(\d+)/i)) != null)
		M.splice(1, 1, tem[1]);
	return M.join(' ');
})();

function changeComponentBackground(id) {
	var d = id.replace(/\:/g, '\\:');
	$(d).addClass("xis-input-autocomplete-nothingfound");
	$(d).on('focusout ', function() {
		if ($(d).hasClass("xis-input-autocomplete-nothingfound")) {
			$(d).removeClass("xis-input-autocomplete-nothingfound");
		}
	});
}

function clearComponentBackground(id) {
	var d = id.replace(/\:/g, '\\:');
	if ($(d).hasClass("xis-input-autocomplete-nothingfound")) {
		$(d).removeClass("xis-input-autocomplete-nothingfound");
	}
}

/*******************************************************************************
 * copy height, used in configFilter
 ******************************************************************************/
function adjustFilterListHeight() {
	$("[id$='cFilterListLeft'] .ui-datatable-scrollable-body").height($("[id$='cTreeFilter']").innerHeight());
}

/*******************************************************************************
 * add holidays, used in scheduler
 ******************************************************************************/
function setHolidays(json, yearView) {
	try {
		$holidays = json;
		if (json) {
			$.each(json, function(i, obj) {
				if (yearView) {
					if ($("td").find('[data-date="' + i + '"]').size() >= 3) {
						$("td").find('[data-date="' + i + '"]').eq(2).addClass('ui-xis-holiday-wrapper');
						$("td").find('[data-date="' + i + '"]').eq(2).prop('title', obj);
						$("td").find('[data-date="' + i + '"]').eq(2).addClass('ui-xis-vertical-align');
					} else {
						$("td").find('[data-date="' + i + '"]').eq(0).addClass('ui-xis-holiday-wrapper');
						$("td").find('[data-date="' + i + '"]').eq(0).prop('title', obj);
					}
				} else {
					if ($("td").find('[data-date="' + i + '"]').size() >= 3) {
						$("td").find('[data-date="' + i + '"]').eq(2).addClass('ui-xis-holiday-wrapper');
						$("td").find('[data-date="' + i + '"]').eq(1).text(' ' + obj);
						$("td").find('[data-date="' + i + '"]').eq(1).addClass('ui-xis-vertical-align');
					} else {
						$("td").find('[data-date="' + i + '"]').eq(0).addClass('ui-xis-holiday-wrapper');
						if (!yearView) {
							$("td").find('[data-date="' + i + '"]').eq(0).text(' ' + obj);
						}
						$("td").find('[data-date="' + i + '"]').eq(0).prop('title', obj);
					}
				}
			});
		}
	} catch (err) {
		console.log(err);
	}
}
