var xmlhttp;

function XmlHttpObject()
{
	var xmlhttp = null;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (a)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (b)
		{
		}
	}
	if (!xmlhttp && (typeof XMLHttpRequest != 'undefined'))
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function getCars(nr)
{
	xmlhttp=XmlHttpObject();
	if (xmlhttp==null){	return;	} 
	xmlhttp.open("POST","ajax/gt_crs2.php?s="+Math.random()+"&nr="+nr,true);
	xmlhttp.onreadystatechange=getCarsNow; 
	xmlhttp.send(null);
	
	setTimeout('getCars('+(parseInt(nr)+1)+')',5000);
	document.getElementById("count_ids").value=(parseInt(nr)+1);
}

function getCarsNow() 
{ 
	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
	{
		var temp = xmlhttp.responseText.split('|||');
		if(parseInt(document.getElementById("count_ids").value)<=parseInt(temp[1])-1)
		{
			document.getElementById("cars").innerHTML=temp[0];
		}
		else
		{
			window.status="restart";
			getCars("3");
			document.getElementById("count_ids").value="2";
		}
	}
	else
	{
		if(document.getElementById("count_ids").value=="1")
		{
			document.getElementById("cars").innerHTML="<img src=\"images/loading.jpg\" alt=\"Het huidige aanbod wordt geladen...\" />";
		}
	}
}
