$(document).ready(function() {
	
	//change the region when clicking on Countries..
	$("#idareacountries").change(function () {
		countryid = $(this).val();
		countryname = $("#idareacountries option:selected").text();
		$.post("/usersection/index.php/personals/changeregions/" + countryid + "/" + countryname + "/", function(data){
			$("#idarearegions").html(data);
 		});
	})
	
	
	
	//change the town when clicking on Regions..
	$("#idarearegions").change(function () {
		regionid = $(this).val();
		regionname = $("#idarearegions option:selected").text();
		$.post("/usersection/index.php/personals/changelocals/" + regionid + "/" + regionname + "/", function(data){
			$("#idarealocals").html(data);
 		});
	})
	
	
	
	//add countries to selected country box.. 
	$("#add_country").click(function () {
	   $("#idareacountries").copyOptions("#idselectedcountries");
	});
	
	//remove countries from selected countrylist
	$("#remove_country").click(function () {
	   countryid = $("#idselectedcountries").val(); 
	   $("#idselectedcountries").removeOption(countryid);
	});
	
	//add regions to selected region box.. 
	$("#add_region").click(function () {
	   $("#idarearegions").copyOptions("#idselectedregions");
	});
	
	//remove regions from selected regionlist
	$("#remove_region").click(function () {
	   regionid = $("#idselectedregions").val(); 
	   $("#idselectedregions").removeOption(regionid);
	});

	//add locals to selected local box.. 
	$("#add_town").click(function () {
	   $("#idarealocals").copyOptions("#idselectedlocals");
	});
	
	//remove regions from selected regionlist
	$("#remove_town").click(function () {
	   regionid = $("#idselectedlocals").val(); 
	   $("#idselectedlocals").removeOption(regionid);
	});

   //select all selected before you press submit..
   $("#submit").click(function() {
	  $("#idselectedcountries").selectOptions(/^/);
	  $("#idselectedregions").selectOptions(/^/);
	  $("#idselectedlocals").selectOptions(/^/);
   });


});

