function filterProducts(t){
let value = t.value;
//let fid = t.attributes['data-fid'].value;
let fig = parseInt(t.attributes['data-filtergroup'].value);
if(fig > 0 ){
if(t.checked){
if(typeof appliedFilters['f'+fig] === 'undefined') appliedFilters['f'+fig] = [];
appliedFilters['f'+fig].push(parseInt(value));
}else{
if(typeof appliedFilters['f'+fig] !== 'undefined')
appliedFilters['f'+fig] = appliedFilters['f'+fig].filter(x => x != value);
}
if(fig == 1){
fillSizeFilter(filtruSize.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(fig == 2){
fillBrandFilter(filterBrands.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(fig == 5){
fillMaterialFilter(filtruMaterial.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(fig == 3){
fillColorFilter(filtruCuloare.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
}
if(fig == 0){
if(t.checked){
if(typeof appliedFilters['c'] === 'undefined') appliedFilters['c'] = [];
appliedFilters['c'].push(parseInt(value));
}else{
if(typeof appliedFilters['c'] !== 'undefined')
appliedFilters['c'] = appliedFilters['c'].filter(x => x != value);
}
fillCategoryFilter(filterCategories.filter(id => (id > 0 && typeof assideCats[id] !== 'undefined' )).map(id => ({id:id, name:assideCats[id].name})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(fig == -1){
if(t.checked){
if(typeof appliedFilters['pf'] === 'undefined') appliedFilters['pf'] = [];
appliedFilters['pf'].push(parseInt(value));
}else{
if(typeof appliedFilters['pf'] !== 'undefined')
appliedFilters['pf'] = appliedFilters['pf'].filter(x => x != value);
}
fillPriceFilter();
}
// let filterurl = makeQueryParamNoCat(Object.entries(appliedFilters));
//console.log(filterurl);
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function showProducts(msg, t){
let htmlContent = '';
if(!msg.items.length){
htmlContent = "Nu am gasit nici un produs!"
}
let listaA = document.getElementById('showresults');
if(!listaA) return false;
let htmlContentArray = [];
for(item of msg.items){
let htmlTo = '
\
\
\
\
'+item.name+'
';
if(parseFloat(item.priceS) < parseFloat(item.price)) {
htmlTo += ''+item.price+' lei ';
htmlTo += '
';
} else {
htmlTo += '\
'+item.price+' lei'+item.priceS+' lei\
\
\
- '+(100 - (item.price * 100 / item.priceS)).toFixed(0)+' %\
';
}
if(parseInt(item.priceL)){ htmlTo += 'RRP: '+item.priceL+' lei';}
if (item.priceL > item.price) {
const savePercentage = 100-Math.ceil((item.price/item.priceL)*100)
htmlTo += '' +
'Economisești ' + (item.priceL- item.price) + ' lei' +
' '+ savePercentage +'% OFF RRP\n' +
'
'
}
htmlTo += '\
';
htmlContentArray.push(htmlTo);
}
listaA.innerHTML = htmlContentArray.join('');
document.getElementById('countProducts').innerHTML = msg.total+' produs'+((msg.total>1)?"e":'');
document.getElementById('countProducts').innerHTML = msg.total+' produs'+((msg.total>1)?"e":'');
document.getElementById('arataNrProdFilter').innerHTML = "Arata ("+msg.total+' produs'+((msg.total>1)?"e":'')+")";
if(window.innerWidth > 1080 && msg.items.length){
setTimeout(getSecondPicture, 100);
}
updatePagination(msg);
updateFilters(msg, t);
if(msg.items.length){
getProductsVariations();
}
}
function makeQueryParamNoCat(appliedFiltersNoCat, excluded = []){
try{
return appliedFiltersNoCat.map( ([k,a]) => (a.length && k != 'cids' && k != 'collection' && typeof a === 'object')? a.map(v => (!excluded.includes(v)) ? k+'[]='+v : null).join('&'):((a.length && k != 'cids')? ( k+'='+a ): false) ).filter(a => a).join('&');
}catch(e){
console.log(e,appliedFiltersNoCat);
return '';
}
}
function makeQueryParam(){
return Object.entries(appliedFilters).map( ([k,a]) => (a.length && typeof a === 'object')? a.map(v => k+'[]='+v ).join('&'):((a.length )? ( k+'='+a ): false)).filter(a => a).join('&');
}
function updatePagination(msg){
let paginationEl = document.getElementById('pagination');
if(!paginationEl) return false;
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
let validPath = [];
basepath.forEach(trep => {
let miurl = trep.match(/\-m([0-9]+)$/);
if(miurl){
exclude = parseInt(miurl[1]);
//validPath.push(trep);
}
let biurl = trep.match(/\-b([0-9]+)$/);
if(biurl){
// exclude = parseInt(biurl[1]);
}
else{
if(!miurl || appliedFilters.f5.includes(parseInt(miurl[1])))
validPath.push(trep);
}
});
let fullPath = validPath.filter(pat => pat !== null).join('/');
const qcst = makeQueryParamNoCat(Object.entries(appliedFilters));
paginationEl.innerHTML = '';
for(let i = 1; i <= msg.pagini; i++){
if(i == 1 || (i<(msg.p+3) && i>(msg.p-3)) || i == msg.pagini) {
if(msg.p == i){
paginationEl.innerHTML += '1';
if(msg.p > 3){
paginationEl.innerHTML += '...';
}
}else{
paginationEl.innerHTML += ''+(i)+'';
}
}
}
if(msg.pagini > msg.p){
paginationEl.innerHTML += '';
}
}
function fillBrandFilter(aBrands){
let brandFilter = document.getElementById('brandFilter');
let brandFilterSelected = document.getElementById('selectedBrandFilter');
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
let validPath = [];
basepath.forEach(trep => {
let miurl = trep.match(/\-m([0-9]+)$/);
if(miurl){
exclude = parseInt(miurl[1]);
//validPath.push(trep);
}
let biurl = trep.match(/\-b([0-9]+)$/);
if(biurl){
// exclude = parseInt(biurl[1]);
}
else{
if(!miurl || appliedFilters.f5.includes(parseInt(miurl[1])))
validPath.push(trep);
}
});
let fullPath = validPath.filter(pat => pat !== null).join('/');
let qcst ='';// makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
if(brandFilter){
brandFilter.innerHTML = '';
brandFilterSelected.innerHTML = '';
let outputhtml = '';
let outputhtml2 = '';
document.getElementById('selFilterBrand').classList.add('noshow');
appliedFilters.f2.forEach(sid => {
let fname = attrValNames[sid].value;
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [sid, exclude]);
if(qcst != '') qcst = "?" + qcst;
outputhtml += ''+fname+'';
}else{
outputhtml += '';
}
})
brandFilterSelected.innerHTML = outputhtml;
if(appliedFilters.f2.length){document.getElementById('selFilterBrand').classList.remove('noshow');}
for(const sid of aBrands){
let checked = appliedFilters.f2.includes(parseInt(sid.id)) ? "checked" : "";
let fname = sid.name;
let bid = parseInt(sid.id);
let gurl = !checked ? '/'+(cleanUnwantedChars(HtmlEntities.decode(fname)))+'-b'+sid.id : '';
if(checked){
// brandFilterSelected.innerHTML += ''+fname+'';
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [bid, exclude]);
if(qcst != '') qcst = "?" + qcst;
outputhtml2 += ''+fname+'';
}else{
outputhtml2 += '';
}
}else{
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [exclude]);
if(qcst != '') qcst = "?" + qcst;
outputhtml2 += ''+fname+'';
}else{
outputhtml2 += '';
}
}
}
brandFilter.innerHTML = outputhtml2;
}
}
function fillSizeFilter(aSizes){
let sizeFilter = document.getElementById('sizeFilter');
let sizeFilterSelected = document.getElementById('selectedSizeFilter');
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
if(typeof basepath[1] !== 'undefined') {
let biurl = basepath[1].match(/\-b([0-9]+)$/);
if(biurl)
exclude = biurl[1];
}
let qcst ='';// makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
if(sizeFilter){
sizeFilter.innerHTML = '';
sizeFilterSelected.innerHTML = '';
let outputhtml = '';
let outputhtml2 = '';
document.getElementById('selFilterSize').classList.add('noshow');
appliedFilters.f1.forEach(bid => {
let fname = attrValNames[bid].value;
outputhtml += '';
})
sizeFilterSelected.innerHTML = outputhtml;
if(appliedFilters.f1.length){document.getElementById('selFilterSize').classList.remove('noshow');}
for(const sid of aSizes){
let checked = appliedFilters.f1.includes(parseInt(sid.id)) ? true : false;
let fname = sid.name;
let bid = sid.id;
// / let gurl = !checked ? '/'+(cleanUnwantedChars(reverseEntities(fname)))+'-b'+bid : '';
if(checked){
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), bid);
// sizeFilterSelected.innerHTML += '';
outputhtml2 += '';
}else{
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), 0);
outputhtml2 += '';
}
}
sizeFilter.innerHTML = outputhtml2;
}
}
function fillColorFilter(aColors){
let colorFilter = document.getElementById('colorFilter');
let colorFilterSelected = document.getElementById('colorSizeFilter');
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
if(typeof basepath[1] !== 'undefined') {
let biurl = basepath[1].match(/\-b([0-9]+)$/);
if(biurl)
exclude = biurl[1];
}
let qcst ='';// makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
if(colorFilter){
colorFilter.innerHTML = '';
colorFilterSelected.innerHTML = '';
document.getElementById('selFilterColor').classList.add('noshow');
appliedFilters.f3.forEach(bid => {
let fname = attrValNames[bid].value;
let classname = fname.toLowerCase().replace(' ', '');
colorFilterSelected.innerHTML +='';
})
if(appliedFilters.f3.length){document.getElementById('selFilterColor').classList.remove('noshow');}
for(const sid of aColors){
let checked = appliedFilters.f3.includes(parseInt(sid.id)) ? true : false;
let fname = sid.name;
let bid = sid.id;
let classname = fname.toLowerCase().replace(' ', '');
// / let gurl = !checked ? '/'+(cleanUnwantedChars(reverseEntities(fname)))+'-b'+bid : '';
if(checked){
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), bid);
// colorFilterSelected.innerHTML += '';
colorFilter.innerHTML += '';
}else{
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), 0);
colorFilter.innerHTML += '';
}
}
}
}
function fillMaterialFilter(aMaterials){
let materialFilter = document.getElementById('materialFilter');
let materialFilterSelected = document.getElementById('selectedMaterialFilter');
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
let validPath = [];
basepath.forEach(trep => {
let biurl = trep.match(/\-b([0-9]+)$/);
if(biurl){
exclude = parseInt(biurl[1]);
}
let miurl = trep.match(/\-m([0-9]+)$/);
if(miurl){
// exclude = miurl[1];
//validPath.push(trep);
}else{
if(!biurl || appliedFilters.f2.includes(parseInt(biurl[1])))
validPath.push(trep);
}
});
let fullPath = validPath.filter(pat => pat !== null).join('/');
let qcst ='';// makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
if(materialFilter){
materialFilter.innerHTML = '';
materialFilterSelected.innerHTML = '';
document.getElementById('selFilterMaterial').classList.add('noshow');
appliedFilters.f5.forEach(sid => {
let fname = attrValNames[sid].value;
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [sid, exclude]);
if(qcst != '') qcst = "?" + qcst;
materialFilterSelected.innerHTML += ''+fname+'';
}else{
materialFilterSelected.innerHTML += '';
}
})
if(appliedFilters.f5.length){document.getElementById('selFilterMaterial').classList.remove('noshow');}
for(const sid of aMaterials){
let checked = appliedFilters.f5.includes(parseInt(sid.id)) ? "checked" : "";
let fname = sid.name;
let bid = parseInt(sid.id);
let gurl = !checked ? '/'+(cleanUnwantedChars(HtmlEntities.decode(fname)))+'-m'+sid.id : '';
if(checked){
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [bid,exclude]);
// if(qcst != '') qcst = "?" + qcst;
//materialFilterSelected.innerHTML += ''+fname+'';
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [bid, exclude]);
if(qcst != '') qcst = "?" + qcst;
materialFilter.innerHTML += ''+fname+'';
}else{
materialFilter.innerHTML += '';
}
}else{
if(window.innerWidth > 1080){
qcst = makeQueryParamNoCat(Object.entries(appliedFilters), [exclude]);
if(qcst != '') qcst = "?" + qcst;
materialFilter.innerHTML += ''+fname+'';
}else{
materialFilter.innerHTML += '';
}
}
}
}
}
function fillPriceFilter(){
let priceFilter = document.getElementById('priceFilter');
//let priceFilterSelected = document.getElementById('selectedPriceFilter');
priceFilter.innerHTML = '';
if(parseInt(priceRange.min) < 50){
priceFilter.innerHTML += '';
}
if((priceRange.max > 50 && priceRange.max < 100) || (priceRange.max > 100 && priceRange.min < 100 ) ){
priceFilter.innerHTML += '';
}
if((priceRange.min > 100 && priceRange.min < 200) || (priceRange.max > 200 && priceRange.min < 200 )){
priceFilter.innerHTML += '';
}
if(priceRange.max > 200){
priceFilter.innerHTML += '';
}
}
function fillCategoryFilter(aCategories){
let categoryFilter = document.getElementById('categoryFilter');
let categoryFilterSelected = document.getElementById('selectedCategoryFilter');
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = 0;
if(typeof basepath[1] !== 'undefined') {
let biurl = basepath[1].match(/\-b([0-9]+)$/);
if(biurl)
exclude = biurl[1];
}
let qcst ='';// makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
if(categoryFilter){
categoryFilter.innerHTML = '';
categoryFilterSelected.innerHTML = '';
document.getElementById('selFilterCat').classList.add('noshow');
appliedFilters.c.filter(id => (id > 0 && typeof assideCats[id] !== 'undefined' )).map(id => ({id:id, name:assideCats[id].name})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ).forEach(sid => {
let fname = sid.name;
let bid = sid.id;
categoryFilterSelected.innerHTML += '';
})
if(appliedFilters.c.length){document.getElementById('selFilterCat').classList.remove('noshow');}
for(const sid of aCategories){
let checked = appliedFilters.c.includes(parseInt(sid.id)) ? "checked" : "";
let fname = sid.name;
let bid = sid.id;
// let gurl = !checked ? '/'+(cleanUnwantedChars(HtmlEntities.decode(fname)))+'-b'+bid : '';
if(checked){
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), bid);
// categoryFilterSelected.innerHTML += '';
categoryFilter.innerHTML += '';
}else{
// qcst = makeQueryParamNoCat(Object.entries(appliedFilters), 0);
categoryFilter.innerHTML += '';
}
}
}
}
function populateFilters (){
fillBrandFilter(filterBrands.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
fillSizeFilter(filtruSize.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
fillColorFilter(filtruCuloare.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
fillMaterialFilter(filtruMaterial.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
fillCategoryFilter(filterCategories.filter(id => (id > 0 && typeof assideCats[id] !== 'undefined' )).map(id => ({id:id, name:assideCats[id].name})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
fillPriceFilter();
updateFilterCount();
}
function updateFilters(msg, t){
const filterClk = t.attributes['data-filtergroup'].value;
if(filterClk != 1 || !t.checked){
if(filterClk != 1 )
filtruSize = msg.sizeIds;
fillSizeFilter(msg.sizeIds.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(filterClk != 3 || !t.checked){
if(filterClk != 3)
filtruCuloare = msg.colorIds;
fillColorFilter(msg.colorIds.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(filterClk != 2 || !t.checked){
if(filterClk != 2)
filterBrands = msg.brandIds;
fillBrandFilter(msg.brandIds.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(filterClk != 5 || !t.checked){
fillMaterialFilter(msg.materialIds.filter(id => (id > 0 && typeof attrValNames[id] !== 'undefined' )).map(id => ({id:id, name:attrValNames[id].value})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(filterClk != 0 || !t.checked){
if(filterClk != 0 )
filterCategories = msg.categories;
fillCategoryFilter(msg.categories.filter(id => (id > 0 && typeof assideCats[id] !== 'undefined' )).map(id => ({id:id, name:assideCats[id].name})).sort((a, b) => a.name.toLowerCase() < b.name.toLowerCase() ? -1 : (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : 0) ));
}
if(filterClk != -1 || !t.checked){
//if(filterClk != 0 )
// filterCategories = msg.categories;
fillPriceFilter();
}
updateFilterLinks();
updateFilterCount();
}
function updateFilterCount(){
document.getElementById('filterCount-1').innerHTML = appliedFilters.f1.length ? (''+appliedFilters.f1.length+'') : '';
document.getElementById('filterCount-2').innerHTML = appliedFilters.f2.length ? (''+appliedFilters.f2.length+'') : '';
document.getElementById('filterCount-3').innerHTML = appliedFilters.f3.length ? (''+appliedFilters.f3.length+'') : '';
document.getElementById('filterCount-5').innerHTML = appliedFilters.f5.length ? (''+appliedFilters.f5.length+'') : '';
document.getElementById('filterCount-0').innerHTML = appliedFilters.c.length ? (''+appliedFilters.c.length+'') : '';
document.getElementById('filterCount-pf').innerHTML = appliedFilters.pf.length ? (''+appliedFilters.pf.length+'') : '';
let cfa = appliedFilters.f1.length+appliedFilters.f2.length+appliedFilters.f3.length+appliedFilters.f5.length+appliedFilters.c.length
document.getElementById('allFiltercounter').innerHTML = cfa ? ''+cfa+'' : '0';
}
// doar pentru linkurile de sortare. acolo e bubita
function updateFilterLinks(){
let basepath = location.pathname.split('/').filter(b => b.trim() != '');
let exclude = [];
let validPath = [];
basepath.forEach(trep => {
let biurl = trep.match(/\-b([0-9]+)$/);
if(biurl){
exclude.push(parseInt(biurl[1]));
if(appliedFilters.f2.includes(parseInt(biurl[1])))
validPath.push(trep);
}
let miurl = trep.match(/\-m([0-9]+)$/);
if(miurl){
exclude.push(parseInt(miurl[1]));
if(appliedFilters.f5.includes(parseInt(miurl[1])))
validPath.push(trep);
}
if(!miurl && !biurl){
validPath.push(trep);
}
});
let fullPath = validPath.filter(pat => pat !== null).join('/');
let qcst = makeQueryParamNoCat(Object.entries(appliedFilters), exclude);
//window.location.assign(fullPath+qcst);
//history.pushState(null, null, "https://"+location.host+myJson.baseUrl);
history.pushState(null, null, fullPath+'?'+qcst);
Array.from(document.getElementsByClassName('filterURL')).forEach(alem => {
const queryp = alem.href.split('?');
let aquery = '';
if(typeof queryp[1] !== 'undefined' ){
let ceva = queryp[1].split('&').filter(qs=> qs.match(/^ordonare/));
if(ceva.length)
aquery = "?"+ceva[0]+(qcst.length >0?"&":"");
}
// console.log(aquery, fullPath+aquery+qcst);
alem.href = fullPath+aquery+qcst;
})
}
function cleanUnwantedChars(value){
value = value.normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[\W_]+/g,"-").replace(/\-\-+/g, '-').replace(/(^-+|-+$)/g, '').toLowerCase();
return value;
}
function reverseEntities(str){
const htmlEntities = {
"&": "&",
"<": "<",
">": ">" ,
""": '"',
"'": "'"
};
//return str.replace(/([&<>\"'])/g, match => htmlEntities[match]);
return str.replace(/(\&|\<|\>|\"|\')/g, match => htmlEntities[match]);
}
function searchFilter(t, type){
const lookfor = t.value.trim().toLowerCase();
Array.from(document.getElementsByClassName('filterFamily'+type)).forEach(lbl => {
const val = lbl.attributes['data-valuetxt'].value.toLowerCase();
const reg = new RegExp('^'+lookfor+'', 'i');
if(type == 0 ){
let pass = false;
val.split(' ').forEach(word => {
if(word.match(reg)) pass = true;
});
if(pass) lbl.style.display ="";
else lbl.style.display ="none";
}else{
if(val.match(reg)){
lbl.style.display ="";
}else{
lbl.style.display ="none";
}
}
});
}
function resetCategoryFilters(t){
appliedFilters.c = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function resetSizeFilters(t){
appliedFilters.f1 = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function resetColorFilters(t){
appliedFilters.f3 = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function resetBrandFilters(t){
appliedFilters.f2 = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function resetMaterialFilters(t){
appliedFilters.f5 = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}
function resetPriceFilters(t){
appliedFilters.pf = [];
localCall("filterProducts", makeQueryParam() , msg=>showProducts(msg, t), failGetCart, "GET");
}