			$(document).ready(function(){

		    	$('#reg').transformToWindow({width: 810, height: 580, title: 'Регистрация'});
		    	$('#pravila').transformToWindow({width: 410, height: 550, title: 'Пользовательское соглашение'});
		    	$('#parol').transformToWindow({width: 410, height: 230, title: 'Восстановление пароля'});
		    	$('#pay').transformToWindow({width: 410, height: 530, title: 'Платное размещение'});
		    	$('#townsWindow').transformToWindow({width: 256, height: 381, title: 'Выбор города'});
		    	$('#specWindow').transformToWindow({width: 256, height: 381, title: 'Выбор специализации'});
		    	$('#mes').transformToWindow({width: 410, height: 480, title: 'Сообщение'});
		    	$('#reccomend_spec_window').transformToWindow({width: 790, height: 550, title: 'Рекомендовать специалиста'});
		    	$('#reccomend_org_window').transformToWindow({width: 790, height: 550, title: 'Рекомендовать заведение'});
		    	$('#chose_reccomend').transformToWindow({width: 340, height: 220, title: 'Вы рекомендуете'});
		    	$('#info').transformToWindow({width: 795, height: 660, title: 'Редактирование личных данных'});
		    	$('#new_spec').transformToWindow({width: 410, height: 230, title: 'Добавление новой специальности'});
		    	$('#new_sfera').transformToWindow({width: 410, height: 230, title: 'Добавление новой специализации'});
		    	$('#new_town').transformToWindow({width: 410, height: 230, title: 'Добавление нового города'});
		    	
		    	
		    	$('#show_pravila').click(function(){
		    		showWindow('#pravila', false);
					return false;
			    });

			    $('#simple_info').click(function(){
			    	showWindow('#user_info', false);
					return false;
				});

		    	$('#show_pravila2').click(function(){
		    		showWindow('#pravila', false);
					return false;
			    });

		    	$('#show_parol').click(function(){
		    		showWindow('#parol', false);
					return false;
			    });
		    	
		    	
		    	$('#showSpec').click(function(){
		    		$('#new_spec_rec').text('');
		    		$('#new_sfera_rec').text('');
			    	
			    	if($('#search_org').attr('checked')){
						$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=2', function(){
							addTreeEventListeners('.dTree');
							bindTreeClick();
						});
			    	}else{
			    		$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=1', function(){
			    			addTreeEventListeners('.dTree');
			    			bindTreeClick();
				    	});
					}
					showWindow('#specWindow', false);
					return false;
				});

		    	$('#showSpec2').click(function(){
			    	$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=1', function(){
			    		addTreeEventListeners('.dTree');
			    		bindTreeClick();
			    		$('#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('#specWindow', false);
					return false;
				});

		    	$('#showSpec3').click(function(){
			    	$('#specWindow .spisok').load('/modules/constract_w_sf.php?c=2', function(){
			    		addTreeEventListeners('.dTree');
			    		bindTreeClick();
			    		$('#new_sfera_rec').text('Сообщите о специализации заведения в Тексте рекомендации.');
			    		$('#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('#specWindow', false);
					return false;
				});
		    	
		    	
				$('#showTowns').click(function(){
					$('#new_town_rec').text('');
					$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country').val(), function(){
						$('#town4').change(function(){
							if($(this).find('.other_town').attr('selected')){
								$('#townsWindow').css('display', 'none');
								$('#town').val('');
								$('#new_town input[type=submit]').unbind('click');
								$('#new_town input[type=submit]').click(function(){
									if($('#new_town input[type=text]').val()!=""){
										$('#new_town').css('display', 'none');
										$.post('/modules/new_spec_ajax.php', {name:$('#new_town input[type=text]').val(), add_town: true}, function(data){
											if(data==""){
												alert('Ваш запрос был отправлен!');
											}else{
												alert(data);
											}
										});
										$('#new_town input[type=submit]').unbind('click');
									}else{
										alert('Не указано название населенного пункта');
									}
									return false;
								});
								showWindow('#new_town', false);
							}						
							
							//alert(1);

							return false;
						});
					});
					showWindow('#townsWindow', false);
					return false;
				});

				$('#showTowns2').click(function(){
					$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country2').val(), function(){
						$('#town4').change(function(){
							if($(this).find('.other_town').attr('selected')){
								$('#townWindow').css('display', 'none');
								$('#new_town input[type=submit]').unbind('click');
								$('#new_town input[type=submit]').click(function(){
									if($('#new_town input[type=text]').val()!=""){
										$('#new_town').css('display', 'none');
										$.post('/modules/new_spec_ajax.php', {name:$('#new_town input[type=text]').val(), add_town: true}, function(data){
											if(data==""){
												alert('Ваш запрос был отправлен!');
											}else{
												alert(data);
											}
										});
										$('#new_town_rec').text('');
										$("#town2").val('');
										$('#new_town input[type=submit]').unbind('click');
									}else{
										alert('Не указано название населенного пункта');
									}
									return false;
								});

								$('#new_town .abort').unbind('click');
								$('#new_town .abort').click(function(){
									$('#new_town_rec').text('');
								});

								$('#new_town_rec').text(' Сообщите о месте проживания специалиста в Тексте рекомендации.');

								$("#townsWindow").css('display', 'none');
								showWindow('#new_town', false);
							}						
							
							//alert(1);

							return false;
						});
					});
					showWindow('#townsWindow', false);
					return false;
				});

				$('#showTowns3').click(function(){
					$('#townsWindow select').load('/modules/constract_towns.php?c='+$('#country3').val(), function(){
						$('#town4').change(function(){
							if($(this).find('.other_town').attr('selected')){
								$('#townWindow').css('display', 'none');
								$('#town').val('');
								$('#new_town input[type=submit]').unbind('click');
								$('#new_town input[type=submit]').click(function(){
									if($('#new_town input[type=text]').val()!=""){
										$('#new_town').css('display', 'none');
										$.post('/modules/new_spec_ajax.php', {name:$('#new_town input[type=text]').val(), add_town: true}, function(data){
											if(data==""){
												alert('Ваш запрос был отправлен!');
											}else{
												alert(data);
											}
										});
										$('#new_town_rec').text('');
										$("#town3").val('');
										$('#new_town input[type=submit]').unbind('click');
									}else{
										alert('Не указано название населенного пункта');
									}
									return false;
								});

								$('#new_town .abort').unbind('click');
								$('#new_town .abort').click(function(){
									$('#new_town_rec').text('');
								});

								$('#new_town_rec').text('Сообщите о месте нахождения заведения в Тексте рекомендации.');


								$("#townsWindow").css('display', 'none');
								showWindow('#new_town', false);
							}						
							
							//alert(1);

							return false;
						});
					});
					showWindow('#townsWindow', false);
					return false;
				});

				$('#townsWindow select').bind('dblclick', function(){
					$('#town').val($(this).val());
					$('#town2').val($(this).val());
					$('#town3').val($(this).val());
					$('#townsWindow').css('display', 'none');
				});

				$('.write_mes').click(function(){
					$('#to_mess').val(parseInt($(this).attr('id')));
					showWindow('#mes', false);
					return false;
				});
		    	
		    	$('#reg_linck').click(function(){
		    		showWindow('#reg', false);
		    		return false;
			    });

		    	$('#showPay').click(function(){
		    		showWindow('#pay', false);
		    		return false;
			    });

		    	$('#showPay2').click(function(){
		    		showWindow('#pay', false);
		    		return false;
			    });

		    	$('#reccomend').click(function(){
		    		showWindow('#chose_reccomend', false);
		    		return false;
			    });

		    	$('#reccomend_g').click(function(){
		    		showWindow('#chose_reccomend', false);
		    		return false;
			    });

			   // function asd(){
			    	$('.do_reccomend_spec').click(function(){
			    		$('#chose_reccomend').css('display', 'none');
			    		showWindow('#reccomend_spec_window', false);
			    		return false;
				    });

			    	$('.do_reccomend_org').click(function(){
			    		$('#chose_reccomend').css('display', 'none');
			    		showWindow('#reccomend_org_window', false);
			    		return false;
				    });
				//}

				//setTimeout(asd, 1000);
			    
			    if($('#pravila').length == 1){
			    	$('#pravila div#pravilaContent').load('/modules/pravila.php');
			    }		    	
		    	
			});