$(document).ready(function(){

    /* отправка комментария */
	$("#commentform").submit(function() {
		var params = $(this).serialize();	
				 				
	 	jQuery.ajax({			
		  	data: params,
			type: "POST",
			url: '/back/comment',
			timeout: 10000,			
			error: function(xhr, desc, e) {
				$("#error").html("Ошибка, повтори свою попытку");
				reloadCaptcha();						
			},			
			success: function(response) {
				$(".error").hide();
				$(response).insertBefore("#result");
				reloadCaptcha();																											
			}	
		});	
		
		return false;
	});

})

/* чистим форму комментариев */
function clearCommentForm(){
	var form = $("#commentform");
	
 	$(':input', form).each(function() {
    var type = this.type;
    var tag = this.tagName.toLowerCase(); 
    
    if (type == 'text' || tag == 'textarea')
    	this.value = "";
    
  });
  	
}

/* обновляем капчу */
function reloadCaptcha(){
	
	$("#captchaImg").attr("src","/captcha/"+Math.round(Math.random()*1000));
	$(".captchaText").attr("value","");
	
	return true;
}

/* разворачивающиеся блоки */
function toggleBlock(block){
	if ($("#"+block).css("display") == 'block'){	
		//сворачиваем				
		$("#"+block).slideUp("slow");
	}else{										
		$("#"+block).slideDown("slow");
		
	}	
}		
