function updateFromRegion(selectID){

	if(!selectID){
		selectID = 'regionUID';
	}
	var regionUID = $('#'+selectID).val();
	var url = "/ajax/getCountryFromRegion.php?regionUID=" + regionUID;

	$.ajax({
	  url: url,
	  dataType: 'json',
	  success: function(response){
			  
		  var ih = "";
		  ih += '<option value="0">Please Choose</option>';
		  
		  var icons = [];
		  
		  $.each(response, function(key, val){
			  
			  
			  var tehClass = val.name;
			  tehClass = tehClass.replace(/ /gi, '');
			  tehClass = tehClass.replace('/', '');
			  ih += '<option value="' + val.UID + '" class="CI' + tehClass + '" >' + val.name + '</option>';
			  
			  icons.push({find: '.CI'+tehClass});
		  });
		  $('#countryUID-menu').html('');
		  $('#countryUIDdiv').html('<p><label style="color:#47454E;" for="name">Select a Country</label></p><p><select name="countryUID" style="width:400px;" id="countryUID" onChange="updateFromCountry();">');
		  $('#countryUID').html(ih);
		  $('#countryUID').selectmenu({style:'dropdown',maxHeight: 200,icons:icons});
			
		  $('#stateUID').html('<option value="0">Please Choose</option>');
	  }
	});
	
}

function updateFromRegion2(selectID){

	if(!selectID){
		selectID = 'regionUID';
	}
	var regionUID = $('#'+selectID).val();
	var url = "/ajax/getCountryFromRegion.php?regionUID=" + regionUID;

	$.ajax({
		url: url,
		dataType: 'json',
		success: function(response){
			
			var ih = "";
			ih += '<option value="0">Please Choose</option>';
		  
			var icons = [];
		  
			$.each(response, function(key, val){
			  
				var tehClass = val.name;
				tehClass = tehClass.replace(/ /gi, '');
				tehClass = tehClass.replace('/', '');
				ih += '<option value="' + val.UID + '" class="CI' + tehClass + '" >' + val.name + '</option>';
				
				icons.push({find: '.CI'+tehClass});
			});
			$('#countryUIDa-menu').html('');
			$('#countryUIDadiv').html('<p><label style="color:#47454E;" for="name">Select a Country</label><select name="countryUID" id="countryUIDa" style="width:400px;"  onChange="updateFromCountry(this.id);">');
			$('#countryUIDa').html(ih);
			$('#countryUIDa').selectmenu({style:'dropdown',maxHeight: 200,icons:icons});
		
			$('#stateUID').html('<option value="0">Please Choose</option>');
		}
	});
	
}

function updateFromFlag(selectID){

	if(!selectID){
		selectID = 'regionUID';
	}
	var regionUID = $('#'+selectID).val();
	var url = "/ajax/getCountryFromRegion.php?regionUID=" + regionUID;

	$.ajax({
	  url: url,
	  dataType: 'json',
	  success: function(response){
			  
		  var ih = "";
		  ih += '<option value="0">Please Choose</option>';
		  
		  var icons = [];
		  
		  $.each(response, function(key, val){
			  
			  
			  var tehClass = val.name;
			  tehClass = tehClass.replace(/ /gi, '');
			  tehClass = tehClass.replace('/', '');
			  ih += '<option value="' + val.UID + '" class="CI' + tehClass + '" >' + val.name + '</option>';
			  
			  icons.push({find: '.CI'+tehClass});
		  });
		  $('#countryUID-menu').html('');
		  $('#countryUIDdiv').html('<p><label style="color:#47454E;" for="name">Select a Country</label><select name="countryUID" id="countryUID" style="width:400px;">');
		  $('#countryUID').html(ih);
		  $('#countryUID').selectmenu({style:'dropdown',maxHeight: 200,icons:icons});
			
		  $('#stateUID').html('<option value="0">Please Choose</option>');
	  }
	});
	
	
}

function updateFromCountry(selectID){
	
	if(!selectID){
		selectID = 'countryUID';
	}
	var countryUID = $('#'+selectID).val();
	var url = "/ajax/getStatesFromCountry.php?countryUID=" + countryUID;
	
	$.ajax({
		url: url,
		dataType: 'json',
		success: function(response){
			
			var ih = "";
			ih += '<option value="0">Please Choose</option>';

			$.each(response, function(key, val){

				ih += '<option value="' + val.UID + '">' + val.name + '</option>';
		  
			});
			$('#stateUID').html(ih);
		  
		}
	});

}

function updateFromState(){
	

	var stateUID = $('#stateUID').val();
	var url = "/ajax/getSubRegionsFromState.php?stateUID=" + stateUID;

	$.ajax({
		url: url,
		dataType: 'json',
		success: function(response){
			
			var ih = "";
			ih += '<option value="0">Please Choose</option>';

			$.each(response, function(key, val){

				ih += '<option value="' + val.UID + '">' + val.name + '</option>';
		  
			});

			$('#subRegionUID').html(ih);
		  
		}
	});

}
