/*
WAS DOING THIS VIA AJAX, BUT NOW DOING JUST ON PAGE LOAD
function loadCars() {
	document.getElementById('results').style.display = "none";
	document.getElementById('results_loading').style.display = "block";
	
	var url = "/includes/ajax_cars.php";
	var f = document.searchForm;
		
	var make = f.make.options[f.make.selectedIndex].value;
	var model = f.model.options[f.model.selectedIndex].value;
	
	var order = f.order.options[f.order.selectedIndex].value;
	var view = f.view.value;
	
	var price_min = f.price_min.value;
	if(price_min == "$ min price") price_min = "";
	
	var price_max = f.price_max.value;
	if(price_max == "$ max price") price_max = "";
	
	var year_min = f.year_min.options[f.year_min.selectedIndex].value;
	var year_max = f.year_max.options[f.year_max.selectedIndex].value;

	var mileage_min = f.mileage_min.value;
	if(mileage_min == "min mileage") mileage_min = "";
	
	var mileage_max = f.mileage_max.value;
	if(mileage_max == "max mileage") mileage_max = "";
	
	var color = f.color.options[f.color.selectedIndex].value;
	var type = f.type.options[f.type.selectedIndex].value;
	
	var http = new XMLHttpRequest();
	var params = "action=getCars&make="+make+"&model="+model+"&view="+view+"&order="+order+"&price_min="+price_min+"&price_max="+price_max+"&color="+color+"&type="+type+"&mileage_min="+mileage_min+"&mileage_max="+mileage_max+"&year_min="+year_min+"&year_max="+year_max;
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			if(http.responseText != "") {
				document.getElementById('results').innerHTML = http.responseText;
				document.getElementById('results_loading').style.display = "none";
				document.getElementById('results').style.display = "block";
			} else {
				document.getElementById('results_loading').style.display = "none";
				document.getElementById('results').innerHTML = "";
				document.getElementById('results').style.display = "block";
			}
		}
	}
	http.send(params);
}*/

function toggleRefineIcon(elem) {
	var i = document.getElementById(elem);
	if(i.src.substr(-9,5) == "minus") {
		i.src = "/images/buttons/plus.jpg"
	} else {
		i.src = "/images/buttons/minus.jpg"
	}
}

function submitSearch() {
	var f = document.searchForm;
	//disable any fields that are empty
	if(f.make.options[f.make.selectedIndex].value == "") { f.make.disabled = true; }
	if(f.model.options[f.model.selectedIndex].value == "") { f.model.disabled = true; }
	if(f.year_min.options[f.year_min.selectedIndex].value == "") { f.year_min.disabled = true; }
	if(f.year_max.options[f.year_max.selectedIndex].value == "") { f.year_max.disabled = true; }
	if(f.price_min.value == "" || f.price_min.value == "$ min price") { f.price_min.disabled = true; }
	if(f.price_max.value == "" || f.price_max.value == "$ max price") { f.price_max.disabled = true; }
	//if(f.location.value == "" || f.location.value == "City or Zip code") { f.location.disabled = true; }
	//if(f.loc_distance.options[f.loc_distance.selectedIndex].value == "") { f.loc_distance.disabled = true; }
	if(f.order.options[f.order.selectedIndex].value == "") { f.order.disabled = true; }
	if(f.view.value == "") { f.view.disabled = true; }
	if(f.photos.value == "" || f.photos.value == "all") { f.photos.disabled = true; }
	//if(f.color.options[f.color.selectedIndex].value == "") { f.color.disabled = true; }
	if(f.type.options[f.type.selectedIndex].value == "") { f.type.disabled = true; }
	//if(f.doors.options[f.doors.selectedIndex].value == "") { f.doors.disabled = true; }
	if(f.mileage_min.value == "" || f.mileage_min.value == "min mileage") { f.mileage_min.disabled = true; }
	if(f.mileage_max.value == "" || f.mileage_max.value == "max mileage") { f.mileage_max.disabled = true; }
	if(f.tab.value == "") { f.tab.disabled = true; }
	if(f.dealer.options[f.dealer.selectedIndex].value == "") { f.dealer.disabled = true; }
	//f.perPageList.disabled = true;
	//document.getElementById('perPageList').disabled = true;
	
	//submit the form
	f.submit();
}

function resetSearch() {
	var f = document.searchForm;
	f.year_min.selectedIndex = 0;
	f.year_max.selectedIndex = 0;
	f.price_min.value = "$ min price";
	f.price_max.value = "$ max price";
	f.order.selectedIndex = 0;
	f.type.selectedIndex = 0;
	//f.doors.selectedIndex = 0;
	f.mileage_min.value = "min mileage";
	f.mileage_max.value = "max mileage";
	f.dealer.selectedIndex = 0;
	//submit the form
	submitSearch();
}

function selectCity(city) {
	var f = document.searchForm;
	f.location.value = city;
	submitSearch();
}

function setPriceRange(low,high) {
	var f = document.searchForm;
	f.price_min.value = low;
	f.price_max.value = high;
	submitSearch();
}
function clearRefineOption(field) {
	var f = document.searchForm;
	switch(field) {
		case "year": f.year_min.selectedIndex = 0;  f.year_max.selectedIndex = 0;
			break;
		case "price": f.price_min.value = "$ min price"; f.price_max.value = "$ max price";
			break;
		case "mileage": f.mileage_min.value = "min mileage"; f.mileage_max.value = "max mileage";
			break;
		case "type": f.type.selectedIndex = 0;  f.year_max.selectedIndex = 0;
			break;
		case "dealer": f.dealer.selectedIndex = 0;  f.year_max.selectedIndex = 0;
			break;
	}
}
function changeNumPerPage() {
	var f = document.searchForm;
	var ppf = document.perPageListForm;
	var num = ppf.perPageList.options[ppf.perPageList.selectedIndex].value;
	f.perPage.value = num;
	f.perPage.disabled = false;
	submitSearch();
}
