// Функция, осуществляющая AJAX запрос. 
function loadXMLDoc( method, url ){ 
  if ( window.XMLHttpRequest ) { 
    req = new XMLHttpRequest(); 
    req.onreadystatechange = processReqChange; 
    req.open(method, url, true); 
    req.send( null ); 
  } else if ( window.ActiveXObject ) { 
    req = new ActiveXObject( "Microsoft.XMLHTTP" ); 
    if ( req ) { 
      req.onreadystatechange = processReqChange; 
      req.open( method, url, true ); 
      req.send( ); 
    } 
  } 
} 
// Функция, выполняемая при изменении статуса 
// запроса, если статус  равен 200, данные получены. 
function processReqChange() { 
  if ( req.readyState == 4 ) { 
    if ( req.status == 200 ) 
      getColors(req.responseXML.documentElement); 
    else 
      alert("There was a problem retrieving the XML data:\n" + req.statusText); 
  } 
} 
function onChange( _this ) { 
    var url = "ajax.php?models=" + _this.value; 
    loadXMLDoc( "get", url ); 
} 



function getColors( xml ) { 
  
  
  var colors = xml.getElementsByTagName( "color" ); 
  
  var _select = document.getElementById( "colors" ); 
  _select.innerHTML = ""; // Удаляем всех потомков. 
  // Создаем список с доступными цветами. 
  for ( i=0; i<colors.length; i++ ) {  
    var option = document.createElement( "option" ); 
    var optionText = document.createTextNode( colors[i].firstChild.data ); 
    option.appendChild( optionText ); 
    if (colors[i].firstChild.data=="-=Select Model=-")
	{option.setAttribute( "value","0");}
	else
	{option.setAttribute( "value",colors[i].firstChild.data )};
	/*option.setAttribute( "value",colors[i].getAttribute("value") ); */
    _select.appendChild( option ); 
  } 
}


