﻿// Function name : fnRemoveLblMsg
// Author: Amanpreet
// Date : 16th Oct
// Description :  used to remove visibility of Error msg for invalid credentials
// in Login
 function fnRemoveLblMsg() {
    //alert("in remove lbl");
    var lblLoginMsg = document.getElementById("lblLoginMsg");
   lblLoginMsg.style.visibility = "hidden";

}

// Function name : fnLoginClick
// Author: Amanpreet
// Date : 28th Oct
// Description :  to call server side function to check for valid/invalid user
function fnLoginClick() {
    //alert("in loginclick()");
    var txtUserName = document.getElementById("txtUserName");
    var txtPwd = document.getElementById("txtPwd");
    PageMethods.IsValidUser(txtUserName.value, txtPwd.value, OnSucceeded);
}

// Function name : fnLoginClick
// Author: Amanpreet
// Date : 28th Oct
// Description :  Callback function invoked on successful completion of the page method.
//                Implemented the logic of changing left menus for valid/invalid user.
function OnSucceeded(result, userContext, methodName) {
    //alert("succeeded");
    var lblLoginMsg = document.getElementById("lblLoginMsg");
    var lblLogin = document.getElementById("lblLogin");
    var lblLogout = document.getElementById("lblLogout");
    var dvLogin = document.getElementById("dvLogin");
    var link2Register = document.getElementById("link2Register");
    var tdViewProfile = document.getElementById("tdViewProfile");
    //var tdChangePwd = document.getElementById("tdChangePwd");

    if (methodName == "IsValidUser") {
        if (result == true) {
            //alert("valid");
            dvLogin.style.visibility = "hidden";
            lblLoginMsg.style.visibility = "hidden";
            lblLogin.style.visibility = "visible";
            lblLogout.style.visibility = "visible";
            lblLogin.innerHTML = "Welcome " + document.getElementById("txtUserName").value + ",";
            lblLogout.innerHTML = "<a href='OLogout.aspx' title='Logout'>Logout</a>";

            link2Register.innerText = "Change Password";
            link2Register.href = "OChangePwd.aspx";

            tdViewProfile.innerHTML = "<a href='OProfile.aspx' title='Profile'>प्रोफाईल</a>";
            //tdChangePwd.innerHTML = "<a href='OChangePwd.aspx' title='Change Password'>Change Password</a>";

            //alert(lblLogin.value);
        }
        else {
            //alert("invalid");
            dvLogin.style.visibility = "visible";
            lblLoginMsg.style.visibility = "visible";
            lblLogin.style.visibility = "hidden";
            lblLogout.style.visibility = "hidden";
            lblLoginMsg.innerHTML = "Invalid credentials";
            //alert(lblLoginMsg.value);
        }
    }
}


 //Function name : fnKeyPress
//Author : Amanpreet
 //Date : 22nd Oct
// Description : handling enter key in password field
/*function fnKeyPress(event)
{
    
   if (event.keyCode == 13)
   { 
   fnLoginClick();
   return false;
   }
   else
    return true;
}*/