<?php

function ya_comment($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?>
  	<div id="comment-<?php comment_ID(); ?>" <?php comment_class('media btn'); ?>>
  		<div class="author">
			<a class="pull-left" href="<?php echo get_comment_author_link(get_comment_ID())?>"><?php echo get_avatar($comment, $size = '64'); ?></a>
		</div>
		<div class="media-body">
        	<div class="media">
            	<div class="media-heading">
                	<div class="author-name">
                    	<a href="#"><?php echo comment_author_link(get_comment_ID())?></a>
                    </div>
                    <div class="time">
                        <?php edit_comment_link(__('(Edit)', 'yatheme'), '', ''); ?>
                        <time datetime="<?php echo comment_date('c'); ?>"><?php printf(__('%1$s', 'yatheme'), get_comment_date(),  get_comment_time()); ?></time>
                    </div>
                </div>
		        <?php if ($comment->comment_approved == '0') : ?>
			        <div class="awaiting row-fluid">
			          <i><?php _e('Your comment is awaiting moderation.', 'yatheme'); ?></i>
			        </div>
				<?php endif; ?>
                <div class="media-content row-fluid">
				<?php comment_text(); ?>
                </div>
      		</div>
      		
      		<div class="reply">
      			<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
      		</div>
      </div>
 </div>
<?php
}
// end function
?>

<?php if (post_password_required()) : ?>
	<section id="comments">
		<div class="alert alert-block fade in">
			<a class="close" data-dismiss="alert">&times;</a>
			<p><?php _e('This post is password protected. Enter the password to view comments.', 'yatheme'); ?></p>
		</div>
	</section><!-- /#comments -->
<?php endif; ?>

<?php if (have_comments()) : ?>
	<section id="comments">
		<h3>نظرات <small>(<?php echo get_post()->comment_count;?>)</small></h3>

		<div class="commentlist">
		<?php wp_list_comments(array('callback' => 'ya_comment')); ?>
	</div>

	<?php if (get_comment_pages_count() > 1 && get_option('page_comments')) : // are there comments to navigate through ?>
	<nav id="comments-nav" class="pager">
		<ul class="pager">
		<?php if (get_previous_comments_link()) : ?>
			<li class="previous"><?php previous_comments_link(__('&larr; Older comments', 'yatheme')); ?></li>
		<?php else: ?>
			<li class="previous disabled"><a><?php _e('&larr; Older comments', 'yatheme'); ?></a></li>
		<?php endif; ?>
		<?php if (get_next_comments_link()) : ?>
			<li class="next"><?php next_comments_link(__('Newer comments &rarr;', 'yatheme')); ?></li>
		<?php else: ?>
			<li class="next disabled"><a><?php _e('Newer comments &rarr;', 'yatheme'); ?></a></li>
		<?php endif; ?>
		</ul>
	</nav>
	<?php endif; // check for comment navigation ?>

	<?php if (!comments_open() && !is_page() && post_type_supports(get_post_type(), 'comments')) : ?>
		<div class="alert alert-block fade in">
			<a class="close" data-dismiss="alert">&times;</a>
			<p><?php _e('Comments are closed.', 'yatheme'); ?></p>
		</div>
	<?php endif; ?>
</section><!-- /#comments -->
<?php endif; ?>

<?php if (!have_comments() && !comments_open() && !is_page() && post_type_supports(get_post_type(), 'comments')) : ?>
<section id="comments">
	<div class="alert alert-block fade in">
		<a class="close" data-dismiss="alert">&times;</a>
		<p><?php _e('Comments are closed.', 'yatheme'); ?></p>
	</div>
</section>
<!-- /#comments -->
<?php endif; ?>

<?php if (comments_open()) : ?>
<section id="respond">
	<p class="cancel-comment-reply"><?php cancel_comment_reply_link(); ?></p>
	
	<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" name="commentform" onsubmit="return submitform()" class="form-horizontal row-fluid">
		<h3><?php _e('Leave a Reply', 'yatheme'); ?></h3>
		<p><?php _e('Your email address will not be published. Required fields are marked *', 'yatheme'); ?></p>
		<?php if (is_user_logged_in()) : ?>
			<p><?php printf(__('Logged in as <a href="%s/wp-admin/profile.php">%s</a>.', 'yatheme'), get_option('siteurl'), $user_identity); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php __('Log out of this account', 'yatheme'); ?>"><?php _e('Log out &raquo;', 'yatheme'); ?></a></p>
		<?php else : ?>
		<div class="control-group">
			<label class="control-label" for="author"><?php _e('Name*','yatheme'); ?></label>
			<div class="controls">
				<input type="text" class="input-block-level" placeholder="نام شما ..." name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?>>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="author"><?php _e('Mail*', 'yatheme'); ?></span></label>
			<div class="controls">
				<input placeholder="ایمیل شما ..."
				type="email" class="input-block-level" name="email" id="email"
				value="<?php echo esc_attr($comment_author_email); ?>" size="22"
				tabindex="2" <?php if ($req) echo "aria-required='true'"; ?>>
				</div>
			</div>
            <div class="control-group">
				<label class="control-label" for="author"><?php _e('Website', 'yatheme'); ?></label>
				<div class="controls">
					<input placeholder="وب سایت شما ..."
					type="url" class="input-block-level" name="url" id="url"
					value="<?php echo esc_attr($comment_author_url); ?>" size="22"
				tabindex="3">
			</div>
		</div>
		
		<?php endif; ?>
		<div class="control-group">
			<label class="control-label" for="author"><?php _e('Comment', 'yatheme'); ?></label>
			<div class="controls">
				<textarea name="comment" placeholder="Comment..." id="comment" class="input-block-level"
					rows="7" tabindex="4"
					<?php if ($req) echo "aria-required='true'"; ?>>
					<?php _e('', 'yatheme'); ?>
				</textarea>
			</div>
		</div>
		<div class="post-comment">
			<button type="submit" class="btn">
				<i class="icon-comment-alt"></i><?php _e('Post comment', 'yatheme'); ?>
			</button>
		</div>

		<?php comment_id_fields(); ?>
		<?php do_action('comment_form', $post->ID ); ?>
	</form>

</section><!-- /#respond -->
<?php endif; ?>
<script type="text/javascript">
	function submitform(){
		if(document.commentform.comment.value=='' || document.commentform.author.value=='' || document.commentform.email.value==''){
			alert('Please fill the required field.');
			return false;
		} else return true;
	}
</script>