// Create user extensions namespace (Ext.ux)
Ext.namespace('Ext.dentist');
 
/**
  * Ext.dentist Extension Class
  *
  */
Ext.dentist.ContactForm = function(config) {

	
	this.chkGroup = new Ext.form.CheckboxGroup({
		xtype: 'checkboxgroup',
		clearCls: "smaller",
		columns: 1,
		hideLabel: true,
		anchor: '100%',
		items: [
			{boxLabel: config.chkOne, name: 'cb-col-1'},
			{boxLabel: config.chkTwo, name: 'cb-col-2'},
			{boxLabel: config.chkThree, name: 'cb-col-3'},
			{boxLabel: config.chkFour, name: 'cb-col-4'},
			{boxLabel: config.chkFive, name: 'cb-col-5'}
		]
	});
	
	
	this.questionsFieldSet = new Ext.form.FieldSet({
        xtype:'fieldset',
        autoHeight:true,
		border: false,
        columnWidth: 0.5,
		hidden: true,
        items :[
				{
					html: config.titleQuestions,
					xtype: 'label'
				},
				{
				    html: config.questionOne,
					xtype: 'label',
					style:'display:block;'
				},
				{
				    html: config.questionTwo,
					xtype: 'label',
					style:'display:block'
				},
				{
				    html: config.questionThree,
					xtype: 'label',
					style:'display:block'
					
				},
				{
				    html: config.questionFour,
					xtype: 'label',
					style:'display:block'
					
				},
				{
				    html: config.questionFive,
					xtype: 'label',
					style:'display:block'
					
				},
				{
				    html: config.questionSix,
					xtype: 'label',
					style:'display:block'
				}
        ]
    });
	
	
	this.chkGroup.on('change', function(chkGroup, arrayChecked) {
		var display = false;

		for(var i = 0; i < arrayChecked.length; i++) {
			if(arrayChecked[i].name == 'cb-col-1' || arrayChecked[i].name == 'cb-col-2' || arrayChecked[i].name == 'cb-col-4')
			{
				display = true;
			}
		}
		this.questionsFieldSet.setVisible(display);
	}, this);
	
	
	this.sendButton = new Ext.Button({
		text: config.buttonText,
		handler: function () {  
			var form = this.getForm() ;
			
			if(form.isValid()) {
				this.showMask(config.maskEmail);
				form.submit({  
					success: function (form, action) {
					if (action.result.success) {
					    if (config.langForm == "eng") {
					            _gaq.push(['_trackEvent', 'Formulaire eng', 'sent']);
					        }
					        else {
					            _gaq.push(['_trackEvent', 'Formulaire fr', 'sent']);
					        }				    
							Ext.Msg.alert('Status', config.emailConfirmation);
						}
						else
						{
							Ext.Msg.alert('Status', "FAILURE !");
						}
						
						this.hideMask();
					},
					failure: function () {
						alert("FAIL");
						this.hideMask();
					},
					scope: this,
					params: {
					    lang: config.langForm
					}
				});  
			}
		},
		scope: this
	});
	
	this.formContactUs = new Ext.FormPanel({
			labelWidth: 100, // label settings here cascade unless overridden
			url: "system/common/send_form_email.php",
			frame:false,
			bodyStyle:'padding-left:10px;',
			defaults: {width: 315, anchor: '95%'},
			defaultType: 'checkbox',
			border: false,
			plain: false,
			items: [
				{
					text: config.title,
					xtype: 'label',
					style: 'display:block;padding-bottom:5px;color:#0079BB;'
				},
				{
					xtype: 'textfield',
					fieldLabel: config.name,
					name: 'contname',
					allowBlank:false
				},{
					xtype: 'textfield',
					fieldLabel: config.address,
					name: 'contaddress',
					allowBlank:false
				},{
					xtype: 'textfield',
					fieldLabel: config.phone,
					name: 'contphone',
					allowBlank:false
				}, {
					xtype: 'textfield',
					fieldLabel: config.mail,
					name: 'contemail',
					vtype:'email',
					allowBlank:false
				},
				{
					style:'display:block;',
					text: config.titleChk,
					xtype: 'label'
				},
				this.chkGroup,
				this.questionsFieldSet, 
                {
                    text: config.otherQuestions,
					xtype: 'label' 
				},				
				{
				    xtype: 'textarea',
				    height: '30px',
					name: 'contmsg',
					hideLabel: true
				}				
			],
			buttons: [
				this.sendButton			
			],
			plugins: [new Ext.ux.plugins.ContainerMask ({msg:config.maskEmail, masked:false })]		
		});

 
    // call parent constructor
    Ext.dentist.ContactForm.superclass.constructor.call(this, this.formContactUs);
 
}; // end of Ext.dentist.ContactForm constructor
 
// extend
Ext.extend(Ext.dentist.ContactForm, Ext.FormPanel, {
 
}); // end of extend
 
// end of file
