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;
}
 

function setOutput_localitate(){
	var combo = document.getElementById('localitate');
	combo.options.length = 0;
	if(httpObject.readyState == 4){
		var response = httpObject.responseText;
		var items = response.split(";");
		var count = items.length;
		combo.options[0] = new Option('Alege localitatea', '');
		for (var i=1;i<count;i++) {
			if (items[i] == '') continue;
			var options = items[i].split("-");
			/*combo.options[i] =	new Option(options[0], options[0]);
			if (options[1] == true)
				combo.options[i].selected = true;*/
			if (options[1] == 'false')
				combo.options[i] =	new Option(options[0], options[0]);
			else
				combo.options[i] =	new Option(options[0], options[0], true, true);			
			
		}
	}
	else 
		combo.options[0] = new Option('asteptati...');
}

function setOutput_localitate_livrare(){
	var combo = document.getElementById('localitate_livrare');
	combo.options.length = 0;
	if(httpObject.readyState == 4){
		var response = httpObject.responseText;
		var items = response.split(";");
		var count = items.length;
		combo.options[0] = new Option('Alege localitatea', '');
		for (var i=1;i<count;i++) {
			if (items[i] == '') continue;
			var options = items[i].split("-");
			/*combo.options[i] =	new Option(options[0], options[0]);
			if (options[1] == true)
				combo.options[i].selected = true;*/
			if (options[1] == 'false')
				combo.options[i] =	new Option(options[0], options[0]);
			else
				combo.options[i] =	new Option(options[0], options[0], true, true);			
			
		}
	}
	else 
		combo.options[0] = new Option('asteptati...');
}

function arata_localitati(judet,livrare){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		loc = '/orase/arata_localitati/'+judet;
		httpObject.open("GET", loc, true);
		if (livrare != 1) {
			httpObject.onreadystatechange = setOutput_localitate;
		} else {
			httpObject.onreadystatechange = setOutput_localitate_livrare;
		}
		httpObject.send(null);
	}
}