﻿

/*
 *
 * Page Font Size handling
 *
 */

function SwitchFontSize(newSize) {
	if(!location.pathname.match("/database/")) {
		var FONTSIZE_COOKIENAME = "fontsize";
		if(newSize) {
			document.body.className = newSize + "Font";
			SetCookie(FONTSIZE_COOKIENAME, newSize, 30);
			}
		else {
			var priorSize = GetCookie(FONTSIZE_COOKIENAME);
			if(priorSize) {
				document.body.className = priorSize + "Font";
				}
			else {
				document.body.className = "mediumFont";
				}
	
			}
		}
	}



/*
 *
 * Menu handling
 *
 */

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}


function HighlightMenu(whichMenu) {
	addClass(whichMenu, "hover");
//	whichMenu.className = "hover";
	}

function DimMenu(whichMenu) {
//	whichMenu.className = "";
	removeClass(whichMenu, "hover");
	}
	
function GoToPage(whichURL, clickEvent) {
	window.location.href = whichURL;
	if (!clickEvent) {
		clickEvent = window.event;
		}
	if(clickEvent) {
		clickEvent.cancelBubble = true;
		if (clickEvent.stopPropagation) clickEvent.stopPropagation();
		if (clickEvent.preventDefault) clickEvent.preventDefault();
		}
	}
	



/*
 *
 * Cookie handling
 *
 */


	
function SetCookie(cookieName, cookieValue, days) {
	var expirationDate = new Date();
	expirationDate.setDate(expirationDate.getDate() + days);
	document.cookie = cookieName+ "=" + escape(cookieValue) + ((days==null) ? "" : ";expires=" + expirationDate.toGMTString());
	}	
	
function GetCookie(whichCookie) {
	if (document.cookie.length > 0) {
		cookies = eval("({\"" + document.cookie.replace(/\s/g, "").replace(/;/g, "\",\"").replace(/=/g, "\":\"") + "\"})");
		return(cookies[whichCookie]);
		}
	return null;
	}	
	
	




