function handleHttpResponse() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
		oficinas = http.responseText.split("\r\n");	
		blanquear_oficina();
		for(i=0; i<oficinas.length-1; i++)	
			setValues2(document.forms[0],oficinas[i]);
		enProceso = false;
          }
       }
    }
}

function setValues2(id,oficina){
	results = oficina.split(",");
	obj = document.getElementById("idciudad");
	var opt = new Option(results[1],results[0]);
	pos = obj.length;
	eval(obj.options[pos] = opt);
}

function blanquear_oficina(){
	obj = document.getElementById("idciudad");
	for (i=obj.options.length-1;i>=0;i--)
		obj.options[i]=null;
}

function ciudadesPorPais(idpais){
	if(document.getElementById('idciudad').disabled==true)
		document.getElementById('idciudad').disabled=false;
	if (!enProceso && http){
		var url = "scripts/ciudades.php?idpais="+idpais;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpResponse;
		enProceso = true;
		http.send(null);
	}
}

function getHTTPObject() {
    var xmlhttp;
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}

var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest

