function setCookie(cookieName, cookieValue) {
    var expiryDate = new Date();
    expiryDate.setDate(expiryDate.getDate() + DAYS_TILL_COOKIE_EXPIRY);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expiryDate.toGMTString();
}

function getCookie(cookieName) {
    if (document.cookie.length > 0) {
        var startPos = document.cookie.indexOf(cookieName + "=");
        if (startPos >= 0) {
            startPos = startPos + cookieName.length + 1;
            var endPos = document.cookie.indexOf(";", startPos);
            if (endPos < 0) {
                endPos = document.cookie.length;
            }
            return unescape(document.cookie.substring(startPos, endPos));
        }
    }
    return null;
}

function setTextBoxToCookieValue(cookieName, textBox) {
    var value = getCookie(cookieName);
    textBox.value = (value != null) ? value : "";
}

function setSelectToCookieValue(cookieName, select, defaultIndex) {
    setSelectValue(getCookie(cookieName), select, defaultIndex);
}

function setSelectValue(value, select, defaultIndex) {
    if (value !== null) {
        for (var i = 0; i < select.options.length; i++)
            if (select.options[i].value == value) {
            select.selectedIndex = i;
            return;
        }
    } else {
        select.selectedIndex = defaultIndex;
    }
}

