/* START OF SETUP - this stuff really belongs on SEARCHBOX.CFM */

	// ===================================
	// Set Arrays for the two search paths
	// A third path could be needed for Motability
	// ===================================


	var makeids = new Array(2);
		// Put several arrays inside that array
		makeids[0] = new Array(1);
		makeids[1] = new Array(1);

	var makenames = new Array(2);
		// Put several arrays inside that array
		makenames[0] = new Array(1);
		makenames[1] = new Array(1);





	var modelids = new Array(2);
		// Put several arrays inside that array
		
		// KEEP IDs IN CASE WE GO FOR SOME SORT OF LKP METHOD, WHICH AVOIDS SPELLING MISTAKES.
		
		modelids[0] = new Array(2);
		modelids[1] = new Array(2);

		modelids[0][0] = new Array(1);
		modelids[0][1] = new Array(1);
		modelids[0][2] = new Array(1);
		modelids[0][3] = new Array(1);
		modelids[0][4] = new Array(1);
		modelids[0][5] = new Array(1);

		modelids[1][0] = new Array(1);
		modelids[1][1] = new Array(1);
		modelids[1][2] = new Array(1);
		modelids[1][3] = new Array(1);
		modelids[1][4] = new Array(1);


	var modelnames = new Array(2);
		// Put several arrays inside that array
		modelnames[0] = new Array(2);
		modelnames[1] = new Array(2);

		modelnames[0][0] = new Array(1);
		modelnames[0][1] = new Array(1);
		modelnames[0][2] = new Array(1);
		modelnames[0][3] = new Array(1);
		modelnames[0][4] = new Array(1);
		modelnames[0][5] = new Array(1);

		modelnames[1][0] = new Array(1);
		modelnames[1][1] = new Array(1);
		modelnames[1][2] = new Array(1);
		modelnames[1][3] = new Array(1);
		modelnames[1][4] = new Array(1);



	var initialbodyids = new Array(2);
		// Put several arrays inside that array
		initialbodyids[0] = new Array(1);
		initialbodyids[1] = new Array(1);

	var initialbodynames = new Array(2);
		// Put several arrays inside that array
		initialbodynames[0] = new Array(1);
		initialbodynames[1] = new Array(1);




	var bodyids = new Array(2);
		// Put several arrays inside that array
		bodyids[0] = new Array(2);
		bodyids[1] = new Array(2);

		bodyids[0][0] = new Array(1);
		bodyids[0][1] = new Array(1);
		bodyids[0][2] = new Array(1);
		bodyids[0][3] = new Array(1);
		bodyids[0][4] = new Array(1);
		bodyids[0][5] = new Array(1);

		bodyids[1][0] = new Array(1);
		bodyids[1][1] = new Array(1);
		bodyids[1][2] = new Array(1);
		bodyids[1][3] = new Array(1);
		bodyids[1][4] = new Array(1);

	var bodynames = new Array(2);
		// Put several arrays inside that array
		bodynames[0] = new Array(2);
		bodynames[1] = new Array(2);

		bodynames[0][0] = new Array(1);
		bodynames[0][1] = new Array(1);
		bodynames[0][2] = new Array(1);
		bodynames[0][3] = new Array(1);
		bodynames[0][4] = new Array(1);
		bodynames[0][5] = new Array(1);

		bodynames[1][0] = new Array(1);
		bodynames[1][1] = new Array(1);
		bodynames[1][2] = new Array(1);
		bodynames[1][3] = new Array(1);
		bodynames[1][4] = new Array(1);




	// For fueltype, just one set (dimension) at present
	var fuelids = new Array(1);
	var fuelnames = new Array(1);

	// For gearbox, just one set (dimension) at present
	var gearids = new Array(1);
	var gearnames = new Array(1);

	// For dealership, just one set (dimension) at present
	var dealerids = new Array(1);
	var dealernames = new Array(1);




	// =====================
	// Array Set 1 USED MAKE
	// =====================
	// ******* Make sure you keep the IDs for all these - as what if the text has spelling mistakes! *******
	makeids[0][0] = 4;
	makeids[0][1] = 5;
	makeids[0][2] = 1;
	makeids[0][3] = 3;
	makeids[0][4] = 2;
	makeids[0][5] = 10;

	makenames[0][0] = "Mercedes-Benz";
	makenames[0][1] = "Smart";
	makenames[0][2] = "Chrysler";
	makenames[0][3] = "Jeep";
	makenames[0][4] = "Dodge";
	makenames[0][5] = "AMG";

	// ======================
	// Array Set 1 USED MODEL
	// ======================
	// For each make there is a different set of models
	// Use modelid as in lkp_models in the database
	/* Mercedes-Benz USED ones */
	modelids[0][0][0] = 20;
	modelids[0][0][1] = 21;
	modelids[0][0][2] = 22;
	modelids[0][0][3] = 23;
	modelids[0][0][4] = 24;
	modelids[0][0][5] = 25;
	modelids[0][0][6] = 26;
	modelids[0][0][7] = 27;
	modelids[0][0][8] = 28;
	modelids[0][0][9] = 29;
	modelids[0][0][10] = 30;
	modelids[0][0][11] = 31;
	modelids[0][0][12] = 32;
	modelids[0][0][13] = 33;
	modelids[0][0][14] = 34;
	modelids[0][0][15] = 35;
	modelids[0][0][16] = 36;
	modelids[0][0][17] = 38;
	modelids[0][0][18] = 39;	/* was: 39 */
	/* modelids[0][0][19] = 37; */

	/* Smart USED ones */
	modelids[0][1][0] = 41;
	modelids[0][1][1] = 42;
	modelids[0][1][2] = 43;
	/* modelids[0][1][3] = 40; */
	modelids[0][1][3] = 72;	/* was: 72 */

	/* Chrysler USED ones */
	modelids[0][2][0] = 1;
	modelids[0][2][1] = 2;
	modelids[0][2][2] = 3;
	modelids[0][2][3] = 4;
	modelids[0][2][4] = 5;
	modelids[0][2][5] = 6;
	modelids[0][2][6] = 7;
	modelids[0][2][7] = 8;
	modelids[0][2][8] = 9;	/* was: 9 */

	/* Jeep USED ones */
	modelids[0][3][0] = 14;
	modelids[0][3][1] = 15;
	modelids[0][3][2] = 16;
	modelids[0][3][3] = 17;
	modelids[0][3][4] = 18;
	modelids[0][3][5] = 19;	/* was: 19 */

	/* Dodge USED ones */
	modelids[0][4][0] = 10;
	modelids[0][4][1] = 11;
	modelids[0][4][2] = 12;
	modelids[0][4][3] = 69;
	modelids[0][4][4] = 13;	/* was: 13 */

	/* AMG USED ones */
	modelids[0][5][0] = 70;

	/* Mercedes-Benz USED ones */
	modelnames[0][0][0] = "A-Class";
	modelnames[0][0][1] = "B-Class";
	modelnames[0][0][2] = "C-Class";
	modelnames[0][0][3] = "CL-Class";
	modelnames[0][0][4] = "CLC-Class";
	modelnames[0][0][5] = "CLK-Class";
	modelnames[0][0][6] = "CLS-Class";
	modelnames[0][0][7] = "E-Class";
	modelnames[0][0][8] = "G-Class";
	modelnames[0][0][9] = "GL-Class";
	modelnames[0][0][10] = "M-Class";
	modelnames[0][0][11] = "R-Class";
	modelnames[0][0][12] = "S-Class";
	modelnames[0][0][13] = "SL-Class";
	modelnames[0][0][14] = "SLK-Class";
	modelnames[0][0][15] = "SLR-Class";
	modelnames[0][0][16] = "SLS-Class";
	modelnames[0][0][17] = "Viano";
	modelnames[0][0][18] = "Other Mercedes-Benz";
	/* modelnames[0][0][19] = "AMG"; */

	/* Smart USED ones */
	modelnames[0][1][0] = "Fortwo";	
	modelnames[0][1][1] = "Forfour";
	modelnames[0][1][2] = "Roadster";
	/* modelnames[0][1][3] = "City"; */
	modelnames[0][1][3] = "All Smart";

	/* Chrysler USED ones */
	modelnames[0][2][0] = "300C";
	modelnames[0][2][1] = "Crossfire";
	modelnames[0][2][2] = "Voyager";
	modelnames[0][2][3] = "Grand Voyager";
	modelnames[0][2][4] = "PT Cruiser";
	modelnames[0][2][5] = "Sebring";
	modelnames[0][2][6] = "Ypsilon";
	modelnames[0][2][7] = "Delta";
	modelnames[0][2][8] = "Other Chrysler";

	/* Jeep USED ones */
	modelnames[0][3][0] = "Cherokee";
	modelnames[0][3][1] = "Grand Cherokee";
	modelnames[0][3][2] = "Compass";
	modelnames[0][3][3] = "Patriot";
	modelnames[0][3][4] = "Wrangler";
	modelnames[0][3][5] = "Other Jeep";

	/* Dodge USED ones */
	modelnames[0][4][0] = "Avenger";
	modelnames[0][4][1] = "Caliber";
	modelnames[0][4][2] = "Nitro";
	modelnames[0][4][3] = "Journey";
	modelnames[0][4][4] = "Other Dodge";

	/* AMG USED ones */
	modelnames[0][5][0] = "AMG";


	// =====================
	// Array Set 1 USED BODY
	// =====================
	// The first set id for the initial version
	initialbodyids[0][0] = 1;
	initialbodyids[0][1] = 3;
	initialbodyids[0][2] = 4;
	initialbodyids[0][3] = 5;
	initialbodyids[0][4] = 6;
	initialbodyids[0][5] = 11;
	initialbodyids[0][6] = 12;
	initialbodyids[0][7] = 15;
	initialbodyids[0][8] = 16;
	/* 	initialbodyids[0][9] = 9;
	initialbodyids[0][10] = 13;
	initialbodyids[0][11] = 14; */

	initialbodynames[0][0] = "Cabriolet";		/* Convertible */
	initialbodynames[0][1] = "Coupe";
	initialbodynames[0][2] = "Estate";
	initialbodynames[0][3] = "Saloon";
	initialbodynames[0][4] = "Hatchback";
	initialbodynames[0][5] = "MPV";
	initialbodynames[0][6] = "SUV";
	initialbodynames[0][7] = "Station Wagon";
	initialbodynames[0][8] = "People Carrier";
	/*initialbodynames[0][9] = "4x4";
	initialbodynames[0][10] = "Roadster";
	initialbodynames[0][11] = "Off Roader"; */

	
	/* MB USED ones */
	bodyids[0][0][0] = 401;
	bodyids[0][0][1] = 402;
	bodyids[0][0][2] = 403;
	bodyids[0][0][3] = 404;
	bodyids[0][0][4] = 405;
	bodyids[0][0][5] = 408;
	bodyids[0][0][6] = 409;
	/*bodyids[0][0][7] = 406;
	bodyids[0][0][8] = 407;*/

	/* Smart USED ones */
	bodyids[0][1][0] = 501;
	bodyids[0][1][1] = 502;

	/* Chrysler USED ones */
	bodyids[0][2][0] = 101;
	bodyids[0][2][1] = 102;
	bodyids[0][2][2] = 103;
	bodyids[0][2][3] = 104;
	bodyids[0][2][4] = 105;
	bodyids[0][2][5] = 106;

	/* Jeep USED ones */
	/* bodyids[0][3][0] = 301;
	bodyids[0][3][1] = 302; */
	bodyids[0][3][0] = 303;

	/* Dodge USED ones */
	bodyids[0][4][0] = 201;
	bodyids[0][4][1] = 202;
	bodyids[0][4][2] = 203;

	/* AMG USED ones */
	bodyids[0][5][0] = 1001;
	bodyids[0][5][1] = 1002;


	/* MB USED ones */
	bodynames[0][0][0] = "Cabriolet";
	bodynames[0][0][1] = "Coupe";
	bodynames[0][0][2] = "Estate";
	bodynames[0][0][3] = "Saloon";
	bodynames[0][0][4] = "Hatchback";
	bodynames[0][0][5] = "SUV";
	bodynames[0][0][6] = "MPV";
	/*bodynames[0][0][7] = "Roadster";
	bodynames[0][0][8] = "Off Roader";*/

	/* Smart USED Ones */
	bodynames[0][1][0] = "Cabriolet";		/* Convertible */
	bodynames[0][1][1] = "Coupe";

	/* Chrysler USED Ones */
	bodynames[0][2][0] = "Cabriolet";		/* Convertible */
	bodynames[0][2][1] = "Coupe";
	bodynames[0][2][2] = "Estate";
	bodynames[0][2][3] = "MPV";
	bodynames[0][2][4] = "Saloon";
	bodynames[0][2][5] = "Hatchback";

	/* Jeep USED ones - need to get rid of Hard Top and Soft Top in due course */
	/* bodynames[0][3][0] = "Hard Top";
	bodynames[0][3][1] = "Soft Top"; */
	bodynames[0][3][0] = "Station Wagon";

	/* Dodge USED ones */
	bodynames[0][4][0] = "Hatchback";
	bodynames[0][4][1] = "Saloon";
	bodynames[0][4][2] = "Station Wagon";

	/* AMG USED ones */
	bodynames[0][5][0] = "Coupe";
	bodynames[0][5][1] = "Roadster";

/*
----Chrysler----
Cabriolet
Coupe
Estate
MPV
Saloon

----Dodge---
Hatchback
Saloon
Station Wagon

----Jeep---
Hard Top
Soft Top
Station Wagon

----Mercedes-Benz (OLD)----
Cabriolet
Coupe
Estate
Hatchback
Off Roader
People Carrier
Saloon

----Smart----
Cabriolet
Coupe
*/

	// ====================
	// Array Set 2 NEW MAKE
	// ====================
	makeids[1][0] = 8;
	makeids[1][1] = 9;
	makeids[1][2] = 6;
	makeids[1][3] = 7;
	makeids[1][4] = 11;

	makenames[1][0] = "Mercedes-Benz";
	makenames[1][1] = "Smart";
	makenames[1][2] = "Chrysler";
	makenames[1][3] = "Jeep";
	makenames[1][4] = "AMG";


	// =====================
	// Array Set 2 NEW MODEL
	// =====================
	// Use modelid as in lkp_models in the database
	/* Mercedes-Benz NEW ones */	
	modelids[1][0][0] = 50;
	modelids[1][0][1] = 51;
	modelids[1][0][2] = 52;
	modelids[1][0][3] = 53;
	modelids[1][0][4] = 54;
	modelids[1][0][5] = 55;
	modelids[1][0][6] = 56;
	modelids[1][0][7] = 57;
	modelids[1][0][8] = 76; /* was 58 for M-Class */
	modelids[1][0][9] = 59;
	modelids[1][0][10] = 60;
	modelids[1][0][11] = 61;
	modelids[1][0][12] = 62;
	modelids[1][0][13] = 63;
	modelids[1][0][14] = 64;

	/* Smart NEW ones */
	modelids[1][1][0] = 65;
	/* modelids[1][1][1] = 68; */

	/* Chrysler NEW ones */
	modelids[1][2][0] = 77;
	modelids[1][2][1] = 44;
	modelids[1][2][2] = 44;
	modelids[1][2][3] = 46;

	/* Jeep NEW ones */
	modelids[1][3][0] = 47;
	modelids[1][3][1] = 48;
	modelids[1][3][2] = 49;

	/* AMG NEW ones */
	modelids[1][4][0] = 71;


	/* Mercedes-Benz NEW ones */
	modelnames[1][0][0] = "A-Class";
	modelnames[1][0][1] = "B-Class";
	modelnames[1][0][2] = "C-Class";
	modelnames[1][0][3] = "CL-Class";
	modelnames[1][0][4] = "CLS-Class";
	modelnames[1][0][5] = "E-Class";
	modelnames[1][0][6] = "G-Class";
	modelnames[1][0][7] = "GL-Class";
	modelnames[1][0][8] = "ML-Class";
	modelnames[1][0][9] = "R-Class";
	modelnames[1][0][10] = "S-Class";
	modelnames[1][0][11] = "SL-Class";
	modelnames[1][0][12] = "SLK-Class";
	modelnames[1][0][13] = "SLS-Class";		/* was: SLS AMG */
	modelnames[1][0][14] = "Viano";

	/* Smart NEW ones */
	modelnames[1][1][0] = "Fortwo";
	/* modelnames[1][1][1] = "BRABUS"; */

	/* Chrysler NEW ones */
	modelnames[1][2][0] = "300C";
	modelnames[1][2][1] = "Delta";
	modelnames[1][2][2] = "Grand Voyager";
	modelnames[1][2][3] = "Ypsilon";
	/* modelnames[1][0][3] = "Chrysler Car Class Four";
	modelnames[1][0][4] = "Chrysler Car Class Five"; */

	/* Jeep NEW ones */
	modelnames[1][3][0] = "Compass";
	modelnames[1][3][1] = "Grand Cherokee";
	modelnames[1][3][2] = "Wrangler";

	/* AMG NEW ones */
	modelnames[1][4][0] = "AMG";


	// ====================
	// Array Set 2 NEW BODY
	// ====================
	// First set id for the initial version
	initialbodyids[1][0] = 1;
	initialbodyids[1][1] = 3;
	initialbodyids[1][2] = 4;
	initialbodyids[1][3] = 5;
	initialbodyids[1][4] = 6;
	initialbodyids[1][5] = 15;
	initialbodyids[1][6] = 9;
	initialbodyids[1][7] = 11;
	initialbodyids[1][8] = 12;
	initialbodyids[1][9] = 13;
	initialbodyids[1][10] = 16;
	/*initialbodyids[1][11] = 14;*/

	initialbodynames[1][0] = "Cabriolet";		/* Convertible */
	initialbodynames[1][1] = "Coupe";
	initialbodynames[1][2] = "Estate";
	initialbodynames[1][3] = "Saloon";
	initialbodynames[1][4] = "Hatchback";
	initialbodynames[1][5] = "Station Wagon";
	initialbodynames[1][6] = "4x4";
	initialbodynames[1][7] = "MPV";
	initialbodynames[1][8] = "SUV";
	initialbodynames[1][9] = "Roadster";
	initialbodynames[1][10] = "People Carrier";
	/*initialbodynames[1][11] = "Off Roader";*/


	/* MB NEW ones */
	bodyids[1][0][0] = 801;
	bodyids[1][0][1] = 802;
	bodyids[1][0][2] = 803;
	bodyids[1][0][3] = 804;
	bodyids[1][0][4] = 805;
	bodyids[1][0][5] = 807;
	bodyids[1][0][6] = 808;
	bodyids[1][0][7] = 809;
	bodyids[1][0][8] = 810;
	/*bodyids[1][0][9] = 806;*/

	/* Smart NEW ones */
	bodyids[1][1][0] = 901;
	bodyids[1][1][1] = 902;

	/* Chrysler NEW ones */
	bodyids[1][2][0] = 601;
	bodyids[1][2][1] = 602;
	bodyids[1][2][2] = 603;
	bodyids[1][2][3] = 604;
	bodyids[1][2][4] = 605;
	bodyids[1][2][5] = 606;
	bodyids[1][2][6] = 607;
	bodyids[1][2][7] = 608;

	/* Jeep NEW ones */
	bodyids[1][3][0] = 701;
	bodyids[1][3][1] = 702;

	/* AMG NEW ones */
	bodyids[1][4][0] = 1101;
	bodyids[1][4][1] = 1102;


	/* MB NEW ones */
	bodynames[1][0][0] = "Cabriolet";
	bodynames[1][0][1] = "Coupe";
	bodynames[1][0][2] = "Estate";
	bodynames[1][0][3] = "Saloon";
	bodynames[1][0][4] = "Hatchback";
	bodynames[1][0][5] = "MPV";
	bodynames[1][0][6] = "SUV";
	bodynames[1][0][7] = "People Carrier";
	bodynames[1][0][8] = "Roadster";
	/*bodynames[1][0][9] = "4x4";*/

	/* Smart NEW ones */
	bodynames[1][1][0] = "Cabriolet";
	bodynames[1][1][1] = "Coupe";

	/* Chrysler NEW ones */
	bodynames[1][2][0] = "Cabriolet";
	bodynames[1][2][1] = "Coupe";
	bodynames[1][2][2] = "Estate";
	bodynames[1][2][3] = "4x4";
	bodynames[1][2][4] = "Hatchback";
	bodynames[1][2][5] = "People Carrier";
	bodynames[1][2][6] = "Roadster";
	bodynames[1][2][7] = "Saloon";

	/* Jeep NEW ones */
	bodynames[1][3][0] = "4x4";
	bodynames[1][3][1] = "Station Wagon";

	/* AMG NEW ones */
	bodynames[1][4][0] = "Coupe";
	bodynames[1][4][1] = "Roadster";



	// ===========
	// FUEL (BOTH)
	// ===========
	fuelids[0] = 1;
	fuelids[1] = 2;
	/* fuelids[2] = 3;
	fuelids[3] = 4;
	fuelids[4] = 5; */

	fuelnames[0] = "Petrol";
	fuelnames[1] = "Diesel";
	/* fuelnames[2] = "LPG";
	fuelnames[3] = "Biodiesel";
	fuelnames[4] = "Hybrid"; */


	// ==============
	// GEARBOX (BOTH)
	// ==============
	gearids[0] = 1;
	gearids[1] = 2;

	gearnames[0] = "Automatic";
	gearnames[1] = "Manual";


	// ******* Make sure you keep the IDs for this one - need for all of them! *******
	dealerids[0] = 1;	// *** KEEP!!! ***
	dealerids[1] = 2;	// *** KEEP!!! ***
	dealerids[2] = 3;	// *** KEEP!!! ***
	dealerids[3] = 4;	// *** KEEP!!! ***
	dealerids[4] = 5;	// *** KEEP!!! ***
	dealerids[5] = 6;	// *** KEEP!!! ***
	dealerids[6] = 7;	// *** KEEP!!! ***
	dealerids[7] = 8;	// *** KEEP!!! ***
	dealerids[8] = 9;	// *** KEEP!!! ***
	dealerids[9] = 10;	// *** KEEP!!! ***
	// ******* Make sure you keep the IDs for this one *******



	// ==============
	// DEALERS (BOTH)
	// ==============

	dealernames[0] = "Chrysler Jeep & Dodge of Shrewsbury";
	dealernames[1] = "Chrysler Jeep & Dodge of Wolverhampton";
	dealernames[2] = "Mercedes-Benz of Shrewsbury";
	dealernames[3] = "Mercedes-Benz of Stafford";
	dealernames[4] = "Mercedes-Benz of Stoke";
	dealernames[5] = "Mercedes-Benz of Stourbridge";
	dealernames[6] = "Mercedes-Benz of Walsall";
	dealernames[7] = "Mercedes-Benz of Wolverhampton";
	dealernames[8] = "Mercedes-Benz of Worcester";
	dealernames[9] = "Smart Wolverhampton";




// Now make set some choices
// These are now set on searchbox.cfm
/* window.chosentype = 1;
window.chosenmake = 0;
window.chosenmodel = 0;
window.chosenbody = 0;
window.chosenfuel = 0;
window.chosendealership = 0; */

/* END OF SETUP - this stuff really belongs on SEARCHBOX.CFM */











// This should also be the initialise function
function setCarType(radiopressed) {
	// alert('radiopressed: '+radiopressed);

	// Now pick one to use!!!
	if (radiopressed==0) {
		window.chosentype = 0;
		document.getElementById('car_type_chosen').value= 'used';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_on_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_off_trans.gif';
	}
			
	if (radiopressed==1) {
		window.chosentype = 1;
		document.getElementById('car_type_chosen').value= 'new';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_off_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_on_trans.gif';

		// blank out the results found for new cars
		document.getElementById('num_results_found').innerHTML = 'New Cars';
	} 


	// Zap the contents of our hidden storers
	document.getElementById('car_make_chosen').value= 999;
	document.getElementById('car_model_chosen').value= 999;
	document.getElementById('car_body_chosen').value= 999;
	document.getElementById('car_fuel_chosen').value= 999;
	document.getElementById('car_gearbox_chosen').value= 999;
	document.getElementById('car_dealership_chosen').value= 999;
	window.chosenmake = 999;
	window.chosenmodel = 999;
	window.chosenbody = 999;
	window.chosenfuel = 999;
	window.chosengearbox = 999;
	window.chosendealership = 999;


	// Want to reset the hidden storers of what direction they want the columns to be in back to original setting.
	// Morton wants it to forget what it was remembering.
	document.getElementById('col_vehicle_dir').value = 'asc';
	document.getElementById('col_model_dir').value = 'asc';
	document.getElementById('col_year_dir').value = 'desc';
	document.getElementById('col_mileage_dir').value = 'desc';
	document.getElementById('col_price_dir').value = 'asc';
	document.getElementById('col_location_dir').value = 'desc';
	document.getElementById('most_recently_clicked').value = 'col_price_dir';
	// alert('RESET ONE, most_recently_clicked: '+document.getElementById('most_recently_clicked').value)
	// This is great here but we also want it altering after someone makes a change on the form itself
	// i.e. this should also occur at the end of "setChoices"


	// Only need to setup the next menu, not all of them.
	setMakeMenu()
	flushModelMenu()
	
	// Set Initial Car Body Styles
	setInitialBodyMenu()

	// What happened to petrol? I don't know! Think we just leave it as standard! (Also see the comment two comments above this one.)
	// What about gearbox? I think we just leave it as standard!
	/* setFuelMenu()
	setGearBoxMenu() */
	// We don't let them choose from these at the start as it could present hundreds of cars in the search results page.
	
	setDealershipMenu()

	// For used cars get extra info via AJAX
	// if (window.chosentype == 0) {
	if (radiopressed==0) {
		// call up another function to get current number of results found
		getNumResults()
	}
} // End of setCarType










// If we are on a Search Results page, reset the above to the current form settings
function setSearchResultsForm() {
	if (window.chosentype==1) {
		window.chosentype = 1;
		document.getElementById('car_type_chosen').value= 'new';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_off_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_on_trans.gif';

		// blank out the results found for new cars
		document.getElementById('num_results_found').innerHTML = 'New Cars';
	} 

	else {
		window.chosentype = 0;
		document.getElementById('car_type_chosen').value= 'used';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_on_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_off_trans.gif';
	}


	// Clone the form settings into our hidden storers
	document.getElementById('car_make_chosen').value= window.chosenmake;
	document.getElementById('car_model_chosen').value= window.chosenmodel;
	document.getElementById('car_body_chosen').value= window.chosenbody;
	document.getElementById('car_fuel_chosen').value= window.chosenfuel;
	document.getElementById('car_gearbox_chosen').value= window.chosengearbox;
	document.getElementById('car_dealership_chosen').value= window.chosendealership;


	// Setup the more straightforward selectors

	// Setup MAKE
	// alert('got here 1.1 with window.chosenmake: '+window.chosenmake);
	setMakeMenu()

	// Set the selected value to be the same as the one in the form
	for (p=0; p<document.getElementById('car_make').length; p++) {
		if(document.getElementById('car_make').options[p].value==window.chosenmake) {
			document.getElementById('car_make').options[p].selected=true;
		}
	}

	// change textword into it's array number.
	window.chosenmake = document.getElementById('car_make').selectedIndex-1;
	if(window.chosenmake==-1) {
		window.chosenmake = 999;
	}


	// alert('got here 2.1 with window.chosenmake: '+window.chosenmake);
	setModelMenu()

	for (q=0; q<document.getElementById('car_model').length; q++) {
		if(document.getElementById('car_model').options[q].value==window.chosenmodel) {
			document.getElementById('car_model').options[q].selected=true;
		}
	}


	// change textword into it's array number.
	window.chosenmodel = document.getElementById('car_model').selectedIndex-1;
	/* alert("document.getElementById('car_model_chosen').value: "+document.getElementById('car_model_chosen').value+"\nwindow.chosenmodel: "+window.chosenmodel) */
	
	if(window.chosenmodel==-1) {
		window.chosenmodel = 999;
	}




	// Now setup the more complicated selector for body

	// if make is unknown and model is unknown we want to see ALL possible bodies
	if(window.chosenmake == 999 && window.chosenmodel == 999) {
		setInitialBodyMenu()
	}

	// if make IS known while model is unknown we want to see bodies applicable to make
	else if(window.chosenmake != 999 && window.chosenmodel == 999) {
		setBodyMenu()		
	}

	// if both make and model are known want to see bodies applicable to the model
	// else if(window.chosenmake != 999 && window.chosenmodel != 999) {
	else {
		refineBodyMenu()		
	}






	setFuelMenu()

	for (s=0; s<document.getElementById('car_fuel').length; s++) {
		if(document.getElementById('car_fuel').options[s].value==window.chosenfuel) {
			document.getElementById('car_fuel').options[s].selected=true;
		}
	}

	// change textword into it's array number.
	window.chosenfuel = document.getElementById('car_fuel').selectedIndex-1;
	if(window.chosenfuel==-1) {
		window.chosenfuel = 999;
	}


	setGearBoxMenu()
	for (t=0; t<document.getElementById('car_gearbox').length; t++) {
		if(document.getElementById('car_gearbox').options[t].value==window.chosengearbox) {
			document.getElementById('car_gearbox').options[t].selected=true;
		}
	}

	// change textword into it's array number.
	window.chosengearbox = document.getElementById('car_gearbox').selectedIndex-1;
	if(window.chosengearbox==-1) {
		window.chosengearbox = 999;
	}


	setDealershipMenu()
	// alert('window.chosendealership: '+window.chosendealership)

	if(window.chosenmake != 999) {
		// alert('about to refine dealership...\nwindow.chosendealership: '+window.chosendealership)
		refineDealershipMenu()
	}

	for (t=0; t<document.getElementById('car_dealership').length; t++) {
		if(document.getElementById('car_dealership').options[t].value==window.chosendealership) {
			document.getElementById('car_dealership').options[t].selected=true;
		}
	}

	// change textword into it's array number.
	window.chosendealership = document.getElementById('car_dealership').selectedIndex-1;
	if(window.chosendealership==-1) {
		window.chosendealership = 999;
	}



	// Set the selected value to be the same as the one in the form
	// SelectedIndex no use when the values are text
	// alert('selectedindex: '+document.getElementById('car_make').selectedIndex+'\nchosenmake: '+window.chosenmake)
	// document.getElementById('car_make').selectedIndex = window.chosenmake;
	// document.getElementById('car_model').selectedIndex = window.chosenmodel;
	// document.getElementById('car_fuel').selectedIndex = window.chosenfuel;
	// document.getElementById('car_dealership').selectedIndex = window.chosendealership;	


	// For used cars get extra info via AJAX
	if (window.chosentype == 0) {

		if (window.chosenmake==5) {
			// blank out the results found for AMG cars
			document.getElementById('num_results_found').innerHTML = 'AMG Cars';
		}
		else {
			// call up another function to get current number of results found
			getNumResults()
		}

	}

} // End of setSearchResultsForm









function setChoices(choicemade) {
	// alert('choicemade: '+choicemade);

	/* ===== CHOICE 1: MAKE ===== */
	if(choicemade=='car_make') {
		// alert('before: '+window.chosenmake);
		if (document.getElementById('car_make').selectedIndex == 0) {
			window.chosenmake = 999;
		}
		else {
			window.chosenmake = document.getElementById('car_make').selectedIndex-1;
		}

		document.getElementById('car_make_chosen').value = document.getElementById('car_make').options[document.getElementById('car_make').selectedIndex].value;
		// alert('after: '+window.chosenmake);

		// Zap any storer for previous model selected
		window.chosenmodel = 999;
		document.getElementById('car_model_chosen').value = 999;

		window.chosenbody = 999;
		document.getElementById('car_body_chosen').value = 999;


		// junk window.chosenmake = document.getElementById('car_make').selectedIndex-1;
		setModelMenu()
		setBodyMenu()
		setFuelMenu()
		setGearBoxMenu()


		// Just before we setup the dealerships, let's wipe any previous choice held in "memory"
		// alert('wiping dealership!');
		document.getElementById('car_dealership_chosen').value = 999;
		window.chosendealership = 999;


		if (document.getElementById('car_make').selectedIndex == 0) {
			// If make is reset then the dealerships menu also needs to be reset to show them all
			setDealershipMenu();
		}
		else {
			// In most cases we use refineDealershipMenu() to get only the dealerships that are relevant to the chosen make!
			refineDealershipMenu()
		}

	}


	/* ===== CHOICE 2: MODEL ===== */
	if(choicemade=='car_model') {
		window.chosenmodel = document.getElementById('car_model').selectedIndex-1;
		if(window.chosenmodel==-1) {
			window.chosenmodel = 999;
		}

		document.getElementById('car_model_chosen').value = document.getElementById('car_model').options[document.getElementById('car_model').selectedIndex].value;



		// if make is unknown and model is unknown we want to see ALL possible bodies
		if(window.chosenmake == 999 && window.chosenmodel == 999) {
			setInitialBodyMenu()
		}
	
		// if make IS known while model is unknown we want to see bodies applicable to make
		else if(window.chosenmake != 999 && window.chosenmodel == 999) {
			setBodyMenu()		
		}
	
		// We know the make (by now) and must have a model as well
		else {
			refineBodyMenu()
		}

		refineFuelMenu()
		refineGearBoxMenu()
	}



	/* ===== CHOICE 3: BODY ===== */
	if(choicemade=='car_body') {
		window.chosenbody = document.getElementById('car_body').selectedIndex-1;
		if(window.chosenbody==-1) {
			  window.chosenbody = 999;
		}

		document.getElementById('car_body_chosen').value = document.getElementById('car_body').options[document.getElementById('car_body').selectedIndex].value;
	}


	/* ===== CHOICE 4: FUEL ===== */
	if(choicemade=='car_fuel') {
		window.chosenfuel = document.getElementById('car_fuel').selectedIndex;
		document.getElementById('car_fuel_chosen').value = document.getElementById('car_fuel').options[document.getElementById('car_fuel').selectedIndex].value;
	}


	/* ===== CHOICE 5: GEARBOX ===== */
	if(choicemade=='car_gearbox') {
		window.chosengearbox = document.getElementById('car_gearbox').selectedIndex;
		document.getElementById('car_gearbox_chosen').value = document.getElementById('car_gearbox').options[document.getElementById('car_gearbox').selectedIndex].value;
	}


	/* ===== CHOICE 6: DEALERSHIP ===== */
	if(choicemade=='car_dealership') {
		/* alert('dealership chosen: ' + document.getElementById('car_dealership').options[document.getElementById('car_dealership').selectedIndex].value); */
		window.chosendealership = document.getElementById('car_dealership').selectedIndex;
		document.getElementById('car_dealership_chosen').value = document.getElementById('car_dealership').options[document.getElementById('car_dealership').selectedIndex].value;
	} 



	// In all cases, if a change was made to the form, we want to reset the direction columns back to normal
	document.getElementById('col_vehicle_dir').value = 'asc';
	document.getElementById('col_model_dir').value = 'asc';
	document.getElementById('col_year_dir').value = 'desc';
	document.getElementById('col_mileage_dir').value = 'desc';
	document.getElementById('col_price_dir').value = 'asc';
	document.getElementById('col_location_dir').value = 'desc';
	document.getElementById('most_recently_clicked').value = 'col_price_dir';
	// alert('RESET TWO, most_recently_clicked: '+document.getElementById('most_recently_clicked').value)
	


	// For used cars get extra info via AJAX
	if (window.chosentype == 0) {

		if (window.chosenmake==5) {
			// blank out the results found for AMG cars
			document.getElementById('num_results_found').innerHTML = 'AMG Cars';
		}
		else {
			// call up another function to get current number of results found
			getNumResults()
		}

	}

}



// SELECTOR ONE
function setMakeMenu() {
	makearraylength = makenames[window.chosentype].length;
	// alert('make array length: '+makearraylength); 

	for (a=document.getElementById('car_make').options.length-1; a>0; a--) {
		// alert('removing '+a+': '+document.getElementById('car_make').options[a].text);
		document.getElementById('car_make').remove(a);
	}

	for (i=0; i<makearraylength;i++){
		if(makenames[window.chosentype][i]!=undefined) {
			addOption(i, 'car_make', makenames[window.chosentype][i], makenames[window.chosentype][i]);
		}
	}
}



// SELECTOR TWO
function setModelMenu() {

	// alert('got here 5 with\nwindow.chosenmake: '+window.chosenmake+'\nwindow.chosenmodel: '+window.chosenmodel);

	/* alert('setModelMenu called\nmodelnames[window.chosentype]: '+modelnames[window.chosentype]
	+'\n[window.chosentype]: '+window.chosentype
	+'\n[window.chosenmake]: '+window.chosenmake); */

	
    // Before adding any new ones we need to clear out the existing ones
	for (b=document.getElementById('car_model').options.length-1; b>0; b--) {
		// alert('removing '+b+': '+document.getElementById('car_model').options[b].text);
		document.getElementById('car_model').remove(b);
	}

	// Should we add any new ones?
	if(window.chosenmake==999) {
		// Do nothing
	}

	else {
		modelarraylength = modelnames[window.chosentype][window.chosenmake].length;	
		// alert('model array length: '+modelarraylength); 

		for (j=0; j<modelarraylength;j++){
			if(modelnames[window.chosentype][window.chosenmake][j]!=undefined) {
				// For New Search use the word; for Used search use the modelid
				if(window.chosentype == 1) {
					addOption(j, 'car_model', modelnames[window.chosentype][window.chosenmake][j], modelnames[window.chosentype][window.chosenmake][j]);
				}
				else {
					addOption(j, 'car_model', modelids[window.chosentype][window.chosenmake][j], modelnames[window.chosentype][window.chosenmake][j]);
				}
			}
		}
	}
}

function flushModelMenu() {

    // We need to clear out the existing ones
	for (b=document.getElementById('car_model').options.length-1; b>0; b--) {
		// alert('removing '+b+': '+document.getElementById('car_model').options[b].text);
		document.getElementById('car_model').remove(b);
	}

}




// SELECTOR THREE - INITIAL - For the start when we have neither a make nor a model...
function setInitialBodyMenu() {
	// alert('called setInitialBodyMenu');

    // Before adding any new ones we need to clear out the existing ones
	for (c=document.getElementById('car_body').options.length-1; c>0; c--) {
		// alert('removing '+c+': '+document.getElementById('car_body').options[c].text);
		document.getElementById('car_body').remove(c);
	}

	initialbodyarraylength  =  initialbodynames[window.chosentype].length;
	// alert('initial body array length: '+initialbodyarraylength); 

	for (k=0; k<initialbodyarraylength;k++){
		if(initialbodynames[window.chosentype][k]!=undefined) {
			addOption(k, 'car_body', initialbodynames[window.chosentype][k], initialbodynames[window.chosentype][k]);
		}
	}

}




// SELECTOR THREE - for when we have a make but no model yet...
function setBodyMenu() {
	// alert('called setBodyMenu');
	
    // Before adding any new ones we need to clear out the existing ones
	for (c=document.getElementById('car_body').options.length-1; c>0; c--) {
		// alert('removing '+c+': '+document.getElementById('car_body').options[c].text);
		document.getElementById('car_body').remove(c);
	}



	// Should we add any new ones?
	if(window.chosenmake==999) {
		// Do nothing
	}
	
	else {
		bodyarraylength  =  bodynames[window.chosentype][window.chosenmake].length;
		/* alert('bodynames[window.chosentype][window.chosenmake]: '+bodynames[window.chosentype][window.chosenmake]+'\nbodynames[window.chosentype][window.chosenmake].length: '+bodynames[window.chosentype][window.chosenmake].length+'\nbody array length: '+bodyarraylength); */

		for (k=0; k<bodyarraylength;k++){
			// alert('bodynames[window.chosentype][window.chosenmake][k]: '+bodynames[window.chosentype][window.chosenmake][k])
			if(bodynames[window.chosentype][window.chosenmake][k]!=undefined) {
				addOption(k, 'car_body', bodynames[window.chosentype][window.chosenmake][k], bodynames[window.chosentype][window.chosenmake][k]);
			}
		}




		// if the there is only one choice, then pre-select it!
		if(bodyarraylength==1) {
			document.getElementById('car_body').selectedIndex = 1;
		}



		// if we know what body style they have chosen, then select it.
		// more for the second page, so do nothing if choice is currently 999
		if(bodyarraylength>1 && window.chosenbody != 999) {
			// alert('window.chosenbody: '+window.chosenbody)	

			// which one has the current word?
			mychosenindex = 1;
			len_options = document.getElementById('car_body').options.length;
			for(m=0;m<len_options;m++) {
				// alert(document.getElementById('car_body').options[m].text+' vs '+ window.chosenbody+' let battle commence...')
				if(document.getElementById('car_body').options[m].text == window.chosenbody) {
					// alert("We got one!!!!!!!!!!!! = " + m)
					mychosenindex = m;
				}
			}
	
			document.getElementById('car_body').selectedIndex = mychosenindex;
	
		}



	}
}



// SELECTOR THREE - REFINE - for when we have a make and a model...
function refineBodyMenu() {
	// alert('called refineBodyMenu');
	// alert('Refine the BODY options for this model');
	// alert('rbn: '+typeof(refinedbodynames))

	/*	// debug
	if(typeof(refinedbodynames)=="undefined") {
		alert('it has not been defined yet')
	}
	else {
		alert('before: '+refinedbodynames)
	} */

	// This should wipe previous instances
	refinedbodyids = new Array(1);
	refinedbodynames = new Array(1);

	/* // debug
	alert('after: '+refinedbodynames)
	*/

	// Could use SPLICE and SLICE to CHOP stuff.
	// SPLICE will alter the array itself, don't use it.
	// SLICE is non-destructive.
	// slice(start, end)

	// EXAMPLES

	// to chop off the edge ones we don't want anymore, i.e. to keep items 2-3
	// newdisplay = bodynames[0][0].slice(2, 3);

	// keep from left side
	// newdisplay = bodynames[0][0].slice(2);

	// keep from right side
	// newdisplay = bodynames[0][0].slice(-3);

	// to wipe an array entry with a clone of a later one - DESTROYS original array!
	// bodynames[0][0] = bodynames[0][0].slice(3, 4);

	// to put in a new array
	// newbodynames[0][0] = bodynames[0][0].slice(0, 4);

	// Basically we want to make a brand new array each time, delete the body options on the form
	// and then create new options for body using a new version of the code in the previous setBody() function.


	do_add_in_here = 1;


	// We know about USED and NEW cars.
	// Let's start with USED.
	if (window.chosentype==0) {
	

		// For Mercedes-Benz (Used)
		if (window.chosenmake==0) {

			if (window.chosenmodel==0 || window.chosenmodel==1) {
				refinedbodyids[0] = 405;
				refinedbodynames[0] = "Hatchback";
			}

			if (window.chosenmodel==2) {
				refinedbodyids[0] = 402;
				refinedbodyids[1] = 403;
				refinedbodyids[2] = 404;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Estate";
				refinedbodynames[2] = "Saloon";
			}

			// CL-Class
			if (window.chosenmodel==3) {
				/* refinedbodyids[0] = 401; */
				refinedbodyids[0] = 402;
				/* refinedbodynames[0] = "Cabriolet"; */
				refinedbodynames[0] = "Coupe";
			}

			// CLC-Class
			if (window.chosenmodel==4) {
				refinedbodyids[0] = 402;
				/* refinedbodyids[1] = 404; */
				refinedbodynames[0] = "Coupe";
				/* refinedbodynames[1] = "Saloon"; */
			}

			// CLK-Class
			if (window.chosenmodel==5) {
				refinedbodyids[0] = 401;
				refinedbodyids[1] = 402;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
			}

			// CLS-Class
			if (window.chosenmodel==6) {
				refinedbodyids[0] = 402;
				refinedbodynames[0] = "Coupe";
			}

			// E-CLass
			if (window.chosenmodel==7) {
				refinedbodyids[0] = 401;
				refinedbodyids[1] = 402;
				refinedbodyids[2] = 403;
				refinedbodyids[3] = 404;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
				refinedbodynames[2] = "Estate";
				refinedbodynames[3] = "Saloon";
			}

			// G-Class
			if (window.chosenmodel==8) {
				/* refinedbodyids[0] = 407;
				refinedbodynames[0] = "Off Roader"; */
				refinedbodyids[0] = 408;
				refinedbodynames[0] = "SUV";
			}

			// GL-CLass
			if (window.chosenmodel==9) {
				/* refinedbodyids[0] = 407;
				refinedbodynames[0] = "Off Roader"; */
				refinedbodyids[0] = 408;
				refinedbodynames[0] = "SUV";
			}

			// M-Class
			if (window.chosenmodel==10) {
				/* refinedbodyids[0] = 407;
				refinedbodynames[0] = "Off Roader"; */
				refinedbodyids[0] = 408;
				refinedbodynames[0] = "SUV";
			}

			// R-Class
			if (window.chosenmodel==11) {
				/* refinedbodyids[0] = 408;
				refinedbodynames[0] = "People Carrier"; */
				refinedbodyids[0] = 409;
				refinedbodynames[0] = "MPV";
			}

			// S-Class
			if (window.chosenmodel==12) {
				refinedbodyids[0] = 404;
				refinedbodynames[0] = "Saloon";
			}

			// SL-Class and SLK-Class
			if (window.chosenmodel==13 || window.chosenmodel==14) {
				refinedbodyids[0] = 401;
				refinedbodyids[1] = 406;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Roadster";
			}
	
			// SLR-Class
			if (window.chosenmodel==15) {
				refinedbodyids[0] = 402;
				refinedbodynames[0] = "Coupe";
			}

			// SLS-Class
			if (window.chosenmodel==16) {
				refinedbodyids[0] = 402;
				refinedbodyids[1] = 406;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Roadster";
			}

			// Viano
			if (window.chosenmodel==17) {
				refinedbodyids[0] = 409;
				refinedbodynames[0] = "MPV";
			}

			// Other Mercedes-Benz
			if (window.chosenmodel==18) {
				do_add_in_here = 0;
			}

		}// End of Mercedes-Benz (Used)



		// For Smart (Used)
		if (window.chosenmake==1) {

			if (window.chosenmodel==0 || window.chosenmodel==1) {
				refinedbodyids[0] = 501;
				refinedbodyids[1] = 502;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
			}

			if (window.chosenmodel==2) {
				refinedbodyids[0] = 501;
				refinedbodyids[1] = 502;
				/* refinedbodyids[2] = 503; */
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
				/* refinedbodynames[2] = "Roadster"; 	Even though it is called Roadster it doesn't have that as a bodystyle */
			}
	
			// Other Smart
			if (window.chosenmodel==3) {
				do_add_in_here = 0;
			}

		}// End of Smart (Used)



		// For Chrysler (Used)
		if (window.chosenmake==2) {
	
			if (window.chosenmodel==0) {
				// make shorter version!
				refinedbodyids[0] = 103;
				refinedbodyids[1] = 105;
				refinedbodynames[0] = "Estate";
				refinedbodynames[1] = "Saloon";
			}

			if (window.chosenmodel==1) {
				refinedbodyids[0] = 101;
				refinedbodyids[1] = 102;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
			}

			if (window.chosenmodel==2) {
				refinedbodyids[0] = 105;
				refinedbodynames[0] = "Saloon";
			}

			if (window.chosenmodel==3) {
				refinedbodyids[0] = 104;
				refinedbodynames[0] = "MPV";
			}

			if (window.chosenmodel==4) {
				refinedbodyids[0] = 103;
				refinedbodyids[1] = 106;
				refinedbodynames[0] = "Estate";
				refinedbodynames[1] = "Hatchback";
			}

			if (window.chosenmodel==5) {
				refinedbodyids[0] = 105;
				refinedbodynames[0] = "Saloon";
			}

			if (window.chosenmodel==6 || window.chosenmodel==7) {
				refinedbodyids[0] = 106;
				refinedbodynames[0] = "Hatchback";
			}

			// Other Chrysler
			if (window.chosenmodel==8) {
				do_add_in_here = 0;
			}

		} // End of Chrylser (Used)



		// For Jeep (Used)
		if (window.chosenmake==3) {

			if (window.chosenmodel==0 || window.chosenmodel==1 || window.chosenmodel==2 || window.chosenmodel==3) {
				refinedbodyids[0] = 303;
				refinedbodynames[0] = "Station Wagon";
			}

			if (window.chosenmodel==4) {
				refinedbodyids[0] = 301;
				refinedbodyids[1] = 302;
				refinedbodynames[0] = "Hard Top";
				refinedbodynames[1] = "Soft Top";
			}

			// Other Jeep
			if (window.chosenmodel==5) {
				do_add_in_here = 0;
			}

		}// End of Jeep (Used)



		// For Dodge (Used)
		if (window.chosenmake==4) {

			if (window.chosenmodel==0) {
				refinedbodyids[0] = 202;
				refinedbodynames[0] = "Saloon";
			}

			if (window.chosenmodel==1) {
				refinedbodyids[0] = 201;
				refinedbodynames[0] = "Hatchback";
			}

			if (window.chosenmodel==2 || window.chosenmodel==3) {
				refinedbodyids[0] = 203;
				refinedbodynames[0] = "Station Wagon";
			}

			// Other Dodge
			if (window.chosenmodel==4) {
				do_add_in_here = 0;
			}

		}// End of Dodge (Used)



		// For AMG (Used)
		if (window.chosenmake==5) {
	
			if (window.chosenmodel==0) {
				refinedbodyids[0] = 1001;
				refinedbodyids[1] = 1002;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Roadster";
			}

		} // End of AMG (Used)




	} // End of USED cars








	// Start of NEW cars
	if (window.chosentype==1) {



		// For Mercedes-Benz (New)
		if (window.chosenmake==0) {

			// A-Class
			if (window.chosenmodel==0) {
				refinedbodyids[0] = 805;
				refinedbodynames[0] = "Hatchback";
			}

			// B-Class
			if (window.chosenmodel==1) {
				refinedbodyids[0] = 805;
				refinedbodynames[0] = "Hatchback";
			}

			// C-Class
			if (window.chosenmodel==2) {
				refinedbodyids[0] = 802;
				refinedbodyids[1] = 803;
				refinedbodyids[2] = 804;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Estate";
				refinedbodynames[2] = "Saloon";
			}

			// CL-Class OR CLS-Class
			if (window.chosenmodel==3 || window.chosenmodel==4) {
				refinedbodyids[0] = 802;
				refinedbodynames[0] = "Coupe";
			}

			// E-Class
			if (window.chosenmodel==5) {
				refinedbodyids[0] = 801;
				refinedbodyids[1] = 802;
				refinedbodyids[2] = 803;
				refinedbodyids[3] = 804;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
				refinedbodynames[2] = "Estate";
				refinedbodynames[3] = "Saloon";
			}

			// G-Class and GL-Class - use newer SUV body style
			if (window.chosenmodel==6 || window.chosenmodel==7) {
				/* refinedbodyids[0] = 806;
				refinedbodynames[0] = "4x4"; */
				refinedbodyids[0] = 808;
				refinedbodynames[0] = "SUV";
			}

			// M-Class or ML-Class - new SUV body style
			if (window.chosenmodel==8) {
				refinedbodyids[0] = 808;
				refinedbodynames[0] = "SUV";
			}

			// R-Class - new MPV body style
			if (window.chosenmodel==9) {
				refinedbodyids[0] = 807;
				refinedbodynames[0] = "MPV";
			}
			
			// S-Class
			if (window.chosenmodel==10) {
				refinedbodyids[0] = 804;
				refinedbodynames[0] = "Saloon";
			}

			// SL-Class, SLK-Class
			if (window.chosenmodel==11 || window.chosenmodel==12) {
				refinedbodyids[0] = 810;
				refinedbodynames[0] = "Roadster";
			}

			// SLS Class
			if (window.chosenmodel==13) {
				refinedbodyids[0] = 802;
				refinedbodyids[1] = 810;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Roadster";
			}

			// Viano
			if (window.chosenmodel==14) {
				refinedbodyids[0] = 809;
				refinedbodynames[0] = "People Carrier";
			}

	
			/* if (window.chosenmodel==16) {
				refinedbodyids[0] = 801;
				refinedbodyids[1] = 802;
				refinedbodyids[2] = 803;
				refinedbodyids[3] = 804;
				refinedbodyids[4] = 805;
				refinedbodyids[5] = 806;
				refinedbodyids[6] = 807;
				refinedbodyids[7] = 808;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
				refinedbodynames[2] = "Estate";
				refinedbodynames[3] = "Saloon";
				refinedbodynames[4] = "4x4";
				refinedbodynames[5] = "Hatchback";
				refinedbodynames[6] = "People Carrier";
				refinedbodynames[7] = "Roadster";
			} */

		}// End of Mercedes-Benz (New)



		// For Smart (New)
		if (window.chosenmake==1) {

			if (window.chosenmodel==0 || window.chosenmodel==1 || window.chosenmodel==2 || window.chosenmodel==3) {
				refinedbodyids[0] = 901;
				refinedbodyids[1] = 902;
				refinedbodynames[0] = "Cabriolet";
				refinedbodynames[1] = "Coupe";
			}

		}// End of Smart (New)



		// For Chrysler (New)
		if (window.chosenmake==2) {
	
			if (window.chosenmodel==0 || window.chosenmodel==1 || window.chosenmodel==2 || window.chosenmodel==3) {
				// make shorter version!
				refinedbodyids[0] = 602;
				refinedbodyids[1] = 606;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "People Carrier";
			}


		} // End of Chrylser (New)



		// For Jeep (New)
		if (window.chosenmake==3) {

			if (window.chosenmodel==0 || window.chosenmodel==1 || window.chosenmodel==2 || window.chosenmodel==3) {
				refinedbodyids[0] = 701;
				refinedbodyids[1] = 702;
				refinedbodynames[0] = "4x4";
				refinedbodynames[1] = "Station Wagon";

			}

		}// End of Jeep (New)


		// For AMG (New)
		if (window.chosenmake==4) {
	
			if (window.chosenmodel==0) {
				refinedbodyids[0] = 1101;
				refinedbodyids[1] = 1102;
				refinedbodynames[0] = "Coupe";
				refinedbodynames[1] = "Roadster";
			}

		} // End of AMG (New)


	} // End of NEW cars


/* alert('BEFORE:\nwindow.chosenmodel: '+window.chosenmodel
+'\ndocument.getElementById(car_model_chosen).value: '+document.getElementById('car_model_chosen').value
+'\n\nwindow.chosenbody: '+window.chosenbody
+'\ndocument.getElementById(car_body_chosen).value: '+document.getElementById('car_body_chosen').value); */


	refinedbodyarraylength  =  refinedbodynames.length;
	// alert('refinedbodynames: ['+refinedbodynames+']\nrefined body array length: '+refinedbodynames.length); 


	for (c=document.getElementById('car_body').options.length-1; c>0; c--) {
		// alert('removing '+c+': '+document.getElementById('car_body').options[c].text);
		document.getElementById('car_body').remove(c);
	}

	fixmequick = 0;
	
	if(do_add_in_here == 1) {
		for (k=0; k<refinedbodyarraylength;k++){
			// alert('refinedbodynames[k]: '+refinedbodynames[k]+'\nwindow.chosenbody: '+window.chosenbody);
			if(refinedbodynames[k]!=undefined) {
				addOption(k, 'car_body', refinedbodynames[k], refinedbodynames[k]);
			}
			else { fixmequick = 1 }
		}
	}
	else {
		// Call another function to show all relevant body styles for the current make
		setBodyMenu();
		fixmequick = 1;
		// alert('do_add_in_here is 0, called setBodyMenu() instead');
		/* Don't blank them yet, we need to look for the best fit choice */
		/* window.chosenbody = 999;
		document.getElementById('car_body_chosen').value = 999; */
	}



	// if the there is only one choice, then pre-select it!
	if(refinedbodyarraylength==1 && fixmequick == 0) {
		// alert('it\'s a fix 1 - only one possible body style');
		document.getElementById('car_body').selectedIndex = 1;
		window.chosenbody = document.getElementById('car_body').options[document.getElementById('car_body').selectedIndex].value;
		document.getElementById('car_body_chosen').value = document.getElementById('car_body').options[document.getElementById('car_body').selectedIndex].value;
	}
	else {
		// Do a quick fix for when there are no options present, when it is set to "Other" model.
		document.getElementById('car_body').selectedIndex = 0;
		// can't put 999 for the two values here, as it would also wipe it out  last times choices when we want to keep them as well.
	}


	// What if there are no options for body style? Select the top header
	if(refinedbodyarraylength==0) {
		// alert('it\'s a fix 2 - no options for body style');
		document.getElementById('car_body').selectedIndex = 0;
		window.chosenbody = 999;
		document.getElementById('car_body_chosen').value = 999;
	}



	// if we know what body style they have chosen last time, then select it again this time.
	if(refinedbodyarraylength>0 && window.chosenbody != 999) {

		// alert('window.chosenbody: '+window.chosenbody)

		// which one has the current word?
		mychosenindex = 1;
		wegotone = 0;
		len_options = document.getElementById('car_body').options.length;
		for(m=0;m<len_options;m++) {
			// alert(document.getElementById('car_body').options[m].text+' vs '+ window.chosenbody+' let battle commence...')
			if(document.getElementById('car_body').options[m].text == window.chosenbody) {
				// alert("We got one!!!!!!!!!!!! = " + m)
				mychosenindex = m;
				wegotone = 1;
			}
		}

		if(wegotone == 1) {
			document.getElementById('car_body').selectedIndex = mychosenindex;
		}
		else {
			// alert('it\'s a fix 3 - we could not ahem \'get\' one');
			document.getElementById('car_body').selectedIndex = 0;
			window.chosenbody = 999;
			document.getElementById('car_body_chosen').value = 999;
		}

	}

/* alert('AFTER:\nwindow.chosenmodel: '+window.chosenmodel
+'\ndocument.getElementById(car_model_chosen).value: '+document.getElementById('car_model_chosen').value
+'\n\nwindow.chosenbody: '+window.chosenbody
+'\ndocument.getElementById(car_body_chosen).value: '+document.getElementById('car_body_chosen').value); */

}



// SELECTOR FOUR
function setFuelMenu() {
	fuelarraylength  =  fuelnames.length;
	// alert('fuel array length: '+fuelarraylength); 

    // Before adding any new ones we need to clear out the existing ones
	for (d=document.getElementById('car_fuel').options.length-1; d>0; d--) {
		document.getElementById('car_fuel').remove(d);
	}

	for (l=0; l<fuelarraylength;l++){
		if(fuelnames[l]!=undefined) {
			addOption(l, 'car_fuel', fuelnames[l], fuelnames[l]);
		}
	}
}



// SELECTOR FOUR - REFINE
function refineFuelMenu() {
	// alert('Trim stuff to set the FUEL for this model');
	// Don't know the fuel specifications for these cars.
}



// SELECTOR FIVE
function setGearBoxMenu() {
	geararraylength  =  gearnames.length;
	// alert('gear array length: '+geararraylength); 

    // Before adding any new ones we need to clear out the existing ones
	for (e=document.getElementById('car_gearbox').options.length-1; e>0; e--) {
		document.getElementById('car_gearbox').remove(e);
	}

	for (m=0; m<geararraylength;m++){
		if(gearnames[m]!=undefined) {
			addOption(m, 'car_gearbox', gearnames[m], gearnames[m]);
		}
	}
}



// SELECTOR FIVE - REFINE
function refineGearBoxMenu() {
	// alert('Trim stuff to set the possible GEARBOXes for this model');
	// Don't know the gearboxes available for these cars, other than the usual manual/automatic.
}



// SELECTOR SIX
function setDealershipMenu() {
	dealerlength = dealernames.length;
	// alert('dealer length: '+dealerlength); 

    // Before adding any new ones we need to clear out the existing ones
	for (f=document.getElementById('car_dealership').options.length-1; f>0; f--) {
		document.getElementById('car_dealership').remove(f);
	}

	// Add the dealership options
	for (n=0; n<dealerlength;n++){
		if(dealernames[n]!=undefined) {
			// Definately use ids for this one!!!
			addOption(n, 'car_dealership', dealerids[n], dealernames[n]);
			/* alert('dealerids at ['+n+'] is: '+dealerids[n]
			+'\ndealernames at ['+n+'] is: '+dealernames[n]
			+'\noption is now: ' + document.getElementById('car_dealership').options[n].value
			+'\ntext is now: ' + document.getElementById('car_dealership').options[n].text); */
		}
	}
}



// SELECTOR SIX - REFINE
function refineDealershipMenu() {
	// alert('Trim stuff to set the specific DEALERSHIPs for this make');

	// This function should wipe previous instances
	// Build a new list of dealership which are relevant to this make
	refineddealershipids = new Array(1);
	refineddealershipnames = new Array(1);


	// for MB (both Used and New)
	if (window.chosenmake==0) {
		refineddealershipids[0] = 3;
		refineddealershipids[1] = 4;
		refineddealershipids[2] = 5;
		refineddealershipids[3] = 6;
		refineddealershipids[4] = 7;
		refineddealershipids[5] = 8;
		refineddealershipids[6] = 9;
		refineddealershipnames[0] = "Mercedes-Benz of Shrewsbury";
		refineddealershipnames[1] = "Mercedes-Benz of Stafford";
		refineddealershipnames[2] = "Mercedes-Benz of Stoke";
		refineddealershipnames[3] = "Mercedes-Benz of Stourbridge";
		refineddealershipnames[4] = "Mercedes-Benz of Walsall";
		refineddealershipnames[5] = "Mercedes-Benz of Wolverhampton";
		refineddealershipnames[6] = "Mercedes-Benz of Worcester";
	}


	// for Smart (both Used and New)
	if (window.chosenmake==1) {
		refineddealershipids[0] = 10;
		refineddealershipnames[0] = "Smart Wolverhampton";
	}


	// for Chrysler (whether Used or New)
	if (window.chosenmake==2) {
		refineddealershipids[0] = 1;
		refineddealershipids[1] = 2;
		refineddealershipnames[0] = "Chrysler Jeep & Dodge of Shrewsbury";
		refineddealershipnames[1] = "Chrysler Jeep & Dodge of Wolverhampton";
	}


	// for Jeep (both Used and New)
	if (window.chosenmake==3) {
		refineddealershipids[0] = 1;
		refineddealershipids[1] = 2;
		refineddealershipnames[0] = "Chrysler Jeep & Dodge of Shrewsbury";
		refineddealershipnames[1] = "Chrysler Jeep & Dodge of Wolverhampton";
	}


	// for Dodge (just Used)
	if (window.chosentype==0 && window.chosenmake==4) {
		refineddealershipids[0] = 1;
		refineddealershipids[1] = 2;
		refineddealershipnames[0] = "Chrysler Jeep & Dodge of Shrewsbury";
		refineddealershipnames[1] = "Chrysler Jeep & Dodge of Wolverhampton";
	}


	// for AMG - could be fourth or fifth in list. v.similar to the first one (MB).
	if ((window.chosentype==0 && window.chosenmake==5) || (window.chosentype==1 && window.chosenmake==4)) {
		refineddealershipids[0] = 3;
		refineddealershipids[1] = 4;
		refineddealershipids[2] = 5;
		refineddealershipids[3] = 6;
		refineddealershipids[4] = 7;
		refineddealershipids[5] = 8;
		refineddealershipids[6] = 9;
		refineddealershipnames[0] = "Mercedes-Benz of Shrewsbury";
		refineddealershipnames[1] = "Mercedes-Benz of Stafford";
		refineddealershipnames[2] = "Mercedes-Benz of Stoke";
		refineddealershipnames[3] = "Mercedes-Benz of Stourbridge";
		refineddealershipnames[4] = "Mercedes-Benz of Walsall";
		refineddealershipnames[5] = "Mercedes-Benz of Wolverhampton";
		refineddealershipnames[6] = "Mercedes-Benz of Worcester";
	}


	refineddealershiparraylength  =  refineddealershipnames.length;

	for (c=document.getElementById('car_dealership').options.length-1; c>0; c--) {
		// alert('removing '+c+': '+document.getElementById('car_dealership').options[c].text);
		document.getElementById('car_dealership').remove(c);
	}

	for (k=0; k<refineddealershiparraylength;k++){
		if(refineddealershipnames[k]!=undefined) {
			addOption(k, 'car_dealership', refineddealershipids[k], refineddealershipnames[k]);
		}
	}

	// if the there is only one choice, then pre-select it!
	if(refineddealershiparraylength==1) {
		document.getElementById('car_dealership').selectedIndex = 1;
	}
}





/* function adjustWholeMenu() {
	makearraylength = makenames[window.chosentype].length;
	modelarraylength = modelnames[window.chosentype].length;
	bodyarraylength = bodynames[window.chosentype].length;
	fuelarraylength = fuelnames[window.chosentype].length;
	dealerlength = dealernames.length; */
	/* alert('make array length: '+makearraylength
	+'\nmodel array length: '+modelarraylength
	+'\nbody array length: '+bodyarraylength
	+'\nfuel array length: '+fuelarraylength); */

/*
	// FIRST DELETE PREVIOUS SETUP
	for (a=document.getElementById('car_make').options.length-1; a>0; a--) {
		// alert('removing '+a+': '+document.getElementById('car_make').options[a].text);
		document.getElementById('car_make').remove(a);
	}
	for (b=document.getElementById('car_model').options.length-1; b>0; b--) {
		// alert('removing '+b+': '+document.getElementById('car_model').options[b].text);
		document.getElementById('car_model').remove(b);
	}
	for (c=document.getElementById('car_body').options.length-1; c>0; c--) {
		// alert('removing '+c+': '+document.getElementById('car_body').options[c].text);
		document.getElementById('car_body').remove(c);
	}
	for (d=document.getElementById('car_fuel').options.length-1; d>0; d--) {
		document.getElementById('car_fuel').remove(d);
	}
	for (e=document.getElementById('car_gearbox').options.length-1; e>0; e--) {
		document.getElementById('car_gearbox').remove(e);
	}
	for (f=document.getElementById('car_dealership').options.length-1; f>0; f--) {
		document.getElementById('car_dealership').remove(f);
	}



	// NOW ADD IN THE WANTED OPTIONS
	for (i=0; i<makearraylength;i++){
		if(makenames[window.chosentype][i]!=undefined) {
			addOption(i, 'car_make', makeids[window.chosentype][i], makenames[window.chosentype][i]);
		}
	}

	for (j=0; j<modelarraylength;j++){
		if(modelnames[window.chosentype][j]!=undefined) {
			addOption(j, 'car_model', modelids[window.chosentype][j], modelnames[window.chosentype][j]);
		}
	}

	for (k=0; k<bodyarraylength;k++){
		if(bodynames[window.chosentype][k]!=undefined) {
			addOption(k, 'car_body', bodyids[window.chosentype][k], bodynames[window.chosentype][k]);
		}
	}

	for (l=0; l<fuelarraylength;l++){
		if(fuelnames[window.chosentype][l]!=undefined) {
			addOption(l, 'car_fuel', fuelids[window.chosentype][l], fuelnames[window.chosentype][l]);
		}
	}

	for (m=0; m<geararraylength;m++){
		if(gearnames[window.chosentype][m]!=undefined) {
			addOption(m, 'car_gearbox', gearids[window.chosentype][m], gearnames[window.chosentype][m]);
		}
	}

	// Also set the dealership
	for (n=0; n<dealerlength;n++){
		if(dealernames[n]!=undefined) {
			addOption(n, 'car_dealership', dealerids[n], dealernames[n]);
		}
	}

}*/





function addOption(indy,selectboxid,newvalue,newtext)
{
	/* var newoption = document.createElement("OPTION");
	optionindex = indy;
	newoption.value = newvalue;
	newoption.text = newtext;
	document.getElementById(selectboxid).options.add(newoption); */
	// Bit crap as it keeps adding new ones

	// alternate way
	// newtext_string = "'" + newtext + "'"
	// newvalue_string = "'" + newvalue + "'"
	document.getElementById(selectboxid).options[indy+1]= new Option(newtext, newvalue);
	// Normally "newvalue" would go second if you wanted the value to be a number.

	// Used http://www.javascriptkit.com/jsref/select.shtml#section2 as reference

}





function toggleRadio(radiochoice){
	if(radiochoice=='fake_radio_used'){
		document.getElementById('car_type_chosen').value = 'used';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_on_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_off_trans.gif';
		setCarType(0);
	}

	if(radiochoice=='fake_radio_new'){
		document.getElementById('car_type_chosen').value = 'new';
		// select this one and reset the other
		document.getElementById('fake_radio_used').src = 'images/form_radio_off_trans.gif';
		document.getElementById('fake_radio_new').src = 'images/form_radio_on_trans.gif';
		setCarType(1);
	}



}



function prepareToSubmit() {

	/* alert('preparing to submit with:'
	+'\nwindow.chosentype: '+window.chosentype
	+'\nwindow.chosenmake: '+window.chosenmake
	+'\nwindow.chosenmodel: '+window.chosenmodel
	+'\nwindow.chosenbody: '+window.chosenbody
	+'\nwindow.chosenfuel: '+window.chosenfuel
	+'\nwindow.chosendealership: '+window.chosendealership
	); */


	// alert('window.chosentype: '+window.chosentype+'\nwindow.chosenmake: '+window.chosenmake)

	goodtogo = 1;

	// If NEW radio button is pressed
	if(window.chosentype==1) {

		// if they picked New cars but did not select anything further, go to new landing page.
		if (window.chosentype==1 && window.chosenmake==999 && window.chosenmodel==999 && window.chosenbody==999 
		&& window.chosenfuel==999 && window.chosengearbox==999 && window.chosendealership==999) {

			// alert("For new cars you need to select a Make");
			document.getElementById('searchform').action = 'new_landingpage.cfm';
			// goodtogo = 0;
		}


		// If only cartype and make were chosen and cartype is NEW
		else if (window.chosentype==1 && window.chosenmake!=999 && window.chosenmake!=4 && window.chosenmodel==999 && window.chosenbody==999 
		&& window.chosenfuel==999 && window.chosengearbox==999 && window.chosendealership==999) {

			// alert('alternate new path 1...');
			document.getElementById('searchform').action = 'new_landingpage.cfm';
		}


		// If they didn't choose a make then warn them! (we can igonre the rest)
		else if (window.chosentype==1 
		&& window.chosenmake==999) {

			alert('Please select a vehicle Make.');
			document.getElementById('car_make').focus();
			return false;
		}

		// If they didn't chose a make but didn't choose a model also warn them! (we can igonre the rest)
		else if (window.chosentype==1 
		&& window.chosenmake!=999
		&& window.chosenmodel==999) {

			alert('Please select a vehicle Model.');
			document.getElementById('car_model').focus();
			return false;
		}


		// Even more stupid options come in to cover holes in the database... for Make: Mercedes-Benz and Model: C, E or SLS.
		else if (window.chosentype==1 
		&& window.chosenmake==0
		&& (window.chosenmodel==2 || window.chosenmodel==5 || window.chosenmodel==13)
		&& window.chosenbody==999) {

			/* && window.chosenfuel==999 
			&& window.chosengearbox==999
			&& window.chosendealership==999 */

			// alert('alternate new path 2...');
			alert('Please select a Body Style for this model.');
			// document.getElementById('searchform').action = 'new_landingpage.cfm';
			// twas too confusing to go back, plus we lost choices already made on the search form
			document.getElementById('car_body').focus();
			return false;
		}


		// Even more stupid options come in to cover holes in the database... for Make: Smart and Model: Fortwo.
		else if (window.chosentype==1 
		&& window.chosenmake==1
		&& (window.chosenmodel==1)
		&& window.chosenbody==999) {

			/* && window.chosenfuel==999 
			&& window.chosengearbox==999
			&& window.chosendealership==999 */

			// alert('alternate new path 3...');
			alert('Please select a Body Style for this model.');
			// document.getElementById('searchform').action = 'new_landingpage.cfm';
			// twas too confusing to go back, plus we lost choices already made on the search form
			document.getElementById('car_body').focus();
			return false;
		}


		else if (window.chosentype==1 
		&& window.chosenmake==0&&window.chosenmodel==8) {

			//alert('alternate new path 4...'); 
			document.getElementById('searchform').action = 'new_car_ml_class.cfm';
			/* ?Manuf=Mercedes-Benz&New_Class=ML-Class&callingelement=new_landingpage_link */
		}


		else if (window.chosentype==1 
		&& window.chosenmake==4) {

			// alert('alternate new path 5...');
			document.getElementById('searchform').action = 'amg_performance.cfm';
		}


		else if (window.chosentype==1 
		&& window.chosenmake==2&&window.chosenmodel==0) {

			//alert('alternate new path 6...'); 
			document.getElementById('searchform').action = 'new_car_300c.cfm';
			/* ?ManufChrysler&New_Class=300C&callingelement=new_landingpage_link */
		}


		else {
			// Regular action... got to new_car.cfm
			document.getElementById('searchform').action = 'new_car.cfm';
		}



	// If USED radio button is pressed
	} 
	else {
		// was simply the following line
		// document.getElementById('searchform').action = 'searchresults.cfm';

		// now they want it more complicated
		// Extrordinarily stupid path begins...

		// When window.bypass is set to 0 and they only choose a make, 
		// then the next test will delibrately go to used_carselector instead of searchresults.


		// If no make was chosen and cartype is USED - basically no drop downs selected on the search form.
		if (window.chosentype==0 && window.chosenmake==999 && window.chosenmodel==999 && window.chosenbody==999 
		&& window.chosenfuel==999 && window.chosengearbox==999 && window.chosendealership==999 && window.bypass==0) {

			// alert('alternate used path 1...');
			document.getElementById('searchform').action = 'used_landingpage.cfm';
		}

		// If only make and cartype were chosen and cartype is USED
		else if (window.chosentype==0 && window.chosenmake!=999 && window.chosenmake!=5 && window.chosenmodel==999 && window.chosenbody==999 
		&& window.chosenfuel==999 && window.chosengearbox==999 && window.chosendealership==999 && window.bypass==0) {

			// alert('alternate used path 2...');
			document.getElementById('searchform').action = 'used_carselector.cfm';
		}

		else if (window.chosentype==0 
		&& window.chosenmake==5) {

			// alert('alternate used path 3...');
			document.getElementById('searchform').action = 'amg_performance.cfm';
		}

		else {
			// Normal path to searchresults
			// alert('regular used path...');
			document.getElementById('searchform').action = 'searchresults.cfm';
		}

	}

	// could even need others for motability, etc.

	if(goodtogo==1) {
		// alert('my action is: '+document.getElementById('searchform').action)
		document.getElementById('searchform').submit();
	}
}












function initialiseMenu() {
	// alert("initialise menu...")
	window.callNumber = 1;
	window.retNumber = 1;

	// set the menu to "used" cars
	setCarType(0);
}










function setLandingPage(cartype,thischosenmake) {
	// alert("initialise menu...")
	window.callNumber = 1;
	window.retNumber = 1;

	// set the menu to "used" cars
	setCarType(cartype);	// this function also set window.chosentype
	if(thischosenmake!=999) {
		document.getElementById('car_make').selectedIndex = thischosenmake + 1;
		document.getElementById('car_make_chosen').value = thischosenmake;
		window.chosenmake = chosenmake;

		setChoices('car_make') // Also sets window.chosenmake and car_make_chosen itself so don't worry about them.
	}
}















<!--- Scripts for AJAX call --->

/* ---------------------------- */
/* XMLHTTPRequest Enable        */
/* ---------------------------- */
function createObject() {
	var myrequest;

	/* attempt 1
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		myrequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		myrequest = new XMLHttpRequest();
	    myrequest.overrideMimeType('text/plain');
	} */

	myrequest = new XMLHttpRequest();

	if(typeof myrequest == "undefined")
	{

		myrequest = function () {
	    	try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
    		  catch (e) {}
	    	try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
    		  catch (e) {}
	    	try { return new ActiveXObject("Microsoft.XMLHTTP"); }
    		  catch (e) {}
	    	//Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant
		    throw new Error('This browser does not support XMLHttpRequest or XMLHTTP.');
		}; 

		// Another bit that doesn't work in IE
	    if(myrequest.overrideMimeType) {   
		    myrequest.overrideMimeType('text/plain');
			// some may need to be this mime type, others xml, query, etc
		}

	}

	return myrequest;
}

var xmlHttpReq = createObject();





function getNumResults() {

	// only do this for "used" cars.
	window.callNumber = window.callNumber + 1;

	var strURL = 'ajax_getnumresults.cfm'; // or a cfc???

	// strURL = strURL + '?method=getnumresults'; // call the method (does nothing if .cfm)
	// For the following we have to use document.getElementById not window.make
	// as we are using the window.chosenmake to store the numbers for the chosen array.
	// If we DO NEED window. identifiers we will have to invent new ones.

	strURL = strURL + '?currmake='+document.getElementById('car_make_chosen').value;
	strURL = strURL + '&currmodel='+document.getElementById('car_model_chosen').value;
	strURL = strURL + '&currbody='+document.getElementById('car_body_chosen').value;
	strURL = strURL + '&currfuel='+document.getElementById('car_fuel_chosen').value;
	strURL = strURL + '&currgear='+document.getElementById('car_gearbox_chosen').value;
	strURL = strURL + '&currdealer='+document.getElementById('car_dealership_chosen').value;
	strURL = strURL + '&callno='+window.callNumber;
	// Each time we will send all of these variables as they are mostly all set to 999 by default.


	// alert("getNumResults called with strURL: "+strURL);


	// set the parameters for the xmlHttpReq object
	xmlHttpReq.open('get', strURL, true);
	/* The open function takes three parameters: 
		- HTTP request method, 
		- script to send the request to, 
		- and a flag that determines whether the request is asynchronous.
	*/


	// call the callback function
	xmlHttpReq.onreadystatechange = displayOperationResult;
	// an alternative is: function(){displayOperationResult(xmlHttpReq);} when xmlHttpReq is not global.

	xmlHttpReq.send(null);
}








// The callback function will be called whenever the state of the request has changed
// xmlHttpReq
function displayOperationResult()
{
   window.retNumber += 1;

   var operationdata = "";
   var output = "";

   if (xmlHttpReq.readyState == 4 || xmlHttpReq.readyState=='complete')
   {
      // operationdata = xmlHttpReq.responseText.split(",");
	  // Don't want to split it yet
	  operationdata = xmlHttpReq.responseText

	  // alert('display opearation\n'+operationdata);

      // processing information produced by the script
      if( operationdata.length > 1 )
      {
		  output = operationdata;
      }
      else {
         output = 'Result not found';
	  }

      // Now write "output" into the outputdiv
      // document.getElementById('num_results_found').value = output;
      document.getElementById('num_results_found').innerHTML = output;
   }

   else
   {
      // document.getElementById('num_results_found').value = 'Loading...';
      document.getElementById('num_results_found').innerHTML = 'Loading...';
   } 


}


