// Start Ajax Code

	function gw_popMakes( year, selectedMake ) {
		var url = '../gateways/gw_Common_getMakes.cfm';
		var ajaxGroupRequest = new AjaxRequest( url );
		ajaxGroupRequest.setQueryString('select_id=SelectMake' + '&year=' + year + '&selected=' + selectedMake );
//		ajaxGroupRequest.setEchoDebugInfo();
		ajaxGroupRequest.sendRequest();
	
		return ajaxGroupRequest;
	}
	
	function gw_popModels( year, make, selectedModel ) {
		var url = '../gateways/gw_Common_getModels.cfm';
		var ajaxGroupRequest = new AjaxRequest( url );
		ajaxGroupRequest.setQueryString('select_id=SelectModel' + '&year=' + year + '&Make=' + make + '&selected=' + selectedModel.replace('&','%26') );
//		ajaxGroupRequest.setEchoDebugInfo();
		ajaxGroupRequest.sendRequest();

		return ajaxGroupRequest;
	}
	
	function gw_getMakes( sourceID, selectID, modelSelectID, selectedMake ) {
//		Disable the year select to prevent another ajax request while this one is processing
		var source = document.getElementById( sourceID );
		var year = source[source.selectedIndex].value;
		source.disabled = true;
		source.className = "js_input";

//		Show state of the Make Select
		target = document.getElementById( selectID );
		target.options.length = 0;
		target.options[target.options.length] = new Option ('Loading...','-1');
		//target.options.add( new Option( 'Loading...', -1 ) );
		target.className = "js_input";

//		Reset the Model Select
		modelSelect = document.getElementById( modelSelectID )
		modelSelect.options.length = 0;
		modelSelect.options[modelSelect.options.length] = new Option ('Select Make','-1');
//		modelSelect.options.add( new Option( 'Select Make', -1 ) );
		modelSelect.className = "js_input";

//		issue the ajax request
		var ajaxGroupRequest = gw_popMakes( year, selectedMake );
//		Enable the select boxes after the request completes
		ajaxGroupRequest.setPostRequest( gw_getGroup_Select_Cleanup( source, target ) );

	}

	function gw_getModels( yearSourceID, makeSelectID, targetSelectID, selectedModel ) {
//		Disable the year select to prevent another ajax request while this one is processing
		var yearSelect = document.getElementById( yearSourceID );
		var year = yearSelect[yearSelect.selectedIndex].value;
		yearSelect.className = "js_input";
		yearSelect.disabled = true;

//		Disable the make select to prevent another ajax request while this one is processing
		var makeSelect = document.getElementById( makeSelectID );
		var make = makeSelect[makeSelect.selectedIndex].value;
		makeSelect.className = "js_input";
		makeSelect.disabled = true;

//		Show state of the Model Select
		target = document.getElementById( targetSelectID );
		target.options.length = 0;
		target.options[target.options.length] = new Option ('Loading...','-1');
//		target.options.add( new Option( 'Loading...', -1 ) );
		target.className = "js_input";
		
//		issue the ajax request
		var ajaxGroupRequest = gw_popModels( year, make, selectedModel );
//		Enable the select boxes after the request completes
		ajaxGroupRequest.setPostRequest( gw_getGroup_Select_Cleanup( yearSelect, makeSelect, target ) );
	}
	
	function gw_getGroup_Select_Cleanup( source1, source2, source3 ) {
		if( source1 ) {
			source1.disabled = false;
		}
		if( source2 ) {
			source2.disabled = false;
		}
		if( source3 ) {
			source3.disabled = false;
		}
	}

	function gw_popTransmissionsAndColors( vehicleNMB ) {
		var url = '../gateways/gw_Common_getTransmissionsAndColors.cfm';
		var ajaxGroupRequest = new AjaxRequest( url );
		ajaxGroupRequest.setQueryString('trans_select_id=SelectTransmission&color_select_id=SelectColor&vehicleNMB=' + vehicleNMB );
//		ajaxGroupRequest.setEchoDebugInfo();
		ajaxGroupRequest.sendRequest();
	
		return ajaxGroupRequest;
	}
	
	function getTransmissionsAndColors( sourceID, transSelectID, colorSelectID ) {
		var trimSource = document.getElementById( sourceID );
		trimSource.className = "js_input";
		trimSource.disabled = true;
		var vehicleNMB = trimSource.value;

		transTarget = document.getElementById( transSelectID );
				
		transTarget.options.length = 0;
		transTarget.options[transTarget.options.length] = new Option ('Loading...','-1');
//		transTarget.options.add( new Option( 'Loading...', '-1' ) );
		transTarget.className = "js_input";

		colorTarget = document.getElementById( colorSelectID );
		colorTarget.options.length = 0;
		colorTarget.options[colorTarget.options.length] = new Option ('Loading...','-1');
//		colorTarget.options.add( new Option( 'Loading...', '-1' ) );
		colorTarget.className = "js_input";

		var ajaxGroupRequest = gw_popTransmissionsAndColors( vehicleNMB );
		ajaxGroupRequest.setPostRequest( gw_getGroup_Select2_Cleanup( trimSource, transTarget, colorTarget ) );
	}

	function gw_getGroup_Select2_Cleanup( source1, source2, target ) {
		source1.disabled = false;
		source2.disabled = false;
		target.disabled = false;
	}
