{% if reviews %}
{% for review in reviews %}
<div class="reviewpro">
	<div class="reviewhead">
		<p class="authorname">
			{{ review.author }}
			{% if review.verifyreview %}<span class="authorverify">{{ purchaseverify.verify }}</span>{% endif %}
			{% if adminlogin %}
				<a class="adminreply" rel="{{ review.review_id }}">Mağaza Cevabı</a>
			{% endif %}
			<span class="reviewdate">{{ review.date_added }}</span>
		</p>
	</div>
	<div class="reviewcontent">
		<div class="row">
			<div class="col-xs-7">
				<p class="reviewtitle">{{ review.title }}</p>
				<p class="reviewdesc">{{ review.text }}</p>
				{% if reviewpro_fields.attachvisible %}
				{% if review.attachmentfiles %}
					<div class="reviewimage">
					{% for attachfile in review.attachmentfiles %}
						{% if attachfile.thumb %}
						<a href="{{ attachfile.popup }}">
							<img src="{{ attachfile.thumb }}"  />
						</a>
						{% endif %}
					{% endfor %}
					</div>
					{% for attachfile in review.attachmentfiles %}
						{% if not attachfile.thumb %}
							<a class="reviewdownloadfile" rel="{{ attachfile.file }}">Attachment <i class="fa fa-download"></i></a>
						{% endif %}
					{% endfor %}
				{% endif %}
				{% endif %}
			</div>
			<div class="col-xs-5">
				{% if rating_desc %}
					{% for ratings in rating_desc %}
						<div class="reviewbarsec">
							{{ ratings.rating_name }}
						</div>
						<div class="partuclarreview">
							{% for i in 1..5 %}
								{% if i <= review.rating[ratings.rating_id].rating %}
									<i class="fa fa-star"></i>
								{% else %}
									<i class="fa fa-star-o"></i>
								{% endif %}
							{% endfor %}
						</div>
						<div class="clearfix"></div>
					{% endfor %}
				{% endif %}
			</div>
			{% if reviewpro_fields.reviewshare %}
			<br />
			<div class="col-sm-12">
				<!-- AddThis Button BEGIN -->
				<div class="addthis_toolbox addthis_default_style" data-url="{{ review.share }}">
					<a class="addthis_counter addthis_pill_style"></a>
					<a class="addthis_button_compact">
					  <img src="http://s7.addthis.com/static/btn/sm-plus.gif" width="16" height="16" border="0" alt="Share" />
					</a>
				</div>
				<!-- AddThis Button END --> 
			</div>
			{% endif %}
			
		</div>
		{% if reviewpro_fields.votestatus or reviewpro_fields.reviewabuse %}
		<div class="row reviewcaption">
			<div class="col-sm-7">
				{% if reviewpro_fields.votestatus %}
					<div class="voteyesno">
						<span {% if not guestvote %} data-toggle="tooltip" data-placement="top" title="{{ votingtext.login }}" {% endif %} class="{% if guestvote %} clickreview {% endif %} reviewvote yes" data="1" rel="{{ review.review_id }}">{{ votetext.helpful }} ({{ review.yesvotes }}) <i class="fa fa-thumbs-up"></i></span>
						<span {% if not guestvote %} data-toggle="tooltip" data-placement="top" title="{{ votingtext.login }}" {% endif %} class="{% if guestvote %} clickreview {% endif %} reviewvote no" data="0" rel="{{ review.review_id }}">{{ votetext.nothelpful }}  ({{ review.novotes }}) <i class="fa fa-thumbs-down"></i></span>
					</div>
				{% endif %}
			</div>
			<div class="col-sm-5 text-right">
				{% if reviewpro_fields.reviewabuse %}
					<a class="abuse" {% if not reviewabuseguest %} data-toggle="tooltip" data-placement="top" title="{{ reporttext.logintoreport }}" {% endif %} rel="{{ review.review_id }}">{{ reporttext.title }}</a>
				{% endif %}
			</div>
		</div>
		{% endif %}
		{% if reviewpro_fields.reviewby %}
		{% if review.replies[review.review_id] %}
		<div class="administrator_container">
			<div class="expandreply"><a>{{ totaladminreply[review.review_id] }} {{ reviewpro_fields.replyby }}</a></div>
			<div class="row replyslide" style="display:none;">
				<div class="col-sm-12">
					{% for replies in review.replies[review.review_id] %}
						<div class="replyadmin">
							<a>Reply by admin:</a> - {{ replies.date }}
							<p>{{ replies.comment }}</p>
						</div>
					{% endfor %}
				</div>
			</div>
		</div>
		{% endif %}
		{% endif %}
	</div>
</div>
{% endfor %}
<div class="text-right">{{ pagination }}</div>
{% else %}
<p>{{ text_no_reviews }}</p>
{% endif %}


{% if reviewabuseguest %}
<div id="abuse" class="white-popup-block reviewpropopup mfp-hide">
	<a class="popup-modal-dismiss" data-effect="mfp-zoom-in" href="#"></a>
	<h2>{{ reporttext.formtitle }}</h2>
	<form id="form-abuse" method="post" class="form-horizontal" enctype="multipart/form-data">
		{% if getreports %}
		{% if reviewpro_fields.selectreason %}
		<div class="form-group {% if reviewpro_fields.selectreason == '2' %} required {% endif %}">
		  <label class="col-sm-3 control-label" for="input_reason_1">{{ reporttext.reviewtitle }}</label>
		  <div class="col-sm-9">
			<select class="form-control" name="abuse_reason" id="input_reason_1">
				{% for getreport in getreports %}
					<option value="{{ getreport.reason_id }}">{{ getreport.name }}</option>
				{% endfor %}
			</select>
		  </div>
		</div>
		{% endif %}
		{% endif %}
		{% if reviewpro_fields.reportcomment %}
		<div class="form-group {% if reviewpro_fields.reportcomment == '2' %} required {% endif %}">
		  <label class="col-sm-3 control-label" for="input_reason_2">{{ reporttext.commentfield }}</label>
		  <div class="col-sm-9">
			<textarea id="input_reason_2" name="comment" class="form-control" placeholder="{{ reporttext.commentfield }}"></textarea>
		  </div>
		</div>
		{% endif %}
		<input type="hidden" name="review_id" value="" id="review_id_hidden" />
		<div class="buttons clearfix">
		  <div class="pull-right">
			<button type="button" id="button-abuse" data-loading-text="{{ text_loading }}" class="btn btn-primary">{{ reporttext.btntext }}</button>
		  </div>
		</div>
	</form>
</div>
{% endif %}

{% if adminlogin %}
<div id="adminreply" class="white-popup-block reviewpropopup mfp-hide">
	<a class="popup-modal-dismiss" data-effect="mfp-zoom-in" href="#"></a>
	<h4>Mağaza Cevabı</h4>
	<form id="form-adminreply" method="post" class="form-horizontal" enctype="multipart/form-data">
		<textarea class="form-control" placeholder="Mağaza cevabınızı yazınız" name="comment"></textarea>
		<input type="hidden" name="review_id" value="" id="review_id_reply_hidden" />
		<div class="buttons clearfix">
		  <div class="pull-right">
			<button type="button" id="button-adminreply" data-loading-text="{{ text_loading }}" class="btn btn-primary">Gönder</button>
		  </div>
		</div>
	</form>
</div>
{% endif %}

<script type="text/javascript"><!--
$('.clickreview').on('click', function(){
	var review_id = $(this).attr("rel");
	var helpful = $(this).attr("data");
	var $this = $(this);
	var parent = $(this).parent();
	$.ajax({
		url: 'index.php?route=extension/reviewpro/reviewvote&review_id=' + review_id + '&helpful=' + helpful,
		type: 'post',
		dataType: 'json',
		beforeSend: function() {
			$this.button('loading');
		},
		complete: function() {
			$this.button('reset');
		},
		success: function(json){
			$(".errorvote").remove();
			if(json['error']){
				parent.append('<p class="errorvote text-danger">' + json['error'] + '</p>');
			}else{
				parent.append('<p class="errorvote text-success">{{ votingtext.thankyouvote }}</p>');
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

$('#button-abuse').on('click', function(){
	var $this = $(this);
	$.ajax({
		url: 'index.php?route=extension/reviewpro/abuse',
		type: 'post',
		data: $('#form-abuse input, #form-abuse select, #form-abuse textarea'),
		dataType: 'json',
		beforeSend: function() {
			$this.button('loading');
		},
		complete: function() {
			$this.button('reset');
		},
		success: function(json){
			$(".alertabuse").remove();
			$('#form-abuse .text-danger').remove();
			$('#form-abuse .form-group').removeClass('has-error');
			if(json['error']){
				if(json['error']['alreadyvote']){
					$('#form-abuse').prepend('<p class="alert alertabuse alert-danger">' + json['error']['alreadyvote'] + '</p>');
				}
				
				for(i in json['error']){
					var element = $('#input_reason_' + i);
					$(element).after('<div class="text-danger">' + json['error'][i] + '</div>');
					$(element).parent().addClass('has-error');
				}
			}else{
				$('#form-abuse').prepend('<p class="alert alertabuse alert-success">{{ reporttext.thankyoureport }}</p>');
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

$('#button-adminreply').on('click', function(){
	var $this = $(this);
	$.ajax({
		url: 'index.php?route=extension/reviewpro/reviewreply',
		type: 'post',
		data: $('#form-adminreply input, #form-adminreply select, #form-adminreply textarea'),
		dataType: 'json',
		beforeSend: function() {
			$this.button('loading');
		},
		complete: function() {
			$this.button('reset');
		},
		success: function(json){
			if(json['error']){
				alert(json['error']);
			}else{
				$('#form-adminreply').html(json['success']);
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

{% if reviewabuseguest %}
$('.abuse').on('click', function() {
	var review_id = $(this).attr("rel");
	$('#review_id_hidden').val(review_id);
	$("#form-abuse").trigger("reset");
	$(".alertabuse").remove();
	$('.abuse').magnificPopup({
        items: {
            src: '#abuse',
            type: 'inline',
            preloader: true,
            fixedContentPos: false
        },
        closeBtnInside: true
    }).magnificPopup('open');
	$(document).on('click', '.popup-modal-dismiss', function (e) {
		e.preventDefault();
		$.magnificPopup.close();
		$('form')[0].reset();
	});
});
{% endif %}

$('.adminreply').on('click', function() {
	var review_id = $(this).attr("rel");
	$('#review_id_reply_hidden').val(review_id);
	$('.adminreply').magnificPopup({
        items: {
            src: '#adminreply',
            type: 'inline',
            preloader: true,
            fixedContentPos: false
        },
        closeBtnInside: true
    }).magnificPopup('open');
	$(document).on('click', '.popup-modal-dismiss', function (e) {
		e.preventDefault();
		$.magnificPopup.close();
		$('form')[0].reset();
	});
});

$('.expandreply').on('click', function() {
	$(this).siblings().slideToggle();
});

$(document).ready(function() {
	$('.reviewimage').magnificPopup({
		type:'image',
		delegate: 'a',
		gallery: {
			enabled: true
		}
	});
});

$('.reviewdownloadfile').on('click', function(){
	var review_id = $(this).attr("rel");
	var $this = $(this);
	var parent = $(this).parent();
	$.ajax({
		url: 'index.php?route=extension/reviewpro/downloadattachment&review_id=' + review_id,
		dataType: 'json',
		beforeSend: function() {
			$this.button('loading');
		},
		complete: function() {
			$this.button('reset');
		},
		success: function(json){
			if(json['download']){
				window.location=json['download'];
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});

//--></script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#ra-5a65cb048736152a"></script>