window.onload = function () {
  document.getElementById('brand').onchange = function() {
		hideElement('searchResults');
		showElement('searchProgress');
		var path = document.location.href;
		if (!(/browse/.match(path))) {
			path = path + 'outfits/browse'
		}
		if (this.value == 0) {
			if (/\?brand=/.match(path)) {
				path = path.replace(/\?brand=[^\&]+/, '\?');
			} else {
				path = path.replace(/&brand=[^\&]+/, '');
			}
		} else {
			if (/brand=/.match(path)) {
				path = path.replace(/brand=[^\&]+/, 'brand='+this.value);
			} else {
				if (/\?/.match(path)) {
					path = path+'&brand='+this.value;
				} else {
					path = path+'?brand='+this.value;
				}
			}
		}
		if (/page=/.match(path)) {
			path = path.replace(/page=[^\&]+/, 'page=1')
		}
		if (/\?$/.match(path)) {
			document.location.href = path.replace(/\?$/,'');
		} else {
			document.location.href = path;
		}
  }
  document.getElementById('garment_type').onchange = function() {
		hideElement('searchResults');
		showElement('searchProgress');
		var path = document.location.href;
		if (!(/browse/.match(path))) {
			path = path + 'outfits/browse'
		}
		if (this.value == 0) {
			if (/\?garment_type=/.match(path)) {
				path = path.replace(/\?garment_type=[^\&]+/, '\?');
			} else {
				path = path.replace(/&garment_type=[^\&]+/, '');
			}
		} else {
			if (/garment_type=/.match(path)) {
				path = path.replace(/garment_type=[^\&]+/, 'garment_type='+this.value);
			} else {
				if (/\?/.match(location.href)) {
					path = path+'&garment_type='+this.value;
				} else {
					path = path+'?garment_type='+this.value;
				}
			}
		}
		if (/page=/.match(path)) {
			path = path.replace(/page=[^\&]+/, 'page=1')
		}
		if (/\?$/.match(path)) {
			document.location.href = path.replace(/\?$/,'');
		} else {
			document.location.href = path;
		}
  }
  document.getElementById('style').onchange = function() {
		hideElement('searchResults');
		showElement('searchProgress');
		var path = document.location.href;
		if (!(/browse/.match(path))) {
			path = path + 'outfits/browse'
		}
		if (this.value == 0) {
			if (/\?style=/.match(path)) {
				path = path.replace(/\?style=[^\&]+/, '\?');
			} else {
				path = path.replace(/&style=[^\&]+/, '');
			}
		} else {
			if (/style=/.match(path)) {
				path = path.replace(/style=[^\&]+/, 'style='+this.value);
			} else {
				if (/\?/.match(path)) {
					path = path+'&style='+this.value;
				} else {
					path = path+'?style='+this.value;
				}
			}
		}
		if (/page=/.match(path)) {
			path = path.replace(/page=[^\&]+/, 'page=1')
		}
		if (/\?$/.match(path)) {
			document.location.href = path.replace(/\?$/,'');
		} else {
			document.location.href = path;
		}
  }
  document.getElementById('season').onchange = function() {
		hideElement('searchResults');
		showElement('searchProgress');
		var path = document.location.href;
		if (!(/browse/.match(path))) {
			path = path + 'outfits/browse'
		}
		if (this.value == 0) {
			if (/\?season=/.match(location.href)) {
				path = path.replace(/\?season=[^\&]+/, '\?');
			} else {
				path = path.replace(/&season=[^\&]+/, '');
			}
		} else {
			if (/season=/.match(path)) {
				path = path.replace(/season=[^\&]+/, 'season='+this.value);
			} else {
				if (/\?/.match(path)) {
					path = path+'&season='+this.value;
				} else {
					path = path+'?season='+this.value;
				}
			}
		}
		if (/page=/.match(path)) {
			path = path.replace(/page=[^\&]+/, 'page=1')
		}
		if (/\?$/.match(path)) {
			document.location.href = path.replace(/\?$/,'');
		} else {
			document.location.href = path;
		}
  }
	if (document.getElementById('sort')) {
		document.getElementById('sort').onchange = function() {
			hideElement('searchResults');
			showElement('searchProgress');
			var path = document.location.href;
			if (!(/browse/.match(path))) {
				path = path + 'outfits/browse'
			}
			if (/sort=/.match(path)) {
				document.location.href = path.replace(/sort=[^\&]+/, 'sort='+this.value);
			} else {
				if (/\?/.match(location.href)) {
					document.location.href = path+'&sort='+this.value;
				} else {
					document.location.href = path+'?sort='+this.value;
				}
			}
		}
	}
}