//
// $Id: sendConfInfo.js,v 1.1 2008/02/18 10:15:29 zetaka Exp zetaka $
//
Ext.onReady(function() {
	var btn=Ext.get('sendConfBtn');

	btn.on('click', function(){
		this.hide(); // hide Button 

		var submitForm=new Ext.form.FormPanel({
			labelWidth: 116, 
			labelAlign: 'right', 
			url: 'save-form.php',
			frame:true,
			title: 'Submit Unlisted Conference Information Form - ConfShare',
			bodyStyle: 'padding:5px 5px 0',
			width: 580,
			buttonAlign: 'right',
			defaults: { width: 440 },
			defaultType: 'textfield',
			onSubmit: Ext.emptyFn,

			items: [{
					fieldLabel: 'Your name',
					name: 'name',
					allowBlank: false
				},{
					fieldLabel: 'Your E-mail address',
					name: 'email',
					vtype: 'email',
					allowBlank: false
				},{
					fieldLabel: 'URL of Conference',
					name: 'url',
					vtype: 'url',
					emptyText: 'Enter a URL of conference web page',
					allowBlank: false
				}
			],

			buttons: [{
					text: 'Send',
					handler: function () {
						var bf=submitForm.getForm()
						if (bf.isValid()) {
							// Ext.MessageBox.alert('', bf.getValues().toSource()); // for debug
							bf.submit({
								url:'/~zetaka/cgi-bin/ConfShare/nagekomi.cgi', 
								method: 'POST', 
								waitMsg: 'Wait a moment...',
								success: function(form, action){
									Ext.MessageBox.alert('Thanks!!', 'Thank you for your cooperation'); 
									submitForm.destroy();
									btn.show(); // show Button
								},
								failure: function(form, action){
									Ext.MessageBox.alert('', 'failed to send information: '+action.failureType+', '+action.result.toSource()); 
									
								}
							});
						} else {
							Ext.MessageBox.alert('Error', 'Wrong data! You enter all fields of the form correctly.');
						}
					}
				},{
					text: 'Cancel',
					handler: function(){
						Ext.MessageBox.confirm(
							'Confirm', 
							'Are you really you want to close the form window?', 
							function(abtn, text) { 
								if (abtn=='yes') {
									submitForm.destroy();
									btn.show(); // show Button
								}
							}
						);
					}
			}]
		});

		submitForm.render( document.getElementById('drawArea') );
	});

});

//
// ends here
//
