var loc_counter = 3
// LOCATIONS
function show_popup(name) {
	document.getElementById(name).style.display = "block";
}

function close_popup(name) {
	document.getElementById(name).style.display = "none";
}

function change_cities() {
	var country = document.getElementById('Country');
	var div_city = document.getElementById('div_city');
	var div_temp = document.getElementById('div_country'+country.value);
	div_city.innerHTML = div_temp.innerHTML;
}

function check_filled_loc() {
	var counter_filled = 0;
	var tabs_counter_filled = 0;
	var div_id
	for (i=1;i <= loc_counter;i++)
	{
		div_id = 'locationsearch'+i;
		$('input, textarea, select', '#'+div_id).each(function(){ if($(this).val() != '' && $(this).val() != null ){counter_filled++;
			if(i>1){tabs_counter_filled++;}
		}});
	}
	
	if(tabs_counter_filled > 0)
	{
		$('#loc_filled').css('display','inline');
	}else
	{
		$('#loc_filled').css('display','none');
	}
}

function add_loc() {
	var container = $('#cont_loc').html();
	var new_container = container.replace(/_numb_/g, loc_counter);
	$('#one_more_loc').append(new_container);

	loc_counter++;
}

function remove_loc_el(block_numb) {
	 
	 var el = document.getElementById("loc"+block_numb);
	el.parentNode.removeChild(el);
	check_filled_loc();
}

function clear_loc() {
	//$('#alias2_firstname').value = '';
	document.getElementById('address2_City').value = '';
	document.getElementById('address2_Country').value = '';
	
	for(i=3;i<loc_counter;i++)
	{
		//remove_loc_el(i);
		var el = document.getElementById("loc"+i);
		if(el){
		el.parentNode.removeChild(el);
		}
		//el.remove;
	}
	loc_counter = 3;
	check_filled_loc();
}

