function DeshabilitaMunicipiosColonias()
{
var idMunicipio=document.getElementById("idMunicipios");
var idColonia=document.getElementById("idColonias");


//Cambiar el COMBO a Seleccione uno... una vez se tenga mas anuncios
idMunicipio.options[idMunicipio.selectedIndex].text="Opcional...";
idMunicipio.disabled=true;

idColonia.options[idColonia.selectedIndex].text="Opcional...";
idColonia.disabled=true;
	
}


function DeshabilitaColonias()
{
var idColonia=document.getElementById("idColonias");
idColonia.options[idColonia.selectedIndex].text="Opcional...";
idColonia.disabled=true;
}



function DeshabilitaMunicipiosColoniasAltas()
{
var idMunicipio=document.getElementById("idMunicipios");
var idColonia=document.getElementById("idColonias");

idMunicipio.options[idMunicipio.selectedIndex].text="Seleccione uno...";
idMunicipio.disabled=true;

idColonia.options[idColonia.selectedIndex].text="Seleccione uno...";
idColonia.disabled=true;
	
}


function DeshabilitaColoniasAltas()
{
var idColonia=document.getElementById("idColonias");
idColonia.options[idColonia.selectedIndex].text="Seleccione uno...";
idColonia.disabled=true;
}




//*****************************************************************************************************************************
//*****************************************************************************************************************************
function CargaMunicipiosAltas()
{
	var xmlHttp= createXmlRequestObject();
	var idMunicipio=document.getElementById("idMunicipios");

	divMunicipios=document.getElementById("divMunicipio");	
//	divMunicipios.innerHTML="<img src=Imagenes/cargando.gif />";
	

	if (xmlHttp)
		{
			try
			{


						//Extraemos el indice del estado 
					var x=document.getElementById("idEstados");
					idEstadoBuscar=x.options[x.selectedIndex].value;
					
					xmlHttp.open("GET","SelectMuestraMunicipios.php?idEstadoBuscar=" + idEstadoBuscar,false);
					xmlHttp.onreadystatechange=function()
					{

						
						
						if (xmlHttp.readyState==4)
						{
										if(xmlHttp.status==200)
										{
												try
												{
				divMunicipios=document.getElementById("divMunicipio");													
htmlSelect="";				
htmlSelect="<select  name='nMunicipios' id='idMunicipios' onfocus='DeshabilitaColoniasAltas()' onchange='CargaColoniasAltas()' style ='width:185px' tabindex='9'>";
	
													
													htmlSelect+="<option value=0>Seleccione uno...</option>";

													htmlSelect+="</select>";
													divMunicipios=document.getElementById("divMunicipio");																										
													divMunicipios.innerHTML=htmlSelect;
													
													
													var idMunicipio=document.getElementById("idMunicipios");
													var xmlResponse= xmlHttp.responseXML;
													xmlRoot=xmlResponse.documentElement;
													MunicipioXML=xmlRoot.getElementsByTagName("Municipio");
													idMunicipioXML=xmlRoot.getElementsByTagName("idMunicipio");
													idMunicipio.disabled=false;
													

																for(var i=0;i<=MunicipioXML.length;i++)
																{
																	var nuevaOpcion=document.createElement("option");
																	nuevaOpcion.value=idMunicipioXML[i].childNodes[0].nodeValue;
																	nuevaOpcion.innerHTML=MunicipioXML[i].childNodes[0].nodeValue;
																	idMunicipio.appendChild(nuevaOpcion);

									
																}

												}
											catch(e){ }
										
										}
										else{
										alert("hay un problema al tratar de recuperar los datos: \n"+xmlHttp.statusText);
										}
						
						}//cerramos readystate 4
					
					}//cerramos funcion
			xmlHttp.send(null);
		}
			catch(e){alert("no se pudo conectar al servidor:\n"+e.toString());}	
	}
	

}

//*****************************************************************************************************************************
//*****************************************************************************************************************************
function MuestraMunicipios()
{
	var xmlHttp= createXmlRequestObject();
	var idMunicipio=document.getElementById("idMunicipios");

	divMunicipios=document.getElementById("divMunicipio");	
//	divMunicipios.innerHTML="<img src=Imagenes/cargando.gif />";


	if (xmlHttp)
		{
			try
			{
						//Extraemos el indice del estado 
					var x=document.getElementById("idEstados");
					idEstadoBuscar=x.options[x.selectedIndex].value;
					

					instruccion="SelectMuestraMunicipios.php?idEstadoBuscar=" + idEstadoBuscar;

					xmlHttp.open("GET",instruccion,false);
					
					xmlHttp.onreadystatechange=function()
					{
						
				
						
						if (xmlHttp.readyState==4)
						{

											if(xmlHttp.status==200)
											{
												
															try
															{
																			
																divMunicipios=document.getElementById("divMunicipio");													
																htmlSelect="";				
																htmlSelect="<select  name='nMunicipios' id='idMunicipios'   style ='width:185px' tabindex='9'>";
				
//Cambiar el Opcional por Seleccione uno cuando se tenga mas datos									
																htmlSelect+="<option value=0>Opcional...</option>";
			
																htmlSelect+="</select>";
																divMunicipios=document.getElementById("divMunicipio");																										
																divMunicipios.innerHTML=htmlSelect;
													
																var idMunicipio=document.getElementById("idMunicipios");																
																var xmlResponse= xmlHttp.responseXML;
																xmlRoot=xmlResponse.documentElement;
																MunicipioXML=xmlRoot.getElementsByTagName("Municipio");
																idMunicipioXML=xmlRoot.getElementsByTagName("idMunicipio");
																
																idMunicipio.disabled=false;



																			for(var i=0;i<=MunicipioXML.length;i++)
																			{
																				var nuevaOpcion=document.createElement("option");
																				nuevaOpcion.value=idMunicipioXML[i].childNodes[0].nodeValue;
																				nuevaOpcion.innerHTML=MunicipioXML[i].childNodes[0].nodeValue;
																				idMunicipio.appendChild(nuevaOpcion);
																				//y.options[i+1]= new Option(AgenciaXML.item(i).firstChild.data);
																			}
															}
												catch(e){ }
											
											}
											else{
											alert("hay un problema al tratar de recuperar los datos: \n"+xmlHttp.statusText);
											}
						
							}//cerramos readystate 4
					
				}//cerramos funcion
			xmlHttp.send(null);
		}
			catch(e){alert("no se pudo conectar al servidor:\n"+e.toString());}	
	}
	

}



//*****************************************************************************************************************************
//*****************************************************************************************************************************
function CargaMunicipios()
{
	var xmlHttp= createXmlRequestObject();
	var idMunicipio=document.getElementById("idMunicipios");

	divMunicipios=document.getElementById("divMunicipio");	
//	divMunicipios.innerHTML="<img src=Imagenes/cargando.gif />";



	if (xmlHttp)
		{
			try
			{
						//Extraemos el indice del estado 
					var x=document.getElementById("idEstados");
					idEstadoBuscar=x.options[x.selectedIndex].value;
					

					instruccion="SelectMuestraMunicipios.php?idEstadoBuscar=" + idEstadoBuscar;

					xmlHttp.open("GET",instruccion,false);
					
					xmlHttp.onreadystatechange=function()
					{
						
				
						
						if (xmlHttp.readyState==4)
						{

											if(xmlHttp.status==200)
											{
												
															try
															{
																			
																divMunicipios=document.getElementById("divMunicipio");													
																htmlSelect="";				
																htmlSelect="<select  name='nMunicipios' id='idMunicipios' onfocus='DeshabilitaColonias()' onchange='CargaColonias()' style ='width:185px' tabindex='9'>";
				
//Cambiar el Opcional por Seleccione uno cuando se tenga mas datos																
																htmlSelect+="<option value=0>Opcional...</option>";
			
																htmlSelect+="</select>";
																divMunicipios=document.getElementById("divMunicipio");																										
																divMunicipios.innerHTML=htmlSelect;
													
																var idMunicipio=document.getElementById("idMunicipios");																
																var xmlResponse= xmlHttp.responseXML;
																xmlRoot=xmlResponse.documentElement;
																MunicipioXML=xmlRoot.getElementsByTagName("Municipio");
																idMunicipioXML=xmlRoot.getElementsByTagName("idMunicipio");
																
																idMunicipio.disabled=false;



																			for(var i=0;i<=MunicipioXML.length;i++)
																			{
																				var nuevaOpcion=document.createElement("option");
																				nuevaOpcion.value=idMunicipioXML[i].childNodes[0].nodeValue;
																				nuevaOpcion.innerHTML=MunicipioXML[i].childNodes[0].nodeValue;
																				idMunicipio.appendChild(nuevaOpcion);
																				//y.options[i+1]= new Option(AgenciaXML.item(i).firstChild.data);
																			}
															}
												catch(e){ }
											
											}
											else{
											alert("hay un problema al tratar de recuperar los datos: \n"+xmlHttp.statusText);
											}
						
							}//cerramos readystate 4
					
				}//cerramos funcion
			xmlHttp.send(null);
		}
			catch(e){alert("no se pudo conectar al servidor:\n"+e.toString());}	
	}
	

}



//*****************************************************************************************************************************
//*****************************************************************************************************************************

function CargaColonias()
{
	var xmlHttp=createXmlRequestObject();
	var idColonias=document.getElementById("idColonias");

	divColonia=document.getElementById("divColonias");	
//	divColonia.innerHTML="<img src=Imagenes/cargando.gif />";

	if (xmlHttp)
		{
			try
			{
					//Extraemos el indice del estado a Buscar
					var x=document.getElementById("idEstados");
					idEstadoBuscar=x.options[x.selectedIndex].value;
					
						//Extraemos el indice del Municipio a buscar
					var x=document.getElementById("idMunicipios");
					idMunicipioBuscar=x.options[x.selectedIndex].value;

					xmlHttp.open("GET","SelectMuestraColonias.php?idEstadoBuscar=" + idEstadoBuscar+"&idMunicipioBuscar="+idMunicipioBuscar,false);
					xmlHttp.onreadystatechange=function()
					{
						

						if (xmlHttp.readyState==4)
						{
											if(xmlHttp.status==200)
											{
															try
															{
																
																htmlSelect="";
																htmlSelect="<select  disabled='disabled' name='nColonias'  id='idColonias' style ='width:185px' tabindex='10'>";
																htmlSelect+="<option value=0>Opcional...</option>";
																htmlSelect+="</select>";
																
																divColonia=document.getElementById("divColonias");																										
																divColonia.innerHTML=htmlSelect;
																
																var idColonias=document.getElementById("idColonias"); 
																
																var xmlResponse= xmlHttp.responseXML;
																xmlRoot=xmlResponse.documentElement;
																idColoniaXML=xmlRoot.getElementsByTagName("idColonia");
																ColoniaXML=xmlRoot.getElementsByTagName("Colonia");
											
																		idColonias.disabled=false;
																			for(var i=0;i<=ColoniaXML.length;i++)
																			{
																				var nuevaOpcion=document.createElement("option");
																				nuevaOpcion.value=idColoniaXML[i].childNodes[0].nodeValue;
																				nuevaOpcion.innerHTML=ColoniaXML[i].childNodes[0].nodeValue;
																				idColonias.appendChild(nuevaOpcion);
																			}																			
																		

																			
															}
												catch(e){ }
											
											}
											else{
											alert("hay un problema al tratar de recuperar los datos: \n"+xmlHttp.statusText);
											}
						
							}//cerramos readystate 4
					
				}//cerramos funcion
			xmlHttp.send(null);
		}
			catch(e){alert("no se pudo conectar al servidor:\n"+e.toString());}	
	}
	
	idColonias.remove(0);
}


//*****************************************************************************************************************************
//*****************************************************************************************************************************



function CargaColoniasAltas()
{
	var xmlHttp=createXmlRequestObject();
	var idColonias=document.getElementById("idColonias");

	divColonia=document.getElementById("divColonias");	
//	divColonia.innerHTML="<img src=Imagenes/cargando.gif />";


	if (xmlHttp)
		{
			try
			{
					//Extraemos el indice del estado a Buscar
					var x=document.getElementById("idEstados");
					idEstadoBuscar=x.options[x.selectedIndex].value;
					
						//Extraemos el indice del Municipio a buscar
					var x=document.getElementById("idMunicipios");
					idMunicipioBuscar=x.options[x.selectedIndex].value;

					xmlHttp.open("GET","SelectMuestraColonias.php?idEstadoBuscar=" + idEstadoBuscar+"&idMunicipioBuscar="+idMunicipioBuscar,false);
					xmlHttp.onreadystatechange=function()
					{
						if (xmlHttp.readyState==4)
						{
											if(xmlHttp.status==200)
											{
												
															try
															{
																htmlSelect="";
																htmlSelect="<select  disabled='disabled' name='nColonias'  id='idColonias' style ='width:185px' tabindex='10'>";
																htmlSelect+="<option value=0>Seleccione uno...</option>";
																htmlSelect+="</select>";
																
																divColonia=document.getElementById("divColonias");																										
																divColonia.innerHTML=htmlSelect;
																
																var idColonias=document.getElementById("idColonias"); 
																var xmlResponse= xmlHttp.responseXML;
																xmlRoot=xmlResponse.documentElement;
																idColoniaXML=xmlRoot.getElementsByTagName("idColonia");
																ColoniaXML=xmlRoot.getElementsByTagName("Colonia");
											

																		idColonias.disabled=false;
//																		idColonias.parentNode.innerHTML=xmlHttp.responseXML;
																		for(var i=0;i<=ColoniaXML.length;i++)
																			{
																				var nuevaOpcion=document.createElement("option");
																				nuevaOpcion.value=idColoniaXML[i].childNodes[0].nodeValue;
																				nuevaOpcion.innerHTML=ColoniaXML[i].childNodes[0].nodeValue;
																				idColonias.appendChild(nuevaOpcion);
																			}																			
																		

																			
															}
												catch(e){ }
											
											}
											else{
											alert("hay un problema al tratar de recuperar los datos: \n"+xmlHttp.statusText);
											}
						
							}//cerramos readystate 4
					
				}//cerramos funcion
			xmlHttp.send(null);
		}
			catch(e){alert("no se pudo conectar al servidor:\n"+e.toString());}	
	}
	
	idColonias.remove(0);
}

/*

function createXmlRequestObject()
{
    
    // Probamos con IE
    try
    {
        // Funcionar para JavaScript 5.0
        XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {   
            XMLHttpRequestObject = null;
        }
    }

    // Si no se trataba de un IE, probamos con esto
    if(!XMLHttpRequestObject && typeof XMLHttpRequest != "undefined")
    {
        XMLHttpRequestObject = new XMLHttpRequest();
    }

    return XMLHttpRequestObject;
}
*/

function createXmlRequestObject()
{
var XMLHttpRequestObject;

	try{
		XMLHttpRequestObject= new XMLHTTPRequest();
	}
	catch(e)
	{

		var versiones=new Array("Microsoft.XMLHTTP");
	

		for (var i=0; i< versiones.length;i++)
		{
			try{
					 XMLHttpRequestObject = new ActiveXObject(versiones[i]);
			   }
			catch(oError){}	
		}		
	}

	if(!XMLHttpRequestObject) {
		alert("No se creo objeto HTTPrequestObject");
	}
	else 
	return XMLHttpRequestObject;
}

