
$(document).ready(function(){

	$(".mitemtitle a").click(function() {

		$('#fp50').attr('value',$(this).attr('href'));

		$(".menuitem").removeClass("active");

		$(this).parent().parent().addClass("active");

		return false;

	});


	$(".locationmenu a").click(function() {

		$('#fp2').attr('value',$(this).attr('href'));

		$(".locationmenu div").removeClass("active");

		$(this).parent().addClass("active");

		return false;

	});




/*
	$(".postformnewbutton").click(function() {

	alert(1);


//		alert(document.getElementById())

//		if ($(".postformnew .required1").attr('value')=="") {
//				alert("Для отправки заявки необходимо придумать заголовок");
//				return false;
//			};
			
//		if ($(".postformnew .required2").attr('value')=="") {
//				alert("Для отправки заявки необходимо выбрать фотографию, подходящую формату заявки");
//				return false;
//			}

		$(".postformnew").submit();

		return false;
	});
*/

	$(".postsavebutton").click(function() {
		if ($(".postformedit .required1").attr('value')=="") {
				alert("Заявка должна содержать заголовок");
				return false;
			};

		$(".postformedit").submit();

		return false;
	});


	$(".postpublicbutton").click(function() {
		if ($(".postformedit .required1").attr('value')=="") {
				alert("Заявка должна содержать заголовок");
				return false;
			};

		$("#public").attr('value',"1");	
		$(".postformedit").submit();

		return false;
	});


	$(".postpicaline .back").click(function() {

		postpicacurrent--;
		
		if (postpicacurrent==0) postpicacurrent=5;

		set_post_photo_text(postpicacurrent);

		return false;
	});

	$(".postpicaline .next").click(function() {

		postpicacurrent++;
		
		if (postpicacurrent==6) postpicacurrent=1;

		set_post_photo_text(postpicacurrent);

		return false;
	});

});





function set_post_photo_text(n)
{
 switch(n)
  { 
   case(1): if ($(".pic1").html()=="") htmlStr="Загрузить основную фотографию"; else htmlStr="Изменить основную фотографию"; break;
   case(2): if ($(".pic2").html()=="") htmlStr="Загрузить вторую фотографию"; else htmlStr="Изменить вторую фотографию"; break;
   case(3): if ($(".pic3").html()=="") htmlStr="Загрузить третью фотографию"; else htmlStr="Изменить третью фотографию"; break;
   case(4): if ($(".pic4").html()=="") htmlStr="Загрузить четвертую фотографию"; else htmlStr="Изменить четвертую фотографию"; break;
   case(5): if ($(".pic5").html()=="") htmlStr="Загрузить пятую фотографию"; else htmlStr="Изменить пятую фотографию"; break;
  }

 $(".postpicaline .pic").removeClass("active");

 $(".postpicaline .pic"+postpicacurrent).addClass("active");

 $("#pictitle").text(htmlStr); 

 $("#photonum").attr("value",postpicacurrent); 
 

}
