﻿function set_cookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/;";  //domain=fisherinvestments.com;";
}

function get_cookie(name) {
    var name_eq = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(name_eq) == 0) return c.substring(name_eq.length, c.length);
    }
    return null;
}

function delete_cookie(name) {
    var expires = "; expires=Thu, 01-Jan-70 00:00:01 GMT;";
    document.cookie = name + expires;
}

function SendEmail() {
    var mailto = "mailto:?subject=Check out the " + document.title + "&body=I thought you might be interested in the " + document.title + ". You can view it at " + location.href;
    window.location = mailto;
}

function addToFavorites() {
    var urlAddress = location.href;
    var pageName = document.title;
    if (window.sidebar) { // firefox
        window.sidebar.addPanel(pageName, urlAddress, "");
    } else if (window.external) {
        window.external.AddFavorite(urlAddress, pageName)
    } else if (window.opera) {
        return true;
    } else if (navigator.userAgent.toLowerCase().indexOf("safari") != -1) {
        alert("You need to press CTRL + D to bookmark our site.");
    }
    else {
        alert("In order to bookmark this site you need to do so manually through your browser.");
    }
}

//global click handling
function click(e) {
    //if IE 
    if (typeof event != 'undefined') {
        if (event.srcElement.href) {
            var ref = event.srcElement.href;
            if (ref.toLowerCase().indexOf('quiz') > -1) {
                cookie_sweep('survey');
            }
        }
        //else assume w3 standard (ns6+, mozilla) 
    } else {
        if (e.target.href) {
            var ref = e.target.href;
            if (ref.toLowerCase().indexOf('quiz') > -1) {
                cookie_sweep('survey');
            }
        }
    }
}

function set_specialcookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function cookie_sweep(type) {
    var thecookie = document.cookie.split(';');
    for (var i = 0; i < thecookie.length; i++) {
        if (thecookie[i].toLowerCase().indexOf(type) > -1) {
            var mycookie = thecookie[i].split('=');
            set_specialcookie(mycookie[0], mycookie[1], -1);
        }
    }
}
document.onclick = click;

function changeFontSize(styleID) {
    set_cookie("page_size", styleID, 180);

    var fsize = getFontStyle(styleID);
    
    $("#Site").css({
        "font-size": fsize
    });

    setSurveyFontSize(fsize);    
 }

function SetFontStyle() {
    
    $("#Site").css({
        "font-size": "1.0em"
    });

    var fsize = get_cookie("page_size");
    if (fsize != null) {
        var font = getFontStyle(fsize);
        setSurveyFontSize(font)
    } else {
        setSurveyFontSize("9pt");
    }
}

function getFontStyle(styleID) 
{
    var fsize;
    if (styleID == "small") {
        fsize = "9pt";
    } else if (styleID == "medium") {
        fsize = "10pt";
    } else if (styleID == "large") {
        fsize = "11pt";
    }
    return fsize;
}

function setSurveyFontSize(fsize) {

    $(".survey span.FieldLabelSurvey").css({
        "font-size": fsize
    });
    $(".survey span.RadioLabelArea").css({
        "font-size": fsize
    });
    $(".survey span.RatingLabel").css({
        "font-size": fsize
    });
    $(".survey div.RatingInfoRight1").css({
        "font-size": fsize
    });
    $(".survey div.RatingInfoLeft1").css({
        "font-size": fsize
    });
    $(".survey span.VerticalRadioInput").css({
        "font-size": fsize
    });
    $(".survey div.VerticalRadioInput").css({
        "font-size": fsize
    });
}

