
//********************************************************************************
//LOGIN PAGE FUNCTIONALITY
//********************************************************************************

//--------------------------------------------------------------------------------
// Events
//--------------------------------------------------------------------------------

//Set the events on load
$(document).ready
(
    function()
    {   
        //CHECK : Verify if the 'Enter Key' was pressed
        $(".Login").keypress
        (
            function(e) 
            {   
                //Gather the key pressed
                var charCode = (e.which) ? e.which : event.keyCode
        
                //CHECK : Verify that the key pressed is 'Enter' key                        
                if (charCode == 13) //Enter Key 
                {  
                    //Initialize variable                
                    var strSource = $(this).attr("id").replace("ButtonLogin","");   
                    
                    window.event.cancelBubble = true;
                    window.event.returnValue = false;
                
                    VerifyLogin(strSource);                            
                    
                    return false;                          
                }                 
            }
        );
        
        $(".Login").click
        (
            function() 
            { 
                //Initialize variable                
                var strSource = $(this).attr("id").replace("ButtonLogin","");               
                
                VerifyLogin(strSource);  
                           
                return false;
            }
        );
        
         $("#sidecolPassword").keyup
        (
            function(e)
            {
                if( e.keyCode == 13 )
                {
                    //Initialize variable                
                    var strSource = $(this).attr("id").replace("Password","");
                
                    VerifyLogin(strSource);
                    return false;
                }
            }
        )

        $("#loginPassword").keyup
        (
            function(e)
            {
                if( e.keyCode == 13)
                {
                    //Initialize variable                
                    var strSource = $(this).attr("id").replace("Password","");
                
                    VerifyLogin(strSource);
                    return false;
                }
            }
        )
    }
);

//--------------------------------------------------------------------------------


//--------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------

function VerifyLogin(strSource)
{   
    $.blockUI
                (
                    { 
                        css: 
                        { 
                        border: 'none', 
                        padding: '15px', 
                        backgroundColor: '#000', 
                        '-webkit-border-radius': '10px', 
                        '-moz-border-radius': '10px', 
                        opacity: '.5', 
                        color: '#fff' 
                        }
                    }
                );
                
    //Verify the Login information
    ob_post.AddParam("strUsername", $("#" + strSource + "Username").val());                  
    ob_post.AddParam("strPassword", $("#" + strSource + "Password").val());      
    ob_post.post("../Login.aspx", "VerifyLogin", "function(){}");            
   
    return false;            
}

function LoginSuccess(response)
{      
    //Transfer to page
    window.location = "Browse.aspx";
    
    return false;
}

function LoginFailed(response)
{      
    $.unblockUI();
        
    //Show the error message
    var t = "Login Error"; 
	var a = "LoginError.aspx?height=160&width=360&modal=true";
	var g = "";	
	tb_show(t,a,g);
	
    return false;
}

function AccountFailed(response)
{      
    $.unblockUI();         
    
    //Show the error message
    var t = "Account Error"; 
	var a = "AccountError.aspx?height=160&width=360&modal=true";
	var g = "";	
	tb_show(t,a,g);
	
    return false;
}
//--------------------------------------------------------------------------------
