function populate_models(myForm) {
	if (document.forms[myForm].manufacturer_id.options[0].text == "Select Make") {
		document.forms[myForm].manufacturer_id.options[0] = null;
		document.forms[myForm].model_id.disabled = false;
	}else if (document.forms[myForm].manufacturer_id.options[0].text == "Any Make") {
		document.forms[myForm].model_id.disabled = false;
	}
	document[myForm].model_id.options.length = 0;
	manufacturer_value = document[myForm].manufacturer_id.value;
	if (manufacturer_value != "Any") {
		model_length = model[manufacturer_value].length;
		if (myForm == "searchForm") {
			document.forms[myForm].model_id.options[0] = new Option("All Models","Any");
			for(i=0;i<model_length;i++) {
				document.forms[myForm].model_id.options[i+1] = new Option(model[manufacturer_value][i]['title'],model[manufacturer_value][i]['id']);
			}
		}else{
			for(i=0;i<model_length;i++) {
				document.forms[myForm].model_id.options[i] = new Option(model[manufacturer_value][i]['title'],model[manufacturer_value][i]['id']);
			}
		}
	}else{
		document.forms[myForm].model_id.options[0] = new Option("All Models","Any");
		document.forms[myForm].model_id.disabled = true;
	}
}

function rowSelect(myId) {
	myTable = document.getElementById('varTable');
	rows = myTable.getElementsByTagName("tr");
	for (i=0;i<rows.length;i++) {
		if (rows[i].className == "excel_row_selected") {
			rows[i].className = "excel_row";
		}
	}
	featured = document.getElementById('row_'+myId);
	featured.className = "excel_row_selected";
	document.form1.vehicle_id.value = myId;
}

function swap_main(mySrc,myCaption) {
	document.getElementById('img_main').src = mySrc;
	document.getElementById('caption').innerHTML = myCaption;
}

function select_sort(me) {
	url = window.location.href;
	sort_value = document.forms[me.form.name].sort.value + " " + document.forms[me.form.name].sort_direction.value;
	sort_position = url.lastIndexOf("sort=");
	
	if (sort_position != -1) {
		and_position = url.indexOf("&",sort_position);
		if (and_position != -1) {
			url_f = url.substring(0,sort_position+5) + sort_value;
			url_l = url.substring(and_position);
			url = url_f + url_l;
		}else{
			url = url.substring(0,sort_position+5) + sort_value;
		}
	}else{
		if (url.lastIndexOf("?") != -1) {
			url += "&sort="+sort_value;
		}else{
			url += "?sort="+sort_value;
		}
	}
	window.location.href = url;
}

function sort_dir(formName) {
	if (document.forms[formName].sort_direction.value == "DESC") {
		document.forms[formName].sort_direction.value = "ASC";
	}else{
		document.forms[formName].sort_direction.value = "DESC";
	}
	select_sort(document.forms[formName].sort);
}

function goPage(pageValue) {
	url = window.location.href;
	page_position = url.lastIndexOf("page=");
	
	if (page_position != -1) {
		and_position = url.indexOf("&",page_position);
		if (and_position != -1) {
			url_f = url.substring(0,page_position+5) + pageValue;
			url_l = url.substring(and_position);
			url = url_f + url_l;
		}else{
			url = url.substring(0,page_position+5) + pageValue;
		}
	}else{
		if (url.lastIndexOf("?") != -1) {
			url += "&page="+pageValue;
		}else{
			url += "?page="+pageValue;
		}
	}
	window.location.href = url;
}

function nextPage() {
	url = window.location.href;
	page_position = url.lastIndexOf("page=");
	
	if (page_position != -1) {
		and_position = url.indexOf("&",page_position);
		if (and_position != -1) {
			pageValue = url.substring(page_position+5,and_position)+1;
			url_f = url.substring(0,page_position+5) + pageValue;
			url_l = url.substring(and_position);
			url = url_f + url_l;
		}else{
			pageValue = url.substring(page_position+5);
			url = url.substring(0,page_position+5) + pageValue;
		}
	}else{
		if (url.lastIndexOf("?") != -1) {
			url += "&page="+2;
		}else{
			url += "?page="+2;
		}
	}
	window.location.href = url;
}

function prevPage() {
	url = window.location.href;
	page_position = url.lastIndexOf("page=");
	
	if (page_position != -1) {
		and_position = url.indexOf("&",page_position);
		if (and_position != -1) {
			pageValue = url.substring(page_position+5,and_position)-1;
			url_f = url.substring(0,page_position+5) + pageValue;
			url_l = url.substring(and_position);
			url = url_f + url_l;
		}else{
			pageValue = url.substring(page_position+5);
			url = url.substring(0,page_position+5) + pageValue;
		}
		window.location.href = url;
	}	
}