function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

function getProductCount()
{
		
	document.getElementById("matchResults").style.display = "none";
	document.getElementById("filterSearching").style.display = "block";
	if(document.getElementById("matchResults2"))
	{
		document.getElementById("matchResults2").style.display = "none";
	}
	if(document.getElementById("filterSearching2"))
	{
		document.getElementById("filterSearching2").style.display = "block";
	}
	
	url = 'http://www.seriousbats.com/sniff.php?display_type=' + document.filterForm.display_type.value + '&display_id=' + document.filterForm.display_id.value;
		
	if(document.getElementById("brands_len"))
	{
	
		len = parseInt(document.filterForm.brands_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("brand" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("brand" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&brands=' + chosen;
		}
	}
		
	if(document.getElementById("categories_len"))
	{
	
		len = parseInt(document.filterForm.categories_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("category" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("category" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&cat=' + chosen;
		}
	}
		
	if(document.getElementById("wd_len"))
	{
	
		len = parseInt(document.filterForm.wd_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("wd" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("wd" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&wd=' + chosen;
		}
	}
	
	if(document.getElementById("lgt_len"))
	{
	
		len = parseInt(document.filterForm.lgt_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("length" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("length" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&lgt=' + chosen;
		}
	}
	
	if(document.getElementById("weight_len"))
	{
	
		len = parseInt(document.filterForm.weight_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("weight" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("weight" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&weight=' + chosen;
		}
	}
	
	if(document.getElementById("price_len"))
	{
	
		len = parseInt(document.filterForm.price_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("price" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("price" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&price=' + chosen;
		}
	}
	
	if(document.getElementById("barrel_len"))
	{
	
		len = parseInt(document.filterForm.barrel_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("barrel" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("barrel" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&barrel=' + chosen;
		}
	}
		
	if(document.getElementById("handle_len"))
	{
	
		len = parseInt(document.filterForm.handle_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("handle" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("handle" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&handle=' + chosen;
		}
	}
		
	if(document.getElementById("construction_len"))
	{
	
		len = parseInt(document.filterForm.construction_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("construction" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("construction" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&construction=' + chosen;
		}
	}
	
	if(document.getElementById("diameter_len"))
	{
	
		len = parseInt(document.filterForm.diameter_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("diameter" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("diameter" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&diameter=' + chosen;
		}
	}
		
	if(document.getElementById("taper_len"))
	{
	
		len = parseInt(document.filterForm.taper_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("taper" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("taper" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&taper=' + chosen;
		}
	}
		
	if(document.getElementById("assoc_len"))
	{
	
		len = parseInt(document.filterForm.assoc_len.value);
				
		chosen = "";
		
		for (i = 0; i <len; i++) {
			if (document.getElementById("assoc" + i.toString()).checked) {
				if(chosen != "")
				{
					chosen = chosen + ',';
				}
				chosen = chosen + document.getElementById("assoc" + i.toString()).value;
			}
		}
		
		if (chosen != "")
		{
			url = url + '&assoc=' + chosen;
		}
	}
							
	httpRequest = createRequestObject();
	httpRequest.open('get', url);
	httpRequest.onreadystatechange = returnProductCount;
	httpRequest.send(null);
		
}

function returnProductCount()
{
	if(httpRequest.readyState == 4){ //Finished loading the response
		try
		{
			var response = httpRequest.responseXML;
			var prod = response.getElementsByTagName('products');

			if(prod.length > 0){
				/* this means I received a response from the server */

				var prod_count = parseFloat(unescape(prod[0].childNodes[0].firstChild.nodeValue));
				var min_price = parseFloat(unescape(prod[0].childNodes[1].firstChild.nodeValue));
				var max_price = parseFloat(unescape(prod[0].childNodes[2].firstChild.nodeValue));
				
				if(prod_count != 1){
					output = '<b>' + String(prod_count) + ' bats found</b>';
				} else {
					output = '<b>1 bat found</b>';
				}
				output = output + '<br>';
				if(min_price > 0){
					output = output + ' ($' + addCommas(min_price.toFixed(2));
					if(max_price > min_price){
						output = output + ' - $' + addCommas(max_price.toFixed(2));	
					}	
					output += ')';
				}
				
				document.getElementById('matchResults').innerHTML = output;
				if(document.getElementById("matchResults2"))
				{
					document.getElementById("matchResults2").innerHTML = output;
				}

				document.getElementById("filterSearching").style.display = "none";
				document.getElementById("matchResults").style.display = "block";
				
				if(document.getElementById("matchResults2"))
				{
					document.getElementById("matchResults2").style.display = "block";
				}
				if(document.getElementById("filterSearching2"))
				{
					document.getElementById("filterSearching2").style.display = "none";
				}				
				
			}
		}
		catch(e)
		{
		}
	}
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function B( objAny ){
	if(objAny.toString() == "true"){
		return(true);
	}
	if(objAny.toString() == "false"){
		return(false);
	}
}
