﻿var previous = "";

function blogSearch(category, variable, count)
{	//alert("make: "+make);
	var xmlhttp;
	try	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  	} catch (e)
  	{
	  	try	{
		  	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  	} catch (E)
	  	{
		  	xmlhttp = false;
	  	}
 	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e)
		{
			xmlhttp = false;
		}
	}
	
	var data;
	var dir;
	var breadcrumb;
	
	data = "variable="+variable;
	data += "&category="+category;
	
	xmlhttp.open("GET", "/util/search/search.aspx?" + data, true);
	
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			var text = xmlhttp.responseText;
			window.document.getElementById("results").innerHTML = text;
			//window.document.getElementById("clear").style.display = "block";
			if(variable == "iqs") {
				breadcrumb = "Quality";
			} else if(variable == "apeal") {
				breadcrumb = "Performance and Design";
			} else if(variable == "vds") {
				breadcrumb = "Dependability";
			} else if(variable == "5") {
				breadcrumb = "Safety";
			} else if(variable == "under 20") {
				breadcrumb = "Under $20K";
			} else if(variable == "20-30") {
				breadcrumb = "$20K - $30K";
			} else if(variable == "30-40") {
				breadcrumb = "$30K - $40K";
			} else if(variable == "40-60") {
				breadcrumb = "$40K - $60K";
			} else if(variable == "over 60") {
				breadcrumb = "Over $60K";
			} else {
				breadcrumb = variable;
			}
			
			window.document.getElementById("breadcrumb").innerHTML = "<a href='/'>Home</a> &gt; <a href='/autos/'>Autos</a> &gt; <a href='/autos/powersteering/'>PowerSteering Home</a> &gt; " + breadcrumb;

			if(category == "body_type")
				variable = "bt"+variable;
				
			window.document.getElementById(variable+"Link").style.display = "none";

			if(previous != "") {
				window.document.getElementById(variable).style.display = "block";
				window.document.getElementById(previous+"Link").style.display = "block";
				window.document.getElementById(previous).style.display = "none";
				previous = variable;
			} else {
				window.document.getElementById(variable).style.display = "block";
				previous = variable;
			}
		}
	}
	
	//xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(data);
	
	adRefresh(category, variable, count);
}

function adRefresh(category, variable, count)
{	//alert("make: "+make);
	var xmlhttp;
	try	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  	} catch (e)
  	{
	  	try	{
		  	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  	} catch (E)
	  	{
		  	xmlhttp = false;
	  	}
 	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e)
		{
			xmlhttp = false;
		}
	}
	
	var data;
	var dir;
	var breadcrumb;
	
	data = "variable="+variable;
	data += "&category="+category;
	
	xmlhttp.open("GET", "/util/search/adRefresh.aspx?" + data, true);
	
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			var text = xmlhttp.responseText;

			window.document.getElementById("bannerad").src = "/ads/Model_728x90.aspx?" + text;
			window.document.getElementById("rightad").src = "/ads/Model_160x100.aspx?" + text;
			window.document.getElementById("towerad").src = "/ads/Model_160x600.aspx?" + text;
		}
	}
	
	//xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(data);	
}
