// JavaScript Document
Ext.namespace('Ext.exampledata');
Ext.exampledata.issue_type = [
						  	['General'],
							['My Account'],
							['Become a Candidate'],
							['My Position'],
							['Protest Incubments'],
							['Elections & Referenda'],
							['Frame Referendum'],
							['Measures'],
							['Frame Measures'],
							['Forum Sessions'],
							['Attend Forum'],
							['Register Issues'],
							['Lobby Groups'],
							['Manage Lobby Group'],
							['Public Meetings'],
							['Email'],
							['Mail Referrals'],
							['Read Newspapers'],
							['Edit a Newspaper']
						  ];

Ext.exampledata.browser_type = [
						  	['MS Internet Explorer 6'],
							['MS Internet Explorer 7'],
							['Mozilla Firefox 2'],
							['Mozilla Firefox 3'],
							['Google Chrome'],
							['Apple Safari'],
							['Other (please specify)']
						  ];

Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'under';

if(person_id == '0')
{
    var fs = new Ext.FormPanel({
        frame: false,
        title:'',
        labelAlign: 'right',
        labelWidth: 150,
        width:900,
        waitMsgTarget: true,

        // configure how to read the XML Data
        reader : new Ext.data.XmlReader({
            record : 'contact',
            success: '@success'
        }, [
            'txttext' // custom data types
        ]),

        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.form.XmlErrorReader(),

        items: [
            new Ext.form.FieldSet({
                title: 'Send Message to the Site Team',
                autoHeight: true,
                defaultType: 'textfield',
                items: [
					{
						inputType: 'hidden',
                        name: 'date_raised',
						value: p_date
                    },{
						inputType: 'hidden',
                        name: 'person_id',
						value: person_id
                    },{
						inputType: 'text',
                        fieldLabel: 'Name',
                        name: 'txtname'
                    },{
						inputType: 'text',
                        fieldLabel: 'Email Address',
                        name: 'txtemail'
                    },{
						inputType: 'hidden',
                        name: 'server_action',
						value: 'userproblem_form'
                    },
					new Ext.form.TextArea({
                        fieldLabel: 'Message',
                        name: 'txttext',
						id: 'txttext',
						allowBlank: false,
						maxLength: '5000',
                        width:500,
                        height: 150
                    })
                ]
            })
        ]
    });
}
else
{
    var fs = new Ext.FormPanel({
        frame: false,
        title:'',
        labelAlign: 'right',
        labelWidth: 150,
        width:900,
        waitMsgTarget: true,

        // configure how to read the XML Data
        reader : new Ext.data.XmlReader({
            record : 'contact',
            success: '@success'
        }, [
            'txttext' // custom data types
        ]),

        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.form.XmlErrorReader(),

        items: [
            new Ext.form.FieldSet({
                title: 'Report User Problems Form',
                autoHeight: true,
                defaultType: 'textfield',
                items: [
					{
						inputType: 'hidden',
                        name: 'date_raised',
						value: p_date
                    },{
						inputType: 'hidden',
                        name: 'person_id',
						value: person_id
                    },{
						inputType: 'hidden',
                        name: 'person_role',
						value: person_role
                    },{
						inputType: 'hidden',
                        name: 'server_action',
						value: 'userproblem_form'
                    },
					new Ext.form.ComboBox({
                        fieldLabel: 'Area of Problem ',
                        hiddenName:'txtarea_problem',
                        store: new Ext.data.SimpleStore({
                            fields: ['val'],
                            data : Ext.exampledata.issue_type // from titles array above
                        }),
						
                        valueField:'val',
                        displayField:'val',
                        typeAhead: true,
                        mode: 'local',
						editable: false,
                        triggerAction: 'all',
                        emptyText:'Select a Area of Problem...',
                        selectOnFocus:true,
						allowBlank:false,
                        width:250
                    }),
					new Ext.form.ComboBox({
                        fieldLabel: 'Browser Used ',
                        hiddenName:'txtbrowser',
                        store: new Ext.data.SimpleStore({
                            fields: ['val'],
                            data : Ext.exampledata.browser_type // from titles array above
                        }),
						
                        valueField:'val',
                        displayField:'val',
                        typeAhead: true,
                        mode: 'local',
						editable: false,
                        triggerAction: 'all',
                        emptyText:'Select which browser you are using...',
                        selectOnFocus:true,
						allowBlank:false,
                        width:250
                    }), 
					new Ext.form.TextArea({
                        fieldLabel: 'Description',
                        name: 'txttext',
						id: 'txttext',
						allowBlank:false,
						maxLength: '5000',
                        width:500,
                        height: 150
                    })
                ]
            })
        ]
    });
}

    // explicit add
    var submit = fs.addButton({
        text: 'Submit',
        handler: function(){
            fs.getForm().submit({url: SITE_URL+'contact_us/', waitMsg:'Please Wait...'});
			//Ext.MessageBox.alert('Status', 'This form will be redirected to third party software.');
        }
    });

    fs.render('form_contactus');

    fs.on({	
        actioncomplete: function(form, action){
            if(action.type == 'submit'){
                 form.reset();
if(person_id == '0')
{
				 Ext.MessageBox.alert('Status', 'Thank you for sending a message to the site team. We will get back to you soon.');
}
else
{
				 Ext.MessageBox.alert('Status', 'Thank you for sending your message to the site team. We will get back to you soon.');
}
            }
        },
		 actionfailed: function(form, action){
            if(action.type == 'submit'){
				Ext.MessageBox.alert('Error', 'Please correct the errors specified in Red.');
			}
		}
    });

});

// A reusable error reader class for XML forms
Ext.form.XmlErrorReader = function(){
    Ext.form.XmlErrorReader.superclass.constructor.call(this, {
            record : 'field',
            success: '@success'
        }, [
            'id', 'msg'
        ]
    );
};
Ext.extend(Ext.form.XmlErrorReader, Ext.data.XmlReader);