﻿// write the fontsize tool
function writeFontSize() {

    //check cookie
	var FontSizeCookie = "FontSize = ";
	var Cookies = document.cookie.split(';');
	for(var i=0; i < Cookies.length; i++) {
		var Cookie = Cookies[i];
		while (Cookie.charAt(0) == ' ') {
			Cookie = Cookie.substring(1,Cookie.length);
		}
		if (Cookie.indexOf(FontSizeCookie) == 0) {
			return Cookie.substring(FontSizeCookie.length,Cookie.length);
		}
		if (Cookie.substring(0,8) == "FontSize") {
		    var FontCookie = Cookie;
		}
	}
	// if yes cookie perform function
	switch (FontCookie) {
		case "FontSize=smaller": 
		    document.write("<a href style='text-decoration: underline' class=\"small\" onclick=\"changeFontSize('smaller');\">A</a>" +
	        "<a href class=\"medium\" onclick=\"changeFontSize('medium');\">A</a>" +
            "<a href class=\"large\" onclick=\"changeFontSize('larger');\">A</a>" );
		    break;
		case "FontSize=medium": 
		    document.write("<a href class=\"small\" onclick=\"changeFontSize('smaller');\">A</a>" +
	        "<a href style='text-decoration: underline' class=\"medium\" onclick=\"changeFontSize('medium');\">A</a>" +
            "<a href class=\"large\" onclick=\"changeFontSize('larger');\">A</a>" );
           break;
		case "FontSize=larger": 
		    document.write("<a href class=\"small\" onclick=\"changeFontSize('smaller');\">A</a>" +
	        "<a href class=\"medium\" onclick=\"changeFontSize('medium');\">A</a>" +
            "<a href style='text-decoration: underline' class=\"large\" onclick=\"changeFontSize('larger');\">A</a>" );
            break;
		default:
		    document.write("<a href style='text-decoration: underline' class=\"small\" onclick=\"changeFontSize('smaller');\">A</a>" +
	        "<a href class=\"medium\" onclick=\"changeFontSize('medium');\">A</a>" +
            "<a href class=\"large\" onclick=\"changeFontSize('larger');\">A</a>" );
	}
	

//    document.write("<a href class=\"small\" onclick=\"changeFontSize('smaller');\">A</a>" +
//	    "<a href class=\"medium\" onclick=\"changeFontSize('medium');\">A</a>" +
//        "<a href class=\"large\" onclick=\"changeFontSize('larger');\">A</a>" );

	return;
}



// performed onclick
function changeFontSize(fontSize) {
    //set cookie
	document.cookie = "FontSize = " + fontSize + "; path=/";
	// reload the page
	window.location.reload();
}


// performed onload
function checkFontSize() {
	//check cookie
	var FontSizeCookie = "FontSize = ";
	var Cookies = document.cookie.split(';');
	for(var i=0; i < Cookies.length; i++) {
		var Cookie = Cookies[i];
		while (Cookie.charAt(0) == ' ') {
			Cookie = Cookie.substring(1,Cookie.length);
		}
		if (Cookie.indexOf(FontSizeCookie) == 0) {
			return Cookie.substring(FontSizeCookie.length,Cookie.length);
		}
		if (Cookie.substring(0,8) == "FontSize") {
		    var FontCookie = Cookie;
		}
	}
	// if yes cookie perform function
	switch (FontCookie) {
	    case "FontSize=smaller": var setFontSize = "1"; var footerFontSize = "1"; break;
	    case "FontSize=medium": var setFontSize = "1.13"; var footerFontSize = "1.10"; break;
	    case "FontSize=larger": var setFontSize = "1.30"; var footerFontSize = "1.20"; break;
		default: var setFontSize = "1";
	}
	document.write('<style type="text/css" media="screen">div#main { font-size: ' + setFontSize + 'em; }</style>');
	document.write('<style type="text/css" media="screen">div#footer_container { font-size: ' + footerFontSize + 'em; }</style>');
	
	return null;
}

/* perform and write out the Font Size */
checkFontSize();
