//************************************************************************//
//   QShop E-Commerce Solutions                                           //
//   Copyright @ VISUAL TECHNOLOGIES INC  2002-2007                       //
//   http://qshop.com.pl qshop@qshop.com.pl                               //
//************************************************************************//
//   This software is copyrighted, do not attempt to copy                 //
//   without permission                                                   //
//************************************************************************//
// obsługa filtrowania dla pól własnych z subiekta
function statlow_change(linkx) {
	var opt = '';
	var opt1 = '';
	error = 0;
	error_no_change = 0;
	for(i=1;i<=10;i++) {
		try {
			val = document.getElementById('opt_val1_'+i).value;	
			if(val!='') {
				minx = (document.getElementById('opt_val1_'+i).value);
				maxx = (document.getElementById('opt_val2_'+i).value);
				al = document.getElementById('opt_valx_'+i).value.split('|');
				pole = al[0];
				ac = al[1].split('-');
				wart_min = (ac[0]);
				wart_max = (ac[1]);
				if(isNaN(minx)||isNaN(maxx)) {
					error++;
					alert("W pole o nazwie "+pole+" proszę wpisywać tylko liczby");
				}
				if(minx==0||maxx==0) {
					error++;
					alert("W polu o nazwie "+pole+" brakuje wartości");
				}
				if(minx<wart_min) {
					error++;
					alert("W polu o nazwie "+pole+" wartość minimalna jest za mała, musi wynosić minimum:"+wart_min);
				}
				if(minx>maxx) {
					error++;
					alert("W polu o nazwie "+pole+" wartość minimalna nie może być większa niż maksymalna");	
				}
				opt+= " options"+i+">='"+val+"' and options"+i+"<='"+maxx+"' and";
				opt1+= " options"+i+"='"+val+'-'+maxx+"' and";
			}
		}
		catch(Ec) {
			
		}
	}
	for(i=1;i<=10;i++) {
		try {
			val = document.getElementById('stat_low'+i).value;
			if(val!='') {
				if(val.indexOf('|')>0) {
					valx = val.split('|');
					val = val.replace('|','');
					opt+= " options"+i+">="+valx[0]+" and options"+i+"<="+valx[1]+" and";
					opt1+= " options"+i+"='"+valx[0]+"-"+valx[1]+"' and";
				} else {
					opt+= " options"+i+"='"+val+"' and";
					opt1+= " options"+i+"='"+val+"' and";	
				}
			}
		}
		catch(Ex) {
			val = '';
		}
	}
	if(error==0) {
		document.getElementById('clear_filter_link').innerHTML = 'Proszę czekać...';
		if(opt!="") {
			http.open('get', '_classes/__fields_submited.php?action=add&paramxx='+opt+'&paramxy='+opt1+'&linky='+linkx.replace('&','|'));
			http.onreadystatechange = statlow_response;
			http.send(null);
		} else {
			statlow_change_all(linkx);
			//alert("Proszę wybrać opcje do filtrowania !");	
		}
	}
}
function statlow_response() {
	if(http.readyState == 4){
		var response = http.responseText;
		document.location.href = 'category.php?'+response.replace('|','&')+FILTERS_URL_PARAMX+FILTERS_URL_PARAMY;
    }
}
function statlow_change_all(linkx) {
	document.getElementById('clear_filter_link').innerHTML = 'Proszę czekać...';
	http.open('get', '_classes/__fields_submited.php?action=remove&linky='+linkx.replace('&','|'));
	http.onreadystatechange = statlow_response;
	http.send(null);
}
function statlow_keydown(linkres,e) {
	if(e.keyCode==13) {
		var price_a = parseFloat(GE('price_from').value);
		var price_b = parseFloat(GE('price_to').value);
		if(price_a<price_b) {
			document.location.href =linkres.replace('&sort=','')+'&save_price_range='+price_a+'-'+price_b;
		} else {
			alert("Cena minimalna nie może być większa od maksymalnej");	
		}
	}
	if (e.keyCode > 31) {
		if (e.keyCode > 47 && e.keyCode < 58 || e.keyCode > 95 && e.keyCode < 106) {
			return true;
		} else {
			return false;
		}
	}
}
function statlow_clear(linkres) {
	document.location.href =linkres.replace('&sort=','')+'&save_price_range=1';	
}
