function eget(id)
{
	if (document.all)
	{
		var el = document.getElementById(id) ? document.getElementById(id) : document.all[id];
	}
	else
	{
		var el = document.getElementById(id);
	}

	if (el)
	{
		return el;
	}
	else
	{
		return null;
	}
}

var xmlHttp = getHTTPObject();
function getHTTPObject()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.7.0", "MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");

		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {}
		}
	}

	if (!xmlHttp) alert("Error creating the XMLHttpRequest object.");
	else return xmlHttp;
}

function process(gourl, eid)
{
	var r = getHTTPObject();
	r.open("GET", gourl);
	r.onreadystatechange = function()
	{
		if (r.readyState == 4)
		{
			eget(eid).innerHTML = r.responseText;
		}
	}

	r.send(null);
}

function check3(form_name, count1, count2)
{
	var c=0;
	element = document.forms[form_name].elements;
	for (i=6; i < (6 + count1); i++)
	{
		if (element[i].checked == true)
		{
			c++;
		}
	}

	if (c==3)
	{
		for (i=6; i < (6 + count1); i++)
		{
			if (element[i].checked == false)
			{
				element[i].disabled = true;
			}
		}
	}
	else
	{
		for (i=6; i < (6 + count1); i++)
		{
			if (element[i].checked == false)
			{
				element[i].disabled = false;
			}
		}
	}

	c=0;
	for (i=(6 + count1); i < (6 + count1 + count2); i++)
	{
		if (element[i].checked == true)
		{
			c++;
		}
	}

	if (c==3)
	{
		for (i=(6 + count1); i < (6 + count1 + count2); i++)
		{
			if (element[i].checked == false)
			{
				element[i].disabled = true;
			}
		}
	}
	else
	{
		for (i=(6 + count1); i < (6 + count1 + count2); i++)
		{
			if (element[i].checked == false)
			{
				element[i].disabled = false;
			}
		}
	}
}

function show(town)
{
	var oldtown;
	oldtown=eget('town').value;
	if (town==oldtown&&(eget('i' + town).className!=='dn'))
	{
		eget(oldtown).className='direct';
		eget('i' + oldtown).className='dn';
	}
	else
	{
		eget(oldtown).className='direct';
		eget(town).className='direct selected';
		eget('i' + oldtown).className='dn';
		process('/ajax/shops.php?town=' + town, 'i' + town);
		eget('i' + town).className='buy';
		eget('town').value=town;
	}
}
