﻿var expirationDate = new Date();
var currYear = expirationDate.getYear();
var documentCookie = "";

if (currYear < 1000) {
    if (currYear >= 100)
        currYear -= 100;
    currYear += 2000;
}

function setFields() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_cbRememberUsername").checked == true) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_tbusername") == "" && document.getElementById("ctl00_ContentPlaceHolder1_tbpassword") == "") {
            //location.href = '<%=Session("mainurl")%>';
        }
        else {
            expirationDate.setYear(currYear + 1);
            expirationDate = expirationDate.toGMTString();
            document.cookie = "username=" + document.getElementById("ctl00_ContentPlaceHolder1_tbusername").value + ": password=" + document.getElementById("ctl00_ContentPlaceHolder1_tbpassword").value + ":; expires= " + expirationDate;
        }
    }
    else {
        expirationDate.setYear(currYear - 1);
        expirationDate = expirationDate.toGMTString();
        document.cookie = "username=: password=:; expires= " + expirationDate;

    }
}

function getCookie() {
   
    if (document.getElementById("ctl00_ContentPlaceHolder1_tbusername")) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_tbusername").value == "") {
           
            arg = "username=";
            alen = arg.length;
            clen = document.cookie.length;
            i = 0;
            while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg) {
                    temp = cEnd = document.cookie.indexOf(":", j);
                    if (temp == -1) {
                        cEnd = document.cookie.indexOf(";", j);
                    }
                    if (cEnd == -1) cEnd = document.cookie.length;
                    document.getElementById("ctl00_ContentPlaceHolder1_tbusername").value = unescape(document.cookie.substring(j, cEnd));
                    document.getElementById("ctl00_ContentPlaceHolder1_cbRememberUsername").checked = true;
                    document.getElementById("ctl00_ContentPlaceHolder1_tbpassword").focus();
                }
                i++;
            }
        }
    }
    arg = "password=";
    alen = arg.length;
    clen = document.cookie.length;
    i = 0;

    if (document.getElementById("ctl00_ContentPlaceHolder1_tbpassword")) {
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg) {
                cEnd = document.cookie.indexOf(":", j);
                if (cEnd == -1) cEnd = document.cookie.length;
                document.getElementById("ctl00_ContentPlaceHolder1_tbpassword").value = unescape(document.cookie.substring(j, cEnd));
            }
            i++;
        }
    }
}

