<?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,
     	forceLayout: true,
		style:'padding-Top:90px;padding-right:0px;',
        bodyStyle:'padding:6px 6px 0',
        width: 350,
		defaultType: 'textfield',
                items :[

					   {	
					   		xtype: 'textfield',
				            fieldLabel: 'User Name',
				            name: 'username',
							labelStyle:'font-weight: bold; color:#15428B',
							emptyText: 'User Name',
							width:190,
						    allowBlank:false
					   },
					   {
							fieldLabel:'Email',
							name:'email',
							width:190,
							labelStyle:'font-weight: bold; color:#15428B',
							emptyText: 'Email',
							vtype:'email',
							allowBlank:false
						}
					],
					buttonAlign: 'center',
				    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 Name or Email ID.',
											   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";
							}
						}
					 ]	
						   
    });	
	
	
	
	/*var  AccountGroupWindow=new Ext.Window({
	   title: 'Recover Password',
		height     : 150,
		layout     : 'fit',
		labelWidth : 100,		
		width      : 360,
		modal:true,
		border: false,
		//closable   : true,
		collapsible:'true',
		bodyStyle  : 'padding: 5px',
		items      : forgotpass 
	});
	var varWidth =  (screen.width - AccountGroupWindow.width)/2;
AccountGroupWindow.setPosition(varWidth,((screen.height/4)-40));
AccountGroupWindow.show();*/
		
		forgotpass.render ('main-contenthome'); 

	//////// 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},//, company_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 Name 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();			
	if(varemail!="")
		{	
				if(varemail!='a@a.com')
				{
					Ext.MessageBox.show({
											   title: 'Error',
											   msg: 'Email does not exist.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.ERROR
					                       });
											forgotpass.getForm().findField('email').reset();
				}
		}									
	/*
		
		var resbool="";		
				
		if(varemail!="")
		{			
					Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
							  url: 'data/checkschoolemail.php',
							  params: {emailid: varemail},//, company_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>
<div align="center">
	<div id="main-contenthome" align="center" style="width:300px"></div>
</div>
<!-- end custom CSS/JS -->
<?php require "_footerhome.php";?>