function submitSearch() {
	var exists = false;
	document.CatalogSearchForm.searchTerm.value = document.CatalogSearchForm.searchTerm.value.replace(/s+$/g, '');
		//below line trims and drops toLowerCase
	var searchTerm = $.trim(document.CatalogSearchForm.searchTerm.value.toLowerCase());
	if (searchTerm == 'treadmills') {
			searchTerm = 'treadmill';
		} else if (searchTerm == 'ellipticals') {
			searchTerm = 'elliptical';
		} else if (searchTerm == 'bikes') {
			searchTerm = 'bike';
		} else if (searchTerm == 'exercise bikes') {
			searchTerm = 'exercise bike';
		} else if (searchTerm == 'systems') {
			searchTerm = 'system';
		} else if (searchTerm == 'strength systems') {
			searchTerm = 'strength system';
		}
		// standard sku's 
		else if (searchTerm.match(/^([A-Za-z]{3,7})([0-9]{1})([A-Za-z]{0,})([0-9]{1,})$/)) {
			exists = true;
		}
		//regex for ifit skus such as 14818
		else if (searchTerm.match(/^([0-9]{5})$/)) {
			exists = true;
		}
		if(exists) { // if one of the above regex is matched submit the sku to the search
			document.CatalogSearchForm.sku.value = searchTerm;
			document.CatalogSearchForm.searchTerm.value = '';
		}else{
		document.CatalogSearchForm.searchTerm.value = searchTerm;
	}
	document.CatalogSearchForm.submit();
}

/*
function submitSearch() {
	var searchTerm = $.trim(document.CatalogSearchForm.searchTerm.value);
		document.CatalogSearchForm.searchTerm.value = document.CatalogSearchForm.searchTerm.value.replace(/s+$/g, '');
	if (searchTerm.match(/^([A-Za-z]{3,7})([0-9]{1})([A-Za-z]{0,})([0-9]{1,})$/)) {
		document.CatalogSearchForm.sku.value = searchTerm;
		document.CatalogSearchForm.searchTerm.value = '';
	}
	document.CatalogSearchForm.submit();
}
*/
function submitCompare(form) {
	var actionAppendString = '';
	var compareElements = document.getElementsByName('compare[]');
	if (compareElements.length > 0) {
		var totalCount = 0;
		for (var i=0, length=compareElements.length; i<length; i++) {
			if (compareElements[i].checked == true) {
				++totalCount;
			}
		}
		if (totalCount <= 1) {
			alert('Please choose 2 or more products to compare.');
		} else {
			for (var i=0, length=compareElements.length; i<length; i++) {
				if (compareElements[i].checked == true) {
					var newInput = document.createElement('input');
						newInput.setAttribute('type', 'hidden');
						newInput.setAttribute('name', 'compare');
						newInput.setAttribute('value', compareElements[i].value);
					document.FastFinderForm.appendChild(newInput);
				}
			}
			document.FastFinderForm.submit();
		}
	}
}

function compareAll(form) {
	$(".checkbox").each(function() {
		$(this).attr("checked","checked");
	})
	submitCompare(form);
}

$(document).ready(function(){
	$(".compare-image input[type=checkbox]").click(function(){
		if($(".compare-image input[type=checkbox]:checked").length >= 2){
			$(".compare-image img").attr('src','http://img.iconcdn.com/ProForm/images/compare-on.gif');
		} else {
			$(".compare-image img").attr('src','http://img.iconcdn.com/ProForm/images/compare-off.jpg');
		}
	});
});

$(document).ready(function(){
	$("#products-cart input").change(function() {
		if(this.value == '' || this.value == null){
			this.value = 0;
		}
	});

	$(".series-container .cat-product-compare input[type=checkbox]").click(function(){
		if($(".series-container input[type=checkbox]:checked").length <= 6) {
			if($(".series-container input[type=checkbox]:checked").length >= 2){
//				$("#compare a").html('<img src="/wcsstore/NordicTrack/images/compare-selected-active.png" alt="Compare Selected" />');
				$(".compare-form a").addClass('cat-product-compare-highlighted');
			} else {
//				$("#compare a").html('<img src="/wcsstore/NordicTrack/images/compare-selected-off.png" alt="Compare Selected" />');
				$(".compare-form a").removeClass('cat-product-compare-highlighted');
			}
		} else {
			alert("Please select 6 products or less to compare.");
		}
	});
});

