function dynamicSelect(id1, id2) {
	// Feature tests to see if there is enough W3C DOM support
	if (document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		// Clone the dynamic select box
		var clone = sel2.cloneNode(true);
		// Obtain references to all cloned options
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
			changeAction();
		};
	}
}

function changeAction() {
	if(document.getElementById('kindsearch').value == 'USED')
		document.getElementById('vehicleSearch').action = 'vehicles-used.html';
	else
		document.getElementById('vehicleSearch').action = 'vehicles-new.html';
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {
		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

function setupDealerSearchBox(){
	if (!document.getElementById('dealers') || !document.getElementsByTagName){return;}
	var inputs = document.getElementById('dealers').getElementsByTagName('input');
	for(var i=0; i<inputs.length; i++){
		inputs[i].setAttribute( 'onClick' , 'changeDealerKind();');
	}
	//disable make and model dropdowns... will get re-enabled when parent changed
	var disabledselects = document.getElementById('dealers').getElementsByTagName('select');
}

function changeDealerKind() {
	if (!document.getElementById || !document.getElementsByTagName){return;}
	var inputs = document.getElementById('dealers').getElementsByTagName('input');
	var options = new Array();
	var temp = new Array();
	for(var i=0; i<inputs.length; i++){
		if(inputs[i].checked==true){
			options[inputs[i].getAttribute('value')] = inputs[i].getAttribute('class').split( '_' );
		}
	}
	/*for(k in options){
	console.log(k);
	console.log(options[k]);
	}*/
	var kind = new Array();

	for(dealervalue in options){
		while(0!=options[dealervalue].length){
			var possiblenewkind = options[dealervalue].shift();
			if(0==kind.length){
				//nothing in kind array so this must be a new kind. ;-)
				kind[kind.length] = possiblenewkind;
			}else{
				for(var i=0; i<kind.length; i++){
					if(kind[i]==possiblenewkind){
						break;
					}
					if(i==kind.length-1){
						kind[kind.length] = possiblenewkind;
					}
				}
			}
		}
	}
	console.log(kind);
	//we now have our kind array. test for empty.
	var kindselect = document.getElementById('kind');
	for(var i=0; i<kind.length; i++){
		var newKindSelect = document.createElement('option');
		newKindSelect.setAttribute( 'value' ,  kind[i] );
	}
}
//addBodyLoad(setupDealerSearchBox);