// JavaScript Document

function atualizar_motores(modelos, motores, motor_default) {
	var ajax = null;
	try {
		if(window.XMLHttpRequest)
			ajax = new XMLHttpRequest();
		else if (window.ActiveXObject)
	    	ajax = new ActiveXObject('Microsoft.XMLHTTP');
	} catch(e) {
		alert('Erro ao atualizar lista de motores.');
	}
	
	
	ajax.onreadystatechange = function() {
		
		switch(ajax.readyState) {
		case 4:
			var i;
			var length = motores.childNodes.length;
			for(i = 0; i < length; ++i) {
				motores.removeChild(motores.childNodes[0]);
			}
			
			for(i = 0; i < ajax.responseXML.firstChild.childNodes.length; ++i) {
				var node = ajax.responseXML.firstChild.childNodes[i];
				if(node.nodeName == 'option') {
					var option = document.createElement('option');
					option.setAttribute('value', unescape(node.getAttribute('value')));
					if(node.getAttribute('selected') != null)
						option.setAttribute('selected', 'selected');
					option.innerHTML = (unescape(node.firstChild.nodeValue));
					motores.appendChild(option);
				}
			}
			break;
		}
		
	}
	
	ajax.open('GET', 'index.php?op=opcoes_motor&modelo='+escape(modelos.options[modelos.selectedIndex].value)+(motor_default != null?('&motor='+escape(motor_default)):''), true);
	ajax.send(null);
	
}