var sFilterURL = '/monstercms/frontend/includes/prodajax.asp'
var sFilterPostValues, sFilterTimer, sFilterTimer2, iFilterPageNumber;
function filterProducts(bUpdatePageNumber) {
	o1 = document.forms['prodfilter'].pagenum;
	if(bUpdatePageNumber) {
		if(o1){iFilterPageNumber=o1.value}
	}else{
		iFilterPageNumber=1
	}
	if(sFilterTimer) {
		clearTimeout(sFilterTimer);
	}
	if(sFilterTimer2){
		clearTimeout(sFilterTimer2);	
	}
	oProdHolder = document.getElementById('idProductHolder');
	oProdHider = document.getElementById('idProdHider');
	oProdLoader = document.getElementById('idProdLoader');
	if(oProdHolder&&oProdHider&&oProdLoader) {
		oGroup = document.getElementsByName('filtergroup');
		iSelectedGroupCount=0;
		sGroups = '';
		for(x=0;x<oGroup.length;x++) {
			if(oGroup[x].checked){
				if(iSelectedGroupCount>0){sGroups+=',';}
				sGroups+=oGroup[x].value;
				iSelectedGroupCount++;
			}
		}
		iWidth = oProdHolder.offsetWidth;
		iHeight = oProdHolder.offsetHeight;
		//fix issue for browsers other than IE
		if(iWidth==0){iWidth=716;}
		if(iHeight==0){iHeight = document.body.clientHeight-345;}
		oProdHider.style.width=iWidth+'px';
		oProdHider.style.height=iHeight+'px';
		oProdLoader.style.display='';
		oProdHider.style.display='';
		oForm = document.prodfilter
		iCatID = oForm.catid.value;
		if(sAdvancedSearchExtraValues){
			sFilterPostValues = 'c='+iCurrentCategory+sAdvancedSearchExtraValues+'&group='+sGroups+'&_pg='+iFilterPageNumber+'&ajax=true'
		}else if(sSearchString) {
			sFilterPostValues = 'c='+iCurrentCategory+'&q='+sSearchString+'&group='+sGroups+'&_pg='+iFilterPageNumber+'&ajax=true'
		}else{
			sFilterPostValues = 'catid='+iCatID+'&group='+sGroups+'&_pg='+iFilterPageNumber+'&ajax=true'	
		}
		sFilterTimer = setTimeout("doFilter()",1000);
	}
}
function doFilter() {
	oProdHolder = document.getElementById('idProductHolder');
	oProdHider = document.getElementById('idProdHider');
	oProdLoader = document.getElementById('idProdLoader');
	sHTML = readFileInAsync(sFilterURL, true, sFilterPostValues)
	oProdHolder.innerHTML = sHTML;
	tb_init('a.thickbox, area.thickbox, input.thickbox');
	sFilterTimer2 = setTimeout("oProdLoader.style.display='none';oProdHider.style.display='none';",100)
}

function checkFilterSizes() {
	iSelectedGroupCount=0;
	oGroup = document.getElementsByName('filtergroup');
	for(x=0;x<oGroup.length;x++) {
		if(oGroup[x].checked){
			iSelectedGroupCount++;
		}
	}
	if(oGroup.length>iSelectedGroupCount&&iSelectedGroupCount>0){
		filterProducts();
	}
}
var sSearchString;
var iCurrentCategory;
var sAdvancedSearchExtraValues='';
function searchWithFilter(q,c,hg,g,pg) {
	iFilterPageNumber = 1;
	o1 = document.forms['prodfilter'].pagenum;
	if(o1){iFilterPageNumber=o1.value}
	sSearchString = q.replace(/ /g,'+');
	iCurrentCategory = c;
	oGroup = document.getElementsByName('filtergroup');
	iSelectedGroupCount=0;
	sGroups = '';
	for(x=0;x<oGroup.length;x++) {
		if(oGroup[x].checked){
			if(iSelectedGroupCount>0){sGroups+=',';}
			sGroups+=oGroup[x].value;
			iSelectedGroupCount++;
		}
	}
	sExtraValues = '';
	if(hg&&g){
		sAdvancedSearchExtraValues = '&hg='+hg+'&g='+g+'&pg='+pg;	
	}
	sFilterPostValues = 'c='+iCurrentCategory+'&q='+sSearchString+sAdvancedSearchExtraValues+'&group='+sGroups+'&_pg='+iFilterPageNumber+'&ajax=true'
	sFilterTimer = setTimeout("doFilter()",1000);
}
function GoToPage(iPage) {
	o1 = document.forms['prodfilter'].pagenum;
	if(o1) {
		o1.value=iPage;
	}
	filterProducts(true);
}
