<?php require "_headerhome.php";
require "data/combo_login.php";

$t = 1;
if ($_REQUEST['verr'] == "Invalid") {
	$t = 0;
}

?>
<!-- start custom CSS/JS -->

<script type="text/javascript">
	Ext.onReady(function () {

		//var yearstore = new Ext.data.ArrayStore({
		//	    fields: ['year_id','year_name','year_active'],
		//         data:Ext.login.year
		//     });  					
		if (<?php echo $t ?> == 0) {
			Ext.MessageBox.show({
				title: 'Error',
				msg: 'Invalid User ID or Password Otherwise Your Acoount is Disable Please Contact Your Administrator',
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.ERROR
			});
		}
		Ext.QuickTips.init();

		//var modulestore = new Ext.data.ArrayStore({
		//			 fields: ['module_id', 'module_fullname','module_shortname','module_active'],
		//            data: Ext.login.module
		//          
		//      }); 

		var forgotPasswordPnl = new Ext.XTemplate(
			'<div align="right"><a href="forgot-password.php">forgot password?</a></div>'
		);
		var loginForm = new Ext.FormPanel({
			url: 'logincheck.php',
			method: 'post',
			standardSubmit: true,
			frame: true,
			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>'
					}
				}]
			}, {
				columnWidth: 0.7,
				layout: 'form',
				labelWidth: 75,
				items: [{
					height: 5
				}, {
					xtype: 'textfield',
					labelStyle: 'font-weight: bold; color:#15428B',
					fieldLabel: 'User Name',
					name: 'userid',
					id: 'userid',
					tabIndex: 1,
					width: 120,
					allowBlank: false
				}, {
					xtype: 'textfield',
					labelStyle: 'font-weight: bold; color:#15428B',
					fieldLabel: 'Password',
					name: 'password',
					inputType: 'password',
					tabIndex: 2,
					width: 120,
					allowBlank: false,
					listeners: {
						specialkey: function (f, e) {
							if (e.getKey() == e.ENTER) {
								formsubmit();
							}
						}
					}
				}, {
					xtype: 'textfield',
					labelStyle: 'font-weight: bold; color:#15428B',
					name: 'captcha',
					fieldLabel: 'Captcha',
					width: 120,
					id: 'captcha',
					tabIndex: 3,
					allowBlank: false,
					listeners: {
						specialkey: function (f, e) {
							if (e.getKey() == e.ENTER) {
								formsubmit();
							}
						}
					}
				},
				{
					xtype: 'box',
					name: 'captchaimage',
					id: 'captchaimage',
					autoEl: {
						tag: 'div',
						html: '<img id="pic" src="captcha.php" alt="captchaimage" />'
					}
				},
					// {				
					// 						xtype: 'combo',
					// 						name: 'module_fullname',
					// 						hiddenName: 'module_hidden',
					// 						id:'module_id1',
					// 						tabIndex: 3,
					// 						labelStyle:'font-weight: bold; color:#15428B',
					// 						fieldLabel: 'Module',
					// 						forceSelection:true,				
					// 						displayField:'module_shortname',
					// 						valueField: 'module_id',
					// 						allowBlank:false,
					// 						triggerAction:'all',
					// 						mode:'local',
					// 						store: modulestore,
					// 						width:120,
					// 						selectOnFocus: true,
					// 						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: 4,
					// 					fieldLabel: 'Year',
					// 					labelWidth:70,
					// 					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,{
					// 			xtype: 'textfield',
					// 			name: 'yearname',
					// 			id:'yearname',
					// 			height:1,
					// 			hidden: true
					// 	},
					//			{
					//	xtype: 'textfield',
					//	name: 'module_shortname',
					//		id:'module_shortname',
					//		hidden: true

					//	}
				]
			}]
		});
		var loginWindow = new Ext.Window({
			title: 'Login',
			width: 350,
			height: 200,
			closeAction: 'close',
			closeable: false,
			collapsible: true,
			items: loginForm,
			buttonAlign: 'center',
			buttons: [{
				text: 'Login',
				iconCls: 'icon-login',
				tabIndex: 4,
				width: 60,
				handler: function () {
					var userid1 = loginForm.getForm().findField('userid').getValue();
					var password1 = loginForm.getForm().findField('password').getValue();
					var captcha1 = loginForm.getForm().findField('captcha').getValue();
					//var module=loginForm.getForm().findField('module_id1').getValue();

					//var year=loginForm.getForm().findField('year_id1').getValue();
					if (captcha1 != "") {



						Ext.Ajax.request({
							url: 'logincheck.php',
							sync: true,
							loadMask: true,
							params: { userid: userid1, password: password1, captcha: captcha1 },
							method: 'POST',
							waitMsg: 'Checking...',
							success: function () {


								Ext.Msg.alert('Status', 'You logged in!', function (btn, text) {
									if (btn == 'ok') {
										var redirect = 'logincheck.php?userid=' + userid1 + '&password=' + password1 + '&captcha=' + captcha1;
										window.location = redirect;

									}
								});
							},

						})
					} else {
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'Please Enter captcha',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.ERROR
						});
					}
				}
			}, {
				text: 'Reset',
				iconCls: 'icon-reset',
				width: 60,
				tabIndex: 5,
				handler: function () {
					loginForm.getForm().reset();
					var captchaImg = document.getElementById('pic'); 
					captchaImg.src = 'captcha.php?' + new Date().getTime();
				}
			}]
		});
		var varWidth = (screen.width - loginWindow.width) / 2;
		loginWindow.setPosition(varWidth, ((screen.height / 4) - 30));
		loginWindow.show();
		//for(var i=0;i<yearstore.getCount();i++ )
		//	    {		
		//if(yearstore.getAt(i).data.year_active == 1)
		//{ 
		// loginForm.getForm().findField('year_id1').setValue(yearstore.getAt(i).data.year_id);
		//  loginForm.getForm().findField('yearname').setValue(yearstore.getAt(i).data.year_name);

		//	break;
		//	   //  } 
		//}
		// for(var k=0;k<modulestore.getCount();k++ )
		// 		{  
		// 							  if(modulestore.getAt(k).data.module_active == 1)
		// 							   { 
		// 								  loginForm.getForm().findField('module_id1').setRawValue(modulestore.getAt(k).data.module_fullname);
		// 								  loginForm.getForm().findField('module_id1').setValue(modulestore.getAt(k).data.module_id);
		// 								  loginForm.getForm().findField('module_shortname').setValue(modulestore.getAt(k).data.module_shortname);

		// 								  break;
		// 							   } 
		// 							}	
		if (<?php echo $t ?> == 0) {
			Ext.MessageBox.show({
				title: 'Error',
				msg: 'Invalid User ID or Password Otherwise Your Acoount is Disable Please Contact Your Administrator',
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.ERROR
			});
		}
		Ext.getCmp('userid').focus(true, 500);
		function formsubmit() {
			//loginForm.getForm().findField('yearname').setValue(Ext.getCmp('year_id1').getRawValue());
			loginForm.getForm().submit({
				waitMsg: 'Checking...',
				success: function () {

					loginForm.getForm().reset();
					window.location = 'logincheck.php';
				},
				failure: function () {
					Ext.MessageBox.show({
						title: 'Error',
						msg: 'Invalid User ID or Password or Captcha Otherwise Your Acoount is Disable Please Contact Your Administrator',
						buttons: Ext.MessageBox.OK,
						icon: Ext.MessageBox.ERROR
					});
				}
			});
		}
	});
</script>
<!-- end custom CSS/JS -->
<div align="center">
	<div id="abcdhome" align="center" style="width:300px"></div>
</div>
<?php require "_footerhome.php"; ?>

