function create_element(element_name,append_to,attributes) {
	var El=document.createElement(element_name);
	if (typeof(attributes)=="object") {
		for (i=0;i<attributes.length;i++) {
			xxx=attributes[i].split("=");
			attributName=xxx[0];
			attributVal=xxx[1];
			El.setAttribute(attributName,attributVal);
		}
	}
	myElement=append_to.appendChild(El);
	return myElement;
}


function makeTextNode(target,text) {
	customText = document.createTextNode(text);
	target.appendChild(customText);
}

function show_cities_div() {
	var myDiv = document.getElementById('cities_div');
	myDiv.style.display = 'block';
}
$('#c_div').click(function(event){
     event.stopPropagation();
 });
$('html').click(function(e) {
	if ($(e.target).is('#cities_div')) return;
	if ($('#cities_div').is(":visible")) {
		$('#cities_div').hide();
	}
});
function show_cities(country_id, lang) {
	if (!lang) lang = 'ru';
	if (!country_id) return;
	$("#country_select").disabled = true;
	$("#prev_btn").disabled = true;
	$("#next_btn").disabled = true;
			$.ajax( {
			url : "/ajax/get_cities.php?country=" + country_id + "&lang=" + lang,
			type: "get",
			dataType : 'text',
			success : function(data) {
				$("#city_select").empty();

				if (data != "") {
					lang == 'ru' ? $("#city_select").append( $('<option value="0">[ Выберите город ]</option>') ) : $("#city_select").append( $('<option value="0">[ Select city]</option>') )
					//$("#city_select").options[0].style.color = "#888888";

					var new_cities = data.split("\n")
					for (var i = 0; i < new_cities.length; i++) {
						if (new_cities[i] != "") {
							var o = new_cities[i].split(":")
							$("#city_select").append( $('<option value="'+o[0]+'">'+o[1]+'</option>') )
						}
					}
					//$("#cities").show();
					slideDiv('cities',1);
				} else {
					lang == 'ru' ? $("#city_select").append( $('<option value="0">[ Выберите город ]</option>') ) : $("#city_select").append( $('<option value="0">[ Select city]</option>') )
					//$("#cities").hide();
					slideDiv('cities',0);
				}
				$("#country_select").disabled = false
				$("#prev_btn").disabled = false;
				$("#next_btn").disabled = false;
			},
			error : function() {
				alert('Ошибка загрузки данных.')
			}
		});
		
}






