var rarApp = {};
var elApi  = {};

function escapeRegexp (str)
	{
	var reg, symbols;
	spc = ('['+'\\^$*+?.()|{}[]'.split('').join('\\'))+']';
	reg = new RegExp(spc,'g');
	return str.replace(reg,'\\$1');
	}

/*
htmlClassFind = function (class_string, name)
	{
	if (!isString(class_string) || !isString(name))
		{
		return;
		}
	var patt, reg;
	name = escapeRegexp(name);
	patt = ' '+name+' '+'|'+' '+name+'$' +'|'+'^'+name+' ' +'|'+'^'+name+'$';
	reg  = new RegExp(patt, 'g');
	return class_string.match(reg);
	}

htmlClassAdd = function (class_string, name)
	{
	if (!isString(class_string) || !isString(name))
		{
		return class_string;
		}
	class_string = htmlClassRemove(class_string, name);
	return class_string!='' ? ' '+name : name;
	}

htmlClassRemove = function (class_string, name)
	{
	if (!isString(class_string) || !isString(name))
		{
		return class_string;
		}
	var patt, reg;
	name = escapeRegexp(name);
	patt = ' '+name+'( )'+'|'+' '+name+'()$' +'|'+'^()'+name+' ' +'|'+'^()'+name+'$';
	reg  = new RegExp(patt, 'g');
	return class_string.replace(reg,'$1');
	}
*/
elApi.strClassAdd = function (str, name)
	{
	return str += str!='' ? ' '+name : name;
	}

elApi.strClassRemove = function (str, name)
	{
	var patt, reg;
	name = escapeRegexp(name);
	patt = ' '+name+'( )'+'|'+' '+name+'()$' +'|'+'^()'+name+' ' +'|'+'^()'+name+'$';
	reg  = new RegExp(patt, 'g');
	return str.replace(reg,'$1');
	}

elApi.strClassFind = function (str, name)
	{
	var patt, reg;
	name = escapeRegexp(name);
	patt = ' '+name+' '+'|'+' '+name+'$' +'|'+'^'+name+' ' +'|'+'^'+name+'$';
	reg  = new RegExp(patt, 'g');
	return str.match(reg);
	}

elApi.toggleClass = function (id, name)
	{
	var el, cl;
	el = document.getElementById(id);
	cl = el.className;
	if (elApi.strClassFind(cl, name))
		{
		cl = elApi.strClassRemove(cl, name);
	        el.className = cl;
		return false;	// removed
		}
	cl = elApi.strClassAdd(cl, name);
        el.className = cl;
	return true;	// added
	}

elApi.addClass = function (id, name)	// id nebo querystring napr: '.class', '#id'
	{
	var el, cl, i, i_end;
	el = document.getElementById(id);
	el = el ? [el] : document.querySelectorAll(id);
	i_end = el.length;
	for (i=0; i<i_end; i++)
		{
		cl = el[i].className;
		cl = elApi.strClassRemove(cl, name);
		cl = elApi.strClassAdd(cl, name);
        	el[i].className = cl;
		}
	}

elApi.removeClass = function (id, name)
	{
	var el, cl, i, i_end;
	el = el ? [el] : document.querySelectorAll(id);
	i_end = el.length;
	for (i=0; i<i_end; i++)
		{
		cl = el[i].className;
		cl = elApi.strClassRemove(cl, name);
        	el[i].className = cl;
		}
	}

rarApp.navToggle = function (id)
	{
	var bool;
	bool = elApi.toggleClass(id, 'closed');
	if (bool)
		{
//                elApi.removeClass('.rar_layout_right'  , 'col-12 col-sm-12 col-md-8 col-lg-9 col');
//                elApi.addClass   ('.rar_layout_right'  , 'col');	// right 100% width
		elApi.removeClass('#sidebarCollapsible', 'd-xs-none d-sm-none d-md-block');	// button by device - added by resize
		}
	else	{
//                elApi.removeClass('.rar_layout_right'  , 'col-12 col-sm-12 col-md-8 col-lg-9 col');
//                elApi.addClass   ('.rar_layout_right'  , 'col-12 col-sm-12 col-md-8 col-lg-9');	// right width by device
		elApi.removeClass('#sidebarCollapsible', 'd-xs-none d-sm-none d-md-block');	// button by device - added by resize
		}
	}

