﻿Ext.BLANK_IMAGE_URL = 'ext-2.1/resources/images/default/s.gif';
try { console.log(''); } catch(e) { console = { log: function(s) { alert(s.toString()) } } }

Ext.namespace('Ext.Mapper');

/*
* @class Ext.Mapper.ContactForm
* @extends Ext.form.FormPanel
*
* Author Mapper Contact Us Form
*/
Ext.Mapper.ContactForm = Ext.extend(Ext.Panel, {
		
	initComponent : function() {
		
		Ext.apply(this, {
			layout: 'form',
			frame: false,
			border: false,
			labelWidth : 120,
			width: 395,
			expanded : false,
			labelAlign: 'right',
 			defaults : { 
 				width : 250,
 				labelSeparator: '',
 				msgTarget : 'side'
 			},
			items: [
				{
					xtype:'textfield',
					fieldLabel : 'First Name *',
					id: 'f_First_Name',
					allowBlank:false
				},
				{
					xtype:'textfield',
					fieldLabel : 'Last Name *',
					id: 'f_Last_Name',
					allowBlank:false
				},
				{
					xtype:'textfield',
					fieldLabel : 'Email *',
					vtype : 'email',
					id: 'f_Email',
					allowBlank:false
				},
				{
					xtype:'textfield',
					fieldLabel : 'Address 1',
					id: 'f_Address_1',
					allowBlank:true
				},
				{
					xtype:'textfield',
					fieldLabel : 'Address 2',
					id: 'f_Address_2',
					allowBlank:true
				},
				{
					xtype:'textfield',
					fieldLabel : 'City',
					id: 'f_City',
					allowBlank:true
				},
				{
					xtype:'textfield',
					fieldLabel : 'State/Province',
					id: 'f_State',
					allowBlank:true
				},
				{
					xtype:'textfield',
					fieldLabel : 'Zip/Postal Code',
					id: 'f_Zip',
					allowBlank:true
				},
				new Ext.form.ComboBox({
					fieldLabel : 'Country *',
					id : 'f_Country',
					mode: 'local',
					hideTrigger1: true,
					triggerAction: 'all',
					allowBlank : false,
					displayField : 'n',
					valueField: 'n',
					editable: true,
					forceSelection: true,
					typeAhead : true,
					store : new Ext.data.Store({
						proxy: new Ext.data.HttpProxy(
							new Ext.data.Connection({
								url: '/xqueries/countries.xqy',
								disableCaching : false,
								method : 'GET'
						})), 
						reader: new Ext.data.XmlReader({record : 'c'}, Ext.data.Record.create([{name: 'n'}])),
						autoLoad : true
					}),
					onTrigger2Click : function() { this.onTriggerClick(); }
				}),
				{
					xtype : 'textarea',
					fieldLabel : 'Message *',
					grow : true,
					growMax : 200,
					id : 'f_Message',
					allowBlank : false
				}
			],
			buttonAlign : 'right'
		});		
		Ext.Mapper.ContactForm.superclass.initComponent.call(this, arguments);
	}
});


Ext.onReady(function() {
	Ext.QuickTips.init();
	var contactForm = new Ext.Mapper.ContactForm({ id : 'contactForm'});
	var bf = new Ext.form.BasicForm(document.forms[0]);
	contactForm.items.each(function(i) { bf.add(i); });

  contactForm.addButton("Submit", function() {
		if (bf.isValid()) {
			var mask = new Ext.LoadMask('contact-form', {msg: 'Saving...'});
			mask.show();
			bf.submit({
				url : 'form-emailer.ashx',
				success : function() { 
					mask.hide();  
					Ext.fly('contact-form').update('<p class="msg">Thank you for your message.</p>');
				},
				failure : function() { 
					mask.hide(); 
					if (!Ext.fly('send-failure')) {
						Ext.fly('contact-form').insertHtml('beforeEnd', '<p class="msg" id="send-failure">Sorry there was a problem sending the form. Please try again later or email us at <a href="mailto:authormapper@springer.com">authormapper@springer.com</a>.</p>');
					}
				}
			});
			
		}
  });
 
	contactForm.render('contact-form');


});