var req = null;

function InitXMLHttpRequest() {
	// Make a new XMLHttp object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
}


function SelectCountry(section, destination) {
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				destination.innerHTML = req.responseText;
			} else {
				destination.innerHTML = "Loading data...";
			}
		}
		req.open("GET", "location.php?sec=" + section + "&sel=country", true);
		req.send(null);
	} else {
		destination.innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function SelectRegion(section, id_country, destination, destination2, text, text2) {
	InitXMLHttpRequest();
	if (id_country != '') {
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				} else {
					destination.innerHTML = "<select style=\"width:150px;\"><option>"+text+"</option></select>";
				}
			}
			req.open("GET", "location.php?sec=" + section + "&sel=region&id_country=" + id_country, true);
			req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		req.open('GET', 'location.php?sec=' + section + '&sel=region', false);
	    req.send(null);
    	destination.innerHTML = req.responseText;
	}
    destination2.innerHTML = "<select style=\"width:150px;\"><option>"+text2+"</option></select>";
}

function SelectCity(section, id_region, destination, text){
	InitXMLHttpRequest();
    if (id_region != '') {
		// Load the result from the response page
	    if (req){
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				} else {
					destination.innerHTML = "<select style=\"width:150px;\"><option>"+text+"</option></select>";
				}
			}
	       req.open('GET', 'location.php?sec=' + section + '&sel=city&id_region=' + id_region, true);
	       req.send(null);
	    }
	    else{
	       destination.innerHTML = 'Browser unable to create XMLHttp Object';
	    }
    }
    else {
    	req.open('GET', 'location.php?sec=' + section + '&sel=city', false);
		req.send(null);
    	destination.innerHTML = req.responseText;
    }
}
