/**
 * Elmec
 * Requires prototype library 1.6
 * 
 */


/** GLOBALS **/
var aTypeSizes = ['typeSmaller', 'typeNormal', 'typeLarger', 'typeLargest'];
var nCurrentSize = 1;


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	var sCookie = sName + "=" + encodeURIComponent(sValue);
	
	if (oExpires) {
		SCookie += "; expires=" + oExpires.toGMTString();
	}
	
	if (sPath) {
		sCookie += "; path=" + sPath;
	}
	
	if (sDomain) {
		sCookie += "; domain= " + sDomain;
	}
	
	if (bSecure) {
		sCookie += "; secure";
	}
	
	document.cookie = sCookie;
}

function getCookie(sName) {
	var sRE = "(?:; )?" + sName + "=([^;]*);?";
	var oRE = new RegExp(sRE);
	
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}
}

function deleteCookie(sName, sPath, sDomain) {
	setCookie(sName, "", new Date(0), sPath, sDomain);
}



function increaseTextSize() {
	if (nCurrentSize != (aTypeSizes.length - 1)) {
		setActiveTextSize('mainColumn', aTypeSizes[++nCurrentSize]);
	}
}
			
function decreaseTextSize() {
	if (nCurrentSize != 0) {
		setActiveTextSize('mainColumn', aTypeSizes[--nCurrentSize]);
	}			
}

function setActiveTextSize(sId, sFontClass) {
	$(sId).className = sFontClass;
	setCookie("ActiveFontSize", sFontClass);
}

function applyTextSize() {
	var sCurrentFontSize ='typeNormal';
	if (getCookie('ActiveFontSize')) {
    	sCurrentFontSize = getCookie('ActiveFontSize');
		var nIndex = aTypeSizes.indexOf(sCurrentFontSize);
		if (nIndex != -1) { 
			nCurrentSize = nIndex; 
			setActiveTextSize('mainColumn', sCurrentFontSize);
		}
	} else {
		setActiveTextSize('mainColumn', sCurrentFontSize);
		nCurrentSize = 1; // default text size
	}
}


