function objetoAjax(){
        var xmlhttp=false;
        try {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
               try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (E) {
                       xmlhttp = false;
               }
        }
 
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
               xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}

function refrescar_modelos(id_marca){
	select=document.forms['personalizada'].elements['modelo'];
	select.options.length = 0;
	opcion=new Option("Todos","-1");
	select.options[select.options.length]=opcion;
    ajax=objetoAjax();
    ajax.open("GET", 'http://coches.cope.es/lib/modelos_marca.php?id_marca='+id_marca);
    ajax.onreadystatechange=function() {
           if (ajax.readyState==4) {
               respuesta = ajax.responseText;
			   a_res = respuesta.split('&');
               nombres = a_res[0].split('-');
               valores = a_res[1].split('-');
	           for (i=0;i<nombres.length;i++){
					opcion=new Option(nombres[i],valores[i]);
					select.options[select.options.length]=opcion;
			   }
           }
	}	
    ajax.send(null)	
}

function refrescar_version(id_marca,id_modelo){
	select=document.forms['personalizada'].elements['version'];
	select.options.length = 0;
	opcion=new Option("Todos","-1");
	select.options[select.options.length]=opcion;
    ajax=objetoAjax();
    ajax.open("GET", "http://coches.cope.es/lib/versiones_modelos.php?id_marca="+id_marca+"&id_modelo="+id_modelo);
    ajax.onreadystatechange=function() {
           if (ajax.readyState==4) {
               respuesta = ajax.responseText;
			   a_res = respuesta.split('&');			   
               nombres = a_res[0].split('-');
               valores = a_res[1].split('-');
	           for (i=0;i<nombres.length;i++){
					opcion=new Option(nombres[i],valores[i]);
					select.options[select.options.length]=opcion;
			   } 
           }         
	}	
    ajax.send(null)		
}
function texto_campo(id,valor){
	texto = valor.options[valor.selectedIndex].text;
	document.getElementById("texto_"+id).value=texto;
}
