var xmlhttp

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

//toggle the radio buttons to display the filtering options
function toggleFilter(rad)
{ 
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	//clear the sections that will be updated
	document.getElementById("productList").innerHTML=""; 
	//document.getElementById("productSection").innerHTML="";
//	document.getElementById("filterOptions").innerHTML=""; 
		
	if(rad == 'all')
	{
		//show all products
		showProducts(2, -1);	
	}
	else
	{
		if(rad == 'condicion')
		{
			var combo = document.getElementById("conditionCombo");
			showProducts(0, combo.options[combo.selectedIndex].value);
		}
		
		var url="../../../scripts/products/setFilterControls.php";
		url=url+"?q="+rad;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=stateChangedFilter;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
	}
}

//update the filter options in the screen
function stateChangedFilter()
{
	if (xmlhttp.readyState==4)
	{
		//document.getElementById("filterOptions").innerHTML=xmlhttp.responseText;
	}
}

//show the corresponding products in the product section
function showProducts(type, value) 
{
	//alert('entr&oacute; a showProducts ' + type + ' value:' + value);
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../../../scripts/products/getProducts.php";
	url=url+"?type="+type;
	url=url+"&q="+value;
	url=url+"&sid="+Math.random();	
	//alert("url value:"+url); //print value of url	
	xmlhttp.onreadystatechange=stateChangedProducts;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//set the product section of the screen
function stateChangedProducts()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("productList").innerHTML=xmlhttp.responseText;
	}
}

function showProductDetail(id) 
{
	//alert(id + " en showproductdetail");
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url="../../../scripts/products/getProductDetails.php";
	url=url+"?q="+id;
	url=url+"&sid="+Math.random();	
	//alert("url value:"+url); //print value of url	
	xmlhttp.onreadystatechange=stateChangeProductDetail;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//set the product section of the screen
function stateChangeProductDetail()
{
	if (xmlhttp.readyState==4)
	{
		document.getElementById("productSection").innerHTML=xmlhttp.responseText;
	}
}

