$( function() {

	// Advanced Search Filter AJAX calls 
	
	 $(".attrSearch").change(function () {
		var attributeValue = $(this).val();
		//alert(attributeValue);
		var searchTerms = $("#searchTerms").val();
		//alert(searchTerms);
		
		var normalurl = "?cmd=searchfilter&searchTerms=" + searchTerms + "&attributeValue=" + attributeValue;
		window.location.href = normalurl;
		
	});
	 
	 
	$("#attrBrand").change(function () {
		var pageCmd = $("#command").val();
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();

		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}

		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	
	$(".attrWheelModel").change(function () {
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();

		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}

		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrColour").change(function () {
		var pageCmd = $("#command").val();
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();

		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}

		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrColour2").change(function () {
		
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();
		
		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}
		
		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrColour3").change(function () {
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();

		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}

		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrStyle").change(function () {
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();

		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}

		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrStyle2").change(function () {
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();
		
		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}
		
		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
	$(".attrStyle3").change(function () {
		var pageCmd = $("#command").val();
		
		// The next three are related to wheel selector call
		
		var modelID = $("#modelid").val();
		var makerID = $("#makerid").val();
		var sizeID = $("#sizeid").val();
		
		// End of wheel selector related vars
		
		var brandValue = $("#attrBrand").val();
		var searchTerms = $("#searchTerms").val();
		var wheelModel = $(".attrWheelModel").val();
		var colourOne = $(".attrColour").val();
		var colourTwo = $(".attrColour2").val();
		var colourThree = $(".attrColour3").val();
		var styleOne = $(".attrStyle").val();
		var styleTwo = $(".attrStyle2").val();
		var styleThree = $(".attrStyle3").val();
		
		if (pageCmd == 'search') {
			var normalurl = '?cmd=' + pageCmd + '&s=' + searchTerms;
		} else {
			var normalurl = '/?cmd=' + pageCmd + '&maker=' + makerID + '&model=' + modelID + '&size=' + sizeID;
		}
		
		if (!brandValue.length == 0) {
			normalurl += '&brandValue=' + brandValue;
		}
		
		if (!wheelModel.length == 0) {
			normalurl += '&wheelModel=' + wheelModel;
		}
		
		if (!colourOne.length == 0) {
			normalurl += '&colourOne=' + colourOne;
		}
	
		// check the next two as they might not actually exist on the page.
		if (colourTwo !== undefined) {
			if (!colourTwo.length == 0) {
				normalurl += '&colourTwo=' + colourTwo;
			}
		}
		
		if (colourThree !==  undefined) {
			if (!colourThree.length == 0) {
				normalurl += '&colourThree=' + colourThree;
			}
		}

		if (!styleOne.length == 0) {
			normalurl += '&styleOne=' + styleOne;
		}
		
		if (styleTwo !== undefined) {
			if (!styleTwo.length == 0) {
				normalurl += '&styleTwo=' + styleTwo;
			}
		}
		
		if (styleThree !== undefined) {
			if (!styleThree.length == 0) {
				normalurl += '&styleThree=' + styleThree;
			}
		}

		window.location.href = normalurl;
	});
	
});
