/*	$(document).ready(function(){
			$("#top-nav li").hover(
				function() { 
					//hovered = true;
					$(this).children('.sub-nav').show();
					$(this).children('a').addClass("hovered");
					$('#form-buckets select').css({ visibility: "hidden" });
					//$(this).
					/*$(this).children('.sub-nav').slideDown(400, function(){
						if(!hovered){
							$('.sub-nav').hide();
						}
					});
				},
				function() {
					//hovered = false;
					$(this).children('.sub-nav').hide();
					$(this).children('a').removeClass("hovered");
					$('#form-buckets select').css({ visibility: "visible" });
				});
		});
*/
function getModels(manufacturer) {
	if (manufacturer == 0) {
		return false;
	}
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('GET', '/store/include/manufacturer_search.php?manufacturer=' + escape(manufacturer), true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
            //updateModelSelect(self.xmlHttpReq.responseText);
            modelSelectPopulate(self.xmlHttpReq.responseText);
        }
	}
    self.xmlHttpReq.send(null);
}

function modelSelectPopulate(str){
	var options = "";
	var model_array = str.split(",");
	for (i=0; i < model_array.length; i++){
		options += "<option value='"+model_array[i]+"'>"+model_array[i]+"</option>";
	}
	
	$("#models").html(options);

}

function updateModelSelect(str){
	for (x = document.modelsForm1.models.length; x >= 0; x--) {
		document.modelsForm1.models[x] = null;
	}
	
	var model_array = str.split(",");
	AddToOptionList(document.modelsForm.models, '0', 'Choose a Model:');
	for (var i = 0; i < model_array.length; i++) {
		AddToOptionList(document.modelsForm.models, model_array[i], model_array[i]);
	}
    
}
function AddToOptionList(OptionList, OptionValue, OptionText) {
	OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function SubmitManufacturerModelSearch() {
	if ($("#models").val() == 0) {
		alert ('Please pick a model to search for.');
		return false;
	}
	$("#searchtext").val($("#manufacturer").val() + " " + $("#models").val());
	$("#modelsForm").submit();
}
