
	var search_e = '';
  	var accums = Array();
  	accums[-1] = '____';
  	var accum_texts = Array();
  	accum_texts[-1] = '';
  	var accum_ymms = Array();
  	accum_ymms[-1] = '';
  	var steps = Array(
    	"car_years",
    	"car_makes",
    	"car_models",
    	"car_years_2",
    	"car_makes_2",
    	"car_models_2",
    	"car_years_3",
    	"car_makes_3",
    	"car_models_3"
  	);
  	var truncate = false;
  	var cur_text_ymm = "";
  	if (cur_text_ymm != '') {
  		truncate = true;
		vals = cur_text_ymm.split('###');
		var cur_text = vals[0];
		var cur_ymm = vals[1];
  	} 

 	var cur_step = 0;
  
  	function xrequest(step) {
  		
    	cur_step = step;
		accum = accums[cur_step];
		accum_text = accum_texts[cur_step];
		accum_ymm = accum_ymms[cur_step];
    	do_request = true;
    	drop_step = false;
    	if(cur_step >= 0) {
    		pop_makes = true;
      		sel = steps[cur_step];
      		/*
      		to reduce the number of reads to the keystone database.. the year and make 
      		variables are populated from existing data, this is now used to retrieve the models
      		*/
      		if(sel == 'car_makes_2') {
				accum	= '____';
      			sel_1 = 'car_years_2';
      			obj = search_e[sel_1];
        		arr = obj.options[obj.selectedIndex].value.split(':');	
        		val = arr[0];
        		text = arr[1];
        		accum = accum + text;
        		accum_text = text + '|';
      		}
      		if(sel == 'car_makes_3') {
				accum	= '____';
      			//sel_1 = 'car_years_3';
      			obj = search_e['car_years_3'];
        		arr = obj.options[obj.selectedIndex].value.split(':');	
        		val = arr[0];
        		text = arr[1];
        		accum = accum + text;
        		accum_text = text + '|';
      		}
      		
        	obj = search_e[sel];
        	arr = obj.options[obj.selectedIndex].value.split(':');	
        	val = arr[0];
        	text = arr[1];
        		
        	if(val == 0) {
          		do_request = false;
          		drop_step = true;
        	}
        	short_val = drop_last_four(val);
			accum = accum + val;
			accum_text += text;
	  		accum_ymm = '';   
    		accum_ymms[cur_step + 1] = accum_ymm;
    		if(cur_step == 2 || cur_step == 5) {
      			Cookies.set("cookie_text_ymmx", accum_text + "###" + accum_ymm);
      			accum	= '____';
      			accum_text = "";
      			accum_ymm  = "";
      			if(cur_step == 5) {
      				
      				do_request = false;
      			}
    		}
    	}
			
    	//if(cur_step < 0) {// disable all except years on initial page load
		//	disable();
    	//}
    	if(do_request) {// read keystone database 
    		
      		new Ajax.Request('generic_request.php', {
       	 		method: 'post',
        		parameters: {accum: accum, accum_text: accum_text, accum_ymm: accum_ymm},
        		requestHeaders: {Accept: 'application/json'},
        		onSuccess: succ,
        		onFailure: fail
      		});
    	} else {
      		if (drop_step)
        		cur_step--;
      		enable();
    	}
  	}
  	
  	function succ(transport) { //  retrieve the data from keystone and populate select boxes
       	var res = transport.responseText.evalJSON(true);
       	
       	last = res['IsLastQuestion'];     
        opts = res['Options'];
        accums[cur_step + 1] = res['Accum'];
        if(res['AccumText'] == '____|')
            accum_texts[cur_step + 1] = '';
        else
            accum_texts[cur_step + 1] = res['AccumText'];
        sel = steps[cur_step + 1];
        e_sel = search_e[sel]; 
        e_sel.options.length = 0;
        e_sel_y2 = search_e['car_years_2'];
        e_sel_mk2 = search_e['car_makes_2'];
        e_sel_y3 = search_e['car_years_3'];
        e_sel_mk3 = search_e['car_makes_3'];
        cur_index = 0;  	
        e_sel.options[0] = new Option("--Select One--", 0);
        cur_index++;           
        for (k in opts) {
          v = opts[k];
          e_sel.options[cur_index] = new Option(v, k + ':' + v); // populate the next dropdown          
          cur_index++;
        }
        enable();
  }
  function fail() {
    alert('This search is temporarily unavailable.');
  }
	function disable() {
    	max = steps.length; // total select boxes to disable
    	for (var i = 0; i < max; i++) { // disable all trailing select boxes on initial page load
      		name = steps[i];
      		obj = search_e[name];
        	obj.disabled = true;      
    	} 
  	}
  	function enable() { // enable the next select box
    	i = cur_step + 1;
      	name = steps[i];
      	obj = search_e[name];
        obj.disabled = false;
  	}
  function drop_last_four(str) {
    len = str.length;
    len = len - 4;
    return str.substring(0, len);
  }
