Ext.onReady(function(){
	user=new Ext.form.TextField({
		fieldLabel: 'Email',
		name: 'user',
		id: 'user',
		allowBlank:false,
		vtype:'email',
		anchor:'90%',
		listeners:{
			specialkey: function(f,e)
			  {	if (e.getKey() == e.ENTER) 
				 {	 
					Ext.getCmp('pwd').focus('', 10);  
                 }
              }
			
		}
	});
	pwd=new Ext.form.TextField({
		fieldLabel: 'Password',
		inputType:'password',
		anchor:'90%',
		allowBlank:false,
		name: 'pwd',
		id: 'pwd',
		listeners: 
		{
              specialkey: function(f,e)
			  {
                if (e.getKey() == e.ENTER) 
				 {	 login_form.form.submit({
							url:'pages/index/db_memberlogin.php',
							"success":function(form,action){ 
								  var redirect = 'pages/jobseeker/editprofile/candidateprofile.php'; 
								  window.location = redirect;
							  },
							"failure":function(form, action) {
								Ext.MessageBox.alert('Message', 'Login failed');
							}
						});
						
                }
              }
        }
	});
	var lregister=new Ext.form.DisplayField({
						id:'lregister',
						name:'lregister',
						cls:'jobseekercls',
						hideLabel:true,
						value:'<a href="pages/jobseeker/register/jobseeker.php">New Job Seeker</a>'
					});
	
	function loginsent()
	{
		login_form.form.submit({
			url:'pages/index/db_memberlogin.php',
			"success":function(form,action){ 
				  var redirect = 'pages/jobseeker/editprofile/candidateprofile.php'; 
				  window.location = redirect;
			  },
			"failure":function(form, action) {
				Ext.MessageBox.alert('Message', 'Login failed');
			}
		});
	
	
	}
	
	lforgot = new Ext.form.DisplayField({
		value:'Forgot Password',
		name: 'lforgot',
		labelSeparator:'',
		cls:'forgotpointer1',
		hideLabel:true,
		listeners: {
		render: function(c){
				  c.getEl().on('click', function(){
					forgotwin.show();
					login_form.getForm().reset();
					loginwin.hide();
				  }, c);
			}
		}
	});
	lresent = new Ext.form.DisplayField({
		value:'Resend Activation Key',
		name: 'lforgot',
		labelSeparator:'',
		cls:'forgotpointer1',
		hideLabel:true,
		listeners: {
		render: function(c){
				  c.getEl().on('click', function(){
					resentwin.show();
					login_form.getForm().reset();
					loginwin.hide();
				  }, c);
			}
		}
	});
	
	login_form = new Ext.form.FormPanel({
		labelWidth: 55,
		width:375,
		//renderTo:'loginform',
		bodyStyle:'padding:10px 10px',
		frame: false,
		defaults:{msgTarget: 'side'},//,lregister,lresent
		items: [ user,pwd,
				{	layout:'column',
					items:[
							{	columnWidth:.4,
								layout:'form',
								border:false,
								items:[lforgot]
							},
							{	columnWidth:.1,
								layout:'form',
								border:false,
								items:[
									{	xtype:'displayfield',
										value:'|',
										cls:'loginsep',
										hideLabel:true
									}
								]
							},
							{	columnWidth:.4,
								layout:'form',
								border:false,
								items:[lresent]
							}
							
					]
				}
		
		 ],
		buttons: [	{	text: 'Login',
						handler:loginsent
					},
					{	text:'Reset',
						handler:function(){
							login_form.getForm().reset();
						}
							
					}
				]
	});
	
	loginwin= new Ext.Window({
		layout:'form',
		title:"JobSeeker Member Login ",
		width:385,
		height:170,
		closeAction:'hide',
		plain: true,
		items:login_form
	});
	
	function sendpassword()
	{
			if (fform.getForm().isValid())
			{
				Ext.Ajax.request({  
					 waitMsg: 'Please Wait',
					 url: 'pages/jobseeker/register/forgotfunc.php',
					 params: { 	  fuser: fuser.getValue() },
					 success: function(response)
					 {
						  var result=eval(response.responseText);
						  switch(result){
							  case 1:  
									Ext.MessageBox.alert('Thank you','Your password is posted to your emil address . Please check your mail after some time.');
									fform.getForm().reset();
									forgotwin.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;
							  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');      
						} 
								});
			}
			else{	Ext.MessageBox.alert('Error','Please fill in the required field.');}
		
		}
		
		
	 fform=new Ext.form.FormPanel({
			id:'fform',
			name:'fform',
			bodyStyle:'padding: 5px 5px 0',
			defaults:{msgTarget: 'side'},
			items:[
				fuser=new Ext.form.TextField({
					fieldLabel: 'Email',
					name: 'fuser',
					id: 'fuser',
					allowBlank:false,
					vtype:'email',
					anchor:'90%',
					listeners: {
					  specialkey: function(f,e){
							if (e.getKey() == e.ENTER) 
							{	if(fform.getForm().isValid())
								{	
									Ext.Ajax.request({  
										 waitMsg: 'Please Wait',
										 url: 'pages/jobseeker/register/forgotfunc.php',
										 params: { 	  fuser: fuser.getValue() },
										 success: function(response)
										 {
											  var result=eval(response.responseText);
											  switch(result){
												  case 1:  
														Ext.MessageBox.alert('Thank you','Your password is posted to your emil address . Please check your mail after some time.');
														fform.getForm().reset();
														forgotwin.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;
												  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');      
											} 
									});
								}
								else
								{	Ext.MessageBox.alert('Error','Please fill in the required field.');}
								
							}
						}	
					}
				})
			],
			buttons: [
					{	text:'Send',
						handler:sendpassword
					},
					{
						text: 'Cancel',
						handler: function(){
							forgotwin.hide();
							fform.getForm().reset();
							
						}
					}
				]
		
		});
	
	forgotwin= new Ext.Window({
		layout:'fit',
		title:"Forgot Password",
		width:500,
		height:100,
		closeAction:'hide',
		plain: true,
		items:fform
	});
	
	
	
	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) 
							{	
								if(resentform.getForm.isValid())
								{
									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');      
												} 
										});
								}
								else {
									Ext.MessageBox.alert('Error','Please Fill in the required Field');
								}
							}
						}	
					}
				})
			],
			buttons: [
					{	text:'Send',
						handler:resentkey
					},
					{
						text: 'Cancel',
						handler: function(){
							resentwin.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()
	{	if(resentform.getForm().isValid())
		{
			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');      
				} 
			});
		}else
		{	Ext.MessageBox.alert('Error','Please Fill in the required Field');}
	}
	
	


});	
