jQuery(document).ready(function(){
	
	/*block comments start*/
	
	var hash = window.location.hash;
	if(hash)
	{
		jQuery('.otzyvinn .oneotz').slideDown(200);
		jQuery('.otzyvinn .allotz').hide();
		jQuery('.otzyvinn .hideotz').show();
	
	}
	
	//show all comments
	jQuery('a.show-all-comments').click(function(){
		
		jQuery('.otzyvinn .oneotz .allotz, .otzyvinn .oneotz .childs .close, .otzyvinn .oneotz .child-comments').hide();
		
		jQuery('.otzyvinn .oneotz').slideDown(200);
		
		jQuery('.otzyvinn .hideotz').show();
		
		
		
		
		return anchorScroller(this);
	});
	
	//hide all comments
	jQuery('a.hide-all-comments').click(function(){
		
		jQuery('.otzyvinn .oneotz .allotz').show();
		
		jQuery('.otzyvinn .hide-comments').slideUp(200);
		
		jQuery(' .otzyvinn .oneotz .child-comments').hide();
		
		jQuery('.otzyvinn .hideotz').hide();
		
		return anchorScroller(this);
	});
	
	
	//show child-comments
	jQuery('.childs .open').click(function(){
		jQuery(this).closest('.oneotz').find('.child-comments').slideDown(200);
		jQuery(this).hide();
		jQuery(this).next('.close').show();
		
		return false;
	});
	
	//hide child-comments
	jQuery('.childs .close').click(function(){
		jQuery(this).closest('.oneotz').find('.child-comments').slideUp(200);
		jQuery(this).hide();
		jQuery(this).prev('.open').show();
		
		return false;
	});
	
	
	//open comment form
	jQuery('.open-form').click(function(){
	
		var idArr = jQuery(this).attr('id').split('-');
			
			
			
			jQuery('input[name=parent]').val(idArr[1]);
			
			if(idArr[1]!=0)
			{
				name = jQuery(this).closest('div').find('.parent_name').html();
				date = jQuery(this).closest('div').find('.parent_date').html();
				
				jQuery('.comment-form .content').prepend('<div class="label-form"><h1>Ответить на сообщение</h1></div>');
			}
			else
			{
				jQuery('.comment-form .content').prepend('<h1>Оставьте свой отзыв!</h1>');
			}
						
			jQuery('.comment-form').show();
		return false;
	});
	
	
	//close comment form
	jQuery('.comment-form .right_button').click(function(){
			
		jQuery('.comment-form').hide();
		jQuery('.comment-form .content h1, .comment-form .content .label-form').remove();
		jQuery('p.errors').empty();
		jQuery('#required_err').empty();
		jQuery('.comment-form .content td').css('color', 'black');
		jQuery('.comment-form .content td input, .comment-form .content td textarea').css('border-color', 'black');
		
		return false;
	});
	
	//send form
	jQuery('#save').click(function(){
		return validate();
		
	});
	
	//if the server returned negative results - start validation
	if(!jQuery('.comment-form:hidden'))
	{
		validate();
	}
	
	

	
	/*block comments end*/
	
	
	//close message form
	jQuery(".message .right img").click(function(){
		jQuery(".message").hide();
		return false;
	});
});


function validate()
{
	return	jQuery('.comment-form').checkform(
			{
				rules: {
					name : {
						required : {value : true, message : ''},		
					},	
					comment : {
						required : {value : true, message : ''},		
					},			
					captcha_response : {
						required : {value : true, message : ''},
					}
					
				},
				viewErrors : {
						required: {
							color: 'red',
							message: 'Заполните все обязательные поля',
							block: '#required_err'
						}
						
					}
			}
		).validate();
}


