﻿Ext.onReady(function() {

    Ext.QuickTips.init();
    // code here
	    // second tabs built from JS
	var RegWin;
   	var FeedBackWin;
	
	//Форма регистрации на игру
	var RegForm = new Ext.form.FormPanel({
										url			:'/core/register.php',
										labelWidth	: 60, // label settings here cascade unless overridden
										frame		:true,
										defaultType	: 'textfield',
										monitorValid:false,
										items: [{
												fieldLabel	: 'Ф.И.О',
												width		: 300,
												name		: 'author'
												},
												new Ext.form.TextArea({
												fieldLabel	: 'Текст',
												width		: 300,
												height		: 180,
												value 		: 'Желаю записаться на игру, которая состоится:\n\nСо мной можно связаться:',
												name		: 'text'
												})]
										});
	
	Ext.get('registerLink').on('click', function(){
		if (!RegWin){
					RegWin = new Ext.Window({
					renderTo	: Ext.getBody(),
					title		: 'Принять участие в игре',
					layout      : 'fit',
					width       : 400,
					height      : 300,
					closeAction :'hide',
					plain       : true,
					items      	: RegForm,
					buttons: [{
								text: 'Отправить',
								handler : function(){
													RegForm.getForm().submit({ 
													method		:'POST', 
													waitTitle	:'Connecting', 
													waitMsg		:'Sending data...',
													 
													success		:function(){ 
																						Ext.Msg.alert('Status', 'Ваше сообщение успешно отправленно!');
																						RegForm.getForm().reset(); 
																						RegWin.hide();
																			},
													failure		:function(form, action){
																				if(action.failureType == 'server'){ 
																								obj = Ext.util.JSON.decode(action.response.responseText); 
																								Ext.Msg.alert('Warning!', obj.errors.reason); 
																						   } else { 
																								Ext.Msg.alert('Warning!', action.response.responseText); 
																						   }
																			}	 
                 									}); 
				 				}
				 				},{
				 				text	: 'Отмена',
								handler	: function(){
											RegWin.hide();
											}
							}]
					});
		}									 
		RegWin.show();
		});
	
	//Форма Обратной связи
	var FeedBackForm = new Ext.form.FormPanel({
										url			:'/core/feedback.php',
										labelWidth	: 60, // label settings here cascade unless overridden
										frame		:true,
										defaultType	: 'textfield',
										monitorValid:false,
										items: [{
												fieldLabel	: 'Ф.И.О',
												width		: 300,
												name		: 'author'
												},
												new Ext.form.TextArea({
												fieldLabel	: 'Текст',
												width		: 300,
												height		: 180,
												name		: 'text'
												})]
										});
	
	Ext.get('mail').on('click', function(){
		if (!FeedBackWin){
					FeedBackWin = new Ext.Window({
					renderTo	: Ext.getBody(),
					title		: 'Обратная связь',
					layout      : 'fit',
					width       : 400,
					height      : 300,
					closeAction :'hide',
					plain       : true,
					items      	: FeedBackForm,
					buttons: [{
								text: 'Отправить',
								handler : function(){
													FeedBackForm.getForm().submit({ 
													method		:'POST', 
													waitTitle	:'Connecting', 
													waitMsg		:'Sending data...',
													 
													success		:function(){ 
																						Ext.Msg.alert('Status', 'Ваше сообщение успешно отправленно!');
																						FeedBackForm.getForm().reset(); 
																						FeedBackWin.hide();
																			},
													failure		:function(form, action){
																				if(action.failureType == 'server'){ 
																								obj = Ext.util.JSON.decode(action.response.responseText); 
																								Ext.Msg.alert('Warning!', obj.errors.reason); 
																						   } else { 
																								Ext.Msg.alert('Warning!', action.response.responseText); 
																						   }
																			}	 
                 									}); 
				 				}
				 				},{
				 				text	: 'Отмена',
								handler	: function(){
											FeedBackWin.hide();
											}
							}]
					});
		}									 
		FeedBackWin.show();
		});
	
}); // eo function onReady

// eof
