<?php require "_headerhome.php";?>
<?php
$t=1 ;
if($_REQUEST['verr']=="Invalid")
{
  $t=0;
}
?>
<!-- start custom CSS/JS -->
<script type="text/javascript">

var resbool = "";

Ext.onReady(function() { 
	
	Ext.QuickTips.init();
		 		
	var forgotpass = new Ext.FormPanel({
        labelWidth: 90, // label settings here cascade unless overridden
        url:'data/recover-password.php',
		method:'post',
        frame:true,
		standardSubmit:false,
        title: 'Recover Password',
		forceLayout: true,
        bodyStyle:'padding:6px 6px 0',
        width: 350,
		defaultType: 'textfield',
                items :[

					   {	
					   		xtype: 'textfield',
				            fieldLabel: 'User Name',
				            name: 'username',
							emptyText: 'User Name',
							width:190,
						    allowBlank:false
					   },
					   {
							fieldLabel:'School Email',
							name:'email',
							width:190,
							emptyText: 'School Email',
							vtype:'email',
							allowBlank:false
						}
					],
				    buttons:[						
						{

							text: 'Get Password',
							name:'btnSave',
							id:'btnSave',
							handler: function(){
							var varusername=forgotpass.getForm().findField('username').getValue();
		
							var varemail=forgotpass.getForm().findField('email').getValue();	
							
							Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
								 url:'data/recover-password.php',
							  	params: {username: varusername, email: varemail},
							  	success: function(resp) {
								resbool=Ext.decode(resp.responseText).success;	
								
										if(resbool=='false')
										{
										    Ext.MessageBox.show({
											   title: 'Error',
											   msg: 'Invalid User ID or School Email.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.ERROR
				                      			 });
										}
										if(resbool=='true')
										{
										     Ext.MessageBox.show({
											   title: 'Message',
											   msg: 'Login details successfully sent.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.INFO
				                     		  });
										}
									 			
							  }				
							});
												
							}
												
						},
					   	{
						text: 'Reset',
						name:'btnReset',
						id:'btnReset',
							handler: function (){
									forgotpass.getForm().reset();
							}
						},
						{
						text: 'Close',
						name:'btnCancel',
						id:'btnCancel',			
						handler: function (){
							location.href="index.php";
							}
						}
					 ]	
						   
    });	
	
	
		
    forgotpass.render('abcd');
	
	//////// username validation onblur event
	forgotpass.getForm().findField('username').on('blur',function (){
		
	var varusername=forgotpass.getForm().findField('username').getValue();			
	var resbool="";		
				
		if(varusername!="")
		{			
					Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
							  url: 'data/checkuserid.php',
							  params: {username: varusername},//, school_id: schoolid,userid : user_id
							  success: function(resp) {
								// resp is the XmlHttpRequest object
								resbool=Ext.decode(resp.responseText).success;			                     
							
							  
										if(resbool=='false')
										{
											Ext.MessageBox.show({
											   title: 'Error',
											   msg: 'User ID does not exist.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.ERROR
					                       });
											forgotpass.getForm().findField('username').reset();
										}	 			
							  }				
							});		
		}
		else
		{
		}			
			}); //blur event

//////// school email validation onblur event
	forgotpass.getForm().findField('email').on('blur',function (){
		
	var varemail=forgotpass.getForm().findField('email').getValue();			
		
	
		
		var resbool="";		
				
		if(varemail!="")
		{			
					Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
							  url: 'data/checkschoolemail.php',
							  params: {emailid: varemail},//, school_id: schoolid,userid : user_id
							  success: function(resp) {
								// resp is the XmlHttpRequest object
								resbool=Ext.decode(resp.responseText).success;			                     
							
							  
										if(resbool=='false')
										{
											Ext.MessageBox.show({
											   title: 'Error',
											   msg: 'School Email does not exist.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.ERROR
					                       });
											forgotpass.getForm().findField('email').reset();
										}	 			
							  }				
							});		
		}
		else
		{
		}			
			}); //blur event

});

</script>
<!-- end custom CSS/JS -->
<div align="center">
<div id="abcd" align="center">
</div>
</div>
<?php require "_footerhome.php";?>