﻿
/*
    Computer Science Group, LLC
    225-766-2397 office
    225-205-0263 cell
    darrell@computersciencegroup.com
    Copyright © 2010 Computer Science Group, LLC, All rights reserved.
*/

var __ThisLogIn;

//csgLogIn()
//11/11/2010
function csgLogIn()
{
    //global used in properties/methods/events
    __ThisLogIn = this;
    this.userName = new csgTextBox(window, "__userName", 16);
    this.passWord = new csgTextBox(window, "__passWord", 16);
    this.requestLogInInfoEmailAddress = new csgTextBox(window, "__requestLogInInfoEmailAddress", 50);
    //pageEnableLogOutButton()
    //11/11/2010
    this.pageEnableLogOutButton = function ()
    {
        var oBtn = $get("__btnLogOut");
        var oUser_idValue;
        var oUserName;
        if (oBtn)
        {
            oUser_idValue = pageGetSystemUser_idValue();
            if (oUser_idValue)
            {
                if (oUser_idValue)
                {
                    oBtn.disabled = "";
                    oUserName = top.$get("__pageHeaderUserName");
                    if (oUserName) { oBtn.title = "Log " + oUserName.innerText + " out." }
                    else { oBtn.title = "Log out." }
                    return;
                }
            }
        }
    }
    //----------------------------------------
    this.pageEnableLogOutButton();
    //07/30/2011
    var odd = helpDragAndDrop_getLogin();
    if (odd)
    {
        if (odd.isVisible() == true)
        {
            try { this.userName.textBox.focus(); }
            catch (e) { }
        } 
    }
}

//onClick(<opElement>)
//11/11/2010
window.onClick = function (opElement)
{
    switch (opElement.id)
    {
        case "__btnLogIn":
            postBackWithPostBackAction(opElement.id);
            break;
        case "__btnLogOut":
            postBackWithPostBackAction(opElement.id);
            break;
//        case "__btnToggleRequestLogInInfo":
//            toggleRequestLogInInfo(opElement.id);
//            break;
        case "__btnRequestLogInInfo":
            postBackRequestForLogInInfo(opElement.id);
            break;
    }
}

//textBoxOnKeyPress(<opElement>)
//11/12/2010
window.textBoxOnKeyPress = function (opElement)
{
    if (event.keyCode == 13)
    {
        if ((opElement.textBox.id == "__userName") || (opElement.textBox.id == "__passWord"))
        {
            if ($get("__btnLogIn").disabled == "") { postBackWithPostBackAction("__btnLogIn") }
        }
        else if (opElement.textBox.id == "__requestLogInInfoEmailAddress")
        {
            if ($get("__btnRequestLogInInfo").disabled == "") { postBackRequestForLogInInfo("__btnRequestLogInInfo") }
        }
    }
}

//saveToHiddenFields()
//11/17/2010
function saveToHiddenFields()
{
    var oHidden = $get("__pageHiddenFieldUserName");
    if (oHidden) { oHidden.value = __ThisLogIn.userName.textBox.value; }
    oHidden = $get("__pageHiddenFieldPassword");
    if (oHidden) { oHidden.value = __ThisLogIn.passWord.textBox.value; }
    oHidden = $get("__pageHiddenFieldRequestLogInInfoEmailAddress");
    if (oHidden) { oHidden.value = __ThisLogIn.requestLogInInfoEmailAddress.textBox.value; }
}

//postBackRequestForLogInInfo(<opButtonId>)
//11/12/2010
//called by window.textBoxOnKeyPress(opElement) and window.onClick(opElement)
function postBackRequestForLogInInfo(opButtonId)
{
    var oemail = __ThisLogIn.requestLogInInfoEmailAddress.textBox.value;
    var omsg = "If a user with the email address: " + oemail + " is found, log in information will be sent to " + oemail + ". Continue?";
    if (confirm(omsg)) { postBackWithPostBackAction(opButtonId); }

}

//postBackWithPostBackAction(<opButtonId>)
//11/12/2010
//called by window.textBoxOnKeyPress(opElement) and window.onClick(opElement)
function postBackWithPostBackAction(opButtonId)
{
    saveToHiddenFields();
    pageSetPostBackActionValue(opButtonId);
    document.forms[0].submit();
}

////toggleRequestLogInInfo(<opElementId>)
////11/12/2010
////called by window.onClick(opElement)
//function toggleRequestLogInInfo(opElementId)
//{
//    var oOuterDiv;
//    var oInnerDiv;
//    var oTR = $get("__requestLogInInfoTR");
//    if (oTR)
//    {
//        oOuterDiv = $get("__ddLogIn40OuterDiv");
//        if (oOuterDiv)
//        {
//            oInnerDiv = $get("__ddLogIn40Div");
//            if (oInnerDiv)
//            {
//                oTR = $get("__requestLogInInfoTR");
//                oTR.style.visibility = (oTR.style.visibility == "visible" ? "hidden" : "visible");
//                if (oTR.style.visibility == "visible")
//                {
//                    oOuterDiv.style.height = "100px";
//                    oInnerDiv.style.height = "83px";
//                    __ThisLogIn.requestLogInInfoEmailAddress.textBox.focus();
//                    disableRequestLogInInfoIfNotAValidEmail();
//                }
//                else
//                {
//                    oOuterDiv.style.height = "79px";
//                    oInnerDiv.style.height = "62px";
//                }
//            }
//        } 
//    }
//}

//window.textBoxOnKeyUp(<opElement>)
//window.textBoxOnKeyPress(<opElement>)
//11/11/2010
window.textBoxOnKeyUp = function (opElement)
{
    if ((event.srcElement.id == "__userName") || (event.srcElement.id == "__passWord"))
    {
        disableLogInButtonIfNoUserNameAndPassword();
    }
    else if (event.srcElement.id == "__requestLogInInfoEmailAddress")
    {
        disableRequestLogInInfoIfNotAValidEmail();
    }
}

//disableLogInButtonIfNoUserNameAndPassword()
//11/11/2010
function disableLogInButtonIfNoUserNameAndPassword()
{
    var oBtn = $get("__btnLogIn");
    if (oBtn)
    {
        if (__ThisLogIn.userName.textBox.value == "")
        {
            oBtn.disabled = "disabled";
            return;
        }
        if (__ThisLogIn.passWord.textBox.value == "")
        {
            oBtn.disabled = "disabled";
            return;
        }
    }
    oBtn.disabled = "";
}

//disableRequestLogInInfoIfNotAValidEmail()
//11/11/2010
function disableRequestLogInInfoIfNotAValidEmail()
{
    var oBtn = $get("__btnRequestLogInInfo");
    if (oBtn)
    {
        if (pageValidEMailAddress(__ThisLogIn.requestLogInInfoEmailAddress.textBox.value) == false)
        {
            oBtn.disabled = "disabled";
            return;
        }
    }
    oBtn.disabled = "";
}
