/*global de*/
de = this.de || {};
de.datev = de.datev || {};
de.datev.portal = de.datev.portal || {};
de.datev.portal.fontsize = function () {
    var thisNamespace = de.datev.portal.fontsize || {};

	var defaultFontSize = "small";

	///////////////////////////////////////////////////////
	// Funktionen
	///////////////////////////////////////////////////////

	// aktuellen Cookie abfragen
	var getFontSize = function() {
		var regExp = /^.*fontSize=([a-z]+)(;.*|)$/;
		var result = regExp.exec(document.cookie);
		if (!result) {
			// es existiert kein Cookie -> Default-Wert zurückgeben
			return defaultFontSize;
		}
		if (result.length > 2) {
			return result[1];
		}
		return defaultFontSize;
	};

	var setFontSize = function(size) {
		//(1) FontSize aendern
		if (size === "small") {
			document.body.style.fontSize = "70%";
		} else if (size === "medium") {
			document.body.style.fontSize = "80%";
		} else if (size === "large") {
			document.body.style.fontSize = "90%";
		} else {
			// Default: small
			size = defaultFontSize;
			document.body.style.fontSize = "70%";
		}

		// (2) Cookie setzen
		if(navigator.cookieEnabled === true) {

			if (JS_GLOBAL_VAR_Portal == 'dpicom') {
				document.cookie =  "fontSize=" + size + ";domain=datev.com;path=/;";
			}
			else if (JS_GLOBAL_VAR_Portal == 'dpiat') {
				document.cookie =  "fontSize=" + size + ";domain=datev.at;path=/;";
			}
			else {
				document.cookie =  "fontSize=" + size + ";domain=datev.de;path=/;";
			}

		}
	};

    //////////////////////////////////////////////////////
    // PUBLIC
    //////////////////////////////////////////////////////
    thisNamespace.getFontSize = getFontSize;
    thisNamespace.setFontSize = setFontSize;

    return thisNamespace;
}(); // de.datev.portal.fontsize