	$(document).ready(function(){
		$('.maxlength2000').bind('keydown', function(){
			var val = $(this).val();
			if(val.length>2000){
				$(this).val(val.substring(0,2000));
			}
		});
		
		
		
		function asd(){

			function blink(){
				if($('.blink').css('color') == 'rgb(153, 102, 51)'){
					$('.blink').css('color', '#669966');
				}else{
					$('.blink').css('color', '#996633');
				}

				//alert($('.blink').css('color'));
				setTimeout(blink, 1000);
			}

			function blink2(){
				if($('.blink2').css('color') == 'rgb(0, 0, 0)'){
					$('.blink2').css('color', '#669966');
				}else{
					$('.blink2').css('color', '#000000');
				}

				//alert($('.blink').css('color'));
				setTimeout(blink2, 1000);
			}

			blink();
			blink2();

			bindTreeClick();
			
			$('#country').change(function(){
				$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country').val());
				$('#town').html('<img src="/img/loader.gif"/>');
				$('#town').load('/modules/constract_towns.php?c='+$(this).val(), function(){
					bindTreeClick();
				});
			});
			
			$('#country2').change(function(){
				$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country').val());
				$('#town2').html('<img src="/img/loader.gif"/>');
				$('#town2').load('/modules/constract_towns.php?c='+$(this).val(), function(){
					bindTreeClick();
				});
			});

			$('#country3').change(function(){
				$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country').val());
				$('#town3').html('<img src="/img/loader.gif"/>');
				$('#town3').load('/modules/constract_towns.php?c='+$(this).val(), function(){
					bindTreeClick();
				});
			});

			$('#country5').change(function(){
				$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country').val());
				$('#town5').html('<img src="/img/loader.gif"/>');
				$('#town5').load('/modules/constract_towns.php?c='+$(this).val(), function(){
					bindTreeClick();
				});
			});
		}

		bindTreeClick();

		$('#search_spec').click(function(){
			$('#specUl').css('display', 'block');
			//$('#spec').css('display', 'none');
			$('#sort_type').html('<option value="1">отзывам посетителей</option><option value="2">мнению специалистов</option>');
			$('#caption').html('Сфера деятельности');
			
			$('#spec').html('<img src="/img/loader.gif"/>');
			$('#specUl').html('<img src="/img/loader.gif"/>');
			$('#specWindow .spisok').css('display', 'none');
			$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=1', function(){
				addTreeEventListeners('.dTree');
				bindTreeClick();
				$('#specWindow .spisok').css('display', 'block');
			});
			$('#spec').load('/modules/constract_sf.php?c=1', function(){
				addTreeEventListeners('.dTree');
				bindTreeClick();
				$('#specWindow .spisok').css('display', 'block');
				if($('#search_spec').hasClass('inSearch')){
					$('#specUl').load('/modules/constract_ul_sf.php?c=1', function(){
						bindSpecUl();
					});
				}
			});
			$('#newSearchForm').submit();
		});

		$('#search_org').click(function(){
			//$('#specUl').css('display', 'none');
			//$('#spec').css('display', 'block');
			$('#sort_type').html('<option value="1">отзывам посетителей</option>');
			$('#caption').html('Специализация');
			
			$('#spec').html('<img src="/img/loader.gif"/>');
			$('#specUl').html('<img src="/img/loader.gif"/>');
			$('#specWindow .spisok').css('display', 'none');
			$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=2', function(){
				addTreeEventListeners('.dTree');
				bindTreeClick();
				$('#specWindow .spisok').css('display', 'block');
			});
			$('#spec').load('/modules/constract_sf.php?c=2', function(){
				addTreeEventListeners('.dTree');
				bindTreeClick();
				$('#specWindow .spisok').css('display', 'block');
				if($('#search_org').hasClass('inSearch')){
					$('#specUl').load('/modules/constract_ul_sf.php?c=2', function(){
						bindSpecUl();
					});
				}
			});
			$('#newSearchForm').submit();
		});


		function textareaLimit(){
			var val = $(this).val();
			if(val.length>400){
				$(this).val(val.substring(0,400));
			}
		}

		$('#opinion_ask').focus(function(){
			$(this).unbind('keyup');
			$(this).bind('keyup', textareaLimit);
		});

		$('#consalt_ask').focus(function(){
			$(this).unbind('keyup');
			$(this).bind('keyup', textareaLimit);
		});

		$('.consalt_answer').focus(function(){
			$(this).unbind('keyup');
			$(this).bind('keyup', textareaLimit);
		});
		
		setTimeout(asd, 1);
	});