Ext.BLANK_IMAGE_URL='/scripts/ext-2.2/resources/images/default/s.gif';

function clearReq(ele) {
	if (ele.getValue() == '<required>')
		ele.setRawValue('');
}
 
Ext.apply(Ext.form.VTypes, {
    futuredate : function(val, field) {
        var date = field.parseDate(val);
		var currentDate = new Date();
        if(!date){
            return;
        }
        if (currentDate > date) {
            return false;
        }
		return true;
	},
	biztime : function(val, field) {
		var fldTime = field.parseDate(val);
		var fldDate = Ext.getCmp('per-appt-day');
		if (fldDate.getValue().getDay() == 6) {
			if (fldTime.getHours() > 13 || (fldTime.getHours() == 13 && fldTime.getMinutes() > 0)) {
				return false;
			}
		}
		return true;
	},
	required : function(val, field) {
		if (val == '<required>')
			return false;
		
		return true;
	}
	// need a custom validator for the custom <required> fields.
});

var fp;

Ext.onReady(function(){

	Ext.QuickTips.init();
    
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';
	
    fp = new Ext.FormPanel({
        frame: true,
        title:'Contact Us About Lunch & Learn',
        labelWidth: 110,
        width: 600,
        renderTo:'form-ct',
        bodyStyle: 'padding:0 10px 0;',
        
        items: [{
				xtype:'textfield',
				name: 'form-name',
				id: 'form-name',
				hidden: 'true',
				value: 'Lunch and Learn Form',
				labelSeparator: ''
			},{
				xtype:'textfield',
				fieldLabel: 'Name',
				name: 'per-name',
				id: 'per-name',
				allowBlank: false,
				listeners: { focus : clearReq },
				vtype:'required',
				anchor:'95%'
			},{
				xtype:'textfield',
				fieldLabel: 'Email Address',
				name: 'per-email',
				allowBlank: false,
				listeners: { focus : clearReq },
				vtype:'required',
				id: 'per-email',
				vtype: 'email',
				anchor:'95%',
				validationDelay: 15000
			},{
				xtype:'textfield',
				fieldLabel: 'Phone',
				name: 'per-phone',
				id: 'per-phone',
				anchor:'95%'
			},{
				xtype:'textfield',
				fieldLabel: 'Company',
				name: 'per-company',
				allowBlank: false,
				listeners: { focus : clearReq },
				vtype:'required',
				id: 'per-company',
				anchor:'95%'
			},{
                xtype:'textfield',
                fieldLabel: 'Desired Seminar Date',
                name: 'per-date',
				id: 'per-date',
				allowBlank: true,
                anchor:'95%'
            },{
				xtype:'textfield',
				fieldLabel: 'Referral Source',
				name: 'per-referral',
				allowBlank: true,
				id: 'per-referral',
				anchor:'95%'
			},{
				xtype:'fieldset',
	            title: 'Check a topic (all seminars include ergonomic setup)',
	            autoHeight: true,
	            layout: 'form',
				//style: 'border:none;',
	            items: [{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Stay Fit While You Sit for Optimal Spinal Health',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Stay Fit While You Sit for Optimal Spinal Health'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: '20 Minutes To Health (our best all around health seminar)',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: '20 Minutes To Health (our best all around health seminar)'
                },{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Natural Solutions For Chronic Back and Neck Pain ',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Natural Solutions For Chronic Back and Neck Pain '
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Sports Injuries: Causes, Preventions, Cures ',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Sports Injuries: Causes, Preventions, Cures '
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Stress Workshop: How To Prevent The Silent Killer',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Stress Workshop: How To Prevent The Silent Killer'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Good Posture=Good Health (Interactive Electronic Posture Scans)',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Good Posture=Good Health (Interactive Electronic Posture Scans)'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Eliminate Headaches & Migraines Forever',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Eliminate Headaches & Migraines Forever'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Carpal Tunnel Syndrome (Causes, Prevention, Cures)',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Carpal Tunnel Syndrome (Causes, Prevention, Cures)'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Healthy Living and Nutritional Healing',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Healthy Living and Nutritional Healing'
                	},{
                    xtype:'checkbox',
					labelSeparator: '',
                    boxLabel: 'Nonsurgical Solutions For Herniated Discs',
					fieldLabel: '',
                    name: 'per-topic',
					inputValue: 'Nonsurgical Solutions For Herniated Discs'
                	}]
			}],
        buttons: [{
            text: 'Submit Form',
            handler: function(){
				var form = fp.getForm();
				form.submit({
					waitMsg:'Processing...',
					url: '/chiropractic-services/lunch-form-processor.aspx',
					success: function(form,action) {
						//window.location = action.result.nextURL;
						fp.getForm().reset();
						Ext.Msg.show({
						   title:'Success',
						   msg: 'Thank you for your inquiry. We will contact you shortly.',
						   buttons: Ext.Msg.OK,
						   icon: Ext.MessageBox.INFO
						});
					},
					failure: function(form,action){
						Ext.Msg.show({
						   title:'Error',
						   msg: action.result.failMessage,
						   buttons: Ext.Msg.OK,
						   icon: Ext.MessageBox.WARNING
						});
					}
				});
            }
        }]
    });

	var fldEmail = Ext.getCmp('per-email');
	fldEmail.setRawValue('<required>');
	var fldName = Ext.getCmp('per-name');
	fldName.setRawValue('<required>');
	var fldComp = Ext.getCmp('per-company');
	fldComp.setRawValue('<required>');
	
	
	
	
});
