// JavaScript Document
function httpRequest(url,callback)
{
	var httpObj = null;
	try {
		httpObj = new XMLHttpRequest();
	}catch (e) {
		try {
			httpObj = new ActiveXObject("Msxml2.XMLHTTP");	
		}catch (e) {
			httpObj = new ActiveXObject("Microsoft.XMLHTTP");	
		}
	}
	//process the returned obj from server
	httpObj.onreadystatechange = function() {
		if(httpObj.readyState == 4)
			callback(httpObj.responseText);
	};
	httpObj.open('GET', url, true);
    httpObj.send(null);
}

function fillSelect(obj)
{
	var selectTwo = document.getElementById("productBrand");
	selectTwo.options.length = 1;
	
	var data = obj.split(",");
	
	for (var i=0;i < data.length-1;i++) {
        selectTwo.options[selectTwo.options.length] = new Option(data[i],data[i]);
		
    }
}

function onSelectChange()
{
	var selectOne = document.getElementById("productModel");
	var selectedOption = selectOne.options[selectOne.selectedIndex].value;
	
	if(selectedOption != null) {
		httpRequest("modules/products/product_model.php?brand=" + selectedOption,fillSelect);	
	}else {
		fillSelect('[]');
	}
}

