	var anyMakeMenu_one;
	var anyMakeMenu_two;

	var modelMenu_one;
	var modelMenu_two;

	var anyMakeButton_one;
	var anyMakeButton_two;

	var modelButton_one;
	var modelButton_two;




		var YUC = YAHOO.util.Connect; 
		
		var args = [''];
		

		// #################################################################################
		// #							CALLBACK FUNCTIONS                                 #
		// #################################################################################

		var modelResponseSuccess = function(o){
			setModelButtonMenu(o.responseText);
		};
		var modelResponseFailure = function(o){
		};

		var modelcallback =
		{
		  success:modelResponseSuccess,
		  failure:modelResponseFailure,
		  timeout: 5000
		};

		var anyMakeResponseSuccess = function(o){
			var json = o.responseText;
			setAnyMakeButtonMenu(json);

		};
		var makeResponseFailure = function(o){

		};
		var allmakecallback =
		{
		  success:anyMakeResponseSuccess,
		  failure:makeResponseFailure,
		  timeout: 10000
		};


		// #################################################################################
		// #							BUTTON SETUP                                       #
		// #################################################################################

		YAHOO.util.Event.onContentReady("makebuttonNew", function() {

			anyMakeMenu_one = new YAHOO.widget.Menu("myanymakebutton_one", { scrollincrement: 2, iframe: false, lazyload: true } );
	        anyMakeButton_one = new YAHOO.widget.Button({ type: "menu", label: "<em>Make</em>", name: "myanymakebutton_one", menu: anyMakeMenu_one, container: "makebuttonNew" });            

			YAHOO.util.Event.onContentReady("makebuttonUsed", function() {
	
				anyMakeMenu_two = new YAHOO.widget.Menu("myanymakebutton_two", { scrollincrement: 2, iframe: false, lazyload: true } );
		        anyMakeButton_two = new YAHOO.widget.Button({ type: "menu", label: "<em>Make</em>", name: "myanymakebutton_two", menu: anyMakeMenu_two, container: "makebuttonUsed" });            
	
				YUC.asyncRequest('GET', '/ADMIN/makemodel/getMakes.php', allmakecallback, null);
			
			});


		
		});

		YAHOO.util.Event.onContentReady("modelbuttonNew", function() {

			modelMenu_one = new YAHOO.widget.Menu("mymodelbutton_one", { scrollincrement: 2, iframe: false, lazyload: true } );
	        modelButton_one = new YAHOO.widget.Button({ type: "menu", label: "<em>Model</em>", name: "mymodelbutton_one", menu: modelMenu_one, container: "modelbuttonNew" });
			modelMenu_one.addItems(["Select a make first"]);
			modelMenu_one.render(document.body);
	
			//modelMenu_two = new YAHOO.widget.Menu("mymodelbutton_two", { scrollincrement: 2, iframe: false, lazyload: true } );
	        //modelButton_two = new YAHOO.widget.Button({ type: "menu", label: "<em>Select model</em>", name: "mymodelbutton_two", menu: modelMenu_two, container: "modelbuttons" });
			//modelMenu_two.addItems(["Select a make first"]);
			//modelMenu_two.render(document.body);
	
		});


		YAHOO.util.Event.onContentReady("modelbuttonUsed", function() {

			modelMenu_two = new YAHOO.widget.Menu("mymodelbutton_two", { scrollincrement: 2, iframe: false, lazyload: true } );
	        modelButton_two = new YAHOO.widget.Button({ type: "menu", label: "<em>Model</em>", name: "mymodelbutton_two", menu: modelMenu_two, container: "modelbuttonUsed" });
			modelMenu_two.addItems(["Select a make first"]);
			modelMenu_two.render(document.body);
	
	
		});

		/* 	By default, event handlers are called with two arguments: a string 
			representing the name of the event and an array of arguments sent 
			when the event fired. Events based on DOM events (e.g. "mouseover," 
			"mouseout," "click," etc.) pass back the DOM event object to the 
			listener as the first argument in the arguments array; if the target
			of the event was a MenuItem instance, it will be passed back as the 
			second argument.
		*/

		function genericItemClick(p_sType, p_aArgs, p_aParent) {
			var obj = p_aArgs[1];

			// The parent is just a button
			var btn = p_aParent;

			// This is the text value of the menuItem chosen
			labelTxt = obj.cfg.getProperty("text");

			btn.set("label", labelTxt);
		}



		YAHOO.util.Event.onContentReady("submitcontainerNew", function() {
			submitButton = new YAHOO.widget.Button("submitbuttonNew", { type: "submit", label: "Search" } );
		});

		YAHOO.util.Event.onContentReady("submitcontainerUsed", function() {
			submitButton = new YAHOO.widget.Button("submitbuttonUsed", { type: "submit", label: "Search" } );
		});

		function clearContent(obj) {
			obj.clearContent();
		}

		function setAnyMakeButtonMenu(json) {
			anyMakeMenu_one.addItems(eval(json));
			anyMakeMenu_one.render(document.body);
			anyMakeMenu_two.addItems(eval(json));
			anyMakeMenu_two.render(document.body);
		}

		function setModelButtonMenu(json) {
			if (json == "") {
				// Nothing to do, something went wrong
				// This happens when you click Select, then choose a style, then click Any, then choose a make
				return;
			} else {
				var data = eval( "(" + json + ")" ); /* Thanks to http://willcode4beer.com/tips.jsp?set=jsonInvalidLabel */
				//alert(data.id);
				//alert(data.buttondef);
				// Need to wipe out the model menu first
	
				if (data.id == "mymakebutton_one" || data.id == "myanymakebutton_one" || data.id == "mymakebutton_one_INITIAL" || data.id == "myanymakebutton_one_INITIAL") {
					clearContent(modelMenu_one);
					modelMenu_one.addItems(data.buttondef); // was eval(json)
					modelMenu_one.render(document.body);
					modelButton_one.set("label", "<em>Select model</em>");  
				} else if (data.id == "mymakebutton_two" || data.id == "myanymakebutton_two" || data.id == "mymakebutton_two_INITIAL" || data.id == "myanymakebutton_two_INITIAL") {
					clearContent(modelMenu_two);
					modelMenu_two.addItems(data.buttondef); // was eval(json)
					modelMenu_two.render(document.body);
					modelButton_two.set("label", "<em>Select model</em>");
				}

			}
		}

		// #################################################################################
		// #							ONCLICK FUNCTIONS                                  #
		// #################################################################################


        function onMakeItemClick(p_sType, p_aArgs, p_oVal) {
			// p_oVal contains the value of the menu option
			// this.cfg.getProperty("text") gets the label of the menu option
			var btn = this.parent.id; // the button is the parent of the menu, so that's how 
									  // we can tell which button corresponds to the menu item that was clicked
			if (btn == "myanymakebutton_one") {
            	anyMakeButton_one.set("label", "<em>"+this.cfg.getProperty("text")+"</em>");
				modelButton_one.set("label", "<em>Loading...</em>"); 
				clearContent(modelMenu_one);		
			} else if (btn == "myanymakebutton_two") {
            	anyMakeButton_two.set("label", "<em>"+this.cfg.getProperty("text")+"</em>");
				modelButton_two.set("label", "<em>Loading...</em>"); 
				clearContent(modelMenu_two);
			}

			YUC.asyncRequest('POST', '/ADMIN/makemodel/getModels.php', modelcallback, 'btn=' + btn + '&make=' + p_oVal);
        }

        function onModelItemClick(p_sType, p_aArgs, p_oVal) {
			var btn = this.parent.id;
			if (btn == "mymodelbutton_one") {
    	            modelButton_one.set("label", "<em>"+this.cfg.getProperty("text")+"</em>");
			} else if (btn == "mymodelbutton_two") {
    	            modelButton_two.set("label", "<em>"+this.cfg.getProperty("text")+"</em>");
			}
        }


		function removeSelections(obj) {
					var tmp = obj.getItems();
					for (i in tmp) {
						var item = tmp[i];
						if (item.cfg.getProperty("selected") == true) {
							item.cfg.setProperty("selected",false);
						}
					}
		}



        function onSubmit(p_oEvent) {

			var formComplete = 1;
			var msg = "";


            if(!formComplete) {
                YAHOO.util.Event.preventDefault(p_oEvent);
				msg = "Please enter a value for the following fields:\n\n" + msg;
            	alert(msg);
            }

			YAHOO.widget.Button.addHiddenFieldsToForm("basicSearch");

        }

        YAHOO.util.Event.on("basicSearch", "submit", onSubmit);

