$(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");
		
	}	
}		

function vote(){
						
	var params = jQuery('#pollForm').serialize();				 				            		  					  	 
	
	jQuery("#voteresult" ).ajaxStart(function() {				
			jQuery(this).hide();	
		}
	).ajaxStop(function() {
			jQuery(this).animate({opacity: "show"}, 500);	
		}
	);
	
	jQuery.ajax({
	  	data: params,
		type: "POST",
		url: '/back/vote',
		timeout: 2000,			
		error: function(xhr, desc, e) {
			alert("Ошибка при добавлении: " + desc);
		},			
		success: function(data) {
				
			jQuery("#voteresult" ).html(data);	 	
			
		}	
	});	
	
	
}
