Ext.BLANK_IMAGE_URL = 'pages/images/default/s.gif';
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
Ext.Ajax.timeout = 300000;

Ext.onReady(function() {
	var crmData = [['SalesForce', 'SalesForce'],
			['MS Dynamics CRM', 'MS Dynamics CRM'], ['NetSuite', 'NetSuite'],
			['SugarCRM On-Demand', 'SugarCRM On-Demand'],
			['SugarCRM On-Premise', 'SugarCRM On-Premise'], ['Other', 'Other']];
	var sourceData = [['Another WebSite', 'Another WebSite'],
			['Conference', 'Conference'], ['Internet Ad', 'Internet Ad'],
			['Print Ad', 'Print Ad'], ['Search Engine', 'Search Engine'],
			['Word of Mouth', 'Word of Mouth'], ['Other', 'Other']];
	var interestData = [
			['Automated Lead Nurturing', 'Automated Lead Nurturing'],
			['Lead/List Management', 'Lead/List Management'],
			['Lead Scoring', 'Lead Scoring'],
			['ROI Reporting', 'ROI Reporting'],
			['Sales Enablement', 'Sales Enablement'],
			['Web Analytics', 'Web Analytics'], ['Other', 'Other']];

	var trialSignUpForm = new Ext.FormPanel({
		id : 'trialSignUpForm',
		monitorValid : true,
		frame : true,
		title : "Trial Registration Form",
		width : '99%',
		closable : false,
		bodyStyle : 'padding:5px 5px 0',
		renderTo : document.body,
		// layout : 'fit',
		items : [{ // fieldset
			xtype : 'fieldset',
			title : 'Contact Information',
			layout : 'column',
			autoHeight : true,
			defaults : {
				border : false,
				style : 'padding:10px'
			},
			items : [{
						columnWidth : 0.5,
						layout : 'form',
						defaults : {
							xtype : 'textfield',
							anchor : '95%'
						},
						items : [{
									fieldLabel : 'First Name',
									name : 'firstName',
									emptyText : 'First Name (required)',
									width : 190,
									allowBlank : false,
									blankText : 'First Name cannot be left blank.',
									id : 'firstName'
								}, {
									fieldLabel : 'Last Name',
									emptyText : 'Last Name (required)',
									name : 'lastName',
									width : 190,
									allowBlank : false,
									blankText : 'Last Name cannot be left blank.'
								}, {
									fieldLabel : 'Telephone',
									name : 'phone_office',
									width : 190,
									allowBlank : false,
									blankText : 'Telephone cannot be left blank.',
									emptyText : 'Telephone (required)'
								}, {
									fieldLabel : 'Fax',
									name : 'number_fax',
									width : 190,
									allowBlank : true
								}]
					}, {
						columnWidth : 0.5,
						layout : 'form',
						defaults : {
							xtype : 'textfield',
							anchor : '95%'
						},
						items : [{
									fieldLabel : 'Street Address',
									name : 'address_1',
									width : 190,
									allowBlank : true
								}, {
									fieldLabel : 'City',
									name : 'city',
									width : 190,
									allowBlank : true
								}, {
									fieldLabel : 'State/Province',
									name : 'state_region',
									width : 190,
									allowBlank : true
								}, {
									fieldLabel : 'Country',
									name : 'country',
									width : 190,
									allowBlank : true
								}, {
									fieldLabel : 'Postal Code',
									name : 'postal_code',
									width : 190,
									allowBlank : true
								}]
					}]
		}, new Ext.form.FieldSet({
					title : 'Trial Registration Information',
					autoHeight : true,
					collapsed : false,
					defaultType : 'textfield',
					border : true,
					loadMask : true,
					collapsible : false,
					labelWidth : 170,
					labelAlign : 'right',
					items : [{
								fieldLabel : 'E-Mail Address',
								name : 'email',
								id : 'email',
								width : 190,
								allowBlank : false,
								vtype : 'email',
								blankText : 'E-Mail Address cannot be left blank.',
								emptyText : 'E-Mail (required)'
							}, {
								fieldLabel : 'Password',
								name : 'pass1',
								id : 'pass1',
								width : 190,
								inputType : 'password',
								allowBlank : false,
								blankText : 'Password cannot be left blank.',
								vtype : 'password'
							}, {
								fieldLabel : 'Confirm Password',
								name : 'pass2',
								id : 'pass2',
								vtype : 'passv',
								initialPassField : 'pass1',
								width : 190,
								inputType : 'password',
								allowBlank : false,
								blankText : 'Password cannot be left blank.',
								vtypeText : 'Passwords do not match.'
							}, new Ext.form.ComboBox({
										fieldLabel : 'Which CRM are you using?',
										store : crmData,
										triggerAction : 'all',
										allowBlank : false,
										emptyText : 'Select a CRM... (required)',
										width : 190,
										editable : false,
										name : 'crm',
										id : 'crm'
									}), new Ext.form.ComboBox({
										fieldLabel : 'Primary solution interest?',
										store : interestData,
										triggerAction : 'all',
										allowBlank : false,
										emptyText : 'Select an interest... (required)',
										width : 195,
										editable : false,
										name : 'interest',
										id : 'interest'
									})]
				}), new Ext.form.FieldSet({
					title : 'Company Information',
					autoHeight : true,
					collapsed : false,
					defaultType : 'textfield',
					border : true,
					loadMask : true,
					collapsible : false,
					items : [{
								fieldLabel : 'Job Title',
								name : 'title',
								id : 'title',
								width : 190,
								allowBlank : false,
								blankText : 'Job Title cannot be left blank.',
								emptyText : 'Job Title (required)'
							}, {
								fieldLabel : 'Company Name',
								name : 'companyName',
								id : 'companyName',
								width : 190,
								allowBlank : false,
								blankText : 'Company Name cannot be left blank.',
								emptyText : 'Company Name (required)'
							}, {
								fieldLabel : 'Company URL',
								name : 'companyURL',
								id : 'companyURL',
								width : 190,
								allowBlank : false,
								blankText : 'Company URL cannot be left blank.',
								emptyText : 'Company URL (required)'
							}]
				}), new Ext.form.FieldSet({
					autoHeight : true,
					collapsed : false,
					defaultType : 'textfield',
					border : false,
					loadMask : true,
					collapsible : false,
					labelWidth : 200,
					items : new Ext.form.ComboBox({
								fieldLabel : 'How did you hear about us?',
								store : sourceData,
								allowBlank : true,
								emptyText : 'Select Source...',
								selectOnFocus : true,
								width : 190,
								editable : true,
								name : 'source'
							})
				})],
		buttons : [{
			text : 'Register',
			formBind : true,
			handler : function() {
				trialSignUpForm.form.submit({
							url : '/register/sentinel',
							params : {
								c : 1,
                                a : a,
                                d : d
							},
							waitMsg : 'Saving Data...',
							success : function(form, action) {
								submitSuccess();
							},
							failure : function(form, action) {
								Ext.MessageBox.alert('Message',
										'Trial Registration failed!');
							}
						});
			}
		}]
	});
	Ext.DomHelper.insertAfter('email', {
		tag : 'span',
		html : '<br/><font size="1"><i>This will be your primary login username.</i></font><br/><br/>'
	}, true);

	function lf_tracking() {
		_lf_cid = "loopfuse";
		_lf_remora();
	}
	trialSignUpForm.on('afterlayout', lf_tracking(), this, {
				delay : 1,
				single : true
			});

	var p = new Ext.Panel({
		// title : 'My Panel',
		collapsible : false,
		width : '100%',
		bodyStyle : 'padding-bottom:15px;background:#eeeeee;',
		autoScroll : true,
		html : '<p class="details-info">Thank you for registering for the LoopFuse OneView On-Demand 15-day Trial. '
				+ '<br/><br/>You will be receiving additional instructions via email, from our '
				+ 'support address, support@loopfuse.com.<br/><br/><br/>You may close this window at any time. </p>',
		region : 'center'
	});

	var win = new Ext.Window({
				title : 'Trial Registration',
				closable : true,
				width : 500,
				height : 350,
				plain : true,
				maximizable : false,
				layout : 'border',
				items : [p]
			});

	function submitSuccess() {
		trialSignUpForm.hide();
		win.show();
	}
});
