$(function(){
	$("#accordion").accordion({ header: "h3", autoHeight: false, active: false, collapsible:true});
	$("#question_c").css('height','');
	
	
	$(".contentc .button").click(function() {
		var action = $(this).attr('id');
		
		html = '';
		try { 
			var name = $('#' + action + '_name').val();
			var contact = $('#' + action + '_contact').val();
			var message = $('#' + action + '_message').val();
			var time = '';
			
			if (!contact) {
				$('#' + action + '_result').html('Укажите Ваши контакты');
				$('#' + action + '_result').show();
				return false;
			}
			
			switch (action) {
				case 'comp':
					haction = 'Заказ КП';
				break;
				case 'question':
					haction = 'Вопрос';
				break;
				case 'feedback':
					haction = 'Отзыв';
				break;
				case 'freecall':
					var time = $('#' + action + '_time').val();
					message = '<b>Время звонка: </b>' + time;
					haction = 'Заказ звонка консультанта';
				break;
			}
		}catch(e) {}
		
		message = '<b>Имя: </b>' + name + ' <br />' + '<b>Контакт: </b>' + contact + ' <br />' + message;
		$.post(location.protocol + '//' + location.hostname + '/nextstep', {nssent: true, haction: haction, message: message, action: action}, function(data) {
			data = eval("(" + data + ")");
			if (data.result != 'successful') {
				$('#' + data.action + '_result').html(data.message);
				$('#' + data.action + '_result').show();
			}
			else {
				$('#' + data.action + '_result').hide();
				location.href = location.protocol + '//' + location.hostname + '/nextstep-thankyou';
			}
			return false;
		});
		
		return false;
	});
});
