function updateSubcategory() {
	var catobj = document.getElementById("flaming_cat");
	if(catobj != undefined) {
		var catval = catobj.options[catobj.selectedIndex].value;
		ajax_subcat("flaming_sub",catval);
	}
}
function updateModel() {
	var makeobj = document.getElementById("flaming_make");
	if(makeobj != undefined) {
		var makeval = makeobj.options[makeobj.selectedIndex].value;
		ajax_model("flaming_model",makeval);
	}
	
}
function updateYear() {
        var makeobj = document.getElementById("flaming_make");
	var modelobj = document.getElementById("flaming_model");
        if(makeobj != undefined && modelobj != undefined) {
                var makeval = makeobj.options[makeobj.selectedIndex].value;
		var modelval = modelobj.options[modelobj.selectedIndex].value;
                ajax_year("flaming_year",makeval,modelval);
	}
}

function ajax_subcat(target,catid) {
	theURL = "/scripts/options_subcategory.php?catid=" + catid;
	generic_ajax(target,theURL,false);
}

function ajax_model(target,makeid) {
	theURL = "/scripts/options_model.php?makeid=" + makeid;
	generic_ajax(target,theURL,true);
}

function ajax_year(target,makeid,modelid) {
	theURL = "/scripts/options_year.php?makeid=" + makeid + "&modelid=" + modelid;
	generic_ajax(target,theURL,false);
}

function generic_ajax(target,theURL,ismodel) {
	var displayobj = document.getElementById(target);
	if(displayobj == undefined) 
		return;
        try {
                httpContent = new XMLHttpRequest();
        } catch(e) {
                httpContent = new ActiveXObject("Microsoft.XMLHTTP");
        }

        httpContent.onreadystatechange = function() {
                if(httpContent.readyState == 4) {
                        if(httpContent.responseText != "ERROR") {
                                displayobj.innerHTML = httpContent.responseText;
				if(ismodel) {
					displayobj.addEventListener('change',updateYear,false);
				}
                        }
                }
        };

        httpContent.open("GET", theURL, true);
        httpContent.send(null);
}
	

