var jawin;

Ext.onReady(function(){
   
    var frmCreateJobAlert = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 350,
        autoHeight: true,
        items: [
        	{
				html: 	'<div id="createjobalertblurb">' +
						'To receive this job alert, please enter your email address.' +
						'</div>'
			},{
        		xtype:'textfield',
				fieldLabel: 'Email',
				allowBlank: false,
				name: 'email',
				vtype:'email',
				id: 'NewJobAlertEmail',
				anchor:'95%'
            },{
        		xtype:'textfield',
				fieldLabel: '',
				allowBlank: false,
				labelSeparator: '',
				name: 'search',
				id: 'NewJobAlertCriteria',
				hidden: true,
				anchor: '95%'
            },new Ext.form.ComboBox({
								        store: ['Daily', 'Weekly'],
								     	fieldLabel: 'Frequency',
								        typeAhead: true,
								        forceSelection: true,
								        triggerAction: 'all',
								        emptyText:'Select a frequency...',
								        selectOnFocus:true,
								        name:'frequency',
								        allowBlank:false,
								        forceSelection: true,
								        value: 'Daily',
								        width:150
								    })
        ],

        buttons: [{
            text: 'Create',
            handler: function()
            		{
            			frmCreateJobAlert.getForm().submit({
            									clientValidation: true,
							                    url: '/jobalert.php',
							                    success: function(form, action) {
							                    									Ext.Msg.alert("Success", "Job Alert Created");
							                    									jawin.hide();
																			    	
																			    },
											    failure: function(form, action) {
																					switch (action.failureType) {
																						case Ext.form.Action.CLIENT_INVALID:
																							Ext.Msg.alert("Failure", "Form fields may not be submitted with invalid values");
																							break;
																						case Ext.form.Action.CONNECT_FAILURE:
																							Ext.Msg.alert("Failure", "Ajax communication failed");
																							break;
																						case Ext.form.Action.SERVER_INVALID:
																						   Ext.Msg.alert("Failure", action.result.msg);
																						default : Ext.Msg.alert("Failure", action.result.msg);
																					}
																				}

							                });
            			
            		}
        },{
            text: 'Close',
            handler  : function(){
                        jawin.hide();
                    }
        }]
	});

	wirss = new Ext.Window({
		applyTo     : 'hello-win',
		layout      : 'fit',
		width       : 500,
		height      : 220,
		closeAction :'hide',
		plain       : true,
		items       : new Ext.Panel({
				applyTo        : 'hello-tabs',
				deferredRender : false,
				border         : false
			}),
		buttons: [{
				text     : 'Close',
				handler  : function(){
						wirss.hide();
					}
			}]
	});	
		
	jawin = new Ext.Window({
		layout      : 'fit',
		width       : 500,
		autoHeight : true,
		closeAction :'hide',
		plain       : true,
		title		: 'Create Job Alert',
		items		: frmCreateJobAlert
	});    

	// Ext.get('createjobalert').on('click', function( e ){ e.stopEvent(); jawin.show(); });	
	Ext.get('WhatIsRSS').on('click', function( e ){ e.stopEvent(); wirss.show(); });	
});



function create_job_alert( aSearch, aEmail )
{
	jawin.show();
	Ext.getDom('NewJobAlertCriteria').value = aSearch;
	Ext.getDom('NewJobAlertEmail').value = aEmail;
	// alert( 'Create alert '+aSearch );	
}
