var Utils = {};

Utils.createCookie = function (name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

Utils.readCookie = function (name) {
    var nameEQ = 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(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

Utils.increaseFont = function() {
    var currentSize = parseInt(Utils.readCookie("font"));
    if (currentSize < 3) {
        Utils.createCookie("font", currentSize+1, 30);
        window.location.reload(true);
    }
}

Utils.decreaseFont = function() {
    var currentSize = parseInt(Utils.readCookie("font"));
    if (currentSize > 1) {
        Utils.createCookie("font", (currentSize-1), 30);
        window.location.reload(true);
    }
}

Utils.submitAudience = function(form) {
    var selectGuidelineForm = $(form);
    var audienceGroup = $('audienceGroup');
    var value = audienceGroup.options[audienceGroup.options.selectedIndex].value;
    if (value.length>0) {
        selectGuidelineForm.action = value;
        selectGuidelineForm.submit();
    }
    return false;
}

Utils.replaceAnchors = function(replacePath) {
    var anchorHolders = $ES('div.anchorHolder');
    var baseUrl = document.location.toString();

    if (baseUrl.indexOf('#') > -1) baseUrl = baseUrl.substring(0,baseUrl.indexOf('#'));
    if (baseUrl.indexOf('?') > -1) baseUrl = baseUrl.substring(0,baseUrl.indexOf('?'));

    for (var y=0; y<anchorHolders.length; y++) {
        var anchors = anchorHolders[y].getElements('a');
        for (var x=0; x<anchors.length; x++) {
            var currentAnchor = anchors[x];
            currentAnchor.href = baseUrl + currentAnchor.href.replace(replacePath, '');
        }
    }
}