<?php
//This code is copyright (c) ViciSoft SL, all rights reserved.
//The contents of this file are protected under law as the intellectual property 
//of ViciSoft SL. Any use, reproduction, disclosure or copying of any kind 
//without the express and written permission of ViciSoft SL is forbidden.
//Author: Vince Reid, vincereid@gmail.com
global $catid,$seocategoryurls,$usecategoryname,$countryTaxRate,$adminProdsPerPage,$catalogroot,$sNOTSQL,$sortoptions,$dosortby,$filterpricebands,$detlinkspacechar,$explicitid,$WSP,$OWSP,$TWSP;
$showallgrplist=$idtogroup=$grouplist=$addcomma='';
$GLOBALS['alreadygotadmin']=getadminsettings();
$sSQL="SELECT sideFilter,sideFilterOrder,".getlangid("sideFilterText",262144).",adminProdsPerPage FROM admin WHERE adminID=1";
$result=ect_query($sSQL) or ect_error();
$rs=ect_fetch_assoc($result);
$sidefilterorder=$rs['sideFilterOrder'];
$sidefiltertext=explode('&',$rs[getlangid("sideFilterText",262144)]);
$adminProdsPerPage=$rs['adminProdsPerPage'];
for($index=0; $index<9; $index++)
	$sidefiltertext[$index]=str_replace('%26','&',trim_(@$sidefiltertext[$index]));
ect_free_result($result);
if(getget('cat')!='') $catid=getget('cat'); else $catid='';
if(getget('man')!='') $manid=getget('man'); else $manid='';
if(@$GLOBALS['iswordpress'] && get_query_var( 'ectcat' ) != '') $catid=urldecode(get_query_var('ectcat'));
if(@$GLOBALS['iswordpress'] && get_query_var( 'ectman' ) != '') $manid=urldecode(get_query_var('ectman'));
if(!@$GLOBALS['alreadygotattributevars']){
	$GLOBALS['numscrgroup']=$GLOBALS['numscrid']=0;
	$GLOBALS['scrid']=commaseplist(getget('scri'));
	if($GLOBALS['scrid']=='' && is_numeric(@$explicitmanid)) $GLOBALS['scrid']=@$explicitmanid;
	$GLOBALS['scridarr']=explode(',',$GLOBALS['scrid']);
	$GLOBALS['numscrid']=count($GLOBALS['scridarr']);
	for($scrindex=0; $scrindex<$GLOBALS['numscrid']; $scrindex++){
		if(strlen($GLOBALS['scridarr'][$scrindex])>10) $GLOBALS['scrid']='';
	}
	$GLOBALS['alreadygotattributevars']=TRUE;
}
$sprice=preg_replace('/[^\d\-\.]/','',getget('sprice'));
if(is_numeric(@$explicitid)) $catid=$explicitid;
if(is_numeric(@$explicitmanid)) $manid=$explicitmanid;
if(is_numeric(@$_REQUEST['sortby'])) $_SESSION['sortby']=(int)$_REQUEST['sortby'];
if(@$_SESSION['sortby']!='') $dosortby=$_SESSION['sortby'];
if(is_numeric(@$_REQUEST['perpage'])) $_SESSION['perpage']=(int)$_REQUEST['perpage'];
if(@$GLOBALS['orprodsperpage']!='') $adminProdsPerPage=$GLOBALS['orprodsperpage'];
$prodsperpage=$adminProdsPerPage;
if(@$seocategoryurls){$usecategoryname=TRUE;$catid=str_replace(@$detlinkspacechar,' ',$catid);$manid=str_replace(@$detlinkspacechar,' ',$manid);}
if(@$GLOBALS['sidefiltermoreafter']=='') $GLOBALS['sidefiltermoreafter']=8;
if(@$GLOBALS['sidefilterclosedheight']=='') $GLOBALS['sidefilterclosedheight']=150;
$TWSP="pPrice";
if(@$filterpricebands=='') $filterpricebands=100;
if(! function_exists('isidset')){
	function isidset($tid){
		if(is_numeric($GLOBALS['manid']) && $GLOBALS['manid']==$tid)
			return TRUE;
		elseif($GLOBALS['numscrid']!=0){
			for($scrindex=0; $scrindex<=$GLOBALS['numscrid']-1; $scrindex++){
				if((int)$GLOBALS['scridarr'][$scrindex]==$tid) return TRUE;
			}
		}
		return FALSE;
	}
	function pagetlike($fie,$t,$tjn){
		global $sNOTSQL;
		if(substr($t, 0, 1)=='-'){ // pSKU excluded to work around NULL problems
			if($fie!='pSKU') $sNOTSQL.=$fie." LIKE '%".substr($t, 1)."%' OR ";
		}else
			return $fie . " LIKE '%".$t."%' ".$tjn;
	}
	function pasortline($soid, $sotext){
		global $sortoptions,$dosortby;
		if(($sortoptions & pow(2,($soid-1)))!=0) print '<option value="'.$soid.'"'.($dosortby==$soid?' selected="selected"':'').'>'.$sotext.'</option>';
	}
}
if(@$usecategoryname && $catid!=''){
	$sSQL='SELECT sectionID FROM sections WHERE '.(@$seocategoryurls?getlangid('sectionurl',2048)."='".escape_string($catid)."' OR (":'').getlangid('sectionName',256)."='".escape_string($catid)."'".(@$seocategoryurls?' AND '.getlangid('sectionurl',2048)."='')":'');
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)){ $catname=$catid; $catid=$rs['sectionID']; }
	ect_free_result($result);
}
if(@$usecategoryname && $manid!=''){
	$sSQL='SELECT scID FROM searchcriteria WHERE '.getlangid('scName',131072)."='".escape_string($manid)."' ORDER BY scGroup";
	$result=ect_query($sSQL) or ect_error();
	if($rs=ect_fetch_assoc($result)){ $manname=$manid; $manid=$rs['scID']; }
	ect_free_result($result);
}
if(!is_numeric($catid)) $catid=$catalogroot;
if(is_numeric($manid) || @$manufacturers==TRUE) $manufacturers=TRUE; else{ $manufacturers=FALSE; $manid=''; }
//$sectionurl=htmlentities(strip_tags(@$seocategoryurls&&@$_SERVER['REQUEST_URI']!=''?current(explode('?',$_SERVER['REQUEST_URI'])):@$_SERVER['PHP_SELF']));
$sectionurl=htmlentities(str_replace('"','',strip_tags((@$seocategoryurls||@$GLOBALS['iswordpress'])&&@$_SERVER['REQUEST_URI']!=''?current(explode('?',$_SERVER['REQUEST_URI'])):@$_SERVER['PHP_SELF'])));
$filterurl=$manfilterurl='';
foreach(@$_GET as $objQS => $objValue){
	if(gettype($objValue)=='string' && $objQS!='mux' && $objQS!='recentview' && $objQS!='filter' && $objQS!='pg' && $objQS!='sortby' && $objQS!='perpage' && ! (($objQS=='cat' || $objQS=='man') && @$seocategoryurls)){
		$filterurl.=urlencode($objQS) . '=' . urlencode($objValue) . '&';
		if($objQS!='sman' && $objQS!='scri' && $objQS!='sprice') $manfilterurl.=urlencode($objQS) . '=' . urlencode($objValue) . '&';
	}
}
if($filterurl=='') $filterurl=$sectionurl.'?filter='; else $filterurl=$sectionurl.'?'.$filterurl.'filter=';
if($manfilterurl=='') $manfilterurl=$sectionurl.'?'; else $manfilterurl=$sectionurl.'?'.$manfilterurl;
$filtersql='';
if(getget('filter')!=''){
	$Xstext=escape_string(substr(getget('filter'), 0, 1024));
	$aText=explode(' ',$Xstext);
	$aFields[0]='products.pId';
	$aFields[1]=getlangid('pName',1);
	$aFields[2]=getlangid('pDescription',2);
	$aFields[3]=getlangid('pLongDescription',4);
	$aFields[4]='pSKU';
	$aFields[5]='pSearchParams';
	$sNOTSQL=$sYESSQL='';
	foreach($aText as $theopt){
		$tmpSQL='';
		$arrelms=count($aText);
		for($index=0;$index<=5;$index++){
			if(is_array($theopt))$theopt=$theopt[0];
			if(! ((@$nosearchdescription==TRUE && $index==2) || (@$nosearchlongdescription==TRUE && $index==3) || (@$nosearchsku==TRUE && $index==4) || (@$nosearchparams==TRUE && $index==5)))
				$tmpSQL.=pagetlike($aFields[$index], $theopt, 'OR ');
		}
		if($tmpSQL!='') $sYESSQL.= '(' . substr($tmpSQL, 0, strlen($tmpSQL)-3) . ') ';
		if($tmpSQL!='') $sYESSQL.='AND ';
	}
	$sYESSQL=substr($sYESSQL, 0, -4);
	if($sYESSQL!='') $filtersql=' AND (' . $sYESSQL . ') ';
	if($sNOTSQL!='') $filtersql.=' AND NOT (' . substr($sNOTSQL, 0, strlen($sNOTSQL)-4) . ')';
}
$GLOBALS['paminprice']=$GLOBALS['pamaxprice']='';
if($sprice!=''){
	$taxlevel=1;
	if(@$GLOBALS['showtaxinclusive']===2) $taxlevel+=($countryTaxRate/100.0);
	if(strpos($sprice,'-')!==FALSE){
		$spricearr=explode('-',$sprice);
		$GLOBALS['paminprice']=$spricearr[0];
		$GLOBALS['pamaxprice']=$spricearr[1];
		if(is_numeric($GLOBALS['pamaxprice'])){
			if(! is_numeric($GLOBALS['paminprice'])) $GLOBALS['paminprice']=0;
		}else
			$GLOBALS['pamaxprice']='';
	}elseif(is_numeric($sprice)){
		$priceband=(int)$sprice;
		$GLOBALS['paminprice']=($priceband-1)*$filterpricebands;
		$GLOBALS['pamaxprice']=$priceband*$filterpricebands;
	}
	if($GLOBALS['paminprice']!='' && $GLOBALS['pamaxprice']!='') $filtersql.=' AND ((' . $TWSP . '*'.$taxlevel.')>=' . $GLOBALS['paminprice'] . ' AND (' . $TWSP . '*'.$taxlevel.')<=' . $GLOBALS['pamaxprice'] . ')';
}
if(($GLOBALS['sidefilter'] & 1)==1 && ! $manufacturers){
	$manid=getget('sman');
	if(! is_numeric($manid)) $manid='';
}
?>
<script>
/* <![CDATA[ */
var furl="<?php print str_replace(array('<','"'),array('','\\"'),$manfilterurl)?>";
var allscri=[<?php print $GLOBALS['scrid']?>];
var scriqs='<?php print $GLOBALS['scrid']?>';
var spriceqs='<?php print $sprice?>';
var spriceset=false;
var filterqs='<?php print urlencode(getget("filter"))?>';
var allgroups=[];
function hasgotgroup(mID,gotgroups){
	for(var idind=0;idind<gotgroups.length;idind++){
		if(allgroups[mID]==gotgroups[idind]) return true;
	}
	return false;
}
function getallscr(mID,doadd,allowdupgroup){
	var rettxt='';
	var gotgroups=[];
	gotgroups.push(allgroups[mID]);
	for(var idind=0;idind<allscri.length;idind++){
		if(allowdupgroup||!hasgotgroup(allscri[idind],gotgroups)){
			if(doadd||mID!=allscri[idind])rettxt+=','+allscri[idind];
		}
	}
	return rettxt.substring(1);
}
function ectRAm(mID,addcurrid,removegroup){
	var currscr=getallscr(mID,addcurrid,!removegroup);
	var filter=getfilterqs();
	if(addcurrid) currscr=mID+(currscr!=''?','+currscr:'');
	var newurl=furl+(currscr!=''?'scri='+currscr+'&':'')+getpriceqs()+(filter!=''?'filter='+encodeURIComponent(filter)+'&':'');
	document.location=newurl.substring(0,newurl.length-1);
	return false;
}
<?php	if(@$GLOBALS['sidefiltermorestyle']=='mouseover'){ ?>
function ectMOtGrpTr(grpid){
	var currheight=parseInt(document.getElementById('ectpatgrp'+grpid).style.maxHeight.replace(/px/,''));
	if(isNaN(currheight)) return;
	if(currheight><?php print $GLOBALS['sidefilterclosedheight']?>){
		document.getElementById('ectpatgrp'+grpid).style.maxHeight=(currheight-2)+'px';
		setTimeout("ectMOtGrpTr('"+grpid+"');",10);
	}else
		document.getElementById('grpMore'+grpid).style.display='';
}
function ectMOtGrp(tobj,grpid){
tobj.style.maxHeight=tobj.offsetHeight+'px';
setTimeout("ectMOtGrpTr('"+grpid+"');",100);
}
function ectMOGrp(tobj,grpid){
document.getElementById('grpMore'+grpid).style.display='none';
tobj.style.maxHeight='none';
}
<?php	} ?>
var timerid;
function adjustprice(ismaxprice,isincrease){
	spriceset=true;
	doadjustprice(ismaxprice,isincrease);
	timerid=setInterval('doadjustprice('+ismaxprice+','+isincrease+')',100);
}
function stopprice(){
	clearInterval(timerid);
}
function doadjustprice(ismaxprice,isincrease){
	var minprice=parseInt(document.getElementById('paminprice').value);
	var maxprice=parseInt(document.getElementById('pamaxprice').value);
	var origmaxprice=parseInt(document.getElementById('origmaxprice').value);
	var addamount;
	if(isNaN(minprice))minprice=0;
	if(isNaN(maxprice))maxprice=origmaxprice;
	if(maxprice-minprice>100000)addamount=10000;
	if(maxprice-minprice>10000)addamount=1000;
	else if(maxprice-minprice>1000)addamount=100;
	else if(maxprice-minprice>100)addamount=10;
	else if(maxprice-minprice>50)addamount=5;
	else addamount=1;
	if(ismaxprice){
		maxprice=Math.max(isincrease?maxprice+addamount:maxprice-addamount,0);
		document.getElementById('pamaxprice').value=maxprice;
		if(maxprice<minprice)document.getElementById('paminprice').value=maxprice;
	}else{
		minprice=Math.max(isincrease?minprice+addamount:minprice-addamount,0);
		document.getElementById('paminprice').value=minprice;
		if(maxprice<minprice)document.getElementById('pamaxprice').value=minprice;
	}
}
function getpriceqs(){
	var newurl='';
	if(spriceset&&document.getElementById('paminprice')){
		var minprice=parseFloat(document.getElementById('paminprice').value);
		var maxprice=parseFloat(document.getElementById('pamaxprice').value);
		if(!isNaN(minprice))
			newurl+='sprice='+minprice+'-'+(isNaN(maxprice)?'':maxprice)+'&';
	}else if(spriceqs!='')
		newurl+='sprice='+spriceqs+'&';
	return(newurl);
}
function getfilterqs(){
	return document.getElementById('paectfilter')?document.getElementById('paectfilter').value:''
}
function filtergo(){
	var newurl='';
	var filter=getfilterqs();
	if(scriqs!='')newurl+='scri='+scriqs+'&';
	newurl+=getpriceqs();
	if(filter!='')newurl+='filter='+encodeURIComponent(filter)+'&';
	document.location=furl+newurl.substring(0,newurl.length-1);
	return false;
}
function changesflocation(fact,tobj){
document.location='<?php print $filterurl?>'.replace(/filter=/,fact+'='+tobj[tobj.selectedIndex].value<?php if(($GLOBALS['sidefilter'] & 32)==32) print "+(getfilterqs()!=''?'&filter='+encodeURIComponent(getfilterqs()):'')" ?>);
}
function changesffiltertext(tkeycode,tobj){
if(tkeycode==13)document.location='<?php print $filterurl?>'+tobj.value;
}
/* ]]> */
</script>
<?php
if($catid!=$catalogroot) $sectionids=getsectionids($catid, FALSE); else $sectionids='';
if(@$sidefilterorder=='') $sidefilterorder='2,4,8,16,32';
$filterorderarray=explode(',',$sidefilterorder);
if(($GLOBALS['sidefilter'] & 2)==2 && !@$GLOBALS['alreadycheckedscsql']){
	$GLOBALS['numscrid']=0;
	$GLOBALS['numscrgroup']=0;
	if($GLOBALS['scrid']!=''){
		$currgroup=-1;
		$GLOBALS['scSQL']='(multisearchcriteria.mSCscID IN (';
		$sSQL='SELECT scID,scGroup,'.getlangid('scName',131072).' FROM searchcriteria WHERE scID IN (' . $GLOBALS['scrid'] . ') ORDER BY scGroup';
		$result=ect_query($sSQL) or ect_error();
		$GLOBALS['scrid']='';
		$GLOBALS['removalbuttons']='';
		while($rs=ect_fetch_assoc($result)){
			$GLOBALS['scrid'].=$rs['scID'].',';
			$GLOBALS['removalbuttons'].='<button class="ectbutton removefilter" onclick="ectRAm(' . $rs['scID'] . ',false,false)">' . $rs[getlangid('scName',131072)] . '</button> ';
			if($rs['scGroup']!=$currgroup){
				$addcomma='';
				if($currgroup!=-1) $GLOBALS['scSQL'].=') AND msc'.$GLOBALS['numscrgroup'].'.mSCscID IN (';
				$GLOBALS['numscrgroup']++;
				$currgroup=$rs['scGroup'];
			}
			$GLOBALS['scSQL'].=$addcomma.$rs['scID'];
			$addcomma=',';
		}
		if($GLOBALS['scrid']!=''){
			$GLOBALS['scrid']=rtrim($GLOBALS['scrid'],',');
			$GLOBALS['scridarr']=explode(',',$GLOBALS['scrid']);
			$GLOBALS['numscrid']=count($GLOBALS['scridarr']);
		}
		if($GLOBALS['numscrid']==0) $GLOBALS['scSQL']=''; else $GLOBALS['scSQL'].='))';
	}else
		$GLOBALS['scSQL']='';
	$GLOBALS['alreadycheckedscsql']=TRUE;
}
for($indexfilterorder=0; $indexfilterorder<count($filterorderarray); $indexfilterorder++){
	switch($filterorderarray[$indexfilterorder]){
	case 2:
	if(($GLOBALS['sidefilter'] & 2)==2){ // Product Attributes
		if(! @$GLOBALS['hascheckedectfilters']){
			$sSQL='SELECT COUNT(DISTINCT products.pID) as tcount,scID,'.getlangid('scName',131072).',scGroup,scOrder,scgTitle FROM (searchcriteria INNER JOIN searchcriteriagroup ON searchcriteria.scGroup=searchcriteriagroup.scgID) ' .
				'INNER JOIN multisearchcriteria ON multisearchcriteria.mSCscID=searchcriteria.scID ' . (@$GLOBALS['displayzeroattributes']?'LEFT':'INNER') . ' JOIN (products'.($sectionids!=''?' LEFT JOIN multisections ON products.pId=multisections.pId':'').') ON multisearchcriteria.mSCpID=products.pID ' .
				(@$GLOBALS['displayzeroattributes']?'AND':'WHERE') . ' pDisplay<>0' . (@$GLOBALS['ectsiteid']!='' ? ' AND pSiteID='.$GLOBALS['ectsiteid'] : '');
			if(@$GLOBALS['customproductsearch']!='') $sSQL.=' AND ' . $GLOBALS['customproductsearch'];
			if($manid!='0' && is_numeric($manid)) $sSQL.=' AND pManufacturer=' . $manid;
			if($GLOBALS['useStockManagement'] && @$GLOBALS['noshowoutofstock']) $sSQL.=' AND pInStock>pMinQuant';
			if($sectionids!='') $sSQL.=' AND (products.pSection IN ('.$sectionids.') OR multisections.pSection IN ('.$sectionids.'))';
			$sSQL.=$filtersql.' AND (multisearchcriteria.mSCpID IN (' . "\r\n" . 'SELECT products.pID FROM ';
			if($GLOBALS['numscrid']>1) $sSQL.=str_repeat('(',$GLOBALS['numscrid']-1);
			$sSQL.='(products'.($sectionids!=''?' LEFT JOIN multisections ON products.pId=multisections.pId':'').')' . ($GLOBALS['scrid']!=''?' INNER JOIN multisearchcriteria ON multisearchcriteria.mSCpID=products.pID':'');
			for($scrindex=1; $scrindex<=$GLOBALS['numscrid']-1; $scrindex++){
				$sSQL.=') INNER JOIN multisearchcriteria msc'.$scrindex.' ON products.pID=msc'.$scrindex.'.mSCpID';
			}
			$sSQL.=' WHERE 1=1';
			if(@$GLOBALS['customproductsearch']!='') $sSQL.=' AND ' . $GLOBALS['customproductsearch'];
			if($manid!='0' && is_numeric($manid)) $sSQL.=' AND pManufacturer=' . $manid;
			if(@$GLOBALS['scSQL']!='') $sSQL.=' AND ' . $GLOBALS['scSQL'];
			$sSQL.=')'."\r\n".($GLOBALS['numscrid']>0?' OR scGroup=0':'').') GROUP BY scID,'.getlangid('scName',131072).',scGroup,scOrder,scgOrder,scgTitle ORDER BY scgOrder,scGroup,scOrder,'.getlangid('scName',131072);
		//print '<div style="position:absolute;top:-60px;width:800px;background:#FFFFFF;padding:30px">' . $GLOBALS['scSQL'] . '<br><br>' . $sSQL . '</div>';
			$result2=ect_query($sSQL) or ect_error();
			$GLOBALS['nectfiltercache']=0;
			while($rs2=ect_fetch_assoc($result2))
				$GLOBALS['ectfiltercache'][$GLOBALS['nectfiltercache']++]=$rs2;
			ect_free_result($result2);
		}
		$GLOBALS['hascheckedectfilters']=TRUE;
		$currgroupid=-1;
		$showallgrplist=$idtogroup=$grouplist=$addcomma='';
		$hasids='|';
		$outtxt='';
		$lastgroupid=0;
		$filternumber=0;
		$morebuttondisplayed=FALSE;
		if(@$GLOBALS['removalfilterbuttons']) print @$GLOBALS['removalbuttons'];
		if($GLOBALS['nectfiltercache']>0){
			for($cacheindex=0; $cacheindex<$GLOBALS['nectfiltercache']; $cacheindex++){
				$idtogroup.=$addcomma.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].":".$GLOBALS['ectfiltercache'][$cacheindex]['scGroup'];
				$idisset=isidset($GLOBALS['ectfiltercache'][$cacheindex]['scID']);
				if($GLOBALS['ectfiltercache'][$cacheindex]['scGroup']!=$currgroupid){
					if($morebuttondisplayed){
						$outtxt.='</div>';
						$morebuttondisplayed=FALSE;
					}
					$filternumber=0;
					$currgroupid=$GLOBALS['ectfiltercache'][$cacheindex]['scGroup'];
					$grouplist.=$addcomma.$currgroupid;
					if($outtxt!='') print $outtxt . "</div></div>\n";
					$outtxt='';
					print '<div id="ectpatgrp'.$currgroupid.'" class="ectpatgrp"';
					if(@$GLOBALS['sidefiltermorestyle']=='mouseover') print ' onmouseover="ectMOGrp(this,'.$currgroupid.')" onmouseout="ectMOtGrp(this,'.$currgroupid.')" style="max-height:'.$GLOBALS['sidefilterclosedheight'].'px;overflow-y:hidden;position:relative"';
					print '><div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . $GLOBALS['ectfiltercache'][$cacheindex]['scgTitle'] . '<span id="showallgrp'.$currgroupid.'" style="display:none" title="' . $GLOBALS['xxSFClea'] . '"> (<a href="#" onclick="return ectRAm('.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].',false,true)">' . @$GLOBALS['xxSFAll'] . '</a>)</span></div><div class="ectpatfilters">' . "\n";
					if(@$GLOBALS['sidefiltermorestyle']=='mouseover') print '<div id="grpMore'.$currgroupid.'" class="moreattributes" style="width:100%;position:absolute;bottom:0;left:0;text-align:center;background-color:#A0A0B0;border:1px solid black;box-sizing:border-box;-moz-box-sizing:border-box">'.$GLOBALS['xxSFMore'].'</div>' . "\n";
				}
				if($filternumber==$GLOBALS['sidefiltermoreafter'] && @$GLOBALS['sidefiltermorestyle']!='none' && @$GLOBALS['sidefiltermorestyle']!='mouseover'){
					if($GLOBALS['nectfiltercache']-$cacheindex>3){
						if($GLOBALS['ectfiltercache'][$cacheindex+3]['scGroup']==$currgroupid){
							$outtxt.='<div class="grpMoreDiv" id="grpMoreDiv'.$currgroupid.'">' . imageorbutton(@$GLOBALS['imgsidefiltermore'],$GLOBALS['xxSFMobu'],'sidefiltermore','hidesfmorebutton('.$currgroupid.')',TRUE) . '</div><div id="grpMoreLnk'.$currgroupid.'" style="display:none">';
							$morebuttondisplayed=TRUE;
						}
					}
				}
				if($idisset) $showallgrplist.=",".$currgroupid;
				if(@$GLOBALS['sidefilterstyle']=='multiple')
					$outtxt.='<div class="ectpatcb' . ($idisset?'set':'') . ($GLOBALS['ectfiltercache'][$cacheindex]['tcount']<=0?' zeroatt':'') . '"><label style="cursor:pointer"><input type="checkbox" class="ectpatcb ectpatcbsf" onchange="ectRAm('.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].','.($idisset?'false':'true').',false)" '.($idisset?'checked="checked" ':'').'/> ' . $GLOBALS['ectfiltercache'][$cacheindex][getlangid('scName',131072)] . (! $idisset && $GLOBALS['ectfiltercache'][$cacheindex]['tcount']>0?'<div class="ectpacount">('.$GLOBALS['ectfiltercache'][$cacheindex]['tcount'].')</div>':'') . "</label></div>\n";
				elseif(@$GLOBALS['sidefilterstyle']=='selectmenu')
					$outtxt.='<option value="'.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].'"'.($GLOBALS['ectfiltercache'][$cacheindex]['scID']==$GLOBALS['scrid']?' selected="selected"':'').">" . htmlspecials($GLOBALS['ectfiltercache'][$cacheindex][getlangid('scName',131072)]) . "</option>\n";
				else
					$outtxt.='<div class="ectpat'.($idisset?'set':'') . ($GLOBALS['ectfiltercache'][$cacheindex]['tcount']<=0?' zeroatt':'') .'"'.(! $idisset?' onclick="ectRAm('.$GLOBALS['ectfiltercache'][$cacheindex]['scID'].',true,true)"':'').'>' . $GLOBALS['ectfiltercache'][$cacheindex][getlangid('scName',131072)] . (! $idisset && $GLOBALS['ectfiltercache'][$cacheindex]['tcount']>0?'<div class="ectpacount">('.$GLOBALS['ectfiltercache'][$cacheindex]['tcount'].')</div>':'') . "</div>\n";
				$addcomma=",";
				$lastgroupid=$GLOBALS['ectfiltercache'][$cacheindex]['scGroup'];
				$filternumber++;
			}
		}else
			$GLOBALS['sidefilter']-=2;
		if($morebuttondisplayed) $outtxt.='</div>';
		if($outtxt!='') print $outtxt . "</div></div>\n";
	}
	break;
	case 4:
	if(($GLOBALS['sidefilter'] & 4)==4){ // Price bands
		$GLOBALS['setpaminprice']=@$GLOBALS['paminprice'];
		$GLOBALS['setpamaxprice']=@$GLOBALS['pamaxprice'];
		$sSQL="SELECT MAX(" . $TWSP . ") AS maxprice,MIN(" . $TWSP . ') AS minprice FROM products WHERE ' . (@$GLOBALS['ectsiteid']!='' ? 'pSiteID='.$GLOBALS['ectsiteid'].' AND ' : '') . 'pDisplay<>0';
		if($sectionids!='') $sSQL="SELECT MAX(" . $TWSP . ") AS maxprice,MIN(" . $TWSP . ') AS minprice FROM (products LEFT JOIN multisections ON products.pId=multisections.pId) WHERE ' . (@$GLOBALS['ectsiteid']!='' ? 'pSiteID='.$GLOBALS['ectsiteid'].' AND ' : '') . 'pDisplay<>0 AND (products.pSection IN ('.$sectionids.") OR multisections.pSection IN (" . $sectionids . "))";
		$result2=ect_query($sSQL) or ect_error();
		if($rs2=ect_fetch_assoc($result2)){
			if(! is_null($rs2['maxprice'])){
				$GLOBALS['pamaxprice']=$rs2['maxprice']; $GLOBALS['paminprice']=$rs2['minprice'];
				if(@$GLOBALS['showtaxinclusive']===2){ $GLOBALS['pamaxprice']+=$GLOBALS['pamaxprice']*($countryTaxRate/100.0); $GLOBALS['paminprice']+=$GLOBALS['paminprice']*($countryTaxRate/100.0); }
			}
		}
		ect_free_result($result2);
		if(@$GLOBALS['paminprice']=='') $GLOBALS['paminprice']=0;
		if(@$GLOBALS['pamaxprice']=='') $GLOBALS['pamaxprice']=1;
		$GLOBALS['paminprice']=(int)$GLOBALS['paminprice'];
		$GLOBALS['pamaxprice']=ceil($GLOBALS['pamaxprice']);
		if($GLOBALS['setpaminprice']=='') $GLOBALS['setpaminprice']=@$GLOBALS['paminprice'];
		if($GLOBALS['setpamaxprice']=='') $GLOBALS['setpamaxprice']=@$GLOBALS['pamaxprice'];
		if(!@$GLOBALS['useoldsidefilterprice']){
			print '<div id="ectpatgrpPRICE" class="ectpatgrp" style="overflow:auto"><div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . @$sidefiltertext[2] . ($sprice!=''?'<span id="showallgrpPRI" title="' . $GLOBALS['xxSFClea'] . '"> (<a href="#" onclick="document.getElementById(\'paminprice\').value=\'\';document.getElementById(\'pamaxprice\').value=\'\';spriceset=true;return filtergo()">' . @$GLOBALS['xxSFAll'] . '</a>)</span>':'') . '</div>' . "\n";
			$rowcounter=2;
			$currpriceband=getget("sprice"); ?>
	<div class="ectpatfilters">
		<input type="hidden" id="origmaxprice" value="<?php print $GLOBALS['pamaxprice']?>">
		<div class="sfpriceinputs">
			<div><input class="ecttextinput" id="paminprice" type="text" onchange="updatesfpricetext(this)" value="<?php print $GLOBALS['setpaminprice']?>" placeholder="Min Price" aria-label="Min Price"></div>
			<div><input class="ecttextinput" id="pamaxprice" type="text" onchange="updatesfpricetext(this)" value="<?php print $GLOBALS['setpamaxprice']?>" placeholder="Max Price" aria-label="Max Price"></div>
		</div>
		<div class="sfslidercontainer"><div id="sliderdiv"></div></div>
		<div class="sfrangesliders" onmousemove="checkzindex(event,this)">
			<input type="range" oninput="updatesfpriceslider(this)" id="pricerangemin" min="<?php print $GLOBALS['paminprice']?>" max="<?php print $GLOBALS['pamaxprice']?>" value="<?php print $GLOBALS['setpaminprice']?>" step="1">
			<input type="range" oninput="updatesfpriceslider(this)" id="pricerangemax" min="<?php print $GLOBALS['paminprice']?>" max="<?php print $GLOBALS['pamaxprice']?>" value="<?php print $GLOBALS['setpamaxprice']?>" step="1">
		</div>
		<div style="padding:10px 2px;margin-top:10px">
			<input type="button" class="ectbutton sidefilter sidefiltergo" value="<?php print $GLOBALS['xxGo']?>" onclick="filtergo()" style="width:100%">
		</div>
	</div>
<script>
updatesfpriceslider(ectById('pricerangemax'));
</script>
<?php		print "</div>\n";
		}else{
			print '<div id="ectpatgrpPRICE" class="ectpatgrp" style="overflow:auto"><div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . @$sidefiltertext[2] . ($sprice!=''?'<span id="showallgrpPRI" title="' . $GLOBALS['xxSFClea'] . '"> (<a href="#" onclick="document.getElementById(\'paminprice\').value=\'\';document.getElementById(\'pamaxprice\').value=\'\';spriceset=true;return filtergo()">' . @$GLOBALS['xxSFAll'] . '</a>)</span>':'') . (@$GLOBALS['sfpricebuttoninline']?'':' /  <input type="button" class="ectbutton sidefilter sidefiltergo" value="' . $GLOBALS['xxGo'] . '" onclick="filtergo()" />') . '</div>' . "\n";
			$rowcounter=2;
			$currpriceband=getget("sprice"); ?>
	<div class="ectpatfilters">
		<div style="display:table;margin-top:4px;width:100%">
			<div style="width:50%;text-align:center;display:table-cell">
				<div>
					<input class="ecttextinput sfprice" id="paminprice" type="text" onchange="spriceset=true" value="<?php print $GLOBALS['paminprice']?>" placeholder="Min Price" aria-label="Min Price">
				</div>
				<div>
					<img src="images/buttondec.png" onmousedown="adjustprice(false,false)" onmouseup="stopprice()" onmouseout="stopprice()" alt="" /><img src="images/buttoninc.png" onmousedown="adjustprice(false,true)" onmouseup="stopprice()" onmouseout="stopprice()" alt="">
				</div>
			</div>
			<div style="width:50%;text-align:center;display:table-cell">
				<div>
					<input type="hidden" id="origmaxprice" value="<?php print $GLOBALS['pamaxprice']?>">
					<input class="ecttextinput sfprice" id="pamaxprice" type="text" onchange="spriceset=true" value="<?php print $GLOBALS['pamaxprice']?>" placeholder="Max Price" aria-label="Max Price">
				</div>
				<div>
					<img src="images/buttondec.png" onmousedown="adjustprice(true,false)" onmouseup="stopprice()" onmouseout="stopprice()" alt=""><img src="images/buttoninc.png" onmousedown="adjustprice(true,true)" onmouseup="stopprice()" onmouseout="stopprice()" alt="">
				</div>
			</div>
<?php		if(@$GLOBALS['sfpricebuttoninline']){ ?>
			<div style="display:table-cell;vertical-align:middle;padding:2px">
				<input type="button" class="ectbutton sidefilter sidefiltergo" value="<?php print $GLOBALS['xxGo']?>" onclick="filtergo()">
			</div>
<?php		} ?>
		</div>
	</div>
<?php		print "</div>\n";
		}
	}
	break;
	case 8:
	if(($GLOBALS['sidefilter'] & 8)==8){ // Sort Order
		print '<div class="ectpatgrp">';
		if(@$sidefiltertext[3]!='') print '<div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . $sidefiltertext[3] . "</div>\n";
		print '<div class="ectpatfilters">';
		?><select class="ectselectinput sidefilter" size="1" onchange="changesflocation('sortby',this)">
		<option value="0"><?php print $GLOBALS['xxPlsSel']?></option>
<?php	pasortline(1, @$GLOBALS['sortoption1']!=''?$GLOBALS['sortoption1']:'Sort Alphabetically');
		pasortline(11, @$GLOBALS['sortoption11']!=''?$GLOBALS['sortoption1']:'Alphabetically (Desc.)');
		pasortline(2, @$GLOBALS['sortoption2']!=''?$GLOBALS['sortoption2']:'Sort by Product ID');
		pasortline(12, @$GLOBALS['sortoption12']!=''?$GLOBALS['sortoption12']:'Product ID (Desc.)');
		pasortline(14, @$GLOBALS['sortoption14']!=''?$GLOBALS['sortoption14']:'Sort By SKU');
		pasortline(15, @$GLOBALS['sortoption15']!=''?$GLOBALS['sortoption15']:'Sort By SKU (Desc.)');
		pasortline(3, @$GLOBALS['sortoption3']!=''?$GLOBALS['sortoption3']:'Sort Price (Asc.)');
		pasortline(4, @$GLOBALS['sortoption4']!=''?$GLOBALS['sortoption4']:'Sort Price (Desc.)');
		pasortline(5, @$GLOBALS['sortoption5']!=''?$GLOBALS['sortoption5']:'Database Order');
		pasortline(6, @$GLOBALS['sortoption6']!=''?$GLOBALS['sortoption6']:'Product Order');
		pasortline(7, @$GLOBALS['sortoption7']!=''?$GLOBALS['sortoption7']:'Product Order (Desc.)');
		pasortline(8, @$GLOBALS['sortoption8']!=''?$GLOBALS['sortoption8']:'Date Added (Asc.)');
		pasortline(9, @$GLOBALS['sortoption9']!=''?$GLOBALS['sortoption9']:'Date Added (Desc.)');
		pasortline(10, @$GLOBALS['sortoption10']!=''?$GLOBALS['sortoption10']:'Sort by Manufacturer');
		pasortline(16, @$GLOBALS['sortoption16']!=''?$GLOBALS['sortoption16']:'Number of Ratings');
		pasortline(17, @$GLOBALS['sortoption17']!=''?$GLOBALS['sortoption17']:'Average Rating');
		pasortline(18, @$GLOBALS['sortoption18']!=''?$GLOBALS['sortoption18']:'Sales Rank');
		pasortline(19, @$GLOBALS['sortoption19']!=''?$GLOBALS['sortoption19']:'Popularity');
?>		</select><?php
		print "</div></div>\n";
	}
	break;
	case 16:
	if(($GLOBALS['sidefilter'] & 16)==16){
		print '<div class="ectpatgrp">';
		if(@$sidefiltertext[4]!='') print '<div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . $sidefiltertext[4] . '</div>';
		print '<div class="ectpatfilters">';
		?><select class="ectselectinput sidefilter" size="1" onchange="changesflocation('perpage',this)">
<?php	for($index=1; $index<=5; $index++){
			print '<option value="'.$index.'"'.(@$_SESSION['perpage']==$index?' selected="selected"':'').'>'.($prodsperpage*$index).' '.$GLOBALS['xxPerPag'].'</option>';
		}
?>			  </select><?php
		print "</div></div>\n";
	}
	break;
	case 32:
	if(($GLOBALS['sidefilter'] & 32)==32){
		print '<div class="ectpatgrp">';
		if(@$sidefiltertext[5]!='') print '<div class="ectpattitle" style="font-weight:bold;margin-top:5px">' . $sidefiltertext[5] . '</div>';
		print '<div class="ectpatfilters"><div style="display:table;width:100%"><div style="display:table-row"><div style="display:table-cell"><input onkeydown="changesffiltertext(event.keyCode,this)" type="text" class="ecttextinput sidefilter" style="width:100%;box-sizing:border-box" id="paectfilter" name="pafilter" value="'.htmlspecials(getget('filter')).'" placeholder="' . $GLOBALS['xxSeaFil'] . '" aria-label="' . $GLOBALS['xxSeaFil'] . '"></div><div style="display:table-cell;padding-left:5px">' . imageorbutton(@$imgfilterproducts,'&raquo;','sidefilter sidefiltergo','filtergo()',TRUE) . '</div></div></div></div>';
		print "</div>\n";
	}
	break;
	}
}
$GLOBALS['alreadycalculatedattributes']=TRUE;
?>
<script>
/* <![CDATA[ */
var idtogroup='<?php print $idtogroup?>';
var grouplist='<?php print $grouplist?>';
var showallgrplist='<?php print $showallgrplist?>';
var idarr=idtogroup.split(',');
var grouparr=grouplist.split(',');
var showallgrparr=showallgrplist.split(',');
var ECTinGrp=[];
function setgrpHght(grpId,numInGrp){
	document.getElementById('grpMore'+grpId).style.width=document.getElementById('ectpatgrp'+grpId).offsetWidth+'px';
	if(numInGrp<<?php print $GLOBALS['sidefiltermoreafter']?>){
		document.getElementById('grpMore'+grpId).style.display='none';
		document.getElementById('ectpatgrp'+grpId).style.maxHeight='none';
		document.getElementById('ectpatgrp'+grpId).onmouseover=null;
		document.getElementById('ectpatgrp'+grpId).onmouseout=null;
	}
}
for(var idind=0;idind<idarr.length;idind++){
	allgroups[idarr[idind].split(':')[0]]=idarr[idind].split(':')[1];
	if(ECTinGrp[idarr[idind].split(':')[1]])ECTinGrp[idarr[idind].split(':')[1]]++; else ECTinGrp[idarr[idind].split(':')[1]]=1;
}
<?php	if(@$GLOBALS['sidefiltermorestyle']=='mouseover'){  ?>
for(var idind=0;idind<grouparr.length;idind++){
	if(grouparr[idind]!='')setgrpHght(grouparr[idind],ECTinGrp[grouparr[idind]]);
}
<?php	}elseif(@$GLOBALS['sidefiltermorestyle']!='none'){ ?>
function hidesfmorebutton(tid){
	document.getElementById('grpMoreDiv'+tid).style.display='none';
	document.getElementById('grpMoreLnk'+tid).style.display='';
	return false;
}
<?php	} ?>
for(var idind=0;idind<showallgrparr.length;idind++){
	if(showallgrparr[idind]!='') document.getElementById('showallgrp'+showallgrparr[idind]).style.display='';
}
/* ]]> */
</script>
