$(document).ready(function(){
	$("#header_menu li").click(function() {
		location.href=$(this).children("a").attr("href");
	});	
});

function submitComment(typeID, itemID) {
	var textBody = $("#message").val();
	if(textBody == "") {
		alert("Введите текст комментария");
		return false;
	}
	if(textBody.length < 5) {
		alert("Текст комментария слишком короткий");
		return false;
	}
	$("#comment_status").html('<img width="16" height="16" src="/images/ajax/submit_16_cir_black.gif" align="absmiddle" alt="" title="Идет загрузка">');
	$("#comment_submit").attr("disabled","disabled");

  $.ajax({
    url: "/dyn/iSubmitComment.php",
    type: "POST",
    data: ({type : typeID, item : itemID, text: textBody}),
    success: 
   	function(msg){
    	$("#comment_status").html(msg);
    	$("#comment_status").delay(5000).animate({
		    opacity: 0
		  }, {
    			duration: 1500, 
    			complete: function() {
    				$("#comment_status").html("");
			      $("#comment_status").animate({
					    opacity: 1
					  }, 500);
			    }
		  	 }
			);
			$("#message").val("");
		  $("#comment_submit").delay(6000).attr("disabled","");
		  $("#comment_form").delay(5000).slideUp(750);
    	getComments(typeID, itemID);
    },
  	dataType: "html"
  });
  return false;
}

function getComments(typeID, itemID, page) {
	var page = page || 0;
	$("#commentsRow").animate({
	    opacity: 0.25
	  }, 1000);		  
	$.ajax({
    url: "/dyn/iGetComments.php",
    type: "POST",
    data: ({type : typeID, item : itemID, p : page}),
    success: function(msg) {    	
  		$("#commentsRow").html(msg);
    	$("#commentsRow").animate({
		    opacity: 1
		  }, 1000);
		},
  	dataType: "html"
  });
  return false;
}

function countSymb(lim) {
	var lim = lim || 500;
	if ($("#message").val().length > lim) {
		alert("К сожалению, вы превысили максимально допустимую длину комментария");
		document.getElementById("message").value = document.getElementById("message").value.substring(0,lim);
		return false;
	}
	if ($("#message").val().length > (lim - 50)) {
		document.getElementById("count").style.color = "red";
	}
	if ($("#message").val().length < (lim - 50)) {
		document.getElementById("count").style.color = "green";
	}
	document.getElementById("count").innerHTML = document.getElementById("message").value.length;
}
