var TextMarket = {
	init : function(){		
        $('.tm-opinion-img').click(TextMarket.openResponse);
        $('.post-response').click(TextMarket.postResponse)
    },   
	openResponse : function() {
        var id = $(this).attr('id').replace('item-','');
        $.get('/',{
				mode		: 'front-gateway',
				module		: 'text_market_2',
				controller	: 'api',
				format		: 'json',
				action		: 'get_response_text',
				id			: id
			},
			function (result) {
				if (result.success){
					var div = $('<div>'+result.content+'</div>');
					div.dialog({
						title		: 'Отзыв',
						width		: 300,
						height		: 200,
						modal		: true,
						autoResize	: true,
						resizable	: true,
						buttons		: {
							'Закрыть' : function(){
								div.dialog('destroy');
							}
						}
					});
				} else {
					alert(result.errors[0]);
				}
			}, 'json'
		);
    },
    postResponse : function() {
        
        var id = $(this).attr('id').replace('item-','');
        $.get('/', {
				mode		: 'front-gateway',
				module		: 'text_market_2',
				controller	: 'api',
				format		: 'json',
				action		: 'get_postresponse',
				id			: id
			},
			function (result) {
				if (result.success){
					var div = $('<div>'+result.content+'</div>');
					div.dialog({
						title		: 'Отзыв',
						width		: 400,
						height		: 200,
						modal		: true,
						autoResize	: true,
						resizable	: true,
						buttons		: {                           
							'Закрыть' : function(){
								div.dialog('destroy');
							},
                            'Оставить отзыв' : function() {
                                div.find('form').submit();
                            }
						}
					});
				} else {
					alert(result.errors[0]);
				}
			}, 'json'
		);
        return false;
    }
};

$(document).ready(function(){
	TextMarket.init();	
});