﻿// JavaScript Font Resizer
function checkFontSize() {
	// Do this onload
	var receivedCookieData = getCookie("fontsizeswansea");
	if (receivedCookieData != null) {
		if(receivedCookieData == "small") smallFont();
		if(receivedCookieData == "med") medFont();
		if(receivedCookieData == "large") largeFont();
	} else {
		medFont();
	}	
}

// Get cookie function - Return the value of the cookie
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function smallFont() {
	// Change the current font size and write the value back to cookie
	document.body.style.fontSize = '70%';
	document.cookie = "fontsize=small";
}

function medFont() {
	// Change the current font size and write the value back to cookie
	document.body.style.fontSize = '80%';
	document.cookie = "fontsize=med";
}

function largeFont() {
	// Change the current font size and write the value back to cookie
	document.body.style.fontSize = '90%';
	document.cookie = "fontsize=large";
}