$(document).ready(function(){
	$("#callback").click(function(){
		$( "#callback_dialog" ).dialog({
			height: 420,
			width: 400,
			modal: true,
			title: 'Обратного звонока',
			buttons: {
				"Отправить": function() {
					$(this).dialog( "disable" );
					var form = $('#callback_dialog :input').serializeArray();
					form.push({name:'w',value:'callback'});
					$.post('/send.php',form,function(data){
						if(data=='OK'){
							$('#callback_result').slideUp('fast').empty().html('<div class="ui-widget"><div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 10px 5px;">	<p><span class="ui-icon ui-icon-circle-check" style="float: left; margin-right: .3em;"></span><strong>Данные отправлены!</strong> В ближайшее время данная информация поступит на обработку менеджеру.</p></div></div>').slideDown();
						}
						else{
							$('#callback_result').slideUp('fast').empty().html('<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="margin-top: 20px; padding: 10px 5px;">	<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>Ошибка!</strong> '+data+'</p></div></div>').slideDown();
						}
					});
					$(this).dialog("enable");
				}
			},
			open: function(event, ui){
				$('#callback_dialog input[type=text]').val('');
				$('#callback_dialog input[type=radio]').removeAttr('checked');
				$('#callback_result').hide().empty();
				$("#callback_dialog .radio").buttonset();
			}
		});
	});
	
	$(".sign").click(function(){
		$( "#sign_dialog" ).dialog({
			height: 420,
			width: 400,
			modal: true,
			title: 'Заявка на посещение офиса',
			buttons: {
				"Отправить": function() {
					$(this).dialog( "disable" );
					var form = $('#sign_dialog :input').serializeArray();
					form.push({name:'w',value:'sign'});
					$.post('/send.php',form,function(data){
						if(data=='OK'){
							$('#sign_result').slideUp('fast').empty().html('<div class="ui-widget"><div class="ui-state-highlight ui-corner-all" style="margin-top: 10px; padding: 5px;">	<p><span class="ui-icon ui-icon-circle-check" style="float: left; margin:0 10px 30px 0;"></span><strong>Данные отправлены!</strong> В ближайшее рабочее время наши сотрудники свяжуться с вами для подтверждения вашего везита в офис. Без данного звонка запись считается не действительной!.</p></div></div>').slideDown();
						}
						else{
							$('#sign_result').slideUp('fast').empty().html('<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="margin-top: 20px; padding: 10px 5px;">	<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>Ошибка!</strong> '+data+'</p></div></div>').slideDown();
						}
					});
					$(this).dialog("enable");
				}
			},
			open: function(event, ui){
				$('#sign_dialog input[type=text]').val('');
				$('#sign_dialog input[type=radio]').removeAttr('checked');
				$('#sign_result').hide().empty();
				$("#sign_dialog .radio").buttonset();
			}
		});
	});
	$(".wint button").button({
            icons: {
                primary: "ui-icon-calendar"
            }
        })
});
