function OHgetState(){
	var url = "./js/getState.php?Language_id="+ document.getElementById("lang").value +"&Country_id="+ document.getElementById("country").value;
	var state = document.getElementById("state");
	var city = document.getElementById("city");
	
	while(state.options.length != 1){
		state.options[1] = null;
	}
	
	while(city.options.length != 1){
		city.options[1] = null;
	}
	
  xmlhttp.open("GET", url, true);
  xmlhttp.onreadystatechange = function(){
  	if(xmlhttp.readyState == 4){
      if(xmlhttp.status == 200){
        fillState(xmlhttp.responseXML);
	    }else{
        window.alert("Failed to get response: "+ xmlhttp.statusText);
      }
  	}
  }
  xmlhttp.send(null);
}

function fillState(ajaxResponse){
	var data = ajaxResponse.getElementsByTagName("state");
	var state = document.getElementById("state");
	var otherstate = document.getElementById("otherstate");
	
	if(data.length <= 1){
		showAnotherState(state, otherstate);
		OHgetCity();
	}else{
		hideAnotherState(state, otherstate);
		
		for(i = 1; i <= state.options.length; i++){
			state.options[i] = null;
		}
	
		for(i = 0; i < data.length; i++){
			var selectValue = data[i].getElementsByTagName("id_state")[0].firstChild.nodeValue;
			var selectText = data[i].getElementsByTagName("name_state")[0].firstChild.nodeValue;
			state.options[i+1] = new Option(selectText, selectValue);
		}
	}
}
function OHOtherState(){
  	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", 30);
	otherstate.style.visibility = "";
	otherstate.value = "";
}

function hideOtherState(state, otherstate){
	otherstate.setAttribute("size", 1);
	otherstate.style.visibility = "hidden";
	otherstate.value = "";
}
function showAnotherState(state, otherstate){
	state.style.width = "200px";
	state.disabled = true;
	otherstate.setAttribute("size", 30);
	otherstate.style.visibility = "";
	otherstate.value = "";
}

function hideAnotherState(state, otherstate){
	state.style.width = "200px";
	state.disabled = false;
	otherstate.setAttribute("size", 1);
	otherstate.style.visibility = "hidden";
	otherstate.value = "";
}