<?php require "_headerhome.php";?>
<?php
	$t=1 ;
	if($_REQUEST['verr']=="Invalid"){
	  $t=0;
	}
?>

<!-- start custom CSS/JS -->
<script type="text/javascript">
Ext.onReady(function(){						
	
	if(<?php echo $t ?> == 0) {
    		
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Invalid User Name or Password',
			   buttons: Ext.MessageBox.OK,
			   icon:Ext.MessageBox.ERROR
			});
			
    }	
	Ext.QuickTips.init();
	

	
	var yearstore = new Ext.data.Store({
			url: 'data/getlistyear.php', 
	        reader: new Ext.data.JsonReader({			
                fields: ['year_id','year_name','year_active'],
                root: 'rows1'
            }),autoLoad:true
        });    
	
	var forgotPasswordPnl = new Ext.XTemplate(
    	'<div align="right"><a href="forgot-password.php">forgot password?</a></div>'
	);

    var simpleForm = new Ext.FormPanel ({
    	layout: 'form',	
       	url:'logincheck.php',	// when this form submitted, data goes here
        method:'post',
		standardSubmit:true,
		frame:true,
		labelWidth:70,
		autoHeight:true,
		/*style:'padding-Top:90px;padding-right:0px;', */
       // width: 350, 
		items: [
			{
     	       	items: [
					{
			  			layout : 'column',
					    items  : [ 
							{
								columnWidth: .30,
                          		layout: 'form',				
						  		items:[
									{ 
										xtype: 'box', 
										autoEl: 
										{ tag: 'div',
										  html: '<div align="left"><img  src="images/login.png" heigth="100" width="100" /></div>'
										}
									}
								]				
                           	},{
									xtype: 'textfield',
									name: 'yearname',
									id:'yearname',
									height:1,
									hidden: true
							},
							{
								columnWidth: 0.7,
                              	layout: 'form',					
								items:[{
										xtype: 'textfield',
										labelStyle:'font-weight: bold; color:#15428B',
										fieldLabel:'User Name',
										name:'userid',
										style:{margin:'0px 0px 0px 15px'},
										id:'userid',
										tabIndex: 1,
										width:120,
										allowBlank: false
									},
									{
										xtype : 'textfield',
										labelStyle:'font-weight: bold; color:#15428B',
										fieldLabel: 'Password',
										name: 'password',
										inputType:'password',
										tabIndex: 2,
										style:{margin:'0px 0px 0px 15px'},
										width:120,
										allowBlank: false,				
										listeners: {
											specialkey: function(f,e){
												if (e.getKey() == e.ENTER){
													formsubmit();
												}
											}
										}
               						},{  	
										xtype: 'combo',
										name: 'year_id1',
										hiddenName: 'year_hidden',
										labelStyle:'font-weight: bold; color:#15428B;',
										id:'year_id1',
										tabIndex: 3,
										hidden:true,
									//	fieldLabel: 'Year',
										style:{margin:'0px 0px 0px 15px'},
										//labelWidth:0,
										forceSelection:true,				
										displayField:'year_name',
										valueField: 'year_id',
										allowBlank:false,
										triggerAction:'all',
										mode:'local',
										store: yearstore,
										width:120,
										selectOnFocus: true,
										listeners:
											{
												specialkey: function(f,e)
												{
													if (e.getKey() == e.ENTER) 
													{		formsubmit();
													}
												}
											}
											
								},
								forgotPasswordPnl
								]
     						}
					  	]
			   		}
				]
			}	
		]
 
	});
		var loginWindow = new Ext.Window({
        title: 'Login',
		width:340,		
		//height:210,
		autoHeight:true,		
		closeAction:'close',
		closeable:false,
		collapsible:true,
		items: simpleForm,
		buttonAlign:'center',
		buttons: [
			{
				text: 'Login',
				iconCls:'icon-login',
				tabIndex: 4,
				width:60,
				handler: function(){
				
                 simpleForm.getForm().getEl().dom.action = 'logincheck.php';
							simpleForm.getForm().submit();  
				}
			},{
				text: 'Reset',
				iconCls:'icon-reset',
				width:60,
				handler: function(){simpleForm.getForm().reset();}
			}
		]

	});
	var varWidth =  (screen.width - loginWindow.width)/2;
	loginWindow.setPosition(varWidth,((screen.height/4)-30));
	loginWindow.show();
	if(<?php echo $t ?> == 0) {
    		
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: 'Invalid User Name or Password',
			   buttons: Ext.MessageBox.OK,
			   icon:Ext.MessageBox.ERROR
			});
			
    }	
	Ext.getCmp('userid').focus(true,500);

//loginForm.getForm().findField('userid').focus();
	simpleForm.render ('main-contenthome'); 

simpleForm.getForm().findField('userid').focus();

  yearstore.on({'load': {
	fn: function(store, options)
		{
	   		for(var i=0;i<yearstore.getCount();i++ )
		    {  
		  if(yearstore.getAt(i).data.year_active == 1)
		   { 
		
		      simpleForm.getForm().findField('year_id1').setRawValue(yearstore.getAt(i).data.year_name);
			   simpleForm.getForm().findField('year_id1').setValue(yearstore.getAt(i).data.year_id);
			    simpleForm.getForm().findField('yearname').setValue(yearstore.getAt(i).data.year_name);
		      break;
		   } 
		}
	  	}
    } 
	});  
	
function formsubmit()
	{
				    simpleForm.getForm().getEl().dom.action = 'logincheck.php';
							simpleForm.getForm().submit();  
					
	}
  });
</script>
<!-- end custom CSS/JS -->
<div align="center">
	<div id="main-contenthome" align="center" style="width:300px"></div>
</div>
<?php require "_footerhome.php";?>