 /* Окошко обратной связи */

var feedback = (function() {
	
	var tab = $('<div class="feedbackTab"></div>'),
		dlg = $('<div class="dlgFeedback" id="dlgFeedback"> ' +
					'<button class="btnClose">Скрыть</button>' +
					'<h2>Пожалуйста, оцените наш сайт:</h2>' +
					'<div class="feedbackVote">' +
						'<div class="feedbackVoteType">' +
							'<h3>Дизайн:</h3>' +
							'<div class="checkBoxes"><input type="radio" name="voteDesign" id="voteDesignYes" value="1"><label for="voteDesignYes">Нравится</label>' +
							'<input type="radio" name="voteDesign" id="voteDesignNo" value="0"><label for="voteDesignNo">Не нравится</label></div>' +
						'</div>' +
						'<div class="feedbackVoteType">' +
							'<h3>Удобство:</h3>' +
							'<div class="checkBoxes"><input type="radio" name="voteUsability" id="voteUsabilityYes" value="1"><label for="voteUsabilityYes">Нравится</label>' +
							'<input type="radio" name="voteUsability" id="voteUsabilityNo" value="0"><label for="voteUsabilityNo">Не нравится</label></div>' +
						'</div>' +
						'<div class="feedbackVoteType">' +
							'<h3>Тематика:</h3>' +
							'<div class="checkBoxes"><input type="radio" name="voteSubjectArea" id="voteSubjectAreaYes" value="1"><label for="voteSubjectAreaYes">Нравится</label>' +
							'<input type="radio" name="voteSubjectArea" id="voteSubjectAreaNo" value="0"><label for="voteSubjectAreaNo">Не нравится</label></div>' +
						'</div>' +
						'<div class="feedbackVoteType">' +
							'<h3>Содержание:</h3>' +
							'<div class="checkBoxes"><input type="radio" name="voteContent" id="voteContentYes" value="1"><label for="voteContentYes">Нравится</label>' +
							'<input type="radio" name="voteContent" id="voteContentNo" value="0"><label for="voteContentNo">Не нравится</label></div>' +
						'</div>' +
					'</div>' +
					'<div class="feedbackForm">' +
						'<p>Вы можете описать свои впечатления подробнее:</p>' +
						'<textarea id="feedbackText" name="feedbackText" rows="5" cols="40"></textarea>' +
					'</div>' +
					'<div class="submitButton"><button id="feedbackSubmit">Отправить</button></div>' +
				'</div>'),
		visible = false,		
					
		open = function() {
			dlg.animate({
				left: '0'
			}, 1000, function() {
				visible = true;
			});
			
			visible = true;
		},
		
		close = function() {
			dlg.animate({
				left: '-406'
			}, 1000, function() {
				visible = false;
			});
			
		};
		
	$('.btnClose', dlg).click(function(event) {
		close();
	});	
		
	$(tab).click(function() {
		if (visible === false) {
			open();
		} else {
			close();
		}
	});
	
	$('.submitButton button', dlg).button();
	
	$('.submitButton button', dlg).click(function () {
		
		var voteDesign = $('input[name=voteDesign]:checked','.feedbackVoteType').val();
		var voteUsability = $('input[name=voteUsability]:checked','.feedbackVoteType').val();
		var voteSubjectArea = $('input[name=voteSubjectArea]:checked','.feedbackVoteType').val();
		var voteContent = $('input[name=voteContent]:checked','.feedbackVoteType').val();
		var comment = $("#feedbackText").val();
		$.ajax({
			url: "siteRatingVote",
			type : "POST",
			data: JSON.stringify({'voteDesign' : voteDesign, 
								  'voteUsability' : voteUsability,	
								  'voteSubjectArea' : voteSubjectArea,
								  'voteContent' : voteContent,
								  'comment' : comment
			}),
			contentType: "application/json;",
			success: 
				function(response) {
					//console.log(response);
					dialog.messageBox("Спасибо за участие в опросе ! Ваше мнение очень важно для нас.");
				}
		});
	});
	
	$('.checkBoxes', dlg).buttonset();
	
	dlg.append(tab);
	
	$(document).ready(function() {
		dlg.appendTo('body');
	});

}());
