﻿// JScript File
 var useful = new Ext.FormPanel
 ({
        labelWidth: 50,
       // frame:true,
        title: 'กลุ่มข้อมูล',
        style:'padding:0px 0px 0px 0px',  
        //width: 218,
        //defaults: {width: 218},
      closable:true,
     // layout to fit child component
     layout:'fit', 
        items : 
        [{
            html: '<iframe id="Usefull" name="Usefull" src="../../Pages/useful/Default.aspx" width="100%" height="750px" scrolling="auto" frameborder="0"></iframe>'
        }]     
           
 });


 var loginPanel = new Ext.FormPanel({
        labelWidth: 50, // label settings here cascade unless overridden
        //url:'save-form.php',
        frame:true,
        title: 'เข้าสู่ระบบ',
        style:'padding:2px 2px 2px 2px',  
        //width: 218,
        //defaults: {width: 218},
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'ผู้ใช้งาน',
                id : 'username',
                name: 'username',
                width: 140,
                maxLength	:	20,
                allowBlank:false
            },{
                fieldLabel: 'รหัสผ่าน',
                name: 'password',
                id: 'password',
                width: 140,
                maxLength	:	20,
                inputType : 'password',
                allowBlank:false,
                name: 'last'
            }
        ],

        buttons: [{
                    text: 'เข้าสู่ระบบ',
                    handler: function(){
                      var username =  Ext.getCmp('username');
                      var password =  Ext.getCmp('password');
                      var user = username.getRawValue();
                      var pass = password.getRawValue();
                      if(user!=''&&pass!=''){
                        countQuery("Login",user,pass);	
                      }
                    },  
                    iconCls: 'apply',                                
                    scope: this            
                }]
    });
    
    
function countQuery(sCommand, sUserName, sPassword)
{
    Ext.Ajax.request({
       url: '../ConnectServer/Server.aspx?Command='+sCommand+'&UserName='+sUserName+'&Password='+sPassword,
       isLoading:true,
       failure: function(){
            Ext.Msg.alert('Messsage','Cancel');
       },              
       success: function(response,options){  
            
            if(response.responseText!="")
            {            
                var sSplit = response.responseText.split('$');  
                var sMessage = sSplit[1];
                if(sSplit[0]=="1")
                {
                    //MessageBox('ผลการทำงาน',sMessage, Ext.MessageBox.INFO,Ext.MessageBox.OK,showResultText);
                    if (parent.location.href == self.location.href)
                    {
                        //window.location.href = '../../Default.aspx';
                        //window.location.href = '../main/main.htm';
                        window.location.href = '../main/main.aspx';
                    }                    
                }
                else
                {
                    MessageBox('ผลการทำงาน',sMessage, Ext.MessageBox.ERROR,Ext.MessageBox.OK,showResultText);
                }
            }
            else
            {
                MessageBox('ผลการทำงาน',"ข้อผิดพลาด","UserName หรือ Password ไม่ถูกต้อง โปรดระบุใหม่", Ext.MessageBox.ERROR,Ext.MessageBox.OK,showResultText);                
            }			
       }
    });
}
