/**
* @file: demo.js
* @use: on any page with an HB login form.
* @installation: include using a script tag in the markup anywhere AFTER
*           THE LOGIN FORM, and DO NOT CHANGE ANYTHING.
*/

var urltocheck = self.location.href;

if (GetCookie("demo").length > 1) {
    DeleteCookie("demo");
}

document.forms["Login"].setAttribute("autocomplete", "off");

var pwdField = document.forms['Login'].elements['password'];
if (pwdField) {
    document.forms['Login'].password.value = "";
}

var unumField = document.forms['Login'].elements['userNumber'];
if (unumField) {
    document.forms['Login'].userNumber.value = "";
}


if (urltocheck.indexOf("demo") > 0) {
    goDemo();
}

//Functions are below.

function goDemo() {
    document.cookie = "cookie_check=valid; path=/";
    document.cookie = "demo=START; path=/";
    document.forms['Login'].userNumber.backgroundImage = "";
    document.forms['Login'].password.backgroundImage = "";
    document.forms['Login'].userNumber.value = "999999999";
    document.forms['Login'].password.value = "1234";

    openDemoWin();
    dofocus();
}

function GetCookie(name) {
    var cValue = '';
    if (document.cookie.length > 0) {
        var cName = name + "=";
        var cBegin = document.cookie.indexOf(cName);
        var cEnd = 0;
        if (cBegin > -1) {
            cBegin += cName.length;
            cEnd = document.cookie.indexOf(";", cBegin);
            if (cEnd < cBegin) {
                cEnd = document.cookie.length;
            }
            cValue = document.cookie.substring(cBegin, cEnd);
            cValue = unescape(cValue);
        }
    }
    return (cValue);
}
function DeleteCookie(name) {
    expireDate = new Date;
    expireDate.setDate((expireDate.getDate() - 1));
    document.cookie = name + "=Deleted;expires=" + expireDate.toGMTString();
}

function dofocus() {
    document.cookie = "cookie_check=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/";
    document.cookie = "current=signon; path=/onlineserv/HB/";
    document.cookie = "LogTime=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
    document.cookie = "dihb30=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
    document.cookie = "direc30=expired; expires=Mon, 21-Nov-1988 14:30:00 GMT; path=/onlineserv/HB/";
    inSubmit = 0;
}
function openDemoWin() {
    demoWin = window.open("https://www.landmarkcuonline.com/onlineserv/HB/dimlDisplayer.cgi?DIML_FILE=DemoLayout.diml&DIML_PATH=../HB3.library/standard/layout/&pageType=Signon&language=english&DEFAULT_HTTP_CHAR_SET=charset=ISO-8859-1", "demo", "resizable,scrollbars,toolbar,height=400,width=700");
    if (demoWin) demoWin.focus();
    document.cookie = "demo=DISPLAY; path=/";
}

//NEW CODE TO ENSURE PASSWORD AND USERNAME HAVE LENGTHS
var pwdField = document.forms['Login'].elements['password'];
if (pwdField) {
    var pwLength = document.forms['Login'].elements['password'].maxLength;

    if ((!pwLength) || (pwLength <= 0) || (pwLength > 32))
    { alert("No maxlength is set for the password field\nor it is set incorrectly.\nThis MUST be set."); }


}

var userField = document.forms['Login'].elements['userNumber'];
if (userField) {
    var userLength = document.forms['Login'].elements['userNumber'].maxLength;

    if ((!userLength) || (userLength != 32) || (userLength > 32))
    { alert("Maxlength should be set for userName, and it should be 32.\nPlease set the maxlenght attribute appropriately."); }
}

//end of file

