function bindTreeClick(){
	
	$('#specWindow .elemtxt').unbind('dblclick');
	$('#specWindow .elemtxt').bind('dblclick', function(){
		var value = parseInt($(this).attr('id'));
								
		$('#spec').val(value);

		$('#specWindow').css('display', 'none');
	});
	
	$('#other_spec').unbind('click');
	$('#other_spec').click(function(){
		$('#specWindow').css('display', 'none');
		$('#spec').val('');
		showWindow('#new_spec', false);
		return false;
	});
	
	$('#other_sfera').unbind('click');
	$('#other_sfera').click(function(){
		$('#specWindow').css('display', 'none');
		$('#spec').val('');
		$('#spec2').val('');
		$('#spec3').val('');
		showWindow('#new_sfera', false);
		return false;
	});
	
	
	//$('.other_spec2').parent().unbind('change');
	//$('.other_sfera2').parent().unbind('change');
	$('#spec').unbind('click');
	$('#spec2').unbind('click');
	$('#spec3').unbind('click');
	
	
	$('#spec').change(function(){
		$('#new_spec_rec').text('');
		$('#new_sfera_rec').text('');
		if($(this).find('.other_spec2').attr('selected')){
			$('#specWindow').css('display', 'none');
			showWindow('#new_spec', false);
			return false;
		}else{
			if($(this).find('.other_sfera2').attr('selected')){
				$('#specWindow').css('display', 'none');
				showWindow('#new_sfera', false);
			}
		}
	});
	
	$('#spec2').change(function(){
		if($(this).find('.other_spec2').attr('selected')){
			$('#new_spec_rec').text('Сообщите о профессии специалиста в Тексте рекомендации.');
			$('#new_spec input[type=submit]').unbind('click');
			$('#new_spec input[type=submit]').click(function(){		
				if($('#new_spec input[type=text]').val()!=""){
					$('#new_spec').css('display', 'none');
					$.post('/modules/new_spec_ajax.php', {name:$('#new_spec input[type=text]').val(), add_spec: true}, function(data){
						if(data==""){
							alert('Ваш запрос был отправлен!');
						}else{
							alert(data);
						}
					});
					
					$('#new_spec input[type=submit]').unbind('click');
				}else{
					alert('Не указано название специальности');
				}
				return false;
			});
			showWindow('#new_spec', false);
			return false;
		}
	});
	
	
	$('#spec3').change(function(){
		if($(this).find('.other_sfera2').attr('selected')){
			$('#new_spec_rec').text('Сообщите о специализации заведения в Тексте рекомендации.');
			$('#new_spec input[type=submit]').unbind('click');
			$('#new_spec input[type=submit]').click(function(){		
				if($('#new_spec input[type=text]').val()!=""){
					$('#new_spec').css('display', 'none');
					$.post('/modules/new_spec_ajax.php', {name:$('#new_spec input[type=text]').val(), add_spec: true}, function(data){
						if(data==""){
							alert('Ваш запрос был отправлен!');
						}else{
							alert(data);
						}
					});
					$('#new_spec input[type=submit]').unbind('click');
				}else{
					alert('Не указано название специальности');
				}
				return false;
			});
			showWindow('#new_spec', false);
			return false;
		}
	});
	
	$('#spec4').change(function(){
		$('#new_spec_rec').text('');
		$('#new_sfera_rec').text('');
		if($(this).find('.other_sfera2').attr('selected')){
			$('#new_spec input[type=submit]').unbind('click');
			$('#new_spec input[type=submit]').click(function(){		
				if($('#new_spec input[type=text]').val()!=""){
					$('#new_spec').css('display', 'none');
					$.post('/modules/new_spec_ajax.php', {name:$('#new_spec input[type=text]').val(), add_spec: true}, function(data){
						if(data==""){
							alert('Ваш запрос был отправлен!');
						}else{
							alert(data);
						}
					});
					$('#new_spec input[type=submit]').unbind('click');
				}else{
					alert('Не указано название специальности');
				}
				return false;
			});
			showWindow('#new_spec', false);
			return false;
		}else{
			if($(this).find('.other_sfera2').attr('selected')){
				$('#new_sfera input[type=submit]').unbind('click');
				$('#new_sfera input[type=submit]').click(function(){
					if($('#new_sfera input[type=text]').val()!=""){
						$('#new_sfera').css('display', 'none');
						$.post('/modules/new_spec_ajax.php', {name:$('#new_sfera input[type=text]').val(), add_sfera: true}, function(data){
							if(data==""){
								alert('Ваш запрос был отправлен!');
							}else{
								alert(data);
							}
						});
						$('#new_sfera input[type=submit]').unbind('click');
					}else{
						alert('Не указано название специализации');
					}
					return false;
				});
				showWindow('#new_sfera', false);
				return false;
			}
		}
	});
	
	$('#town').unbind('click');
	$('#town2').unbind('click');
	$('#town3').unbind('click');

	$('#town').change(function(){
		if($(this).val() == ''){
			$('#townWindow').css('display', 'none');
			$('#town').val('');
			
			$("#townsWindow").css('display', 'none');
			showWindow('#new_town', false);

			return false;
		}
	});
	
	$('#town2').change(function(){
		if($(this).find('.other_town').attr('selected')){
			$('#townWindow').css('display', 'none');
			
			$('#new_town input[type=submit]').unbind('click');
			$('#new_town_rec').text(' Сообщите о месте проживания специалиста в Тексте рекомендации.');
			
			$('#new_town .abort').unbind('click');
			$('#new_town .abort').click(function(){
				$('#new_town_rec').text('');
			});
			
			$('#new_town input[type=submit]').click(function(){
				if($('#new_town input[type=text]').val()!=""){
					$('#new_town').css('display', 'none');
					$('#new_town_rec').text('');
					$.post('/modules/new_spec_ajax.php', {name:$('#new_town input[type=text]').val(), add_town: true}, function(data){
						if(data==""){
							alert('Ваш запрос был отправлен!');
						}else{
							alert(data);
						}
					});
					$("#town2").val('');
					$('#new_town input[type=submit]').unbind('click');
				}else{
					alert('Не указано название населенного пункта');
				}
				return false;
			});
			
			$("#townsWindow").css('display', 'none');
			showWindow('#new_town', false);
	
			return false;
		}
	});
	
	$('#town3').change(function(){
		if($(this).find('.other_town').attr('selected')){
			$('#townWindow').css('display', 'none');
			$('#town').val('');
			$('#new_town input[type=submit]').unbind('click');
			$('#new_town_rec').text(' Сообщите о месте нахождения заведения в Тексте рекомендации.');
			
			$('#new_town .abort').unbind('click');
			$('#new_town .abort').click(function(){
				$('#new_town_rec').text('');
			});
			
			$('#new_town input[type=submit]').click(function(){
				if($('#new_town input[type=text]').val()!=""){
					$('#new_town').css('display', 'none');
					$('#new_town_rec').text('');
					$('#new_town_rec').text('');
					$.post('/modules/new_spec_ajax.php', {name:$('#new_town input[type=text]').val(), add_town: true}, function(data){
						if(data==""){
							alert('Ваш запрос был отправлен!');
						}else{
							alert(data);
						}
					});
					$("#town3").val('');
					$('#new_town input[type=submit]').unbind('click');
				}else{
					alert('Не указано название населенного пункта');
				}
				return false;
			});
			
			$("#townsWindow").css('display', 'none');
			showWindow('#new_town', false);
	
			return false;
		}
	});
}