var assoc_custom_default = new Array();
var assoc_default_custom = new Array();
var assoc_exists = new Array();
var object_path = {
	"country" 		: {"empty" : true,	"path" : "/includes/ajax/place.php",		"data" : ""},
	"region" 		: {"empty" : false,	"path" : "/includes/ajax/place.php",		"data" : "country_id="},
	"city" 			: {"empty" : false,	"path" : "/includes/ajax/place.php", 		"data" : "region_id="},
	"education" 	: {"empty" : true,	"path" : "/includes/ajax/education.php",	"data" : ""},
	"job_type" 		: {"empty" : true,	"path" : "/includes/ajax/job_type.php",		"data" : ""},
	"job_sub_type" 	: {"empty" : false,	"path" : "/includes/ajax/job_type.php",		"data" : "type_id="}};

// Function get list of items by ajax
function getAjaxSelectList(name, id, selected) {	if (object_path[name].empty || (!object_path[name].empty && id > 0)) {
		$.ajax({async: false, url: object_path[name].path, data: object_path[name].data + (id ? id:""), success: function(data) {			if (data) {
				// Get objects
				var list = $("select#" + name);

				// Remove old data
				$("select#" + name + " option[value!='0']").remove();

				// Split get data
				var items = data.split("|");

				// Get count of elements on the list
				var items_count = items.length;

				for (i=0; i<items_count; i++) {
					// Split element data
					var item = items[i].split(":");

					// Create new option
					list.append("<option value='" + item[0] + "'>" + item[1] + "</option>");
				}

				// If selected item then set option
				if (selected) {
					$("select#" + name + " option[value='" + selected + "']").attr("selected", "true");
				}

				if (assoc_exists[name]) {					// alert(selects[assoc_default_custom[name]].options.length)
					populateSelectOptions(selects[assoc_default_custom[name]]);
					$("#optionsDiv" + assoc_default_custom[name] + " ul").html(selects[assoc_default_custom[name]]._options);
				}
			}
		}});
	}

	return true;}

// Selected user's place
function setPlaceList(country_id, region_id, city_id) {
	if (country_id) {
		getAjaxSelectList("country", false, country_id);
		getAjaxSelectList("region", country_id);

		if (region_id) {
			getAjaxSelectList("region", country_id, region_id);
			getAjaxSelectList("city", region_id);

			if (city_id) {
				getAjaxSelectList("city", region_id, city_id);
			}
		}
	} else {
		getAjaxSelectList("country");
	}
}

// Selected user's job type
function setTypeList(type_id, sub_type_id) {
	if (type_id) {
		getAjaxSelectList("job_type", false, type_id);
		getAjaxSelectList("job_sub_type", type_id);

		if (sub_type_id) {
			getAjaxSelectList("job_sub_type", type_id, sub_type_id);
		}
	} else {
		getAjaxSelectList("job_type");
	}
}

// Associate custom selects
function assocCustomSelect(old_id, new_id) {	if (old_id && old_id != "") {		assoc_exists[old_id] = true;		assoc_custom_default[new_id] = old_id;		assoc_default_custom[old_id] = new_id;
	}}

// Get language from
function addMoreLang(object) {
	if ($(object).val() > 0) {
		var id = $(object).val();
		var text = $(object).children("[value=" + id + "]").text();
		var html = $("#lang-template").html();
		html = html.replace(/::id::/ig, id);
		html = html.replace(/::text::/ig, text);
		$("#lang-template").before(html);
		$(object).children("[value=" + id + "]").remove();

		getElements();
		replaceSelects();
	}
}
