function preview(what, where)
{
 alert('test');
	$("#preview").attr("src", what);
	$("#link").attr("href", where);
	alert("Param1: "+what+" Param2: "+where);
}
function changePic(what, where){
         //alert(what + " FUCK YOU! " + where);
         $("#preview").hide().fadeIn(1000).attr("src", what);
         $("#link").attr("href", where);
}
$(document).ready(
		function()
		{
		 
			$(".chose a").click(function(){return false;});
			$(".chose p:eq(0)").click(function(){
				$(".chose p:eq(1)").css("background", "url(templates/images/button2-bl-search.png)");
				$(".chose p:eq(2)").css("background", "url(templates/images/button3-bl-search.png)");
				$(this).css("background", "url(templates/images/button1-bl-search-hover.png)");
        $("form input[name*=action][type=hidden]").val("3");
			});
			$(".chose p:eq(1)").click(function(){
				$(".chose p:eq(0)").css("background", "url(templates/images/button1-bl-search.png)");
				$(".chose p:eq(2)").css("background", "url(templates/images/button3-bl-search.png)");
				$(this).css("background", "url(templates/images/button2-bl-search-hover.png)");
				$("form input[name*=action][type=hidden]").val("1");
			});
			$(".chose p:eq(2)").click(function(){
				$(".chose p:eq(0)").css("background", "url(templates/images/button1-bl-search.png)");
				$(".chose p:eq(1)").css("background", "url(templates/images/button2-bl-search.png)");
				$(this).css("background", "url(templates/images/button3-bl-search-hover.png)");
				$("form input[name*=action][type=hidden]").val("2");
			});
			//Календарик
			$.datepicker.setDefaults(
				$.extend($.datepicker.regional["ru"])
			);
			$("#datepicker").datepicker({
				changeYear: true,
				changeMonth: true	
			});
			
			if($("#newPage").length > 0)
			{
				 $("#error").hide();
				 $("input[type=button]").click(function(){
						var display = 0;
						var error = 'Вы не заполнили следующие поля:\n';
						if(tinyMCE.activeEditor.getContent().length==0)
						{
							display = 1;
							error = error + 'Текст страницы\n';
						}
						if(!$('input[name*=title]').val())
						{
							display = 1;
							error = error + 'Заголовок страницы';
						}
						if(display)
						{
							$("#error").text(error).show(300);
						}
						else
						{
							$("#error").hide(300);
							$("#newPage").submit();
						}
					});
			}
			if($("#newBuilding").length > 0)
			{
				$(".header").css("text-align", "center").css("border-bottom", "1px solid black").css("padding", "0px");
				$("#error").hide();
				$("#newBuilding form").attr("action", "?act=newBuilding");
				$("input[type=button]").click(function(){
						var display = 0;
						var error = 'Вы не заполнили следующие поля:<ul>\n';
						if(!$('input[name*=title]').val())
						{
							display = 1;
							error = error + '<li>Заголовок</li>\n';
						}
						/*if(!$('textarea').val())
						{
							display = 1;
							error = error + '<li>Описание</li>\n';
						}
						if(!$('input[name*=price]').val())
						{
							display = 1;
							error = error + '<li>Цена</li>\n';
						}*/
						error += "</ul>";
						if(display)
						{
							$("#error").html(error).show(300);
						}
						else
						{
							$("#error").hide(300);
							$("#newBuilding").submit();
						}
						/*$.post("?act=test", { 
							title: $('input[name*=title]').val(),
							price: $('input[name*=price]').val(),
							desc: $('textarea').val(),
							action: $('input[name*=action]:checked').val(),
							situation: $('select[name*=situation] option:selected').val(),
						},
					   function(data){
					     $("#error").text(data).show();
					   });*/
					});
				/* $("input[type=submit]").click(function(){
						var display = 0;
						var error = 'Вы не заполнили следующие поля:<ul>\n';
						if(!$('input[name*=title]').val())
						{
							display = 1;
							error = error + '<li>Заголовок</li>\n';
						}
						if(!$('textarea').val())
						{
							display = 1;
							error = error + '<li>Описание</li>\n';
						}
						if(!$('input[name*=price]').val())
						{
							display = 1;
							error = error + '<li>Цена</li>\n';
						}
						error += "</ul>";
						if(display)
						{
							$("#error").html(error).show(300);
							$("form").submit(function(){return false;});
						}
						else
						{
							
							$("#error").hide(300);
							$("form").submit();
							
						}
						/*$.post("?act=test", { 
							title: $('input[name*=title]').val(),
							price: $('input[name*=price]').val(),
							desc: $('textarea').val(),
							action: $('input[name*=action]:checked').val(),
							situation: $('select[name*=situation] option:selected').val(),
						},
					   function(data){
					     $("#error").text(data).show();
					   });
					});*/
			}
			if($("#table").length > 0)
			{
				$("#table tr:even").css('background', "#ECE9E9");
				$("#table td").css("padding", "5px");
			}
			if($("#question").length > 0)
			{
				$("#error").hide();
				$("input[type=button]").click(function(){
					var display = 0;
					var error;
					if(!$('textarea').val())
					{
						display = 1;
						error = 'Вы не можете отправить пустой запрос\n';
					}
					if(display)
					{
						$("#error").html(error).show(300);
					}
					else
					{
						$("form").submit();
						$("#error").hide(300);
						
						
					}
				});
			}
			if($("#newSubTopic").length > 0)
			{
				$("#error").hide();
				$("input[type=button]").click(function(){
					var display = 0;
					var error;
					if(!$('#newSubTopic > input').val())
					{
						display = 1;
						error = 'Вы не можете создать пустой раздел\n';
					}
					if(display)
					{
						$("#error").html(error).show(300);
					}
					else
					{
						
						$("#error").hide(300);
						$("#newSubTopic").submit();
					}
				});
			}
			if($("#newTopic").length > 0)
			{
				$("#error").hide();
				$("input[type=button]").click(function(){
					var display = 0;
					var error;
					if(!$('#newTopic input[name*=name]').val())
					{
						display = 1;
						error = 'Вы не заполнили название темы!\n';
					}
					if(!$('#newTopic textarea[name*=msg]').val())
					{
						display = 1;
						error = 'Вы не заполнили описание темы!\n';
					}
					if(display)
					{
						$("#error").html(error).show(300);
					}
					else
					{
						
						$("#error").hide(300);
						$("#newTopic").submit();
					}
				});
			}
			if($("#newMsg").length > 0)
			{
				$("#error").hide();
				$("input[type=button]").click(function(){
					var display = 0;
					var error;
					if(!$('#newMsg input').val())
					{
						display = 1;
						error = 'Вы не можете отправить пустое сообщение!\n';
					}
					if(display)
					{
						$("#error").html(error).show(300);
					}
					else
					{
						
						$("#error").hide(300);
						$("#newMsg").submit();
					}
				});
			}
			if($("#feedback").length > 0)
			{
				$("#error").hide();
				$("input[type=button]").click(function(){
					var display = 0;
					var error = "";
					if(!$("#feedback input[name*=name]").val())
					{
						display = 1;
						error += 'Вы не указали имя!<br>\n';
					}
					if(!$("#feedback input[name*=email]").val())
					{
						display = 1;
						error += 'Вы не указали email!<br>\n';
					}
					if(!$("#feedback input[name*=topic]").val())
					{
						display = 1;
						error += 'Вы не указали тему сообщения!<br>\n';
					}
					if(!$("#feedback textarea[name*=msg]").val())
					{
						display = 1;
						error += 'Вы не можете отправить пустое сообщение!<br>\n';
					}
					if(!$("#feedback input[name*=captcha]").val())
					{
						display = 1;
						error += 'Вы не указали защитный код!<br>\n';
					}
					
					if(display)
					{
						$("#error").html(error).show(300);
					}
					else
					{
						
						$("#error").hide(300);
						$("#feedback").submit();
					}
				});
			}
			if($(".info-block").length > 0)
			{
				$(".info-block").hide();
				setTimeout(function(){$(".info-block").show();}, 500);
				setTimeout(function(){$(".info-block").hide()}, 5000);
			}
			//Удаляем лишнюю черту в главном меню
			$("#top-menu li:first").css("border-left", "none");
			//Удаляем лишнюю черту в меню риэлторов
			$("#companies div:last").css("border-bottom", "none");
			//Для формы аутентификации
			if($("#login input").length > 0)
			{
				$("#login input:eq(0)").focus(function(){
					if($("#login input:eq(0)").val()=="Логин")$("#login input:eq(0)").val("");
				});
				$("#login input:eq(1)").focus(function(){
					if($("#login input:eq(1)").val()=="Пароль")$("#login input:eq(1)").after("<input type=\"password\" class='text' name='pass'>").remove();
					$("#login input:eq(1)").focus();
				});
			}
			//Для быстрого поиска
			if($("#quick-search").length > 0)
			{
				$("#quick-search input[type=button]").click(function()
				{
					
					if($("#quick-search input:eq(0)").val()=="от")$("#quick-search input:eq(0)").val("");
					if($("#quick-search input:eq(1)").val()=="до")$("#quick-search input:eq(1)").val("");
					$("#quick-search form").submit();
				});
			}
		}
);

