function getHTTPObject()
{
	var xmlhttp;
	//do not take out this section of code that appears to be commented out...if you do the guns stop working.
	/*@cc_on
	@if (@_jscript_version >= 5)
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			xmlhttp = false;
		}
	}
	@else
	{
		xmlhttp = false;
	}
	@end @*/

	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

var isWorking = false;
var http = getHTTPObject();
var div_name = "";
var eval_line_when_done = "";

function HtResponse_div_write()
{
	if (http.readyState == 4)
	{
		if((http.responseText!=null)&&(div_name!=""))
		{
			document.getElementById(div_name).innerHTML = http.responseText;
		}
		else if(send_alert)
		{
			alert(http.responseText);
			send_alert = false;
		}
		
		if(eval_line_when_done != '')
		{
			var eval_this = eval_line_when_done;
			eval_line_when_done = "";
			eval(eval_this);
		}
		isWorking = false;
	}
}

function HtResponse_js_eval()
{
	if (http.readyState == 4)
	{
		eval(http.responseText);
		isWorking = false;
	}
}

function Ht_generic(file_name,print_div,var1,var2)
{
	file_name = file_name || "";
	print_div = print_div || "";
	var1 = var1 || "";
	var2 = var2 || "";
	if((file_name != "") && (print_div != ""))
	{
		if(!isWorking)
		{
			http.open("GET", "/ajax/" + file_name + "?var1=" + escape(var1) + "&var2=" + escape(var2) + "&math=" + Math.random(), true);
			isWorking = true;
			div_name = print_div;
			http.onreadystatechange = HtResponse_div_write;
			http.send(null);
		}
		else
		{
			setTimeout("Ht_generic('" + file_name + "','" + print_div + "','" + var1 + "','" + var2 + "')",100);
		}
	}
}

function Ht_generic_eval(file_name,var1,var2)
{
	file_name = file_name || "";
	var1 = var1 || "";
	var2 = var2 || "";
	if(file_name != "")
	{
		if(!isWorking)
		{
			http.open("GET", "/ajax/" + file_name + "?var1=" + escape(var1) + "&var2=" + escape(var2) + "&math=" + Math.random(), true);
			isWorking = true;
			http.onreadystatechange = HtResponse_js_eval;
			http.send(null);
		}
		else
		{
			setTimeout("Ht_generic_eval('" + file_name + "','" + print_div + "','" + var1 + "','" + var2 + "')",100);
		}
	}
}

function Ht_find_model(brand_id,equipment_id)
{
	brand_id = brand_id || 0;
	equipment_id = equipment_id || 0;
	if(!isWorking)
	{
		if(brand_id > 0)
		{
			document.forms.top_search.brand_id.value = brand_id;
		}
		http.open("GET", "/ajax/find_model.php?brand_id=" + escape(brand_id) + "&equipment_id=" + escape(equipment_id) + "&math=" + Math.random(), true);
		isWorking = true;
		div_name = 'div_find_model';
		http.onreadystatechange = HtResponse_div_write;
		http.send(null);
	}
	else
	{
		setTimeout("Ht_find_model(" + brand_id + "," + equipment_id + ")",100);
	}
}

function Ht_equipment_drop_down(depth,brand_id,equipment_id,equipment_diagram_id)
{
	depth = depth || 'equipment';
	brand_id = brand_id || 0;
	equipment_id = equipment_id || 0;
	equipment_diagram_id = equipment_diagram_id || 0;
	if(!isWorking)
	{
		http.open("GET", "/ajax/equipment_drop_down.php?depth=" + escape(depth) + "&brand_id=" + escape(brand_id) + "&equipment_id=" + escape(equipment_id) + "&equipment_diagram_id=" + escape(equipment_diagram_id) + "&math=" + Math.random(), true);
		isWorking = true;
		div_name = 'id_equipment_drop_down';
		http.onreadystatechange = HtResponse_div_write;
		http.send(null);
	}
	else
	{
		setTimeout("Ht_equipment_drop_down('" + depth + "'," + brand_id + "," + equipment_id + "," + equipment_diagram_id + ")",100);
	}
}

function HtAddToCart(form_name)
{
	if(form_name!="")
	{
		if(!isWorking)
		{
			eval('var this_qty = document.forms.'+form_name+'.qty.value;');
			eval('var this_product_id = document.forms.'+form_name+'.product_id.value;');
			http.open("GET", "/ajax/cart_add.php?product_id=" + escape(this_product_id) + "&qty=" + escape(this_qty) + "&math=" + Math.random(), true);
			isWorking = true;
			http.onreadystatechange = HtResponse_js_eval;
			http.send(null);
		}
		else
		{
			setTimeout("HtAddToCart('" + form_name + "')",100);
		}
	}
}

function Ht_file_viewer(this_div,file_link_id,file_link_type,file_id,size)
{
	this_div = this_div || '';
	file_link_id = file_link_id || 0;
	file_link_type = file_link_type || 'product';
	file_id = file_id || 0;
	size = size || 's';
	
	if(!isWorking)
	{
		http.open("GET", "/ajax/file_viewer.php?file_link_id=" + escape(file_link_id) + "&file_link_type=" + escape(file_link_type) + "&file_id=" + escape(file_id) + "&size=" + escape(size) + "&this_div=" + escape(this_div) + "&math=" + Math.random(), true);
		isWorking = true;
		div_name = this_div;
		http.onreadystatechange = HtResponse_div_write;
		http.send(null);
	}
	else
	{
		setTimeout("Ht_file_viewer('" + this_div + "'," + file_link_id + ",'" + file_link_type + "'," + file_id + ",'" + size + "')",100);
	}
}

function Ht_equipment_part_list(list_equipment_id)
{
	if(!isWorking)
	{
		var all_select_attrib = 'N';
		var selected_attrib = '';
		if(document.forms.equip_list_attrib.all_select_attrib.checked)
		{
			all_select_attrib = 'Y';
		}
		list_equipment_id = list_equipment_id || 0;
		var product_attribute_id_list = document.forms.equip_list_attrib.product_attribute_id_list.value;
		var poststr = "equipment_id=" + encodeURIComponent(list_equipment_id) +
									"&all_select_attrib=" + encodeURIComponent(all_select_attrib);
		
		var product_attribute_id_array = product_attribute_id_list.split(',');
		var array_count = 0;
		while (array_count < product_attribute_id_array.length)
		{
			var product_attribute_id = product_attribute_id_array[array_count];
			array_count+=1;
			
			var this_checked_value = 'N';
			eval('if(document.forms.equip_list_attrib.product_attribute_id_check_'+product_attribute_id+') { this_checked_value = document.forms.equip_list_attrib.product_attribute_id_check_'+product_attribute_id+'; }');
			if(this_checked_value.checked)
			{
				selected_attrib = selected_attrib + product_attribute_id + ',';
			}
		}
		if(selected_attrib != '')
		{
			poststr = poststr + "&selected_attrib=" + selected_attrib;
		}
		
		isWorking = true;
		http.open("POST", "/ajax/equipment_part_list.php", true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", poststr.length);
		http.setRequestHeader("Connection", "close");
		div_name = 'equipment_part_list';
		http.onreadystatechange = HtResponse_div_write;
		http.send(poststr);
		//http.send(null);
	}
	else
 	{
 		setTimeout("Ht_equipment_part_list('" + list_equipment_id + "')",100);
	}
}