Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var forgotwin;
var forgot;
var register;
var fform;
var mygrid;
var detailPanel;
var confrim_form;
var confrimwin;
var ResumeCreateForm;
var resumewin;
var resume;
var user;
var position;
var qualification;
var jobtype;
var experience;
var confirm_pwd;
var	confirm_user;
var resumedatastore;
var ResumeColumnModel;
var ResumeGrid;
var ResumeCreateForm;
Ext.onReady(function() {
    Ext.QuickTips.init();
	Ext.override(Ext.form.DisplayField, {
		getValue : function(){
			return this.value;
		},
		setValue : function(v){
			this.value = v;
			this.setRawValue(this.formatValue(v));
			return this;
		},
		formatValue : function(v){
			if(this.dateFormat && Ext.isDate(v)){
				return v.dateFormat(this.dateFormat);
			}
			if(this.numberFormat && typeof v == 'number'){
				return Ext.util.Format.number(v, this.numberFormat);
			}
			return v;
		}
	});
	Ext.apply(Ext.form.VTypes, {
	   document: function(v) {
		  return /^.*.(doc|docx|txt)$/.test(v);
	   }
	});

	
	function confirmjob()
	{	var error='';
		if ( confirm_user.getValue()=='' )
		{
			error=1;
		}
		if (confirm_pwd.getValue()=='')
		{
			error=1;
		}
		if(	error=='')
		{	
			Ext.Ajax.request({  
				 waitMsg: 'Please Wait',
				 url: 'pages/index/db_memberlogin_confirm.php', 
				 params: {	task:'login',
							confirm_user:confirm_user.getValue(),
							confirm_pwd:confirm_pwd.getValue(),
							jobsid: jobdetailID.getValue()
						 },
				success:function(response)
				{ 		
					var result=eval(response.responseText);
					switch(result){
					case 1:
							resumedatastore.load();	
							resumewin.show();
							break;
					case 2: 
								Ext.MessageBox.confirm('Dear Candidate', 'Please spare 3 minutes to fill in your particulars as in qualification and work experiences in your profile page <b> qualification  and experiences tab </b>for faster processing of your job application.<br/> Thank you.',keyindetail);
								break;
					default:
						  Ext.MessageBox.alert('Error','Could not create');
						  break;
					}
				},
				failure:function(response) {Ext.MessageBox.alert('Message', 'Login failed');}
			});		
		}
		if (error==1)
		{	Ext.MessageBox.alert('Message', 'Please Log In First.');}
	}
	
	
	var mydatastore = new Ext.data.Store({
		id: 'mydatastore',
		name: 'mydatastore',
		proxy: new Ext.data.HttpProxy({
				url: 'pages/index/db_search.php',
				method:'POST'
			}),
		baseParams:{task:'LISTING'},
		reader: new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id:'job_id',
		remoteSort:true
	},	
	[	{name: 'job_id', type: 'int', mapping: 'id'},
		{name: 'job_position', type: 'string', mapping: 'position'},
		{name: 'job_function', type: 'string', mapping: 'category'},
		{name: 'job_experience', type: 'string', mapping: 'experience'},
		{name: 'job_qualification', type: 'string', mapping: 'qualification'},
		{name: 'job_country', type: 'string', mapping: 'country'},
		{name: 'job_roadname', type: 'string', mapping: 'roadname'},
		{name: 'job_type', type: 'string', mapping: 'jobtype'},
		{name: 'job_responsibilities', type: 'string', mapping: 'responsibilities'},
		{name: 'job_minpay', type: 'string', mapping: 'minpay'},
		{name: 'job_maxpay', type: 'string', mapping: 'maxpay'},
		{name: 'job_workhrsnormstart', type: 'string', mapping: 'workhrsnormstart'},
		{name: 'job_workhrsnormend', type: 'string', mapping: 'workhrsnormend'},
		{name: 'job_workhrssatstart', type: 'string', mapping: 'workhrssatstart'},
		{name: 'job_workhrssatend', type: 'string', mapping: 'workhrssatend'},
		{name: 'job_alternatesat', type: 'string', mapping: 'alternatesat'},
		{name: 'job_orderdate', type: 'date',dateFormat:'c',  mapping: 'joborderdate'}
			
    ]),
		sortInfo:{field: 'job_orderdate', direction: "DESC"}
		
	});
		var column= new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),						
			{	header: 'Job Position',
				sortable:true,
				dataIndex: 'job_position',
				css:'white-space:normal;font-weight:bold;',
				renderer:  function(value, cell,record){ 
					return '<a href="pages/index/jobdetail.php?id='+ record.data['job_id']+ '" target="_blank"  style="color:#000144">'+ value  +'</a>';
				}
			},
			{	header: 'Job Function',
				sortable:true,
				dataIndex: 'job_function'
			},
			{	header: 'Job Experience',
				sortable:true,
				dataIndex: 'job_experience'
			},
			{	header: 'Job Type',
				sortable:true,
				dataIndex: 'job_type'
			},
			{	header: 'Location',
				sortable:true,
				dataIndex: 'job_roadname'
			},
			{	header: 'Job Order Date',
				sortable:true,
				dataIndex: 'job_orderdate',
				renderer: function(value, cell){ 
				 value = new Date(value).format('d-m-Y H:i:s');
				 return value;
				}
			}
		]);
		mygrid = new Ext.grid.GridPanel({
			store: mydatastore,
			id: 'mygrid',
			frame:false,
			colModel:column,
			stripeRows: true,
			loadMask:true,
			split:true,
			region: 'center',
			iconCls: 'icon-grid',
			rowSelector : 'div.x-grid3-row',
			Layout:'fit',
			viewConfig: {
				enableRowBody:true,
				forceFit:true,
				getRowClass : function(record, rowIndex, p,store)
				{	if(this.showPreview)
					{	p.body = '<p style=\"padding-left:18px\";>&nbsp;'+'Job Function:'+record.data.job_function+'<br/>&nbsp;Job Experience:&nbsp;'+record.data.job_experience+'</p>';
						return 'x-grid3-row-expanded';
					}
					return 'x-grid3-row-collapsed';
					
				}
			},
			listeners: {
			afterrender: function(c){
					if(scatid!="" || scatid!=0)
					{	mydatastore.baseParams = {task:'SEARCHCATEGORY',category: scatid};
						mydatastore.load({params:{start: 0,limit: 20,task:'SEARCHCATEGORY',category: scatid}});
						jobdetailform.getForm().reset();
						confrim_form.getForm().reset();
					} 
					else if (basicpos!="")
					{
						mydatastore.baseParams = {task:'SEARCH',query: basicpos};
						mydatastore.load({params:{start: 0,limit: 20,task:'SEARCH',query: basicpos}});
						jobdetailform.getForm().reset();
						confrim_form.getForm().reset();
					}
					else
					{
						mydatastore.load({params:{start: 0, limit: 20}});
					}
				}
			}
			
		});
		
	
		mygrid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) 
		{	Ext.getCmp('detailPanel').expand();
			jobdetailform.getForm().loadRecord(r);
			confrim_form.getForm().loadRecord(r);
			Ext.getCmp('btn-applyjob').setDisabled(false);
			Ext.getCmp('btn-applyjob').addClass('x-btn-pressed');
			if ( jobdetailworkhrssatalt.getValue ()==1)
			{	Ext.getCmp('jobdetailworkhrssatalt').show();
				Ext.getCmp('jobdetailworkhrssat').hide();
				var satstart=Ext.getCmp('job_workhrssatstart').getValue();
				var satend=Ext.getCmp('job_workhrssatend').getValue();
				Ext.getCmp('job_workhrssatend1').setValue(satend);
				Ext.getCmp('job_workhrssatstart1').setValue(satstart);
			}	
			var encoded_jobid = r['data']['job_id'];
			Ext.Ajax.request({  
				 waitMsg: 'Please Wait',
				 url: 'pages/index/db_memberlogin_confirm.php', 
				 params:{jobsid: encoded_jobid }
			});
		});
		
		
		var jobdetailID = new Ext.form.Hidden({
			id: 'jobdetailID',
			name: 'job_id',
			fieldLabel: '',
			anchor : '90%'
		});
		var jobdetailPosition = new Ext.form.DisplayField({
			id: 'jobdetailPosition',
			name: 'job_position',
			fieldLabel: '<b>Position</b>',
			labelSeparator:'',
			readOnly : true,
			anchor : '90%'
		}); 
		var jobdetailfunction = new Ext.form.DisplayField({
			id: 'jobdetailfunction',
			name: 'job_function',
			fieldLabel: '<b>Job Function</b>',
			labelSeparator:'',
			readOnly : true,
			anchor : '90%'
		}); 
		var jobdetailexperience = new Ext.form.DisplayField({
			id: 'jobdetailexperience',
			name: 'job_experience',
			fieldLabel: '<b>Experience</b>',
			labelSeparator:'',
			readOnly : true,
			anchor : '90%'
		});
		var jobdetailqualification = new Ext.form.DisplayField({
			id: 'jobdetailqualification',
			name: 'job_qualification',
			fieldLabel: '<b>Qualification</b>',
			labelSeparator:'',
			readOnly : true,
			anchor : '90%'
		});
		var jobdetailtype = new Ext.form.DisplayField({
			id: 'jobdetailtype',
			name: 'job_type',
			fieldLabel: '<b>Job Type</b>',
			readOnly : true,
			labelSeparator:'',
			anchor : '90%'
		});
		var jobdetailcountry = new Ext.form.DisplayField({
			id: 'jobdetailcountry',
			name: 'job_country',
			fieldLabel: '<b>Country</b>',
			readOnly : true,
			labelSeparator:'',
			anchor : '90%'
		});
		var jobdetailrequirement = new Ext.form.DisplayField({
			id: 'jobdetailrequirement',
			name: 'job_responsibilities',
			fieldLabel: '<b>Requirements & Responsibilities</b>',
			readOnly : true,
			autoWidth:true,
			autoHeight:true,
			labelSeparator:'',
			cls:'jobdescription'
		});
		var jobdetailorderdate = new Ext.form.DisplayField({
			id: 'jobdetailorderdate',
			name: 'job_orderdate',
			fieldLabel: '<b>Date Posted</b>',
			readOnly : true,
			labelSeparator:'',
			anchor : '90%',
			formatValue: Ext.util.Format.dateRenderer('d-m-Y H:i:s')
			
		});
		var jobdetailroadname = new Ext.form.DisplayField({
			id: 'jobdetailroadname',
			name: 'job_roadname',
			fieldLabel: '<b>Location</b>',
			readOnly : true,
			labelSeparator:'',
			anchor : '90%'
			
		});
		var jobdetailworkhrsnorm = new Ext.form.CompositeField({
			id: 'jobdetailworkhrsnorm',
			name: 'jobdetailworkhrsnorm',
			labelSeparator:'',
			fieldLabel: '<b>Mon-Fri</b>',
			readOnly : true,
			items:[
						
							{  xtype: 'displayfield',
                               name:'job_workhrsnormstart',
							   id:'job_workhrsnormstart',
							   value:'',
							   width:55
							},
							{	xtype: 'displayfield',
                                value: '-'
							},
						    {
                               xtype: 'displayfield',
                               name:'job_workhrsnormend',
							   id:'job_workhrsnormend',
							   value:''
							   
							}
												
			
			]
		
		});
		
		var jobdetailworkhrssat = new Ext.form.CompositeField({
			id: 'jobdetailworkhrssat',
			name: 'jobdetailworkhrssat',
			fieldLabel: '<b>Saturday</b>',
			labelSeparator:'',
			readOnly : true,
			items:[			{  xtype: 'displayfield',
                               name:'job_workhrssatstart',
							   id:'job_workhrssatstart',
							   value:'',
							   width:55
							},
							{  xtype: 'displayfield',
                               value: '-'
							},
						    {  xtype: 'displayfield',
                               name:'job_workhrssatend',
							   id:'job_workhrssatend',
							   value:''
							} 
				]
		
		});
		
		var jobdetailworkhrssatalt = new Ext.form.CompositeField({
			id: 'jobdetailworkhrssatalt',
			name: 'job_alternatesat',
			hidden:true,
			labelSeparator:'',
			fieldLabel: '<b>Alternate Saturday</b>',
			readOnly : true,
			items:[			{  xtype: 'displayfield',
                               name:'job_workhrssatstart1',
							   id:'job_workhrssatstart1',
							   width:55
							},
							{  xtype: 'displayfield',
                               value: '-'
							},
						    {  xtype: 'displayfield',
                               name:'job_workhrssatend1',
							   id:'job_workhrssatend1'
							  } 
				]
		
		});
		
		
		var jobdetailsalary= new Ext.form.CompositeField({
			id:'jobdetailsalary',
			name:'jobdetailsalary',
			labelSeparator:'',
			fieldLabel:'<b>Salary Range(S$)</b>',
			items:[			{  xtype: 'displayfield',
							   name:'job_minpay',
							   id:'job_minpay',
							   value:'',
							   width:35
							},
							{  xtype: 'displayfield',
                               value: '-'
							},
						    {  xtype: 'displayfield',
                               name:'job_maxpay',
							   id:'job_maxpay',
							   value:''
							}
			]
		
		
		});
		// var media=new Ext.BoxComponent({
			// id: 'media',
			// html:"",
			// contentEl:'addthis'
		// });
		var jobdetailform = new Ext.FormPanel({
			id:'jobdetailform',
			name:'jobdetailform',
			width:550,
			region:'center',
			border:true,
			labelWidth:100,
			labelAlign:'top',
			bodyStyle:'padding: 5px 10px 0',
			layout:'column',
			items:[	{	columnWidth:0.5,
						border:false,
						layout:'form',
						items:[jobdetailPosition]
					},
					{	columnWidth:0.5,
						border:false,
						layout:'form',
						items:[jobdetailorderdate]
					},
					{	columnWidth:1.0,
						border:false,
						layout:'form',
						items:[jobdetailrequirement]
					}
				]
		
		});
		var confirmregister=new Ext.form.DisplayField({
			id:'confirmregister',
			name:'confrimregister',
			hideLabel:true,
			value:'New Job Seeker <a href="pages/jobseeker/register/jobseeker.php"  style="color:Green">Click Here!</a>',
			cls:'jobseekercls1'
		});
		var	confirmforgot = new Ext.form.DisplayField({
			value:'Forgot Password',
			name: 'confirmforgot',
			id:'confirmforgot',
			labelSeparator:'',
			cls:'forgotpointer1',
			hideLabel:true,
			listeners: {
			render: function(c){
					  c.getEl().on('click', function(){
						forgotwin.show();
					  }, c);
				}
			}
		});
			
		confirm_user=new Ext.form.TextField({
			fieldLabel: 'Email',
			name: 'confirm_user',
			id: 'confirm_user',
			allowBlank:false,
			vtype:'email',
			width:150,
			listeners:{
			specialkey: function(f,e)
			  {	if (e.getKey() == e.ENTER) 
				 {	 
					Ext.getCmp('confirm_pwd').focus('', 10);  
                 }
              }
			
			}
		});
		confirm_pwd=new Ext.form.TextField({
			fieldLabel: 'Password',
			inputType:'password',
			width:150,
			allowBlank:false,
			name: 'confirm_pwd',
			id: 'confirm_pwd',
			listeners: {
              specialkey: function(f,e){
                if (e.getKey() == e.ENTER) 
				{	var error='';
					if ( confirm_user.getValue()=='' )
					{
						error=1;
					}
					if (confirm_pwd.getValue()=='')
					{
						error=1;
					}
					if(	error=='')
					{	
						Ext.Ajax.request({  
							 waitMsg: 'Please Wait',
							 url: 'pages/index/db_memberlogin_confirm.php', 
							 params: {	task:'login',
										confirm_user:confirm_user.getValue(),
										confirm_pwd:confirm_pwd.getValue(),
										jobsid: jobdetailID.getValue()
									 },
							success:function(response)
							{ 		
								var result=eval(response.responseText);
								switch(result){
								case 1:
										resumedatastore.load();	
										resumewin.show();
										confirm_user.reset();
										confirm_pwd.reset();
										break;
								case 2: 
											Ext.MessageBox.confirm('Dear Candidate', 'Please spare 3 minutes to fill in your particulars as in qualification and work experiences in your profile page <b> qualification  and experiences tab </b>for faster processing of your job application.<br/> Thank you.',keyindetail);
											confirm_user.reset();
											confirm_pwd.reset();
											break;
								default:
									  Ext.MessageBox.alert('Error','Could not create');
									  break;
								}
							},
							failure:function(response) {Ext.MessageBox.alert('Message', 'Login failed');}
						});		
					}
					if (error==1)
					{	Ext.MessageBox.alert('Message', 'Please Log In First.');}
							}
              }
            }
		});
		
		function keyindetail(btn)
		{
			if (btn=='yes')
			{
				var redirect = 'pages/jobseeker/editprofile/editcandidate.php'; 
				window.location = redirect;
			}
		
		}
		confrim_form = new Ext.FormPanel({
			id:'confirm_form',	
			labelWidth: 55,
			region:'south',
			bodyStyle:'margin-left:10px;padding:10px 10px;',
			width:550,
			autoHeight:true,
			waitMsgTarget: true,
			defaults:{msgTarget: 'side'},
			layout:'column',
			
			items: [
					{	columnWidth:0.25,
						layout:'form',
						border:false,
						labelAlign:'top',
						items:[		jobdetailID,
									jobdetailqualification,
									jobdetailexperience,
									jobdetailsalary,
									jobdetailworkhrsnorm
							  ]
					},
					{	columnWidth:0.25,
						layout:'form',
						labelAlign:'top',
						border:false,
						items:[	 jobdetailfunction,	 jobdetailtype, jobdetailroadname, jobdetailworkhrssat, jobdetailworkhrssatalt]
					},
					{	columnWidth:0.5,
						layout:'form',
						border:false,
						items:[		confirmregister,confirmforgot,confirm_user,confirm_pwd	],
						buttons: [	
							{
								text: 'Login',
								handler:confirmjob
							},
							{	text:'Reset',
								handler:function()
								{	confirm_user.reset();
									confirm_pwd.reset();
								}
							}						
						]	
					}
			
			]
		});
			
		var confrimPanel= new Ext.Panel({
			id:'confrimPanel',
			region:'south',
			items:[confrim_form]
		});
		var detailPanel=new Ext.Panel({
			id: 'detailPanel',
			region: 'east',
			frame:true,
			title:'Job Detail Information',
			width:600,
			split:true,
			autoScroll:true,
			bodyStyle: {background: '#ffffff'},
			collapseMode :'mini', 
			collapsible:true,
			collapsed:true,
			autoHide:false,
			items:[jobdetailform,confrimPanel],
			tbar:[ 	
					{	contentEl: 'addthis',
						xtype: "panel"
					},'->',
					{	text:'<b>Quick Apply</b>',
						id:'btn-applyjob',
						disabled:true,
						handler:function()
						{	var selected=mygrid.getSelectionModel().getSelected();
								var selections = mygrid.selModel.getSelections();
								if (!selected){
									Ext.MessageBox.show({
									   title: 'Information',
									   msg: 'Please select any Job',
									   buttons: Ext.MessageBox.OK,
									   icon:  Ext.MessageBox.INFO
								   });
								}
								else
								{	 Ext.Ajax.request({  
										 waitMsg: 'Please Wait',
										 url: 'pages/index/db_memberlogin_confirm.php', 
										 params: { 	  jobsid: jobdetailID.getValue() },
										 success: function(response)
										 {	var result=eval(response.responseText);
											switch(result)
											{	case 1:  
													resumewin.show();
													resumedatastore.load();
													break;
											    case 2:
													Ext.MessageBox.confirm('Dear Candidate', 'Please spare 3 minutes to fill in your particulars as in qualification and work experiences in your profile page <b> qualification  and experiences tab </b>for faster processing of your job application.<br/> Thank you.',keyindetail);
												break;
											    case 3:
													Ext.MessageBox.alert('Error','can not applied job.');
												break;
												case 1008: 	Ext.MessageBox.alert('Information','Your Session is already expired!'); 
															window.location='http://www.staffhub.com';
												break;
											    default://not login user
													Ext.getCmp('confirm_user').focus('', 10);  
												break;
											}
										 },
										failure: function(response){
											  var result=response.responseText;
											  Ext.MessageBox.alert('error','Could not connect to the database. Retry later');      
											} 
									});
								}
						}
					}
			]
		});
		
		var myinfo = new Ext.Panel({
			frame: false,
			autoWidth: true,
			height:498,
			layout: 'border',
			split:true,
			items: [	mygrid,detailPanel]		
			});
	
	 var pattern=new Ext.app.SearchField({
		store: mydatastore,
		width: 300,
		id:'pattern',
		name:'pattern',
		params:{start: 0, limit:20},
		listeners: 
		{	'render': function(c) 
			{	c.getEl().on('keypress', function(e) {
					if(e.getKey() == e.ENTER && this.getValue().length > 0) 
					{
						mydatastore.baseParams = {	 task:'SEARCH',pattern: document.getElementById('pattern').value};
						mydatastore.load({params: {start: 0, limit: 20}});											
					}
				});
			}
		}
	});
	
	var search_grid = new Ext.Panel({
         frame:false,
         xtype: 'form',
		 renderTo:'searchjob',
         id:'asset-form',
         collapsed: false,
         height:498,
		 width:970,
		 autoscroll:true,
		 layout:'fit',
		 items: [ myinfo ],
         tbar:[	'->',
					{	text: '<b>Detail</b>',
						handler: function(btn, pressed)
						{	
							mygrid.getColumnModel().setHidden(2,true);
							mygrid.getColumnModel().setHidden(3,true);
							mygrid.getColumnModel().setHidden(4,true);
							mygrid.getColumnModel().setHidden(5,true);
							mygrid.getColumnModel().setHidden(6,true);
							var view = mygrid.getView();
							view.showPreview = pressed;
							view.refresh();
						}	
					},'-',
					{	text:'<b>Column</b>',
							handler:function(btn,pressed)
							{	
								mygrid.getColumnModel().setHidden(2,false);
								mygrid.getColumnModel().setHidden(3,false);
								mygrid.getColumnModel().setHidden(4,false);
								mygrid.getColumnModel().setHidden(5,false);
								mygrid.getColumnModel().setHidden(6,false);
								var view=mygrid.getView();
								view.showPreview=false;
								view.refresh();
							}		
					},'-',
					new Ext.PagingToolbar({
						id:'bbar',
						pageSize: 20,
						store: mydatastore,
						displayInfo: true
					})
					
					
					 ]
				
		
            });
			
	resentform=new Ext.form.FormPanel({
			id:'resentform',
			name:'resentform',
			bodyStyle:'padding: 5px 5px 0',
			defaults:{msgTarget: 'side'},
			items:[
				resentuser=new Ext.form.TextField({
					fieldLabel: 'Email',
					name: 'resentuser',
					id: 'resentuser',
					allowBlank:false,
					vtype:'email',
					anchor:'90%',
					listeners: {
					  specialkey: function(f,e){
							if (e.getKey() == e.ENTER) 
							{	Ext.Ajax.request({  
										 waitMsg: 'Please Wait',
										 url: 'pages/jobseeker/register/resentactivationkey.php',
										 params: { 	  resentuser: resentuser.getValue() },
										 success: function(response)
										 {
											  var result=eval(response.responseText);
											  switch(result){
												  case 1:  
														Ext.MessageBox.alert('Thank you','Please proceed to your email account for notification. Kindly activate your account ASAP.Thank you.');
														resentform.getForm().reset();
														resentwin.close();
														break;
												  case 2:
														Ext.MessageBox.alert('No Password','Sorry Your address is not there in our database .You can signup and login to use our site.');
													break;
												 case 3:
														Ext.MessageBox.alert('Dear Candidate','Your Account in our database is already activated.Please Log in with your account and password.If you forgot the password, you can send to us by using forgot password.<br/>Thank you.');
														resentform.getForm().reset();
														resentwin.close();
														break;		
												  default://not login user
														Ext.MessageBox.alert('Error','Please Fill in the required Field');
													break;
											  }
										},
										failure: function(response){
										  var result=response.responseText;
										  Ext.MessageBox.alert('error','Could not connect to the database. Retry later');      
											} 
									});
							}
						}	
					}
				})
			],
			buttons: [
					{	text:'Send',
						handler:resentkey
					},
					{
						text: 'Close',
						handler: function(){
							forgotwin.hide();
							fform.getForm().reset();
							
						}
					}
				]
		
		});
	resentwin= new Ext.Window({
		layout:'fit',
		title:"Request for Activation Key",
		width:500,
		height:100,
		closeAction:'hide',
		plain: true,
		items:resentform
	});
	function resentkey()
	{
		Ext.Ajax.request({  
			 waitMsg: 'Please Wait',
			 url: 'pages/jobseeker/register/resentactivationkey.php',
			 params: { 	  resentuser: resentuser.getValue() },
			 success: function(response)
			 {
				  var result=eval(response.responseText);
				  switch(result){
					  case 1:  
							Ext.MessageBox.alert('Thank you','Please proceed to your email account for notification. Kindly activate your account ASAP.Thank you.');
							resentform.getForm().reset();
							resentwin.hide();
							break;
					  case 2:
							Ext.MessageBox.alert('No Password','Sorry Your address is not there in our database .You can signup and login to use our site.');
						break;
					  case 3:
							Ext.MessageBox.alert('Dear Candidate','Your Account in our database is already activated.Please Log in with your account and password.If you forgot the password, you can send to us by using forgot password.<br/>Thank you.');
							resentform.getForm().reset();
							resentwin.hide();
						break;		
					  default://not login user
							Ext.MessageBox.alert('Error','Please Fill in the required Field');
						break;
				  }
			},
			failure: function(response)
			{
				  var result=response.responseText;
				  Ext.MessageBox.alert('error','Could not connect to the database. Retry later');      
			} 
		});
	
	}		
			
	
	resumedatastore = new Ext.data.Store({
      id: 'resumedatastore',
      proxy: new Ext.data.HttpProxy({
                url: 'pages/jobseeker/Resume/db_resume.php', 
                method: 'POST'
            }),
            baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request
      reader: new Ext.data.JsonReader({
        root: 'results',
        totalProperty: 'total',
        idProperty:'id'
      },[ 
        {name: 'id', type: 'int', mapping: 'id'},
		{name: 'candidate_id', type: 'int', mapping: 'candidate_id'},
		{name: 'createdate', type: 'string', mapping: 'createdate'},
        {name: 'attachpath', type: 'string', mapping: 'attachpath'},
        {name: 'description', type: 'string', mapping: 'description'},
        {name: 'maindefault', type: 'int', mapping: 'maindefault'}
      ]),
      sortInfo:{field: 'id', direction: "ASC"}
    });
	ResumeColumnModel = new Ext.grid.ColumnModel(
    [	new Ext.grid.RowNumberer(),
		{	header: 'Resumes',	dataIndex: 'attachpath',width: 200},
		{	header: 'Description',dataIndex: 'description',width: 210 },
		{	header: 'Main Resume',dataIndex: 'maindefault',width: 210 },
		{	header: 'Created Date',dataIndex: 'createdate',width: 200}
		
	] );
    ResumeColumnModel.defaultSortable= true;
	ResumeGrid = new Ext.grid.GridPanel({
		id:'ResumeGrid',
		stripeRows: true,
		autoWidth:true,
		height:200,
		region:"center",
		frame:true,
		store: resumedatastore,
		cm:ResumeColumnModel,
		sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) {
                           resume=rec;
						   Ext.getCmp('applybtn').setDisabled(false);
                        }
						 
                    }
                }),
		viewConfig:{ forceFit:true,autoFill:true},
		Layout:'fit',
		tbar:[	'->',
				{	text:'<b>Apply Job</b>',
					id:'applybtn',
					cls:'x-btn-pressed',
					disabled:true,
					handler:confrimresume 
				}	
			]
		
	});
	
	var jobcatdatastore = new Ext.data.JsonStore({
		url: 'shared/dropdown/dropdown.php?tabledisp=jobcategory',
		fields:[	
			{name: 'id'},
			{name: 'category'}
			]
	});
	jobcatdatastore.load();	
	
	var rid=new Ext.form.Hidden({
		id:'rid',
		name:'rid',
		anchor:'90%',
		fieldLabel:'resume ID'
	});
	var cid=new Ext.form.Hidden({
		id:'cid',
		name:'candidate_id',
		anchor:'90%',
		fieldLabel:'Candidate ID'
	});
	var description=new Ext.form.TextField({
		id:'description',
		name:'description',
		anchor:'90%',
		fieldLabel:'Resume Description',
		allowBlank:false
	});
	var jobcategory = new Ext.form.ComboBox({
		id: 'jobcategory',
		name: 'rscateid',
		fieldLabel: 'Job Function',
		fields: ['id', 'category'],
		mode:'local',
		store: jobcatdatastore,
		valueField:'id',
		displayField:'category',
		triggerAction: 'all',
		selectOnFocus:true,
		allowBlank: false,
		blankText:'Please select',
		autoSelect:true,
		autoLoad:true,
		forceSelection:true,
		anchor : '90%'	
	});
	var	defaultresume=new Ext.form.Checkbox({
		name:'maindefault',
		id:'maindefault',
		fieldLabel:'Main Resume'
	});
	ResumeCreateForm = new Ext.FormPanel({
		id:'ResumeCreateForm',
		name:'ResumeCreateForm',
		fileUpload: true,
		title:'Upload New Resume',
		autoHeight: true,
		autoWidth:true,
		collapsed:false,
		collapseMode:'mini',
		labelWidth: 120,
		border:false,
		bodyStyle:'padding:5px 5px;',	
		defaults: {
			allowBlank: false,
			anchor: '90%',
			msgTarget: 'side'
		},
		items:
		[ 	rid,cid,description,
			{	xtype: 'fileuploadfield',
				fieldLabel: 'Upload Resume',
				buttonText: 'Select a File',
				name: 'attachpath1',
				id: 'form-file-2',
				emptyText: 'Select a document to upload...',
				anchor:'90%',
				vtype:'document',
				vtypeText: 'File must be doc|docx|txt',
				allowBlank:false
			},jobcategory,defaultresume
		],
		tbar: [	'->',
				{	text: '<b>Save</b>',
					id:'cr-savebtn',
					handler: function()
					{	var mainresume;
						if ((defaultresume.getValue())!='')
						{ mainresume=1;	}	
						else{	mainresume=0;}
							
							if (ResumeCreateForm.getForm().isValid())
							{
								ResumeCreateForm.getForm().submit({
									url: 'pages/jobseeker/Resume/db_resume.php',
									params:{	task:'CREATE',
												main: mainresume,
												jobcategory:jobcategory.getValue()
											},
									waitMsg: 'Saving Data and Uploading file ...',
									success: function(form,action)
									{
										 Ext.MessageBox.alert('Success', 'Processed file on the server');
										 ResumeCreateForm.getForm().reset();
										 resumedatastore.reload();
										 
									},
									failure:function(form, action) 
									{	
										if(action.response.responseText == '{success:false,errors:{ufile:"File size is too big"}}')
										{
										  Ext.MessageBox.alert('Message','Resume File size is too big. Maximum file size is 1MB.');
										}
										if(action.response.responseText == '{success:false,errors:{description:"Maximum of total resume is 8 resume."}}')
										{
										  Ext.MessageBox.alert('Message','Maximum of total resume is 8 resumes.If you want to add new resume, please delete old resumes first.');
										}
										if(action.response.responseText == '{success:false,errors:{ufile:" File has error" }}')
										{
											Ext.MessageBox.alert('Message','Upload resume file size has error. try again !');
										}
										if (action.response.responseText == '1008') 
										{
											Ext.MessageBox.alert('Information','Your Session is already expired!'); 
											window.location='http://www.staffhub.com';
										}
										
									}
									
								});
							}
							else
							{	Ext.MessageBox.alert('Error', 'Please Fill in the required fields.');}
					}
				},'-',
				{	text: '<b>Cancel</b>',
					handler: function(){	ResumeCreateForm.getForm().reset();	 }
				}
				]	
					
					
					
				
	});
	  
	function confrimresume()
	{
		if(ResumeGrid.selModel.getCount() == 1) 
		{
		  Ext.MessageBox.confirm('Confirmation','Before you confirm Quick Apply to this job vacancy,<br/>1.Have you read the job description & requirements?<br/>2.Are you comfortable with the job and the location?<br/>Click here to confirm your job application.', applyResume);
		 
		} else if(ResumeListingEditorGrid.selModel.getCount() > 1){
		  Ext.MessageBox.confirm('Information','You can choose one resume', applyResume);
		} else {
		  Ext.MessageBox.alert('Please select before applying.');
		}
	}  

	function applyResume(btn)
	{		
		if (btn=="yes")
		{
			var selected=ResumeGrid.getSelectionModel().getSelected();
			var selections = ResumeGrid.selModel.getSelections();
			if (!selected){
				Ext.MessageBox.show({
				   title: 'Information',
				   msg: 'Please select any JoB!',
				   buttons: Ext.MessageBox.OK,
				   icon:  Ext.MessageBox.INFO
			   });
			}else
			{	
				
				var encoded_resumeid =selected.id;
				 Ext.Ajax.request({  
				 waitMsg: 'Please Wait',
				 url: 'pages/index/applyjob_confirm.php', 
				 params:{task:"applyjob" ,
						resume:encoded_resumeid	}, 
				success: function(response){
				  var result=eval(response.responseText);
				  switch(result){
				  case 1:  // Success : simply reload
					resumewin.hide();
					var redirect = 'pages/jobseeker/applicationlist/applicationlist.php'; 
					window.location = redirect;
					break;
				  case 2:
					Ext.MessageBox.alert('Information','You already applied to this position.');
					resumewin.hide();
					break;
				  case 1008: 	Ext.MessageBox.alert('Information','Your Session is already expired!'); 
								window.location='http://www.staffhub.com';
								break;
				 default:
						Ext.MessageBox.alert('Error','Can not applied job.');
					break;
				  
				  }
				},
				failure: function(response){
				  var result=response.responseText;
				  Ext.MessageBox.alert('error','Could not connect to the database. Retry later');      
					}
				});
			}
		}	
	}
	media2=new Ext.BoxComponent({
		id:'media2',
		name:'media2',
		region:'west',
		height: 58 // give north and south regions a height
		//contentEl:'media'
	}); 
	var item2 = new Ext.Panel({
		title: 'Resume',
		autoWidth:true,
		autoHeight:true,
		titleCollapse: false,
		items:[ResumeGrid,ResumeCreateForm]
	});
	var accordion = new Ext.Panel({
		margins:'5 0 5 5',
		split:true,
		frame:true,
		autoWidth:true,
		autoHeight:true,
		layout:'form',
		items: [item2]
	});
	 resumewin= new Ext.Window({
				layout:'fit',
				title:'Select Resume',
                width:700,
                height:440,
                closeAction:'hide',
				constrainHeader:true,
                plain: true,
				items:[accordion]
				
	});
	
	

}); 

	



