function whenReady()
{
	if ((ajax.readyState) == 4)
	{
		if (ajax.status == 200)
		{
			var error = noOffers();
			if (!error)
			{
				offersLayer.innerHTML = ajax.responseText;
				var offersHover = new TableHover(document.getElementById('offersList'),'hoverOn','hoverOff');
				location.href='#offers';
				if (searchBtn != null) searchBtn.onclick = findOffers;
				messageWnd.hide();
				ajax = null;
			}
			else
			{
				ajaxError(error);
			};
		}
		else
		{
			ajaxError("<br />Connection Error",true);
		};
	}
} 	

function findOffers()
{
	messageWnd.reset();
	messageWnd.show(waitHTML,false);
	if (searchBtn != null) searchBtn.onclick = null;
	if (window.XMLHttpRequest)
		ajax=new XMLHttpRequest();
	else
		if (window.ActiveXObject) 
			ajax=new ActiveXObject("Microsoft.XMLHTTP");
	if (countryLabel.innerHTML == '&nbsp;') countryLabel.innerHTML = 'All';
	if (departmentLabel.innerHTML == '&nbsp;') departmentLabel.innerHTML = 'All';
	ajax.onreadystatechange = whenReady;
	ajax.open("GET",getPath(type),true);
	offersLayer.innerHTML = '&nbsp;';
	ajax.send();
}

function getPath(type)
{
	return 'ajax/searchOffers.php?country='+countryLabel.innerHTML+'&department='+departmentLabel.innerHTML+'&type='+type+'&rand='+(Math.random()*1000);
}

function noOffers()
{
	rqstText = ajax.responseText;
	if (rqstText.substr(0,2) == '!#') return rqstText.substr(2);
	else return false;
}	

function ajaxError(rqstText)
{
	messageWnd.setText(rqstText,true);
	ajax=null;
	if (searchBtn != null) searchBtn.onclick = findOffers;
}


