/*
	Name: 		cars_improved.js
	Author: 	Markus Diersbock
	Details: 	Uses make/model arrays and a few lines of code from Jon's original cars.js.
				Added code to work with multiple vehicles.
			
	Revisions:	2009/09/30		Moved from old legacy Olawski code arrays to JSON.
								Modified suppotive code to handle JSON
				2009/04/04		Updated Make/Models
				2008/06/03		Created, with legacy Olawski code
*/
		
	function populateMakes(objForm, selected_num) {
		
		if(objForm.options.length == 1) {
			for (i = 0; i<obj_make_model.length; i++) {
				var newOption = new Option(obj_make_model[i].Make, obj_make_model[i].Make);
				objForm.options[i+1] = newOption;
			}
			if(selected_num > 0) {
				objForm.options[selected_num].selected = true;
			}
		}
	}	

    function makeSelected(objForm, selected_num, defix) {
		// Verify if "Select" wasn't clicked
		if(objForm.selectedIndex>0){
			populateModels(objForm, objForm.selectedIndex - 1, defix);
		}
		
		if(selected_num > 0){
			objForm.options[selected_num].selected = true;
		}
    }

   /* function p2opulateModels(objForm, make_num, defix) {
    	
		// Block that works with muliple rows
		var id_len = objForm.id.length;
		var id_num = objForm.id.substring(id_len, id_len - 1);
		
		if(id_num != parseInt(id_num)){
			objModel = document.getElementById("model"+defix);
		}else{
			objModel = document.getElementById("model" + id_num+defix);
		}
		
		if (objModel.options.length > 0) {
		// Clear dropdown
			objModel.options.length = 1;
		}

		// Populate models based on index from Make dropdown
        for (i=0; i<obj_make_model[make_num].Models.length; i++) {
              objModel.options[i+1] = new Option(obj_make_model[make_num].Models[i], obj_make_model[make_num].Models[i]);
        }
    }*/
    
	function populateModels(objForm, make_num) {
	
		// Block that works with muliple rows
		//var id_len = objForm.id.length;
		//var id_num = objForm.id.substring(id_len, id_len - 1);
		
		/*if(id_num != parseInt(id_num)){
			objModel = document.getElementById("model");
		}else{
			objModel = document.getElementById("model" + id_num);
		}*/
		//console.log (window.defix);
		
		// Clear dropdown
		objForm.options.length = 1;
		if (make_num != 0) {
			make_num = make_num-1;
		} else {
			make_num = 0;
		}

		// Populate models based on index from Make dropdown
        for (i=0; i<obj_make_model[make_num].Models.length; i++) {
        	objForm.options[i+1] = new Option(obj_make_model[make_num].Models[i], obj_make_model[make_num].Models[i]);
        }
    }
	  
