function LoadAjax() { 

	var xmlhttp = false;
	
	try	{
		
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
	} catch(e) {
		
				try {
				
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					
				} catch(E) {
					
						if (!xmlhttp && typeof XMLHttpRequest != 'undefined') xmlhttp = new XMLHttpRequest();
						
				}
				
	}
	
	return xmlhttp; 
	
}

var Selects = new Array();

Selects[0] = "Country";
Selects[1] = "District";

function SearchArray(array, data) {
	
	var x=0;
	
	while(array[x])	{
		
		if(array[x] == data) return x;
		
		x++;
		
	}
	
	return null;
	
}

function LoadContent(idSource, Base, Districts, SelectOne) {	
		
	var iSelectDestination = SearchArray(Selects, idSource) + 1;
	var SelectSource = document.getElementById(idSource);
	var Selected = SelectSource.options[SelectSource.selectedIndex].value;
	
	if(Selected == 0)	{
		
		var x = iSelectDestination, Current=null;
		
		while(Selects[x]) {
			
			Current = document.getElementById(Selects[x]);
			Current.length=0;
			
			var NewOption = document.createElement("option"); 
			
			NewOption.value = 0; 
			NewOption.innerHTML = "Selecciona Opci&oacute;n...";
			Current.appendChild(NewOption);	
			Current.disabled = true;
			
			x++;
			
		}
		
	} else if(idSource != Selects[Selects.length - 1]) {
		
		var idDestination = Selects[iSelectDestination];
		var SelectDestination = document.getElementById(idDestination);
		var ajax = LoadAjax();
		
		ajax.open("POST", Base + "/lib/scripts/ajax/users/countries.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function() { 
		
			if(ajax.readyState == 1) {
				
				SelectDestination.length = 0;
				
				var NewOption = document.createElement("option"); 
				
				NewOption.value = 0; 
				NewOption.innerHTML = "Cargando...";
				SelectDestination.appendChild(NewOption); 
				SelectDestination.disabled = true;	
				
			}
			
			if(ajax.readyState == 4) {
				
				SelectDestination.parentNode.innerHTML = ajax.responseText;
				
			} 
			
		}
		
		ajax.send("Country=" + Selected + "&Districts=" + Districts + "&SelectOne=" + SelectOne);
		
	}
	
}