function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
var xmlhttp = false;
function getHTTPReq(url, query, destinationid)
{
	url = url+'?'+query+'&sid='+Math.random();
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	if (xmlhttp)
	{
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState==4)
			{
				if (xmlhttp.status==200) { $(destinationid).innerHTML = xmlhttp.responseText; }
				else { $(destinationid).innerHTML = 'Fail'; }
			}
		}
		if (window.XMLHttpRequest) { xmlhttp.send(null); }
		else if (window.ActiveXObject) { xmlhttp.send(); }
	}
}
function clearValue(str)
{
	$('search').disabled=false;
	$('filter').checked=false;
	$('filter').disabled=true;
	var el = str.split('|');
	for(var e=0; e<el.length; e++)
	{
		if($(el[e])) $(el[e]).value='';
	}
}
function createLoading(id)
{
	$(id).innerHTML = '<div style="width: 32px; padding: 40px 0 40px 0; margin: 0 auto;"><img src="inc/loading.gif" alt="Loading ..." \/><\/div>';
}
function createTemp(id, width)
{
	$(id).innerHTML = '<select size="1" style="width: '+width+'px"><option>Loading . . .<\/option><\/select>';
}
function createResult()
{
	createLoading('divresult');
	var manufacturer_name = encodeURI($('manufacturer_name').value);
	var manufacturer_premier_color = encodeURI($('manufacturer_premier_color').value);
	var family = encodeURI($('family').value);
	var three_digits = encodeURI($('three_digits').value);
	var name = encodeURI($('name').value);
	var filter = ($('filter') && $('filter').checked==true) ? 'yes' : 'no';
	getHTTPReq('inc/search.php', 'search=y&manufacturer_name='+manufacturer_name+'&manufacturer_premier_color='+manufacturer_premier_color+'&family='+family+'&three_digits='+three_digits+'&name='+name+'&filter='+filter, 'divresult');
}
function createFamily(family, width)
{
	createTemp('divfam', width);
	getHTTPReq('inc/dd_color_family.php', 'family='+encodeURI(family), 'divfam');
}
function createColor(manufacturer_name, width)
{
	createTemp('divcol', width);
	getHTTPReq('inc/dd_manufacturers_colors.php', 'manufacturer_name='+encodeURI(manufacturer_name)+'&c=', 'divcol');
}
function createManufacturer(manufacturer_name, width)
{
	createTemp('divmfg', width);
	getHTTPReq('inc/dd_manufacturers.php', 'manufacturer_name='+encodeURI(manufacturer_name), 'divmfg');
}
function enableFilter(id)
{
	if($(id).value !== '')
	{
		$('filter').disabled=false;
	}
	else
	{
		$('filter').checked=false;
		$('filter').disabled=true;
	}
}
function toggle(el)
{
	var h = el.offsetHeight;
	if(h < 75) { el.style.height = '75px'; }
	else { el.style.height = '20px'; }
}
function init()
{
	createFamily('', 250);
	setTimeout("createManufacturer('', 250)", 1000);
}
window.onload = init;