function getHTTPObject(){
	var xmlhttp;
	// Attempt to initialize xmlhttp object
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
    catch (e) {
		// Try to use different activex object
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	// If not initialized, create XMLHttpRequest object
	if (!xmlhttp) {
		if (typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
		}
		else {
			alert("This browser does not support AJAX.");
			return null;
		}
	}
	return xmlhttp;
}

// Implement business logic
function get_orase(){
	httpObject = getHTTPObject();
	var categorie = document.getElementById('categorie').value;
	var tip_oferta = document.getElementById('tip_oferta').value;
	
	if (httpObject != null) {
		loc = '/imobile/get_orase/' + categorie + '/' + tip_oferta;
		httpObject.open("GET", loc, true);
		httpObject.onreadystatechange = showOrase;
		httpObject.send(null);
	}
}

function showOrase(){
	var combo = document.getElementById('localitate');
	combo.options.length = 0;
	if(httpObject.readyState == 4){
		var response = httpObject.responseText;
		combo.innerHTML = response;
		/*
		var items = response.split(";");
		var count = items.length;
		
		for (var i = 0; i < count; i++) {
			if (items[i] == '') continue;
			var options = items[i].split("-");
			combo.options[i] =	new Option(options[1], options[0]);
			if (options[1] == 'Sibiu')
				combo.options[i].selected = true;
		}*/
	}
	else 
		combo.options[0] = new Option('se incarca...');
}
