﻿/* Cookies */
function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function GetCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}
/* End Cookies */

function ChangeFontSize(link) {
    var body = document.getElementsByTagName("body")[0];

    switch (body.className) {
        case "BigFont":
            body.className = "";
            break;
        default:
            body.className = "BigFont";
    }
    $(link).toggleClass("actFont");

    var curDate = new Date();
    curDate.setFullYear(curDate.getFullYear() + 1);
    SetCookie("fontSize", body.className, curDate.toGMTString(), "/", document.domain);
}

function submitEmail() {
    var email = document.getElementById("email").value;
    if (isEmailCorrect(email)) {
        var url = location.href;
        location.href = "http://www.hfma.org/Site/publications/subscribehwytk.cfm?email=" + email + "&return=" + escape(url);
        document.getElementById("emailError").style.display = "none";
    }
    else {
        document.getElementById("emailError").style.display = "block";
    }
}

function isEmailCorrect(email) {
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) {
        return false;
    }
    return true;
}
