function changeLoc(value) {
	if (!value) {
		value = '';
	}
	var form = document.forms['filterForm'];
	if (form && form.elements['loc'] && form.elements['loc'].options) {
		var es = form.elements['loc'].options;
		for (var i = 0; i < es.length; i++) {
			if (es[i].value == value) {
				es[i].selected = true;
				form.submit();
				return;
			}
		}
	}else if (form && form.elements['loc'] && (form.elements['loc'].type == 'text' || form.elements['loc'].type == 'TEXT')) {
		form.elements['loc'].value = value;
		form.submit();
		return;
	}
}

function trim(str) {
	if (!str) {
		return '';
	}
	return str.replace(/^\s*|\s*$/g,'');
}

function _v(obj, v) {
	if (!obj) {
		return '';
	}
	try {
		var o = obj.elements[v];
		if (o) {
			return trim(o.value);
		}else {
			return '';
		}
	}catch (e) {
		return '';
	}
}

function checkCondition(obj) {
	var alstr = '\u8BF7\u8F93\u5165\u5173\u952E\u5B57';
	if (!obj) {
		return true;
	}
	var cat = obj.elements['cat'];
	var q = obj.elements['q'];
	if ((!_v(obj,'cat') || _v(obj,'cat') == '0') && !_v(obj,'q') && !_v(obj,'nick') && !_v(obj,'user') && !_v(obj,'price') && !_v(obj,'oney') && !_v(obj,'counts')) {
		alert(alstr);
		q.focus();
		return false;
	}
	var filter = obj.elements['filter'];
	var startPrice = obj.elements['start_price'];
	var endPrice = obj.elements['end_price'];
	if (filter && startPrice && endPrice) {
		var s = startPrice.value;
		var e = endPrice.value;
		var is = 0;
		var ie = 0;
		if (!isNaN(s) && !isNaN(parseInt(s))) {
			is = parseInt(s);
		}
		if (!isNaN(e) && !isNaN(parseInt(e))) {
			ie = parseInt(e);
		}
		if (is > 0 || ie > 0) {
			if (ie<=0) {
				ie = 100000000;
			}
			if (is <= 0) {
				is = 0;
			}
			if ((ie+1) < (is+1)) {
				filter.value = 'reserve_price[' + ie + ',' + is + ']';
			}else {
				filter.value = 'reserve_price[' + is + ',' + ie + ']';
			}
		}else {
			filter.value = '';
		}
	}else if (filter) {
		filter.value = '';
	}
	return true;
}
function parseFilter(str) {
	var reg = /reserve_price\[([0-9]+),([0-9]+)\]/ig;
	var arr = reg.exec(str);
	var f = new Array();
	f[0] = RegExp.$1;
	f[1] = RegExp.$2;
	if (f[1] >= 100000000) {
		f[1] = '';
	}
	if (f[0] <= 0) {
		f[0] = '';
	}
	return f;
}
