function WDYTNgetState(idState){
 	var objhttp = new XMLHttpRequest();
	var url = "../Register/fillState.php?Language_id="+ document.getElementById("lang").value +"&Country_id="+ document.getElementById("country").value;
	var state = document.getElementById("state");
	var city = document.getElementById("city");
	state.setAttribute("disabled", "disabled");
	while(state.options.length >= 3){
		state.options[2] = null;
	}
	
	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){
	        	fillState(objhttp.responseXML, idState);
		    }else{
	        	window.alert("Failed to get response: "+ objhttp.statusText);
	      	}
	  	}
  	}
	objhttp.send(null);
}

function fillState(ajaxResponse, idState){
	var data = ajaxResponse.getElementsByTagName("Option");
	var state = document.getElementById("state");
	var otherstate = document.getElementById("otherstate");
	var country = document.getElementById("country");

	if(data.length <= 1 && country.value != ""){
		showAnotherState(state, otherstate);
	}else if(data.length > 1){
		hideAnotherState(state, otherstate);

		for(i = 2; i <= state.options.length; i++){
			state.options[i] = null;
		}
		for(i = 0; i < data.length; i++){
			var selectValue = data[i].getAttribute("Id");
			var selectText = data[i].firstChild.nodeValue;
			if (selectValue == idState) {
				state.options[i+2] = new Option(selectText, selectValue, true, true);
			} else {
				state.options[i+2] = new Option(selectText, selectValue, false, false);
			}
		}
	}
}
function WDYTNOtherState(){
  	var state = document.getElementById("state");
	var otherstate = document.getElementById("otherstate");
	
  	if(state.value == 1){
	  	showOtherState(state, otherstate);
	} else {
	  	hideOtherState(state, otherstate);
	}
}
function showOtherState(state, otherstate){
	otherstate.setAttribute("size", 20);
	otherstate.style.display = "block";
	otherstate.value = "";
	document.getElementById("otherstatetxt").style.display = "block";
}

function hideOtherState(state, otherstate){
	otherstate.setAttribute("size", 1);
	otherstate.style.display = "none";
	otherstate.value = "";
	document.getElementById("otherstatetxt").style.display = "none";
}
function showAnotherState(state, otherstate){
	state.style.width = "150px";
	state.disabled = true;
	otherstate.setAttribute("size", 20);
	otherstate.style.display = "block";
	otherstate.value = "";
	document.getElementById("otherstatetxt").style.display = "block";
}

function hideAnotherState(state, otherstate){
	state.style.width = "150px";
	state.disabled = false;
	otherstate.setAttribute("size", 1);
	otherstate.style.display = "none";
	otherstate.value = "";
	document.getElementById("otherstatetxt").style.display = "none";
}