function WDYTNgetCity(state, idCity){
 	var objhttp = new XMLHttpRequest();
 	if (state == null) {
		state = document.getElementById("state").value;
	}
	var url = "../Register/fillCity.php?Language_id="+ document.getElementById("lang").value +"&State_id="+ state;
	var city = document.getElementById("city");
	city.setAttribute("disabled", "disabled");
	while(city.options.length != 1){
		city.options[1] = null;
	}

  	objhttp.open("GET", url, true);
  	objhttp.onreadystatechange = function(){
	  	if(objhttp.readyState == 4){
	    	if(objhttp.status == 200){
	        	fillCity(objhttp.responseXML, idCity);
		    }else{
	        	window.alert("Failed to get response: "+ objhttp.statusText);
	    	}
	  	}
  	}
  	objhttp.send(null);
}

function fillCity(ajaxResponse, idCity){
	var data = ajaxResponse.getElementsByTagName("Option");
	var city = document.getElementById("city");
	var othercity = document.getElementById("othercity");
	var state = document.getElementById("state");
	
	if(data.length <= 1 && state.value != ""){
		showAnotherCity(city, othercity);
	}else if(data.length > 1){
		hideAnotherCity(city, othercity);
		
		for(i = 1; i <= city.options.length; i++){
			city.options[i] = null;
		}
		for(i = 0; i < data.length; i++){
			var selectValue = data[i].getAttribute("Id");
			var selectText = data[i].firstChild.nodeValue;
			if (selectValue == idCity) {
				city.options[i+1] = new Option(selectText, selectValue, true, true);
			} else {
				city.options[i+1] = new Option(selectText, selectValue, false, false);
			}
		}
	}
}
function WDYTNOtherCity(){
  	var city = document.getElementById("city");
	var othercity = document.getElementById("othercity");
	
  	if(city.value == 11103){
	  	showOtherCity(city, othercity);
	} else {
	  	hideOtherCity(city, othercity);
	}
}
function showOtherCity(city, othercity){
	othercity.setAttribute("size", 20);
	othercity.style.display = "block";
	othercity.value = "";
	othercitytxt.style.display = "block";
}

function hideOtherCity(city, othercity){
	othercity.setAttribute("size", 1);
	othercity.style.display = "none";
	othercity.value = "";
	othercitytxt.style.display = "none";
}
function showAnotherCity(city, othercity){
	city.style.width = "150px";
	city.disabled = true;
	othercity.setAttribute("size", 20);
	othercity.style.display = "block";
	othercity.value = "";
	othercitytxt.style.display = "block";
}

function hideAnotherCity(city, othercity){
	city.style.width = "150px";
	city.disabled = false;
	othercity.setAttribute("size", 1);
	othercity.style.display = "none";
	othercity.value = "";
	othercitytxt.style.display = "none";
}