﻿function getObj(objId) {
	if (document.getElementById)
		obj = document.getElementById(objId);
	else if (document.all)
		obj = document.all[objId];
	else
		obj = null;
	return obj;
}

var Cookies = {
	add: function(name,value,days) {
		var expires = '';
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = '; expires='+ date.toGMTString();;
		}
		document.cookie = name+"="+escape(value) + expires+"; path=/";
	},
	remove: function(name) {
		this.add(name, '', -1);
	},
	get: function(name) {
		var results = document.cookie.match ( name + '=([^;]*?)(;|$)' );
		if ( results )
			return ( unescape ( results[1] ) );
		else
			return null;
	}
};
FontSizer.Instances = new Object();

function FontSizer(type,upid,downid,resetid) {
	this.baseSize = 13;
	this.stepSize = 2;	
	this.maxSize = 20;
	this.minSize = 9;
	this.sizeElement = type;
	
	this.cookieName = type+"FontSizer";
	var x = Cookies.get(this.cookieName);
	this.currentSize = (x) ? parseInt(x) : this.baseSize;
	if (this.currentSize!=this.baseSize) this.ChangeSize();
	
	FontSizer.Instances[type] = this;
	
	var upObj = getObj(upid);
	if (upObj) upObj.onclick =  function() { FontSizer.Instances[type].UpSize(); return false; };
	var downObj = getObj(downid);
	if (downObj) downObj.onclick =  function() { FontSizer.Instances[type].DownSize(); return false; };
	var rsObj = getObj(resetid);
	if (rsObj) rsObj.onclick = function() { FontSizer.Instances[type].Reset(); return false; }
}

var FSP = FontSizer.prototype;
FSP.Reset = function() { Cookies.remove(this.cookieName); this.currentSize = this.baseSize; this.ChangeSize(); }
FSP.ChangeSize = function() { 
	Cookies.add(this.cookieName,this.currentSize,7); 
	var sizeElement = getObj(this.sizeElement);
	if (sizeElement) sizeElement.style.fontSize = (this.currentSize/this.baseSize) +'em';
}
FSP.UpSize = function() { this.currentSize = Math.min(this.currentSize + this.stepSize, this.maxSize); this.ChangeSize(); }
FSP.DownSize = function() { this.currentSize = Math.max(this.currentSize - this.stepSize, this.minSize); this.ChangeSize(); }

//window.onload = function init() {var FS = new FontSizer('subcontent','fntSizeInc','fntSizeDec','fntSizeReset');}
 //FS.update();