addEvent(window,'load',inicializarEventosBusEdos,false);

function inicializarEventosBusEdos()
{
  var select1=document.getElementById('estado_id1');
  addEvent(select1,'change',mostrarmunicipios,false);
}

var conexion1;
function mostrarmunicipios(e) 
{
  var codigo=document.getElementById('estado_id1').value;
  if (codigo >= -1)
  {
	conexion1=crearXMLHttpRequest();
    conexion1.onreadystatechange = procesarEventosMun;
    conexion1.open('GET','ajax/reg_mun2.php?cod='+codigo, true);
    conexion1.send(null);
  }
  else
  {
    var select2=document.getElementById('municipio_id1');
    select2.options.length=0;
  }
}

function procesarEventosMun()
{
	if(conexion1.readyState == 4)
	{
		var d=document.getElementById('espera');
		d.innerHTML = '';
		var xml = conexion1.responseXML;
		var total=xml.getElementsByTagName('mun');
		var select2=document.getElementById('municipio_id1');
		select2.options.length=0;
		for(f=0;f<total.length;f++)
		{
			var paso=total[f].getAttribute('id_mun');
			var op=document.createElement('option');
			var texto=document.createTextNode(total[f].firstChild.nodeValue);
			op.setAttribute("value",paso);
			op.appendChild(texto);
			select2.appendChild(op);
		}
	} 
	else 
	{
		var d=document.getElementById('espera');
//		d.innerHTML = '<font color=#800000 size=3> P r o c e s a n d o . . . . </font>';
		d.innerHTML = '';
	}
}


//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

